Exemplo n.º 1
0
def movesquarematrixcolnrow(M, indi, indf):
    """
    Move row and col of a square matrix from index i to index j

    Parameters
    ----------

    M: 2D array like
        A square matrix.

    indi, indf: intergers
        Indices.

    Return
    ------
    A: same type as :code:`M`.
        :code:`A[j, :] == M[i, :]` and :code:`A[:, j] == M[:, i]`.

    Example
    -------
    >>> import numpy as np
    >>> M = np.eye(3)
    >>> print(M)
    [[ 1.  0.  0.]
     [ 0.  1.  0.]
     [ 0.  0.  1.]]
    >>> from pyphs.core.structure.moves import movesquarematrixcolnrow
    >>> A = movesquarematrixcolnrow(M, 0, 2)
    >>> print(A)
    """
    n = M.shape[0]
    new_indices = myrange(n, indi, indf)
    return M[new_indices, new_indices]
Exemplo n.º 2
0
def movesquarematrixcolnrow(M, indi, indf):
    """
    Move row and col of a square matrix from index i to index j

    Parameters
    ----------

    M: 2D array like
        A square matrix.

    indi, indf: intergers
        Indices.

    Return
    ------
    A: same type as :code:`M`.
        :code:`A[j, :] == M[i, :]` and :code:`A[:, j] == M[:, i]`.

    Example
    -------
    >>> import numpy as np
    >>> M = np.eye(3)
    >>> print(M)
    [[ 1.  0.  0.]
     [ 0.  1.  0.]
     [ 0.  0.  1.]]
    >>> from pyphs.core.structure.moves import movesquarematrixcolnrow
    >>> A = movesquarematrixcolnrow(M, 0, 2)
    >>> print(A)
    """
    n = M.shape[0]
    new_indices = myrange(n, indi, indf)
    return M[new_indices, new_indices]
Exemplo n.º 3
0
 def move_edge(self, indi, indf):
     """
     move edge 'indi' to position 'indf' in
         - self.edges
         - self.Gamma
         - self.Lambda
     """
     old_indices = list(range(self.ne))
     new_indices = myrange(self.ne, indi, indf)
     self.Gamma = self.Gamma[:, new_indices]
     self.Lambda = self.Lambda[:, new_indices]
     self.edges = [self.edges[n] for n in new_indices]
     return old_indices, new_indices
Exemplo n.º 4
0
 def move_node(self, indi, indf):
     """
     move node 'indi' to position 'indf' in
         - phs.nodes
         - phs.Gamma
         - phs.Lambda
     """
     old_indices = list(range(self.nn))
     new_indices = myrange(self.nn, indi, indf)
     self.nodes = [self.nodes[n] for n in new_indices]
     self.Gamma = self.Gamma[new_indices, :]
     self.Lambda = self.Lambda[new_indices, :]
     for (old_i, new_i) in zip(old_indices, new_indices):
         self.ic_nodes[self.ic_nodes.index(old_i)] = new_i
Exemplo n.º 5
0
def movematrixcols(matrix, indi, indf):
    """
    Move column of matrix M from indi to indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final column/row indices in [0, shape(M)[1]-1].
    """
    n = matrix.shape[1]
    new_indices = myrange(n, indi, indf)
    return matrix[:, new_indices]
Exemplo n.º 6
0
def movematrixcols(matrix, indi, indf):
    """
    Move column of matrix M from indi to indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final column/row indices in [0, shape(M)[1]-1].
    """
    n = matrix.shape[1]
    new_indices = myrange(n, indi, indf)
    return matrix[:, new_indices]
Exemplo n.º 7
0
def move_stor(core, indi, indf):
    """
    Move storage of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final storage indices in the set of storages.
    """
    new_indices = myrange(core.dims.x(), indi, indf)
    core.x = [core.x[el] for el in new_indices]
    if core._dxH is not None:
        core._dxH = [core._dxH[el] for el in new_indices]
    moveCoreMcolnrow(core, indi, indf)
Exemplo n.º 8
0
def move_stor(core, indi, indf):
    """
    Move storage of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final storage indices in the set of storages.
    """
    new_indices = myrange(core.dims.x(), indi, indf)
    core.x = [core.x[el] for el in new_indices]
    if core._dxH is not None:
        core._dxH = [core._dxH[el] for el in new_indices]
    moveCoreMcolnrow(core, indi, indf)
Exemplo n.º 9
0
def move_connector(core, indi, indf):
    """
    Move connector of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final connector indices in the set of connectors.
    """
    new_indices = myrange(core.dims.cy(), indi, indf)
    core.cu = [core.cu[el] for el in new_indices]
    core.cy = [core.cy[el] for el in new_indices]
    moveCoreMcolnrow(core, core.dims.x()+core.dims.w()+core.dims.y()+indi,
                     core.dims.x()+core.dims.w()+core.dims.y()+indf)
Exemplo n.º 10
0
def move_port(core, indi, indf):
    """
    Move port of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final port indices in the set of ports.
    """
    new_indices = myrange(core.dims.y(), indi, indf)
    core.u = [core.u[el] for el in new_indices]
    core.y = [core.y[el] for el in new_indices]
    moveCoreMcolnrow(core, core.dims.x()+core.dims.w()+indi,
                     core.dims.x()+core.dims.w()+indf)
Exemplo n.º 11
0
def move_diss(core, indi, indf):
    """
    Move dissipation of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final dissipation indices in the set of dissipations.
    """
    new_indices = myrange(core.dims.w(), indi, indf)
    core.w = [core.w[el] for el in new_indices]
    core.z = [core.z[el] for el in new_indices]
    moveCoreMcolnrow(core, core.dims.x() + indi, core.dims.x() + indf)
    if not core.Zl.is_zero:
        core.Zl = movesquarematrixcolnrow(core.Zl, indi, indf)
Exemplo n.º 12
0
def move_diss(core, indi, indf):
    """
    Move dissipation of Core from initial position indi to final position indf.

    Parameters
    ----------

    core : Core

    indi, indf : intergers
        Initial and final dissipation indices in the set of dissipations.
    """
    new_indices = myrange(core.dims.w(), indi, indf)
    core.w = [core.w[el] for el in new_indices]
    core.z = [core.z[el] for el in new_indices]
    moveCoreMcolnrow(core, core.dims.x()+indi, core.dims.x()+indf)
    if (not core.Zl.is_zero and
            indi < core.dims.wl() and
            indf < core.dims.wl()):
        core.Zl = movesquarematrixcolnrow(core.Zl, indi, indf)
    elif (not core.Zl.is_zero):
        core.Zl = core.Zl[:0, :0]  # Set Matrix to zero
Exemplo n.º 13
0
def movesquarematrixcolnrow(M, indi, indf):
    """
    Move row and col of a square matrix from index i to index j

    Parameters
    ----------

    M: 2D array like
        A square matrix.

    indi, indf: intergers
        Indices.

    Return
    ------
    A: same type as :code:`M`.
        :code:`A[j, :] == M[i, :]` and :code:`A[:, j] == M[:, i]`.

    Example
    -------
    >>> import sympy as sp
    >>> # Define a skew-symmetric matrix
    >>> M = sp.Matrix([[ 0, +1,  0],
    ...                [-1,  0, +2],
    ...                [ 0, -2,  0]])
    >>> # Move row/column from index 0 to index 2
    >>> from pyphs.core.structure.moves import movesquarematrixcolnrow
    >>> movesquarematrixcolnrow(M, 0, 2)
    Matrix([
    [ 0, 2, -1],
    [-2, 0,  0],
    [ 1, 0,  0]])
    """
    n = M.shape[0]
    new_indices = myrange(n, indi, indf)
    return M[new_indices, new_indices]