/[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 6651 - (show annotations)
Wed Feb 7 02:12:08 2018 UTC (22 months ago) by jfenwick
File MIME type: text/x-python
File size: 30038 byte(s)
Make everyone sad by touching all the files

Copyright dates update

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26