Skip to content

Commit cbe458b

Browse files
committedMar 4, 2020
Fix Issue thelfer#32
1 parent 96fe5b6 commit cbe458b

File tree

5 files changed

+58
-5
lines changed

5 files changed

+58
-5
lines changed
 

‎include/MGIS/Behaviour/BehaviourDataView.hxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ struct mgis_bv_BehaviourDataView {
8787
/*!
8888
* \brief state at the beginning of the time step
8989
*/
90-
mgis_bv_StateView s0;
90+
mgis_bv_InitialStateView s0;
9191
/*!
9292
* \brief state at the end of the time step
9393
*/

‎include/MGIS/Behaviour/State.hxx

+7
Original file line numberDiff line numberDiff line change
@@ -387,6 +387,13 @@ namespace mgis {
387387
* \note the view has at most the same life time as the state.
388388
*/
389389
MGIS_EXPORT StateView make_view(State&);
390+
/*!
391+
* \brief make a view from a behaviour data
392+
* \param[in] s: state
393+
* \return the view
394+
* \note the view has at most the same life time as the state.
395+
*/
396+
MGIS_EXPORT InitialStateView make_view(const State&);
390397
/*!
391398
* \brief print a detailled (verbose) description of the integration point
392399
* state using a markdown format

‎include/MGIS/Behaviour/StateView.hxx

+31-3
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ extern "C" {
3030
*/
3131
typedef struct{
3232
//! \brief value of the gradients
33-
mgis_real * gradients;
33+
const mgis_real* gradients;
3434
//! \brief values of the thermodynamic_forces
3535
mgis_real * thermodynamic_forces;
3636
//! \brief values of the material properties
37-
mgis_real * material_properties;
37+
const mgis_real* material_properties;
3838
//! \brief values of the internal state variables
3939
mgis_real * internal_state_variables;
4040
/*!
@@ -48,9 +48,35 @@ typedef struct{
4848
*/
4949
mgis_real* dissipated_energy;
5050
//! \brief values of the external state variables
51-
mgis_real * external_state_variables;
51+
const mgis_real* external_state_variables;
5252
} mgis_bv_StateView;
5353

54+
/*!
55+
* \brief state of the material
56+
*/
57+
typedef struct{
58+
//! \brief value of the gradients
59+
const mgis_real* gradients;
60+
//! \brief values of the thermodynamic_forces
61+
const mgis_real* thermodynamic_forces;
62+
//! \brief values of the material properties
63+
const mgis_real* material_properties;
64+
//! \brief values of the internal state variables
65+
const mgis_real* internal_state_variables;
66+
/*!
67+
* \brief stored energy (computed by `@InternalEnergy` in `MFront`
68+
* files) This output is optional.
69+
*/
70+
const mgis_real* stored_energy;
71+
/*!
72+
* \brief stored energy (computed by `@DissipatedEnergy` in `MFront`
73+
* files) This output is optional.
74+
*/
75+
const mgis_real* dissipated_energy;
76+
//! \brief values of the external state variables
77+
const mgis_real* external_state_variables;
78+
} mgis_bv_InitialStateView;
79+
5480
#ifdef __cplusplus
5581
}
5682
#endif /* __cplusplus */
@@ -63,6 +89,8 @@ namespace mgis {
6389

6490
//! a simple alias
6591
using StateView = ::mgis_bv_StateView;
92+
//! a simple alias
93+
using InitialStateView = ::mgis_bv_InitialStateView;
6694

6795
} // end of namespace behaviour
6896

‎src/BehaviourData.cxx

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ namespace mgis {
6464
v.dt = d.dt;
6565
v.rdt = d.rdt;
6666
v.K = get_ptr(d.K);
67-
v.s0 = make_view(d.s0);
67+
v.s0 = make_view(static_cast<const State&>(d.s0));
6868
v.s1 = make_view(d.s1);
6969
return v;
7070
} // end of make_view

‎src/State.cxx

+18
Original file line numberDiff line numberDiff line change
@@ -340,6 +340,24 @@ namespace mgis {
340340
return v;
341341
} // end of make_view
342342

343+
InitialStateView make_view(const State& s) {
344+
auto get_ptr = [](const std::vector<real>& v) -> const real* {
345+
if (v.empty()) {
346+
return nullptr;
347+
}
348+
return &v[0];
349+
}; // end of get_ptr
350+
InitialStateView v;
351+
v.gradients = get_ptr(s.gradients);
352+
v.thermodynamic_forces = get_ptr(s.thermodynamic_forces);
353+
v.material_properties = get_ptr(s.material_properties);
354+
v.internal_state_variables = get_ptr(s.internal_state_variables);
355+
v.stored_energy = &s.stored_energy;
356+
v.dissipated_energy = &s.dissipated_energy;
357+
v.external_state_variables = get_ptr(s.external_state_variables);
358+
return v;
359+
} // end of make_view
360+
343361
static void print_variables(std::ostream& os,
344362
const Behaviour& b,
345363
const std::vector<Variable>& variables,

0 commit comments

Comments
 (0)
Please sign in to comment.