use alloc::format;
use alloc::vec::Vec;
use deep_causality_physics::PhysicsError;
use deep_causality_physics::PressureZeroForm;
use deep_causality_physics::SolenoidalField;
use deep_causality_physics::VelocityOneForm;
use super::DecNsSolver;
use crate::solvers::dec::DecNsScalar;
impl<const D: usize, R: DecNsScalar> DecNsSolver<'_, D, R> {
pub fn pressure_diagnostic(
&self,
state: &SolenoidalField<R>,
) -> Result<(PressureZeroForm<R>, PressureZeroForm<R>), PhysicsError> {
let u = VelocityOneForm::from_raw(state.as_one_form().clone());
let (_projected_rhs, potential) = self
.rate
.eval_projected_with_potential(&u, &self.cg_options)
.map_err(|e| {
PhysicsError::TopologyError(format!("pressure diagnostic projection failed: {e}"))
})?;
let bernoulli: Vec<R> = potential.as_slice().to_vec();
let vertex_vectors = self
.manifold
.sharp(state.as_one_form())
.map_err(|e| PhysicsError::TopologyError(format!("sharp failed: {e}")))?;
let half = R::from_f64(0.5)
.expect("0.5 lifts into R");
let kinetic: Vec<R> = vertex_vectors
.as_slice()
.as_chunks::<D>()
.0
.iter()
.map(|v| v.iter().fold(R::zero(), |acc, x| acc + *x * *x) * half)
.collect();
let stat: Vec<R> = bernoulli
.iter()
.zip(kinetic.iter())
.map(|(b, k)| *b - *k)
.collect();
let n0 = bernoulli.len();
let bernoulli_tensor = deep_causality_tensor::CausalTensor::new(bernoulli, alloc::vec![n0])
.expect("1-D tensor allocation cannot fail");
let static_tensor = deep_causality_tensor::CausalTensor::new(stat, alloc::vec![n0])
.expect("1-D tensor allocation cannot fail");
let bernoulli_form = PressureZeroForm::new(bernoulli_tensor, self.manifold)?;
let static_form = PressureZeroForm::new(static_tensor, self.manifold)?;
Ok((bernoulli_form, static_form))
}
}