Changeset 8196


Ignore:
Timestamp:
Aug 12, 2011, 1:30:07 PM (13 years ago)
Author:
paul
Message:

Pipe now has two reconstruction methods available, both taken from channel

Location:
trunk/anuga_work/development/2010-projects/anuga_1d/pipe
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_work/development/2010-projects/anuga_1d/pipe/pipe_domain.py

    r8188 r8196  
    140140        #Call correct module function
    141141        #(either from this module or C-extension)
    142         distribute_to_vertices_and_edges_limit_a_d(self)
     142        distribute_to_vertices_and_edges_limit_s_v_h(self)
     143        #distribute_to_vertices_and_edges_limit_s_v(self)
    143144       
    144145
     
    166167
    167168#-----------------------------------------------------------------------
    168 # Distribute to verticies with stage reconstructed and then extrapolated
     169# Distribute to verticies with stage, velocity and pipe geometry
     170# reconstructed and then extrapolated.
    169171#-----------------------------------------------------------------------
    170 def distribute_to_vertices_and_edges_limit_a_d(domain):
    171    
    172     #Remove very thin layers of water
    173     #protect_against_infinitesimal_and_negative_heights(domain) 
    174 
    175 
    176 
     172def distribute_to_vertices_and_edges_limit_s_v(domain):
    177173    import sys
    178174    from anuga_1d.config import epsilon, h0
    179175
    180    
    181176    N = domain.number_of_elements
    182177
     
    203198    s_C   = state.centroid_values
    204199
    205     if domain.setstageflag:
    206         a_C[:,] = (w_C-z_C)*b_C
    207         domain.setstageflag = False
    208 
    209     # Paul: Same for top?
    210     if domain.discontinousb:
    211         width.extrapolate_second_order()
    212        
    213 
    214     h0 = 1.0e-12
    215 
    216     # Paul: How does top (i.e. t_C) affect these?
    217     h_C[:] = numpy.where( (a_C>h0) | (b_C>h0), a_C/(b_C+h0/b_C), 0.0 )
    218     u_C[:] = numpy.where( (a_C>h0) | (b_C>h0), d_C/(a_C+h0/a_C), 0.0 )
    219 
    220     a_C[:] = numpy.where( (a_C>h0) | (b_C>h0), a_C, 0.0 )
    221     b_C[:] = numpy.where( (a_C>h0) | (b_C>h0), b_C, 0.0 )
    222     t_C[:] = numpy.where( (a_C>h0) | (b_C>h0), t_C, 0.0 )
    223     d_C[:] = numpy.where( (a_C>h0) | (b_C>h0), d_C, 0.0 )
    224 
    225     w_C[:] = h_C + z_C
    226    
    227                
    228     # Paul: same for top?
    229     bed.extrapolate_second_order()
    230    
    231     for name in ['velocity','stage']:
     200    # Calculate height, velocity and stage.
     201    # Here we assume the conserved quantities and the channel geometry
     202    # (i.e. bed, top and width) have been accurately computed in the previous
     203    # timestep.
     204    h_C[:] = numpy.where(a_C > 0.0, a_C/(b_C + h0/b_C), 0.0)
     205    u_C[:] = numpy.where(a_C > 0.0, d_C/(a_C + h0/a_C), 0.0)
     206
     207    w_C[:] = h_C + z_C   
     208     
     209    # Extrapolate velocity and stage as well as channel geometry.
     210    for name in ['velocity', 'stage', 'elevation', 'width', 'top']:
    232211        Q = domain.quantities[name]
    233212        if domain.order == 1:
     
    238217            raise 'Unknown order'
    239218
    240 
    241     a_V  = area.vertex_values
     219    # Stage, bed, width, top and velocity have been extrapolated.
     220    # We may need to ensure that top is never 0.
    242221    w_V  = stage.vertex_values
     222    u_V  = velocity.vertex_values
    243223    z_V  = bed.vertex_values
    244     h_V  = height.vertex_values
    245     u_V  = velocity.vertex_values
    246     d_V  = discharge.vertex_values
    247224    b_V  = width.vertex_values
    248225    t_V  = top.vertex_values
     226
     227    # These quantites need to update vertex_values
     228    a_V  = area.vertex_values
     229    h_V  = height.vertex_values
     230    d_V  = discharge.vertex_values
     231
     232    # State is true of false so should not be extrapolated
    249233    s_V  = state.vertex_values
    250234
    251235
    252     h_V[:] = w_V-z_V
    253 
    254     w_V[:] = numpy.where(h_V > h0, w_V, z_V)
    255     h_V[:] = numpy.where(h_V > h0, h_V, 0.0)
     236    # Calculate height and fix up negatives. The main idea here is
     237    # fix up the wet/dry interface.
     238    h_V[:,:] = w_V - z_V
     239
     240    h_0 = numpy.where(h_V[:,0] < 0.0, 0.0, h_V[:,0])
     241    h_1 = numpy.where(h_V[:,0] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,1])
     242
     243    h_V[:,0] = h_0
     244    h_V[:,1] = h_1
     245
     246
     247    h_0 = numpy.where(h_V[:,1] < 0.0, h_V[:,1]+h_V[:,0], h_V[:,0])
     248    h_1 = numpy.where(h_V[:,1] < 0.0, 0.0, h_V[:,1])
     249
     250    h_V[:,0] = h_0
     251    h_V[:,1] = h_1
     252
     253
     254    # Protect against negative and small heights. If we set h to zero
     255    # we better do the same with velocity (i.e. no water, no velocity).
     256    h_V[:,:] = numpy.where (h_V <= h0, 0.0, h_V)
     257    u_V[:,:] = numpy.where (h_V <= h0, 0.0, u_V)
     258
     259
     260    # Clean up conserved quantities
     261    w_V[:] = z_V + h_V
     262    a_V[:] = b_V * h_V
     263    d_V[:] = u_V * a_V
     264
     265   
     266    return
     267
     268#-----------------------------------------------------------------------
     269# Distribute to verticies with stage, height and velocity reconstructed
     270# and then extrapolated.
     271# In this method, we extrapolate the stage and height out to the vertices.
     272# The bed, although given as initial data to the problem, is reconstructed
     273# from the stage and height. This ensures consistency of the reconstructed
     274# quantities (i.e. w = z + h) as well as protecting against negative
     275# heights.
     276#-----------------------------------------------------------------------
     277def distribute_to_vertices_and_edges_limit_s_v_h(domain):
     278    import sys
     279    from anuga_1d.config import epsilon, h0
     280
     281    N = domain.number_of_elements
     282
     283    #Shortcuts
     284    area      = domain.quantities['area']
     285    discharge = domain.quantities['discharge']
     286    bed       = domain.quantities['elevation']
     287    height    = domain.quantities['height']
     288    velocity  = domain.quantities['velocity']
     289    width     = domain.quantities['width']
     290    top     = domain.quantities['top']
     291    stage     = domain.quantities['stage']
     292    state     = domain.quantities['state']
     293
     294    #Arrays   
     295    a_C   = area.centroid_values
     296    d_C   = discharge.centroid_values
     297    z_C   = bed.centroid_values
     298    h_C   = height.centroid_values
     299    u_C   = velocity.centroid_values
     300    b_C   = width.centroid_values
     301    t_C   = top.centroid_values
     302    w_C   = stage.centroid_values
     303    s_C   = state.centroid_values
     304
     305    # Construct h,u,w from the conserved quantities after protecting
     306    # conserved quantities from becoming too small.
     307    a_C[:] = numpy.where( (a_C>h0), a_C, 0.0 )
     308    d_C[:] = numpy.where( (a_C>h0), d_C, 0.0 )
     309    h_C[:] = numpy.where( (b_C>h0), a_C/(b_C + h0/b_C), 0.0 )
     310    u_C[:] = numpy.where( (a_C>h0), d_C/(a_C + h0/a_C), 0.0 )   
     311
     312    # Set the stage
     313    w_C[:] = h_C + z_C         
     314
     315    # Extrapolate "fundamental" quantities.
     316    # All other quantities will be reconstructed from these.
     317    for name in ['velocity', 'stage',  'height', 'width', 'top']:
     318        Q = domain.quantities[name]
     319        if domain.order == 1:
     320            Q.extrapolate_first_order()
     321        elif domain.order == 2:
     322            Q.extrapolate_second_order()
     323        else:
     324            raise 'Unknown order'
     325
     326    # These quantities have been extrapolated.
     327    # We may need to ensure top is never 0.
     328    u_V  = velocity.vertex_values
     329    w_V  = stage.vertex_values
     330    h_V  = height.vertex_values
     331    b_V  = width.vertex_values
     332    t_V  = top.vertex_values
     333       
     334    # These need to be reconstructed
     335    a_V  = area.vertex_values
     336    d_V  = discharge.vertex_values
     337    z_V  = bed.vertex_values
     338
     339    # State is true or false so should never be extrapolated.
     340    s_V = state.vertex_values
     341
     342    # Reconstruct bed from stage and height.
     343    z_V[:] = w_V-h_V
     344
     345    # Now reconstruct our conserved quantities from the above
     346    # reconstructed quantities.
    256347    a_V[:] = b_V*h_V
    257348    d_V[:] = u_V*a_V
    258349
    259    
    260350    return
    261351
  • trunk/anuga_work/development/2010-projects/anuga_1d/pipe/pipe_domain_ext.c

    r8188 r8196  
    2121
    2222// Hard coded choices of computational methods
    23 #define flux_formula0 flux_formula_press0
    24 #define flux_formula1 flux_formula_press1
     23//#define flux_formula0 flux_formula_press0
     24//#define flux_formula1 flux_formula_press1
     25#define flux_formula0 flux_formula_fs0
     26#define flux_formula1 flux_formula_fs1
    2527#define compute_flux compute_flux_godunov
    2628#define forcingterm_formula_press forcingterm_formula_press_naive
    2729#define forcingterm_formula_fs forcingterm_formula_fs_naive
    28 #define compute_forcingterm compute_forcingterm_press
     30//#define compute_forcingterm compute_forcingterm_press
     31#define compute_forcingterm compute_forcingterm_fs
    2932
    3033// Some formulae
     
    9194
    9295    edgeflux[1] = smax*flux_formula1(q_m, g) - smin*flux_formula1(q_p, g);
    93     edgeflux[1] += smax*smin * (q_p[4]*a_p - q_m[4]*a_m);
     96    //edgeflux[1] += smax*smin * (q_p[4]*a_p - q_m[4]*a_m);
     97    edgeflux[1] += smax*smin * (q_p[1] - q_m[1]);
    9498    edgeflux[1] /= denom;
    9599    }
  • trunk/anuga_work/development/2010-projects/anuga_1d/pipe/test_pipe.py

    r8188 r8196  
    1212print "Pipe Variable Width Only Test"
    1313
     14z_infty = 10.0       ## max equilibrium water depth at lowest point.
     15L_x = 2500.0         ## width of channel
     16A0 = 0.5*L_x                  ## determines amplitudes of oscillations
     17omega = sqrt(2*g*z_infty)/L_x ## angular frequency of osccilation
     18
    1419# Define functions for initial quantities
    1520def initial_stage(x):
    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
    2021    t=0.0
    2122    y = numpy.zeros(len(x),numpy.float)
    2223    for i in range(len(x)):
    23         #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))
    24         y[i] = 12.0
     24        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))
     25        #y[i] = 12.0
    2526    return y
    2627
    2728def bed(x):
    28     N = len(x)
    29     z_infty = 10.0
    30     z = numpy.zeros(N,numpy.float)
    31     L_x = 2500.0
    32     A0 = 0.5*L_x
    33     omega = sqrt(2*g*z_infty)/L_x
    34     for i in range(N):
     29    z = numpy.zeros(len(x),numpy.float)
     30    for i in range(len(x)):
    3531        z[i] = z_infty*(x[i]**2/L_x**2)
    3632    return z
     33
     34def width(x):
     35    return 1.0
     36
     37def top(x):
     38    return 4.0
    3739
    3840def initial_area(x):
     
    4042    for i in range(len(x)):
    4143        y[i]=initial_stage([x[i]])-bed([x[i]])
    42 
    4344    return y
    44 
    45 def width(x):
    46     return 1
    47 
    48 def top(x):
    49     return 4
    5045 
    5146def initial_state(x):
     
    5752
    5853# Set final time and yield time for simulation
    59 finaltime = 10.0
    60 yieldstep = 1.0
     54finaltime = 500.0
     55yieldstep = 10.0
    6156
    6257# Length of channel (m)
Note: See TracChangeset for help on using the changeset viewer.