qualia_core_db/specialized_libs/physics_simulation/results.rs
1use super::*;
2
3/// Physics simulation result
4#[derive(Debug, Clone)]
5pub struct PhysicsSimulationResult<T> {
6 pub result: T,
7 pub simulation_time: u64,
8 pub solver_time: u64,
9 pub data_time: u64,
10 pub convergence_info: ConvergenceInfo,
11 pub performance_info: PerformanceInfo,
12}
13
14/// Convergence information
15#[derive(Debug, Clone)]
16pub struct ConvergenceInfo {
17 pub converged: bool,
18 pub iterations: u32,
19 pub residual_norm: f64,
20 pub convergence_rate: f64,
21 pub final_error: f64,
22}
23
24/// Performance information
25#[derive(Debug, Clone)]
26pub struct PerformanceInfo {
27 pub cpu_utilization: f64,
28 pub memory_utilization: f64,
29 pub network_utilization: f64,
30 pub io_utilization: f64,
31 pub parallel_efficiency: f64,
32}
33
34// ============================================================================
35// Genuine simulations for the declared `SimulationType` domains.
36//
37// Every method below marshals an initial state into slices and hands the actual
38// time-integration / eigenproblem to a tested solver in `crate::solvers`:
39// * `integrate_dopri5` — adaptive Dormand–Prince RK45 (vector ODE systems)
40// * `integrate_symplectic` — Störmer–Verlet / Ruth / Yoshida (separable Hamiltonians)
41// * `symmetric_eigen` — cyclic-Jacobi symmetric eigensolver
42// The physics (forces, Laplacians, Hamiltonians) is set up here; the numerics are not.
43// ============================================================================
44
45/// Trajectory + landing diagnostics for `run_projectile_motion` (ParticlePhysics).
46#[derive(Debug, Clone)]
47pub struct ProjectileResult {
48 /// Sampled `[t, x, y, vx, vy]` rows along the flight.
49 pub trajectory: Vec<[f64; 5]>,
50 /// Horizontal distance at ground return (interpolated y=0). No-drag: v0²·sin(2θ)/g.
51 pub range: f64,
52 /// Peak height reached.
53 pub max_height: f64,
54 /// Time of flight to ground return (interpolated).
55 pub time_of_flight: f64,
56 /// Whether the projectile returned to y=0 within `max_time`.
57 pub landed: bool,
58 pub steps_accepted: u32,
59 pub steps_rejected: u32,
60}
61
62/// Result of `run_harmonic_oscillator` (StructuralDynamics / spring–mass), symplectic.
63#[derive(Debug, Clone)]
64pub struct OscillatorResult {
65 pub times: Vec<f64>,
66 pub positions: Vec<f64>,
67 pub velocities: Vec<f64>,
68 /// Analytic period 2π·√(m/k).
69 pub analytic_period: f64,
70 /// Period measured from the integrated trajectory (mean crossing interval).
71 pub measured_period: f64,
72 pub energy_initial: f64,
73 pub energy_final: f64,
74 /// Max |E−E₀| over the run — the bounded symplectic energy drift.
75 pub max_energy_drift: f64,
76}
77
78/// Result of `run_pendulum` (nonlinear rigid-body dynamics).
79#[derive(Debug, Clone)]
80pub struct PendulumResult {
81 pub times: Vec<f64>,
82 pub angles: Vec<f64>,
83 pub angular_velocities: Vec<f64>,
84 /// Small-angle period 2π·√(L/g).
85 pub small_angle_period: f64,
86 pub measured_period: f64,
87 pub energy_initial: f64,
88 pub energy_final: f64,
89 pub steps_accepted: u32,
90 pub steps_rejected: u32,
91}
92
93/// Result of `run_nbody_gravitation` (Astrophysics), direct-sum Newtonian gravity.
94#[derive(Debug, Clone)]
95pub struct NBodyResult {
96 pub num_bodies: usize,
97 pub times: Vec<f64>,
98 /// Position snapshots; each is the flat `[x0,y0,x1,y1,…]` vector at that time.
99 pub position_snapshots: Vec<Vec<f64>>,
100 pub final_positions: Vec<f64>,
101 pub final_velocities: Vec<f64>,
102 pub energy_initial: f64,
103 pub energy_final: f64,
104 /// |E_final − E_initial| / |E_initial|.
105 pub energy_drift_rel: f64,
106 pub angular_momentum_initial: f64,
107 pub angular_momentum_final: f64,
108 pub steps_accepted: u32,
109 pub steps_rejected: u32,
110}
111
112/// Result of `run_heat_diffusion_1d` (HeatTransfer), insulated (Neumann) ends.
113#[derive(Debug, Clone)]
114pub struct HeatDiffusionResult {
115 pub times: Vec<f64>,
116 pub snapshots: Vec<Vec<f64>>,
117 pub final_temperature: Vec<f64>,
118 pub initial_mean: f64,
119 pub final_mean: f64,
120 /// max_i |u_i − mean| in the final field (→ 0 as the profile relaxes).
121 pub max_deviation_from_mean: f64,
122 pub steps_accepted: u32,
123 pub steps_rejected: u32,
124}
125
126/// Result of `run_wave_equation_1d` (CEM — 1D scalar wave / plane-wave field), fixed ends.
127#[derive(Debug, Clone)]
128pub struct WaveResult {
129 pub times: Vec<f64>,
130 /// Displacement (field) snapshots.
131 pub snapshots: Vec<Vec<f64>>,
132 pub final_displacement: Vec<f64>,
133 pub energy_initial: f64,
134 pub energy_final: f64,
135 pub steps_accepted: u32,
136 pub steps_rejected: u32,
137}
138
139/// Result of `run_molecular_dynamics` (MolecularDynamics), Lennard-Jones in 2D.
140#[derive(Debug, Clone)]
141pub struct MolecularDynamicsResult {
142 pub num_particles: usize,
143 pub times: Vec<f64>,
144 pub final_positions: Vec<f64>,
145 pub final_velocities: Vec<f64>,
146 pub energy_initial: f64,
147 pub energy_final: f64,
148 pub energy_drift_rel: f64,
149 /// Instantaneous kinetic temperature (reduced units, kB=1): 2·KE/dof.
150 pub temperature: f64,
151 pub steps_accepted: u32,
152 pub steps_rejected: u32,
153}
154
155/// Result of `run_quantum_stationary_states_1d` (QuantumMechanics), finite-difference
156/// time-independent Schrödinger eigenproblem solved by `symmetric_eigen`.
157#[derive(Debug, Clone)]
158pub struct QuantumSpectrumResult {
159 /// Lowest `num_levels` energy eigenvalues, ascending.
160 pub eigenvalues: Vec<f64>,
161 pub num_grid_points: usize,
162 pub dx: f64,
163}
164
165/// Result of `run_logistic_growth` (Biophysics — population dynamics).
166#[derive(Debug, Clone)]
167pub struct PopulationDynamicsResult {
168 pub times: Vec<f64>,
169 pub population: Vec<f64>,
170 pub carrying_capacity: f64,
171 pub growth_rate: f64,
172 pub steps_accepted: u32,
173 pub steps_rejected: u32,
174}
175
176/// Result of `run_advection_diffusion_1d` (MultiPhysics — coupled transport + diffusion).
177#[derive(Debug, Clone)]
178pub struct AdvectionDiffusionResult {
179 pub times: Vec<f64>,
180 pub snapshots: Vec<Vec<f64>>,
181 pub final_field: Vec<f64>,
182 pub advection_velocity: f64,
183 pub diffusion_coeff: f64,
184 /// Σ_i u_i·dx at t=0 and t=end (conserved under the periodic scheme).
185 pub initial_total: f64,
186 pub final_total: f64,
187 pub steps_accepted: u32,
188 pub steps_rejected: u32,
189}
190
191/// Result of `run_emf_interference` — superposition of N EMF sources at a point.
192#[derive(Debug, Clone)]
193pub struct EmfInterferenceResult {
194 /// Instantaneous field value E(t) at the observation point.
195 pub instantaneous_value: f64,
196 /// Peak amplitude of the resultant over one cycle of the lowest frequency.
197 pub amplitude: f64,
198 /// Effective phase of the resultant (radians). For single-frequency sources
199 /// this is the exact combined phase; for multi-frequency it is the phase of
200 /// the dominant component.
201 pub phase: f64,
202 /// Dominant or beat frequency of the resultant (Hz).
203 pub frequency_effective: f64,
204 /// Number of sources contributing.
205 pub num_sources: usize,
206}
207
208/// Result of `run_emf_attenuation` — inverse-square + atmospheric absorption.
209#[derive(Debug, Clone)]
210pub struct EmfAttenuationResult {
211 /// Received power after inverse-square and absorption (W).
212 pub received_power: f64,
213 /// Total attenuation in dB.
214 pub attenuation_db: f64,
215 /// Free-space path loss in dB (inverse-square only).
216 pub free_space_loss_db: f64,
217 /// Atmospheric absorption loss in dB.
218 pub absorption_loss_db: f64,
219 /// Distance from source (m).
220 pub distance: f64,
221 /// Frequency (Hz).
222 pub frequency: f64,
223}
224
225/// Result of `run_doppler_shift` — relativistic Doppler effect.
226#[derive(Debug, Clone)]
227pub struct DopplerShiftResult {
228 /// Observed frequency (Hz).
229 pub observed_frequency: f64,
230 /// Ratio f_observed / f_source.
231 pub shift_ratio: f64,
232 /// Relative velocity (m/s, positive = approaching).
233 pub relative_velocity: f64,
234 /// Beta = v / c.
235 pub beta: f64,
236}
237
238/// Result of `run_emf_field_grid_3d` — 4D physics grid (x×y×z×t).
239#[derive(Debug, Clone)]
240pub struct EmfFieldGrid3DResult {
241 pub nx: usize,
242 pub ny: usize,
243 pub nz: usize,
244 pub nt: usize,
245 /// Grid extents: \[x_min, x_max, y_min, y_max, z_min, z_max\].
246 pub bounds: [f64; 6],
247 /// Time values for each time slice.
248 pub times: Vec<f64>,
249 /// Flat amplitude array, indexed as \[t\]\[z\]\[y\]\[x\], length nx*ny*nz*nt.
250 pub amplitudes: Vec<f64>,
251 /// Flat phase array, indexed as \[t\]\[z\]\[y\]\[x\], length nx*ny*nz*nt.
252 pub phases: Vec<f64>,
253 /// Flat frequency array, indexed as \[t\]\[z\]\[y\]\[x\], length nx*ny*nz*nt.
254 pub frequencies: Vec<f64>,
255 /// Flat manifold coordinates, indexed as \[t\]\[z\]\[y\]\[x\], length nx*ny*nz*nt.
256 pub manifold_coords: Vec<crate::modalities::manifold::ManifoldCoordinate10D>,
257 /// Number of sources.
258 pub num_sources: usize,
259}
260
261/// A single depth sample from `run_emf_sample_at_depth`.
262#[derive(Debug, Clone)]
263pub struct DepthSample {
264 /// Distance from camera/observer (m).
265 pub depth: f64,
266 /// Field amplitude at this depth.
267 pub amplitude: f64,
268 /// Field phase at this depth (radians).
269 pub phase: f64,
270 /// Field frequency at this depth (Hz).
271 pub frequency: f64,
272 /// Perspective scaling factor (1 / depth, clamped).
273 pub perspective_scale: f64,
274 /// Display attenuation factor (0..1, decreases with depth).
275 pub display_attenuation: f64,
276 /// Level-of-detail level (0 = highest detail, increases with depth).
277 pub lod_level: u32,
278 /// 10D manifold coordinate at this sample.
279 pub manifold_coord: crate::modalities::manifold::ManifoldCoordinate10D,
280}
281
282/// Result of `run_emf_sample_at_depth` — depth-aware sampling for render integration.
283#[derive(Debug, Clone)]
284pub struct EmfSampleAtDepthResult {
285 /// One sample per requested depth.
286 pub samples: Vec<DepthSample>,
287 /// Number of depths sampled.
288 pub num_depths: usize,
289 /// Time of the sample.
290 pub time: f64,
291}
292
293/// Simulation result
294#[derive(Debug, Clone)]
295pub struct SimulationResult {
296 pub node_id: String,
297 pub fields: Vec<PhysicsField>,
298 pub convergence_info: ConvergenceInfo,
299 pub performance_info: PerformanceInfo,
300}