source: trunk/anuga_work/development/2010-projects/anuga_1d/sww-sudi/run-discrepancy.py @ 8427

Last change on this file since 8427 was 8427, checked in by davies, 13 years ago

Adding the trapezoidal channel validation test, and editing the ANUGA manual

File size: 3.9 KB
Line 
1import os, time, csv, pprint
2from scipy.special import jn
3from scipy import sin, cos, sqrt, linspace, pi, zeros
4from rootsearch import *
5from bisect_function import *
6from Numeric import zeros,Float,dot
7from gaussPivot import *
8from config import g
9from analytical_prescription import *
10
11
12def j0(x):
13    return jn(0.0, x)
14
15def j1(x):
16    return jn(1.0, x)
17
18def j2(x):
19    return jn(2.0, x)
20
21def j3(x):
22    return jn(3.0, x)
23
24def jm1(x):
25    return jn(-1.0, x)
26
27def jm2(x):
28    return jn(-2.0, x)
29
30def bed(x):
31    return x-1.0
32
33
34def wu_at_O_by_formal_expansion(t):
35    W1 = j0(4*pi/T)*cos(2*pi*t/T)
36    U1 = -j1(4*pi/T)*sin(2*pi*t/T)
37
38    gu = -2*pi/T*j0(4*pi/T)*sin(2*pi*t/T)
39    gw = -2*pi/T*j1(4*pi/T)*cos(2*pi*t/T)
40    fu = gw
41    fw = gu + j1(4*pi/T)*sin(2*pi*t/T)
42    W2 = gu*U1 + gw*W1 - 0.5*U1**2
43    U2 = fu*U1 + fw*W1
44
45    w = W1*A + W2*A*A
46    u = U1*A + U2*A*A
47    return w,u
48
49def wu_at_O_by_fixed_point_iteration(t):
50    w1 = A*j0(4.0*pi/T)*cos(2.0*pi*t/T)
51    u1 = -1.0*A*j1(4.0*pi/T)*sin(2.0*pi*t/T)
52
53    w2 = -0.5*u1**2.0 + A*j0(4.0*pi*(w1+1.0)**0.5/T)*cos(2.0*pi*(u1+t)/T)
54    u2 = -1.0*A*j1(4.0*pi*(w1+1.0)**0.5/T)*(w1+1.0)**-0.5*sin(2.0*pi*(u1+t)/T)
55
56    #w3 = -0.5*u2**2.0 + A*j0(4.0*pi*(w2+1.0)**0.5/T)*cos(2.0*pi*(u2+t)/T)
57    #u3 = -1.0*A*j1(4.0*pi*(w2+1.0)**0.5/T)*(w2+1.0)**-0.5*sin(2.0*pi*(u2+t)/T)
58
59    #w4 = -0.5*u3**2.0 + A*j0(4.0*pi*(w3+1.0)**0.5/T)*cos(2.0*pi*(u3+t)/T)
60    #u4 = -1.0*A*j1(4.0*pi*(w3+1.0)**0.5/T)*(w3+1.0)**-0.5*sin(2.0*pi*(u3+t)/T)
61
62    #w5 = -0.5*u4**2.0 + A*j0(4.0*pi*(w4+1.0)**0.5/T)*cos(2.0*pi*(u4+t)/T)
63    #u5 = -1.0*A*j1(4.0*pi*(w4+1.0)**0.5/T)*(w4+1.0)**-0.5*sin(2.0*pi*(u4+t)/T)   
64    return w2,u2
65
66
67Time = linspace(0.0,T,1000)
68N_T = len(Time)
69
70
71Stage = zeros(N_T, Float)   
72Veloc = zeros(N_T, Float)
73for i in range(N_T):
74    t=Time[i]
75    #print "Here.................................t=",t
76    zet, vel = prescribe(0.0,t)
77    Stage[i] = zet
78    Veloc[i] = vel
79
80
81Stage_sudi = zeros(N_T, Float)   
82Veloc_sudi = zeros(N_T, Float)
83for i in range(N_T):
84    t=Time[i]
85    Stage_sudi[i],Veloc_sudi[i] = wu_at_O_by_formal_expansion(t)#wu_at_O_by_fixed_point_iteration(t)
86
87
88num=len(Stage)
89error_w=(1.0/num)*sum(abs(Stage-Stage_sudi))*h_0
90error_u=(1.0/num)*sum(abs(Veloc-Veloc_sudi))*sqrt(g*h_0)
91print "error_w=", error_w
92print "error_u=", error_u
93
94#######Numerical C-G at centroids########
95table = zeros((num,3),Float)
96for r in range(num):
97    for c in range(3):
98        if c==0:
99            table[r][c] = Time[r]
100        elif c==1:
101            table[r][c] = Stage[r]
102        else:
103            table[r][c] = Veloc[r]
104
105outname = "%s%f%s" %("Exact_at_O_", Tp, ".csv")               
106outfile = open(outname, 'w')
107writer = csv.writer(outfile)
108for row in table:
109    writer.writerow(row)       
110outfile.close()
111
112
113#######Numerical stage and velocity########
114table = zeros((num,3),Float)
115for r in range(num):
116    for c in range(3):
117        if c==0:
118            table[r][c] = Time[r]
119        elif c==1:
120            table[r][c] = Stage_sudi[r]
121        else:
122            table[r][c] = Veloc_sudi[r]
123
124outname = "%s%f%s" %("Numeric_w2u2_FE_at_O_", Tp, ".csv")             
125outfile = open(outname, 'w')
126writer = csv.writer(outfile)
127for row in table:
128    writer.writerow(row)       
129outfile.close()
130
131from pylab import clf,plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot
132
133hold(False)
134clf()
135plot1 = subplot(211)
136plot(Time/T,Stage*h_0,'b-', Time/T,Stage_sudi*h_0,'k--')
137#xlabel('t/T')
138ylabel('Stage')
139#plot1.set_xlim([0.000,0.030])
140#plot1.set_ylim([0.980,1.005]) #([-9.0e-3,9.0e-3])
141legend(('C-G', 'M-R'),
142       'lower left', shadow=False)
143
144plot2 = subplot(212)
145plot(Time/T,Veloc*sqrt(g*h_0),'b-', Time/T,Veloc_sudi*sqrt(g*h_0),'k--')
146xlabel('t/T')
147ylabel('Velocity')
148#plot1.set_xlim([0.0,1.1])
149#plot2.set_ylim([-0.05,0.05]) #([-1.0e-12,1.0e-12])
150legend(('C-G', 'M-R'),
151       'upper right', shadow=False)
152
153
154#filename = "discrepancy-closer"
155#filename += str(i)
156#filename += ".eps"
157#savefig(filename)
158#show()
159
160#plot(Time,Vel_at_O)
161show()
Note: See TracBrowser for help on using the repository browser.