def run_validation_script(script, np=1, cfl=None, alg=None, verbose=False): """ For backwards compatiblity wrap new run_anuga_script as run_validation_script """ from anuga import run_anuga_script run_anuga_script(script, np=np, cfl=cfl, alg=alg, verbose=verbose)
def produce_report(script, args=None): import anuga if args is None: args = anuga.get_args() verbose = args.verbose #print args # Get the arguments from the calling script run_anuga_script(script, args=args) # We don't want to run plot_results in parallel args.np = 1 run_anuga_script('plot_results.py', args=args) typeset_report(verbose=verbose)
def test_simulation(self): if verbose: print(indent + 'Running simulation script') s = 'run_okushiri.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print(indent + 'Running test script') s = 'test_results.py' res = os.system('python %s' % s) # Test that script runs ok assert res == 0
def test_simulation(self): if verbose: print indent+'Running simulation script' s = 'run_okushiri.py' res = anuga.run_anuga_script(s,args=args) # Test that script runs ok assert res == 0 if verbose: print indent+'Running test script' s = 'plot_results.py' res = os.system('python %s' %s) # Test that script runs ok assert res == 0
def test_dam_break_dry(self): if verbose: print print indent + 'Running simulation script' s = 'numerical_dam_break_dry.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + 'Testing accuracy' import anuga.utilities.plot_utils as util import analytical_dam_break_dry as analytic p_st = util.get_output('dam_break.sww') p2_st = util.get_centroids(p_st) v = p2_st.y[10] v2 = (p2_st.y == v) h0 = 1.0 h1 = 10.0 # calculate analytic values at various time slices h10, u10 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[10], h0=h0, h1=h1) h50, u50 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[50], h0=h0, h1=h1) h100, u100 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[100], h0=h0, h1=h1) #Test stages # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eh10 = numpy.sum(numpy.abs(p2_st.stage[10, v2] - h10)) / numpy.sum( numpy.abs(h10)) eh50 = numpy.sum(numpy.abs(p2_st.stage[50, v2] - h50)) / numpy.sum( numpy.abs(h50)) eh100 = numpy.sum(numpy.abs(p2_st.stage[100, v2] - h100)) / numpy.sum( numpy.abs(h100)) print print indent + 'Errors in stage: ', eh10, eh50, eh100 #Test xmomenta # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 euh10 = numpy.sum( numpy.abs(p2_st.xmom[10, v2] - u10 * h10)) / numpy.sum( numpy.abs(u10 * h10)) euh50 = numpy.sum( numpy.abs(p2_st.xmom[50, v2] - u50 * h50)) / numpy.sum( numpy.abs(u50 * h50)) euh100 = numpy.sum( numpy.abs(p2_st.xmom[100, v2] - u100 * h100)) / numpy.sum( numpy.abs(u100 * h100)) print indent + 'Errors in xmomentum: ', euh10, euh50, euh100 #Test xvelocity # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eu10 = numpy.sum(numpy.abs(p2_st.xvel[10, v2] - u10)) / numpy.sum( numpy.abs(u10)) eu50 = numpy.sum(numpy.abs(p2_st.xvel[50, v2] - u50)) / numpy.sum( numpy.abs(u50)) eu100 = numpy.sum(numpy.abs(p2_st.xvel[100, v2] - u100)) / numpy.sum( numpy.abs(u100)) print indent + 'Errors in xvelocity: ', eu10, eu50, eu100 assert eh10 < 0.1, 'Relative L^1 error %g greater than 0.1' % eh10 assert eh50 < 0.1, 'Relative L^1 error %g greater than 0.1' % eh50 assert eh100 < 0.15, 'Relative L^1 error %g greater than 0.15' % eh100 assert euh10 < 0.25, 'Relative L^1 error %g greater than 0.25' % euh10 assert euh50 < 0.25, 'Relative L^1 error %g greater than 0.25' % euh50 assert euh100 < 0.25, 'Relative L^1 error %g greater than 0.25' % euh100 assert eu10 < 2.0, 'Relative L^1 error %g greater than 2.0' % eu10 assert eu50 < 2.0, 'Relative L^1 error %g greater than 2.0' % eu50 assert eu100 < 0.3, 'Relative L^1 error %g greater than 0.3' % eu100
def test_avalanche_dry(self): if verbose: print print indent + 'Running simulation script' # Run basic script (can be parallel if -np used in call # to this script s = 'numerical_avalanche_dry.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + 'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_avalanche_dry import analytical_sol p_st = util.get_output('avalanche.sww') p2_st = util.get_centroids(p_st) v = p2_st.y[10] v2 = (p2_st.y == v) x_n = p2_st.x[v2] u0, h0, w0, z0, p0 = analytical_sol(x_n, p2_st.time[0]) u10, h10, w10, z10, p10 = analytical_sol(x_n, p2_st.time[10]) u30, h30, w30, z30, p30 = analytical_sol(x_n, p2_st.time[30]) w0_n = p2_st.stage[0, v2] w10_n = p2_st.stage[10, v2] w30_n = p2_st.stage[30, v2] z_n = p2_st.elev[v2] uh0_n = p2_st.xmom[0, v2] uh10_n = p2_st.xmom[10, v2] uh30_n = p2_st.xmom[30, v2] u0_n = p2_st.xvel[0, v2] u10_n = p2_st.xvel[10, v2] u30_n = p2_st.xvel[30, v2] #Test stages # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eh10 = numpy.sum(numpy.abs(w10_n - w10)) / numpy.sum(numpy.abs(w10)) eh30 = numpy.sum(numpy.abs(w30_n - w30)) / numpy.sum(numpy.abs(w30)) print print indent + 'Errors in stage: ', eh10, eh30 #Test xmomenta # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 euh10 = numpy.sum(numpy.abs(uh10_n - u10 * h10)) / numpy.sum( numpy.abs(u10 * h10)) euh30 = numpy.sum(numpy.abs(uh30_n - u30 * h30)) / numpy.sum( numpy.abs(u30 * h30)) print indent + 'Errors in xmomentum: ', euh10, euh30 #Test xvelocity # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eu10 = numpy.sum(numpy.abs(u10_n - u10)) / numpy.sum(numpy.abs(u10)) eu30 = numpy.sum(numpy.abs(u30_n - u30)) / numpy.sum(numpy.abs(u30)) print indent + 'Errors in xvelocity: ', eu10, eu30 assert eh10 < 0.01, 'L^1 error %g greater than 1 percent' % eh10 assert eh30 < 0.01, 'L^1 error %g greater than 1 percent' % eh30 assert euh10 < 0.025, 'L^1 error %g greater than 2.5 percent' % euh10 assert euh30 < 0.025, 'L^1 error %g greater than 2.5 percent' % euh30 assert eu10 < 0.2, 'L^1 error %g greater than 20 percent' % eu10 assert eu30 < 0.2, 'L^1 error %g greater than 20 percent' % eu30
def test_carrier_greenspan_transient(self): if verbose: print print indent + 'Running simulation script' s = 'numerical_cg_transient.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + 'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_cg_transient import analytical_sol p_st = util.get_output('carrier_greenspan.sww') p2_st = util.get_centroids(p_st) v = p2_st.y[10] v2 = (p2_st.y == v) x_n = p2_st.x[v2] ids = [1, 15, 30] use_absolute = [False, True, True] n = len(ids) W, UH, Z, H, U = [], [], [], [], [] W_n, U_n, UH_n = [], [], [] #Dimensional parameters L = 5e4 # Length of channel (m) h0 = 5e2 # Height at origin when the water is still g = 9.81 # Gravity for i, id in enumerate(ids): w, z, u = analytical_sol(x_n / L, p2_st.time[id] * sqrt(g * h0) / L) w = w * h0 z = z * h0 u = u * sqrt(g * h0) h = w - z uh = u * h W.append(w) Z.append(z) H.append(h) U.append(u) UH.append(uh) W_n.append(p2_st.stage[id, v2]) UH_n.append(p2_st.xmom[id, v2]) U_n.append(p2_st.xvel[id, v2]) #print id, numpy.max(H[i]), numpy.min(H[i]) #print id, numpy.max(U[i]), numpy.min(U[i]) #print id, numpy.max(U_n[i]), numpy.min(U_n[i]) #Test stages # Calculate L^1 error at times ew = numpy.zeros(n) for i, id in enumerate(ids): ew[i] = numpy.sum(numpy.abs(W_n[i] - W[i])) / numpy.sum( numpy.abs(W[i])) print print indent + 'L^1 Errors in stage: ', ew #Test xmomenta # Calculate L^1 error at times euh = numpy.zeros(n) for i, id in enumerate(ids): euh[i] = numpy.sum(numpy.abs(UH_n[i] - U[i] * H[i])) / numpy.sum( numpy.abs(UH_n[i])) print indent + 'L^1 Errors in xmomentum: ', euh #Test xvelocity # Calculate L^1 error at times eu = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: eu[i] = numpy.sum(numpy.abs(U_n[i] - U[i])) / len(U[i]) else: eu[i] = numpy.sum(numpy.abs(U_n[i] - U[i])) / numpy.sum( numpy.abs(U[i])) print indent + 'L^1 Errors in xvelocity: ', eu for i, id in enumerate(ids): assert ew[i] < 0.01, 'L^1 error %g greater than 1 percent' % ew[i] for i, id in enumerate(ids): assert euh[ i] < 0.025, 'L^1 error %g greater than 2.5 percent' % euh[i] for i, id in enumerate(ids): assert eu[ i] < 0.025, 'L^1 error %g greater than 2.5 percent' % eu[i]
def test_carrier_greenspan_periodic(self): if verbose: print print indent + 'Running simulation script' s = 'numerical_carrier_greenspan.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + 'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_carrier_greenspan import analytic_cg p_st = util.get_output('carrier_greenspan.sww') p2_st = util.get_centroids(p_st) v = p2_st.y[10] v2 = (p2_st.y == v) x_n = p2_st.x[v2] #ids = [288, 296, 304, 312, 320, 328] ids = [296, 304, 320, 328] # For the velocity and xmomentum calculations use # absolute error (as the exact solution is 0) use_absolute = [False, False, False, False] n = len(ids) W, P, Z, H, U = [], [], [], [], [] W_n, U_n, UH_n = [], [], [] for i, id in enumerate(ids): w0, p0, z0, h0, u0 = analytic_cg(x_n, p2_st.time[id], h0=5e2, L=5e4, a=1.0, Tp=900.0) W.append(w0) H.append(h0) U.append(u0) W_n.append(p2_st.stage[id, v2]) UH_n.append(p2_st.xmom[id, v2]) U_n.append(p2_st.xvel[id, v2]) #print id, numpy.max(H[i]), numpy.min(H[i]) #print id, numpy.max(U[i]), numpy.min(U[i]) #print id, numpy.max(U_n[i]), numpy.min(U_n[i]) #Test stages # Calculate L^1 error at times ew = numpy.zeros(n) for i, id in enumerate(ids): ew[i] = numpy.sum(numpy.abs(W_n[i] - W[i])) / numpy.sum( numpy.abs(W[i])) print print indent + 'L^1 Errors in stage: ', ew #Test xmomenta # Calculate L^1 error at times euh = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: euh[i] = numpy.sum(numpy.abs(UH_n[i] - U[i] * H[i])) / len( U[i]) else: euh[i] = numpy.sum( numpy.abs(UH_n[i] - U[i] * H[i])) / numpy.sum( numpy.abs(UH_n[i])) print indent + 'L^1 Errors in xmomentum: ', euh #Test xvelocity # Calculate L^1 error at times eu = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: eu[i] = numpy.sum(numpy.abs(U_n[i] - U[i])) / len(U[i]) else: eu[i] = numpy.sum(numpy.abs(U_n[i] - U[i])) / numpy.sum( numpy.abs(U[i])) print indent + 'L^1 Errors in xvelocity: ', eu for i, id in enumerate(ids): assert ew[i] < 0.01, 'L^1 error %g greater than 1 percent' % ew[i] for i, id in enumerate(ids): assert euh[ i] < 0.025, 'L^1 error %g greater than 2.5 percent' % euh[i] for i, id in enumerate(ids): assert eu[i] < 0.1, 'L^1 error %g greater than 10 percent' % eu[i]
def test_carrier_greenspan_periodic(self): if verbose: print print indent+'Running simulation script' s = 'numerical_carrier_greenspan.py' res = anuga.run_anuga_script(s,args=args) # Test that script runs ok assert res == 0 if verbose: print indent+'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_carrier_greenspan import analytic_cg p_st = util.get_output('carrier_greenspan.sww') p2_st=util.get_centroids(p_st) v = p2_st.y[10] v2=(p2_st.y==v) x_n = p2_st.x[v2] #ids = [288, 296, 304, 312, 320, 328] ids = [296, 304, 320, 328] # For the velocity and xmomentum calculations use # absolute error (as the exact solution is 0) use_absolute = [False, False, False, False] n = len(ids) W, P, Z, H, U = [], [], [], [], [] W_n, U_n, UH_n = [], [], [] for i, id in enumerate(ids): w0, p0, z0, h0, u0 = analytic_cg(x_n, p2_st.time[id], h0=5e2, L=5e4, a=1.0, Tp=900.0) W.append(w0) H.append(h0) U.append(u0) W_n.append(p2_st.stage[id,v2]) UH_n.append(p2_st.xmom[id,v2]) U_n.append(p2_st.xvel[id,v2]) #print id, numpy.max(H[i]), numpy.min(H[i]) #print id, numpy.max(U[i]), numpy.min(U[i]) #print id, numpy.max(U_n[i]), numpy.min(U_n[i]) #Test stages # Calculate L^1 error at times ew = numpy.zeros(n) for i, id in enumerate(ids): ew[i] = numpy.sum(numpy.abs(W_n[i]-W[i]))/numpy.sum(numpy.abs(W[i])) print print indent+'L^1 Errors in stage: ', ew #Test xmomenta # Calculate L^1 error at times euh = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: euh[i] = numpy.sum(numpy.abs(UH_n[i]-U[i]*H[i]))/len(U[i]) else: euh[i] = numpy.sum(numpy.abs(UH_n[i]-U[i]*H[i]))/numpy.sum(numpy.abs(UH_n[i])) print indent+'L^1 Errors in xmomentum: ',euh #Test xvelocity # Calculate L^1 error at times eu = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/len(U[i]) else: eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/numpy.sum(numpy.abs(U[i])) print indent+'L^1 Errors in xvelocity: ', eu for i, id in enumerate(ids): assert ew[i] < 0.01, 'L^1 error %g greater than 1 percent'% ew[i] for i, id in enumerate(ids): assert euh[i] < 0.025, 'L^1 error %g greater than 2.5 percent'% euh[i] for i, id in enumerate(ids): assert eu[i] < 0.1, 'L^1 error %g greater than 10 percent'% eu[i]
def test_dam_break_dry(self): if verbose: print print indent+'Running simulation script' s = 'numerical_dam_break_dry.py' res = anuga.run_anuga_script(s,args=args) # Test that script runs ok assert res == 0 if verbose: print indent+'Testing accuracy' import anuga.utilities.plot_utils as util import analytical_dam_break_dry as analytic p_st = util.get_output('dam_break.sww') p2_st=util.get_centroids(p_st) v = p2_st.y[10] v2=(p2_st.y==v) h0 = 1.0 h1 = 10.0 # calculate analytic values at various time slices h10,u10 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[10], h0=h0, h1=h1) h50,u50 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[50], h0=h0, h1=h1) h100,u100 = analytic.vec_dam_break(p2_st.x[v2], p2_st.time[100], h0=h0, h1=h1) #Test stages # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eh10 = numpy.sum(numpy.abs(p2_st.stage[10,v2]-h10))/numpy.sum(numpy.abs(h10)) eh50 = numpy.sum(numpy.abs(p2_st.stage[50,v2]-h50))/numpy.sum(numpy.abs(h50)) eh100 = numpy.sum(numpy.abs(p2_st.stage[100,v2]-h100))/numpy.sum(numpy.abs(h100)) print print indent+'Errors in stage: ',eh10, eh50, eh100 #Test xmomenta # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 euh10 = numpy.sum(numpy.abs(p2_st.xmom[10,v2]-u10*h10))/numpy.sum(numpy.abs(u10*h10)) euh50 = numpy.sum(numpy.abs(p2_st.xmom[50,v2]-u50*h50))/numpy.sum(numpy.abs(u50*h50)) euh100 = numpy.sum(numpy.abs(p2_st.xmom[100,v2]-u100*h100))/numpy.sum(numpy.abs(u100*h100)) print indent+'Errors in xmomentum: ',euh10, euh50, euh100 #Test xvelocity # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eu10 = numpy.sum(numpy.abs(p2_st.xvel[10,v2]-u10))/numpy.sum(numpy.abs(u10)) eu50 = numpy.sum(numpy.abs(p2_st.xvel[50,v2]-u50))/numpy.sum(numpy.abs(u50)) eu100 = numpy.sum(numpy.abs(p2_st.xvel[100,v2]-u100))/numpy.sum(numpy.abs(u100)) print indent+'Errors in xvelocity: ', eu10, eu50, eu100 assert eh10 < 0.1, 'Relative L^1 error %g greater than 0.1'% eh10 assert eh50 < 0.1, 'Relative L^1 error %g greater than 0.1'% eh50 assert eh100 < 0.15, 'Relative L^1 error %g greater than 0.15'% eh100 assert euh10 < 0.25, 'Relative L^1 error %g greater than 0.25'% euh10 assert euh50 < 0.25, 'Relative L^1 error %g greater than 0.25'% euh50 assert euh100 < 0.25, 'Relative L^1 error %g greater than 0.25'% euh100 assert eu10 < 2.0, 'Relative L^1 error %g greater than 2.0'% eu10 assert eu50 < 2.0, 'Relative L^1 error %g greater than 2.0'% eu50 assert eu100 < 0.3, 'Relative L^1 error %g greater than 0.3'% eu100
def test_avalanche_dry(self): if verbose: print print indent + "Running simulation script" # Run basic script (can be parallel if -np used in call # to this script s = "numerical_avalanche_dry.py" res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + "Testing accuracy" import anuga.utilities.plot_utils as util from analytical_avalanche_dry import analytical_sol p_st = util.get_output("avalanche.sww") p2_st = util.get_centroids(p_st) v = p2_st.y[10] v2 = p2_st.y == v x_n = p2_st.x[v2] u0, h0, w0, z0, p0 = analytical_sol(x_n, p2_st.time[0]) u10, h10, w10, z10, p10 = analytical_sol(x_n, p2_st.time[10]) u30, h30, w30, z30, p30 = analytical_sol(x_n, p2_st.time[30]) w0_n = p2_st.stage[0, v2] w10_n = p2_st.stage[10, v2] w30_n = p2_st.stage[30, v2] z_n = p2_st.elev[v2] uh0_n = p2_st.xmom[0, v2] uh10_n = p2_st.xmom[10, v2] uh30_n = p2_st.xmom[30, v2] u0_n = p2_st.xvel[0, v2] u10_n = p2_st.xvel[10, v2] u30_n = p2_st.xvel[30, v2] # Test stages # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eh10 = numpy.sum(numpy.abs(w10_n - w10)) / numpy.sum(numpy.abs(w10)) eh30 = numpy.sum(numpy.abs(w30_n - w30)) / numpy.sum(numpy.abs(w30)) print print indent + "Errors in stage: ", eh10, eh30 # Test xmomenta # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 euh10 = numpy.sum(numpy.abs(uh10_n - u10 * h10)) / numpy.sum(numpy.abs(u10 * h10)) euh30 = numpy.sum(numpy.abs(uh30_n - u30 * h30)) / numpy.sum(numpy.abs(u30 * h30)) print indent + "Errors in xmomentum: ", euh10, euh30 # Test xvelocity # Calculate L^1 error at times corrsponding to slices 10, 50 and 100 eu10 = numpy.sum(numpy.abs(u10_n - u10)) / numpy.sum(numpy.abs(u10)) eu30 = numpy.sum(numpy.abs(u30_n - u30)) / numpy.sum(numpy.abs(u30)) print indent + "Errors in xvelocity: ", eu10, eu30 assert eh10 < 0.01, "L^1 error %g greater than 1 percent" % eh10 assert eh30 < 0.01, "L^1 error %g greater than 1 percent" % eh30 assert euh10 < 0.025, "L^1 error %g greater than 2.5 percent" % euh10 assert euh30 < 0.025, "L^1 error %g greater than 2.5 percent" % euh30 assert eu10 < 0.2, "L^1 error %g greater than 20 percent" % eu10 assert eu30 < 0.2, "L^1 error %g greater than 20 percent" % eu30
def test_carrier_greenspan_transient(self): if verbose: print print indent+'Running simulation script' s = 'numerical_cg_transient.py' res = anuga.run_anuga_script(s,args=args) # Test that script runs ok assert res == 0 if verbose: print indent+'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_cg_transient import analytical_sol p_st = util.get_output('carrier_greenspan.sww') p2_st=util.get_centroids(p_st) v = p2_st.y[10] v2=(p2_st.y==v) x_n = p2_st.x[v2] ids = [1, 15, 30] use_absolute = [False, True, True] n = len(ids) W, UH, Z, H, U = [], [], [], [], [] W_n, U_n, UH_n = [], [], [] #Dimensional parameters L = 5e4 # Length of channel (m) h0 = 5e2 # Height at origin when the water is still g = 9.81 # Gravity for i, id in enumerate(ids): w, z, u = analytical_sol(x_n/L, p2_st.time[id]*sqrt(g*h0)/L) w = w*h0 z = z*h0 u = u*sqrt(g*h0) h = w-z uh = u*h W.append(w) Z.append(z) H.append(h) U.append(u) UH.append(uh) W_n.append(p2_st.stage[id,v2]) UH_n.append(p2_st.xmom[id,v2]) U_n.append(p2_st.xvel[id,v2]) #print id, numpy.max(H[i]), numpy.min(H[i]) #print id, numpy.max(U[i]), numpy.min(U[i]) #print id, numpy.max(U_n[i]), numpy.min(U_n[i]) #Test stages # Calculate L^1 error at times ew = numpy.zeros(n) for i, id in enumerate(ids): ew[i] = numpy.sum(numpy.abs(W_n[i]-W[i]))/numpy.sum(numpy.abs(W[i])) print print indent+'L^1 Errors in stage: ', ew #Test xmomenta # Calculate L^1 error at times euh = numpy.zeros(n) for i, id in enumerate(ids): euh[i] = numpy.sum(numpy.abs(UH_n[i]-U[i]*H[i]))/numpy.sum(numpy.abs(UH_n[i])) print indent+'L^1 Errors in xmomentum: ',euh #Test xvelocity # Calculate L^1 error at times eu = numpy.zeros(n) for i, id in enumerate(ids): if use_absolute[i]: eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/len(U[i]) else: eu[i] = numpy.sum(numpy.abs(U_n[i]-U[i]))/numpy.sum(numpy.abs(U[i])) print indent+'L^1 Errors in xvelocity: ', eu for i, id in enumerate(ids): assert ew[i] < 0.01, 'L^1 error %g greater than 1 percent'% ew[i] for i, id in enumerate(ids): assert euh[i] < 0.025, 'L^1 error %g greater than 2.5 percent'% euh[i] for i, id in enumerate(ids): assert eu[i] < 0.025, 'L^1 error %g greater than 2.5 percent'% eu[i]
def test_avalanche_wet(self): if verbose: print print indent + 'Running simulation script' s = 'numerical_avalanche_wet.py' res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + 'Testing accuracy' import anuga.utilities.plot_utils as util from analytical_avalanche_wet import analytical_sol p_st = util.get_output('avalanche.sww') p2_st = util.get_centroids(p_st) v = p2_st.y[20] v2 = (p2_st.y == v) x_n = p2_st.x[v2] u0, h0, w0, z0, p0 = analytical_sol(x_n, p2_st.time[0]) u20, h20, w20, z20, p20 = analytical_sol(x_n, p2_st.time[20]) u40, h40, w40, z40, p40 = analytical_sol(x_n, p2_st.time[40]) w0_n = p2_st.stage[0, v2] w20_n = p2_st.stage[20, v2] w40_n = p2_st.stage[40, v2] z_n = p2_st.elev[v2] uh0_n = p2_st.xmom[0, v2] uh20_n = p2_st.xmom[20, v2] uh40_n = p2_st.xmom[40, v2] u0_n = p2_st.xvel[0, v2] u20_n = p2_st.xvel[20, v2] u40_n = p2_st.xvel[40, v2] #Test stages # Calculate L^1 error at times corrsponding to slices 20, 40 eh20 = numpy.sum(numpy.abs(w20_n - w20)) / numpy.sum(numpy.abs(w20)) eh40 = numpy.sum(numpy.abs(w40_n - w40)) / numpy.sum(numpy.abs(w40)) print print indent + 'Errors in stage: ', eh20, eh40 #Test xmomenta # Calculate L^1 error at times corrsponding to slices 20, 40 euh20 = numpy.sum(numpy.abs(uh20_n - u20 * h20)) / numpy.sum( numpy.abs(u20 * h20)) euh40 = numpy.sum(numpy.abs(uh40_n - u40 * h40)) / numpy.sum( numpy.abs(u40 * h40)) print indent + 'Errors in xmomentum: ', euh20, euh40 #Test xvelocity # Calculate L^1 error at times corrsponding to slices 20, 40 eu20 = numpy.sum(numpy.abs(u20_n - u20)) / numpy.sum(numpy.abs(u20)) eu40 = numpy.sum(numpy.abs(u40_n - u40)) / numpy.sum(numpy.abs(u40)) print indent + 'Errors in xvelocity: ', eu20, eu40 assert eh20 < 0.01, 'L^1 error %g greater than 1 percent' % eh20 assert eh40 < 0.01, 'L^1 error %g greater than 1 percent' % eh40 assert euh20 < 0.025, 'L^1 error %g greater than 2.5 percent' % euh20 assert euh40 < 0.025, 'L^1 error %g greater than 2.5 percent' % euh40 assert eu20 < 0.02, 'L^1 error %g greater than 2 percent' % eu20 assert eu40 < 0.01, 'L^1 error %g greater than 2 percent' % eu40
def test_avalanche_wet(self): if verbose: print print indent + "Running simulation script" s = "numerical_avalanche_wet.py" res = anuga.run_anuga_script(s, args=args) # Test that script runs ok assert res == 0 if verbose: print indent + "Testing accuracy" import anuga.utilities.plot_utils as util from analytical_avalanche_wet import analytical_sol p_st = util.get_output("avalanche.sww") p2_st = util.get_centroids(p_st) v = p2_st.y[20] v2 = p2_st.y == v x_n = p2_st.x[v2] u0, h0, w0, z0, p0 = analytical_sol(x_n, p2_st.time[0]) u20, h20, w20, z20, p20 = analytical_sol(x_n, p2_st.time[20]) u40, h40, w40, z40, p40 = analytical_sol(x_n, p2_st.time[40]) w0_n = p2_st.stage[0, v2] w20_n = p2_st.stage[20, v2] w40_n = p2_st.stage[40, v2] z_n = p2_st.elev[v2] uh0_n = p2_st.xmom[0, v2] uh20_n = p2_st.xmom[20, v2] uh40_n = p2_st.xmom[40, v2] u0_n = p2_st.xvel[0, v2] u20_n = p2_st.xvel[20, v2] u40_n = p2_st.xvel[40, v2] # Test stages # Calculate L^1 error at times corrsponding to slices 20, 40 eh20 = numpy.sum(numpy.abs(w20_n - w20)) / numpy.sum(numpy.abs(w20)) eh40 = numpy.sum(numpy.abs(w40_n - w40)) / numpy.sum(numpy.abs(w40)) print print indent + "Errors in stage: ", eh20, eh40 # Test xmomenta # Calculate L^1 error at times corrsponding to slices 20, 40 euh20 = numpy.sum(numpy.abs(uh20_n - u20 * h20)) / numpy.sum(numpy.abs(u20 * h20)) euh40 = numpy.sum(numpy.abs(uh40_n - u40 * h40)) / numpy.sum(numpy.abs(u40 * h40)) print indent + "Errors in xmomentum: ", euh20, euh40 # Test xvelocity # Calculate L^1 error at times corrsponding to slices 20, 40 eu20 = numpy.sum(numpy.abs(u20_n - u20)) / numpy.sum(numpy.abs(u20)) eu40 = numpy.sum(numpy.abs(u40_n - u40)) / numpy.sum(numpy.abs(u40)) print indent + "Errors in xvelocity: ", eu20, eu40 assert eh20 < 0.01, "L^1 error %g greater than 1 percent" % eh20 assert eh40 < 0.01, "L^1 error %g greater than 1 percent" % eh40 assert euh20 < 0.025, "L^1 error %g greater than 2.5 percent" % euh20 assert euh40 < 0.025, "L^1 error %g greater than 2.5 percent" % euh40 assert eu20 < 0.02, "L^1 error %g greater than 2 percent" % eu20 assert eu40 < 0.01, "L^1 error %g greater than 2 percent" % eu40