Rename observables to regulators

This commit is contained in:
Aaron Fenyes 2025-02-12 11:35:07 -08:00
parent de7122d871
commit 24139ad5e9
4 changed files with 87 additions and 87 deletions

View file

@ -7,9 +7,9 @@ use web_sys::{console, wasm_bindgen::JsValue}; /* DEBUG */
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 observables
// the types of the keys we use to access an assembly's elements and regulators
pub type ElementKey = usize;
pub type ObservableKey = usize;
pub type RegulatorKey = usize;
pub type ElementColor = [f32; 3];
@ -26,7 +26,7 @@ pub struct Element {
pub label: String,
pub color: ElementColor,
pub representation: Signal<DVector<f64>>,
pub observables: Signal<BTreeSet<ObservableKey>>,
pub regulators: Signal<BTreeSet<RegulatorKey>>,
// a serial number, assigned by `Element::new`, that uniquely identifies
// each element
@ -61,7 +61,7 @@ impl Element {
label: label,
color: color,
representation: create_signal(representation),
observables: create_signal(BTreeSet::default()),
regulators: create_signal(BTreeSet::default()),
serial: serial,
column_index: None
}
@ -111,30 +111,30 @@ impl Element {
}
}
pub enum ObservableRole {
pub enum RegulatorRole {
Measurement,
Constraint(bool)
}
impl ObservableRole {
impl RegulatorRole {
pub fn is_valid_constraint(&self) -> bool {
match self {
ObservableRole::Measurement => false,
ObservableRole::Constraint(valid) => *valid
RegulatorRole::Measurement => false,
RegulatorRole::Constraint(valid) => *valid
}
}
}
#[derive(Clone)]
pub struct Observable {
pub struct Regulator {
pub subjects: (ElementKey, ElementKey),
pub measured: ReadSignal<f64>,
pub desired: Signal<f64>,
pub desired_text: Signal<String>,
pub role: Signal<ObservableRole>
pub role: Signal<RegulatorRole>
}
impl Observable {
impl Regulator {
fn role_is_valid_constraint_untracked(&self) -> bool {
self.role.with_untracked(|role| role.is_valid_constraint())
}
@ -151,9 +151,9 @@ type AssemblyMotion<'a> = Vec<ElementMotion<'a>>;
// a complete, view-independent description of an assembly
#[derive(Clone)]
pub struct Assembly {
// elements and observables
// elements and regulators
pub elements: Signal<Slab<Element>>,
pub observables: Signal<Slab<Observable>>,
pub regulators: Signal<Slab<Regulator>>,
// solution variety tangent space. the basis vectors are stored in
// configuration matrix format, ordered according to the elements' column
@ -175,13 +175,13 @@ impl Assembly {
pub fn new() -> Assembly {
Assembly {
elements: create_signal(Slab::new()),
observables: create_signal(Slab::new()),
regulators: create_signal(Slab::new()),
tangent: create_signal(ConfigSubspace::zero(0)),
elements_by_id: create_signal(FxHashMap::default())
}
}
// --- inserting elements and observables ---
// --- inserting elements and regulators ---
// insert an element into the assembly without checking whether we already
// have an element with the same identifier. any element that does have the
@ -224,14 +224,14 @@ impl Assembly {
);
}
pub fn insert_observable(&self, observable: Observable) {
let subjects = observable.subjects;
let key = self.observables.update(|obsls| obsls.insert(observable));
let subject_observables = self.elements.with(
|elts| (elts[subjects.0].observables, elts[subjects.1].observables)
pub fn insert_regulator(&self, regulator: Regulator) {
let subjects = regulator.subjects;
let key = self.regulators.update(|regs| regs.insert(regulator));
let subject_regulators = self.elements.with(
|elts| (elts[subjects.0].regulators, elts[subjects.1].regulators)
);
subject_observables.0.update(|obsls| obsls.insert(key));
subject_observables.1.update(|obsls| obsls.insert(key));
subject_regulators.0.update(|regs| regs.insert(key));
subject_regulators.1.update(|regs| regs.insert(key));
}
// --- realization ---
@ -248,13 +248,13 @@ impl Assembly {
let (gram, guess) = self.elements.with_untracked(|elts| {
// set up the off-diagonal part of the Gram matrix
let mut gram_to_be = PartialMatrix::new();
self.observables.with_untracked(|obsls| {
for (_, obs) in obsls {
if obs.role_is_valid_constraint_untracked() {
let subjects = obs.subjects;
self.regulators.with_untracked(|regs| {
for (_, reg) in regs {
if reg.role_is_valid_constraint_untracked() {
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, obs.desired.get_untracked());
gram_to_be.push_sym(row, col, reg.desired.get_untracked());
}
}
});