Skip to main content

runmat_meshing/analysis_prep/
types.rs

1use runmat_geometry_core::MeshKind;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
5#[serde(rename_all = "snake_case")]
6pub enum MeshingProfile {
7    SurfaceOnly,
8    AnalysisReady,
9    AdaptiveRefine,
10}
11
12#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
13pub struct MeshingOptions {
14    pub profile: MeshingProfile,
15    pub target_element_budget: usize,
16}
17
18impl Default for MeshingOptions {
19    fn default() -> Self {
20        Self {
21            profile: MeshingProfile::AnalysisReady,
22            target_element_budget: 250_000,
23        }
24    }
25}
26
27#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
28#[serde(rename_all = "snake_case")]
29pub enum MeshConnectivityClass {
30    SparseBand,
31    SurfacePatch,
32    VolumeCore,
33}
34
35#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
36#[serde(rename_all = "snake_case")]
37pub enum ElementFamilyHint {
38    Triangle,
39    Quad,
40    Tetrahedron,
41    Hex,
42    Mixed,
43}
44
45pub(super) fn default_coordinate_span_m() -> [f64; 3] {
46    [1.0, 0.0, 0.0]
47}
48
49fn default_coordinate_active_dimension_count() -> u8 {
50    1
51}
52
53pub(super) fn default_coordinate_characteristic_length_m() -> f64 {
54    1.0
55}
56
57fn default_zero_u64() -> u64 {
58    0
59}
60
61fn default_zero_f64() -> f64 {
62    0.0
63}
64
65fn default_reference_element_coordinates_m() -> [[f64; 3]; 3] {
66    [[0.0; 3]; 3]
67}
68
69fn default_element_topology_sample_edge_nodes() -> [[u32; 2]; 8] {
70    [[0; 2]; 8]
71}
72
73fn default_element_topology_sample_node_coordinates_m() -> [[f64; 3]; 8] {
74    [[0.0; 3]; 8]
75}
76
77fn default_element_topology_sample_element_edges() -> [[u32; 3]; 4] {
78    [[0; 3]; 4]
79}
80
81fn default_element_topology_sample_element_orientations() -> [[i8; 3]; 4] {
82    [[0; 3]; 4]
83}
84
85fn default_element_topology_sample_element_areas_m2() -> [f64; 4] {
86    [0.0; 4]
87}
88
89fn default_element_topology_node_coordinates_m() -> Vec<[f64; 3]> {
90    Vec::new()
91}
92
93fn default_element_topology_edge_nodes() -> Vec<[u32; 2]> {
94    Vec::new()
95}
96
97fn default_element_topology_element_edges() -> Vec<[u32; 3]> {
98    Vec::new()
99}
100
101fn default_element_topology_element_orientations() -> Vec<[i8; 3]> {
102    Vec::new()
103}
104
105fn default_element_topology_element_areas_m2() -> Vec<f64> {
106    Vec::new()
107}
108
109#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
110pub struct PreparedMeshDescriptor {
111    pub prepared_mesh_id: String,
112    pub source_mesh_id: String,
113    pub kind: MeshKind,
114    pub node_count: u64,
115    pub element_count: u64,
116    pub connectivity_class: MeshConnectivityClass,
117    pub element_family_hint: ElementFamilyHint,
118    pub region_span_hint: u32,
119    #[serde(default = "default_coordinate_span_m")]
120    pub coordinate_span_m: [f64; 3],
121    #[serde(default = "default_coordinate_active_dimension_count")]
122    pub coordinate_active_dimension_count: u8,
123    #[serde(default = "default_coordinate_characteristic_length_m")]
124    pub coordinate_characteristic_length_m: f64,
125    #[serde(default = "default_zero_u64")]
126    pub element_geometry_node_count: u64,
127    #[serde(default = "default_zero_u64")]
128    pub element_geometry_edge_count: u64,
129    #[serde(default = "default_zero_f64")]
130    pub mean_element_edge_length_m: f64,
131    #[serde(default = "default_zero_f64")]
132    pub mean_element_area_m2: f64,
133    #[serde(default = "default_zero_f64")]
134    pub element_geometry_coverage_ratio: f64,
135    #[serde(default = "default_reference_element_coordinates_m")]
136    pub reference_element_coordinates_m: [[f64; 3]; 3],
137    #[serde(default = "default_zero_f64")]
138    pub reference_element_area_m2: f64,
139    #[serde(default = "default_zero_u64")]
140    pub control_volume_cell_count: u64,
141    #[serde(default = "default_zero_u64")]
142    pub control_volume_face_count: u64,
143    #[serde(default = "default_zero_u64")]
144    pub control_volume_internal_face_count: u64,
145    #[serde(default = "default_zero_u64")]
146    pub control_volume_boundary_face_count: u64,
147    #[serde(default = "default_zero_f64")]
148    pub control_volume_connectivity_coverage_ratio: f64,
149    #[serde(default = "default_zero_u64")]
150    pub element_topology_sample_element_count: u64,
151    #[serde(default = "default_zero_u64")]
152    pub element_topology_sample_edge_count: u64,
153    #[serde(default = "default_element_topology_sample_edge_nodes")]
154    pub element_topology_sample_edge_nodes: [[u32; 2]; 8],
155    #[serde(default = "default_element_topology_sample_node_coordinates_m")]
156    pub element_topology_sample_node_coordinates_m: [[f64; 3]; 8],
157    #[serde(default = "default_element_topology_sample_element_edges")]
158    pub element_topology_sample_element_edges: [[u32; 3]; 4],
159    #[serde(default = "default_element_topology_sample_element_orientations")]
160    pub element_topology_sample_element_orientations: [[i8; 3]; 4],
161    #[serde(default = "default_element_topology_sample_element_areas_m2")]
162    pub element_topology_sample_element_areas_m2: [f64; 4],
163    #[serde(default = "default_element_topology_node_coordinates_m")]
164    pub element_topology_node_coordinates_m: Vec<[f64; 3]>,
165    #[serde(default = "default_element_topology_edge_nodes")]
166    pub element_topology_edge_nodes: Vec<[u32; 2]>,
167    #[serde(default = "default_element_topology_element_edges")]
168    pub element_topology_element_edges: Vec<[u32; 3]>,
169    #[serde(default = "default_element_topology_element_orientations")]
170    pub element_topology_element_orientations: Vec<[i8; 3]>,
171    #[serde(default = "default_element_topology_element_areas_m2")]
172    pub element_topology_element_areas_m2: Vec<f64>,
173}
174
175#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
176pub struct RegionMeshMapping {
177    pub region_id: String,
178    pub source_mesh_ids: Vec<String>,
179    pub prepared_mesh_ids: Vec<String>,
180}
181
182#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
183pub struct MeshingQualityReport {
184    pub min_scaled_jacobian: f64,
185    pub mean_aspect_ratio: f64,
186    pub inverted_element_count: u64,
187}
188
189#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
190pub struct MeshingProvenance {
191    pub algorithm: String,
192    pub profile: MeshingProfile,
193    pub source_geometry_id: String,
194    pub source_geometry_revision: u32,
195}
196
197#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
198pub struct MeshingPrepResult {
199    pub schema_version: String,
200    pub prepared_meshes: Vec<PreparedMeshDescriptor>,
201    pub region_mappings: Vec<RegionMeshMapping>,
202    pub quality: MeshingQualityReport,
203    pub provenance: MeshingProvenance,
204}