16#ifndef lethe_cahn_hilliard_h
17#define lethe_cahn_hilliard_h
29#include <deal.II/base/convergence_table.h>
30#include <deal.II/base/quadrature_lib.h>
31#include <deal.II/base/timer.h>
33#include <deal.II/distributed/tria_base.h>
35#include <deal.II/fe/fe_q.h>
36#include <deal.II/fe/fe_simplex_p.h>
37#include <deal.II/fe/mapping_fe.h>
38#include <deal.II/fe/mapping_q.h>
40#include <deal.II/grid/grid_tools.h>
42#include <deal.II/lac/trilinos_precondition.h>
43#include <deal.II/lac/trilinos_sparse_matrix.h>
44#include <deal.II/lac/trilinos_vector.h>
46#include <deal.II/numerics/solution_transfer.h>
51 CahnHilliardBoundaryConditionMissing,
53 <<
"The boundary id: " << arg1
54 <<
" is defined in the triangulation, but not as a boundary condition for the Cahn Hilliard 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.");
65 const std::shared_ptr<parallel::DistributedTriangulationBase<dim>>
67 std::shared_ptr<SimulationControl> p_simulation_control)
75 TimerOutput::wall_times)
87 fe = std::make_shared<FESystem<dim>>(
92 .potential_cahn_hilliard_degree),
94 mapping = std::make_shared<MappingFE<dim>>(*fe);
99 .potential_cahn_hilliard_degree) +
105 .potential_cahn_hilliard_degree) +
112 fe = std::make_shared<FESystem<dim>>(
117 .potential_cahn_hilliard_degree),
119 mapping = std::make_shared<MappingQ<dim>>(std::max(
126 .potential_cahn_hilliard_degree) +
132 .potential_cahn_hilliard_degree) +
138 std::make_shared<SolutionTransfer<dim, GlobalVectorType>>(*dof_handler);
150 SolutionTransfer<dim, GlobalVectorType>(*this->dof_handler));
163 std::vector<OutputStruct<dim, GlobalVectorType>>
169 std::pair<double, double>
230 const std::pair<const Variable, Parameters::MultipleAdaptationParameters>
232 dealii::Vector<float> &estimated_error_per_cell)
override;
246 compute_kelly(dealii::Vector<float> &estimated_error_per_cell,
247 const ComponentMask &component_mask);
268 std::vector<OutputStructTableHandler>
274 const DoFHandler<dim> &
350 AffineConstraints<double> &
373 .rescale_residual_by_volume ?
391 std::vector<types::boundary_id> boundary_ids_in_triangulation =
393 for (
auto const &boundary_id_in_tria : boundary_ids_in_triangulation)
397 boundary_id_in_tria) !=
399 CahnHilliardBoundaryConditionMissing(boundary_id_in_tria));
434 const typename DoFHandler<dim>::active_cell_iterator &cell,
453 const typename DoFHandler<dim>::active_cell_iterator &cell,
512 template <
typename VectorType>
513 std::pair<Tensor<1, dim>, Tensor<1, dim>>
537 std::shared_ptr<FESystem<dim>>
fe;
577 std::vector<SolutionTransfer<dim, GlobalVectorType>>
581 std::vector<std::shared_ptr<CahnHilliardAssemblerBase<dim>>>
assemblers;
593 std::shared_ptr<CahnHilliardFilterBase>
filter;
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
DeclException1(CahnHilliardBoundaryConditionMissing, types::boundary_id,<< "The boundary id: "<< arg1<< " is defined in the triangulation, but not as a boundary condition for the Cahn Hilliard 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.")
AuxiliaryPhysics(const Parameters::NonLinearSolver non_linear_solver_parameters)
Class that stores the information required by the assembly procedure for the Cahn-Hilliard equations....
void apply_phase_filter()
Applies filter on phase fraction values.
std::vector< OutputStructTableHandler > gather_tables() override
Returns a vector of references to TableHandler objects that needs to be serialized/deserialized for t...
virtual void setup_assemblers()
sets up the vector of assembler functions
std::shared_ptr< TrilinosWrappers::PreconditionAMG > amg_preconditioner
AMG preconditioner used by the iterative linear solver.
void verify_consistency_of_boundary_conditions()
Verify consistency of the input parameters for boundary conditions to ensure that for every boundary ...
std::shared_ptr< DoFHandler< dim > > dof_handler
std::shared_ptr< TrilinosWrappers::PreconditionILU > ilu_preconditioner
ILU preconditioner used by the iterative linear solver.
TrilinosWrappers::SparseMatrix system_matrix
TableHandler barycenter_table
GlobalVectorType newton_update
void solve_linear_system() override
Call for the solution of the linear system of equation using a strategy appropriate to the auxiliary ...
TimerOutput computing_timer
std::shared_ptr< Quadrature< dim - 1 > > face_quadrature
std::shared_ptr< std::vector< GlobalVectorType > > previous_solutions
void finish_simulation() override
Carry out the operations required to finish a simulation correctly.
virtual void copy_local_matrix_to_global_matrix(const StabilizedMethodsCopyData ©_data)
Copy local cell information to global matrix.
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....
IndexSet locally_relevant_dofs
std::vector< std::shared_ptr< CahnHilliardAssemblerBase< dim > > > assemblers
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
void setup_amg()
Set up the AMG preconditioner stored in amg_preconditioner.
const DoFHandler< dim > & get_dof_handler() override
Returns the dof_handler of the Cahn-Hilliard physics.
IndexSet locally_owned_dofs
std::shared_ptr< GlobalVectorType > filtered_solution
std::shared_ptr< FESystem< dim > > fe
void setup_dofs() override
Sets-up the DofHandler and the degree of freedom associated with the physics.
void assemble_system_matrix() override
Assembles the matrix associated with the solver.
void modify_solution() override
Carry out modifications on the auxiliary physic solution.
void setup_ilu()
Set up the ILU preconditioner stored in ilu_preconditioner.
std::shared_ptr< SimulationControl > simulation_control
GlobalVectorType system_rhs
void write_phase_statistics()
Writes the phase statistics to an output file.
GlobalVectorType & get_newton_update() override
virtual void copy_local_rhs_to_global_rhs(const StabilizedMethodsCopyData ©_data)
Copy local cell rhs information to global rhs.
GlobalVectorType & get_evaluation_point() override
Getter methods to get the private attributes for the physic currently solved NB : dof_handler and pre...
TableHandler phase_energy_table
MultiphysicsInterface< dim > * multiphysics
GlobalVectorType & get_local_evaluation_point() override
GlobalVectorType local_evaluation_point
GlobalVectorType evaluation_point
std::pair< Tensor< 1, dim >, Tensor< 1, dim > > calculate_barycenter(const GlobalVectorType &solution, const VectorType ¤t_solution_fd)
Calculates the barycenter of fluid 1 and its velocity.
std::shared_ptr< CahnHilliardFilterBase > filter
AffineConstraints< double > nonzero_constraints
void post_mesh_adaptation() override
post_mesh_adaption Interpolates the auxiliary physics variables to the new mesh
std::shared_ptr< SolutionTransfer< dim, GlobalVectorType > > solution_transfer
void read_checkpoint() override
Allows Cahn-Hilliard physics to set-up solution vector from checkpoint file;.
void write_checkpoint() override
Prepares Cahn-Hilliard to write checkpoint.
void assemble_system_rhs() override
Assemble the rhs associated with the solver.
std::vector< SolutionTransfer< dim, GlobalVectorType > > previous_solutions_transfer
std::shared_ptr< Quadrature< dim > > cell_quadrature
std::shared_ptr< Mapping< dim > > mapping
AffineConstraints< double > zero_constraints
void write_phase_energy()
virtual void assemble_local_system_rhs(const typename DoFHandler< dim >::active_cell_iterator &cell, CahnHilliardScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local rhs for a given cell.
void percolate_time_vectors() override
Rearrange vector solution correctly for transient simulations.
void calculate_phase_statistics()
Calculate phase statistics for monitoring purposes.
ConvergenceTable error_table
double get_residual_rescale_metric() const override
Return the metric for residual rescaling. By default, should return 1. If the rescale_residual_by_vol...
CahnHilliard(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)
std::shared_ptr< GlobalVectorType > present_solution
GlobalVectorType & get_present_solution() override
void set_initial_conditions() override
Sets-up the initial conditions associated with the physics. Generally, physics only support imposing ...
const SimulationParameters< dim > & simulation_parameters
AffineConstraints< double > & get_nonzero_constraints() override
void postprocess(bool first_iteration) override
Postprocess the auxiliary physics results. Post-processing this case implies the calculation of all d...
void calculate_phase_energy()
Calculate the phase energies : bulk energy, interface energy and total energy.
GlobalVectorType & get_system_rhs() override
void output_per_iteration_timer() override
Output the per iteration wallclock times.
TableHandler statistics_table
virtual void assemble_local_system_matrix(const typename DoFHandler< dim >::active_cell_iterator &cell, CahnHilliardScratchData< dim > &scratch_data, StabilizedMethodsCopyData ©_data)
Assemble the local matrix for a given cell.
std::pair< double, double > calculate_L2_error()
Calculates the L2 error of the solution.
void update_boundary_conditions() override
Update non zero constraints if the boundary is time-dependent.
void pre_mesh_adaptation() override
pre_mesh_adaption Prepares the auxiliary physics variables for a mesh refinement/coarsening
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.
std::vector< OutputStruct< dim, GlobalVectorType > > gather_output_hook() override
Gather and return vector of output structs that are particular to some applications.
void output_newton_update_norms() override
Output the L2 and Linfty norms of the correction vector.
PhysicsSolverStrategy< GlobalVectorType > * physics_solving_strategy
Class responsible for storing the information calculated using the assembly of stabilized scalar equa...
PhysicsID
Unique identifiers for each physics module in Lethe.
@ cahn_hilliard
Cahn-Hilliard (Phase indicator, Potential).
Simulation control classes for managing time-stepping and iteration control in Lethe.
GlobalVectorType VectorType
dealii::TrilinosWrappers::MPI::Vector GlobalVectorType