pymor.bindings.fenics

Classes

ComplexifiedFenicsVector

FenicsLinearSolver

FenicsMatrixBasedOperator

Wraps a parameterized FEniCS linear or bilinear form as an Operator.

FenicsMatrixOperator

Wraps a FEniCS matrix as an Operator.

FenicsOperator

Wraps a FEniCS form as an Operator.

FenicsVector

Wraps a FEniCS vector to make it usable with ListVectorArray.

FenicsVectorSpace

FenicsVisualizer

Visualize a FEniCS grid function.

RestrictedFenicsOperator

Restricted FenicsOperator.

Functions

compute_parent_facet_indices

class pymor.bindings.fenics.ComplexifiedFenicsVector(real_part, imag_part)[source]

Bases: ComplexifiedVector

amax()[source]
class pymor.bindings.fenics.FenicsLinearSolver(method='default', preconditioner=None, keep_solver=True)[source]

Bases: ComplexifiedListVectorArrayBasedSolver

class pymor.bindings.fenics.FenicsMatrixBasedOperator(form, params, bc=None, bc_zero=False, functional=False, solver=None, name=None)[source]

Bases: 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 by to_fenics.

  • bc – dolfin DirichletBC object to be applied.

  • bc_zero – If True also clear the diagonal entries of Dirichlet dofs.

  • functional – If True return a VectorFunctional instead of a VectorOperator in case form is a linear form.

  • solver – The Solver for the operator.

  • name – Name of the operator.

apply(U, mu=None)[source]

Apply the operator to a VectorArray.

Parameters:
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 and VectorArrays U, V in the source resp. range we have:

op.apply_adjoint(V, mu).dot(U) == V.inner(op.apply(U, mu))

Thus, when op is represented by a matrix M, apply_adjoint is given by left-multiplication of (the complex conjugate of) M with V.

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.

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 as source, this method returns for given parameter values mu a VectorArray V in the operator’s range, such that

V.lincomb(U.to_numpy()) == self.apply(U, mu)

for all VectorArrays U.

Parameters:

mu – The parameter values for which to return the VectorArray 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 as range, this method returns for given parameter values mu a VectorArray V in the operator’s source, such that

self.range.make_array(V.inner(U)) == self.apply(U, mu)

for all VectorArrays U.

Parameters:

mu – The parameter values for which to return the VectorArray 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 a FixedParameterOperator. The only assured property of the assembled operator is that it no longer depends on a Parameter.

If the operator has a Solver, the assembled Operator will be equipped with the same Solver.

Parameters:

mu – The parameter values for which to assemble the operator.

Returns:

Parameter-independent, assembled |Operator|.

linear: bool = True[source]

True if the operator is linear.

class pymor.bindings.fenics.FenicsMatrixOperator(matrix, source_space, range_space, solver=None, name=None)[source]

Bases: 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=None, name=None)[source]

Bases: Operator

Wraps a FEniCS form as an Operator.

apply(U, mu=None)[source]

Apply the operator to a VectorArray.

Parameters:
Returns:

|VectorArray| of the operator evaluations.

jacobian(U, mu=None)[source]

Return the operator’s Jacobian as a new Operator.

If the operator has a Solver, the Jacobian Operator will be equipped with the solver’s jacobian_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.

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 array source_dofs such that for any VectorArray U in self.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 few source_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 operator range to which to restrict.

Returns:

linear: bool = False[source]

True if the operator is linear.

class pymor.bindings.fenics.FenicsVector(impl)[source]

Bases: CopyOnWriteVector

Wraps a FEniCS vector to make it usable with ListVectorArray.

classmethod from_instance(instance)[source]
amax()[source]
dofs(dof_indices)[source]
inner(other)[source]
norm()[source]
norm2()[source]
sup_norm()[source]
to_numpy(ensure_copy=False)[source]
class pymor.bindings.fenics.FenicsVectorSpace(V)[source]

Bases: ComplexifiedListVectorSpace

real_vector_type[source]

alias of FenicsVector

vector_type[source]

alias of ComplexifiedFenicsVector

real_full_vector(value)[source]
real_make_vector(obj)[source]
real_random_vector(distribution, **kwargs)[source]
real_vector_from_numpy(data, ensure_copy=False)[source]
real_zero_vector()[source]
property dim[source]

The type of the None singleton.

class pymor.bindings.fenics.FenicsVisualizer(space, mesh_refinements=0)[source]

Bases: 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).

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 of VectorArrays which will be visualized in separate windows. If filename is specified, only one VectorArray 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 of VectorArrays, 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, solver=None)[source]

Bases: Operator

Restricted FenicsOperator.

apply(U, mu=None)[source]

Apply the operator to a VectorArray.

Parameters:
Returns:

|VectorArray| of the operator evaluations.

jacobian(U, mu=None)[source]

Return the operator’s Jacobian as a new Operator.

If the operator has a Solver, the Jacobian Operator will be equipped with the solver’s jacobian_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.

linear: bool = False[source]

True if the operator is linear.

pymor.bindings.fenics.compute_parent_facet_indices(submesh, mesh)[source]