applications/mp-melt-pool/cases/evaporating_droplet/evaporating_droplet.hpp Source File๏ƒ

Developer Documentation: applications/mp-melt-pool/cases/evaporating_droplet/evaporating_droplet.hpp Source File
Developer Documentation
evaporating_droplet.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/shared_tria.h>
8#include <deal.II/distributed/tria.h>
9
10#include <deal.II/grid/grid_generator.h>
11
15
16#include <iostream>
17
18#include "../../melt_pool_case.hpp"
19
21{
22 static double droplet_radius = 0.5;
23 static double domain_length = 4;
24 static double bc_pressure = 0.0;
25 static double droplet_phi = 1.0;
26
27 BETTER_ENUM(DomainType, char, rectangle, ball)
28
29 static DomainType domain_type = DomainType::rectangle;
30
31 template <int dim>
32 class InitialValuesLS : public dealii::Function<dim>
33 {
34 public:
36 : dealii::Function<dim>()
37 , distance_sphere(dealii::Point<dim>(), droplet_radius)
38 {}
39
40 double
41 value(const dealii::Point<dim> &p, const unsigned int /*component*/) const override
42 {
43 return -droplet_phi * distance_sphere.value(p);
44 }
45
46 private:
47 const dealii::Functions::SignedDistance::Sphere<dim> distance_sphere;
48 };
49
50 template <int dim, typename number>
51 class SimulationEvaporatingDroplet : public MeltPoolCase<dim, number>
52 {
53 private:
54 mutable std::shared_ptr<PostProcessingTools::DivergenceCalculator<dim, double>> diver;
55
56 public:
59 {
60 AssertThrow(std::abs(droplet_phi) - 1.0 < 1e-10,
61 dealii::ExcMessage("'droplet phi' must be either 1 or"
62 "-1."));
63 }
64
65 bool
66 add_case_specific_parameters(dealii::ParameterHandler &prm) override
67 {
68 prm.add_parameter("droplet radius", droplet_radius, "Set the radius of the droplet.");
69 prm.add_parameter("domain length",
71 "Set the characteristic length of the domain.");
72 prm.add_parameter("domain type", domain_type, "Set the type of the domain.");
73 prm.add_parameter("bc pressure",
75 "Set the normal stress component on the outflow boundary.");
76 prm.add_parameter("droplet phi",
78 "Set the level set value inside the droplet, either -1 or 1.");
79
80 return this->parameters.base.do_print_parameters;
81 }
82
83 void
85 {
86 // create triangulation
87 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP || dim == 1)
88 this->triangulation =
89 std::make_shared<dealii::parallel::shared::Triangulation<dim>>(this->mpi_communicator);
90 else
91 this->triangulation = std::make_shared<dealii::parallel::distributed::Triangulation<dim>>(
92 this->mpi_communicator);
93
94 const double half_length = domain_length / 2.;
95
96 AssertThrow(droplet_radius < half_length,
97 dealii::ExcMessage(
98 "The droplet radius exceeds the domain size. "
99 "You might adjust either the domain length or the droplet radius."));
100
101 if (domain_type == DomainType::rectangle)
102 {
103 std::vector<unsigned int> subdivisions(
104 dim,
105 5 * (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP ?
106 dealii::Utilities::pow(2, this->parameters.base.global_refinements) :
107 1));
108
109 const dealii::Point<dim> bottom_left =
110 (dim == 1 ? dealii::Point<dim>(-half_length) :
111 dim == 2 ? dealii::Point<dim>(-half_length, -half_length) :
112 dealii::Point<dim>(-half_length, -half_length, -half_length));
113 const dealii::Point<dim> top_right =
114 (dim == 1 ? dealii::Point<dim>(half_length) :
115 dim == 2 ? dealii::Point<dim>(half_length, half_length) :
116 dealii::Point<dim>(half_length, half_length, half_length));
117
118 if (this->parameters.base.fe.type == FiniteElementType::FE_SimplexP)
119 dealii::GridGenerator::subdivided_hyper_rectangle_with_simplices(*this->triangulation,
120 subdivisions,
121 bottom_left,
122 top_right);
123 else
124 dealii::GridGenerator::subdivided_hyper_rectangle(*this->triangulation,
125 subdivisions,
126 bottom_left,
127 top_right);
128 }
129 else if (domain_type == DomainType::ball)
130 {
131 // create circular domain
132 const dealii::Point<dim> center;
133 dealii::GridGenerator::hyper_ball(*this->triangulation, center, half_length /*radius*/);
134 }
135 else
136 AssertThrow(false, dealii::ExcNotImplemented());
137
138 if (this->parameters.base.fe.type != FiniteElementType::FE_SimplexP)
139 this->triangulation->refine_global(this->parameters.base.global_refinements);
140 }
141
142 void
144 {
145 // prescribe pressure dirichlet BC
147 {0, std::make_shared<dealii::Functions::ConstantFunction<dim>>(bc_pressure)},
148 "open",
149 "navier_stokes_u");
150 }
151
152 void
154 {
155 this->attach_initial_condition(std::make_shared<InitialValuesLS<dim>>(), "signed_distance");
156 this->attach_initial_condition(std::shared_ptr<dealii::Function<dim>>(
157 new dealii::Functions::ZeroFunction<dim>(dim)),
158 "navier_stokes_u");
159 }
160
161 void
162 do_postprocessing(const GenericDataOut<dim, double> &generic_data_out) const final
163 {
164 dealii::ConditionalOStream pcout(
165 std::cout, dealii::Utilities::MPI::this_mpi_process(this->mpi_communicator) == 0);
166 if (!diver)
167 diver = std::make_shared<PostProcessingTools::DivergenceCalculator<dim, double>>(
168 generic_data_out, "interface_velocity");
169 else
170 // @todo: We need to reinit, since generic_data_out is currently created
171 // for every time step.
172 diver->reinit(generic_data_out);
173
174
175 diver->process(0 /*does not matter*/);
176 std::ostringstream str;
177 str << "โˆ‡ยทuฮ“ = " << std::setprecision(10) << std::scientific << diver->get_divergence();
178
179 Journal::print_line(pcout, str.str(), "user_defined_postprocess", 4);
180 ;
181 }
182 };
183} // namespace MeltPoolDG::Simulation::EvaporatingDroplet
A generic utility for managing simulation output data in the MeltPoolDG context.
Definition generic_data_out.hpp:32
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
InitialValuesLS()
Definition evaporating_droplet.hpp:35
const dealii::Functions::SignedDistance::Sphere< dim > distance_sphere
Definition evaporating_droplet.hpp:47
double value(const dealii::Point< dim > &p, const unsigned int) const override
Definition evaporating_droplet.hpp:41
void set_field_conditions() override
Pure virtual function to set the field conditions.
Definition evaporating_droplet.hpp:153
void set_boundary_conditions() override
Pure virtual function to set the boundary conditions.
Definition evaporating_droplet.hpp:143
std::shared_ptr< PostProcessingTools::DivergenceCalculator< dim, double > > diver
Definition evaporating_droplet.hpp:54
SimulationEvaporatingDroplet(std::string parameter_file, const MPI_Comm mpi_communicator)
Definition evaporating_droplet.hpp:57
bool add_case_specific_parameters(dealii::ParameterHandler &prm) override
Add simulation-specific parameters (can be overridden).
Definition evaporating_droplet.hpp:66
void do_postprocessing(const GenericDataOut< dim, double > &generic_data_out) const final
Definition evaporating_droplet.hpp:162
void create_spatial_discretization() override
Pure virtual function to create the spatial discretization.
Definition evaporating_droplet.hpp:84
void print_line(const ConditionalOStream &pcout, const std::string &text="", const std::string &operation_name="", const unsigned int extra_size=0)
Definition journal.cpp:11
Definition evaporating_droplet.cpp:6
static double droplet_radius
Definition evaporating_droplet.hpp:22
static DomainType domain_type
Definition evaporating_droplet.hpp:29
static double droplet_phi
Definition evaporating_droplet.hpp:25
static double domain_length
Definition evaporating_droplet.hpp:23
static double bc_pressure
Definition evaporating_droplet.hpp:24
BETTER_ENUM(MaterialTemplate, char, none, stainless_steel, Ti64, Ti64Benchmark) BETTER_ENUM(SolidLiquidPropertiesTransitionType
Definition dealii_tensor.hpp:10