Skip to content

Commit

Permalink
Clean up some of the code and add more doc-strings
Browse files Browse the repository at this point in the history
  • Loading branch information
mandli committed Jul 23, 2014
1 parent 9bdfba6 commit 5648d5a
Showing 1 changed file with 45 additions and 13 deletions.
58 changes: 45 additions & 13 deletions examples/euler_2d/quadrants.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
#!/usr/bin/env python
# encoding: utf-8
"""
2D Euler Riemann problem
================================
Euler 2D Quadrants example
==========================
Solve the Euler equations of compressible fluid dynamics:
Simple example solving the Euler equations of compressible fluid dynamics:
.. math::
\rho_t + (\rho u)_x + (\rho v)_y & = 0 \\
Expand All @@ -15,9 +15,15 @@
Here :math:`\rho` is the density, (u,v) is the velocity, and E is the total energy.
The initial condition is one of the 2D Riemann problems from the paper of
Liska and Wendroff.
"""

def setplot(plotdata):
r"""Plotting settings
Should plot two figures both of density.
"""

from clawpack.visclaw import colormaps

Expand Down Expand Up @@ -62,7 +68,24 @@ def setplot(plotdata):


def setup(use_petsc=False):

r"""Setup for Euler 2D quadrants example
Simple example solving the Euler equations of compressible fluid dynamics:
.. math::
\rho_t + (\rho u)_x + (\rho v)_y & = 0 \\
(\rho u)_t + (\rho u^2 + p)_x + (\rho uv)_y & = 0 \\
(\rho v)_t + (\rho uv)_x + (\rho v^2 + p)_y & = 0 \\
E_t + (u (E + p) )_x + (v (E + p))_y & = 0.
Here :math:`\rho` is the density, (u,v) is the velocity, and E is the total energy.
The initial condition is one of the 2D Riemann problems from the paper of
Liska and Wendroff.
Currently the only setup option is the *use_petsc* argument.
"""

if use_petsc:
import clawpack.petclaw as pyclaw
else:
Expand All @@ -80,15 +103,24 @@ def setup(use_petsc=False):
solver.transverse_waves = 2

# Set initial data
xx,yy = domain.grid.p_centers
l = xx<0.8; r = xx>=0.8; b = yy<0.8; t = yy>=0.8
solution.q[0,...] = 1.5*r*t + 0.532258064516129*l*t + 0.137992831541219*l*b + 0.532258064516129*r*b
u = 0.*r*t + 1.206045378311055*l*t + 1.206045378311055*l*b + 0.*r*b
v = 0.*r*t + 0.*l*t + 1.206045378311055*l*b + 1.206045378311055*r*b
p = 1.5*r*t + 0.3*l*t + 0.029032258064516*l*b + 0.3*r*b
solution.q[1,...] = solution.q[0,...] * u
solution.q[2,...] = solution.q[0,...] * v
solution.q[3,...] = 0.5*solution.q[0,...]*(u**2+v**2) + p/(gamma-1.)
xx, yy = domain.grid.p_centers
l = xx < 0.8
r = xx >= 0.8
b = yy < 0.8
t = yy >= 0.8
solution.q[0,...] = 1.5 * r * t + 0.532258064516129 * l * t \
+ 0.137992831541219 * l * b \
+ 0.532258064516129 * r * b
u = 0.0 * r * t + 1.206045378311055 * l * t \
+ 1.206045378311055 * l * b \
+ 0.0 * r * b
v = 0.0 * r * t + 0.0 * l * t \
+ 1.206045378311055 * l * b \
+ 1.206045378311055 * r * b
p = 1.5 * r * t + 0.3 * l * t + 0.029032258064516 * l * b + 0.3 * r * b
solution.q[1,...] = solution.q[0, ...] * u
solution.q[2,...] = solution.q[0, ...] * v
solution.q[3,...] = 0.5 * solution.q[0,...]*(u**2 + v**2) + p / (gamma - 1.0)

claw = pyclaw.Controller()
claw.tfinal = 0.8
Expand Down

0 comments on commit 5648d5a

Please sign in to comment.