Peano
Loading...
Searching...
No Matches
test_exagrype_fd4_with_ko_dissipation.py
Go to the documentation of this file.
1import types
2
3import pytest
4
5import peano4.api
8
9import exahype2.api
10import exagrype.api
11
12
13def _solver(quantities=None, sigma=8.0, rk_order=2):
14 solver = exagrype.api.CCZ4Solver("CCZ4")
15 solver.numerical_scheme = exagrype.api.FD4WithKODissipation(
16 solver,
17 patch_size=5,
18 rk_order=rk_order,
19 kreiss_oliger_sigma=sigma,
20 quantities=quantities,
21 )
22 return solver
23
24
25def _construct_time_step(solver, directory):
26 exahype2_project = types.SimpleNamespace(periodic_BC=[True, True, True])
27 peano_project = peano4.api.Project(["probe"], "probe", str(directory))
28 time_step = peano4.api.taskgraph.Graph()
29 solver.numerical_scheme.construct_output(exahype2_project, peano_project, time_step)
30 return {task.name: task for task in time_step.tasks}
31
32
33def _body(action_set):
34 return action_set.get_body_of_operation(
35 peano4.api.solversteps.ActionSet.OPERATION_TOUCH_CELL_FIRST_TIME
36 )
37
38
40 solver = _solver()
41 assert solver.numerical_scheme.overlap == 3
42 assert solver._patch_with_halo.dim == (11, 11, 11)
43 assert solver._patch_overlap_current_time_step.dim == (6, 5, 5)
44
45
47 solver = exagrype.api.CCZ4Solver("CCZ4")
49 solver, patch_size=5, rk_order=2
50 )
51 assert scheme.overlap == 2
52 assert not hasattr(scheme, "kreiss_oliger_sigma")
53
54
56 solver = _solver()
57 assert solver.numerical_scheme.dissipative_quantities == list(range(59))
58
59
61 solver = _solver(quantities=["lapse", "G", 58, 0])
62 assert solver.numerical_scheme.dissipative_quantities == [0, 1, 2, 3, 4, 5, 16, 58]
63
64
65@pytest.mark.parametrize("quantities", [["lapsee"], [59], [-1], [1.5], []])
67 with pytest.raises((ValueError, TypeError)):
68 _solver(quantities=quantities)
69
70
72 with pytest.raises(ValueError):
73 _solver(sigma=-1.0)
74
75
77 solver = _solver(quantities=["lapse", "phi"], rk_order=2)
78 tasks = _construct_time_step(solver, tmp_path)
79 for stage in range(2):
80 action_sets = tasks[f"CCZ4_Evaluate right hand side stage {stage}"].action_sets
81 assert [type(action_set) for action_set in action_sets] == [
84 ]
85 body = _body(action_sets[1])
86 assert "::exagrype::ccz4::addKreissOligerDissipation(" in body
87 assert "constexpr int dissipativeQuantities[] = { 16, 54 };" in body
88 # Estimate slot of the stage: stage * 59 unknowns * 5^3 grid cells
89 assert f"fineGridCellCCZ4QRhsEstimates.value + {stage * 59 * 125}," in body
90 assert " 3,\n" in body
91 assert " 8.0,\n" in body
92
93
95 solver = _solver()
96 _construct_time_step(solver, tmp_path)
97 # The kernel gets the halo of three, and the functors follow patchData directly
98 assert "<\n 5,\n 3,\n 59,\n 0\n>" in solver.compute_kernel_call
99 assert "(\n patchData,\n [&](" in solver.compute_kernel_call
Solver for the Einstein equations in the first-order CCZ4 formulation.
Definition CCZ4Solver.py:16
Fourth-order Finite Differences with Kreiss-Oliger dissipation.
Add the Kreiss-Oliger dissipation to the right-hand side of one Runge-Kutta stage.
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Evaluate the right-hand side of one Runge-Kutta stage over a patch.
Represents a Peano 4 project.
Definition Project.py:23
Holds a sequence of Task instances.
Definition Graph.py:9
This file is part of the ExaGRyPE project.
Definition __init__.py:1
The Python-side model of "what happens during one mesh sweep".
Definition __init__.py:1
The task graph abstraction allows users to formalise their solver steps over small task graphs which ...
Definition __init__.py:1