test = False problem = 'RM_theta' ## Define a mesh Npts = 64 imesh = """ xdom = (0.0, 2.8*pi , int(Npts*1.4), periodic=False) ydom = (0.0, 2*pi*FF, Npts, periodic=True) zdom = (0.0, 2*pi*FF, 1, periodic=True) """.replace('Npts', str(Npts)).replace('pi', str(numpy.pi)).replace( 'FF', str(float(Npts - 1) / Npts)) # Initialize a simulation object on a mesh ss = pyrandaSim(problem, imesh) ss.addPackage(pyrandaTimestep(ss)) ss.addPackage(pyrandaBC(ss)) # Define the equations of motion eom = """ # Primary Equations of motion here ddt(:rhoYh:) = -ddx(:rhoYh:*:u: - :Jx:) - ddy(:rhoYh:*:v: - :Jy:) - ddz(:rhoYh:*:w: - :Jz:) ddt(:rhoYl:) = -ddx(:rhoYl:*:u: + :Jx:) - ddy(:rhoYl:*:v: + :Jy:) - ddz(:rhoYl:*:w: + :Jz:) ddt(:rhou:) = -ddx(:rhou:*:u: - :tauxx:) - ddy(:rhou:*:v: - :tauxy:) - ddz(:rhou:*:w: - :tauxz:) ddt(:rhov:) = -ddx(:rhov:*:u: - :tauxy:) - ddy(:rhov:*:v: - :tauyy:) - ddz(:rhov:*:w: - :tauyz:) ddt(:rhow:) = -ddx(:rhow:*:u: - :tauxz:) - ddy(:rhow:*:v: - :tauyz:) - ddz(:rhow:*:w: - :tauzz:) ddt(:Et:) = -ddx( (:Et: - :tauxx:)*:u: - :tauxy:*:v: - :tauxz:*:w: ) - ddy( (:Et: - :tauyy:)*:v: -:tauxy:*:u: - :tauyz:*:w:) - ddz( (:Et: - :tauzz:)*:w: - :tauxz:*:u: - :tauyz:*:v: ) # Conservative filter of the EoM :rhoYh: = fbar( :rhoYh: ) :rhoYl: = fbar( :rhoYl: ) :rhou: = fbar( :rhou: )
def getShu(Npts, viz=False): L = 10.0 Lp = L * (Npts - 1.0) / Npts imesh = "xdom = (-Lp/2.0, Lp/2.0, Npts)" imesh = imesh.replace('Lp', str(Lp)) imesh = imesh.replace('Npts', str(Npts)) # Initialize a simulation object on a mesh ss = pyrandaSim('sod', imesh) ss.addPackage(pyrandaBC(ss)) ss.addPackage(pyrandaTimestep(ss)) # Define the equations of motion from equation_library import euler_1d eom = euler_1d eom += """ # Apply constant BCs bc.const(['u'],['xn'],0.0) bc.const(['u'],['x1'],2.629369) bc.const(['rho'],['x1'],3.857143) bc.const(['p'],['x1'],10.33333) bc.const(['Et'],['x1'],39.166585) :rhou: = :rho:*:u: :cs: = sqrt( :p: / :rho: * :gamma: ) :dt: = dt.courant(:u:,0.0,0.0,:cs:) :dt: = numpy.minimum(:dt:,0.2 * dt.diff(:beta:,:rho:)) """ # Add the EOM to the solver ss.EOM(eom) # Initial conditions Shu-Osher test problem ic = """ :gamma: = 1.4 eps = 2.0e-1 :tmp: = (meshx+4.0)/%s :dum: = tanh(:tmp:) :dum: = (:dum:+1.0)/2.0 :rho: = 3.857143 + :dum:*(1.0+eps*sin(5.0*meshx) - 3.857143) :u: = 2.629369*(1.0-:dum:) :p: = 10.33333 + :dum:*(1.0-10.33333) :rhou: = :rho: * :u: :Et: = :p:/(:gamma: -1.0) + .5*:rho:*:u:*:u: """ # Set the initial conditions ss.setIC(ic % ss.dx) # Write a time loop time = 0.0 # Approx a max dt and stopping time CFL = 0.5 dt = ss.variables['dt'].data * CFL * .01 # Mesh for viz on master x = ss.mesh.coords[0].data xx = ss.PyMPI.zbar(x) # Start time loop cnt = 1 viz_freq = 50 pvar = 'rho' #viz = True tt = 1.8 while tt > time: # Update the EOM and get next dt time = ss.rk4(time, dt) dt = min(dt * 1.1, ss.variables['dt'].data * CFL) dt = min(dt, (tt - time)) # Print some output ss.iprint("%s -- %s" % (cnt, time)) cnt += 1 v = ss.PyMPI.zbar(ss.variables[pvar].data) if viz: if (ss.PyMPI.master and (cnt % viz_freq == 0)) and True: #raw_input('Poop') plt.figure(1) plt.clf() plt.plot(xx[:, 0], v[:, 0], 'k.-') plt.title(pvar) plt.pause(.001) return [ss, xx[:, 0], v[:, 0]]
## Define a mesh L = 1.0 Re = 100.0 mesh_options = {} mesh_options['coordsys'] = 0 mesh_options['periodic'] = numpy.array([False, False, True]) mesh_options['x1'] = [0.0, 0.0, 0.0] mesh_options['xn'] = [L, L, L] mesh_options['nn'] = [Npts, Npts, 1] # Initialize a simulation object on a mesh pysim = pyrandaSim('lidDrivenCavity', mesh_options) pysim.addPackage(pyrandaBC(pysim)) pysim.addPackage(pyrandaTimestep(pysim)) eom = """ # Primary Equations of motion here :us: = :u: + :dt: * ( - :u: * ddx( :u: ) - :v: * ddy( :u: ) + lap(:u:)*:nu: ) :vs: = :v: + :dt: * ( - :u: * ddx( :v: ) - :v: * ddy( :v: ) + lap(:v:)*:nu: ) Delta(:ps:) = 1.0/:dt: * ( ddx(:us:) + ddy(:vs:) ) :u: = :us: - :dt: * ddx(:ps:) :v: = :vs: - :dt: * ddy(:ps:) :u: = fbar(:u:) :v: = fbar(:v:) # Boundary conditions bc.const(['u','v'],['x1','xn','y1'],0.0) bc.const(['u'],['yn'],1.0) bc.const(['v'],['yn'],0.0) :umag: = sqrt( :u:*:u: + :v:*:v: )
icDict['expRad'] = detRad icDict['p0'] = p0 icDict['T0'] = T0 icDict['Pamp'] = Pamp ## SETUP A PYRANDA SIMULATION OBJECT: From initial conditions OR restart if not restart: # Initialize a simulation object on a mesh ss = pyrandaSim(problem,mesh_options) # Add packages to simulation object, EOM, and ICs ss.addPackage( pyrandaBC(ss) ) # BC package allows for "bc.*" functions ss.addPackage( pyrandaTimestep(ss) ) # Timestep package allows for "dt.*" functions ss.EOM(eom, eomDict ) # Add equations of motion ss.setIC(ic,icDict) # Set the initial conditions dt = ss.variables['dt'].data * CFL*.01 # Setup the initial 'dt' over_pressure = [] ptime = [] else: # Initialize a simulation form a restart file [ ss , local_vars] = pyrandaRestart( problem ) # Restore simulation object locals().update( local_vars ) # Restore local vars saved time = ss.time # Resume time dt = ss.deltat # Last deltat import pdb