Changeset 2458
- Timestamp:
- Mar 1, 2006, 1:59:25 PM (19 years ago)
- Location:
- development/momentum_sink
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
development/momentum_sink/CCS.py
r2446 r2458 1 1 """Read in sww file, interpolate at specified locations and 2 Cross section at specified T 2 Cross section at specified T. Cross sections are spatial drawing 3 at the specified time. 4 5 '2nd normal' test is employed to find the best fit friction value 6 for the given building scenario => 'B_file' 3 7 4 8 """ … … 7 11 import project 8 12 from pyvolution.util import file_function 9 from create_buildings import porosity, WidtH 10 # from run_friction import fric 13 from create_buildings import WidtH 11 14 from pylab import * 12 15 from numerical_tools import norm, corr, err 13 16 17 B_list=['buildings_Str_D=3_1714.sww', 18 'buildings_Str_D=5_1578.sww', 19 'buildings_Str_D=7_1067.sww', 20 'buildings_Str_D=9_1052.sww', 21 'buildings_Str_D=11_694.sww', 22 'buildings_Str_D=13_693.sww', 23 'buildings_Str_D=15_717.sww', 24 'buildings_Str_D=17_749.sww', 25 'buildings_Str_D=19_1008.sww', 26 'buildings_Str_D=21_1581.sww', 27 'buildings_Str_D=23_1798.sww'] 14 28 15 29 16 17 gauge_depth = Numeric.arrayrange(46, 1.5*WidtH, 25) 18 print len(gauge_depth),"gauge_depth length" 19 gauge_breadth = 100 20 gauge_locations = [] 21 22 for GD in gauge_depth: 23 gauge_location = [GD,gauge_breadth] 24 gauge_locations.append(gauge_location) 30 fd = open("Straight_log_report.csv", 'w') 31 fd.write( 'Straight_log_report. Summary at bottom.' + '\n' ) 25 32 26 33 27 swwfile_B = project.outputdir + sep + 'Straight_offset_11.sww' 34 # Building scenario file to be compared to 35 #--------------------------------------------- 36 #B_list = ['buildings_S0_D=23_1784.sww'] 37 #--------------------------------------------- 28 38 29 #Read model output 30 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] 39 best_fric=[] 40 B_Density=[] 41 best_norm=[] 42 Breadth=[] 31 43 32 f_B = file_function(swwfile_B,33 quantities = quantities,34 interpolation_points = gauge_locations,35 verbose = True,36 use_cache = True)37 44 38 Corr_OK=[] 39 fric_OK=[] 40 least_norm=[1] 41 norm_OK=[] 42 Friction = Numeric.arrayrange(1,80,1) 43 for fric in Friction: 44 swwfile_F = project.outputdir + sep + 'friction_n=' + repr(fric) + '_3135.sww' 45 f_F = file_function(swwfile_F, 45 for B_file in B_list: 46 swwfile_B = project.outputdir + sep + B_file 47 a=B_file.split('_') 48 b=a[2].split('=') 49 bre=int(b[1]) 50 51 gauge_depth = Numeric.arrayrange((52.5-bre/2), 1.5*WidtH, 25) 52 gauge_breadth = 100 53 gauge_locations = [] 54 55 for GD in gauge_depth: 56 gauge_location = [GD,gauge_breadth] 57 gauge_locations.append(gauge_location) 58 59 60 #Read model output 61 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'] 62 63 f_B = file_function(swwfile_B, 46 64 quantities = quantities, 47 65 interpolation_points = gauge_locations, … … 49 67 use_cache = True) 50 68 51 t=1000 # specifies times to look at cross sections 69 fric_OK=[] 70 least_norm=[100] 71 Normal=[] 72 #Friction = Numeric.arrayrange(1,120,1) 73 Friction = [0.025, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000, 2000, 5000, 10000] 74 for fric in Friction: 75 swwfile_F = project.outputdir + sep + 'friction_n=' + str(fric) + '_3135.sww' 76 f_F = file_function(swwfile_F, 77 quantities = quantities, 78 interpolation_points = gauge_locations, 79 verbose = True, 80 use_cache = True) 81 82 t=990 # specifies times to look at cross sections 83 84 stages_B = [] 85 stages_F = [] 86 for i, GL in enumerate(gauge_depth): 87 88 # mines data from specified time values in sww file 89 # Building file 90 wB = f_B(t, point_id = i)[0] 91 zB = f_B(t, point_id = i)[1] 92 uhB = f_B(t, point_id = i)[2] 93 vhB = f_B(t, point_id = i)[3] 94 # Friction file 95 wF = f_F(t, point_id = i)[0] 96 uhF = f_B(t, point_id = i)[2] 97 vhF = f_B(t, point_id = i)[3] 98 99 #m = sqrt(uh*uh + vh*vh) #Absolute momentum 100 velB = sqrt(uhB*uhB + vhB*vhB) / (wB + 1.e-30) #Absolute velocity 101 velF = sqrt(uhF*uhF + vhF*vhF) / (wF + 1.e-30) #Absolute velocity 102 stages_B.append(wB) 103 stages_F.append(wF) 104 105 106 Ar_B = Numeric.array(stages_B) 107 Ar_F = Numeric.array(stages_F) 108 diff = abs(Ar_B - Ar_F) 109 norm_F = err(Ar_F, Ar_B, 2, relative = True) # 2nd norm (rel. RMS) test 110 Normal.append(norm_F) 111 #print " " 112 #print norm_F, "2nd norm test result (N_F)" 113 #print " " 114 if norm_F < least_norm: 115 least_norm = norm_F 116 fric_OK = fric 117 else: 118 print fric, " NOT OK" 52 119 53 stages_B = [] 54 stages_F = [] 55 for i, GL in enumerate(gauge_depth): 120 print fric_OK, " <- This Manning's n is best fit from 2nd norm test" 121 print least_norm, "2nd normal of Friction vs Buildings " 122 best_fric.append(fric_OK) 123 B_Density.append((float(bre)**2)/625) 124 best_norm.append(least_norm) 125 Breadth.append(bre) 126 127 print len(Friction), "friction" 128 print len(Normal), "normal" 129 fd.write('_______________________________________________________' + '\n' ) 130 fd.write( '<<<< Mannings n for [' + B_file + '] >>>>' + '\n' ) 131 fd.write( '(n), 2nd norm ' + '\n') 132 for j,drt in enumerate(Friction): 133 fd.write(str(Friction[j]) + ', ' + str(Normal[j]) + '\n') 134 135 print best_fric, " << Best fit friction" 136 print B_Density, " << Building footprint density" 137 print best_norm, " << Matching normal densities" 56 138 57 # mines data from specified time values in sww file58 # Building file59 wB = f_B(t, point_id = i)[0]60 zB = f_B(t, point_id = i)[1]61 uhB = f_B(t, point_id = i)[2]62 vhB = f_B(t, point_id = i)[3]63 # Friction file64 wF = f_F(t, point_id = i)[0]65 uhF = f_B(t, point_id = i)[2]66 vhF = f_B(t, point_id = i)[3]67 139 68 #m = sqrt(uh*uh + vh*vh) #Absolute momentum 69 velB = sqrt(uhB*uhB + vhB*vhB) / (wB + 1.e-30) #Absolute velocity 70 velF = sqrt(uhF*uhF + vhF*vhF) / (wF + 1.e-30) #Absolute velocity 71 stages_B.append(wB) 72 stages_F.append(wF) 73 74 75 Ar_B = Numeric.array(stages_B) 76 Ar_F = Numeric.array(stages_F) 77 diff = abs(Ar_B - Ar_F) 78 norm_F = err(Ar_B, Ar_F, 2, relative = True)# 2nd norm (RMS) test 79 80 print " " 81 print norm_F, "norm N_F" 82 print " " 83 norm_OK.append(norm_F) 140 len_file=Numeric.arrayrange(0,len(B_list),1) 141 fd.write('_______________________________________________________' + '\n' ) 142 fd.write( '<<<<< Straight_log_report Summary >>>>>' + '\n' ) 143 fd.write( 'width, footprint ratio, mannings n, 2nd norm ' + '\n') 144 for i in len_file: 145 fd.write( str(Breadth[i]) + ', ' + str(B_Density[i]) + ', ' + str(best_fric[i]) + ', ' + str(best_norm[i]) + '\n') 146 fd.close 84 147 85 if norm_F < least_norm:86 least_norm = norm_F87 fric_OK = fric88 else:89 print fric, " NOT OK"90 91 92 93 print " "94 print "_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_"95 print fric_OK, " <- This Manning's n is best fit from 2nd norm test"96 print "_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_"97 print least_norm, "2nd normal of Friction vs Buildings "98 print "_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_"99 -
development/momentum_sink/PCS.py
r2446 r2458 7 7 import project 8 8 from pyvolution.util import file_function 9 from create_buildings import porosity,WidtH9 from create_buildings import WidtH 10 10 # from run_friction import fric 11 11 from pylab import * … … 16 16 17 17 #swwfile_B = project.outputdir + sep + 'Buildings_3790.sww' 18 swwfile_B = project.outputdir + sep + ' Straight_offset.sww'18 swwfile_B = project.outputdir + sep + 'buildings_S0_D=19_1037.sww' 19 19 #swwfile_B = project.outputdir + sep + 'friction_n=10_3135.sww' 20 swwfile_F = project.outputdir + sep + 'friction_n= 51_3135.sww'20 swwfile_F = project.outputdir + sep + 'friction_n=37_3135.sww' 21 21 22 gauge_depth = Numeric.arrayrange( 46, 1.5*WidtH, 25) # Random special22 gauge_depth = Numeric.arrayrange(51, 1.5*WidtH, 25) # Random special 23 23 #gauge_depth = Numeric.arrayrange(0, 1.5*WidtH, 25) 24 24 gauge_breadth = 100 … … 90 90 91 91 plot(gauge_depth, stages_B, '-b',gauge_depth,stages_F,'-r') 92 title('Time_%d_ vs water depth (n=%f, BP=%f)' %(t, fric, porosity))92 title('Time_%d_ vs water depth ' %t) 93 93 xlabel('gauge length(m)') 94 94 ylabel('water depths (m)') -
development/momentum_sink/create_buildings.py
r2446 r2458 7 7 from coordinate_transforms.geo_reference import Geo_reference 8 8 9 depth = 11 # depth of building side to oncoming wave10 breadth = 11 # breadth of building, width of building to oncoming wave11 #from loop_buildings import depth12 13 9 WidtH = 200 # width of boudary in metres 14 #breadth = depth15 16 print "building footprint"17 print depth * breadth , "m^2"18 block = 62519 BL = block**0.520 21 porosity = breadth/BL22 print porosity, " Building porosity"23 10 24 11 #random.uniform(0,1) #proper implemantation of random generator 25 12 26 def create_mesh(maximum_triangle_area, 13 def create_mesh(maximum_triangle_area, depth, 27 14 mesh_file=None, 28 15 triangles_in_name = False): … … 32 19 """ 33 20 34 21 WidtH = 200 # width of boudary in metres 22 breadth = depth 23 24 print "building footprint" 25 print depth * breadth , "m^2" 26 block = 625 27 BL = block**0.5 28 29 porosity = breadth/BL 30 print porosity, " Building porosity" 35 31 # create a mesh instance of class Mesh 36 32 m = Mesh() … … 44 40 whs = depth/2 45 41 lhs = breadth/2 46 #Th = (45 *(3.142/180)) # sets an initial rotation47 Th = 042 Th = (45 *(3.142/180)) # sets an initial rotation 43 #Th = 0 48 44 ForDep = (0.2*WidtH) + (BL-whs) 49 45 RearDep = 1.2*WidtH 50 46 51 47 Breadths = Numeric.arrayrange( -(BL/2), WidtH+(BL/2), (BL)) 48 #Breadths = Numeric.arrayrange( (BL/2), WidtH-(BL/2), (BL)) # For ortho-offset 52 49 print Breadths, "Breadths" 53 50 Depths = Numeric.arrayrange( ForDep, RearDep, BL ) … … 55 52 56 53 for i,D in enumerate(Depths): 57 Breadths = Breadths + ((-1)**i)*(BL/2) #Used to offset buildings54 #Breadths = Breadths + ((-1)**i)*(BL/2) #Used to offset buildings 58 55 for B in Breadths: 59 56 wh1 = (-whs) * math.cos(Th) + (-lhs) * math.sin(Th) … … 76 73 else: 77 74 if triangles_in_name is True: 78 mesh_file = mesh_file[:-4] + '_ Ran_' + str(depth) + '_' + str(triangle_count) \75 mesh_file = mesh_file[:-4] + '_Orth(45)_D=' + str(depth) + '_' + str(triangle_count) \ 79 76 + mesh_file[-4:] 80 77 m.export_mesh_file(mesh_file) … … 83 80 #------------------------------------------------------------- 84 81 if __name__ == "__main__": 85 _, triangle_count = create_mesh(10 ,mesh_file="test.tsh")82 _, triangle_count = create_mesh(100,15,mesh_file="test.tsh") 86 83 print "triangle_count",triangle_count -
development/momentum_sink/friction_block.py
r2395 r2458 6 6 from coordinate_transforms.geo_reference import Geo_reference 7 7 8 #test = 300 8 9 9 def create_mesh(maximum_triangle_area, 10 10 mesh_file=None, … … 17 17 m = Mesh() 18 18 19 #print "test", test20 19 # Boundary of problem 21 20 WidtH = 200 # width of boudary in metres 22 #W = WidtH/823 #L = W24 #outer_polygon = [[0,0],[2*WidtH,0],[2*WidtH,WidtH],[0,WidtH]]25 #m.add_region_from_polygon(outer_polygon, tags={'wall':[0,1,2], 'wave':[3]})26 27 #domain.set_region(Set_region('mound', 'elevation', 100, location='unique vertices'))28 21 29 22 #Boundary … … 38 31 'wall', 39 32 'wall', 40 'back', 33 'back', # defines direchet boundary for back of test area 41 34 'wall', 42 35 'wall', 43 'wave', 36 'wave', # defines the wave boundary 44 37 '', 45 38 ''] … … 51 44 m.generate_mesh(maximum_triangle_area=maximum_triangle_area) 52 45 triangle_count = m.get_triangle_count() 53 54 55 46 56 47 if mesh_file is None: -
development/momentum_sink/loop_buildings.py
r2446 r2458 10 10 File_boundary, Dirichlet_boundary, Time_boundary, Transmissive_boundary 11 11 from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA 12 12 import project 13 from create_buildings import create_mesh 14 from pmesh.mesh import importMeshFromFile 13 15 import Numeric 14 16 … … 19 21 20 22 21 DR = [3,5,7,9 ]23 DR = [3,5,7,9,11,13,15,17] 22 24 for depth in DR: 23 import project24 25 25 from create_buildings import create_mesh26 from pmesh.mesh import importMeshFromFile27 26 meshname = project.meshname 28 27 outputname = project.outputname 29 28 t0 = time.time() 30 meshname, triagle_count = cache(create_mesh,(100 ),29 meshname, triagle_count = cache(create_mesh,(1000,depth), 31 30 {'mesh_file':meshname, 32 31 'triangles_in_name':True} … … 44 43 45 44 46 domain.set_name(project.basename + '_ brd=%dm_%d' %(depth, triagle_count))45 domain.set_name(project.basename + '_Orth(45)_D=%d_%d' %(depth, triagle_count)) 47 46 domain.set_datadir(project.outputdir) 48 47 domain.store = True 49 domain.quantities_to_be_stored = ['stage' ]48 domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum'] 50 49 51 50 print 'Number of triangles = ', len(domain) 52 51 print 'The extent is ', domain.get_extent() 52 print 'current building depth = ', depth 53 53 54 54 #Setup Initial Conditions … … 66 66 Bdb = Dirichlet_boundary([0,0,0]) 67 67 Bw = Time_boundary(domain=domain, 68 f=lambda t: [(60<t< 300)*4, 0, 0])68 f=lambda t: [(60<t<660)*4, 0, 0]) 69 69 70 70 domain.set_boundary( {'wall': Br,'wave': Bdw, 'back': Bdb, 'exterior':Bdw} ) … … 73 73 t0 = time.time() 74 74 75 for t in domain.evolve(yieldstep = 1 , finaltime = 10):75 for t in domain.evolve(yieldstep = 10, finaltime = 1000): 76 76 domain.write_time() 77 77 -
development/momentum_sink/loop_friction.py
r2446 r2458 24 24 from pmesh.mesh import importMeshFromFile 25 25 26 Friction = Numeric.arrayrange(50,80,1) 26 #Friction = Numeric.arrayrange(0.025,1,0.025) 27 Friction = [150,200,500,1000,2000,5000,10000] 27 28 for fric in Friction: 28 29 meshname = project_friction.meshname … … 56 57 ) 57 58 58 59 domain.set_name(project_friction.basename + '% d_%d' %(fric, triagle_count))59 #fr=str(fric).strip('.') 60 domain.set_name(project_friction.basename + '%s_%d' %(str(fric).strip('.'), triagle_count)) 60 61 domain.set_datadir(project_friction.outputdir) 61 62 domain.store = True -
development/momentum_sink/run_buildings.py
r2446 r2458 15 15 16 16 17 from create_buildings import create_mesh , depth17 from create_buildings import create_mesh 18 18 #from building_generator import create_mesh 19 19 20 20 from pmesh.mesh import importMeshFromFile 21 22 depth = 17 # depth of building side to oncoming wave 23 breadth = 17 # breadth of building, width of building to oncoming wave 24 #from loop_buildings import depth 21 25 22 26 meshname = project.meshname … … 25 29 t0 = time.time() 26 30 27 meshname, triagle_count = cache(create_mesh,(100 ),31 meshname, triagle_count = cache(create_mesh,(1000,depth), 28 32 {'mesh_file':meshname, 29 33 'triangles_in_name':True} … … 31 35 #,evaluate = True 32 36 ) 33 #meshname = ' build.tsh'37 #meshname = 'test.tsh' 34 38 #outputname = outputname[:-4] + '_' + str(triagle_count) + outputname[-4:] 35 39 … … 43 47 dependencies = [meshname] 44 48 ,verbose = False 49 ,evaluate = True 50 45 51 ) 46 52
Note: See TracChangeset
for help on using the changeset viewer.