Skip to content

Commit 0938356

Browse files
committed
First implementation
1 parent 4246528 commit 0938356

20 files changed

Lines changed: 705 additions & 65 deletions

include/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,14 @@ mgis_header(MGIS/Behaviour Behaviour.hxx)
2525
mgis_header(MGIS/Behaviour StateView.hxx)
2626
mgis_header(MGIS/Behaviour StateView.hxx)
2727
mgis_header(MGIS/Behaviour BehaviourData.hxx)
28+
mgis_header(MGIS/Behaviour BehaviourData.ixx)
2829
mgis_header(MGIS/Behaviour BehaviourDataView.hxx)
2930
mgis_header(MGIS/Behaviour State.hxx)
31+
mgis_header(MGIS/Behaviour State.Ixx)
3032
mgis_header(MGIS/Behaviour MaterialStateManager.hxx)
3133
mgis_header(MGIS/Behaviour MaterialDataManager.hxx)
3234
mgis_header(MGIS/Behaviour Integrate.hxx)
3335
mgis_header(MGIS/Behaviour Integrate.ixx)
36+
mgis_header(MGIS/Behaviour BehaviourIntegrationFailureAnalyser.hxx)
3437
mgis_header(MGIS/Behaviour FiniteStrainSupport.hxx)
3538
mgis_header(MGIS/Model Model.hxx)

include/MGIS/Behaviour/BehaviourData.hxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,6 @@ namespace mgis::behaviour {
146146

147147
} // end of namespace mgis::behaviour
148148

149+
#include "MGIS/Behaviour/BehaviourData.ixx"
150+
149151
#endif /* LIB_MGIS_BEHAVIOUR_BEHAVIOURDATA_HXX */
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*!
2+
* \file BehaviourData.ixx
3+
* \brief
4+
* \author Thomas Helfer
5+
* \date 02/08/2018
6+
* \copyright (C) Copyright Thomas Helfer 2018.
7+
* Use, modification and distribution are subject
8+
* to one of the following licences:
9+
* - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying
10+
* file LGPL-3.0.txt)
11+
* - CECILL-C, Version 1.0 (See accompanying files
12+
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
13+
*/
14+
15+
#ifndef LIB_MGIS_BEHAVIOUR_BEHAVIOURDATA_IXX
16+
#define LIB_MGIS_BEHAVIOUR_BEHAVIOURDATA_IXX
17+
18+
namespace mgis::behaviour {
19+
20+
inline BehaviourDataView make_view(BehaviourData& d) {
21+
auto get_ptr = [](std::vector<real>& v) -> real* {
22+
if (v.empty()) {
23+
return nullptr;
24+
}
25+
return &v[0];
26+
}; // end of get_ptr
27+
BehaviourDataView v;
28+
v.error_message = d.error_message;
29+
v.dt = d.dt;
30+
v.rdt = &(d.rdt);
31+
v.speed_of_sound = &(d.speed_of_sound);
32+
v.K = get_ptr(d.K);
33+
v.s0 = make_view(static_cast<const State&>(d.s0));
34+
v.s1 = make_view(d.s1);
35+
return v;
36+
} // end of make_view
37+
38+
} // end of namespace mgis::behaviour
39+
40+
41+
#endif /* LIB_MGIS_BEHAVIOUR_BEHAVIOURDATA_IXX */

include/MGIS/Behaviour/BehaviourDataView.hxx

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#define LIB_MGIS_BEHAVIOUR_BEHAVIOURDATAVIEW_HXX
1717

1818
#ifdef __cplusplus
19+
#include <iosfwd>
1920
#include "MGIS/Config.hxx"
2021
#else
2122
#include "MGIS/Config-c.h"
@@ -128,6 +129,20 @@ namespace mgis::behaviour {
128129
//! \brief a simple alias
129130
using BehaviourDataView = ::mgis_bv_BehaviourDataView;
130131

132+
/*!
133+
* \brief print a detailled (verbose) description of the data associated
134+
* with an integration point using a markdown format
135+
* \param[in] os: ouptut stream
136+
* \param[in] d: behaviour
137+
* \param[in] d: behaviour data
138+
* \param[in] l: title level
139+
*/
140+
MGIS_EXPORT void print_markdown(std::ostream&,
141+
const Behaviour&,
142+
const BehaviourDataView&,
143+
const mgis::size_type);
144+
145+
131146
} // end of namespace mgis::behaviour
132147

133148
#endif /* __cplusplus */
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/*!
2+
* \file MGIS/Behaviour/BehaviourIntegrationFailureAnalyser.hxx
3+
* \brief The header define some useful features for debugging purposes
4+
* \author Thomas Helfer
5+
* \date 21/08/2025
6+
*/
7+
8+
#ifndef LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX
9+
#define LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX
10+
11+
#include <string>
12+
#include <functional>
13+
#include <string_view>
14+
#include "MGIS/Config.hxx"
15+
#include "MGIS/Behaviour/BehaviourData.hxx"
16+
#include "MGIS/Behaviour/BehaviourDataView.hxx"
17+
18+
namespace mgis::behaviour {
19+
20+
// forward declarations
21+
struct Behaviour;
22+
23+
} // end of namespace mgis::behaviour
24+
25+
namespace mgis::behaviour::debug {
26+
27+
/*!
28+
* \brief object in charge of analysing and integration failure. This object
29+
* is used by the `integrate_debug` function
30+
*
31+
* \note most analysers generate a file. See the
32+
* `getBehaviourIntegrationFailureAnalysisFileName` below for a way to
33+
* generate a unique file name. By default, this file name is unique for the
34+
* given process. In an MPI context, one shall provide a file name generator
35+
* which takes the MPI process id into account to avoid conflicts, see the
36+
* function `setBehaviourIntegrationFailureAnalysisFileNameGenerator` for
37+
* details.
38+
*/
39+
struct MGIS_EXPORT BehaviourIntegrationFailureAnalyser {
40+
/*!
41+
* \brief handle an integration failure
42+
* \param[in] b: behaviour being integrated
43+
* \param[in] d: behaviour data leading to the integration failure
44+
*/
45+
virtual void analyse(const Behaviour&,
46+
const BehaviourData&) const noexcept = 0;
47+
/*!
48+
* \brief handle an integration failure
49+
* \param[in] b: behaviour being integrated
50+
* \param[in] d: behaviour data view leading to the integration failure
51+
*/
52+
virtual void analyse(const Behaviour&,
53+
const BehaviourDataView&) const noexcept = 0;
54+
/*!
55+
* \brief use a copy of the inputs
56+
*
57+
* If true, the behaviour data view passed to the `integrate_debug`
58+
* function is copied before integrating the behaviour. Copying has
59+
* a significant overhead and is normally not required for correctly written
60+
* behaviours but data corruption may occur, so copying is safer.
61+
*/
62+
virtual bool shallCopyBehaviourDataBeforeIntegration() const noexcept = 0;
63+
//! \brief destructor
64+
virtual ~BehaviourIntegrationFailureAnalyser() noexcept;
65+
};
66+
67+
/*!
68+
* \return a file name used to output
69+
* debugging information in case of integration
70+
* failure
71+
*
72+
* \param[in] n: behaviour name
73+
* \param[in] ext: file name
74+
*/
75+
MGIS_EXPORT std::string getBehaviourIntegrationFailureAnalysisFileName(
76+
std::string_view, std::string_view);
77+
78+
/*!
79+
* \brief a function hook used to generate a file name
80+
* for debugging behaviour integration failures
81+
* \param[in] g: generator
82+
*
83+
* \note the generator takes the behaviour name as first argument and a unique
84+
* identifier (for the given process) as second argument
85+
*/
86+
MGIS_EXPORT void setBehaviourIntegrationFailureAnalysisFileNameGenerator(
87+
std::function<std::string(std::string_view, // behaviour name
88+
std::string_view, // unique identifier
89+
std::string_view) // file extension
90+
>);
91+
92+
#ifndef LIB_MGIS_BEHAVIOUR_INTEGRATE_HXX
93+
/*!
94+
* \return the default debugging options
95+
*/
96+
MGIS_EXPORT const debug::BehaviourIntegrationFailureAnalyser&
97+
getDefaultBehaviourIntegrationFailureAnalyser();
98+
#endif
99+
100+
} // end of namespace mgis::behaviour::debug
101+
102+
#endif /* LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX */

include/MGIS/Behaviour/Integrate.hxx

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,23 @@ namespace mgis {
3030

3131
namespace mgis::behaviour {
3232

33-
// forward declaration
33+
// forward declarations
3434
struct Behaviour;
35-
// forward declaration
3635
struct MaterialDataManager;
3736

37+
namespace debug {
38+
39+
// forward declaration
40+
struct BehaviourIntegrationFailureAnalyser;
41+
42+
#ifndef LIB_MGIS_BEHAVIOUR_BEHAVIOURINTEGRATIONFAILUREANALYSER_HXX
43+
// forward declaration
44+
MGIS_EXPORT const debug::BehaviourIntegrationFailureAnalyser&
45+
getDefaultBehaviourIntegrationFailureAnalyser();
46+
#endif
47+
48+
} // end of namespace debug
49+
3850
/*!
3951
* \brief type of integration to be performed
4052
*/
@@ -74,7 +86,7 @@ namespace mgis::behaviour {
7486
BehaviourIntegrationResult();
7587
//! \brief move constructor
7688
BehaviourIntegrationResult(BehaviourIntegrationResult&&);
77-
//! \brief copye constructor
89+
//! \brief copy constructor
7890
BehaviourIntegrationResult(const BehaviourIntegrationResult&);
7991
//! \brief move assignement
8092
BehaviourIntegrationResult& operator=(BehaviourIntegrationResult&&);
@@ -240,7 +252,6 @@ namespace mgis::behaviour {
240252
* \param[in,out] d: behaviour data
241253
* \param[in,out] b: behaviour
242254
*
243-
244255
* \note: the type of integration to be performed, must be
245256
* explicitely set in d.K[0], as follows (see the `IntegrationType` enum).
246257
*
@@ -274,6 +285,23 @@ namespace mgis::behaviour {
274285
* must be computed.
275286
*/
276287
int integrate(BehaviourDataView&, const Behaviour&);
288+
/*!
289+
* \brief integrate the behaviour. In case of non convergence, an
290+
* mtest file is generated.
291+
*
292+
* The returned value has the following meaning:
293+
* - -1: integration failed
294+
* - 0: integration succeeded but results are unreliable
295+
* - 1: integration succeeded and results are reliable
296+
*
297+
* \param[in,out] d: behaviour data
298+
* \param[in,out] b: behaviour
299+
*/
300+
MGIS_EXPORT int integrate_debug(
301+
BehaviourDataView&,
302+
const Behaviour&,
303+
const debug::BehaviourIntegrationFailureAnalyser& =
304+
debug::getDefaultBehaviourIntegrationFailureAnalyser());
277305
/*!
278306
* \brief integrate the behaviour for a range of integration points.
279307
* \return the result of the behaviour integration.

include/MGIS/Behaviour/State.hxx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -401,21 +401,20 @@ namespace mgis::behaviour {
401401
*/
402402
MGIS_EXPORT const real* getExternalStateVariable(const State&,
403403
const size_type);
404-
405404
/*!
406405
* \brief make a view from a behaviour data
407406
* \param[in] s: state
408407
* \return the view
409408
* \note the view has at most the same life time as the state.
410409
*/
411-
MGIS_EXPORT StateView make_view(State&);
410+
StateView make_view(State&);
412411
/*!
413412
* \brief make a view from a behaviour data
414413
* \param[in] s: state
415414
* \return the view
416415
* \note the view has at most the same life time as the state.
417416
*/
418-
MGIS_EXPORT InitialStateView make_view(const State&);
417+
InitialStateView make_view(const State&);
419418
/*!
420419
* \brief print a detailled (verbose) description of the integration point
421420
* state using a markdown format
@@ -431,4 +430,6 @@ namespace mgis::behaviour {
431430

432431
} // end of namespace mgis::behaviour
433432

433+
#include "MGIS/Behaviour/State.ixx"
434+
434435
#endif /* LIB_MGIS_BEHAVIOUR_STATE_HXX */

include/MGIS/Behaviour/State.ixx

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
/*!
2+
* \file State.ixx
3+
* \brief
4+
* \author Thomas Helfer
5+
* \date 02/08/2018
6+
* \copyright (C) Copyright Thomas Helfer 2018.
7+
* Use, modification and distribution are subject
8+
* to one of the following licences:
9+
* - GNU Lesser General Public License (LGPL), Version 3.0. (See accompanying
10+
* file LGPL-3.0.txt)
11+
* - CECILL-C, Version 1.0 (See accompanying files
12+
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
13+
*/
14+
15+
#ifndef LIB_MGIS_BEHAVIOUR_STATE_IXX
16+
#define LIB_MGIS_BEHAVIOUR_STATE_IXX
17+
18+
namespace mgis::behaviour {
19+
20+
inline StateView make_view(State& s) {
21+
auto get_ptr = [](std::vector<real>& v) -> real* {
22+
if (v.empty()) {
23+
return nullptr;
24+
}
25+
return &v[0];
26+
}; // end of get_ptr
27+
StateView v;
28+
v.mass_density = &(s.mass_density);
29+
v.gradients = get_ptr(s.gradients);
30+
v.thermodynamic_forces = get_ptr(s.thermodynamic_forces);
31+
v.material_properties = get_ptr(s.material_properties);
32+
v.internal_state_variables = get_ptr(s.internal_state_variables);
33+
v.stored_energy = &s.stored_energy;
34+
v.dissipated_energy = &s.dissipated_energy;
35+
v.external_state_variables = get_ptr(s.external_state_variables);
36+
return v;
37+
} // end of make_view
38+
39+
inline InitialStateView make_view(const State& s) {
40+
auto get_ptr = [](const std::vector<real>& v) -> const real* {
41+
if (v.empty()) {
42+
return nullptr;
43+
}
44+
return &v[0];
45+
}; // end of get_ptr
46+
InitialStateView v;
47+
v.gradients = get_ptr(s.gradients);
48+
v.thermodynamic_forces = get_ptr(s.thermodynamic_forces);
49+
v.material_properties = get_ptr(s.material_properties);
50+
v.internal_state_variables = get_ptr(s.internal_state_variables);
51+
v.stored_energy = &s.stored_energy;
52+
v.dissipated_energy = &s.dissipated_energy;
53+
v.external_state_variables = get_ptr(s.external_state_variables);
54+
return v;
55+
} // end of make_view
56+
57+
} // end of namespace mgis::behaviour
58+
59+
#endif /* LIB_MGIS_BEHAVIOUR_STATE_IXX */

0 commit comments

Comments
 (0)