/[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 2061 - (hide annotations)
Wed Nov 19 03:40:21 2008 UTC (11 years, 4 months ago) by jfenwick
File MIME type: text/x-python
File size: 28485 byte(s)
Fixing some warnings from epydoc.
Disabled c++ signatures in python docstrings.
Removed references to Bruce in epydoc and the users guide.
1 ksteube 1809
2     ########################################################
3 ksteube 1312 #
4 ksteube 1809 # Copyright (c) 2003-2008 by University of Queensland
5     # Earth Systems Science Computational Center (ESSCC)
6     # http://www.uq.edu.au/esscc
7 ksteube 1312 #
8 ksteube 1809 # Primary Business: Queensland, Australia
9     # Licensed under the Open Software License version 3.0
10     # http://www.opensource.org/licenses/osl-3.0.php
11 ksteube 1312 #
12 ksteube 1809 ########################################################
13 jgs 127
14 ksteube 1809 __copyright__="""Copyright (c) 2003-2008 by University of Queensland
15     Earth Systems Science Computational Center (ESSCC)
16     http://www.uq.edu.au/esscc
17     Primary Business: Queensland, Australia"""
18 elspeth 628 __license__="""Licensed under the Open Software License version 3.0
19 ksteube 1809 http://www.opensource.org/licenses/osl-3.0.php"""
20     __url__="http://www.uq.edu.au/esscc/escript-finley"
21 jgs 127
22 jgs 149 from esys.escript import *
23     from esys.escript.modelframe import Model,ParameterSet
24     from esys import finley
25 jgs 127
26 gross 823 class FinleyReader(ParameterSet):
27 jgs 149 """
28 gross 819 reads finley mesh file.
29 jgs 147
30 gross 938 @ivar source: mesh file in finley or gmsh format
31     @type source: C{DataSource}
32 gross 823 @ivar intergrationOrder: integration order, default -1 (in).
33     @type intergrationOrder: C{int}
34 gross 938 @ivar reducedIntegrationOrder: reduced integration order, default -1 (in).
35     @type reducedIntegrationOrder: C{int}
36     @ivar optimizeLabeling: switches on optimization of the labeling of the nodes
37     @type optimizeLabeling: C{bool}
38 gross 398 """
39 gross 918 def __init__(self,**kwargs):
40 gross 823 """
41     initializes the object
42     """
43 gross 918 super(FinleyReader,self).__init__(**kwargs)
44 gross 823 self.declareParameter(source="none",
45 gross 997 dim=None,
46 gross 938 optimizeLabeling=True,
47     reducedIntegrationOrder=-1,
48     integrationOrder=-1)
49 gross 823 self.__domain=None
50 gross 398
51 gross 953
52 gross 823 def domain(self):
53     """
54     returns the domain
55    
56     @return: the domain
57     @rtype: L{Domain}
58     """
59 gross 911 if self.__domain == None:
60 gross 938 if self.source.fileformat == "fly":
61     self.__domain=finley.ReadMesh(self.source.getLocalFileName(),self.integrationOrder)
62     elif self.source.fileformat == "gmsh":
63 gross 997 if self.dim==None:
64     dim=3
65     else:
66     dim=self.dim
67     self.__domain=finley.ReadGmsh(self.source.getLocalFileName(),dim,self.integrationOrder,self.reducedIntegrationOrder, self.optimizeLabeling)
68 gross 938 else:
69     raise TypeError("unknown mesh file format %s."%self.source.fileformat)
70 gross 950 self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat))
71 gross 823 return self.__domain
72     class RectangularDomain(ParameterSet):
73 gross 398 """
74     Generates a mesh over a rectangular domain finley.
75    
76 gross 819 @ivar dim: spatial dimension, default =2 (in).
77     @type dim: spatial dimension
78     @ivar l: spatial lengths, default [1.,1.,1.] (in).
79     @type l: C{list} of C{floats}s
80     @ivar n: number of elements, default [10,10,10] (in).
81     @type n: C{list} of C{int}s
82     @ivar order: element order, default 1 (in).
83     @type order: C{int}
84     @ivar periodic: flags for periodicity, default [False,False,False] (in).
85     @type periodic: C{list} of C{bool}s
86 gross 823 @ivar intergrationOrder: integration order, default -1 (in).
87     @type intergrationOrder: C{int}
88 jgs 147 """
89 gross 918 def __init__(self,**kwargs):
90 gross 819 """
91     initializes the object
92     """
93 gross 918 super(RectangularDomain,self).__init__(**kwargs)
94 jgs 147 self.declareParameter(dim=2,\
95 jgs 127 l=[1.,1.,1.],\
96     n=[10,10,10], \
97     order=1,\
98 gross 823 periodic=[False,False,False],
99     integrationOrder=-1)
100     self.__domain=None
101 jgs 127
102 gross 823 def domain(self):
103 gross 819 """
104 gross 823 returns the domain
105    
106     @return: the domain
107     @rtype: L{Domain}
108 gross 819 """
109 gross 911 if self.__domain==None:
110 gross 823 if self.dim==2:
111 gross 911 self.__domain=finley.Rectangle(n0=self.n[0],\
112 gross 1152 n1=self.n[2],\
113 gross 823 l0=self.l[0],\
114 gross 1152 l1=self.l[2],\
115 gross 823 order=self.order, \
116     periodic0=self.periodic[0], \
117 gross 1152 periodic1=self.periodic[2], \
118 gross 823 integrationOrder=self.integrationOrder)
119     else:
120     self.__domain=finley.Brick(n0=self.n[0],\
121     n1=self.n[1],\
122     n2=self.n[2],\
123     l0=self.l[0],\
124     l1=self.l[1],\
125     l2=self.l[2],\
126     order=self.order, \
127     periodic0=self.periodic[0], \
128     periodic1=self.periodic[1], \
129     periodic2=self.periodic[2], \
130     integrationOrder=self.integrationOrder)
131     return self.__domain
132 jgs 147
133 gross 823 class UpdateGeometry(Model):
134     """
135     applies a displacement field to a domain
136    
137     @ivar displacement: displacements applied to the original mesh coordinates (in).
138     @type displacement: L{escript.Vector}
139     @ivar domain: domain
140     @type domain: L{escript.Domain}
141     """
142 gross 918 def __init__(self,**kwargs):
143 gross 823 """
144     set-up the object
145     """
146 gross 918 super(UpdateGeometry, self).__init__(**kwargs)
147 gross 823 self.declareParameter(domain=None,\
148     displacement=None)
149 jgs 147
150 gross 823
151     def doInitialization(self):
152     """
153     initialize model
154     """
155     self.__x=self.domain.getX()
156     self.__reset=True
157    
158     def doStepPreprocessing(self,dt):
159     """
160     applies the current L{displacement} to mesh nodes if required.
161     """
162     if self.__reset:
163     self.trace("mesh nodes updated.")
164     self.domain.setX(self.__x+self.displacement)
165     self.__reset=False
166    
167     def doStep(self,dt):
168     """
169     applies the current L{displacement} to mesh nodes.
170     """
171     self.trace("mesh nodes updated.")
172     self.domain.setX(self.__x+self.displacement)
173     self.__reset=True
174    
175     def doStepPostprocessing(self,dt):
176     """
177     marks nodes as beeing updated.
178     """
179     self.__reset=False
180    
181 gross 953 class ConstrainerOverBox(Model):
182     """
183     Creates a characteristic function for the location of constraints
184     for all components of a value and selects the value from an initial value
185     ate these locations.
186    
187     In the case that the spatial dimension is two, the arguments front and back are ignored.
188    
189     @ivar domain: domain (in).
190     @ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
191     @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
192     @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
193     @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
194     @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
195     @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
196     @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
197     """
198     def __init__(self,**kwargs):
199     super(ConstrainerOverBox, self).__init__(**kwargs)
200     self.declareParameter(domain=None, \
201     value=None, \
202     left=False, \
203     right=False, \
204     top=False, \
205     bottom=False, \
206     front=False, \
207     back=False, \
208     tol=1.e-8)
209     self.__value_of_constraint = None
210     self.__location_of_constraint=None
211     def location_of_constraint(self):
212     """
213     return the values used to constrain a solution
214    
215     @return: the mask marking the locations of the constraints
216     @rtype: L{escript.Scalar}
217     """
218     if self.__location_of_constraint == None: self.__setOutput()
219     return self.__location_of_constraint
220    
221     def value_of_constraint(self):
222     """
223     return the values used to constrain a solution
224    
225     @return: values to be used at the locations of the constraints. If
226 jfenwick 2061 C{value} is not given C{None} is rerturned.
227 gross 953 @rtype: L{escript.Scalar}
228     """
229     if self.__location_of_constraint == None: self.__setOutput()
230     return self.__value_of_constraint
231    
232     def __setOutput(self):
233 gross 993 if self.__location_of_constraint == None:
234     x=self.domain.getX()
235     val=self.value
236     if isinstance(val, int) or isinstance(val, float):
237     shape=()
238     elif isinstance(val, list) or isinstance(val, tuple) :
239     shape=(len(val),)
240     elif isinstance(val, numarray.NumArray):
241     shape=val.shape
242     elif val == None:
243     shape=()
244     else:
245     shape=val.getShape()
246     self.__location_of_constraint=Data(0,shape,x.getFunctionSpace())
247     if self.domain.getDim()==3:
248     x0,x1,x2=x[0],x[1],x[2]
249     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
250     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
251     if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
252     if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
253     if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)
254     if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)
255     else:
256     x0,x1=x[0],x[1]
257     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
258     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
259     if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
260     if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
261     if not self.value == None:
262     self.__value_of_constraint=self.__location_of_constraint*self.value
263 gross 911 class ScalarConstrainerOverBox(Model):
264 gross 823 """
265     Creates a characteristic function for the location of constraints
266     for a scalar value and selects the value from an initial value
267     ate these locations.
268 jgs 127
269 gross 823 In the case that the spatial dimension is two, the arguments front and back are ignored.
270 jgs 127
271 gross 823 @ivar domain: domain (in).
272     @ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in).
273     @ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in).
274     @ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in).
275     @ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in).
276     @ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in).
277     @ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in).
278     @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
279     """
280 gross 918 def __init__(self,**kwargs):
281     super(ScalarConstrainerOverBox, self).__init__(**kwargs)
282 jgs 127 self.declareParameter(domain=None, \
283 gross 823 value=None, \
284 jgs 147 left=False, \
285     right=False, \
286     top=False, \
287     bottom=False, \
288     front=False, \
289 gross 819 back=False, \
290 gross 823 tol=1.e-8)
291     self.__value_of_constraint = None
292     self.__location_of_constraint=None
293     def location_of_constraint(self):
294 jgs 149 """
295 gross 823 return the values used to constrain a solution
296    
297     @return: the mask marking the locations of the constraints
298     @rtype: L{escript.Scalar}
299 jgs 149 """
300 gross 908 if self.__location_of_constraint == None: self.__setOutput()
301 gross 823 return self.__location_of_constraint
302    
303     def value_of_constraint(self):
304     """
305     return the values used to constrain a solution
306    
307     @return: values to be used at the locations of the constraints. If
308 jfenwick 2061 C{value} is not given C{None} is rerturned.
309 gross 823 @rtype: L{escript.Scalar}
310     """
311 gross 908 if self.__location_of_constraint == None: self.__setOutput()
312 gross 823 return self.__value_of_constraint
313    
314     def __setOutput(self):
315 gross 819 x=self.domain.getX()
316 gross 823 self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
317 gross 819 if self.domain.getDim()==3:
318     x0,x1,x2=x[0],x[1],x[2]
319 gross 823 if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
320     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
321     if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
322     if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
323     if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol)
324     if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol)
325 gross 819 else:
326     x0,x1=x[0],x[1]
327 gross 823 if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol)
328     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol)
329     if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol)
330     if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol)
331 gross 993 if not self.value == None:
332 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value
333 jgs 147
334 gross 911 class VectorConstrainerOverBox(Model):
335 jgs 149 """
336 gross 819 Creates a characteristic function for the location of constraints vector value.
337     In the case that the spatial dimension is two, the arguments front and
338     back as well as the third component of each argument is ignored.
339 jgs 127
340 gross 819 @ivar domain: domain
341     @ivar left: list of three boolean. left[i]==True sets a constraint for the i-th component at the left face of the domain (x[0]=min x[0]),
342     default [False,False,False] (in).
343     @ivar right: list of three boolean. left[i]==True sets a constraint for the i-th component at the right face of the domain (x[0]=max x[0]),
344     default [False,False,False] (in).
345     @ivar top: list of three boolean. left[i]==True sets a constraint for the i-th component at the top face of the domain (x[1]=min x[1]),
346     default [False,False,False] (in).
347     @ivar bottom: list of three boolean. left[i]==True sets a constraint for the i-th component at the bottom face of the domain (x[1]=min x[1]),
348     default [False,False,False] (in).
349     @ivar front: list of three boolean. left[i]==True sets a constraint for the i-th component at the front face of the domain (x[2]=min x[2]),
350     default [False,False,False] (in).
351     @ivar back: list of three boolean. left[i]==True sets a constraint for the i-th component at the back face of the domain (x[2]=max x[2]),
352     default [False,False,False] (in).
353     @ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
354 jgs 127 """
355 gross 918 def __init__(self, **kwargs):
356     super(VectorConstrainerOverBox, self).__init__(**kwargs)
357 jgs 127 self.declareParameter(domain=None, \
358 gross 823 value=None, \
359 gross 1152 left=[False ,False ,False ], \
360     right=[False ,False ,False ], \
361     top=[False ,False ,False ], \
362     bottom=[False ,False ,False ], \
363     front=[False ,False ,False ], \
364     back=[False ,False ,False ], \
365 gross 823 tol=1.e-8)
366     self.__value_of_constraint = None
367     self.__location_of_constraint=None
368    
369     def location_of_constraint(self):
370 jgs 149 """
371 gross 823 return the values used to constrain a solution
372    
373     @return: the mask marking the locations of the constraints
374     @rtype: L{escript.Vector}
375 jgs 149 """
376 gross 908 if self.__location_of_constraint == None: self.__setOutput()
377 gross 823 return self.__location_of_constraint
378    
379     def value_of_constraint(self):
380     """
381     return the values used to constrain a solution
382 jgs 149
383 gross 823 @return: values to be used at the locations of the constraints. If
384 jfenwick 2061 C{value} is not given C{None} is rerturned.
385 gross 823 @rtype: L{escript.Vector}
386     """
387 gross 908 if self.__location_of_constraint == None: self.__setOutput()
388 gross 823 return self.__value_of_constraint
389    
390     def __setOutput(self):
391     x=self.domain.getX()
392     self.__location_of_constraint=Vector(0,x.getFunctionSpace())
393     if self.domain.getDim()==3:
394     x0,x1,x2=x[0],x[1],x[2]
395     left_mask=whereZero(x0-inf(x0),self.tol)
396     if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.,0.]
397     if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.,0.]
398     if self.left[2]: self.__location_of_constraint+=left_mask*[0.,0.,1.]
399     right_mask=whereZero(x0-sup(x0),self.tol)
400     if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.,0.]
401     if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.,0.]
402     if self.right[2]: self.__location_of_constraint+=right_mask*[0.,0.,1.]
403     front_mask=whereZero(x1-inf(x1),self.tol)
404     if self.front[0]: self.__location_of_constraint+=front_mask*[1.,0.,0.]
405     if self.front[1]: self.__location_of_constraint+=front_mask*[0.,1.,0.]
406     if self.front[2]: self.__location_of_constraint+=front_mask*[0.,0.,1.]
407     back_mask=whereZero(x1-sup(x1),self.tol)
408     if self.back[0]: self.__location_of_constraint+=back_mask*[1.,0.,0.]
409     if self.back[1]: self.__location_of_constraint+=back_mask*[0.,1.,0.]
410     if self.back[2]: self.__location_of_constraint+=back_mask*[0.,0.,1.]
411     bottom_mask=whereZero(x2-inf(x2),self.tol)
412     if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.,0.]
413     if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.,0.]
414     if self.bottom[2]: self.__location_of_constraint+=bottom_mask*[0.,0.,1.]
415     top_mask=whereZero(x2-sup(x2),self.tol)
416     if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.,0.]
417     if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.,0.]
418     if self.top[2]: self.__location_of_constraint+=top_mask*[0.,0.,1.]
419 gross 993 if not self.value == None:
420 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value
421     else:
422     x0,x1=x[0],x[1]
423     left_mask=whereZero(x0-inf(x0),self.tol)
424     if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
425     if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
426     right_mask=whereZero(x0-sup(x0),self.tol)
427     if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
428     if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
429     bottom_mask=whereZero(x1-inf(x1),self.tol)
430     if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
431     if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
432     top_mask=whereZero(x1-sup(x1),self.tol)
433     if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
434     if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
435 gross 993 if not self.value == None:
436 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value[:2]
437    
438 gross 1152 class ConstrainerAtBoxVertex(Model):
439     """
440     Creates a characteristic function for the location of constraints
441     for all components of a value and selects the value from an initial value
442     ate these locations.
443    
444     In the case that the spatial dimension is two, the arguments front and back are ignored.
445    
446     @ivar domain: domain (in).
447     @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
448     """
449     def __init__(self,**kwargs):
450     super(ConstrainerAtBoxVertex, self).__init__(**kwargs)
451     self.declareParameter(domain=None, \
452     value=None, \
453     tol=1.e-8)
454     self.__value_of_constraint = None
455     self.__location_of_constraint=None
456     def location_of_constraint(self):
457     """
458     return the values used to constrain a solution
459    
460     @return: the mask marking the locations of the constraints
461     @rtype: L{escript.Scalar}
462     """
463     if self.__location_of_constraint == None: self.__setOutput()
464     return self.__location_of_constraint
465    
466     def value_of_constraint(self):
467     """
468     return the values used to constrain a solution
469    
470     @return: values to be used at the locations of the constraints. If
471 jfenwick 2061 C{value} is not given C{None} is rerturned.
472 gross 1152 @rtype: L{escript.Scalar}
473     """
474     if self.__location_of_constraint == None: self.__setOutput()
475     return self.__value_of_constraint
476    
477     def __setOutput(self):
478     if self.__location_of_constraint == None:
479     x=self.domain.getX()
480     val=self.value
481     if isinstance(val, int) or isinstance(val, float):
482     shape=()
483     elif isinstance(val, list) or isinstance(val, tuple) :
484     shape=(len(val),)
485     elif isinstance(val, numarray.NumArray):
486     shape=val.shape
487     elif val == None:
488     shape=()
489     else:
490     shape=val.getShape()
491     if self.domain.getDim()==3:
492     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
493     else:
494     vertex=[inf(x[0]),inf(x[1])]
495     self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)
496     if not self.value == None:
497     self.__value_of_constraint=self.__location_of_constraint*self.value
498     class ScalarConstrainerAtBoxVertex(Model):
499     """
500     Creates a characteristic function for the location of constraints
501     for a scalar value and selects the value from an initial value
502     ate these locations.
503    
504     In the case that the spatial dimension is two, the arguments front and back are ignored.
505    
506     @ivar domain: domain (in).
507     @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
508     """
509     def __init__(self,**kwargs):
510     super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)
511     self.declareParameter(domain=None, \
512     value=None, \
513     tol=1.e-8)
514     self.__value_of_constraint = None
515     self.__location_of_constraint=None
516     def location_of_constraint(self):
517     """
518     return the values used to constrain a solution
519    
520     @return: the mask marking the locations of the constraints
521     @rtype: L{escript.Scalar}
522     """
523     if self.__location_of_constraint == None: self.__setOutput()
524     return self.__location_of_constraint
525    
526     def value_of_constraint(self):
527     """
528     return the values used to constrain a solution
529    
530     @return: values to be used at the locations of the constraints. If
531 jfenwick 2061 C{value} is not given C{None} is rerturned.
532 gross 1152 @rtype: L{escript.Scalar}
533     """
534     if self.__location_of_constraint == None: self.__setOutput()
535     return self.__value_of_constraint
536    
537     def __setOutput(self):
538     x=self.domain.getX()
539     self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
540     if self.domain.getDim()==3:
541     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
542     else:
543     vertex=[inf(x[0]),inf(x[1])]
544     self.__location_of_constraint=whereZero(length(x-vertex),self.tol)
545     if not self.value == None:
546     self.__value_of_constraint=self.__location_of_constraint*self.value
547    
548     class VectorConstrainerAtBoxVertex(Model):
549     """
550     Creates a characteristic function for the location of constraints vector value.
551     In the case that the spatial dimension is two, the arguments front and
552     back as well as the third component of each argument is ignored.
553    
554     @ivar domain: domain
555     @ivar comp_mask: list of three boolean. comp_mask[i]==True sets a constraint for the i-th component at the left, front, bottom vertex, default [False,False,False] (in).
556     @ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
557     """
558     def __init__(self, **kwargs):
559     super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)
560     self.declareParameter(domain=None, \
561     value=None, \
562     comp_mask=[False, False, False],
563     tol=1.e-8)
564     self.__value_of_constraint = None
565     self.__location_of_constraint=None
566    
567     def location_of_constraint(self):
568     """
569     return the values used to constrain a solution
570    
571     @return: the mask marking the locations of the constraints
572     @rtype: L{escript.Vector}
573     """
574     if self.__location_of_constraint == None: self.__setOutput()
575     return self.__location_of_constraint
576    
577     def value_of_constraint(self):
578     """
579     return the values used to constrain a solution
580    
581     @return: values to be used at the locations of the constraints. If
582 jfenwick 2061 C{value} is not given C{None} is rerturned.
583 gross 1152 @rtype: L{escript.Vector}
584     """
585     if self.__location_of_constraint == None: self.__setOutput()
586     return self.__value_of_constraint
587    
588     def __setOutput(self):
589     x=self.domain.getX()
590     self.__location_of_constraint=Vector(0,x.getFunctionSpace())
591     if self.domain.getDim()==3:
592     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
593     msk=numarray.zeros((3,))
594     if self.comp_mask[0]: msk[0]=1
595     if self.comp_mask[1]: msk[1]=1
596     if self.comp_mask[2]: msk[2]=1
597     else:
598     vertex=[inf(x[0]),inf(x[1])]
599     msk=numarray.zeros((2,))
600     if self.comp_mask[0]: msk[0]=1
601     if self.comp_mask[1]: msk[1]=1
602     self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numarray.ones(shape)
603     if not self.value == None:
604     self.__value_of_constraint=self.__location_of_constraint*self.value
605    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26