/[escript]/trunk/finley/test/python/gentest
ViewVC logotype

Annotation of /trunk/finley/test/python/gentest

Parent Directory Parent Directory | Revision Log Revision Log


Revision 769 - (hide annotations)
Sun Jul 2 23:58:22 2006 UTC (13 years, 7 months ago) by gross
File size: 32134 byte(s)
A bit more tests are generated now. Ther is still a problem with the slection of the solution order.


1 gross 589 #!/usr/bin/python
2 gross 766 import numarray
3     import random
4 gross 589 t_prog={}
5 gross 769 t_prog["2Do1"]=""
6     t_prog["2Do2"]=""
7     t_prog["3Do1"]=""
8     t_prog["3Do2"]=""
9     t_prog["2Do1_reduced"]=""
10     t_prog["2Do2_reduced"]=""
11     t_prog["3Do1_reduced"]=""
12     t_prog["3Do2_reduced"]=""
13 gross 589 t_prog["2Do1_contact"]=""
14     t_prog["2Do2_contact"]=""
15     t_prog["3Do1_contact"]=""
16     t_prog["3Do2_contact"]=""
17     intend=" "
18 gross 766 max_order=3
19 gross 589
20 gross 766 def makeTitle(d,coeffo,o,s,coef,case,typ,body="",mark="",pdeargs="",add_jump=False):
21 gross 589 if mark=="":
22 gross 769 name="test_assemblage_%sD_solO%s_coeffO%s_NEqu%s_%s_%s_type%s"%(d,o,coeffo,s,coef,case,typ)
23 gross 589 else:
24 gross 769 name="test_assemblage_%sD_solO%s_coeffO%s_NEqu%s_%s_%s_type%s_comp%s"%(d,o,coeffo,s,coef,case,typ,mark)
25     if typ.lower()=="contact":
26     key="%sDo%s_contact"%(d,o)
27     elif coeffo.lower()=="reduced":
28     key="%sDo%s_reduced"%(d,o)
29     else:
30     key="%sDo%s"%(d,o)
31 gross 766 t_prog[key]+=intend+"#"+50*"="+"\n"+intend+"def %s(self):\n"%name
32     t_prog[key]+=2*intend+"x=self.domain.getX()\n"
33     if add_jump:
34     t_prog[key]+=2*intend+"jump=Data(0.,(),ContinuousFunction(self.domain))\n"
35     t_prog[key]+=2*intend+"jump.setTaggedValue(2,1.)\n"
36     t_prog[key]+=body
37     t_prog[key]+=2*intend+"pde=LinearPDE(self.domain)\n"
38     t_prog[key]+=2*intend+"pde.setValue(%s)\n"%pdeargs
39     t_prog[key]+=2*intend+"r=pde.getResidual(u)\n"
40     t_prog[key]+=2*intend+"rhs=pde.getRightHandSide()\n"
41     t_prog[key]+=2*intend+"self.failUnless(Lsup(rhs)>0,\"right hand side is zero\")\n"
42     t_prog[key]+=2*intend+"self.failUnless(Lsup(r)<=self.RES_TOL*Lsup(rhs),\"residual is too big\")\n"
43    
44     def getRandom():
45     out=0
46     while out==0:
47     out = int(18*random.random())-9
48     return out
49    
50     def makeTestSolution(order,ncomps,dim):
51     if dim == 2:
52     out=numarray.zeros((ncomps,max_order+1,max_order+1))
53     for d1 in range(order+1):
54     for d2 in range(order+1):
55     for k in range(ncomps):
56     out[k,d1,d2]=getRandom()
57     if dim == 3:
58     out=numarray.zeros((ncomps,max_order+1,max_order+1,max_order+1))
59     for d1 in range(order+1):
60     for d2 in range(order+1):
61     for d3 in range(order+1):
62     for k in range(ncomps):
63     out[k,d1,d2,d3]=getRandom()
64     return out
65    
66     def makeGradient(func,dim):
67     sh=func.shape
68     if len(sh)==dim+1:
69     sh_out=sh[:1]+(dim,)+sh[1:]
70     out=numarray.zeros(sh_out)
71     if dim==2:
72     for d1 in range(sh[1]-1):
73     for d2 in range(sh[2]-1):
74     for k in range(sh[0]):
75     out[k,0,d1,d2]=(d1+1)*func[k,d1+1,d2]
76     out[k,1,d1,d2]=(d2+1)*func[k,d1,d2+1]
77     else:
78     for d1 in range(sh[1]-1):
79     for d2 in range(sh[2]-1):
80     for d3 in range(sh[3]-1):
81     for k in range(sh[0]):
82     out[k,0,d1,d2,d3]=(d1+1)*func[k,d1+1,d2,d3]
83     out[k,1,d1,d2,d3]=(d2+1)*func[k,d1,d2+1,d3]
84     out[k,2,d1,d2,d3]=(d3+1)*func[k,d1,d2,d3+1]
85     elif len(sh)==dim+2:
86     raise RunTimeError,"sdfadsa"
87     sh_out=sh[:2]+(dim,)+sh[2:]
88     out=numarray.zeros(sh_out)
89 gross 589 else:
90 gross 766 raise RunTimeError,"sdfadsa"
91     return out
92 gross 589
93 gross 766 def makeDiv(func,dim):
94     sh=func.shape
95     if len(sh)==dim+1:
96     sh_out=(1,)+sh[1:]
97     out=numarray.zeros(sh_out)
98     if dim==2:
99     for d1 in range(sh[1]-1):
100     for d2 in range(sh[2]-1):
101     for k in range(sh[0]):
102     out[0,d1,d2]=(d1+1)*func[0,d1+1,d2]+(d2+1)*func[1,d1,d2+1]
103     else:
104     for d1 in range(sh[1]-1):
105     for d2 in range(sh[2]-1):
106     for d3 in range(sh[3]-1):
107     for k in range(sh[0]):
108     out[0,d1,d2,d3]=(d1+1)*func[0,d1+1,d2,d3]+(d2+1)*func[1,d1,d2+1,d3]+(d3+1)*func[2,d1,d2,d3+1]
109     elif len(sh)==dim+2:
110     sh_out=(sh[0],)+sh[2:]
111     out=numarray.zeros(sh_out)
112     if dim==2:
113     for d1 in range(sh[2]-1):
114     for d2 in range(sh[3]-1):
115     for k in range(sh[0]):
116     out[k,d1,d2]=(d1+1)*func[k,0,d1+1,d2]+(d2+1)*func[k,1,d1,d2+1]
117     else:
118     for d1 in range(sh[2]-1):
119     for d2 in range(sh[3]-1):
120     for d3 in range(sh[4]-1):
121     for k in range(sh[0]):
122     out[k,d1,d2,d3]=(d1+1)*func[k,0,d1+1,d2,d3]+(d2+1)*func[k,1,d1,d2+1,d3]+(d3+1)*func[k,2,d1,d2,d3+1]
123     else:
124     raise RunTimeError,"sdfadsa"
125     return out
126    
127     def multiplyByFandX(f,n,func,in_index,out_shape,out_index):
128     if n==0:
129     n1=1
130     else:
131     n1=0
132     if n==1:
133     n2=1
134     else:
135     n2=0
136     if n==2:
137     n3=1
138     else:
139     n3=0
140    
141     sh=func.shape
142     dim=len(sh)-len(in_index)
143     sh_out=out_shape+sh[len(in_index):]
144     out=numarray.zeros(sh_out)
145     if len(in_index)==1:
146     if len(out_index)==1:
147     if dim==2:
148     for d1 in range(n1,sh[1]):
149     for d2 in range(n2,sh[2]):
150     out[out_index[0],d1,d2]=f*func[in_index[0],d1-n1,d2-n2]
151    
152     else:
153     for d1 in range(n1,sh[1]):
154     for d2 in range(n2,sh[2]):
155     for d3 in range(n3,sh[3]):
156     out[out_index[0],d1,d2,d3]=f*func[in_index[0],d1-n1,d2-n2,d3-n3]
157    
158     elif len(out_index)==2:
159     if dim==2:
160     for d1 in range(n1,sh[1]):
161     for d2 in range(n2,sh[2]):
162     out[out_index[0],out_index[1],d1,d2]=f*func[in_index[0],d1-n1,d2-n2]
163     else:
164     for d1 in range(n1,sh[1]):
165     for d2 in range(n2,sh[2]):
166     for d3 in range(n3,sh[3]):
167     out[out_index[0],out_index[1],d1,d2,d3]=f*func[in_index[0],d1-n1,d2-n2,d3-n3]
168    
169     else:
170     raise RunTimeError,"sdfadsa"
171    
172     elif len(in_index)==2:
173     if len(out_index)==1:
174     if dim==2:
175     for d1 in range(n1,sh[2]):
176     for d2 in range(n2,sh[3]):
177     out[out_index[0],d1,d2]=f*func[in_index[0],in_index[1],d1-n1,d2-n2]
178     else:
179     for d1 in range(n1,sh[2]):
180     for d2 in range(n2,sh[3]):
181     for d3 in range(n3,sh[4]):
182     out[out_index[0],d1,d2,d3]=f*func[in_index[0],in_index[1],d1-n1,d2-n2,d3-n3]
183    
184     elif len(out_index)==2:
185     if dim==2:
186     for d1 in range(n1,sh[2]):
187     for d2 in range(n2,sh[3]):
188     out[out_index[0],out_index[1],d1,d2]=f*func[in_index[0],in_index[1],d1-n1,d2-n2]
189     else:
190     for d1 in range(n1,sh[2]):
191     for d2 in range(n2,sh[3]):
192     for d3 in range(n3,sh[4]):
193     out[out_index[0],out_index[1],d1,d2,d3]=f*func[in_index[0],in_index[1],d1-n1,d2-n2,d3-n3]
194    
195     else:
196     raise RunTimeError,"sdfadsa"
197     else:
198     raise RunTimeError,"sdfadsa"
199     return out
200    
201     def powTextforX(c,e):
202     if e==0:
203     out=""
204     elif e==1:
205     out="x[%s]"%c
206     else:
207     out="x[%s]**%s"%(c,e)
208     return out
209     def multTextFactors(*txt):
210     out=""
211     for t in txt:
212     if len(t)>0:
213     if len(out)==0:
214     out=t
215     else:
216     out+="*"+t
217     return out
218    
219     def addSumTermText(txt,f,fac):
220     if len(fac)>0:
221     fac2="*"+fac
222     if f>0:
223     if f==1:
224     if len(txt)==0:
225     out="%s"%fac
226     else:
227     out="+%s"%fac
228     else:
229     if len(txt)==0:
230     out="%s%s"%(f,fac2)
231     else:
232     out="+%s%s"%(f,fac2)
233     elif f<0:
234     if f==1:
235     out="-%s"%fac
236     else:
237     if len(txt)==0:
238     out="(-%s)%s"%(-f,fac2)
239     else:
240     out="-%s%s"%(-f,fac2)
241     else:
242     out=""
243     else:
244     if f>0:
245     if f==1:
246     if len(txt)==0:
247     out="1"
248     else:
249     out="+1"
250     else:
251     if len(txt)==0:
252     out="%s"%f
253     else:
254     out="+%s"%f
255     elif f<0:
256     if f==1:
257     out="-1"
258     else:
259     if len(txt)==0:
260     out="(-%s)"%(-f,)
261     else:
262     out="-%s"%(-f,)
263     else:
264     out=""
265    
266     return txt+out
267    
268     def makeTermText(func):
269     sh=func.shape
270     out=""
271     if len(sh)==2:
272     for d1 in range(sh[0]):
273     for d2 in range(sh[1]):
274     fac=multTextFactors(powTextforX(0,d1),powTextforX(1,d2))
275     out=addSumTermText(out,func[d1,d2],fac)
276     else:
277     for d1 in range(sh[0]):
278     for d2 in range(sh[1]):
279     for d3 in range(sh[2]):
280     fac=multTextFactors(powTextforX(0,d1),powTextforX(1,d2),powTextforX(2,d3))
281     out=addSumTermText(out,func[d1,d2,d3],fac)
282     if len(out)==0:
283     return "0"
284     else:
285     return out
286     def makeContactDerivativeText(func,dim,func_name):
287     sh=func.shape
288 gross 768 out=2*intend+"n_contact=FunctionOnContactZero(self.domain).getNormal()\n"
289 gross 766 if len(sh)==dim+2:
290     if sh[0]==1:
291     out2=""
292     for j in range(sh[1]):
293     t=makeTermText(func[0,j])
294     if not t == "0":
295 gross 768 if j==0:
296     if len(out2)>0: out2+="+"
297     out2+=t
298 gross 766 if len(out2)==0:
299     out+=2*intend+"%s=%s\n"%(func_name,0)
300     else:
301 gross 768 out+=2*intend+"%s=n_contact[0]*(%s)\n"%(func_name,out2)
302 gross 766 else:
303     out+=2*intend+"%s=Data(0.,%s,FunctionOnContactZero(self.domain))\n"%(func_name,str(tuple(sh[:1])))
304     for i in range(sh[0]):
305     out2=""
306     for j in range(sh[1]):
307     t=makeTermText(func[i,j])
308     if not t == "0":
309 gross 768 if j==0:
310     if len(out2)>0: out2+="+"
311     out2+="%s"%t
312 gross 766 if len(out2)>0:
313 gross 768 out+=2*intend+"%s[%s]=n_contact[0]*(%s)\n"%(func_name,i,out2)
314 gross 766 else:
315     raise RunTimeError,"KKK"
316     return out
317    
318     def makeNormalDerivativeText(func,dim,func_name,add_jump=False):
319     sh=func.shape
320     out=""
321     if add_jump:
322     extra=")*jump"
323     extra_pre="("
324     else:
325     extra=""
326     extra_pre=""
327    
328     out=2*intend+"x_boundary=FunctionOnBoundary(self.domain).getX()\n"
329     if dim==3:
330     out+=2*intend+"n=%swhereZero(x_boundary[0] ,self.ABS_TOL)*numarray.array([-1., 0., 0.])"%extra_pre
331     out+="+whereZero(x_boundary[0]-1.,self.ABS_TOL)*numarray.array([ 1., 0., 0.])"
332     out+="+whereZero(x_boundary[1] ,self.ABS_TOL)*numarray.array([ 0.,-1., 0.])"
333     out+="+whereZero(x_boundary[1]-1.,self.ABS_TOL)*numarray.array([ 0., 1., 0.])"
334     out+="+whereZero(x_boundary[2] ,self.ABS_TOL)*numarray.array([ 0., 0.,-1.])"
335     out+="+whereZero(x_boundary[2]-1.,self.ABS_TOL)*numarray.array([ 0., 0., 1.])%s\n"%extra
336     else:
337     out+=2*intend+"n=%swhereZero(x_boundary[0] ,self.ABS_TOL)*numarray.array([-1., 0.])"%extra_pre
338     out+="+whereZero(x_boundary[0]-1.,self.ABS_TOL)*numarray.array([ 1., 0.])"
339     out+="+whereZero(x_boundary[1] ,self.ABS_TOL)*numarray.array([ 0.,-1.])"
340     out+="+whereZero(x_boundary[1]-1.,self.ABS_TOL)*numarray.array([ 0., 1.])%s\n"%extra
341     if len(sh)==dim+2:
342     if sh[0]==1:
343     out2=""
344     for j in range(sh[1]):
345     t=makeTermText(func[0,j])
346     if not t == "0":
347     if len(out2)>0: out2+="+"
348     out2+="n[%s]*(%s)"%(j,t)
349     if len(out2)==0:
350     out+=2*intend+"%s=%s\n"%(func_name,0)
351     else:
352 gross 768 out+=2*intend+"%s=%s%s%s\n"%(func_name,extra_pre,out2,extra)
353 gross 766 else:
354     out+=2*intend+"%s=Data(0.,%s,FunctionOnBoundary(self.domain))\n"%(func_name,str(tuple(sh[:1])))
355     for i in range(sh[0]):
356     out2=""
357     for j in range(sh[1]):
358     t=makeTermText(func[i,j])
359     if not t == "0":
360     if len(out2)>0: out2+="+"
361     out2+="n[%s]*(%s)"%(j,t)
362     if len(out2)>0:
363 gross 768 out+=2*intend+"%s[%s]=%s%s%s\n"%(func_name,i,extra_pre,out2,extra)
364 gross 766 else:
365     raise RunTimeError,"KKK"
366     return out
367    
368     def makeFunctionText(func,dim,func_name,add_jump=False):
369     sh=func.shape
370     out=""
371     if add_jump:
372     extra=")*jump"
373     extra_pre="("
374     else:
375     extra=""
376     extra_pre=""
377    
378     if len(sh)==dim:
379     out+=2*intend+"%s=%s%s%s\n"%(func_name,extra_pre,makeTermText(func),extra)
380     elif len(sh)==dim+1:
381     if sh[0]==1:
382     out+=2*intend+"%s=%s%s%s\n"%(func_name,extra_pre,makeTermText(func[0]),extra)
383     else:
384     out+=2*intend+"%s=Data(0.,%s,ContinuousFunction(self.domain))\n"%(func_name,str(tuple(sh[:1])))
385     for i in range(sh[0]):
386     t=makeTermText(func[i])
387     if not t=="0": out+=2*intend+"%s[%s]=%s%s%s\n"%(func_name,i,extra_pre,t,extra)
388     elif len(sh)==dim+2:
389     if sh[0]==1:
390     if sh[1]==1:
391     out+=2*intend+"%s=%s%s%s\n"%(func_name,extra_pre,makeTermText(func[0,0]),extra)
392     else:
393     out+=2*intend+"%s=Data(0.,%s,ContinuousFunction(self.domain))\n"%(func_name,str(tuple(sh[1:2])))
394     for j in range(sh[1]):
395     t=makeTermText(func[0,j])
396     if not t=="0": out+=2*intend+"%s[%s]=%s%s%s\n"%(func_name,j,extra_pre,t,extra)
397     else:
398     if sh[1]==1:
399     out+=2*intend+"%s=Data(0.,%s,ContinuousFunction(self.domain))\n"%(func_name,str(tuple(sh[:1])))
400     for i in range(sh[0]):
401     t=makeTermText(func[i,0])
402     if not t=="0": out+=2*intend+"%s[%s]=%s%s%s\n"%(func_name,i,extra_pre,t,extra)
403     else:
404     out+=2*intend+"%s=Data(0.,%s,ContinuousFunction(self.domain))\n"%(func_name,str(tuple(sh[:2])))
405     for i in range(sh[0]):
406     for j in range(sh[1]):
407     t=makeTermText(func[i,j])
408     if not t=="0": out+=2*intend+"%s[%s,%s]=%s%s%s\n"%(func_name,i,j,extra_pre,t,extra)
409     return out
410 gross 769 for s in [1,2,3]:
411 gross 589 for d in [2,3]:
412 gross 766 for typ in ["Strong","Weak", "Contact"]:
413 gross 769 for coffo in ["Full", "Reduced" ]:
414 gross 766 if coffo=="Full":
415     func_i="Function"
416     else:
417     func_i="ReducedFunction"
418     for case in ["Const", "Vario" ]:
419     for solo in [1, 2 ]:
420     order=solo
421     if typ in ["Strong","Weak"]:
422     # coefficient A:
423     if s==1:
424 gross 589 for i in range(d):
425     for j in range(d):
426 gross 766 test_func=makeTestSolution(order,s,d)
427     grad_test_func=makeGradient(test_func,d)
428     body2=makeFunctionText(test_func,d,"u")
429     body2+=2*intend+"A_test=Data(0.,(%d,%d),%s(self.domain))\n"%(d,d,func_i)
430     if case == "Const" :
431     f=int(8*random.random())+1
432     body2+=2*intend+"A_test[%d,%d]=%s\n"%(i,j,f)
433     A_x_grad=multiplyByFandX(f,-1,grad_test_func,(0,j),(1,d),(0,i))
434     else:
435     body2+=2*intend+"A_test[%d,%d]=x[%s]\n"%(i,j,i)
436     A_x_grad=multiplyByFandX(1.,i,grad_test_func,(0,j),(1,d),(0,i))
437     if typ=="Weak":
438     body2+=makeFunctionText(A_x_grad,d,"X_test")
439     args="A=A_test, X=X_test"
440     else:
441     div_A_x_grad=makeDiv(A_x_grad,d)
442     body2+=makeFunctionText(-div_A_x_grad,d,"Y_test")
443     body2+=makeNormalDerivativeText(A_x_grad,d,"y_test")
444     args="A=A_test, Y=Y_test, y=y_test"
445    
446     makeTitle(d,coffo,solo,s,"A",case,typ,body2,mark="%s%s"%(i,j),pdeargs=args)
447     else:
448 gross 589 for p in range(s):
449     for i in range(d):
450     for q in range(s):
451     for j in range(d):
452 gross 766 test_func=makeTestSolution(order,s,d)
453     grad_test_func=makeGradient(test_func,d)
454     body2=makeFunctionText(test_func,d,"u")
455     body2+=2*intend+"A_test=Data(0.,(%d,%d,%d,%d),%s(self.domain))\n"%(s,d,s,d,func_i)
456     if case == "Const" :
457     f=int(8*random.random())+1
458     body2+=2*intend+"A_test[%d,%d,%d,%d]=%s\n"%(p,i,q,j,f)
459     A_x_grad=multiplyByFandX(f,-1,grad_test_func,(q,j),(s,d),(p,i))
460     else:
461     body2+=2*intend+"A_test[%d,%d,%d,%d]=x[%s]\n"%(p,i,q,j,i)
462     A_x_grad=multiplyByFandX(1.,i,grad_test_func,(q,j),(s,d),(p,i))
463     if typ=="Weak":
464     body2+=makeFunctionText(A_x_grad,d,"X_test")
465     args="A=A_test, X=X_test"
466     else:
467     div_A_x_grad=makeDiv(A_x_grad,d)
468     body2+=makeFunctionText(-div_A_x_grad,d,"Y_test")
469     body2+=makeNormalDerivativeText(A_x_grad,d,"y_test")
470     args="A=A_test, Y=Y_test, y=y_test"
471     makeTitle(d,coffo,solo,s,"A",case,typ,body2,mark="%s%s%s%s"%(p,i,q,j),pdeargs=args)
472 gross 589 # coefficient B:
473 gross 769 if typ in ["Strong","Weak"] or coffo=="Full":
474     if s==1:
475 gross 589 for i in range(d):
476 gross 769 test_func=makeTestSolution(order,s,d)
477     body2=makeFunctionText(test_func,d,"u")
478     body2+=2*intend+"B_test=Data(0.,(%d,),%s(self.domain))\n"%(d,func_i)
479     if case == "Const" :
480     f=int(8*random.random())+1
481     body2+=2*intend+"B_test[%d]=%s\n"%(i,f)
482     B=multiplyByFandX(f,-1,test_func,(0,),(1,d),(0,i))
483     else:
484     body2+=2*intend+"B_test[%d]=x[%i]\n"%(i,i)
485     B=multiplyByFandX(1.,i,test_func,(0,),(1,d),(0,i))
486     if typ=="Weak":
487     body2+=makeFunctionText(B,d,"X_test")
488     args="B=B_test, X=X_test"
489     elif typ=="Strong":
490     div_B=makeDiv(B,d)
491     body2+=makeFunctionText(-div_B,d,"Y_test")
492     body2+=makeNormalDerivativeText(B,d,"y_test")
493     args="B=B_test, Y=Y_test, y=y_test"
494     else:
495     div_B=makeDiv(B,d)
496     body2+=makeFunctionText(-div_B,d,"Y_test")
497     body2+=makeNormalDerivativeText(B,d,"y_test")
498     body2+=makeContactDerivativeText(-B,d,"y_contact_test")
499     args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"
500     makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s"%(i),pdeargs=args)
501     else:
502     for p in range(s):
503     for i in range(d):
504     for q in range(s):
505     test_func=makeTestSolution(order,s,d)
506     grad_test_func=makeGradient(test_func,d)
507     body2=makeFunctionText(test_func,d,"u")
508     body2+=2*intend+"B_test=Data(0.,(%d,%d,%d),%s(self.domain))\n"%(s,d,s,func_i)
509     if case == "Const" :
510     f=int(8*random.random())+1
511     body2+=2*intend+"B_test[%d,%d,%d]=%s\n"%(p,i,q,f)
512     B=multiplyByFandX(f,-1,test_func,(q,),(s,d),(p,i))
513     else:
514     body2+=2*intend+"B_test[%d,%d,%d]=x[%i]\n"%(p,i,q,i)
515     B=multiplyByFandX(1.,i,test_func,(q,),(s,d),(p,i))
516     if typ=="Weak":
517     body2+=makeFunctionText(B,d,"X_test")
518     args="B=B_test, X=X_test"
519     elif typ=="Strong":
520     div_B=makeDiv(B,d)
521     body2+=makeFunctionText(-div_B,d,"Y_test")
522     body2+=makeNormalDerivativeText(B,d,"y_test")
523     args="B=B_test, Y=Y_test, y=y_test"
524     else:
525     div_B=makeDiv(B,d)
526     body2+=makeFunctionText(-div_B,d,"Y_test")
527     body2+=makeNormalDerivativeText(B,d,"y_test")
528     body2+=makeContactDerivativeText(-B,d,"y_contact_test")
529     args="B=B_test, Y=Y_test, y=y_test, y_contact=y_contact_test"
530     makeTitle(d,coffo,solo,s,"B",case,typ,body2,mark="%s%s%s"%(p,i,q),pdeargs=args)
531 gross 766 if typ=="Strong":
532 gross 589 # coefficient C:
533     if s==1:
534     for j in range(d):
535 gross 766 test_func=makeTestSolution(order,s,d)
536     grad_test_func=makeGradient(test_func,d)
537     body2=makeFunctionText(test_func,d,"u")
538     body2+=2*intend+"C_test=Data(0.,(%d,),%s(self.domain))\n"%(d,func_i)
539     if case == "Const" :
540     f=int(8*random.random())+1
541     body2+=2*intend+"C_test[%d]=%s\n"%(j,f)
542     C_x_grad=multiplyByFandX(f,-1,grad_test_func,(0,j),(1,),(0,))
543     else:
544     body2+=2*intend+"C_test[%d]=x[%i]\n"%(j,j)
545     C_x_grad=multiplyByFandX(1,j,grad_test_func,(0,j),(1,),(0,))
546     body2+=makeFunctionText(C_x_grad,d,"Y_test")
547     args="C=C_test, Y=Y_test"
548     makeTitle(d,coffo,solo,s,"C",case,typ,body2,mark="%s"%(j),pdeargs=args)
549 gross 589 else:
550     for p in range(s):
551 gross 766 for q in range(s):
552     for j in range(d):
553     test_func=makeTestSolution(order,s,d)
554     grad_test_func=makeGradient(test_func,d)
555     body2=makeFunctionText(test_func,d,"u")
556     body2+=2*intend+"C_test=Data(0.,(%d,%d,%d),%s(self.domain))\n"%(s,s,d,func_i)
557     if case == "Const" :
558     f=int(8*random.random())+1
559     body2+=2*intend+"C_test[%d,%d,%d]=%s\n"%(p,q,j,f)
560     C_x_grad=multiplyByFandX(f,-1,grad_test_func,(q,j),(s,),(p,))
561     else:
562     body2+=2*intend+"C_test[%d,%d,%d]=x[%i]\n"%(p,q,j,j)
563     C_x_grad=multiplyByFandX(1.,j,grad_test_func,(q,j),(s,),(p,))
564     args="C=C_test, Y=Y_test"
565     body2+=makeFunctionText(C_x_grad,d,"Y_test")
566     makeTitle(d,coffo,solo,s,"C",case,typ,body2,mark="%s%s%s"%(p,q,j),pdeargs=args)
567 gross 589 # coefficient D:
568     if s==1:
569 gross 766 if case == "Const" :
570     test_func=makeTestSolution(order,s,d)
571     else:
572     test_func=makeTestSolution(order-1,s,d)
573     body2=makeFunctionText(test_func,d,"u")
574     if case == "Const" :
575     f=int(8*random.random())+1
576     body2+=2*intend+"D_test=Data(%s,(),%s(self.domain))\n"%(f,func_i)
577     D=multiplyByFandX(f,-1,test_func,(0,),(1,),(0,))
578     else:
579     body2+=2*intend+"D_test=%s(self.domain).getX()[0]\n"%func_i
580     D=multiplyByFandX(1,0,test_func,(0,),(1,),(0,))
581     args="D=D_test, Y=Y_test"
582     body2+=makeFunctionText(D,d,"Y_test")
583     makeTitle(d,coffo,solo,s,"D",case,typ,body2,mark="",pdeargs=args)
584 gross 589 else:
585     for p in range(s):
586     for q in range(s):
587 gross 766 if case == "Const" :
588     test_func=makeTestSolution(order,s,d)
589     else:
590     test_func=makeTestSolution(order-1,s,d)
591     body2=makeFunctionText(test_func,d,"u")
592     body2+=2*intend+"D_test=Data(0.,(%d,%d),%s(self.domain))\n"%(s,s,func_i)
593     if case == "Const" :
594     f=int(8*random.random())+1
595     body2+=2*intend+"D_test[%d,%d]=%s\n"%(p,q,f)
596     D=multiplyByFandX(f,-1,test_func,(q,),(s,),(p,))
597     else:
598     body2+=2*intend+"D_test[%d,%d]=x[0]\n"%(p,q)
599     D=multiplyByFandX(1.,0,test_func,(q,),(s,),(p,))
600     args="D=D_test, Y=Y_test"
601     body2+=makeFunctionText(D,d,"Y_test")
602     makeTitle(d,coffo,solo,s,"D",case,typ,body2,mark="%s%s"%(p,q),pdeargs=args)
603     if coffo=="Full":
604     # coefficient d:
605     if typ == "Strong":
606     if s==1:
607     if case == "Const" :
608     test_func=makeTestSolution(order,s,d)
609     else:
610     test_func=makeTestSolution(order-1,s,d)
611     body2=makeFunctionText(test_func,d,"u")
612     if case == "Const" :
613     f=int(8*random.random())+1
614     body2+=2*intend+"d_test=Data(%s,(),FunctionOnBoundary(self.domain))\n"%(f,)
615     D=multiplyByFandX(f,-1,test_func,(0,),(1,),(0,))
616     else:
617     body2+=2*intend+"d_test=interpolate(x[0],FunctionOnBoundary(self.domain))\n"
618     D=multiplyByFandX(1.,0,test_func,(0,),(1,),(0,))
619     body2+=makeFunctionText(D,d,"y_test")
620     args="d=d_test, y=y_test"
621     makeTitle(d,coffo,solo,s,"d",case,typ,body2,mark="",pdeargs=args)
622     else:
623     for p in range(s):
624     for q in range(s):
625     if case == "Const" :
626     test_func=makeTestSolution(order,s,d)
627     else:
628     test_func=makeTestSolution(order-1,s,d)
629     body2=makeFunctionText(test_func,d,"u")
630     body2+=2*intend+"d_test=Data(0.,(%d,%d),FunctionOnBoundary(self.domain))\n"%(s,s)
631     if case == "Const" :
632     f=int(8*random.random())+1
633     body2+=2*intend+"d_test[%d,%d]=%s\n"%(p,q,f)
634     D=multiplyByFandX(f,-1,test_func,(q,),(s,),(p,))
635     else:
636     body2+=2*intend+"d_test[%d,%d]=x[0]\n"%(p,q)
637    
638     D=multiplyByFandX(1.,0,test_func,(q,),(s,),(p,))
639     args="d=d_test, y=y_test"
640     body2+=makeFunctionText(D,d,"y_test")
641     makeTitle(d,coffo,solo,s,"d",case,typ,body2,mark="%s%s"%(p,q),pdeargs=args)
642     # coefficient d_contact:
643     if typ == "Contact":
644     if s==1:
645     if case == "Const" :
646     test_func=makeTestSolution(order,s,d)
647     else:
648     test_func=makeTestSolution(order-1,s,d)
649    
650     body2=makeFunctionText(test_func,d,"u",add_jump=True)
651     if case == "Const" :
652     f=int(8*random.random())+1
653     body2+=2*intend+"d_contact_test=Data(%s,(),FunctionOnContactZero(self.domain))\n"%(f,)
654     D=multiplyByFandX(f,-1,test_func,(0,),(1,),(0,))
655     else:
656     body2+=2*intend+"d_contact_test=interpolate(x[0],FunctionOnContactZero(self.domain))\n"
657     D=multiplyByFandX(1.,0,test_func,(0,),(1,),(0,))
658     body2+=makeFunctionText(D,d,"y_contact_test")
659     args="d_contact=d_contact_test, y_contact=y_contact_test"
660     makeTitle(d,coffo,solo,s,"d_contact",case,typ,body2,mark="",pdeargs=args,add_jump=True)
661     else:
662     for p in range(s):
663     for q in range(s):
664     if case == "Const" :
665     test_func=makeTestSolution(order,s,d)
666     else:
667     test_func=makeTestSolution(order-1,s,d)
668    
669     body2=makeFunctionText(test_func,d,"u",add_jump=True)
670     body2+=2*intend+"d_contact_test=Data(0.,(%d,%d),FunctionOnContactZero(self.domain))\n"%(s,s)
671     if case == "Const" :
672     f=int(8*random.random())+1
673     body2+=2*intend+"d_contact_test[%d,%d]=%s\n"%(p,q,f)
674     D=multiplyByFandX(f,-1,test_func,(q,),(s,),(p,))
675     else:
676     body2+=2*intend+"d_contact_test[%d,%d]=x[0]\n"%(p,q)
677     D=multiplyByFandX(1.,0,test_func,(q,),(s,),(p,))
678     body2+=makeFunctionText(D,d,"y_contact_test")
679     args="d_contact=d_contact_test, y_contact=y_contact_test"
680     makeTitle(d,coffo,solo,s,"d_contact",case,typ,body2,mark="%s%s"%(p,q),pdeargs=args,add_jump=True
681     )
682     #================================
683 gross 589 print "import unittest"
684     print "import numarray"
685     print "from esys.escript import *"
686     print "from esys.finley import Rectangle,Brick"
687 gross 769 print "class Test_assemblage_2Do1(unittest.TestCase):"
688     print t_prog["2Do1"]
689     print "class Test_assemblage_2Do1_Reduced(unittest.TestCase):"
690     print t_prog["2Do1_reduced"]
691 gross 766 print "class Test_assemblage_2Do1_Contact(unittest.TestCase):"
692 gross 589 print t_prog["2Do1_contact"]
693 gross 769
694     #print "class Test_assemblage_2Do2(unittest.TestCase):"
695     #print t_prog["2Do2"]
696     #print "class Test_assemblage_2Do2_Reduced(unittest.TestCase):"
697     #print t_prog["2Do2_reduced"]
698 gross 766 #print "class Test_assemblage_2Do2_Contact(unittest.TestCase):"
699     #print t_prog["2Do2_contact"]
700 gross 769
701     #print "class Test_assemblage_3Do1(unittest.TestCase):"
702     #print t_prog["3Do1"]
703     #print "class Test_assemblage_3Do1_Reduced(unittest.TestCase):"
704     #print t_prog["3Do1_reduced"]
705 gross 766 #print "class Test_assemblage_3Do1_Contact(unittest.TestCase):"
706     #print t_prog["3Do1_contact"]
707 gross 769
708     #print "class Test_assemblage_3Do2(unittest.TestCase):"
709     #print t_prog["3Do2"]
710     #print "class Test_assemblage_3Do2_Reduced(unittest.TestCase):"
711     #print t_prog["3Do2_reduced"]
712 gross 766 #print "class Test_assemblage_3Do2_contact(unittest.TestCase):"
713     #print t_prog["3Do2_contact"]
714 gross 589
715 gross 766
716 gross 769 print "from esys.escript import *"
717     print "from esys.finley import *"
718     print "from esys.escript.linearPDEs import LinearPDE"
719 gross 766 print "import numarray"
720     print "import unittest"
721 gross 769 print "NE=2 # number of element sin each spatial direction (must be even)"
722 gross 766
723 gross 769 print "class Test_Finley_assemblage_2Do1(Test_assemblage_2Do1):"
724     print " RES_TOL=1.e-7"
725     print " ABS_TOL=1.e-8"
726     print " def setUp(self):"
727     print " self.domain =Rectangle(NE,NE,1)"
728 gross 766 print "class Test_Finley_assemblage_2Do1_Contact(Test_assemblage_2Do1_Contact):"
729 gross 589 print " RES_TOL=1.e-7"
730 gross 766 print " ABS_TOL=1.e-8"
731 gross 589 print " def setUp(self):"
732 gross 769 print " d1 = Rectangle(n0=int(NE/2),n1=NE,l0=0.5,order=1,useElementsOnFace=True)"
733 gross 766 print " x1 = ContinuousFunction(d1).getX()"
734     print " ContinuousFunction(d1).setTags(1,Scalar(1,ContinuousFunction(d1)))"
735 gross 769 print " d2 = Rectangle(n0=int(NE/2),n1=NE,l0=0.5,order=1,useElementsOnFace=True)"
736 gross 766 print " ContinuousFunction(d2).setTags(2,Scalar(1,ContinuousFunction(d2)))"
737     print " d2.setX(d2.getX()+[0.5,0.])"
738     print " self.domain = JoinFaces([d1,d2])"
739 gross 589 print "suite = unittest.TestSuite()"
740 gross 769 print "suite.addTest(unittest.makeSuite(Test_Finley_assemblage_2Do1))"
741 gross 766 print "suite.addTest(unittest.makeSuite(Test_Finley_assemblage_2Do1_Contact))"
742 gross 589 print "unittest.TextTestRunner(verbosity=2).run(suite)"

  ViewVC Help
Powered by ViewVC 1.1.26