Lethe Open-Source Library version 1.2.0
Developer Guide
Loading...
Searching...
No Matches
cahn_hilliard_boundary_conditions.cc
Go to the documentation of this file.
1// SPDX-FileCopyrightText: Copyright (c) 2026 The Lethe Authors
2// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception OR LGPL-2.1-or-later
3
5#include <core/utilities.h>
6
7#include <deal.II/base/parameter_handler.h>
8#include <deal.II/base/parsed_function.h>
9#include <deal.II/base/patterns.h>
10
11#include <string>
12#include <vector>
13
14using namespace dealii;
15
16DeclException1(CahnHilliardBoundaryDuplicated,
17 types::boundary_id,
18 << "Cahn Hilliard boundary id: " << arg1
19 << " has already been declared as a boundary condition");
20
21namespace BoundaryConditions
22{
23 template <int dim>
24 void
26 ParameterHandler &prm,
27 const types::boundary_id default_boundary_id)
28 {
30 prm,
31 "type",
33 "Type of boundary condition for the Cahn-Hilliard equations.",
34 {},
36
37 prm.declare_entry("id",
38 Utilities::int_to_string(default_boundary_id, 2),
39 Patterns::List(Patterns::Integer()),
40 "Mesh id for boundary conditions");
41
42 prm.declare_entry(
43 "angle value",
44 "0",
45 Patterns::Double(),
46 "Inner angle of contact between the fluid 1 and the boundary (in degrees)");
47
48 Functions::ParsedFunction<dim> temporary_function;
49 prm.enter_subsection("phi");
50 temporary_function.declare_parameters(prm);
51 prm.leave_subsection();
52
53 // Periodic boundary condition parameters for Cahn-Hilliards physics
54 prm.declare_entry(
55 "periodic id",
56 "-1",
57 Patterns::Integer(),
58 "Mesh id for periodic face matching. Default entry is -1 to ensure that the periodic id is set by the user");
59
60 prm.declare_entry("periodic direction",
61 "0",
62 Patterns::Integer(),
63 "Direction for periodic boundary condition");
64 }
65
66 template <int dim>
67 void
69 ParameterHandler &prm,
70 const unsigned int number_of_boundary_conditions)
71 {
72 prm.enter_subsection("boundary conditions cahn hilliard");
73 {
74 prm.declare_entry("number",
75 "0",
76 Patterns::Integer(),
77 "Number of boundary conditions");
78 prm.declare_entry(
79 "time dependent",
80 "false",
81 Patterns::Bool(),
82 "Bool to define if the boundary condition is time dependent");
83
84 for (unsigned int n = 0; n < number_of_boundary_conditions; n++)
85 {
86 prm.enter_subsection("bc " + std::to_string(n));
87 {
89 }
90 prm.leave_subsection();
91 }
92 }
93 prm.leave_subsection();
94 }
95
96 template <int dim>
97 void
99 {
100 // Parse the list of boundary ids
101 std::vector<types::boundary_id> boundary_ids =
103
104 // Check if the list contains at least one boundary id
105 AssertThrow(
106 boundary_ids.size() > 0,
107 ExcMessage(
108 "A boundary id has not been set for one of the Cahn Hilliard boundary conditions. Please ensure that the id is set for every boundary condition."));
109 // Loop through all boundary ids to ensure that they are all non-negative
110 // and unique
111 for (const auto boundary_id : boundary_ids)
112 {
113 AssertThrow(this->type.find(boundary_id) == this->type.end(),
114 CahnHilliardBoundaryDuplicated(boundary_id));
115
116 // Create and parse the phase order boundary condition for all cases.
117 prm.enter_subsection("phi");
118 this->bcFunctions[boundary_id] =
119 std::make_shared<CahnHilliardBoundaryFunctions<dim>>();
120 bcFunctions[boundary_id]->phi.parse_parameters(prm);
121 prm.leave_subsection();
122
123 // Do the same with the angle of contact
124 this->angle_of_contact[boundary_id] = prm.get_double("angle value");
125
126 const CahnHilliardBoundaryType boundary_type =
128 this->type[boundary_id] = boundary_type;
129 if (boundary_type == CahnHilliardBoundaryType::periodic)
130 {
131 types::boundary_id periodic_boundary_id =
132 prm.get_integer("periodic id");
133
134 // We attribute a periodic neighbor boundary type to the neighbor
135 // boundary to ensure that all boundaries have a defined type
136 this->type[periodic_boundary_id] =
138
139 // We store the periodic id and direction
140 this->periodic_boundaries[boundary_id] = {
141 .neighbor_id = periodic_boundary_id,
142 .direction = static_cast<unsigned int>(
143 prm.get_integer("periodic direction"))};
144 }
145 }
146 }
147
148 template <int dim>
149 void
151 {
152 prm.enter_subsection("boundary conditions cahn hilliard");
153 {
154 this->number_of_boundary_conditions = prm.get_integer("number");
155 this->time_dependent = prm.get_bool("time dependent");
156
157 for (unsigned int n = 0; n < this->number_of_boundary_conditions; n++)
158 {
159 prm.enter_subsection("bc " + std::to_string(n));
160 {
161 parse_boundary(prm);
162 }
163 prm.leave_subsection();
164 }
165 }
166 prm.leave_subsection();
167 }
168
171} // namespace BoundaryConditions
172
173
174template <int dim>
175double
177 const unsigned int component) const
178{
179 Assert(component < this->n_components,
180 ExcIndexRange(component, 0, this->n_components));
181
182 if (component == 0)
183 {
184 return phi->value(p);
185 }
186 if (component == 1)
187 {
188 return 0.;
189 }
190 return 0.;
191}
192
193
194template class CahnHilliardFunctionDefined<2>;
195template class CahnHilliardFunctionDefined<3>;
DeclException1(CahnHilliardBoundaryDuplicated, types::boundary_id,<< "Cahn Hilliard boundary id: "<< arg1<< " has already been declared as a boundary condition")
std::map< types::boundary_id, CahnHilliardBoundaryType > type
This class manages the boundary conditions for the Cahn-Hilliard solver It introduces the boundary fu...
void parse_parameters(ParameterHandler &prm)
Parse the Cahn-Hilliard boundary condition parameters.
void declare_default_entry(ParameterHandler &prm, types::boundary_id default_boundary_id)
Declare the default parameters for one Cahn-Hilliard boundary condition.
void declare_parameters(ParameterHandler &prm, unsigned int number_of_boundary_conditions)
Declare the Cahn-Hilliard boundary condition parameters.
std::map< types::boundary_id, std::shared_ptr< CahnHilliardBoundaryFunctions< dim > > > bcFunctions
void parse_boundary(ParameterHandler &prm)
Parse the information for one Cahn-Hilliard boundary condition.
Class that implements a boundary conditions for the Cahn-Hilliard equation where the phase and chemic...
double value(const Point< dim > &p, unsigned int component) const override
Calculates the value of a Function-type for the Cahn-Hilliard equations.
Functions::ParsedFunction< dim > * phi
std::vector< T > convert_string_to_vector(const ParameterHandler &prm, const std::string &entry_string)
Return the vector of size N of entry @entry_string. If the entry is specified in the ....
Definition utilities.h:1330
EnumType string_to_enum(const std::string &name)
Return the enumerator whose identifier is name, e.g. to parse the value of a parameter entry into its...
Definition utilities.h:734
void declare_enum_entry(ParameterHandler &prm, const std::string &entry_name, const EnumType default_value, const std::string &description, const DeprecatedEnumNames< EnumType > &deprecated_names={}, const std::vector< EnumType > &allowed_values={})
Declare a parameter entry whose value is an enumerator. The default value, the accepted values and th...
Definition utilities.h:888
const std::vector< CahnHilliardBoundaryType > cahn_hilliard_boundary_types