pymor.discretizers.builtin

Subpackages

Submodules

Package Contents

Classes

OnedGrid

One-dimensional Grid on an interval.

RectGrid

Basic implementation of a rectangular Grid on a rectangular domain.

TriaGrid

Basic implementation of a triangular grid on a rectangular domain.

Functions

discretize_stationary_cg

Discretizes a StationaryProblem using finite elements.

discretize_instationary_cg

Discretizes an InstationaryProblem with a StationaryProblem as stationary part

discretize_stationary_fv

Discretizes a StationaryProblem using the finite volume method.

discretize_instationary_fv

FV Discretization of an InstationaryProblem with a StationaryProblem as stationary part

load_gmsh

Parse a Gmsh file and create a corresponding GmshGrid and GmshBoundaryInfo.

pymor.discretizers.builtin.discretize_stationary_cg(analytical_problem, diameter=None, domain_discretizer=None, grid_type=None, grid=None, boundary_info=None, preassemble=True, mu_energy_product=None)[source]

Discretizes a StationaryProblem using finite elements.

Parameters

analytical_problem

The StationaryProblem to discretize.

diameter

If not None, diameter is passed as an argument to the domain_discretizer.

domain_discretizer

Discretizer to be used for discretizing the analytical domain. This has to be a function domain_discretizer(domain_description, diameter, ...). If None, discretize_domain_default is used.

grid_type

If not None, this parameter is forwarded to domain_discretizer to specify the type of the generated Grid.

grid

Instead of using a domain discretizer, the Grid can also be passed directly using this parameter.

boundary_info

A BoundaryInfo specifying the boundary types of the grid boundary entities. Must be provided if grid is specified.

preassemble

If True, preassemble all operators in the resulting Model.

mu_energy_product

If not None, parameter values for which to assemble the symmetric part of the Operator of the resulting Model fom (ignoring the advection part). Thus, assuming no advection and a symmetric diffusion tensor, fom.products['energy'] is equal to fom.operator.assemble(mu), except for the fact that the former has cleared Dirichlet rows and columns, while the latter only has cleared Dirichlet rows).

Returns

m

The Model that has been generated.

data

Dictionary with the following entries:

grid

The generated Grid.

boundary_info

The generated BoundaryInfo.

unassembled_m

In case preassemble is True, the generated Model before preassembling operators.

pymor.discretizers.builtin.discretize_instationary_cg(analytical_problem, diameter=None, domain_discretizer=None, grid_type=None, grid=None, boundary_info=None, num_values=None, time_stepper=None, nt=None, preassemble=True)[source]

Discretizes an InstationaryProblem with a StationaryProblem as stationary part using finite elements.

Parameters

analytical_problem

The InstationaryProblem to discretize.

diameter

If not None, diameter is passed as an argument to the domain_discretizer.

domain_discretizer

Discretizer to be used for discretizing the analytical domain. This has to be a function domain_discretizer(domain_description, diameter, ...). If None, discretize_domain_default is used.

grid_type

If not None, this parameter is forwarded to domain_discretizer to specify the type of the generated Grid.

grid

Instead of using a domain discretizer, the Grid can also be passed directly using this parameter.

boundary_info

A BoundaryInfo specifying the boundary types of the grid boundary entities. Must be provided if grid is specified.

num_values

The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.

time_stepper

The time-stepper to be used by solve.

nt

If time_stepper is not specified, the number of time steps for implicit Euler time stepping.

preassemble

If True, preassemble all operators in the resulting Model.

Returns

m

The Model that has been generated.

data

Dictionary with the following entries:

grid

The generated Grid.

boundary_info

The generated BoundaryInfo.

unassembled_m

In case preassemble is True, the generated Model before preassembling operators.

pymor.discretizers.builtin.discretize_stationary_fv(analytical_problem, diameter=None, domain_discretizer=None, grid_type=None, num_flux='lax_friedrichs', lxf_lambda=1.0, eo_gausspoints=5, eo_intervals=1, grid=None, boundary_info=None, preassemble=True)[source]

Discretizes a StationaryProblem using the finite volume method.

Parameters

analytical_problem

The StationaryProblem to discretize.

diameter

If not None, diameter is passed as an argument to the domain_discretizer.

domain_discretizer

Discretizer to be used for discretizing the analytical domain. This has to be a function domain_discretizer(domain_description, diameter, ...). If None, discretize_domain_default is used.

grid_type

If not None, this parameter is forwarded to domain_discretizer to specify the type of the generated Grid.

num_flux

The numerical flux to use in the finite volume formulation. Allowed values are 'lax_friedrichs', 'engquist_osher', 'simplified_engquist_osher' (see pymor.discretizers.builtin.fv).

lxf_lambda

The stabilization parameter for the Lax-Friedrichs numerical flux (ignored, if different flux is chosen).

eo_gausspoints

Number of Gauss points for the Engquist-Osher numerical flux (ignored, if different flux is chosen).

eo_intervals

Number of sub-intervals to use for integration when using Engquist-Osher numerical flux (ignored, if different flux is chosen).

grid

Instead of using a domain discretizer, the Grid can also be passed directly using this parameter.

boundary_info

A BoundaryInfo specifying the boundary types of the grid boundary entities. Must be provided if grid is specified.

preassemble

If True, preassemble all operators in the resulting Model.

Returns

m

The Model that has been generated.

data

Dictionary with the following entries:

grid

The generated Grid.

boundary_info

The generated BoundaryInfo.

unassembled_m

In case preassemble is True, the generated Model before preassembling operators.

pymor.discretizers.builtin.discretize_instationary_fv(analytical_problem, diameter=None, domain_discretizer=None, grid_type=None, num_flux='lax_friedrichs', lxf_lambda=1.0, eo_gausspoints=5, eo_intervals=1, grid=None, boundary_info=None, num_values=None, time_stepper=None, nt=None, preassemble=True)[source]

FV Discretization of an InstationaryProblem with a StationaryProblem as stationary part

Parameters

analytical_problem

The InstationaryProblem to discretize.

diameter

If not None, diameter is passed to the domain_discretizer.

domain_discretizer

Discretizer to be used for discretizing the analytical domain. This has to be a function domain_discretizer(domain_description, diameter, ...). If further arguments should be passed to the discretizer, use functools.partial. If None, discretize_domain_default is used.

grid_type

If not None, this parameter is forwarded to domain_discretizer to specify the type of the generated Grid.

num_flux

The numerical flux to use in the finite volume formulation. Allowed values are 'lax_friedrichs', 'engquist_osher', 'simplified_engquist_osher' (see pymor.discretizers.builtin.fv).

lxf_lambda

The stabilization parameter for the Lax-Friedrichs numerical flux (ignored, if different flux is chosen).

eo_gausspoints

Number of Gauss points for the Engquist-Osher numerical flux (ignored, if different flux is chosen).

eo_intervals

Number of sub-intervals to use for integration when using Engquist-Osher numerical flux (ignored, if different flux is chosen).

grid

Instead of using a domain discretizer, the Grid can also be passed directly using this parameter.

boundary_info

A BoundaryInfo specifying the boundary types of the grid boundary entities. Must be provided if grid is specified.

num_values

The number of returned vectors of the solution trajectory. If None, each intermediate vector that is calculated is returned.

time_stepper

The time-stepper to be used by solve.

nt

If time_stepper is not specified, the number of time steps for implicit Euler time stepping.

preassemble

If True, preassemble all operators in the resulting Model.

Returns

m

The Model that has been generated.

data

Dictionary with the following entries:

grid

The generated Grid.

boundary_info

The generated BoundaryInfo.

unassembled_m

In case preassemble is True, the generated Model before preassembling operators.

pymor.discretizers.builtin.load_gmsh(filename)[source]

Parse a Gmsh file and create a corresponding GmshGrid and GmshBoundaryInfo.

Parameters

filename

Path of the Gmsh MSH-file.

Returns

grid

The generated GmshGrid.

boundary_info

The generated GmshBoundaryInfo.

class pymor.discretizers.builtin.OnedGrid(domain=(0, 1), num_intervals=4, identify_left_right=False)[source]

Bases: pymor.discretizers.builtin.grids.interfaces.GridWithOrthogonalCenters

One-dimensional Grid on an interval.

Parameters

domain

Tuple (left, right) containing the left and right boundary of the domain.

num_intervals

The number of codim-0 entities.

dim = 1[source]
reference_element[source]
__reduce__(self)[source]

Helper for pickle.

__str__(self)[source]

Return str(self).

size(self, codim=0)[source]

The number of entities of codimension codim.

subentities(self, codim, subentity_codim)[source]

retval[e,s] is the global index of the s-th codim-subentity_codim subentity of the codim-codim entity with global index e.

The ordering of subentities(0, subentity_codim)[e] has to correspond, w.r.t. the embedding of e, to the local ordering inside the reference element.

For codim > 0, we provide a default implementation by calculating the subentities of e as follows:

  1. Find the codim-1 parent entity e_0 of e with minimal global index

  2. Lookup the local indices of the subentities of e inside e_0 using the reference element.

  3. Map these local indices to global indices using subentities(codim - 1, subentity_codim).

This procedures assures that subentities(codim, subentity_codim)[e] has the right ordering w.r.t. the embedding determined by e_0, which agrees with what is returned by embeddings(codim)

embeddings(self, codim)[source]

Returns tuple (A, B) where A[e] and B[e] are the linear part and the translation part of the map from the reference element of e to e.

For codim > 0, we provide a default implementation by taking the embedding of the codim-1 parent entity e_0 of e with lowest global index and composing it with the subentity_embedding of e into e_0 determined by the reference element.

bounding_box(self)[source]

Returns a (2, dim)-shaped array containing lower/upper bounding box coordinates.

orthogonal_centers(self)[source]

retval[e] is a point inside the codim-0 entity with global index e such that the line segment from retval[e] to retval[e2] is always orthogonal to the codim-1 entity shared by the codim-0 entities with global index e and e2.

(This is mainly useful for gradient approximation in finite volume schemes.)

visualize(self, U, codim=1, **kwargs)[source]

Visualize scalar data associated to the grid as a patch plot.

Parameters

U

NumPy array of the data to visualize. If U.dim == 2 and len(U) > 1, the data is visualized as a time series of plots. Alternatively, a tuple of NumPy arrays can be provided, in which case a subplot is created for each entry of the tuple. The lengths of all arrays have to agree.

codim

The codimension of the entities the data in U is attached to (either 0 or 1).

kwargs

See visualize

class pymor.discretizers.builtin.RectGrid(num_intervals=(2, 2), domain=([0, 0], [1, 1]), identify_left_right=False, identify_bottom_top=False)[source]

Bases: pymor.discretizers.builtin.grids.interfaces.GridWithOrthogonalCenters

Basic implementation of a rectangular Grid on a rectangular domain.

The global face, edge and vertex indices are given as follows

x1
^
|

6--10---7--11---8
|       |       |
3   2   4   3   5
|       |       |
3---8---4---9---5
|       |       |
0   0   1   1   2
|       |       |
0---6---1---7---2  --> x0

Parameters

num_intervals

Tuple (n0, n1) determining a grid with n0 x n1 codim-0 entities.

domain

Tuple (ll, ur) where ll defines the lower left and ur the upper right corner of the domain.

identify_left_right

If True, the left and right boundaries are identified, i.e. the left-most codim-0 entities become neighbors of the right-most codim-0 entities.

identify_bottom_top

If True, the bottom and top boundaries are identified, i.e. the bottom-most codim-0 entities become neighbors of the top-most codim-0 entities.

dim = 2[source]
reference_element[source]
__reduce__(self)[source]

Helper for pickle.

__str__(self)[source]

Return str(self).

size(self, codim=0)[source]

The number of entities of codimension codim.

subentities(self, codim, subentity_codim)[source]

retval[e,s] is the global index of the s-th codim-subentity_codim subentity of the codim-codim entity with global index e.

The ordering of subentities(0, subentity_codim)[e] has to correspond, w.r.t. the embedding of e, to the local ordering inside the reference element.

For codim > 0, we provide a default implementation by calculating the subentities of e as follows:

  1. Find the codim-1 parent entity e_0 of e with minimal global index

  2. Lookup the local indices of the subentities of e inside e_0 using the reference element.

  3. Map these local indices to global indices using subentities(codim - 1, subentity_codim).

This procedures assures that subentities(codim, subentity_codim)[e] has the right ordering w.r.t. the embedding determined by e_0, which agrees with what is returned by embeddings(codim)

embeddings(self, codim=0)[source]

Returns tuple (A, B) where A[e] and B[e] are the linear part and the translation part of the map from the reference element of e to e.

For codim > 0, we provide a default implementation by taking the embedding of the codim-1 parent entity e_0 of e with lowest global index and composing it with the subentity_embedding of e into e_0 determined by the reference element.

bounding_box(self)[source]

Returns a (2, dim)-shaped array containing lower/upper bounding box coordinates.

structured_to_global(self, codim)[source]

Returns an NumPy array which maps structured indices to global codim-codim indices.

In other words structured_to_global(codim)[i, j] is the global index of the i-th in x0-direction and j-th in x1-direction codim-codim entity of the grid.

global_to_structured(self, codim)[source]

Returns an array which maps global codim-codim indices to structured indices.

I.e. if GTS = global_to_structured(codim) and STG = structured_to_global(codim), then STG[GTS[:, 0], GTS[:, 1]] == numpy.arange(size(codim)).

vertex_coordinates(self, dim)[source]

Returns an array of the x_dim coordinates of the grid vertices.

I.e.

centers(2)[structured_to_global(2)[i, j]] == np.array([vertex_coordinates(0)[i],
                                                       vertex_coordinates(1)[j]])
orthogonal_centers(self)[source]

retval[e] is a point inside the codim-0 entity with global index e such that the line segment from retval[e] to retval[e2] is always orthogonal to the codim-1 entity shared by the codim-0 entities with global index e and e2.

(This is mainly useful for gradient approximation in finite volume schemes.)

visualize(self, U, codim=2, **kwargs)[source]

Visualize scalar data associated to the grid as a patch plot.

Parameters

U

NumPy array of the data to visualize. If U.dim == 2 and len(U) > 1, the data is visualized as a time series of plots. Alternatively, a tuple of NumPy arrays can be provided, in which case a subplot is created for each entry of the tuple. The lengths of all arrays have to agree.

codim

The codimension of the entities the data in U is attached to (either 0 or 2).

kwargs

See visualize

class pymor.discretizers.builtin.TriaGrid(num_intervals=(2, 2), domain=([0, 0], [1, 1]), identify_left_right=False, identify_bottom_top=False)[source]

Bases: pymor.discretizers.builtin.grids.interfaces.GridWithOrthogonalCenters

Basic implementation of a triangular grid on a rectangular domain.

The global face, edge and vertex indices are given as follows

6---------10----------7---------11----------8
| \                 / | \                 / |
|    22   10    18    |    23   11    19    |
|       \     /       |       \     /       |
3    14   11     6    4    15   12     7    5
|       /     \       |       /     \       |
|    14    2    26    |    15    3    27    |
| /                 \ | /                 \ |
3----------8----------4----------9----------5
| \                 / | \                 / |
|    20    8    16    |    21    9    17    |
|       \     /       |       \     /       |
0    12    9     4    1    13   10     5    2
|       /     \       |       /     \       |
|    12    0    24    |    13    1    25    |
| /                 \ | /                 \ |
0----------6----------1----------7----------2

Parameters

num_intervals

Tuple (n0, n1) determining a grid with n0 x n1 codim-0 entities.

domain

Tuple (ll, ur) where ll defines the lower left and ur the upper right corner of the domain.

identify_left_right

If True, the left and right boundaries are identified, i.e. the left-most codim-0 entities become neighbors of the right-most codim-0 entities.

identify_bottom_top

If True, the bottom and top boundaries are identified, i.e. the bottom-most codim-0 entities become neighbors of the top-most codim-0 entities.

dim = 2[source]
reference_element[source]
__reduce__(self)[source]

Helper for pickle.

__str__(self)[source]

Return str(self).

size(self, codim=0)[source]

The number of entities of codimension codim.

subentities(self, codim, subentity_codim)[source]

retval[e,s] is the global index of the s-th codim-subentity_codim subentity of the codim-codim entity with global index e.

The ordering of subentities(0, subentity_codim)[e] has to correspond, w.r.t. the embedding of e, to the local ordering inside the reference element.

For codim > 0, we provide a default implementation by calculating the subentities of e as follows:

  1. Find the codim-1 parent entity e_0 of e with minimal global index

  2. Lookup the local indices of the subentities of e inside e_0 using the reference element.

  3. Map these local indices to global indices using subentities(codim - 1, subentity_codim).

This procedures assures that subentities(codim, subentity_codim)[e] has the right ordering w.r.t. the embedding determined by e_0, which agrees with what is returned by embeddings(codim)

embeddings(self, codim=0)[source]

Returns tuple (A, B) where A[e] and B[e] are the linear part and the translation part of the map from the reference element of e to e.

For codim > 0, we provide a default implementation by taking the embedding of the codim-1 parent entity e_0 of e with lowest global index and composing it with the subentity_embedding of e into e_0 determined by the reference element.

bounding_box(self)[source]

Returns a (2, dim)-shaped array containing lower/upper bounding box coordinates.

orthogonal_centers(self)[source]

retval[e] is a point inside the codim-0 entity with global index e such that the line segment from retval[e] to retval[e2] is always orthogonal to the codim-1 entity shared by the codim-0 entities with global index e and e2.

(This is mainly useful for gradient approximation in finite volume schemes.)

visualize(self, U, codim=2, **kwargs)[source]

Visualize scalar data associated to the grid as a patch plot.

Parameters

U

NumPy array of the data to visualize. If U.dim == 2 and len(U) > 1, the data is visualized as a time series of plots. Alternatively, a tuple of NumPy arrays can be provided, in which case a subplot is created for each entry of the tuple. The lengths of all arrays have to agree.

codim

The codimension of the entities the data in U is attached to (either 0 or 2).

kwargs

See visualize