24template <
typename Particle_T>
49 using Position = std::array<double, 3>;
50 using Box = std::pair<Position, Position>;
51 std::vector<Box> boxes;
53 auto boxCount = boxes.size();
54 auto pointCount = 8 * boxCount;
57 char filename[256] = {0};
58 snprintf(filename,
sizeof(filename),
"octree_%d.vtk", iteration++);
59 std::ofstream vtkFile;
60 vtkFile.open(filename);
62 if (not vtkFile.is_open()) {
63 throw std::runtime_error(
"OctreeLogger::logTree(): Failed to open file \"" + std::string(filename) +
"\".");
67 vtkFile <<
"# vtk DataFile Version 2.0\n"
71 <<
"DATASET UNSTRUCTURED_GRID\n"
75 vtkFile <<
"POINTS " << pointCount <<
" float\n";
76 for (Box box : boxes) {
77 Position min = box.first;
78 Position max = box.second;
80 auto [minX, minY, minZ] = min;
81 auto [maxX, maxY, maxZ] = max;
86 vtkFile << minX <<
" " << minY <<
" " << minZ <<
"\n";
87 vtkFile << maxX <<
" " << minY <<
" " << minZ <<
"\n";
88 vtkFile << maxX <<
" " << maxY <<
" " << minZ <<
"\n";
89 vtkFile << minX <<
" " << maxY <<
" " << minZ <<
"\n";
90 vtkFile << minX <<
" " << minY <<
" " << maxZ <<
"\n";
91 vtkFile << maxX <<
" " << minY <<
" " << maxZ <<
"\n";
92 vtkFile << maxX <<
" " << maxY <<
" " << maxZ <<
"\n";
93 vtkFile << minX <<
" " << maxY <<
" " << maxZ <<
"\n";
98 auto cellListSize = pointCount + boxCount;
99 vtkFile <<
"CELLS " << boxCount <<
" " << cellListSize <<
"\n";
100 for (
auto boxIndex = 0; boxIndex < boxCount; ++boxIndex) {
102 for (
auto pointIndex = 0; pointIndex < 8; ++pointIndex) {
104 auto offset = 8 * boxIndex + pointIndex;
106 if (pointIndex < 7) {
115 vtkFile <<
"CELL_TYPES " << boxCount <<
"\n";
116 for (
int i = 0; i < boxes.size(); ++i) {
154 for (
int leafIndex = 0; leafIndex < leaves.size(); ++leafIndex) {
155 auto leaf = leaves[leafIndex];
156 fprintf(out,
"{\"minmax\": ");
157 outBoxCoordinatesJSON(out, leaf);
160 fprintf(out,
", \"fn\": [");
163 auto neighbor = leaf->GTEQ_FACE_NEIGHBOR(face);
169 outBoxCoordinatesJSON(out, neighbor);
174 fprintf(out,
"], \"fnl\": [");
177 auto neighbor = leaf->GTEQ_FACE_NEIGHBOR(face);
179 auto neighborLeaves = neighbor->getNeighborLeaves(face);
180 for (
auto neighborLeaf : neighborLeaves) {
185 outBoxCoordinatesJSON(out, neighborLeaf);
191 fprintf(out,
"], \"en\": [");
194 auto neighbor = leaf->GTEQ_EDGE_NEIGHBOR(edge);
200 outBoxCoordinatesJSON(out, neighbor);
205 fprintf(out,
"], \"enl\": [");
208 auto neighbor = leaf->GTEQ_EDGE_NEIGHBOR(edge);
210 auto neighborLeaves = neighbor->getNeighborLeaves(edge);
211 for (
auto neighborLeaf : neighborLeaves) {
216 outBoxCoordinatesJSON(out, neighborLeaf);
222 fprintf(out,
"], \"vn\": [");
225 auto neighbor = leaf->GTEQ_VERTEX_NEIGHBOR(vertex);
231 outBoxCoordinatesJSON(out, neighbor);
236 fprintf(out,
"], \"vnl\": [");
239 auto neighbor = leaf->GTEQ_VERTEX_NEIGHBOR(vertex);
241 auto neighborLeaves = neighbor->getNeighborLeaves(vertex);
243 for (
auto neighborLeaf : neighborLeaves) {
248 outBoxCoordinatesJSON(out, neighborLeaf);
254 if (leafIndex < (leaves.size() - 1)) {
261 fprintf(stderr,
"ERROR: Dump file is nullptr.\n");
276 std::vector<OctreeLeafNode<Particle_T> *> leaves;
280 for (
int leafIndex = 0; leafIndex < leaves.size(); ++leafIndex) {
283 auto n = leaf->
size();
284 for (
int particleIndex = 0; particleIndex < n; ++particleIndex) {
285 Particle_T &particle = leaf->
at(particleIndex);
286 auto p = particle.getR();
288 out3(out, p[0], p[1], p[2]);
290 if ((particleIndex < (n - 1)) || (leafIndex < (leaves.size() - 1))) {
297 fprintf(stderr,
"ERROR: Dump file is nullptr.\n");
313#if AUTOPAS_LOG_OCTREE
318 FILE *particles = fopen(
"particles.json",
"w");
319 fprintf(particles,
"{\"owned\": ");
321 fprintf(particles,
", \"halo\": \n");
323 fprintf(particles,
"}");
336 static void out3(FILE *out,
double x,
double y,
double z) { fprintf(out,
"%.3f,%.3f,%.3f", x, y, z); }
345 static void outLocationArrayJSON(FILE *out,
const std::array<double, 3> &min,
const std::array<double, 3> &max) {
347 out3(out, min[0], min[1], min[2]);
349 out3(out, max[0], max[1], max[2]);
358 static void outBoxCoordinatesJSON(FILE *out, OctreeNodeInterface<Particle_T> *node) {
359 const auto min = node->getBoxMin();
360 const auto max = node->getBoxMax();
361 outLocationArrayJSON(out, min, max);
367 int unsigned iteration = 0;
Particle_T & at(size_t index)
Returns the particle at position index.
Definition: FullParticleCell.h:212
An octree leaf node.
Definition: OctreeLeafNode.h:27
size_t size() const override
Get the total number of particles saved in the container (owned + halo + dummy).
Definition: OctreeLeafNode.h:147
Log an octree to a .vtk file.
Definition: OctreeLogger.h:25
~OctreeLogger()=default
Destructor.
static void octreeToJSON(OctreeNodeInterface< Particle_T > *owned, OctreeNodeInterface< Particle_T > *halo, std::vector< OctreeLeafNode< Particle_T > * > &ownedLeaves, std::vector< OctreeLeafNode< Particle_T > * > &haloLeaves)
Log the octree to JSON files understandable by https://github.com/AutoPas/OctreeVisualization.
Definition: OctreeLogger.h:310
OctreeLogger()=default
Constructor.
void logTree(OctreeNodeWrapper< Particle_T > *wrapper)
Write the octree below the wrapper to a .vtk file.
Definition: OctreeLogger.h:41
void logTree(OctreeNodeInterface< Particle_T > *root)
This function writes the octree to a .vtk file.
Definition: OctreeLogger.h:47
static FILE * leavesToJSON(FILE *out, std::vector< OctreeLeafNode< Particle_T > * > &leaves)
Convert a list of octree leaves to JSON and write it to an output file.
Definition: OctreeLogger.h:151
static FILE * particlesToJSON(FILE *out, OctreeNodeInterface< Particle_T > *root)
Print a list of particle positions to a file as JSON.
Definition: OctreeLogger.h:273
The base class that provides the necessary function definitions that can be applied to an octree.
Definition: OctreeNodeInterface.h:32
virtual void appendAllLeaves(std::vector< OctreeLeafNode< Particle_T > * > &leaves) const =0
Put all leaves below this subtree into a given list.
virtual void appendAllLeafBoxes(std::vector< std::pair< std::array< double, 3 >, std::array< double, 3 > > > &boxes) const =0
Put the min/max corner coordinates of every leaf into the vector.
This class wraps the functionality provided by the octree leaves and inner nodes in a structure that ...
Definition: OctreeNodeWrapper.h:37
OctreeNodeInterface< Particle_T > * getRaw() const
Get a raw pointer to the enclosed cell.
Definition: OctreeNodeWrapper.h:273
static constexpr std::array< Face, 6 > faces
All available faces for a cube.
Definition: OctreeDirection.h:98
static constexpr std::array< Edge, 12 > edges
All available edges for a cube.
Definition: OctreeDirection.h:103
static constexpr std::array< Vertex, 8 > vertices
All available vertices for a cube.
Definition: OctreeDirection.h:108
constexpr std::array< T, SIZE > max(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Takes elementwise maximum and returns the result.
Definition: ArrayMath.h:96
constexpr std::array< T, SIZE > min(const std::array< T, SIZE > &a, const std::array< T, SIZE > &b)
Takes elementwise minimum, returns the result.
Definition: ArrayMath.h:62
This is the main namespace of AutoPas.
Definition: AutoPasDecl.h:32
@ halo
Halo state, a particle with this state is an actual particle, but not owned by the current AutoPas ob...
@ owned
Owned state, a particle with this state is an actual particle and owned by the current AutoPas object...