preCICE v3.1.2
Loading...
Searching...
No Matches
MappingConfigurationTest.cpp
Go to the documentation of this file.
1#include <memory>
2#include <string>
3#include <vector>
4#include "logging/Logger.hpp"
5#include "mapping/Mapping.hpp"
11#include "testing/Testing.hpp"
12#include "xml/XMLTag.hpp"
13
14using namespace precice;
15using namespace precice::mapping;
16
17BOOST_AUTO_TEST_SUITE(MappingTests)
18BOOST_AUTO_TEST_SUITE(Configuration)
19
21{
22 PRECICE_TEST(1_rank);
23
24 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
25 std::string file(pathToTests + "mapping-config.xml");
26 using xml::XMLTag;
27 XMLTag tag = xml::getRootTag();
29 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
30 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
32
33 BOOST_TEST(meshConfig->meshes().size() == 3);
34 BOOST_TEST(mappingConfig.mappings().size() == 3);
35 BOOST_TEST(mappingConfig.mappings().at(0).fromMesh == meshConfig->meshes().at(0));
36 BOOST_TEST(mappingConfig.mappings().at(0).toMesh == meshConfig->meshes().at(2));
37 BOOST_TEST(mappingConfig.mappings().at(0).direction == MappingConfiguration::WRITE);
38
39 BOOST_TEST(mappingConfig.mappings().at(1).fromMesh == meshConfig->meshes().at(2));
40 BOOST_TEST(mappingConfig.mappings().at(1).toMesh == meshConfig->meshes().at(1));
41 BOOST_TEST(mappingConfig.mappings().at(1).direction == MappingConfiguration::READ);
42
43 BOOST_TEST(mappingConfig.mappings().at(2).fromMesh == meshConfig->meshes().at(1));
44 BOOST_TEST(mappingConfig.mappings().at(2).toMesh == meshConfig->meshes().at(0));
45 BOOST_TEST(mappingConfig.mappings().at(2).direction == MappingConfiguration::WRITE);
46}
47
48BOOST_AUTO_TEST_CASE(RBFDirectConfiguration)
49{
50 PRECICE_TEST(1_rank);
51
52 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
53 std::string file(pathToTests + "mapping-rbf-direct-config.xml");
54 using xml::XMLTag;
55 XMLTag tag = xml::getRootTag();
57 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
58 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
60
61 BOOST_TEST(meshConfig->meshes().size() == 13);
62 BOOST_TEST(mappingConfig.mappings().size() == 12);
63 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
64 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
65 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
66 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
67 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::READ);
68 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
69 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
70 }
71 {
72 // last configured RBF
73 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::GlobalDirect;
74 BOOST_TEST(solverSelection);
75 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
76 BOOST_TEST(poly);
77 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == true);
78 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
79 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == true);
80 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-9);
81 }
82}
83
84BOOST_AUTO_TEST_CASE(RBFPUMConfiguration)
85{
86 PRECICE_TEST(1_rank);
87
88 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
89 std::string file(pathToTests + "mapping-rbf-pum-direct-config.xml");
90 using xml::XMLTag;
91 XMLTag tag = xml::getRootTag();
93 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
94 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
96
97 BOOST_TEST(meshConfig->meshes().size() == 13);
98 BOOST_TEST(mappingConfig.mappings().size() == 12);
99 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
100 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
101 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
102 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
103 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::READ);
104 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
105 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
106 }
107 {
108 // last configured RBF
109 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::PUMDirect;
110 BOOST_TEST(solverSelection);
111 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
112 BOOST_TEST(poly);
113 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-9);
114 BOOST_TEST(mappingConfig.rbfConfig().verticesPerCluster == 10);
115 BOOST_TEST(mappingConfig.rbfConfig().relativeOverlap == 0.4);
116 BOOST_TEST(mappingConfig.rbfConfig().projectToInput == true);
117 }
118}
119
120#ifndef PRECICE_NO_PETSC
121
122BOOST_AUTO_TEST_CASE(RBFIterativeConfiguration)
123{
124 PRECICE_TEST(1_rank, Require::PETSc);
125
126 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
127 std::string file(pathToTests + "mapping-rbf-iterative-config.xml");
128 using xml::XMLTag;
129 XMLTag tag = xml::getRootTag();
131 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
132 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
134
135 BOOST_TEST(meshConfig->meshes().size() == 13);
136 BOOST_TEST(mappingConfig.mappings().size() == 12);
137 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
138 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
139 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
140 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
141 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::WRITE);
142 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
143 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
144 }
145 {
146 // last configured RBF
147 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::GlobalIterative;
148 BOOST_TEST(solverSelection);
149 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
150 BOOST_TEST(poly);
151 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == true);
152 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
153 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == true);
154 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-6);
155 }
156}
157#endif
158
159BOOST_AUTO_TEST_CASE(RBFAliasConfiguration)
160{
161 PRECICE_TEST(1_rank, Require::PETSc);
162
163 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
164 std::string file(pathToTests + "mapping-rbf-alias-config.xml");
165 using xml::XMLTag;
166 XMLTag tag = xml::getRootTag();
168 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
169 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
171
172 BOOST_TEST(meshConfig->meshes().size() == 3);
173 BOOST_TEST(mappingConfig.mappings().size() == 2);
174 BOOST_TEST(mappingConfig.mappings().at(0).mapping != nullptr);
175 BOOST_TEST(mappingConfig.mappings().at(0).fromMesh == meshConfig->meshes().at(0));
176 BOOST_TEST(mappingConfig.mappings().at(0).toMesh == meshConfig->meshes().at(2));
177 BOOST_TEST(mappingConfig.mappings().at(0).direction == MappingConfiguration::WRITE);
178 BOOST_TEST(mappingConfig.mappings().at(0).requiresBasisFunction == true);
179 BOOST_TEST(mappingConfig.mappings().at(0).configuredWithAliasTag == true);
180
181 // The second mapping
182 BOOST_TEST(mappingConfig.mappings().at(1).mapping != nullptr);
183 BOOST_TEST(mappingConfig.mappings().at(1).fromMesh == meshConfig->meshes().at(2));
184 BOOST_TEST(mappingConfig.mappings().at(1).toMesh == meshConfig->meshes().at(1));
185 BOOST_TEST(mappingConfig.mappings().at(1).direction == MappingConfiguration::READ);
186 BOOST_TEST(mappingConfig.mappings().at(1).requiresBasisFunction == true);
187 BOOST_TEST(mappingConfig.mappings().at(1).configuredWithAliasTag == true);
188 {
189 // last configured RBF
190 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::PUMDirect;
191 BOOST_TEST(solverSelection);
192 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::SEPARATE;
193 BOOST_TEST(poly);
194 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == false);
195 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
196 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == false);
197 BOOST_TEST(mappingConfig.rbfConfig().verticesPerCluster == 100);
198 BOOST_TEST(mappingConfig.rbfConfig().relativeOverlap == 0.3);
199 BOOST_TEST(mappingConfig.rbfConfig().projectToInput == true);
200 }
201}
202
203#ifndef PRECICE_NO_GINKGO
204
205#ifdef PRECICE_WITH_CUDA
206// This test mostly runs the configuration path, but it does not test the actual
207// setting in the Ginkgo solver class (being a cuda executor), since the mapping
208// configuration does not expose this information
209BOOST_AUTO_TEST_CASE(RBFGinkgoCudaConfiguration)
210{
211 PRECICE_TEST(1_rank);
212
213 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
214 std::string file(pathToTests + "mapping-rbf-cuda-config.xml");
215 using xml::XMLTag;
216 XMLTag tag = xml::getRootTag();
218 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
219 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
221
222 BOOST_TEST(meshConfig->meshes().size() == 3);
223 BOOST_TEST(mappingConfig.mappings().size() == 2);
224 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
225 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
226 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
227 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
228 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::READ);
229 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
230 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
231 }
232 {
233 // last configured RBF
234 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::GlobalIterative;
235 BOOST_TEST(solverSelection);
236 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
237 BOOST_TEST(poly);
238 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == true);
239 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
240 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == true);
241 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-6);
242 }
243}
244#endif
245
246#ifdef PRECICE_WITH_HIP
247// This test mostly runs the configuration path, but it does not test the actual
248// setting in the Ginkgo solver class (being a hip executor), since the mapping
249// configuration does not expose this information
250BOOST_AUTO_TEST_CASE(RBFGinkgoHipConfiguration)
251{
252 PRECICE_TEST(1_rank);
253
254 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
255 std::string file(pathToTests + "mapping-rbf-hip-config.xml");
256 using xml::XMLTag;
257 XMLTag tag = xml::getRootTag();
259 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
260 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
262
263 BOOST_TEST(meshConfig->meshes().size() == 3);
264 BOOST_TEST(mappingConfig.mappings().size() == 2);
265 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
266 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
267 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
268 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
269 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::READ);
270 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
271 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
272 }
273 {
274 // last configured RBF
275 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::GlobalIterative;
276 BOOST_TEST(solverSelection);
277 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
278 BOOST_TEST(poly);
279 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == true);
280 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
281 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == true);
282 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-6);
283 }
284}
285#endif
286
287#ifdef PRECICE_WITH_OMP
288// This test mostly runs the configuration path, but it does not test the actual
289// setting in the Ginkgo solver class (being an OpenMP executor), since the mapping
290// configuration does not expose this information
291BOOST_AUTO_TEST_CASE(RBFGinkgoOMPConfiguration)
292{
293 PRECICE_TEST(1_rank);
294
295 std::string pathToTests = testing::getPathToSources() + "/mapping/tests/";
296 std::string file(pathToTests + "mapping-rbf-omp-config.xml");
297 using xml::XMLTag;
298 XMLTag tag = xml::getRootTag();
300 mesh::PtrMeshConfiguration meshConfig(new mesh::MeshConfiguration(tag, dataConfig));
301 mapping::MappingConfiguration mappingConfig(tag, meshConfig);
303
304 BOOST_TEST(meshConfig->meshes().size() == 2);
305 BOOST_TEST(mappingConfig.mappings().size() == 1);
306 for (unsigned int i = 0; i < mappingConfig.mappings().size(); ++i) {
307 BOOST_TEST(mappingConfig.mappings().at(i).mapping != nullptr);
308 BOOST_TEST(mappingConfig.mappings().at(i).fromMesh == meshConfig->meshes().at(i + 1));
309 BOOST_TEST(mappingConfig.mappings().at(i).toMesh == meshConfig->meshes().at(i));
310 BOOST_TEST(mappingConfig.mappings().at(i).direction == MappingConfiguration::WRITE);
311 BOOST_TEST(mappingConfig.mappings().at(i).requiresBasisFunction == true);
312 BOOST_TEST(mappingConfig.mappings().at(i).configuredWithAliasTag == false);
313 }
314 {
315 // last configured RBF
316 bool solverSelection = mappingConfig.rbfConfig().solver == MappingConfiguration::RBFConfiguration::SystemSolver::GlobalIterative;
317 BOOST_TEST(solverSelection);
318 bool poly = mappingConfig.rbfConfig().polynomial == Polynomial::OFF;
319 BOOST_TEST(poly);
320 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[0] == true);
321 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[1] == false);
322 BOOST_TEST(mappingConfig.rbfConfig().deadAxis[2] == true);
323 BOOST_TEST(mappingConfig.rbfConfig().solverRtol == 1e-6);
324 }
325}
326#endif
327#endif
328
BOOST_AUTO_TEST_CASE(Configuration)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Performs XML configuration and holds configured mappings.
const std::vector< ConfiguredMapping > & mappings()
Returns all configured mappings.
const RBFConfiguration & rbfConfig() const
Performs and provides configuration for Data objects from XML files.
Represents an XML tag to be configured automatically.
Definition XMLTag.hpp:31
contains data mapping from points to meshes.
std::string getPathToSources()
Returns the base path to the sources.
Definition Testing.cpp:31
XMLTag getRootTag()
Returns an XMLTag::Listener that does nothing on callbacks.
Definition XMLTag.cpp:389
void configure(XMLTag &tag, const precice::xml::ConfigurationContext &context, std::string_view configurationFilename)
Configures the given configuration from file configurationFilename.
Definition XMLTag.cpp:395
Main namespace of the precice library.
T size(T... args)
Tightly coupled to the parameters of Participant()
Definition XMLTag.hpp:24