21#include <deal.II/base/convergence_table.h>
22#include <deal.II/base/table_handler.h>
23#include <deal.II/base/timer.h>
25#include <deal.II/distributed/tria_base.h>
27#include <deal.II/grid/grid_tools.h>
29#include <deal.II/lac/trilinos_precondition.h>
30#include <deal.II/lac/trilinos_sparse_matrix.h>
31#include <deal.II/lac/trilinos_vector.h>
33#include <deal.II/numerics/solution_transfer.h>
39 <<
"The CLS physics is enabled, but the number of fluids is set to " << arg1
40 <<
". The CLS solver only supports 2 fluids.");
43 CLSBoundaryConditionMissing,
45 <<
"The boundary id: " << arg1
46 <<
" is defined in the triangulation, but not as a boundary condition for the CLS physics. Lethe does not assign a default boundary condition to boundary ids. Every boundary id defined within the triangulation must have a corresponding boundary condition defined in the input file.");
49 UnsupportedReinitialization,
50 "The CLS physics has been set to use DG and the latter implementation currently does not support any interface reinitialization mechanism.");
53 UnsupportedReinitializationWithSimplex,
54 "The CLS physics has been set to use simplex and the latter implementation currently does not support the geometric interface reinitialization mechanism.");
57 UnsupportedInitialProjection,
58 "The CLS physics has been set to use DG and the latter implementation currently does not support defining an initial condition with a projection.");
70 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
72 std::shared_ptr<SimulationControl> p_simulation_control);
94 virtual std::vector<OutputStruct<dim, GlobalVectorType>>
114 template <
typename VectorType>
133 template <
typename VectorType>
147 template <
typename VectorType>
148 std::pair<Tensor<1, dim>, Tensor<1, dim>>
180 const bool temperature_dependent);
242 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
244 dealii::Vector<float> &estimated_error_per_cell)
override;
258 compute_kelly(dealii::Vector<float> &estimated_error_per_cell,
259 const ComponentMask &component_mask);
282 std::vector<OutputStructTableHandler>
342 const DoFHandler<dim> &
378 AffineConstraints<double> &
384 const DoFHandler<dim> &
391 const DoFHandler<dim> &
417 this->
pcout <<
"\t ||dphi||_L2 = " << std::setw(6)
434 .rescale_residual_by_volume ?
451 std::vector<types::boundary_id> boundary_ids_in_triangulation =
453 for (
auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
456 boundary_id_in_tria) !=
458 CLSBoundaryConditionMissing(boundary_id_in_tria));
516 const typename DoFHandler<dim>::active_cell_iterator &cell,
535 const typename DoFHandler<dim>::active_cell_iterator &cell,
659 const bool sharpen_previous_solutions);
752 const typename DoFHandler<dim>::active_cell_iterator &velocity_cell,
753 const unsigned int &face_no,
762 this->simulation_parameters.ale);
770 this->simulation_parameters.ale);
787 std::shared_ptr<FiniteElement<dim>>
fe;
819 std::vector<SolutionTransfer<dim, GlobalVectorType>>
862 std::vector<std::shared_ptr<CLSAssemblerBase<dim>>>
assemblers;
868 std::shared_ptr<ConservativeLevelSetFilterBase>
filter;
871 std::shared_ptr<InterfaceTools::SignedDistanceSolver<dim, GlobalVectorType>>
875 std::shared_ptr<SignedDistanceTransformationBase>
AuxiliaryPhysics(const Parameters::NonLinearSolver non_linear_solver_parameters)
Store the information required by the assembly procedure for a CLS free surface equation....
void reinit_face_velocity(const typename DoFHandler< dim >::active_cell_iterator &velocity_cell, const unsigned int &face_no, const VectorType &velocity_solution, const Parameters::ALE< dim > &ale)
Reinitialize the content of the scratch regarding the velocity for internal/boundary faces....
const SimulationParameters< dim > & simulation_parameters
GlobalVectorType system_rhs_phase_indicator
void compute_error_estimate(const std::pair< const Variable, Parameters::MultipleAdaptationParameters > &ivar, dealii::Vector< float > &estimated_error_per_cell) override
Compute the error estimator for mesh refinement.
TableHandler table_monitoring_cls
double find_sharpening_threshold()
Find the sharpening threshold to ensure mass conservation of the fluid monitored, as given in the prm...
TableHandler table_barycenter
GlobalVectorType nodal_phase_indicator_owned
std::shared_ptr< GlobalVectorType > filtered_solution
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
void percolate_time_vectors() override
Carry out the operations required to rearrange the values of the previous solution at the end of a ti...
void assemble_mass_matrix(TrilinosWrappers::SparseMatrix &mass_matrix)
Assembles a mass_matrix which is used in update_solution_and_constraints function to limit the phase ...
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
ConvergenceTable error_table
void compute_level_set_from_phase_indicator(const GlobalVectorType &solution, GlobalVectorType &level_set_solution)
Compute level-set field from the phase indicator field using an inverse tanh-based transformation.
void assemble_projection_phase_indicator(GlobalVectorType &solution)
Assembles the matrix and rhs for calculation of a smooth phase indicator using a projection.
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
void setup_amg()
Set up the AMG preconditioner stored in amg_preconditioner.
const double phase_lower_bound
double sharpening_threshold
void assemble_system_matrix_dg()
Assemble the matrix associated with the solver when DG elements are used.
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, CLSScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local rhs for a given cell.
std::shared_ptr< SimulationControl > simulation_control
GlobalVectorType & get_evaluation_point() override
Getter methods that give access to the private attributes of the physics being solved....
TrilinosWrappers::SparseMatrix system_matrix
GlobalVectorType newton_update
void solve_interface_sharpening(GlobalVectorType &solution)
Solves the assembled system to sharpen the interface. The linear_solver_tolerance is hardcoded = 1e-1...
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsCopyData ©_data)
Copy local cell rhs information to global rhs.
ConservativeLevelSet(MultiphysicsInterface< dim > *multiphysics_interface, const SimulationParameters< dim > &p_simulation_parameters, const std::shared_ptr< parallel::DistributedTriangulationBase< dim > > &p_triangulation, std::shared_ptr< SimulationControl > p_simulation_control)
CLS - Base constructor.
void modify_solution() override
Carry out modifications on the auxiliary physic solution.
void solve_projection_phase_indicator(GlobalVectorType &solution)
Solves smooth phase indicator system.
std::shared_ptr< CLSSubequationsInterface< dim > > cls_subequations_interface
void update_boundary_conditions() override
Update non zero constraints if the boundary is time dependent.
void smooth_phase_indicator(GlobalVectorType &solution)
Carries out the smoothing phase indicator with a projection step (to avoid a staircase interface).
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
void update_solution_and_constraints(GlobalVectorType &solution)
Limit the phase indicators between 0 and 1. This is necessary before interface sharpening....
void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
GlobalVectorType & get_system_rhs() override
void pre_mesh_adaptation() override
pre_mesh_adaption Prepares the auxiliary physics variables for a mesh refinement/coarsening
void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
std::shared_ptr< CLSAssemblerSIPG< dim > > inner_face_assembler
void assemble_system_rhs_cg()
Assemble the rhs associated with the solver when CG elements are used.
std::shared_ptr< DoFHandler< dim > > dof_handler
MultiphysicsInterface< dim > * multiphysics
TrilinosWrappers::SparseMatrix system_matrix_phase_indicator
std::vector< std::shared_ptr< CLSAssemblerBase< dim > > > assemblers
void compute_kelly(dealii::Vector< float > &estimated_error_per_cell, const ComponentMask &component_mask)
Compute the Kelly error estimator on the phase variable for mesh refinement. See : https://www....
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsCopyData ©_data)
Copy local cell information to global matrix.
GlobalVectorType local_evaluation_point
void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
void define_zero_constraints()
defined the zero constraints used to solve the problem.
double calculate_L2_error()
Calculates the L2 error of the solution.
std::shared_ptr< ConservativeLevelSetFilterBase > filter
void setup_ilu()
Set up the ILU preconditioner stored in ilu_preconditioner.
double compute_capillary_time_step_constraint(const bool pressure_dependent, const bool temperature_dependent)
Computes the capillary time-step constraint.
void write_checkpoint() override
Prepares auxiliary physics to write checkpoint.
const double phase_upper_bound
~ConservativeLevelSet()=default
CLS - Base destructor. At the present moment this is an interface with nothing.
void sharpen_interface(GlobalVectorType &solution, const double sharpening_threshold, const bool sharpen_previous_solutions)
Carries out interface sharpening. It is called in the modify solution function.
GlobalVectorType complete_system_rhs_phase_indicator
GlobalVectorType level_set
std::shared_ptr< FiniteElement< dim > > fe
void assemble_system_matrix_cg()
Assemble the matrix associated with the solver when CG elements are used.
AffineConstraints< double > zero_constraints
void compute_phase_indicator_from_level_set(const GlobalVectorType &level_set_solution, GlobalVectorType &phase_indicator_solution)
Compute the phase indicator field from level-set field using a tanh-based transformation.
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
AffineConstraints< double > nonzero_constraints
std::shared_ptr< SignedDistanceTransformationBase > signed_distance_transformation
GlobalVectorType system_rhs
const GlobalVectorType & get_curvature_solution()
AffineConstraints< double > & get_nonzero_constraints() override
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, CLSScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local matrix for a given cell.
void set_initial_conditions() override
Sets-up the initial conditions associated with the physics. Generally, physics only support imposing ...
TrilinosWrappers::SparseMatrix mass_matrix_phase_indicator
GlobalVectorType & get_present_solution() override
void solve_linear_system() override
Call for the solution of the linear system of equation using a strategy appropriate to the auxiliary ...
void reinitialize_interface_with_geometric_method()
Reinitialize the interface between fluids using the geometric approach.
const DoFHandler< dim > & get_dof_handler() override
Getter methods to get the private attributes for the physic currently solved NB : dof_handler and pre...
double calculate_mass_deviation(const Parameters::FluidIndicator monitored_fluid, const double sharpening_threshold)
Calculate the mass deviation of the monitored fluid, between the current iteration and the mass at fi...
const DoFHandler< dim > & get_projected_phase_indicator_gradient_dof_handler()
TrilinosWrappers::SparseMatrix complete_system_matrix_phase_indicator
TimerOutput computing_timer
IndexSet locally_owned_dofs
void define_non_zero_constraints()
defined the non zero constraints used to solve the problem.
void calculate_volume_and_mass(const GlobalVectorType &solution, const VectorType ¤t_solution_fd, const Parameters::FluidIndicator monitored_fluid)
Calculates the volume and mass for a given fluid phase. Used for conservation monitoring.
void assemble_system_matrix() override
Assembles the matrix associated with the solver.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
virtual void setup_assemblers()
sets up the vector of assembler functions
Tensor< 1, dim > calculate_momentum(const GlobalVectorType &solution, const VectorType ¤t_solution_fd, const Parameters::FluidIndicator monitored_fluid)
Calculates the momentum for a given fluid phase. Used for conservation monitoring.
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
void output_per_iteration_timer() override
Output the per iteration wallclock times.
std::shared_ptr< InterfaceTools::SignedDistanceSolver< dim, GlobalVectorType > > signed_distance_solver
void post_mesh_adaptation() override
post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
void handle_interface_sharpening()
Carries out interface sharpening. It is called in the modify solution function. Launches sharpen_inte...
void apply_phase_filter(const GlobalVectorType &original_solution, GlobalVectorType &filtered_solution)
Apply filter on phase indicator values.
GlobalVectorType evaluation_point
void setup_dofs() override
Sets-up the DofHandler and the degree of freedom associated with the physics.
void read_checkpoint() override
Set solution vector of Auxiliary Physics using checkpoint.
void assemble_rhs()
Call for the assembly of the right-hand side.
std::pair< Tensor< 1, dim >, Tensor< 1, dim > > calculate_barycenter(const GlobalVectorType &solution, const VectorType ¤t_solution_fd)
Calculates the barycenter of the fluid and its velocity.
GlobalVectorType & get_newton_update() override
void assemble_L2_projection_interface_sharpening(GlobalVectorType &solution, const double sharpening_threshold)
Assemble the system for interface sharpening.
virtual std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
std::shared_ptr< Mapping< dim > > mapping
const GlobalVectorType & get_projected_phase_indicator_gradient_solution()
IndexSet locally_relevant_dofs
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
double mass_first_iteration
void reinitialize_interface_with_pde_based_method()
Reinitialize the interface between fluids using the PDE-based approach.
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
AMG preconditioner used by the iterative linear solver of the main conservative level set system.
std::vector< TableHandler > phase_indicator_isocontour_bounding_values_tables
Vector of tables containing evolution of phase indicator isocontour bounding values.
std::shared_ptr< GlobalVectorType > present_solution
AffineConstraints< double > bounding_constraints
void reinit_face_velocity_with_adequate_solution(const typename DoFHandler< dim >::active_cell_iterator &velocity_cell, const unsigned int &face_no, CLSScratchData< dim > &scratch_data)
Helper function to reinit the face velocity with the adequate solution. This prevents code duplicatio...
void assemble_system_rhs_dg()
Assemble the rhs associated with the solver when DG elements are used.
const DoFHandler< dim > & get_curvature_dof_handler()
GlobalVectorType & get_local_evaluation_point() override
std::shared_ptr< Quadrature< dim > > cell_quadrature
Class responsible for storing the information calculated using the assembly of stabilized scalar equa...
DeclExceptionMsg(UnsupportedReinitialization, "The CLS physics has been set to use DG and the latter implementation currently does not support any interface reinitialization mechanism.")
DeclException1(InvalidNumberOfFluid, int,<< "The CLS physics is enabled, but the number of fluids is set to "<< arg1<< ". The CLS solver only supports 2 fluids.")
@ curvature_projection
CLS curvature L2 projection.
@ phase_gradient_projection
CLS phase indicator gradient L2 projection.
@ fluid_dynamics
Fluid Dynamics (Velocity,Pressure).
FluidIndicator
Class to account for different fluid indicators. This is used for multiphase simulations in PostProce...
Simulation control classes for managing time-stepping and iteration control in Lethe.
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType