Skip to content

Commit

Permalink
Update and improve Riemann solver code (#176)
Browse files Browse the repository at this point in the history
* Start using implicit none in all Riemann solvers.

* Start using implicit none in all Riemann solvers.

* Add a temporary testing workflow

It uses PyClaw's tests since, to my understanding, an ensemble
of local regression tests for the Riemann repository using
Pytest would require the appropriate argument intents of the
rp* subroutines to be explicitly declared already.
So the Riemann solvers should be modernized first.

Also, the test for shallow water on the sphere is omitted for the moment.

* Fix typo branch name

* Use implicit none in more Riemann solvers

* implicit none in SWEs on the sphere

The PyClaw test that uses this RS is skipped in the testing
workflow since it leads to a core dump
(I suspect this has to do with the OS or the system
architecture).

However, this test passes locally for me (before and after the
implicit none changes).

* All 2D RSs using implicit none

* implicit none used in every Riemann solver

* Add workflow for Classic tests

* Temporary fix Pytest not collecting AMRClaw tests

The regression tests in AMRClaw are not being collected by Pytest. They
just have to be renamed. This is a temporary fix to run them from this
repo in a single pytest session.

---------

Co-authored-by: Carlos Munoz Moncayo <[email protected]>
  • Loading branch information
ketch and carlosmunozmoncayo authored Dec 2, 2024
1 parent 95a03ca commit 8d62870
Show file tree
Hide file tree
Showing 43 changed files with 942 additions and 465 deletions.
66 changes: 66 additions & 0 deletions .github/workflows/amrclaw_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test Riemann solvers with AMRClaw tests

on:
push:
branches: [ "implicit_none" ]
pull_request:
branches: [ "implicit_none" ]

workflow_dispatch:

permissions:
contents: read

env:
CLAW: ${{ github.workspace }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran
python -m pip install --upgrade pip
pip install 'numpy<2.0'
pip install matplotlib #Some imports require matplotlib
pip install scipy #To not skip tests
pip install nose
pip install flake8 meson-python ninja pytest
- name: Checkout Clawpack
uses: actions/[email protected]
with:
repository: clawpack/clawpack
submodules: true

- name: Checkout AMRClaw branch
uses: actions/[email protected]
with:
repository: clawpack/amrclaw #
path: amrclaw
ref: master

- name: Checkout implicit_none from this repo
uses: actions/[email protected]
with:
repository: ${{ github.repository }}
path: ${{ env.CLAW }}/riemann
ref: implicit_none

- name: Install Clawpack
run: |
cd ${CLAW}
pip install --no-build-isolation --editable .
- name: Test with pytest
run: |
cd ${CLAW}/riemann
bash collect_pytests_amrclaw.sh
66 changes: 66 additions & 0 deletions .github/workflows/classic_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: Test Riemann solvers with Classic Clawpack tests

on:
push:
branches: [ "implicit_none" ]
pull_request:
branches: [ "implicit_none" ]

workflow_dispatch:

permissions:
contents: read

env:
CLAW: ${{ github.workspace }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran
python -m pip install --upgrade pip
pip install 'numpy<2.0'
pip install matplotlib #Some imports require matplotlib
pip install scipy #To not skip tests
pip install nose
pip install flake8 meson-python ninja pytest
- name: Checkout Clawpack
uses: actions/[email protected]
with:
repository: clawpack/clawpack
submodules: true

- name: Checkout Classic branch
uses: actions/[email protected]
with:
repository: clawpack/classic #
path: classic
ref: master

- name: Checkout implicit_none from this repo
uses: actions/[email protected]
with:
repository: ${{ github.repository }}
path: ${{ env.CLAW }}/riemann
ref: implicit_none

- name: Install Clawpack
run: |
cd ${CLAW}
pip install --no-build-isolation --editable .
- name: Test with pytest
run: |
cd ${CLAW}/classic
pytest tests
65 changes: 65 additions & 0 deletions .github/workflows/pyclaw_tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
name: Test Riemann solvers with PyClaw tests

on:
push:
branches: [ "implicit_none" ]
pull_request:
branches: [ "implicit_none" ]

workflow_dispatch:

permissions:
contents: read

env:
CLAW: ${{ github.workspace }}

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Set up Python 3.10
uses: actions/setup-python@v5
with:
python-version: "3.10"

- name: Install dependencies
run: |
sudo apt-get update
sudo apt-get install gfortran
python -m pip install --upgrade pip
pip install 'numpy<2.0'
pip install matplotlib #Some imports require matplotlib
pip install scipy #To not skip tests
pip install flake8 meson-python ninja pytest
- name: Checkout Clawpack
uses: actions/[email protected]
with:
repository: clawpack/clawpack
submodules: true

- name: Checkout PyClaw branch
uses: actions/[email protected]
with:
repository: clawpack/pyclaw #
path: pyclaw
ref: master

- name: Checkout implicit_none from this repo
uses: actions/[email protected]
with:
repository: ${{ github.repository }}
path: ${{ env.CLAW }}/riemann
ref: implicit_none

- name: Install Clawpack
run: |
cd ${CLAW}
pip install --no-build-isolation --editable .
- name: Test with pytest
run: |
cd ${CLAW}/pyclaw
pytest --ignore=development --ignore=examples/shallow_sphere
19 changes: 19 additions & 0 deletions collect_pytests_amrclaw.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#Collect Pytest tests for AMRClaw
cd ${CLAW}/amrclaw/tests
pathlist=()
for dir in $(ls -d */); do
cd $dir
#Check if there are any test files
#Capture the error message and check if it is empty
if [ -z "$(ls *test*.py 2>/dev/null )" ]; then
cd ..
continue
fi
for file in $(ls *test*.py); do
pathlist+=($(pwd)/$file)
done
cd ..
done

#Run the tests
pytest ${pathlist[@]}
26 changes: 13 additions & 13 deletions src/rp1_acoustics.f90
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,23 @@ subroutine rp1(maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)
! From the basic clawpack routines, this routine is called with ql = qr


implicit double precision (a-h,o-z)
implicit none

dimension wave(meqn, mwaves, 1-mbc:maxm+mbc)
dimension s(mwaves,1-mbc:maxm+mbc)
dimension ql(meqn, 1-mbc:maxm+mbc)
dimension qr(meqn, 1-mbc:maxm+mbc)
dimension apdq(meqn, 1-mbc:maxm+mbc)
dimension amdq(meqn, 1-mbc:maxm+mbc)
integer, intent(in) :: maxm, meqn, mwaves, mbc, mx, maux
real(kind=8), intent(in) :: ql(meqn, 1-mbc:maxm+mbc),qr(meqn, 1-mbc:maxm+mbc)

! local arrays
! ------------
dimension delta(2)
real(kind=8), intent(out) :: wave(meqn, mwaves, 1-mbc:maxm+mbc)
real(kind=8), intent(out) :: s(mwaves,1-mbc:maxm+mbc)
real(kind=8), intent(out) :: apdq(meqn, 1-mbc:maxm+mbc), amdq(meqn, 1-mbc:maxm+mbc)

! # density, bulk modulus, and sound speed, and impedence of medium:
! # (should be set in setprob.f)
common /cparam/ rho,bulk,cc,zz
real(kind=8) :: delta(2)
real(kind=8) :: rho, bulk, cc, zz
real(kind=8) :: a1, a2, auxl, auxr
integer :: i, m

! density, bulk modulus, and sound speed, and impedence of medium:
! (should be set in setprob.f)
common /cparam/ rho,bulk,cc,zz

! # split the jump in q at each interface into waves

Expand Down
34 changes: 20 additions & 14 deletions src/rp1_acoustics_adjoint.f90
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,26 @@ subroutine rp1(maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,fwave,s,amdq,apdq)

! # aux arrays not used in this solver.

implicit double precision (a-h,o-z)
implicit none

dimension fwave(meqn, mwaves, 1-mbc:maxm+mbc)
dimension s(mwaves, 1-mbc:maxm+mbc)
dimension ql(meqn, 1-mbc:maxm+mbc)
dimension qr(meqn, 1-mbc:maxm+mbc)
dimension apdq(meqn, 1-mbc:maxm+mbc)
dimension amdq(meqn, 1-mbc:maxm+mbc)
dimension auxl(maux, 1-mbc:maxm+mbc)
dimension auxr(maux, 1-mbc:maxm+mbc)
!Input
integer, intent(in) :: maxm, meqn, mwaves, maux, mbc, mx
double precision, intent(in) :: ql(meqn, 1-mbc:maxm+mbc)
double precision, intent(in) :: qr(meqn, 1-mbc:maxm+mbc)
double precision, intent(in) :: auxl(maux, 1-mbc:maxm+mbc)
double precision, intent(in) :: auxr(maux, 1-mbc:maxm+mbc)

double precision, intent(out) :: fwave(meqn, mwaves, 1-mbc:maxm+mbc)
double precision, intent(out) :: s(mwaves, 1-mbc:maxm+mbc)
double precision, intent(out) :: amdq(meqn, 1-mbc:maxm+mbc)
double precision, intent(out) :: apdq(meqn, 1-mbc:maxm+mbc)

!local
integer :: i, m
double precision :: rhoi, bulki, beta1, beta2
double precision :: rho, bulk, cc, zz
double precision, dimension(2) :: delta

! local arrays
! ------------
dimension delta(2)

! # density, bulk modulus, and sound speed, and impedence of medium:
! # (should be set in setprob.f)
Expand All @@ -47,7 +53,7 @@ subroutine rp1(maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,fwave,s,amdq,apdq)
! # split the jump in f(q) at each interface into waves

! # find b1 and b2, the coefficients of the 2 eigenvectors:
do 20 i = 2-mbc, mx+mbc
do i = 2-mbc, mx+mbc
! # material properties
rhoi = zz/cc
bulki = rhoi*cc**2
Expand All @@ -70,7 +76,7 @@ subroutine rp1(maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,fwave,s,amdq,apdq)
fwave(2,2,i) = -beta2*zz
s(2,i) = cc

20 END DO
END DO


! # compute the leftgoing and rightgoing flux differences:
Expand Down
29 changes: 15 additions & 14 deletions src/rp1_acoustics_variable.f90
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,21 @@ subroutine rp1(maxm,meqn,mwaves,maux,mbc,mx,ql,qr,auxl,auxr,wave,s,amdq,apdq)
! From the basic clawpack routines, this routine is called with ql = qr


implicit double precision (a-h,o-z)

dimension auxl(maux, 1-mbc:maxm+mbc)
dimension auxr(maux, 1-mbc:maxm+mbc)
dimension wave(meqn, mwaves, 1-mbc:maxm+mbc)
dimension s(mwaves, 1-mbc:maxm+mbc)
dimension ql(meqn, 1-mbc:maxm+mbc)
dimension qr(meqn, 1-mbc:maxm+mbc)
dimension apdq(meqn, 1-mbc:maxm+mbc)
dimension amdq(meqn, 1-mbc:maxm+mbc)

! local arrays
! ------------
dimension delta(2)
implicit none

integer, intent(in) :: maxm, meqn, mwaves, maux, mbc, mx
real(kind=8), intent(in) :: ql(meqn, 1-mbc:mx+mbc)
real(kind=8), intent(in) :: qr(meqn, 1-mbc:mx+mbc)
real(kind=8), intent(in) :: auxl(maux, 1-mbc:maxm+mbc)
real(kind=8), intent(in) :: auxr(maux, 1-mbc:maxm+mbc)
real(kind=8), intent(out) :: wave(meqn, mwaves, 1-mbc:maxm+mbc)
real(kind=8), intent(out) :: s(mwaves, 1-mbc:maxm+mbc)
real(kind=8), intent(out) :: apdq(meqn, 1-mbc:maxm+mbc)
real(kind=8), intent(out) :: amdq(meqn, 1-mbc:maxm+mbc)

real(kind=8) :: delta(2)
real(kind=8) :: zi, zim, a1, a2
integer :: i, m


! split the jump in q at each interface into waves
Expand Down
Loading

0 comments on commit 8d62870

Please sign in to comment.