Пример #1
0
 def projected_to_subbasis(self, dim_range=None, dim_source=None, name=None):
     if self.rhs_is_functional:
         rhs = project_to_subbasis(self.rhs, None, dim_range)
     else:
         rhs = project_to_subbasis(self.rhs, dim_range, None)
     return ResidualOperator(project_to_subbasis(self.operator, dim_range, dim_source), rhs,
                             self.rhs_is_functional, name=name)
Пример #2
0
 def projected_to_subbasis(self,
                           dim_range=None,
                           dim_source=None,
                           name=None):
     return self.with_(operator=project_to_subbasis(self.operator, None,
                                                    dim_source),
                       mass=project_to_subbasis(self.mass, None,
                                                dim_source))
Пример #3
0
 def projected_to_subbasis(self,
                           dim_range=None,
                           dim_source=None,
                           name=None):
     return ResidualOperator(project_to_subbasis(self.operator, dim_range,
                                                 dim_source),
                             project_to_subbasis(self.rhs, dim_range, None),
                             name=name)
Пример #4
0
 def project_operators_to_subbasis(self, dims):
     rom = self._last_rom
     dim = dims['RB']
     projected_operators = {'operator': project_to_subbasis(rom.operator, dim, dim),
                            'rhs':      project_to_subbasis(rom.rhs, dim, None),
                            'products': {k: project_to_subbasis(v, dim, dim) for k, v in rom.products.items()},
                            'outputs':  {k: project_to_subbasis(v, None, dim) for k, v in rom.outputs.items()}}
     return projected_operators
Пример #5
0
 def project_operators_to_subbasis(self, dims):
     rom = self._last_rom
     dim = dims['RB']
     projected_operators = {'operator': project_to_subbasis(rom.operator, dim, dim),
                            'rhs':      project_to_subbasis(rom.rhs, dim, None),
                            'products': {k: project_to_subbasis(v, dim, dim) for k, v in rom.products.items()},
                            'outputs':  {k: project_to_subbasis(v, None, dim) for k, v in rom.outputs.items()}}
     return projected_operators
Пример #6
0
 def projected_to_subbasis(self,
                           dim_range=None,
                           dim_source=None,
                           name=None):
     return ImplicitEulerResidualOperator(
         project_to_subbasis(self.operator, dim_range, dim_source),
         project_to_subbasis(self.mass, dim_range, dim_source),
         project_to_subbasis(self.rhs, dim_range, None),
         self.dt,
         name=name)
Пример #7
0
 def project_operators_to_subbasis(self, dims):
     if dims['W'] != dims['V']:
         raise ValueError
     rom = self._last_rom
     dim = dims['V']
     projected_operators = {'A': project_to_subbasis(rom.A, dim, dim),
                            'B': project_to_subbasis(rom.B, dim, None),
                            'C': project_to_subbasis(rom.C, None, dim),
                            'D': rom.D,
                            'E': None if self.E_biorthonormal else project_to_subbasis(rom.E, dim, dim)}
     return projected_operators
Пример #8
0
 def project_operators_to_subbasis(self, dims):
     if dims['W'] != dims['V']:
         raise ValueError
     rom = self._last_rom
     dim = dims['V']
     projected_operators = {'A': project_to_subbasis(rom.A, dim, dim),
                            'B': project_to_subbasis(rom.B, dim, None),
                            'C': project_to_subbasis(rom.C, None, dim),
                            'D': rom.D,
                            'E': None if self.E_biorthonormal else project_to_subbasis(rom.E, dim, dim)}
     return projected_operators
Пример #9
0
    def project_operators_to_subbasis(self, dims):
        rom = self._last_rom
        dim = dims['RB']
        product = self.products['RB']

        if self.initial_data_product != product:
            # TODO there should be functionality for this somewhere else
            pop = project_to_subbasis(rom.initial_data.operators[1], dim_range=dim, dim_source=None)
            inverse_projection_op = InverseOperator(
                project_to_subbasis(rom.initial_data.operators[0].operator, dim_range=dim, dim_source=dim),
                name='inverse_projection_op'
            )
            projected_initial_data = ConcatenationOperator([inverse_projection_op, pop])
        else:
            projected_initial_data = project_to_subbasis(rom.initial_data, dim_range=dim, dim_source=None)

        projected_operators = {
            'mass':              project_to_subbasis(rom.mass, dim, dim),
            'operator':          project_to_subbasis(rom.operator, dim, dim),
            'rhs':               project_to_subbasis(rom.rhs, dim, None),
            'initial_data':      projected_initial_data,
            'products':          {k: project_to_subbasis(v, dim, dim) for k, v in rom.products.items()},
            'output_functional': (project_to_subbasis(rom.output_functional, None, dim)
                                  if rom.output_functional else None)
        }
        return projected_operators
Пример #10
0
def test_project_to_subbasis(operator_with_arrays):
    op, mu, U, V = operator_with_arrays
    op_UV = project(op, V, U)
    np.random.seed(4711 + U.dim + len(V))

    for dim_range in {None, 0, len(V) // 2, len(V)}:
        for dim_source in {None, 0, len(U) // 2, len(U)}:
            op_UV_sb = project_to_subbasis(op_UV, dim_range, dim_source)

            assert op_UV_sb.range.dim == (op_UV.range.dim
                                          if dim_range is None else dim_range)
            assert op_UV_sb.source.dim == (op_UV.source.dim if
                                           dim_source is None else dim_source)

            range_basis = V if dim_range is None else V[:dim_range]
            source_basis = U if dim_source is None else U[:dim_source]

            op_UV_sb2 = project(op, range_basis, source_basis)

            u = op_UV_sb2.source.make_array(np.random.random(
                len(source_basis)))

            assert np.all(
                almost_equal(op_UV_sb.apply(u, mu=mu), op_UV_sb2.apply(u,
                                                                       mu=mu)))
Пример #11
0
def test_project_to_subbasis_no_source_basis(operator_with_arrays):
    op, mu, U, V = operator_with_arrays
    op_V = project(op, V, None)
    np.random.seed(4711 + U.dim + len(V))

    for dim_range in {None, 0, len(V) // 2, len(V)}:
        op_V_sb = project_to_subbasis(op_V, dim_range, None)

        assert op_V_sb.range.dim == (op_V.range.dim
                                     if dim_range is None else dim_range)
        assert op_V_sb.source == op_V.source

        range_basis = V if dim_range is None else V[:dim_range]

        op_V_sb2 = project(op, range_basis, None)

        assert np.all(
            almost_equal(op_V_sb.apply(U, mu=mu), op_V_sb2.apply(U, mu=mu)))
Пример #12
0
    def project_operators_to_subbasis(self, dims):
        rom = self._last_rom
        dim = dims['RB']
        product = self.products['RB']

        if self.initial_data_product != product:
            # TODO there should be functionality for this somewhere else
            pop = project_to_subbasis(rom.initial_data.operators[1], dim_range=dim, dim_source=None)
            inverse_projection_op = InverseOperator(
                project_to_subbasis(rom.initial_data.operators[0].operator, dim_range=dim, dim_source=dim),
                name='inverse_projection_op'
            )
            projected_initial_data = Concatenation([inverse_projection_op, pop])
        else:
            projected_initial_data = project_to_subbasis(rom.initial_data, dim_range=dim, dim_source=None)

        projected_operators = {'mass':     (None if rom.mass is None or self.product_is_mass else
                                            project_to_subbasis(rom.mass, dim, dim)),
                               'operator': project_to_subbasis(rom.operator, dim, dim),
                               'rhs':      project_to_subbasis(rom.rhs, dim, None) if rom.rhs is not None else None,
                               'initial_data': projected_initial_data,
                               'products': {k: project_to_subbasis(v, dim, dim) for k, v in rom.products.items()},
                               'outputs':  {k: project_to_subbasis(v, None, dim) for k, v in rom.outputs.items()}}
        return projected_operators
Пример #13
0
 def projected_to_subbasis(self, dim_range=None, dim_source=None, name=None):
     return self.with_(operator=project_to_subbasis(self.operator, None, dim_source),
                       mass=project_to_subbasis(self.mass, None, dim_source))
Пример #14
0
 def projected_to_subbasis(self, dim_range=None, dim_source=None, name=None):
     return ImplicitEulerResidualOperator(project_to_subbasis(self.operator, dim_range, dim_source),
                                          project_to_subbasis(self.mass, dim_range, dim_source),
                                          project_to_subbasis(self.rhs, dim_range, None),
                                          self.dt,
                                          name=name)
Пример #15
0
 def projected_to_subbasis(self, dim_range=None, dim_source=None, name=None):
     return ResidualOperator(project_to_subbasis(self.operator, dim_range, dim_source),
                             project_to_subbasis(self.rhs, dim_range, None),
                             name=name)
Пример #16
0
 def project_operator(op):
     return project_to_subbasis(
         op,
         dim_range=dim if op.range == rd.solution_space else None,
         dim_source=dim if op.source == rd.solution_space else None)
Пример #17
0
 def project_operator(op):
     return project_to_subbasis(op,
                                dim_range=dim if op.range == rd.solution_space else None,
                                dim_source=dim if op.source == rd.solution_space else None)