forked from StudioInfinity/dyna3
Simplify the realization triggering system (#105)
Simplifies the system that reactively triggers realizations, at the cost of removing the preconditioning step described in issue #101 and doing unnecessary realizations after certain kinds of updates. Co-authored-by: Aaron Fenyes <aaron.fenyes@fareycircles.ooo> Reviewed-on: StudioInfinity/dyna3#105 Co-authored-by: Vectornaut <vectornaut@nobody@nowhere.net> Co-committed-by: Vectornaut <vectornaut@nobody@nowhere.net>
This commit is contained in:
parent
0801200210
commit
2eba80fb69
4 changed files with 48 additions and 104 deletions
|
@ -1,7 +1,6 @@
|
|||
use lazy_static::lazy_static;
|
||||
use nalgebra::{Const, DMatrix, DVector, DVectorView, Dyn, SymmetricEigen};
|
||||
use std::fmt::{Display, Error, Formatter};
|
||||
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
|
||||
|
||||
// --- elements ---
|
||||
|
||||
|
@ -50,40 +49,6 @@ pub fn project_point_to_normalized(rep: &mut DVector<f64>) {
|
|||
rep.scale_mut(0.5 / rep[3]);
|
||||
}
|
||||
|
||||
// given a sphere's representation vector, change the sphere's half-curvature to
|
||||
// `half-curv` and then restore normalization by contracting the representation
|
||||
// vector toward the curvature axis
|
||||
pub fn change_half_curvature(rep: &mut DVector<f64>, half_curv: f64) {
|
||||
// set the sphere's half-curvature to the desired value
|
||||
rep[3] = half_curv;
|
||||
|
||||
// restore normalization by contracting toward the curvature axis
|
||||
const SIZE_THRESHOLD: f64 = 1e-9;
|
||||
let half_q_lt = -2.0 * half_curv * rep[4];
|
||||
let half_q_lt_sq = half_q_lt * half_q_lt;
|
||||
let mut spatial = rep.fixed_rows_mut::<3>(0);
|
||||
let q_sp = spatial.norm_squared();
|
||||
if q_sp < SIZE_THRESHOLD && half_q_lt_sq < SIZE_THRESHOLD {
|
||||
spatial.copy_from_slice(
|
||||
&[0.0, 0.0, (1.0 - 2.0 * half_q_lt).sqrt()]
|
||||
);
|
||||
} else {
|
||||
let scaling = half_q_lt + (q_sp + half_q_lt_sq).sqrt();
|
||||
spatial.scale_mut(1.0 / scaling);
|
||||
rep[4] /= scaling;
|
||||
}
|
||||
|
||||
/* DEBUG */
|
||||
// verify normalization
|
||||
let rep_for_debug = rep.clone();
|
||||
console::log_1(&JsValue::from(
|
||||
format!(
|
||||
"Sphere self-product after curvature change: {}",
|
||||
rep_for_debug.dot(&(&*Q * &rep_for_debug))
|
||||
)
|
||||
));
|
||||
}
|
||||
|
||||
// --- partial matrices ---
|
||||
|
||||
pub struct MatrixEntry {
|
||||
|
@ -199,13 +164,6 @@ impl ConfigSubspace {
|
|||
).collect::<Vec<_>>().as_slice()
|
||||
);
|
||||
|
||||
/* DEBUG */
|
||||
// print the eigenvalues
|
||||
#[cfg(all(target_family = "wasm", target_os = "unknown"))]
|
||||
console::log_1(&JsValue::from(
|
||||
format!("Eigenvalues used to find kernel:{}", eig.eigenvalues)
|
||||
));
|
||||
|
||||
// express the basis in the standard coordinates
|
||||
let basis_std = proj_to_std * &basis_proj;
|
||||
|
||||
|
@ -425,9 +383,22 @@ pub fn realize_gram(
|
|||
// start the descent history
|
||||
let mut history = DescentHistory::new();
|
||||
|
||||
// handle the case where the assembly is empty. our general realization
|
||||
// routine can't handle this case because it builds the Hessian using
|
||||
// `DMatrix::from_columns`, which panics when the list of columns is empty
|
||||
let assembly_dim = guess.ncols();
|
||||
if assembly_dim == 0 {
|
||||
let result = Ok(
|
||||
ConfigNeighborhood {
|
||||
config: guess.clone(),
|
||||
nbhd: ConfigSubspace::zero(0)
|
||||
}
|
||||
);
|
||||
return Realization { result, history }
|
||||
}
|
||||
|
||||
// find the dimension of the search space
|
||||
let element_dim = guess.nrows();
|
||||
let assembly_dim = guess.ncols();
|
||||
let total_dim = element_dim * assembly_dim;
|
||||
|
||||
// scale the tolerance
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue