696 |
else: |
else: |
697 |
out[i0,i1,i2,i3]=arg0[i0,i1,i2,i3] |
out[i0,i1,i2,i3]=arg0[i0,i1,i2,i3] |
698 |
return out |
return out |
699 |
def unrollLoops(a,b,o,arg,tap=""): |
def unrollLoops(a,b,o,arg,tap="",x="x"): |
700 |
out="" |
out="" |
701 |
if a.rank==1: |
if a.rank==1: |
702 |
z="" |
z="" |
703 |
for i99 in range(a.shape[0]): |
for i99 in range(a.shape[0]): |
704 |
if not z=="": z+="+" |
if not z=="": z+="+" |
705 |
if o=="1": |
if o=="1": |
706 |
z+="(%s)*x[%s]"%(a[i99]+b[i99],i99) |
z+="(%s)*%s[%s]"%(a[i99]+b[i99],x,i99) |
707 |
else: |
else: |
708 |
z+="(%s)*x[%s]**o+(%s)*x[%s]"%(a[i99],i99,b[i99],i99) |
z+="(%s)*%s[%s]**o+(%s)*%s[%s]"%(a[i99],x,i99,b[i99],x,i99) |
709 |
|
|
710 |
out+=tap+"%s=%s\n"%(arg,z) |
out+=tap+"%s=%s\n"%(arg,z) |
711 |
|
|
717 |
if o=="1": |
if o=="1": |
718 |
z+="(%s)*x[%s]"%(a[i0,i99]+b[i0,i99],i99) |
z+="(%s)*x[%s]"%(a[i0,i99]+b[i0,i99],i99) |
719 |
else: |
else: |
720 |
z+="(%s)*x[%s]**o+(%s)*x[%s]"%(a[i0,i99],i99,b[i0,i99],i99) |
z+="(%s)*%s[%s]**o+(%s)*%s[%s]"%(a[i0,i99],x,i99,b[i0,i99],x,i99) |
721 |
|
|
722 |
out+=tap+"%s[%s]=%s\n"%(arg,i0,z) |
out+=tap+"%s[%s]=%s\n"%(arg,i0,z) |
723 |
elif a.rank==3: |
elif a.rank==3: |
727 |
for i99 in range(a.shape[2]): |
for i99 in range(a.shape[2]): |
728 |
if not z=="": z+="+" |
if not z=="": z+="+" |
729 |
if o=="1": |
if o=="1": |
730 |
z+="(%s)*x[%s]"%(a[i0,i1,i99]+b[i0,i1,i99],i99) |
z+="(%s)*%s[%s]"%(a[i0,i1,i99]+b[i0,i1,i99],x,i99) |
731 |
else: |
else: |
732 |
z+="(%s)*x[%s]**o+(%s)*x[%s]"%(a[i0,i1,i99],i99,b[i0,i1,i99],i99) |
z+="(%s)*%s[%s]**o+(%s)*%s[%s]"%(a[i0,i1,i99],x,i99,b[i0,i1,i99],x,i99) |
733 |
|
|
734 |
out+=tap+"%s[%s,%s]=%s\n"%(arg,i0,i1,z) |
out+=tap+"%s[%s,%s]=%s\n"%(arg,i0,i1,z) |
735 |
elif a.rank==4: |
elif a.rank==4: |
740 |
for i99 in range(a.shape[3]): |
for i99 in range(a.shape[3]): |
741 |
if not z=="": z+="+" |
if not z=="": z+="+" |
742 |
if o=="1": |
if o=="1": |
743 |
z+="(%s)*x[%s]"%(a[i0,i1,i2,i99]+b[i0,i1,i2,i99],i99) |
z+="(%s)*%s[%s]"%(a[i0,i1,i2,i99]+b[i0,i1,i2,i99],x,i99) |
744 |
else: |
else: |
745 |
z+="(%s)*x[%s]**o+(%s)*x[%s]"%(a[i0,i1,i2,i99],i99,b[i0,i1,i2,i99],i99) |
z+="(%s)*%s[%s]**o+(%s)*%s[%s]"%(a[i0,i1,i2,i99],x,i99,b[i0,i1,i2,i99],x,i99) |
746 |
|
|
747 |
out+=tap+"%s[%s,%s,%s]=%s\n"%(arg,i0,i1,i2,z) |
out+=tap+"%s[%s,%s,%s]=%s\n"%(arg,i0,i1,i2,z) |
748 |
elif a.rank==5: |
elif a.rank==5: |
754 |
for i99 in range(a.shape[4]): |
for i99 in range(a.shape[4]): |
755 |
if not z=="": z+="+" |
if not z=="": z+="+" |
756 |
if o=="1": |
if o=="1": |
757 |
z+="(%s)*x[%s]"%(a[i0,i1,i2,i3,i99]+b[i0,i1,i2,i3,i99],i99) |
z+="(%s)*%s[%s]"%(a[i0,i1,i2,i3,i99]+b[i0,i1,i2,i3,i99],x,i99) |
758 |
else: |
else: |
759 |
z+="(%s)*x[%s]**o+(%s)*x[%s]"%(a[i0,i1,i2,i3,i99],i99,b[i0,i1,i2,i3,i99],i99) |
z+="(%s)*%s[%s]**o+(%s)*%s[%s]"%(a[i0,i1,i2,i3,i99],x,i99,b[i0,i1,i2,i3,i99],x,i99) |
760 |
|
|
761 |
out+=tap+"%s[%s,%s,%s,%s]=%s\n"%(arg,i0,i1,i2,i3,z) |
out+=tap+"%s[%s,%s,%s,%s]=%s\n"%(arg,i0,i1,i2,i3,z) |
762 |
return out |
return out |
917 |
|
|
918 |
return out |
return out |
919 |
|
|
920 |
|
#======================================================================================================= |
921 |
|
# interpolation |
922 |
|
#======================================================================================================= |
923 |
|
for where in ["Function","FunctionOnBoundary","FunctionOnContactZero","FunctionOnContactOne","Solution","ReducedSolution"]: |
924 |
|
for data in ["Data","Symbol"]: |
925 |
|
for case in ["ContinuousFunction","Solution","ReducedSolution","Function","FunctionOnBoundary","FunctionOnContactZero","FunctionOnContactOne"]: |
926 |
|
for sh in [ (),(2,), (4,5), (6,2,2),(4,5,3,2)]: |
927 |
|
if where==case or \ |
928 |
|
( case in ["ContinuousFunction","Solution","ReducedSolution"] and where in ["Function","FunctionOnBoundary","FunctionOnContactZero","FunctionOnContactOne"] ) or \ |
929 |
|
( case in ["FunctionOnContactZero","FunctionOnContactOne"] and where in ["FunctionOnContactZero","FunctionOnContactOne"] ) or \ |
930 |
|
(case=="ContinuousFunction" and where in ["Solution","ReducedSolution"]) or \ |
931 |
|
(case=="Solution" and where=="ReducedSolution") : |
932 |
|
|
933 |
|
|
934 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
935 |
|
tname="test_interpolation_on%s_from%s_%s_rank%s"%(where,data,case,len(sh)) |
936 |
|
text+=" def %s(self):\n"%tname |
937 |
|
text+=" \"\"\"\n" |
938 |
|
text+=" tests interpolation for rank %s %s onto the %s\n\n"%(len(sh),data,where) |
939 |
|
text+=" assumptions: self.domain supports inpterpolation from %s onto %s\n"%(case,where) |
940 |
|
text+=" \"\"\"\n" |
941 |
|
if case=="ReducedSolution" or where=="ReducedSolution": |
942 |
|
text+=" o=1\n" |
943 |
|
o="1" |
944 |
|
else: |
945 |
|
text+=" o=self.order\n" |
946 |
|
o="o" |
947 |
|
text+=" dim=self.domain.getDim()\n" |
948 |
|
text+=" w_ref=%s(self.domain)\n"%where |
949 |
|
text+=" x_ref=w_ref.getX()\n" |
950 |
|
text+=" w=%s(self.domain)\n"%case |
951 |
|
text+=" x=w.getX()\n" |
952 |
|
a_2=makeArray(sh+(2,),[-1.,1]) |
953 |
|
b_2=makeArray(sh+(2,),[-1.,1]) |
954 |
|
a_3=makeArray(sh+(3,),[-1.,1]) |
955 |
|
b_3=makeArray(sh+(3,),[-1.,1]) |
956 |
|
if data=="Symbol": |
957 |
|
text+=" arg=Symbol(shape=%s,dim=dim)\n"%str(sh) |
958 |
|
val="s" |
959 |
|
res="sub" |
960 |
|
else: |
961 |
|
val="arg" |
962 |
|
res="res" |
963 |
|
text+=" %s=Data(0,%s,w)\n"%(val,str(sh)) |
964 |
|
text+=" ref=Data(0,%s,w_ref)\n"%str(sh) |
965 |
|
text+=" if dim==2:\n" |
966 |
|
text+=unrollLoops(a_2,b_2,o,val,tap=" ") |
967 |
|
text+=unrollLoops(a_2,b_2,o,"ref",tap=" ",x="x_ref") |
968 |
|
text+=" else:\n" |
969 |
|
|
970 |
|
text+=unrollLoops(a_3,b_3,o,val,tap=" ") |
971 |
|
text+=unrollLoops(a_3,b_3,o,"ref",tap=" ",x="x_ref") |
972 |
|
text+=" res=interpolate(arg,where=w_ref)\n" |
973 |
|
if data=="Symbol": |
974 |
|
text+=" sub=res.substitute({arg:s})\n" |
975 |
|
text+=" self.failUnless(isinstance(res,%s),\"wrong type of result.\")\n"%data |
976 |
|
text+=" self.failUnlessEqual(%s.getFunctionSpace(),w_ref,\"wrong functionspace of result.\")\n"%res |
977 |
|
text+=" self.failUnlessEqual(res.getShape(),%s,\"wrong shape of result.\")\n"%str(sh) |
978 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
979 |
|
t_prog+=text |
980 |
|
print test_header |
981 |
|
print t_prog |
982 |
|
print test_tail |
983 |
|
1/0 |
984 |
|
|
985 |
#======================================================================================================= |
#======================================================================================================= |
986 |
# grad |
# grad |