OGS 6.2.1-97-g73d1aeda3
CreateThermoMechanicalPhaseFieldProcess.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
13 
16 #include "ParameterLib/Utils.h"
19 
22 
23 namespace ProcessLib
24 {
25 namespace ThermoMechanicalPhaseField
26 {
27 template <int DisplacementDim>
28 std::unique_ptr<Process> createThermoMechanicalPhaseFieldProcess(
29  std::string name,
30  MeshLib::Mesh& mesh,
31  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
32  std::vector<ProcessVariable> const& variables,
33  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
34  boost::optional<ParameterLib::CoordinateSystem> const&
35  local_coordinate_system,
36  unsigned const integration_order,
37  BaseLib::ConfigTree const& config)
38 {
40  config.checkConfigParameter("type", "THERMO_MECHANICAL_PHASE_FIELD");
41  DBUG("Create ThermoMechanicalPhaseFieldProcess.");
42 
43  INFO(
44  "Solve the coupling with the staggered scheme,"
45  "which is the only option for TM-Phasefield in the current code");
46 
47  // Process variable.
48 
50  auto const pv_config = config.getConfigSubtree("process_variables");
51  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
52  process_variables;
53  int heat_conduction_process_id = 0;
54  int mechanics_related_process_id = 1;
55  int phase_field_process_id = 2;
56 
57  auto process_variable_T = findProcessVariables(
58  variables, pv_config,
59  {
60  "temperature"});
61  process_variables.push_back(std::move(process_variable_T));
62  ProcessVariable* variable_T =
63  &process_variables[process_variables.size() - 1][0].get();
64 
65  auto process_variable_u = findProcessVariables(
66  variables, pv_config,
67  {
68  "displacement"});
69  process_variables.push_back(std::move(process_variable_u));
70  ProcessVariable* variable_u =
71  &process_variables[process_variables.size() - 1][0].get();
72  auto process_variable_ph = findProcessVariables(
73  variables, pv_config,
74  {
75  "phasefield"});
76  process_variables.push_back(std::move(process_variable_ph));
77  ProcessVariable* variable_ph =
78  &process_variables[process_variables.size() - 1][0].get();
79 
80  DBUG("Associate displacement with process variable '%s'.",
81  variable_u->getName().c_str());
82 
83  if (variable_u->getNumberOfComponents() != DisplacementDim)
84  {
85  OGS_FATAL(
86  "Number of components of the process variable '%s' is different "
87  "from the displacement dimension: got %d, expected %d",
88  variable_u->getName().c_str(),
89  variable_u->getNumberOfComponents(),
90  DisplacementDim);
91  }
92 
93  DBUG("Associate phase field with process variable '%s'.",
94  variable_ph->getName().c_str());
95  if (variable_ph->getNumberOfComponents() != 1)
96  {
97  OGS_FATAL(
98  "Phasefield process variable '%s' is not a scalar variable but has "
99  "%d components.",
100  variable_ph->getName().c_str(),
101  variable_ph->getNumberOfComponents());
102  }
103 
104  DBUG("Associate temperature with process variable '%s'.",
105  variable_T->getName().c_str());
106  if (variable_T->getNumberOfComponents() != 1)
107  {
108  OGS_FATAL(
109  "Temperature process variable '%s' is not a scalar variable but "
110  "has "
111  "%d components.",
112  variable_T->getName().c_str(),
113  variable_T->getNumberOfComponents());
114  }
115 
116  auto solid_constitutive_relations =
117  MaterialLib::Solids::createConstitutiveRelations<DisplacementDim>(
118  parameters, local_coordinate_system, config);
119 
120  auto const phasefield_parameters_config =
122  config.getConfigSubtree("phasefield_parameters");
123 
124  auto const thermal_parameters_config =
126  config.getConfigSubtree("thermal_parameters");
127 
128  // Residual stiffness
129  auto& residual_stiffness = ParameterLib::findParameter<double>(
130  phasefield_parameters_config,
132  "residual_stiffness", parameters, 1, &mesh);
133  DBUG("Use '%s' as residual stiffness.", residual_stiffness.name.c_str());
134 
135  // Crack resistance
136  auto& crack_resistance = ParameterLib::findParameter<double>(
137  phasefield_parameters_config,
139  "crack_resistance", parameters, 1, &mesh);
140  DBUG("Use '%s' as crack resistance.", crack_resistance.name.c_str());
141 
142  // Crack length scale
143  auto& crack_length_scale = ParameterLib::findParameter<double>(
144  phasefield_parameters_config,
146  "crack_length_scale", parameters, 1, &mesh);
147  DBUG("Use '%s' as crack length scale.", crack_length_scale.name.c_str());
148 
149  // Kinetic coefficient
150  auto& kinetic_coefficient = ParameterLib::findParameter<double>(
151  phasefield_parameters_config,
153  "kinetic_coefficient", parameters, 1, &mesh);
154  DBUG("Use '%s' as kinetic coefficient.", kinetic_coefficient.name.c_str());
155 
156  // Solid density
157  auto& solid_density = ParameterLib::findParameter<double>(
158  config,
160  "solid_density", parameters, 1, &mesh);
161  DBUG("Use '%s' as solid density parameter.", solid_density.name.c_str());
162 
163  // Linear thermal expansion coefficient
164  auto& linear_thermal_expansion_coefficient = ParameterLib::findParameter<
165  double>(
166  thermal_parameters_config,
168  "linear_thermal_expansion_coefficient", parameters, 1, &mesh);
169  DBUG("Use '%s' as linear thermal expansion coefficient.",
170  linear_thermal_expansion_coefficient.name.c_str());
171 
172  // Specific heat capacity
173  auto& specific_heat_capacity = ParameterLib::findParameter<double>(
174  thermal_parameters_config,
176  "specific_heat_capacity", parameters, 1, &mesh);
177  DBUG("Use '%s' as specific heat capacity.",
178  specific_heat_capacity.name.c_str());
179 
180  // Thermal conductivity
181  auto& thermal_conductivity = ParameterLib::findParameter<double>(
182  thermal_parameters_config,
184  "thermal_conductivity", parameters, 1, &mesh);
185  DBUG("Use '%s' as thermal conductivity parameter.",
186  thermal_conductivity.name.c_str());
187  // Residual thermal conductivity
188  auto& residual_thermal_conductivity = ParameterLib::findParameter<double>(
189  thermal_parameters_config,
191  "residual_thermal_conductivity", parameters, 1, &mesh);
192  DBUG("Use '%s' as residual thermal conductivity parameter.",
193  residual_thermal_conductivity.name.c_str());
194  // Reference temperature
195  const auto reference_temperature =
197  config.getConfigParameter<double>("reference_temperature");
198 
199  // Specific body force
200  Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
201  {
202  std::vector<double> const b =
204  config.getConfigParameter<std::vector<double>>(
205  "specific_body_force");
206  if (specific_body_force.size() != DisplacementDim)
207  {
208  OGS_FATAL(
209  "The size of the specific body force vector does not match the "
210  "displacement dimension. Vector size is %d, displacement "
211  "dimension is %d",
212  specific_body_force.size(), DisplacementDim);
213  }
214 
215  std::copy_n(b.data(), b.size(), specific_body_force.data());
216  }
217 
219  materialIDs(mesh),
220  std::move(solid_constitutive_relations),
221  residual_stiffness,
222  crack_resistance,
223  crack_length_scale,
224  kinetic_coefficient,
225  solid_density,
226  linear_thermal_expansion_coefficient,
229  residual_thermal_conductivity,
230  specific_body_force,
231  reference_temperature};
232 
233  SecondaryVariableCollection secondary_variables;
234 
235  NumLib::NamedFunctionCaller named_function_caller(
236  {"temperature_phasefield_displacement"});
237 
238  ProcessLib::createSecondaryVariables(config, secondary_variables,
239  named_function_caller);
240 
241  return std::make_unique<ThermoMechanicalPhaseFieldProcess<DisplacementDim>>(
242  std::move(name), mesh, std::move(jacobian_assembler), parameters,
243  integration_order, std::move(process_variables),
244  std::move(process_data), std::move(secondary_variables),
245  std::move(named_function_caller), mechanics_related_process_id,
246  phase_field_process_id, heat_conduction_process_id);
247 }
248 
249 template std::unique_ptr<Process> createThermoMechanicalPhaseFieldProcess<2>(
250  std::string name,
251  MeshLib::Mesh& mesh,
252  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
253  std::vector<ProcessVariable> const& variables,
254  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
255  boost::optional<ParameterLib::CoordinateSystem> const&
256  local_coordinate_system,
257  unsigned const integration_order,
258  BaseLib::ConfigTree const& config);
259 
260 template std::unique_ptr<Process> createThermoMechanicalPhaseFieldProcess<3>(
261  std::string name,
262  MeshLib::Mesh& mesh,
263  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
264  std::vector<ProcessVariable> const& variables,
265  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
266  boost::optional<ParameterLib::CoordinateSystem> const&
267  local_coordinate_system,
268  unsigned const integration_order,
269  BaseLib::ConfigTree const& config);
270 
271 } // namespace ThermoMechanicalPhaseField
272 } // namespace ProcessLib
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables, NumLib::NamedFunctionCaller &named_function_caller)
Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase >> const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)
Definition: Utils.h:101
std::vector< std::reference_wrapper< ProcessVariable > > findProcessVariables(std::vector< ProcessVariable > const &variables, BaseLib::ConfigTree const &pv_config, std::initializer_list< std::string > tags)
Builds expression trees of named functions dynamically at runtime.
std::unique_ptr< Process > createThermoMechanicalPhaseFieldProcess(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters, boost::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
void checkConfigParameter(std::string const &param, T const &value) const
template std::unique_ptr< Process > createThermoMechanicalPhaseFieldProcess< 3 >(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters, boost::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
std::string const & getName() const
int getNumberOfComponents() const
Returns the number of components of the process variable.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:403
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:150
template std::unique_ptr< Process > createThermoMechanicalPhaseFieldProcess< 2 >(std::string name, MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterLib::ParameterBase >> const &parameters, boost::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
Handles configuration of several secondary variables from the project file.
#define OGS_FATAL(fmt,...)
Definition: Error.h:63