applications/mp-melt-pool/cases/stefans_problem/stefans_problem2_with_flow_and_heat.hpp Source File

Developer Documentation: applications/mp-melt-pool/cases/stefans_problem/stefans_problem2_with_flow_and_heat.hpp Source File
Developer Documentation
stefans_problem2_with_flow_and_heat.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/mpi.h>
5#include <deal.II/base/point.h>
6#include <deal.II/base/types.h>
7#include <deal.II/base/utilities.h>
8
9#include <deal.II/distributed/shared_tria.h>
10#include <deal.II/distributed/tria.h>
11
12#include <deal.II/grid/grid_generator.h>
13#include <deal.II/grid/tria.h>
14
15#include <deal.II/lac/vector.h>
16
17#include <deal.II/numerics/vector_tools.h>
18
22
23#include <cmath>
24#include <iostream>
25#include <memory>
26#include <string>
27#include <vector>
28
29#include "../../melt_pool_case.hpp"
30
41{
42 using namespace MeltPoolDG::Simulation;
43
44
45 template <int dim>
46 class InitialValuesLS : public dealii::Function<dim>
47 {
48 public:
49 InitialValuesLS(const dealii::Point<dim> &lower_left, const dealii::Point<dim> &upper_right)
50 : dealii::Function<dim>()
51 , signed_distance(lower_left, upper_right)
52 {}
53
54 double
55 value(const dealii::Point<dim> &p, const unsigned int /*component*/) const override
56 {
58 }
59
60 dealii::Functions::SignedDistance::Rectangle<dim> signed_distance;
61 };
62
63 template <int dim>
64 class InitialValuesTemperature : public dealii::Function<dim>
65 {
66 public:
68 : dealii::Function<dim>()
69 {}
70
71 double
72 value(const dealii::Point<dim> &p, const unsigned int /*component*/) const override
73 {
74 const double T_bottom = 573.15;
75 const double T_sat = 373.15;
76 if (p[dim - 1] >= 0.0001)
77 return T_sat;
78 else
79 return T_bottom - (T_bottom - T_sat) / 1e-4 * p[dim - 1];
80 }
81 };
82 /*
83 * This class collects all relevant input data for the level set simulation
84 */
85
86 template <int dim, typename number>
88 {
89 public:
94
95 void
97 {
98 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP or dim == 1)
99 {
100#ifdef DEAL_II_WITH_METIS
101 this->triangulation = std::make_shared<dealii::parallel::shared::Triangulation<dim>>(
102 this->mpi_communicator,
103 dealii::Triangulation<dim>::none,
104 false,
105 dealii::parallel::shared::Triangulation<dim>::Settings::partition_metis);
106#else
107 AssertThrow(
108 false,
109 dealii::ExcMessage(
110 "Missing Metis support of the deal.II installation. "
111 "Configure deal.II with -D DEAL_II_WITH_METIS='ON' to execute this example."));
112#endif
113 }
114 else
115 {
116 this->triangulation = std::make_shared<dealii::parallel::distributed::Triangulation<dim>>(
117 this->mpi_communicator);
118 }
119
120 // create mesh
121 const dealii::Point<dim> bottom_left = dim == 1 ? dealii::Point<dim>(y_min) :
122 dim == 2 ? dealii::Point<dim>(x_min, y_min) :
123 dealii::Point<dim>(x_min, x_min, y_min);
124 const dealii::Point<dim> top_right = dim == 1 ? dealii::Point<dim>(y_max) :
125 dim == 2 ? dealii::Point<dim>(x_max, y_max) :
126 dealii::Point<dim>(x_max, x_max, y_max);
127
128 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP)
129 {
130 // create mesh
131 std::vector<unsigned int> subdivisions(
132 dim, 5 * dealii::Utilities::pow(2, this->parameters.base.global_refinements));
133 subdivisions[dim - 1] *= 2;
134
135 dealii::GridGenerator::subdivided_hyper_rectangle_with_simplices(*this->triangulation,
136 subdivisions,
137 bottom_left,
138 top_right);
139 }
140 else
141 {
142 dealii::GridGenerator::hyper_rectangle(*this->triangulation, bottom_left, top_right);
143 this->triangulation->refine_global(this->parameters.base.global_refinements);
144 }
145 }
146
147 void
149 {
150 /*
151 * create a pair of (boundary_id, dirichlet_function)
152 */
153
154 const dealii::types::boundary_id lower_bc = 1;
155 const dealii::types::boundary_id upper_bc = 2;
156 const dealii::types::boundary_id left_bc = 3;
157 const dealii::types::boundary_id right_bc = 4;
158
159 // lower part = liquid; upper part = gas
160 this->attach_boundary_condition(lower_bc, "no_slip", "navier_stokes_u");
161 this->attach_boundary_condition(upper_bc, "open", "navier_stokes_u");
162
163 if (dim >= 2)
164 {
165 this->attach_boundary_condition(left_bc, "symmetry", "navier_stokes_u");
166 this->attach_boundary_condition(right_bc, "symmetry", "navier_stokes_u");
167 }
168
169 this->attach_boundary_condition({lower_bc, std::make_shared<InitialValuesTemperature<dim>>()},
170 "dirichlet",
171 "heat_transfer");
173 {lower_bc, std::make_shared<dealii::Functions::ConstantFunction<dim>>(1.0)},
174 "dirichlet",
175 "level_set");
176
177 /*
178 * mark inflow edges with boundary label (no boundary on outflow edges must be prescribed
179 * due to the hyperbolic nature of the analyzed problem)
180 *
181 open
182 +---------------+
183 | ls=-1 |
184 | |
185 sym | | sym
186 | |
187 | |
188 | ls=1 |
189 +---------------+
190 * fix/open
191 */
192 if constexpr (dim == 1)
193 {
194 for (auto &cell : this->triangulation->cell_iterators())
195 for (auto &face : cell->face_iterators())
196 if (face->at_boundary())
197 {
198 if (face->center()[0] == y_min)
199 face->set_boundary_id(lower_bc);
200 else if (face->center()[0] == y_max)
201 face->set_boundary_id(upper_bc);
202 }
203 }
204 else if constexpr (dim == 2)
205 {
206 for (const auto &cell : this->triangulation->cell_iterators())
207 for (const auto &face : cell->face_iterators())
208 if (face->at_boundary())
209 {
210 if (face->center()[1] == y_min)
211 face->set_boundary_id(lower_bc);
212 else if (face->center()[1] == y_max)
213 face->set_boundary_id(upper_bc);
214 else if (face->center()[0] == x_min)
215 face->set_boundary_id(left_bc);
216 else if (face->center()[0] == x_max)
217 face->set_boundary_id(right_bc);
218 }
219 }
220 else
221 {
222 AssertThrow(false, dealii::ExcNotImplemented());
223 }
224 }
225
226 void
228 {
229 const dealii::Point<dim> lower_left(dim == 1 ? dealii::Point<dim>(y_min) :
230 dim == 2 ? dealii::Point<dim>(x_min, y_min) :
231 dealii::Point<dim>(x_min, x_min, y_min));
232 const dealii::Point<dim> upper_right(
233 dim == 1 ? dealii::Point<dim>(y_interface) :
234 dim == 2 ? dealii::Point<dim>(x_max, y_interface) :
235 dealii::Point<dim>(x_max, x_max, y_interface));
236 this->attach_initial_condition(std::make_shared<InitialValuesLS<dim>>(lower_left,
237 upper_right),
238 "level_set");
239 this->attach_initial_condition(std::make_shared<dealii::Functions::ZeroFunction<dim>>(dim),
240 "navier_stokes_u");
242 "heat_transfer");
243 }
244
245 private:
246 const double x_min = 0.0;
247 const double x_max = 5.0e-4;
248 const double y_min = 0.0;
249 const double y_max = 0.5e-3;
250 const double y_interface = 0.0001;
251 };
252} // namespace MeltPoolDG::Simulation::StefansProblem2WithFlowAndHeat
Definition melt_pool_case.hpp:290
MeltPoolCaseParameters< number > parameters
Definition melt_pool_case.hpp:292
void attach_boundary_condition(std::pair< const dealii::types::boundary_id, const std::shared_ptr< dealii::Function< dim > > > id_and_function, const std::string &type, const std::string &operation_name)
Attach a boundary condition for a specific operation.
Definition simulation_case_base.hpp:345
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
Definition stefans_problem2_with_flow_and_heat.hpp:47
double value(const dealii::Point< dim > &p, const unsigned int) const override
Definition stefans_problem2_with_flow_and_heat.hpp:55
InitialValuesLS(const dealii::Point< dim > &lower_left, const dealii::Point< dim > &upper_right)
Definition stefans_problem2_with_flow_and_heat.hpp:49
dealii::Functions::SignedDistance::Rectangle< dim > signed_distance
Definition stefans_problem2_with_flow_and_heat.hpp:60
InitialValuesTemperature()
Definition stefans_problem2_with_flow_and_heat.hpp:67
double value(const dealii::Point< dim > &p, const unsigned int) const override
Definition stefans_problem2_with_flow_and_heat.hpp:72
void create_spatial_discretization() override
Pure virtual function to create the spatial discretization.
Definition stefans_problem2_with_flow_and_heat.hpp:96
const double y_max
Definition stefans_problem2_with_flow_and_heat.hpp:249
const double x_min
Definition stefans_problem2_with_flow_and_heat.hpp:246
const double x_max
Definition stefans_problem2_with_flow_and_heat.hpp:247
SimulationStefansProblem2WithFlowAndHeat(std::string parameter_file, const MPI_Comm mpi_communicator)
Definition stefans_problem2_with_flow_and_heat.hpp:90
const double y_interface
Definition stefans_problem2_with_flow_and_heat.hpp:250
const double y_min
Definition stefans_problem2_with_flow_and_heat.hpp:248
void set_boundary_conditions() final
Pure virtual function to set the boundary conditions.
Definition stefans_problem2_with_flow_and_heat.hpp:148
void set_field_conditions() final
Pure virtual function to set the field conditions.
Definition stefans_problem2_with_flow_and_heat.hpp:227
int sgn(const number &x)
Definition characteristic_functions.hpp:63
Definition stefans_problem2_with_flow_and_heat.cpp:6
Definition advection_diffusion.cpp:6
Definition dealii_tensor.hpp:10