preCICE v3.2.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
ValidationMacros.hpp
Go to the documentation of this file.
1#pragma once
2
9//
10// MESH VALIDATION
11//
12
17#include "utils/stacktrace.hpp"
18#define PRECICE_VALIDATE_MESH_NAME_IMPL(name) \
19 PRECICE_CHECK(_accessor->hasMesh(name), \
20 "The mesh named \"{}\" is unknown to preCICE.{}", \
21 name, _accessor->hintForMesh(name));
22
27#define PRECICE_REQUIRE_MESH_USE_IMPL(name) \
28 PRECICE_VALIDATE_MESH_NAME_IMPL(name) \
29 PRECICE_CHECK(_accessor->isMeshUsed(name), \
30 "This participant does not use the mesh \"{0}\", but attempted to access it. " \
31 "Please define a <provide-mesh name=\"{0}\" /> or <receive-mesh name=\"{0}\" from=\"...\" /> " \
32 "tag in the configuration of participant \" {1}.", \
33 name, _accessorName);
34
39#define PRECICE_REQUIRE_MESH_PROVIDE_IMPL(name) \
40 PRECICE_REQUIRE_MESH_USE_IMPL(name) \
41 PRECICE_CHECK(_accessor->isMeshProvided(name), \
42 "This participant does not provide Mesh \"{0}\", but attempted to modify it. " \
43 "Please add a provide-mesh tag as follows <provide-mesh name=\"{0}\" />.", \
44 name);
45
50#define PRECICE_REQUIRE_MESH_MODIFY_IMPL(name) \
51 PRECICE_REQUIRE_MESH_PROVIDE_IMPL(name) \
52 PRECICE_CHECK(!_meshLock.check(name), \
53 "This participant attempted to modify the Mesh \"{}\" while locked. " \
54 "Mesh modification is only allowed before calling initialize().", \
55 name);
56
61#define PRECICE_VALIDATE_MESH_DATA_ACCESS_IMPL(name) \
62 PRECICE_VALIDATE_MESH_NAME_IMPL(name) \
63 PRECICE_CHECK(_accessor->isMeshProvided(name) || _accessor->isDirectAccessAllowed(name), \
64 "This participant does not provide Mesh \"{0}\" nor does it enable direct access to it. " \
65 "To provide the mesh add a provide-mesh tag as follows <provide-mesh name=\"{0}\" />. " \
66 "To enable direct access to the mesh please add a receive-mesh tag as follows " \
67 "<receive-mesh name=\"{0}\" from=\"...\" api-access=\"true\" />, or modify an existing one. ", \
68 name);
69
73#define PRECICE_VALIDATE_MESH_NAME(name) \
74 do { \
75 PRECICE_VALIDATE_MESH_NAME_IMPL(name) \
76 } while (false)
77
81#define PRECICE_REQUIRE_MESH_USE(name) \
82 do { \
83 PRECICE_REQUIRE_MESH_USE_IMPL(name) \
84 } while (false)
85
89#define PRECICE_REQUIRE_MESH_PROVIDE(name) \
90 do { \
91 PRECICE_REQUIRE_MESH_PROVIDE_IMPL(name) \
92 } while (false)
93
97#define PRECICE_REQUIRE_MESH_MODIFY(name) \
98 do { \
99 PRECICE_REQUIRE_MESH_MODIFY_IMPL(name) \
100 } while (false)
101
102//
103// DATA VALIDATION
104//
105
110#define PRECICE_VALIDATE_DATA_NAME_IMPL(mesh, data) \
111 PRECICE_CHECK(_accessor->hasData(mesh, data), \
112 "The given data \"{}\" is unknown to preCICE mesh \"{}\".{}", data, mesh, _accessor->hintForMeshData(mesh, data));
113
118#define PRECICE_REQUIRE_DATA_READ_IMPL(mesh, data) \
119 PRECICE_VALIDATE_DATA_NAME_IMPL(mesh, data) \
120 PRECICE_CHECK((_accessor->isDataRead(mesh, data)), \
121 "This participant does not use data \"{0}\" via mesh \"{2}\", but attempted to read it. " \
122 "Please extend the configuration of participant \"{1}\" by defining <read-data mesh=\"{2}\" name=\"{0}\" /> " \
123 "or check if the data is defined on this mesh.", \
124 data, _accessorName, mesh);
125
130#define PRECICE_REQUIRE_DATA_WRITE_IMPL(mesh, data) \
131 PRECICE_VALIDATE_DATA_NAME_IMPL(mesh, data) \
132 PRECICE_CHECK((_accessor->isDataWrite(mesh, data)), \
133 "This participant does not use data \"{0}\" via mesh \"{2}\", but attempted to write it. " \
134 "Please extend the configuration of participant \"{1}\" by defining <write-data mesh=\"{2}\" name=\"{0}\" /> " \
135 "or check if the data is defined on this mesh.", \
136 data, _accessorName, mesh);
137
141#define PRECICE_VALIDATE_DATA_NAME(mesh, data) \
142 do { \
143 PRECICE_VALIDATE_DATA_NAME_IMPL(mesh, data) \
144 } while (false)
145
149#define PRECICE_REQUIRE_DATA_READ(mesh, data) \
150 do { \
151 PRECICE_VALIDATE_MESH_DATA_ACCESS_IMPL(mesh) \
152 PRECICE_REQUIRE_DATA_READ_IMPL(mesh, data) \
153 } while (false)
154
158#define PRECICE_REQUIRE_DATA_WRITE(mesh, data) \
159 do { \
160 PRECICE_VALIDATE_MESH_DATA_ACCESS_IMPL(mesh) \
161 PRECICE_REQUIRE_DATA_WRITE_IMPL(mesh, data) \
162 } while (false)
163
164//
165// DATA VALUE VALIDATION
166//
167#ifdef NDEBUG
168
169#define PRECICE_VALIDATE_DATA(data, size) \
170 { \
171 }
172#else // NDEBUG
173
174#define PRECICE_VALIDATE_DATA(data, size) \
175 PRECICE_CHECK(std::all_of(data, data + size, [](double val) { return std::isfinite(val); }), "One of the given data values is either plus or minus infinity or NaN.");
176
177#endif
178
179#define PRECICE_EXPERIMENTAL_API() \
180 PRECICE_CHECK(_allowsExperimental, "You called the API function \"{}\", which is part of the experimental API. " \
181 "You may unlock the full API by specifying <precice-configuration experimental=\"true\" ... > in the configuration. " \
182 "Please be aware that experimental features may change in any future version (even minor or bugfix).", \
183 __func__)