9 |
|
|
10 |
from esys.escript import * |
from esys.escript import * |
11 |
from esys.escript.modelframe import Model,ParameterSet |
from esys.escript.modelframe import Model,ParameterSet |
12 |
|
from esys.pycad import TagMap |
13 |
from esys import finley |
from esys import finley |
14 |
|
|
15 |
class FinleyReader(ParameterSet): |
class FinleyReader(ParameterSet): |
31 |
""" |
""" |
32 |
super(FinleyReader,self).__init__(**kwargs) |
super(FinleyReader,self).__init__(**kwargs) |
33 |
self.declareParameter(source="none", |
self.declareParameter(source="none", |
34 |
|
region_tag_map_source=None, |
35 |
|
surface_tag_map_source=None, |
36 |
optimizeLabeling=True, |
optimizeLabeling=True, |
37 |
reducedIntegrationOrder=-1, |
reducedIntegrationOrder=-1, |
38 |
integrationOrder=-1) |
integrationOrder=-1) |
39 |
self.__domain=None |
self.__domain=None |
40 |
|
self.__region_tag_map=None |
41 |
|
self.__surface_tag_map=None |
42 |
|
|
43 |
|
|
44 |
def domain(self): |
def domain(self): |
45 |
""" |
""" |
57 |
raise TypeError("unknown mesh file format %s."%self.source.fileformat) |
raise TypeError("unknown mesh file format %s."%self.source.fileformat) |
58 |
self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat)) |
self.trace("mesh read from %s in %s format."%(self.source.getLocalFileName(), self.source.fileformat)) |
59 |
return self.__domain |
return self.__domain |
60 |
|
|
61 |
|
def region_tag_map(self): |
62 |
|
""" |
63 |
|
returns the map from regional tag names to tag integers used in the mesh |
64 |
|
|
65 |
|
@return: the tag map |
66 |
|
@rtype: L{TagMap} |
67 |
|
""" |
68 |
|
if self.__region_tag_map == None: |
69 |
|
self.__region_tag_map = TagMap() |
70 |
|
if self.region_tag_map_source != None: |
71 |
|
self.__region_tag_map.fillFromXML(open(self.region_tag_map_source.getLocalFileName())) |
72 |
|
self.trace("region tag map read from %s in %s format."%(self.region_tag_map_source.getLocalFileName(), self.region_tag_map_source.fileformat)) |
73 |
|
return self.__region_tag_map |
74 |
|
|
75 |
|
def surface_tag_map(self): |
76 |
|
""" |
77 |
|
returns the map from surface tag names to tag integers used in the mesh |
78 |
|
|
79 |
|
@return: the tag map |
80 |
|
@rtype: L{TagMap} |
81 |
|
""" |
82 |
|
if self.__surface_tag_map == None: |
83 |
|
self.__surface_tag_map = TagMap() |
84 |
|
if self.surface_tag_map_source != None: |
85 |
|
self.__surface_tag_map.fillFromXML(open(self.surface_tag_map_source.getLocalFileName())) |
86 |
|
self.trace("surface tag map read from %s in %s format."%(self.surface_tag_map_source.getLocalFileName(), self.surface_tag_map_source.fileformat)) |
87 |
|
return self.__surface_tag_map |
88 |
|
|
89 |
|
|
90 |
class RectangularDomain(ParameterSet): |
class RectangularDomain(ParameterSet): |
196 |
""" |
""" |
197 |
self.__reset=False |
self.__reset=False |
198 |
|
|
199 |
|
class ConstrainerOverBox(Model): |
200 |
|
""" |
201 |
|
Creates a characteristic function for the location of constraints |
202 |
|
for all components of a value and selects the value from an initial value |
203 |
|
ate these locations. |
204 |
|
|
205 |
|
In the case that the spatial dimension is two, the arguments front and back are ignored. |
206 |
|
|
207 |
|
@ivar domain: domain (in). |
208 |
|
@ivar left: True to set a constraint at the left face of the domain (x[0]=min x[0]), default False (in). |
209 |
|
@ivar right: True to set a constraint at the left face of the domain (x[0]=max x[0]), default False (in). |
210 |
|
@ivar top: True to set a constraint at the left face of the domain (x[1]=min x[1]), default False (in). |
211 |
|
@ivar bottom: True to set a constraint at the left face of the domain (x[1]=max x[1]), default False (in). |
212 |
|
@ivar front: True to set a constraint at the left face of the domain (x[2]=min x[2]), default False (in). |
213 |
|
@ivar back: True to set a constraint at the left face of the domain (x[2]=max x[2]), default False (in). |
214 |
|
@ivar tol: absolute tolerance for "x=max x" condition, default 1.e-8 (in). |
215 |
|
""" |
216 |
|
def __init__(self,**kwargs): |
217 |
|
super(ConstrainerOverBox, self).__init__(**kwargs) |
218 |
|
self.declareParameter(domain=None, \ |
219 |
|
value=None, \ |
220 |
|
left=False, \ |
221 |
|
right=False, \ |
222 |
|
top=False, \ |
223 |
|
bottom=False, \ |
224 |
|
front=False, \ |
225 |
|
back=False, \ |
226 |
|
tol=1.e-8) |
227 |
|
self.__value_of_constraint = None |
228 |
|
self.__location_of_constraint=None |
229 |
|
def location_of_constraint(self): |
230 |
|
""" |
231 |
|
return the values used to constrain a solution |
232 |
|
|
233 |
|
@return: the mask marking the locations of the constraints |
234 |
|
@rtype: L{escript.Scalar} |
235 |
|
""" |
236 |
|
if self.__location_of_constraint == None: self.__setOutput() |
237 |
|
return self.__location_of_constraint |
238 |
|
|
239 |
|
def value_of_constraint(self): |
240 |
|
""" |
241 |
|
return the values used to constrain a solution |
242 |
|
|
243 |
|
@return: values to be used at the locations of the constraints. If |
244 |
|
L{value} is not given C{None} is rerturned. |
245 |
|
@rtype: L{escript.Scalar} |
246 |
|
""" |
247 |
|
if self.__location_of_constraint == None: self.__setOutput() |
248 |
|
return self.__value_of_constraint |
249 |
|
|
250 |
|
def __setOutput(self): |
251 |
|
x=self.domain.getX() |
252 |
|
val=self.value |
253 |
|
if isinstance(val, int) or isinstance(val, float): |
254 |
|
shape=() |
255 |
|
elif isinstance(val, list) or isinstance(val, tuple) : |
256 |
|
shape=(len(val),) |
257 |
|
elif isinstance(val, numarray.NumArray): |
258 |
|
shape=val.shape |
259 |
|
else: |
260 |
|
shape=val.getShape() |
261 |
|
self.__location_of_constraint=Data(0,shape,x.getFunctionSpace()) |
262 |
|
if self.domain.getDim()==3: |
263 |
|
x0,x1,x2=x[0],x[1],x[2] |
264 |
|
if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol) |
265 |
|
if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol) |
266 |
|
if self.front: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol) |
267 |
|
if self.back: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol) |
268 |
|
if self.bottom: self.__location_of_constraint+=whereZero(x2-inf(x2),self.tol) |
269 |
|
if self.top: self.__location_of_constraint+=whereZero(x2-sup(x2),self.tol) |
270 |
|
else: |
271 |
|
x0,x1=x[0],x[1] |
272 |
|
if self.left: self.__location_of_constraint+=whereZero(x0-inf(x0),self.tol) |
273 |
|
if self.right: self.__location_of_constraint+=whereZero(x0-sup(x0),self.tol) |
274 |
|
if self.bottom: self.__location_of_constraint+=whereZero(x1-inf(x1),self.tol) |
275 |
|
if self.top: self.__location_of_constraint+=whereZero(x1-sup(x1),self.tol) |
276 |
|
self.__value_of_constraint=self.__location_of_constraint*self.value |
277 |
class ScalarConstrainerOverBox(Model): |
class ScalarConstrainerOverBox(Model): |
278 |
""" |
""" |
279 |
Creates a characteristic function for the location of constraints |
Creates a characteristic function for the location of constraints |