Skip to content

Commit

Permalink
NavierStokesOperatorBase: precompute forcing term (#1270)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterrum authored Aug 29, 2024
1 parent f34bbcb commit 0ba8ab1
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 14 deletions.
12 changes: 12 additions & 0 deletions include/solvers/fluid_dynamics_matrix_free_operators.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,12 @@ class NavierStokesOperatorBase : public Subscriptor
void
compute_element_size();

/**
* @brief Precompute forcing term.
*/
void
compute_forcing_term();

/**
* @brief Get the total number of DoFs.
*
Expand Down Expand Up @@ -449,6 +455,12 @@ class NavierStokesOperatorBase : public Subscriptor
*/
bool enable_hessians_residual;

/**
* @brief Table with precomputed forcing term values.
*
*/
Table<2, Tensor<1, dim, VectorizedArray<number>>> forcing_terms;

/**
* @brief Table with correct alignment for vectorization to store the values
* of the previous newton step.
Expand Down
46 changes: 32 additions & 14 deletions source/solvers/fluid_dynamics_matrix_free_operators.cc
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ NavierStokesOperatorBase<dim, number>::reinit(

this->compute_element_size();

this->compute_forcing_term();

bool_dof_mask = create_bool_dof_mask(dof_handler.get_fe(), quadrature);

constrained_indices.clear();
Expand Down Expand Up @@ -322,6 +324,34 @@ NavierStokesOperatorBase<dim, number>::compute_element_size()
}
}

template <int dim, typename number>
void
NavierStokesOperatorBase<dim, number>::compute_forcing_term()
{
if (this->forcing_function)
{
const unsigned int n_cells =
matrix_free.n_cell_batches() + matrix_free.n_ghost_cell_batches();

FECellIntegrator integrator(matrix_free);

forcing_terms.reinit(n_cells, integrator.n_q_points);

for (unsigned int cell = 0; cell < n_cells; ++cell)
{
integrator.reinit(cell);
for (const auto q : integrator.quadrature_point_indices())
{
const Point<dim, VectorizedArray<number>> point_batch =
integrator.quadrature_point(q);
forcing_terms(cell, q) =
evaluate_function<dim, number, dim>(*(this->forcing_function),
point_batch);
}
}
}
}

template <int dim, typename number>
types::global_dof_index
NavierStokesOperatorBase<dim, number>::m() const
Expand Down Expand Up @@ -868,13 +898,7 @@ NavierStokesStabilizedOperator<dim, number>::do_cell_integral_local(

// Evaluate source term function if enabled
if (this->forcing_function)
{
Point<dim, VectorizedArray<number>> point_batch =
integrator.quadrature_point(q);
source_value =
evaluate_function<dim, number, dim>(*(this->forcing_function),
point_batch);
}
source_value = this->forcing_terms(cell, q);

// Add to source term the dynamic flow control force (zero if not enabled)
source_value += this->beta_force;
Expand Down Expand Up @@ -1096,13 +1120,7 @@ NavierStokesStabilizedOperator<dim, number>::local_evaluate_residual(

// Evaluate source term function if enabled
if (this->forcing_function)
{
Point<dim, VectorizedArray<number>> point_batch =
integrator.quadrature_point(q);
source_value =
evaluate_function<dim, number, dim>(*(this->forcing_function),
point_batch);
}
source_value = this->forcing_terms(cell, q);

// Add to source term the dynamic flow control force (zero if not
// enabled)
Expand Down

0 comments on commit 0ba8ab1

Please sign in to comment.