forked from StudioInfinity/dyna3
Print the edge distortions
This commit is contained in:
parent
b74cbf10c1
commit
cc2da3406b
3 changed files with 73 additions and 5 deletions
|
@ -227,8 +227,14 @@ details[open]:has(li) .element-switch::after {
|
||||||
border-radius: 8px;
|
border-radius: 8px;
|
||||||
}
|
}
|
||||||
|
|
||||||
#distortion-gauge {
|
#distortion-bar {
|
||||||
|
display: flex;
|
||||||
margin-top: 8px;
|
margin-top: 8px;
|
||||||
|
gap: 8px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#distortion-gauge {
|
||||||
|
flex-grow: 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* display */
|
/* display */
|
||||||
|
|
|
@ -367,6 +367,9 @@ pub trait Regulator: Serial + ProblemPoser + OutlineItem {
|
||||||
fn subjects(&self) -> Vec<Rc<dyn Element>>;
|
fn subjects(&self) -> Vec<Rc<dyn Element>>;
|
||||||
fn measurement(&self) -> ReadSignal<f64>;
|
fn measurement(&self) -> ReadSignal<f64>;
|
||||||
fn set_point(&self) -> Signal<SpecifiedValue>;
|
fn set_point(&self) -> Signal<SpecifiedValue>;
|
||||||
|
fn soft(&self) -> Option<Signal<bool>> {
|
||||||
|
None
|
||||||
|
}
|
||||||
fn distortion(&self) -> Option<ReadSignal<f64>> { /* KLUDGE */
|
fn distortion(&self) -> Option<ReadSignal<f64>> { /* KLUDGE */
|
||||||
None
|
None
|
||||||
}
|
}
|
||||||
|
@ -426,8 +429,8 @@ impl InversiveDistanceRegulator {
|
||||||
match set_point_opt {
|
match set_point_opt {
|
||||||
None => 0.0,
|
None => 0.0,
|
||||||
Some(set_point_val) => SQRT_2 * (
|
Some(set_point_val) => SQRT_2 * (
|
||||||
(-set_point_val).sqrt() - (-measurement_val).sqrt()
|
(-measurement_val).sqrt() - (-set_point_val).sqrt()
|
||||||
).abs(),
|
),
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
} else {
|
} else {
|
||||||
|
@ -453,6 +456,10 @@ impl Regulator for InversiveDistanceRegulator {
|
||||||
self.set_point
|
self.set_point
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn soft(&self) -> Option<Signal<bool>> {
|
||||||
|
Some(self.soft)
|
||||||
|
}
|
||||||
|
|
||||||
fn distortion(&self) -> Option<ReadSignal<f64>> {
|
fn distortion(&self) -> Option<ReadSignal<f64>> {
|
||||||
self.distortion
|
self.distortion
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,7 +119,7 @@ fn DistortionGauge() -> View {
|
||||||
let mut total = 0.0;
|
let mut total = 0.0;
|
||||||
for reg in regs {
|
for reg in regs {
|
||||||
if let Some(distortion) = reg.distortion() {
|
if let Some(distortion) = reg.distortion() {
|
||||||
total += distortion.get();
|
total += distortion.get().abs();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
total
|
total
|
||||||
|
@ -133,6 +133,58 @@ fn DistortionGauge() -> View {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[component]
|
||||||
|
fn DistortionPrintButton() -> View {
|
||||||
|
view! {
|
||||||
|
button(
|
||||||
|
on:click = |_| {
|
||||||
|
let state = use_context::<AppState>();
|
||||||
|
let mut hard_distortion_table = String::new();
|
||||||
|
let mut soft_distortion_table = String::new();
|
||||||
|
let mut highest_distortion = f64::NEG_INFINITY;
|
||||||
|
let mut lowest_distortion = f64::INFINITY;
|
||||||
|
let mut largest_hard_distortion = f64::NEG_INFINITY;
|
||||||
|
state.assembly.regulators.with_untracked(|regs| {
|
||||||
|
for reg in regs {
|
||||||
|
if let Some(distortion) = reg.distortion() {
|
||||||
|
let distortion_val = distortion.get();
|
||||||
|
let subjects = reg.subjects();
|
||||||
|
let distortion_line = format!(
|
||||||
|
"{}, {}: {distortion_val}\n",
|
||||||
|
subjects[0].id(),
|
||||||
|
subjects[1].id(),
|
||||||
|
);
|
||||||
|
match reg.soft() {
|
||||||
|
Some(soft) if soft.get() => {
|
||||||
|
soft_distortion_table += &distortion_line;
|
||||||
|
highest_distortion = highest_distortion.max(distortion_val);
|
||||||
|
lowest_distortion = lowest_distortion.min(distortion_val);
|
||||||
|
},
|
||||||
|
_ => {
|
||||||
|
hard_distortion_table += &distortion_line;
|
||||||
|
largest_hard_distortion = largest_hard_distortion.max(distortion_val.abs());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
console_log!("\
|
||||||
|
=== Distortions of flexible edges (for labels) ===\n\n\
|
||||||
|
--- Range ---\n\n\
|
||||||
|
Highest: {highest_distortion}\n\
|
||||||
|
Lowest: {lowest_distortion}\n\n\
|
||||||
|
--- Table ---\n\n{soft_distortion_table}\n\
|
||||||
|
=== Distortions of rigid edges (for validation) ===\n\n\
|
||||||
|
These values should be small relative to the ones for the flexible edges\n\n\
|
||||||
|
--- Range ---\n\n\
|
||||||
|
Largest absolute: {largest_hard_distortion}\n\n\
|
||||||
|
--- Table ---\n\n{hard_distortion_table}\
|
||||||
|
");
|
||||||
|
},
|
||||||
|
) { "Print" }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fn into_log10_time_point((step, value): (usize, f64)) -> Vec<Option<f64>> {
|
fn into_log10_time_point((step, value): (usize, f64)) -> Vec<Option<f64>> {
|
||||||
vec![
|
vec![
|
||||||
Some(step as f64),
|
Some(step as f64),
|
||||||
|
@ -337,7 +389,10 @@ pub fn Diagnostics() -> View {
|
||||||
}
|
}
|
||||||
DiagnosticsPanel(name = "loss") { LossHistory {} }
|
DiagnosticsPanel(name = "loss") { LossHistory {} }
|
||||||
DiagnosticsPanel(name = "spectrum") { SpectrumHistory {} }
|
DiagnosticsPanel(name = "spectrum") { SpectrumHistory {} }
|
||||||
DistortionGauge {}
|
div(id = "distortion-bar") {
|
||||||
|
DistortionGauge {}
|
||||||
|
DistortionPrintButton {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Add table
Add a link
Reference in a new issue