/[escript]/trunk/ripley/py_src/MultiResolutionDomain.py
ViewVC logotype

Contents of /trunk/ripley/py_src/MultiResolutionDomain.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5575 - (show annotations)
Wed Apr 1 03:17:22 2015 UTC (4 years ago) by sshaw
File MIME type: text/x-python
File size: 3819 byte(s)
sphinx now builds python doco including module-level docstrings and class __init__ docstrings, also cleared up some doco errors and added multires documentation
1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2015 by University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Open Software License version 3.0
9 # http://www.opensource.org/licenses/osl-3.0.php
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 #
15 ##############################################################################
16
17 from __future__ import division, print_function
18
19 from esys.ripley import MultiRectangle, MultiBrick
20
21 class MultiResolutionDomain(object):
22 """ Constructs domains of varying resolutions that are guaranteed to be
23 compatible for cross-domain interpolation. The parameters supplied will be
24 used to construct the coarsest resolution. No coarser domain can be
25 constructed.
26
27 Each domain of finer resolution will have the number of elements in every
28 axis of the coarsest domain multiplied by ``2**n``, where ``n`` is the level of
29 subdivision.
30 """
31 def __init__(self, dim, **kwargs):
32 """
33 :param dim: the spatial dimension of the domain to create
34 :type dim: `int`
35 :param kwargs: the arguments normally passed to a constructor of
36 Rectangle or Brick, including as the number of elements ``n0=...``, ``n1=...``, etc.
37 """
38 self.__kwargs = kwargs
39 self.__levels = {}
40 self.__dim = dim
41 self.__generateDomain(0)
42
43 def __generateDomain(self, level):
44 if self.__dim == 2:
45 self.__levels[level] = self.__newRectangle(2**level)
46 elif self.__dim == 3:
47 self.__levels[level] = self.__newBrick(2**level)
48 else:
49 raise ValueError("Invalid spatial dimension of domain: %d"%self.__dim)
50 return self.__levels[level]
51
52 def __newRectangle(self, subdivisions):
53 n0 = self.__kwargs['n0']
54 n1 = self.__kwargs['n1']
55 l0 = self.__kwargs.get('l0', 1.)
56 l1 = self.__kwargs.get('l1', 1.)
57 d0 = self.__kwargs.get('d0', -1)
58 d1 = self.__kwargs.get('d1', -1)
59 diracPoints = self.__kwargs.get('diracPoints', [])
60 tags = self.__kwargs.get('diracTags', [])
61 escriptworld = self.__kwargs.get('escriptWorld', None)
62 return MultiRectangle(n0, n1, l0, l1, d0, d1, diracPoints, tags,
63 escriptworld, subdivisions)
64
65 def __newBrick(self, subdivisions):
66 n0 = self.__kwargs['n0']
67 n1 = self.__kwargs['n1']
68 n2 = self.__kwargs['n2']
69 l0 = self.__kwargs.get('l0', 1.)
70 l1 = self.__kwargs.get('l1', 1.)
71 l2 = self.__kwargs.get('l2', 1.)
72 d0 = self.__kwargs.get('d0', -1)
73 d1 = self.__kwargs.get('d1', -1)
74 d2 = self.__kwargs.get('d2', -1)
75 diracPoints = self.__kwargs.get('diracPoints', [])
76 tags = self.__kwargs.get('diracTags', [])
77 escriptworld = self.__kwargs.get('escriptWorld', None)
78 return MultiBrick(n0, n1, n2, l0, l1, l2, d0, d1, d2, diracPoints, tags,
79 escriptworld, subdivisions)
80
81 def getMaxDepth(self):
82 """ Returns the level of the finest domain created so far """
83 return len(self.__levels) - 1
84
85 def getLevel(self, level):
86 """ Returns a domain with each element subdivided ``level`` times
87
88 :param level: the number of times to subdivide each element
89 :type level: `int`
90 """
91 if int(level) != level or level < 0:
92 raise ValueError("level must be a non-negative integer")
93 dom = self.__levels.get(level)
94 if not dom:
95 dom = self.__generateDomain(level)
96 return dom

  ViewVC Help
Powered by ViewVC 1.1.26