1 |
# $Id$ |
# $Id$ |
2 |
|
|
3 |
|
|
4 |
from esys.modelframe import Model |
from escript.escript import * |
5 |
from esys.escript import * |
from escript.modelframe import Model |
6 |
import esys.finley as finley |
from finley import finley |
7 |
|
|
8 |
class RectangularDomain(Model): |
class RectangularDomain(Model): |
9 |
""" """ |
"""generates a mesh over a rectangular domain finley |
10 |
|
|
11 |
|
dim |
12 |
|
l |
13 |
|
n |
14 |
|
order |
15 |
|
periodic |
16 |
|
intergration order |
17 |
|
|
18 |
|
domain (callable) |
19 |
|
|
20 |
|
""" |
21 |
def __init__(self,debug=False): |
def __init__(self,debug=False): |
22 |
Model.__init__(self,debug=debug) |
Model.__init__(self,debug=debug) |
23 |
self.declareParameter(domain=None, dim=2,\ |
self.declareParameter(dim=2,\ |
24 |
l=[1.,1.,1.],\ |
l=[1.,1.,1.],\ |
25 |
n=[10,10,10], \ |
n=[10,10,10], \ |
26 |
order=1,\ |
order=1,\ |
27 |
periodic=[False,False,False],\ |
periodic=[False,False,False],\ |
28 |
integrationOrder=-1) |
integrationOrder=-1) |
29 |
def doInitialization(self,t): |
self._domain=None |
30 |
if self.dim==2: |
|
31 |
self.domain=finley.Rectangle(n0=self.n[0],\ |
def domain(self): |
32 |
n1=self.n[1],\ |
if self._domain==None: |
33 |
l0=self.l[0],\ |
if self.dim==2: |
34 |
l1=self.l[1],\ |
self._domain=finley.Rectangle(n0=self.n[0],\ |
35 |
order=self.order, \ |
n1=self.n[1],\ |
36 |
periodic0=self.periodic[0], \ |
l0=self.l[0],\ |
37 |
periodic1=self.periodic[1], \ |
l1=self.l[1],\ |
38 |
integrationOrder=self.integrationOrder) |
order=self.order, \ |
39 |
else: |
periodic0=self.periodic[0], \ |
40 |
self.domain=finley.Brick(n0=self.n[0],\ |
periodic1=self.periodic[1], \ |
41 |
n1=self.n[1],\ |
integrationOrder=self.integrationOrder) |
42 |
n2=self.n[2],\ |
else: |
43 |
l0=self.l[0],\ |
self._domain=finley.Brick(n0=self.n[0],\ |
44 |
l1=self.l[1],\ |
n1=self.n[1],\ |
45 |
l2=self.l[2],\ |
n2=self.n[2],\ |
46 |
order=self.order, \ |
l0=self.l[0],\ |
47 |
periodic0=self.periodic[0], \ |
l1=self.l[1],\ |
48 |
periodic1=self.periodic[1], \ |
l2=self.l[2],\ |
49 |
periodic2=self.periodic[2], \ |
order=self.order, \ |
50 |
integrationOrder=self.integrationOrder) |
periodic0=self.periodic[0], \ |
51 |
|
periodic1=self.periodic[1], \ |
52 |
|
periodic2=self.periodic[2], \ |
53 |
|
integrationOrder=self.integrationOrder) |
54 |
|
|
55 |
|
return self._domain |
56 |
|
|
57 |
class ScalarConstrainer(Model): |
class ScalarConstrainer(Model): |
58 |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
72 |
def __init__(self,debug=False): |
def __init__(self,debug=False): |
73 |
Model.__init__(self,debug=debug) |
Model.__init__(self,debug=debug) |
74 |
self.declareParameter(domain=None, \ |
self.declareParameter(domain=None, \ |
75 |
left=False, |
left=False, \ |
76 |
right=False, |
right=False, \ |
77 |
top=False, |
top=False, \ |
78 |
bottom=False, |
bottom=False, \ |
79 |
front=False, |
front=False, \ |
80 |
back=False, |
back=False) |
81 |
location_of_constraint=Data()) |
self._location_of_constraint=None |
82 |
def doInitialization(self,t): |
|
83 |
x=self.domain.getX() |
def location_of_constraint(self): |
84 |
self.location_of_constraint=Scalar(0,x.getFunctionSpace()) |
"""returns the mask of the location of constraint""" |
85 |
if self.domain.getDim()==3: |
if self._location_of_constraint==None: |
86 |
if self.left: self.location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
x=self.domain.getX() |
87 |
if self.right: self.location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
self._location_of_constraint=Scalar(0,x.getFunctionSpace()) |
88 |
if self.front: self.location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
if self.domain.getDim()==3: |
89 |
if self.back: self.location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
90 |
if self.bottom: self.location_of_constraint+=(x[2]-inf(x[2])).whereZero() |
if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
91 |
if self.top: self.location_of_constraint+=(x[2]-sup(x[2])).whereZero() |
if self.front: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
92 |
else: |
if self.back: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
93 |
if self.left: self.location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
if self.bottom: self._location_of_constraint+=(x[2]-inf(x[2])).whereZero() |
94 |
if self.right: self.location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
if self.top: self._location_of_constraint+=(x[2]-sup(x[2])).whereZero() |
95 |
if self.bottom: self.location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
else: |
96 |
if self.top: self.location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
if self.left: self._location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
97 |
|
if self.right: self._location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
98 |
|
if self.bottom: self._location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
99 |
|
if self.top: self._location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
100 |
|
return self._location_of_constraint |
101 |
|
|
102 |
class VectorConstrainer(Model): |
class VectorConstrainer(Model): |
103 |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
115 |
face of the domain (x[2]=min x[2]), default is [False,False,False] |
face of the domain (x[2]=min x[2]), default is [False,False,False] |
116 |
@param back (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the back |
@param back (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the back |
117 |
face of the domain (x[2]=max x[2]), default is [False,False,False] |
face of the domain (x[2]=max x[2]), default is [False,False,False] |
118 |
@param location_of_constraint (out) - object that defines the location of the constraints for each vector component. |
@param location_of_constraint (callable) - object that defines the location of the constraints for each vector component. |
119 |
|
|
120 |
In the case that the spatial dimension is two, thh arguments front and back as well as the third component of each argument is ignored. |
In the case that the spatial dimension is two, thh arguments front and back as well as the third component of each argument is ignored. |
121 |
|
|
123 |
def __init__(self,debug=False): |
def __init__(self,debug=False): |
124 |
Model.__init__(self,debug=debug) |
Model.__init__(self,debug=debug) |
125 |
self.declareParameter(domain=None, \ |
self.declareParameter(domain=None, \ |
126 |
left=[0,0,0], |
left=[0,0,0], \ |
127 |
right=[0,0,0], |
right=[0,0,0], \ |
128 |
top=[0,0,0], |
top=[0,0,0], \ |
129 |
bottom=[0,0,0], |
bottom=[0,0,0], \ |
130 |
front=[0,0,0], |
front=[0,0,0], |
131 |
back=[0,0,0], |
back=[0,0,0]) |
132 |
location_of_constraint=Data()) |
self._location_of_constraint=None |
133 |
def doInitialization(self,t): |
def location_of_constraint(self): |
134 |
x=self.domain.getX() |
"""returns the mask of the location of constraint""" |
135 |
self.location_of_constraint=Vector(0,x.getFunctionSpace()) |
if self._location_of_constraint==None: |
136 |
if self.domain.getDim()==3: |
x=self.domain.getX() |
137 |
left_mask=(x[0]-inf(x[0])).whereZero() |
self._location_of_constraint=Vector(0,x.getFunctionSpace()) |
138 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.,0.] |
if self.domain.getDim()==3: |
139 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.,0.] |
left_mask=(x[0]-inf(x[0])).whereZero() |
140 |
if self.left[2]: self.location_of_constraint+=left_mask*[0.,0.,1.] |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.,0.] |
141 |
right_mask=(x[0]-inf(x[0])).whereZero() |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.,0.] |
142 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.,0.] |
if self.left[2]: self._location_of_constraint+=left_mask*[0.,0.,1.] |
143 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.,0.] |
right_mask=(x[0]-sup(x[0])).whereZero() |
144 |
if self.right[2]: self.location_of_constraint+=right_mask*[0.,0.,1.] |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.,0.] |
145 |
front_mask=(x[1]-inf(x[1])).whereZero() |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.,0.] |
146 |
if self.front[0]: self.location_of_constraint+=front_mask*[1.,0.,0.] |
if self.right[2]: self._location_of_constraint+=right_mask*[0.,0.,1.] |
147 |
if self.front[1]: self.location_of_constraint+=front_mask*[0.,1.,0.] |
front_mask=(x[1]-inf(x[1])).whereZero() |
148 |
if self.front[2]: self.location_of_constraint+=front_mask*[0.,0.,1.] |
if self.front[0]: self._location_of_constraint+=front_mask*[1.,0.,0.] |
149 |
back_mask=(x[1]-sup(x[1])).whereZero() |
if self.front[1]: self._location_of_constraint+=front_mask*[0.,1.,0.] |
150 |
if self.back[0]: self.location_of_constraint+=back_mask*[1.,0.,0.] |
if self.front[2]: self._location_of_constraint+=front_mask*[0.,0.,1.] |
151 |
if self.back[1]: self.location_of_constraint+=back_mask*[0.,1.,0.] |
back_mask=(x[1]-sup(x[1])).whereZero() |
152 |
if self.back[2]: self.location_of_constraint+=back_mask*[0.,0.,1.] |
if self.back[0]: self._location_of_constraint+=back_mask*[1.,0.,0.] |
153 |
bottom_mask=(x[2]-inf(x[2])).whereZero() |
if self.back[1]: self._location_of_constraint+=back_mask*[0.,1.,0.] |
154 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.,0.] |
if self.back[2]: self._location_of_constraint+=back_mask*[0.,0.,1.] |
155 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.,0.] |
bottom_mask=(x[2]-inf(x[2])).whereZero() |
156 |
if self.bottom[2]: self.location_of_constraint+=bottom_mask*[0.,0.,1.] |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.,0.] |
157 |
top_mask=(x[2]-sup(x[2])).whereZero() |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.,0.] |
158 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.,0.] |
if self.bottom[2]: self._location_of_constraint+=bottom_mask*[0.,0.,1.] |
159 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.,0.] |
top_mask=(x[2]-sup(x[2])).whereZero() |
160 |
if self.top[2]: self.location_of_constraint+=top_mask*[0.,0.,1.] |
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.,0.] |
161 |
else: |
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.,0.] |
162 |
left_mask=(x[0]-inf(x[0])).whereZero() |
if self.top[2]: self._location_of_constraint+=top_mask*[0.,0.,1.] |
163 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.] |
else: |
164 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.] |
left_mask=(x[0]-inf(x[0])).whereZero() |
165 |
right_mask=(x[0]-inf(x[0])).whereZero() |
if self.left[0]: self._location_of_constraint+=left_mask*[1.,0.] |
166 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.] |
if self.left[1]: self._location_of_constraint+=left_mask*[0.,1.] |
167 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.] |
right_mask=(x[0]-sup(x[0])).whereZero() |
168 |
bottom_mask=(x[1]-inf(x[1])).whereZero() |
if self.right[0]: self._location_of_constraint+=right_mask*[1.,0.] |
169 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.] |
if self.right[1]: self._location_of_constraint+=right_mask*[0.,1.] |
170 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.] |
bottom_mask=(x[1]-inf(x[1])).whereZero() |
171 |
top_mask=(x[1]-sup(x[1])).whereZero() |
if self.bottom[0]: self._location_of_constraint+=bottom_mask*[1.,0.] |
172 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.] |
if self.bottom[1]: self._location_of_constraint+=bottom_mask*[0.,1.] |
173 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.] |
top_mask=(x[1]-sup(x[1])).whereZero() |
174 |
|
if self.top[0]: self._location_of_constraint+=top_mask*[1.,0.] |
175 |
|
if self.top[1]: self._location_of_constraint+=top_mask*[0.,1.] |
176 |
|
return self._location_of_constraint |