Skip to main content

teamcraft/
simmesh.rs

1//! Simulation results (FEA/CFD) for the 3D preview – pure Rust, no ParaView.
2//!
3//! Readers for the open result formats most solvers can write:
4//!
5//! * legacy VTK (`.vtk`): ASCII and BINARY (big endian), `DATASET
6//!   UNSTRUCTURED_GRID` and `POLYDATA`, the classic `CELLS` layout and the
7//!   `OFFSETS`/`CONNECTIVITY` layout of file version 5;
8//! * VTK XML `UnstructuredGrid` (`.vtu`) and `PolyData` (`.vtp`): `ascii`,
9//!   inline `binary` (base64) and appended data (`raw` or `base64`), optional
10//!   zlib compression, `UInt32`/`UInt64` headers, every integer and float type;
11//! * CalculiX results (`.frd`, ASCII): nodes (`2C`), elements (`3C`) and the
12//!   nodal result blocks (`-4 DISP`, `-4 STRESS`, …).
13//!
14//! Every reader fills one `Grid` (points, cells, point and cell data);
15//! `Grid::into_mesh` turns it into the preview [`Mesh`](crate::mesh::Mesh): volume cells
16//! (tetrahedra, hexahedra, wedges, pyramids – quadratic ones by their corner
17//! nodes) contribute only their outer faces (faces used by exactly one cell),
18//! surface cells are drawn as they are, and interior points are dropped.
19//!
20//! Result values become scalar [`Field`](crate::mesh::Field)s on the vertices: one-component
21//! data as is, six- or nine-component tensors as von Mises equivalent,
22//! other vectors as magnitude. Cell data is averaged to the points. At most
23//! [`MAX_FIELDS`](crate::mesh::MAX_FIELDS) fields are kept – the viewer offers them in a selector.
24//!
25//! Like the mesh readers, everything is defensive: counts are limited and
26//! checked against the data before anything is allocated, decompression is
27//! bounded by the sizes the arrays need, indices are checked – a hostile file
28//! is an error, never a panic, an endless loop or an unbounded allocation.
29#![deny(
30    clippy::unwrap_used,
31    clippy::expect_used,
32    clippy::indexing_slicing,
33    clippy::panic,
34    clippy::unreachable
35)]
36
37mod frd;
38mod grid;
39mod numbers;
40mod vtk_legacy;
41mod vtk_xml;
42
43use grid::*;
44use numbers::*;
45
46pub use frd::frd;
47pub use vtk_legacy::vtk_legacy;
48pub use vtk_xml::vtk_xml;
49
50/// Points of one result file.
51pub const MAX_NODES: usize = 20_000_000;
52/// Cells (elements) of one result file.
53pub const MAX_CELLS: usize = 20_000_000;
54/// Node references of all cells together.
55pub const MAX_CONNECTIVITY: usize = 160_000_000;
56/// Surfaces with more triangles are thinned out evenly (gaps are visible,
57/// the viewer stays fast).
58pub const MAX_RESULT_TRIANGLES: usize = 2_000_000;
59/// Field values carried at most (fields × vertices).
60const FIELD_BUDGET: usize = 24_000_000;
61/// Components of one data array.
62const MAX_COMPONENTS: usize = 64;
63/// Decoded bytes of one XML data array.
64const MAX_ARRAY_BYTES: usize = 1 << 31;
65
66#[cfg(test)]
67mod tests;