OpenFPM_pdata  4.1.0
Project that contain the implementation of distributed structures
 
Loading...
Searching...
No Matches
GraphMLWriter_unit_tests.hpp
1/*
2 * GraphMLWriter_unit_tests.hpp
3 *
4 * Created on: Dec 9, 2014
5 * Author: i-bird
6 */
7
8#ifndef GRAPHMLWRITER_UNIT_TESTS_HPP_
9#define GRAPHMLWRITER_UNIT_TESTS_HPP_
10
11#define GS_SIZE 8
12
13#include "GraphMLWriter.hpp"
14#include "Graph/CartesianGraphFactory.hpp"
15#include "util/util.hpp"
16
17BOOST_AUTO_TEST_SUITE( graphml_writer_test )
18
19
25struct ne_cp
26{
28 typedef boost::fusion::vector<float,float,float,double,long int,int,std::string> type;
29
32
34 static const unsigned int x = 0;
36 static const unsigned int y = 1;
38 static const unsigned int z = 2;
40 static const unsigned int double_num = 3;
42 static const unsigned int long_num = 4;
44 static const unsigned int integer = 5;
46 static const unsigned int string = 6;
48 static const unsigned int max_prop = 7;
49
51 float & get_x() {return boost::fusion::at_c<x>(data);}
53 float & get_y() {return boost::fusion::at_c<y>(data);}
55 float & get_z() {return boost::fusion::at_c<z>(data);}
57 double & get_dn() {return boost::fusion::at_c<double_num>(data);}
59 long int & get_ln() {return boost::fusion::at_c<long_num>(data);}
61 int & get_i() {return boost::fusion::at_c<integer>(data);}
63 std::string & get_str() {return boost::fusion::at_c<string>(data);}
64
67 {
68 static const std::string name[max_prop];
69 };
70
71 static inline bool noPointers()
72 {
73 return true;
74 }
75
77 typedef float s_type;
78};
79
80// Initialize the attributes strings array
81const std::string ne_cp::attributes::name[] = {"x","y","z","double_num","long_num","integer","string"};
82
83BOOST_AUTO_TEST_CASE( graphml_writer_use)
84{
85 Vcluster<> & v_cl = create_vcluster();
86
87 if (v_cl.getProcessUnitID() != 0)
88 return;
89
90#ifdef OPENFPM_PDATA
91
92 if (v_cl.rank() != 0) {return;}
93 std::string c2 = std::string("openfpm_io/test_data/test_graph2_test.graphml");
94 std::string c3 = std::string("openfpm_io/test_data/test_graph_test.graphml");
95
96#else
97
98 std::string c2 = std::string("test_data/test_graph2_test.graphml");
99 std::string c3 = std::string("test_data/test_graph_test.graphml");
100
101#endif
102
104
105 // Add 4 vertex and connect
106
107 struct ne_cp n1;
108 n1.get_x() = 1.0;
109 n1.get_y() = 2.0;
110 n1.get_z() = 3.0;
111 n1.get_dn() = 4.0;
112 n1.get_ln() = 5.0;
113 n1.get_i() = 6.0;
114 n1.get_str() = std::string("test");
115 g_csr2.addVertex(n1);
116 n1.get_str() = std::string("tes2");
117 g_csr2.addVertex(n1);
118 n1.get_str() = std::string("test3");
119 g_csr2.addVertex(n1);
120 n1.get_str() = std::string("test4");
121 g_csr2.addVertex(n1);
122 n1.get_str() = std::string("test5");
123
124 g_csr2.addEdge(0,1,n1);
125 n1.get_str() = std::string("test6");
126 g_csr2.addEdge(2,1,n1);
127 n1.get_str() = std::string("test7");
128 g_csr2.addEdge(3,1,n1);
129 n1.get_str() = std::string("test8");
130 g_csr2.addEdge(2,0,n1);
131 n1.get_str() = std::string("test9");
132 g_csr2.addEdge(3,2,n1);
133
134 // Create a graph ML
136 gv2.write("test_graph2.graphml");
137
138 // check that match
139
140 bool test = compare("test_graph2.graphml",c2);
141 BOOST_REQUIRE_EQUAL(true,test);
142
144
146
147 // Cartesian grid
148 size_t sz[] = {GS_SIZE,GS_SIZE,GS_SIZE};
149
150 // Box
151 Box<3,float> box({0.0,0.0,0.0},{1.0,1.0,1.0});
152
153 // Boundary conditions, non periodic
154 size_t bc[] = {NON_PERIODIC,NON_PERIODIC,NON_PERIODIC};
155
156 Graph_CSR<ne_cp,ne_cp> g_csr = g_factory.construct<5,NO_VERTEX_ID,float,2,ne_cp::x,ne_cp::y,ne_cp::z>(sz,box,bc);
157
158 // Create a graph ML
160 gw.write("test_graph.graphml");
161
162
163 // check that match
164 test = compare("test_graph.graphml",c3);
165 BOOST_REQUIRE_EQUAL(true,test);
166}
167
168BOOST_AUTO_TEST_SUITE_END()
169
170
171#endif /* GRAPHMLWRITER_UNIT_TESTS_HPP_ */
This class represent an N-dimensional box.
Definition Box.hpp:61
This class construct a cartesian graph.
static Graph construct(const size_t(&sz)[dim], Box< dim, T > &dom, const size_t(&bc)[dim])
Construct a cartesian graph, with V and E edge properties.
Structure that store a graph in CSR format or basically in compressed adjacency matrix format.
void addVertex(const V &vrt)
add vertex
auto addEdge(size_t v1, size_t v2, const E &ed) -> decltype(e.get(0))
add edge on the graph
size_t rank()
Get the process unit id.
size_t getProcessUnitID()
Get the process unit id.
Implementation of VCluster class.
Definition VCluster.hpp:59
define attributes names
double & get_dn()
get double number
float & get_z()
get z
boost::fusion::vector< float, float, float, double, long int, int, std::string > type
The node contain several properties.
float & get_x()
get x
type data
The data.
static const unsigned int x
x property id in boost::fusion::vector
static const unsigned int y
y property id in boost::fusion::vector
float & get_y()
get y
int & get_i()
get integer
float s_type
type of the spatial information
std::string & get_str()
get string
static const unsigned int z
z property id in boost::fusion::vector
long int & get_ln()
get long number