Changeset 8189


Ignore:
Timestamp:
Jul 1, 2011, 2:52:36 PM (14 years ago)
Author:
steve
Message:

Added in Sudi's most recent 1d codes

Location:
trunk/anuga_work/development/2010-projects/anuga_1d
Files:
28 added
6 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/2010-projects/anuga_1d/base/limiters_python.py

    r7930 r8189  
    1212    from numpy import abs, where
    1313
    14     phi = where((abs(a) < abs(b)) & (a*b > 0.0), a, 0.0)
    15     phi = where((abs(b) < abs(a)) & (a*b > 0.0), b, phi)
     14    phi = where((abs(a) < abs(b)) & (a*b >= 0.0), a, 0.0)
     15    phi = where((abs(b) < abs(a)) & (a*b >= 0.0), b, phi)
    1616
    1717    return phi
     
    2020    from numpy import sign, abs, minimum, where
    2121
    22     return where( (sign(a)*sign(b) > 0.0) & (sign(a)*sign(c)>0.0),
     22    return where( (sign(a)*sign(b) >= 0.0) & (sign(a)*sign(c)>0.0),
    2323        sign(a)*minimum(minimum(abs(a),abs(b)),abs(c)), 0.0 )
    2424
  • trunk/anuga_work/development/2010-projects/anuga_1d/base/quantity_ext.c

    r7930 r8189  
    8888
    8989          phi = 0.0;
    90           if ((fabs(a) < fabs(b)) & (a*b > 0.0 )) {
     90          if ((fabs(a) < fabs(b)) & (a*b >= 0.0 )) {
    9191              phi = a;
    9292          }
    93           if ((fabs(b) < fabs(a)) & (a*b > 0.0 )) {
     93          if ((fabs(b) < fabs(a)) & (a*b >= 0.0 )) {
    9494              phi = b;
    9595          }
     
    191191
    192192          phi = 0.0;
    193           if ((sign(a)*sign(b) > 0.0) & (sign(a)*sign(c) > 0.0 )) {
     193          if ((sign(a)*sign(b) > 0.0) & (sign(a)*sign(c) >= 0.0 )) {
    194194              phi = sign(a)*min(theta*min(fabs(a),fabs(b)),fabs(c));
    195195          }
  • trunk/anuga_work/development/2010-projects/anuga_1d/sww/run_parabolic_canal.py

    r8073 r8189  
    11import os
    22from math import sqrt, pi, sin, cos
    3 from shallow_water_vel_domain import *
    4 from Numeric import allclose, array, zeros, ones, Float, take, sqrt
    5 from config import g, epsilon
    6 
    7 def analytic_cannal(C,t):
    8     N = len(C)
    9     u = zeros(N,Float)    ## water velocity
    10     h = zeros(N,Float)    ## water depth
    11     x = C
    12     g = 9.81
    13     ## Define Basin Bathymetry
    14     z_b = zeros(N,Float) ## elevation of basin
    15     z = zeros(N,Float)   ## elevation of water surface
    16     z_infty = 10.0       ## max equilibrium water depth at lowest point.
    17     L_x = 2500.0         ## width of channel
    18     A0 = 0.5*L_x                  ## determines amplitudes of oscillations
    19     omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
    20     for i in range(N):
    21         z_b[i] = z_infty*(x[i]**2/L_x**2)
    22         u[i] = -A0*omega*sin(omega*t)
    23         z[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))
    24     h = z-z_b
    25     T = 2.0*pi/omega
    26     return u,h,z,z_b, T
     3import numpy
     4import time
    275
    286
    29 L_x = 2500.0     # Length of channel (m)
    30 N = 1000         # Number of compuational cells
    31 cell_len = 4*L_x/N   # Origin = 0.0
     7from anuga_1d.sww.sww_domain import *
     8from anuga_1d.config import g, epsilon
     9from anuga_1d.base.generic_mesh import uniform_mesh
    3210
    33 points = zeros(N+1,Float)
    34 for i in range(N+1):
    35         points[i] = -2*L_x +i*cell_len
     11#===============================================================================
     12# setup problem
     13#===============================================================================
     14
     15
     16z_infty = 5.0       ## max equilibrium water depth at lowest point.
     17L_x = 2500.0         ## width of channel
     18A0 = 0.5*L_x                  ## determines amplitudes of oscillations
     19omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
     20
     21def analytic_canal(x,t):
     22    u = numpy.zeros_like(x)    ## water velocity
     23    h = numpy.zeros_like(x)    ## water depth
     24
     25    ## Define Basin Bathymetry
     26    z = numpy.zeros_like(x) ## elevation of basin
     27    w = numpy.zeros_like(x)   ## elevation of water surface
     28
     29    z[:] = z_infty*(x**2/L_x**2)
     30    u[:] = -A0*omega*sin(omega*t)
     31    w[:] = numpy.maximum(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x/L_x-0.5*A0/(L_x)*cos(omega*t)),z)
     32    h[:] = numpy.maximum(w-z, 0.0)
     33
     34    T = 2.0*pi/omega
     35
     36    return u,h,w,z, T
     37
    3638
    3739def stage(x):
    38     z_infty = 10.0       ## max equilibrium water depth at lowest point.
    39     L_x = 2500.0         ## width of channel
    40     A0 = 0.5*L_x                  ## determines amplitudes of oscillations
    41     omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
    4240    t=0.0
    43     y = zeros(len(x),Float)
    44     for i in range(len(x)):
    45         y[i] = z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))
    46         #y[i] = 12.0
    47     return y
     41    u,h,w,z,T = analytic_canal(x,t)
     42
     43    return w
    4844
    4945def elevation(x):
    50     N = len(x)
    51     z_infty = 10.0
    52     z = zeros(N,Float)
    53     L_x = 2500.0
    54     A0 = 0.5*L_x
    55     omega = sqrt(2*g*z_infty)/L_x
    56     for i in range(N):
    57         z[i] = z_infty*(x[i]**2/L_x**2)
     46    t=0.0
     47    u,h,w,z,T = analytic_canal(x,t)
     48
    5849    return z
    5950
     51
    6052def height(x):
    61     z_infty = 10.0       ## max equilibrium water depth at lowest point.
    62     L_x = 2500.0         ## width of channel
    63     A0 = 0.5*L_x                  ## determines amplitudes of oscillations
    64     omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
    6553    t=0.0
    66     y = zeros(len(x),Float)
    67     for i in range(len(x)):
    68         y[i] = max(z_infty+2*A0*z_infty/L_x*cos(omega*t)*(x[i]/L_x-0.5*A0/(L_x)*cos(omega*t))-z_infty*(x[i]**2/L_x**2),0.0)
    69     return y
     54    u,h,w,z,T = analytic_canal(x,t)
    7055
    71 domain = Domain(points)
    72 domain.order = 2
    73 domain.set_timestepping_method('euler')
     56    return h
     57
     58
     59#===============================================================================
     60finaltime = 1000.0
     61yieldstep = 10.0
     62
     63
     64
     65N = 100
     66print "Evaluating domain with %d cells" %N
     67domain = Domain(*uniform_mesh(N, x_0 = -2.0*L_x, x_1 = 2.0*L_x))
     68
     69domain.set_spatial_order(2)
     70domain.set_timestepping_method('rk2')
    7471domain.set_CFL(1.0)
    75 domain.beta = 1.0
    76 domain.set_limiter("vanleer")
     72domain.set_limiter("minmod_kurganov")
    7773
    78    
     74domain.set_beta(1.0)
     75
    7976domain.set_quantity('stage', stage)
    8077domain.set_quantity('elevation',elevation)
    81 domain.set_boundary({'exterior': Reflective_boundary(domain)})
    82  
    83 X = domain.vertices
    84 u,h,z,z_b,T = analytic_cannal(X.flat,domain.time)
    85 print 'T = ',T
    8678
    87 yieldstep = finaltime = 10.0 #T/2.0
    88 StageQ = domain.quantities['stage'].vertex_values
    89 XmomQ = domain.quantities['xmomentum'].vertex_values
     79domain.quantities['elevation'].extrapolate_second_order()
     80domain.quantities['stage'].extrapolate_second_order()
    9081
    91 import time
     82Br = Reflective_boundary(domain)
     83
     84domain.set_boundary({'left': Br, 'right' : Br})
     85
     86#domain.h0=0.0001
     87
    9288t0 = time.time()
     89
    9390for t in domain.evolve(yieldstep = yieldstep, finaltime = finaltime):
    9491    domain.write_time()
    95     print "integral", domain.quantities['stage'].get_integral()
    96     if t>0.0:
    97        
    98         x = X.flat
    99         print 'domain.time=',domain.time
    100        
    101         w_V = domain.quantities['stage'].vertex_values.flat
    102         uh_V = domain.quantities['xmomentum'].vertex_values.flat
    103         u_V = domain.quantities['velocity'].vertex_values.flat
    104         h_V = domain.quantities['height'].vertex_values.flat
    105        
    106         u,h,z,z_b,T = analytic_cannal(x,domain.time)
    107         w = z
    108         for k in range(len(h)):
    109             if h[k] < 0.0:
    110                 h[k] = 0.0
    111                 w[k] = z_b[k]
    112        
    113         from pylab import plot,title,xlabel,ylabel,legend,savefig,show,hold,subplot
    114         hold(False)
    11592
    116         #print 'size X',X.shape
    117         #print 'size w',w.shape
    118         signh = (h_V>0)
     93print 'That took %.2f seconds' %(time.time()-t0)
    11994
    120         plot1 = subplot(311)
    121         #plot(x,w,  x,w_V,  x,z_b)
    122         plot(x,signh)
    123         plot1.set_xlim([-6000,6000])
    124         xlabel('Position')
    125         ylabel('Stage')
    126         legend(('Analytic Solution', 'Numerical Solution', 'Bed'),
    127                'upper center', shadow=True)
    12895
    129        
    130         plot2 = subplot(312)
    131         plot(x,u*h,x,uh_V)
    132         #plot2.set_ylim([-1,25])
    133         xlabel('Position')
    134         ylabel('Xmomentum')
     96N = float(N)
     97HeightC    = domain.quantities['height'].centroid_values
     98StageC     = domain.quantities['stage'].centroid_values
     99BedC       = domain.quantities['elevation'].centroid_values
     100C          = domain.centroids
    135101
    136         print u_V
    137        
    138         plot3 = subplot(313)
    139         plot(x,u, x,u_V)
    140         #plot2.set_ylim([-1,25])
    141         xlabel('Position')
    142         ylabel('Velocity')
    143         show()
    144 raw_input("Press the return key!")
     102HeightV    = domain.quantities['height'].vertex_values
     103StageV     = domain.quantities['stage'].vertex_values
     104BedV       = domain.quantities['elevation'].vertex_values
     105VelocityV  = domain.quantities['velocity'].vertex_values
     106X          = domain.vertices
     107
     108
     109import pylab
     110
     111pylab.hold(False)
     112
     113plot1 = pylab.subplot(311)
     114
     115pylab.plot(X.flat,BedV.flat,X.flat,StageV.flat)
     116
     117plot1.set_ylim([-1,40])
     118
     119pylab.xlabel('Position')
     120pylab.ylabel('Stage')
     121pylab.legend(('Analytical Solution', 'Numerical Solution'),
     122           'upper right', shadow=True)
     123
     124
     125plot2 = pylab.subplot(312)
     126
     127pylab.plot(X.flat,HeightV.flat)
     128
     129plot2.set_ylim([-1,10])
     130
     131pylab.xlabel('Position')
     132pylab.ylabel('Height')
     133
     134plot3 = pylab.subplot(313)
     135
     136pylab.plot(X.flat,VelocityV.flat)
     137plot3.set_ylim([-15,15])
     138
     139pylab.xlabel('Position')
     140pylab.ylabel('Velocity')
     141
     142pylab.show()
     143
     144
     145
     146
     147
     148
  • trunk/anuga_work/development/2010-projects/anuga_1d/sww/sww_comp_flux_ext.c

    r7884 r8189  
    33#include "math.h"
    44#include <stdio.h>
     5
    56const double pi = 3.14159265358979;
    67
  • trunk/anuga_work/development/2010-projects/anuga_1d/sww/sww_domain.py

    r7884 r8189  
    237237    h_C[:] = w_C - z_C
    238238    u_C[:]  = uh_C/(h_C + h0/h_C)
    239        
     239
     240    #print 'domain.order', domain.order
     241   
    240242    for name in [ 'velocity', 'stage' ]:
    241243        Q = domain.quantities[name]
     
    258260
    259261    h_V[:,:]    = stage_V - bed_V
     262
     263
     264    #print 'any' ,numpy.any( h_V[:,0] < 0.0)
     265    #print 'any' ,numpy.any( h_V[:,1] < 0.0)
     266
     267
     268    h_0 = numpy.where(h_V[:,0] < 0.0, 0.0, h_V[:,0])
     269    h_1 = numpy.where(h_V[:,0] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,1])
     270
     271    h_V[:,0] = h_0
     272    h_V[:,1] = h_1
     273
     274
     275    h_0 = numpy.where(h_V[:,1] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,0])
     276    h_1 = numpy.where(h_V[:,1] < 0.0, 0.0, h_V[:,1])
     277
     278    h_V[:,0] = h_0
     279    h_V[:,1] = h_1
     280   
     281    #print 'any' ,numpy.any( h_V[:,0] < 0.0)
     282    #print 'any' ,numpy.any( h_V[:,1] < 0.0)
     283
     284    #h00 = 1e-12
     285    #print h00
     286
     287    h_V[:,:] = numpy.where (h_V <= h0, 0.0, h_V)
     288    u_V[:,:] = numpy.where (h_V <= h0, 0.0, u_V)
    260289
    261290#    # protect from edge values going negative
  • trunk/anuga_work/development/2010-projects/anuga_1d/test_all.py

    r7884 r8189  
    2323
    2424# Directories that should not be searched for test files.
    25 exclude_dirs = ['channel', '.svn']
     25exclude_dirs = [ '.svn']
    2626               
    2727
Note: See TracChangeset for help on using the changeset viewer.