Changeset 9158


Ignore:
Timestamp:
Jun 15, 2014, 5:22:06 PM (10 years ago)
Author:
steve
Message:

Combined plot_result scripts

Location:
trunk/anuga_core/validation_tests/analytical_exact/paraboloid_basin
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/anuga_core/validation_tests/analytical_exact/paraboloid_basin/numerical_paraboloid_basin.py

    r9155 r9158  
    1919from time import localtime, strftime, gmtime
    2020from anuga.geometry.polygon import inside_polygon, is_inside_triangle
    21 
     21from anuga import myid, finalize, distribute
    2222
    2323#-------------------------------------------------------------------------------
     
    3232
    3333
     34args = anuga.get_args()
     35alg = args.alg
     36verbose = args.v
     37
    3438#-------------------------------------------------------------------------------
    3539# Domain
     
    4145origin = (-4000.0, -4000.0)
    4246
    43 points, elements, boundary = anuga.rectangular_cross(m, n, lenx, leny, origin)
    44 domain = anuga.Domain(points, elements, boundary)
    4547
    4648
    47 #-------------------------------------------------------------------------------
    48 # Provide file name for storing output
    49 #-------------------------------------------------------------------------------
    50 domain.store = True #False
    51 domain.format = 'sww'
    52 domain.set_name(output_file)               
    53 domain.set_datadir(output_dir)
     49#===============================================================================
     50# Create Sequential Domain
     51#===============================================================================
     52if myid == 0:
     53    points, elements, boundary = anuga.rectangular_cross(m, n, lenx, leny, origin)
     54    domain = anuga.Domain(points, elements, boundary)
    5455
    5556
    56 #-------------------------------------------------------------------------------
    57 # Order of scheme
    58 # Good compromise between
    59 # limiting and CFL
    60 # CUT THIS FOR AUTOMATED TESTS
    61 #-------------------------------------------------------------------------------
    62 #domain.set_default_order(2)
    63 #domain.set_timestepping_method(2)
    64 #domain.set_beta(1.5)
    65 ##domain.set_CFL(0.6)
    66 #domain.smooth = True
     57    domain.set_name(output_file)               
     58    domain.set_datadir(output_dir)
     59   
     60    domain.set_flow_algorithm(alg)
    6761
     62   
     63    #-------------------------------------------------------------------------------
     64    # Initial conditions
     65    #-------------------------------------------------------------------------------
     66    t = 0.0
     67    D0 = 1000.
     68    L = 2500.
     69    R0 = 2000.
     70   
     71    A = (L**4 - R0**4)/(L**4 + R0**4)
     72    omega = 2./L*sqrt(2.*g*D0)
     73    T = pi/omega
     74   
     75    #------------------
     76    # Set bed elevation
     77    def bed_elevation(x,y):
     78        n = x.shape[0]
     79        z = 0*x
     80        for i in range(n):
     81            r = sqrt(x[i]*x[i] + y[i]*y[i])
     82            z[i] = -D0*(1.-r*r/L/L)
     83        return z
     84    domain.set_quantity('elevation', bed_elevation)
     85   
     86    #----------------------------
     87    # Set the initial water level
     88    def stage_init(x,y):
     89        z = bed_elevation(x,y)
     90        n = x.shape[0]
     91        w = 0*x
     92        for i in range(n):
     93            r = sqrt(x[i]*x[i] + y[i]*y[i])
     94            w[i] = D0*((sqrt(1-A*A))/(1.-A*cos(omega*t))
     95                    -1.-r*r/L/L*((1.-A*A)/((1.-A*cos(omega*t))**2)-1.))
     96        if w[i] < z[i]:
     97            w[i] = z[i]
     98        return w
     99    domain.set_quantity('stage', stage_init)
    68100
    69 #-------------------------------------------------------------------------------
    70 # Decide which quantities are to be stored at each timestep
    71 #-------------------------------------------------------------------------------
    72 #domain.quantities_to_be_stored = ['stage', 'xmomentum', 'ymomentum']
     101else:
     102   
     103    domain = None
     104 
     105#============================================================================
     106# Create Parallel Domain
     107#============================================================================
     108domain = distribute(domain)
    73109
    74 
    75 #-------------------------------------------------------------------------------
    76 # Reduction operation for get_vertex_values
    77 from anuga.utilities.numerical_tools import mean
    78 domain.reduction = mean #domain.reduction = min  #Looks better near steep slopes
    79 
    80 
    81 #-------------------------------------------------------------------------------
    82 # Initial condition
    83 #-------------------------------------------------------------------------------
    84 t = 0.0
    85 D0 = 1000.
    86 L = 2500.
    87 R0 = 2000.
    88 
    89 A = (L**4 - R0**4)/(L**4 + R0**4)
    90 omega = 2./L*sqrt(2.*g*D0)
    91 T = pi/omega
    92 
    93 #------------------
    94 # Set bed elevation
    95 def bed_elevation(x,y):
    96     n = x.shape[0]
    97     z = 0*x
    98     for i in range(n):
    99         r = sqrt(x[i]*x[i] + y[i]*y[i])
    100         z[i] = -D0*(1.-r*r/L/L)
    101     return z
    102 domain.set_quantity('elevation', bed_elevation)
    103 
    104 #----------------------------
    105 # Set the initial water level
    106 def stage_init(x,y):
    107     z = bed_elevation(x,y)
    108     n = x.shape[0]
    109     w = 0*x
    110     for i in range(n):
    111         r = sqrt(x[i]*x[i] + y[i]*y[i])
    112         w[i] = D0*((sqrt(1-A*A))/(1.-A*cos(omega*t))
    113                 -1.-r*r/L/L*((1.-A*A)/((1.-A*cos(omega*t))**2)-1.))
    114     if w[i] < z[i]:
    115         w[i] = z[i]
    116     return w
    117 domain.set_quantity('stage', stage_init)
    118110
    119111#---------
     
    124116domain.set_boundary({'left': D, 'right': D, 'top': D, 'bottom': D})
    125117
    126 #---------------------------------------------
    127 # Find triangle that contains the point Point
    128 # and print to file
    129 #---------------------------------------------
    130 Point = (0.0, 0.0)
    131 for n in range(len(domain.triangles)):
    132     tri = domain.get_vertex_coordinates(n)
    133     if is_inside_triangle(Point,tri):
    134         #print 'Point is within triangle with vertices '+'%s'%tri
    135         n_point = n
    136         break
    137 print 'n_point = ',n_point
    138 #bla
    139    
    140 #t = domain.triangles[n_point]
    141 #print 't = ', t
    142 #tri = domain.get_vertex_coordinates(n)
    143 
    144 filename=domain.get_name()
    145 file = open(filename,'w')
    146 
    147 #----------
    148 # Evolution
    149 import time
    150 t0 = time.time()
    151 
    152 time_array = []
    153 stage_array = []
    154 Stage     = domain.quantities['stage']
    155 Xmomentum = domain.quantities['xmomentum']
    156 Ymomentum = domain.quantities['ymomentum']
    157 
    158 #interactive_visualisation = True
    159 #===============================================================================
    160 ##if interactive_visualisation:
    161 ##    from anuga.visualiser import RealtimeVisualiser
    162 ##    vis = RealtimeVisualiser(domain)
    163 ##    vis.render_quantity_height("stage", zScale =1000, dynamic=True)
    164 ##    vis.colour_height_quantity('stage', (1.0, 0.5, 0.5))
    165 ##    vis.start()
    166 #===============================================================================
    167 
    168118
    169119#------------------------------------------------------------------------------
    170120# Produce a documentation of parameters
    171121#------------------------------------------------------------------------------
    172 parameter_file=open('parameters.tex', 'w')
    173 parameter_file.write('\\begin{verbatim}\n')
    174 from pprint import pprint
    175 pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
    176 parameter_file.write('\\end{verbatim}\n')
    177 parameter_file.close()
     122if myid == 0:
     123    parameter_file=open('parameters.tex', 'w')
     124    parameter_file.write('\\begin{verbatim}\n')
     125    from pprint import pprint
     126    pprint(domain.get_algorithm_parameters(),parameter_file,indent=4)
     127    parameter_file.write('\\end{verbatim}\n')
     128    parameter_file.close()
    178129
     130import time
     131t0 = time.time()
    179132for t in domain.evolve(yieldstep = 1.0, finaltime = 200.0):
    180     domain.write_time()
     133    if myid == 0 and verbose : domain.write_time()
    181134
    182     #tri_array = asarray(tri)
    183     #t_array = asarray([[0,1,2]])
    184     #interp = Interpolation(tri_array,t_array,[points])
     135if myid==0 and verbose: print 'That took %s secs' % str(time.time()- t0)
    185136
    186     stage     = Stage.get_values(location='centroids',indices=[n_point])
    187     xmomentum = Xmomentum.get_values(location='centroids',indices=[n_point])
    188     ymomentum = Ymomentum.get_values(location='centroids',indices=[n_point])
    189     #print '%10.6f   %10.6f  %10.6f   %10.6f\n'%(t,stage,xmomentum,ymomentum)
    190     file.write( '%10.6f   %10.6f  %10.6f   %10.6f\n'%(t,stage,xmomentum,ymomentum) )
     137domain.sww_merge(delete_old=True)
    191138
    192     #time_array.append(t)
    193     #stage_array.append(stage)
    194 
    195     #if interactive_visualisation:
    196     #    vis.update()
    197 """
    198 file.close()
    199 print 'That took %.2f seconds' %(time.time()-t0)
    200 from pylab import *
    201 #ion()
    202 hold(False)
    203 plot(time_array, stage_array, 'r.-')
    204 #title('Gauge %s' %name)
    205 xlabel('time (s)')
    206 ylabel('stage (m)')
    207 #legend(('Observed', 'Modelled'), shadow=True, loc='upper left')
    208 #savefig(name, dpi = 300)
    209 
    210 #raw_input('Next')
    211 show()
    212 """
    213 
    214 #if interactive_visualisation:
    215 #    vis.evolveFinished()
     139finalize()
  • trunk/anuga_core/validation_tests/analytical_exact/paraboloid_basin/produce_results.py

    r9117 r9158  
    22# import modules
    33#--------------------------------
    4 from anuga.validation_utilities.fabricate import *
    5 from anuga.validation_utilities import run_validation_script
    6 from anuga.validation_utilities import typeset_report
     4import anuga
     5from anuga.validation_utilities import produce_report
     6
     7args = anuga.get_args()
     8
     9produce_report('numerical_paraboloid_basin.py', args=args)
    710
    811
    9 # Setup the python scripts which produce the output for this
    10 # validation test
    11 def build():
    12     run_validation_script('numerical_paraboloid_basin.py')
    13     run_validation_script('plot_results_cross_section.py')
    14     run_validation_script('plot_results_origin_wrt_time.py')   
    15     typeset_report()
    16 
    17 def clean():
    18     autoclean()
    19 
    20 main()
Note: See TracChangeset for help on using the changeset viewer.