OGS
anonymous_namespace{CreateMFrontGeneric.cpp} Namespace Reference

Functions

const char * btypeToString (int btype)
const char * toString (mgis::behaviour::Behaviour::Kinematic kin)
const char * toString (mgis::behaviour::Behaviour::Symmetry sym)
void varInfo (std::string const &msg, std::vector< mgis::behaviour::Variable > const &vars, mgis::behaviour::Hypothesis hypothesis)
 Prints info about MFront variables.
void varInfo (std::string const &msg, std::vector< std::string > const &parameters)
 Prints info about MFront parameters.
std::vector< ParameterLib::Parameter< double > const * > readMaterialProperties (mgis::behaviour::Behaviour const &behaviour, mgis::behaviour::Hypothesis const &hypothesis, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, BaseLib::ConfigTree const &config)
std::map< std::string, ParameterLib::Parameter< double > const * > readStateVariablesInitialValueProperties (mgis::behaviour::Behaviour const &behaviour, mgis::behaviour::Hypothesis const &hypothesis, std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const &parameters, BaseLib::ConfigTree const &config)
mgis::behaviour::Behaviour loadBehaviour (std::string const &lib_path, std::string behaviour_name, mgis::behaviour::Hypothesis const hypothesis)

Function Documentation

◆ btypeToString()

const char * anonymous_namespace{CreateMFrontGeneric.cpp}::btypeToString ( int btype)

Definition at line 14 of file CreateMFrontGeneric.cpp.

15{
16 using B = mgis::behaviour::Behaviour;
17 if (btype == B::GENERALBEHAVIOUR)
18 {
19 return "GENERALBEHAVIOUR";
20 }
21 if (btype == B::STANDARDSTRAINBASEDBEHAVIOUR)
22 {
23 return "STANDARDSTRAINBASEDBEHAVIOUR";
24 }
25 if (btype == B::STANDARDFINITESTRAINBEHAVIOUR)
26 {
27 return "STANDARDFINITESTRAINBEHAVIOUR";
28 }
29 if (btype == B::COHESIVEZONEMODEL)
30 {
31 return "COHESIVEZONEMODEL";
32 }
33
34 OGS_FATAL("Unknown behaviour type {}.", btype);
35}
#define OGS_FATAL(...)
Definition Error.h:19

References OGS_FATAL.

◆ loadBehaviour()

mgis::behaviour::Behaviour anonymous_namespace{CreateMFrontGeneric.cpp}::loadBehaviour ( std::string const & lib_path,
std::string behaviour_name,
mgis::behaviour::Hypothesis const hypothesis )

Definition at line 273 of file CreateMFrontGeneric.cpp.

276{
277 // Fix for https://gitlab.opengeosys.org/ogs/ogs/-/issues/3073
278 // Pre-load dependencies of mfront lib
279#ifndef _WIN32
280 dlopen("libTFELNUMODIS.so", RTLD_NOW);
281 dlopen("libTFELUtilities.so", RTLD_NOW);
282 dlopen("libTFELException.so", RTLD_NOW);
283#endif
284
285 std::optional<std::runtime_error> small_strain_load_error;
286
287 // Try small strains first.
288 try
289 {
290 return mgis::behaviour::load(lib_path, behaviour_name, hypothesis);
291 }
292 catch (std::runtime_error const& e)
293 {
294 // Didn't work, store the exception and try finite strain.
295 small_strain_load_error = e;
296 }
297
298 try
299 {
300 auto o = mgis::behaviour::FiniteStrainBehaviourOptions{};
301 o.stress_measure = mgis::behaviour::FiniteStrainBehaviourOptions::PK2;
302 o.tangent_operator =
303 mgis::behaviour::FiniteStrainBehaviourOptions::DS_DEGL;
304
305 return mgis::behaviour::load(o, lib_path, behaviour_name, hypothesis);
306 }
307 catch (std::runtime_error const& e)
308 {
309 if (small_strain_load_error)
310 {
311 OGS_FATAL(
312 "Could not load the {} from {} neither for small strains "
313 "(error {}) nor for finite strains (error {}).",
314 behaviour_name, lib_path, small_strain_load_error->what(),
315 e.what());
316 }
317 }
318
319 OGS_FATAL("Could not load the {} from {}.", behaviour_name, lib_path);
320}

References OGS_FATAL.

◆ readMaterialProperties()

std::vector< ParameterLib::Parameter< double > const * > anonymous_namespace{CreateMFrontGeneric.cpp}::readMaterialProperties ( mgis::behaviour::Behaviour const & behaviour,
mgis::behaviour::Hypothesis const & hypothesis,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
BaseLib::ConfigTree const & config )
Input File Parameter
material__solid__constitutive_relation__MFront__material_properties
Input File Parameter
material__solid__constitutive_relation__MFront__material_properties__material_property
Input File Parameter
material__solid__constitutive_relation__MFront__material_properties__material_property__name
Input File Parameter
material__solid__constitutive_relation__MFront__material_properties__material_property__parameter

Definition at line 100 of file CreateMFrontGeneric.cpp.

105{
106 if (behaviour.mps.empty())
107 {
108 return {};
109 }
110
111 std::map<std::string, std::string> map_name_to_param;
112
113 // gather material properties from the prj file
115 auto const mps_config = config.getConfigSubtree("material_properties");
116 for (
117 auto const& mp_config :
119 mps_config.getConfigParameterList("material_property"))
120 {
122 auto name = mp_config.getConfigAttribute<std::string>("name");
123 auto param_name =
125 mp_config.getConfigAttribute<std::string>("parameter");
126
127 map_name_to_param.emplace(std::move(name), std::move(param_name));
128 }
129
130 std::vector<ParameterLib::Parameter<double> const*> material_properties;
131 for (auto const& mp : behaviour.mps)
132 {
133 auto const it = map_name_to_param.find(mp.name);
134 if (it == map_name_to_param.end())
135 OGS_FATAL(
136 "Material Property `{:s}' has not been configured in the "
137 "project file.",
138 mp.name);
139
140 auto const& param_name = it->second;
141 auto const num_comp = mgis::behaviour::getVariableSize(mp, hypothesis);
142 auto const* param = &ParameterLib::findParameter<double>(
143 param_name, parameters, num_comp);
144
145 INFO("Using OGS parameter `{:s}' for material property `{:s}'.",
146 param_name, mp.name);
147
148 using V = mgis::behaviour::Variable;
149 if (mp.type == V::STENSOR || mp.type == V::TENSOR)
150 {
151 WARN(
152 "Material property `{:s}' is a tensorial quantity. You, "
153 "the "
154 "user, have to make sure that the component order of "
155 "parameter `{:s}' matches the one required by MFront!",
156 mp.name, param_name);
157 }
158
159 material_properties.push_back(param);
160 map_name_to_param.erase(it);
161 }
162
163 if (!map_name_to_param.empty())
164 {
165 ERR("Some material parameters that were configured are not used by "
166 "the material model.");
167 ERR("These parameters are:");
168
169 for (auto const& e : map_name_to_param)
170 {
171 ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second);
172 }
173
174 OGS_FATAL(
175 "Configuration errors occurred. Please fix the project file.");
176 }
177
178 return material_properties;
179}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:28
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:34
OGS_NO_DANGLING Parameter< ParameterDataType > & findParameter(std::string const &parameter_name, std::vector< std::unique_ptr< ParameterBase > > const &parameters, int const num_components, MeshLib::Mesh const *const mesh=nullptr)

References ERR(), ParameterLib::findParameter(), BaseLib::ConfigTree::getConfigSubtree(), INFO(), OGS_FATAL, and WARN().

◆ readStateVariablesInitialValueProperties()

std::map< std::string, ParameterLib::Parameter< double > const * > anonymous_namespace{CreateMFrontGeneric.cpp}::readStateVariablesInitialValueProperties ( mgis::behaviour::Behaviour const & behaviour,
mgis::behaviour::Hypothesis const & hypothesis,
std::vector< std::unique_ptr< ParameterLib::ParameterBase > > const & parameters,
BaseLib::ConfigTree const & config )
Input File Parameter
material__solid__constitutive_relation__MFront__initial_values
Input File Parameter
material__solid__constitutive_relation__MFront__initial_values__state_variable
Input File Parameter
material__solid__constitutive_relation__MFront__initial_values__state_variable__name
Input File Parameter
material__solid__constitutive_relation__MFront__initial_values__state_variable__parameter

Definition at line 184 of file CreateMFrontGeneric.cpp.

189{
190 if (behaviour.isvs.empty())
191 {
192 return {};
193 }
194
195 // gather state variables from the prj file
196 auto const initial_values_config =
198 config.getConfigSubtreeOptional("initial_values");
199 if (!initial_values_config)
200 {
201 return {};
202 }
203
204 std::map<std::string, std::string> map_name_to_param;
205 for (
206 auto const c :
208 initial_values_config->getConfigParameterList("state_variable"))
209 {
211 auto name = c.getConfigAttribute<std::string>("name");
213 auto param_name = c.getConfigAttribute<std::string>("parameter");
214
215 map_name_to_param.emplace(std::move(name), std::move(param_name));
216 }
217
218 std::map<std::string, ParameterLib::Parameter<double> const*>
219 state_variables_initial_properties;
220 for (auto const& isv : behaviour.isvs)
221 {
222 auto const it = map_name_to_param.find(isv.name);
223
224 // Not all internal state variables might need initialization and are
225 // skipped.
226 if (it == map_name_to_param.end())
227 {
228 continue;
229 }
230
231 auto const& param_name = it->second;
232 auto const num_comp = mgis::behaviour::getVariableSize(isv, hypothesis);
233 auto const* param = &ParameterLib::findParameter<double>(
234 param_name, parameters, num_comp);
235
236 INFO(
237 "Using OGS parameter `{:s}' for initial value of internal "
238 "state variable `{:s}'.",
239 param_name, isv.name);
240
241 using V = mgis::behaviour::Variable;
242 if (isv.type == V::STENSOR || isv.type == V::TENSOR)
243 {
244 WARN(
245 "State variable `{:s}' is a tensorial quantity. You, the user, "
246 "have to make sure that the component order of parameter "
247 "`{:s}' matches the one required by MFront!",
248 isv.name, param_name);
249 }
250
251 state_variables_initial_properties[isv.name] = param;
252 map_name_to_param.erase(it);
253 }
254
255 if (!map_name_to_param.empty())
256 {
257 ERR("Some state variables initial value parameters that were "
258 "configured are not used by the material model.");
259 ERR("These parameters are:");
260
261 for (auto const& e : map_name_to_param)
262 {
263 ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second);
264 }
265
266 OGS_FATAL(
267 "Configuration errors occurred. Please fix the project file.");
268 }
269
270 return state_variables_initial_properties;
271}

References ERR(), ParameterLib::findParameter(), BaseLib::ConfigTree::getConfigSubtreeOptional(), INFO(), OGS_FATAL, and WARN().

◆ toString() [1/2]

const char * anonymous_namespace{CreateMFrontGeneric.cpp}::toString ( mgis::behaviour::Behaviour::Kinematic kin)

Definition at line 37 of file CreateMFrontGeneric.cpp.

38{
39 using K = mgis::behaviour::Behaviour::Kinematic;
40 switch (kin)
41 {
42 case K::UNDEFINEDKINEMATIC:
43 return "UNDEFINEDKINEMATIC";
44 case K::SMALLSTRAINKINEMATIC:
45 return "SMALLSTRAINKINEMATIC";
46 case K::COHESIVEZONEKINEMATIC:
47 return "COHESIVEZONEKINEMATIC";
48 case K::FINITESTRAINKINEMATIC_F_CAUCHY:
49 return "FINITESTRAINKINEMATIC_F_CAUCHY";
50 case K::FINITESTRAINKINEMATIC_ETO_PK1:
51 return "FINITESTRAINKINEMATIC_ETO_PK1";
52 }
53
54 OGS_FATAL("Unknown kinematic {}.", BaseLib::to_underlying(kin));
55}
constexpr auto to_underlying(E e) noexcept
Converts an enumeration to its underlying type.
Definition cpp23.h:22

References OGS_FATAL, and BaseLib::to_underlying().

◆ toString() [2/2]

const char * anonymous_namespace{CreateMFrontGeneric.cpp}::toString ( mgis::behaviour::Behaviour::Symmetry sym)

Definition at line 57 of file CreateMFrontGeneric.cpp.

58{
59 using S = mgis::behaviour::Behaviour::Symmetry;
60 switch (sym)
61 {
62 case S::ISOTROPIC:
63 return "ISOTROPIC";
64 case S::ORTHOTROPIC:
65 return "ORTHOTROPIC";
66 }
67
68 OGS_FATAL("Unknown symmetry {}.", BaseLib::to_underlying(sym));
69}

References OGS_FATAL, and BaseLib::to_underlying().

◆ varInfo() [1/2]

void anonymous_namespace{CreateMFrontGeneric.cpp}::varInfo ( std::string const & msg,
std::vector< mgis::behaviour::Variable > const & vars,
mgis::behaviour::Hypothesis hypothesis )

Prints info about MFront variables.

Definition at line 72 of file CreateMFrontGeneric.cpp.

75{
76 INFO("#{:s}: {:d} (array size {:d}).",
77 msg,
78 vars.size(),
79 mgis::behaviour::getArraySize(vars, hypothesis));
80 for (auto const& var : vars)
81 {
82 INFO(" --> type `{:s}' with name `{:s}', size {:d}, offset {:d}.",
84 var.name,
85 mgis::behaviour::getVariableSize(var, hypothesis),
86 mgis::behaviour::getVariableOffset(vars, var.name, hypothesis));
87 }
88}
const char * varTypeToString(int v)

References INFO(), and MaterialLib::Solids::MFront::varTypeToString().

◆ varInfo() [2/2]

void anonymous_namespace{CreateMFrontGeneric.cpp}::varInfo ( std::string const & msg,
std::vector< std::string > const & parameters )

Prints info about MFront parameters.

Definition at line 91 of file CreateMFrontGeneric.cpp.

92{
93 INFO("#{:s}: {:d}.", msg, parameters.size());
94 for (auto const& parameter : parameters)
95 {
96 INFO(" --> with name `{:s}'.", parameter);
97 }
98}

References INFO().