Pause realization while loading assemblies

This avoids redundant realizations as we set an assembly's regulators
during loading. Adding some regulators to the low-curvature assembly
confirms that the feature is working as intended.
This commit is contained in:
Aaron Fenyes 2025-07-02 13:59:22 -07:00
parent 5864017e6f
commit 40d665d8ac
2 changed files with 90 additions and 9 deletions

View file

@ -552,6 +552,10 @@ pub struct Assembly {
// indexing
pub elements_by_id: Signal<BTreeMap<String, Rc<dyn Element>>>,
// realization control
pub keep_realized: Signal<bool>,
pub needs_realization: Signal<bool>,
// realization diagnostics
pub realization_status: Signal<Result<(), String>>,
pub descent_history: Signal<DescentHistory>
@ -559,14 +563,30 @@ pub struct Assembly {
impl Assembly {
pub fn new() -> Assembly {
Assembly {
// create an assembly
let assembly = Assembly {
elements: create_signal(BTreeSet::new()),
regulators: create_signal(BTreeSet::new()),
tangent: create_signal(ConfigSubspace::zero(0)),
elements_by_id: create_signal(BTreeMap::default()),
keep_realized: create_signal(true),
needs_realization: create_signal(false),
realization_status: create_signal(Ok(())),
descent_history: create_signal(DescentHistory::new())
}
};
// realize the assembly whenever it becomes simultaneously true that
// we're trying to keep it realized and it needs realization
let assembly_for_effect = assembly.clone();
create_effect(move || {
let should_realize = assembly_for_effect.keep_realized.get()
&& assembly_for_effect.needs_realization.get();
if should_realize {
assembly_for_effect.realize();
}
});
assembly
}
// --- inserting elements and regulators ---
@ -627,7 +647,7 @@ impl Assembly {
regulators.update(|regs| regs.insert(regulator.clone()));
}
// update the realization when the regulator becomes a constraint, or is
// request a realization when the regulator becomes a constraint, or is
// edited while acting as a constraint
let self_for_effect = self.clone();
create_effect(move || {
@ -636,7 +656,7 @@ impl Assembly {
console_log!("Updated regulator with subjects {:?}", regulator.subjects());
if regulator.try_activate() {
self_for_effect.realize();
self_for_effect.needs_realization.set(true);
}
});
@ -731,6 +751,9 @@ impl Assembly {
// save the tangent space
self.tangent.set_silent(tangent);
// clear the realization request flag
self.needs_realization.set(false);
},
Err(message) => {
// report the realization status. the `Err(message)` we're
@ -826,10 +849,10 @@ impl Assembly {
});
}
// bring the configuration back onto the solution variety. this also
// gets the elements' column indices and the saved tangent space back in
// sync
self.realize();
// request a realization to bring the configuration back onto the
// solution variety. this also gets the elements' column indices and the
// saved tangent space back in sync
self.needs_realization.set(true);
}
}