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    /// Creates an empty engineering model.
164    pub fn new() -> Self {
165        Self {
166            model_id: "model_1".to_string(),
167            model_name: "Test Model".to_string(),
168            model_type: ModelType::Structural,
169            geometry: Geometry::new(),
170            materials: HashMap::new(),
171            boundary_conditions: Vec::new(),
172            loads: Vec::new(),
173        }
174    }
175}
176
177impl Geometry {
178    /// Creates empty model geometry.
179    pub fn new() -> Self {
180        Self {
181            geometry_type: GeometryType::Beam,
182            dimensions: vec![1.0, 0.1, 0.1],
183            features: Vec::new(),
184        }
185    }
186}
187
188impl GeometricFeature {
189    /// Creates a default geometric feature.
190    pub fn new() -> Self {
191        Self {
192            feature_id: "feature_1".to_string(),
193            feature_type: FeatureType::Hole,
194            feature_parameters: HashMap::new(),
195        }
196    }
197}
198
199impl Material {
200    /// Creates a default material record.
201    pub fn new() -> Self {
202        Self {
203            material_id: "steel_1".to_string(),
204            material_name: "Steel".to_string(),
205            material_properties: MaterialProperties::new(),
206        }
207    }
208}
209
210impl MaterialProperties {
211    /// Creates default material properties.
212    pub fn new() -> Self {
213        Self {
214            youngs_modulus: 200000.0,
215            poissons_ratio: 0.3,
216            density: 7850.0,
217            thermal_expansion: 12e-6,
218            thermal_conductivity: 50.0,
219            specific_heat: 500.0,
220            yield_strength: 250.0,
221            ultimate_strength: 400.0,
222        }
223    }
224}
225
226impl BoundaryCondition {
227    /// Creates a default boundary condition.
228    pub fn new() -> Self {
229        Self {
230            condition_id: "bc_1".to_string(),
231            condition_type: BoundaryConditionType::Fixed,
232            condition_value: 0.0,
233        }
234    }
235}
236
237impl Load {
238    /// Creates a default load record.
239    pub fn new() -> Self {
240        Self {
241            load_id: "load_1".to_string(),
242            load_type: LoadType::Point,
243            load_magnitude: 1000.0,
244            load_direction: vec![0.0, -1.0, 0.0],
245            application_point: vec![1.0, 0.0, 0.0],
246        }
247    }
248}
249
250impl AnalysisResults {
251    /// Creates empty analysis results.
252    pub fn new() -> Self {
253        Self {
254            results_id: "results_1".to_string(),
255            analysis_type: AnalysisType::LinearStatic,
256            displacement_field: Vec::new(),
257            stress_field: Vec::new(),
258            strain_field: Vec::new(),
259            reaction_forces: Vec::new(),
260            // No analysis on a default-constructed value — 0, never a fabricated 2.5 safety factor.
261            safety_factor: 0.0,
262            temperature_field: Vec::new(),
263            heat_flux_field: Vec::new(),
264        }
265    }
266}
267
268impl ReliabilityResults {
269    /// Creates empty reliability results.
270    pub fn new() -> Self {
271        Self {
272            results_id: "reliability_1".to_string(),
273            reliability_index: 0.95,
274            failure_probability: 0.05,
275            mean_time_to_failure: 10000.0,
276            maintenance_interval: 30,
277        }
278    }
279}
280
281impl EngineeringPerformanceMetrics {
282    /// Creates zeroed performance metrics.
283    pub fn new() -> Self {
284        Self {
285            total_analyses: 0,
286            average_computation_time: 0.0,
287            average_accuracy: None,
288            convergence_rate: None,
289        }
290    }
291}