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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
//! Loading a behaviour from a library generated by MFront, and integrating it
//! at one material point.
use core::ffi::{c_char, c_int, c_void, CStr};
use std::path::Path;
use libloading::Library;
use crate::{ffi, Error, Hypothesis};
/// The kind of a variable. With the hypothesis, it fixes the number of
/// components of the variable.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum VariableType {
/// One value.
Scalar,
/// As many components as the space dimension.
Vector,
/// Symmetric tensor: 3, 4 or 6 components, stored in TFEL's convention
/// (`xx`, `yy`, `zz`, `√2·xy`, `√2·xz`, `√2·yz`).
Stensor,
/// Unsymmetric tensor: 3, 5 or 9 components.
Tensor,
}
/// A variable of the behaviour, and where its components sit in the array
/// that holds it.
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Variable {
/// The name, such as `ElasticStrain` or `Temperature`.
pub name: String,
/// The kind.
pub variable_type: VariableType,
/// Position of the first component in the array.
pub offset: usize,
/// Number of components.
pub size: usize,
}
/// The variables stored one after the other in one array (gradients,
/// material properties, internal state variables, …).
#[derive(Clone, Debug, PartialEq, Eq, Default)]
pub struct Variables {
/// The variables, in the order of the array.
pub list: Vec<Variable>,
/// The length of the array: the sum of the sizes.
pub size: usize,
}
/// The material symmetry of the behaviour.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum Symmetry {
/// Isotropic.
Isotropic,
/// Orthotropic: gradients and thermodynamic forces are expressed in the
/// material frame, the caller rotates them.
Orthotropic,
}
/// What the behaviour declares about itself, read from the library by
/// [`Behaviour::load`].
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct Description {
/// The name of the behaviour.
pub name: String,
/// The hypothesis it was loaded for.
pub hypothesis: Hypothesis,
/// The TFEL version that generated the library.
pub tfel_version: String,
/// The material symmetry.
pub symmetry: Symmetry,
/// The gradients: `Strain` for a small strain behaviour.
pub gradients: Variables,
/// The thermodynamic forces, dual of the gradients: `Stress`.
pub thermodynamic_forces: Variables,
/// The material properties. When the behaviour computes its stiffness or
/// thermal expansion tensor itself, the elastic properties
/// (`YoungModulus`, `PoissonRatio`, …) and thermal expansion coefficients
/// come first.
pub material_properties: Variables,
/// The internal state variables, auxiliary ones included.
pub internal_state_variables: Variables,
/// The external state variables, `Temperature` first.
pub external_state_variables: Variables,
/// The blocks of the tangent operator, as pairs (derivative of, with
/// respect to), such as (`Stress`, `Strain`). They are stored one after
/// the other, each row major.
pub tangent_operator_blocks: Vec<(String, String)>,
/// The length of the tangent operator array: the sum of the block sizes.
pub tangent_operator_size: usize,
}
/// The tangent operator the behaviour is asked to compute.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub enum TangentOperator {
/// The elastic operator.
Elastic,
/// The secant operator.
Secant,
/// The tangent operator.
Tangent,
/// The consistent tangent operator, the one a Newton-Raphson algorithm
/// needs.
ConsistentTangent,
}
/// The state at the beginning of the time step, borrowed from the caller.
///
/// Every array must have the length the [`Description`] gives.
#[derive(Clone, Copy, Debug, Default)]
pub struct InitialState<'a> {
/// The gradients.
pub gradients: &'a [f64],
/// The thermodynamic forces.
pub thermodynamic_forces: &'a [f64],
/// The material properties.
pub material_properties: &'a [f64],
/// The internal state variables.
pub internal_state_variables: &'a [f64],
/// The external state variables, temperature first.
pub external_state_variables: &'a [f64],
/// The stored energy, for behaviours that compute it.
pub stored_energy: f64,
/// The dissipated energy, for behaviours that compute it.
pub dissipated_energy: f64,
}
/// The state at the end of the time step, borrowed from the caller: the
/// caller gives the gradients, material properties and external state
/// variables, the behaviour writes the thermodynamic forces and internal state
/// variables.
///
/// Every array must have the length the [`Description`] gives.
#[derive(Debug, Default)]
pub struct FinalState<'a> {
/// The gradients.
pub gradients: &'a [f64],
/// The thermodynamic forces, written by the behaviour.
pub thermodynamic_forces: &'a mut [f64],
/// The material properties.
pub material_properties: &'a [f64],
/// The internal state variables, written by the behaviour.
pub internal_state_variables: &'a mut [f64],
/// The external state variables, temperature first.
pub external_state_variables: &'a [f64],
}
/// The outcome of a successful integration.
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Integration {
/// The factor by which the behaviour proposes to scale the time step, at
/// most 1. Below 1, the step is accepted but the behaviour advises a
/// smaller one.
pub time_step_scaling_factor: f64,
/// The stored energy at the end of the step: the initial one when the
/// behaviour does not compute it.
pub stored_energy: f64,
/// The dissipated energy at the end of the step: the initial one when the
/// behaviour does not compute it.
pub dissipated_energy: f64,
}
/// A behaviour loaded from a library generated by MFront with the `generic`
/// interface, for one modelling hypothesis.
///
/// It can be shared between threads: integrating does not modify it.
#[derive(Debug)]
pub struct Behaviour {
description: Description,
integrate: ffi::IntegrateFn,
/// Keeps the library loaded as long as `integrate` can be called.
_library: Library,
}
impl Behaviour {
/// Loads the behaviour `name` from `library` for `hypothesis`, and reads
/// its [`Description`].
///
/// ```no_run
/// use rustfront::{Behaviour, Hypothesis};
///
/// // SAFETY: `libBehaviour.so` was generated by `mfront --interface=generic`.
/// let norton = unsafe {
/// Behaviour::load("src/libBehaviour.so", "Norton", Hypothesis::Tridimensional)?
/// };
/// assert_eq!(norton.description().gradients.size, 6);
/// # Ok::<(), rustfront::Error>(())
/// ```
///
/// # Errors
///
/// When the library cannot be opened, when a symbol is missing, and when
/// the behaviour is not supported: interface other than `generic`, TFEL
/// older than 5.1.0, version of the interface other than 1, behaviour
/// other than small strain, hypothesis not provided, variable of an
/// unsupported type.
///
/// # Safety
///
/// Opening a library runs its initialisation code, and the symbols it
/// exports are trusted to have the types MFront gives them: `library`
/// must be a library generated by MFront, which is not modified while the
/// returned `Behaviour` lives.
pub unsafe fn load(
library: impl AsRef<Path>,
name: &str,
hypothesis: Hypothesis,
) -> Result<Self, Error> {
let path = library.as_ref();
// SAFETY: the caller guarantees that the library is a genuine MFront
// library, whose initialisation code is safe to run.
let library = unsafe { Library::new(path) }.map_err(|source| Error::Open {
library: path.to_path_buf(),
source,
})?;
let h = hypothesis.name();
// Address of `<name>_<hypothesis>_<suffix>`, or else of
// `<name>_<suffix>`: MFront exports a symbol per hypothesis only for
// the values that depend on it.
let find = |suffix: &str| {
[format!("{name}_{h}_{suffix}"), format!("{name}_{suffix}")]
.iter()
.find_map(|symbol| {
// SAFETY: only the address of the symbol is taken here;
// each reader below reads it with the type MFront gives it.
let address = unsafe { library.get::<*const c_void>(symbol.as_str()) };
address.ok().map(|a| *a).filter(|a| !a.is_null())
})
.ok_or_else(|| Error::MissingSymbol {
symbol: format!("{name}_{suffix}"),
})
};
let read_u16 = |suffix: &str| -> Result<u16, Error> {
// SAFETY: MFront exports these symbols as `unsigned short`.
Ok(unsafe { *find(suffix)?.cast::<u16>() })
};
// The `n` strings of the array `suffix`. A single string, exported as
// a `const char*` variable, is an array of one.
let read_strings = |suffix: &str, n: usize| -> Result<Vec<String>, Error> {
let array = find(suffix)?.cast::<*const c_char>();
(0..n)
.map(|i| {
// SAFETY: MFront exports these symbols as arrays of `n`
// NUL-terminated strings.
let s = unsafe { CStr::from_ptr(*array.add(i)) };
s.to_str()
.map(str::to_owned)
.map_err(|_| Error::InvalidString {
symbol: format!("{name}_{suffix}"),
})
})
.collect()
};
// The names and types of the variables `suffix`: their number is
// `n<suffix>`, their types `<suffix>Types` unless `typed` is false
// (material properties are always scalars and have no such symbol).
let read_variables =
|suffix: &str, typed: bool| -> Result<Vec<(String, VariableType)>, Error> {
let n = usize::from(read_u16(&format!("n{suffix}"))?);
if n == 0 {
return Ok(Vec::new());
}
let codes: Vec<c_int> = if typed {
let array = find(&format!("{suffix}Types"))?.cast::<c_int>();
// SAFETY: MFront exports these symbols as arrays of `n` `int`.
unsafe { core::slice::from_raw_parts(array, n) }.to_vec()
} else {
vec![0; n]
};
read_strings(suffix, n)?
.into_iter()
.zip(codes)
.map(|(variable, code)| match code {
0 => Ok((variable, VariableType::Scalar)),
1 => Ok((variable, VariableType::Stensor)),
2 => Ok((variable, VariableType::Vector)),
3 => Ok((variable, VariableType::Tensor)),
_ => Err(Error::UnsupportedVariableType { variable, code }),
})
.collect()
};
let dimension = hypothesis.space_dimension();
let layout = |list: Vec<(String, VariableType)>| {
let mut offset = 0;
let list = list
.into_iter()
.map(|(name, variable_type)| {
let size = match (variable_type, dimension) {
(VariableType::Scalar, _) => 1,
(VariableType::Vector, d) => d,
(VariableType::Stensor | VariableType::Tensor, 1) => 3,
(VariableType::Stensor, 2) => 4,
(VariableType::Tensor, 2) => 5,
(VariableType::Stensor, _) => 6,
(VariableType::Tensor, _) => 9,
};
let variable = Variable {
name,
variable_type,
offset,
size,
};
offset += size;
variable
})
.collect();
Variables { list, size: offset }
};
// Is this a behaviour this crate can call?
let interface = read_strings("mfront_interface", 1)?.remove(0);
if interface != "Generic" {
return Err(Error::NotGeneric {
behaviour: name.to_owned(),
interface,
});
}
let version = read_u16("api_version")?;
if version != 1 {
return Err(Error::UnsupportedApiVersion {
behaviour: name.to_owned(),
version,
});
}
let tfel_version = read_strings("tfel_version", 1)?.remove(0);
// `5.1.0`, `5.2-dev`, …: the leading numbers, compared in order.
let numbers: Vec<u32> = tfel_version
.split(['.', '-'])
.map_while(|s| s.parse().ok())
.collect();
if numbers.as_slice() < [5, 1, 0].as_slice() {
return Err(Error::UnsupportedTfelVersion {
behaviour: name.to_owned(),
version: tfel_version,
});
}
let code = read_u16("BehaviourType")?;
if code != 1 {
return Err(Error::UnsupportedBehaviourType {
behaviour: name.to_owned(),
code,
});
}
let n = usize::from(read_u16("nModellingHypotheses")?);
let supported = read_strings("ModellingHypotheses", n)?;
if !supported.iter().any(|s| s == h) {
return Err(Error::UnsupportedHypothesis {
behaviour: name.to_owned(),
hypothesis,
supported,
});
}
let symmetry = match read_u16("SymmetryType")? {
0 => Symmetry::Isotropic,
_ => Symmetry::Orthotropic,
};
// The variables, in the arrays the integration function reads. The
// elastic properties and thermal expansion coefficients of a behaviour
// that computes these tensors itself, then the temperature, are not
// listed by the library but expected first, as MGIS does.
let gradients = layout(read_variables("Gradients", true)?);
let thermodynamic_forces = layout(read_variables("ThermodynamicForces", true)?);
let mut material_properties = Vec::new();
let mut scalars = |names: &[&str]| {
material_properties.extend(names.iter().map(|n| (n.to_string(), VariableType::Scalar)));
};
if read_u16("requiresStiffnessTensor")? == 1 {
if read_u16("ElasticSymmetryType")? == 0 {
scalars(&["YoungModulus", "PoissonRatio"]);
} else {
scalars(&["YoungModulus1", "YoungModulus2", "YoungModulus3"]);
scalars(&["PoissonRatio12", "PoissonRatio23", "PoissonRatio13"]);
match dimension {
1 => {}
2 => scalars(&["ShearModulus12"]),
_ => scalars(&["ShearModulus12", "ShearModulus23", "ShearModulus13"]),
}
}
}
if read_u16("requiresThermalExpansionCoefficientTensor")? == 1 {
match symmetry {
Symmetry::Isotropic => scalars(&["ThermalExpansion"]),
Symmetry::Orthotropic => scalars(&[
"ThermalExpansion1",
"ThermalExpansion2",
"ThermalExpansion3",
]),
}
}
material_properties.extend(read_variables("MaterialProperties", false)?);
let material_properties = layout(material_properties);
let internal_state_variables = layout(read_variables("InternalStateVariables", true)?);
let mut external_state_variables = Vec::new();
if read_u16("TemperatureRemovedFromExternalStateVariables")? == 1 {
external_state_variables.push(("Temperature".to_owned(), VariableType::Scalar));
}
external_state_variables.extend(read_variables("ExternalStateVariables", true)?);
let external_state_variables = layout(external_state_variables);
// The tangent operator: blocks (derivative of, with respect to),
// listed as a flat array of names.
let n = usize::from(read_u16("nTangentOperatorBlocks")?);
let names = read_strings("TangentOperatorBlocks", n)?;
let mut tangent_operator_size = 0;
let mut tangent_operator_blocks = Vec::new();
for [of, with_respect_to] in names.as_chunks::<2>().0 {
// The block size: the product of the sizes of its two variables.
let mut size = 1;
for variable in [of, with_respect_to] {
size *= [
&gradients,
&thermodynamic_forces,
&internal_state_variables,
&external_state_variables,
]
.iter()
.flat_map(|v| &v.list)
.find(|v| &v.name == variable)
.ok_or_else(|| Error::InvalidTangentOperatorBlock {
variable: variable.clone(),
})?
.size;
}
tangent_operator_size += size;
tangent_operator_blocks.push((of.clone(), with_respect_to.clone()));
}
let symbol = format!("{name}_{h}");
// SAFETY: MFront exports `<behaviour>_<hypothesis>` with the signature
// of `ffi::IntegrateFn`. The pointer stays valid as long as the library
// is loaded, which `_library` guarantees.
let integrate = *unsafe { library.get::<ffi::IntegrateFn>(symbol.as_str()) }
.map_err(|_| Error::MissingSymbol { symbol })?;
Ok(Behaviour {
description: Description {
name: name.to_owned(),
hypothesis,
tfel_version,
symmetry,
gradients,
thermodynamic_forces,
material_properties,
internal_state_variables,
external_state_variables,
tangent_operator_blocks,
tangent_operator_size,
},
integrate,
_library: library,
})
}
/// What the behaviour declares about itself: its variables and the
/// length of each array [`Behaviour::integrate`] expects.
pub fn description(&self) -> &Description {
&self.description
}
/// Integrates the behaviour over a time step `dt`, from the state `s0` to
/// the state `s1`. When `tangent` is given, the behaviour computes that
/// operator into the array, of length
/// [`Description::tangent_operator_size`].
///
/// The time step scaling factor the behaviour may propose is at most 1.
///
/// ```no_run
/// use rustfront::{Behaviour, FinalState, Hypothesis, InitialState, TangentOperator};
///
/// // SAFETY: `libBehaviour.so` was generated by `mfront --interface=generic`.
/// let norton = unsafe {
/// Behaviour::load("src/libBehaviour.so", "Norton", Hypothesis::Tridimensional)?
/// };
/// let d = norton.description();
/// // NortonCoefficient, NortonExponent, YoungModulus, PoissonRatio.
/// let material = [8e-67, 8.2, 150e9, 0.3];
/// let temperature = [293.15];
/// let isv0 = vec![0.0; d.internal_state_variables.size];
/// let mut isv1 = isv0.clone();
/// let (eps0, eps1) = ([0.0; 6], [1e-3, 0.0, 0.0, 0.0, 0.0, 0.0]);
/// let (sig0, mut sig1) = ([0.0; 6], [0.0; 6]);
/// let mut k = vec![0.0; d.tangent_operator_size];
/// let s0 = InitialState {
/// gradients: &eps0,
/// thermodynamic_forces: &sig0,
/// material_properties: &material,
/// internal_state_variables: &isv0,
/// external_state_variables: &temperature,
/// ..Default::default()
/// };
/// let mut s1 = FinalState {
/// gradients: &eps1,
/// thermodynamic_forces: &mut sig1,
/// material_properties: &material,
/// internal_state_variables: &mut isv1,
/// external_state_variables: &temperature,
/// };
/// norton.integrate(1.0, &s0, &mut s1, Some((TangentOperator::ConsistentTangent, &mut k)))?;
/// # Ok::<(), rustfront::Error>(())
/// ```
///
/// # Errors
///
/// [`Error::WrongLength`] when an array does not have the length the
/// [`Description`] gives, [`Error::IntegrationFailed`] when the behaviour
/// fails.
pub fn integrate(
&self,
dt: f64,
s0: &InitialState<'_>,
s1: &mut FinalState<'_>,
tangent: Option<(TangentOperator, &mut [f64])>,
) -> Result<Integration, Error> {
let d = &self.description;
let tangent_length = tangent.as_ref().map(|(_, k)| k.len());
let lengths = [
("s0.gradients", d.gradients.size, s0.gradients.len()),
("s1.gradients", d.gradients.size, s1.gradients.len()),
(
"s0.thermodynamic_forces",
d.thermodynamic_forces.size,
s0.thermodynamic_forces.len(),
),
(
"s1.thermodynamic_forces",
d.thermodynamic_forces.size,
s1.thermodynamic_forces.len(),
),
(
"s0.material_properties",
d.material_properties.size,
s0.material_properties.len(),
),
(
"s1.material_properties",
d.material_properties.size,
s1.material_properties.len(),
),
(
"s0.internal_state_variables",
d.internal_state_variables.size,
s0.internal_state_variables.len(),
),
(
"s1.internal_state_variables",
d.internal_state_variables.size,
s1.internal_state_variables.len(),
),
(
"s0.external_state_variables",
d.external_state_variables.size,
s0.external_state_variables.len(),
),
(
"s1.external_state_variables",
d.external_state_variables.size,
s1.external_state_variables.len(),
),
(
"tangent",
d.tangent_operator_size,
tangent_length.unwrap_or(d.tangent_operator_size),
),
];
if let Some(&(array, expected, found)) = lengths.iter().find(|(_, e, f)| e != f) {
return Err(Error::WrongLength {
array,
expected,
found,
});
}
// `K[0]` tells the behaviour which operator to compute, 0 for none. It
// must be readable even when no operator is requested, hence a one
// value array when the caller gives none (or an empty one).
let mut no_tangent = [0.0];
let k = match tangent {
Some((operator, k)) if !k.is_empty() => {
k[0] = match operator {
TangentOperator::Elastic => 1.0,
TangentOperator::Secant => 2.0,
TangentOperator::Tangent => 3.0,
TangentOperator::ConsistentTangent => 4.0,
};
k
}
_ => &mut no_tangent[..],
};
// A behaviour that does not compute the energies leaves them as they
// were at the beginning of the step.
let mut stored_energy = s0.stored_energy;
let mut dissipated_energy = s0.dissipated_energy;
// Only read to compute the speed of sound, which is never requested.
let mass_density = 0.0;
let mut speed_of_sound = 0.0;
let mut rdt = 1.0;
let mut message: [c_char; ffi::ERROR_MESSAGE_SIZE] = [0; ffi::ERROR_MESSAGE_SIZE];
let mut data = ffi::BehaviourData {
error_message: message.as_mut_ptr(),
dt,
k: k.as_mut_ptr(),
rdt: &mut rdt,
speed_of_sound: &mut speed_of_sound,
s0: ffi::InitialState {
gradients: s0.gradients.as_ptr(),
thermodynamic_forces: s0.thermodynamic_forces.as_ptr(),
mass_density: &mass_density,
material_properties: s0.material_properties.as_ptr(),
internal_state_variables: s0.internal_state_variables.as_ptr(),
stored_energy: &s0.stored_energy,
dissipated_energy: &s0.dissipated_energy,
external_state_variables: s0.external_state_variables.as_ptr(),
},
s1: ffi::State {
gradients: s1.gradients.as_ptr(),
thermodynamic_forces: s1.thermodynamic_forces.as_mut_ptr(),
mass_density: &mass_density,
material_properties: s1.material_properties.as_ptr(),
internal_state_variables: s1.internal_state_variables.as_mut_ptr(),
stored_energy: &mut stored_energy,
dissipated_energy: &mut dissipated_energy,
external_state_variables: s1.external_state_variables.as_ptr(),
},
};
// SAFETY: `integrate` was read from the library with its signature at
// load time. Every array has the length the behaviour reads or writes,
// checked above, and outlives the call; the scalars and the error
// buffer are locals of this function.
let status = unsafe { (self.integrate)(&mut data) };
if status < 0 {
// SAFETY: the buffer was zeroed, and the behaviour writes at most
// `ERROR_MESSAGE_SIZE - 1` bytes followed by a NUL.
let message = unsafe { CStr::from_ptr(message.as_ptr()) };
return Err(Error::IntegrationFailed {
message: message.to_string_lossy().into_owned(),
time_step_scaling_factor: rdt,
});
}
Ok(Integration {
time_step_scaling_factor: rdt,
stored_energy,
dissipated_energy,
})
}
}