PYTHON   8

setrun.py

Guest on 16th May 2021 08:42:23 PM

  1. """
  2. Module to set up run time parameters for Clawpack.
  3.  
  4. The values set in the function setrun are then written out to data files
  5. that will be read in by the Fortran code.
  6.    
  7. """
  8.  
  9. import os
  10. from pyclaw import data
  11.  
  12.  
  13. #------------------------------
  14. def setrun(claw_pkg='classic'):
  15. #------------------------------
  16.    
  17.     """
  18.    Define the parameters used for running Clawpack.
  19.  
  20.    INPUT:
  21.        claw_pkg expected to be "classic" for this setrun.
  22.  
  23.    OUTPUT:
  24.        rundata - object of class ClawRunData
  25.    
  26.    """
  27.    
  28.     assert claw_pkg.lower() == 'classic',  "Expected claw_pkg = 'classic'"
  29.  
  30.     ndim = 2
  31.     rundata = data.ClawRunData(claw_pkg, ndim)
  32.  
  33.     #------------------------------------------------------------------
  34.     # Problem-specific parameters to be written to setprob.data:
  35.     #------------------------------------------------------------------
  36.  
  37.     # MUST BE ADDED BY USER IF DESIRED !!
  38.     #probdata = rundata.new_UserData(name='probdata',fname='setprob.data')
  39.     # For example:
  40.     #probdata.add_param('u',     1.0,  'advection velocity')
  41.    
  42.     #------------------------------------------------------------------
  43.     # Standard Clawpack parameters to be written to claw.data:
  44.     #------------------------------------------------------------------
  45.  
  46.     clawdata = rundata.clawdata  # initialized when rundata instantiated
  47.  
  48.     # ---------------
  49.     # Spatial domain:
  50.     # ---------------
  51.  
  52.     # Number of space dimensions:
  53.     clawdata.ndim = ndim
  54.    
  55.     # Lower and upper edge of computational domain:
  56.     clawdata.xlower = 0.0
  57.     clawdata.xupper = 1.0
  58.    
  59.     clawdata.ylower = 0.0
  60.     clawdata.yupper = 1.0
  61.        
  62.  
  63.     # Number of grid cells:
  64.     clawdata.mx = 50
  65.    
  66.     clawdata.my = 50
  67.        
  68.  
  69.     # ---------------
  70.     # Size of system:
  71.     # ---------------
  72.  
  73.     # Number of equations in the system:
  74.     clawdata.meqn = 1
  75.  
  76.     # Number of auxiliary variables in the aux array (initialized in setaux)
  77.     clawdata.maux = 0
  78.    
  79.     # Index of aux array corresponding to capacity function, if there is one:
  80.     clawdata.mcapa = 0
  81.    
  82.    
  83.    
  84.     # -------------
  85.     # Initial time:
  86.     # -------------
  87.  
  88.     clawdata.t0 = 0.0
  89.    
  90.    
  91.     # -------------
  92.     # Output times:
  93.     #--------------
  94.  
  95.     # Specify at what times the results should be written to fort.q files.
  96.     # Note that the time integration stops after the final output time.
  97.     # The solution at initial time t0 is always written in addition.
  98.  
  99.     clawdata.outstyle = 1
  100.  
  101.     if clawdata.outstyle==1:
  102.         # Output nout frames at equally spaced times up to tfinal:
  103.         clawdata.nout = 10
  104.         clawdata.tfinal = 1.0
  105.  
  106.     elif clawdata.outstyle == 2:
  107.         # Specify a list of output times.  
  108.         clawdata.tout =  [0.5, 1.0]   # used if outstyle == 2
  109.         clawdata.nout = len(clawdata.tout)
  110.  
  111.     elif clawdata.outstyle == 3:
  112.         # Output every iout timesteps with a total of ntot time steps:
  113.         iout = 1
  114.         ntot = 5
  115.         clawdata.iout = [iout, ntot]
  116.    
  117.  
  118.  
  119.     # ---------------------------------------------------
  120.     # Verbosity of messages to screen during integration:  
  121.     # ---------------------------------------------------
  122.  
  123.     # The current t, dt, and cfl will be printed every time step
  124.     # at AMR levels <= verbosity.  Set verbosity = 0 for no printing.
  125.     #   (E.g. verbosity == 2 means print only on levels 1 and 2.)
  126.     clawdata.verbosity = 1
  127.    
  128.    
  129.  
  130.     # --------------
  131.     # Time stepping:
  132.     # --------------
  133.  
  134.     # if dt_variable==1: variable time steps used based on cfl_desired,
  135.     # if dt_variable==0: fixed time steps dt = dt_initial will always be used.
  136.     clawdata.dt_variable = 1
  137.    
  138.     # Initial time step for variable dt.  
  139.     # If dt_variable==0 then dt=dt_initial for all steps:
  140.     clawdata.dt_initial = 0.1
  141.    
  142.     # Max time step to be allowed if variable dt used:
  143.     clawdata.dt_max = 1e+99
  144.    
  145.     # Desired Courant number if variable dt used, and max to allow without
  146.     # retaking step with a smaller dt:
  147.     clawdata.cfl_desired = 0.9
  148.     clawdata.cfl_max = 1.0
  149.    
  150.     # Maximum number of time steps to allow between output times:
  151.     clawdata.max_steps = 500
  152.  
  153.    
  154.    
  155.  
  156.     # ------------------
  157.     # Method to be used:
  158.     # ------------------
  159.  
  160.     # Order of accuracy:  1 => Godunov,  2 => Lax-Wendroff plus limiters
  161.     clawdata.order = 2
  162.    
  163.     # Transverse order for 2d or 3d (not used in 1d):
  164.     clawdata.order_trans = 2
  165.    
  166.     # Number of waves in the Riemann solution:
  167.     clawdata.mwaves = 1
  168.    
  169.     # List of limiters to use for each wave family:  
  170.     # Required:  len(mthlim) == mwaves
  171.     clawdata.mthlim = [3]
  172.    
  173.     # Source terms splitting:
  174.     #   src_split == 0  => no source term (src routine never called)
  175.     #   src_split == 1  => Godunov (1st order) splitting used,
  176.     #   src_split == 2  => Strang (2nd order) splitting used,  not recommended.
  177.     clawdata.src_split = 0
  178.    
  179.    
  180.     # --------------------
  181.     # Boundary conditions:
  182.     # --------------------
  183.  
  184.     # Number of ghost cells (usually 2)
  185.     clawdata.mbc = 2
  186.    
  187.     # Choice of BCs at xlower and xupper:
  188.     #   0 => user specified (must modify bcN.f to use this option)
  189.     #   1 => extrapolation (non-reflecting outflow)
  190.     #   2 => periodic (must specify this at both boundaries)
  191.     #   3 => solid wall for systems where q(2) is normal velocity
  192.    
  193.     clawdata.mthbc_xlower = 2
  194.     clawdata.mthbc_xupper = 2
  195.    
  196.     clawdata.mthbc_ylower = 2
  197.     clawdata.mthbc_yupper = 2
  198.    
  199.     return rundata
  200.     # end of function setrun
  201.     # ----------------------
  202.  
  203.  
  204. if __name__ == '__main__':
  205.     # Set up run-time parameters and write all data files.
  206.     import sys
  207.     if len(sys.argv) == 2:
  208.       rundata = setrun(sys.argv[1])
  209.     else:
  210.       rundata = setrun()
  211.  
  212.     rundata.write()

Raw Paste


Login or Register to edit or fork this paste. It's free.