4#ifndef lethe_fluid_dynamics_matrix_free_operators_h
5#define lethe_fluid_dynamics_matrix_free_operators_h
15#include <deal.II/base/timer.h>
17#include <deal.II/lac/dynamic_sparsity_pattern.h>
18#include <deal.II/lac/trilinos_sparse_matrix.h>
20#include <deal.II/matrix_free/fe_evaluation.h>
21#include <deal.II/matrix_free/matrix_free.h>
22#include <deal.II/matrix_free/operators.h>
23#include <deal.II/matrix_free/tools.h>
61template <
int dim,
typename Number>
62VectorizedArray<Number>
64 const Point<dim, VectorizedArray<Number>> &p_vectorized,
65 const unsigned int component = 0)
67 VectorizedArray<Number> result;
68 for (
unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
71 for (
int d = 0; d < dim; ++d)
72 p[d] = p_vectorized[d][v];
73 result[v] = function.value(p, component);
87template <
int dim,
typename Number>
88Tensor<1, dim, VectorizedArray<Number>>
90 const Function<dim> &function,
91 const Point<dim, VectorizedArray<Number>> &p_vectorized)
93 Tensor<1, dim, VectorizedArray<Number>> result;
94 for (
unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
97 for (
int d = 0; d < dim; ++d)
98 p[d] = p_vectorized[d][v];
100 Tensor<1, dim> gradient = function.gradient(p);
101 for (
int d = 0; d < dim; ++d)
102 result[d][v] = gradient[d];
117template <
int dim,
typename Number,
int components>
118Tensor<1, components, VectorizedArray<Number>>
120 const Point<dim, VectorizedArray<Number>> &p_vectorized)
122 Tensor<1, components, VectorizedArray<Number>> result;
123 for (
unsigned int v = 0; v < VectorizedArray<Number>::size(); ++v)
126 for (
int d = 0; d < dim; ++d)
127 p[d] = p_vectorized[d][v];
128 for (
int d = 0; d < components; ++d)
129 result[d][v] = function.value(p, d);
164template <
int dim,
typename number>
170 using VectorType = LinearAlgebra::distributed::Vector<number>;
207 const Mapping<dim> &mapping,
208 const DoFHandler<dim> &dof_handler,
210 const Quadrature<dim> &quadrature,
212 const std::shared_ptr<PhysicalPropertiesManager>
213 &physical_properties_manager,
215 const unsigned int mg_level,
250 const DoFHandler<dim> &dof_handler,
252 const Quadrature<dim> &quadrature,
254 const std::shared_ptr<PhysicalPropertiesManager>
255 &physical_properties_manager,
257 const unsigned int mg_level,
301 const DoFHandler<dim> &temperature_dof_handler);
308 types::global_dof_index
320 el(
unsigned int,
unsigned int)
const;
343 const std::shared_ptr<const Utilities::MPI::Partitioner> &
392 const DynamicSparsityPattern &
401 const TrilinosWrappers::SparseMatrix &
409 const MatrixFree<dim, number> &
417 const AlignedVector<VectorizedArray<number>>
457 const VectorType &time_derivative_previous_solutions);
471 const Point<dim> center_of_rotation,
472 const unsigned int rotation_axis_direction,
473 const std::shared_ptr<Functions::ParsedFunction<dim>>
474 &rotor_angular_velocity);
502 std::shared_ptr<NavierStokesCouplingEvaluationSIPG<dim, double>>
532 const std::pair<unsigned int, unsigned int> &range)
const;
542 template <
bool assemble_res
idual>
559 template <
bool assemble_res
idual>
565 const std::pair<unsigned int, unsigned int> &range)
const;
583 const std::pair<unsigned int, unsigned int> &range)
const;
600 const std::pair<unsigned int, unsigned int> &range)
const = 0;
643 mutable DynamicSparsityPattern
dsp;
760 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
768 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
776 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
784 Table<2, Tensor<1, dim + 1, Tensor<2, dim, VectorizedArray<number>>>>
792 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
800 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
831 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
868 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
876 Table<2, Tensor<1, dim + 1, Tensor<1, dim, VectorizedArray<number>>>>
904 Table<2, Tensor<1, dim + 1, VectorizedArray<number>>>
982template <
int dim,
typename number>
989 using VectorType = LinearAlgebra::distributed::Vector<number>;
1020 const std::pair<unsigned int, unsigned int> &range)
const override;
1029template <
int dim,
typename number>
1067 const std::pair<unsigned int, unsigned int> &range)
const override;
This class manages the boundary conditions forhe fluid dynamics solver It introduces the boundary fun...
FEEvaluation< dim, -1, 0, dim+1, number > FECellIntegrator
void do_cell_integral_local(FECellIntegrator &integrator) const override
Perform cell integral on a cell batch without gathering and scattering the values,...
void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const override
Perform cell integral on a cell batch with gathering and scattering the values, and according to the ...
FEFaceEvaluation< dim, -1, 0, dim+1, number > FEFaceIntegrator
NavierStokesNonNewtonianStabilizedOperator()
LinearAlgebra::distributed::Vector< number > VectorType
Table< 2, VectorizedArray< MGNumber > > face_target_pressure
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > nonlinear_previous_advective_values
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > face_target_velocity
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_gradient
TrilinosWrappers::SparseMatrix system_matrix
std::vector< unsigned int > constrained_indices
number el(unsigned int, unsigned int) const
Access a particular element in the matrix. Only required for compilation and it is not used.
Table< 2, bool > bool_dof_mask
void evaluate_velocity_ale(const Mapping< dim > &mapping, const Point< dim > center_of_rotation, const unsigned int rotation_axis_direction, const std::shared_ptr< Functions::ParsedFunction< dim > > &rotor_angular_velocity)
Store the values of the vector containing the ALE velocity to use them in the Jacobian and residual c...
virtual void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const =0
Interface to function in charge of computing the residual using a cell integral in a cell batch with ...
const DynamicSparsityPattern & get_sparsity_pattern() const
Return sparsity pattern used to set up the sparse matrix by get_system_matrix().
std::shared_ptr< NavierStokesCouplingEvaluationSIPG< dim, double > > mortar_coupling_evaluator_mf
void do_boundary_face_integral_local(FEFaceIntegrator &integrator) const
Carry out the integration of boundary face integrals.
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > forcing_terms
void reinit(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number > &constraints, const Quadrature< dim > &quadrature, const std::shared_ptr< Function< dim > > &forcing_function, const std::shared_ptr< PhysicalPropertiesManager > &physical_properties_manager, const StabilizationType stabilization, const unsigned int mg_level, const std::shared_ptr< SimulationControl > &simulation_control, const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > &boundary_conditions, const bool &enable_hessians_jacobian, const bool &enable_hessians_residual, const bool &enable_mortar)
Initialize the main matrix free object that contains all data and is needed to perform loops over cel...
bool has_edge_constrained_indices
virtual void evaluate_non_linear_term_and_calculate_tau(const VectorType &newton_step)
Store relevant values of the vector of the last newton step to use it in the Jacobian and pre-calcula...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > velocity_ale
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > nonlinear_previous_values
std::shared_ptr< CouplingOperator< dim, double > > mortar_coupling_operator_mf
void update_beta_force(const Tensor< 1, dim > &beta_force)
Store the values of the source term calculated if dynamic control is enabled in the appropriate struc...
std::shared_ptr< PhysicalPropertiesManager > properties_manager
std::vector< unsigned int > edge_constrained_indices
std::vector< std::pair< MGNumber, MGNumber > > constrained_values
void compute_thermal_buoyancy_term(const VectorType &temperature_solution, const DoFHandler< dim > &temperature_dof_handler)
Precompute thermal buoyancy term for heat-transfer coupling.
void evaluate_prescribed_neumann_traction()
Store the values of the prescribed Neumann traction boundary condition to use it ....
Table< 2, Tensor< 1, dim, VectorizedArray< MGNumber > > > thermal_buoyancy_term
bool enable_hessians_jacobian
AffineConstraints< MGNumber > constraints
bool enable_hessians_residual
void clear()
Clear the matrix-free object.
void vmult_interface_down(VectorType &dst, VectorType const &src) const
Vmult operator for an interface. Required only if local smoothing multigrid is used and for meshes wi...
void vmult(VectorType &dst, const VectorType &src) const
Perform an operator evaluation dst = A*src by looping with the help of the MatrixFree object over all...
const std::shared_ptr< const Utilities::MPI::Partitioner > & get_vector_partitioner() const
Get the vector partitioner object required for local smoothing multigrid preconditioner.
void do_boundary_face_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all boundary face batches within certain range and perform a face integral with access to g...
BoundaryConditions::FluidDynamicsBoundaryConditions< dim > boundary_conditions
void compute_element_size()
Compute the element size h of the cells required to calculate stabilization parameters.
Table< 2, VectorizedArray< MGNumber > > stabilization_parameter_lsic
Table< 1, VectorizedArray< MGNumber > > effective_beta_face
types::global_dof_index m() const
Get the total number of DoFs.
void compute_solid_cell_mask()
Compute a per-cell-batch mask that suppresses contributions from solid cells (material_id > 0)....
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > face_nonlinear_previous_values
std::shared_ptr< Function< dim > > forcing_function
FEFaceEvaluation< dim, -1, 0, dim+1, MGNumber > FEFaceIntegrator
NavierStokesOperatorBase(const Mapping< dim > &mapping, const DoFHandler< dim > &dof_handler, const AffineConstraints< number > &constraints, const Quadrature< dim > &quadrature, const std::shared_ptr< Function< dim > > &forcing_function, const std::shared_ptr< PhysicalPropertiesManager > &physical_properties_manager, const StabilizationType stabilization, const unsigned int mg_level, const std::shared_ptr< SimulationControl > &simulation_control, const BoundaryConditions::FluidDynamicsBoundaryConditions< dim > &boundary_conditions, const bool &enable_hessians_jacobian, const bool &enable_hessians_residual, const bool &enable_mortar)
Constructor that points to the reinit function.
void evaluate_residual(VectorType &dst, const VectorType &src)
Evaluate right hand side using the matrix-free operator.
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > prescribed_neumann_traction
TimeSteppingData initialize_time_stepping_data() const
Initialize time stepping data such as the time step size and BDF coefficients.
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > previous_shear_rate
AlignedVector< VectorizedArray< MGNumber > > element_size
std::vector< MGNumber > edge_constrained_values
std::shared_ptr< MortarManagerBase< dim > > mortar_manager_mf
Table< 2, Tensor< 1, dim+1, Tensor< 2, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_hessian
AlignedVector< VectorizedArray< MGNumber > > solid_cell_mask
void evaluate_time_derivative_previous_solutions(const VectorType &time_derivative_previous_solutions)
Store the values of the vector containing the time derivatives of previous solutions to use them in t...
void do_internal_face_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all internal face batches within certain range and perform a face integral with access to g...
void do_cell_integral_range(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const
Loop over all cell batches within certain range and perform a cell integral with access to global vec...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > time_derivatives_previous_solutions
FEEvaluation< dim, -1, 0, dim+1, MGNumber > FECellIntegrator
Parameters::Stabilization::NavierStokesStabilization StabilizationType
void compute_inverse_diagonal(VectorType &diagonal) const
Compute the diagonal of the operator using an optimized MatrixFree function. Needed for preconditione...
virtual void do_cell_integral_local(FECellIntegrator &integrator) const =0
Interface to function that performs a cell integral in a cell batch without gathering and scattering ...
VectorizedArray< MGNumber > size_type
std::vector< bool > edge_constrained_cell
static IndexSet get_refinement_edges(const MatrixFree< dim, number > &matrix_free)
Get the refinement edges. Only needed if the local smoothing multigrid approach is used.
virtual void compute_forcing_term()
Precompute forcing term at the quadrature points. This is called when the operator is initialized and...
Table< 2, Tensor< 1, dim+1, VectorizedArray< MGNumber > > > kinematic_viscosity_gradient
StabilizationType stabilization
std::shared_ptr< SimulationControl > simulation_control
NavierStokesOperatorBase()
Default constructor.
const AlignedVector< VectorizedArray< number > > get_element_size() const
Get the element size object.
void initialize_dof_vector(VectorType &vec) const
Initialize a given vector by delegating it to the MatrixFree function in charge of this task.
const MatrixFree< dim, number > & get_system_matrix_free() const
Get the system matrix free object.
Table< 2, Tensor< 1, dim+1, Tensor< 1, dim, VectorizedArray< MGNumber > > > > nonlinear_previous_hessian_diagonal
Tensor< 1, dim, VectorizedArray< MGNumber > > beta_force
Table< 2, VectorizedArray< MGNumber > > grad_kinematic_viscosity_shear_rate
Table< 2, VectorizedArray< MGNumber > > kinematic_viscosity_vector
Table< 2, VectorizedArray< MGNumber > > stabilization_parameter
void Tvmult(VectorType &dst, const VectorType &src) const
Perform the transposed operator evaluation.
void vmult_interface_up(VectorType &dst, VectorType const &src) const
Vmult operator for an interface. Required only if local smoothing multigrid is used and for meshes wi...
DynamicSparsityPattern dsp
LinearAlgebra::distributed::Vector< MGNumber > VectorType
const TrilinosWrappers::SparseMatrix & get_system_matrix() const
Calculate matrix if needed, e.g., by coarse-grid solver when a multigrid algorithm is used.
Table< 2, VectorizedArray< MGNumber > > previous_shear_rate_magnitude
MatrixFree< dim, MGNumber > matrix_free
void local_evaluate_residual(const MatrixFree< dim, number > &matrix_free, VectorType &dst, const VectorType &src, const std::pair< unsigned int, unsigned int > &range) const override
Perform cell integral on a cell batch with gathering and scattering the values, and according to the ...
void do_cell_integral_local(FECellIntegrator &integrator) const override
Perform cell integral on a cell batch without gathering and scattering the values,...
FEFaceEvaluation< dim, -1, 0, dim+1, number > FEFaceIntegrator
LinearAlgebra::distributed::Vector< number > VectorType
NavierStokesStabilizedOperator()
FEEvaluation< dim, -1, 0, dim+1, number > FECellIntegrator
Tensor< 1, dim, VectorizedArray< Number > > evaluate_function_gradient(const Function< dim > &function, const Point< dim, VectorizedArray< Number > > &p_vectorized)
Evaluate the gradient of a function at a batch of points to obtain a tensor of vectorized arrays.
bool boundary_condition_requires_face_assembly(BoundaryConditions::FluidDynamicsBoundaryType boundary_type)
Check if a boundary condition type requires face assembly in the matrix-free operator.
VectorizedArray< Number > evaluate_function(const Function< dim > &function, const Point< dim, VectorizedArray< Number > > &p_vectorized, const unsigned int component=0)
Evaluate the value of a function at a batch of points to obtain a vectorized array of numbers.
FluidDynamicsBoundaryType
Simulation control classes for managing time-stepping and iteration control in Lethe.
NavierStokesStabilization
Data structure to store time-stepping data in the matrix-free operator. This is a very small structur...
bool is_transient
Boolean indicating if the method is transient.
bool is_bdf
Boolean indicating that the method is a BDF method.
const Vector< double > * bdf_coefficients