andes.core.service.NumRepeat#
- class andes.core.service.NumRepeat(u, ref, **kwargs)[source]#
A helper Service type which repeats a v-provider's value based on the shape from a BackRef
Examples
NumRepeat was originally designed for computing the inertia-weighted average rotor speed (center of inertia speed). COI speed is computed with
\[\omega_{COI} = \frac{ \sum{M_i * \omega_i} } {\sum{M_i}}\]The numerator can be calculated with a mix of BackRef, ExtParam and ExtState. The denominator needs to be calculated with NumReduce and Service Repeat. That is, use NumReduce to calculate the sum, and use NumRepeat to repeat the summed value for each device.
In the COI class, one would have
class COIModel(...): def __init__(...): ... self.SynGen = BackRef() self.SynGenIdx = RefFlatten(ref=self.SynGen) self.M = ExtParam(model='SynGen', src='M', indexer=self.SynGenIdx) self.wgen = ExtState(model='SynGen', src='omega', indexer=self.SynGenIdx) self.Mt = NumReduce(u=self.M, fun=np.sum, ref=self.SynGen) self.Mtr = NumRepeat(u=self.Mt, ref=self.SynGen) self.pidx = IdxRepeat(u=self.idx,ref=self.SynGen)
Finally, one would define the center of inertia speed as
self.wcoi = Algeb(v_str='1', e_str='-wcoi') self.wcoi_sub = ExtAlgeb(model='COI', src='wcoi', e_str='M * wgen / Mtr', v_str='M / Mtr', indexer=self.pidx, )
It is very worth noting that the implementation uses a trick to separate the average weighted sum into n sub-equations, each calculating the \((M_i * \omega_i) / (\sum{M_i})\). Since all the variables are preserved in the sub-equation, the derivatives can be calculated correctly.
Methods
assign_memory(n)Assign memory for
self.vand set the array to zero.get_names()Return name in a list
Attributes
class_nameReturn the class name
nReturn the count of values in
self.v.vReturn the values of the repeated values in a sequential 1-D array