Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 0 additions & 11 deletions examples/Makefile

This file was deleted.

49 changes: 14 additions & 35 deletions examples/acoustics_1d_adjoint/adjoint/test_acoustics_1d_adjoint.py
Original file line number Diff line number Diff line change
@@ -1,45 +1,24 @@
"""
Test for the adjoint problem for 2D acoustics
Test for the adjoint problem for 1D acoustics
"""

import sys
import unittest
from pathlib import Path
import pytest

import clawpack.amrclaw.test as test
import clawpack.amrclaw.data as data

class Acoustics1DAdjointTest(test.AMRClawRegressionTest):
def test_acoustics_1d_adjoint(tmp_path: Path, save: bool):
"""Acoustics 1D adjoint test"""

def runTest(self, save=False):
ctr = test.AMRClawTestRunner(tmp_path)
ctr.set_data()
ctr.write_data()
ctr.build_executable()
ctr.run_code()

# Write out data files
self.load_rundata()

# self.rundata.clawdata.num_output_times = 10
# self.rundata.clawdata.tfinal = 1.0
ctr.check_gauge(gauge_id=0)
ctr.check_gauge(gauge_id=1)

# self.rundata.clawdata.use_fwaves = False

self.write_rundata_objects()

self.run_code()

# Perform Tests
self.check_gauges(save=save, gauge_id=0)
self.check_gauges(save=save, gauge_id=1)

self.success = True


if __name__=="__main__":
if len(sys.argv) > 1:
if bool(sys.argv[1]):
# Fake the setup and save out output
test = Acoustics1DAdjointTest()
try:
test.setUp()
test.runTest(save=True)
finally:
test.tearDown()
sys.exit(0)
unittest.main()
if __name__ == "__main__":
pytest.main([__file__])
105 changes: 35 additions & 70 deletions examples/acoustics_1d_adjoint/test_acoustics_1d_adjoint_forward.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,76 +3,41 @@
"""

from pathlib import Path
import sys
import shutil
import unittest
import os
import pytest

import clawpack.amrclaw.test as test
import clawpack.clawutil.runclaw

from adjoint.test_acoustics_1d_adjoint import Acoustics1DAdjointTest


class Acoustics1DAdjointForwardTest(test.AMRClawRegressionTest):
r"""Basic test for a 1D acoustics adjoint-flagging forward problem test case"""


def runTest(self, save=False):

# Run adjoint problem
try:
adjoint_run = Acoustics1DAdjointTest()
adjoint_run.setUp()
adjoint_run.runTest()

# Copy output to local directory
adjoint_output = Path(self.temp_path) / "_adjoint_output"

if Path(adjoint_output).exists():
shutil.rmtree(adjoint_output)
shutil.copytree(adjoint_run.temp_path, adjoint_output)
finally:
adjoint_run.tearDown()

# Write out data files
self.load_rundata()

# self.rundata.clawdata.num_output_times = 1
# self.rundata.clawdata.tfinal = 0.5

# self.rundata.amrdata.flag2refine_tol = 0.05

# self.rundata.gaugedata.gauges = []
# self.rundata.gaugedata.gauges.append([0, -1.0, 0., 1e9])
# self.rundata.gaugedata.gauges.append([1, -2.5, 0., 1e9])
# self.rundata.gaugedata.gauges.append([2, -1.75, 0., 1e9])

# Look for adjoint data
self.rundata.adjointdata.adjoint_outdir = adjoint_output

self.write_rundata_objects()

# Run code
self.run_code()

# Perform tests
self.check_gauges(save=save, gauge_id=0)
self.check_gauges(save=save, gauge_id=1)
# self.check_gauges(save=save, gauge_id=2)

self.success = True



if __name__=="__main__":
if len(sys.argv) > 1:
if bool(sys.argv[1]):
# Fake the setup and save out output
test = Acoustics1DAdjointForwardTest()
try:
test.setUp()
test.runTest(save=True)
finally:
test.tearDown()
sys.exit(0)
unittest.main()
# import adjoint.test_acoustics_1d_adjoint

def test_acoustics_1d_adjoint_forward(tmp_path: Path, save: bool):
"""Test for a 1D acoustics adjoint-flagging forward problem test case"""

ctr = test.AMRClawTestRunner(tmp_path, test_path=__file__)

# Run adjoint problem
adjoint_output = ctr.temp_path / "_adjoint_output"

if not adjoint_output.exists():
os.makedirs(adjoint_output)
adjoint_ctr = test.AMRClawTestRunner(adjoint_output,
test_path=ctr.test_path / "adjoint")
adjoint_ctr.set_data(setrun_path=adjoint_ctr.test_path / "setrun.py")
adjoint_ctr.write_data()
adjoint_ctr.build_executable()
adjoint_ctr.run_code()

# Write problem data
ctr.set_data()
ctr.rundata.adjointdata.adjoint_outdir = adjoint_output
ctr.write_data()

ctr.build_executable()
ctr.run_code()

ctr.check_gauge(gauge_id=0)
ctr.check_gauge(gauge_id=1)


if __name__ == "__main__":
pytest.main([__file__])
55 changes: 18 additions & 37 deletions examples/acoustics_1d_homogeneous/test_acoustics_1d_homogeneous.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,50 +2,31 @@
Regression tests for 1D acoustics in a homogeneous medium.
"""

import sys
import unittest
from pathlib import Path
import pytest

import clawpack.amrclaw.test as test


class Acoustics1DTest_Homogeneous(test.AMRClawRegressionTest):
def test_acoustics_1d_homogeneous(tmp_path: Path, save: bool):
"""Basic test for a 1D acoustics test case in a homogeneous medium"""

ctr = test.AMRClawTestRunner(tmp_path)

ctr.set_data()
ctr.rundata.clawdata.num_output_times = 1
ctr.rundata.clawdata.tfinal = 0.200000
ctr.rundata.gaugedata.gauges = []
ctr.rundata.gaugedata.gauges.append([0, 0.0, 0., 0.8])
ctr.rundata.gaugedata.gauges.append([1, 0.6, 0., 0.8])
ctr.write_data()

def runTest(self, save=False):

# Write out data files
self.load_rundata()

self.rundata.clawdata.num_output_times = 1
self.rundata.clawdata.tfinal = 0.200000

self.rundata.gaugedata.gauges = []
self.rundata.gaugedata.gauges.append([0, 0.0, 0., 0.8])
self.rundata.gaugedata.gauges.append([1, 0.6, 0., 0.8])

self.write_rundata_objects()

# Run code
self.run_code()

# Perform tests
self.check_gauges(save=save, gauge_id=0)
self.check_gauges(save=save, gauge_id=1)
ctr.build_executable()

self.success = True
ctr.run_code()

ctr.check_gauge(gauge_id=0)
ctr.check_gauge(gauge_id=1)


if __name__=="__main__":
if len(sys.argv) > 1:
if bool(sys.argv[1]):
# Fake the setup and save out output
test = Acoustics1DTest_Homogeneous()
try:
test.setUp()
test.runTest(save=True)
finally:
test.tearDown()
sys.exit(0)
unittest.main()
if __name__ == "__main__":
pytest.main([__file__])
127 changes: 52 additions & 75 deletions examples/advection_2d_square/test_advection_2d_square.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,82 +2,59 @@
Regression tests for 2D advection on a square.
"""

import sys
import unittest
from pathlib import Path
import pytest

import clawpack.amrclaw.test as test
import clawpack.amrclaw.data as data


class Advection2DSquareTest(test.AMRClawRegressionTest):
r"""Basic test for a 2D advection test case"""


def runTest(self, save=False):

# Write out data files
self.load_rundata()

self.rundata.clawdata.num_output_times = 1
self.rundata.clawdata.tfinal = 0.4

self.rundata.gaugedata.gauges = []
self.rundata.gaugedata.gauges.append([1, 0.65, 0.4, 0., 10.])
self.rundata.gaugedata.gauges.append([2, 0.2, 0.8, 0., 10.])

# Test newer flagregions

# The entire domain restricted to level 1 for illustration:
# Note that this is a rectangle specified in the new way:
# (other regions below will force/allow more refinement)
flagregion = data.FlagRegion(num_dim=2)
flagregion.name = 'Region_domain'
flagregion.minlevel = 1
flagregion.maxlevel = 1
flagregion.t1 = 0.
flagregion.t2 = 1e9
flagregion.spatial_region_type = 1 # Rectangle
flagregion.spatial_region = [0.,1.,0.,1.] # = [x1,x2,y1,y2]
self.rundata.flagregiondata.flagregions.append(flagregion)

# Another rectangle specified in the new way:
flagregion = data.FlagRegion(num_dim=2)
flagregion.name = 'Region_3levels'
flagregion.minlevel = 1
flagregion.maxlevel = 3
flagregion.t1 = 0.
flagregion.t2 = 1e9
flagregion.spatial_region_type = 1 # Rectangle
flagregion.spatial_region = [0.,1.,0.,0.7]
self.rundata.flagregiondata.flagregions.append(flagregion)

self.write_rundata_objects()

# Run code
self.run_code()

# Perform tests
self.check_gauges(save=save, gauge_id=1)
self.check_gauges(save=save, gauge_id=2)

# self.check_gauges(save=save, gauge_num=1,
# regression_data_path='regression_data_test2.txt')
# self.check_gauges(save=save, gauge_num=2,
# regression_data_path='regression_data_test3.txt')

self.success = True



if __name__=="__main__":
if len(sys.argv) > 1:
if bool(sys.argv[1]):
# Fake the setup and save out output
test = Advection2DSquareTest()
try:
test.setUp()
test.runTest(save=True)
finally:
test.tearDown()
sys.exit(0)
unittest.main()
def test_advection_2d_square(tmp_path: Path, save: bool):
"""Basic test for a 2D advection test case"""

ctr = test.AMRClawTestRunner(tmp_path)

ctr.set_data()
ctr.rundata.clawdata.num_output_times = 1
ctr.rundata.clawdata.tfinal = 0.4
ctr.rundata.gaugedata.gauges = []
ctr.rundata.gaugedata.gauges.append([1, 0.65, 0.4, 0., 10.])
ctr.rundata.gaugedata.gauges.append([2, 0.2, 0.8, 0., 10.])

# Test newer flagregions

# The entire domain restricted to level 1 for illustration:
# Note that this is a rectangle specified in the new way:
# (other regions below will force/allow more refinement)
flagregion = data.FlagRegion(num_dim=2)
flagregion.name = 'Region_domain'
flagregion.minlevel = 1
flagregion.maxlevel = 1
flagregion.t1 = 0.
flagregion.t2 = 1e9
flagregion.spatial_region_type = 1 # Rectangle
flagregion.spatial_region = [0.,1.,0.,1.] # = [x1,x2,y1,y2]
ctr.rundata.flagregiondata.flagregions.append(flagregion)

# Another rectangle specified in the new way:
flagregion = data.FlagRegion(num_dim=2)
flagregion.name = 'Region_3levels'
flagregion.minlevel = 1
flagregion.maxlevel = 3
flagregion.t1 = 0.
flagregion.t2 = 1e9
flagregion.spatial_region_type = 1 # Rectangle
flagregion.spatial_region = [0.,1.,0.,0.7]
ctr.rundata.flagregiondata.flagregions.append(flagregion)

ctr.write_data()

ctr.build_executable()

ctr.run_code()

ctr.check_gauge(gauge_id=1)
ctr.check_gauge(gauge_id=2)


if __name__ == "__main__":
pytest.main([__file__])
Loading
Loading