Beispiel #1
0
    def v(self):
        """
        Return the values of the repeated values in a sequantial 1-D array

        Returns
        -------
        The array, ``self._v`` storing the repeated values
        """
        if self._v is None:
            self._v = np.zeros(len(list_flatten(self.ref.v)))
            idx = 0
            for i, v in enumerate(self.ref.v):
                self._v[idx:idx + len(v)] = self.u.v[i]
                idx += len(v)
            return self._v
        else:
            return self._v
Beispiel #2
0
def sort_psse_models(dyr_yaml):
    """
    Sort supported models so that model names are ordered by dependency.
    """
    from andes.models import non_jit
    from andes.utils.func import list_flatten

    andes_models = list_flatten(list(non_jit.values()))
    number = dict()

    for psse_model in dyr_yaml:
        dest = dyr_yaml[psse_model]['destination']
        if dest in andes_models:
            number[dest] = andes_models.index(dest)

    sorted_models = [k for k, v in sorted(number.items(), key=lambda item: item[1])]

    return sorted_models
Beispiel #3
0
    def idx2model(self, idx, allow_none=False):
        """
        Find model name for the given idx.

        Parameters
        ----------
        idx : float, int, str, array-like
            idx or idx-es of devices.
        allow_none : bool
           If True, return `None` at the positions where idx is not found.

        Returns
        -------
        If `idx` is a list, return a list of model instances.
        If `idx` is a single element, return a model instance.
        """

        ret = []
        single = False

        if not isinstance(idx, (list, tuple, np.ndarray)):
            single = True
            idx = (idx, )
        elif len(idx) > 0 and isinstance(idx[0], (list, tuple, np.ndarray)):
            idx = list_flatten(idx)

        for i in idx:
            try:
                if i is None and allow_none:
                    ret.append(None)
                else:
                    ret.append(self._idx2model[i])
            except KeyError:
                raise KeyError(
                    f'Group <{self.class_name}> does not contain device with idx={i}'
                )

        if single:
            ret = ret[0]
        return ret
Beispiel #4
0
 def v(self):
     return list_flatten(self.ref.v)
Beispiel #5
0
"""
Package for ANDES analysis routines.
"""

from collections import OrderedDict
from andes.utils.func import list_flatten

# all_routines: file name: class name
all_routines = OrderedDict([
    ('pflow', ['PFlow']),
    ('tds', ['TDS']),
    ('eig', ['EIG']),
])

class_names = list_flatten(list(all_routines.values()))
routine_cli = OrderedDict([(item.lower(), item) for item in class_names])

from andes.routines import daeint  # NOQA