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