Skip to content

Commit

Permalink
[domaindescriptions] remove the BoundaryType class
Browse files Browse the repository at this point in the history
  • Loading branch information
sdrave committed Oct 19, 2016
1 parent 1742152 commit 56c004f
Show file tree
Hide file tree
Showing 13 changed files with 88 additions and 160 deletions.
2 changes: 0 additions & 2 deletions docs/source/substitutions.py
Expand Up @@ -64,8 +64,6 @@
.. |ParabolicProblem| replace:: :class:`~pymor.analyticalproblems.parabolic.ParabolicProblem`
.. |InstationaryAdvectionProblem| replace:: :class:`~pymor.analyticalproblems.advection.InstationaryAdvectionProblem`
.. |BoundaryType| replace:: :class:`~pymor.domaindescriptions.boundarytypes.BoundaryType`
.. |BoundaryTypes| replace:: :class:`BoundaryTypes <pymor.domaindescriptions.boundarytypes.BoundaryType>`
.. |RectDomain| replace:: :class:`~pymor.domaindescriptions.basic.RectDomain`
.. |PolygonalDomain| replace:: :class:`~pymor.domaindescriptions.polygonal.PolygonalDomain`
.. |CylindricalDomain| replace:: :class:`~pymor.domaindescriptions.basic.CylindricalDomain`
Expand Down
4 changes: 2 additions & 2 deletions docs/source/technical_overview.rst
Expand Up @@ -212,14 +212,14 @@ element or finite volume discretizations based on the `NumPy/Scipy
describes the problem we want to discretize. |analytical problems| contain
|Functions| which define the analytical data functions associated with the
problem and a |DomainDescription| that provides a geometrical definition of the
domain the problem is posed on and associates a |BoundaryType| to each part of
domain the problem is posed on and associates a boundary type to each part of
its boundary.

To obtain a |Discretization| from an |analytical problem| we use a
:mod:`discretizer <pymor.discretizers>`. A discretizer will first mesh the
computational domain by feeding the |DomainDescription| into a
:mod:`domaindiscretizer <pymor.domaindiscretizers>` which will return the |Grid|
along with a |BoundaryInfo| associating boundary entities with |BoundaryTypes|.
along with a |BoundaryInfo| associating boundary entities with boundary types.
Next, the |Grid|, |BoundaryInfo| and the various data functions of the
|analytical problem| are used to instatiate :mod:`finite element
<pymor.operators.cg>` or :mod:`finite volume <pymor.operators.fv>` operators.
Expand Down
1 change: 0 additions & 1 deletion src/pymor/basic.py
Expand Up @@ -32,7 +32,6 @@
from pymor.discretizations.basic import StationaryDiscretization, InstationaryDiscretization

from pymor.domaindescriptions.basic import RectDomain, CylindricalDomain, TorusDomain, LineDomain, CircleDomain
from pymor.domaindescriptions.boundarytypes import BoundaryType
from pymor.domaindescriptions.polygonal import DiscDomain, CircularSectorDomain, PolygonalDomain

from pymor.domaindiscretizers.default import discretize_domain_default
Expand Down
66 changes: 33 additions & 33 deletions src/pymor/domaindescriptions/basic.py
Expand Up @@ -4,28 +4,27 @@

import numpy as np

from pymor.domaindescriptions.boundarytypes import BoundaryType
from pymor.domaindescriptions.interfaces import DomainDescriptionInterface
from pymor.domaindescriptions.interfaces import DomainDescriptionInterface, KNOWN_BOUNDARY_TYPES


class RectDomain(DomainDescriptionInterface):
"""Describes a rectangular domain.
|BoundaryTypes| can be associated edgewise.
Boundary types can be associated edgewise.
Parameters
----------
domain
List of two points defining the lower-left and upper-right corner
of the domain.
left
The |BoundaryType| of the left edge.
The boundary type of the left edge.
right
The |BoundaryType| of the right edge.
The boundary type of the right edge.
top
The |BoundaryType| of the top edge.
The boundary type of the top edge.
bottom
The |BoundaryType| of the bottom edge.
The boundary type of the bottom edge.
Attributes
----------
Expand All @@ -38,14 +37,13 @@ class RectDomain(DomainDescriptionInterface):

dim = 2

def __init__(self, domain=([0, 0], [1, 1]), left=BoundaryType('dirichlet'), right=BoundaryType('dirichlet'),
top=BoundaryType('dirichlet'), bottom=BoundaryType('dirichlet')):
def __init__(self, domain=([0, 0], [1, 1]), left='dirichlet', right='dirichlet',
top='dirichlet', bottom='dirichlet'):
assert domain[0][0] <= domain[1][0]
assert domain[0][1] <= domain[1][1]
assert left is None or isinstance(left, BoundaryType)
assert right is None or isinstance(right, BoundaryType)
assert top is None or isinstance(top, BoundaryType)
assert bottom is None or isinstance(bottom, BoundaryType)
for bt in (left, right, top, bottom):
if bt is not None and bt not in KNOWN_BOUNDARY_TYPES:
self.logger.warn('Unknown boundary type: {}'.format(bt))
self.boundary_types = frozenset({left, right, top, bottom})
self.left = left
self.right = right
Expand Down Expand Up @@ -78,27 +76,27 @@ def diameter(self):
return np.sqrt(self.width ** 2 + self.height ** 2)

def __repr__(self):
left = ', left=' + repr(self.left) if self.left != BoundaryType('dirichlet') else ''
right = ', right=' + repr(self.right) if self.right != BoundaryType('dirichlet') else ''
top = ', top=' + repr(self.top) if self.top != BoundaryType('dirichlet') else ''
bottom = ', bottom=' + repr(self.bottom) if self.bottom != BoundaryType('dirichlet') else ''
left = ', left=' + repr(self.left) if self.left != 'dirichlet' else ''
right = ', right=' + repr(self.right) if self.right != 'dirichlet' else ''
top = ', top=' + repr(self.top) if self.top != 'dirichlet' else ''
bottom = ', bottom=' + repr(self.bottom) if self.bottom != 'dirichlet' else ''
return 'RectDomain({}{})'.format(str(self.domain).replace('\n', ','), left + right + top + bottom)


class CylindricalDomain(DomainDescriptionInterface):
"""Describes a cylindrical domain.
|BoundaryTypes| can be associated edgewise.
Boundary types can be associated edgewise.
Parameters
----------
domain
List of two points defining the lower-left and upper-right corner
of the domain. The left and right edge are identified.
top
The |BoundaryType| of the top edge.
The boundary type of the top edge.
bottom
The |BoundaryType| of the bottom edge.
The boundary type of the bottom edge.
Attributes
----------
Expand All @@ -109,11 +107,12 @@ class CylindricalDomain(DomainDescriptionInterface):

dim = 2

def __init__(self, domain=([0, 0], [1, 1]), top=BoundaryType('dirichlet'), bottom=BoundaryType('dirichlet')):
def __init__(self, domain=([0, 0], [1, 1]), top='dirichlet', bottom='dirichlet'):
assert domain[0][0] <= domain[1][0]
assert domain[0][1] <= domain[1][1]
assert top is None or isinstance(top, BoundaryType)
assert bottom is None or isinstance(bottom, BoundaryType)
for bt in (top, bottom):
if bt is not None and bt not in KNOWN_BOUNDARY_TYPES:
self.logger.warn('Unknown boundary type: {}'.format(bt))
self.boundary_types = frozenset({top, bottom})
self.top = top
self.bottom = bottom
Expand Down Expand Up @@ -144,8 +143,8 @@ def diameter(self):
return np.sqrt(self.width ** 2 + self.height ** 2)

def __repr__(self):
top = ', top=' + repr(self.top) if self.top != BoundaryType('dirichlet') else ''
bottom = ', bottom=' + repr(self.bottom) if self.bottom != BoundaryType('dirichlet') else ''
top = ', top=' + repr(self.top) if self.top != 'dirichlet' else ''
bottom = ', bottom=' + repr(self.bottom) if self.bottom != 'dirichlet' else ''
return 'CylindricalDomain({}{})'.format(str(self.domain).replace('\n', ','), top + bottom)


Expand Down Expand Up @@ -203,16 +202,16 @@ def __repr__(self):
class LineDomain(DomainDescriptionInterface):
"""Describes an interval domain.
|BoundaryTypes| can be associated edgewise.
Boundary types can be associated edgewise.
Parameters
----------
domain
List [x_l, x_r] providing the left and right endpoint.
left
The |BoundaryType| of the left endpoint.
The boundary type of the left endpoint.
right
The |BoundaryType| of the right endpoint.
The boundary type of the right endpoint.
Attributes
----------
Expand All @@ -223,10 +222,11 @@ class LineDomain(DomainDescriptionInterface):

dim = 1

def __init__(self, domain=(0, 1), left=BoundaryType('dirichlet'), right=BoundaryType('dirichlet')):
def __init__(self, domain=(0, 1), left='dirichlet', right='dirichlet'):
assert domain[0] <= domain[1]
assert left is None or isinstance(left, BoundaryType)
assert right is None or isinstance(right, BoundaryType)
for bt in (left, right):
if bt is not None and bt not in KNOWN_BOUNDARY_TYPES:
self.logger.warn('Unknown boundary type: {}'.format(bt))
self.boundary_types = frozenset({left, right})
self.left = left
self.right = right
Expand All @@ -237,8 +237,8 @@ def width(self):
return self.domain[1] - self.domain[0]

def __repr__(self):
left = ', left=' + repr(self.left) if self.left != BoundaryType('dirichlet') else ''
right = ', right=' + repr(self.right) if self.right != BoundaryType('dirichlet') else ''
left = ', left=' + repr(self.left) if self.left != 'dirichlet' else ''
right = ', right=' + repr(self.right) if self.right != 'dirichlet' else ''
return 'LineDomain({}{})'.format(self.domain, left + right)


Expand Down
66 changes: 0 additions & 66 deletions src/pymor/domaindescriptions/boundarytypes.py

This file was deleted.

12 changes: 7 additions & 5 deletions src/pymor/domaindescriptions/interfaces.py
Expand Up @@ -3,7 +3,9 @@
# License: BSD 2-Clause License (http://opensource.org/licenses/BSD-2-Clause)

from pymor.core.interfaces import ImmutableInterface
from pymor.domaindescriptions.boundarytypes import BoundaryType


KNOWN_BOUNDARY_TYPES = {'dirichlet', 'neumann', 'robin'}


class DomainDescriptionInterface(ImmutableInterface):
Expand All @@ -14,20 +16,20 @@ class DomainDescriptionInterface(ImmutableInterface):
dim
The dimension of the domain
boundary_types
Set of |BoundaryTypes| the domain has.
Set of boundary types the domain has.
"""

dim = None
boundary_types = frozenset()

@property
def has_dirichlet(self):
return BoundaryType('dirichlet') in self.boundary_types
return 'dirichlet' in self.boundary_types

@property
def has_neumann(self):
return BoundaryType('neumann') in self.boundary_types
return 'neumann' in self.boundary_types

@property
def has_robin(self):
return BoundaryType('robin') in self.boundary_types
return 'robin' in self.boundary_types

0 comments on commit 56c004f

Please sign in to comment.