preCICE v3.1.1
Loading...
Searching...
No Matches
ExportCSVTest.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/ExportCSV.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(CSVExport)
25
26BOOST_AUTO_TEST_CASE(ExportPolygonalMeshSerial)
27{
28 PRECICE_TEST(""_on(1_rank).setupIntraComm());
29 int dim = 2;
30 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
31 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Zero());
32 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(1));
33 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0.0});
34
35 mesh.createEdge(v1, v2);
36 mesh.createEdge(v2, v3);
37 mesh.createEdge(v3, v1);
38
39 io::ExportCSV exportCSV;
40 std::string filename = "io-CSVExport-ExportPolygonalMesh";
41 std::string location = "";
42 exportCSV.doExport(filename, location, mesh);
43}
44
45BOOST_AUTO_TEST_CASE(ExportPolygonalMesh)
46{
47 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
48 int dim = 2;
49 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
50
51 if (context.isRank(0)) {
52 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Zero());
53 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(1));
54 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0});
55
56 mesh.createEdge(v1, v2);
57 mesh.createEdge(v2, v3);
58 mesh.createEdge(v3, v1);
59 mesh.setVertexOffsets({3, 3, 6, 7});
60 } else if (context.isRank(1)) {
61 // nothing
62 } else if (context.isRank(2)) {
63 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Constant(1));
64 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(2));
65 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0.0});
66
67 mesh.createEdge(v1, v2);
68 mesh.createEdge(v2, v3);
69 mesh.createEdge(v3, v1);
70 } else if (context.isRank(3)) {
71 mesh.createVertex(Eigen::Vector2d::Constant(3.0));
72 }
73
74 io::ExportCSV exportCSV;
75 std::string filename = "io-ExportCSVTest-testExportPolygonalMesh";
76 std::string location = "";
77 exportCSV.doExport(filename, location, mesh);
78}
79
80BOOST_AUTO_TEST_CASE(ExportTriangulatedMesh)
81{
82 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
83 int dim = 3;
84 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
85
86 if (context.isRank(0)) {
87 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Zero());
88 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d::Constant(1));
89 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
90
91 mesh::Edge &e1 = mesh.createEdge(v1, v2);
92 mesh::Edge &e2 = mesh.createEdge(v2, v3);
93 mesh::Edge &e3 = mesh.createEdge(v3, v1);
94 mesh.createTriangle(e1, e2, e3);
95
96 mesh.setVertexOffsets({3, 3, 6, 7});
97 } else if (context.isRank(1)) {
98 // nothing
99 } else if (context.isRank(2)) {
100 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Constant(1));
101 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d::Constant(2));
102 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{0.0, 1.0, 0.0});
103
104 mesh::Edge &e1 = mesh.createEdge(v1, v2);
105 mesh::Edge &e2 = mesh.createEdge(v2, v3);
106 mesh::Edge &e3 = mesh.createEdge(v3, v1);
107 mesh.createTriangle(e1, e2, e3);
108 } else if (context.isRank(3)) {
109 mesh.createVertex(Eigen::Vector3d::Constant(3.0));
110 }
111
112 io::ExportCSV exportCSV;
113 std::string filename = "io-ExportCSVTest-testExportTriangulatedMesh";
114 std::string location = "";
115 exportCSV.doExport(filename, location, mesh);
116}
117
118BOOST_AUTO_TEST_CASE(ExportSplitSquare)
119{
120 PRECICE_TEST(""_on(4_ranks).setupIntraComm());
121 int dim = 3;
122 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
123
124 mesh::Vertex &vm = mesh.createVertex(Eigen::Vector3d::Zero());
125 if (context.isRank(0)) {
126 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{-1.0, 1.0, 0.0});
127 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{1.0, 1.0, 0.0});
128 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{0.0, 2.0, 0.0});
129 mesh::Edge & em1 = mesh.createEdge(vm, v1);
130 mesh::Edge & e12 = mesh.createEdge(v1, v2);
131 mesh::Edge & e2m = mesh.createEdge(v2, vm);
132 mesh.createTriangle(em1, e12, e2m);
133 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
134 mesh::Edge &e2o = mesh.createEdge(v2, vo);
135 mesh.createTriangle(eo1, e12, e2o);
136
137 mesh.setVertexOffsets({3, 6, 9, 12});
138 } else if (context.isRank(1)) {
139 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{1.0, -1.0, 0.0});
140 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{-1.0, -1.0, 0.0});
141 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{0.0, -2.0, 0.0});
142 mesh::Edge & em1 = mesh.createEdge(vm, v1);
143 mesh::Edge & e12 = mesh.createEdge(v1, v2);
144 mesh::Edge & e2m = mesh.createEdge(v2, vm);
145 mesh.createTriangle(em1, e12, e2m);
146 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
147 mesh::Edge &e2o = mesh.createEdge(v2, vo);
148 mesh.createTriangle(eo1, e12, e2o);
149 } else if (context.isRank(2)) {
150 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{-1.0, 1.0, 0.0});
151 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{-1.0, -1.0, 0.0});
152 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{-2.0, 0.0, 0.0});
153 mesh::Edge & em1 = mesh.createEdge(vm, v1);
154 mesh::Edge & e12 = mesh.createEdge(v1, v2);
155 mesh::Edge & e2m = mesh.createEdge(v2, vm);
156 mesh.createTriangle(em1, e12, e2m);
157 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
158 mesh::Edge &e2o = mesh.createEdge(v2, vo);
159 mesh.createTriangle(eo1, e12, e2o);
160 } else if (context.isRank(3)) {
161 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d{1.0, 1.0, 0.0});
162 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{1.0, -1.0, 0.0});
163 mesh::Vertex &vo = mesh.createVertex(Eigen::Vector3d{2.0, 0.0, 0.0});
164 mesh::Edge & em1 = mesh.createEdge(vm, v1);
165 mesh::Edge & e12 = mesh.createEdge(v1, v2);
166 mesh::Edge & e2m = mesh.createEdge(v2, vm);
167 mesh.createTriangle(em1, e12, e2m);
168 mesh::Edge &eo1 = mesh.createEdge(vo, v1);
169 mesh::Edge &e2o = mesh.createEdge(v2, vo);
170 mesh.createTriangle(eo1, e12, e2o);
171 }
172
173 io::ExportCSV exportCSV;
174 std::string filename = "io-ExportCSVTest-Square";
175 std::string location = "";
176 exportCSV.doExport(filename, location, mesh);
177}
178
179BOOST_AUTO_TEST_SUITE_END() // IOTests
180BOOST_AUTO_TEST_SUITE_END() // CSVExport
181
182#endif // PRECICE_NO_MPI
BOOST_AUTO_TEST_CASE(ExportPolygonalMeshSerial)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
virtual void doExport(const std::string &name, const std::string &location, const mesh::Mesh &mesh)
Does export. Has to be implemented in subclass.
Definition ExportCSV.cpp:38
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
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
Vertex of a mesh.
Definition Vertex.hpp:16
provides Mesh, Data and primitives.
Main namespace of the precice library.