Update project structure and configurations
This commit is contained in:
@@ -18,6 +18,7 @@ use std::collections::HashMap;
|
||||
/// - Fluid backend information
|
||||
/// - Solver configuration
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SystemSnapshot {
|
||||
/// Schema version for forward/backward compatibility
|
||||
pub version: String,
|
||||
@@ -25,7 +26,7 @@ pub struct SystemSnapshot {
|
||||
pub topology: TopologySnapshot,
|
||||
/// Component-specific parameters indexed by component name
|
||||
#[serde(default)]
|
||||
pub parameters: std::collections::HashMap<String, ComponentParams>,
|
||||
pub parameters: HashMap<String, ComponentParams>,
|
||||
/// Fluid state (edge pressures and enthalpies)
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub fluid_state: Option<SystemState>,
|
||||
@@ -34,13 +35,26 @@ pub struct SystemSnapshot {
|
||||
/// Solver configuration
|
||||
#[serde(default, skip_serializing_if = "Option::is_none")]
|
||||
pub solver_config: Option<SolverConfigSnapshot>,
|
||||
/// Component name → type mapping for stable reconstruction
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub component_names: HashMap<String, String>,
|
||||
/// Component name → circuit ID mapping
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub circuit_assignments: HashMap<String, u16>,
|
||||
/// Constraints for inverse control
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub constraints: Vec<ConstraintSnapshot>,
|
||||
/// Bounded control variables for inverse control
|
||||
#[serde(default, skip_serializing_if = "Vec::is_empty")]
|
||||
pub bounded_variables: Vec<BoundedVariableSnapshot>,
|
||||
/// Optional metadata
|
||||
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
|
||||
pub metadata: std::collections::HashMap<String, serde_json::Value>,
|
||||
pub metadata: HashMap<String, serde_json::Value>,
|
||||
}
|
||||
|
||||
/// Snapshot of system topology
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct TopologySnapshot {
|
||||
/// Flow edges between components
|
||||
#[serde(default)]
|
||||
@@ -52,14 +66,17 @@ pub struct TopologySnapshot {
|
||||
|
||||
/// Snapshot of a flow edge
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct EdgeSnapshot {
|
||||
/// Source component name
|
||||
pub source: String,
|
||||
/// Source port name
|
||||
#[serde(default)]
|
||||
pub source_port: String,
|
||||
/// Target component name
|
||||
pub target: String,
|
||||
/// Target port name
|
||||
#[serde(default)]
|
||||
pub target_port: String,
|
||||
/// Circuit ID
|
||||
pub circuit_id: u16,
|
||||
@@ -67,6 +84,7 @@ pub struct EdgeSnapshot {
|
||||
|
||||
/// Information about the fluid backend
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct FluidBackendInfo {
|
||||
/// Backend name (e.g., "CoolPropBackend", "TabularBackend")
|
||||
pub name: String,
|
||||
@@ -79,6 +97,7 @@ pub struct FluidBackendInfo {
|
||||
|
||||
/// Snapshot of solver configuration
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct SolverConfigSnapshot {
|
||||
/// Solver type ("NewtonRaphson", "SequentialSubstitution", etc.)
|
||||
pub solver_type: String,
|
||||
@@ -101,6 +120,38 @@ impl Default for SolverConfigSnapshot {
|
||||
}
|
||||
}
|
||||
|
||||
/// Snapshot of a constraint for inverse control
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct ConstraintSnapshot {
|
||||
/// Constraint identifier
|
||||
pub id: String,
|
||||
/// Component name the constraint targets
|
||||
pub component: String,
|
||||
/// Output type being constrained (e.g., "capacity", "superheat")
|
||||
pub output_type: String,
|
||||
/// Target value for the constraint
|
||||
pub target: f64,
|
||||
}
|
||||
|
||||
/// Snapshot of a bounded control variable
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq)]
|
||||
#[serde(rename_all = "camelCase")]
|
||||
pub struct BoundedVariableSnapshot {
|
||||
/// Variable identifier
|
||||
pub id: String,
|
||||
/// Component name the variable belongs to
|
||||
pub component: String,
|
||||
/// Variable name (e.g., "f_m", "f_power", "opening")
|
||||
pub variable_name: String,
|
||||
/// Lower bound
|
||||
pub lower_bound: f64,
|
||||
/// Upper bound
|
||||
pub upper_bound: f64,
|
||||
/// Initial value
|
||||
pub initial_value: f64,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -121,6 +172,10 @@ mod tests {
|
||||
hash: Some("abc123".to_string()),
|
||||
},
|
||||
solver_config: Some(SolverConfigSnapshot::default()),
|
||||
component_names: HashMap::new(),
|
||||
circuit_assignments: HashMap::new(),
|
||||
constraints: vec![],
|
||||
bounded_variables: vec![],
|
||||
metadata: HashMap::new(),
|
||||
};
|
||||
|
||||
@@ -137,4 +192,35 @@ mod tests {
|
||||
assert_eq!(config.max_iterations, 100);
|
||||
assert_eq!(config.tolerance, 1e-6);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_camel_case_output() {
|
||||
let edge = EdgeSnapshot {
|
||||
source: "comp_a".to_string(),
|
||||
source_port: "outlet".to_string(),
|
||||
target: "comp_b".to_string(),
|
||||
target_port: "inlet".to_string(),
|
||||
circuit_id: 0,
|
||||
};
|
||||
let json = serde_json::to_string(&edge).unwrap();
|
||||
assert!(json.contains("\"sourcePort\""));
|
||||
assert!(json.contains("\"targetPort\""));
|
||||
assert!(json.contains("\"circuitId\""));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_backward_compat_missing_fields() {
|
||||
// Old snapshot without new fields should deserialize with defaults
|
||||
let old_json = r#"{
|
||||
"version": "1.0",
|
||||
"topology": { "edges": [] },
|
||||
"parameters": {},
|
||||
"fluidBackend": { "name": "Test", "version": "1.0" }
|
||||
}"#;
|
||||
let snapshot: SystemSnapshot = serde_json::from_str(old_json).unwrap();
|
||||
assert!(snapshot.component_names.is_empty());
|
||||
assert!(snapshot.circuit_assignments.is_empty());
|
||||
assert!(snapshot.constraints.is_empty());
|
||||
assert!(snapshot.bounded_variables.is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user