applications/mp-heat-transfer/cases/powder_bed/powder_bed.templates.hpp Source File

Developer Documentation: applications/mp-heat-transfer/cases/powder_bed/powder_bed.templates.hpp Source File
Developer Documentation
powder_bed.templates.hpp
Go to the documentation of this file.
1#pragma once
2
3#include "powder_bed.hpp"
4//
5#include <deal.II/base/exceptions.h>
6#include <deal.II/base/function.h>
7#include <deal.II/base/point.h>
8#include <deal.II/base/utilities.h>
9
10#include <deal.II/distributed/shared_tria.h>
11#include <deal.II/distributed/tria.h>
12
13#include <deal.II/grid/grid_generator.h>
14#include <deal.II/grid/grid_tools_geometry.h>
15#include <deal.II/grid/tria.h>
16
24
25#include <cmath>
26#include <memory>
27#include <type_traits>
28
29#include "../../../mp-melt-pool/melt_pool_case.hpp"
30#include "../../heat_transfer_case.hpp"
31
32#ifdef MELT_POOL_DG_WITH_RTE
33# include "../../../mp-radiative-transport/radiative_transport_case.hpp"
34#endif
35
36
38{
39 template <int dim, typename number, typename CaseClass>
41 const MPI_Comm mpi_communicator)
42 : CaseClass(parameter_file, mpi_communicator)
43 , cell_repetitions(dim, 1)
44 {}
45
46
47 template <int dim, typename number, typename CaseClass>
48 bool
50 dealii::ParameterHandler &prm)
51 {
52 prm.add_parameter("domain x min", domain_x_min, "minimum x coordinate of simulation domain");
53 prm.add_parameter("domain x max", domain_x_max, "maximum x coordinate of simulation domain");
54 prm.add_parameter("domain y min", domain_y_min, "minimum y coordinate of simulation domain");
55 prm.add_parameter("domain y max", domain_y_max, "maximum y coordinate of simulation domain");
56 prm.add_parameter("domain z min", domain_z_min, "minimum z coordinate of simulation domain");
57 prm.add_parameter("domain z max", domain_z_max, "maximum z coordinate of simulation domain");
58 prm.add_parameter("cell repetitions",
59 cell_repetitions,
60 "cell repetitions per dim applied before global refinement or amr");
61 prm.add_parameter("initial temperature", T_initial, "Set the initial temperature.");
62 powder_bed_data.add_parameters(prm);
63
64 return this->parameters.base.do_print_parameters;
65 }
66
67
68 template <int dim, typename number, typename CaseClass>
69 void
71 {
72 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP || dim == 1)
73 {
74#ifdef DEAL_II_WITH_METIS
75 this->triangulation = std::make_shared<dealii::parallel::shared::Triangulation<dim>>(
76 this->mpi_communicator,
77 dealii::Triangulation<dim>::none,
78 false,
79 dealii::parallel::shared::Triangulation<dim>::Settings::partition_metis);
80#else
81 AssertThrow(
82 false,
83 dealii::ExcMessage(
84 "Missing Metis support of the deal.II installation. "
85 "Configure deal.II with -D DEAL_II_WITH_METIS='ON' to execute this example."));
86#endif
87 }
88 else
89 {
90 this->triangulation = std::make_shared<dealii::parallel::distributed::Triangulation<dim>>(
91 this->mpi_communicator);
92 }
93
94 const dealii::Point<dim, number> bottom_left =
95 dim == 1 ? dealii::Point<dim, number>(domain_x_min) :
96 dim == 2 ? dealii::Point<dim, number>(domain_x_min, domain_y_min) :
97 dealii::Point<dim, number>(domain_x_min, domain_y_min, domain_z_min);
98 const dealii::Point<dim, number> top_right =
99 dim == 1 ? dealii::Point<dim, number>(domain_x_max) :
100 dim == 2 ? dealii::Point<dim, number>(domain_x_max, domain_y_max) :
101 dealii::Point<dim, number>(domain_x_max, domain_y_max, domain_z_max);
102
103 if (this->parameters.base.fe.type != FiniteElementType::FE_SimplexP)
104 {
105 dealii::GridGenerator::subdivided_hyper_rectangle(*this->triangulation,
106 cell_repetitions,
107 bottom_left,
108 top_right,
109 /* colorize */ true);
110 }
111 else // do simplex
112 {
113 std::vector<unsigned int> subdivisions(
114 dim, 5 * dealii::Utilities::pow(2, this->parameters.base.global_refinements));
115 subdivisions[dim - 1] *= 2;
116 for (int d = 0; d < dim; d++)
117 subdivisions[d] *= cell_repetitions[d];
118
119 dealii::GridGenerator::subdivided_hyper_rectangle_with_simplices(*this->triangulation,
120 subdivisions,
121 bottom_left,
122 top_right,
123 /* colorize */ true);
124 }
125 }
126
127
128 template <int dim, typename number, typename CaseClass>
129 void
131 {
132 // face numbering according to the deal.II colorize flag
133 const auto [lower_bc, upper_bc, left_bc, right_bc, front_bc, back_bc] =
134 get_colorized_rectangle_boundary_ids<dim>();
135
136 // BC for heat transfer
137 this->attach_boundary_condition(
138 {lower_bc, std::make_shared<dealii::Functions::ConstantFunction<dim>>(T_initial)},
139 "dirichlet",
140 "heat_transfer");
141
142 // BC for two-phase flow
143 if constexpr (std::is_same_v<CaseClass, MeltPoolCase<dim, number>>)
144 {
145 // slip BC on all boundaries
146 this->attach_boundary_condition(lower_bc, "symmetry", "navier_stokes_u");
147 this->attach_boundary_condition(upper_bc, "symmetry", "navier_stokes_u");
148 if (dim >= 2)
149 {
150 this->attach_boundary_condition(left_bc, "symmetry", "navier_stokes_u");
151 this->attach_boundary_condition(right_bc, "symmetry", "navier_stokes_u");
152 }
153 if (dim >= 3)
154 {
155 this->attach_boundary_condition(front_bc, "symmetry", "navier_stokes_u");
156 this->attach_boundary_condition(back_bc, "symmetry", "navier_stokes_u");
157 }
158
159 // fix pressure condition can be set on any (non-periodic) boundary
160 this->attach_boundary_condition(lower_bc, "fix_pressure_constant", "navier_stokes_p");
161 }
162
163 // BC for RTE
164#ifdef MELT_POOL_DG_WITH_RTE
165 if constexpr (std::is_same_v<CaseClass,
167 {
168 this->attach_boundary_condition(
169 {upper_bc,
170 std::make_shared<Heat::GaussProjectionIntensityProfile<dim, number>>(
171 this->parameters.laser.power,
172 this->parameters.laser.radius,
173 this->parameters.laser.template get_starting_position<dim>(),
174 this->parameters.laser.template get_beam_direction<dim>())},
175 "dirichlet",
176 "intensity");
177 }
178 else
179#endif
180 if (this->parameters.laser.model == Heat::LaserModelType::RTE)
181 {
182 this->parameters.laser.rte_boundary_id = upper_bc;
183 }
184
185 if (this->parameters.base.fe.type != FiniteElementType::FE_SimplexP)
186 this->triangulation->refine_global(this->parameters.base.global_refinements);
187 }
188
189
190 template <int dim, typename number, typename CaseClass>
191 void
193 {
194 // attach initial temperature
195 this->attach_initial_condition(
196 std::make_shared<dealii::Functions::ConstantFunction<dim>>(T_initial), "heat_transfer");
197
198 // only for heat transfer case
199 if constexpr (std::is_same_v<CaseClass, Heat::HeatTransferCase<dim, number>>)
200 {
201 // create a temporary reinit data instance since reinit data is not available for the heat
202 // problem
205 LevelSet::InterfaceThicknessParameterType::proportional_to_cell_size;
206 reinit_data.interface_thickness_parameter.value = 1.5;
207
208 // attach prescribed heaviside
209 this->attach_initial_condition(
211 powder_bed_data,
212 LevelSet::LevelSetType::smoothed_heaviside,
214 dealii::GridTools::minimal_cell_diameter(*this->triangulation) / std::sqrt(dim))),
215 "prescribed_heaviside");
216 }
217
218 // only for melt pool case
219 if constexpr (std::is_same_v<CaseClass, MeltPoolCase<dim, number>>)
220 {
221 auto mp_case = dynamic_cast<MeltPoolCase<dim, number> *>(this);
222
223 this->attach_initial_condition(
225 powder_bed_data,
226 LevelSet::LevelSetType::signed_distance,
227 mp_case->parameters.ls.reinit.compute_interface_thickness_parameter_epsilon(
228 dealii::GridTools::minimal_cell_diameter(*this->triangulation) / std::sqrt(dim))),
229 "signed_distance");
230
231 this->attach_initial_condition(std::make_shared<dealii::Functions::ZeroFunction<dim>>(dim),
232 "navier_stokes_u");
233 }
234
235 if (this->parameters.laser.model == Heat::LaserModelType::RTE)
236 {
237 this->attach_initial_condition(std::make_shared<dealii::Functions::ZeroFunction<dim>>(),
238 "intensity");
239 }
240 }
241} // namespace MeltPoolDG::Simulation::PowderBed
Definition melt_pool_case.hpp:290
Definition powder_bed.hpp:31
Definition radiative_transport_case.hpp:62
void set_field_conditions() override
Definition powder_bed.templates.hpp:192
void set_boundary_conditions() override
Definition powder_bed.templates.hpp:130
SimulationPowderBed(std::string parameter_file, const MPI_Comm mpi_communicator)
Definition powder_bed.templates.hpp:40
bool add_case_specific_parameters(dealii::ParameterHandler &prm) override
Definition powder_bed.templates.hpp:49
void create_spatial_discretization() override
Definition powder_bed.templates.hpp:70
Definition powder_bed.cpp:9
InterfaceThicknessParameterType type
Definition reinitialization_data.hpp:147
number value
Definition reinitialization_data.hpp:150
Definition reinitialization_data.hpp:126
struct MeltPoolDG::LevelSet::ReinitializationData::InterfaceThickness interface_thickness_parameter
number2 compute_interface_thickness_parameter_epsilon(const number2 cell_size) const
Definition reinitialization_data.hpp:164