Skip to content

Commit 3677592

Browse files
committed
Fix Issue thelfer#95
1 parent e88c8b0 commit 3677592

File tree

4 files changed

+102
-14
lines changed

4 files changed

+102
-14
lines changed

docs/web/release-notes-2.1.md

+20
Original file line numberDiff line numberDiff line change
@@ -184,8 +184,28 @@ auto outputs = allocatePostProcessingVariables(m, "PrincipalStrain");
184184
executePostProcessing(outputs, m, "PrincipalStrain");
185185
~~~~
186186

187+
## Utility function to extract the value of an internal state variable {#sec:mgis:2.1:extractInternalStateVariable}
188+
189+
The `extractInternalStateVariable` function can now be used to extract
190+
the value of an internal state variable in a pre-allocated buffer.
191+
192+
### Example of usage
193+
194+
~~~~{.cxx}
195+
auto m = MaterialDataManager{b, 2u};
196+
...
197+
auto pr = std::vector<real>(2u);
198+
extractInternalStateVariable(pr, m.s1, "HydrostaticPressure");
199+
~~~~
200+
187201
# Issues solved
188202

203+
## Issue #95: Add an utility function to extract the value of an internal state variable
204+
205+
This feature is described in Section @sec:mgis:2.1:extractInternalStateVariable.
206+
207+
For more details, see <https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/95>.
208+
189209
## Issue #83: Add support for extended variable types
190210

191211
This feature is described in depth in Section @sec:mgis:2.1:extended_types.

include/MGIS/Behaviour/MaterialStateManager.hxx

+20-7
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,14 @@ namespace mgis::behaviour {
174174
std::vector<mgis::real> stored_energies_values;
175175
//! \brief value of the dissipated energies, if hold internally
176176
std::vector<mgis::real> dissipated_energies_values;
177-
//! move constructor
177+
//! \brief move constructor
178178
MaterialStateManager(MaterialStateManager&&) = delete;
179-
//! copy constructor
179+
//! \brief copy constructor
180180
MaterialStateManager(const MaterialStateManager&) = delete;
181-
//! move assignement
181+
//! \brief move assignement
182182
MaterialStateManager& operator=(MaterialStateManager&&) = delete;
183-
//! copy assignement
183+
//! \brief copy assignement
184184
MaterialStateManager& operator=(const MaterialStateManager&) = delete;
185-
186185
}; // end of struct MaterialStateManager
187186

188187
/*!
@@ -269,8 +268,22 @@ namespace mgis::behaviour {
269268
* \param[out] o: output state
270269
* \param[out] i: input state
271270
*/
272-
MGIS_EXPORT void update_values(MaterialStateManager&,
273-
const MaterialStateManager&);
271+
MGIS_EXPORT void updateValues(MaterialStateManager&,
272+
const MaterialStateManager&);
273+
/*!
274+
* \brief extract an internal state variable
275+
*
276+
* \param[out] o: buffer in which the values of the given internal state
277+
* variable is stored
278+
* \param[in] s: material state manager
279+
* \param[in] n: name of the internal state variables
280+
*
281+
* \note the output buffer must be allocated properly
282+
*/
283+
MGIS_EXPORT void extractInternalStateVariable(
284+
mgis::span<mgis::real>,
285+
const mgis::behaviour::MaterialStateManager&,
286+
const mgis::string_view);
274287

275288
} // end of namespace mgis::behaviour
276289

src/MaterialDataManager.cxx

+2-2
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,12 @@ namespace mgis::behaviour {
167167

168168
void update(MaterialDataManager& m) {
169169
std::fill(m.K.begin(), m.K.end(), real{0});
170-
update_values(m.s0, m.s1);
170+
updateValues(m.s0, m.s1);
171171
} // end of update
172172

173173
void revert(MaterialDataManager& m) {
174174
std::fill(m.K.begin(), m.K.end(), real{0});
175-
update_values(m.s1, m.s0);
175+
updateValues(m.s1, m.s0);
176176
} // end of update
177177

178178
std::vector<mgis::real> allocatePostProcessingVariables(

src/MaterialStateManager.cxx

+60-5
Original file line numberDiff line numberDiff line change
@@ -261,11 +261,11 @@ namespace mgis::behaviour {
261261
return std::holds_alternative<real>(p->second);
262262
} // end of isExternalStateVariableUniform
263263

264-
void update_values(MaterialStateManager& o, const MaterialStateManager& i) {
264+
void updateValues(MaterialStateManager& o, const MaterialStateManager& i) {
265265
auto check_size = [](const mgis::size_type s1, const mgis::size_type s2) {
266266
if (s1 != s2) {
267267
mgis::raise(
268-
"mgis::behaviour::update_values: "
268+
"mgis::behaviour::updateValues: "
269269
"arrays' size does not match");
270270
}
271271
}; // end of check_size
@@ -323,7 +323,7 @@ namespace mgis::behaviour {
323323
if (std::find_if(b.mps.begin(), b.mps.end(), find_mp) ==
324324
b.mps.end()) {
325325
mgis::raise(
326-
"mgis::behaviour::update_values: "
326+
"mgis::behaviour::updateValues: "
327327
"material property '" +
328328
mp.first +
329329
"' defined in the material state manager is not defined "
@@ -333,7 +333,7 @@ namespace mgis::behaviour {
333333
};
334334
if (&i.b != &o.b) {
335335
mgis::raise(
336-
"mgis::behaviour::update_values: the material state managers "
336+
"mgis::behaviour::updateValues: the material state managers "
337337
"do not holds the same behaviour");
338338
}
339339
check_mps(o.b, i.material_properties);
@@ -365,6 +365,61 @@ namespace mgis::behaviour {
365365
for (const auto& ev : i.external_state_variables) {
366366
update_field_holder(o.external_state_variables[ev.first], ev.second);
367367
}
368-
} // end of update_values
368+
} // end of updateValues
369+
370+
namespace internals {
371+
372+
void extractScalarInternalStateVariable(
373+
mgis::span<mgis::real> o,
374+
const mgis::behaviour::MaterialStateManager& s,
375+
const mgis::size_type offset) {
376+
const auto stride = s.internal_state_variables_stride;
377+
auto* const p = o.data();
378+
const auto* const piv = s.internal_state_variables.data() + offset;
379+
for (mgis::size_type i = 0; i != s.n; ++i) {
380+
p[i] = piv[i * stride];
381+
}
382+
} // end of extractScalarInternalStateVariable
383+
384+
void extractInternalStateVariable(
385+
mgis::span<mgis::real> o,
386+
const mgis::behaviour::MaterialStateManager& s,
387+
const mgis::size_type nc,
388+
const mgis::size_type offset) {
389+
const auto stride = s.internal_state_variables_stride;
390+
auto* p = o.data();
391+
const auto* const piv = s.internal_state_variables.data() + offset;
392+
for (mgis::size_type i = 0; i != s.n; ++i) {
393+
const auto is = i * stride;
394+
for (mgis::size_type j = 0; j != nc; ++j, ++p) {
395+
*p = piv[is + j];
396+
}
397+
}
398+
} // end of extractScalarInternalStateVariable
399+
400+
} // end of namespace internals
401+
402+
void extractInternalStateVariable(
403+
mgis::span<mgis::real> o,
404+
const mgis::behaviour::MaterialStateManager& s,
405+
const mgis::string_view n) {
406+
const auto& iv = mgis::behaviour::getVariable(s.b.isvs, n);
407+
const auto nc = mgis::behaviour::getVariableSize(iv, s.b.hypothesis);
408+
const auto offset =
409+
mgis::behaviour::getVariableOffset(s.b.isvs, n, s.b.hypothesis);
410+
// checking compatibility
411+
if (o.size() != s.n * nc) {
412+
mgis::raise(
413+
"extractInternalStateVariable: "
414+
"unmatched number of integration points");
415+
}
416+
if (nc == 1) {
417+
mgis::behaviour::internals::extractScalarInternalStateVariable(o, s,
418+
offset);
419+
} else {
420+
mgis::behaviour::internals::extractInternalStateVariable(o, s, nc,
421+
offset);
422+
}
423+
} // end of extractInternalStateVariable
369424

370425
} // end of namespace mgis::behaviour

0 commit comments

Comments
 (0)