chore: remove BMAD framework files and IDE configuration artifacts
Clean up unused BMAD workflow, agent, and command files across all IDE configurations (.agent, .clinerules, .cursor, .gemini, .github, .kilocode, .opencode) and internal module files (_bmad/bmb, _bmad/bmm). Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
140
crates/solver/src/snapshot.rs
Normal file
140
crates/solver/src/snapshot.rs
Normal file
@@ -0,0 +1,140 @@
|
||||
//! System snapshot structures for JSON serialization/deserialization
|
||||
//!
|
||||
//! This module provides types for capturing complete system state including
|
||||
//! topology, component parameters, fluid state, and backend information.
|
||||
|
||||
use crate::coupling::ThermalCoupling;
|
||||
use entropyk_components::ComponentParams;
|
||||
use entropyk_core::SystemState;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
/// Snapshot of the complete system for serialization
|
||||
///
|
||||
/// Contains all information needed to reconstruct an identical system:
|
||||
/// - Topology (components and their connections)
|
||||
/// - Component parameters
|
||||
/// - Fluid state (pressures and enthalpies)
|
||||
/// - Fluid backend information
|
||||
/// - Solver configuration
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct SystemSnapshot {
|
||||
/// Schema version for forward/backward compatibility
|
||||
pub version: String,
|
||||
/// System topology (components, edges, thermal couplings)
|
||||
pub topology: TopologySnapshot,
|
||||
/// Component-specific parameters indexed by component name
|
||||
#[serde(default)]
|
||||
pub parameters: std::collections::HashMap<String, ComponentParams>,
|
||||
/// Fluid state (edge pressures and enthalpies)
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub fluid_state: Option<SystemState>,
|
||||
/// Fluid backend information
|
||||
pub fluid_backend: FluidBackendInfo,
|
||||
/// Solver configuration
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub solver_config: Option<SolverConfigSnapshot>,
|
||||
/// Optional metadata
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub metadata: std::collections::HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
/// Snapshot of system topology
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct TopologySnapshot {
|
||||
/// Flow edges between components
|
||||
#[serde(default)]
|
||||
pub edges: Vec<EdgeSnapshot>,
|
||||
/// Thermal couplings between circuits
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub thermal_couplings: Vec<ThermalCoupling>,
|
||||
}
|
||||
|
||||
/// Snapshot of a flow edge
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct EdgeSnapshot {
|
||||
/// Source component name
|
||||
pub source: String,
|
||||
/// Source port name
|
||||
pub source_port: String,
|
||||
/// Target component name
|
||||
pub target: String,
|
||||
/// Target port name
|
||||
pub target_port: String,
|
||||
/// Circuit ID
|
||||
pub circuit_id: u16,
|
||||
}
|
||||
|
||||
/// Information about the fluid backend
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct FluidBackendInfo {
|
||||
/// Backend name (e.g., "CoolPropBackend", "TabularBackend")
|
||||
pub name: String,
|
||||
/// Backend version
|
||||
pub version: String,
|
||||
/// Backend hash for verification
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub hash: Option<String>,
|
||||
}
|
||||
|
||||
/// Snapshot of solver configuration
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
pub struct SolverConfigSnapshot {
|
||||
/// Solver type ("NewtonRaphson", "SequentialSubstitution", etc.)
|
||||
pub solver_type: String,
|
||||
/// Maximum iterations
|
||||
pub max_iterations: usize,
|
||||
/// Convergence tolerance
|
||||
pub tolerance: f64,
|
||||
/// Divergence threshold
|
||||
pub divergence_threshold: f64,
|
||||
}
|
||||
|
||||
impl Default for SolverConfigSnapshot {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
solver_type: "NewtonRaphson".to_string(),
|
||||
max_iterations: 100,
|
||||
tolerance: 1e-6,
|
||||
divergence_threshold: 1e10,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_system_snapshot_serialization() {
|
||||
let snapshot = SystemSnapshot {
|
||||
version: "1.0".to_string(),
|
||||
topology: TopologySnapshot {
|
||||
edges: vec![],
|
||||
thermal_couplings: vec![],
|
||||
},
|
||||
parameters: HashMap::new(),
|
||||
fluid_state: None,
|
||||
fluid_backend: FluidBackendInfo {
|
||||
name: "TestBackend".to_string(),
|
||||
version: "1.0.0".to_string(),
|
||||
hash: Some("abc123".to_string()),
|
||||
},
|
||||
solver_config: Some(SolverConfigSnapshot::default()),
|
||||
metadata: HashMap::new(),
|
||||
};
|
||||
|
||||
let json = serde_json::to_string_pretty(&snapshot).unwrap();
|
||||
let deserialized: SystemSnapshot = serde_json::from_str(&json).unwrap();
|
||||
|
||||
assert_eq!(snapshot, deserialized);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_solver_config_default() {
|
||||
let config = SolverConfigSnapshot::default();
|
||||
assert_eq!(config.solver_type, "NewtonRaphson");
|
||||
assert_eq!(config.max_iterations, 100);
|
||||
assert_eq!(config.tolerance, 1e-6);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user