From 6fe8f1ecd313b5b961ac6ee3b5054bc85e741b60 Mon Sep 17 00:00:00 2001 From: Thomas Witkowski <thomas.witkowski@gmx.de> Date: Tue, 6 Jul 2010 07:53:09 +0000 Subject: [PATCH] Added hierarchical mesh writer based on mesh structure codes. --- AMDiS/src/MeshStructure.cc | 54 ++++++++++++++++++++++++++++++++++++++ AMDiS/src/MeshStructure.h | 4 +++ 2 files changed, 58 insertions(+) diff --git a/AMDiS/src/MeshStructure.cc b/AMDiS/src/MeshStructure.cc index 05da7b3c..44ce8a82 100644 --- a/AMDiS/src/MeshStructure.cc +++ b/AMDiS/src/MeshStructure.cc @@ -299,4 +299,58 @@ namespace AMDiS { { return (other.getCode() == code); } + + + void MeshStructure::writeMeshFile(Mesh *mesh, std::string filename) + { + FUNCNAME("MeshStructure::writeMeshFile()"); + + int nMacroElements = 0; + int macroElIndex = -1; + std::ofstream file; + file.open(filename.c_str(), std::ios::out | std::ios::binary | std::ios::trunc); + + TraverseStack stack; + ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL); + while (elInfo) { + nMacroElements++; + elInfo = stack.traverseNext(elInfo); + } + + file << nMacroElements; + + elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_PREORDER); + while (elInfo) { + if (elInfo->getLevel() == 0) { + if (macroElIndex != -1) { + commit(); + writeMacroElement(file, macroElIndex); + } + + clear(); + macroElIndex = elInfo->getElement()->getIndex(); + } + + insertElement(elInfo->getElement()->isLeaf()); + elInfo = stack.traverseNext(elInfo); + } + + // And write the last macro element to file. + TEST_EXIT_DBG(macroElIndex != -1)("Should not happen!\n"); + commit(); + writeMacroElement(file, macroElIndex); + + file.close(); + } + + + void MeshStructure::writeMacroElement(std::ofstream& file, int macroElIndex) + { + file << macroElIndex; + file << nElements; + file << code.size(); + for (unsigned int i = 0; i < code.size(); i++) + file << code[i]; + } + } diff --git a/AMDiS/src/MeshStructure.h b/AMDiS/src/MeshStructure.h index 2fac234a..b0f64162 100644 --- a/AMDiS/src/MeshStructure.h +++ b/AMDiS/src/MeshStructure.h @@ -156,6 +156,8 @@ namespace AMDiS { /// Returns true, if the given mesh structure code is equal to this one. bool compare(MeshStructure &other); + void writeMeshFile(Mesh *mesh, std::string filename); + protected: /// Insert a new element to the structure code. Is used by the init function. void insertElement(bool isLeaf); @@ -167,6 +169,8 @@ namespace AMDiS { MeshStructure *structure2, MeshStructure *result); + void writeMacroElement(std::ofstream& file, int macroElIndex); + protected: /// Mesh structure code. std::vector<unsigned long int> code; -- GitLab