pymor.bindings.fenics
¶
Module Contents¶
- class pymor.bindings.fenics.ComplexifiedFenicsVector(real_part, imag_part)[source]¶
Bases:
pymor.vectorarrays.list.ComplexifiedVector
Interface for vectors used in conjunction with
ListVectorArray
.This interface must be satisfied by the individual entries of the vector
list
managed byListVectorArray
. All interface methods have a direct counterpart in theVectorArray
interface.Methods
- class pymor.bindings.fenics.FenicsMatrixBasedOperator(form, params, bc=None, bc_zero=False, functional=False, solver_options=None, name=None)[source]¶
Bases:
pymor.operators.interface.Operator
Wraps a parameterized FEniCS linear or bilinear form as an
Operator
.Parameters
- form
The
Form
object which is assembled to a matrix or vector.- params
Dict mapping parameters to dolfin
Constants
as returned byto_fenics
.- bc
dolfin
DirichletBC
object to be applied.- bc_zero
If
True
also clear the diagonal entries of Dirichlet dofs.- functional
If
True
return aVectorFunctional
instead of aVectorOperator
in caseform
is a linear form.- solver_options
The
solver_options
for the assembledFenicsMatrixOperator
.- name
Name of the operator.
Methods
Apply the operator to a
VectorArray
.Apply the adjoint operator.
Apply the inverse operator.
Return a
VectorArray
representation of the operator in its range space.Return a
VectorArray
representation of the operator in its source space.Assemble the operator for given
parameter values
.- 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.
- 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, least_squares=False)[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.- 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_options
are 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.
- 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).T) == 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.
- 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
.Parameters
- mu
The
parameter values
for which to assemble the operator.
Returns
Parameter-independent, assembled
Operator
.
- class pymor.bindings.fenics.FenicsMatrixOperator(matrix, source_space, range_space, solver_options=None, name=None)[source]¶
Bases:
pymor.operators.list.LinearComplexifiedListVectorArrayOperatorBase
Wraps a FEniCS matrix as an
Operator
.
- class pymor.bindings.fenics.FenicsOperator(form, source_space, range_space, source_function, dirichlet_bcs=(), parameter_setter=None, parameters={}, solver_options=None, name=None)[source]¶
Bases:
pymor.operators.interface.Operator
Wraps a FEniCS form as an
Operator
.Methods
Apply the operator to a
VectorArray
.Return the operator's Jacobian as a new
Operator
.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
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.
- jacobian(U, mu=None)[source]¶
Return the operator’s Jacobian as a new
Operator
.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.
- 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(NumpyVectorArray(U.dofs(source_dofs)), mu))
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.
- class pymor.bindings.fenics.FenicsVector(impl)[source]¶
Bases:
pymor.vectorarrays.list.CopyOnWriteVector
Wraps a FEniCS vector to make it usable with ListVectorArray.
- class pymor.bindings.fenics.FenicsVectorSpace(V, id='STATE')[source]¶
Bases:
pymor.vectorarrays.list.ComplexifiedListVectorSpace
VectorSpace
ofListVectorArrays
.Methods
- class pymor.bindings.fenics.FenicsVisualizer(space, mesh_refinements=0)[source]¶
Bases:
pymor.core.base.ImmutableObject
Visualize a FEniCS grid function.
Parameters
- space
The
FenicsVectorSpace
for which we want to visualize DOF vectors.- mesh_refinements
Number of uniform mesh refinements to perform for vtk visualization (of functions from higher-order FE spaces).
Methods
Visualize the provided data.
- visualize(U, title='', legend=None, filename=None, block=True, separate_colorbars=True)[source]¶
Visualize the provided data.
Parameters
- U
VectorArray
of the data to visualize (length must be 1). Alternatively, a tuple ofVectorArrays
which will be visualized in separate windows. Iffilename
is specified, only oneVectorArray
may be provided which, however, is allowed to contain multiple vectors that will be interpreted as a time series.- title
Title of the plot.
- legend
Description of the data that is plotted. If
U
is a tuple ofVectorArrays
,legend
has to be a tuple of the same length.- filename
If specified, write the data to that file.
filename
needs to have an extension supported by FEniCS (e.g..pvd
).- separate_colorbars
If
True
, use separate colorbars for each subplot.- block
If
True
, block execution until the plot window is closed.
- class pymor.bindings.fenics.RestrictedFenicsOperator(op, restricted_range_dofs)[source]¶
Bases:
pymor.operators.interface.Operator
Restricted
FenicsOperator
.Methods
Apply the operator to a
VectorArray
.Return the operator's Jacobian as a new
Operator
.- 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.
- jacobian(U, mu=None)[source]¶
Return the operator’s Jacobian as a new
Operator
.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.