Encapsulate the constraint problem data

This will make it easier for elements and regulators to write themselves
into the constraint problem.
This commit is contained in:
Aaron Fenyes 2025-03-24 23:21:55 -04:00
parent b86f176151
commit bb226c5f45
4 changed files with 172 additions and 167 deletions

View file

@ -6,7 +6,13 @@ use sycamore::prelude::*;
use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
use crate::{
engine::{Q, local_unif_to_std, realize_gram, ConfigSubspace, PartialMatrix},
engine::{
Q,
local_unif_to_std,
realize_gram,
ConfigSubspace,
ConstraintProblem
},
specified::SpecifiedValue
};
@ -268,6 +274,11 @@ impl Assembly {
// --- realization ---
pub fn realize(&self) {
// create a blank constraint problem
let mut problem = ConstraintProblem::new(
self.elements.with_untracked(|elts| elts.len())
);
// index the elements
self.elements.update_silent(|elts| {
for (index, (_, elt)) in elts.into_iter().enumerate() {
@ -276,9 +287,8 @@ impl Assembly {
});
// set up the Gram matrix and the initial configuration matrix
let (gram, guess) = self.elements.with_untracked(|elts| {
self.elements.with_untracked(|elts| {
// set up the off-diagonal part of the Gram matrix
let mut gram_to_be = PartialMatrix::new();
self.regulators.with_untracked(|regs| {
for (_, reg) in regs {
reg.set_point.with_untracked(|set_pt| {
@ -286,7 +296,7 @@ impl Assembly {
let subjects = reg.subjects;
let row = elts[subjects.0].column_index.unwrap();
let col = elts[subjects.1].column_index.unwrap();
gram_to_be.push_sym(row, col, val);
problem.gram.push_sym(row, col, val);
}
});
}
@ -294,36 +304,32 @@ impl Assembly {
// set up the initial configuration matrix and the diagonal of the
// Gram matrix
let mut guess_to_be = DMatrix::<f64>::zeros(5, elts.len());
for (_, elt) in elts {
let index = elt.column_index.unwrap();
gram_to_be.push_sym(index, index, 1.0);
guess_to_be.set_column(index, &elt.representation.get_clone_untracked());
problem.gram.push_sym(index, index, 1.0);
problem.guess.set_column(index, &elt.representation.get_clone_untracked());
}
(gram_to_be, guess_to_be)
});
/* DEBUG */
// log the Gram matrix
console::log_1(&JsValue::from("Gram matrix:"));
gram.log_to_console();
problem.gram.log_to_console();
/* DEBUG */
// log the initial configuration matrix
console::log_1(&JsValue::from("Old configuration:"));
for j in 0..guess.nrows() {
for j in 0..problem.guess.nrows() {
let mut row_str = String::new();
for k in 0..guess.ncols() {
row_str.push_str(format!(" {:>8.3}", guess[(j, k)]).as_str());
for k in 0..problem.guess.ncols() {
row_str.push_str(format!(" {:>8.3}", problem.guess[(j, k)]).as_str());
}
console::log_1(&JsValue::from(row_str));
}
// look for a configuration with the given Gram matrix
let (config, tangent, success, history) = realize_gram(
&gram, guess, &[],
1.0e-12, 0.5, 0.9, 1.1, 200, 110
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
);
/* DEBUG */