|
3 | 3 | """ |
4 | 4 |
|
5 | 5 | from pathlib import Path |
6 | | -import sys |
7 | | -import shutil |
8 | | -import unittest |
| 6 | +import os |
| 7 | +import pytest |
9 | 8 |
|
10 | 9 | import clawpack.amrclaw.test as test |
11 | | -import clawpack.clawutil.runclaw |
12 | 10 |
|
13 | | -from adjoint.test_acoustics_1d_adjoint import Acoustics1DAdjointTest |
14 | | - |
15 | | - |
16 | | -class Acoustics1DAdjointForwardTest(test.AMRClawRegressionTest): |
17 | | - r"""Basic test for a 1D acoustics adjoint-flagging forward problem test case""" |
18 | | - |
19 | | - |
20 | | - def runTest(self, save=False): |
21 | | - |
22 | | - # Run adjoint problem |
23 | | - try: |
24 | | - adjoint_run = Acoustics1DAdjointTest() |
25 | | - adjoint_run.setUp() |
26 | | - adjoint_run.runTest() |
27 | | - |
28 | | - # Copy output to local directory |
29 | | - adjoint_output = Path(self.temp_path) / "_adjoint_output" |
30 | | - |
31 | | - if Path(adjoint_output).exists(): |
32 | | - shutil.rmtree(adjoint_output) |
33 | | - shutil.copytree(adjoint_run.temp_path, adjoint_output) |
34 | | - finally: |
35 | | - adjoint_run.tearDown() |
36 | | - |
37 | | - # Write out data files |
38 | | - self.load_rundata() |
39 | | - |
40 | | - # self.rundata.clawdata.num_output_times = 1 |
41 | | - # self.rundata.clawdata.tfinal = 0.5 |
42 | | - |
43 | | - # self.rundata.amrdata.flag2refine_tol = 0.05 |
44 | | - |
45 | | - # self.rundata.gaugedata.gauges = [] |
46 | | - # self.rundata.gaugedata.gauges.append([0, -1.0, 0., 1e9]) |
47 | | - # self.rundata.gaugedata.gauges.append([1, -2.5, 0., 1e9]) |
48 | | - # self.rundata.gaugedata.gauges.append([2, -1.75, 0., 1e9]) |
49 | | - |
50 | | - # Look for adjoint data |
51 | | - self.rundata.adjointdata.adjoint_outdir = adjoint_output |
52 | | - |
53 | | - self.write_rundata_objects() |
54 | | - |
55 | | - # Run code |
56 | | - self.run_code() |
57 | | - |
58 | | - # Perform tests |
59 | | - self.check_gauges(save=save, gauge_id=0) |
60 | | - self.check_gauges(save=save, gauge_id=1) |
61 | | - # self.check_gauges(save=save, gauge_id=2) |
62 | | - |
63 | | - self.success = True |
64 | | - |
65 | | - |
66 | | - |
67 | | -if __name__=="__main__": |
68 | | - if len(sys.argv) > 1: |
69 | | - if bool(sys.argv[1]): |
70 | | - # Fake the setup and save out output |
71 | | - test = Acoustics1DAdjointForwardTest() |
72 | | - try: |
73 | | - test.setUp() |
74 | | - test.runTest(save=True) |
75 | | - finally: |
76 | | - test.tearDown() |
77 | | - sys.exit(0) |
78 | | - unittest.main() |
| 11 | +# import adjoint.test_acoustics_1d_adjoint |
| 12 | + |
| 13 | +def test_acoustics_1d_adjoint_forward(tmp_path: Path, save: bool): |
| 14 | + """Test for a 1D acoustics adjoint-flagging forward problem test case""" |
| 15 | + |
| 16 | + ctr = test.AMRClawTestRunner(tmp_path, test_path=__file__) |
| 17 | + |
| 18 | + # Run adjoint problem |
| 19 | + adjoint_output = ctr.temp_path / "_adjoint_output" |
| 20 | + |
| 21 | + if not adjoint_output.exists(): |
| 22 | + os.makedirs(adjoint_output) |
| 23 | + adjoint_ctr = test.AMRClawTestRunner(adjoint_output, |
| 24 | + test_path=ctr.test_path / "adjoint") |
| 25 | + adjoint_ctr.set_data(setrun_path=adjoint_ctr.test_path / "setrun.py") |
| 26 | + adjoint_ctr.write_data() |
| 27 | + adjoint_ctr.build_executable() |
| 28 | + adjoint_ctr.run_code() |
| 29 | + |
| 30 | + # Write problem data |
| 31 | + ctr.set_data() |
| 32 | + ctr.rundata.adjointdata.adjoint_outdir = adjoint_output |
| 33 | + ctr.write_data() |
| 34 | + |
| 35 | + ctr.build_executable() |
| 36 | + ctr.run_code() |
| 37 | + |
| 38 | + ctr.check_gauge(gauge_id=0) |
| 39 | + ctr.check_gauge(gauge_id=1) |
| 40 | + |
| 41 | + |
| 42 | +if __name__ == "__main__": |
| 43 | + pytest.main([__file__]) |
0 commit comments