/[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 155 - (show annotations)
Wed Nov 9 02:02:19 2005 UTC (17 years, 4 months ago) by jgs
File MIME type: text/x-python
File size: 10574 byte(s)
move all directories from trunk/esys2 into trunk and remove esys2

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26