Skip to content

Commit affa5ee

Browse files
committed
add documentation
1 parent 0938356 commit affa5ee

10 files changed

Lines changed: 199 additions & 17 deletions

docs/web/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ if(MGIS_HAVE_PANDOC)
8282
mgis_pandoc_generate_html_page(release-notes-3.0.1 "--toc" "--toc-depth=3")
8383
mgis_pandoc_generate_html_page(release-notes-3.1 "--toc" "--toc-depth=3")
8484
mgis_pandoc_generate_html_page(orthotropic-behaviours "--toc" "--toc-depth=3")
85+
mgis_pandoc_generate_html_page(behaviour-integration-failure-analysis "--toc" "--toc-depth=3")
8586
mgis_pandoc_generate_html_page(FEniCSBindings)
8687
mgis_pandoc_generate_html_page(mgis_fenics "--toc" "--toc-depth=3")
8788
mgis_pandoc_generate_html_page(mgis_fenics_nonlinear_heat_transfer "--toc" "--toc-depth=3")
Lines changed: 175 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,175 @@
1+
---
2+
title: Analysing failure of behaviour integration
3+
author: Thomas Helfer
4+
date: 2025
5+
lang: en-EN
6+
numbersections: true
7+
documentclass: article
8+
from: markdown+tex_math_single_backslash
9+
geometry:
10+
- margin=2cm
11+
papersize: a4
12+
link-citations: true
13+
colorlinks: true
14+
figPrefixTemplate: "$$i$$"
15+
tabPrefixTemplate: "$$i$$"
16+
secPrefixTemplate: "$$i$$"
17+
eqnPrefixTemplate: "($$i$$)"
18+
bibliography: bibliography.bib
19+
---
20+
21+
This section describes the features available to analyse the failure of
22+
the integration of a behaviour at one integration point.
23+
24+
# The `integrate_debug` functions
25+
26+
The `integrate_debug` function are small wrappers around the `integrate`
27+
functions which, in case of integration failure, calls a user defined
28+
analyser or the default one.
29+
30+
## Examples of usage
31+
32+
The `integrate_debug` functions are direct substitutes for the
33+
`integrate` functions and have the same prototypes, when the default
34+
analyser is used. The following snippet shows how to call it using a
35+
behaviour data view `v` and a behaviour `b`:
36+
37+
~~~~{.cxx}
38+
const auto r = integrate_debug(v, b);
39+
~~~~
40+
41+
See Section @sec:mgis:integration_failure:default_analyser for a
42+
description of the default analyser.
43+
44+
The user may pass his own analyser, the type of which must inherit from
45+
the `BehaviourIntegrationFailureAnalyser` interface, describe below, as
46+
an extra argument, as follows:
47+
48+
~~~~{.cxx}
49+
const auto a = CustomAnalyser{};
50+
const auto r = integrate_debug(v, b, a);
51+
~~~~
52+
53+
See Section @sec:mgis:integration_failure:custom_analyser for details.
54+
55+
## Description of the default analyser {#sec:mgis:integration_failure:default_analyser}
56+
57+
The default analyser generates one file per integration failure
58+
containing the information required to re-run the simulation, using
59+
[`MTest`](https://thelfer.github.io/tfel/web/mtest.html) for instance.
60+
61+
By default, a markdown file is generated. Other formats may be supported
62+
in the future.
63+
64+
By default, the file name is composed by the name of the function
65+
implementing the behaviour (for the considered modelling hypothesis), a
66+
unique identifier (a number starting from zero and incremented for each
67+
integration failure report) and an extension. See Section
68+
@sec:mgis:integration_failure:default_output_file_name for details.
69+
70+
### Example of generated file
71+
72+
~~~~{.md}
73+
# Behaviour description
74+
75+
- library:/home/th202608/codes/mgis/master/src/build/tests/libBehaviourTest.so
76+
- behaviour: NortonFailure
77+
- function: NortonFailure_Tridimensional
78+
79+
# State at the beginning of the time step
80+
81+
## Gradients
82+
83+
- Strain (Stensor): {0, 0, 0, 0, 0, 0}
84+
85+
## Thermodynamic forces
86+
87+
- Stress (Stensor): {0, 0, 0, 0, 0, 0}
88+
89+
## Internal state variables
90+
91+
- ElasticStrain (Stensor): {0, 0, 0, 0, 0, 0}
92+
- EquivalentViscoplasticStrain (Scalar): 0
93+
94+
## External state variables
95+
96+
- Temperature (Scalar): 293.15
97+
98+
# State at the end of the time step
99+
100+
## Gradients
101+
102+
- Strain (Stensor): {5e-05, 0, 0, 0, 0, 0}
103+
104+
## Thermodynamic forces
105+
106+
- Stress (Stensor): {0, 0, 0, 0, 0, 0}
107+
108+
## Internal state variables
109+
110+
- ElasticStrain (Stensor): {0, 0, 0, 0, 0, 0}
111+
- EquivalentViscoplasticStrain (Scalar): 0
112+
113+
## External state variables
114+
115+
- Temperature (Scalar): 293.15
116+
~~~~
117+
118+
### Changing the generator of the output file name {#sec:mgis:integration_failure:default_output_file_name}
119+
120+
The output file name is generated by the
121+
`getBehaviourIntegrationFailureAnalysisFileName` function which takes the
122+
behaviour's function as first argument and the file extension as second
123+
argument.
124+
125+
The behaviour of the `getBehaviourIntegrationFailureAnalysisFileName`
126+
function can be altered using the
127+
`setBehaviourIntegrationFailureAnalysisFileNameGenerator` which takes a
128+
`std::function` as first argument. This function can be useful in MPI
129+
computations to distinguish the various processes.
130+
131+
#### Example of usage
132+
133+
~~~~{.cxx}
134+
auto g = [](std::string_view b, std::string_view n, std::string_view e){
135+
int r;
136+
MPI_Comm_rank(MPI_COMM_WORLD, &r);
137+
return std::string{b} + '-' + std::to_string(r) + '-' +
138+
std::string(id) + "." + std::string{ext};
139+
};
140+
setBehaviourIntegrationFailureAnalysisFileNameGenerator(g);
141+
~~~~
142+
143+
## The `BehaviourIntegrationFailureAnalyser` interface {#sec:mgis:integration_failure:custom_analyser}
144+
145+
The `BehaviourIntegrationFailureAnalyser` interface is defined as follows:
146+
147+
~~~~{.cxx}
148+
struct MGIS_EXPORT BehaviourIntegrationFailureAnalyser {
149+
virtual void analyse(const Behaviour&,
150+
const BehaviourData&) const noexcept = 0;
151+
virtual void analyse(const Behaviour&,
152+
const BehaviourDataView&) const noexcept = 0;
153+
virtual bool shallCopyBehaviourDataBeforeIntegration() const noexcept = 0;
154+
virtual ~BehaviourIntegrationFailureAnalyser() noexcept;
155+
};
156+
~~~~
157+
158+
The two `analyse` functions do the actual work. The one effectively
159+
called depends on the value returned by the
160+
`shallCopyBehaviourDataBeforeIntegration` method.
161+
162+
If the `shallCopyBehaviourDataBeforeIntegration` return `true`, the
163+
behaviour data view passed to the `integrate_debug` function is copied
164+
before integrating the behaviour using `integrate`:
165+
166+
- Copying has a significant overhead and is normally not required for
167+
correctly written behaviours but data corruption may occur, so copying
168+
is safer.
169+
- Without copying, calling `integrate_debug` shall be almost as
170+
efficient than calling `integrate`.
171+
172+
> **Note**
173+
>
174+
> The default analyser does a copy of the data, which indeed incurs an
175+
> overhead.

docs/web/mgis-template.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@
129129
<li><a>Specific topics</a>
130130
<ul>
131131
<li><a href="orthotropic-behaviours.html">Support for orthotropic behaviours</a></li>
132+
<li><a href="behaviour-integration-failure-analysis.html">Analysing failure of behaviour integration</a></li>
132133
</ul>
133134
</li>
134135
<li><a href="faq.html">FAQ</a></li>

include/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ mgis_header(MGIS/Behaviour BehaviourData.hxx)
2828
mgis_header(MGIS/Behaviour BehaviourData.ixx)
2929
mgis_header(MGIS/Behaviour BehaviourDataView.hxx)
3030
mgis_header(MGIS/Behaviour State.hxx)
31-
mgis_header(MGIS/Behaviour State.Ixx)
31+
mgis_header(MGIS/Behaviour State.ixx)
3232
mgis_header(MGIS/Behaviour MaterialStateManager.hxx)
3333
mgis_header(MGIS/Behaviour MaterialDataManager.hxx)
3434
mgis_header(MGIS/Behaviour Integrate.hxx)

src/BehaviourData.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,10 @@ namespace mgis::behaviour {
6262
<< " Behaviour description\n\n";
6363
print_markdown(os, b, l + 1);
6464
os << mgis::utilities::get_heading_signs(l + 1)
65-
<< " State at the beginning of the time step\n";
65+
<< " State at the beginning of the time step\n\n";
6666
print_markdown(os, b, d.s0, l + 1);
6767
os << mgis::utilities::get_heading_signs(l + 1)
68-
<< " State at the end of the time step\n";
68+
<< " State at the end of the time step\n\n";
6969
print_markdown(os, b, d.s1, l + 1);
7070
} // end of print_markdown
7171

src/BehaviourDataView.cxx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@ namespace mgis::behaviour {
2020
<< " Behaviour description\n\n";
2121
print_markdown(os, b, l + 1);
2222
os << mgis::utilities::get_heading_signs(l + 1)
23-
<< " State at the beginning of the time step\n";
23+
<< " State at the beginning of the time step\n\n";
2424
print_markdown(os, b, d.s0, l + 1);
2525
os << mgis::utilities::get_heading_signs(l + 1)
26-
<< " State at the end of the time step\n";
26+
<< " State at the end of the time step\n\n";
2727
print_markdown(os, b, d.s1, l + 1);
2828
} // end of print_markdown
2929

src/BehaviourDescription.cxx

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
1313
*/
1414

15+
#include <ostream>
1516
#include <cstdlib>
1617
#include <iterator>
1718

@@ -457,9 +458,13 @@ namespace mgis::behaviour {
457458
return lm.getUpperPhysicalBound(b.library, b.behaviour, b.hypothesis, v);
458459
} // end of getUpperPhysicalBound
459460

460-
void print_markdown(std::ostream &,
461-
const BehaviourDescription &,
462-
const mgis::size_type) {} // end of print_markdown
461+
void print_markdown(std::ostream & os,
462+
const BehaviourDescription & b,
463+
const mgis::size_type) {
464+
os << "- library:" << b.library << '\n'
465+
<< "- behaviour: " << b.behaviour << '\n'
466+
<< "- function: " << b.function << "\n\n";
467+
} // end of print_markdown
463468

464469
std::vector<Variable> getBehaviourInitializeFunctionInputs(
465470
const std::string &l,

src/Markdown.cxx

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,13 @@
1212
* CeCILL-C_V1-en.txt and CeCILL-C_V1-fr.txt).
1313
*/
1414

15+
#include <algorithm>
1516
#include "MGIS/Utilities/Markdown.hxx"
1617

17-
namespace mgis {
18+
namespace mgis::utilities {
1819

19-
namespace utilities {
20+
std::string get_heading_signs(const mgis::size_type l) {
21+
return std::string(std::max(l, mgis::size_type{1}), '#');
22+
} // end of get_heading_signs
2023

21-
std::string get_heading_signs(const mgis::size_type) {
22-
return std::string(1, '#');
23-
} // end of get_heading_signs
24-
25-
} // end of namespace utilities
26-
27-
} // end of namespace mgis
24+
} // end of namespace mgis::utilities

src/State.cxx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,8 @@ namespace mgis::behaviour {
416416
if (!b.esvs.empty()) {
417417
os << mgis::utilities::get_heading_signs(l + 1)
418418
<< " External state variables\n\n";
419+
print_variables(os, b, b.esvs, s.external_state_variables);
420+
os << '\n';
419421
}
420422
} // end of print_markdown
421423

src/StateView.cxx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ namespace mgis::behaviour {
7070
if (!b.esvs.empty()) {
7171
os << mgis::utilities::get_heading_signs(l + 1)
7272
<< " External state variables\n\n";
73+
os << "(" << b.esvs.size() << ")\n";
7374
print_variables(os, b, b.esvs, s.external_state_variables);
7475
os << '\n';
7576
}

0 commit comments

Comments
 (0)