Skip to content

Commit

Permalink
Add copy data correctly
Browse files Browse the repository at this point in the history
  • Loading branch information
blaisb authored and oguevremont committed Sep 24, 2024
1 parent 5970820 commit 41cf5bd
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 26 deletions.
56 changes: 42 additions & 14 deletions include/solvers/copy_data.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class CopyData
CopyData(const unsigned int n_dofs)
: local_matrix(n_dofs, n_dofs)
, local_rhs(n_dofs)
, local_dof_indices(n_dofs){};
, local_dof_indices(n_dofs) {};

/**
* @brief Resets the cell_matrix and the cell_rhs to zero
Expand Down Expand Up @@ -96,7 +96,7 @@ class StabilizedMethodsCopyData
, local_rhs(n_dofs)
, local_dof_indices(n_dofs)
, strong_residual(n_q_points)
, strong_jacobian(n_q_points, Vector<double>(n_dofs)){};
, strong_jacobian(n_q_points, Vector<double>(n_dofs)) {};


/**
Expand All @@ -116,29 +116,57 @@ class StabilizedMethodsCopyData
}
}


struct CopyDataFace
{
FullMatrix<double> cell_matrix;
Vector<double> cell_rhs;

std::vector<types::global_dof_index> joint_dof_indices;
};

FullMatrix<double> local_matrix;
Vector<double> local_rhs;
std::vector<types::global_dof_index> local_dof_indices;
Vector<double> strong_residual;
std::vector<Vector<double>> strong_jacobian;
std::vector<CopyDataFace> face_data;


// Boolean used to indicate if the cell being assembled is local or not
// This information is used to indicate to the copy_local_to_global function
// if it should indeed copy or not.
bool cell_is_local;
};



/**
* @brief Responsible for storing the information calculated using the discontinuous galerkin (DG) assembly of stabilized
* scalar equations. Like the StabilizedCopyData class, this class is used to
*initialize, zero (reset) and store the cell_matrix and the cell_rhs while
*having support for stabilized terms. However, it also has additional structure
*to support the storage of information at internal faces. This is required for
*the DG methods.
**/
class StabilizedDGMethodsCopyData : public StabilizedMethodsCopyData
{
public:
/**
* @brief Constructor. Allocates the memory for the cell_matrix, cell_rhs
* and dof-indices using the number of dofs and the strong_residual using the
* number of quadrature points and, the strong_jacobian using both
*
* @param n_dofs Number of degrees of freedom per cell in the problem
*
* @param n_q_points Number of quadrature points
*/
StabilizedDGMethodsCopyData(const unsigned int n_dofs,
const unsigned int n_q_points)
: StabilizedMethodsCopyData(n_dofs, n_q_points) {};


// Additional small struct
struct CopyDataFace
{
FullMatrix<double> cell_matrix;
Vector<double> cell_rhs;

std::vector<types::global_dof_index> joint_dof_indices;
};

std::vector<CopyDataFace> face_data;
};

/**
* @brief Class responsible for storing the information calculated using the assembly of stabilized
* Tensor<1,dim> equations. Like the CopyData class, this class is used to
Expand Down Expand Up @@ -170,7 +198,7 @@ class StabilizedMethodsTensorCopyData
, local_rhs(n_dofs)
, local_dof_indices(n_dofs)
, strong_residual(n_q_points)
, strong_jacobian(n_q_points, std::vector<Tensor<1, dim>>(n_dofs)){};
, strong_jacobian(n_q_points, std::vector<Tensor<1, dim>>(n_dofs)) {};

/**
* @brief Resets the cell_matrix, cell_rhs, strong_residual
Expand Down
1 change: 1 addition & 0 deletions include/solvers/tracer_assemblers.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,4 +186,5 @@ class TracerAssemblerBDF : public TracerAssemblerBase<dim>
};



#endif
27 changes: 15 additions & 12 deletions source/solvers/tracer.cc
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,24 @@ Tracer<dim>::assemble_system_matrix_dg()
*this->mapping,
dof_handler_fluid->get_fe());

StabilizedMethodsCopyData copy_data(this->fe->n_dofs_per_cell(),
this->cell_quadrature->size());
StabilizedDGMethodsCopyData copy_data(this->fe->n_dofs_per_cell(),
this->cell_quadrature->size());

// We first wrap the assembly of the matrix within a cell_worker lambda
// function This is only done for compatibility reasons with the MeshWorker
// paradigm and does not have any functional purpose.
const auto cell_worker =
[&](const typename DoFHandler<dim>::active_cell_iterator &cell,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
this->assemble_local_system_matrix(cell, scratch_data, copy_data);
};

const auto boundary_worker =
[&](const typename DoFHandler<dim>::active_cell_iterator &cell,
const unsigned int &face_no,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
double beta = 10;
beta *= 1 / compute_cell_diameter<dim>(cell->measure(), 1);

Expand Down Expand Up @@ -329,7 +332,7 @@ Tracer<dim>::assemble_system_matrix_dg()
const unsigned int &nf,
const unsigned int &nsf,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
double beta = 10;
beta *= 1 / compute_cell_diameter<dim>(cell->measure(), 1);
FEInterfaceValues<dim> &fe_iv = scratch_data.fe_interface_values_tracer;
Expand Down Expand Up @@ -404,7 +407,7 @@ Tracer<dim>::assemble_system_matrix_dg()
};


const auto copier = [&](const StabilizedMethodsCopyData &c) {
const auto copier = [&](const StabilizedDGMethodsCopyData &c) {
this->copy_local_matrix_to_global_matrix(c);

const AffineConstraints<double> &constraints_used = this->zero_constraints;
Expand Down Expand Up @@ -587,21 +590,21 @@ Tracer<dim>::assemble_system_rhs_dg()
*this->mapping,
dof_handler_fluid->get_fe());

StabilizedMethodsCopyData copy_data(this->fe->n_dofs_per_cell(),
this->cell_quadrature->size());
StabilizedDGMethodsCopyData copy_data(this->fe->n_dofs_per_cell(),
this->cell_quadrature->size());

const auto cell_worker =
[&](const typename DoFHandler<dim>::active_cell_iterator &cell,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
this->assemble_local_system_rhs(cell, scratch_data, copy_data);
};

const auto boundary_worker =
[&](const typename DoFHandler<dim>::active_cell_iterator &cell,
const unsigned int &face_no,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
double beta = 10;

beta *= 1 / compute_cell_diameter<dim>(cell->measure(), 1);
Expand Down Expand Up @@ -728,7 +731,7 @@ Tracer<dim>::assemble_system_rhs_dg()
const unsigned int &nf,
const unsigned int &nsf,
TracerScratchData<dim> &scratch_data,
StabilizedMethodsCopyData &copy_data) {
StabilizedDGMethodsCopyData &copy_data) {
// TODO refactor and put inside a parameter formally
double beta = 10;
beta *= 1 / compute_cell_diameter<dim>(cell->measure(), 1);
Expand Down Expand Up @@ -832,7 +835,7 @@ Tracer<dim>::assemble_system_rhs_dg()
};


const auto copier = [&](const StabilizedMethodsCopyData &c) {
const auto copier = [&](const StabilizedDGMethodsCopyData &c) {
this->copy_local_rhs_to_global_rhs(c);
const AffineConstraints<double> &constraints_used = this->zero_constraints;
for (const auto &cdf : c.face_data)
Expand Down

0 comments on commit 41cf5bd

Please sign in to comment.