/[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 4657 - (show annotations)
Thu Feb 6 06:12:20 2014 UTC (5 years, 8 months ago) by jfenwick
File MIME type: text/x-python
File size: 28979 byte(s)
I changed some files.
Updated copyright notices, added GeoComp.



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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.26