Calc

Trait Calc 

Source
pub trait Calc:
    Send
    + Sync
    + Debug
    + Serialize
    + Deserialize {
    // Required methods
    fn init(
        &mut self,
        ctx: ControllerCtx,
        input_indices: Vec<usize>,
        output_range: Range<usize>,
    ) -> Result<(), String>;
    fn terminate(&mut self) -> Result<(), String>;
    fn eval(&mut self, tape: &mut [f64]) -> Result<(), String>;
    fn get_input_map(&self) -> BTreeMap<CalcInputName, FieldName>;
    fn update_input_map(
        &mut self,
        field: &str,
        source: &str,
    ) -> Result<(), String>;
    fn get_save_outputs(&self) -> bool;
    fn set_save_outputs(&mut self, save_outputs: bool);
    fn get_config(&self) -> BTreeMap<String, f64>;
    fn set_config(&mut self, cfg: &BTreeMap<String, f64>) -> Result<(), String>;
    fn get_input_names(&self) -> Vec<CalcInputName> ;
    fn get_output_names(&self) -> Vec<CalcOutputName> ;

    // Provided method
    fn kind(&self) -> String { ... }
}
Expand description

A calculation that takes some inputs and produces some outputs at each timestep, and may have some persistent internal state.

Required Methods§

Source

fn init( &mut self, ctx: ControllerCtx, input_indices: Vec<usize>, output_range: Range<usize>, ) -> Result<(), String>

Reset internal state and register calc tape indices

Source

fn terminate(&mut self) -> Result<(), String>

Clear state to reset for another run

Source

fn eval(&mut self, tape: &mut [f64]) -> Result<(), String>

Run calcs for a cycle

Source

fn get_input_map(&self) -> BTreeMap<CalcInputName, FieldName>

Map from input field names (like v, without prefix) to the state name that the input should draw from (like peripheral_0.output_1, with prefix)

Source

fn update_input_map(&mut self, field: &str, source: &str) -> Result<(), String>

Change a value in the input map

Source

fn get_save_outputs(&self) -> bool

Get flag for whether to save outputs

Source

fn set_save_outputs(&mut self, save_outputs: bool)

Set flag for whether to save outputs

Source

fn get_config(&self) -> BTreeMap<String, f64>

Get config field values

Source

fn set_config(&mut self, cfg: &BTreeMap<String, f64>) -> Result<(), String>

Apply config field values

Source

fn get_input_names(&self) -> Vec<CalcInputName>

List of input field names in the order that they will be consumed

Source

fn get_output_names(&self) -> Vec<CalcOutputName>

List of output field names in the order that they will be written out

Provided Methods§

Source

fn kind(&self) -> String

Get the type name, which is guaranteed to be unique among implementations of the trait because of the use of a global vtable for serialization, and guaranteed not to include non-’static lifetimes due to trait bounds.

Trait Implementations§

Source§

impl Clone for Box<dyn Calc>

Clone isn’t inherently object-safe, so to be able to clone dyn trait objects, we send it for a loop through the serde typetag system, which provides an automatically-assembled vtable to determine the downcasted type and clone into it.

Source§

fn clone(&self) -> Box<dyn Calc>

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a, 'py> FromPyObject<'a, 'py> for Box<dyn Calc>

Glue for passing dyn Trait objects from Python to Rust via json to handle the fact that they are concrete types on the Python side, but dyn Trait objects on the Rust side.

Source§

type Error = PyErr

The type returned in the event of a conversion error. Read more
Source§

fn extract(obj: Borrowed<'a, 'py, PyAny>) -> Result<Self, Self::Error>

Extracts Self from the bound smart pointer obj. Read more
Source§

impl<'typetag> Serialize for dyn Calc + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Calc + Send + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Calc + Send + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl<'typetag> Serialize for dyn Calc + Sync + 'typetag

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more

Implementors§