OGS 6.1.0-1721-g6382411ad
CreateMFront.cpp
Go to the documentation of this file.
1 
10 #include "CreateMFront.h"
11 
12 #ifdef OGS_USE_MFRONT
13 
14 #include "MFront.h"
15 
16 #include "BaseLib/FileTools.h"
18 
19 namespace
20 {
22 void varInfo(std::string const& msg,
23  std::vector<mgis::behaviour::Variable> const& vars,
24  mgis::behaviour::Hypothesis hypothesis)
25 {
26  INFO("#%s: %lu (array size %lu).",
27  msg.c_str(),
28  vars.size(),
29  mgis::behaviour::getArraySize(vars, hypothesis));
30  for (auto& var : vars)
31  {
32  INFO(" --> type `%s' with name `%s', size %lu, offset %lu.",
34  var.name.c_str(),
35  mgis::behaviour::getVariableSize(var, hypothesis),
36  mgis::behaviour::getVariableOffset(vars, var.name, hypothesis));
37  }
38 }
39 } // anonymous namespace
40 
41 namespace MaterialLib
42 {
43 namespace Solids
44 {
45 namespace MFront
46 {
47 template <int DisplacementDim>
48 std::unique_ptr<MechanicsBase<DisplacementDim>> createMFront(
49  std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters,
50  BaseLib::ConfigTree const& config)
51 {
52  INFO("### MFRONT ########################################################");
53 
55  config.checkConfigParameter("type", "MFront");
56 
57  auto const lib_path = BaseLib::joinPaths(
60  config.getConfigParameter<std::string>("library"));
61  auto const behaviour_name =
63  config.getConfigParameter<std::string>("behaviour");
64 
65  static_assert(DisplacementDim == 2 || DisplacementDim == 3,
66  "Given DisplacementDim not supported.");
67 
68  mgis::behaviour::Hypothesis hypothesis;
69  if (DisplacementDim == 2)
70  {
71  // TODO support the axial symmetry modelling hypothesis.
72  WARN(
73  "The model is defined in 2D. On the material level currently a "
74  "plane strain setting is used. In particular it is not checked if "
75  "axial symmetry or plane stress are assumed. Special material "
76  "behaviour for these settings is currently not supported.");
77  hypothesis = mgis::behaviour::Hypothesis::PLANESTRAIN;
78  }
79  else if (DisplacementDim == 3)
80  {
81  hypothesis = mgis::behaviour::Hypothesis::TRIDIMENSIONAL;
82  }
83 
84  auto behaviour =
85  mgis::behaviour::load(lib_path, behaviour_name, hypothesis);
86 
87  INFO("Behaviour: `%s'.", behaviour.behaviour.c_str());
88  INFO("Hypothesis: `%s'.", mgis::behaviour::toString(hypothesis));
89  INFO("Source: `%s'.", behaviour.source.c_str());
90  INFO("TFEL version: `%s'.", behaviour.tfel_version.c_str());
91  INFO("Behaviour type: `%s'.", btypeToString(behaviour.btype));
92  INFO("Kinematic: `%s'.", toString(behaviour.kinematic));
93  INFO("Symmetry: `%s'.", toString(behaviour.symmetry));
94 
95  varInfo("Mat. props.", behaviour.mps, hypothesis);
96  varInfo("Gradients", behaviour.gradients, hypothesis);
97  varInfo("Thdyn. forces", behaviour.thermodynamic_forces, hypothesis);
98  varInfo("Int. StVars.", behaviour.isvs, hypothesis);
99  varInfo("Ext. StVars.", behaviour.esvs, hypothesis);
100 
101  // TODO read parameters from prj file, not yet (2018-11-05) supported by
102  // MGIS library.
103  varInfo("Parameters", behaviour.parameters, hypothesis);
104 
105  std::vector<ProcessLib::Parameter<double> const*> material_properties;
106 
107  if (!behaviour.mps.empty())
108  {
109  std::map<std::string, std::string> map_name_to_param;
110 
111  // gather material properties from the prj file
113  auto const mps_config = config.getConfigSubtree("material_properties");
114  for (
115  auto const mp_config :
117  mps_config.getConfigParameterList("material_property"))
118  {
120  auto name = mp_config.getConfigAttribute<std::string>("name");
121  auto const param_name =
123  mp_config.getConfigAttribute<std::string>("parameter");
124 
125  map_name_to_param.emplace(std::move(name), std::move(param_name));
126  }
127 
128  for (auto& mp : behaviour.mps)
129  {
130  auto const it = map_name_to_param.find(mp.name);
131  if (it == map_name_to_param.end())
132  OGS_FATAL(
133  "Material Property `%s' has not been configured in the "
134  "project file.",
135  mp.name.c_str());
136 
137  auto const param_name = it->second;
138  auto const num_comp =
139  mgis::behaviour::getVariableSize(mp, hypothesis);
140  auto const* param = &ProcessLib::findParameter<double>(
141  param_name, parameters, num_comp);
142 
143  INFO("Using OGS parameter `%s' for material property `%s'.",
144  param_name.c_str(), mp.name.c_str());
145 
146  using V = mgis::behaviour::Variable;
147  if (mp.type == V::STENSOR || mp.type == V::TENSOR)
148  {
149  WARN(
150  "Material property `%s' is a tensorial quantity. You, the "
151  "user, have to make sure that the component order of "
152  "parameter `%s' matches the one required by MFront!",
153  mp.name.c_str(), param_name.c_str());
154  }
155 
156  material_properties.push_back(param);
157  map_name_to_param.erase(it);
158  }
159 
160  if (!map_name_to_param.empty())
161  {
162  ERR("Some material parameters that were configured are not used by "
163  "the material model.");
164  ERR("These parameters are:");
165 
166  for (auto& e : map_name_to_param)
167  {
168  ERR(" name: `%s', parameter: `%s'.", e.first.c_str(),
169  e.second.c_str());
170  }
171 
172  OGS_FATAL(
173  "Configuration errors occured. Please fix the project file.");
174  }
175  }
176 
177  INFO("### MFRONT END ####################################################");
178 
179  return std::make_unique<MFront<DisplacementDim>>(
180  std::move(behaviour), std::move(material_properties));
181 }
182 } // namespace MFront
183 } // namespace Solids
184 } // namespace MaterialLib
185 
186 #else // OGS_USE_MFRONT
187 
188 namespace MaterialLib
189 {
190 namespace Solids
191 {
192 namespace MFront
193 {
194 template <int DisplacementDim>
195 std::unique_ptr<MechanicsBase<DisplacementDim>> createMFront(
196  std::vector<
197  std::unique_ptr<ProcessLib::ParameterBase>> const& /*parameters*/,
198  BaseLib::ConfigTree const& /*config*/)
199 {
200  OGS_FATAL("OpenGeoSys has not been build with MFront support.");
201 }
202 } // namespace MFront
203 } // namespace Solids
204 } // namespace MaterialLib
205 
206 #endif // OGS_USE_MFRONT
207 
208 namespace MaterialLib
209 {
210 namespace Solids
211 {
212 namespace MFront
213 {
214 template std::unique_ptr<MechanicsBase<2>> createMFront<2>(
215  std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters,
216  BaseLib::ConfigTree const& config);
217 template std::unique_ptr<MechanicsBase<3>> createMFront<3>(
218  std::vector<std::unique_ptr<ProcessLib::ParameterBase>> const& parameters,
219  BaseLib::ConfigTree const& config);
220 } // namespace MFront
221 } // namespace Solids
222 } // namespace MaterialLib
std::unique_ptr< MechanicsBase< DisplacementDim > > createMFront(std::vector< std::unique_ptr< ProcessLib::ParameterBase >> const &, BaseLib::ConfigTree const &)
const char * varTypeToString(int v)
Converts MGIS variable type to a string representation.
Definition: MFront.cpp:142
T getConfigParameter(std::string const &param) const
void checkConfigParameter(std::string const &param, T const &value) const
template std::unique_ptr< MechanicsBase< 2 > > createMFront< 2 >(std::vector< std::unique_ptr< ProcessLib::ParameterBase >> const &parameters, BaseLib::ConfigTree const &config)
std::string const & getProjectDirectory()
Returns the directory where the prj file resides.
Definition: FileTools.cpp:188
const char * btypeToString(int btype)
Converts MGIS behaviour type to a string representation.
Definition: MFront.cpp:128
ConfigTree getConfigSubtree(std::string const &root) const
Definition: ConfigTree.cpp:146
template std::unique_ptr< MechanicsBase< 3 > > createMFront< 3 >(std::vector< std::unique_ptr< ProcessLib::ParameterBase >> const &parameters, BaseLib::ConfigTree const &config)
#define OGS_FATAL(fmt,...)
Definition: Error.h:71
Filename manipulation routines.
const char * toString(mgis::behaviour::Behaviour::Kinematic kin)
Converts MGIS kinematic to a string representation.
Definition: MFront.cpp:95
std::string joinPaths(std::string const &pathA, std::string const &pathB)
Definition: FileTools.cpp:173