pymor.operators.mpi¶
Module Contents¶
- class pymor.operators.mpi.MPIOperator(obj_id, mpi_range, mpi_source, with_apply2=False, pickle_local_spaces=True, space_type=MPIVectorSpace, solver=None, name=None)[source]¶
Bases:
pymor.operators.interface.OperatorMPI distributed
Operator.Given a single-rank implementation of an
Operator, this wrapper class uses the event loop frompymor.tools.mpito allow an MPI distributed usage of theOperator.Instances of
MPIOperatorcan be used on rank 0 like any other (non-distributed)Operator.Note, however, that the underlying
Operatorimplementation needs to be MPI aware. For instance, the operator’sapplymethod has to perform the necessary MPI communication to obtain all DOFs hosted on other MPI ranks which are required for the local operator evaluation.Instead of instantiating
MPIOperatordirectly, it is usually preferable to usempi_wrap_operatorinstead.- Parameters:
mpi_range – Set to
Trueif the range of theOperatoris MPI distributed.mpi_source – Set to
Trueif the source of theOperatoris MPI distributed.with_apply2 – Set to
Trueif the operator implementation has its own MPI aware implementation ofapply2andpairwise_apply2. Otherwise, the default implementations usingapplyandinnerwill be used.pickle_local_spaces – If
pickle_local_spacesisFalse, a unique identifier is computed for each local source/rangeVectorSpace, which is then transferred to rank 0 instead of the trueVectorSpace. This allows the usage ofMPIVectorArrayeven when the localVectorSpacesare not picklable.space_type – This class will be used to wrap the local
VectorArraysreturned by the local operators into an MPI distributedVectorArraymanaged from rank 0. By default,MPIVectorSpacewill be used, other options areMPIVectorSpaceAutoCommandMPIVectorSpaceNoComm.
Methods
Apply the operator to a
VectorArray.Treat the operator as a 2-form and apply it to V and U.
Apply the adjoint operator.
Return a
VectorArrayrepresentation of the operator in its range space.Return a
VectorArrayrepresentation of the operator in its source space.Assemble the operator for given
parameter values.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.
- 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.
- 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.
- 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.If the operator has a
Solver, the assembledOperatorwill be equipped with the sameSolver.- Parameters:
mu – The
parameter valuesfor which to assemble the operator.- Returns:
Parameter-independent, assembled |Operator|.
- jacobian(U, mu=None)[source]¶
Return the operator’s Jacobian as a new
Operator.If the operator has a
Solver, the JacobianOperatorwill be equipped with the solver’sjacobian_solver.- 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.
- 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.
- pymor.operators.mpi.mpi_wrap_operator(obj_id, mpi_range, mpi_source, with_apply2=False, pickle_local_spaces=True, space_type=MPIVectorSpace)[source]¶
Wrap MPI distributed local
Operatorsto a globalOperatoron rank 0.Given MPI distributed local
Operatorsreferred to by theObjectIdobj_id, return a newOperatorwhich manages these distributed operators from rank 0. This is done by instantiatingMPIOperator. Additionally, the structure of the wrapped operators is preserved. E.g.LincombOperatorswill be wrapped as aLincombOperatorofMPIOperators.:param See
MPIOperator.:- Returns:
The wrapped |Operator|.