/[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 3259 - (hide annotations)
Mon Oct 11 01:48:14 2010 UTC (9 years, 5 months ago) by jfenwick
File MIME type: text/x-python
File size: 28677 byte(s)
Merging dudley and scons updates from branches

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26