applications/mp-reinit/cases/reinit_circle/reinit_circle.hpp Source File

Developer Documentation: applications/mp-reinit/cases/reinit_circle/reinit_circle.hpp Source File
Developer Documentation
reinit_circle.hpp
Go to the documentation of this file.
1#pragma once
2#include <deal.II/base/function.h>
3#include <deal.II/base/function_signed_distance.h>
4#include <deal.II/base/point.h>
5#include <deal.II/base/tensor_function.h>
6
7#include <deal.II/distributed/tria.h>
8
9#include <deal.II/grid/grid_generator.h>
10
11#include <deal.II/lac/vector.h>
12
15
16#include <cmath>
17
18#include "../../reinitialization_case.hpp"
19
21{
31 template <int dim, typename number>
32 class InitializePhi : public dealii::Function<dim, number>
33 {
34 public:
48 InitializePhi(const dealii::Point<dim, number> center_point,
49 const number radius,
50 const LevelSet::LevelSetType level_set_type_in,
51 const bool apply_initial_jump_at_interface_in,
52 const number distortion_parameter_in,
53 const number eps_in)
54 : dealii::Function<dim, number>()
55 , distance_sphere(center_point, radius)
56 , level_set_type(level_set_type_in)
57 , apply_initial_jump_at_interface(apply_initial_jump_at_interface_in)
58 , distortion_parameter(distortion_parameter_in)
59 , eps(eps_in)
60 {}
61
69 number
70 value(const dealii::Point<dim, number> &p, const unsigned int /*component*/) const override
71 {
72 const number phi = -distance_sphere.value(p);
73
75 {
76 switch (level_set_type)
77 {
78 case LevelSet::LevelSetType::tanh:
79 case LevelSet::LevelSetType::signed_distance:
81
82 case LevelSet::LevelSetType::smoothed_heaviside:
84 default:
85 AssertThrow(false, dealii::ExcNotImplemented());
86 }
87 }
88
89 switch (level_set_type)
90 {
91 case LevelSet::LevelSetType::tanh:
93 eps *
95 case LevelSet::LevelSetType::smoothed_heaviside:
97 case LevelSet::LevelSetType::signed_distance:
98 return phi * distortion_parameter;
99 default:
100 AssertThrow(false, dealii::ExcNotImplemented());
101 }
102 }
103
104 private:
106 const dealii::Functions::SignedDistance::Sphere<dim> distance_sphere;
107
109 const LevelSet::LevelSetType level_set_type;
110
113
116
119 const number eps;
120 };
121
125 template <int dim, typename number>
126 class ExactSolution : public dealii::Function<dim, number>
127 {
128 public:
138 ExactSolution(const dealii::Point<dim, number> center_point,
139 const number radius,
140 const LevelSet::LevelSetType level_set_type_in,
141 const number eps_in)
142 : dealii::Function<dim, number>()
143 , distance_sphere(center_point, radius)
144 , level_set_type(level_set_type_in)
145 , eps(eps_in)
146 {}
147
155 number
156 value(const dealii::Point<dim, number> &p, const unsigned int /*component*/) const override
157 {
158 const number phi = -distance_sphere.value(p);
159
160 switch (level_set_type)
161 {
162 case LevelSet::LevelSetType::tanh:
164 case LevelSet::LevelSetType::smoothed_heaviside:
166 case LevelSet::LevelSetType::signed_distance:
167 return phi;
168 default:
169 AssertThrow(false, dealii::ExcNotImplemented());
170 }
171 }
172
173 private:
175 const dealii::Functions::SignedDistance::Sphere<dim> distance_sphere;
176
178 const LevelSet::LevelSetType level_set_type;
179
182 const number eps;
183 };
184
189 template <int dim, typename number>
191 {
192 public:
202 : LevelSet::ReinitializationCase<dim, number>(parameter_file, mpi_communicator)
203 {}
204
208 void
210 {
211 if (dim == 1 || this->parameters.base.fe.type == FiniteElementType::FE_SimplexP)
212 {
213 // Distributed triangulation is not supported for dim=1 or Simplex elements.
214 AssertDimension(dealii::Utilities::MPI::n_mpi_processes(this->mpi_communicator), 1);
215 this->triangulation = std::make_shared<dealii::Triangulation<dim>>();
216 }
217 else
218 {
219 this->triangulation = std::make_shared<dealii::parallel::distributed::Triangulation<dim>>(
220 this->mpi_communicator);
221 }
222
223 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP)
224 {
225 dealii::GridGenerator::subdivided_hyper_cube_with_simplices(
226 *this->triangulation,
227 dealii::Utilities::pow(2, this->parameters.base.global_refinements),
230 }
231 else
232 {
233 dealii::GridGenerator::hyper_cube(*this->triangulation, left_domain, right_domain);
234 this->triangulation->refine_global(this->parameters.base.global_refinements);
235 }
236 }
237
243 void
245 {}
246
250 void
252 {
253 AssertDimension(center_point.size(), dim);
254
255 dealii::Point<dim, number> point;
256 for (unsigned int d = 0; d < dim; ++d)
257 point[d] = center_point[d];
258
260 std::make_shared<InitializePhi<dim, number>>(
262 "level_set");
263 }
264
270 bool
271 add_case_specific_parameters(dealii::ParameterHandler &prm) override
272 {
273 prm.add_parameter(
274 "center point",
276 "Center point of the hyperspherical level-set field. "
277 "Specify comma-separated values: the first for the x-coordinate, the second for the y-coordinate, "
278 "and the third for the z-coordinate.");
279 prm.add_parameter("radius",
280 radius,
281 "Radius of the hyperspherical zero level-set isosurface.",
282 dealii::Patterns::Double(0., std::numeric_limits<number>::max()));
283 prm.add_parameter("level set type",
285 "Level-set type description of initial condition function. "
286 "The options are \"tanh\", \"smoothed_heaviside\" and \"signed_distance\".",
287 dealii::Patterns::Selection("tanh|smoothed_heaviside|signed_distance"));
288 prm.add_parameter(
289 "apply initial jump at interface",
291 "Should the initial level-set field contain a jump at the zero level-set isosurface?",
292 dealii::Patterns::Bool());
293 prm.add_parameter(
294 "distortion factor",
296 "Distortion factor for the initial level-set field. For the level-set types "
297 "\"tanh\" and \"smoothed_heaviside\" the interface thickness parameter is scaled by the "
298 "distortion factor. For the type \"signed_distance\" the signed-distance field is scaled by "
299 "the factor.",
300 dealii::Patterns::Double());
301 prm.add_parameter(
302 "epsilon",
303 eps,
304 "Interface thickness parameter. Relevant for the level-set types \"tanh\" and "
305 "\"smoothed_heaviside\".",
306 dealii::Patterns::Double(0., std::numeric_limits<number>::max()));
307
308 return this->parameters.base.do_print_parameters;
309 }
310
311 private:
313 number left_domain = -1.0;
314
316 number right_domain = 1.0;
317
320 std::vector<number> center_point{};
321
323 number radius = 0.25;
324
326 LevelSet::LevelSetType level_set_type = LevelSet::LevelSetType::tanh;
327
331
333 number distortion_factor = 1.;
334
337 number eps = 0.;
338 };
339} // namespace MeltPoolDG::Simulation::ReinitCircle
Definition reinitialization_case.hpp:79
ReinitializationCase(const std::string &parameter_file_in, MPI_Comm mpi_communicator_in)
Definition reinitialization_case.hpp:83
ReinitializationCaseParameters< number > parameters
Definition reinitialization_case.hpp:81
std::shared_ptr< dealii::Triangulation< dim, spacedim > > triangulation
Definition simulation_case_base.hpp:49
const std::string parameter_file
Definition simulation_case_base.hpp:52
void attach_initial_condition(std::shared_ptr< dealii::Function< dim > > initial_function, const std::string &operation_name)
Definition simulation_case_base.hpp:327
const MPI_Comm mpi_communicator
Definition simulation_case_base.hpp:56
Field function for the exact level-set solution.
Definition reinit_circle.hpp:127
ExactSolution(const dealii::Point< dim, number > center_point, const number radius, const LevelSet::LevelSetType level_set_type_in, const number eps_in)
Constructor.
Definition reinit_circle.hpp:138
const LevelSet::LevelSetType level_set_type
Level-set type.
Definition reinit_circle.hpp:178
number value(const dealii::Point< dim, number > &p, const unsigned int) const override
Computes the current function value at a specific coordinate point p.
Definition reinit_circle.hpp:156
const number eps
Definition reinit_circle.hpp:182
const dealii::Functions::SignedDistance::Sphere< dim > distance_sphere
Signed distance function for a hyperspherical zero level-set isosurface.
Definition reinit_circle.hpp:175
Field function for the initial level-set.
Definition reinit_circle.hpp:33
const dealii::Functions::SignedDistance::Sphere< dim > distance_sphere
Signed distance function for a hyperspherical zero level-set isosurface.
Definition reinit_circle.hpp:106
const number distortion_parameter
Level-set distortion parameter.
Definition reinit_circle.hpp:115
number value(const dealii::Point< dim, number > &p, const unsigned int) const override
Computes the current function value at a specific coordinate point p.
Definition reinit_circle.hpp:70
InitializePhi(const dealii::Point< dim, number > center_point, const number radius, const LevelSet::LevelSetType level_set_type_in, const bool apply_initial_jump_at_interface_in, const number distortion_parameter_in, const number eps_in)
Constructor.
Definition reinit_circle.hpp:48
const bool apply_initial_jump_at_interface
Boolean indicator if the initial level-set field should have a jump at the interface.
Definition reinit_circle.hpp:112
const LevelSet::LevelSetType level_set_type
Level-set type.
Definition reinit_circle.hpp:109
const number eps
Definition reinit_circle.hpp:119
A specific reinitialization simulation setup for a hyperrectangular domain with a hyperspherical zero...
Definition reinit_circle.hpp:191
void set_boundary_conditions() override
Sets the boundary conditions.
Definition reinit_circle.hpp:244
bool add_case_specific_parameters(dealii::ParameterHandler &prm) override
Add case-specific material parameters in the parameter handler.
Definition reinit_circle.hpp:271
SimulationReinit(std::string parameter_file, const MPI_Comm mpi_communicator)
Constructor.
Definition reinit_circle.hpp:201
void create_spatial_discretization() override
Creates the spatial discretization for the simulation setup.
Definition reinit_circle.hpp:209
number distortion_factor
Level-set distortion parameter.
Definition reinit_circle.hpp:333
std::vector< number > center_point
Definition reinit_circle.hpp:320
number eps
Definition reinit_circle.hpp:337
number left_domain
Left domain boundary for the hyperrectangular domain.
Definition reinit_circle.hpp:313
void set_field_conditions() override
Sets the field functions for the simulation.
Definition reinit_circle.hpp:251
LevelSet::LevelSetType level_set_type
Level-set type.
Definition reinit_circle.hpp:326
number right_domain
Right domain boundary for the hyperrectangular domain.
Definition reinit_circle.hpp:316
bool apply_initial_jump_at_interface
Definition reinit_circle.hpp:330
number radius
Radius of the hyperspherical zero level-set isosurface.
Definition reinit_circle.hpp:323
number heaviside(const number in, const number limit=0.0)
Definition characteristic_functions.hpp:37
number smoothed_heaviside(const number &distance, const number &eps)
Definition characteristic_functions.hpp:19
number tanh_characteristic_function(const number &distance, const number &eps)
Definition characteristic_functions.hpp:12
int sgn(const number &x)
Definition characteristic_functions.hpp:63
Definition reinit_circle.cpp:6
Definition dealii_tensor.hpp:10