hydr_structures/structures/controlled_pump/
batch.rs1use super::{ControlledPumpOutput, ControlledPumpTrial, PumpResponseDefinition};
4use crate::structures::tensor::controlled_pump::{
5 TensorControlledPumpContext, TensorControlledPumpSelection,
6};
7use crate::structures::{
8 ControlEvent, ControlSample, OperatingControlBatch, StructureError, StructureOperation,
9};
10use numr::dtype::DType;
11use numr::runtime::Runtime;
12use std::sync::Arc;
13
14#[derive(Clone, Debug)]
16pub struct ControlledPumpBatch<R: Runtime<DType = DType>> {
17 pub(crate) context: Arc<TensorControlledPumpContext<R>>,
18 pub(crate) controls: OperatingControlBatch<R>,
19}
20impl<R: Runtime<DType = DType>> ControlledPumpBatch<R> {
21 pub fn new(
25 controls: OperatingControlBatch<R>,
26 definitions: Vec<PumpResponseDefinition>,
27 ) -> Result<Self, StructureError> {
28 let context = Arc::new(TensorControlledPumpContext::new(&controls, definitions)?);
29 Ok(Self { context, controls })
30 }
31 pub fn controls(&self) -> &OperatingControlBatch<R> {
33 &self.controls
34 }
35 pub fn definitions(&self) -> &[PumpResponseDefinition] {
37 &self.context.definitions
38 }
39 pub fn time(&self) -> f64 {
41 self.controls.time()
42 }
43 pub fn accepted_steps(&self) -> usize {
45 self.controls.accepted_steps()
46 }
47 pub fn next_event(&self) -> Option<ControlEvent> {
49 self.controls.next_event()
50 }
51 pub fn trial_to(
55 &self,
56 end_s: f64,
57 samples: &[ControlSample],
58 ) -> Result<ControlledPumpTrial<R>, StructureError>
59 where
60 R::Client: numr::ops::BinaryOps<R>
61 + numr::ops::CompareOps<R>
62 + numr::ops::ConditionalOps<R>
63 + numr::ops::ReduceOps<R>
64 + numr::ops::ScalarOps<R>
65 + numr::ops::TwoSumOps<R>
66 + numr::ops::TypeConversionOps<R>
67 + numr::ops::UnaryOps<R>,
68 {
69 self.complete(self.prepare_to(end_s)?, samples)
70 }
71 pub(crate) fn selected(&self) -> Result<TensorControlledPumpSelection<R>, StructureError>
72 where
73 R::Client: numr::ops::ConditionalOps<R>,
74 {
75 self.context.select(&self.controls.state.high)
76 }
77 pub fn outputs(&self) -> Result<Vec<ControlledPumpOutput>, StructureError>
79 where
80 R::Client: numr::ops::ConditionalOps<R>,
81 {
82 super::projection::outputs(self)
83 }
84 pub fn operations(&self) -> Result<Vec<StructureOperation>, StructureError>
86 where
87 R::Client: numr::ops::ConditionalOps<R>,
88 {
89 Ok(self
90 .outputs()?
91 .into_iter()
92 .map(|output| StructureOperation {
93 structure_id: output.structure_id,
94 operating_point: output.operating_point,
95 })
96 .collect())
97 }
98}