Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cahn_hilliard_scratch_data.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2023-2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
4#include <core/bdf.h>
5
7template <int dim>
8void
10{
11 // Initialize size of arrays
12 this->n_q_points = fe_values_cahn_hilliard.get_quadrature().size();
13 this->n_dofs = fe_values_cahn_hilliard.get_fe().n_dofs_per_cell();
14
15 // Initialize arrays related to quadrature
16 this->JxW.reinit(n_q_points);
17
18 // Forcing term array
19 this->source_phase_order = std::vector<double>(n_q_points);
20 this->source_chemical_potential = std::vector<double>(n_q_points);
21
22 // Initialize arrays related to phase order and chemical potential
23 this->phase_order.component = 0;
24 this->chemical_potential.component = 1;
25
26 // Variables for the Cahn-Hilliard equations
27 this->phase_order_values = std::vector<double>(n_q_points);
28 this->phase_order_gradients = std::vector<Tensor<1, dim>>(n_q_points);
29 this->phase_order_laplacians = std::vector<double>(n_q_points);
30 this->chemical_potential_values = std::vector<double>(n_q_points);
31 this->chemical_potential_gradients = std::vector<Tensor<1, dim>>(n_q_points);
32 this->chemical_potential_laplacians = std::vector<double>(n_q_points);
33
34 // Phase order for BDF schemes
36 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
37 std::vector<double>(n_q_points));
38
40 std::vector<std::vector<double>>(maximum_number_of_previous_solutions(),
41 std::vector<double>(n_q_points));
42
43 // Initialize arrays related to shape functions
44 // Phase-order shape functions
45 this->phi_phase.reinit(n_q_points, n_dofs);
46 this->grad_phi_phase.reinit(n_q_points, n_dofs);
47 this->hess_phi_phase.reinit(n_q_points, n_dofs);
49
50 // Chemical potential shape functions
51 this->phi_potential.reinit(n_q_points, n_dofs);
55
56 // Velocity values
57 this->velocity_values = std::vector<Tensor<1, dim>>(this->n_q_points);
58 this->previous_velocity_values = std::vector<std::vector<Tensor<1, dim>>>(
60 std::vector<Tensor<1, dim>>(this->n_q_points));
62 std::vector<Tensor<2, dim>>(this->n_q_points);
63
64 // Allocate physical properties
65 this->surface_tension = std::vector<double>(n_q_points);
66 this->mobility_cahn_hilliard = std::vector<double>(n_q_points);
67 this->mobility_cahn_hilliard_gradient = std::vector<double>(n_q_points);
68
69 // Physical properties
70 fields.insert(
71 std::pair<field, std::vector<double>>(field::phase_order_cahn_hilliard,
72 n_q_points));
73 fields.insert(std::pair<field, std::vector<double>>(
75}
76
77template <int dim>
78void
80{
81 switch (properties_manager.get_number_of_fluids())
82 {
83 case 1:
84 {
85 throw std::runtime_error("Unsupported number of fluids (<2)");
86 }
87 case 2:
88 {
91 this->fields);
92
93 // Gather properties from material interactions
94 const auto material_interaction_id =
95 properties_manager.get_material_interaction_id(
97
98 // Gather surface tension
99 const auto surface_tension_model =
100 properties_manager.get_surface_tension(material_interaction_id);
101 surface_tension_model->vector_value(fields, surface_tension);
102
103 // Gather mobility
104 const auto mobility_cahn_hilliard_model =
105 properties_manager.get_mobility_cahn_hilliard(
106 material_interaction_id);
107 mobility_cahn_hilliard_model->vector_value(fields,
109 mobility_cahn_hilliard_model->vector_jacobian(
110 fields,
113
114 break;
115 }
116 default:
117 throw std::runtime_error("Unsupported number of fluids (>2)");
118 }
119}
120
121template class CahnHilliardScratchData<2>;
122template class CahnHilliardScratchData<3>;
unsigned int maximum_number_of_previous_solutions()
Get the maximum number of previous time steps supposed by the BDF schemes implemented in Lethe.
Definition bdf.h:84
Class that stores the information required by the assembly procedure for the Cahn-Hilliard equations....
std::map< field, std::vector< double > > fields
std::vector< double > source_chemical_potential
PhysicalPropertiesManager properties_manager
std::vector< double > surface_tension
std::vector< double > phase_order_laplacians
Table< 2, Tensor< 2, dim > > hess_phi_potential
std::vector< double > mobility_cahn_hilliard_gradient
std::vector< double > chemical_potential_laplacians
std::vector< double > source_phase_order
std::vector< std::vector< Tensor< 1, dim > > > previous_velocity_values
Table< 2, Tensor< 2, dim > > hess_phi_phase
std::vector< double > mobility_cahn_hilliard
FEValuesExtractors::Scalar phase_order
std::vector< Tensor< 2, dim > > velocity_gradient_values
std::vector< Tensor< 1, dim > > chemical_potential_gradients
std::vector< Tensor< 1, dim > > velocity_values
Table< 2, Tensor< 1, dim > > grad_phi_phase
std::vector< double > chemical_potential_values
void allocate() override
Allocates the necessary memory for all members of the scratch.
FEValuesExtractors::Scalar chemical_potential
std::vector< std::vector< double > > previous_chemical_potential_values
void calculate_physical_properties()
Calculates the physical properties that may be required by the Cahn-Hilliard problem....
Table< 2, Tensor< 1, dim > > grad_phi_potential
std::vector< Tensor< 1, dim > > phase_order_gradients
std::vector< double > phase_order_values
std::vector< std::vector< double > > previous_phase_order_values
@ phase_order_cahn_hilliard_filtered
void set_field_vector(const field &id, const std::vector< double > &data, std::map< field, std::vector< double > > &fields)