Commit 733b3e73 authored by Thomas Witkowski's avatar Thomas Witkowski

Added first support to read and write arh files.

parent 14739310
......@@ -151,6 +151,8 @@ SET(AMDIS_SRC ${SOURCE_DIR}/DOFIndexed.cc
${SOURCE_DIR}/parallel/InteriorBoundary.cc
${SOURCE_DIR}/ElementDofIterator.cc
${SOURCE_DIR}/Debug.cc
${SOURCE_DIR}/ArhReader.cc
${SOURCE_DIR}/ArhWriter.cc
${SOURCE_DIR}/time/RosenbrockAdaptInstationary.cc
${SOURCE_DIR}/time/RosenbrockStationary.cc
${SOURCE_DIR}/time/RosenbrockMethod.cc
......
......@@ -226,6 +226,8 @@ $(SOURCE_DIR)/SolutionDataStorage.h $(SOURCE_DIR)/SolutionDataStorage.hh \
$(SOURCE_DIR)/ElementDofIteartor.h $(SOURCE_DIR)/ElementDofIterator.cc \
$(SOURCE_DIR)/parallel/InteriorBoundary.h $(SOURCE_DIR)/parallel/InteriorBoundary.cc \
$(SOURCE_DIR)/Debug.h $(SOURCE_DIR)/Debug.cc \
$(SOURCE_DIR)/ArhReader.h $(SOURCE_DIR)/ArhReader.cc \
$(SOURCE_DIR)/ArhWriter.h $(SOURCE_DIR)/ArhWriter.cc \
$(SOURCE_DIR)/time/RosenbrockAdaptInstationary.h $(SOURCE_DIR)/time/RosenbrockAdaptInstationary.cc \
$(SOURCE_DIR)/time/RosenbrockStationary.h $(SOURCE_DIR)/time/RosenbrockStationary.cc \
$(SOURCE_DIR)/time/RosenbrockMethod.h $(SOURCE_DIR)/time/RosenbrockMethod.cc
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -128,7 +128,7 @@ old_postinstall_cmds="chmod 644 \$oldlib~\$RANLIB \$oldlib"
old_postuninstall_cmds=""
# A C compiler.
LTCC="gcc"
LTCC="/usr/lib64/mpi/gcc/openmpi//bin/mpicc"
# LTCC compiler flags.
LTCFLAGS="-g -O2"
......@@ -259,7 +259,7 @@ LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$oldlib"
# A language specific compiler.
CC="gcc"
CC="/usr/lib64/mpi/gcc/openmpi//bin/mpicc"
# Is the compiler the GNU compiler?
with_gcc=yes
......@@ -274,7 +274,7 @@ wl="-Wl,"
pic_flag=" -fPIC -DPIC"
# Compiler flag to prevent dynamic linking.
link_static_flag="-static"
link_static_flag=""
# Does compiler simultaneously support -c and -o options?
compiler_c_o="yes"
......@@ -8914,7 +8914,7 @@ LD="/usr/x86_64-suse-linux/bin/ld -m elf_x86_64"
old_archive_cmds="\$AR \$AR_FLAGS \$oldlib\$oldobjs~\$RANLIB \$oldlib"
# A language specific compiler.
CC="g++"
CC="/usr/lib64/mpi/gcc/openmpi//bin/mpicxx"
# Is the compiler the GNU compiler?
with_gcc=yes
......@@ -8929,7 +8929,7 @@ wl="-Wl,"
pic_flag=" -fPIC -DPIC"
# Compiler flag to prevent dynamic linking.
link_static_flag="-static"
link_static_flag=""
# Does compiler simultaneously support -c and -o options?
compiler_c_o="yes"
......@@ -9039,17 +9039,17 @@ file_list_spec=""
hardcode_action=immediate
# The directories searched by this compiler when creating a shared library.
compiler_lib_search_dirs="/usr/lib64/gcc/x86_64-suse-linux/4.5 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 /lib/../lib64 /usr/lib/../lib64 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib /usr/lib64/gcc/x86_64-suse-linux/4.5/../../.."
compiler_lib_search_dirs="/usr/lib64/mpi/gcc/openmpi/lib64 /usr/lib64/gcc/x86_64-suse-linux/4.5 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 /lib/../lib64 /usr/lib/../lib64 /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib /usr/lib64/gcc/x86_64-suse-linux/4.5/../../.."
# Dependencies to place before and after the objects being linked to
# create a shared library.
predep_objects="/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crti.o /usr/lib64/gcc/x86_64-suse-linux/4.5/crtbeginS.o"
postdep_objects="/usr/lib64/gcc/x86_64-suse-linux/4.5/crtendS.o /usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64/crtn.o"
predeps=""
postdeps="-lstdc++ -lm -lgcc_s -lc -lgcc_s"
postdeps="-lmpi_cxx -lmpi -lopen-rte -lopen-pal -ldl -lnsl -lutil -ldl -lstdc++ -lm -lgcc_s -lpthread -lc -lgcc_s"
# The library search path used internally by the compiler when linking
# a shared library.
compiler_lib_search_path="-L/usr/lib64/gcc/x86_64-suse-linux/4.5 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.."
compiler_lib_search_path="-L/usr/lib64/mpi/gcc/openmpi/lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../lib64 -L/lib/../lib64 -L/usr/lib/../lib64 -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../../../x86_64-suse-linux/lib -L/usr/lib64/gcc/x86_64-suse-linux/4.5/../../.."
# ### END LIBTOOL TAG CONFIG: CXX
......@@ -5,6 +5,8 @@
#include "AdaptInfo.h"
#include "AdaptInstationary.h"
#include "AdaptStationary.h"
#include "ArhReader.h"
#include "ArhWriter.h"
#include "Assembler.h"
#include "BasisFunction.h"
#include "Boundary.h"
......
#include <fstream>
#include "ArhReader.h"
#include "Mesh.h"
#include "MeshStructure.h"
namespace AMDiS {
using namespace std;
void ArhReader::read(string filename, Mesh *mesh)
{
FUNCNAME("ArhReader::read()");
RefinementManager *refManager;
switch (mesh->getDim()) {
case 2:
refManager = new RefinementManager2d();
break;
case 3:
refManager = new RefinementManager3d();
break;
default:
ERROR_EXIT("Should not happen!\n");
}
ifstream file;
file.open(filename.c_str(), ios::in | ios::binary);
string typeId = "";
long nMacroElements = 0;
long nValueVectors = 0;
long nAllValues = 0;
file.read(const_cast<char*>(typeId.data()), 4);
file.read(reinterpret_cast<char*>(&nMacroElements), 4);
file.read(reinterpret_cast<char*>(&nValueVectors), 4);
file.read(reinterpret_cast<char*>(&nAllValues), 4);
for (long i = 0; i < nMacroElements; i++) {
long elIndex = 0;
long nStructureCodes = 0;
long codeSize = 0;
file.read(reinterpret_cast<char*>(&elIndex), 4);
file.read(reinterpret_cast<char*>(&nStructureCodes), 4);
file.read(reinterpret_cast<char*>(&codeSize), 4);
vector<unsigned long> structureCode(nStructureCodes);
file.read(reinterpret_cast<char*>(&(structureCode[0])), 4 * nStructureCodes);
MeshStructure elementStructure;
elementStructure.init(structureCode, codeSize);
elementStructure.fitMeshToStructure(mesh, refManager, false, false, elIndex);
long nValuesPerVector = 0;
file.read(reinterpret_cast<char*>(&nValuesPerVector), 4);
for (long j = 0; j < nValuesPerVector * nValueVectors; j++) {
double value = 0.0;
file.read(reinterpret_cast<char*>(&value), 8);
}
}
file.close();
MSG("ARH file read from: %s\n", filename.c_str());
}
}
// ============================================================================
// == ==
// == Amdis - Adaptive multidimensional simulations ==
// == ==
// ============================================================================
// == ==
// == TU Dresden ==
// == ==
// == Institut für Wissenschaftliches Rechnen ==
// == Zellescher Weg 12-14 ==
// == 01069 Dresden ==
// == germany ==
// == ==
// ============================================================================
// == ==
// == https://gforge.zih.tu-dresden.de/projects/amdis/ ==
// == ==
// ============================================================================
/** \file ArhReader.h */
#ifndef AMDIS_ARH_READER_H
#define AMDIS_ARH_READER_H
#include "AMDiS_fwd.h"
namespace AMDiS {
class ArhReader
{
public:
static void read(std::string filename, Mesh *mesh);
};
}
#endif
#include <fstream>
#include "ArhWriter.h"
#include "Mesh.h"
#include "MeshStructure.h"
#include "Traverse.h"
namespace AMDiS {
using namespace std;
void ArhWriter::write(string filename, Mesh *mesh)
{
FUNCNAME("ArhWriter::write()");
ofstream file;
file.open(filename.c_str(), ios::out | ios::binary | ios::trunc);
string typeId = "arhS";
file.write(typeId.c_str(), 4);
long nMacroElements = 0;
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL);
while (elInfo) {
nMacroElements++;
elInfo = stack.traverseNext(elInfo);
}
file.write(reinterpret_cast<char*>(&nMacroElements), 4);
long nValueVectors = 0;
file.write(reinterpret_cast<char*>(&nValueVectors), 4);
long nAllValues = 0;
file.write(reinterpret_cast<char*>(&nAllValues), 4);
MeshStructure elementStructure;
long macroElIndex = -1;
elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_EVERY_EL_PREORDER);
while (elInfo) {
if (elInfo->getLevel() == 0) {
if (macroElIndex != -1) {
elementStructure.commit();
writeMacroElement(file, elementStructure, macroElIndex);
}
elementStructure.clear();
macroElIndex = elInfo->getElement()->getIndex();
}
elementStructure.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");
elementStructure.commit();
writeMacroElement(file, elementStructure, macroElIndex);
file.close();
MSG("ARH file written to: %s\n", filename.c_str());
}
void ArhWriter::writeMacroElement(std::ofstream &file,
MeshStructure &code,
long elIndex)
{
file.write(reinterpret_cast<char*>(&elIndex), 4);
long nStructureCodes = code.getCode().size();
file.write(reinterpret_cast<char*>(&nStructureCodes), 4);
long codeSize = code.getNumElements();
file.write(reinterpret_cast<char*>(&codeSize), 4);
file.write(reinterpret_cast<char*>(&(const_cast<vector<unsigned long int>&>(code.getCode())[0])),
4 * nStructureCodes);
long nValuesPerVector = 0;
file.write(reinterpret_cast<char*>(&nValuesPerVector), 4);
}
}
// ============================================================================
// == ==
// == Amdis - Adaptive multidimensional simulations ==
// == ==
// ============================================================================
// == ==
// == TU Dresden ==
// == ==
// == Institut für Wissenschaftliches Rechnen ==
// == Zellescher Weg 12-14 ==
// == 01069 Dresden ==
// == germany ==
// == ==
// ============================================================================
// == ==
// == https://gforge.zih.tu-dresden.de/projects/amdis/ ==
// == ==
// ============================================================================
/** \file ArhWriter.h */
#ifndef AMDIS_ARH_WRITER_H
#define AMDIS_ARH_WRITER_H
#include <iostream>
#include <fstream>
#include "AMDiS_fwd.h"
namespace AMDiS {
class ArhWriter
{
public:
static void write(std::string filename, Mesh *mesh);
protected:
static void writeMacroElement(std::ofstream &file,
MeshStructure &code,
long elIndex);
};
}
#endif
......@@ -347,99 +347,4 @@ 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.write(reinterpret_cast<char*>(&nMacroElements), sizeof(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::readMeshFile(Mesh *mesh,
RefinementManager *refManager,
std::string filename)
{
FUNCNAME("MeshStructure::readMeshFile()");
std::ifstream file;
file.open(filename.c_str(), std::ios::in | std::ios::binary);
int nMacroElements = -1;
file.read(reinterpret_cast<char*>(&nMacroElements), sizeof(nMacroElements));
for (int i = 0; i < nMacroElements; i++) {
int macroElIndex = -1;
int codeSize = 0;
code.clear();
file.read(reinterpret_cast<char*>(&macroElIndex), sizeof(macroElIndex));
file.read(reinterpret_cast<char*>(&nElements), sizeof(nElements));
file.read(reinterpret_cast<char*>(&codeSize), sizeof(codeSize));
for (int j = 0; j < codeSize; j++) {
unsigned long int readCode = 0;
file.read(reinterpret_cast<char*>(&readCode), sizeof(readCode));
code.push_back(readCode);
}
TEST_EXIT_DBG(macroElIndex >= 0)("Should not happen!\n");
reset();
fitMeshToStructure(mesh, refManager, false, false, macroElIndex);
}
file.close();
}
void MeshStructure::writeMacroElement(std::ofstream& file, int macroElIndex)
{
unsigned int size = code.size();
file.write(reinterpret_cast<char*>(&macroElIndex), sizeof(macroElIndex));
file.write(reinterpret_cast<char*>(&nElements), sizeof(nElements));
file.write(reinterpret_cast<char*>(&size), sizeof(size));
for (unsigned int i = 0; i < code.size(); i++)
file.write(reinterpret_cast<char*>(&(code[i])), sizeof(code[i]));
}
}
......@@ -140,10 +140,6 @@ 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);
void readMeshFile(Mesh *mesh, RefinementManager *refManager, std::string filename);
protected:
/// Insert a new element to the structure code. Is used by the init function.
void insertElement(bool isLeaf);
......@@ -155,8 +151,6 @@ namespace AMDiS {
MeshStructure *structure2,
MeshStructure *result);
void writeMacroElement(std::ofstream& file, int macroElIndex);
protected:
/// Mesh structure code.
std::vector<unsigned long int> code;
......@@ -175,6 +169,8 @@ namespace AMDiS {
bool debugMode;
static const int unsignedLongSize;
friend class ArhWriter;
};
}
......
......@@ -93,6 +93,7 @@ namespace AMDiS {
Mesh::CALL_LEAF_EL | Mesh::FILL_NEIGH | Mesh::FILL_BOUND);
while (elInfo) {
if (elInfo->getElement() == el) {
MSG("REFINE EL IN HERE\n");
refineFunction(elInfo);
TEST_EXIT(!doMoreRecursiveRefine)("Okay, this will not work in that way!\n");
......
......@@ -516,7 +516,7 @@ namespace AMDiS {
// === Check the boundaries and adapt mesh if necessary. ===
MSG("TEST 1: %d\n", mesh->getDOFAdmin(0).getUsedSize());
#if (DEBUG != 0)
MSG("Run checkAndAdaptBoundary ...\n");
#endif
......@@ -534,6 +534,7 @@ namespace AMDiS {
#endif
} while (recvAllValues != 0);
MSG("TEST 2: %d\n", mesh->getDOFAdmin(0).getUsedSize());
#if (DEBUG != 0)
debug::writeMesh(feSpace, -1, "mesh");
......@@ -698,9 +699,7 @@ namespace AMDiS {
refineManager->setMesh(el->getMesh());
refineManager->setStack(&stack);
refineManager->refineFunction(elInfo);
MSG("A-NEW ELs %d %d\n", el->getChild(0)->getIndex(), el->getChild(1)->getIndex());
MSG("REFINE EL %d %d %d\n", elInfo->getElement()->getIndex(), el->getChild(0)->getIndex(), el->getChild(1)->getIndex());
meshChanged = true;
}
......@@ -779,6 +778,7 @@ namespace AMDiS {
refineManager->setMesh(el->getMesh());
refineManager->setStack(&stack);
refineManager->refineFunction(elInfo);
MSG("REFINE EL %d %d %d\n", elInfo->getElement()->getIndex(), el->getChild(0)->getIndex(), el->getChild(1)->getIndex());
meshChanged = true;
}
......
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