|
4 | 4 | from .. import prognostics_model |
5 | 5 | from math import inf |
6 | 6 | from copy import deepcopy |
7 | | -from numpy import sqrt, sign, maximum |
| 7 | +from numpy import sqrt, sign, maximum, minimum, isscalar, array, any, shape |
8 | 8 |
|
9 | 9 |
|
10 | 10 | class PneumaticValveBase(prognostics_model.PrognosticsModel): |
@@ -183,6 +183,20 @@ def initialize(self, u, z = None): |
183 | 183 | return x0 |
184 | 184 |
|
185 | 185 | def gas_flow(self, pIn, pOut, C, A): |
| 186 | + # Step 1: If array- run for each element |
| 187 | + # Note: this is so complicated because it is run multiple times with mixtures of scalars and arrays |
| 188 | + inputs = array([pIn, pOut, C, A]) |
| 189 | + if any([not isscalar(i) for i in inputs]): |
| 190 | + # Handle case where one or more is array |
| 191 | + size = [shape(i) for i in inputs] |
| 192 | + size = max([i[0] if i else 0 for i in size]) # Size of array |
| 193 | + |
| 194 | + # Create Iterable Elements for scalars |
| 195 | + iter_inputs = [[i] * size if isscalar(i) else i for i in inputs] |
| 196 | + |
| 197 | + # Run each element through function |
| 198 | + return array([self.gas_flow(a, b, c, d) for a, b, c, d in zip(*iter_inputs)]) |
| 199 | + |
186 | 200 | k = self.parameters['gas_gamma'] |
187 | 201 | T = self.parameters['gas_temp'] |
188 | 202 | Z = self.parameters['gas_z'] |
|
0 commit comments