Skip to content

Commit

Permalink
Merge pull request #720 from ketch/compile_all_examples
Browse files Browse the repository at this point in the history
Fix some issues with examples and meson.
  • Loading branch information
rjleveque authored Mar 19, 2024
2 parents c2b0478 + df99b7c commit 4fa92af
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 18 deletions.
6 changes: 3 additions & 3 deletions examples/euler_1d/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ all:
make sharpclaw1.so
make euler_tfluct.so

sharpclaw1.so: $(ONE_D_SHARPCLAW_SOURCES)
${F2PY} -m sharpclaw1 -c $(ONE_D_SHARPCLAW_SOURCES)
euler_sharpclaw1.so: $(ONE_D_SHARPCLAW_SOURCES)
${F2PY} -m euler_sharpclaw1 -c $(ONE_D_SHARPCLAW_SOURCES)

euler_tfluct.so: euler_tfluct.f90
euler_tfluct1.so: euler_tfluct.f90
f2py -m $(basename $(notdir $@)) -c $^

clean:
Expand Down
4 changes: 2 additions & 2 deletions examples/euler_1d/shocksine.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ def setup(use_petsc=False,iplot=False,htmlplot=False,outdir='./_output',solver_t
solver.fmod = euler_sharpclaw1
solver.tfluct_solver = tfluct_solver # Use total fluctuation solver for efficiency
if solver.tfluct_solver:
from pyclaw.sharpclaw import euler_tfluct
solver.tfluct = euler_tfluct
from pyclaw.sharpclaw import euler_tfluct1
solver.tfluct = euler_tfluct1
solver.lim_type = 2 # WENO reconstruction
solver.char_decomp = 2 # characteristic-wise reconstruction
else:
Expand Down
4 changes: 2 additions & 2 deletions examples/euler_1d/woodward_colella_blast.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ def setup(use_petsc=False,outdir='./_output',solver_type='sharpclaw',kernel_lang
solver.cfl_desired = 0.6
solver.tfluct_solver = tfluct_solver
if solver.tfluct_solver:
from clawpack.pyclaw.examples.euler_1d import euler_tfluct
solver.tfluct = euler_tfluct
from clawpack.pyclaw.sharpclaw import euler_tfluct1
solver.tfluct = euler_tfluct1
solver.lim_type = 1
solver.char_decomp = 2
from clawpack.pyclaw.sharpclaw import euler_sharpclaw1
Expand Down
12 changes: 6 additions & 6 deletions examples/shallow_sphere/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ CLASSIC = ../../src/pyclaw/classic
TWO_D_CLASSIC_SOURCES = step2qcor.f90 qcor.f90 $(CLASSIC)/step2ds.f90 $(CLASSIC)/flux2.f90 $(CLASSIC)/limiter.f90 $(CLASSIC)/philim.f90

all:
make classic2.so
make problem.so
make classic2_sw_sphere.so
make sw_sphere_problem.so

classic2.so: $(TWO_D_CLASSIC_SOURCES) $(RP_SOURCE)
${F2PY} -m classic2 -c $(TWO_D_CLASSIC_SOURCES) $(RP_SOURCE)
classic2_sw_sphere.so: $(TWO_D_CLASSIC_SOURCES) $(RP_SOURCE)
${F2PY} -m classic2_sw_sphere -c $(TWO_D_CLASSIC_SOURCES) $(RP_SOURCE)

problem.so: mapc2p.f90 setaux.f90 qinit.f90 src2.f90
$(F2PY) -m problem -c $^
sw_sphere_problem.so: mapc2p.f90 setaux.f90 qinit.f90 src2.f90
$(F2PY) -m sw_sphere_problem -c $^

clean:
rm -f *.o *.so *.pyc *.log
Expand Down
10 changes: 5 additions & 5 deletions examples/shallow_sphere/Rossby_wave.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ def fortran_src_wrapper(solver,state,dt):
t = state.t

# Call src2 function
state.q = problem.src2(mx,my,num_ghost,xlower,ylower,dx,dy,q,aux,t,dt,Rsphere)
state.q = sw_sphere_problem.src2(mx,my,num_ghost,xlower,ylower,dx,dy,q,aux,t,dt,Rsphere)


def mapc2p_sphere_nonvectorized(X,Y):
Expand Down Expand Up @@ -312,7 +312,7 @@ def auxbc_lower_y(state,dim,t,qbc,auxbc,num_ghost):

# Impose BC
auxtemp = auxbc.copy()
auxtemp = problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtemp,Rsphere)
auxtemp = sw_sphere_problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtemp,Rsphere)
auxbc[:,:,:num_ghost] = auxtemp[:,:,:num_ghost]

def auxbc_upper_y(state,dim,t,qbc,auxbc,num_ghost):
Expand All @@ -330,7 +330,7 @@ def auxbc_upper_y(state,dim,t,qbc,auxbc,num_ghost):

# Impose BC
auxtemp = auxbc.copy()
auxtemp = problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtemp,Rsphere)
auxtemp = sw_sphere_problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtemp,Rsphere)
auxbc[:,:,-num_ghost:] = auxtemp[:,:,-num_ghost:]


Expand Down Expand Up @@ -441,7 +441,7 @@ def setup(use_petsc=False,solver_type='classic',outdir='./_output', disable_outp

num_ghost = 2
auxtmp = np.ndarray(shape=(num_aux,mx+2*num_ghost,my+2*num_ghost), dtype=float, order='F')
auxtmp = problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtmp,Rsphere)
auxtmp = sw_sphere_problem.setaux(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,auxtmp,Rsphere)
state.aux[:,:,:] = auxtmp[:,num_ghost:-num_ghost,num_ghost:-num_ghost]

# Set index for capa
Expand All @@ -451,7 +451,7 @@ def setup(use_petsc=False,solver_type='classic',outdir='./_output', disable_outp
# ======================
# 1) Call fortran function
qtmp = np.ndarray(shape=(solver.num_eqn,mx+2*num_ghost,my+2*num_ghost), dtype=float, order='F')
qtmp = problem.qinit(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,qtmp,auxtmp,Rsphere)
qtmp = sw_sphere_problem.qinit(mx,my,num_ghost,mx,my,xlower,ylower,dx,dy,qtmp,auxtmp,Rsphere)
state.q[:,:,:] = qtmp[:,num_ghost:-num_ghost,num_ghost:-num_ghost]

# 2) call python function define above
Expand Down
24 changes: 24 additions & 0 deletions src/pyclaw/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,8 @@ py.extension_module(

# Special extensions for examples

## Shallow water on the sphere

ext_name = 'sw_sphere_problem'
ext_srcs = [
'../../examples/shallow_sphere/mapc2p.f90',
Expand All @@ -305,3 +307,25 @@ py.extension_module(
subdir: 'clawpack/pyclaw/examples/shallow_sphere',
install : true
)

## 2D Advection-reaction problem

ext_name = 'advection_2d'
ext_srcs = [
'../../examples/advection_reaction_2d/rpn2_vc_advection_vector.f90',
'../../examples/advection_reaction_2d/rpt2_dummy.f90',
]
f2py_srcs = custom_target(
command: [f2py, ext_name],
input: ext_srcs,
output: [ext_name + 'module.c', ext_name + '-f2pywrappers.f'],
)

py.extension_module(
ext_name, [ext_srcs, f2py_srcs],
incdir_f2py / 'fortranobject.c',
include_directories: inc_np,
dependencies : py_dep,
subdir: 'clawpack/pyclaw/examples/advection_reaction_2d',
install : true
)

0 comments on commit 4fa92af

Please sign in to comment.