OGS 6.1.0-1699-ge946d4c5f
CreatePhaseFieldProcess.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
13 
18 
19 #include "PhaseFieldProcess.h"
20 #include "PhaseFieldProcessData.h"
21 
22 namespace ProcessLib
23 {
24 namespace PhaseField
25 {
26 template <int DisplacementDim>
27 std::unique_ptr<Process> createPhaseFieldProcess(
28  MeshLib::Mesh& mesh,
29  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
30  std::vector<ProcessVariable> const& variables,
31  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
32  unsigned const integration_order,
33  BaseLib::ConfigTree const& config)
34 {
36  config.checkConfigParameter("type", "PHASE_FIELD");
37  DBUG("Create PhaseFieldProcess.");
38 
39  auto const staggered_scheme =
41  config.getConfigParameterOptional<std::string>("coupling_scheme");
42  const bool use_monolithic_scheme =
43  !(staggered_scheme && (*staggered_scheme == "staggered"));
44 
45  // Process variable.
46 
48  auto const pv_config = config.getConfigSubtree("process_variables");
49 
50  ProcessVariable* variable_ph;
51  ProcessVariable* variable_u;
52  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
53  process_variables;
54  if (use_monolithic_scheme) // monolithic scheme.
55  {
56  OGS_FATAL("Monolithic implementation is not available.");
57  }
58  else // staggered scheme.
59  {
60  using namespace std::string_literals;
61  for (auto const& variable_name : {"displacement"s, "phasefield"s})
62  {
63  auto per_process_variables =
64  findProcessVariables(variables, pv_config, {variable_name});
65  process_variables.push_back(std::move(per_process_variables));
66  }
67  variable_u = &process_variables[0][0].get();
68  variable_ph = &process_variables[1][0].get();
69  }
70 
71  DBUG("Associate displacement with process variable '%s'.",
72  variable_u->getName().c_str());
73 
74  if (variable_u->getNumberOfComponents() != DisplacementDim)
75  {
76  OGS_FATAL(
77  "Number of components of the process variable '%s' is different "
78  "from the displacement dimension: got %d, expected %d",
79  variable_u->getName().c_str(),
80  variable_u->getNumberOfComponents(),
81  DisplacementDim);
82  }
83 
84  DBUG("Associate phase field with process variable '%s'.",
85  variable_ph->getName().c_str());
86  if (variable_ph->getNumberOfComponents() != 1)
87  {
88  OGS_FATAL(
89  "Phasefield process variable '%s' is not a scalar variable but has "
90  "%d components.",
91  variable_ph->getName().c_str(),
92  variable_ph->getNumberOfComponents());
93  }
94 
95  auto solid_constitutive_relations =
96  MaterialLib::Solids::createConstitutiveRelations<DisplacementDim>(
97  parameters, config);
98 
99  auto const phasefield_parameters_config =
101  config.getConfigSubtree("phasefield_parameters");
102 
103  // Residual stiffness
104  auto& residual_stiffness = findParameter<double>(
105  phasefield_parameters_config,
107  "residual_stiffness", parameters, 1);
108  DBUG("Use '%s' as residual stiffness.", residual_stiffness.name.c_str());
109 
110  // Crack resistance
111  auto& crack_resistance = findParameter<double>(
112  phasefield_parameters_config,
114  "crack_resistance", parameters, 1);
115  DBUG("Use '%s' as crack resistance.", crack_resistance.name.c_str());
116 
117  // Crack length scale
118  auto& crack_length_scale = findParameter<double>(
119  phasefield_parameters_config,
121  "crack_length_scale", parameters, 1);
122  DBUG("Use '%s' as crack length scale.", crack_length_scale.name.c_str());
123 
124  // Kinetic coefficient
125  auto& kinetic_coefficient = findParameter<double>(
126  phasefield_parameters_config,
128  "kinetic_coefficient", parameters, 1);
129  DBUG("Use '%s' as kinetic coefficient.", kinetic_coefficient.name.c_str());
130 
131  // Solid density
132  auto& solid_density = findParameter<double>(
133  config,
135  "solid_density", parameters, 1);
136  DBUG("Use '%s' as solid density parameter.", solid_density.name.c_str());
137 
138  // History field
139  auto& history_field = findParameter<double>(
140  phasefield_parameters_config,
142  "history_field", parameters, 1);
143  DBUG("Use '%s' as history field.", history_field.name.c_str());
144 
145  // Specific body force
146  Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
147  {
148  std::vector<double> const b =
150  config.getConfigParameter<std::vector<double>>(
151  "specific_body_force");
152  if (b.size() != DisplacementDim)
153  OGS_FATAL(
154  "The size of the specific body force vector does not match the "
155  "displacement dimension. Vector size is %d, displacement "
156  "dimension is %d",
157  b.size(), DisplacementDim);
158 
159  std::copy_n(b.data(), b.size(), specific_body_force.data());
160  }
161 
162  auto const crack_scheme =
164  config.getConfigParameterOptional<std::string>("hydro_crack_scheme");
165  if (crack_scheme &&
166  ((*crack_scheme != "propagating") && (*crack_scheme != "static")))
167  {
168  OGS_FATAL(
169  "hydro_crack_scheme must be 'propagating' or 'static' but "
170  "'%s' was given",
171  crack_scheme->c_str());
172  }
173 
174  const bool propagating_crack =
175  (crack_scheme && (*crack_scheme == "propagating"));
176  const bool crack_pressure =
177  (crack_scheme &&
178  ((*crack_scheme == "propagating") || (*crack_scheme == "static")));
179 
181  materialIDs(mesh), std::move(solid_constitutive_relations),
182  residual_stiffness, crack_resistance,
183  crack_length_scale, kinetic_coefficient,
184  solid_density, history_field,
185  specific_body_force, propagating_crack,
186  crack_pressure};
187 
188  SecondaryVariableCollection secondary_variables;
189 
190  NumLib::NamedFunctionCaller named_function_caller(
191  {"PhaseField_displacement"});
192 
193  ProcessLib::createSecondaryVariables(config, secondary_variables,
194  named_function_caller);
195 
196  return std::make_unique<PhaseFieldProcess<DisplacementDim>>(
197  mesh, std::move(jacobian_assembler), parameters, integration_order,
198  std::move(process_variables), std::move(process_data),
199  std::move(secondary_variables), std::move(named_function_caller),
200  use_monolithic_scheme);
201 }
202 
203 template std::unique_ptr<Process> createPhaseFieldProcess<2>(
204  MeshLib::Mesh& mesh,
205  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
206  std::vector<ProcessVariable> const& variables,
207  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
208  unsigned const integration_order,
209  BaseLib::ConfigTree const& config);
210 
211 template std::unique_ptr<Process> createPhaseFieldProcess<3>(
212  MeshLib::Mesh& mesh,
213  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
214  std::vector<ProcessVariable> const& variables,
215  std::vector<std::unique_ptr<ParameterBase>> const& parameters,
216  unsigned const integration_order,
217  BaseLib::ConfigTree const& config);
218 
219 } // namespace PhaseField
220 } // namespace ProcessLib
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables, NumLib::NamedFunctionCaller &named_function_caller)
template std::unique_ptr< Process > createPhaseFieldProcess< 2 >(MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterBase >> const &parameters, unsigned const integration_order, BaseLib::ConfigTree const &config)
std::unique_ptr< Process > createPhaseFieldProcess(MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterBase >> const &parameters, unsigned const integration_order, BaseLib::ConfigTree const &config)
template std::unique_ptr< Process > createPhaseFieldProcess< 3 >(MeshLib::Mesh &mesh, std::unique_ptr< ProcessLib::AbstractJacobianAssembler > &&jacobian_assembler, std::vector< ProcessVariable > const &variables, std::vector< std::unique_ptr< ParameterBase >> const &parameters, unsigned const integration_order, BaseLib::ConfigTree const &config)
T getConfigParameter(std::string const &param) const
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.
void checkConfigParameter(std::string const &param, T const &value) const
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:342
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:146
Handles configuration of several secondary variables from the project file.
boost::optional< T > getConfigParameterOptional(std::string const &param) const
#define OGS_FATAL(fmt,...)
Definition: Error.h:71