Peano
Loading...
Searching...
No Matches
coupling-illustrations.py
Go to the documentation of this file.
1# This file is part of the ExaHyPE2 project. For conditions of distribution and
2# use, please see the copyright notice at www.peano-framework.org
3"""!
4
5Create the task graphs of the page "Coupling solvers"
6
7Run from anywhere via
8
9~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
10python3 documentation/exahype2/programmers-guide/coupling-illustrations.py
11~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
12
13The script writes four pictures next to itself. They show the time stepping task graph of
14
15- Euler with Finite Volumes (coupling-graph-euler.png),
16- CCZ4 with fourth-order Finite Differences and Runge-Kutta 2, without any
17 additional step such as lopsided advection (coupling-graph-ccz4.png), and
18- the two solvers coupled in an outer additive way
19 (coupling-graph-outer-additive.png) or in an outer multiplicative way
20 (coupling-graph-outer-multiplicative.png).
21
22The generated project goes into a temporary directory. The script uses a
23matplotlib backend without windows, i.e. nothing pops up.
24
25"""
26import os
27import sys
28import tempfile
29
30Here = os.path.dirname(os.path.abspath(__file__))
31Root = os.path.abspath(os.path.join(Here, "..", "..", ".."))
32sys.path.insert(0, os.path.join(Root, "src"))
33
34import matplotlib
35
36matplotlib.use("Agg")
37import matplotlib.pyplot as plt
38
39import peano4.api
40import exahype2.api
41import exagrype.api
42
43
44def plot_graph(graph, title, file_name):
45 plt.close("all")
46 graph.visualise(title=title)
47 output = os.path.join(Here, file_name)
48 plt.gcf().savefig(output, dpi=90)
49 plt.close("all")
50 print("Wrote", output)
51
52
53def create_host(host_class, ccz4_patch_size=8):
54 coupled = host_class()
55 ccz4, euler = coupled.ccz4, coupled.euler
56 ccz4.add_pde_term(exagrype.api.initialvalues.gauge_wave())
58 ccz4, ccz4_patch_size, rk_order=2
59 )
60 euler.numerical_scheme = exahype2.api.fv.RusanovWithExplicitEuler(
61 euler, 2 * ccz4_patch_size + 1
62 )
64 ccz4, volume_size=1.01 / 3 / ccz4_patch_size
65 )
67 ccz4, first_plot_time_stamp=0.0, time_in_between_plots=0.1
68 )
69 euler.grid_construction = exahype2.api.fv.SetupSimulationOverRegularGrid(
70 euler, volume_size=1.01 / 3 / (2 * ccz4_patch_size + 1)
71 )
72 euler.plotter = exahype2.api.fv.PlotAsVTKFile(
73 euler, first_plot_time_stamp=0.0, time_in_between_plots=0.1
74 )
75 return coupled
76
77
78def plot_host(host_class, file_name, title, single_solver_graphs):
79 peano4.api.Logger().file_name = os.path.join(
80 tempfile.gettempdir(), "coupling-illustrations-log.md"
81 )
82 coupled = create_host(host_class)
83 single_solver_pictures = {
84 coupled.ccz4: (
85 "Time stepping task graph of CCZ4 (Runge-Kutta 2)",
86 "coupling-graph-ccz4.png",
87 ),
88 coupled.euler: (
89 "Time stepping task graph of Euler (Finite Volumes)",
90 "coupling-graph-euler.png",
91 ),
92 }
93
94 # Each solver builds its time step graph on its own. Draw it before the
95 # coupling adds its dependencies.
96 for solver in coupled.solvers:
97
98 def realise(*args, _solver=solver, _original=solver.generate_solver_realisation, **kwargs):
99 outcome = _original(*args, **kwargs)
100 if single_solver_graphs:
101 plot_graph(args[3], *single_solver_pictures[_solver])
102 return outcome
103
104 solver.generate_solver_realisation = realise
105
106 # The load balancing and AMR tasks are added after the coupling, but they
107 # wrap the graph, i.e. the picture shows the coupling itself
108 scheme = coupled.ccz4.numerical_scheme
109 original_wrap = scheme.wrap_task_graph_in_load_balancing_and_amr_tasks
110
111 def wrap(coupled_time_step):
112 plot_graph(coupled_time_step, title, file_name)
113 original_wrap(coupled_time_step)
114
115 scheme.wrap_task_graph_in_load_balancing_and_amr_tasks = wrap
116
117 with tempfile.TemporaryDirectory() as directory:
118 project = exahype2.api.Project(
119 namespace=["illustration"],
120 project_name="illustration",
121 directory=directory,
122 executable="illustration",
123 )
124 project.add_solver(coupled)
125 project.compiler = peano4.api.taskgraph.compiler.FuseSteps.translate
126 project.set_global_simulation_parameters(
127 dimensions=3,
128 offset=[0.0, 0.0, 0.0],
129 size=[1.0, 1.0, 1.0],
130 min_end_time=0.02,
131 max_end_time=0.02,
132 periodic_BC=[True, True, True],
133 )
134 project.set_Peano4_installation(Root, peano4.api.output.CompileMode.RELEASE)
135 project.generate_Peano4_project(verbosity=peano4.api.LoggerVerbosity.TEXT)
136
137
138if __name__ == "__main__":
139 plot_host(
141 "coupling-graph-outer-additive.png",
142 "Outer additive coupling of CCZ4 (RK2) and Euler (FV)",
143 single_solver_graphs=True,
144 )
145 plot_host(
147 "coupling-graph-outer-multiplicative.png",
148 "Outer multiplicative coupling of CCZ4 (RK2) and Euler (FV)",
149 single_solver_graphs=False,
150 )
First-order CCZ4 and an Euler fluid, coupled only at the begin and the end of each time step.
ExaHyPE 2 project.
Definition Project.py:15
Plotting counterpart to RusanovWithExplicitEuler: maps the patch data of a Finite Volume scheme with ...
Finite Volumes with a Rusanov Riemann solver and explicit Euler time stepping, realised over a block-...
Setup phase counterpart to RusanovWithExplicitEuler: sets the initial condition for a Finite Volume s...
Fourth-order central Finite Differences with explicit Runge-Kutta time stepping, realised over a bloc...
Plotting counterpart of the fourth-order Finite Differences with Runge-Kutta time stepping (exahype2....
Setup phase of the fourth-order Finite Differences with Runge-Kutta time stepping (exahype2....
Singleton logger for the Peano 4 Python API.
Definition Logger.py:37
plot_graph(graph, title, file_name)
plot_host(host_class, file_name, title, single_solver_graphs)
create_host(host_class, ccz4_patch_size=8)
exahype2.api.InitPointWisely gauge_wave()
Gauge wave along the x-axis,.
This file is part of the ExaGRyPE project.
Definition __init__.py:1