/[escript]/trunk/modellib/py_src/geometry.py
ViewVC logotype

Contents of /trunk/modellib/py_src/geometry.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 147 - (show annotations)
Fri Aug 12 01:45:47 2005 UTC (14 years, 4 months ago) by jgs
Original Path: trunk/esys2/modellib/py_src/geometry.py
File MIME type: text/x-python
File size: 10385 byte(s)
erge of development branch dev-02 back to main trunk on 2005-08-12

1 # $Id$
2
3
4 from escript.escript import *
5 from escript.modelframe import Model
6 from finley import finley
7
8 class RectangularDomain(Model):
9 """generates a mesh over a rectangular domain finley
10
11 dim
12 l
13 n
14 order
15 periodic
16 intergration order
17
18 domain (callable)
19
20 """
21 def __init__(self,debug=False):
22 Model.__init__(self,debug=debug)
23 self.declareParameter(dim=2,\
24 l=[1.,1.,1.],\
25 n=[10,10,10], \
26 order=1,\
27 periodic=[False,False,False],\
28 integrationOrder=-1)
29 self._domain=None
30
31 def domain(self):
32 if self._domain==None:
33 if self.dim==2:
34 self._domain=finley.Rectangle(n0=self.n[0],\
35 n1=self.n[1],\
36 l0=self.l[0],\
37 l1=self.l[1],\
38 order=self.order, \
39 periodic0=self.periodic[0], \
40 periodic1=self.periodic[1], \
41 integrationOrder=self.integrationOrder)
42 else:
43 self._domain=finley.Brick(n0=self.n[0],\
44 n1=self.n[1],\
45 n2=self.n[2],\
46 l0=self.l[0],\
47 l1=self.l[1],\
48 l2=self.l[2],\
49 order=self.order, \
50 periodic0=self.periodic[0], \
51 periodic1=self.periodic[1], \
52 periodic2=self.periodic[2], \
53 integrationOrder=self.integrationOrder)
54
55 return self._domain
56
57 class ScalarConstrainer(Model):
58 """@brief creates a characteristic function for the location of constraints for a scalar value
59
60 @param domain (in) - rectangular domain
61 @param left (in) - True to set a constraint at the left face of the domain (x[0]=min x[0]), default is False
62 @param right (in) - True to set a constraint at the left face of the domain (x[0]=max x[0]), default is False
63 @param top (in) - True to set a constraint at the left face of the domain (x[1]=min x[1]), default is False
64 @param bottom (in) - True to set a constraint at the left face of the domain (x[1]=max x[1]), default is False
65 @param front (in) - True to set a constraint at the left face of the domain (x[2]=min x[2]), default is False
66 @param back (in) - True to set a constraint at the left face of the domain (x[2]=max x[2]), default is False
67 @param location_of_constraint (out) - object that defines the location of the constraints.
68
69 In the case that the spatial dimension is two, teh arguments front and back are ignored
70
71 """
72 def __init__(self,debug=False):
73 Model.__init__(self,debug=debug)
74 self.declareParameter(domain=None, \
75 left=False, \
76 right=False, \
77 top=False, \
78 bottom=False, \
79 front=False, \
80 back=False)
81 self._location_of_constraint=None
82
83 def location_of_constraint(self):
84 """returns the mask of the location of constraint"""
85 if self._location_of_constraint==None:
86 x=self.domain.getX()
87 self._location_of_constraint=Scalar(0,x.getFunctionSpace())
88 if self.domain.getDim()==3:
89 if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()
90 if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()
91 if self.front: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()
92 if self.back: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()
93 if self.bottom: self._location_of_constraint+=(x[2]-inf(x[2])).whereZero()
94 if self.top: self._location_of_constraint+=(x[2]-sup(x[2])).whereZero()
95 else:
96 if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero()
97 if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero()
98 if self.bottom: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero()
99 if self.top: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero()
100 return self._location_of_constraint
101
102 class VectorConstrainer(Model):
103 """@brief creates a characteristic function for the location of constraints for a scalar value
104
105 @param domain (in) - rectangular domain
106 @param left (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the left
107 face of the domain (x[0]=min x[0]), default is [False,False,False]
108 @param right (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the right
109 face of the domain (x[0]=max x[0]), default is [False,False,False]
110 @param top (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the top
111 face of the domain (x[1]=min x[1]), default is [False,False,False]
112 @param bottom (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the bottom
113 face of the domain (x[1]=min x[1]), default is [False,False,False]
114 @param front (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the front
115 face of the domain (x[2]=min x[2]), default is [False,False,False]
116 @param back (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the back
117 face of the domain (x[2]=max x[2]), default is [False,False,False]
118 @param location_of_constraint (callable) - object that defines the location of the constraints for each vector component.
119
120 In the case that the spatial dimension is two, thh arguments front and back as well as the third component of each argument is ignored.
121
122 """
123 def __init__(self,debug=False):
124 Model.__init__(self,debug=debug)
125 self.declareParameter(domain=None, \
126 left=[0,0,0], \
127 right=[0,0,0], \
128 top=[0,0,0], \
129 bottom=[0,0,0], \
130 front=[0,0,0],
131 back=[0,0,0])
132 self._location_of_constraint=None
133 def location_of_constraint(self):
134 """returns the mask of the location of constraint"""
135 if self._location_of_constraint==None:
136 x=self.domain.getX()
137 self._location_of_constraint=Vector(0,x.getFunctionSpace())
138 if self.domain.getDim()==3:
139 left_mask=(x[0]-inf(x[0])).whereZero()
140 if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.]
141 if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.]
142 if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.]
143 right_mask=(x[0]-sup(x[0])).whereZero()
144 if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.]
145 if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.]
146 if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.]
147 front_mask=(x[1]-inf(x[1])).whereZero()
148 if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.]
149 if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.]
150 if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.]
151 back_mask=(x[1]-sup(x[1])).whereZero()
152 if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.]
153 if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.]
154 if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.]
155 bottom_mask=(x[2]-inf(x[2])).whereZero()
156 if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.]
157 if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.]
158 if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.]
159 top_mask=(x[2]-sup(x[2])).whereZero()
160 if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.]
161 if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.]
162 if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.]
163 else:
164 left_mask=(x[0]-inf(x[0])).whereZero()
165 if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.]
166 if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.]
167 right_mask=(x[0]-sup(x[0])).whereZero()
168 if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.]
169 if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.]
170 bottom_mask=(x[1]-inf(x[1])).whereZero()
171 if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.]
172 if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.]
173 top_mask=(x[1]-sup(x[1])).whereZero()
174 if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.]
175 if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.]
176 return self._location_of_constraint

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.26