Beispiel #1
0
def gridAdv(npts, cfl=1.0):

    # Define the domain/mesh
    xf = 1.0 * (npts - 1) / npts
    domain = "xdom = (0.0 , xf , npts , periodic=True)"
    domain = domain.replace('xf', str(xf))
    domain = domain.replace('npts', str(npts))

    # Initialize a simulation object on a mesh
    pysim = pyrandaSim('advection', domain, silent=True)

    # Define the equations of motion
    pysim.EOM(" ddt(:phi:)  =  -:c: * ddx(:phi:) ")

    # Initialize variables
    ic = """
:phi: = 1.0 + 0.1 * exp( -(abs(meshx-.5)/.1 )**2 )
:phi0: = :phi:
:c:   = 1.0
"""
    pysim.setIC(ic)

    # Integrate in time
    dt = 1.0 / (npts - 1) / 1.0 * cfl
    time = 0.0
    tfinal = 1.0
    while time < tfinal:
        time = pysim.rk4(time, dt)
        dt = min(dt, (tfinal - time))

    x = pysim.mesh.coords[0].data
    phi = pysim.variables['phi'].data
    phi0 = pysim.variables['phi0'].data

    error = numpy.sum(numpy.abs(phi - phi0))
    return error
Beispiel #2
0
mesh_options = {}
mesh_options['coordsys'] = 0
mesh_options['periodic'] = numpy.array([twoD, twoD, True])
mesh_options['dim'] = 3
mesh_options['x1'] = [0.0, 0.0, 0.0]
mesh_options['xn'] = [Lp, Lp, Lp]
#mesh_options['x1'] = [ -Lp/2.0 , -Lp/2.0  ,  0.0 ]
#mesh_options['xn'] = [ Lp/2.0   , Lp/2.0   ,  Lp ]

mesh_options['nn'] = [Npts, 1, 1]
if twoD:
    mesh_options['nn'] = [Npts, Npts, 1]

# Initialize a simulation object on a mesh
ss = pyrandaSim('swirl', mesh_options)
ss.addPackage(pyrandaIBM(ss))

# Define the equations of motion
eom = """
# Primary Equations of motion here
ddt(:rho:)  =  -ddx(:rho:*:u: - :tau:) - ddy(:rho:*:v: - :tau:) 
ddt(:rhoA:)  =  -ddx(:rhoA:*:uA: - :tauA:) -ddy(:rhoA:*:vA: - :tauA:) 
ddt(:phi:)  =  - :gx: * :u1: - :gy: * :v1:  - .01*sign(:phi:)*(:mgp:-1.0)
# Conservative filter of the EoM
:rho:       =  fbar( :rho:  )
:rhoA:      =  fbar( :rhoA:  )
#:phi:       =  fbar( :phi: )
# Update the primatives and enforce the EOS
:dr:        = ddx(:rho:)
:drA:       = ddx(:rhoA:)
Beispiel #3
0
except:
    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:  )
Beispiel #4
0
problem = 'sod'

Lp = L * (Npts - 1.0) / Npts
mesh_options = {}
mesh_options['coordsys'] = 0
mesh_options['periodic'] = numpy.array([False, False, True])
mesh_options['dim'] = 3
mesh_options['x1'] = [0.0, 0.0, 0.0]
mesh_options['xn'] = [Lp, Lp, Lp]
mesh_options['nn'] = [Npts, 1, 1]
if dim == 2:
    mesh_options['nn'] = [Npts, Npts, 1]

# Initialize a simulation object on a mesh
ss = pyrandaSim('advection', mesh_options)
ss.addPackage(pyrandaBC(ss))

# Define the equations of motion
eom = """
# Primary Equations of motion here
ddt(:rho:)  =  -ddx(:rho:*:u:)                  - ddy(:rho:*:v:)
ddt(:rhou:) =  -ddx(:rhou:*:u: + :p: - :tau:)   - ddy(:rhou:*:v:)
ddt(:rhov:) =  -ddx(:rhov:*:u:)                 - ddy(:rhov:*:v: + :p: - :tau:)
ddt(:Et:)   =  -ddx( (:Et: + :p: - :tau:)*:u: ) - ddy( (:Et: + :p: - :tau:)*:v: )
# Conservative filter of the EoM
:rho:       =  fbar( :rho:  )
:rhou:      =  fbar( :rhou: )
:rhov:      =  fbar( :rhov: )
:Et:        =  fbar( :Et:   )
# Update the primatives and enforce the EOS
Beispiel #5
0
except:
    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)
Beispiel #6
0
except:
    test = False

## Define a mesh
L = numpy.pi * 2.0

# Define the domain/mesh
imesh = """
Lp = %s
Npts = %d
xdom = (0.0, Lp,  Npts, periodic=False)
ydom = (0.0, Lp,  Npts, periodic=False)
""" % (L, Npts)

# Initialize a simulation object on a mesh
ss = pyrandaSim('Poisson', imesh)

# Define the equations of motion
eom = """
:wx: = meshx * ( 2.0 * pi - meshx )
:wy: = meshy * ( 2.0 * pi - meshy )
:phi: =  cos( meshx ) * :wy: + cos( meshy ) * :wx:
Delta(:ff:) = :phi:
:gg: = lap(:ff:)
"""
ss.EOM(eom)

# Perform the solve at update
ss.updateVars()

if not test:
Beispiel #7
0
except:
    test = False

## Define a mesh
L = numpy.pi * 2.0
Lp = L * (Npts - 1.0) / Npts

# Define the domain/mesh
imesh = """
Lp = %s
Npts = %d
xdom = (0.0, Lp,  Npts, periodic=True)
""" % (Lp, Npts)

# Initialize a simulation object on a mesh
ss = pyrandaSim('advection', imesh)

# Define the equations of motion
ss.EOM(" ddt(:phi:)  =  -:c: * ddx(:phi:) ")

# Initialize variables
ic = """
r   = sqrt( (meshx-pi)**2  )
:phi: = 1.0 + 0.1 * exp( -(r/(pi/4.0))**2 )
:phi2: = 1.0*:phi:
:c:   = 1.0
"""
ss.setIC(ic)

#ss.variables["u"].data += 1.0
Beispiel #8
0
ERROR = 0.0
##############################
########  DERIVATIVES ########
##############################

# Define the domain/mesh
Nx = 32
L = numpy.pi * 2.0 * (Nx - 1) / Nx
domain = """
xdom = (0.0 , L , Nx ,periodic=True)
ydom = (0.0 , L , Nx ,periodic=True)
zdom = (0.0 , L , Nx ,periodic=True)
""".replace('L', str(L)).replace('Nx', str(Nx))

# Periodic function in X-Y-Z
pysim = pyrandaSim('advection', domain)

expr = "sum( abs( ddx( sin(meshx) ) - cos(meshx) ))"
errorX = pysim.eval(expr)
errorY = pysim.eval(expr.replace('x', 'y'))
errorZ = pysim.eval(expr.replace('x', 'z'))
ERROR += errorX + errorY + errorZ

print('Error X = %s' % errorX)
print('Error Y = %s' % errorY)
print('Error Z = %s' % errorZ)

# Non-periodic case
domain = """
xdom = (0.0 , 1.0 , Nx )
ydom = (0.0 , 1.0 , Nx )
Beispiel #9
0
    z = 0.0
    return x,y,z

mesh_options = {}
mesh_options['coordsys'] = 3
mesh_options['function'] = zoomMesh
mesh_options['periodic'] = numpy.array([False, False, True])
mesh_options['gridPeriodic'] = numpy.array([False, 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'] = [ Npts, Npts ,  1  ]


# Initialize a simulation object on a mesh
ss = pyrandaSim(problem,mesh_options)
ss.addPackage( pyrandaBC(ss) )
ss.addPackage( pyrandaIBM(ss) )
ss.addPackage( pyrandaTimestep(ss) )


rho0 = 1.0
p0   = 1.0
gamma = 1.4
mach = 2.0
s0 = numpy.sqrt( p0 / rho0 * gamma )
u0 = s0 * mach
e0 = p0/(gamma-1.0) + rho0*.5*u0*u0


# Define the equations of motion
Beispiel #10
0
from matplotlib import cm

from pyranda import pyrandaSim, pyrandaBC
from pyranda.pyranda import pyrandaRestart

## 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('sod', imesh)
ss.addPackage(pyrandaBC(ss))

# Define the equations of motion
eom = """
# Primary Equations of motion here
ddt(:rho:)  =  -ddx(:rho:*:u:)
ddt(:rhou:) =  -ddx(:rhou:*:u: + :p: - :tau:)
ddt(:Et:)   =  -ddx( (:Et: + :p: - :tau:)*:u: )
# Conservative filter of the EoM
:rho:       =  fbar( :rho:  )
:rhou:      =  fbar( :rhou: )
:Et:        =  fbar( :Et:   )
# Update the primatives and enforce the EOS
:u:         =  :rhou: / :rho:
:p:         =  ( :Et: - .5*:rho:*(:u:*:u:) ) * ( :gamma: - 1.0 )
Beispiel #11
0
# Produced at the Lawrence Livermore National Laboratory.
#
# LLNL-CODE-749864
# This file is part of pyranda
# For details about use and distribution, please read: pyranda/LICENSE
#
# Written by: Britton J. Olson, [email protected]
################################################################################

from pyranda import pyrandaSim

# Define the domain/mesh
domain = "xdom = (0.0 , 1.0 , 100 )"

# Initialize a simulation object on a mesh
pysim = pyrandaSim('advection', domain)

# Define the equations of motion
pysim.EOM("ddt(:phi:)  =  - ddx(:phi:)")

# Initialize variables
pysim.setIC(":phi: = 1.0 + 0.1 * exp( -(abs(meshx-.5)/.1 )**2 )")

# Integrate in time
dt = .001
time = 0.0
while time < .1:
    time = pysim.rk4(time, dt)

# Plot solution
pysim.plot.plot('phi')
Beispiel #12
0
    test = False

## Define a mesh
L = numpy.pi * 2.0
Lp = L * (Npts - 1.0) / Npts

mesh_options = {}
mesh_options['coordsys'] = 0
mesh_options['periodic'] = numpy.array([False, True, True])
mesh_options['dim'] = 1
mesh_options['x1'] = [0.0, 0.0, 0.0]
mesh_options['xn'] = [Lp, Lp, Lp]
mesh_options['nn'] = [Npts, 1, 1]

# Initialize a simulation object on a mesh
ss = pyrandaSim('heat_equation', mesh_options)

ss.addPackage(pyrandaBC(ss))

# Define the equations of motion
eom = """
# Heat equation
ddt(:phi:)  =  :c: * lap(:phi:)
# Boundary condition
bc.const(['phi'],['x1'],2.0)
bc.const(['phi'],['xn'],1.0)
"""
ss.EOM(eom)

# Initialize variables
ic = """
Beispiel #13
0
# LLNL-CODE-749864
# This file is part of pyranda
# For details about use and distribution, please read: pyranda/LICENSE
#
# Written by: Britton J. Olson, [email protected]
################################################################################
from pyranda import pyrandaSim, pyrandaBC
from numpy import pi

# Domain is specified with a "mesh dictionary"
mesh_options = {}
mesh_options['x1'] = [0.0, 0.0, 0.0]
mesh_options['xn'] = [2.0 * pi, 2.0 * pi, 1.0]
mesh_options['nn'] = [64, 64, 1]

ss = pyrandaSim('sod', mesh_options)

ss.addPackage(pyrandaBC(ss))

# Define the equations of motion
eom = """
# Primary Equations of motion here
ddt(:rho:)  =  -ddx(:rho:*:u:)                  - ddy(:rho:*:v:)
ddt(:rhou:) =  -ddx(:rhou:*:u: + :p: - :tau:)   - ddy(:rhou:*:v:)
ddt(:rhov:) =  -ddx(:rhov:*:u:)                 - ddy(:rhov:*:v: + :p: - :tau:)
ddt(:Et:)   =  -ddx( (:Et: + :p: - :tau:)*:u: ) - ddy( (:Et: + :p: - :tau:)*:v: )
# Conservative filter of the EoM
:rho:       =  fbar( :rho:  )
:rhou:      =  fbar( :rhou: )
:rhov:      =  fbar( :rhov: )
:Et:        =  fbar( :Et:   )
Beispiel #14
0
################################################################################
# Copyright (c) 2018, Lawrence Livemore National Security, LLC.
# Produced at the Lawrence Livermore National Laboratory.
#
# LLNL-CODE-749864
# This file is part of pyranda
# For details about use and distribution, please read: pyranda/LICENSE
#
# Written by: Britton J. Olson, [email protected]
################################################################################

from pyranda import pyrandaSim, pyrandaBC

ss = pyrandaSim('sod', 'xdom=(0.0,6.0,200)')

ss.addPackage(pyrandaBC(ss))

# Define the equations of motion
eom = """
# Primary Equations of motion here
ddt(:rho:)  =  -ddx(:rho:*:u:)
ddt(:rhou:) =  -ddx(:rhou:*:u: + :p: - :tau:)
ddt(:Et:)   =  -ddx( (:Et: + :p: - :tau:)*:u: )
# Conservative filter of the EoM
:rho:       =  fbar( :rho:  )
:rhou:      =  fbar( :rhou: )
:Et:        =  fbar( :Et:   )
# Update the primatives and enforce the EOS
:u:         =  :rhou: / :rho:
:p:         =  ( :Et: - .5*:rho:*(:u:*:u:) ) * ( :gamma: - 1.0 )
# Artificial bulk viscosity (old school way)
Beispiel #15
0
# Try to get args
try:
    Npts = int(sys.argv[1])
except:
    Npts = 10

try:
    test = bool(int(sys.argv[2]))
except:
    test = False

# Define the domain/mesh
domain = "xdom = (0.0 , 1.0 , 1 )"

# Initialize a simulation object on a mesh
pysim = pyrandaSim('integralTests', domain)

# Define the equations of motion
eom = """
ddt(:a:)  =  :a:
ddt(:b:)  =  cos( 6.0*simtime )
"""
pysim.EOM(eom)

# Initialize variables
a0 = 1.0
b0 = 0.0
ic = """
:a: = %s
:b: = %s
""" % (a0, b0)
Beispiel #16
0
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]]
Beispiel #17
0
            y1 += yw
            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:)
Beispiel #18
0
    y = (j - 1) * dx - .5 * numpy.sin(i / float(Npts) * 2.0 * numpy.pi)
    z = 0.0
    return x, y, z


imesh = {}

imesh['x1'] = [0.0, 0.0, 0.0]
imesh['xn'] = [Lp, Lp, 1]
imesh['nn'] = [Npts, Npts, 1]
imesh['periodic'] = numpy.array([True, True, True])
imesh['coordsys'] = 3
imesh['dim'] = 3
imesh['function'] = myMesh

ss = pyrandaSim('curved_advection', imesh)

eom = """
ddt(:phi:) = -div( :phi: * :u: , :phi:*:v: )
"""

ss.EOM(eom)

ic = """
r   = sqrt( (meshx-pi)**2 + (meshy-pi)**2  )
:u: = 1.0
:v: = 0.0
:phi: = 1.0 + 0.1 * exp( -(r/(pi/4.0))**2 )
"""

# Set the initial conditions