46 |
|
|
47 |
from esys.escript.util import Lsup,kronecker,interpolate,whereZero |
from esys.escript.util import Lsup,kronecker,interpolate,whereZero |
48 |
from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor |
from esys.escript import Function,FunctionOnBoundary,FunctionOnContactZero,Solution,ReducedSolution,Vector,ContinuousFunction,Scalar, ReducedFunction,ReducedFunctionOnBoundary,ReducedFunctionOnContactZero,Data, Tensor4, Tensor |
49 |
from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient |
from esys.escript.linearPDEs import LinearPDE,IllegalCoefficientValue,Poisson, IllegalCoefficientFunctionSpace, TransportPDE, IllegalCoefficient, Helmholtz |
50 |
import numarray |
import numarray |
51 |
import unittest |
import unittest |
52 |
|
|
62 |
if tol==None: tol=self.TOL |
if tol==None: tol=self.TOL |
63 |
return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg) |
return Lsup(arg-ref_arg)<=tol*Lsup(ref_arg) |
64 |
|
|
65 |
|
class Test_Helmholtz(Test_linearPDEs): |
66 |
|
|
67 |
|
def test_config(self): |
68 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
69 |
|
self.failUnlessEqual((mypde.getNumEquations(),mypde.getNumSolutions(),mypde.isSymmetric()),(1,1,True),"set up incorrect") |
70 |
|
def test_setCoefficient_q(self): |
71 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
72 |
|
x=self.domain.getX() |
73 |
|
mypde.setValue(q=whereZero(x[0])) |
74 |
|
|
75 |
|
q_ref=interpolate(whereZero(x[0]),Solution(self.domain)) |
76 |
|
A_ref=kronecker(self.domain) |
77 |
|
|
78 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
79 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
80 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
81 |
|
self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty") |
82 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
83 |
|
self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty") |
84 |
|
self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty") |
85 |
|
self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty") |
86 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
87 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
88 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
89 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
90 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
91 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
92 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
93 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty") |
94 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
95 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
96 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
97 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
98 |
|
self.failUnless(self.check(mypde.getCoefficient("q"),q_ref),"q is not empty") |
99 |
|
self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty") |
100 |
|
|
101 |
|
def test_setCoefficient_r(self): |
102 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
103 |
|
x=self.domain.getX() |
104 |
|
mypde.setValue(r=x[0]) |
105 |
|
|
106 |
|
r_ref=interpolate(x[0],Solution(self.domain)) |
107 |
|
A_ref=kronecker(self.domain) |
108 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
109 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
110 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
111 |
|
self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty") |
112 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
113 |
|
self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty") |
114 |
|
self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty") |
115 |
|
self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty") |
116 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
117 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
118 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
119 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
120 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
121 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
122 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
123 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty") |
124 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
125 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
126 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
127 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
128 |
|
self.failUnless(self.check(mypde.getCoefficient("r"),r_ref),"r is nor x[0]") |
129 |
|
self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty") |
130 |
|
|
131 |
|
|
132 |
|
def test_setCoefficient_f(self): |
133 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
134 |
|
x=self.domain.getX() |
135 |
|
mypde.setValue(f=x[0]) |
136 |
|
|
137 |
|
Y_ref=interpolate(x[0],Function(self.domain)) |
138 |
|
A_ref=kronecker(self.domain) |
139 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
140 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
141 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
142 |
|
self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty") |
143 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
144 |
|
self.failUnless(self.check(mypde.getCoefficient("Y"),Y_ref),"Y is not x[0]") |
145 |
|
self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty") |
146 |
|
self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty") |
147 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
148 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
149 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
150 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
151 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
152 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
153 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
154 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty") |
155 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
156 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
157 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
158 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
159 |
|
self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty") |
160 |
|
self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty") |
161 |
|
|
162 |
|
def test_setCoefficient_alpha(self): |
163 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
164 |
|
x=self.domain.getX() |
165 |
|
mypde.setValue(alpha=x[0]) |
166 |
|
|
167 |
|
d_ref=interpolate(x[0],FunctionOnBoundary(self.domain)) |
168 |
|
A_ref=kronecker(self.domain) |
169 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
170 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
171 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
172 |
|
self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty") |
173 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
174 |
|
self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty") |
175 |
|
self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty") |
176 |
|
self.failUnless(self.check(mypde.getCoefficient("d"),d_ref),"d is not x[0]") |
177 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
178 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
179 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
180 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
181 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
182 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
183 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
184 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"X_reduced is not empty") |
185 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
186 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
187 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
188 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
189 |
|
self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty") |
190 |
|
self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty") |
191 |
|
|
192 |
|
def test_setCoefficient_g(self): |
193 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
194 |
|
x=self.domain.getX() |
195 |
|
mypde.setValue(g=x[0]) |
196 |
|
|
197 |
|
y_ref=interpolate(x[0],FunctionOnBoundary(self.domain)) |
198 |
|
A_ref=kronecker(self.domain) |
199 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
200 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
201 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
202 |
|
self.failUnless(mypde.getCoefficient("D").isEmpty(),"D is not empty") |
203 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
204 |
|
self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty") |
205 |
|
self.failUnless(self.check(mypde.getCoefficient("y"),y_ref),"y is not x[0]") |
206 |
|
self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty") |
207 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
208 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
209 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
210 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
211 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
212 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
213 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
214 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty") |
215 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
216 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
217 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
218 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
219 |
|
self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty") |
220 |
|
self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty") |
221 |
|
|
222 |
|
def test_setCoefficient_omega(self): |
223 |
|
mypde=Helmholtz(self.domain,debug=self.DEBUG) |
224 |
|
x=self.domain.getX() |
225 |
|
mypde.setValue(omega=x[0]) |
226 |
|
|
227 |
|
D_ref=interpolate(x[0],Function(self.domain)) |
228 |
|
A_ref=kronecker(self.domain) |
229 |
|
self.failUnless(self.check(mypde.getCoefficient("A"),A_ref),"A is not kronecker") |
230 |
|
self.failUnless(mypde.getCoefficient("B").isEmpty(),"B is not empty") |
231 |
|
self.failUnless(mypde.getCoefficient("C").isEmpty(),"C is not empty") |
232 |
|
self.failUnless(self.check(mypde.getCoefficient("D"),D_ref),"D is not x[0]") |
233 |
|
self.failUnless(mypde.getCoefficient("X").isEmpty(),"X is not empty") |
234 |
|
self.failUnless(mypde.getCoefficient("Y").isEmpty(),"Y is not empty") |
235 |
|
self.failUnless(mypde.getCoefficient("y").isEmpty(),"y is not empty") |
236 |
|
self.failUnless(mypde.getCoefficient("d").isEmpty(),"d is not empty") |
237 |
|
self.failUnless(mypde.getCoefficient("d_contact").isEmpty(),"d_contact is not empty") |
238 |
|
self.failUnless(mypde.getCoefficient("y_contact").isEmpty(),"y_contact is not empty") |
239 |
|
self.failUnless(mypde.getCoefficient("A_reduced").isEmpty(),"A_reduced is not empty") |
240 |
|
self.failUnless(mypde.getCoefficient("B_reduced").isEmpty(),"B_reduced is not empty") |
241 |
|
self.failUnless(mypde.getCoefficient("C_reduced").isEmpty(),"C_reduced is not empty") |
242 |
|
self.failUnless(mypde.getCoefficient("D_reduced").isEmpty(),"D_reduced is not empty") |
243 |
|
self.failUnless(mypde.getCoefficient("X_reduced").isEmpty(),"X_reduced is not empty") |
244 |
|
self.failUnless(mypde.getCoefficient("Y_reduced").isEmpty(),"Y_reduced is not empty") |
245 |
|
self.failUnless(mypde.getCoefficient("y_reduced").isEmpty(),"y_reduced is not empty") |
246 |
|
self.failUnless(mypde.getCoefficient("d_reduced").isEmpty(),"d_reduced is not empty") |
247 |
|
self.failUnless(mypde.getCoefficient("d_contact_reduced").isEmpty(),"d_contact_reduced is not empty") |
248 |
|
self.failUnless(mypde.getCoefficient("y_contact_reduced").isEmpty(),"y_contact_reduced is not empty") |
249 |
|
self.failUnless(mypde.getCoefficient("q").isEmpty(),"q is not empty") |
250 |
|
self.failUnless(mypde.getCoefficient("r").isEmpty(),"r is not empty") |
251 |
|
|
252 |
|
def test_solve(self): |
253 |
|
d=self.domain.getDim() |
254 |
|
cf=ContinuousFunction(self.domain) |
255 |
|
u_ex=Scalar(1.,cf) |
256 |
|
mypde=Helmholtz(self.domain) |
257 |
|
mypde.setValue(f=3,omega=3,alpha=2,g=2) |
258 |
|
u=mypde.getSolution() |
259 |
|
self.failUnless(self.check(u,u_ex,10*self.TOL),"incorrect solution") |
260 |
|
|
261 |
class Test_Poisson(Test_linearPDEs): |
class Test_Poisson(Test_linearPDEs): |
262 |
|
|
263 |
def test_config(self): |
def test_config(self): |