Skip to main content

carapace_wasm/input_v1/
mod.rs

1//! `CarapaceInputV1` — the pysees ↔ Carapace wire format and its decoder,
2//! (see `docs/input-format.md`). Header/table DTOs, the hand-written per-table
3//! decoder into a `carapace-core` `Domain`/`Analysis`, and the stepped
4//! `Session`/`advance` API. Every type here derives `serde`'s
5//! `Serialize`/`Deserialize` so `../boundary.rs` can hand them across
6//! `wasm_bindgen` via `serde-wasm-bindgen` — but that boundary today
7//! accepts plain JS objects/arrays, not the structured-clone-plus-
8//! transferable-typed-array shapes `postMessage` will eventually carry.
9//! That optimization is deferred until `pysees`'s compiler exists to
10//! actually produce `CarapaceInputV1` bytes; see each table's doc comment
11//! for the exact correspondence once it does.
12
13pub mod error;
14pub mod materials;
15pub mod sequence;
16pub mod tables;
17
18mod decode;
19mod session;
20
21pub use decode::decode;
22pub use error::DecodeError;
23pub use materials::MaterialSpec;
24pub use session::{
25    AnalysisErrorDetail, ArcFailureDetail, ContinuationDetail, ContinuationStopDetail,
26    ModalResultsReport, ModalStageResult, ModeResult, RecorderBatch, Session, Session2, Session3,
27    StepOutcome, StopReasonDetail,
28};
29
30use sequence::SequenceSpec;
31use serde::{Deserialize, Serialize};
32use tables::{
33    ElasticBeamColumn2dTable, ElasticBeamColumn3dTable, ElementLoadTable, EqualDofTable,
34    FiberBeamColumn2dTable, FiberBeamColumn3dTable, FiberTable, LinearConstraintTable,
35    LoadPatternTable, NodalLoadTable, NodeTable, PlaneMaterialSpec, QuadTable, RigidDiaphragmTable,
36    RigidLinkTable, Shell3Table, Shell4Table, ShellSectionSpec, TriangleTable, TrussTable,
37    ZeroLengthSectionTable, ZeroLengthTable,
38};
39
40/// Small structured-clone header fields — everything else in
41/// `CarapaceInputV1` is a bulk table.
42#[derive(Debug, Clone, Serialize, Deserialize, tsify::Tsify)]
43#[serde(rename_all = "camelCase")]
44pub struct Header {
45    /// The wire format's own version, independent of `engine_version`.
46    pub schema_version: u32,
47    /// Model dimension: `2` (`NDM=2`/`NDF=3`) or `3` (`NDM=3`/`NDF=6`).
48    /// [`decode`] rejects any other value.
49    pub ndm: u8,
50    /// `carapace-core`'s version, recorded for run provenance.
51    pub engine_version: String,
52    /// Record one sample of every supported recorder at the start of each `Static`/`Transient`
53    /// stage, before its first step (the stage's initial conditions, at load factor/time `0`).
54    /// Off by default: every stage's samples are then only the ones its steps produce.
55    #[serde(default)]
56    #[tsify(optional)]
57    pub record_initial: bool,
58}
59
60/// The full wire payload: header plus one table per entity kind, mirroring
61/// `core`'s closed-enum element/material catalog.
62///
63/// One format for both profiles (`header.ndm`). Dimension-agnostic entities
64/// share a table; formulations that differ between 2D and 3D have a table per
65/// formulation (`*2d`/`*3d`), and the other profile's must be empty or
66/// omitted ([`DecodeError::TableNotInProfile`]). Every table may be omitted,
67/// which is the same as empty.
68#[derive(Debug, Clone, Serialize, Deserialize, tsify::Tsify)]
69#[serde(rename_all = "camelCase")]
70pub struct CarapaceInputV1 {
71    pub header: Header,
72    #[serde(default)]
73    #[tsify(optional)]
74    pub nodes: NodeTable,
75    #[serde(default)]
76    #[tsify(optional)]
77    pub materials: Vec<MaterialSpec>,
78    #[serde(default)]
79    #[tsify(optional)]
80    pub fibers: FiberTable,
81    #[serde(default)]
82    #[tsify(optional)]
83    pub trusses: TrussTable,
84    #[serde(default)]
85    #[tsify(optional)]
86    pub elastic_beam_columns_2d: ElasticBeamColumn2dTable,
87    #[serde(default)]
88    #[tsify(optional)]
89    pub elastic_beam_columns_3d: ElasticBeamColumn3dTable,
90    #[serde(default)]
91    #[tsify(optional)]
92    pub disp_beam_columns_2d: FiberBeamColumn2dTable,
93    #[serde(default)]
94    #[tsify(optional)]
95    pub disp_beam_columns_3d: FiberBeamColumn3dTable,
96    #[serde(default)]
97    #[tsify(optional)]
98    pub force_beam_columns_2d: FiberBeamColumn2dTable,
99    #[serde(default)]
100    #[tsify(optional)]
101    pub force_beam_columns_3d: FiberBeamColumn3dTable,
102    #[serde(default)]
103    #[tsify(optional)]
104    pub zero_lengths: ZeroLengthTable,
105    #[serde(default)]
106    #[tsify(optional)]
107    pub zero_length_sections: ZeroLengthSectionTable,
108    #[serde(default)]
109    #[tsify(optional)]
110    pub equal_dofs: EqualDofTable,
111    /// Arena of plane materials for `triangles`/`quads` (2D models only).
112    #[serde(default)]
113    #[tsify(optional)]
114    pub plane_materials: Vec<PlaneMaterialSpec>,
115    #[serde(default)]
116    #[tsify(optional)]
117    pub triangles: TriangleTable,
118    #[serde(default)]
119    #[tsify(optional)]
120    pub quads: QuadTable,
121    /// Arena of shell sections for `shell4s` (3D models only).
122    #[serde(default)]
123    #[tsify(optional)]
124    pub shell_sections: Vec<ShellSectionSpec>,
125    #[serde(default)]
126    #[tsify(optional)]
127    pub shell3s: Shell3Table,
128    #[serde(default)]
129    #[tsify(optional)]
130    pub shell4s: Shell4Table,
131    #[serde(default)]
132    #[tsify(optional)]
133    pub rigid_diaphragms: RigidDiaphragmTable,
134    #[serde(default)]
135    #[tsify(optional)]
136    pub rigid_links: RigidLinkTable,
137    #[serde(default)]
138    #[tsify(optional)]
139    pub linear_constraints: LinearConstraintTable,
140    #[serde(default)]
141    #[tsify(optional)]
142    pub load_patterns: LoadPatternTable,
143    #[serde(default)]
144    #[tsify(optional)]
145    pub nodal_loads: NodalLoadTable,
146    #[serde(default)]
147    #[tsify(optional)]
148    pub element_loads: ElementLoadTable,
149    #[serde(default)]
150    #[tsify(optional)]
151    pub sequence: SequenceSpec,
152}