Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mapped grids #80

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
c14b419
mapped grids
harpolea Feb 25, 2019
a6fb2b1
mapped grids
harpolea Feb 25, 2019
9c3270c
mapped grids works with all cartesian metric
harpolea Feb 26, 2019
3eeb16b
area, line element and rotation matrices can now be passed in
harpolea Feb 26, 2019
c63321b
added problems to mapped directory
harpolea Feb 26, 2019
cbbd037
fixed bug so acoustic_pulse now works for rectilinear grids
harpolea Feb 26, 2019
82b5903
use sympy to calculate area elements
harpolea Feb 26, 2019
414b266
use sympy to calculate area elements
harpolea Feb 26, 2019
944389f
mapped grids work with sympy calculating stuff (at least for rectilin…
harpolea Feb 26, 2019
3583445
made a NullVariables class, added some documentation for the mapped g…
harpolea Feb 27, 2019
b0f7332
added tests for curvilinear grids
harpolea Feb 27, 2019
e356ddb
rotation matrix is less broken
harpolea Feb 28, 2019
6baf2df
finally got it working on non-square grids
harpolea Feb 28, 2019
28e00ae
fixed rotation matrix so works on non-rectilinear grids as well
harpolea Feb 28, 2019
8054e6a
fixed tests
harpolea Feb 28, 2019
632c3b7
switch to computing line and area elements numerically to deal with n…
harpolea Mar 1, 2019
6e05c17
reflect-odd boundary conditions for mapped grids must be rotated
harpolea Mar 1, 2019
7fb135c
moved some function calls outside of loops to speed up problem initia…
harpolea Mar 6, 2019
178ce58
updated tests
harpolea Mar 7, 2019
f73fa35
updated docs
harpolea Mar 7, 2019
bf42bf4
updated mapped grids problems
harpolea Mar 7, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 6 additions & 3 deletions compressible/interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ def riemann_cgf(idir, ng,
lambdastar_r = ustar + cstar_r

if (pstar > p_r):
# the wave if a shock -- find the shock speed
# the wave is a shock -- find the shock speed
sigma = (lambda_r + lambdastar_r) / 2.0

if (sigma > 0.0):
Expand Down Expand Up @@ -713,7 +713,7 @@ def riemann_prim(idir, ng,
lambdastar_r = ustar + cstar_r

if (pstar > p_r):
# the wave if a shock -- find the shock speed
# the wave is a shock -- find the shock speed
sigma = (lambda_r + lambdastar_r) / 2.0

if (sigma > 0.0):
Expand Down Expand Up @@ -801,7 +801,7 @@ def riemann_prim(idir, ng,
return q_int


@njit(cache=True)
# @njit(cache=True)
def riemann_hllc(idir, ng,
idens, ixmom, iymom, iener, irhoX, nspec,
lower_solid, upper_solid,
Expand Down Expand Up @@ -857,6 +857,9 @@ def riemann_hllc(idir, ng,
# primitive variable states
rho_l = U_l[i, j, idens]

if (rho_l <= 0):
print(f"-ve density {rho_l} at i,j = ({i},{j})")

# un = normal velocity; ut = transverse velocity
if (idir == 1):
un_l = U_l[i, j, ixmom] / rho_l
Expand Down
11 changes: 6 additions & 5 deletions compressible/problems/acoustic_pulse.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,19 @@ def init_data(myd, rp):
ymin = rp.get_param("mesh.ymin")
ymax = rp.get_param("mesh.ymax")

xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
xctr = 0.5 * (xmin + xmax)
yctr = 0.5 * (ymin + ymax)

dist = np.sqrt((myd.grid.x2d - xctr)**2 +
(myd.grid.y2d - yctr)**2)

dens[:, :] = rho0
idx = dist <= 0.5
dens[idx] = rho0 + drho0*np.exp(-16*dist[idx]**2) * np.cos(np.pi*dist[idx])**6
dens[idx] = rho0 + drho0 * \
np.exp(-16 * dist[idx]**2) * np.cos(np.pi * dist[idx])**6

p = (dens/rho0)**gamma
ener[:, :] = p/(gamma - 1)
p = (dens / rho0)**gamma
ener[:, :] = p / (gamma - 1)


def finalize():
Expand Down
15 changes: 8 additions & 7 deletions compressible/problems/advect.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,22 +38,23 @@ def init_data(my_data, rp):
ymin = rp.get_param("mesh.ymin")
ymax = rp.get_param("mesh.ymax")

xctr = 0.5*(xmin + xmax)
yctr = 0.5*(ymin + ymax)
xctr = 0.5 * (xmin + xmax)
yctr = 0.5 * (ymin + ymax)

# this is identical to the advection/smooth problem
dens[:, :] = 1.0 + np.exp(-60.0*((my_data.grid.x2d-xctr)**2 +
(my_data.grid.y2d-yctr)**2))
dens[:, :] = 1.0 + np.exp(-60.0 * ((my_data.grid.x2d - xctr)**2 +
(my_data.grid.y2d - yctr)**2))

# velocity is diagonal
u = 1.0
v = 1.0
xmom[:, :] = dens[:, :]*u
ymom[:, :] = dens[:, :]*v
xmom[:, :] = dens[:, :] * u
ymom[:, :] = dens[:, :] * v

# pressure is constant
p = 1.0
ener[:, :] = p/(gamma - 1.0) + 0.5*(xmom[:, :]**2 + ymom[:, :]**2)/dens[:, :]
ener[:, :] = p / (gamma - 1.0) + 0.5 * (xmom[:, :]
** 2 + ymom[:, :]**2) / dens[:, :]


def finalize():
Expand Down
2 changes: 1 addition & 1 deletion compressible/problems/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def init_data(my_data, rp):

# make sure that we are passed a valid patch object
if not isinstance(my_data, patch.CellCenterData2d):
print("ERROR: patch invalid in sedov.py")
print("ERROR: patch invalid in test.py")
print(my_data.__class__)
sys.exit()

Expand Down
61 changes: 31 additions & 30 deletions compressible/simulation.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,18 +10,18 @@
import compressible.derives as derives
import compressible.unsplit_fluxes as flx
import mesh.boundary as bnd
from simulation_null import NullSimulation, grid_setup, bc_setup
from simulation_null import NullSimulation, NullVariables, grid_setup, bc_setup
import util.plot_tools as plot_tools
import particles.particles as particles


class Variables(object):
class Variables(NullVariables):
"""
a container class for easy access to the different compressible
variable by an integer key
"""
def __init__(self, myd):
self.nvar = len(myd.names)

def initialize(self, myd):

# conserved variables -- we set these when we initialize for
# they match the CellCenterData2d object
Expand Down Expand Up @@ -58,19 +58,19 @@ def cons_to_prim(U, gamma, ivars, myg):
q = myg.scratch_array(nvar=ivars.nq)

q[:, :, ivars.irho] = U[:, :, ivars.idens]
q[:, :, ivars.iu] = U[:, :, ivars.ixmom]/U[:, :, ivars.idens]
q[:, :, ivars.iv] = U[:, :, ivars.iymom]/U[:, :, ivars.idens]
q[:, :, ivars.iu] = U[:, :, ivars.ixmom] / U[:, :, ivars.idens]
q[:, :, ivars.iv] = U[:, :, ivars.iymom] / U[:, :, ivars.idens]

e = (U[:, :, ivars.iener] -
0.5*q[:, :, ivars.irho]*(q[:, :, ivars.iu]**2 +
q[:, :, ivars.iv]**2))/q[:, :, ivars.irho]
0.5 * q[:, :, ivars.irho] * (q[:, :, ivars.iu]**2 +
q[:, :, ivars.iv]**2)) / q[:, :, ivars.irho]

q[:, :, ivars.ip] = eos.pres(gamma, q[:, :, ivars.irho], e)

if ivars.naux > 0:
for nq, nu in zip(range(ivars.ix, ivars.ix+ivars.naux),
range(ivars.irhox, ivars.irhox+ivars.naux)):
q[:, :, nq] = U[:, :, nu]/q[:, :, ivars.irho]
for nq, nu in zip(range(ivars.ix, ivars.ix + ivars.naux),
range(ivars.irhox, ivars.irhox + ivars.naux)):
q[:, :, nq] = U[:, :, nu] / q[:, :, ivars.irho]

return q

Expand All @@ -81,18 +81,18 @@ def prim_to_cons(q, gamma, ivars, myg):
U = myg.scratch_array(nvar=ivars.nvar)

U[:, :, ivars.idens] = q[:, :, ivars.irho]
U[:, :, ivars.ixmom] = q[:, :, ivars.iu]*U[:, :, ivars.idens]
U[:, :, ivars.iymom] = q[:, :, ivars.iv]*U[:, :, ivars.idens]
U[:, :, ivars.ixmom] = q[:, :, ivars.iu] * U[:, :, ivars.idens]
U[:, :, ivars.iymom] = q[:, :, ivars.iv] * U[:, :, ivars.idens]

rhoe = eos.rhoe(gamma, q[:, :, ivars.ip])

U[:, :, ivars.iener] = rhoe + 0.5*q[:, :, ivars.irho]*(q[:, :, ivars.iu]**2 +
q[:, :, ivars.iv]**2)
U[:, :, ivars.iener] = rhoe + 0.5 * q[:, :, ivars.irho] * (q[:, :, ivars.iu]**2 +
q[:, :, ivars.iv]**2)

if ivars.naux > 0:
for nq, nu in zip(range(ivars.ix, ivars.ix+ivars.naux),
range(ivars.irhox, ivars.irhox+ivars.naux)):
U[:, :, nu] = q[:, :, nq]*q[:, :, ivars.irho]
for nq, nu in zip(range(ivars.ix, ivars.ix + ivars.naux),
range(ivars.irhox, ivars.irhox + ivars.naux)):
U[:, :, nu] = q[:, :, nq] * q[:, :, ivars.irho]

return U

Expand All @@ -113,7 +113,8 @@ def initialize(self, extra_vars=None, ng=4):

# define solver specific boundary condition routines
bnd.define_bc("hse", BC.user, is_solid=False)
bnd.define_bc("ramp", BC.user, is_solid=False) # for double mach reflection problem
# for double mach reflection problem
bnd.define_bc("ramp", BC.user, is_solid=False)

bc, bc_xodd, bc_yodd = bc_setup(self.rp)

Expand Down Expand Up @@ -182,10 +183,10 @@ def method_compute_timestep(self):
u, v, cs = self.cc_data.get_var(["velocity", "soundspeed"])

# the timestep is min(dx/(|u| + cs), dy/(|v| + cs))
xtmp = self.cc_data.grid.dx/(abs(u) + cs)
ytmp = self.cc_data.grid.dy/(abs(v) + cs)
xtmp = self.cc_data.grid.dx / (abs(u) + cs)
ytmp = self.cc_data.grid.dy / (abs(v) + cs)

self.dt = cfl*float(min(xtmp.min(), ytmp.min()))
self.dt = cfl * float(min(xtmp.min(), ytmp.min()))

def evolve(self):
"""
Expand All @@ -211,19 +212,19 @@ def evolve(self):
old_ymom = ymom.copy()

# conservative update
dtdx = self.dt/myg.dx
dtdy = self.dt/myg.dy
dtdx = self.dt / myg.dx
dtdy = self.dt / myg.dy

for n in range(self.ivars.nvar):
var = self.cc_data.get_var_by_index(n)

var.v()[:, :] += \
dtdx*(Flux_x.v(n=n) - Flux_x.ip(1, n=n)) + \
dtdy*(Flux_y.v(n=n) - Flux_y.jp(1, n=n))
dtdx * (Flux_x.v(n=n) - Flux_x.ip(1, n=n)) + \
dtdy * (Flux_y.v(n=n) - Flux_y.jp(1, n=n))

# gravitational source terms
ymom[:, :] += 0.5*self.dt*(dens[:, :] + old_dens[:, :])*grav
ener[:, :] += 0.5*self.dt*(ymom[:, :] + old_ymom[:, :])*grav
ymom[:, :] += 0.5 * self.dt * (dens[:, :] + old_dens[:, :]) * grav
ener[:, :] += 0.5 * self.dt * (ymom[:, :] + old_ymom[:, :]) * grav

if self.particles is not None:
self.particles.update_particles(self.dt)
Expand Down Expand Up @@ -257,7 +258,7 @@ def dovis(self):
u = q[:, :, ivars.iu]
v = q[:, :, ivars.iv]
p = q[:, :, ivars.ip]
e = eos.rhoe(gamma, p)/rho
e = eos.rhoe(gamma, p) / rho

magvel = np.sqrt(u**2 + v**2)

Expand Down Expand Up @@ -297,7 +298,7 @@ def dovis(self):

# plot particles
ax.scatter(particle_positions[:, 0],
particle_positions[:, 1], s=5, c=colors, alpha=0.8, cmap="Greys")
particle_positions[:, 1], s=5, c=colors, alpha=0.8, cmap="Greys")
ax.set_xlim([myg.xmin, myg.xmax])
ax.set_ylim([myg.ymin, myg.ymax])

Expand Down
8 changes: 8 additions & 0 deletions compressible_mapped/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
"""A method-of-lines compressible hydrodynamics solver. Piecewise
constant reconstruction is done in space and a Runge-Kutta time
integration is used to advance the solutiion.

"""
__all__ = ["simulation"]

from .simulation import Simulation
24 changes: 24 additions & 0 deletions compressible_mapped/_defaults
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[driver]
cfl = 0.8


[eos]
gamma = 1.4 ; pres = rho ener (gamma - 1)


[compressible]
use_flattening = 1 ; apply flattening at shocks (1)

z0 = 0.75 ; flattening z0 parameter
z1 = 0.85 ; flattening z1 parameter
delta = 0.33 ; flattening delta parameter

cvisc = 0.1 ; artifical viscosity coefficient

limiter = 2 ; limiter (0 = none, 1 = 2nd order, 2 = 4th order)

temporal_method = RK4 ; integration method (see mesh/integration.py)

grav = 0.0 ; gravitational acceleration (in y-direction)

riemann = HLLC ; HLLC or CGF
Loading