pymor.operators.interface
¶
Module Contents¶
- class pymor.operators.interface.Operator[source]¶
Bases:
pymor.parameters.base.ParametricObject
Interface for
Parameter
dependent discrete operators.An operator in pyMOR is simply a mapping which for any given
parameter values
maps vectors from itssource
VectorSpace
to vectors in itsrange
VectorSpace
.Note that there is no special distinction between functionals and operators in pyMOR. A functional is simply an operator with
NumpyVectorSpace
(1)
as itsrange
VectorSpace
.- source[source]¶
The source
VectorSpace
.
- range[source]¶
The range
VectorSpace
.
Methods
Try to assemble a linear combination of the given operators.
Apply the operator to a
VectorArray
.Treat the operator as a 2-form and apply it to V and U.
Apply the adjoint operator.
Apply the inverse operator.
Apply the inverse adjoint operator.
Return a
VectorArray
representation of the operator in its range space.Return a
VectorArray
representation of the operator in its source space.Return a vector representation of a linear functional or vector operator.
Assemble the operator for given
parameter values
.Return the operator's derivative with respect to a given parameter.
Return the operator's Jacobian as a new
Operator
.Treat the operator as a 2-form and apply it to V and U in pairs.
Restrict the operator range to a given set of degrees of freedom.
- _assemble_lincomb(operators, coefficients, identity_shift=0.0, name=None)[source]¶
Try to assemble a linear combination of the given operators.
Returns a new
Operator
which represents the sumc_1*O_1 + ... + c_N*O_N + s*I
where
O_i
areOperators
,c_i
,s
scalar coefficients andI
the identity.This method is called in the
assemble
method ofLincombOperator
on the first of its operators. If an assembly of the given linear combination is possible, e.g. the linear combination of the system matrices of the operators can be formed, then the assembled operator is returned. Otherwise, the method returnsNone
to indicate that assembly is not possible.
- abstract apply(U, mu=None)[source]¶
Apply the operator to a
VectorArray
.- Parameters:
U –
VectorArray
of vectors to which the operator is applied.mu – The
parameter values
for which to evaluate the operator.
- Returns:
|VectorArray| of the operator evaluations.
- apply2(V, U, mu=None)[source]¶
Treat the operator as a 2-form and apply it to V and U.
This method is usually implemented as
V.inner(self.apply(U))
. In particular, if the operator is a linear operator given by multiplication with a matrix M, thenapply2
is given as:op.apply2(V, U) = V^T*M*U.
In the case of complex numbers, note that
apply2
is anti-linear in the first variable by definition ofinner
.- Parameters:
V –
VectorArray
of the left arguments V.U –
VectorArray
of the right arguments U.mu – The
parameter values
for which to evaluate the operator.
- Returns:
A
NumPy array
with shape(len(V), len(U))
containing the 2-formevaluations.
- apply_adjoint(V, mu=None)[source]¶
Apply the adjoint operator.
For any given linear
Operator
op
,parameter values
mu
andVectorArrays
U
,V
in thesource
resp.range
we have:op.apply_adjoint(V, mu).dot(U) == V.inner(op.apply(U, mu))
Thus, when
op
is represented by a matrixM
,apply_adjoint
is given by left-multiplication of (the complex conjugate of)M
withV
.- Parameters:
V –
VectorArray
of vectors to which the adjoint operator is applied.mu – The
parameter values
for which to apply the adjoint operator.
- Returns:
|VectorArray| of the adjoint operator evaluations.
- apply_inverse(V, mu=None, initial_guess=None, return_info=False, solver=None)[source]¶
Apply the inverse operator.
- Parameters:
V –
VectorArray
of vectors to which the inverse operator is applied.mu – The
parameter values
for which to evaluate the inverse operator.initial_guess –
VectorArray
with the same length asV
containing initial guesses for the solution. Some implementations ofapply_inverse
may ignore this parameter. IfNone
a solver-dependent default is used.return_info – If
True
, return a dict with additional information on the solution process (runtime, iterations, residuals, etc.) as a second return value.solver – If not
None
, use thisSolver
for computing the solution.
- Returns:
U –
VectorArray
containing the inverse operator evaluations.info – Dict with additional information. Only returned when
return_info
isTrue
.
- Raises:
InversionError – The operator could not be inverted.
- apply_inverse_adjoint(U, mu=None, initial_guess=None, return_info=False, solver=None)[source]¶
Apply the inverse adjoint operator.
- Parameters:
U –
VectorArray
of vectors to which the inverse adjoint operator is applied.mu – The
parameter values
for which to evaluate the inverse adjoint operator.initial_guess –
VectorArray
with the same length asU
containing initial guesses for the solution. Some implementations ofapply_inverse_adjoint
may ignore this parameter. IfNone
a solver-dependent default is used.return_info – If
True
, return a dict with additional information on the solution process (runtime, iterations, residuals, etc.) as a second return value.solver – If not
None
, use thisSolver
for computing the solution.
- Returns:
V –
VectorArray
containing the inverse adjoint operator evaluations.info – Dict with additional information. Only returned when
return_info
isTrue
.
- Raises:
InversionError – The operator could not be inverted.
- as_range_array(mu=None)[source]¶
Return a
VectorArray
representation of the operator in its range space.In the case of a linear operator with
NumpyVectorSpace
assource
, this method returns for givenparameter values
mu
aVectorArray
V
in the operator’srange
, such thatV.lincomb(U.to_numpy()) == self.apply(U, mu)
for all
VectorArrays
U
.- Parameters:
mu – The
parameter values
for which to return theVectorArray
representation.- Returns:
V – The
VectorArray
defined above.
- as_source_array(mu=None)[source]¶
Return a
VectorArray
representation of the operator in its source space.In the case of a linear operator with
NumpyVectorSpace
asrange
, this method returns for givenparameter values
mu
aVectorArray
V
in the operator’ssource
, such thatself.range.make_array(V.inner(U)) == self.apply(U, mu)
for all
VectorArrays
U
.- Parameters:
mu – The
parameter values
for which to return theVectorArray
representation.- Returns:
V – The
VectorArray
defined above.
- as_vector(mu=None)[source]¶
Return a vector representation of a linear functional or vector operator.
Depending on the operator’s
source
andrange
, this method is equivalent to callingas_range_array
oras_source_array
respectively. The resultingVectorArray
is required to have length 1.- Parameters:
mu – The
parameter values
for which to return the vector representation.- Returns:
V –
VectorArray
of length 1 containing the vector representation.
- assemble(mu=None)[source]¶
Assemble the operator for given
parameter values
.The result of the method strongly depends on the given operator. For instance, a matrix-based operator will assemble its matrix, a
LincombOperator
will try to form the linear combination of its operators, whereas an arbitrary operator might simply return aFixedParameterOperator
. The only assured property of the assembled operator is that it no longer depends on aParameter
.If the operator has a
Solver
, the assembledOperator
will be equipped with the sameSolver
.- Parameters:
mu – The
parameter values
for which to assemble the operator.- Returns:
Parameter-independent, assembled |Operator|.
- d_mu(parameter, index=0)[source]¶
Return the operator’s derivative with respect to a given parameter.
If the operator has a
Solver
, the derivativeOperator
will be equipped with the sameSolver
.- Parameters:
parameter – The parameter w.r.t. which to return the derivative.
index – Index of the parameter’s component w.r.t which to return the derivative.
- Returns:
New |Operator| representing the partial derivative.
- jacobian(U, mu=None)[source]¶
Return the operator’s Jacobian as a new
Operator
.If the operator has a
Solver
, the JacobianOperator
will be equipped with the solver’sjacobian_solver
.- Parameters:
U – Length 1
VectorArray
containing the vector for which to compute the Jacobian.mu – The
parameter values
for which to compute the Jacobian.
- Returns:
Linear |Operator| representing the Jacobian.
- pairwise_apply2(V, U, mu=None)[source]¶
Treat the operator as a 2-form and apply it to V and U in pairs.
This method is usually implemented as
V.pairwise_inner(self.apply(U))
. In particular, if the operator is a linear operator given by multiplication with a matrix M, thenapply2
is given as:op.apply2(V, U)[i] = V[i]^T*M*U[i].
In the case of complex numbers, note that
pairwise_apply2
is anti-linear in the first variable by definition ofpairwise_inner
.- Parameters:
V –
VectorArray
of the left arguments V.U –
VectorArray
of the right arguments U.mu – The
parameter values
for which to evaluate the operator.
- Returns:
A
NumPy array
with shape(len(V),) == (len(U),)
containingthe 2-form evaluations.
- abstract restricted(dofs)[source]¶
Restrict the operator range to a given set of degrees of freedom.
This method returns a restricted version
restricted_op
of the operator along with an arraysource_dofs
such that for anyVectorArray
U
inself.source
the following is true:self.apply(U, mu).dofs(dofs) == restricted_op.apply(restricted_op.source.from_numpy(U.dofs(source_dofs)) mu).to_numpy()
Such an operator is mainly useful for
empirical interpolation
where the evaluation of the original operator only needs to be known for few selected degrees of freedom. If the operator has a small stencil, only fewsource_dofs
will be needed to evaluate the restricted operator which can make its evaluation very fast compared to evaluating the original operator.- Parameters:
dofs – One-dimensional
NumPy array
of degrees of freedom in the operatorrange
to which to restrict.- Returns:
restricted_op – The restricted operator as defined above. The operator will have
NumpyVectorSpace
(len(source_dofs))
assource
andNumpyVectorSpace
(len(dofs))
asrange
.source_dofs – One-dimensional
NumPy array
of source degrees of freedom as defined above.