Dendro  5.01
Dendro in Greek language means tree. The Dendro library is a large scale (262K cores on ORNL's Titan) distributed memory adaptive octree framework. The main goal of Dendro is to perform large scale multiphysics simulations efficeiently in mordern supercomputers. Dendro consists of efficient parallel data structures and algorithms to perform variational ( finite element) methods and finite difference mthods on 2:1 balanced arbitary adaptive octrees which enables the users to perform simulations raning from black holes (binary black hole mergers) to blood flow in human body, where applications ranging from relativity, astrophysics to biomedical engineering.
treenode2vtk.h
1 //
2 // Created by milinda on 2/8/16.
3 //
4 
5 #ifndef SFCSORTBENCH_TREENODE2VTK_H
6 #define SFCSORTBENCH_TREENODE2VTK_H
7 #include "TreeNode.h"
8 //#include "Point.h"
9 //#include "nodeAndValues.h"
10 #include <algorithm>
11 
12 #include <iostream>
13 #include <fstream>
14 #include <vector>
15 #include <sstream>
16 
17 #define VTK_HEXAHEDRON 12
18 
19 // convert one treenode to vtk file compatibel string
20 //std::string treeNodeTovtk(const TreeNode& T,int mpi_rank,int hindex);
21 
22 //void treeNodesTovtk(std::vector<ot::TreeNode>& nodes,int mpi_rank,std::string vtk_file_name,bool hsorted=false);
23 template <typename T>
24 void treeNodesTovtk(std::vector<T>& nodes,int mpi_rank,std::string vtk_file_name,bool hsorted=false);
25 
26 template <typename T>
27 void treeNodesTovtk(std::vector<T> &nodes, int mpi_rank, std::string vtk_file_name, bool hsorted) {
28 
29  //std::sort(nodes.begin(), nodes.end());
30  if (!mpi_rank) std::cout << "writing mesh to VTK file: " << vtk_file_name << std::endl;
31  std::ostringstream convert;
32 
33 #ifdef HILBERT_ORDERING
34  convert << vtk_file_name << "_H_" << mpi_rank << ".vtk";
35 #else
36  convert << vtk_file_name << "_M_" << mpi_rank << ".vtk";
37 #endif
38 
39  //convert << vtk_file_name << "_" << mpi_rank << ".vtk";
40  vtk_file_name = convert.str();
41 
42  std::ofstream myfile;
43  myfile.open(vtk_file_name.c_str());
44 
45  myfile << "# vtk DataFile Version 2.0" << std::endl;
46  myfile << "DENDRO OCTREES" << std::endl;
47  myfile << "ASCII" << std::endl;
48  myfile << "DATASET UNSTRUCTURED_GRID" << std::endl;
49 
50  int dim = 3;//nodes[0].getDim();
51 
52  int unit_points = 1 << dim;
53  int num_verticies = nodes.size() * (unit_points);
54  int num_cells = nodes.size();
55 
56  //std::cout<<"FileName :"<<vtk_file_name<<"\t DIM:"<<dim<<"\t number of points:"<<num_verticies<<"\t number of cells:"<<num_cells<<std::endl;
57 
58 
59  myfile << "POINTS " << num_verticies << " float" << std::endl;
60 
61  if (dim == 2) {
62 
63  } else if (dim == 3) {
64  unsigned int len;
65  unsigned int xl, yl, zl;
66  int num_data_field = 2;
67  /* if (hsorted) {
68  num_data_field++;
69  std::sort(nodes.begin(), nodes.end());
70  }*/
71 
72  int num_cells_elements = num_cells * unit_points + num_cells;
73 
74  for (int i = 0; i < nodes.size(); i++) {
75  //std::cout<<nodes[i]<<std::endl;
76  len = 1 << (nodes[i].getMaxDepth() - nodes[i].getLevel());
77  xl = nodes[i].getX();
78  yl = nodes[i].getY();
79  zl = nodes[i].getZ();
80 
81  myfile << xl << " " << yl << " " << zl << std::endl;
82  myfile << (xl + len) << " " << yl << " " << zl << std::endl;
83  myfile << (xl + len) << " " << (yl + len) << " " << zl << std::endl;
84  myfile << xl << " " << (yl + len) << " " << zl << std::endl;
85 
86  myfile << xl << " " << yl << " " << (zl + len) << std::endl;
87  myfile << (xl + len) << " " << yl << " " << (zl + len) << std::endl;
88  myfile << (xl + len) << " " << (yl + len) << " " << (zl + len) << std::endl;
89  myfile << xl << " " << (yl + len) << " " << (zl + len) << std::endl;
90 
91  }
92 
93  myfile << "CELLS " << nodes.size() << " " << num_cells_elements << std::endl;
94 
95  for (int i = 0; i < num_cells; i++) {
96  myfile << unit_points << " ";
97  for (int j = 0; j < unit_points; j++) {
98  myfile << (i * unit_points + j) << " ";
99  }
100  myfile << std::endl;
101  }
102 
103  myfile << "CELL_TYPES " << num_cells << std::endl;
104  for (int i = 0; i < num_cells; i++) {
105  myfile << VTK_HEXAHEDRON << std::endl;
106  }
107 
108  //myfile<<"CELL_DATA "<<num_cells<<std::endl;
109  //myfile<<"POINT_DATA "<<(num_cells*unit_points)<<std::endl;
110 
111 
112 
113  myfile <<"CELL_DATA "<<num_cells<<std::endl;
114  //myfile<<"POINT_DATA "<<(num_cells*unit_points)<<std::endl;
115 
116 
117 
118  //myfile << "FIELD OCTREE_DATA " << num_data_field << std::endl;
119 
120  //myfile << "cell_level 1 " << num_cells << " int" << std::endl;
121  myfile << "SCALARS cell_level FLOAT"<< std::endl;
122  myfile << "LOOKUP_TABLE default"<<std::endl;
123 
124  for (int i = 0; i < nodes.size(); i++)
125  myfile << nodes[i].getLevel() <<std::endl;
126 
127  myfile << std::endl;
128  //myfile << std::endl;
129 
130  //myfile << "mpi_rank 1 " << num_cells << " int" << std::endl;
131  myfile << "SCALARS mpi_rank FLOAT"<< std::endl;
132  myfile << "LOOKUP_TABLE default"<<std::endl;
133  for (int i = 0; i < nodes.size(); i++)
134  myfile <<mpi_rank << std::endl;
135 
136  myfile << std::endl;
137 
138 
139  }
140 
141  myfile.close();
142 
143 }
144 
145 
146 #endif //SFCSORTBENCH_TREENODE2VTK_H