Skip to content

Commit

Permalink
Merge pull request #114 from ketch/python3
Browse files Browse the repository at this point in the history
Support Python 3
  • Loading branch information
ketch authored Dec 20, 2016
2 parents 48a46d3 + c374fae commit 483c8c6
Show file tree
Hide file tree
Showing 14 changed files with 118 additions and 94 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
language: python
python:
- 2.7
- 3.5
before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq gfortran liblapack-pic
Expand Down
8 changes: 5 additions & 3 deletions rptest/1d/test_rp1_meqn2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@

from __future__ import absolute_import
from __future__ import print_function
import test_rp1_meqn2
import numpy

Expand All @@ -13,6 +15,6 @@
qr = [1.,0.]
wave,s,amdq,apdq = test_rp1_meqn2.rp1_driver.call_rp1(2,ql,qr)

print "s = ",s
print "wave = "
print wave
print("s = ",s)
print("wave = ")
print(wave)
146 changes: 74 additions & 72 deletions src/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,91 +4,93 @@
Wave propagation Riemann solvers implemented in Python and Fortran.
"""

from __future__ import absolute_import
from __future__ import print_function
rp_solver_list_1d = []
rp_solver_list_2d = []
rp_solver_list_3d = []

# Import 1d Riemann solvers
from advection_1D_py import advection_1D
from vc_advection_1D_py import vc_advection_1D
from acoustics_1D_py import acoustics_1D
from burgers_1D_py import burgers_1D
from shallow_1D_py import shallow_roe_1D, shallow_hll_1D, shallow_exact_1D
from euler_1D_py import euler_roe_1D, euler_hll_1D, euler_hllc_1D, euler_exact_1D
from nonlinear_elasticity_1D_py import nonlinear_elasticity_1D
import static
from . import advection_1D_py
from . import vc_advection_1D_py
from . import acoustics_1D_py
from . import burgers_1D_py
from . import shallow_1D_py
from . import euler_1D_py
from . import nonlinear_elasticity_1D_py
from . import static

import acoustics_1D_constants
import acoustics_variable_1D_constants
import advection_1D_constants
import burgers_1D_constants
import euler_with_efix_1D_constants
import nonlinear_elasticity_fwave_1D_constants
import reactive_euler_with_efix_1D_constants
import shallow_roe_with_efix_1D_constants
import traffic_1D_constants
import traffic_vc_1D_constants
import acoustics_2D_constants
import acoustics_mapped_2D_constants
import advection_2D_constants
import burgers_2D_constants
import euler_mapgrid_2D_constants
import euler_5wave_2D_constants
import euler_4wave_2D_constants
import kpp_2D_constants
import psystem_2D_constants
import shallow_roe_with_efix_2D_constants
import shallow_sphere_2D_constants
import vc_acoustics_2D_constants
import vc_advection_2D_constants
import vc_elasticity_2D_constants
import vc_acoustics_3D_constants
import euler_3D_constants
import burgers_3D_constants
import vc_advection_3D_constants
from . import acoustics_1D_constants
from . import acoustics_variable_1D_constants
from . import advection_1D_constants
from . import burgers_1D_constants
from . import euler_with_efix_1D_constants
from . import nonlinear_elasticity_fwave_1D_constants
from . import reactive_euler_with_efix_1D_constants
from . import shallow_roe_with_efix_1D_constants
from . import traffic_1D_constants
from . import traffic_vc_1D_constants
from . import acoustics_2D_constants
from . import acoustics_mapped_2D_constants
from . import advection_2D_constants
from . import burgers_2D_constants
from . import euler_mapgrid_2D_constants
from . import euler_5wave_2D_constants
from . import euler_4wave_2D_constants
from . import kpp_2D_constants
from . import psystem_2D_constants
from . import shallow_roe_with_efix_2D_constants
from . import shallow_sphere_2D_constants
from . import vc_acoustics_2D_constants
from . import vc_advection_2D_constants
from . import vc_elasticity_2D_constants
from . import vc_acoustics_3D_constants
from . import euler_3D_constants
from . import burgers_3D_constants
from . import vc_advection_3D_constants


try:
import acoustics_1D
import acoustics_variable_1D
import acoustics_1D_ptwise
import advection_1D
import advection_1D_ptwise
import burgers_1D
import euler_with_efix_1D
import nonlinear_elasticity_fwave_1D
import reactive_euler_with_efix_1D
import shallow_roe_with_efix_1D
import traffic_1D
import traffic_vc_1D
import acoustics_2D
import acoustics_mapped_2D
import acoustics_2D_ptwise
import advection_2D
import burgers_2D
import euler_mapgrid_2D
import euler_5wave_2D
import euler_4wave_2D
import kpp_2D
import psystem_2D
import shallow_roe_with_efix_2D
import shallow_sphere_2D
import vc_acoustics_2D
import vc_advection_2D
import vc_elasticity_2D
import vc_acoustics_3D
import euler_3D
import burgers_3D
import vc_advection_3D
from . import acoustics_1D
from . import acoustics_variable_1D
from . import acoustics_1D_ptwise
from . import advection_1D
from . import advection_1D_ptwise
from . import burgers_1D
from . import euler_with_efix_1D
from . import nonlinear_elasticity_fwave_1D
from . import reactive_euler_with_efix_1D
from . import shallow_roe_with_efix_1D
from . import traffic_1D
from . import traffic_vc_1D
from . import acoustics_2D
from . import acoustics_mapped_2D
from . import acoustics_2D_ptwise
from . import advection_2D
from . import burgers_2D
from . import euler_mapgrid_2D
from . import euler_5wave_2D
from . import euler_4wave_2D
from . import kpp_2D
from . import psystem_2D
from . import shallow_roe_with_efix_2D
from . import shallow_sphere_2D
from . import vc_acoustics_2D
from . import vc_advection_2D
from . import vc_elasticity_2D
from . import vc_acoustics_3D
from . import euler_3D
from . import burgers_3D
from . import vc_advection_3D
except ImportError as e:
import traceback
print "********************************************************************"
print 'Warning: Some Riemannn solvers were not able to be imported.'
print ' Did you run "pip install" in your clawpack directory?'
print("********************************************************************")
print('Warning: Some Riemannn solvers were not able to be imported.')
print(' Did you run "pip install" in your clawpack directory?')
traceback.print_exc()
print "********************************************************************"
print("********************************************************************")

import os
if os.path.exists('./layered_shallow_water_1D.so'):
import layered_shallow_water_1D
import layered_shallow_water_1D_constants
from . import layered_shallow_water_1D_constants
4 changes: 3 additions & 1 deletion src/acoustics_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
from six.moves import range
num_eqn = 2
num_waves = 2

Expand Down Expand Up @@ -78,7 +80,7 @@ def acoustics_1D(q_l,q_r,aux_l,aux_r,problem_data):
s[1,:] = problem_data['cc']

# Compute the left going and right going fluctuations
for m in xrange(num_eqn):
for m in range(num_eqn):
amdq[m,:] = s[0,:] * wave[m,0,:]
apdq[m,:] = s[1,:] * wave[m,1,:]

Expand Down
1 change: 1 addition & 0 deletions src/advection_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
# ============================================================================

# Riemann solver constants
from __future__ import absolute_import
num_eqn = 1
num_waves = 1

Expand Down
1 change: 1 addition & 0 deletions src/burgers_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
num_eqn = 1
num_waves = 1

Expand Down
14 changes: 8 additions & 6 deletions src/euler_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
import numpy as np
from six.moves import range

num_eqn = 3

Expand Down Expand Up @@ -101,8 +103,8 @@ def euler_roe_1D(q_l,q_r,aux_l,aux_r,problem_data):
else:
# Godunov update
s_index = np.zeros((2,num_rp))
for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
s_index[0,:] = s[mw,:]
amdq[m,:] += np.min(s_index,axis=0) * wave[m,mw,:]
apdq[m,:] += np.max(s_index,axis=0) * wave[m,mw,:]
Expand Down Expand Up @@ -175,8 +177,8 @@ def euler_hll_1D(q_l,q_r,aux_l,aux_r,problem_data):

# Compute variations
s_index = np.zeros((2,num_rp))
for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
s_index[0,:] = s[mw,:]
amdq[m,:] += np.min(s_index,axis=0) * wave[m,mw,:]
apdq[m,:] += np.max(s_index,axis=0) * wave[m,mw,:]
Expand Down Expand Up @@ -281,8 +283,8 @@ def euler_hllc_1D(q_l,q_r,aux_l,aux_r,problem_data):

# Compute variations
s_index = np.zeros((2,num_rp))
for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
s_index[0,:] = s[mw,:]
amdq[m,:] += np.min(s_index,axis=0) * wave[m,mw,:]
apdq[m,:] += np.max(s_index,axis=0) * wave[m,mw,:]
Expand Down
4 changes: 3 additions & 1 deletion src/nonlinear_elasticity_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
import numpy as np
from six.moves import range

def nonlinear_elasticity_1D(q_l,q_r,aux_l,aux_r,problem_data):
r"""
Expand Down Expand Up @@ -81,7 +83,7 @@ def nonlinear_elasticity_1D(q_l,q_r,aux_l,aux_r,problem_data):
s[1,:] = cr

# Compute the left going and right going fluctuations
for m in xrange(num_eqn):
for m in range(num_eqn):
amdq[m,:] = fwave[m,0,:]
apdq[m,:] = fwave[m,1,:]

Expand Down
1 change: 1 addition & 0 deletions src/riemann_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"""


from __future__ import absolute_import
import numpy as np
import jinja2
import json
Expand Down
11 changes: 7 additions & 4 deletions src/riemann_tools.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from __future__ import absolute_import
from __future__ import print_function
from matplotlib import animation
from clawpack.visclaw.JSAnimation import IPython_display
from IPython.display import display
Expand All @@ -6,6 +8,7 @@
import numpy as np
import matplotlib.pyplot as plt
import matplotlib
from six.moves import range


sympy.init_printing(use_latex='mathjax')
Expand Down Expand Up @@ -55,19 +58,19 @@ def riemann_solution(solver,q_l,q_r,aux_l=None,aux_r=None,t=0.2,problem_data=Non
num_states = num_waves + 1

if verbose:
print 'States in Riemann solution:'
print('States in Riemann solution:')
states_sym = sympy.Matrix(states)
display([states_sym[:,k] for k in range(num_states)])

print 'Waves (jumps between states):'
print('Waves (jumps between states):')
wave_sym = sympy.Matrix(wave[:,:,0])
display([wave_sym[:,k] for k in range(num_waves)])

print "Speeds: "
print("Speeds: ")
s_sym = sympy.Matrix(s)
display(s_sym.T)

print "amdq, apdq: "
print("amdq, apdq: ")
amdq_sym = sympy.Matrix(amdq).T
apdq_sym = sympy.Matrix(apdq).T
display([amdq_sym, apdq_sym])
Expand Down
1 change: 1 addition & 0 deletions src/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#
# f2py -c ../../rp1_layered_shallow_water.f90 -m layered_shallow_water_1D

from __future__ import absolute_import
one_d_ptwise_riemann = ['acoustics',
'advection']

Expand Down
14 changes: 8 additions & 6 deletions src/shallow_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@
# http://www.opensource.org/licenses/
# ============================================================================

from __future__ import absolute_import
import numpy as np
from six.moves import range

num_eqn = 2
num_waves = 2
Expand Down Expand Up @@ -97,8 +99,8 @@ def shallow_roe_1D(q_l,q_r,aux_l,aux_r,problem_data):
raise NotImplementedError("Entropy fix has not been implemented.")
else:
s_index = np.zeros((2,num_rp))
for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
s_index[0,:] = s[mw,:]
amdq[m,:] += np.min(s_index,axis=0) * wave[m,mw,:]
apdq[m,:] += np.max(s_index,axis=0) * wave[m,mw,:]
Expand Down Expand Up @@ -165,8 +167,8 @@ def shallow_hll_1D(q_l,q_r,aux_l,aux_r,problem_data):

# Compute variations
s_index = np.zeros((2,num_rp))
for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
s_index[0,:] = s[mw,:]
amdq[m,:] += np.min(s_index,axis=0) * wave[m,mw,:]
apdq[m,:] += np.max(s_index,axis=0) * wave[m,mw,:]
Expand Down Expand Up @@ -222,8 +224,8 @@ def shallow_fwave_1d(q_l, q_r, aux_l, aux_r, problem_data):
fwave[0,1,:] = beta2
fwave[1,1,:] = beta2 * s[1,:]

for m in xrange(num_eqn):
for mw in xrange(num_waves):
for m in range(num_eqn):
for mw in range(num_waves):
amdq[m,:] += (s[mw,:] < 0.0) * fwave[m,mw,:]
apdq[m,:] += (s[mw,:] >= 0.0) * fwave[m,mw,:]

Expand Down
1 change: 1 addition & 0 deletions src/vc_advection_1D_py.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
Note that this is the color equation, not the conservative advection equation.
"""

from __future__ import absolute_import
import numpy as np

# Riemann solver constants
Expand Down
Loading

0 comments on commit 483c8c6

Please sign in to comment.