pymor.bindings.fenics

Module Contents

Classes

FenicsVector

Wraps a FEniCS vector to make it usable with ListVectorArray.

ComplexifiedFenicsVector

Interface for vectors used in conjunction with ListVectorArray.

FenicsVectorSpace

VectorSpace of ListVectorArrays.

FenicsMatrixOperator

Wraps a FEniCS matrix as an Operator.

FenicsOperator

Wraps a FEniCS form as an Operator.

RestrictedFenicsOperator

Interface for Parameter dependent discrete operators.

FenicsVisualizer

Visualize a FEniCS grid function.

Functions

compute_parent_facet_indices

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

Bases: pymor.vectorarrays.list.CopyOnWriteVector

Wraps a FEniCS vector to make it usable with ListVectorArray.

__radd__[source]
classmethod from_instance(cls, instance)[source]
_copy_data(self)[source]
to_numpy(self, ensure_copy=False)[source]
_scal(self, alpha)[source]
_axpy(self, alpha, x)[source]
inner(self, other)[source]
norm(self)[source]
norm2(self)[source]
sup_norm(self)[source]
dofs(self, dof_indices)[source]
abstract amax(self)[source]
__add__(self, other)[source]
__iadd__(self, other)[source]
__sub__(self, other)[source]
__isub__(self, other)[source]
__mul__(self, other)[source]
__neg__(self)[source]
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.

amax(self)[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]
property dim(self)[source]
__eq__(self, other)[source]

Return self==value.

__hash__(self)[source]

Return hash(self).

real_zero_vector(self)[source]
real_full_vector(self, value)[source]
real_random_vector(self, distribution, random_state, **kwargs)[source]
real_vector_from_numpy(self, data, ensure_copy=False)[source]
real_make_vector(self, obj)[source]
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.

_real_apply_one_vector(self, u, mu=None, prepare_data=None)[source]
_real_apply_adjoint_one_vector(self, v, mu=None, prepare_data=None)[source]
_real_apply_inverse_one_vector(self, v, mu=None, initial_guess=None, least_squares=False, prepare_data=None)[source]
_real_apply_inverse_adjoint_one_vector(self, u, mu=None, initial_guess=None, least_squares=False, prepare_data=None)[source]
_assemble_lincomb(self, 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 Operator which represents the sum

c_1*O_1 + ... + c_N*O_N + s*I

where O_i are Operators, c_i, s scalar coefficients and I the identity.

This method is called in the assemble method of LincombOperator on 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 returns None to indicate that assembly is not possible.

Parameters

operators

List of Operators O_i whose linear combination is formed.

coefficients

List of the corresponding linear coefficients c_i.

identity_shift

The coefficient s.

solver_options

solver_options for the assembled operator.

name

Name of the assembled operator.

Returns

The assembled Operator if assembly is possible, otherwise None.

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.

linear = False[source]
_set_mu(self, mu=None)[source]
apply(self, 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(self, 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(self, 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.

_restrict_form(self, submesh, source_dofs)[source]
_restrict_dirichlet_bcs(self, submesh, source_dofs, V_r_source)[source]
_build_dof_map(self, V, V_r, dofs)[source]
class pymor.bindings.fenics.RestrictedFenicsOperator(op, restricted_range_dofs)[source]

Bases: pymor.operators.interface.Operator

Interface for Parameter dependent discrete operators.

An operator in pyMOR is simply a mapping which for any given parameter values maps vectors from its source VectorSpace to vectors in its range VectorSpace.

Note that there is no special distinction between functionals and operators in pyMOR. A functional is simply an operator with NumpyVectorSpace (1) as its range VectorSpace.

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_options is None or a dict entry is missing or None, default options are used. The interpretation of the given solver options is up to the operator at hand. In general, values in solver_options should 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.

linear[source]

True if the operator is linear.

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.

apply(self, 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(self, 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.

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

visualize(self, 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.

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