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 return "GENERALBEHAVIOUR";
19 if (btype == B::STANDARDSTRAINBASEDBEHAVIOUR)
20 return "STANDARDSTRAINBASEDBEHAVIOUR";
21 if (btype == B::STANDARDFINITESTRAINBEHAVIOUR)
22 return "STANDARDFINITESTRAINBEHAVIOUR";
23 if (btype == B::COHESIVEZONEMODEL)
24 return "COHESIVEZONEMODEL";
25
26 OGS_FATAL("Unknown behaviour type {}.", btype);
27}
#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 265 of file CreateMFrontGeneric.cpp.

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

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 92 of file CreateMFrontGeneric.cpp.

97{
98 if (behaviour.mps.empty())
99 {
100 return {};
101 }
102
103 std::map<std::string, std::string> map_name_to_param;
104
105 // gather material properties from the prj file
107 auto const mps_config = config.getConfigSubtree("material_properties");
108 for (
109 auto const& mp_config :
111 mps_config.getConfigParameterList("material_property"))
112 {
114 auto name = mp_config.getConfigAttribute<std::string>("name");
115 auto param_name =
117 mp_config.getConfigAttribute<std::string>("parameter");
118
119 map_name_to_param.emplace(std::move(name), std::move(param_name));
120 }
121
122 std::vector<ParameterLib::Parameter<double> const*> material_properties;
123 for (auto const& mp : behaviour.mps)
124 {
125 auto const it = map_name_to_param.find(mp.name);
126 if (it == map_name_to_param.end())
127 OGS_FATAL(
128 "Material Property `{:s}' has not been configured in the "
129 "project file.",
130 mp.name);
131
132 auto const& param_name = it->second;
133 auto const num_comp = mgis::behaviour::getVariableSize(mp, hypothesis);
134 auto const* param = &ParameterLib::findParameter<double>(
135 param_name, parameters, num_comp);
136
137 INFO("Using OGS parameter `{:s}' for material property `{:s}'.",
138 param_name, mp.name);
139
140 using V = mgis::behaviour::Variable;
141 if (mp.type == V::STENSOR || mp.type == V::TENSOR)
142 {
143 WARN(
144 "Material property `{:s}' is a tensorial quantity. You, "
145 "the "
146 "user, have to make sure that the component order of "
147 "parameter `{:s}' matches the one required by MFront!",
148 mp.name, param_name);
149 }
150
151 material_properties.push_back(param);
152 map_name_to_param.erase(it);
153 }
154
155 if (!map_name_to_param.empty())
156 {
157 ERR("Some material parameters that were configured are not used by "
158 "the material model.");
159 ERR("These parameters are:");
160
161 for (auto const& e : map_name_to_param)
162 {
163 ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second);
164 }
165
166 OGS_FATAL(
167 "Configuration errors occurred. Please fix the project file.");
168 }
169
170 return material_properties;
171}
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 176 of file CreateMFrontGeneric.cpp.

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

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 29 of file CreateMFrontGeneric.cpp.

30{
31 using K = mgis::behaviour::Behaviour::Kinematic;
32 switch (kin)
33 {
34 case K::UNDEFINEDKINEMATIC:
35 return "UNDEFINEDKINEMATIC";
36 case K::SMALLSTRAINKINEMATIC:
37 return "SMALLSTRAINKINEMATIC";
38 case K::COHESIVEZONEKINEMATIC:
39 return "COHESIVEZONEKINEMATIC";
40 case K::FINITESTRAINKINEMATIC_F_CAUCHY:
41 return "FINITESTRAINKINEMATIC_F_CAUCHY";
42 case K::FINITESTRAINKINEMATIC_ETO_PK1:
43 return "FINITESTRAINKINEMATIC_ETO_PK1";
44 }
45
46 OGS_FATAL("Unknown kinematic {}.", BaseLib::to_underlying(kin));
47}
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 49 of file CreateMFrontGeneric.cpp.

50{
51 using S = mgis::behaviour::Behaviour::Symmetry;
52 switch (sym)
53 {
54 case S::ISOTROPIC:
55 return "ISOTROPIC";
56 case S::ORTHOTROPIC:
57 return "ORTHOTROPIC";
58 }
59
60 OGS_FATAL("Unknown symmetry {}.", BaseLib::to_underlying(sym));
61}

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 64 of file CreateMFrontGeneric.cpp.

67{
68 INFO("#{:s}: {:d} (array size {:d}).",
69 msg,
70 vars.size(),
71 mgis::behaviour::getArraySize(vars, hypothesis));
72 for (auto const& var : vars)
73 {
74 INFO(" --> type `{:s}' with name `{:s}', size {:d}, offset {:d}.",
76 var.name,
77 mgis::behaviour::getVariableSize(var, hypothesis),
78 mgis::behaviour::getVariableOffset(vars, var.name, hypothesis));
79 }
80}
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 83 of file CreateMFrontGeneric.cpp.

84{
85 INFO("#{:s}: {:d}.", msg, parameters.size());
86 for (auto const& parameter : parameters)
87 {
88 INFO(" --> with name `{:s}'.", parameter);
89 }
90}

References INFO().