-
Notifications
You must be signed in to change notification settings - Fork 57
Open
Description
Hi,
I'm having a use case where I have multiple fields defined on a common interpolation grid. My current implementation is to do something like this
struct PointWithHeight{
position: Point2<f64>,
height: f64,
}
impl HasPosition for PointWithHeight {
type Scalar = f64;
fn position(&self) -> Point2<f64> {
self.position
}
}
pub fn interpolate_field(
field: &ArrayView2<f64>,
r_in: &ArrayView2<f64>,
z_in: &ArrayView2<f64>,
r_out: &ArrayView2<f64>,
z_out: &ArrayView2<f64>,
) -> Array2<f64> {
let mut triangulation = DelaunayTriangulation::<PointWithHeight>::new();
for ((&r, &z), &value) in r_in.iter().zip(z_in.iter()).zip(field.iter()) {
let point = PointWithHeight {
position: Point2::new(r, z),
height: value,
};
triangulation.insert(point).unwrap();
}
let mut query_values = Array2::<f64>::zeros(r_out.raw_dim());
let interpolator = triangulation.natural_neighbor();
Zip::from(&mut query_values).and(r_out).and(z_out).for_each(|qv, &r, &z| {
let query_point = Point2::new(r, z);
*qv = interpolator.interpolate(|v| v.data().height, query_point).unwrap_or(f64::NAN);
});
return query_values;
}and then do something like
let interp_f1 = interpolate_field(f1,r,z,r_out,z_out);
...
let interp_fn = interpolate_field(fn,r,z,r_out,z_out); It seems a little wasteful to build the triangulation over and over again. Is there any way to save the triangulation and simply change the field values?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels