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