OGS 6.2.1-97-g73d1aeda3
CreatePhaseFieldProcess.cpp
Go to the documentation of this file.
1 
11 
12 #include <cassert>
13 
16 #include "ParameterLib/Utils.h"
19 
20 #include "PhaseFieldProcess.h"
21 #include "PhaseFieldProcessData.h"
22 
23 namespace ProcessLib
24 {
25 namespace PhaseField
26 {
27 template <int DisplacementDim>
28 std::unique_ptr<Process> createPhaseFieldProcess(
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", "PHASE_FIELD");
41  DBUG("Create PhaseFieldProcess.");
42 
43  auto const staggered_scheme =
45  config.getConfigParameterOptional<std::string>("coupling_scheme");
46  const bool use_monolithic_scheme =
47  !(staggered_scheme && (*staggered_scheme == "staggered"));
48 
49  // Process variable.
50 
52  auto const pv_config = config.getConfigSubtree("process_variables");
53 
54  ProcessVariable* variable_ph;
55  ProcessVariable* variable_u;
56  std::vector<std::vector<std::reference_wrapper<ProcessVariable>>>
57  process_variables;
58  if (use_monolithic_scheme) // monolithic scheme.
59  {
60  OGS_FATAL("Monolithic implementation is not available.");
61  }
62  else // staggered scheme.
63  {
64  using namespace std::string_literals;
65  for (
66  auto const& variable_name :
67  {
68  "displacement"s,
70  "phasefield"s})
71  {
72  auto per_process_variables =
73  findProcessVariables(variables, pv_config, {variable_name});
74  process_variables.push_back(std::move(per_process_variables));
75  }
76  variable_u = &process_variables[0][0].get();
77  variable_ph = &process_variables[1][0].get();
78  }
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  auto solid_constitutive_relations =
105  MaterialLib::Solids::createConstitutiveRelations<DisplacementDim>(
106  parameters, local_coordinate_system, config);
107 
108  auto const phasefield_parameters_config =
110  config.getConfigSubtree("phasefield_parameters");
111 
112  // Residual stiffness
113  auto& residual_stiffness = ParameterLib::findParameter<double>(
114  phasefield_parameters_config,
116  "residual_stiffness", parameters, 1);
117  DBUG("Use '%s' as residual stiffness.", residual_stiffness.name.c_str());
118 
119  // Crack resistance
120  auto& crack_resistance = ParameterLib::findParameter<double>(
121  phasefield_parameters_config,
123  "crack_resistance", parameters, 1);
124  DBUG("Use '%s' as crack resistance.", crack_resistance.name.c_str());
125 
126  // Crack length scale
127  auto& crack_length_scale = ParameterLib::findParameter<double>(
128  phasefield_parameters_config,
130  "crack_length_scale", parameters, 1);
131  DBUG("Use '%s' as crack length scale.", crack_length_scale.name.c_str());
132 
133  // Kinetic coefficient
134  auto& kinetic_coefficient = ParameterLib::findParameter<double>(
135  phasefield_parameters_config,
137  "kinetic_coefficient", parameters, 1);
138  DBUG("Use '%s' as kinetic coefficient.", kinetic_coefficient.name.c_str());
139 
140  // Solid density
141  auto& solid_density = ParameterLib::findParameter<double>(
142  config,
144  "solid_density", parameters, 1);
145  DBUG("Use '%s' as solid density parameter.", solid_density.name.c_str());
146 
147  // History field
148  auto& history_field = ParameterLib::findParameter<double>(
149  phasefield_parameters_config,
151  "history_field", parameters, 1);
152  DBUG("Use '%s' as history field.", history_field.name.c_str());
153 
154  // Specific body force
155  Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
156  {
157  std::vector<double> const b =
159  config.getConfigParameter<std::vector<double>>(
160  "specific_body_force");
161  if (b.size() != DisplacementDim)
162  {
163  OGS_FATAL(
164  "The size of the specific body force vector does not match the "
165  "displacement dimension. Vector size is %d, displacement "
166  "dimension is %d",
167  b.size(), DisplacementDim);
168  }
169 
170  std::copy_n(b.data(), b.size(), specific_body_force.data());
171  }
172 
173  auto const crack_scheme =
175  config.getConfigParameterOptional<std::string>("hydro_crack_scheme");
176  if (crack_scheme &&
177  ((*crack_scheme != "propagating") && (*crack_scheme != "static")))
178  {
179  OGS_FATAL(
180  "hydro_crack_scheme must be 'propagating' or 'static' but "
181  "'%s' was given",
182  crack_scheme->c_str());
183  }
184 
185  const bool propagating_crack =
186  (crack_scheme && (*crack_scheme == "propagating"));
187  const bool crack_pressure =
188  (crack_scheme &&
189  ((*crack_scheme == "propagating") || (*crack_scheme == "static")));
190 
192  materialIDs(mesh), std::move(solid_constitutive_relations),
193  residual_stiffness, crack_resistance,
194  crack_length_scale, kinetic_coefficient,
195  solid_density, history_field,
196  specific_body_force, propagating_crack,
197  crack_pressure};
198 
199  SecondaryVariableCollection secondary_variables;
200 
201  NumLib::NamedFunctionCaller named_function_caller(
202  {"PhaseField_displacement"});
203 
204  ProcessLib::createSecondaryVariables(config, secondary_variables,
205  named_function_caller);
206 
207  return std::make_unique<PhaseFieldProcess<DisplacementDim>>(
208  std::move(name), mesh, std::move(jacobian_assembler), parameters,
209  integration_order, std::move(process_variables),
210  std::move(process_data), std::move(secondary_variables),
211  std::move(named_function_caller), use_monolithic_scheme);
212 }
213 
214 template std::unique_ptr<Process> createPhaseFieldProcess<2>(
215  std::string name,
216  MeshLib::Mesh& mesh,
217  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
218  std::vector<ProcessVariable> const& variables,
219  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
220  boost::optional<ParameterLib::CoordinateSystem> const&
221  local_coordinate_system,
222  unsigned const integration_order,
223  BaseLib::ConfigTree const& config);
224 
225 template std::unique_ptr<Process> createPhaseFieldProcess<3>(
226  std::string name,
227  MeshLib::Mesh& mesh,
228  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
229  std::vector<ProcessVariable> const& variables,
230  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
231  boost::optional<ParameterLib::CoordinateSystem> const&
232  local_coordinate_system,
233  unsigned const integration_order,
234  BaseLib::ConfigTree const& config);
235 
236 } // namespace PhaseField
237 } // namespace ProcessLib
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables, NumLib::NamedFunctionCaller &named_function_caller)
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.
template std::unique_ptr< Process > createPhaseFieldProcess< 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)
void checkConfigParameter(std::string const &param, T const &value) const
std::unique_ptr< Process > createPhaseFieldProcess(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.
template std::unique_ptr< Process > createPhaseFieldProcess< 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)
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:403
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:150
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:63