797 |
else: |
else: |
798 |
out+=tap+"%s[%s,%s,%s,%s]=o*(%s)*x_ref[%s]**(o-1)+(%s)\n"%(arg,i0,i1,i2,i99,a[i0,i1,i2,i99],i99,b[i0,i1,i2,i99]) |
out+=tap+"%s[%s,%s,%s,%s]=o*(%s)*x_ref[%s]**(o-1)+(%s)\n"%(arg,i0,i1,i2,i99,a[i0,i1,i2,i99],i99,b[i0,i1,i2,i99]) |
799 |
return out |
return out |
800 |
|
def unrollLoopsOfDiv(a,b,o,arg,tap=""): |
801 |
|
|
802 |
|
|
803 |
|
|
804 |
|
out=tap+arg+"=" |
805 |
|
if o=="1": |
806 |
|
z=0. |
807 |
|
for i99 in range(a.shape[0]): |
808 |
|
z+=b[i99,i99]+a[i99,i99] |
809 |
|
out+="(%s)"%z |
810 |
|
else: |
811 |
|
z=0. |
812 |
|
for i99 in range(a.shape[0]): |
813 |
|
z+=b[i99,i99] |
814 |
|
if i99>0: out+="+" |
815 |
|
out+="o*(%s)*x_ref[%s]**(o-1)"%(a[i99,i99],i99) |
816 |
|
out+="+(%s)"%z |
817 |
|
return out |
818 |
|
|
819 |
def unrollLoopsOfInteriorIntegral(a,b,where,arg,tap=""): |
def unrollLoopsOfInteriorIntegral(a,b,where,arg,tap=""): |
820 |
if where=="Function": |
if where=="Function": |
821 |
xfac_o=1. |
xfac_o=1. |
935 |
out+="+(%s)*0.5**o\n"%zop |
out+="+(%s)*0.5**o\n"%zop |
936 |
|
|
937 |
return out |
return out |
938 |
|
#======================================================================================================= |
939 |
|
# div |
940 |
|
#======================================================================================================= |
941 |
|
for where in ["Function","FunctionOnBoundary","FunctionOnContactZero","FunctionOnContactOne"]: |
942 |
|
for data in ["Data","Symbol"]: |
943 |
|
for case in ["ContinuousFunction","Solution","ReducedSolution"]: |
944 |
|
text=" #+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n" |
945 |
|
tname="test_div_on%s_from%s_%s"%(where,data,case) |
946 |
|
text+=" def %s(self):\n"%tname |
947 |
|
text+=" \"\"\"\n" |
948 |
|
text+=" tests divergence of %s on the %s\n\n"%(data,where) |
949 |
|
text+=" assumptions: %s(self.domain) exists\n"%case |
950 |
|
text+=" self.domain supports div on %s\n"%where |
951 |
|
text+=" \"\"\"\n" |
952 |
|
if case=="ReducedSolution": |
953 |
|
text+=" o=1\n" |
954 |
|
o="1" |
955 |
|
else: |
956 |
|
text+=" o=self.order\n" |
957 |
|
o="o" |
958 |
|
text+=" dim=self.domain.getDim()\n" |
959 |
|
text+=" w_ref=%s(self.domain)\n"%where |
960 |
|
text+=" x_ref=w_ref.getX()\n" |
961 |
|
text+=" w=%s(self.domain)\n"%case |
962 |
|
text+=" x=w.getX()\n" |
963 |
|
a_2=makeArray((2,2),[-1.,1]) |
964 |
|
b_2=makeArray((2,2),[-1.,1]) |
965 |
|
a_3=makeArray((3,3),[-1.,1]) |
966 |
|
b_3=makeArray((3,3),[-1.,1]) |
967 |
|
if data=="Symbol": |
968 |
|
text+=" arg=Symbol(shape=(dim,),dim=dim)\n" |
969 |
|
val="s" |
970 |
|
res="sub" |
971 |
|
else: |
972 |
|
val="arg" |
973 |
|
res="res" |
974 |
|
text+=" %s=Vector(0,w)\n"%val |
975 |
|
text+=" if dim==2:\n" |
976 |
|
text+=unrollLoops(a_2,b_2,o,val,tap=" ") |
977 |
|
text+=unrollLoopsOfDiv(a_2,b_2,o,"ref",tap=" ") |
978 |
|
text+="\n else:\n" |
979 |
|
|
980 |
|
text+=unrollLoops(a_3,b_3,o,val,tap=" ") |
981 |
|
text+=unrollLoopsOfDiv(a_3,b_3,o,"ref",tap=" ") |
982 |
|
text+="\n res=div(arg,where=w_ref)\n" |
983 |
|
if data=="Symbol": |
984 |
|
text+=" sub=res.substitute({arg:s})\n" |
985 |
|
text+=" self.failUnless(isinstance(res,%s),\"wrong type of result.\")\n"%data |
986 |
|
text+=" self.failUnlessEqual(res.getShape(),(),\"wrong shape of result.\")\n" |
987 |
|
text+=" self.failUnlessEqual(%s.getFunctionSpace(),w_ref,\"wrong function space of result.\")\n"%res |
988 |
|
text+=" self.failUnless(Lsup(%s-ref)<=self.RES_TOL*Lsup(ref),\"wrong result\")\n"%res |
989 |
|
|
990 |
|
|
991 |
|
t_prog+=text |
992 |
|
print t_prog |
993 |
|
1/0 |
994 |
|
|
995 |
#======================================================================================================= |
#======================================================================================================= |
996 |
# interpolation |
# interpolation |