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

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

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

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

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

103{
104 if (behaviour.mps.empty())
105 {
106 return {};
107 }
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 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 std::vector<ParameterLib::Parameter<double> const*> material_properties;
129 for (auto const& mp : behaviour.mps)
130 {
131 auto const it = map_name_to_param.find(mp.name);
132 if (it == map_name_to_param.end())
133 OGS_FATAL(
134 "Material Property `{:s}' has not been configured in the "
135 "project file.",
136 mp.name);
137
138 auto const& param_name = it->second;
139 auto const num_comp = mgis::behaviour::getVariableSize(mp, hypothesis);
140 auto const* param = &ParameterLib::findParameter<double>(
141 param_name, parameters, num_comp);
142
143 INFO("Using OGS parameter `{:s}' for material property `{:s}'.",
144 param_name, mp.name);
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, "
151 "the "
152 "user, have to make sure that the component order of "
153 "parameter `{:s}' matches the one required by MFront!",
154 mp.name, param_name);
155 }
156
157 material_properties.push_back(param);
158 map_name_to_param.erase(it);
159 }
160
161 if (!map_name_to_param.empty())
162 {
163 ERR("Some material parameters that were configured are not used by "
164 "the material model.");
165 ERR("These parameters are:");
166
167 for (auto const& e : map_name_to_param)
168 {
169 ERR(" name: `{:s}', parameter: `{:s}'.", e.first, e.second);
170 }
171
172 OGS_FATAL(
173 "Configuration errors occurred. Please fix the project file.");
174 }
175
176 return material_properties;
177}
void INFO(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:35
void ERR(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:45
void WARN(fmt::format_string< Args... > fmt, Args &&... args)
Definition Logging.h:40
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)
Definition Utils.h:102

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

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

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

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

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

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

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

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

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

References INFO().