1use super::*;
2#[cfg(not(target_arch = "wasm32"))]
3use crate::acoustic_ble_mesh::{MeshNetworkManager, MessagePriority, NetworkStatus};
4
5pub struct MeshCoordinator {
7 #[cfg(not(target_arch = "wasm32"))]
9 mesh_network: Arc<Mutex<MeshNetworkManager>>,
10 node_manager: NodeManager,
11 load_balancer: MeshLoadBalancer,
12 synchronization: MeshSynchronization,
13}
14
15#[derive(Debug, Clone)]
17pub struct MeshStatus {
18 pub total_nodes: u32,
19 pub acoustic_nodes: u32,
20 pub ble_nodes: u32,
21 pub active_routes: u32,
22 pub pending_messages: u32,
23}
24
25pub struct NodeManager {
27 nodes: HashMap<String, MeshNode>,
28 node_capabilities: HashMap<String, NodeCapabilities>,
29 node_status: HashMap<String, NodeStatus>,
30}
31
32#[derive(Debug, Clone)]
34pub struct MeshNode {
35 pub node_id: String,
36 pub node_type: NodeType,
37 pub capabilities: NodeCapabilities,
38 pub current_load: f64,
39 pub network_address: String,
40 pub last_heartbeat: u64,
41}
42
43#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
45pub enum NodeType {
46 Master,
48 Worker,
50 Storage,
52 Visualization,
54 IO,
56}
57
58#[derive(Debug, Clone)]
60pub struct NodeCapabilities {
61 pub cpu_cores: usize,
62 pub memory_size: u64,
63 pub gpu_count: usize,
64 pub storage_capacity: u64,
65 pub network_bandwidth: f64,
66 pub supported_algorithms: Vec<String>,
67}
68
69#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71pub enum NodeStatus {
72 Active,
73 Idle,
74 Busy,
75 Offline,
76 Error,
77}
78
79pub struct MeshLoadBalancer {
81 balancing_strategy: LoadBalancingStrategy,
82 load_metrics: LoadMetrics,
83 redistribution_policy: RedistributionPolicy,
84}
85
86#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
88pub enum LoadBalancingStrategy {
89 RoundRobin,
91 LoadBased,
93 CapabilityBased,
95 Geographic,
97 Adaptive,
99}
100
101#[derive(Debug, Clone)]
103pub struct LoadMetrics {
104 pub cpu_utilization: f64,
105 pub memory_utilization: f64,
106 pub network_utilization: f64,
107 pub task_completion_rate: f64,
108}
109
110#[derive(Debug, Clone)]
112pub struct RedistributionPolicy {
113 pub redistribution_threshold: f64,
114 pub redistribution_interval: u64,
115 pub max_redistribution_time: u64,
116}
117
118pub struct MeshSynchronization {
120 synchronization_method: SynchronizationMethod,
121 consistency_model: ConsistencyModel,
122 conflict_resolution: ConflictResolution,
123}
124
125#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
127pub enum SynchronizationMethod {
128 Barrier,
130 PointToPoint,
132 Collective,
134 Asynchronous,
136 Hybrid,
138}
139
140#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
142pub enum ConsistencyModel {
143 Strong,
145 Eventual,
147 Causal,
149 Weak,
151 Eventually,
153}
154
155#[derive(Debug, Clone)]
157pub struct ConflictResolution {
158 resolution_strategy: ConflictResolutionStrategy,
159 conflict_detection: ConflictDetection,
160 resolution_policy: ResolutionPolicy,
161}
162
163#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
165pub enum ConflictResolutionStrategy {
166 LastWriterWins,
168 FirstWriterWins,
170 VectorClock,
172 LamportTimestamp,
174 Paxos,
176 Raft,
178}
179
180#[derive(Debug, Clone)]
182pub struct ConflictDetection {
183 detection_method: ConflictDetectionMethod,
184 conflict_types: Vec<ConflictType>,
185}
186
187#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
189pub enum ConflictDetectionMethod {
190 VersionNumber,
192 Timestamp,
194 HashBased,
196 ContentBased,
198}
199
200#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
202pub enum ConflictType {
203 WriteWrite,
205 ReadWrite,
207 UpdateUpdate,
209 DeleteUpdate,
211}
212
213#[derive(Debug, Clone)]
215pub struct ResolutionPolicy {
216 policy_id: String,
217 policy_rules: Vec<ResolutionRule>,
218 default_action: ResolutionAction,
219}
220
221#[derive(Debug, Clone)]
223pub struct ResolutionRule {
224 pub rule_id: String,
225 pub condition: String,
226 pub action: ResolutionAction,
227 pub priority: u32,
228}
229
230#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
232pub enum ResolutionAction {
233 Accept,
234 Reject,
235 Merge,
236 Transform,
237 Escalate,
238}
239
240impl MeshCoordinator {
241 pub fn new() -> Self {
243 Self {
244 #[cfg(not(target_arch = "wasm32"))]
245 mesh_network: Arc::new(Mutex::new(MeshNetworkManager::new())),
246 node_manager: NodeManager::new(),
247 load_balancer: MeshLoadBalancer::new(),
248 synchronization: MeshSynchronization::new(),
249 }
250 }
251
252 pub fn initialize(&mut self) -> Result<(), PhysicsError> {
254 self.node_manager.initialize()?;
255 self.load_balancer.initialize()?;
256 self.synchronization.initialize()?;
257 Ok(())
258 }
259
260 pub fn initialize_mesh_network(&mut self) -> Result<(), PhysicsError> {
262 #[cfg(not(target_arch = "wasm32"))]
263 {
264 let mut network = self.mesh_network.lock().map_err(|e| {
265 PhysicsError::NetworkError(format!("Mesh network lock poisoned: {}", e))
266 })?;
267 return network
268 .initialize()
269 .map_err(|e| PhysicsError::NetworkError(format!("Mesh init failed: {}", e)));
270 }
271 #[cfg(target_arch = "wasm32")]
272 Err(PhysicsError::NetworkError(
273 "BLE/acoustic mesh cannot run in WASM".into(),
274 ))
275 }
276
277 pub fn get_mesh_status(&self) -> Result<MeshStatus, PhysicsError> {
279 #[cfg(not(target_arch = "wasm32"))]
280 {
281 let network = self.mesh_network.lock().map_err(|e| {
282 PhysicsError::NetworkError(format!("Mesh network lock poisoned: {}", e))
283 })?;
284 let status: NetworkStatus = network.get_network_status();
285 return Ok(MeshStatus {
286 total_nodes: status.total_nodes,
287 acoustic_nodes: status.acoustic_nodes,
288 ble_nodes: status.ble_nodes,
289 active_routes: status.active_routes,
290 pending_messages: status.pending_messages,
291 });
292 }
293 #[cfg(target_arch = "wasm32")]
294 Err(PhysicsError::NetworkError(
295 "BLE/acoustic mesh cannot run in WASM".into(),
296 ))
297 }
298
299 pub fn distribute_simulation_task(&self, task_data: &[u8]) -> Result<(), PhysicsError> {
301 #[cfg(not(target_arch = "wasm32"))]
302 {
303 let mut network = self.mesh_network.lock().map_err(|e| {
304 PhysicsError::NetworkError(format!("Mesh network lock poisoned: {}", e))
305 })?;
306 network
307 .send_message_ephemeral("broadcast", task_data, MessagePriority::High)
308 .map_err(|e| PhysicsError::NetworkError(format!("Mesh send failed: {}", e)))?;
309 return Ok(());
310 }
311 #[cfg(target_arch = "wasm32")]
312 {
313 let _ = task_data;
314 Err(PhysicsError::NetworkError(
315 "BLE/acoustic mesh cannot run in WASM".into(),
316 ))
317 }
318 }
319
320 pub fn distribute_simulation(
324 &self,
325 simulation: &Simulation,
326 ) -> Result<NodeDistribution, PhysicsError> {
327 let mut node_ids: Vec<String> = self.node_manager.nodes.keys().cloned().collect();
328 if node_ids.is_empty() {
329 return Err(PhysicsError::InvalidConfiguration(
330 "No worker nodes registered in mesh coordinator".into(),
331 ));
332 }
333 node_ids.sort();
334
335 let n = node_ids.len();
336 let capacities: Vec<f64> = node_ids
338 .iter()
339 .map(|id| {
340 let load = self.node_manager.nodes.get(id).map(|node| node.current_load).unwrap_or(0.0);
341 (1.0 - load).max(0.05)
342 })
343 .collect();
344
345 let total_cap: f64 = capacities.iter().sum();
346 let node_loads: Vec<f64> = if total_cap > 0.0 {
347 capacities
348 .iter()
349 .map(|c| (c / total_cap * 1000.0).round() / 1000.0)
350 .collect()
351 } else {
352 vec![1.0 / n as f64; n]
353 };
354
355 let communication_pattern = if simulation.mesh.is_some() {
357 CommunicationPattern::Neighborhood
358 } else if n > 4 {
359 CommunicationPattern::Collective
360 } else if n > 1 {
361 CommunicationPattern::PointToPoint
362 } else {
363 CommunicationPattern::Hybrid
364 };
365
366 let distribution = NodeDistribution {
367 node_ids,
368 node_loads,
369 communication_pattern,
370 };
371
372 Ok(distribution)
373 }
374
375 pub fn collect_results(
377 &self,
378 results: &[SimulationResult],
379 ) -> Result<Vec<PhysicsField>, PhysicsError> {
380 if results.is_empty() {
381 return Ok(Vec::new());
382 }
383 let mut field_groups: HashMap<String, Vec<&PhysicsField>> = HashMap::new();
385 for result in results {
386 for field in &result.fields {
387 let base_name = field
389 .field_id
390 .split('_')
391 .next()
392 .unwrap_or(&field.field_id)
393 .to_string();
394 field_groups.entry(base_name).or_default().push(field);
395 }
396 }
397 let mut combined_fields = Vec::new();
398 for (base_name, fields) in field_groups {
399 if fields.is_empty() {
400 continue;
401 }
402 let dim = fields[0].dimensions.clone();
403 let data_len = fields[0].data.len();
404 let mut combined_data = vec![0.0f64; data_len];
405 for field in &fields {
406 if field.data.len() == data_len {
407 for (i, &v) in field.data.iter().enumerate() {
408 combined_data[i] += v;
409 }
410 }
411 }
412 let count = fields.len() as f64;
413 for v in &mut combined_data {
414 *v /= count;
415 }
416 combined_fields.push(PhysicsField {
417 field_id: base_name.clone(),
418 field_type: fields[0].field_type.clone(),
419 dimensions: dim,
420 data: combined_data,
421 metadata: FieldMetadata {
422 field_name: fields[0].metadata.field_name.clone(),
423 physical_quantity: fields[0].metadata.physical_quantity.clone(),
424 units: fields[0].metadata.units.clone(),
425 time_step: fields[0].metadata.time_step,
426 iteration: fields[0].metadata.iteration,
427 },
428 });
429 }
430 Ok(combined_fields)
431 }
432}
433
434impl NodeManager {
435 pub fn new() -> Self {
437 Self {
438 nodes: HashMap::new(),
439 node_capabilities: HashMap::new(),
440 node_status: HashMap::new(),
441 }
442 }
443
444 pub fn initialize(&mut self) -> Result<(), PhysicsError> {
446 let now = std::time::SystemTime::now()
447 .duration_since(std::time::UNIX_EPOCH)
448 .unwrap()
449 .as_secs();
450
451 let node1 = MeshNode {
453 node_id: "node1".to_string(),
454 node_type: NodeType::Worker,
455 capabilities: NodeCapabilities::new(),
456 current_load: 0.0,
457 network_address: "192.168.1.1".to_string(),
458 last_heartbeat: now,
459 };
460 let node2 = MeshNode {
461 node_id: "node2".to_string(),
462 node_type: NodeType::Worker,
463 capabilities: NodeCapabilities::new(),
464 current_load: 0.0,
465 network_address: "192.168.1.2".to_string(),
466 last_heartbeat: now,
467 };
468 let node3 = MeshNode {
469 node_id: "node3".to_string(),
470 node_type: NodeType::Worker,
471 capabilities: NodeCapabilities::new(),
472 current_load: 0.0,
473 network_address: "192.168.1.3".to_string(),
474 last_heartbeat: now,
475 };
476
477 self.nodes.insert("node1".to_string(), node1);
478 self.nodes.insert("node2".to_string(), node2);
479 self.nodes.insert("node3".to_string(), node3);
480 Ok(())
481 }
482
483 pub fn add_node_capability(&mut self, node_id: &str, caps: NodeCapabilities) {
485 self.node_capabilities.insert(node_id.to_string(), caps);
486 }
487
488 pub fn get_node_capability(&self, node_id: &str) -> Option<&NodeCapabilities> {
490 self.node_capabilities.get(node_id)
491 }
492
493 pub fn set_node_status(&mut self, node_id: &str, status: NodeStatus) {
495 self.node_status.insert(node_id.to_string(), status);
496 }
497
498 pub fn get_node_status(&self, node_id: &str) -> Option<&NodeStatus> {
500 self.node_status.get(node_id)
501 }
502
503 pub fn list_node_status_ids(&self) -> Vec<String> {
505 self.node_status.keys().cloned().collect()
506 }
507}
508
509impl NodeCapabilities {
510 pub fn new() -> Self {
512 Self {
513 cpu_cores: 8,
514 memory_size: 16 * 1024 * 1024 * 1024, gpu_count: 1,
516 storage_capacity: 1 * 1024 * 1024 * 1024 * 1024, network_bandwidth: 1000.0, supported_algorithms: vec!["CFD".to_string(), "FEM".to_string()],
519 }
520 }
521}
522
523impl MeshLoadBalancer {
524 pub fn new() -> Self {
526 Self {
527 balancing_strategy: LoadBalancingStrategy::LoadBased,
528 load_metrics: LoadMetrics::new(),
529 redistribution_policy: RedistributionPolicy::new(),
530 }
531 }
532
533 pub fn initialize(&mut self) -> Result<(), PhysicsError> {
535 Ok(())
536 }
537
538 pub fn get_balancing_strategy(&self) -> &LoadBalancingStrategy {
540 &self.balancing_strategy
541 }
542
543 pub fn set_balancing_strategy(&mut self, strategy: LoadBalancingStrategy) {
545 self.balancing_strategy = strategy;
546 }
547
548 pub fn get_load_metrics(&self) -> &LoadMetrics {
550 &self.load_metrics
551 }
552
553 pub fn get_load_metrics_mut(&mut self) -> &mut LoadMetrics {
555 &mut self.load_metrics
556 }
557
558 pub fn get_redistribution_policy(&self) -> &RedistributionPolicy {
560 &self.redistribution_policy
561 }
562
563 pub fn get_redistribution_policy_mut(&mut self) -> &mut RedistributionPolicy {
565 &mut self.redistribution_policy
566 }
567}
568
569impl LoadMetrics {
570 pub fn new() -> Self {
572 Self {
573 cpu_utilization: 0.0,
574 memory_utilization: 0.0,
575 network_utilization: 0.0,
576 task_completion_rate: 0.0,
577 }
578 }
579}
580
581impl RedistributionPolicy {
582 pub fn new() -> Self {
584 Self {
585 redistribution_threshold: 0.8,
586 redistribution_interval: 60, max_redistribution_time: 300, }
589 }
590}
591
592impl MeshSynchronization {
593 pub fn new() -> Self {
595 Self {
596 synchronization_method: SynchronizationMethod::Hybrid,
597 consistency_model: ConsistencyModel::Eventual,
598 conflict_resolution: ConflictResolution::new(),
599 }
600 }
601
602 pub fn initialize(&mut self) -> Result<(), PhysicsError> {
604 self.conflict_resolution.initialize()?;
605 Ok(())
606 }
607
608 pub fn get_synchronization_method(&self) -> &SynchronizationMethod {
610 &self.synchronization_method
611 }
612
613 pub fn set_synchronization_method(&mut self, method: SynchronizationMethod) {
615 self.synchronization_method = method;
616 }
617
618 pub fn get_consistency_model(&self) -> &ConsistencyModel {
620 &self.consistency_model
621 }
622
623 pub fn set_consistency_model(&mut self, model: ConsistencyModel) {
625 self.consistency_model = model;
626 }
627}
628
629impl ConflictResolution {
630 pub fn new() -> Self {
632 Self {
633 resolution_strategy: ConflictResolutionStrategy::LastWriterWins,
634 conflict_detection: ConflictDetection::new(),
635 resolution_policy: ResolutionPolicy::new(),
636 }
637 }
638
639 pub fn initialize(&mut self) -> Result<(), PhysicsError> {
641 Ok(())
642 }
643
644 pub fn get_resolution_strategy(&self) -> &ConflictResolutionStrategy {
646 &self.resolution_strategy
647 }
648
649 pub fn set_resolution_strategy(&mut self, strategy: ConflictResolutionStrategy) {
651 self.resolution_strategy = strategy;
652 }
653
654 pub fn get_conflict_detection(&self) -> &ConflictDetection {
656 &self.conflict_detection
657 }
658
659 pub fn get_conflict_detection_mut(&mut self) -> &mut ConflictDetection {
661 &mut self.conflict_detection
662 }
663
664 pub fn get_resolution_policy(&self) -> &ResolutionPolicy {
666 &self.resolution_policy
667 }
668
669 pub fn get_resolution_policy_mut(&mut self) -> &mut ResolutionPolicy {
671 &mut self.resolution_policy
672 }
673}
674
675impl ConflictDetection {
676 pub fn new() -> Self {
678 Self {
679 detection_method: ConflictDetectionMethod::Timestamp,
680 conflict_types: vec![ConflictType::WriteWrite],
681 }
682 }
683
684 pub fn get_detection_method(&self) -> &ConflictDetectionMethod {
686 &self.detection_method
687 }
688
689 pub fn set_detection_method(&mut self, method: ConflictDetectionMethod) {
691 self.detection_method = method;
692 }
693
694 pub fn get_conflict_types(&self) -> &[ConflictType] {
696 &self.conflict_types
697 }
698
699 pub fn add_conflict_type(&mut self, ctype: ConflictType) {
701 self.conflict_types.push(ctype);
702 }
703}
704
705impl ResolutionPolicy {
706 pub fn new() -> Self {
708 Self {
709 policy_id: "default".to_string(),
710 policy_rules: Vec::new(),
711 default_action: ResolutionAction::Accept,
712 }
713 }
714
715 pub fn get_policy_id(&self) -> &str {
717 &self.policy_id
718 }
719
720 pub fn get_policy_rules(&self) -> &[ResolutionRule] {
722 &self.policy_rules
723 }
724
725 pub fn add_policy_rule(&mut self, rule: ResolutionRule) {
727 self.policy_rules.push(rule);
728 }
729
730 pub fn get_default_action(&self) -> &ResolutionAction {
732 &self.default_action
733 }
734
735 pub fn set_default_action(&mut self, action: ResolutionAction) {
737 self.default_action = action;
738 }
739}
740
741impl PhysicsSimulationLibrary {
742 pub fn run_distributed_simulation(
744 &mut self,
745 simulation: &mut Simulation,
746 ) -> Result<PhysicsSimulationResult<Vec<PhysicsField>>, PhysicsError> {
747 let start_time = std::time::Instant::now();
748
749 self.mesh_coordinator.initialize_mesh_network()?;
751
752 let node_distribution = self.mesh_coordinator.distribute_simulation(simulation)?;
754
755 let mut results = Vec::new();
757 for node_id in node_distribution.node_ids {
758 let node_result = self.run_simulation_on_node(simulation, &node_id)?;
759 results.push(node_result);
760 }
761
762 let final_result = self.mesh_coordinator.collect_results(&results)?;
764
765 let simulation_time = start_time.elapsed().as_millis() as u64;
766
767 let all_converged =
770 !results.is_empty() && results.iter().all(|r| r.convergence_info.converged);
771 let agg_residual = results
772 .iter()
773 .map(|r| r.convergence_info.residual_norm)
774 .fold(0.0f64, f64::max);
775 let agg_iterations = results
776 .iter()
777 .map(|r| r.convergence_info.iterations)
778 .max()
779 .unwrap_or(0);
780 let agg_conv_rate = results
781 .iter()
782 .map(|r| r.convergence_info.convergence_rate)
783 .fold(0.0f64, f64::max);
784
785 Ok(PhysicsSimulationResult {
786 result: final_result,
787 simulation_time,
788 solver_time: simulation_time,
789 data_time: 0,
790 convergence_info: ConvergenceInfo {
791 converged: all_converged,
792 iterations: agg_iterations,
793 residual_norm: agg_residual,
794 convergence_rate: agg_conv_rate,
795 final_error: agg_residual,
796 },
797 performance_info: PerformanceInfo {
799 cpu_utilization: 0.0,
800 memory_utilization: 0.0,
801 network_utilization: 0.0,
802 io_utilization: 0.0,
803 parallel_efficiency: 0.0,
804 },
805 })
806 }
807 fn run_simulation_on_node(
808 &self,
809 simulation: &Simulation,
810 node_id: &str,
811 ) -> Result<SimulationResult, PhysicsError> {
812 let nx = simulation.config.spatial_resolution.nx;
813 let dx = simulation.config.spatial_resolution.dx;
814 let dt = simulation.config.time_step;
815 let nu = 1.5e-5_f64; let mut u = vec![0.0f64; nx];
819 for i in 0..nx {
820 let x = i as f64 * dx;
821 u[i] = (std::f64::consts::PI * x).sin();
822 }
823 let steps = ((simulation.config.total_time / dt) as usize)
824 .max(1)
825 .min(500);
826 let mut residual = f64::INFINITY;
827 let mut prev_residual = f64::INFINITY;
828 for _ in 0..steps {
829 let mut u_new = u.clone();
830 let mut sumsq = 0.0f64;
831 for i in 1..nx - 1 {
832 let advection = -u[i] * (u[i + 1] - u[i - 1]) / (2.0 * dx);
833 let diffusion = nu * (u[i + 1] - 2.0 * u[i] + u[i - 1]) / (dx * dx);
834 u_new[i] = u[i] + dt * (advection + diffusion);
835 let d = u_new[i] - u[i];
836 sumsq += d * d;
837 }
838 prev_residual = residual;
839 residual = sumsq.sqrt();
840 u = u_new;
841 }
842 let node_converged = residual.is_finite() && residual < 1e-6;
844 let node_conv_rate = if prev_residual.is_finite() && prev_residual > 0.0 {
845 residual / prev_residual
846 } else {
847 0.0
848 };
849 let node_residual = if residual.is_finite() {
850 residual
851 } else {
852 f64::MAX
853 };
854
855 let rho = 1.225_f64;
857 let p_ref = 101325.0_f64;
858 let pressure: Vec<f64> = u.iter().map(|&ui| p_ref - 0.5 * rho * ui * ui).collect();
859
860 let gamma = 1.4_f64;
862 let t0 = 293.15_f64;
863 let temperature: Vec<f64> = pressure
864 .iter()
865 .map(|&pi| t0 * (pi / p_ref).powf((gamma - 1.0) / gamma))
866 .collect();
867
868 let velocity_field = PhysicsField {
869 field_id: format!("velocity_{}", node_id),
870 field_type: FieldType::Vector,
871 dimensions: vec![nx],
872 data: u,
873 metadata: FieldMetadata {
874 field_name: "Velocity".to_string(),
875 physical_quantity: "Velocity".to_string(),
876 units: "m/s".to_string(),
877 time_step: steps as u64,
878 iteration: steps as u64,
879 },
880 };
881 let pressure_field = PhysicsField {
882 field_id: format!("pressure_{}", node_id),
883 field_type: FieldType::Scalar,
884 dimensions: vec![nx],
885 data: pressure,
886 metadata: FieldMetadata {
887 field_name: "Pressure".to_string(),
888 physical_quantity: "Pressure".to_string(),
889 units: "Pa".to_string(),
890 time_step: steps as u64,
891 iteration: steps as u64,
892 },
893 };
894 let temperature_field = PhysicsField {
895 field_id: format!("temperature_{}", node_id),
896 field_type: FieldType::Scalar,
897 dimensions: vec![nx],
898 data: temperature,
899 metadata: FieldMetadata {
900 field_name: "Temperature".to_string(),
901 physical_quantity: "Temperature".to_string(),
902 units: "K".to_string(),
903 time_step: steps as u64,
904 iteration: steps as u64,
905 },
906 };
907
908 Ok(SimulationResult {
909 node_id: node_id.to_string(),
910 fields: vec![velocity_field, pressure_field, temperature_field],
911 convergence_info: ConvergenceInfo {
912 converged: node_converged,
913 iterations: steps as u32,
914 residual_norm: node_residual,
915 convergence_rate: node_conv_rate,
916 final_error: node_residual,
917 },
918 performance_info: PerformanceInfo {
921 cpu_utilization: 0.0,
922 memory_utilization: 0.0,
923 network_utilization: 0.0,
924 io_utilization: 0.0,
925 parallel_efficiency: 0.0,
926 },
927 })
928 }
929}