preCICE v3.1.2
Loading...
Searching...
No Matches
ExportVTKTest.cpp
Go to the documentation of this file.
1#include <Eigen/Core>
2#include <algorithm>
3#include <string>
4#include "io/Export.hpp"
5#include "io/ExportVTK.hpp"
6#include "mesh/Mesh.hpp"
9#include "testing/Testing.hpp"
10
11namespace precice::mesh {
12class Edge;
13class Vertex;
14} // namespace precice::mesh
15
17
18BOOST_AUTO_TEST_SUITE(VTKExport)
19
20using namespace precice;
21
22BOOST_AUTO_TEST_CASE(ExportDataWithGradient)
23{
24 PRECICE_TEST(1_rank)
25 int dimensions = 2;
26 // Create mesh to map from
27 mesh::Mesh mesh("MyMesh", dimensions, testing::nextMeshID());
28 mesh::PtrData dataScalar = mesh.createData("dataScalar", 1, 0_dataID);
29 mesh::PtrData dataVector = mesh.createData("dataVector", 2, 1_dataID);
30 dataScalar->requireDataGradient();
31 dataVector->requireDataGradient();
32 mesh.createVertex(Eigen::Vector2d::Constant(0.0));
33 mesh.createVertex(Eigen::Vector2d::Constant(1.0));
34
35 // Create data
36 mesh.allocateDataValues();
37 Eigen::VectorXd &valuesScalar = dataScalar->values();
38 Eigen::VectorXd &valuesVector = dataVector->values();
39 valuesScalar << 1.0, 2.0;
40 valuesVector << 1.0, 2.0, 3.0, 4.0;
41
42 // Create corresponding gradient data (all gradients = const = 1)
43 Eigen::MatrixXd &gradientsScalar = dataScalar->gradients();
44 Eigen::MatrixXd &gradientsVector = dataVector->gradients();
45 gradientsScalar.setOnes();
46 gradientsVector.setOnes();
47 io::ExportVTK exportVTK;
48 std::string filename = "io-VTKExport-ExportDatawithGradient";
49 std::string location = "";
50 exportVTK.doExport(filename, location, mesh);
51}
52
53BOOST_AUTO_TEST_CASE(ExportPolygonalMesh)
54{
55 PRECICE_TEST(1_rank);
56 int dim = 2;
57 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
58 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector2d::Constant(0.0));
59 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector2d::Constant(1.0));
60 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector2d{1.0, 0.0});
61
62 mesh.createEdge(v1, v2);
63 mesh.createEdge(v2, v3);
64 mesh.createEdge(v3, v1);
65
66 io::ExportVTK exportVTK;
67 std::string filename = "io-VTKExport-ExportPolygonalMesh";
68 std::string location = "";
69 exportVTK.doExport(filename, location, mesh);
70}
71
72BOOST_AUTO_TEST_CASE(ExportTriangulatedMesh)
73{
74 PRECICE_TEST(1_rank);
75 int dim = 3;
76 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
77 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Constant(0.0));
78 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d::Constant(1.0));
79 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
80
81 mesh::Edge &e1 = mesh.createEdge(v1, v2);
82 mesh::Edge &e2 = mesh.createEdge(v2, v3);
83 mesh::Edge &e3 = mesh.createEdge(v3, v1);
84 mesh.createTriangle(e1, e2, e3);
85
86 io::ExportVTK exportVTK;
87 std::string filename = "io-VTKExport-ExportTriangulatedMesh";
88 std::string location = "";
89 exportVTK.doExport(filename, location, mesh);
90}
91
92BOOST_AUTO_TEST_CASE(ExportTetrahedron)
93{
94 PRECICE_TEST(1_rank);
95 int dim = 3;
96 mesh::Mesh mesh("MyMesh", dim, testing::nextMeshID());
97 mesh::Vertex &v1 = mesh.createVertex(Eigen::Vector3d::Constant(0.0));
98 mesh::Vertex &v2 = mesh.createVertex(Eigen::Vector3d{1.0, 0.0, 0.0});
99 mesh::Vertex &v3 = mesh.createVertex(Eigen::Vector3d{0.0, 1.0, 0.0});
100 mesh::Vertex &v4 = mesh.createVertex(Eigen::Vector3d{0.0, 0.0, 1.0});
101
102 mesh.createTetrahedron(v1, v2, v3, v4);
103
104 io::ExportVTK exportVTK;
105 std::string filename = "io-VTKExport-ExportTetrahedron";
106 std::string location = "";
107 exportVTK.doExport(filename, location, mesh);
108}
109
110BOOST_AUTO_TEST_SUITE_END() // ExportVTK
111BOOST_AUTO_TEST_SUITE_END() // IOTests
BOOST_AUTO_TEST_CASE(ExportDataWithGradient)
BOOST_AUTO_TEST_SUITE(PreProcess)
BOOST_AUTO_TEST_SUITE_END()
#define PRECICE_TEST(...)
Definition Testing.hpp:27
Writes polygonal, or triangle meshes to vtk files.
Definition ExportVTK.hpp:19
virtual void doExport(const std::string &name, const std::string &location, const mesh::Mesh &mesh)
Perform writing to VTK file.
Definition ExportVTK.cpp:20
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
Tetrahedron & createTetrahedron(Vertex &vertexOne, Vertex &vertexTwo, Vertex &vertexThree, Vertex &vertexFour)
Creates and initializes a Tetrahedron object.
Definition Mesh.cpp:141
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.