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

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

Parent Directory Parent Directory | Revision Log Revision Log


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