Changeset 2458


Ignore:
Timestamp:
Mar 1, 2006, 1:59:25 PM (18 years ago)
Author:
nicholas
Message:

CCS.py modified to loop through building scenarios and write results to file.

Location:
development/momentum_sink
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • development/momentum_sink/CCS.py

    r2446 r2458  
    11"""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'
    37
    48"""
     
    711import project
    812from pyvolution.util import file_function
    9 from create_buildings import porosity, WidtH
    10 # from run_friction import fric
     13from create_buildings import WidtH
    1114from pylab import *
    1215from numerical_tools import norm, corr, err 
    1316
     17B_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']
    1428
    1529
    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)
     30fd = open("Straight_log_report.csv", 'w')
     31fd.write( 'Straight_log_report. Summary at bottom.' + '\n' )
    2532
    2633
    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#---------------------------------------------
    2838
    29 #Read model output
    30 quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum']
     39best_fric=[]
     40B_Density=[]
     41best_norm=[]
     42Breadth=[]
    3143
    32 f_B = file_function(swwfile_B,
    33                   quantities = quantities,
    34                   interpolation_points = gauge_locations,
    35                   verbose = True,
    36                   use_cache = True)
    3744
    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,
     45for 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,
    4664                      quantities = quantities,
    4765                      interpolation_points = gauge_locations,
     
    4967                      use_cache = True)
    5068
    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"
    52119   
    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         
     135print best_fric, " << Best fit friction"
     136print B_Density, " << Building footprint density"
     137print best_norm, " << Matching normal densities"
    56138
    57         # mines data from specified time values in sww file
    58         # Building file
    59         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 file
    64         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]
    67139
    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)
     140len_file=Numeric.arrayrange(0,len(B_list),1)
     141fd.write('_______________________________________________________' + '\n' )
     142fd.write( '<<<<< Straight_log_report Summary >>>>>' + '\n' )
     143fd.write( 'width, footprint ratio, mannings n, 2nd norm ' + '\n')
     144for i in len_file:
     145    fd.write( str(Breadth[i]) + ', ' + str(B_Density[i]) + ', ' +  str(best_fric[i]) + ', ' +  str(best_norm[i]) + '\n')
     146fd.close
    84147
    85     if norm_F < least_norm:
    86         least_norm = norm_F
    87         fric_OK = fric
    88     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  
    77import project
    88from pyvolution.util import file_function
    9 from create_buildings import porosity, WidtH
     9from create_buildings import WidtH
    1010# from run_friction import fric
    1111from pylab import *
     
    1616
    1717#swwfile_B = project.outputdir + sep  + 'Buildings_3790.sww'
    18 swwfile_B = project.outputdir + sep  + 'Straight_offset.sww'
     18swwfile_B = project.outputdir + sep  + 'buildings_S0_D=19_1037.sww'
    1919#swwfile_B = project.outputdir + sep  + 'friction_n=10_3135.sww'
    20 swwfile_F = project.outputdir + sep  + 'friction_n=51_3135.sww'
     20swwfile_F = project.outputdir + sep  + 'friction_n=37_3135.sww'
    2121
    22 gauge_depth = Numeric.arrayrange(46, 1.5*WidtH, 25) # Random special
     22gauge_depth = Numeric.arrayrange(51, 1.5*WidtH, 25) # Random special
    2323#gauge_depth = Numeric.arrayrange(0, 1.5*WidtH, 25)
    2424gauge_breadth = 100
     
    9090   
    9191    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)
    9393    xlabel('gauge length(m)')
    9494    ylabel('water depths (m)')
  • development/momentum_sink/create_buildings.py

    r2446 r2458  
    77from coordinate_transforms.geo_reference import Geo_reference
    88
    9 depth = 11 # depth of building side to oncoming wave
    10 breadth = 11 # breadth of building, width of building to oncoming wave
    11 #from loop_buildings import depth
    12 
    139WidtH = 200 # width of boudary in metres
    14 #breadth = depth
    15 
    16 print "building footprint"
    17 print depth * breadth , "m^2"
    18 block = 625
    19 BL = block**0.5
    20 
    21 porosity = breadth/BL                           
    22 print porosity, " Building porosity"
    2310
    2411#random.uniform(0,1) #proper implemantation of random generator
    2512
    26 def create_mesh(maximum_triangle_area,
     13def create_mesh(maximum_triangle_area, depth,
    2714                mesh_file=None,
    2815                triangles_in_name = False):
     
    3219    """
    3320
    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"
    3531    # create a mesh instance of class Mesh
    3632    m = Mesh()
     
    4440    whs = depth/2
    4541    lhs = breadth/2
    46     #Th = (45 *(3.142/180)) # sets an initial rotation     
    47     Th = 0
     42    Th = (45 *(3.142/180)) # sets an initial rotation     
     43    #Th = 0
    4844    ForDep = (0.2*WidtH) + (BL-whs)
    4945    RearDep = 1.2*WidtH
    5046       
    5147    Breadths = Numeric.arrayrange( -(BL/2), WidtH+(BL/2), (BL))
     48    #Breadths = Numeric.arrayrange( (BL/2), WidtH-(BL/2), (BL)) # For ortho-offset
    5249    print Breadths, "Breadths"
    5350    Depths = Numeric.arrayrange( ForDep, RearDep, BL )
     
    5552
    5653    for i,D in enumerate(Depths):
    57         Breadths = Breadths + ((-1)**i)*(BL/2) #Used to offset buildings
     54        #Breadths = Breadths + ((-1)**i)*(BL/2) #Used to offset buildings
    5855        for B in Breadths:
    5956            wh1 = (-whs) * math.cos(Th) + (-lhs) * math.sin(Th)
     
    7673    else:
    7774        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) \
    7976                        + mesh_file[-4:]
    8077        m.export_mesh_file(mesh_file)
     
    8380#-------------------------------------------------------------
    8481if __name__ == "__main__":
    85     _, triangle_count = create_mesh(10,mesh_file="test.tsh")
     82    _, triangle_count = create_mesh(100,15,mesh_file="test.tsh")
    8683    print "triangle_count",triangle_count
  • development/momentum_sink/friction_block.py

    r2395 r2458  
    66from coordinate_transforms.geo_reference import Geo_reference
    77
    8 #test = 300
     8
    99def create_mesh(maximum_triangle_area,
    1010                mesh_file=None,
     
    1717    m = Mesh()
    1818   
    19     #print "test", test 
    2019    # Boundary of problem
    2120    WidtH = 200 # width of boudary in metres
    22     #W = WidtH/8
    23     #L = W
    24     #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'))
    2821
    2922    #Boundary
     
    3831                            'wall',                           
    3932                            'wall',
    40                             'back',
     33                            'back', # defines direchet boundary for back of test area
    4134                            'wall',
    4235                            'wall',
    43                             'wave',
     36                            'wave', # defines the wave boundary
    4437                            '',                           
    4538                            '']
     
    5144    m.generate_mesh(maximum_triangle_area=maximum_triangle_area)
    5245    triangle_count = m.get_triangle_count()
    53  
    54 
    5546   
    5647    if mesh_file is None:   
  • development/momentum_sink/loop_buildings.py

    r2446 r2458  
    1010File_boundary, Dirichlet_boundary, Time_boundary, Transmissive_boundary
    1111from pyvolution.least_squares import fit_to_mesh_file, DEFAULT_ALPHA
    12 
     12import project
     13from create_buildings import create_mesh
     14from pmesh.mesh import importMeshFromFile
    1315import Numeric
    1416
     
    1921
    2022
    21 DR = [3,5,7,9]
     23DR = [3,5,7,9,11,13,15,17]
    2224for depth in DR:
    23     import project
    2425   
    25     from create_buildings import create_mesh
    26     from pmesh.mesh import importMeshFromFile
    2726    meshname = project.meshname
    2827    outputname = project.outputname
    2928    t0 = time.time()
    30     meshname, triagle_count = cache(create_mesh,(100),
     29    meshname, triagle_count = cache(create_mesh,(1000,depth),
    3130                                    {'mesh_file':meshname,
    3231                                     'triangles_in_name':True}
     
    4443
    4544
    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))
    4746    domain.set_datadir(project.outputdir)
    4847    domain.store = True
    49     domain.quantities_to_be_stored = ['stage']
     48    domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
    5049
    5150    print 'Number of triangles = ', len(domain)
    5251    print 'The extent is ', domain.get_extent()
     52    print 'current building depth = ', depth
    5353
    5454    #Setup Initial Conditions
     
    6666    Bdb = Dirichlet_boundary([0,0,0])
    6767    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])
    6969
    7070    domain.set_boundary( {'wall': Br,'wave': Bdw, 'back': Bdb, 'exterior':Bdw} )
     
    7373    t0 = time.time()
    7474
    75     for t in domain.evolve(yieldstep = 1, finaltime = 10):
     75    for t in domain.evolve(yieldstep = 10, finaltime = 1000):
    7676        domain.write_time()     
    7777
  • development/momentum_sink/loop_friction.py

    r2446 r2458  
    2424from pmesh.mesh import importMeshFromFile
    2525
    26 Friction = Numeric.arrayrange(50,80,1)
     26#Friction = Numeric.arrayrange(0.025,1,0.025)
     27Friction = [150,200,500,1000,2000,5000,10000]
    2728for fric in Friction:
    2829    meshname = project_friction.meshname
     
    5657                   )               
    5758
    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))
    6061    domain.set_datadir(project_friction.outputdir)
    6162    domain.store = True
  • development/momentum_sink/run_buildings.py

    r2446 r2458  
    1515
    1616
    17 from create_buildings import create_mesh, depth
     17from create_buildings import create_mesh
    1818#from building_generator import create_mesh
    1919
    2020from pmesh.mesh import importMeshFromFile
     21
     22depth = 17 # depth of building side to oncoming wave
     23breadth = 17 # breadth of building, width of building to oncoming wave
     24#from loop_buildings import depth
    2125
    2226meshname = project.meshname
     
    2529t0 = time.time()
    2630
    27 meshname, triagle_count = cache(create_mesh,(100),
     31meshname, triagle_count = cache(create_mesh,(1000,depth),
    2832                                {'mesh_file':meshname,
    2933                                 'triangles_in_name':True}
     
    3135                                #,evaluate = True     
    3236                                )
    33 #meshname = 'build.tsh'
     37#meshname = 'test.tsh'
    3438#outputname = outputname[:-4] + '_' + str(triagle_count) + outputname[-4:]
    3539
     
    4347               dependencies = [meshname]                   
    4448               ,verbose = False
     49               ,evaluate = True     
     50
    4551               )               
    4652
Note: See TracChangeset for help on using the changeset viewer.