1 |
# $Id$ |
2 |
|
3 |
|
4 |
from esys.modelframe import Model |
5 |
from esys.escript import * |
6 |
import esys.finley as finley |
7 |
|
8 |
class RectangularDomain(Model): |
9 |
""" """ |
10 |
def __init__(self,debug=False): |
11 |
Model.__init__(self,debug=debug) |
12 |
self.declareParameter(domain=None, dim=2,\ |
13 |
l=[1.,1.,1.],\ |
14 |
n=[10,10,10], \ |
15 |
order=1,\ |
16 |
periodic=[False,False,False],\ |
17 |
integrationOrder=-1) |
18 |
def doInitialization(self,t): |
19 |
if self.dim==2: |
20 |
self.domain=finley.Rectangle(n0=self.n[0],\ |
21 |
n1=self.n[1],\ |
22 |
l0=self.l[0],\ |
23 |
l1=self.l[1],\ |
24 |
order=self.order, \ |
25 |
periodic0=self.periodic[0], \ |
26 |
periodic1=self.periodic[1], \ |
27 |
integrationOrder=self.integrationOrder) |
28 |
else: |
29 |
self.domain=finley.Brick(n0=self.n[0],\ |
30 |
n1=self.n[1],\ |
31 |
n2=self.n[2],\ |
32 |
l0=self.l[0],\ |
33 |
l1=self.l[1],\ |
34 |
l2=self.l[2],\ |
35 |
order=self.order, \ |
36 |
periodic0=self.periodic[0], \ |
37 |
periodic1=self.periodic[1], \ |
38 |
periodic2=self.periodic[2], \ |
39 |
integrationOrder=self.integrationOrder) |
40 |
|
41 |
class ScalarConstrainer(Model): |
42 |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
43 |
|
44 |
@param domain (in) - rectangular domain |
45 |
@param left (in) - True to set a constraint at the left face of the domain (x[0]=min x[0]), default is False |
46 |
@param right (in) - True to set a constraint at the left face of the domain (x[0]=max x[0]), default is False |
47 |
@param top (in) - True to set a constraint at the left face of the domain (x[1]=min x[1]), default is False |
48 |
@param bottom (in) - True to set a constraint at the left face of the domain (x[1]=max x[1]), default is False |
49 |
@param front (in) - True to set a constraint at the left face of the domain (x[2]=min x[2]), default is False |
50 |
@param back (in) - True to set a constraint at the left face of the domain (x[2]=max x[2]), default is False |
51 |
@param location_of_constraint (out) - object that defines the location of the constraints. |
52 |
|
53 |
In the case that the spatial dimension is two, teh arguments front and back are ignored |
54 |
|
55 |
""" |
56 |
def __init__(self,debug=False): |
57 |
Model.__init__(self,debug=debug) |
58 |
self.declareParameter(domain=None, \ |
59 |
left=False, |
60 |
right=False, |
61 |
top=False, |
62 |
bottom=False, |
63 |
front=False, |
64 |
back=False, |
65 |
location_of_constraint=Data()) |
66 |
def doInitialization(self,t): |
67 |
x=self.domain.getX() |
68 |
self.location_of_constraint=Scalar(0,x.getFunctionSpace()) |
69 |
if self.domain.getDim()==3: |
70 |
if self.left: self.location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
71 |
if self.right: self.location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
72 |
if self.front: self.location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
73 |
if self.back: self.location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
74 |
if self.bottom: self.location_of_constraint+=(x[2]-inf(x[2])).whereZero() |
75 |
if self.top: self.location_of_constraint+=(x[2]-sup(x[2])).whereZero() |
76 |
else: |
77 |
if self.left: self.location_of_constraint+=(x[0]-inf(x[0])).whereZero() |
78 |
if self.right: self.location_of_constraint+=(x[0]-sup(x[0])).whereZero() |
79 |
if self.bottom: self.location_of_constraint+=(x[1]-inf(x[1])).whereZero() |
80 |
if self.top: self.location_of_constraint+=(x[1]-sup(x[1])).whereZero() |
81 |
|
82 |
class VectorConstrainer(Model): |
83 |
"""@brief creates a characteristic function for the location of constraints for a scalar value |
84 |
|
85 |
@param domain (in) - rectangular domain |
86 |
@param left (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the left |
87 |
face of the domain (x[0]=min x[0]), default is [False,False,False] |
88 |
@param right (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the right |
89 |
face of the domain (x[0]=max x[0]), default is [False,False,False] |
90 |
@param top (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the top |
91 |
face of the domain (x[1]=min x[1]), default is [False,False,False] |
92 |
@param bottom (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the bottom |
93 |
face of the domain (x[1]=min x[1]), default is [False,False,False] |
94 |
@param front (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the front |
95 |
face of the domain (x[2]=min x[2]), default is [False,False,False] |
96 |
@param back (in) - list of three boolean. left[i]==True sets a constraint for the i-th component at the back |
97 |
face of the domain (x[2]=max x[2]), default is [False,False,False] |
98 |
@param location_of_constraint (out) - object that defines the location of the constraints for each vector component. |
99 |
|
100 |
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. |
101 |
|
102 |
""" |
103 |
def __init__(self,debug=False): |
104 |
Model.__init__(self,debug=debug) |
105 |
self.declareParameter(domain=None, \ |
106 |
left=[0,0,0], |
107 |
right=[0,0,0], |
108 |
top=[0,0,0], |
109 |
bottom=[0,0,0], |
110 |
front=[0,0,0], |
111 |
back=[0,0,0], |
112 |
location_of_constraint=Data()) |
113 |
def doInitialization(self,t): |
114 |
x=self.domain.getX() |
115 |
self.location_of_constraint=Vector(0,x.getFunctionSpace()) |
116 |
if self.domain.getDim()==3: |
117 |
left_mask=(x[0]-inf(x[0])).whereZero() |
118 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.,0.] |
119 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.,0.] |
120 |
if self.left[2]: self.location_of_constraint+=left_mask*[0.,0.,1.] |
121 |
right_mask=(x[0]-inf(x[0])).whereZero() |
122 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.,0.] |
123 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.,0.] |
124 |
if self.right[2]: self.location_of_constraint+=right_mask*[0.,0.,1.] |
125 |
front_mask=(x[1]-inf(x[1])).whereZero() |
126 |
if self.front[0]: self.location_of_constraint+=front_mask*[1.,0.,0.] |
127 |
if self.front[1]: self.location_of_constraint+=front_mask*[0.,1.,0.] |
128 |
if self.front[2]: self.location_of_constraint+=front_mask*[0.,0.,1.] |
129 |
back_mask=(x[1]-sup(x[1])).whereZero() |
130 |
if self.back[0]: self.location_of_constraint+=back_mask*[1.,0.,0.] |
131 |
if self.back[1]: self.location_of_constraint+=back_mask*[0.,1.,0.] |
132 |
if self.back[2]: self.location_of_constraint+=back_mask*[0.,0.,1.] |
133 |
bottom_mask=(x[2]-inf(x[2])).whereZero() |
134 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.,0.] |
135 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.,0.] |
136 |
if self.bottom[2]: self.location_of_constraint+=bottom_mask*[0.,0.,1.] |
137 |
top_mask=(x[2]-sup(x[2])).whereZero() |
138 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.,0.] |
139 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.,0.] |
140 |
if self.top[2]: self.location_of_constraint+=top_mask*[0.,0.,1.] |
141 |
else: |
142 |
left_mask=(x[0]-inf(x[0])).whereZero() |
143 |
if self.left[0]: self.location_of_constraint+=left_mask*[1.,0.] |
144 |
if self.left[1]: self.location_of_constraint+=left_mask*[0.,1.] |
145 |
right_mask=(x[0]-inf(x[0])).whereZero() |
146 |
if self.right[0]: self.location_of_constraint+=right_mask*[1.,0.] |
147 |
if self.right[1]: self.location_of_constraint+=right_mask*[0.,1.] |
148 |
bottom_mask=(x[1]-inf(x[1])).whereZero() |
149 |
if self.bottom[0]: self.location_of_constraint+=bottom_mask*[1.,0.] |
150 |
if self.bottom[1]: self.location_of_constraint+=bottom_mask*[0.,1.] |
151 |
top_mask=(x[1]-sup(x[1])).whereZero() |
152 |
if self.top[0]: self.location_of_constraint+=top_mask*[1.,0.] |
153 |
if self.top[1]: self.location_of_constraint+=top_mask*[0.,1.] |