preCICE v3.1.2
Loading...
Searching...
No Matches
ExportVTPTest.cpp
Go to the documentation of this file.
1#ifndef PRECICE_NO_MPI
2
3#include <Eigen/Core>
4#include <algorithm>
5#include <map>
6#include <string>
8#include "io/Export.hpp"
9#include "io/ExportVTP.hpp"
10#include "mesh/Mesh.hpp"
12#include "testing/Testing.hpp"
13#include "utils/Parallel.hpp"
14
15namespace precice::mesh {
16class Edge;
17class Vertex;
18} // namespace precice::mesh
19
21
22using namespace precice;
23
24BOOST_AUTO_TEST_SUITE(VTPExport)
25
26BOOST_AUTO_TEST_CASE(ExportDataWithGradient2D)
27{
28 PRECICE_TEST(1_rank)
29 const int dimensions = 2;
30 // Create mesh to map from
31 mesh::Mesh mesh("MyMesh", dimensions, testing::nextMeshID());
32 mesh::PtrData dataScalar = mesh.createData("dataScalar", 1, 0_dataID);
33 mesh::PtrData dataVector = mesh.createData("dataVector", dimensions, 1_dataID);
34 dataScalar->requireDataGradient();
35 dataVector->requireDataGradient();
36 mesh.createVertex(Eigen::Vector2d::Constant(0.0));
37 mesh.createVertex(Eigen::Vector2d::Constant(1.0));
38
39 // Create data
40 mesh.allocateDataValues();
41 Eigen::VectorXd &valuesScalar = dataScalar->values();
42 Eigen::VectorXd &valuesVector = dataVector->values();
43 valuesScalar.setLinSpaced(1., 5.);
44 valuesVector.setLinSpaced(1., 5.);
45
46 // Create corresponding gradient data (all gradient values = const = 1)
47 Eigen::MatrixXd &gradientsScalar = dataScalar->gradients();
48 Eigen::MatrixXd &gradientsVector = dataVector->gradients();
49 gradientsScalar.setOnes();
50 gradientsVector.setOnes();
51 io::ExportVTP exportVTP;
52 std::string filename = "io-VTPExport-ExportDatawithGradient" + std::to_string(dimensions);
53 std::string location = "";
54 exportVTP.doExport(filename, location, mesh);
55}
56
57BOOST_AUTO_TEST_CASE(ExportDataWithGradient3D)
58{
59 PRECICE_TEST(1_rank)
60 const int dimensions = 3;
61 // Create mesh to map from
62 mesh::Mesh mesh("MyMesh", dimensions, testing::nextMeshID());
63 mesh::PtrData dataScalar = mesh.createData("dataScalar", 1, 0_dataID);
64 mesh::PtrData dataVector = mesh.createData("dataVector", dimensions, 1_dataID);
65 dataScalar->requireDataGradient();
66 dataVector->requireDataGradient();
67 mesh.createVertex(Eigen::Vector3d::Constant(0.0));
68 mesh.createVertex(Eigen::Vector3d::Constant(1.0));
69
70 // Create data
71 mesh.allocateDataValues();
72 Eigen::VectorXd &valuesScalar = dataScalar->values();
73 Eigen::VectorXd &valuesVector = dataVector->values();
74
75 valuesScalar.setLinSpaced(1., 5.);
76 valuesVector.setLinSpaced(1., 5.);
77
78 // Create corresponding gradient data (all gradient values = const = 1)
79 Eigen::MatrixXd &gradientsScalar = dataScalar->gradients();
80 Eigen::MatrixXd &gradientsVector = dataVector->gradients();
81 gradientsScalar.setOnes();
82 gradientsVector.setOnes();
83 io::ExportVTP exportVTP;
84 std::string filename = "io-VTPExport-ExportDatawithGradient" + std::to_string(dimensions);
85 std::string location = "";
86 exportVTP.doExport(filename, location, mesh);
87}
88
89BOOST_AUTO_TEST_CASE(ExportPolygonalMeshSerial)
90{
91 PRECICE_TEST(""_on(1_rank).setupIntraComm());
92 int dim = 2;
93 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
94 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Zero());
95 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(1));
96 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0.0});
97
98 mesh.createEdge(v1, v2);
99 mesh.createEdge(v2, v3);
100 mesh.createEdge(v3, v1);
101
102 io::ExportVTP exportVTP;
103 std::string filename = "io-VTPExport-ExportPolygonalMesh";
104 std::string location = "";
105 exportVTP.doExport(filename, location, mesh);
106}
107
108BOOST_AUTO_TEST_CASE(ExportPolygonalMesh)
109{
110 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
111 int dim = 2;
112 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
113
114 if (context.isRank(0)) {
115 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Zero());
116 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(1));
117 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0});
118
119 mesh.createEdge(v1, v2);
120 mesh.createEdge(v2, v3);
121 mesh.createEdge(v3, v1);
122 mesh.setVertexOffsets({3, 3, 6, 7});
123 } else if (context.isRank(1)) {
124 // nothing
125 } else if (context.isRank(2)) {
126 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Constant(1));
127 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(2));
128 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0.0});
129
130 mesh.createEdge(v1, v2);
131 mesh.createEdge(v2, v3);
132 mesh.createEdge(v3, v1);
133 } else if (context.isRank(3)) {
134 mesh.createVertex(Eigen::Vector2d::Constant(3.0));
135 }
136
137 io::ExportVTP exportVTP;
138 std::string filename = "io-ExportVTPTest-testExportPolygonalMesh";
139 std::string location = "";
140 exportVTP.doExport(filename, location, mesh);
141}
142
143BOOST_AUTO_TEST_CASE(ExportTriangulatedMesh)
144{
145 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
146 int dim = 3;
147 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
148
149 if (context.isRank(0)) {
150 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Zero());
151 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d::Constant(1));
152 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
153
154 mesh::Edge &e1 = mesh.createEdge(v1, v2);
155 mesh::Edge &e2 = mesh.createEdge(v2, v3);
156 mesh::Edge &e3 = mesh.createEdge(v3, v1);
157 mesh.createTriangle(e1, e2, e3);
158 mesh.setVertexOffsets({3, 3, 6, 7});
159
160 } else if (context.isRank(1)) {
161 // nothing
162 } else if (context.isRank(2)) {
163 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Constant(1));
164 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d::Constant(2));
165 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{0.0, 1.0, 0.0});
166
167 mesh::Edge &e1 = mesh.createEdge(v1, v2);
168 mesh::Edge &e2 = mesh.createEdge(v2, v3);
169 mesh::Edge &e3 = mesh.createEdge(v3, v1);
170 mesh.createTriangle(e1, e2, e3);
171 } else if (context.isRank(3)) {
172 mesh.createVertex(Eigen::Vector3d::Constant(3.0));
173 }
174
175 io::ExportVTP exportVTP;
176 std::string filename = "io-ExportVTPTest-testExportTriangulatedMesh";
177 std::string location = "";
178 exportVTP.doExport(filename, location, mesh);
179}
180
181BOOST_AUTO_TEST_CASE(ExportSplitSquare)
182{
183 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
184 int dim = 3;
185 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
186
187 mesh::Vertex &vm = mesh.createVertex(Eigen::Vector3d::Zero());
188 if (context.isRank(0)) {
189 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{-1.0, 1.0, 0.0});
190 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{1.0, 1.0, 0.0});
191 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{0.0, 2.0, 0.0});
192 mesh::Edge & em1 = mesh.createEdge(vm, v1);
193 mesh::Edge & e12 = mesh.createEdge(v1, v2);
194 mesh::Edge & e2m = mesh.createEdge(v2, vm);
195 mesh.createTriangle(em1, e12, e2m);
196 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
197 mesh::Edge &e2o = mesh.createEdge(v2, vo);
198 mesh.createTriangle(eo1, e12, e2o);
199
200 mesh.setVertexOffsets({3, 6, 9, 12});
201 } else if (context.isRank(1)) {
202 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{1.0, -1.0, 0.0});
203 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{-1.0, -1.0, 0.0});
204 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{0.0, -2.0, 0.0});
205 mesh::Edge & em1 = mesh.createEdge(vm, v1);
206 mesh::Edge & e12 = mesh.createEdge(v1, v2);
207 mesh::Edge & e2m = mesh.createEdge(v2, vm);
208 mesh.createTriangle(em1, e12, e2m);
209 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
210 mesh::Edge &e2o = mesh.createEdge(v2, vo);
211 mesh.createTriangle(eo1, e12, e2o);
212 } else if (context.isRank(2)) {
213 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{-1.0, 1.0, 0.0});
214 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{-1.0, -1.0, 0.0});
215 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{-2.0, 0.0, 0.0});
216 mesh::Edge & em1 = mesh.createEdge(vm, v1);
217 mesh::Edge & e12 = mesh.createEdge(v1, v2);
218 mesh::Edge & e2m = mesh.createEdge(v2, vm);
219 mesh.createTriangle(em1, e12, e2m);
220 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
221 mesh::Edge &e2o = mesh.createEdge(v2, vo);
222 mesh.createTriangle(eo1, e12, e2o);
223 } else if (context.isRank(3)) {
224 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{1.0, 1.0, 0.0});
225 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{1.0, -1.0, 0.0});
226 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{2.0, 0.0, 0.0});
227 mesh::Edge & em1 = mesh.createEdge(vm, v1);
228 mesh::Edge & e12 = mesh.createEdge(v1, v2);
229 mesh::Edge & e2m = mesh.createEdge(v2, vm);
230 mesh.createTriangle(em1, e12, e2m);
231 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
232 mesh::Edge &e2o = mesh.createEdge(v2, vo);
233 mesh.createTriangle(eo1, e12, e2o);
234 }
235
236 io::ExportVTP exportVTP;
237 std::string filename = "io-ExportVTPTest-Square";
238 std::string location = "";
239 exportVTP.doExport(filename, location, mesh);
240}
241
242BOOST_AUTO_TEST_SUITE_END() // IOTests
243BOOST_AUTO_TEST_SUITE_END() // VTPExport
244
245#endif // PRECICE_NO_MPI
BOOST_AUTO_TEST_CASE(ExportDataWithGradient2D)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
void doExport(const std::string &name, const std::string &location, const mesh::Mesh &mesh) override
Does export. Has to be implemented in subclass.
Definition ExportXML.cpp:23
Linear edge of a mesh, defined by two Vertex objects.
Definition Edge.hpp:16
Container and creator for meshes.
Definition Mesh.hpp:39
Triangle & createTriangle(Edge &edgeOne, Edge &edgeTwo, Edge &edgeThree)
Creates and initializes a Triangle object.
Definition Mesh.cpp:119
PtrData & createData(const std::string &name, int dimension, DataID id, int waveformDegree=time::Time::DEFAULT_WAVEFORM_DEGREE)
Create only data for vertex.
Definition Mesh.cpp:151
void setVertexOffsets(VertexOffsets vertexOffsets)
Only used for tests.
Definition Mesh.hpp:254
Edge & createEdge(Vertex &vertexOne, Vertex &vertexTwo)
Creates and initializes an Edge object.
Definition Mesh.cpp:111
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
Vertex of a mesh.
Definition Vertex.hpp:16
provides Mesh, Data and primitives.
Main namespace of the precice library.
T to_string(T... args)