Commit 6fe8f1ec authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

Added hierarchical mesh writer based on mesh structure codes.

parent bc21bb8e
......@@ -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];
}
}
......@@ -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;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment