Peano
Loading...
Searching...
No Matches
SolverRepositoryGenerator.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
3import peano4.api
5
6from ..Project import Project
7
8
10 """!
11
12 Generates repositories/SolverRepository.h/.cpp: one extern instance per
13 solver registered with the project, plus getMinTimeStamp()/
14 getMaxTimeStamp() aggregating over all of them.
15
16 """
17
18 TEMPLATE_HEADER_FILE = """
19// This file is part of the ExaHyPE2 project. For conditions of distribution and
20// use, please see the copyright notice at www.peano-framework.org
21#pragma once
22
23{% for item in SOLVERS -%}
24#include "{{ item[0] }}.h"
25{# Comment to ensure that jinja2 adds a new line#}
26{% endfor %}
27
28
29{% for item in NAMESPACE -%}
30namespace {{ item }} {
31{%- endfor %}
32
33 {% for item in SOLVERS -%}
34 extern {{ item[0] }} {{ item[1] }};
35 {# Comment to ensure that jinja2 adds a new line#}
36 {%- endfor %}
37
38 /**
39 * Return the global min time stamp over all solvers.
40 */
41 double getMinTimeStamp();
42
43 /**
44 * Return the global max time stamp over all solvers.
45 */
46 double getMaxTimeStamp();
47
48 /**
49 * Return the global min time step size over all solvers.
50 */
51 double getMinTimeStepSize();
52
53 /**
54 * Return the global max time step size over all solvers.
55 */
56 double getMaxTimeStepSize();
57
58 /**
59 * Does any solver want to plot? Only solvers with a plotter are asked.
60 * Each plotter then decides itself within the plot phase whether it
61 * plots (@see exahype2.api.Solver.Plotter).
62 */
63 bool wantsToPlot();
64
65{% for item in NAMESPACE -%}
66}
67{%- endfor %}
68"""
69
70 TEMPLATE_CPP_FILE = """
71// This file is part of the ExaHyPE2 project. For conditions of distribution and
72// use, please see the copyright notice at www.peano-framework.org
73#include "SolverRepository.h"
74
75#include <algorithm>
76#include <limits>
77
78{% for item in NAMESPACE -%}
79namespace {{ item }} {
80{%- endfor %}
81
82 {% for item in SOLVERS -%}
83 {{ item[0] }} {{ item[1] }};
84 {# Comment to ensure that jinja2 adds a new line#}
85 {%- endfor %}
86
87
88 double getMinTimeStamp() {
89 double result = std::numeric_limits<double>::max();
90 {% for item in SOLVERS -%}
91 result = std::min( result, {{ item[1] }}.getMinTimeStamp() );
92 {# Comment to ensure that jinja2 adds a new line#}
93 {%- endfor %}
94 return result;
95 }
96
97
98 double getMaxTimeStamp() {
99 double result = 0.0;
100 {% for item in SOLVERS -%}
101 result = std::max( result, {{ item[1] }}.getMaxTimeStamp() );
102 {# Comment to ensure that jinja2 adds a new line#}
103 {%- endfor %}
104 return result;
105 }
106
107
108 double getMinTimeStepSize() {
109 double result = std::numeric_limits<double>::max();
110 {% for item in SOLVERS -%}
111 result = std::min( result, {{ item[1] }}.getMinTimeStepSize() );
112 {# Comment to ensure that jinja2 adds a new line#}
113 {%- endfor %}
114 return result;
115 }
116
117
118 double getMaxTimeStepSize() {
119 double result = 0.0;
120 {% for item in SOLVERS -%}
121 result = std::max( result, {{ item[1] }}.getMaxTimeStepSize() );
122 {# Comment to ensure that jinja2 adds a new line#}
123 {%- endfor %}
124 return result;
125 }
126
127
128 bool wantsToPlot() {
129 bool result = false;
130 {% for item in PLOTTING_SOLVERS -%}
131 result |= {{ item }}.wantsToPlot();
132 {# Comment to ensure that jinja2 adds a new line#}
133 {%- endfor %}
134 return result;
135 }
136
137{% for item in NAMESPACE -%}
138}
139{%- endfor %}
140"""
141
142 def __init__(self, project: Project):
143 super().__init__(project)
144
147 "SOLVERS": [],
148 "PLOTTING_SOLVERS": [],
149 "LOAD_BALANCER": self.project._load_balancer_name,
150 "LOAD_BALANCER_ARGUMENTS": self.project._load_balancer_arguments,
151 "LOG_FILTER_FILE": self.project._log_filter_file,
152 "NUMBER_OF_THREADS": self.project._number_of_threads,
153 "MULTICORE_ORCHESTRATION": self.project._multicore_orchestration,
154 "TIMEOUT": self.project._timeout,
155 "GPUS": self.project._gpus,
156 "ADDITIONAL_INCLUDES": self.project._additional_includes,
157 }
158
159 def construct_output(self, peano_project):
161
162 for solver in self.project._solvers:
163 self.solverRepositoryDictionary["SOLVERS"].append(
164 (solver.get_name_of_solver_class(), solver.get_name_of_global_instance())
165 )
166 if solver.plotters:
167 self.solverRepositoryDictionary["PLOTTING_SOLVERS"].append(
168 solver.get_name_of_global_instance()
169 )
170
171 generated_solver_files = (
175 "SolverRepository",
176 peano_project.namespace + ["repositories"],
177 peano_project.subdirectory + "repositories",
179 True,
180 )
181 )
182
183 peano_project.output.add(generated_solver_files)
184 peano_project.output.makefile.add_cpp_file(
185 peano_project.subdirectory + "repositories/SolverRepository.cpp", generated=True
186 )
Base class for the code generation steps that turn an ExaHyPE 2 Project's configuration into actual g...
Definition Project.py:35
Generates repositories/SolverRepository.h/.cpp: one extern instance per solver registered with the pr...
construct_output(self, peano_project)
Add this generator's output to peano_project (a peano4.api.Project-compatible object,...