Only sync regulator inputs on change
This lets us infer a regulator's role from whether it has a set point and what text specifies the set point.
This commit is contained in:
parent
b3e4e902f3
commit
fef4127f69
3 changed files with 30 additions and 57 deletions
|
|
@ -111,32 +111,17 @@ impl Element {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum RegulatorRole {
|
||||
Measurement,
|
||||
Constraint(bool)
|
||||
}
|
||||
|
||||
impl RegulatorRole {
|
||||
pub fn is_valid_constraint(&self) -> bool {
|
||||
match self {
|
||||
RegulatorRole::Measurement => false,
|
||||
RegulatorRole::Constraint(valid) => *valid
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
#[derive(Clone, Copy)]
|
||||
pub struct Regulator {
|
||||
pub subjects: (ElementKey, ElementKey),
|
||||
pub measurement: ReadSignal<f64>,
|
||||
pub set_point: Signal<f64>,
|
||||
pub set_point_text: Signal<String>,
|
||||
pub role: Signal<RegulatorRole>
|
||||
pub set_point: Signal<Option<f64>>,
|
||||
pub set_point_spec: Signal<String>
|
||||
}
|
||||
|
||||
impl Regulator {
|
||||
fn role_is_valid_constraint_untracked(&self) -> bool {
|
||||
self.role.with_untracked(|role| role.is_valid_constraint())
|
||||
pub fn has_no_set_point_spec(&self) -> bool {
|
||||
self.set_point_spec.with(|spec| spec.is_empty())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -250,11 +235,14 @@ impl Assembly {
|
|||
let mut gram_to_be = PartialMatrix::new();
|
||||
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, reg.set_point.get_untracked());
|
||||
match reg.set_point.get_untracked() {
|
||||
Some(set_pt) => {
|
||||
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, set_pt);
|
||||
},
|
||||
None => ()
|
||||
}
|
||||
}
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue