1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
//! The errors of this crate.
use core::fmt;
use std::path::PathBuf;
use crate::{Hypothesis, ParameterValue};
/// Everything that can go wrong when loading a behaviour, a model or a
/// material property, and when integrating or evaluating it. `name` is the
/// name of the behaviour, model or material property.
#[derive(Debug)]
#[non_exhaustive]
pub enum Error {
/// The shared library could not be opened.
Open {
/// The path given to the loader.
library: PathBuf,
/// Why the system refused it.
source: libloading::Error,
},
/// A symbol that must be exported is missing from the library: the name
/// is wrong, or the library was not generated by MFront.
MissingSymbol {
/// The symbol searched for.
symbol: String,
},
/// The library was generated for another interface than `generic`.
NotGeneric {
/// The behaviour, model or material property.
name: String,
/// The interface it was generated for.
interface: String,
},
/// A material property was loaded as a behaviour, or the other way round.
UnexpectedKind {
/// The behaviour, model or material property.
name: String,
/// What the loader expects: `behaviour or model`, `material property`.
expected: &'static str,
},
/// The version of the `generic` interface is not 1, the only one this
/// crate knows.
UnsupportedApiVersion {
/// The behaviour or model.
name: String,
/// The version found.
version: u16,
},
/// The library was generated by a TFEL version older than 5.1.0.
UnsupportedTfelVersion {
/// The behaviour, model or material property.
name: String,
/// The version found.
version: String,
},
/// The behaviour is of a kind TFEL 5.1 does not know, from a later
/// version.
UnsupportedBehaviourType {
/// The behaviour.
name: String,
/// The `_BehaviourType` symbol: 0 to 3 are known.
code: u16,
},
/// [`crate::Settings`] chooses a stress measure or a tangent operator for
/// a behaviour that is not a finite strain one.
FiniteStrainSettings {
/// The behaviour.
name: String,
},
/// The behaviour was not generated for the requested hypothesis.
UnsupportedHypothesis {
/// The behaviour or model.
name: String,
/// The requested hypothesis.
hypothesis: Hypothesis,
/// The hypotheses the library provides.
supported: Vec<String>,
},
/// A variable has a type this crate does not handle yet (arrays,
/// dimensioned types).
UnsupportedVariableType {
/// The variable.
variable: String,
/// Its type code in MFront's encoding.
code: i32,
},
/// The string is not the name of a modelling hypothesis.
UnknownHypothesis(String),
/// A setting names a parameter that is not declared.
UnknownParameter {
/// The behaviour, model or material property.
name: String,
/// The unknown parameter.
parameter: String,
},
/// A setting gives a parameter a value of another type.
WrongParameterType {
/// The parameter.
parameter: String,
/// Its default value, of the expected type.
expected: ParameterValue,
},
/// The library refused the value of a parameter, and printed why on the
/// standard error.
ParameterRejected {
/// The parameter.
parameter: String,
},
/// An array given to [`crate::Behaviour::integrate`] or
/// [`crate::MaterialProperty::evaluate`] does not have the expected
/// length.
WrongLength {
/// The array, such as `s1.internal_state_variables` or `inputs`.
array: &'static str,
/// The length expected.
expected: usize,
/// The length given.
found: usize,
},
/// An array given to [`crate::Behaviour::rotate`] does not hold whole
/// points.
IncompletePoint {
/// The array: `gradients`, `thermodynamic forces` or `tangent operator`.
array: &'static str,
/// The size of one point.
size: usize,
/// The length given.
found: usize,
},
/// The behaviour is isotropic: it exports no rotation, and needs none.
NotOrthotropic {
/// The behaviour.
name: String,
},
/// A variable to rotate is a vector, which the rotations TFEL 5.1
/// generates do not support: they would end the process.
UnsupportedRotation {
/// The behaviour.
name: String,
/// The vector.
variable: String,
},
/// The matrix given to [`crate::Rotation`] is not a rotation.
InvalidRotation {
/// What is wrong with it.
reason: &'static str,
},
/// The behaviour failed to integrate. The state at the end of the time
/// step is meaningless.
IntegrationFailed {
/// The message the behaviour left, possibly empty.
message: String,
/// The factor by which the behaviour proposes to scale the time step
/// before trying again.
time_step_scaling_factor: f64,
},
/// An input of a material property is out of its physical bounds, or of
/// its bounds with the strict policy: no value.
OutOfBounds {
/// The input.
input: String,
/// What the material property says, such as `T is over its upper
/// bound (1200>1000).`
message: String,
},
/// The evaluation of a material property failed: C++ exception, error of
/// the C library, value that is not finite.
EvaluationFailed {
/// What went wrong.
message: String,
},
}
impl fmt::Display for Error {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Error::Open { library, source } => {
write!(f, "cannot open `{}`: {source}", library.display())
}
Error::MissingSymbol { symbol } => {
write!(f, "the library does not export the symbol `{symbol}`")
}
Error::NotGeneric { name, interface } => write!(
f,
"`{name}` was generated for the `{interface}` interface, \
not for the `generic` one"
),
Error::UnexpectedKind { name, expected } => {
write!(f, "`{name}` is not a {expected}")
}
Error::UnsupportedApiVersion { name, version } => write!(
f,
"`{name}` uses version {version} of the `generic` interface, \
only version 1 is supported"
),
Error::UnsupportedTfelVersion { name, version } => write!(
f,
"`{name}` was generated by TFEL {version}, TFEL 5.1.0 or later is required"
),
Error::UnsupportedBehaviourType { name, code } => write!(
f,
"`{name}` is of an unknown kind of behaviour (behaviour type {code})"
),
Error::FiniteStrainSettings { name } => write!(
f,
"`{name}` is not a finite strain behaviour: it has no stress measure \
nor finite strain tangent operator to choose"
),
Error::UnsupportedHypothesis {
name,
hypothesis,
supported,
} => write!(
f,
"`{name}` was not generated for the `{hypothesis}` hypothesis (available: {})",
supported.join(", ")
),
Error::UnsupportedVariableType { variable, code } => write!(
f,
"the variable `{variable}` has a type (code {code}) that is not supported yet"
),
Error::UnknownHypothesis(name) => {
write!(f, "`{name}` is not a modelling hypothesis")
}
Error::UnknownParameter { name, parameter } => {
write!(f, "`{name}` has no parameter `{parameter}`")
}
Error::WrongParameterType {
parameter,
expected,
} => {
let kind = match expected {
ParameterValue::Real(_) => "real",
ParameterValue::Integer(_) => "integer",
ParameterValue::UnsignedShort(_) => "unsigned short",
};
write!(f, "the parameter `{parameter}` is {kind}")
}
Error::ParameterRejected { parameter } => write!(
f,
"the library refused the value of `{parameter}` (see the standard error)"
),
Error::WrongLength {
array,
expected,
found,
} => write!(f, "`{array}` has {found} values, {expected} expected"),
Error::IncompletePoint { array, size, found } => write!(
f,
"`{array}` has {found} values, not a multiple of {size}, the size of one point"
),
Error::NotOrthotropic { name } => {
write!(f, "`{name}` is isotropic: it has no rotation")
}
Error::UnsupportedRotation { name, variable } => write!(
f,
"`{name}` cannot rotate `{variable}`: the rotation of vectors is not supported"
),
Error::InvalidRotation { reason } => write!(f, "not a rotation matrix: {reason}"),
Error::IntegrationFailed {
message,
time_step_scaling_factor,
} => write!(
f,
"integration failed (proposed time step scaling factor: \
{time_step_scaling_factor}): {message}"
),
Error::OutOfBounds { input, message } => {
write!(f, "`{input}` is out of its bounds: {message}")
}
Error::EvaluationFailed { message } => write!(f, "evaluation failed: {message}"),
}
}
}
impl std::error::Error for Error {
fn source(&self) -> Option<&(dyn std::error::Error + 'static)> {
match self {
Error::Open { source, .. } => Some(source),
_ => None,
}
}
}