if y1 > py_max: y1 = 0 ## Define a mesh L = numpy.pi * 2.0 Npts = 200 Lp = L * (Npts - 1.0) / Npts imesh = """ xdom = (0.0, Lp, Npts) """.replace('Lp', str(Lp)).replace('Npts', str(Npts)) # Initialize a simulation object on a mesh ss = pyrandaSim('sodMM', imesh) ss.addPackage(pyrandaBC(ss)) ss.addPackage(pyrandaIBM(ss)) deltaPhi = 2.0 * L / float(Npts) # Define the equations of motion eom = """ # Primary Equations of motion here ddt(:rhoA:) = -ddx(:rhoA:*:uA:) ddt(:rhoB:) = -ddx(:rhoB:*:uB:) ddt(:rhouA:) = -ddx(:rhouA:*:uA: + :pA: - :tauA:) - :FA: ddt(:rhouB:) = -ddx(:rhouB:*:uB: + :pB: - :tauB:) - :FB: ddt(:EtA:) = -ddx( (:EtA: + :pA: - :tauA:)*:uA: ) - :FA:*:uA: ddt(:EtB:) = -ddx( (:EtB: + :pB: - :tauB:)*:uB: ) - :FB:*:uB: ddt(:phi:) = -:gx:*:uphi: - .1 * sign(:phi:)*(:mgp:-1.0) * deltaPhi / (deltat+1.0e-10) #ddt(:uphi:) = -ddx( :uphi:*:uphi: - :tauphi:) - :Fphi:/(:rhoA: + :rhoB:) # Conservative filter of the EoM
testName = None ## 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)
icDict['Runiv'] = Runiv 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
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]]
return x, y, z mesh_options = {} mesh_options['coordsys'] = 3 mesh_options['function'] = cylMesh mesh_options['periodic'] = numpy.array([True, False, True]) mesh_options['gridPeriodic'] = numpy.array([True, False, False]) mesh_options['dim'] = 3 mesh_options['x1'] = [-2 * Lp, -2 * Lp, 0.0] mesh_options['xn'] = [2 * Lp, 2 * Lp, Lp] mesh_options['nn'] = [NX, NY, 1] # Initialize a simulation object on a mesh ss = pyrandaSim(problem, mesh_options) BCpy = pyrandaBC(ss) # setup for Farfield BC BCpy.BCdata["farfield-properties-yn"] = { 'rho0': rho0, 'p0': p0, 'u0': u0, 'v0': v0, 'w0': w0, 'gamma': gamma, 'rho': 'rho', 'u': 'u', 'v': 'v', 'w': 'w', 'p': 'p' } ss.addPackage(BCpy)