Changeset 3247


Ignore:
Timestamp:
Jun 27, 2006, 6:10:14 PM (18 years ago)
Author:
sexton
Message:

updates for Year 10 student problem

Location:
documentation/user_manual/examples
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • documentation/user_manual/examples/harbour.py

    r3224 r3247  
    5151
    5252domain = Domain(meshname,use_cache=True,verbose = True)
    53 domain.set_name('test')                     # Output to test.sww
     53domain.set_name('harbour')                  # Output to harbour.sww
    5454domain.set_datadir('.')                     # Use current directory for output
    5555domain.set_quantities_to_be_stored(['stage',# Store all conserved quantities
     
    7676                if yi < ycentredown: z[i,j] = 0.0
    7777                if yi > ycentreup: z[i,j] = 0.0
    78                 if yi > ycentredown and yi < ycentreup: z[i,j] =
    79 harbour_depth
    80            if xi > centre-harbour_length and xi < centre: z[i,j] =
    81 harbour_depth
     78                if yi > ycentredown and yi < ycentreup: z[i,j] = harbour_depth
     79           if xi > centre-harbour_length and xi < centre: z[i,j] = harbour_depth
    8280    return z
    8381
     
    108106    domain.write_time()
    109107
     108#-----------------------------------------------------------------------------
     109# Interrogate solution
     110#-----------------------------------------------------------------------------
     111
    110112# Gauge line
    111113def gauge_line(west,east,north,south):
     
    118120    return gauges
    119121
    120 #-----------------------------------------------------------------------------
    121 # Interrogate solution
    122 #-----------------------------------------------------------------------------
    123 
    124122gauges = gauge_line(west,east,north,south)
    125123
    126 f = file_function(gauges)
     124from pyvolution.util import file_function
     125
     126f = file_function('harbour.sww',
     127                  quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
     128                  interpolation_points = gauges,
     129                  verbose = True,
     130                  use_cache = True)
     131
    127132maxw = 0.0
    128133themaxw = maxw
     
    130135for k, g in enumerate(gauges):
    131136    for i, t in enumerate(f.get_time()):
    132          if w > maxw: maxw = w
     137        w = f(t, point_id = k)[0]
     138        elevation = f(t, point_id = k)[1]
     139        if w > maxw: maxw = w
    133140    maxws.append(maxw)
    134     if themaxw < maxw: 
    135        themaxw = maxw
    136        gaugeloc = k
     141    if themaxw < maxw:
     142        themaxw = maxw
     143        gaugeloc = k
    137144
    138 from pylab import plot, xlabel, ylabel, title
     145from pylab import plot, xlabel, ylabel, title, ion, close, savefig
     146ion()
    139147plot(gaugex,maxws,'g-',gaugestar[0],gaugestar[1],'r*')
    140148xlabel('x')
    141149ylabel('stage')
    142150title('Maximum stage for gauge line')
     151savefig('max_stage_harbour')
     152close('all')
  • documentation/user_manual/examples/runuptest.py

    r3224 r3247  
    1717from pyvolution.shallow_water import Transmissive_boundary
    1818
    19 waveheight = 1.0
     19
    2020#------------------------------------------------------------------------------
    2121# Setup computational domain
    2222#------------------------------------------------------------------------------
    2323
    24 west = 340000.
    25 east = 380000.
    26 south = 6265000.
    27 north = 6250000.
     24waveheight = 1000.0
     25depth_east_edge = -4000.
     26west = 0.
     27east = 80000.
     28south = 0.
     29north = 5000.
    2830polygon = [[east,north],[west,north],[west,south],[east,south]]
    2931meshname = 'test.msh'
     
    3436                                        'bottom': [2],
    3537                                        'right': [3]},
    36                          maximum_triangle_area=50000,
     38                         maximum_triangle_area=100000,
    3739                         filename=meshname)
    3840                         #interior_regions=interior_regions)
     
    5153
    5254def topography(x,y):
    53     slope = -1./400.
    54     c = 850.0
    55     return slope*x+c                              # linear bed slope
     55    slope = depth_east_edge/((east-west)/2.)
     56    c = -(west+east)/2.*slope
     57    return slope*x+c                         # linear bed slope
    5658
    5759domain.set_quantity('elevation', topography) # Use function for elevation
     
    7981
    8082stagestep = []
    81 for t in domain.evolve(yieldstep = 10, finaltime = 100.0):
     83for t in domain.evolve(yieldstep = 10, finaltime = 1000.0):
    8284    domain.write_time()
    83 
    84 # Gauge line
    85 def gauge_line(west,east,north,south):
    86     from Numeric import arange
    87     gaugex = arange(west,east,1000.)
    88     gauges = []
    89     for x in gaugex:
    90         y = (north+south)/2.
    91         gauges.append([x,y])
    92     return gauges
    9385
    9486#-----------------------------------------------------------------------------
     
    9688#-----------------------------------------------------------------------------
    9789
    98 gauges = gauge_line(west,east,north,south)
     90# Gauge line
     91def gauge_line(west,east,north,south):
     92    from Numeric import arange
     93    gaugex = arange(east,west,-1000.)
     94    gauges = []
     95    gaugey = []
     96    for x in gaugex:
     97        y = (north+south)/2.
     98        gaugey.append(y)
     99        gauges.append([x,y])
     100    return gauges, gaugex, gaugey
    99101
    100 f = file_function(gauges)
    101 maxw = 0.0
    102 themaxw = maxw
    103 maxws = []
     102gauges, gaugex, gaugey = gauge_line(west,east,north,south)
     103
     104from pyvolution.util import file_function
     105
     106f = file_function('test.sww',
     107                  quantities = ['stage', 'elevation', 'xmomentum', 'ymomentum'],
     108                  interpolation_points = gauges,
     109                  verbose = True,
     110                  use_cache = True)
     111
     112from pylab import plot, xlabel, ylabel, title, ion, close, savefig, figure
     113ion()
     114
     115maxw = []
     116minw = []
     117maxd = []
     118count = 0
    104119for k, g in enumerate(gauges):
     120    stage = []
     121    elevation = []
     122    depths = []
    105123    for i, t in enumerate(f.get_time()):
    106         if elevation > 0:
    107             if w > maxw: maxw = w
    108     maxws.append(maxw)
    109     if elevation > 0:
    110        if themaxw < maxw:
    111            themaxw = maxw
    112            gaugeloc = k
     124        w = f(t, point_id = k)[0]
     125        elev = f(t, point_id = k)[1]
     126        depth = w-elev
     127        stage.append(w)
     128        elevation.append(elev)
     129        depths.append(elev)
     130        if g[0] < (west+east)/2. and depth <= 0 and count == 0:
     131            count += 1
     132            posx = g[0]
     133            loc = k
     134    maxw.append(max(stage))
     135    minw.append(min(stage))
     136    maxd.append(max(depths))
    113137
    114 filename = 'maxrunup'+waveheight+'.csv'
     138filename = 'maxrunup'+str(waveheight)+str(depth_east_edge)+'.csv'
    115139fid = open(filename,'w')   
    116 s = 'Waveheight,Runup distance,Runup height\n'
     140s = 'Depth at eastern boundary,Waveheight,Runup distance,Runup height\n'
    117141fid.write(s)
    118 gaugestar = gauges[gaugeloc]
    119 s = '%.2f, %.2f/n' %(waveheight,gaugestar[0],gaugestar[1])
     142runup_distance = posx
     143runup_height = topography(runup_distance,(north+south)/2.)
     144print 'run up height:   ', runup_height
     145if runup_distance < (east+west)/2.:
     146    runup_distance_from_coast = (east+west)/2.-runup_distance
     147else:
     148    runup_distance_from_coast = runup_distance-(east+west)/2.
     149print 'run up distance from coastline: ', runup_distance_from_coast
     150s = '%.2f,%.2f,%.2f,%.2f\n' %(depth_east_edge,waveheight,runup_distance_from_coast,runup_height)
    120151fid.write(s)
    121152
    122 from pylab import plot, xlabel, ylabel, title
    123 plot(gaugex,maxws,'g-',gaugestar[0],gaugestar[1],'r*')
     153figure(1)
     154plot(gaugex[:loc],maxw[:loc],'g-')
    124155xlabel('x')
    125156ylabel('stage')
    126157title('Maximum stage for gauge line')
     158savefig('max_stage')
     159
     160close('all')
Note: See TracChangeset for help on using the changeset viewer.