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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 149 - (hide annotations)
Thu Sep 1 03:31:39 2005 UTC (17 years, 6 months ago) by jgs
File MIME type: text/x-python
File size: 10574 byte(s)
Merge of development branch dev-02 back to main trunk on 2005-09-01

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     class RectangularDomain(Model):
9 jgs 149 """
10     Generates a mesh over a rectangular domain finley.
11 jgs 147
12 jgs 149 @ivar dim:
13     @ivar l:
14     @ivar n:
15     @ivar order:
16     @ivar periodic:
17     @ivar intergration order:
18     @ivar domain (callable):
19 jgs 147 """
20 jgs 127 def __init__(self,debug=False):
21     Model.__init__(self,debug=debug)
22 jgs 147 self.declareParameter(dim=2,\
23 jgs 127 l=[1.,1.,1.],\
24     n=[10,10,10], \
25     order=1,\
26     periodic=[False,False,False],\
27     integrationOrder=-1)
28 jgs 147 self._domain=None
29 jgs 127
30 jgs 147 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 jgs 148 class ScalarConstrainer(ParameterSet):
57 jgs 149 """
58     Creates a characteristic function for the location of constraints
59     for a scalar value.
60 jgs 127
61 jgs 149 In the case that the spatial dimension is two, the arguments front
62     and back are ignored.
63 jgs 127
64 jgs 149 @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 jgs 127 """
80     def __init__(self,debug=False):
81 jgs 148 ParameterSet.__init__(self,debug=debug)
82 jgs 127 self.declareParameter(domain=None, \
83 jgs 147 left=False, \
84     right=False, \
85     top=False, \
86     bottom=False, \
87     front=False, \
88     back=False)
89     self._location_of_constraint=None
90 jgs 127
91 jgs 147 def location_of_constraint(self):
92 jgs 149 """
93     Returns the mask of the location of constraint.
94     """
95 jgs 147 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 jgs 148 class VectorConstrainer(ParameterSet):
113 jgs 149 """
114     Creates a characteristic function for the location of constraints
115     for a scalar value.
116 jgs 127
117 jgs 149 @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 jgs 127
144 jgs 149 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 jgs 127 """
147     def __init__(self,debug=False):
148 jgs 148 ParameterSet.__init__(self,debug=debug)
149 jgs 127 self.declareParameter(domain=None, \
150 jgs 147 left=[0,0,0], \
151     right=[0,0,0], \
152     top=[0,0,0], \
153     bottom=[0,0,0], \
154 jgs 127 front=[0,0,0],
155 jgs 147 back=[0,0,0])
156     self._location_of_constraint=None
157     def location_of_constraint(self):
158 jgs 149 """
159     Returns the mask of the location of constraint.
160     """
161 jgs 147 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 jgs 149
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