chore: sync project state and current artifacts
This commit is contained in:
@@ -218,7 +218,7 @@ impl JacobianMatrix {
|
||||
compute_residuals: F,
|
||||
state: &[f64],
|
||||
residuals: &[f64],
|
||||
epsilon: f64,
|
||||
relative_epsilon: f64,
|
||||
) -> Result<Self, String>
|
||||
where
|
||||
F: Fn(&[f64], &mut [f64]) -> Result<(), String>,
|
||||
@@ -228,17 +228,21 @@ impl JacobianMatrix {
|
||||
let mut matrix = DMatrix::zeros(m, n);
|
||||
|
||||
for j in 0..n {
|
||||
// Perturb state[j]
|
||||
let mut state_perturbed = state.to_vec();
|
||||
state_perturbed[j] += epsilon;
|
||||
// Use relative epsilon scaled to the state variable magnitude.
|
||||
// For variables like P~350,000 Pa or h~400,000 J/kg, an absolute
|
||||
// epsilon of 1e-8 is below library numerical precision and gives zero
|
||||
// finite differences. A relative epsilon of ~1e-5 gives physically
|
||||
// meaningful perturbations across all thermodynamic property scales.
|
||||
let eps_j = state[j].abs().max(1.0) * relative_epsilon;
|
||||
|
||||
let mut state_perturbed = state.to_vec();
|
||||
state_perturbed[j] += eps_j;
|
||||
|
||||
// Compute perturbed residuals
|
||||
let mut residuals_perturbed = vec![0.0; m];
|
||||
compute_residuals(&state_perturbed, &mut residuals_perturbed)?;
|
||||
|
||||
// Compute finite difference
|
||||
for i in 0..m {
|
||||
matrix[(i, j)] = (residuals_perturbed[i] - residuals[i]) / epsilon;
|
||||
matrix[(i, j)] = (residuals_perturbed[i] - residuals[i]) / eps_j;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -324,7 +328,7 @@ impl JacobianMatrix {
|
||||
// col p_idx = 2*i, col h_idx = 2*i+1.
|
||||
// The equation rows mirror the same layout, so row = col for square systems.
|
||||
let indices: Vec<usize> = system
|
||||
.circuit_edges(crate::system::CircuitId(circuit_id))
|
||||
.circuit_edges(crate::CircuitId(circuit_id.into()))
|
||||
.flat_map(|edge| {
|
||||
let (p_idx, h_idx) = system.edge_state_indices(edge);
|
||||
[p_idx, h_idx]
|
||||
|
||||
Reference in New Issue
Block a user