-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
109 additions
and
249 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,49 +1,30 @@ | ||
def test_2d_acoustics(): | ||
"""test_2d_acoustics""" | ||
from . import acoustics_2d | ||
import numpy as np | ||
from clawpack.pyclaw.util import check_diff | ||
import os | ||
|
||
def verify_data(data_filename): | ||
def verify(claw): | ||
""" verifies 2d homogeneous acoustics from a previously verified run """ | ||
import os | ||
import numpy as np | ||
from clawpack.pyclaw.util import check_diff | ||
def check_error(data_filename,**kwargs): | ||
|
||
claw = acoustics_2d.setup(disable_output=True,**kwargs) | ||
claw.run() | ||
|
||
#grabs parallel results to process 0, None to other processes | ||
test_q=claw.solution.state.get_q_global() | ||
test_pressure = claw.frames[-1].q[0,:,:] | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename)) | ||
return check_diff(expected_pressure, test_pressure, reltol=1e-3, | ||
delta=claw.solution.grid.delta) | ||
|
||
if test_q is not None: | ||
test_pressure = test_q[0,:,:] | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.loadtxt(os.path.join(thisdir,data_filename)) | ||
return check_diff(expected_pressure, test_pressure, reltol=1e-3, | ||
delta=claw.solution.grid.delta) | ||
else: | ||
return | ||
return verify | ||
|
||
from clawpack.pyclaw.util import gen_variants | ||
from . import acoustics_2d | ||
class TestAcoustics2D: | ||
def test_classic(self): | ||
assert check_error('verify_classic.txt',solver_type='classic')==None | ||
|
||
classic_tests = gen_variants(acoustics_2d.setup, verify_data('verify_classic.txt'), | ||
kernel_languages=('Fortran',), solver_type='classic', disable_output=True) | ||
def test_classic_ptwise(self): | ||
assert check_error('verify_classic.txt',solver_type='classic',ptwise=True)==None | ||
|
||
ptwise_tests = gen_variants(acoustics_2d.setup, verify_data('verify_classic.txt'), | ||
kernel_languages=('Fortran',), ptwise=True, solver_type='classic', disable_output=True) | ||
def test_sharpclaw(self): | ||
assert check_error('verify_sharpclaw.txt',solver_type='sharpclaw')==None | ||
|
||
sharp_tests_rk = gen_variants(acoustics_2d.setup, verify_data('verify_sharpclaw.txt'), | ||
kernel_languages=('Fortran',), solver_type='sharpclaw', | ||
time_integrator='SSP104', disable_output=True) | ||
|
||
sharp_tests_lmm = gen_variants(acoustics_2d.setup, verify_data('verify_sharpclaw_lmm.txt'), | ||
kernel_languages=('Fortran',), solver_type='sharpclaw', | ||
time_integrator='SSPLMMk2', disable_output=True) | ||
|
||
from itertools import chain | ||
for test in chain(classic_tests, ptwise_tests, sharp_tests_rk, sharp_tests_lmm): | ||
yield test | ||
|
||
|
||
if __name__=="__main__": | ||
import nose | ||
nose.main() | ||
def test_sharpclaw_multistep(self): | ||
assert check_error('verify_sharpclaw_lmm.txt',solver_type='sharpclaw', | ||
time_integrator='SSPLMMk2')==None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,21 @@ | ||
def test_acoustics_2d_variable(): | ||
"""Test variable-coefficient 2D acoustics on mapped grids""" | ||
from . import acoustics_2d_inclusions | ||
import numpy as np | ||
from clawpack.pyclaw.util import check_diff | ||
import os | ||
|
||
import acoustics_2d_inclusions | ||
def check_error(data_filename,**kwargs): | ||
|
||
def verify_acoustics_inclusions(controller, solver_type='classic'): | ||
""" Regression test against data from a previous run.""" | ||
import os | ||
from clawpack.pyclaw.util import check_diff | ||
import numpy as np | ||
claw = acoustics_2d_inclusions.setup(disable_output=True,**kwargs) | ||
claw.run() | ||
test_pressure = claw.frames[-1].q[0,:,:] | ||
|
||
state = controller.frames[controller.num_output_times].state | ||
dx, dy = controller.solution.domain.grid.delta | ||
test_q = state.get_q_global() | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.load(os.path.join(thisdir, 'pressure.npz'))['arr_0'] | ||
test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - | ||
test_pressure[:].reshape(-1))) | ||
return check_diff(0, test_err, abstol=1e-7) | ||
|
||
if test_q is not None: | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.load(os.path.join(thisdir, | ||
'pressure.npz'))['arr_0'] | ||
test_pressure = test_q[0,:,:] | ||
test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - | ||
test_pressure[:].reshape(-1))) | ||
return check_diff(0, test_err, abstol=1e-7) | ||
|
||
|
||
from clawpack.pyclaw.util import gen_variants | ||
|
||
verify_func = lambda controller: verify_acoustics_inclusions(controller, solver_type='classic') | ||
classic_tests = gen_variants(acoustics_2d_inclusions.setup, verify_func, | ||
solver_type='classic', disable_output=True, | ||
num_cells=100,num_output_times=1) | ||
|
||
from itertools import chain | ||
for test in chain(classic_tests): | ||
yield test | ||
|
||
|
||
if __name__=="__main__": | ||
import nose | ||
nose.main() | ||
def test_classic(): | ||
assert check_error('verify_classic.txt',solver_type='classic', | ||
num_cells=100,num_output_times=1)==None |
71 changes: 23 additions & 48 deletions
71
examples/acoustics_2d_variable/test_acoustics_2d_variable.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,30 @@ | ||
def test_acoustics_2d_variable(): | ||
"""Test variable-coefficient 2D acoustics""" | ||
from . import acoustics_2d_interface | ||
import numpy as np | ||
from clawpack.pyclaw.util import check_diff | ||
import os | ||
|
||
from . import acoustics_2d_interface | ||
def check_error(**kwargs): | ||
|
||
def verify_acoustics(controller, solver_type='classic'): | ||
""" Verifies 2d variable-coefficient acoustics from a previously verified classic run """ | ||
import os | ||
from clawpack.pyclaw.util import check_diff | ||
import numpy as np | ||
solver_type = kwargs['solver_type'] | ||
claw = acoustics_2d_interface.setup(disable_output=True,**kwargs) | ||
claw.run() | ||
test_pressure = claw.frames[-1].q[0,:,:] | ||
|
||
state = controller.frames[controller.num_output_times].state | ||
dx, dy = controller.solution.domain.grid.delta | ||
test_q = state.get_q_global() | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.loadtxt(os.path.join(thisdir, 'pressure_%s.txt' % solver_type)) | ||
test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - | ||
test_pressure[:].reshape(-1))) | ||
print(test_err) | ||
return check_diff(0, test_err, abstol=1e-1) | ||
|
||
if test_q is not None: | ||
thisdir = os.path.dirname(__file__) | ||
expected_pressure = np.loadtxt(os.path.join(thisdir, | ||
'pressure_%s.txt' % solver_type)) | ||
test_pressure = test_q[0,:,:] | ||
#test_err = dx*dy*np.linalg.norm(expected_pressure-test_pressure) | ||
test_err = np.max(np.abs(expected_pressure[:].reshape(-1) - | ||
test_pressure[:].reshape(-1))) | ||
return check_diff(0, test_err, abstol=1e-1) | ||
|
||
class TestAcoustics2D: | ||
def test_classic(self): | ||
assert check_error(solver_type='classic',num_cells=(50,50))==None | ||
|
||
from clawpack.pyclaw.util import gen_variants | ||
def test_sharpclaw(self): | ||
assert check_error(solver_type='sharpclaw',num_cells=(50,50))==None | ||
|
||
verify_func = lambda controller: verify_acoustics(controller, solver_type='classic') | ||
classic_tests = gen_variants(acoustics_2d_interface.setup, verify_func, | ||
solver_type='classic', disable_output=True, | ||
num_cells=(50, 50)) | ||
|
||
verify_func = lambda controller: verify_acoustics(controller, solver_type='sharpclaw') | ||
sharp_tests_rk = gen_variants(acoustics_2d_interface.setup, | ||
verify_func, | ||
solver_type='sharpclaw', | ||
time_integrator='SSP104', | ||
disable_output=True, num_cells=(50, 50)) | ||
|
||
sharp_tests_lmm = gen_variants(acoustics_2d_interface.setup, | ||
verify_func, lim_type=1, | ||
solver_type='sharpclaw', | ||
time_integrator='SSPLMMk2', | ||
disable_output=True, | ||
num_cells=(50, 50)) | ||
|
||
from itertools import chain | ||
for test in chain(classic_tests, sharp_tests_rk, sharp_tests_lmm): | ||
yield test | ||
|
||
|
||
if __name__=="__main__": | ||
import nose | ||
nose.main() | ||
def test_sharpclaw_multistep(self): | ||
assert check_error(solver_type='sharpclaw',num_cells=(50,50), | ||
time_integrator='SSPLMMk2')==None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,76 +1,23 @@ | ||
import os | ||
from itertools import chain | ||
|
||
import numpy as np | ||
|
||
from clawpack.pyclaw.util import gen_variants | ||
from clawpack.pyclaw.util import check_diff | ||
|
||
from . import acoustics_3d_interface | ||
|
||
def check_error(**kwargs): | ||
|
||
def test_3d_acoustics(): | ||
""" Tests for homogeneous and heterogeneous 3D acoustics""" | ||
|
||
def acoustics_verify_homogeneous(claw): | ||
""" Regression test for 3D homogeneous acoustics equations. | ||
""" | ||
|
||
pinitial = claw.frames[0].state.get_q_global() | ||
pfinal = claw.frames[claw.num_output_times].state.get_q_global() | ||
|
||
if pinitial is not None: | ||
pinitial = pinitial[0, :, :, :].reshape(-1) | ||
pfinal = pfinal[0, :, :, :].reshape(-1) | ||
grid = claw.solution.state.grid | ||
final_difference = np.prod(grid.delta)*np.linalg.norm(pfinal-pinitial, ord=1) | ||
return check_diff(0., final_difference, abstol=1e-1) | ||
else: | ||
# In parallel, we check values only for the rank 0 process | ||
return | ||
|
||
def acoustics_verify_heterogeneous(claw): | ||
""" Regression test for 3D heterogeneous acoustics equations | ||
""" | ||
|
||
pinitial = claw.frames[0].state.get_q_global() | ||
pfinal = claw.frames[claw.num_output_times].state.get_q_global() | ||
|
||
if pinitial is not None: | ||
pfinal = pfinal[0, :, :, :].reshape(-1) | ||
thisdir = os.path.dirname(__file__) | ||
verify_pfinal = np.loadtxt(os.path.join(thisdir, 'verify_classic_heterogeneous.txt')) | ||
norm_err = np.linalg.norm(pfinal-verify_pfinal) | ||
return check_diff(0, norm_err, abstol=10.) | ||
else: | ||
# In parallel, we check values only for the rank 0 process | ||
return | ||
|
||
classic_homogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_homogeneous, | ||
kernel_languages=('Fortran',), | ||
solver_type='classic', problem='homogeneous', | ||
disable_output=True,mx=128,my=4,mz=4) | ||
|
||
classic_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_heterogeneous, | ||
kernel_languages=('Fortran',), | ||
solver_type='classic', problem='heterogeneous', | ||
disable_output=True,mx=15,my=15,mz=15) | ||
|
||
sharp_homogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_homogeneous, | ||
kernel_languages=('Fortran',), | ||
solver_type='sharpclaw', problem='homogeneous', | ||
disable_output=True,mx=128,my=4,mz=4) | ||
claw = acoustics_3d_interface.setup(problem='homogeneous',mx=128,my=4,mz=4,disable_output=True,**kwargs) | ||
claw.run() | ||
|
||
sharp_heterogeneous_tests = gen_variants(acoustics_3d_interface.setup, acoustics_verify_heterogeneous, | ||
kernel_languages=('Fortran',), | ||
solver_type='sharpclaw', problem='heterogeneous', | ||
disable_output=True,mx=15,my=15,mz=15) | ||
test_pressure = claw.frames[-1].q[0,:,:,:] | ||
expected_pressure = claw.frames[0].q[0,:,:,:] | ||
return check_diff(expected_pressure, test_pressure, reltol=1e-1, | ||
delta=claw.solution.grid.delta) | ||
|
||
for test in chain(classic_homogeneous_tests, classic_heterogeneous_tests, sharp_homogeneous_tests, | ||
sharp_heterogeneous_tests): | ||
yield test | ||
|
||
class TestAcoustics3D: | ||
def test_classic(self): | ||
assert check_error(solver_type='classic')==None | ||
|
||
if __name__=="__main__": | ||
import nose | ||
nose.main() | ||
def test_sharpclaw(self): | ||
assert check_error(solver_type='sharpclaw')==None |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.