Exemple #1
0
def test_sylv_schur_V_E(n, r, m):
    np.random.seed(0)

    A, E = diff_conv_1d_fem(n, 1, 1)
    B = np.random.randn(n, m)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Er = np.random.randn(r, r)
    Er = (Er + Er.T) / 2
    Er += r * np.eye(r)
    Br = np.random.randn(r, m)

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E)
    Bop = NumpyMatrixOperator(B)

    Arop = NumpyMatrixOperator(Ar)
    Erop = NumpyMatrixOperator(Er)
    Brop = NumpyMatrixOperator(Br)

    Vva = solve_sylv_schur(Aop, Arop, E=Eop, Er=Erop, B=Bop, Br=Brop)

    V = Vva.to_numpy().T

    AVErT = A.dot(V.dot(Er.T))
    EVArT = E.dot(V.dot(Ar.T))
    BBrT = B.dot(Br.T)
    assert fro_norm(AVErT + EVArT + BBrT) / fro_norm(BBrT) < 1e-10
Exemple #2
0
def test_sylv_schur_W_E(n, r, p):
    np.random.seed(0)

    A, E = diff_conv_1d_fem(n, 1, 1)
    C = np.random.randn(p, n)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Er = np.random.randn(r, r)
    Er = (Er + Er.T) / 2
    Er += r * np.eye(r)
    Cr = np.random.randn(p, r)

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E)
    Cop = NumpyMatrixOperator(C)

    Arop = NumpyMatrixOperator(Ar)
    Erop = NumpyMatrixOperator(Er)
    Crop = NumpyMatrixOperator(Cr)

    Wva = solve_sylv_schur(Aop, Arop, E=Eop, Er=Erop, C=Cop, Cr=Crop)

    W = Wva.to_numpy().T

    ATWEr = A.T.dot(W.dot(Er))
    ETWAr = E.T.dot(W.dot(Ar))
    CTCr = C.T.dot(Cr)
    assert fro_norm(ATWEr + ETWAr + CTCr) / fro_norm(CTCr) < 1e-10
Exemple #3
0
    def _projection_matrices(self, rom, projection):
        if self.fom.parametric:
            fom = self.fom.with_(**{
                op: getattr(self.fom, op).assemble(mu=self.mu)
                for op in ['A', 'B', 'C', 'D', 'E']
            },
                                 parameter_space=None)
        else:
            fom = self.fom

        self.V, self.W = solve_sylv_schur(fom.A,
                                          rom.A,
                                          E=fom.E,
                                          Er=rom.E,
                                          B=fom.B,
                                          Br=rom.B,
                                          C=fom.C,
                                          Cr=rom.C)

        if projection == 'orth':
            self.V = gram_schmidt(self.V, atol=0, rtol=0)
            self.W = gram_schmidt(self.W, atol=0, rtol=0)
        elif projection == 'biorth':
            self.V, self.W = gram_schmidt_biorth(self.V, self.W, product=fom.E)

        self._pg_reductor = LTIPGReductor(fom, self.W, self.V,
                                          projection == 'biorth')
Exemple #4
0
def test_sylv_schur_V_E(n, r, m):
    np.random.seed(0)

    A, E = diff_conv_1d_fem(n, 1, 1)
    B = np.random.randn(n, m)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Er = np.random.randn(r, r)
    Er = (Er + Er.T) / 2
    Er += r * np.eye(r)
    Br = np.random.randn(r, m)

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E)
    Bop = NumpyMatrixOperator(B)

    Arop = NumpyMatrixOperator(Ar)
    Erop = NumpyMatrixOperator(Er)
    Brop = NumpyMatrixOperator(Br)

    Vva = solve_sylv_schur(Aop, Arop, E=Eop, Er=Erop, B=Bop, Br=Brop)

    V = Vva.to_numpy().T

    AVErT = A.dot(V.dot(Er.T))
    EVArT = E.dot(V.dot(Ar.T))
    BBrT = B.dot(Br.T)
    assert fro_norm(AVErT + EVArT + BBrT) / fro_norm(BBrT) < 1e-10
Exemple #5
0
def test_sylv_schur_W_E(n, r, p):
    np.random.seed(0)

    A, E = diff_conv_1d_fem(n, 1, 1)
    C = np.random.randn(p, n)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Er = np.random.randn(r, r)
    Er = (Er + Er.T) / 2
    Er += r * np.eye(r)
    Cr = np.random.randn(p, r)

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E)
    Cop = NumpyMatrixOperator(C)

    Arop = NumpyMatrixOperator(Ar)
    Erop = NumpyMatrixOperator(Er)
    Crop = NumpyMatrixOperator(Cr)

    Wva = solve_sylv_schur(Aop, Arop, E=Eop, Er=Erop, C=Cop, Cr=Crop)

    W = Wva.to_numpy().T

    ATWEr = A.T.dot(W.dot(Er))
    ETWAr = E.T.dot(W.dot(Ar))
    CTCr = C.T.dot(Cr)
    assert fro_norm(ATWEr + ETWAr + CTCr) / fro_norm(CTCr) < 1e-10
Exemple #6
0
    def _projection_matrices(self, rom, projection):
        fom = self.fom
        self.V, self.W = solve_sylv_schur(fom.A, rom.A,
                                          E=fom.E, Er=rom.E,
                                          B=fom.B, Br=rom.B,
                                          C=fom.C, Cr=rom.C)
        if projection == 'orth':
            self.V = gram_schmidt(self.V, atol=0, rtol=0)
            self.W = gram_schmidt(self.W, atol=0, rtol=0)
        elif projection == 'biorth':
            self.V, self.W = gram_schmidt_biorth(self.V, self.W, product=fom.E)

        self._pg_reductor = LTIPGReductor(fom, self.W, self.V, projection == 'biorth')
Exemple #7
0
    def _projection_matrices(self, rom, projection):
        fom = self.fom
        self.V, self.W = solve_sylv_schur(fom.A,
                                          rom.A,
                                          E=fom.E,
                                          Er=rom.E,
                                          B=fom.B,
                                          Br=rom.B,
                                          C=fom.C,
                                          Cr=rom.C)
        if projection == 'orth':
            self.V = gram_schmidt(self.V, atol=0, rtol=0)
            self.W = gram_schmidt(self.W, atol=0, rtol=0)
        elif projection == 'biorth':
            self.V, self.W = gram_schmidt_biorth(self.V, self.W, product=fom.E)

        self._pg_reductor = LTIPGReductor(fom, self.W, self.V,
                                          projection == 'biorth')
Exemple #8
0
 def _set_V_W_reductor(self, rom, projection):
     fom = (
         self.fom.with_(
             **{op: getattr(self.fom, op).assemble(mu=self.mu)
                for op in ['A', 'B', 'C', 'D', 'E']}
         )
         if self.fom.parametric
         else self.fom
     )
     self.V, self.W = solve_sylv_schur(fom.A, rom.A,
                                       E=fom.E, Er=rom.E,
                                       B=fom.B, Br=rom.B,
                                       C=fom.C, Cr=rom.C)
     if projection == 'orth':
         gram_schmidt(self.V, atol=0, rtol=0, copy=False)
         gram_schmidt(self.W, atol=0, rtol=0, copy=False)
     elif projection == 'biorth':
         gram_schmidt_biorth(self.V, self.W, product=fom.E, copy=False)
     self._pg_reductor = LTIPGReductor(fom, self.W, self.V,
                                       projection == 'biorth')
Exemple #9
0
def test_sylv_schur_V(n, r, m):
    np.random.seed(0)

    A = diff_conv_1d_fd(n, 1, 1)
    B = np.random.randn(n, m)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Br = np.random.randn(r, m)

    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)

    Arop = NumpyMatrixOperator(Ar)
    Brop = NumpyMatrixOperator(Br)

    Vva = solve_sylv_schur(Aop, Arop, B=Bop, Br=Brop)

    V = Vva.to_numpy().T

    AV = A.dot(V)
    VArT = V.dot(Ar.T)
    BBrT = B.dot(Br.T)
    assert fro_norm(AV + VArT + BBrT) / fro_norm(BBrT) < 1e-10
Exemple #10
0
def test_sylv_schur_W(n, r, p):
    np.random.seed(0)

    A = diff_conv_1d_fd(n, 1, 1)
    C = np.random.randn(p, n)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Cr = np.random.randn(p, r)

    Aop = NumpyMatrixOperator(A)
    Cop = NumpyMatrixOperator(C)

    Arop = NumpyMatrixOperator(Ar)
    Crop = NumpyMatrixOperator(Cr)

    Wva = solve_sylv_schur(Aop, Arop, C=Cop, Cr=Crop)

    W = Wva.to_numpy().T

    ATW = A.T.dot(W)
    WAr = W.dot(Ar)
    CTCr = C.T.dot(Cr)
    assert fro_norm(ATW + WAr + CTCr) / fro_norm(CTCr) < 1e-10
Exemple #11
0
def test_sylv_schur_V(n, r, m):
    np.random.seed(0)

    A = diff_conv_1d_fd(n, 1, 1)
    B = np.random.randn(n, m)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Br = np.random.randn(r, m)

    Aop = NumpyMatrixOperator(A)
    Bop = NumpyMatrixOperator(B)

    Arop = NumpyMatrixOperator(Ar)
    Brop = NumpyMatrixOperator(Br)

    Vva = solve_sylv_schur(Aop, Arop, B=Bop, Br=Brop)

    V = Vva.to_numpy().T

    AV = A.dot(V)
    VArT = V.dot(Ar.T)
    BBrT = B.dot(Br.T)
    assert fro_norm(AV + VArT + BBrT) / fro_norm(BBrT) < 1e-10
Exemple #12
0
def test_sylv_schur_W(n, r, p):
    np.random.seed(0)

    A = diff_conv_1d_fd(n, 1, 1)
    C = np.random.randn(p, n)

    Ar = np.random.randn(r, r) - r * np.eye(r)
    Cr = np.random.randn(p, r)

    Aop = NumpyMatrixOperator(A)
    Cop = NumpyMatrixOperator(C)

    Arop = NumpyMatrixOperator(Ar)
    Crop = NumpyMatrixOperator(Cr)

    Wva = solve_sylv_schur(Aop, Arop, C=Cop, Cr=Crop)

    W = Wva.to_numpy().T

    ATW = A.T.dot(W)
    WAr = W.dot(Ar)
    CTCr = C.T.dot(Cr)
    assert fro_norm(ATW + WAr + CTCr) / fro_norm(CTCr) < 1e-10