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
def project_operators(self): fom = self.fom RB = self.bases['RB'] product = self.products['RB'] if self.initial_data_product != product: # TODO there should be functionality for this somewhere else projection_matrix = RB.gramian(self.initial_data_product) projection_op = NumpyMatrixOperator(projection_matrix) inverse_projection_op = InverseOperator(projection_op, 'inverse_projection_op') pid = project(fom.initial_data, range_basis=RB, source_basis=None, product=self.initial_data_product) projected_initial_data = ConcatenationOperator([inverse_projection_op, pid]) else: projected_initial_data = project(fom.initial_data, range_basis=RB, source_basis=None, product=product) projected_operators = { 'mass': (None if (isinstance(fom.mass, IdentityOperator) and product is None or self.product_is_mass) else project(fom.mass, RB, RB)), 'operator': project(fom.operator, RB, RB), 'rhs': project(fom.rhs, RB, None), 'initial_data': projected_initial_data, 'products': {k: project(v, RB, RB) for k, v in fom.products.items()}, 'output_functional': project(fom.output_functional, None, RB) if fom.output_functional else None } return projected_operators
def test_InverseOperator(operator_with_arrays): op, mu, U, V = operator_with_arrays inv = InverseOperator(op) try: assert np.all(almost_equal(inv.apply(V, mu=mu), op.apply_inverse(V, mu=mu))) except InversionError: pass try: assert np.all(almost_equal(inv.apply_inverse(U, mu=mu), op.apply(U, mu=mu))) except InversionError: pass if op.linear: try: assert np.all(almost_equal(inv.apply_transpose(U, mu=mu), op.apply_inverse_transpose(U, mu=mu))) except (InversionError, NotImplementedError): pass try: assert np.all(almost_equal(inv.apply_inverse_transpose(V, mu=mu), op.apply_transpose(V, mu=mu))) except (InversionError, NotImplementedError): pass
def test_InverseOperator(operator_with_arrays): op, mu, U, V = operator_with_arrays inv = InverseOperator(op) rtol = atol = 1e-12 try: assert np.all(almost_equal(inv.apply(V, mu=mu), op.apply_inverse(V, mu=mu), rtol=rtol, atol=atol)) except InversionError: pass try: assert np.all(almost_equal(inv.apply_inverse(U, mu=mu), op.apply(U, mu=mu), rtol=rtol, atol=atol)) except InversionError: pass if op.linear: try: assert np.all(almost_equal(inv.apply_adjoint(U, mu=mu), op.apply_inverse_adjoint(U, mu=mu), rtol=rtol, atol=atol)) except (InversionError, NotImplementedError): pass try: assert np.all(almost_equal(inv.apply_inverse_adjoint(V, mu=mu), op.apply_adjoint(V, mu=mu), rtol=rtol, atol=atol)) except (InversionError, LinAlgError, NotImplementedError): pass