Adjust normalization step of nudge routine #43

Merged
glen merged 3 commits from normalize-by-contracting into main 2025-02-06 22:53:42 +00:00
Showing only changes of commit dac96cf1ac - Show all commits

View file

@ -5,7 +5,7 @@ use std::{collections::BTreeSet, sync::atomic::{AtomicU64, Ordering}};
use sycamore::prelude::*; use sycamore::prelude::*;
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
use crate::engine::{realize_gram, local_unif_to_std, ConfigSubspace, PartialMatrix, Q}; use crate::engine::{realize_gram, local_unif_to_std, ConfigSubspace, PartialMatrix};
// the types of the keys we use to access an assembly's elements and constraints // the types of the keys we use to access an assembly's elements and constraints
pub type ElementKey = usize; pub type ElementKey = usize;
@ -371,8 +371,8 @@ impl Assembly {
} }
} }
// step the assembly along the deformation, and then project each // step the assembly along the deformation. this changes the elements'
// element back onto its mass shall // normalizations, so we restore those afterward
/* KLUDGE */ /* KLUDGE */
// since our test assemblies only include spheres, we assume that every // since our test assemblies only include spheres, we assume that every
// element is on the 1 mass shell // element is on the 1 mass shell
@ -380,22 +380,16 @@ impl Assembly {
elt.representation.update_silent(|rep| { elt.representation.update_silent(|rep| {
match elt.column_index { match elt.column_index {
Some(column_index) => { Some(column_index) => {
// apply the deformation linearly // step the assembly along the deformation
*rep += motion_proj.column(column_index); *rep += motion_proj.column(column_index);
// project back onto the mass shell by contracting // restore normalization by contracting toward the last
// toward the last coordinate axis // coordinate axis
let q_sp = rep.fixed_rows::<3>(0).norm_squared(); let q_sp = rep.fixed_rows::<3>(0).norm_squared();
let half_q_lt = -2.0 * rep[3] * rep[4]; let half_q_lt = -2.0 * rep[3] * rep[4];
let half_q_lt_sq = half_q_lt * half_q_lt; let half_q_lt_sq = half_q_lt * half_q_lt;
let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt(); let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt();
rep.fixed_rows_mut::<4>(0).scale_mut(1.0 / scaling); rep.fixed_rows_mut::<4>(0).scale_mut(1.0 / scaling);
/* DEBUG */
// report self-product before and after projection
console::log_1(&JsValue::from(
format!("After scaling by {}, self-product of element representation is {}", scaling, rep.dot(&(&*Q * &*rep)))
));
}, },
None => { None => {
console::log_1(&JsValue::from( console::log_1(&JsValue::from(