preCICE v3.1.1
Loading...
Searching...
No Matches
AxialGeoMultiscaleMappingTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <memory>
6#include "mapping/Mapping.hpp"
7#include "math/constants.hpp"
8#include "mesh/Data.hpp"
9#include "mesh/Mesh.hpp"
11#include "mesh/Utils.hpp"
12#include "mesh/Vertex.hpp"
14#include "testing/Testing.hpp"
15
16using namespace precice;
17using namespace precice::mesh;
18
19BOOST_AUTO_TEST_SUITE(MappingTests)
20BOOST_AUTO_TEST_SUITE(AxialGeoMultiscaleMapping)
21
22BOOST_AUTO_TEST_CASE(ConsistentSpreadX)
23{
24 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the x-axis.
25 Then, the data is mapped from the single vertex of the 1D mesh to defined vertices on the circular inlet of the 3D mesh (hence, "spread").
26 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
27 Finally, this expected behavior is tested.
28 */
29
30 PRECICE_TEST(1_rank);
31 constexpr int dimensions = 3;
32 using testing::equals;
33
34 // Create mesh to map from
35 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID())); // Point a (1D)
36 inMesh->createVertex(Eigen::Vector3d::Constant(0.0));
37 inMesh->allocateDataValues();
38
39 // Create mesh to map to
40 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
41 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
42 outMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point B (3D): distance of 1.0 = r to center
43 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
44 outMesh->allocateDataValues();
45
46 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
47
48 // Setup mapping with mapping coordinates and geometry used
49 precice::mapping::AxialGeoMultiscaleMapping mapping(mapping::Mapping::CONSISTENT, dimensions, mapping::AxialGeoMultiscaleMapping::MultiscaleType::SPREAD, mapping::AxialGeoMultiscaleMapping::MultiscaleAxis::X, radius);
50 mapping.setMeshes(inMesh, outMesh);
51 BOOST_TEST(mapping.hasComputedMapping() == false);
52
53 // Create data to map
54 Eigen::VectorXd inValues(3);
55 inValues << 2.0, 0.0, 0.0;
56 const time::Sample inSample{3, inValues};
57 Eigen::VectorXd outValues(9);
58 outValues = Eigen::VectorXd::Zero(9);
59
60 // Map data
61 mapping.computeMapping();
62 mapping.computeMapping(); // Check (only in this case) if calling computeMapping() additional times works.
63 mapping.map(inSample, outValues);
64
65 BOOST_TEST(mapping.hasComputedMapping() == true);
66 mapping.computeMapping(); // Check (only in this case) if calling computeMapping() additional times works.
67
68 // Point A (3D): Check if x axis data is doubled at center node (parabolic profile)
69 BOOST_TEST(outValues(0) == 2 * inSample.values(0));
70 BOOST_TEST(outValues(1) == 0);
71 BOOST_TEST(outValues(2) == 0);
72
73 // Point B (3D): Check if x axis data at distance = r is equal to zero
74 BOOST_TEST(outValues(3) == 0.0);
75 BOOST_TEST(outValues(4) == 0.0);
76 BOOST_TEST(outValues(5) == 0.0);
77
78 // Point C (3D): Check if x axis data at distance = r/2 is 3/2 times invalue data
79 BOOST_TEST(outValues(6) == 1.5 * inSample.values(0));
80 BOOST_TEST(outValues(7) == 0.0);
81 BOOST_TEST(outValues(8) == 0.0);
82}
83
84BOOST_AUTO_TEST_CASE(ConsistentSpreadZ)
85{
86 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the z-axis.
87 Then, the data is mapped from the single vertex of the 1D mesh to defined vertices on the circular inlet of the 3D mesh (hence, "spread").
88 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
89 Finally, this expected behavior is tested.
90 */
91
92 PRECICE_TEST(1_rank);
93 constexpr int dimensions = 3;
94 using testing::equals;
95
96 // Create mesh to map from
97 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
98 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (1D)
99 inMesh->allocateDataValues();
100
101 // Create mesh to map to
102 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
103 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (3D): center, equal to incoming mesh node
104 outMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // Point B (3D): distance of 1.0 = r to center
105 outMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point C (3D): distance of 0.5 = r/2 to center
106 outMesh->allocateDataValues();
107
108 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
109
110 // Setup mapping with mapping coordinates and geometry used
111 precice::mapping::AxialGeoMultiscaleMapping mapping(mapping::Mapping::CONSISTENT, dimensions, mapping::AxialGeoMultiscaleMapping::MultiscaleType::SPREAD, mapping::AxialGeoMultiscaleMapping::MultiscaleAxis::Z, radius);
112 mapping.setMeshes(inMesh, outMesh);
113 BOOST_TEST(mapping.hasComputedMapping() == false);
114
115 // Create data to map
116 Eigen::VectorXd inValues(3);
117 inValues << 0.0, 0.0, 2.0;
118 const time::Sample inSample{3, inValues};
119 Eigen::VectorXd outValues(9);
120 outValues = Eigen::VectorXd::Zero(9);
121
122 // Map data
123 mapping.computeMapping();
124 mapping.map(inSample, outValues);
125
126 BOOST_TEST(mapping.hasComputedMapping() == true);
127
128 // Point A (3D): Check if x axis data is doubled at center node
129 BOOST_TEST(outValues(0) == 0.0);
130 BOOST_TEST(outValues(1) == 0.0);
131 BOOST_TEST(outValues(2) == 2 * inSample.values(2));
132
133 // Point B (3D): Check if x axis data at distance = r is equal to zero
134 BOOST_TEST(outValues(3) == 0.0);
135 BOOST_TEST(outValues(4) == 0.0);
136 BOOST_TEST(outValues(5) == 0.0);
137
138 // Point C (3D): Check if x axis data at distance = r/2 is 3/2 times invalue data
139 BOOST_TEST(outValues(6) == 0.0);
140 BOOST_TEST(outValues(7) == 0.0);
141 BOOST_TEST(outValues(8) == 1.5 * inSample.values(2));
142}
143
144BOOST_AUTO_TEST_CASE(ConsistentCollectX)
145{
146 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the x-axis.
147 Then, the data is mapped from multiple defined vertices on the circular inlet of the 3D mesh to the single vertex of the 1D mesh (hence, "collect").
148 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
149 Finally, this expected behavior is tested.
150 */
151
152 PRECICE_TEST(1_rank);
153 constexpr int dimensions = 3;
154 using testing::equals;
155
156 // Create mesh to map from
157 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
158 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (3D): center
159 inMesh->createVertex(Eigen::Vector3d(0.0, 0.0, 1.0)); // Point b (3D): distance of 1.0 = r to center
160 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point c (3D): distance of 0.5 = r/2 to center
161 inMesh->allocateDataValues();
162
163 // Create mesh to map to
164 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
165 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (1D): equal to center of incoming mesh (averaging)
166 outMesh->allocateDataValues();
167
168 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
169
170 // Setup mapping with mapping coordinates and geometry used
171 precice::mapping::AxialGeoMultiscaleMapping mapping(mapping::Mapping::CONSISTENT, dimensions, mapping::AxialGeoMultiscaleMapping::MultiscaleType::COLLECT, mapping::AxialGeoMultiscaleMapping::MultiscaleAxis::X, radius);
172 mapping.setMeshes(inMesh, outMesh);
173 BOOST_TEST(mapping.hasComputedMapping() == false);
174
175 // Create data to map
176 Eigen::VectorXd inValues(9);
177 inValues << 1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0, 0.0, 0.0;
178 const time::Sample inSample{3, inValues};
179 Eigen::VectorXd outValues(3);
180 outValues = Eigen::VectorXd::Zero(3);
181
182 // Map data
183 mapping.computeMapping();
184 mapping.map(inSample, outValues);
185
186 BOOST_TEST(mapping.hasComputedMapping() == true);
187
188 // Point A (1D): Check if data is averaged at center node
189 BOOST_TEST(outValues(0) == (1 / 3.0) * (inSample.values(0) + inSample.values(3) + inSample.values(6)));
190 BOOST_TEST(outValues(1) == 0.0);
191 BOOST_TEST(outValues(2) == 0.0);
192}
193
194BOOST_AUTO_TEST_CASE(ConsistentCollectZ)
195{
196 /* The following test works by creating two dimensionally heterogeneous meshes, namely 1D and 3D, coupled along the z-axis.
197 Then, the data is mapped from multiple defined vertices on the circular inlet of the 3D mesh to the single vertex of the 1D mesh (hence, "collect").
198 The defined vertices are at certain distances from the center, which enables to predict the expected behavior for Hagen-Poiseuille flow.
199 Finally, this expected behavior is tested.
200 */
201
202 PRECICE_TEST(1_rank);
203 constexpr int dimensions = 3;
204 using testing::equals;
205
206 // Create mesh to map from
207 PtrMesh inMesh(new Mesh("InMesh", dimensions, testing::nextMeshID()));
208 inMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point a (3D): center
209 inMesh->createVertex(Eigen::Vector3d(1.0, 0.0, 0.0)); // Point b (3D): distance of 1.0 = r to center
210 inMesh->createVertex(Eigen::Vector3d(0.0, 0.5, 0.0)); // Point c (3D): distance of 0.5 = r/2 to center
211 inMesh->allocateDataValues();
212
213 // Create mesh to map to
214 PtrMesh outMesh(new Mesh("OutMesh", dimensions, testing::nextMeshID()));
215 outMesh->createVertex(Eigen::Vector3d::Constant(0.0)); // Point A (1D): equal to center of incoming mesh
216 outMesh->allocateDataValues();
217
218 double radius = 1.0; // radius of the "tube" from or to which the data is mapped, i.e., radius of the circular interface between the two participants
219
220 // Setup mapping with mapping coordinates and geometry used
221 precice::mapping::AxialGeoMultiscaleMapping mapping(mapping::Mapping::CONSISTENT, dimensions, mapping::AxialGeoMultiscaleMapping::MultiscaleType::COLLECT, mapping::AxialGeoMultiscaleMapping::MultiscaleAxis::Z, radius);
222 mapping.setMeshes(inMesh, outMesh);
223 BOOST_TEST(mapping.hasComputedMapping() == false);
224
225 // Create data to map
226 Eigen::VectorXd inValues(9);
227 inValues << 0.0, 0.0, 1.0, 0.0, 0.0, 2.0, 0.0, 0.0, 3.0;
228 const time::Sample inSample{3, inValues};
229 Eigen::VectorXd outValues(3);
230 outValues = Eigen::VectorXd::Zero(3);
231
232 // Map data
233 mapping.computeMapping();
234 mapping.map(inSample, outValues);
235
236 BOOST_TEST(mapping.hasComputedMapping() == true);
237
238 // Point A (1D): Check if data is averaged at center node
239 BOOST_TEST(outValues(0) == 0.0);
240 BOOST_TEST(outValues(1) == 0.0);
241 BOOST_TEST(outValues(2) == (1 / 3.0) * (inSample.values(2) + inSample.values(5) + inSample.values(8)));
242}
243
BOOST_AUTO_TEST_CASE(ConsistentSpreadX)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Geometric multiscale mapping in axial direction.
void computeMapping() override
Takes care of compute-heavy operations needed only once to set up the mapping.
void setMeshes(const mesh::PtrMesh &input, const mesh::PtrMesh &output)
Sets input and output meshes carrying data to be mapped.
Definition Mapping.cpp:27
bool hasComputedMapping() const
Returns true, if the mapping has been computed.
Definition Mapping.cpp:252
void map(int inputDataID, int outputDataID)
Definition Mapping.cpp:126
Container and creator for meshes.
Definition Mesh.hpp:39
Vertex & createVertex(const Eigen::VectorXd &coords)
Creates and initializes a Vertex object.
Definition Mesh.cpp:103
void allocateDataValues()
Allocates memory for the vertex data values and corresponding gradient values.
Definition Mesh.cpp:233
provides Mesh, Data and primitives.
boost::test_tools::predicate_result equals(const std::vector< float > &VectorA, const std::vector< float > &VectorB, float tolerance)
equals to be used in tests. Compares two std::vectors using a given tolerance. Prints both operands o...
Definition Testing.cpp:65
Main namespace of the precice library.