Skip to content

Commit 2c6e921

Browse files
committed
Fix Issue #54
1 parent faf8ff2 commit 2c6e921

15 files changed

Lines changed: 308 additions & 72 deletions

bindings/c/include/MGIS/Behaviour/Behaviour.h

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -707,6 +707,20 @@ MGIS_C_EXPORT mgis_status mgis_bv_behaviour_get_lower_physical_bound(
707707
*/
708708
MGIS_C_EXPORT mgis_status mgis_bv_behaviour_get_upper_physical_bound(
709709
long double* const, const mgis_bv_Behaviour* const, const char* const);
710+
/*!
711+
* \brief return if the behaviour computes the stored energy
712+
* \param[out] v: returned value
713+
* \param[in] b: behaviour
714+
*/
715+
MGIS_C_EXPORT mgis_status mgis_bv_behaviour_computes_stored_energy(
716+
int* const, const mgis_bv_Behaviour* const );
717+
/*!
718+
* \brief return if the behaviour computes the dissipated energy
719+
* \param[out] v: returned value
720+
* \param[in] b: behaviour
721+
*/
722+
MGIS_C_EXPORT mgis_status mgis_bv_behaviour_computes_dissipated_energy(
723+
int* const, const mgis_bv_Behaviour* const);
710724
/*!
711725
* \brief free the memory associated with the given behaviour.
712726
* \param[in,out] b: behaviour

bindings/c/src/Behaviour.cxx

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -990,6 +990,24 @@ mgis_bv_finite_strain_behaviour_options_set_tangent_operator_by_string(
990990
return mgis_report_success();
991991
} // end of mgis_bv_behaviour_get_upper_physical_bound
992992

993+
mgis_status mgis_bv_behaviour_computes_stored_energy(
994+
int* const v, const mgis_bv_Behaviour* const b) {
995+
if ((b == nullptr) || (v == nullptr)) {
996+
return mgis_report_failure("invalid argument");
997+
}
998+
*v = static_cast<int>(b->computesStoredEnergy);
999+
return mgis_report_success();
1000+
} // end of mgis_bv_behaviour_computes_stored_energy
1001+
1002+
mgis_status mgis_bv_behaviour_computes_dissipated_energy(
1003+
int* const v, const mgis_bv_Behaviour* const b) {
1004+
if ((b == nullptr) || (v == nullptr)) {
1005+
return mgis_report_failure("invalid argument");
1006+
}
1007+
*v = static_cast<int>(b->computesDissipatedEnergy);
1008+
return mgis_report_success();
1009+
} // end of mgis_bv_behaviour_computes_dissipated_energy
1010+
9931011
mgis_status mgis_bv_free_behaviour(mgis_bv_Behaviour * *b) {
9941012
try {
9951013
delete *b;

bindings/fortran/src/mgis_behaviour.f95

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,6 +1355,71 @@ end function behaviour_get_external_state_variable_type_wrapper
13551355
s = behaviour_get_external_state_variable_type_wrapper(t, b%ptr, nc)
13561356
end function behaviour_get_external_state_variable_type
13571357
!
1358+
function behaviour_computes_stored_energy(v, b) result(s)
1359+
use, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan
1360+
use, intrinsic :: iso_c_binding, only: c_int
1361+
use mgis_fortran_utilities
1362+
use mgis, only: mgis_status, MGIS_SUCCESS
1363+
implicit none
1364+
interface
1365+
function behaviour_computes_stored_energy_wrapper(v, b) &
1366+
bind(c,name='mgis_bv_behaviour_computes_stored_energy') result(s)
1367+
use, intrinsic :: iso_c_binding, only: c_ptr, c_int
1368+
use mgis, only: mgis_status
1369+
integer(kind=c_int), intent(out) :: v
1370+
type(c_ptr), intent(in), value :: b
1371+
type(mgis_status) :: s
1372+
end function behaviour_computes_stored_energy_wrapper
1373+
end interface
1374+
logical, intent(out) :: v
1375+
type(Behaviour), intent(in) :: b
1376+
type(mgis_status) :: s
1377+
integer(kind=c_int) :: vc
1378+
s = behaviour_computes_stored_energy_wrapper(vc, b%ptr)
1379+
if( s % exit_status .eq. MGIS_SUCCESS) then
1380+
if (vc .eq. 1) then
1381+
v = .TRUE.
1382+
else
1383+
v = .FALSE.
1384+
end if
1385+
else
1386+
v = .FALSE.
1387+
end if
1388+
end function behaviour_computes_stored_energy
1389+
!
1390+
function behaviour_computes_dissipated_energy(v, b) result(s)
1391+
use, intrinsic :: ieee_arithmetic, only: ieee_value, ieee_quiet_nan
1392+
use, intrinsic :: iso_c_binding, only: c_int
1393+
use mgis_fortran_utilities
1394+
use mgis, only: mgis_status, MGIS_SUCCESS
1395+
implicit none
1396+
interface
1397+
function behaviour_computes_dissipated_energy_wrapper(v, b) &
1398+
bind(c,name='mgis_bv_behaviour_computes_dissipated_energy') &
1399+
result(s)
1400+
use, intrinsic :: iso_c_binding, only: c_ptr, c_int
1401+
use mgis, only: mgis_status
1402+
integer(kind=c_int), intent(out) :: v
1403+
type(c_ptr), intent(in), value :: b
1404+
type(mgis_status) :: s
1405+
end function behaviour_computes_dissipated_energy_wrapper
1406+
end interface
1407+
logical, intent(out) :: v
1408+
type(Behaviour), intent(in) :: b
1409+
type(mgis_status) :: s
1410+
integer(kind=c_int) :: vc
1411+
s = behaviour_computes_dissipated_energy_wrapper(vc, b%ptr)
1412+
if( s % exit_status .eq. MGIS_SUCCESS) then
1413+
if (vc .eq. 1) then
1414+
v = .TRUE.
1415+
else
1416+
v = .FALSE.
1417+
end if
1418+
else
1419+
v = .FALSE.
1420+
end if
1421+
end function behaviour_computes_dissipated_energy
1422+
!
13581423
function behaviour_has_bounds(r, b, n) result(s)
13591424
use, intrinsic :: iso_c_binding, only: c_int
13601425
use mgis_fortran_utilities

bindings/python/mgis/fenics/nonlinear_material.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,5 +154,5 @@ def get_tangent_block_names(self):
154154
return [(t[0].name, t[1].name) for t in self.behaviour.tangent_operator_blocks]
155155

156156
def get_tangent_block_sizes(self):
157-
return [tuple([mgis_bv.getVariableSize(tt, self.hypothesis) for tt in t]) \
157+
return [tuple([mgis_bv.getVariableSize(tt, self.hypothesis) for tt in t])
158158
for t in self.behaviour.tangent_operator_blocks]

bindings/python/src/Behaviour.cxx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,12 @@ void declareBehaviour() {
354354
"version of TFEL used to generate the behaviour")
355355
.add_property("btype", &Behaviour::btype,
356356
"return the type of the behaviour")
357+
.def_readonly(
358+
"computesStoredEnergy", &Behaviour::computesStoredEnergy,
359+
"a boolean stating if the behaviour computes the stored energy")
360+
.def_readonly(
361+
"computesDissipatedEnergy", &Behaviour::computesDissipatedEnergy,
362+
"a boolean stating if the behaviour computes the dissipated energy")
357363
.def("getBehaviourType", &Behaviour_getType,
358364
"return the type of the behaviour")
359365
.add_property("kinematic", &Behaviour::kinematic,

bindings/python/src/MaterialStateManager.cxx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,21 @@ static boost::python::object MaterialStateManager_getInternalStateVariables(
6969

7070
static boost::python::object MaterialStateManager_getStoredEnergies(
7171
mgis::behaviour::MaterialStateManager& s) {
72+
if (!s.b.computesStoredEnergy) {
73+
mgis::raise(
74+
"MaterialStateManager_getStoredEnergies: "
75+
"the stored energy is not computed by the behaviour");
76+
}
7277
return mgis::python::wrapInNumPyArray(s.stored_energies);
7378
} // end of MaterialStateManager_getStoredEnergy
7479

7580
static boost::python::object MaterialStateManager_getDissipatedEnergies(
7681
mgis::behaviour::MaterialStateManager& s) {
82+
if (!s.b.computesDissipatedEnergy) {
83+
mgis::raise(
84+
"MaterialStateManager_getDissipatedEnergies: "
85+
"the dissipated energy is not computed by the behaviour");
86+
}
7787
return mgis::python::wrapInNumPyArray(s.dissipated_energies);
7888
} // end of MaterialStateManager_getDissipatedEnergy
7989

docs/web/release-notes-1.2.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,12 @@ bibliography: bibliography.bib
2121
Version 1.2 of `MFrontGenericInterfaceSupport` is compatible with the
2222
Version 3.4 of `TFEL/MFront`.
2323

24+
# Known incompatibilities
25+
26+
The `stored_energies` and `dissipated_energies` are now automatically
27+
allocated only of the behaviours by the `MaterialStateManager` class
28+
only if the behaviours is able to compute them.
29+
2430
# New functionalities
2531

2632
## Orthotropic behaviours
@@ -121,6 +127,24 @@ module:
121127

122128
# Issues solved
123129

130+
## Issues #54: Inform the calling code about `@DissipatedEnergy` and/or `@InternalEnergy`
131+
132+
The `Behaviour` class now exposes two new boolean data members:
133+
134+
- `computesStoredEnergy`: if true, the behaviour computes the stored energy
135+
- `computesDissipatedEnergy`: if false, the behaviour computes the dissipated energy
136+
137+
In the `C` bindings, the `mgis_bv_behaviour_computes_stored_energy` and `mgis_bv_behaviour_computes_dissipated_energy` functions are now available.
138+
139+
In the `fortran` bindings, the functions `behaviour_computes_stored_energy` and `behaviour_computes_dissipated_energy` are now available in the `mgis_behaviour` module.
140+
141+
In the `python` bindings, the `Behaviour` class now exposes two read only properties: `computesStoredEnergy` and `computesDissipatedEnergy`.
142+
143+
The `MaterialDataManager` constructor now only allocates the memory associated with the stored and disspated energies only if the behaviour computes those energies.
144+
145+
For details, see <https://github.com/thelfer/MFrontGenericInterfaceSupport/issues/54>
146+
147+
124148
## Issue #33: Function for checking if the behaviour is a Finite Strain one
125149

126150
The `mgis::behaviour::isStandardFiniteStrainBehaviour` has been added to

include/MGIS/Behaviour/Behaviour.hxx

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,40 @@ namespace mgis {
118118
FINITESTRAINKINEMATIC_F_CAUCHY,
119119
FINITESTRAINKINEMATIC_ETO_PK1
120120
} kinematic;
121-
//! behaviour symmetry
121+
//! \brief behaviour symmetry
122122
Symmetry symmetry;
123-
//! gradients
123+
//! \brief gradients
124124
std::vector<Variable> gradients;
125-
//! thermodynamic forces associated to gradients
125+
//! \brief thermodynamic forces associated to gradients
126126
std::vector<Variable> thermodynamic_forces;
127-
//! material properties
127+
//! \brief material properties
128128
std::vector<Variable> mps;
129-
//! internal state variables
129+
//! \brief internal state variables
130130
std::vector<Variable> isvs;
131-
//! external state variables
131+
//! \brief external state variables
132132
std::vector<Variable> esvs;
133-
//! tangent operator blocks
133+
//! \brief tangent operator blocks
134134
std::vector<std::pair<Variable, Variable>> to_blocks;
135-
//! real parameters
135+
//! \brief real parameters
136136
std::vector<std::string> params;
137-
//! integer parameters
137+
//! \brief integer parameters
138138
std::vector<std::string> iparams;
139-
//! unsigned short parameters
139+
//! \brief unsigned short parameters
140140
std::vector<std::string> usparams;
141+
/*!
142+
* \brief this boolean is true if the behaviour computes the
143+
* energy stored by the material per unit of volume in the reference
144+
* configuration. The physical meaning of this
145+
* energy depends on the behaviour considered.
146+
*/
147+
bool computesStoredEnergy;
148+
/*!
149+
* \brief this boolean is true if the behaviour computes the
150+
* energy dissipated by the material per unit of volume in the
151+
* reference configuration. The physical meaning of this
152+
* energy depends on the behaviour considered.
153+
*/
154+
bool computesDissipatedEnergy;
141155
/*!
142156
* \brief behaviour options
143157
*

include/MGIS/Behaviour/MaterialDataManager.hxx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,6 @@ namespace mgis {
109109
MaterialDataManager& operator=(MaterialDataManager&&) = delete;
110110
//! copy assignement
111111
MaterialDataManager& operator=(const MaterialDataManager&) = delete;
112-
113112
}; // end of struct MaterialDataManager
114113

115114
/*!

include/MGIS/Behaviour/MaterialStateManager.hxx

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ namespace mgis {
4242
/*!
4343
* \brief view to an externally allocated memory used to store the
4444
* gradients. If empty, the material state manager will
45-
* initialize the required memory internally.
45+
* initialize the required memory internally.
4646
*/
4747
mgis::span<mgis::real> gradients;
4848
/*!
@@ -60,13 +60,23 @@ namespace mgis {
6060
/*!
6161
* \brief view to an externally allocated memory used to store the stored
6262
* energies. If empty, the material state manager will initialize the
63-
* required memory internally.
63+
* required memory internally, if the behaviour computes the stored
64+
* energy.
65+
*
66+
* \note for backward compatibililty, the user may allocate memory for the
67+
* stored energies even if the behaviour don't compute the stored
68+
* energy.
6469
*/
6570
mgis::span<mgis::real> stored_energies;
6671
/*!
6772
* \brief view to an externally allocated memory used to store the
6873
* dissipated energies. If empty, the material state manager will
69-
* initialize the required memory internally.
74+
* initialize the required memory internally, if the behaviour computes
75+
* the dissipated energy.
76+
*
77+
* \note for backward compatibililty, the user may allocate memory for the
78+
* dissipated energies even if the behaviour don't compute the dissipated
79+
* energy.
7080
*/
7181
mgis::span<mgis::real> dissipated_energies;
7282
}; // end of MaterialStateManagerInitializer
@@ -93,10 +103,10 @@ namespace mgis {
93103
LOCAL_STORAGE, //! \brief use `std::vector` to store the data
94104
EXTERNAL_STORAGE //! \brief use `mgis::span` to store the data
95105
}; // end of StorageMode
96-
/*!
97-
* \param[in] behaviour: behaviour
98-
* \param[in] s: number of integration points
99-
*/
106+
/*!
107+
* \param[in] behaviour: behaviour
108+
* \param[in] s: number of integration points
109+
*/
100110
MaterialStateManager(const Behaviour&, const size_type);
101111
/*!
102112
* \param[in] behaviour: behaviour

0 commit comments

Comments
 (0)