diff --git a/pywr-core/src/network.rs b/pywr-core/src/network.rs index 13a44a2b..de960951 100644 --- a/pywr-core/src/network.rs +++ b/pywr-core/src/network.rs @@ -9,7 +9,7 @@ use crate::parameters::{MultiValueParameterIndex, ParameterType, VariableConfig} use crate::recorders::{MetricSet, MetricSetIndex, MetricSetState}; use crate::scenario::ScenarioIndex; use crate::solvers::{MultiStateSolver, Solver, SolverFeatures, SolverTimings}; -use crate::state::{ParameterStates, State, StateBuilder}; +use crate::state::{MultiValue, ParameterStates, State, StateBuilder}; use crate::timestep::Timestep; use crate::virtual_storage::{VirtualStorage, VirtualStorageIndex, VirtualStorageReset, VirtualStorageVec}; use crate::{parameters, recorders, IndexParameterIndex, NodeIndex, ParameterIndex, PywrError, RecorderIndex}; @@ -201,9 +201,9 @@ pub struct Network { aggregated_nodes: AggregatedNodeVec, aggregated_storage_nodes: AggregatedStorageNodeVec, virtual_storage_nodes: VirtualStorageVec, - parameters: Vec>, - index_parameters: Vec>, - multi_parameters: Vec>, + parameters: Vec>>, + index_parameters: Vec>>, + multi_parameters: Vec>>, derived_metrics: Vec, metric_sets: Vec, resolve_order: Vec, @@ -1089,7 +1089,7 @@ impl Network { } /// Get a `Parameter` from a parameter's name - pub fn get_parameter(&self, index: &ParameterIndex) -> Result<&dyn parameters::Parameter, PywrError> { + pub fn get_parameter(&self, index: &ParameterIndex) -> Result<&dyn parameters::Parameter, PywrError> { match self.parameters.get(*index.deref()) { Some(p) => Ok(p.as_ref()), None => Err(PywrError::ParameterIndexNotFound(*index)), @@ -1097,7 +1097,10 @@ impl Network { } /// Get a `Parameter` from a parameter's name - pub fn get_mut_parameter(&mut self, index: &ParameterIndex) -> Result<&mut dyn parameters::Parameter, PywrError> { + pub fn get_mut_parameter( + &mut self, + index: &ParameterIndex, + ) -> Result<&mut dyn parameters::Parameter, PywrError> { match self.parameters.get_mut(*index.deref()) { Some(p) => Ok(p.as_mut()), None => Err(PywrError::ParameterIndexNotFound(*index)), @@ -1105,7 +1108,7 @@ impl Network { } /// Get a `Parameter` from a parameter's name - pub fn get_parameter_by_name(&self, name: &str) -> Result<&dyn parameters::Parameter, PywrError> { + pub fn get_parameter_by_name(&self, name: &str) -> Result<&dyn parameters::Parameter, PywrError> { match self.parameters.iter().find(|p| p.name() == name) { Some(parameter) => Ok(parameter.as_ref()), None => Err(PywrError::ParameterNotFound(name.to_string())), @@ -1121,7 +1124,7 @@ impl Network { } /// Get a `IndexParameter` from a parameter's name - pub fn get_index_parameter_by_name(&self, name: &str) -> Result<&dyn parameters::IndexParameter, PywrError> { + pub fn get_index_parameter_by_name(&self, name: &str) -> Result<&dyn parameters::Parameter, PywrError> { match self.index_parameters.iter().find(|p| p.name() == name) { Some(parameter) => Ok(parameter.as_ref()), None => Err(PywrError::ParameterNotFound(name.to_string())), @@ -1311,7 +1314,10 @@ impl Network { } /// Add a `parameters::Parameter` to the network - pub fn add_parameter(&mut self, parameter: Box) -> Result { + pub fn add_parameter( + &mut self, + parameter: Box>, + ) -> Result { if let Ok(idx) = self.get_parameter_index_by_name(¶meter.meta().name) { return Err(PywrError::ParameterNameAlreadyExists( parameter.meta().name.to_string(), @@ -1332,7 +1338,7 @@ impl Network { /// Add a `parameters::IndexParameter` to the network pub fn add_index_parameter( &mut self, - index_parameter: Box, + index_parameter: Box>, ) -> Result { if let Ok(idx) = self.get_index_parameter_index_by_name(&index_parameter.meta().name) { return Err(PywrError::IndexParameterNameAlreadyExists( @@ -1353,7 +1359,7 @@ impl Network { /// Add a `parameters::MultiValueParameter` to the network pub fn add_multi_value_parameter( &mut self, - parameter: Box, + parameter: Box>, ) -> Result { if let Ok(idx) = self.get_parameter_index_by_name(¶meter.meta().name) { return Err(PywrError::ParameterNameAlreadyExists( diff --git a/pywr-core/src/parameters/aggregated.rs b/pywr-core/src/parameters/aggregated.rs index 50e7349c..6b77864d 100644 --- a/pywr-core/src/parameters/aggregated.rs +++ b/pywr-core/src/parameters/aggregated.rs @@ -47,7 +47,7 @@ impl AggregatedParameter { } } -impl Parameter for AggregatedParameter { +impl Parameter for AggregatedParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/aggregated_index.rs b/pywr-core/src/parameters/aggregated_index.rs index e4ec3bf7..45f6f8b9 100644 --- a/pywr-core/src/parameters/aggregated_index.rs +++ b/pywr-core/src/parameters/aggregated_index.rs @@ -2,10 +2,11 @@ /// use super::PywrError; use crate::network::Network; -use crate::parameters::{IndexParameter, IndexValue, ParameterMeta}; +use crate::parameters::{IndexValue, Parameter, ParameterMeta}; use crate::scenario::ScenarioIndex; use crate::state::{ParameterState, State}; use crate::timestep::Timestep; +use std::any::Any; use std::str::FromStr; pub enum AggIndexFunc { @@ -49,7 +50,11 @@ impl AggregatedIndexParameter { } } -impl IndexParameter for AggregatedIndexParameter { +impl Parameter for AggregatedIndexParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } diff --git a/pywr-core/src/parameters/array.rs b/pywr-core/src/parameters/array.rs index 0cb69f38..8c9d816c 100644 --- a/pywr-core/src/parameters/array.rs +++ b/pywr-core/src/parameters/array.rs @@ -23,7 +23,7 @@ impl Array1Parameter { } } -impl Parameter for Array1Parameter { +impl Parameter for Array1Parameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } @@ -66,7 +66,7 @@ impl Array2Parameter { } } -impl Parameter for Array2Parameter { +impl Parameter for Array2Parameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/asymmetric.rs b/pywr-core/src/parameters/asymmetric.rs index 775fa535..489df8f1 100644 --- a/pywr-core/src/parameters/asymmetric.rs +++ b/pywr-core/src/parameters/asymmetric.rs @@ -1,9 +1,10 @@ use crate::network::Network; -use crate::parameters::{downcast_internal_state_mut, IndexParameter, IndexValue, ParameterMeta}; +use crate::parameters::{downcast_internal_state_mut, IndexValue, Parameter, ParameterMeta}; use crate::scenario::ScenarioIndex; use crate::state::{ParameterState, State}; use crate::timestep::Timestep; use crate::PywrError; +use std::any::Any; pub struct AsymmetricSwitchIndexParameter { meta: ParameterMeta, @@ -21,7 +22,11 @@ impl AsymmetricSwitchIndexParameter { } } -impl IndexParameter for AsymmetricSwitchIndexParameter { +impl Parameter for AsymmetricSwitchIndexParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } diff --git a/pywr-core/src/parameters/constant.rs b/pywr-core/src/parameters/constant.rs index 658ee86f..d59f1a30 100644 --- a/pywr-core/src/parameters/constant.rs +++ b/pywr-core/src/parameters/constant.rs @@ -37,7 +37,7 @@ impl ConstantParameter { } } -impl Parameter for ConstantParameter { +impl Parameter for ConstantParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/control_curves/apportion.rs b/pywr-core/src/parameters/control_curves/apportion.rs index 5aaaffe1..578f1e03 100644 --- a/pywr-core/src/parameters/control_curves/apportion.rs +++ b/pywr-core/src/parameters/control_curves/apportion.rs @@ -1,10 +1,11 @@ use crate::metric::Metric; use crate::network::Network; -use crate::parameters::{MultiValueParameter, ParameterMeta}; +use crate::parameters::{Parameter, ParameterMeta}; use crate::scenario::ScenarioIndex; use crate::state::{MultiValue, ParameterState, State}; use crate::timestep::Timestep; use crate::PywrError; +use std::any::Any; use std::collections::HashMap; /// A parameter which divides a apportions a metric to an upper and lower amount based @@ -31,7 +32,11 @@ impl ApportionParameter { } } -impl MultiValueParameter for ApportionParameter { +impl Parameter for ApportionParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } diff --git a/pywr-core/src/parameters/control_curves/index.rs b/pywr-core/src/parameters/control_curves/index.rs index 34d157a3..07b80dc4 100644 --- a/pywr-core/src/parameters/control_curves/index.rs +++ b/pywr-core/src/parameters/control_curves/index.rs @@ -1,10 +1,11 @@ use crate::metric::Metric; use crate::network::Network; -use crate::parameters::{IndexParameter, ParameterMeta}; +use crate::parameters::{Parameter, ParameterMeta}; use crate::scenario::ScenarioIndex; use crate::state::{ParameterState, State}; use crate::timestep::Timestep; use crate::PywrError; +use std::any::Any; pub struct ControlCurveIndexParameter { meta: ParameterMeta, @@ -22,7 +23,11 @@ impl ControlCurveIndexParameter { } } -impl IndexParameter for ControlCurveIndexParameter { +impl Parameter for ControlCurveIndexParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } diff --git a/pywr-core/src/parameters/control_curves/interpolated.rs b/pywr-core/src/parameters/control_curves/interpolated.rs index 15f48e31..784fad81 100644 --- a/pywr-core/src/parameters/control_curves/interpolated.rs +++ b/pywr-core/src/parameters/control_curves/interpolated.rs @@ -26,7 +26,7 @@ impl ControlCurveInterpolatedParameter { } } -impl Parameter for ControlCurveInterpolatedParameter { +impl Parameter for ControlCurveInterpolatedParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/control_curves/piecewise.rs b/pywr-core/src/parameters/control_curves/piecewise.rs index a2e3522e..e3ca6a13 100644 --- a/pywr-core/src/parameters/control_curves/piecewise.rs +++ b/pywr-core/src/parameters/control_curves/piecewise.rs @@ -37,7 +37,7 @@ impl PiecewiseInterpolatedParameter { } } -impl Parameter for PiecewiseInterpolatedParameter { +impl Parameter for PiecewiseInterpolatedParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/control_curves/simple.rs b/pywr-core/src/parameters/control_curves/simple.rs index a59553d2..f13013c6 100644 --- a/pywr-core/src/parameters/control_curves/simple.rs +++ b/pywr-core/src/parameters/control_curves/simple.rs @@ -25,7 +25,7 @@ impl ControlCurveParameter { } } -impl Parameter for ControlCurveParameter { +impl Parameter for ControlCurveParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/control_curves/volume_between.rs b/pywr-core/src/parameters/control_curves/volume_between.rs index f1f11880..e4abcff8 100644 --- a/pywr-core/src/parameters/control_curves/volume_between.rs +++ b/pywr-core/src/parameters/control_curves/volume_between.rs @@ -26,7 +26,7 @@ impl VolumeBetweenControlCurvesParameter { } } -impl Parameter for VolumeBetweenControlCurvesParameter { +impl Parameter for VolumeBetweenControlCurvesParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/delay.rs b/pywr-core/src/parameters/delay.rs index 6ca3dc85..d734b530 100644 --- a/pywr-core/src/parameters/delay.rs +++ b/pywr-core/src/parameters/delay.rs @@ -26,7 +26,7 @@ impl DelayParameter { } } -impl Parameter for DelayParameter { +impl Parameter for DelayParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/discount_factor.rs b/pywr-core/src/parameters/discount_factor.rs index 4994ea91..1ecd5b95 100644 --- a/pywr-core/src/parameters/discount_factor.rs +++ b/pywr-core/src/parameters/discount_factor.rs @@ -24,7 +24,7 @@ impl DiscountFactorParameter { } } -impl Parameter for DiscountFactorParameter { +impl Parameter for DiscountFactorParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/division.rs b/pywr-core/src/parameters/division.rs index 4a3a749b..efec1576 100644 --- a/pywr-core/src/parameters/division.rs +++ b/pywr-core/src/parameters/division.rs @@ -24,7 +24,7 @@ impl DivisionParameter { } } -impl Parameter for DivisionParameter { +impl Parameter for DivisionParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/indexed_array.rs b/pywr-core/src/parameters/indexed_array.rs index d83a0361..fdc15a8a 100644 --- a/pywr-core/src/parameters/indexed_array.rs +++ b/pywr-core/src/parameters/indexed_array.rs @@ -23,7 +23,7 @@ impl IndexedArrayParameter { } } -impl Parameter for IndexedArrayParameter { +impl Parameter for IndexedArrayParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/interpolated.rs b/pywr-core/src/parameters/interpolated.rs index 25111aeb..a717bf63 100644 --- a/pywr-core/src/parameters/interpolated.rs +++ b/pywr-core/src/parameters/interpolated.rs @@ -27,7 +27,7 @@ impl InterpolatedParameter { } } -impl Parameter for InterpolatedParameter { +impl Parameter for InterpolatedParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/max.rs b/pywr-core/src/parameters/max.rs index 2074d4b9..062c3ada 100644 --- a/pywr-core/src/parameters/max.rs +++ b/pywr-core/src/parameters/max.rs @@ -24,7 +24,7 @@ impl MaxParameter { } } -impl Parameter for MaxParameter { +impl Parameter for MaxParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/min.rs b/pywr-core/src/parameters/min.rs index 62c3e1ca..a407220c 100644 --- a/pywr-core/src/parameters/min.rs +++ b/pywr-core/src/parameters/min.rs @@ -24,7 +24,7 @@ impl MinParameter { } } -impl Parameter for MinParameter { +impl Parameter for MinParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/mod.rs b/pywr-core/src/parameters/mod.rs index 10f4af27..9d1c6c39 100644 --- a/pywr-core/src/parameters/mod.rs +++ b/pywr-core/src/parameters/mod.rs @@ -28,7 +28,7 @@ pub use self::rhai::RhaiParameter; use super::PywrError; use crate::network::Network; use crate::scenario::ScenarioIndex; -use crate::state::{MultiValue, ParameterState, State}; +use crate::state::{ParameterState, State}; use crate::timestep::Timestep; pub use activation_function::ActivationFunction; pub use aggregated::{AggFunc, AggregatedParameter}; @@ -200,8 +200,10 @@ pub fn downcast_variable_config_ref(variable_config: &dyn VariableCo } } -// TODO It might be possible to make these three traits into a single generic trait -pub trait Parameter: Send + Sync { +/// A trait that defines a component that produces a value each time-step. +/// +/// The trait is generic over the type of the value produced. +pub trait Parameter: Send + Sync { fn as_any_mut(&mut self) -> &mut dyn Any; fn meta(&self) -> &ParameterMeta; fn name(&self) -> &str { @@ -223,7 +225,7 @@ pub trait Parameter: Send + Sync { model: &Network, state: &State, internal_state: &mut Option>, - ) -> Result; + ) -> Result; fn after( &self, @@ -267,75 +269,6 @@ pub trait Parameter: Send + Sync { } } -pub trait IndexParameter: Send + Sync { - fn meta(&self) -> &ParameterMeta; - fn name(&self) -> &str { - self.meta().name.as_str() - } - - fn setup( - &self, - _timesteps: &[Timestep], - _scenario_index: &ScenarioIndex, - ) -> Result>, PywrError> { - Ok(None) - } - - fn compute( - &self, - timestep: &Timestep, - scenario_index: &ScenarioIndex, - model: &Network, - state: &State, - internal_state: &mut Option>, - ) -> Result; - - fn after( - &self, - #[allow(unused_variables)] timestep: &Timestep, - #[allow(unused_variables)] scenario_index: &ScenarioIndex, - #[allow(unused_variables)] model: &Network, - #[allow(unused_variables)] state: &State, - #[allow(unused_variables)] internal_state: &mut Option>, - ) -> Result<(), PywrError> { - Ok(()) - } -} - -pub trait MultiValueParameter: Send + Sync { - fn meta(&self) -> &ParameterMeta; - fn name(&self) -> &str { - self.meta().name.as_str() - } - fn setup( - &self, - #[allow(unused_variables)] timesteps: &[Timestep], - #[allow(unused_variables)] scenario_index: &ScenarioIndex, - ) -> Result>, PywrError> { - Ok(None) - } - - fn compute( - &self, - timestep: &Timestep, - scenario_index: &ScenarioIndex, - model: &Network, - state: &State, - internal_state: &mut Option>, - ) -> Result; - - fn after( - &self, - #[allow(unused_variables)] timestep: &Timestep, - #[allow(unused_variables)] scenario_index: &ScenarioIndex, - #[allow(unused_variables)] model: &Network, - #[allow(unused_variables)] state: &State, - #[allow(unused_variables)] internal_state: &mut Option>, - ) -> Result<(), PywrError> { - Ok(()) - } -} - #[derive(Copy, Clone)] pub enum IndexValue { Constant(usize), diff --git a/pywr-core/src/parameters/negative.rs b/pywr-core/src/parameters/negative.rs index f44621a7..b1a7eab1 100644 --- a/pywr-core/src/parameters/negative.rs +++ b/pywr-core/src/parameters/negative.rs @@ -21,7 +21,7 @@ impl NegativeParameter { } } -impl Parameter for NegativeParameter { +impl Parameter for NegativeParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/offset.rs b/pywr-core/src/parameters/offset.rs index 65c8c1af..1b7be433 100644 --- a/pywr-core/src/parameters/offset.rs +++ b/pywr-core/src/parameters/offset.rs @@ -41,7 +41,7 @@ impl OffsetParameter { } } -impl Parameter for OffsetParameter { +impl Parameter for OffsetParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/polynomial.rs b/pywr-core/src/parameters/polynomial.rs index 16d82126..5b125c07 100644 --- a/pywr-core/src/parameters/polynomial.rs +++ b/pywr-core/src/parameters/polynomial.rs @@ -27,7 +27,7 @@ impl Polynomial1DParameter { } } -impl Parameter for Polynomial1DParameter { +impl Parameter for Polynomial1DParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/profiles/daily.rs b/pywr-core/src/parameters/profiles/daily.rs index 6f2411d2..386b853f 100644 --- a/pywr-core/src/parameters/profiles/daily.rs +++ b/pywr-core/src/parameters/profiles/daily.rs @@ -21,7 +21,7 @@ impl DailyProfileParameter { } } -impl Parameter for DailyProfileParameter { +impl Parameter for DailyProfileParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/profiles/monthly.rs b/pywr-core/src/parameters/profiles/monthly.rs index 60b49679..9bf4244e 100644 --- a/pywr-core/src/parameters/profiles/monthly.rs +++ b/pywr-core/src/parameters/profiles/monthly.rs @@ -67,7 +67,7 @@ fn interpolate_last(date: &NaiveDateTime, first_value: f64, last_value: f64) -> } } -impl Parameter for MonthlyProfileParameter { +impl Parameter for MonthlyProfileParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/profiles/rbf.rs b/pywr-core/src/parameters/profiles/rbf.rs index e92d935f..bcc71e55 100644 --- a/pywr-core/src/parameters/profiles/rbf.rs +++ b/pywr-core/src/parameters/profiles/rbf.rs @@ -101,7 +101,7 @@ impl RbfProfileParameter { } } -impl Parameter for RbfProfileParameter { +impl Parameter for RbfProfileParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/profiles/uniform_drawdown.rs b/pywr-core/src/parameters/profiles/uniform_drawdown.rs index a34d4439..fe13f088 100644 --- a/pywr-core/src/parameters/profiles/uniform_drawdown.rs +++ b/pywr-core/src/parameters/profiles/uniform_drawdown.rs @@ -32,7 +32,7 @@ impl UniformDrawdownProfileParameter { } } -impl Parameter for UniformDrawdownProfileParameter { +impl Parameter for UniformDrawdownProfileParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/profiles/weekly.rs b/pywr-core/src/parameters/profiles/weekly.rs index 4eadb5b4..b43e74a3 100644 --- a/pywr-core/src/parameters/profiles/weekly.rs +++ b/pywr-core/src/parameters/profiles/weekly.rs @@ -180,7 +180,7 @@ impl WeeklyProfileParameter { } } -impl Parameter for WeeklyProfileParameter { +impl Parameter for WeeklyProfileParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/py.rs b/pywr-core/src/parameters/py.rs index 28714beb..ba88286f 100644 --- a/pywr-core/src/parameters/py.rs +++ b/pywr-core/src/parameters/py.rs @@ -1,7 +1,7 @@ use super::{IndexValue, Parameter, ParameterMeta, PywrError, Timestep}; use crate::metric::Metric; use crate::network::Network; -use crate::parameters::{downcast_internal_state_mut, MultiValueParameter}; +use crate::parameters::downcast_internal_state_mut; use crate::scenario::ScenarioIndex; use crate::state::{MultiValue, ParameterState, State}; use pyo3::prelude::*; @@ -69,7 +69,7 @@ impl PyParameter { } } -impl Parameter for PyParameter { +impl Parameter for PyParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } @@ -164,7 +164,11 @@ impl Parameter for PyParameter { } } -impl MultiValueParameter for PyParameter { +impl Parameter for PyParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } @@ -343,7 +347,7 @@ class MyParameter: let mut internal_p_states: Vec<_> = scenario_indices .iter() - .map(|si| Parameter::setup(¶m, ×teps, si).expect("Could not setup the PyParameter")) + .map(|si| Parameter::::setup(¶m, ×teps, si).expect("Could not setup the PyParameter")) .collect(); let model = Network::default(); @@ -412,14 +416,14 @@ class MyParameter: let mut internal_p_states: Vec<_> = scenario_indices .iter() - .map(|si| MultiValueParameter::setup(¶m, ×teps, si).expect("Could not setup the PyParameter")) + .map(|si| Parameter::::setup(¶m, ×teps, si).expect("Could not setup the PyParameter")) .collect(); let model = Network::default(); for ts in timesteps { for (si, internal) in scenario_indices.iter().zip(internal_p_states.iter_mut()) { - let value = MultiValueParameter::compute(¶m, ts, si, &model, &state, internal).unwrap(); + let value = Parameter::::compute(¶m, ts, si, &model, &state, internal).unwrap(); assert_approx_eq!(f64, *value.get_value("a-float").unwrap(), std::f64::consts::PI); diff --git a/pywr-core/src/parameters/rhai.rs b/pywr-core/src/parameters/rhai.rs index 8fcfbb5f..57c14ddc 100644 --- a/pywr-core/src/parameters/rhai.rs +++ b/pywr-core/src/parameters/rhai.rs @@ -55,7 +55,7 @@ impl RhaiParameter { } } -impl Parameter for RhaiParameter { +impl Parameter for RhaiParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/parameters/threshold.rs b/pywr-core/src/parameters/threshold.rs index 6d02fc05..148a0cd9 100644 --- a/pywr-core/src/parameters/threshold.rs +++ b/pywr-core/src/parameters/threshold.rs @@ -1,10 +1,11 @@ use crate::metric::Metric; use crate::network::Network; -use crate::parameters::{downcast_internal_state_mut, IndexParameter, ParameterMeta}; +use crate::parameters::{downcast_internal_state_mut, Parameter, ParameterMeta}; use crate::scenario::ScenarioIndex; use crate::state::{ParameterState, State}; use crate::timestep::Timestep; use crate::PywrError; +use std::any::Any; use std::str::FromStr; pub enum Predicate { @@ -50,7 +51,11 @@ impl ThresholdParameter { } } -impl IndexParameter for ThresholdParameter { +impl Parameter for ThresholdParameter { + fn as_any_mut(&mut self) -> &mut dyn Any { + self + } + fn meta(&self) -> &ParameterMeta { &self.meta } diff --git a/pywr-core/src/parameters/vector.rs b/pywr-core/src/parameters/vector.rs index 7a9263a0..87c25d0f 100644 --- a/pywr-core/src/parameters/vector.rs +++ b/pywr-core/src/parameters/vector.rs @@ -20,7 +20,7 @@ impl VectorParameter { } } -impl Parameter for VectorParameter { +impl Parameter for VectorParameter { fn as_any_mut(&mut self) -> &mut dyn Any { self } diff --git a/pywr-core/src/test_utils.rs b/pywr-core/src/test_utils.rs index 284825e4..941e4d3d 100644 --- a/pywr-core/src/test_utils.rs +++ b/pywr-core/src/test_utils.rs @@ -158,7 +158,7 @@ pub fn simple_storage_model() -> Model { /// See [`AssertionRecorder`] for more information. pub fn run_and_assert_parameter( model: &mut Model, - parameter: Box, + parameter: Box>, expected_values: Array2, ulps: Option, epsilon: Option,