Beispiel #1
0
 def action_apply_basis(self, op):
     range_basis, source_basis = self.range_basis, self.source_basis
     if source_basis is None:
         try:
             V = op.apply_adjoint(range_basis)
         except NotImplementedError:
             raise RuleNotMatchingError('apply_adjoint not implemented')
         if isinstance(op.source, NumpyVectorSpace):
             from pymor.operators.numpy import NumpyMatrixOperator
             return NumpyMatrixOperator(V.to_numpy(),
                                        source_id=op.source.id,
                                        name=op.name)
         else:
             from pymor.operators.constructions import VectorArrayOperator
             return VectorArrayOperator(V, adjoint=True, name=op.name)
     else:
         if range_basis is None:
             V = op.apply(source_basis)
             if isinstance(op.range, NumpyVectorSpace):
                 from pymor.operators.numpy import NumpyMatrixOperator
                 return NumpyMatrixOperator(V.to_numpy().T,
                                            range_id=op.range.id,
                                            name=op.name)
             else:
                 from pymor.operators.constructions import VectorArrayOperator
                 return VectorArrayOperator(V, adjoint=False, name=op.name)
         else:
             from pymor.operators.numpy import NumpyMatrixOperator
             return NumpyMatrixOperator(op.apply2(range_basis,
                                                  source_basis),
                                        name=op.name)
Beispiel #2
0
    def action_EmpiricalInterpolatedOperator(self,
                                             op,
                                             range_basis,
                                             source_basis,
                                             product=None):
        if len(op.interpolation_dofs) == 0:
            return self.apply(ZeroOperator(op.source, op.range, op.name),
                              range_basis, source_basis, product)
        elif not hasattr(op, 'restricted_operator') or source_basis is None:
            raise RuleNotMatchingError(
                'Has no restricted operator or source_basis is None')
        else:
            if range_basis is not None:
                if product is None:
                    projected_collateral_basis = NumpyVectorSpace.make_array(
                        op.collateral_basis.dot(range_basis), op.range.id)
                else:
                    projected_collateral_basis = NumpyVectorSpace.make_array(
                        product.apply2(op.collateral_basis, range_basis),
                        op.range.id)
            else:
                projected_collateral_basis = op.collateral_basis

            return ProjectedEmpiciralInterpolatedOperator(
                op.restricted_operator, op.interpolation_matrix,
                NumpyVectorSpace.make_array(
                    source_basis.components(op.source_dofs)),
                projected_collateral_basis, op.triangular, op.source.id, None,
                op.name)
Beispiel #3
0
 def action_IdentityOperator(self, op):
     dim_range, dim_source = self.dim_range, self.dim_source
     if dim_range != dim_source:
         raise RuleNotMatchingError(
             'dim_range and dim_source must be equal.')
     space = op.source if dim_source is None else NumpyVectorSpace(
         dim_source)
     return IdentityOperator(space, name=op.name)
Beispiel #4
0
 def action_apply_basis(self, op):
     range_basis, source_basis, product = self.range_basis, self.source_basis, self.product
     if source_basis is None:
         if range_basis is None:
             return op
         else:
             try:
                 V = op.apply_transpose(
                     product.apply(range_basis) if product else range_basis)
             except NotImplementedError:
                 raise RuleNotMatchingError(
                     'apply_transpose not implemented')
             if isinstance(op.source, NumpyVectorSpace):
                 from pymor.operators.numpy import NumpyMatrixOperator
                 return NumpyMatrixOperator(V.data,
                                            source_id=op.source.id,
                                            range_id=op.range.id,
                                            name=op.name)
             else:
                 from pymor.operators.constructions import VectorArrayOperator
                 return VectorArrayOperator(V,
                                            transposed=True,
                                            space_id=op.range.id,
                                            name=op.name)
     else:
         if range_basis is None:
             V = op.apply(source_basis)
             if isinstance(op.range, NumpyVectorSpace):
                 from pymor.operators.numpy import NumpyMatrixOperator
                 return NumpyMatrixOperator(V.data.T,
                                            source_id=op.source.id,
                                            range_id=op.range.id,
                                            name=op.name)
             else:
                 from pymor.operators.constructions import VectorArrayOperator
                 return VectorArrayOperator(V,
                                            transposed=False,
                                            space_id=op.source.id,
                                            name=op.name)
         elif product is None:
             from pymor.operators.numpy import NumpyMatrixOperator
             return NumpyMatrixOperator(op.apply2(range_basis,
                                                  source_basis),
                                        source_id=op.source.id,
                                        range_id=op.range.id,
                                        name=op.name)
         else:
             from pymor.operators.numpy import NumpyMatrixOperator
             V = op.apply(source_basis)
             return NumpyMatrixOperator(product.apply2(range_basis, V),
                                        source_id=op.source.id,
                                        range_id=op.range.id,
                                        name=op.name)