Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[operators] add ProxyOperator #365

Merged
merged 2 commits into from
Apr 10, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 47 additions & 12 deletions src/pymor/operators/constructions.py
Original file line number Diff line number Diff line change
Expand Up @@ -700,33 +700,71 @@ def __init__(self, vector, product=None, name=None):
super().__init__(product.apply(vector), transposed=True, name=name)


class FixedParameterOperator(OperatorBase):
"""Makes an |Operator| |Parameter|-independent by setting a fixed |Parameter|.
class ProxyOperator(OperatorBase):
"""Forwards all interface calls to given |Operator|.

Mainly useful as base class for other |Operator| implementations.

Parameters
----------
operator
The |Operator| to wrap.
mu
The fixed |Parameter| that will be fed to the
:meth:`~pymor.operators.interfaces.OperatorInterface.apply` method
of `operator`.
name
Name of the wrapping operator.
"""

def __init__(self, operator, mu=None, name=None):
def __init__(self, operator, name=None):
assert isinstance(operator, OperatorInterface)
assert operator.parse_parameter(mu) or True
self.source = operator.source
self.range = operator.range
self.operator = operator
self.mu = mu.copy()
self.linear = operator.linear
self.name = name
self.build_parameter_type(operator)

@property
def T(self):
return self.with_(operator=self.operator.T, name=self.name + '_transposed')

def apply(self, U, mu=None):
return self.operator.apply(U, mu=mu)

def apply_transpose(self, V, mu=None):
return self.operator.apply_transpose(V, mu=mu)

def apply_inverse(self, V, mu=None, least_squares=False):
return self.operator.apply_inverse(V, mu=mu, least_squares=least_squares)

def apply_inverse_transpose(self, U, mu=None, least_squares=False):
return self.operator.apply_inverse_transpose(U, mu=mu, least_squares=least_squares)

def jacobian(self, U, mu=None):
return self.operator.jacobian(U, mu=mu)

def restricted(self, dofs):
op, source_dofs = self.operator.restricted(dofs)
return self.with_(operator=op), source_dofs


class FixedParameterOperator(ProxyOperator):
"""Makes an |Operator| |Parameter|-independent by setting a fixed |Parameter|.

Parameters
----------
operator
The |Operator| to wrap.
mu
The fixed |Parameter| that will be fed to the
:meth:`~pymor.operators.interfaces.OperatorInterface.apply` method
of `operator`.
"""

def __init__(self, operator, mu=None, name=None):
super().__init__(operator, name)
assert operator.parse_parameter(mu) or True
self.mu = mu.copy()
self.build_parameter_type()

def apply(self, U, mu=None):
return self.operator.apply(U, mu=self.mu)

Expand All @@ -742,9 +780,6 @@ def apply_inverse_transpose(self, U, mu=None, least_squares=False):
def jacobian(self, U, mu=None):
return self.operator.jacobian(U, mu=self.mu)

def restricted(self, dofs):
op, source_dofs = self.operator.restricted(dofs)
return self.with_(operator=op), source_dofs


class InverseOperator(OperatorBase):
Expand Down
3 changes: 3 additions & 0 deletions src/pymor/vectorarrays/block.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ def __eq__(self, other):
len(self.subspaces) == len(other.subspaces) and
all(space == other_space for space, other_space in zip(self.subspaces, other.subspaces)))

def __hash__(self):
return sum(hash(s) for s in self.subspaces) + hash(self.id)

@property
def dim(self):
return sum(subspace.dim for subspace in self.subspaces)
Expand Down