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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

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

Legend:
Removed from v.323  
changed lines
  Added in v.1387

  ViewVC Help
Powered by ViewVC 1.1.26