Changeset 989


Ignore:
Timestamp:
Mar 2, 2005, 5:49:23 PM (20 years ago)
Author:
steve
Message:

Corrected h limited update to ensure conservation.

Location:
inundation/ga/storm_surge
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • inundation/ga/storm_surge/analytical solutions/Analytical_solution_Yoon_import_mesh.py

    r774 r989  
    44and used by Yoon and Chou.
    55
    6    Copyright 2004
    7    Christopher Zoppou, Stephen Roberts, Ole Nielsen, Duncan Gray
    8    Geoscience Australia
     6   Copyright 2005
     7   Christopher Zoppou, Stephen Roberts, Ole Nielsen
     8   ANU, Geoscience Australia
    99   
    1010"""
    1111
    12 ######################
     12#---------------
    1313# Module imports
    1414import sys
    1515from os import sep
    1616sys.path.append('..'+sep+'pyvolution')
    17 
    1817from shallow_water import Domain, Dirichlet_boundary
    1918from math import sqrt, cos, sin, pi
    2019from mesh_factory import strang_mesh
     20from util import inside_polygon
     21from Numeric import asarray
     22from least_squares import Interpolation
    2123
    22 
    23 ######################
    24 # Domain
    25 # Strang_domain will search through the file and test to see if there are
    26 # two or three entries. Two entries are for points and three for triangles.
    27 
     24#-------------------------------
     25# Set up the domain of triangles
     26# Strang_domain will search
     27# through the file and test to
     28# see if there are two or three
     29# entries. Two entries are for
     30# points and three for triangles.
    2831points, elements = strang_mesh('yoon_circle.pt')
    2932domain = Domain(points, elements)
    3033
     34#----------------
     35# Order of scheme
    3136domain.default_order = 2
     37
    3238domain.smooth = True
    3339
    34 
     40#-------------------------------------
    3541# Provide file name for storing output
    36 domain.store = True
     42domain.store = False
    3743domain.format = 'sww'
    38 domain.filename = 'yoon_strang_second_order'
    39 
     44domain.filename = 'yoon_mesh_second_order.2'
    4045print 'Number of triangles = ', len(domain)
    4146
    42 #Reduction operation for get_vertex_values
     47#----------------------------------------------------------
     48# Decide which quantities are to be stored at each timestep
     49domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
     50
     51#------------------------------------------
     52# Reduction operation for get_vertex_values
    4353from util import mean
    44 domain.reduction = mean
    45 #domain.reduction = min  #Looks better near steep slopes
     54domain.reduction = mean #domain.reduction = min  #Looks better near steep slopes
    4655
    4756
    48 ######################
    49 #Initial condition
    50 #
     57#------------------
     58# Initial condition
    5159print 'Initial condition'
    5260t = 0.0
     
    5866A = (L**4 - R0**4)/(L**4 + R0**4)
    5967omega = 2./L*sqrt(2.*g*D0)
    60 print 'omega = ',omega
    6168T = pi/omega
    62 print T
    6369
    64 
    65 #Set bed-elevation and friction(None)
     70#------------------
     71# Set bed elevation
    6672def x_slope(x,y):
    6773    n = x.shape[0]
     
    7177        z[i] = -D0*(1.-r*r/L/L)
    7278    return z
    73 
    7479domain.set_quantity('elevation', x_slope)
    7580
    76 #Set the initial water stage
    77 def stage(x,y):
     81#----------------------------
     82# Set the initial water level
     83def level(x,y):
    7884    z = x_slope(x,y)
    7985    n = x.shape[0]
     
    8692        h[i] = z[i]
    8793    return h   
    88 
    89 domain.set_quantity('stage', stage)
     94domain.set_quantity('stage', level)
    9095
    9196
    92 ############
    93 #Boundary
     97#---------
     98# Boundary
     99print 'Boundary conditions'
    94100domain.set_boundary({'exterior': Dirichlet_boundary([0.0, 0.0, 0.0])})
     101
     102#---------------------------------------------
     103# Find triangle that contains the point points
     104# and print to file
     105points = [0.,0.]
     106for n in range(len(domain.triangles)):
     107    t = domain.triangles[n]
     108    tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]]
     109
     110    if inside_polygon(points,tri):
     111        print 'Point is within triangle with vertices '+'%s'%tri
     112        n_point = n
     113t = domain.triangles[n_point]
     114tri = [domain.coordinates[t[0]],domain.coordinates[t[1]],domain.coordinates[t[2]]]
     115
     116filename=domain.filename
     117file = open(filename,'w')
    95118   
    96 
    97 ######################
    98 #Evolution
     119#----------
     120# Evolution
    99121import time
    100122t0 = time.time()
    101 for t in domain.evolve(yieldstep = 10.0, finaltime = 5000):
     123for t in domain.evolve(yieldstep = 20.0, finaltime = 3000 ):
    102124    domain.write_time()
    103125
     126    tri_array = asarray(tri)
     127    t_array = asarray([[0,1,2]])
     128    interp = Interpolation(tri_array,t_array,[points])
     129
     130    stage = domain.get_quantity('stage')[n_point]
     131    xmomentum = domain.get_quantity('xmomentum')[n_point]
     132    ymomentum = domain.get_quantity('ymomentum')[n_point]
     133
     134    interp_stage = interp.interpolate([[stage[0]],[stage[1]],[stage[2]]])
     135    interp_xmomentum = interp.interpolate([[xmomentum[0]],[xmomentum[1]],[xmomentum[2]]])
     136    interp_ymomentum = interp.interpolate([[ymomentum[0]],[ymomentum[1]],[ymomentum[2]]])
     137   
     138    file.write( '%10.6f   %10.6f  %10.6f   %10.6f\n'%(t,interp_stage[0][0],interp_xmomentum[0][0],interp_ymomentum[0][0]) )
     139
     140file.close()   
    104141print 'That took %.2f seconds' %(time.time()-t0)
    105 
    106    
  • inundation/ga/storm_surge/pyvolution-1d/quantity.py

    r513 r989  
    446446    Q1.limit()
    447447   
    448     from matplotlib.matlab import *
     448    from pylab import *
    449449    plot(Xc,Qc)
    450450
  • inundation/ga/storm_surge/pyvolution/shallow_water.py

    r955 r989  
    5959Generic_domain = Domain #Rename
    6060
     61#Shalow water domain
    6162class Domain(Generic_domain):
    6263
     
    435436            #Update optimal_timestep
    436437            try:
    437                 timestep = min(timestep, domain.radii[k]/max_speed)
     438                timestep = min(timestep, 0.5*domain.radii[k]/max_speed)
    438439            except ZeroDivisionError:
    439440                pass
     
    15011502
    15021503
     1504
     1505def compute_fluxes_python(domain):
     1506    """Compute all fluxes and the timestep suitable for all volumes
     1507    in domain.
     1508
     1509    Compute total flux for each conserved quantity using "flux_function"
     1510
     1511    Fluxes across each edge are scaled by edgelengths and summed up
     1512    Resulting flux is then scaled by area and stored in
     1513    explicit_update for each of the three conserved quantities
     1514    stage, xmomentum and ymomentum   
     1515
     1516    The maximal allowable speed computed by the flux_function for each volume
     1517    is converted to a timestep that must not be exceeded. The minimum of
     1518    those is computed as the next overall timestep.
     1519
     1520    Post conditions:
     1521      domain.explicit_update is reset to computed flux values
     1522      domain.timestep is set to the largest step satisfying all volumes.
     1523    """
     1524
     1525    import sys
     1526    from Numeric import zeros, Float
     1527
     1528    N = domain.number_of_elements
     1529   
     1530    #Shortcuts
     1531    Stage = domain.quantities['stage']
     1532    Xmom = domain.quantities['xmomentum']
     1533    Ymom = domain.quantities['ymomentum']
     1534    Bed = domain.quantities['elevation']       
     1535
     1536    #Arrays
     1537    stage = Stage.edge_values
     1538    xmom =  Xmom.edge_values
     1539    ymom =  Ymom.edge_values
     1540    bed =   Bed.edge_values   
     1541
     1542    stage_bdry = Stage.boundary_values
     1543    xmom_bdry =  Xmom.boundary_values
     1544    ymom_bdry =  Ymom.boundary_values
     1545   
     1546    flux = zeros((N,3), Float) #Work array for summing up fluxes
     1547
     1548    #Loop
     1549    timestep = float(sys.maxint)   
     1550    for k in range(N):
     1551
     1552        for i in range(3):
     1553            #Quantities inside volume facing neighbour i
     1554            ql = [stage[k, i], xmom[k, i], ymom[k, i]]
     1555            zl = bed[k, i]
     1556
     1557            #Quantities at neighbour on nearest face
     1558            n = domain.neighbours[k,i]
     1559            if n < 0:
     1560                m = -n-1 #Convert negative flag to index
     1561                qr = [stage_bdry[m], xmom_bdry[m], ymom_bdry[m]]
     1562                zr = zl #Extend bed elevation to boundary
     1563            else:   
     1564                m = domain.neighbour_edges[k,i]
     1565                qr = [stage[n, m], xmom[n, m], ymom[n, m]]
     1566                zr = bed[n, m]               
     1567
     1568               
     1569            #Outward pointing normal vector   
     1570            normal = domain.normals[k, 2*i:2*i+2]
     1571
     1572            #Flux computation using provided function
     1573            edgeflux, max_speed = flux_function(normal, ql, qr, zl, zr)
     1574       
     1575            flux[k,:] = edgeflux
     1576
     1577    return flux
     1578   
     1579 
     1580
     1581
     1582
     1583
     1584
    15031585##############################################
    15041586#Initialise module
     
    15191601   
    15201602    #distribute_to_vertices_and_edges = distribute_to_vertices_and_edges_c
     1603
    15211604
    15221605
  • inundation/ga/storm_surge/pyvolution/shallow_water_ext.c

    r907 r989  
    626626      //timestep = min(timestep, domain.radii[k]/max_speed)
    627627      if (max_speed > epsilon) {
    628         timestep = min(timestep, ((double *) radii -> data)[k]/max_speed);
     628        timestep = min(timestep, 0.5*((double *) radii -> data)[k]/max_speed);
    629629      }   
    630630    } // end for i
     
    767767  hvbar = (PyArrayObject *) PyArray_FromDims(2, dimensions, PyArray_DOUBLE);
    768768
    769      
     769 
     770
    770771  //Find min and max of this and neighbour's centroid values
    771772  hmin = malloc(N * sizeof(double));
     
    779780    for (i=0; i<3; i++) {
    780781      n = ((long*) neighbours -> data)[k3+i];
     782      ((double*) hvbar -> data)[k3+i] = ((double*) hc -> data)[k]; 
    781783      if (n >= 0) {
    782784        hn = ((double*) hc -> data)[n]; //Neighbour's centroid value
  • inundation/ga/storm_surge/pyvolution/util.py

    r969 r989  
    10161016       Polygon_function(polygons)
    10171017       
    1018     where polygons is a dictionary of the form
    1019    
    1020       {P0: v0, P1: v1, ...}
     1018    where polygons is a list of tuples of the form
     1019   
     1020      [ (P0, v0), (P1, v1), ...]
    10211021     
    10221022      with Pi being lists of vertices defining polygons and vi either
Note: See TracChangeset for help on using the changeset viewer.