OGS
CreatePhaseFieldProcess.cpp
Go to the documentation of this file.
1 
12 
13 #include <cassert>
14 
17 #include "ParameterLib/Utils.h"
18 #include "PhaseFieldProcess.h"
19 #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  std::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 coupling_scheme =
45  config.getConfigParameterOptional<std::string>("coupling_scheme");
46  const bool use_monolithic_scheme =
47  !(coupling_scheme && (*coupling_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());
82 
83  if (variable_u->getNumberOfGlobalComponents() != 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(),
89  variable_u->getNumberOfGlobalComponents(),
90  DisplacementDim);
91  }
92 
93  DBUG("Associate phase field with process variable '{:s}'.",
94  variable_ph->getName());
95  if (variable_ph->getNumberOfGlobalComponents() != 1)
96  {
97  OGS_FATAL(
98  "Phasefield process variable '{:s}' is not a scalar variable but "
99  "has {:d} components.",
100  variable_ph->getName(),
101  variable_ph->getNumberOfGlobalComponents());
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 const& residual_stiffness = ParameterLib::findParameter<double>(
114  phasefield_parameters_config,
116  "residual_stiffness", parameters, 1);
117  DBUG("Use '{:s}' as residual stiffness.", residual_stiffness.name);
118 
119  // Crack resistance
120  auto const& crack_resistance = ParameterLib::findParameter<double>(
121  phasefield_parameters_config,
123  "crack_resistance", parameters, 1);
124  DBUG("Use '{:s}' as crack resistance.", crack_resistance.name);
125 
126  // Crack length scale
127  auto const& 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);
132 
133  // Solid density
134  auto const& solid_density = ParameterLib::findParameter<double>(
135  config,
137  "solid_density", parameters, 1);
138  DBUG("Use '{:s}' as solid density parameter.", solid_density.name);
139 
140  // Specific body force
141  Eigen::Matrix<double, DisplacementDim, 1> specific_body_force;
142  {
143  std::vector<double> const b =
145  config.getConfigParameter<std::vector<double>>(
146  "specific_body_force");
147  if (b.size() != DisplacementDim)
148  {
149  OGS_FATAL(
150  "The size of the specific body force vector does not match the "
151  "displacement dimension. Vector size is {:d}, displacement "
152  "dimension is {:d}",
153  b.size(), DisplacementDim);
154  }
155 
156  std::copy_n(b.data(), b.size(), specific_body_force.data());
157  }
158 
159  auto const crack_scheme =
161  config.getConfigParameterOptional<std::string>("hydro_crack_scheme");
162  if (crack_scheme &&
163  ((*crack_scheme != "propagating") && (*crack_scheme != "static")))
164  {
165  OGS_FATAL(
166  "crack_scheme must be 'propagating' or 'static' but '{:s}' "
167  "was given",
168  crack_scheme->c_str());
169  }
170 
171  const bool hydro_crack = (crack_scheme && (*crack_scheme == "propagating"));
172  const bool crack_pressure = crack_scheme.has_value();
173 
174  auto const irreversible_threshold =
176  config.getConfigParameter<double>("irreversible_threshold", 0.05);
177 
178  auto const phasefield_model = [&]
179  {
180  auto const phasefield_model_string =
182  config.getConfigParameter<std::string>("phasefield_model");
183 
184  if (phasefield_model_string == "AT1")
185  {
186  return PhaseFieldModel::AT1;
187  }
188  else if (phasefield_model_string == "AT2")
189  {
190  return PhaseFieldModel::AT2;
191  }
192  OGS_FATAL(
193  "phasefield_model must be 'AT1' or 'AT2' but '{:s}' "
194  "was given",
195  phasefield_model_string.c_str());
196  }();
197 
199  materialIDs(mesh), std::move(solid_constitutive_relations),
200  residual_stiffness, crack_resistance,
201  crack_length_scale, solid_density,
202  specific_body_force, hydro_crack,
203  crack_pressure, irreversible_threshold,
204  phasefield_model};
205 
206  SecondaryVariableCollection secondary_variables;
207 
208  ProcessLib::createSecondaryVariables(config, secondary_variables);
209 
210  return std::make_unique<PhaseFieldProcess<DisplacementDim>>(
211  std::move(name), mesh, std::move(jacobian_assembler), parameters,
212  integration_order, std::move(process_variables),
213  std::move(process_data), std::move(secondary_variables),
214  use_monolithic_scheme);
215 }
216 
217 template std::unique_ptr<Process> createPhaseFieldProcess<2>(
218  std::string name,
219  MeshLib::Mesh& mesh,
220  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
221  std::vector<ProcessVariable> const& variables,
222  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
223  std::optional<ParameterLib::CoordinateSystem> const&
224  local_coordinate_system,
225  unsigned const integration_order,
226  BaseLib::ConfigTree const& config);
227 
228 template std::unique_ptr<Process> createPhaseFieldProcess<3>(
229  std::string name,
230  MeshLib::Mesh& mesh,
231  std::unique_ptr<ProcessLib::AbstractJacobianAssembler>&& jacobian_assembler,
232  std::vector<ProcessVariable> const& variables,
233  std::vector<std::unique_ptr<ParameterLib::ParameterBase>> const& parameters,
234  std::optional<ParameterLib::CoordinateSystem> const&
235  local_coordinate_system,
236  unsigned const integration_order,
237  BaseLib::ConfigTree const& config);
238 
239 } // namespace PhaseField
240 } // namespace ProcessLib
#define OGS_FATAL(...)
Definition: Error.h:26
void DBUG(char const *fmt, Args const &... args)
Definition: Logging.h:27
void checkConfigParameter(std::string const &param, T const &value) const
std::optional< T > getConfigParameterOptional(std::string const &param) const
T getConfigParameter(std::string const &param) const
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:146
std::string const & getName() const
int getNumberOfGlobalComponents() const
Returns the number of components of the process variable.
Handles configuration of several secondary variables from the project file.
PropertyVector< int > const * materialIDs(Mesh const &mesh)
Definition: Mesh.cpp:258
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, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
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, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
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, std::optional< ParameterLib::CoordinateSystem > const &local_coordinate_system, unsigned const integration_order, BaseLib::ConfigTree const &config)
std::vector< std::reference_wrapper< ProcessVariable > > findProcessVariables(std::vector< ProcessVariable > const &variables, BaseLib::ConfigTree const &pv_config, std::initializer_list< std::string > tags)
void createSecondaryVariables(BaseLib::ConfigTree const &config, SecondaryVariableCollection &secondary_variables)