/[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 6939 - (hide annotations)
Mon Jan 20 03:37:18 2020 UTC (2 months, 1 week ago) by uqaeller
File MIME type: text/x-python
File size: 30108 byte(s)
Updated the copyright header.


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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26