Ejemplo n.º 1
0
    def gramians(self):
        A = self.fom.A
        B = self.fom.B
        C = self.fom.C
        E = self.fom.E if not isinstance(self.fom.E, IdentityOperator) else None
        options = self.solver_options

        cf = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(), trans=False, options=options)
        of = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(), trans=True, options=options)
        return cf, of
Ejemplo n.º 2
0
Archivo: bt.py Proyecto: pymor/pymor
    def _gramians(self):
        A = self.fom.A
        B = self.fom.B
        C = self.fom.C
        E = self.fom.E if not isinstance(self.fom.E, IdentityOperator) else None
        options = self.solver_options

        cf = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                             trans=False, options=options)
        of = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                             trans=True, options=options)
        return cf, of
Ejemplo n.º 3
0
    def _gramians(self):
        A, B, C, E = (getattr(self.fom, op).assemble(mu=self.mu)
                      for op in ['A', 'B', 'C', 'E'])
        if isinstance(E, IdentityOperator):
            E = None
        options = self.solver_options

        cf = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                             trans=False, options=options)
        of = solve_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                             trans=True, options=options)
        return cf, of
Ejemplo n.º 4
0
def test_ricc_lrcf(n, m, p, with_E, with_R, with_S, trans, solver):
    _check_availability(solver)

    if not with_E:
        A = conv_diff_1d_fd(n, 1, 1)
        E = None
    else:
        A, E = conv_diff_1d_fem(n, 1, 1)
    np.random.seed(0)
    B = np.random.randn(n, m)
    C = np.random.randn(p, n)
    D = np.random.randn(p, m)
    if not trans:
        R0 = np.random.randn(p, p)
        R = D.dot(D.T) + R0.dot(R0.T) if with_R else None
        S = B.dot(D.T) if with_S else None
    else:
        R0 = np.random.randn(m, m)
        R = D.T.dot(D) + R0.dot(R0.T) if with_R else None
        S = C.T.dot(D) if with_S else None

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E) if with_E else None
    Bva = Aop.source.from_numpy(B.T)
    Cva = Aop.source.from_numpy(C)
    Sva = Aop.source.from_numpy(S.T) if with_S else None

    try:
        Zva = solve_ricc_lrcf(Aop,
                              Eop,
                              Bva,
                              Cva,
                              R,
                              Sva,
                              trans=trans,
                              options=solver)
    except NotImplementedError:
        return

    assert len(Zva) <= n

    Z = Zva.to_numpy().T
    assert relative_residual(A, E, B, C, R, S, Z, trans) < 1e-8
Ejemplo n.º 5
0
def test_ricc_lrcf(n, m, p, with_E, with_R, with_S, trans, solver):
    _check_availability(solver)

    if not with_E:
        A = conv_diff_1d_fd(n, 1, 1)
        E = None
    else:
        A, E = conv_diff_1d_fem(n, 1, 1)
    np.random.seed(0)
    B = np.random.randn(n, m)
    C = np.random.randn(p, n)
    D = np.random.randn(p, m)
    if not trans:
        R0 = np.random.randn(p, p)
        R = D.dot(D.T) + R0.dot(R0.T) if with_R else None
        S = B.dot(D.T) if with_S else None
    else:
        R0 = np.random.randn(m, m)
        R = D.T.dot(D) + R0.dot(R0.T) if with_R else None
        S = C.T.dot(D) if with_S else None

    Aop = NumpyMatrixOperator(A)
    Eop = NumpyMatrixOperator(E) if with_E else None
    Bva = Aop.source.from_numpy(B.T)
    Cva = Aop.source.from_numpy(C)
    Sva = Aop.source.from_numpy(S.T) if with_S else None

    try:
        Zva = solve_ricc_lrcf(Aop, Eop, Bva, Cva, R, Sva, trans=trans, options=solver)
    except NotImplementedError:
        return

    assert len(Zva) <= n

    Z = Zva.to_numpy().T
    assert relative_residual(A, E, B, C, R, S, Z, trans) < 1e-8