import os import time from math import sqrt, sin, cos, pi, exp from shallow_water_domain_suggestion2 import * from Numeric import zeros, Float from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot print "TEST 1D-SOLUTION I" L=2000.0 N=4 cell_len=L/N points=zeros(N+1, Float) for i in range(N+1): points[i]=i*cell_len domain=Domain(points) domain.order = 1 domain.set_timestepping_method('euler') domain.cfl = 1.0 domain.limiter = "minmod" def stage_flat(x): y=zeros(len(x), Float) for i in range(len(x)): y[i]=4.0 return y def elevation_arbitrary(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 200.0: y[i] = -0.01*(x[i]-200) + 4.0 elif 200.0 <= x[i] < 300.0: y[i] = -0.02*(x[i]-200) + 4.0 elif 300.0 <= x[i] < 400.0: y[i] = -0.01*(x[i]-300) + 2.0 elif 400.0 <= x[i] < 550.0: y[i] = (-1/75.0)*(x[i]-400.0) + 2.0 elif 550.0 <= x[i] < 700.0: y[i] = (1/11250)*(x[i]-550)*(x[i]-550) elif 700.0 <= x[i] < 800.0: y[i] = 0.03*(x[i]-700) elif 800.0 <= x[i] < 900.0: y[i] = -0.03*(x[i]-800) + 3.0 elif 900.0 <= x[i] < 1000.0: y[i] = 6.0 elif 1000.0 <= x[i] < 1400.0: y[i] = (-1.0/20000)*(x[i]-1000)*(x[i]-1400) elif 1400.0 <= x[i] < 1500.0: y[i] = 0.0 elif 1500.0 <= x[i] < 1700.0: y[i] = 3.0 elif 1700.0 <= x[i] < 1800.0: y[i] = -0.03*(x[i]-1700) + 3.0 else: y[i] = (3.0/40000)*(x[i]-1800)*(x[i]-1800) + 2.0 return y def elevation_arbitrary1(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 200.0: y[i] = -0.01*(x[i]-200) + 5.0 elif 200.0 <= x[i] < 900.0: y[i] = 0.0 elif 900.0 <= x[i] < 1000.0: # This is the island y[i] = 5.0 elif 1000.0 <= x[i] < 1800.0: y[i] = 0.0 else: y[i] = 0.03*(x[i]-1700) + 3.0 return y def elevation_arbitrary2(x): y=zeros(len(x), Float) for i in range(len(x)): if 0 <= x[i] < 1000.0: # This is the island y[i] = 5.0 else: y[i] = 0.0 return y domain.set_quantity('stage',stage_flat) domain.set_quantity('elevation',elevation_arbitrary2) domain.set_boundary({'exterior':Reflective_boundary(domain)}) X=domain.vertices.flat C=domain.centroids.flat yieldstep = 1.0 finaltime = 10.0 #--------------------------------------------------------- # Start of step #--------------------------------------------------------- domain._order_ = domain.default_order domain.finaltime = float(finaltime) domain.yieldtime = 0.0 # Track time between 'yields' # Initialise interval of timestep sizes (for reporting only) domain.min_timestep = 1.0e-10 domain.max_timestep = 1.0 domain.number_of_steps = 0 domain.number_of_first_order_steps = 0 # Update ghosts domain.update_ghosts() # Initial update of vertex and edge values domain.distribute_to_vertices_and_edges() # Update extrema if necessary (for reporting) #domain.update_extrema() # Initial update boundary values domain.update_boundary() # Compute fluxes across each element edge domain.compute_fluxes() # Update timestep to fit yieldstep and finaltime domain.update_timestep(yieldstep, finaltime) print 'timestep = ',domain.timestep # Update conserved quantities domain.update_conserved_quantities() # Update ghosts domain.update_ghosts() # Update vertex and edge values domain.distribute_to_vertices_and_edges() # Update boundary values domain.update_boundary() #------------------------------------------------------------ # End od one step #------------------------------------------------------------ domain.write_time() print "integral", domain.quantities['height'].get_integral() StageQ=domain.quantities['stage'].vertex_values.flat StageUp=domain.quantities['stage'].explicit_update MomentumQ=domain.quantities['xmomentum'].vertex_values.flat MomentumUp=domain.quantities['xmomentum'].explicit_update ElevationQ=domain.quantities['elevation'].vertex_values.flat VelocityQ=domain.quantities['velocity'].vertex_values.flat print "momentum", MomentumQ print "StageUpdates", StageUp #StageUp=domain.quantities['stage'].explicit_update print "MomUpdates", MomentumUp hold(False) plot1 = subplot(311) #plot(X,StageQ) plot(X,StageQ, X,ElevationQ) plot1.set_ylim([-1.0,8.0]) xlabel('Position') ylabel('Stage') legend( ('Numerical Solution', 'Bed Elevation'), 'upper right', shadow=False) plot2 = subplot(312) plot(X,MomentumQ) #plot2.set_ylim([3.998,4.002]) legend( ('Numerical Solution', 'for momentum'), 'upper right', shadow=False) xlabel('Position') ylabel('Xmomentum') plot3 = subplot(313) plot(X,VelocityQ) #plot3.set_ylim([-5.0,30.0]) legend( ('Numerical Solution', 'for velocity'), 'upper right', shadow=False) xlabel('Position') ylabel('Velocity') #file = "island_" #file += str(finaltime) #file += ".png" #savefig(file) show() #print 'That took %.2f seconds'%(time.time()-t0) #raw_input("Press return key")