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 by ListVectorArray. All interface methods have a direct counterpart in the VectorArray interface.

Methods

amax

amax()[source]
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 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_options

The solver_options for the assembled FenicsMatrixOperator.

name

Name of the operator.

Methods

apply

Apply the operator to a VectorArray.

apply_adjoint

Apply the adjoint operator.

apply_inverse

Apply the inverse operator.

as_range_array

Return a VectorArray representation of the operator in its range space.

as_source_array

Return a VectorArray representation of the operator in its source space.

assemble

Assemble the operator for given parameter values.

linear = True[source]
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 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.

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 as V containing initial guesses for the solution. Some implementations of apply_inverse may ignore this parameter. If None 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 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).T) == 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.

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

Apply the operator to a VectorArray.

jacobian

Return the operator's Jacobian as a new Operator.

restricted

Restrict the operator range to a given set of degrees of freedom.

linear = False[source]
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 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(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 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

restricted_op

The restricted operator as defined above. The operator will have NumpyVectorSpace (len(source_dofs)) as source and NumpyVectorSpace (len(dofs)) as range.

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.

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

Bases: pymor.vectorarrays.list.ComplexifiedListVectorSpace

VectorSpace of ListVectorArrays.

real_vector_type[source]
vector_type[source]
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]
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

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 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)[source]

Bases: pymor.operators.interface.Operator

Restricted FenicsOperator.

Methods

apply

Apply the operator to a VectorArray.

jacobian

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.

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