/[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 2881 - (hide annotations)
Thu Jan 28 02:03:15 2010 UTC (10 years, 2 months ago) by jfenwick
File MIME type: text/x-python
File size: 28754 byte(s)
Don't panic.
Updating copyright stamps

1 ksteube 1809
2     ########################################################
3 ksteube 1312 #
4 jfenwick 2881 # Copyright (c) 2003-2010 by University of Queensland
5 ksteube 1809 # 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 jfenwick 2881 __copyright__="""Copyright (c) 2003-2010 by University of Queensland
15 ksteube 1809 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 jfenwick 2344 __url__="https://launchpad.net/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 jfenwick 2625 :ivar source: mesh file in finley or gmsh format
31     :type source: ``DataSource``
32     :ivar intergrationOrder: integration order, default -1 (in).
33     :type intergrationOrder: ``int``
34     :ivar reducedIntegrationOrder: reduced integration order, default -1 (in).
35     :type reducedIntegrationOrder: ``int``
36     :ivar optimizeLabeling: switches on optimization of the labeling of the nodes
37     :type optimizeLabeling: ``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 jfenwick 2625 :return: the domain
57     :rtype: `Domain`
58 gross 823 """
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 jfenwick 2625 :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: ``list`` of ``float``
80     :ivar n: number of elements, default [10,10,10] (in).
81     :type n: ``list`` of ``int``
82     :ivar order: element order, default 1 (in).
83     :type order: ``int``
84     :ivar periodic: flags for periodicity, default [False,False,False] (in).
85     :type periodic: ``list`` of ``bool``
86     :ivar intergrationOrder: integration order, default -1 (in).
87     :type intergrationOrder: ``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 jfenwick 2625 :return: the domain
107     :rtype: `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 jfenwick 2625 :ivar displacement: displacements applied to the original mesh coordinates (in).
138     :type displacement: `escript.Vector`
139     :ivar domain: domain
140     :type domain: `escript.Domain`
141 gross 823 """
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 jfenwick 2625 applies the current `displacement` to mesh nodes if required.
161 gross 823 """
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 jfenwick 2625 applies the current `displacement` to mesh nodes.
170 gross 823 """
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 jfenwick 2625 :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 gross 953 """
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 jfenwick 2625 :return: the mask marking the locations of the constraints
216     :rtype: `escript.Scalar`
217 gross 953 """
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 jfenwick 2625 :return: values to be used at the locations of the constraints. If
226     ``value`` is not given ``None`` is rerturned.
227     :rtype: `escript.Scalar`
228 gross 953 """
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 jfenwick 2455 elif isinstance(val, numpy.ndarray):
241 gross 993 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 jfenwick 2625 :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 gross 823 """
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 jfenwick 2625 :return: the mask marking the locations of the constraints
298     :rtype: `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 jfenwick 2625 :return: values to be used at the locations of the constraints. If
308     ``value`` is not given ``None`` is rerturned.
309     :rtype: `escript.Scalar`
310 gross 823 """
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 2236 d=max(sup(x0)-inf(x0), sup(x1)-inf(x1), sup(x2)-inf(x2))
320     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol*d)
321     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol*d)
322     if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol*d)
323     if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol*d)
324     if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol*d)
325     if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol*d)
326 gross 819 else:
327     x0,x1=x[0],x[1]
328 gross 2236 d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
329     if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol*d)
330     if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol*d)
331     if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol*d)
332     if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol*d)
333 gross 993 if not self.value == None:
334 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value
335 jgs 147
336 gross 911 class VectorConstrainerOverBox(Model):
337 jgs 149 """
338 gross 819 Creates a characteristic function for the location of constraints vector value.
339     In the case that the spatial dimension is two, the arguments front and
340     back as well as the third component of each argument is ignored.
341 jgs 127
342 jfenwick 2625 :ivar domain: domain
343     :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]),
344 gross 819 default [False,False,False] (in).
345 jfenwick 2625 :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]),
346 gross 819 default [False,False,False] (in).
347 jfenwick 2625 :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]),
348 gross 819 default [False,False,False] (in).
349 jfenwick 2625 :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]),
350 gross 819 default [False,False,False] (in).
351 jfenwick 2625 :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]),
352 gross 819 default [False,False,False] (in).
353 jfenwick 2625 :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]),
354 gross 819 default [False,False,False] (in).
355 jfenwick 2625 :ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in).
356 jgs 127 """
357 gross 918 def __init__(self, **kwargs):
358     super(VectorConstrainerOverBox, self).__init__(**kwargs)
359 jgs 127 self.declareParameter(domain=None, \
360 gross 823 value=None, \
361 gross 1152 left=[False ,False ,False ], \
362     right=[False ,False ,False ], \
363     top=[False ,False ,False ], \
364     bottom=[False ,False ,False ], \
365     front=[False ,False ,False ], \
366     back=[False ,False ,False ], \
367 gross 823 tol=1.e-8)
368     self.__value_of_constraint = None
369     self.__location_of_constraint=None
370    
371     def location_of_constraint(self):
372 jgs 149 """
373 gross 823 return the values used to constrain a solution
374    
375 jfenwick 2625 :return: the mask marking the locations of the constraints
376     :rtype: `escript.Vector`
377 jgs 149 """
378 gross 908 if self.__location_of_constraint == None: self.__setOutput()
379 gross 823 return self.__location_of_constraint
380    
381     def value_of_constraint(self):
382     """
383     return the values used to constrain a solution
384 jgs 149
385 jfenwick 2625 :return: values to be used at the locations of the constraints. If
386     ``value`` is not given ``None`` is rerturned.
387     :rtype: `escript.Vector`
388 gross 823 """
389 gross 908 if self.__location_of_constraint == None: self.__setOutput()
390 gross 823 return self.__value_of_constraint
391    
392     def __setOutput(self):
393     x=self.domain.getX()
394     self.__location_of_constraint=Vector(0,x.getFunctionSpace())
395     if self.domain.getDim()==3:
396     x0,x1,x2=x[0],x[1],x[2]
397 gross 2236 d=max(sup(x0)-inf(x0), sup(x1)-inf(x1), sup(x2)-inf(x2))
398     left_mask=whereZero(x0-inf(x0),self.tol*d)
399 gross 823 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.,0.]
400     if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.,0.]
401     if self.left[2]: self.__location_of_constraint+=left_mask*[0.,0.,1.]
402 gross 2236 right_mask=whereZero(x0-sup(x0),self.tol*d)
403 gross 823 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.,0.]
404     if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.,0.]
405     if self.right[2]: self.__location_of_constraint+=right_mask*[0.,0.,1.]
406 gross 2236 front_mask=whereZero(x1-inf(x1),self.tol*d)
407 gross 823 if self.front[0]: self.__location_of_constraint+=front_mask*[1.,0.,0.]
408     if self.front[1]: self.__location_of_constraint+=front_mask*[0.,1.,0.]
409     if self.front[2]: self.__location_of_constraint+=front_mask*[0.,0.,1.]
410 gross 2236 back_mask=whereZero(x1-sup(x1),self.tol*d)
411 gross 823 if self.back[0]: self.__location_of_constraint+=back_mask*[1.,0.,0.]
412     if self.back[1]: self.__location_of_constraint+=back_mask*[0.,1.,0.]
413     if self.back[2]: self.__location_of_constraint+=back_mask*[0.,0.,1.]
414 gross 2236 bottom_mask=whereZero(x2-inf(x2),self.tol*d)
415 gross 823 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.,0.]
416     if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.,0.]
417     if self.bottom[2]: self.__location_of_constraint+=bottom_mask*[0.,0.,1.]
418 gross 2236 top_mask=whereZero(x2-sup(x2),self.tol*d)
419 gross 823 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.,0.]
420     if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.,0.]
421     if self.top[2]: self.__location_of_constraint+=top_mask*[0.,0.,1.]
422 gross 993 if not self.value == None:
423 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value
424     else:
425     x0,x1=x[0],x[1]
426 gross 2236 d=max(sup(x0)-inf(x0), sup(x1)-inf(x1))
427     left_mask=whereZero(x0-inf(x0),self.tol*d)
428 gross 823 if self.left[0]: self.__location_of_constraint+=left_mask*[1.,0.]
429     if self.left[1]: self.__location_of_constraint+=left_mask*[0.,1.]
430 gross 2236 right_mask=whereZero(x0-sup(x0),self.tol*d)
431 gross 823 if self.right[0]: self.__location_of_constraint+=right_mask*[1.,0.]
432     if self.right[1]: self.__location_of_constraint+=right_mask*[0.,1.]
433 gross 2236 bottom_mask=whereZero(x1-inf(x1),self.tol*d)
434 gross 823 if self.bottom[0]: self.__location_of_constraint+=bottom_mask*[1.,0.]
435     if self.bottom[1]: self.__location_of_constraint+=bottom_mask*[0.,1.]
436 gross 2236 top_mask=whereZero(x1-sup(x1),self.tol*d)
437 gross 823 if self.top[0]: self.__location_of_constraint+=top_mask*[1.,0.]
438     if self.top[1]: self.__location_of_constraint+=top_mask*[0.,1.]
439 gross 993 if not self.value == None:
440 gross 823 self.__value_of_constraint=self.__location_of_constraint*self.value[:2]
441    
442 gross 1152 class ConstrainerAtBoxVertex(Model):
443     """
444     Creates a characteristic function for the location of constraints
445     for all components of a value and selects the value from an initial value
446     ate these locations.
447    
448     In the case that the spatial dimension is two, the arguments front and back are ignored.
449    
450 jfenwick 2625 :ivar domain: domain (in).
451     :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
452 gross 1152 """
453     def __init__(self,**kwargs):
454     super(ConstrainerAtBoxVertex, self).__init__(**kwargs)
455     self.declareParameter(domain=None, \
456     value=None, \
457     tol=1.e-8)
458     self.__value_of_constraint = None
459     self.__location_of_constraint=None
460     def location_of_constraint(self):
461     """
462     return the values used to constrain a solution
463    
464 jfenwick 2625 :return: the mask marking the locations of the constraints
465     :rtype: `escript.Scalar`
466 gross 1152 """
467     if self.__location_of_constraint == None: self.__setOutput()
468     return self.__location_of_constraint
469    
470     def value_of_constraint(self):
471     """
472     return the values used to constrain a solution
473    
474 jfenwick 2625 :return: values to be used at the locations of the constraints. If
475     ``value`` is not given ``None`` is rerturned.
476     :rtype: `escript.Scalar`
477 gross 1152 """
478     if self.__location_of_constraint == None: self.__setOutput()
479     return self.__value_of_constraint
480    
481     def __setOutput(self):
482     if self.__location_of_constraint == None:
483     x=self.domain.getX()
484     val=self.value
485     if isinstance(val, int) or isinstance(val, float):
486     shape=()
487     elif isinstance(val, list) or isinstance(val, tuple) :
488     shape=(len(val),)
489 jfenwick 2455 elif isinstance(val, numpy.ndarray):
490 gross 1152 shape=val.shape
491     elif val == None:
492     shape=()
493     else:
494     shape=val.getShape()
495     if self.domain.getDim()==3:
496     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
497     else:
498     vertex=[inf(x[0]),inf(x[1])]
499 jfenwick 2455 self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numpy.ones(shape)
500 gross 1152 if not self.value == None:
501     self.__value_of_constraint=self.__location_of_constraint*self.value
502     class ScalarConstrainerAtBoxVertex(Model):
503     """
504     Creates a characteristic function for the location of constraints
505     for a scalar value and selects the value from an initial value
506     ate these locations.
507    
508     In the case that the spatial dimension is two, the arguments front and back are ignored.
509    
510 jfenwick 2625 :ivar domain: domain (in).
511     :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
512 gross 1152 """
513     def __init__(self,**kwargs):
514     super(ScalarConstrainerAtBoxVertex, self).__init__(**kwargs)
515     self.declareParameter(domain=None, \
516     value=None, \
517     tol=1.e-8)
518     self.__value_of_constraint = None
519     self.__location_of_constraint=None
520     def location_of_constraint(self):
521     """
522     return the values used to constrain a solution
523    
524 jfenwick 2625 :return: the mask marking the locations of the constraints
525     :rtype: `escript.Scalar`
526 gross 1152 """
527     if self.__location_of_constraint == None: self.__setOutput()
528     return self.__location_of_constraint
529    
530     def value_of_constraint(self):
531     """
532     return the values used to constrain a solution
533    
534 jfenwick 2625 :return: values to be used at the locations of the constraints. If
535     ``value`` is not given ``None`` is rerturned.
536     :rtype: `escript.Scalar`
537 gross 1152 """
538     if self.__location_of_constraint == None: self.__setOutput()
539     return self.__value_of_constraint
540    
541     def __setOutput(self):
542     x=self.domain.getX()
543     self.__location_of_constraint=Scalar(0,x.getFunctionSpace())
544     if self.domain.getDim()==3:
545     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
546     else:
547     vertex=[inf(x[0]),inf(x[1])]
548     self.__location_of_constraint=whereZero(length(x-vertex),self.tol)
549     if not self.value == None:
550     self.__value_of_constraint=self.__location_of_constraint*self.value
551    
552     class VectorConstrainerAtBoxVertex(Model):
553     """
554     Creates a characteristic function for the location of constraints vector value.
555     In the case that the spatial dimension is two, the arguments front and
556     back as well as the third component of each argument is ignored.
557    
558 jfenwick 2625 :ivar domain: domain
559     :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).
560     :ivar tol: absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
561 gross 1152 """
562     def __init__(self, **kwargs):
563     super(VectorConstrainerAtBoxVertex, self).__init__(**kwargs)
564     self.declareParameter(domain=None, \
565     value=None, \
566     comp_mask=[False, False, False],
567     tol=1.e-8)
568     self.__value_of_constraint = None
569     self.__location_of_constraint=None
570    
571     def location_of_constraint(self):
572     """
573     return the values used to constrain a solution
574    
575 jfenwick 2625 :return: the mask marking the locations of the constraints
576     :rtype: `escript.Vector`
577 gross 1152 """
578     if self.__location_of_constraint == None: self.__setOutput()
579     return self.__location_of_constraint
580    
581     def value_of_constraint(self):
582     """
583     return the values used to constrain a solution
584    
585 jfenwick 2625 :return: values to be used at the locations of the constraints. If
586     ``value`` is not given ``None`` is rerturned.
587     :rtype: `escript.Vector`
588 gross 1152 """
589     if self.__location_of_constraint == None: self.__setOutput()
590     return self.__value_of_constraint
591    
592     def __setOutput(self):
593     x=self.domain.getX()
594     self.__location_of_constraint=Vector(0,x.getFunctionSpace())
595     if self.domain.getDim()==3:
596     vertex=[inf(x[0]),inf(x[1]),inf(x[2])]
597 jfenwick 2455 msk=numpy.zeros((3,))
598 gross 1152 if self.comp_mask[0]: msk[0]=1
599     if self.comp_mask[1]: msk[1]=1
600     if self.comp_mask[2]: msk[2]=1
601     else:
602     vertex=[inf(x[0]),inf(x[1])]
603 jfenwick 2455 msk=numpy.zeros((2,))
604 gross 1152 if self.comp_mask[0]: msk[0]=1
605     if self.comp_mask[1]: msk[1]=1
606 jfenwick 2455 self.__location_of_constraint=whereZero(length(x-vertex),self.tol)*numpy.ones(shape)
607 gross 1152 if not self.value == None:
608     self.__value_of_constraint=self.__location_of_constraint*self.value
609    

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26