pymor.operators.interface¶
Module Contents¶
- class pymor.operators.interface.Operator[source]¶
Bases:
pymor.parameters.base.ParametricObjectInterface for
Parameterdependent discrete operators.An operator in pyMOR is simply a mapping which for any given
parameter valuesmaps vectors from itssourceVectorSpaceto vectors in itsrangeVectorSpace.Note that there is no special distinction between functionals and operators in pyMOR. A functional is simply an operator with
NumpyVectorSpace(1)as itsrangeVectorSpace.- solver_options[source]¶
If not
None, a dict which can contain the following keys:- ‘inverse’:
solver options used for
apply_inverse- ‘inverse_adjoint’:
solver options used for
apply_inverse_adjoint- ‘jacobian’:
solver options for the operators returned by
jacobian(has no effect for linear operators)
If
solver_optionsisNoneor a dict entry is missing orNone, default options are used. The interpretation of the given solver options is up to the operator at hand. In general, values insolver_optionsshould either be strings (indicating a solver type) or dicts of options, usually with an entry'type'which specifies the solver type to use and further items which configure this solver.
- source[source]¶
The source
VectorSpace.
- range[source]¶
The range
VectorSpace.
- H[source]¶
The adjoint operator, i.e.
self.H.apply(V, mu) == self.apply_adjoint(V, mu)
for all V, mu.
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
VectorArrayrepresentation of the operator in its range space.Return a
VectorArrayrepresentation 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, solver_options=None, name=None)[source]¶
Try to assemble a linear combination of the given operators.
Returns a new
Operatorwhich represents the sumc_1*O_1 + ... + c_N*O_N + s*I
where
O_iareOperators,c_i,sscalar coefficients andIthe identity.This method is called in the
assemblemethod ofLincombOperatoron 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 returnsNoneto indicate that assembly is not possible.- Parameters:
operators – List of
OperatorsO_iwhose linear combination is formed.coefficients – List of the corresponding linear coefficients
c_i.identity_shift – The coefficient
s.solver_options –
solver_optionsfor the assembled operator.name – Name of the assembled operator.
- Returns:
The assembled
Operatorif assembly is possible, otherwiseNone.
- abstract apply(U, mu=None)[source]¶
Apply the operator to a
VectorArray.- Parameters:
U –
VectorArrayof vectors to which the operator is applied.mu – The
parameter valuesfor 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, thenapply2is given as:op.apply2(V, U) = V^T*M*U.
In the case of complex numbers, note that
apply2is anti-linear in the first variable by definition ofinner.- Parameters:
V –
VectorArrayof the left arguments V.U –
VectorArrayof the right arguments U.mu – The
parameter valuesfor which to evaluate the operator.
- Returns:
A
NumPy arraywith shape(len(V), len(U))containing the 2-formevaluations.
- apply_adjoint(V, mu=None)[source]¶
Apply the adjoint operator.
For any given linear
Operatorop,parameter valuesmuandVectorArraysU,Vin thesourceresp.rangewe have:op.apply_adjoint(V, mu).dot(U) == V.inner(op.apply(U, mu))
Thus, when
opis represented by a matrixM,apply_adjointis given by left-multiplication of (the complex conjugate of)MwithV.- Parameters:
V –
VectorArrayof vectors to which the adjoint operator is applied.mu – The
parameter valuesfor which to apply the adjoint operator.
- Returns:
|VectorArray| of the adjoint operator evaluations.
- apply_inverse(V, mu=None, initial_guess=None, least_squares=False)[source]¶
Apply the inverse operator.
- Parameters:
V –
VectorArrayof vectors to which the inverse operator is applied.mu – The
parameter valuesfor which to evaluate the inverse operator.initial_guess –
VectorArraywith the same length asVcontaining initial guesses for the solution. Some implementations ofapply_inversemay ignore this parameter. IfNonea solver-dependent default is used.least_squares –
If
True, solve the least squares problem:u = argmin ||op(u) - v||_2.
Since for an invertible operator the least squares solution agrees with the result of the application of the inverse operator, setting this option should, in general, have no effect on the result for those operators. However, note that when no appropriate
solver_optionsare set for the operator, most implementations will choose a least squares solver by default which may be undesirable.
- Returns:
|VectorArray| of the inverse operator evaluations.
- Raises:
InversionError – The operator could not be inverted.
- apply_inverse_adjoint(U, mu=None, initial_guess=None, least_squares=False)[source]¶
Apply the inverse adjoint operator.
- Parameters:
U –
VectorArrayof vectors to which the inverse adjoint operator is applied.mu – The
parameter valuesfor which to evaluate the inverse adjoint operator.initial_guess –
VectorArraywith the same length asUcontaining initial guesses for the solution. Some implementations ofapply_inverse_adjointmay ignore this parameter. IfNonea solver-dependent default is used.least_squares –
If
True, solve the least squares problem:v = argmin ||op^*(v) - u||_2.
Since for an invertible operator the least squares solution agrees with the result of the application of the inverse operator, setting this option should, in general, have no effect on the result for those operators. However, note that when no appropriate
solver_optionsare set for the operator, most operator implementations will choose a least squares solver by default which may be undesirable.
- Returns:
|VectorArray| of the inverse adjoint operator evaluations.
- Raises:
InversionError – The operator could not be inverted.
- as_range_array(mu=None)[source]¶
Return a
VectorArrayrepresentation of the operator in its range space.In the case of a linear operator with
NumpyVectorSpaceassource, this method returns for givenparameter valuesmuaVectorArrayVin the operator’srange, such thatV.lincomb(U.to_numpy()) == self.apply(U, mu)
for all
VectorArraysU.- Parameters:
mu – The
parameter valuesfor which to return theVectorArrayrepresentation.- Returns:
V – The
VectorArraydefined above.
- as_source_array(mu=None)[source]¶
Return a
VectorArrayrepresentation of the operator in its source space.In the case of a linear operator with
NumpyVectorSpaceasrange, this method returns for givenparameter valuesmuaVectorArrayVin the operator’ssource, such thatself.range.make_array(V.inner(U)) == self.apply(U, mu)
for all
VectorArraysU.- Parameters:
mu – The
parameter valuesfor which to return theVectorArrayrepresentation.- Returns:
V – The
VectorArraydefined above.
- as_vector(mu=None)[source]¶
Return a vector representation of a linear functional or vector operator.
Depending on the operator’s
sourceandrange, this method is equivalent to callingas_range_arrayoras_source_arrayrespectively. The resultingVectorArrayis required to have length 1.- Parameters:
mu – The
parameter valuesfor which to return the vector representation.- Returns:
V –
VectorArrayof 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
LincombOperatorwill 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.- Parameters:
mu – The
parameter valuesfor 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.
- 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.- Parameters:
U – Length 1
VectorArraycontaining the vector for which to compute the Jacobian.mu – The
parameter valuesfor 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, thenapply2is given as:op.apply2(V, U)[i] = V[i]^T*M*U[i].
In the case of complex numbers, note that
pairwise_apply2is anti-linear in the first variable by definition ofpairwise_inner.- Parameters:
V –
VectorArrayof the left arguments V.U –
VectorArrayof the right arguments U.mu – The
parameter valuesfor which to evaluate the operator.
- Returns:
A
NumPy arraywith 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_opof the operator along with an arraysource_dofssuch that for anyVectorArrayUinself.sourcethe 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 interpolationwhere 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_dofswill 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 arrayof degrees of freedom in the operatorrangeto which to restrict.- Returns:
restricted_op – The restricted operator as defined above. The operator will have
NumpyVectorSpace(len(source_dofs))assourceandNumpyVectorSpace(len(dofs))asrange.source_dofs – One-dimensional
NumPy arrayof source degrees of freedom as defined above.