Skip to content

Commit

Permalink
Merge pull request #103 from sot/msid_state_power
Browse files Browse the repository at this point in the history
Add MSIDStatePower component
  • Loading branch information
taldcroft authored Nov 4, 2020
2 parents 080a31b + 2ded119 commit 175ec9c
Showing 1 changed file with 61 additions and 0 deletions.
61 changes: 61 additions & 0 deletions xija/component/heat.py
Original file line number Diff line number Diff line change
Expand Up @@ -1195,6 +1195,67 @@ def plot_data__time(self, fig, ax):
ax.set_ylabel('Power')


class MsidStatePower(PrecomputedHeatPower):
"""
A class that applies a constant heat power shift only when the state of an
MSID, ``state_msid``, matches a specified value, ``state_val``. The shift
is ``P`` when the ``state_val`` for ``state_msid`` is matched, otherwise it
is 0.0.
:param model: parent model object
:param node: node name or object for which to apply shift
:param state_msid: state MSID name
:param state_val: value of ``state_msid`` to be matched
:param P: size of shift in heat power (default=0.0)
The name of this component is constructed by concatenating the state msid name
and the state msid value with an underscore. For example, if the ``MsidStatePower``
component defines a power value for when the COSSRBX values match the string,
"ON ", the name of this component is ``cossrbx_on``.
The ``dvals`` data stored for this component are a boolean type. To initialize
this component, one would use the following syntax:
model.comp['cossrbx_on'].set_data(True)
"""
def __init__(self, model, node, state_msid, state_val, P=0.0):
super(MsidStatePower, self).__init__(model)
self.node = self.model.get_comp(node)
self.state_msid = str(state_msid).lower()
self.state_val = state_val
self.state_val_str = str(state_val).lower().strip()
self.n_mvals = 1
self.add_par('P', P, min=-10.0, max=10.0)

def __str__(self):
return f'{self.state_msid}_{self.state_val_str}'

def get_dvals_tlm(self):
"""
Return an array of power values where the power is ``P`` when the
``state_val`` for ``state_msid`` is matched, otherwise it is 0.0.
"""
dvals = self.model.fetch(self.state_msid, 'vals', 'nearest') == self.state_val
return dvals

def update(self):
self.mvals = np.zeros_like(self.model.times)
self.mvals[self.dvals] = self.P
self.tmal_ints = (tmal.OPCODES['precomputed_heat'],
self.node.mvals_i, # dy1/dt index
self.mvals_i,
)
self.tmal_floats = ()

def plot_data__time(self, fig, ax):
lines = ax.get_lines()
if not lines:
plot_cxctime(self.model.times, self.dvals, '#386cb0', fig=fig, ax=ax)
ax.grid()
ax.set_title(f'{self.name}: state match dvals (blue)')
ax.set_ylabel(f'{self.state_msid.upper()} == {repr(self.state_val)}')


@jit(nopython=True)
def quat_to_transform_transpose(q):
"""
Expand Down

0 comments on commit 175ec9c

Please sign in to comment.