Example #1
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_pos_ricc_lrcf(
            A,
            E,
            B.as_range_array(),
            C.as_source_array(),
            R=self.gamma**2 *
            np.eye(self.fom.output_dim) if self.gamma != 1 else None,
            trans=False,
            options=options)
        of = solve_pos_ricc_lrcf(
            A,
            E,
            B.as_range_array(),
            C.as_source_array(),
            R=self.gamma**2 *
            np.eye(self.fom.input_dim) if self.gamma != 1 else None,
            trans=True,
            options=options)
        return cf, of
Example #2
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_pos_ricc_lrcf(
            A,
            E,
            B.as_range_array(),
            C.as_source_array(),
            R=self.gamma**2 *
            np.eye(self.fom.output_dim) if self.gamma != 1 else None,
            trans=False,
            options=options)
        of = solve_pos_ricc_lrcf(
            A,
            E,
            B.as_range_array(),
            C.as_source_array(),
            R=self.gamma**2 *
            np.eye(self.fom.input_dim) if self.gamma != 1 else None,
            trans=True,
            options=options)
        return cf, of
Example #3
0
File: bt.py Project: 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_pos_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                                 R=self.gamma**2 * np.eye(self.fom.output_dim) if self.gamma != 1 else None,
                                 trans=False, options=options)
        of = solve_pos_ricc_lrcf(A, E, B.as_range_array(), C.as_source_array(),
                                 R=self.gamma**2 * np.eye(self.fom.input_dim) if self.gamma != 1 else None,
                                 trans=True, options=options)
        return cf, of
Example #4
0
def test_pos_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) + 10 * 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) + 10 * 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

    Zva = solve_pos_ricc_lrcf(Aop, Eop, Bva, Cva, R, Sva, trans=trans, options=solver)
    assert len(Zva) <= n

    Z = Zva.to_numpy().T
    if not with_R:
        R = np.eye(p if not trans else m)
    assert relative_residual(A, E, B, C, -R, S, Z, trans) < 1e-8
Example #5
0
def test_pos_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) + 10 * 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) + 10 * 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

    Zva = solve_pos_ricc_lrcf(Aop,
                              Eop,
                              Bva,
                              Cva,
                              R,
                              Sva,
                              trans=trans,
                              options=solver)
    assert len(Zva) <= n

    Z = Zva.to_numpy().T
    if not with_R:
        R = np.eye(p if not trans else m)
    assert relative_residual(A, E, B, C, -R, S, Z, trans) < 1e-8