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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 6939 - (show annotations)
Mon Jan 20 03:37:18 2020 UTC (6 months, 2 weeks ago) by uqaeller
File MIME type: text/x-python
File size: 30108 byte(s)
Updated the copyright header.


1
2 ##############################################################################
3 #
4 # Copyright (c) 2003-2020 by The University of Queensland
5 # http://www.uq.edu.au
6 #
7 # Primary Business: Queensland, Australia
8 # Licensed under the Apache License, version 2.0
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Development until 2012 by Earth Systems Science Computational Center (ESSCC)
12 # Development 2012-2013 by School of Earth Sciences
13 # Development from 2014 by Centre for Geoscience Computing (GeoComp)
14 # Development from 2019 by School of Earth and Environmental Sciences
15 #
16 ##############################################################################
17
18 from __future__ import division, print_function
19
20 __copyright__="""Copyright (c) 2003-2020 by The University of Queensland
21 http://www.uq.edu.au
22 Primary Business: Queensland, Australia"""
23 __license__="""Licensed under the Apache License, version 2.0
24 http://www.apache.org/licenses/LICENSE-2.0"""
25 __url__="https://launchpad.net/escript-finley"
26
27 import esys.escript.modelframe as esmf
28 import esys.escript as es
29
30 try:
31 import esys.finley
32 except ImportError:
33 raise ImportError("Finley module not available")
34
35 class DomainReader(esmf.ParameterSet):
36 #class DudleyReader(ParameterSet):
37 """
38 """
39 def __init__(self,domainmodule=None, **kwargs):
40 """
41 initializes the object
42 """
43 super(DomainReader,self).__init__(**kwargs)
44 self.declareParameter(source="none",
45 dim=None,
46 optimizeLabeling=True,
47 reducedIntegrationOrder=-1,
48 integrationOrder=-1)
49 if domainmodule==None:
50 domainmodule=esys.finley
51 self.__domainModule=domainmodule
52 self.__domain=None
53
54
55 def domain(self):
56 """
57 returns the domain
58
59 :return: the domain
60 :rtype: `Domain`
61 """
62 if self.__domain is None:
63 if self.source.fileformat == "fly":
64 self.__domain=self.__domainModule.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=self.__domainModule.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
76 class FinleyReader(DomainReader):
77 def __init__(self, **kw):
78 DomainReader.__init__(self, esys.finley, **kw)
79
80 class RectangularDomain(esmf.ParameterSet):
81 """
82 Generates a mesh over a rectangular domain.
83
84 :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 """
97 def __init__(self,domainmodule=None,**kwargs):
98 """
99 initializes the object
100 """
101 super(RectangularDomain,self).__init__(**kwargs)
102 self.declareParameter(dim=2,\
103 l=[1.,1.,1.],\
104 n=[10,10,10], \
105 order=1,\
106 periodic=[False,False,False],
107 integrationOrder=-1)
108 self.__domain=None
109 self.__domainModule=domainmodule
110 if self.__domainModule==None:
111 self.__domainModule=esys.finley
112
113 def domain(self):
114 """
115 returns the domain
116
117 :return: the domain
118 :rtype: `Domain`
119 """
120 if self.__domain==None:
121 if self.dim==2:
122 self.__domain=self.__domainModule.Rectangle(n0=self.n[0],\
123 n1=self.n[2],\
124 l0=self.l[0],\
125 l1=self.l[2],\
126 order=self.order, \
127 periodic0=self.periodic[0], \
128 periodic1=self.periodic[2], \
129 integrationOrder=self.integrationOrder)
130 else:
131 self.__domain=self__domainModule.Brick(n0=self.n[0],\
132 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
144 class UpdateGeometry(esmf.Model):
145 """
146 applies a displacement field to a domain
147
148 :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 """
153 def __init__(self,**kwargs):
154 """
155 set-up the object
156 """
157 super(UpdateGeometry, self).__init__(**kwargs)
158 self.declareParameter(domain=None,\
159 displacement=None)
160
161
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 applies the current `displacement` to mesh nodes if required.
172 """
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 applies the current `displacement` to mesh nodes.
181 """
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 class ConstrainerOverBox(esmf.Model):
193 """
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 :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 """
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 :return: the mask marking the locations of the constraints
227 :rtype: `escript.Scalar`
228 """
229 if self.__location_of_constraint is None: self.__setOutput()
230 return self.__location_of_constraint
231
232 def value_of_constraint(self):
233 """
234 return the values used to constrain a solution
235
236 :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 """
240 if self.__location_of_constraint is None: self.__setOutput()
241 return self.__value_of_constraint
242
243 def __setOutput(self):
244 if self.__location_of_constraint is None:
245 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 elif isinstance(val, numpy.ndarray):
252 shape=val.shape
253 elif val is None:
254 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 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 else:
267 x0,x1=x[0],x[1]
268 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 if not self.value is None:
273 self.__value_of_constraint=self.__location_of_constraint*self.value
274 class ScalarConstrainerOverBox(esmf.Model):
275 """
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
280 In the case that the spatial dimension is two, the arguments front and back are ignored.
281
282 :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 """
291 def __init__(self,**kwargs):
292 super(ScalarConstrainerOverBox, self).__init__(**kwargs)
293 self.declareParameter(domain=None, \
294 value=None, \
295 left=False, \
296 right=False, \
297 top=False, \
298 bottom=False, \
299 front=False, \
300 back=False, \
301 tol=1.e-8)
302 self.__value_of_constraint = None
303 self.__location_of_constraint=None
304 def location_of_constraint(self):
305 """
306 return the values used to constrain a solution
307
308 :return: the mask marking the locations of the constraints
309 :rtype: `escript.Scalar`
310 """
311 if self.__location_of_constraint is None: self.__setOutput()
312 return self.__location_of_constraint
313
314 def value_of_constraint(self):
315 """
316 return the values used to constrain a solution
317
318 :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 """
322 if self.__location_of_constraint is None: self.__setOutput()
323 return self.__value_of_constraint
324
325 def __setOutput(self):
326 x=self.domain.getX()
327 self.__location_of_constraint=es.Scalar(0,x.getFunctionSpace())
328 if self.domain.getDim()==3:
329 x0,x1,x2=x[0],x[1],x[2]
330 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 else:
338 x0,x1=x[0],x[1]
339 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 if not self.value is None:
345 self.__value_of_constraint=self.__location_of_constraint*self.value
346
347 class VectorConstrainerOverBox(esmf.Model):
348 """
349 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
353 :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 default [False,False,False] (in).
356 :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 default [False,False,False] (in).
358 :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 default [False,False,False] (in).
360 :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 default [False,False,False] (in).
362 :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 default [False,False,False] (in).
364 :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 default [False,False,False] (in).
366 :note: Instance variable tol - absolute tolerance for "x=max x" condition, default 1.e-8 (in).
367 """
368 def __init__(self, **kwargs):
369 super(VectorConstrainerOverBox, self).__init__(**kwargs)
370 self.declareParameter(domain=None, \
371 value=None, \
372 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 tol=1.e-8)
379 self.__value_of_constraint = None
380 self.__location_of_constraint=None
381
382 def location_of_constraint(self):
383 """
384 return the values used to constrain a solution
385
386 :return: the mask marking the locations of the constraints
387 :rtype: `escript.Vector`
388 """
389 if self.__location_of_constraint is None: self.__setOutput()
390 return self.__location_of_constraint
391
392 def value_of_constraint(self):
393 """
394 return the values used to constrain a solution
395
396 :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 """
400 if self.__location_of_constraint is None: self.__setOutput()
401 return self.__value_of_constraint
402
403 def __setOutput(self):
404 x=self.domain.getX()
405 self.__location_of_constraint=es.Vector(0,x.getFunctionSpace())
406 if self.domain.getDim()==3:
407 x0,x1,x2=x[0],x[1],x[2]
408 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 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 right_mask=es.whereZero(x0-es.sup(x0),self.tol*d)
414 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 front_mask=es.whereZero(x1-es.inf(x1),self.tol*d)
418 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 back_mask=es.whereZero(x1-es.sup(x1),self.tol*d)
422 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 bottom_mask=es.whereZero(x2-es.inf(x2),self.tol*d)
426 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 top_mask=es.whereZero(x2-es.sup(x2),self.tol*d)
430 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 if not self.value is None:
434 self.__value_of_constraint=self.__location_of_constraint*self.value
435 else:
436 x0,x1=x[0],x[1]
437 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 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 right_mask=es.whereZero(x0-es.sup(x0),self.tol*d)
442 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 bottom_mask=es.whereZero(x1-es.inf(x1),self.tol*d)
445 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 top_mask=es.whereZero(x1-es.sup(x1),self.tol*d)
448 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 if not self.value is None:
451 self.__value_of_constraint=self.__location_of_constraint*self.value[:2]
452
453 class ConstrainerAtBoxVertex(esmf.Model):
454 """
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
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 """
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 :return: the mask marking the locations of the constraints
476 :rtype: `escript.Scalar`
477 """
478 if self.__location_of_constraint is None: self.__setOutput()
479 return self.__location_of_constraint
480
481 def value_of_constraint(self):
482 """
483 return the values used to constrain a solution
484
485 :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 """
489 if self.__location_of_constraint is None: self.__setOutput()
490 return self.__value_of_constraint
491
492 def __setOutput(self):
493 if self.__location_of_constraint is None:
494 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 elif isinstance(val, numpy.ndarray):
501 shape=val.shape
502 elif val is None:
503 shape=()
504 else:
505 shape=val.getShape()
506 if self.domain.getDim()==3:
507 vertex=[es.inf(x[0]),es.inf(x[1]),es.inf(x[2])]
508 else:
509 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 if not self.value is None:
512 self.__value_of_constraint=self.__location_of_constraint*self.value
513
514 class ScalarConstrainerAtBoxVertex(esmf.Model):
515 """
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 :note: Instance variable domain
523 :note: Instance variable tol - absolute tolerance for "x=left, front, bottom vertex" condition, default 1.e-8 (in).
524 """
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 :return: the mask marking the locations of the constraints
537 :rtype: `escript.Scalar`
538 """
539 if self.__location_of_constraint is None: self.__setOutput()
540 return self.__location_of_constraint
541
542 def value_of_constraint(self):
543 """
544 return the values used to constrain a solution
545
546 :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 """
550 if self.__location_of_constraint is None: self.__setOutput()
551 return self.__value_of_constraint
552
553 def __setOutput(self):
554 x=self.domain.getX()
555 self.__location_of_constraint=es.Scalar(0,x.getFunctionSpace())
556 if self.domain.getDim()==3:
557 vertex=[es.inf(x[0]),es.inf(x[1]),es.inf(x[2])]
558 else:
559 vertex=[es.inf(x[0]),es.inf(x[1])]
560 self.__location_of_constraint=es.whereZero(es.length(x-vertex),self.tol)
561 if not self.value is None:
562 self.__value_of_constraint=self.__location_of_constraint*self.value
563
564 class VectorConstrainerAtBoxVertex(esmf.Model):
565 """
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 :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 """
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 :return: the mask marking the locations of the constraints
588 :rtype: `escript.Vector`
589 """
590 if self.__location_of_constraint is None: self.__setOutput()
591 return self.__location_of_constraint
592
593 def value_of_constraint(self):
594 """
595 return the values used to constrain a solution
596
597 :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 """
601 if self.__location_of_constraint is None: self.__setOutput()
602 return self.__value_of_constraint
603
604 def __setOutput(self):
605 x=self.domain.getX()
606 self.__location_of_constraint=es.Vector(0,x.getFunctionSpace())
607 if self.domain.getDim()==3:
608 vertex=[es.inf(x[0]),es.inf(x[1]),es.inf(x[2])]
609 msk=numpy.zeros((3,))
610 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 vertex=[es.inf(x[0]),es.inf(x[1])]
615 msk=numpy.zeros((2,))
616 if self.comp_mask[0]: msk[0]=1
617 if self.comp_mask[1]: msk[1]=1
618 self.__location_of_constraint=es.whereZero(es.length(x-vertex),self.tol)*numpy.ones(shape)
619 if not self.value is None:
620 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