Add structures for element and assembly motions

This commit is contained in:
Aaron Fenyes 2024-12-17 18:21:53 -08:00
parent 90834fbb93
commit 4fd79b9e47
2 changed files with 20 additions and 6 deletions

View File

@ -119,6 +119,13 @@ pub struct Constraint {
pub active: Signal<bool> pub active: Signal<bool>
} }
pub struct ElementMotion<'a> {
pub key: ElementKey,
pub velocity: DVectorView<'a, f64>
}
type AssemblyMotion<'a> = Vec<ElementMotion<'a>>;
// a complete, view-independent description of an assembly // a complete, view-independent description of an assembly
#[derive(Clone)] #[derive(Clone)]
pub struct Assembly { pub struct Assembly {
@ -290,7 +297,7 @@ impl Assembly {
// --- deformation --- // --- deformation ---
pub fn deform(&self, element_motions: Vec<(ElementKey, DVectorView<f64>)>) { pub fn deform(&self, motion: AssemblyMotion) {
/* KLUDGE */ /* KLUDGE */
// when the tangent space is zero, we currently need to avoid calling // when the tangent space is zero, we currently need to avoid calling
// its `proj` method, because it will panic rather than returning zero. // its `proj` method, because it will panic rather than returning zero.
@ -307,9 +314,9 @@ impl Assembly {
// project the element motions onto the tangent space of the solution // project the element motions onto the tangent space of the solution
// variety, and sum them to get a deformation of the whole assembly // variety, and sum them to get a deformation of the whole assembly
for (elt_key, elt_motion) in element_motions { for elt_motion in motion {
let column_index = self.elements.with(|elts| elts[elt_key].column_index); let column_index = self.elements.with(|elts| elts[elt_motion.key].column_index);
motion_proj += self.tangent.with(|tan| tan.proj(&elt_motion, column_index)); motion_proj += self.tangent.with(|tan| tan.proj(&elt_motion.velocity, column_index));
} }
// step each element along the mass shell geodesic that matches its // step each element along the mass shell geodesic that matches its

View File

@ -14,7 +14,7 @@ use web_sys::{
wasm_bindgen::{JsCast, JsValue} wasm_bindgen::{JsCast, JsValue}
}; };
use crate::{AppState, assembly::ElementKey}; use crate::{AppState, assembly::{ElementKey, ElementMotion}};
fn compile_shader( fn compile_shader(
context: &WebGl2RenderingContext, context: &WebGl2RenderingContext,
@ -341,7 +341,14 @@ pub fn Display() -> View {
]) ])
}; };
let elt_motion: DVector<f64> = time_step * TRANSLATION_SPEED * vel_field * rep; let elt_motion: DVector<f64> = time_step * TRANSLATION_SPEED * vel_field * rep;
assembly_for_raf.deform(vec![(sel, elt_motion.as_view())]); assembly_for_raf.deform(
vec![
ElementMotion {
key: sel,
velocity: elt_motion.as_view()
}
]
);
scene_changed.set(true); scene_changed.set(true);
} }
} }