Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cls_phase_gradient_projection.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2020-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 CLS DoFHandler
15 const DoFHandler<dim> &dof_handler_cls =
16 this->subequations_interface.get_cls_dof_handler();
17
18 // Initialize FEValues for phase indicator gradient projection and CLS
19 FEValues<dim> fe_values_phase_gradient_projection(*this->mapping,
20 *this->fe,
21 *this->cell_quadrature,
22 update_values |
23 update_gradients |
24 update_JxW_values);
25 FEValues<dim> fe_values_cls(*this->mapping,
26 dof_handler_cls.get_fe(),
27 *this->cell_quadrature,
28 update_gradients);
29
30 // Initialize size of arrays
31 const unsigned int n_q_points =
32 fe_values_phase_gradient_projection.get_quadrature().size();
33 const unsigned int n_dofs_per_cell =
34 fe_values_phase_gradient_projection.get_fe().n_dofs_per_cell();
35
36 // Initialize local matrix and rhs
37 FullMatrix<double> local_matrix(n_dofs_per_cell, n_dofs_per_cell);
38 Vector<double> local_rhs(n_dofs_per_cell);
39
40 // Initialize local dof indices array
41 std::vector<types::global_dof_index> local_dof_indices(n_dofs_per_cell);
42
43 // Extractor for phase indicator gradient vector
44 FEValuesExtractors::Vector phase_indicator_gradients(0);
45
46 // Initialize phase indicator gradient solution array
47 std::vector<Tensor<1, dim>> present_cls_phase_gradients(n_q_points);
48
49 // Initialize shape function arrays
50 std::vector<Tensor<1, dim>> phi(n_dofs_per_cell);
51 std::vector<Tensor<2, dim>> grad_phi(n_dofs_per_cell);
52
53 // Get the diffusion factor
54 const double diffusion_factor =
55 this->simulation_parameters.multiphysics.cls_parameters
56 .surface_tension_force.phase_indicator_gradient_diffusion_factor;
57
58 // Get present cls solution
59 auto &present_cls_solution = this->subequations_interface.get_cls_solution();
60
61 // Loop over phase gradient projection cells
62 for (const auto &cell : this->dof_handler->active_cell_iterators())
63 {
64 if (cell->is_locally_owned())
65 {
66 // Reinitialize local linear system
67 local_matrix = 0;
68 local_rhs = 0;
69
70 // Get CLS cell iterator
71 typename DoFHandler<dim>::active_cell_iterator cls_cell(
72 &(*this->triangulation),
73 cell->level(),
74 cell->index(),
75 &dof_handler_cls);
76
77 // Reinitialize FEValues with corresponding cells
78 fe_values_phase_gradient_projection.reinit(cell);
79 fe_values_cls.reinit(cls_cell);
80
81 // Get vector of Jacobi determinant times the quadrature weights
82 std::vector<double> JxW_vec =
83 fe_values_phase_gradient_projection.get_JxW_values();
84
85 // Compute cell size
86 auto &fe_phase_gradient_projection =
87 fe_values_phase_gradient_projection.get_fe();
88 const double h =
90 fe_phase_gradient_projection.degree);
91
92 // Get CLS phase indicator gradients
93 fe_values_cls.get_function_gradients(present_cls_solution,
94 present_cls_phase_gradients);
95
96 // Loop over quadrature points
97 for (unsigned int q = 0; q < n_q_points; ++q)
98 {
99 // Shape functions
100 for (unsigned int k = 0; k < n_dofs_per_cell; ++k)
101 {
102 phi[k] = fe_values_phase_gradient_projection
103 [phase_indicator_gradients]
104 .value(k, q);
105 grad_phi[k] = fe_values_phase_gradient_projection
106 [phase_indicator_gradients]
107 .gradient(k, q);
108 }
109
110 // Local linear system assembly
111 for (unsigned int i = 0; i < n_dofs_per_cell; ++i)
112 {
113 // Assemble local matrix
114 for (unsigned int j = 0; j < n_dofs_per_cell; ++j)
115 {
116 local_matrix(i, j) +=
117 (phi[i] * phi[j] +
118 h * h * diffusion_factor *
119 scalar_product(grad_phi[i], grad_phi[j])) *
120 JxW_vec[q];
121 }
122 // Assemble local right-hand side (rhs)
123 local_rhs(i) +=
124 phi[i] * present_cls_phase_gradients[q] * JxW_vec[q];
125 }
126 }
127
128 // Distribute the local contributions to the global system
129 cell->get_dof_indices(local_dof_indices);
130 this->constraints.distribute_local_to_global(local_matrix,
131 local_rhs,
132 local_dof_indices,
133 this->system_matrix,
134 this->system_rhs);
135 }
136 }
137 this->system_matrix.compress(VectorOperation::add);
138 this->system_rhs.compress(VectorOperation::add);
139}
140
141template <int dim>
142void
144{
145 AssertThrow(this->subequations_interface.get_cls_solution().size() > 0,
146 NoCLSSolution(this->subequations_interface.get_subequation_string(
147 this->subequation_id)));
148 AssertThrow(this->subequations_interface.validity_map_has_been_reset(),
149 SameCLSSolution(
150 this->subequations_interface.get_subequation_string(
151 this->subequation_id)));
152}
153
154
155template class CLSPhaseGradientProjection<2>;
156template class CLSPhaseGradientProjection<3>;
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
CLS phase indicator gradient L2 projection solver.
void check_dependencies_validity() override
Check if a new CLS solution has been set.
void assemble_system_matrix_and_rhs() override
Assemble system matrix and right-hand side (rhs).
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