Skip to main content

hydr_structures/structures/controlled_pump/
batch.rs

1//! Owning sampled control continuation with explicitly assumed instantaneous pump response.
2
3use 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/// Complete accepted controls and an explicit memoryless actual pump response model.
15#[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    /// Adopt any checked pump-only controller continuation with complete explicit response evidence.
22    ///
23    /// Advanced controls remain eligible because this response has no independent continuation memory.
24    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    /// Accepted command continuation, exposed immutably for explicit control projections.
32    pub fn controls(&self) -> &OperatingControlBatch<R> {
33        &self.controls
34    }
35    /// Complete original ordered response assumptions and provenance.
36    pub fn definitions(&self) -> &[PumpResponseDefinition] {
37        &self.context.definitions
38    }
39    /// Accepted original control time in seconds.
40    pub fn time(&self) -> f64 {
41        self.controls.time()
42    }
43    /// Original accepted control interval count. No independent response counter exists.
44    pub fn accepted_steps(&self) -> usize {
45        self.controls.accepted_steps()
46    }
47    /// Next original sampled decision or terminal support boundary.
48    pub fn next_event(&self) -> Option<ControlEvent> {
49        self.controls.next_event()
50    }
51    /// Trial sampled controls without changing accepted operation or qualification memory.
52    ///
53    /// The candidate command governs the response on the endpoint's right side. No water transfer follows.
54    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    /// Explicitly project actual operation, original controller identity, and response assumptions.
78    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    /// Explicitly project original-order operation packets without claiming hydraulic or transfer acceptance.
85    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}