Coverage for src/pymor/grids/interfaces : 73%
Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
|
# This file is part of the pyMOR project (http://www.pymor.org). # Copyright Holders: Rene Milk, Stephan Rave, Felix Schindler # License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)
SimpleReferenceElementDefaultImplementations, AffineGridDefaultImplementations,)
'''A conformal topological grid.
The grid is completely determined via the subentity relation given by :meth:`~ConformalTopologicalGridInterface.subentities`. In addition, only :meth:`~ConformalTopologicalGridInterface.size` has to be implemented, cached default implementations for all other methods are provided by :class:`~pymor.grids.defaultimpl.ConformalTopologicalGridDefaultImplementations`.
Attributes ---------- dim The dimension of the grid. '''
def size(self, codim): '''The number of entities of codimension `codim`.''' pass
def subentities(self, codim, subentity_codim): '''`retval[e,s]` is the global index of the `s`-th codim-`subentity_codim` subentity of the codim-`codim` entity with global index `e`.
Only `subentities(codim, codim+1)` has to be implemented; a default implementation is provided which evaluates `subentities(codim, subentity_codim)` by computing the transitive closure of `subentities(codim, codim+1)`. ''' return self._subentities(codim, subentity_codim)
'''`retval[e,s]` is the global index of the `s`-th codim-`superentity_codim` superentity of the codim-`codim` entity with global index `e`.
`retval[e]` is sorted by global index.
The default implementation is to compute the result from `subentities(superentity_codim, codim)`. '''
'''`retval[e,s]` is the local index of the codim-`codim` entity `e` in the codim-`superentity_codim` superentity `superentities(codim, superentity_codim)[e,s].` '''
'''`retval[e,n]` is the global index of the `n`-th codim-`neighbour_codim` entitiy of the codim-`codim` entity `e` that shares with `e` a subentity of codimension `intersection_codim`.
If `intersection_codim == None`, it is set to `codim + 1` if `codim == neighbour_codim` and to `min(codim, neighbour_codim)` otherwise.
The default implementation is to compute the result from `subentities(codim, intersection_codim)` and `superentities(intersection_codim, neihbour_codim)`. '''
'''`retval[e]` is true iff the codim-`codim` entity with global index `e` is a boundary entity.
By definition, a codim-1 entity is a boundary entity if it has only one codim-0 superentity. For `codim != 1`, a codim-`codim` entity is a boundary entity if it has a codim-1 sub/super-entity. '''
'''Returns the global indices of all codim-`codim` boundary entities.
By definition, a codim-1 entity is a boundary entity if it has only one codim-0 superentity. For `codim != 1`, a codim-`codim` entity is a boundary entity if it has a codim-1 sub/super-entity. '''
def test_instances(): '''Returns a list of Grid instances suitable to be run through our test cases.''' pass
'''Defines a reference element with the property that each of its subentities is of the same type.
I.e. a three-dimensional reference element cannot have triangles and rectangles as faces at the same time.
Attributes ---------- dim The dimension of the reference element volume The volume of the reference element '''
def size(self, codim): 'Number of subentites of codimension `codim`.'
def subentities(self, codim, subentity_codim): '''`subentities(c,sc)[i,j]` is, with respect to the indexing inside the reference element, the index of the `j`-th codim-`subentity_codim` subentity of the `i`-th codim-`codim` subentity of the reference element. ''' pass
def subentity_embedding(self, subentity_codim): '''Returns a tuple `(A, B)` which defines the embedding of the codim-`subentity_codim` subentities into the reference element.
For `subentity_codim > 1', the embedding is by default given recursively via `subentity_embedding(subentity_codim - 1)` and `sub_reference_element(subentity_codim - 1).subentity_embedding(1)` choosing always the superentity with smallest index. ''' return self._subentity_embedding(subentity_codim)
def sub_reference_element(self, codim): '''Returns the reference relement of the codim-`codim` subentities.''' return self._sub_reference_element(codim)
'''Returns the reference relement of the codim-`codim` subentities.'''
def unit_outer_normals(self): '''`retval[e]` is the unit outer-normal vector to the codim-1 subentity with index `e`. ''' pass
def center(self): '''Coordinates of the barycenter.''' pass
def mapped_diameter(self, A): '''The diameter of the reference element after tranforming it with the matrix `A` (vectorized). ''' pass
'''Returns tuple `(P, W)` where `P` is an array of quadrature points with corresponding weights `W`.
The quadrature is of order `order` or has `npoints` integration points. ''' pass
def quadrature_info(self): '''Returns a tuple of dicts `(O, N)` where `O[quadrature_type]` is a list of orders which are implemented for `quadrature_type` and `N[quadrature_type]` is a list of the corrsponding numbers of integration points. ''' pass
o, _ = self.quadrature_info() return frozenset(o.keys())
'''Topological grid with geometry where each codim-0 entity is affinely mapped to the same |ReferenceElement|.
The grid is completely determined via the subentity relation given by :meth:`~AffineGridInterface.subentities` and the embeddings given by :meth:`~AffineGridInterface.embeddings`. In addition, only :meth:`~ConformalTopologicalGridInterface.size` and :meth:`~AffineGridInterface.reference_element` have to be implemented. Cached default implementations for all other methods are provided by :class:`~pymor.grids.defaultimpl.AffineGridDefaultImplementations`.
Attributes ---------- dim_outer The dimension of the space into which the grid is embedded. '''
def reference_element(self, codim): '''The |ReferenceElement| of the codim-`codim` entities.''' pass
def subentities(self, codim, subentity_codim): '''`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 subentites of `e` as follows:
1. Find the `codim-1` parent entity `e_0` of `e` with minimal global index 2. Lookup the local indicies of the subentites of `e` inside `e_0` using the reference element. 3. Map these local indicies to global indicies 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)` '''
def embeddings(self, codim): '''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. '''
'''`retval[e]` is the transposed (pseudo-)inverse of the jacobian of `embeddings(codim)[e]`. '''
'''`retval[e]` is given as `sqrt(det(A^T*A))`, where `A = embeddings(codim)[0][e]`.'''
'''`retval[e]` is the (dim-`codim`)-dimensional volume of the codim-`codim` entity with global index `e`.'''
'''`retval[e] = 1 / volumes(codim)[e]`.'''
'''`retval[e,i]` is the unit outer normal to the i-th codim-1 subentity of the codim-0 entitiy with global index `e`. '''
'''`retval[e]` is the barycenter of the codim-`codim` entity with global index `e`.'''
'''`retval[e]` is the diameter of the codim-`codim` entity with global index `e`.'''
'''`retval[e]` is an array of quadrature points in global coordinates for the codim-`codim` entity with global index `e`.
The quadrature is of order `order` or has `npoints` integration points. To integrate a function `f` over `e` one has to form ::
np.dot(f(quadrature_points(codim, order)[e]), reference_element(codim).quadrature(order)[1]) * integration_elements(codim)[e]. # NOQA '''
'''Provides |BoundaryTypes| for the boundaries of a given |ConformalTopologicalGrid|.
For every |BoundaryType| and codimension a mask is provided, marking grid entities of the respective type and codimension by their global index.
Attributes ---------- boundary_types set of all |BoundaryTypes| the grid has. '''
'''retval[i] is `True` if the codim-`codim` entity of global index `i` is associated to the |BoundaryType| `boundary_type`. ''' raise ValueError('Has no boundary_type "{}"'.format(boundary_type))
'''retval[i] is `True` if the codim-`codim` entity of global index `i` is associated to one and only one |BoundaryType|. ''' return np.less_equal(sum(self.mask(bt, codim=codim).astype(np.int) for bt in self.boundary_types), 1)
'''retval[i] is `True` if the codim-`codim` entity of global index `i` is associated to no |BoundaryType|. ''' return np.equal(sum(self.mask(bt, codim=codim).astype(np.int) for bt in self.boundary_types), 0)
if assert_unique_type: for codim in assert_unique_type: assert np.all(self.unique_boundary_type_mask(codim)) if assert_some_type: for codim in assert_some_type: assert not np.any(self.no_boundary_type_mask(codim))
def has_dirichlet(self):
def has_neumann(self): return BoundaryType('neumann') in self.boundary_types
def has_only_dirichlet(self): return self.boundary_types == {BoundaryType('dirichlet')}
def has_only_neumann(self): return self.boundary_types == {BoundaryType('neumann')}
def has_only_dirichletneumann(self): return self.boundary_types <= {BoundaryType('dirichlet'), BoundaryType('neumann')}
return self.mask(BoundaryType('neumann'), codim)
def _dirichlet_boundaries(self, codim):
def _neumann_boundaries(self, codim): return np.where(self.neumann_mask(codim))[0].astype('int32')
return self._neumann_boundaries(codim) |