use crate::error::DiffError;
use crate::numerical_derivative::DerivatorMultiVariable;
use crate::scalar::Component;
use crate::scalar::{Numeric, VectorFn};
pub fn curl_3d<D: DerivatorMultiVariable, F: VectorFn<NUM_VARS, 3>, const NUM_VARS: usize>(
derivator: D,
vector_field: &F,
point: &[D::Scalar; NUM_VARS],
) -> Result<[D::Scalar; 3], DiffError> {
let vx = Component::new(vector_field, 0);
let vy = Component::new(vector_field, 1);
let vz = Component::new(vector_field, 2);
let mut ans = [<D::Scalar as Numeric>::ZERO; 3];
ans[0] = derivator.first_partial_derivative(&vz, 1, point)?
- derivator.first_partial_derivative(&vy, 2, point)?;
ans[1] = derivator.first_partial_derivative(&vx, 2, point)?
- derivator.first_partial_derivative(&vz, 0, point)?;
ans[2] = derivator.first_partial_derivative(&vy, 0, point)?
- derivator.first_partial_derivative(&vx, 1, point)?;
Ok(ans)
}
pub fn curl_2d<D: DerivatorMultiVariable, F: VectorFn<NUM_VARS, 2>, const NUM_VARS: usize>(
derivator: D,
vector_field: &F,
point: &[D::Scalar; NUM_VARS],
) -> Result<D::Scalar, DiffError> {
let vx = Component::new(vector_field, 0);
let vy = Component::new(vector_field, 1);
Ok(derivator.first_partial_derivative(&vy, 0, point)?
- derivator.first_partial_derivative(&vx, 1, point)?)
}