Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cls_curvature_projection.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-2024, 2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5
6template <int dim>
7void
9{
10 // Reinitialize system matrix and right-hand side (rhs)
11 this->system_matrix = 0;
12 this->system_rhs = 0;
13
14 // Get phase gradient L2 projection DoFHandler
15 const DoFHandler<dim> &dof_handler_phase_indicator_gradient =
16 this->subequations_interface.get_dof_handler(
18
19 // Initialize FEValues for curvature and phase indicator gradient projection
20 FEValues<dim> fe_values_curvature_projection(*this->mapping,
21 *this->fe,
22 *this->cell_quadrature,
23 update_values |
24 update_gradients |
25 update_JxW_values);
26 FEValues<dim> fe_values_phase_gradient_projection(
27 *this->mapping,
28 dof_handler_phase_indicator_gradient.get_fe(),
29 *this->cell_quadrature,
30 update_values);
31
32 // Initialize size of arrays
33 const unsigned int n_q_points =
34 fe_values_curvature_projection.get_quadrature().size();
35 const unsigned int n_dofs_per_cell =
36 fe_values_curvature_projection.get_fe().n_dofs_per_cell();
37
38 // Initialize local matrix and rhs
39 FullMatrix<double> local_matrix(n_dofs_per_cell, n_dofs_per_cell);
40 Vector<double> local_rhs(n_dofs_per_cell);
41
42 // Initialize the local dof indices array
43 std::vector<types::global_dof_index> local_dof_indices(n_dofs_per_cell);
44
45 // Extractor for phase indicator gradient vector
46 FEValuesExtractors::Vector phase_indicator_gradients(0);
47
48 // Initialize projected phase indicator gradient solution array
49 std::vector<Tensor<1, dim>> present_phase_gradient_projection_values(
50 n_q_points);
51
52 // Initialize shape function arrays
53 std::vector<double> phi(n_dofs_per_cell);
54 std::vector<Tensor<1, dim>> grad_phi(n_dofs_per_cell);
55
56 // Get the diffusion factor
57 const double diffusion_factor =
58 this->simulation_parameters.multiphysics.cls_parameters
59 .surface_tension_force.curvature_diffusion_factor;
60
61 // Get present phase gradient projection solution
62 auto &present_phase_gradient_projection_solution =
63 this->subequations_interface.get_solution(
65
66 // Loop over phase gradient projection cells
67 for (const auto &cell : this->dof_handler->active_cell_iterators())
68 {
69 if (cell->is_locally_owned())
70 {
71 // Reinitialize local linear system
72 local_matrix = 0;
73 local_rhs = 0;
74
75 // Get phase gradient projection cell iterator
76 typename DoFHandler<dim>::active_cell_iterator
77 phase_gradient_projection_cell(
78 &(*this->triangulation),
79 cell->level(),
80 cell->index(),
81 &dof_handler_phase_indicator_gradient);
82
83 // Reinitialize FEValues with corresponding cells
84 fe_values_curvature_projection.reinit(cell);
85 fe_values_phase_gradient_projection.reinit(
86 phase_gradient_projection_cell);
87
88 // Get vector of Jacobi determinant times the quadrature weights
89 std::vector<double> JxW_vec =
90 fe_values_curvature_projection.get_JxW_values();
91
92 // Compute cell size
93 auto &fe_curvature_projection =
94 fe_values_curvature_projection.get_fe();
95 const double h =
97 fe_curvature_projection.degree);
98
99 // Get projected indicator gradient values
100 fe_values_phase_gradient_projection[phase_indicator_gradients]
101 .get_function_values(present_phase_gradient_projection_solution,
102 present_phase_gradient_projection_values);
103
104 // Set tolerance to avoid division by zero
105 const double tolerance = 1e-12;
106
107 // Loop over quadrature points
108 for (unsigned int q = 0; q < n_q_points; ++q)
109 {
110 // Shape functions
111 for (unsigned int k = 0; k < n_dofs_per_cell; ++k)
112 {
113 phi[k] = fe_values_curvature_projection.shape_value(k, q);
114 grad_phi[k] = fe_values_curvature_projection.shape_grad(k, q);
115 }
116
117 // Compute projected phase gradient norm
118 const Tensor<1, dim> projected_cls_phase_gradient =
119 present_phase_gradient_projection_values[q];
120 const double projected_cls_phase_gradient_norm =
121 projected_cls_phase_gradient.norm() + tolerance;
122
123 // Local linear system assembly
124 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
125 {
126 // Assemble local matrix
127 for (unsigned int j = 0; j < n_dofs_per_cell; ++j)
128 {
129 local_matrix(i, j) +=
130 (phi[i] * phi[j] +
131 h * h * diffusion_factor *
132 scalar_product(grad_phi[i], grad_phi[j])) *
133 JxW_vec[q];
134 }
135 // Assemble local right-hand side (rhs)
136 local_rhs(i) += grad_phi[i] *
137 (projected_cls_phase_gradient /
138 projected_cls_phase_gradient_norm) *
139 JxW_vec[q];
140 }
141 }
142
143 // Distribute the local contributions to the global system
144 cell->get_dof_indices(local_dof_indices);
145 this->constraints.distribute_local_to_global(local_matrix,
146 local_rhs,
147 local_dof_indices,
148 this->system_matrix,
149 this->system_rhs);
150 }
151 }
152 this->system_matrix.compress(VectorOperation::add);
153 this->system_rhs.compress(VectorOperation::add);
154}
155
156template <int dim>
157void
159{
160 AssertThrow(this->subequations_interface.get_solution_validity(
162 PhaseGradientProjectionIsInvalid(
163 this->subequations_interface.get_subequation_string(
165 this->subequations_interface.get_subequation_string(
166 this->subequation_id)));
167}
168
169template class CLSCurvatureProjection<2>;
170template class CLSCurvatureProjection<3>;
CLS curvature L2 projection solver.
void assemble_system_matrix_and_rhs() override
Assemble system matrix and right-hand side (rhs).
void check_dependencies_validity() override
Check if the phase gradient L2 projection has been solved.
std::shared_ptr< FiniteElement< dim > > fe
std::shared_ptr< parallel::DistributedTriangulationBase< dim > > triangulation
std::shared_ptr< Quadrature< dim > > cell_quadrature
std::shared_ptr< Mapping< dim > > mapping
std::shared_ptr< DoFHandler< dim > > dof_handler
CLSSubequationsInterface< dim > & subequations_interface
const SimulationParameters< dim > & simulation_parameters
TrilinosWrappers::SparseMatrix system_matrix
@ phase_gradient_projection
CLS phase indicator gradient L2 projection.
double compute_cell_measure_with_JxW(const std::vector< double > &JxW_values)
Computes the area (2D) or volume (3D) of the cell by integrating 1 over the cell, by summing JxW valu...
Definition utilities.h:1017
double compute_cell_diameter(const double cell_measure, const unsigned int fe_degree)
Computes equivalent cell diameter by comparing the area to a disk (2D) or the volume to a sphere (3D)...
Definition utilities.h:989