- Timestamp:
- Oct 27, 2011, 8:23:34 PM (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/anuga_work/development/2010-projects/anuga_1d/channel/var_width_depth.py
r7884 r8241 1 1 import os 2 2 import random 3 from math import sqrt, pow, pi 4 from channel_domain _Abimport *5 from Numeric import allclose, array, zeros, ones, Float, take, sqrt6 from config import g, epsilon3 from math import sqrt, pow, pi 4 from channel_domain import * 5 from numpy import allclose, array, zeros, ones, take, sqrt 6 from anuga_1d.config import g, epsilon 7 7 8 9 random.seed(111) 8 10 9 11 print "Variable Width Only Test" … … 11 13 # Define functions for initial quantities 12 14 def initial_area(x): 13 y = zeros(len(x), Float)15 y = zeros(len(x),'f') 14 16 for i in range(len(x)): 15 17 y[i]=(10-randomarray[i]) … … 20 22 def width(x): 21 23 22 y = zeros(len(x), Float)24 y = zeros(len(x),'f') 23 25 for i in range(len(x)): 24 26 y[i]=randomarray[i] … … 28 30 def bed(x): 29 31 30 y = zeros(len(x), Float)32 y = zeros(len(x),'f') 31 33 for i in range(len(x)): 32 34 y[i]=randomarray2[i] … … 38 40 def stage(x): 39 41 40 y = zeros(len(x), Float)42 y = zeros(len(x),'f') 41 43 for i in range(len(x)): 42 44 if x[i]<200 and x[i]>150: … … 64 66 print "Evaluating domain with %d cells" %N 65 67 cell_len = L/N # Origin = 0.0 66 points = zeros(N+1, Float)68 points = zeros(N+1,'f') 67 69 68 70 # Define the centroid points … … 74 76 75 77 # Define random array for width 76 randomarray=zeros(len(points), Float)78 randomarray=zeros(len(points),'f') 77 79 for j in range(N+1): 78 80 randomarray[j]=random.normalvariate(3,1) 79 randomarray2=zeros(len(points), Float)81 randomarray2=zeros(len(points),'f') 80 82 for j in range(N+1): 81 83 randomarray2[j]=random.normalvariate(3,1) … … 98 100 t0 = time.time() 99 101 100 print domain.quantities['elevation'].vertex_values 102 103 AreaC = domain.quantities['area'].centroid_values 104 BedC = domain.quantities['elevation'].centroid_values 105 WidthC = domain.quantities['width'].centroid_values 106 # 107 AreaC[:] = (10.0 - BedC)* WidthC 108 109 110 #print domain.quantities['elevation'].vertex_values 111 112 finaltime = 100.0 113 yieldstep = 1.0 114 115 domain.initialize_plotting(stage_lim = [-1.0, 20.0], 116 width_lim = [0.0, 6.0], 117 velocity_lim = [-1.0, 1.0]) 118 101 119 102 120 for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime): 103 121 domain.write_time() 104 122 105 print domain.quantities['elevation'].vertex_values 123 domain.update_plotting() 106 124 107 N = float(N) 108 HeightC = domain.quantities['height'].centroid_values 109 DischargeC = domain.quantities['discharge'].centroid_values 110 C = domain.centroids 111 print 'That took %.2f seconds' %(time.time()-t0) 112 X = domain.vertices 113 HeightQ = domain.quantities['height'].vertex_values 114 VelocityQ = domain.quantities['velocity'].vertex_values 115 x = X.flat 116 z = domain.quantities['elevation'].vertex_values.flat 117 b = domain.quantities['width'].vertex_values.flat 118 stage=HeightQ.flat+z 125 #print domain.quantities['elevation'].vertex_values 119 126 127 domain.hold_plotting() 120 128 121 122 from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot123 124 #hold(False)125 126 plot1=subplot(211)127 128 plot(x,stage,x,z,x,b)129 130 plot1.set_ylim([-5,15])131 xlabel('Position')132 ylabel('Stage')133 legend(('Solution', 'Bed','Width'),134 'upper right', shadow=True)135 136 plot2=subplot(212)137 plot(x,VelocityQ.flat)138 plot2.set_ylim([-10,10])139 xlabel('Position')140 ylabel('Velocity')141 142 show()143
Note: See TracChangeset
for help on using the changeset viewer.