Skip to main content

qualia_core_db/specialized_libs/engineering_analysis/
model.rs

1use super::*;
2
3/// Engineering library performance summary metrics
4#[derive(Debug, Clone)]
5pub struct EngineeringPerformanceMetrics {
6    pub total_analyses: u64,
7    pub average_computation_time: f64,
8    /// Average solver accuracy / convergence rate across analyses. `None` = not measured —
9    /// this summary does not track per-analysis error, so it must not fabricate a value
10    /// (previously `new()` claimed a hardcoded 95% accuracy / 98% convergence from nothing).
11    pub average_accuracy: Option<f64>,
12    pub convergence_rate: Option<f64>,
13}
14
15/// Engineering operation result
16#[derive(Debug, Clone)]
17pub struct EngineeringOperationResult<T> {
18    pub result: T,
19    pub execution_time: u64,
20    pub computational_cost: f64,
21    /// Solver accuracy for this analysis. `None` = not computed (no error estimate is
22    /// produced), rather than a fabricated per-analysis 0.85–0.95.
23    pub accuracy: Option<f64>,
24    pub convergence_info: ConvergenceInfo,
25}
26
27/// Convergence information
28#[derive(Debug, Clone)]
29pub struct ConvergenceInfo {
30    pub converged: bool,
31    pub iterations: u32,
32    pub convergence_criterion: f64,
33    pub final_error: f64,
34}
35
36/// Engineering model representation
37#[derive(Debug, Clone)]
38pub struct EngineeringModel {
39    pub model_id: String,
40    pub model_name: String,
41    pub model_type: ModelType,
42    pub geometry: Geometry,
43    pub materials: HashMap<String, Material>,
44    pub boundary_conditions: Vec<BoundaryCondition>,
45    pub loads: Vec<Load>,
46}
47
48/// Model types
49#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
50pub enum ModelType {
51    Structural,
52    Mechanical,
53    Thermal,
54    Fluid,
55    Multiphysics,
56}
57
58/// Geometry
59#[derive(Debug, Clone)]
60pub struct Geometry {
61    pub geometry_type: GeometryType,
62    pub dimensions: Vec<f64>,
63    pub features: Vec<GeometricFeature>,
64}
65
66/// Geometry types
67#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
68pub enum GeometryType {
69    Beam,
70    Plate,
71    Shell,
72    Solid,
73    Custom(String),
74}
75
76/// Geometric features
77#[derive(Debug, Clone)]
78pub struct GeometricFeature {
79    pub feature_id: String,
80    pub feature_type: FeatureType,
81    pub feature_parameters: HashMap<String, f64>,
82}
83
84/// Feature types
85#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
86pub enum FeatureType {
87    Hole,
88    Fillet,
89    Chamfer,
90    Rib,
91}
92
93/// Materials
94#[derive(Debug, Clone)]
95pub struct Material {
96    pub material_id: String,
97    pub material_name: String,
98    pub material_properties: MaterialProperties,
99}
100
101/// Boundary conditions
102#[derive(Debug, Clone)]
103pub struct BoundaryCondition {
104    pub condition_id: String,
105    pub condition_type: BoundaryConditionType,
106    pub condition_value: f64,
107}
108
109/// Boundary condition types
110#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
111pub enum BoundaryConditionType {
112    Fixed,
113    Pinned,
114    Roller,
115    Displacement,
116    Force,
117    Pressure,
118    Temperature,
119    HeatFlux,
120}
121
122/// Loads
123#[derive(Debug, Clone)]
124pub struct Load {
125    pub load_id: String,
126    pub load_type: LoadType,
127    pub load_magnitude: f64,
128    pub load_direction: Vec<f64>,
129    pub application_point: Vec<f64>,
130}
131
132/// Load distribution types
133#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
134pub enum LoadDistributionType {
135    Point,
136    Distributed,
137    Moment,
138    Pressure,
139    Thermal,
140    Dynamic,
141}
142
143/// Analysis results
144#[derive(Debug, Clone)]
145pub struct AnalysisResults {
146    pub results_id: String,
147    pub analysis_type: AnalysisType,
148    pub displacement_field: Vec<f64>,
149    pub stress_field: Vec<f64>,
150    pub strain_field: Vec<f64>,
151    pub reaction_forces: Vec<f64>,
152    pub safety_factor: f64,
153    /// Steady-state temperature field (K) at the mesh nodes. Populated by thermal
154    /// conduction analysis (`thermal_conduction`); empty for mechanical analyses.
155    pub temperature_field: Vec<f64>,
156    /// Heat-flux field (W/m²) at the mesh nodes, `q = −k·dT/dx`. Populated by
157    /// thermal conduction analysis; empty for mechanical analyses.
158    pub heat_flux_field: Vec<f64>,
159}
160// Supporting structs
161
162impl EngineeringModel {
163    pub fn new() -> Self {
164        Self {
165            model_id: "model_1".to_string(),
166            model_name: "Test Model".to_string(),
167            model_type: ModelType::Structural,
168            geometry: Geometry::new(),
169            materials: HashMap::new(),
170            boundary_conditions: Vec::new(),
171            loads: Vec::new(),
172        }
173    }
174}
175
176impl Geometry {
177    pub fn new() -> Self {
178        Self {
179            geometry_type: GeometryType::Beam,
180            dimensions: vec![1.0, 0.1, 0.1],
181            features: Vec::new(),
182        }
183    }
184}
185
186impl GeometricFeature {
187    pub fn new() -> Self {
188        Self {
189            feature_id: "feature_1".to_string(),
190            feature_type: FeatureType::Hole,
191            feature_parameters: HashMap::new(),
192        }
193    }
194}
195
196impl Material {
197    pub fn new() -> Self {
198        Self {
199            material_id: "steel_1".to_string(),
200            material_name: "Steel".to_string(),
201            material_properties: MaterialProperties::new(),
202        }
203    }
204}
205
206impl MaterialProperties {
207    pub fn new() -> Self {
208        Self {
209            youngs_modulus: 200000.0,
210            poissons_ratio: 0.3,
211            density: 7850.0,
212            thermal_expansion: 12e-6,
213            thermal_conductivity: 50.0,
214            specific_heat: 500.0,
215            yield_strength: 250.0,
216            ultimate_strength: 400.0,
217        }
218    }
219}
220
221impl BoundaryCondition {
222    pub fn new() -> Self {
223        Self {
224            condition_id: "bc_1".to_string(),
225            condition_type: BoundaryConditionType::Fixed,
226            condition_value: 0.0,
227        }
228    }
229}
230
231impl Load {
232    pub fn new() -> Self {
233        Self {
234            load_id: "load_1".to_string(),
235            load_type: LoadType::Point,
236            load_magnitude: 1000.0,
237            load_direction: vec![0.0, -1.0, 0.0],
238            application_point: vec![1.0, 0.0, 0.0],
239        }
240    }
241}
242
243impl AnalysisResults {
244    pub fn new() -> Self {
245        Self {
246            results_id: "results_1".to_string(),
247            analysis_type: AnalysisType::LinearStatic,
248            displacement_field: Vec::new(),
249            stress_field: Vec::new(),
250            strain_field: Vec::new(),
251            reaction_forces: Vec::new(),
252            // No analysis on a default-constructed value — 0, never a fabricated 2.5 safety factor.
253            safety_factor: 0.0,
254            temperature_field: Vec::new(),
255            heat_flux_field: Vec::new(),
256        }
257    }
258}
259
260impl ReliabilityResults {
261    pub fn new() -> Self {
262        Self {
263            results_id: "reliability_1".to_string(),
264            reliability_index: 0.95,
265            failure_probability: 0.05,
266            mean_time_to_failure: 10000.0,
267            maintenance_interval: 30,
268        }
269    }
270}
271
272impl EngineeringPerformanceMetrics {
273    pub fn new() -> Self {
274        Self {
275            total_analyses: 0,
276            average_computation_time: 0.0,
277            average_accuracy: None,
278            convergence_rate: None,
279        }
280    }
281}