Encapsulate realization results

In the process, spruce up our realization diagnostics logging and factor
out some of the repetitive code in the examples, because we're already
changing those parts of the code to adapt them to the new encapsulation.

This commit changes the example output format. I've checked by hand that
the output is rearranged but not meaningfully changed.
This commit is contained in:
Aaron Fenyes 2025-06-09 22:21:34 -07:00
parent 4cb3262555
commit 679c421d04
8 changed files with 176 additions and 103 deletions

View file

@ -24,7 +24,9 @@ use crate::{
realize_gram,
sphere,
ConfigSubspace,
ConstraintProblem
ConstraintProblem,
Realization,
RealizationResult
},
outline::OutlineItem,
specified::SpecifiedValue
@ -687,22 +689,25 @@ impl Assembly {
console_log!("Old configuration:{:>8.3}", problem.guess);
// look for a configuration with the given Gram matrix
let (config, tangent, success, history) = realize_gram(
let RealizationResult { result, history } = realize_gram(
&problem, 1.0e-12, 0.5, 0.9, 1.1, 200, 110
);
/* DEBUG */
// report the outcome of the search
if success {
console_log!("Target accuracy achieved!")
if let Err(ref msg) = result {
console_log!("❌️ {msg}");
} else {
console_log!("Failed to reach target accuracy")
console_log!("✅️ Target accuracy achieved!");
}
console_log!("Steps: {}", history.scaled_loss.len() - 1);
console_log!("Loss: {}", *history.scaled_loss.last().unwrap());
console_log!("Tangent dimension: {}", tangent.dim());
console_log!("Loss: {}", history.scaled_loss.last().unwrap());
if success {
if let Ok(Realization { config, tangent }) = result {
/* DEBUG */
// report the tangent dimension
console_log!("Tangent dimension: {}", tangent.dim());
// read out the solution
for elt in self.elements.get_clone_untracked() {
elt.representation().update(