Changeset 4703
- Timestamp:
- Sep 5, 2007, 2:23:41 PM (18 years ago)
- Location:
- anuga_validation/convergence_study
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
anuga_validation/convergence_study/animatesww2d_alt.py
r4700 r4703 17 17 ymomentum = fid.variables['ymomentum'] 18 18 19 20 # find indices for where y = 021 22 #23 # Set up plot24 25 spacing=10 # grid interval in metres26 hmax=5 # ??27 28 29 #figure(1);30 31 #if nargin > 132 # figure(1);set(gcf,'Position',[200 400 800 300]);33 # mov=avifile(movie_filename,'FPS',5)34 #end35 36 #i=find(V_y==0);37 38 #[xi,yi]=meshgrid(min(V_x):spacing:max(V_x),min(V_y):spacing:max(V_y));39 40 #elev=griddata(V_x,V_y,V_elevation,xi,yi);41 42 #if nargin < 343 # range=[min(V_x) max(V_x) min(min(V_stage))-1 max(max(V_stage))+1];44 #end45 46 #m=V_stage(1,i);47 48 #for t=1:length(V_time)49 50 # m=max(m,V_stage(t,i));51 # plot(V_x(i),V_stage(t,i),V_x(i),V_elevation(i),V_x(i),m,'.');52 53 # axis(range)54 55 56 # title(num2str(V_time(t)));drawnow;57 58 # if nargin>159 # F=getframe(gcf);60 # mov=addframe(mov,F);61 # end62 63 #end64 65 #if nargin > 166 # mov=close(mov);67 #end68 69 '''70 if __name__ == '__main__':71 72 import sys73 animatesww2d_alt(sys.argv[1], 'cross_section_plot', 5)74 75 '''76 77 '''78 How do I make a movie with matplotlib?79 If you want to take an animated plot and turn it into a movie, the best approach is to save a series of image files (eg PNG) and use an external tool to convert them to a movie. There is a matplotlib tutorial on this subject here. You can use mencoder, which is part of the mplayer suite for this80 #fps (frames per second) controls the play speed81 mencoder 'mf://*.png' -mf type=png:fps=10 -ovc \82 lavc -lavcopts vcodec=wmv2 -oac copy -o animation.avi83 84 The swiss army knife of image tools, ImageMagick's convert, works for this as well.85 Here is a simple example script that saves some PNGs, makes them into a movie, and then cleans up.86 87 import os, sys88 from pylab import *89 90 files = []91 figure(figsize=(5,5))92 ax = subplot(111)93 for i in range(50): # 50 frames94 cla()95 imshow(rand(5,5), interpolation='nearest')96 fname = '_tmp%03d.png'%i97 print 'Saving frame', fname98 savefig(fname)99 files.append(fname)100 101 print 'Making movie animation.mpg - this make take a while'102 os.system("mencoder 'mf://_tmp*.png' -mf type=png:fps=10 \103 -ovc lavc -lavcopts vcodec=wmv2 -oac copy -o animation.mpg")104 105 # cleanup106 for fname in files: os.remove(fname)107 108 '''109 110 19 def animatesww2d(swwfile): 111 20 """Read in sww file and plot cross section of model output … … 124 33 125 34 # interpolation points are for y = 0 126 m = 100 # number of increments in x 35 # number of increments in x 36 m = 100 127 37 max_x = 100000. 128 38 x = 0 … … 131 41 for i in range(m): 132 42 x += max_x/m 133 points.append([x,0 ])43 points.append([x,0.]) 134 44 x_points.append(x) 135 45 … … 157 67 momenta = zeros((n,m), Float) 158 68 speed = zeros((n,m), Float) 159 max_stages = []69 max_stages = zeros((n,m), Float) 160 70 max_stage = None 71 min_stages = zeros((n,m), Float) 72 min_stage = 100. 161 73 162 74 for k, location in enumerate(x_points): … … 181 93 182 94 if w > max_stage: max_stage = w 183 max_stages.append(max_stage) 95 if w < min_stage: min_stage = w 96 max_stages[i,k] = max_stage 97 min_stages[i,k] = min_stage 184 98 185 from pylab import plot, xlabel, ylabel, savefig, close, hold 99 min_stage = min(min(min_stages)) 100 max_stage = max(max(max_stages)) 101 stage_axis = [0, max_x, min_stage-1, max_stage+1] 102 from pylab import plot, xlabel, ylabel, savefig, close, hold, axis, title 186 103 hold(False) 187 for i in range(n): 188 plot(x_points,stage[i,:]) 189 xlabel('x') 104 figs = [] 105 j = 1 106 #max_vec = zeros(100, Float) 107 108 for i in range(0,n,20): 109 #max_vec[i] = max(stage[i,:]) 110 plot(x_points,stage[i,:]) #x_points,max_vec,'+') 111 xlabel('x (m)') 190 112 ylabel('stage (m)') 191 #title('')113 axis(stage_axis) 192 114 name = 'time_%i' %i 193 115 savefig(name) 116 title(name) 117 figs.append(name) 194 118 195 119 close('all') 196 120 197 121 animatesww2d('myexample2.sww') 122 123 # once png files have been created, they can then be dragged into 124 # Windows Movie Maker and exported to a mpeg. -
anuga_validation/convergence_study/convergence.py
r4694 r4703 4 4 similar to a beach environment 5 5 """ 6 7 6 8 7 #------------------------------------------------------------------------------ … … 18 17 from anuga.shallow_water import Transmissive_boundary 19 18 from anuga.shallow_water import Transmissive_Momentum_Set_Stage_boundary 20 #from anuga.fit_interpolate.fit import fit_to_mesh_file21 19 from anuga.geospatial_data.geospatial_data import * 22 20 from math import cos … … 25 23 # Setup computational domain 26 24 #------------------------------------------------------------------------------ 27 28 dx = 1000. 25 dx = 10. 29 26 dy = dx 30 27 L = 100000. 31 28 W = 3000. 32 29 33 points, vertices, boundary = rectangular_cross(int(L/dx), int(L/dy), 34 L, W, (0.0, -W/2)) # Basic mesh 35 30 # structured mesh 31 #points, vertices, boundary = rectangular_cross(int(L/dx), int(W/dy), 32 # L, W, (0.0, -W/2)) # Basic mesh 36 33 #points, vertices, boundary = rectangular_cross(666, 3, 100000, 3000, (0.0, -0.0)) # Basic mesh 37 34 #points, vertices, boundary = rectangular_cross(530, 10, 5300, 100, (-5000.0, -50.0)) # Basic mesh 38 35 #points, vertices, boundary = rectangular_cross(1000, 100, 20, 3) # Basic mesh 36 #domain = Domain(points, vertices, boundary) 39 37 40 domain = Domain(points, vertices, boundary) # Create domain 41 domain.set_name('myexample2') # Output to bedslope.sww 38 # unstructured mesh 39 poly_domain = [[0,-W],[0,W],[L,W],[L,-W]] 40 meshname = 'test.msh' 41 from anuga.pmesh.mesh_interface import create_mesh_from_regions 42 # Create mesh 43 create_mesh_from_regions(poly_domain, 44 boundary_tags={'left': [0], 'top': [1], 45 'right': [2], 'bottom': [3]}, 46 maximum_triangle_area = 25000, 47 filename=meshname) 48 49 # Create domain 50 domain = Domain(meshname, use_cache=True, verbose = True) 51 domain.set_name('myexample2') 42 52 domain.set_datadir('.') # Use current directory for output 43 #domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities44 # 'xmomentum',45 # 'ymomentum'])46 47 53 48 54 #------------------------------------------------------------------------------ 49 55 # Setup initial conditions 50 56 #------------------------------------------------------------------------------ 51 52 53 57 #domain.set_quantity('elevation', topography) # Use function for elevation 54 58 domain.set_quantity('elevation',-100) 55 #domain.set_quantity('elevation',filename='tr10_mod.pts') 56 #domain.set_quantity('elevation',filename='tr5_mod.pts') 57 #domain.set_quantity('elevation',filename='tr4_mod.pts') 58 #domain.set_quantity('friction', 0.1) # Constant friction 59 domain.set_quantity('friction', 0.00) # Constant friction 60 #domain.set_quantity('friction', 0.035) # Constant friction 61 domain.set_quantity('stage', 0.0) # Constant negative initial stage 62 59 domain.set_quantity('friction', 0.00) 60 domain.set_quantity('stage', 0.0) 63 61 64 62 #----------------------------------------------------------------------------- 65 63 # Setup boundary conditions 66 64 #------------------------------------------------------------------------------ 67 68 65 from math import sin, pi, exp 69 66 Br = Reflective_boundary(domain) # Solid reflective wall 70 67 Bt = Transmissive_boundary(domain) # Continue all values on boundary 71 68 Bd = Dirichlet_boundary([1,0.,0.]) # Constant boundary values 72 amplitude =eval(sys.argv[1])69 amplitude = 1 73 70 Bw = Time_boundary(domain=domain, # Time dependent boundary 74 71 ## Sine wave … … 81 78 # f=lambda t: [(-8.0*sin((1./720.)*t*2*pi))*((t<720.)-0.5*(t<360.)), 0.0, 0.0]) 82 79 83 84 80 # Associate boundary tags with boundary objects 85 #domain.set_boundary({'left': Bw, 'right': Br, 'top': Br, 'bottom': Br})86 81 domain.set_boundary({'left': Bw, 'right': Bt, 'top': Br, 'bottom': Br}) 87 88 82 89 83 #------------------------------------------------------------------------------ … … 94 88 domain.write_time() 95 89 96
Note: See TracChangeset
for help on using the changeset viewer.