Commit 7db0b6df authored by Thomas Witkowski's avatar Thomas Witkowski

Work on ARH read and writer.

parent edc55c09
......@@ -111,6 +111,24 @@ namespace AMDiS {
}
void writeMacroElementIndexMesh(Mesh *mesh,
std::string filename)
{
std::map<int, double> vec;
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(mesh, -1, Mesh::CALL_LEAF_EL);
while (elInfo) {
int index = elInfo->getElement()->getIndex();
int macroIndex = elInfo->getMacroElement()->getIndex();
vec[index] = macroIndex;
elInfo = stack.traverseNext(elInfo);
}
ElementFileWriter::writeFile(vec, mesh, filename, ".vtu");
}
void highlightElementIndexMesh(Mesh *mesh, int idx, std::string filename)
{
std::map<int, double> vec;
......
......@@ -93,6 +93,16 @@ namespace AMDiS {
std::string filename,
int level = -1);
/** \brief
* Creates a vtu file where all elements in the mesh are colored by the
* macro element indices.
*
* \param[in] feSpace The FE space to be used.
* \param[in] filename Name of the file.
*/
void writeMacroElementIndexMesh(Mesh *mesh,
std::string filename);
void highlightElementIndexMesh(Mesh *mesh, int idx, std::string filename);
void colorMeshByMacroIndex(Mesh *mesh, std::string filename);
......
......@@ -12,12 +12,14 @@
#include <fstream>
#include <stdint.h>
#include <boost/filesystem.hpp>
#include "ArhReader.h"
#include "Mesh.h"
#include "MeshStructure.h"
#include "Traverse.h"
#include "DOFVector.h"
#include "Debug.h"
namespace AMDiS {
......@@ -76,6 +78,85 @@ namespace AMDiS {
}
void ArhReader::readMeta(string filename,
Mesh *mesh,
DOFVector<double>* vec0,
DOFVector<double>* vec1,
DOFVector<double>* vec2)
{
vector<DOFVector<double>*> vecs;
if (vec0)
vecs.push_back(vec0);
if (vec1)
vecs.push_back(vec1);
if (vec2)
vecs.push_back(vec2);
readMeta(filename, mesh, vecs);
}
void ArhReader::readMeta(string filename,
Mesh *mesh,
vector<DOFVector<double>*> vecs)
{
FUNCNAME("ArhReader::readMeta()");
boost::filesystem::path p(filename.c_str());
boost::filesystem::path directory = p.parent_path();
ifstream file;
file.open(filename.c_str());
TEST_EXIT(file.is_open())
("Cannot open arh meta file \"%s\"\n", filename.c_str());
string readStr = "";
file >> readStr;
string arhPrefix = "";
file >> arhPrefix;
int nProc;
file >> nProc;
// Maps to each macro element index the arh file index it is stored in.
map<int, int> macroInProc;
for (int i = 0; i < nProc; i++) {
int tmp;
file >> tmp;
TEST_EXIT(tmp == i)("Should not happen!\n");
int nMacroEl;
file >> nMacroEl;
for (int j = 0; j < nMacroEl; j++) {
int elIndex;
file >> elIndex;
macroInProc[elIndex] = i;
}
}
file.close();
// Set of all file indices which should be read to restore all macro elements.
std::set<int> readArhFiles;
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(mesh, 0, Mesh::CALL_EL_LEVEL);
while (elInfo) {
int macroElIndex = elInfo->getElement()->getIndex();
TEST_EXIT(macroInProc.count(macroElIndex))("Should not happen!\n");
readArhFiles.insert(macroInProc[macroElIndex]);
elInfo = stack.traverseNext(elInfo);
}
for (std::set<int>::iterator it = readArhFiles.begin();
it != readArhFiles.end(); ++it) {
string arhFilename =
directory.native() + "/" + arhPrefix + "-p" + boost::lexical_cast<string>(*it) + "-.arh";
MSG("READ FILE: %s\n", arhFilename.c_str());
readFile(arhFilename, mesh, vecs);
}
}
void ArhReader::readFile(string filename,
Mesh *mesh,
vector<DOFVector<double>*> vecs)
......@@ -135,8 +216,16 @@ namespace AMDiS {
MeshStructure elementStructure;
elementStructure.init(structureCode, codeSize);
if (macroInMesh.count(elIndex) == 1)
if (macroInMesh.count(elIndex)) {
MSG("READ MACRO EL %d\n", elIndex);
if (MPI::COMM_WORLD.Get_rank() == 52 && elIndex == 19777) {
debug::writeMacroElementIndexMesh(mesh, "test");
}
elementStructure.fitMeshToStructure(mesh, refManager, false, elIndex);
}
if (nValueVectors > 0) {
uint32_t nValuesPerVector = 0;
......@@ -146,7 +235,7 @@ namespace AMDiS {
vector<double> values(nValuesPerVector);
file.read(reinterpret_cast<char*>(&(values[0])), 8 * nValuesPerVector);
if (vecs[j] != NULL) {
if (macroInMesh.count(elIndex) == 1)
if (macroInMesh.count(elIndex))
setDofValues(elIndex, mesh, values, vecs[j]);
}
}
......
......@@ -32,7 +32,8 @@ namespace AMDiS {
class ArhReader
{
public:
static void read(string filename, Mesh *mesh,
static void read(string filename,
Mesh *mesh,
DOFVector<double>* vec0 = NULL,
DOFVector<double>* vec1 = NULL,
DOFVector<double>* vec2 = NULL,
......@@ -43,7 +44,8 @@ namespace AMDiS {
#endif
int nProcs = -1);
static void read(string filename, Mesh *mesh,
static void read(string filename,
Mesh *mesh,
vector<DOFVector<double>*> vecs,
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
bool writeParallel = true,
......@@ -52,6 +54,16 @@ namespace AMDiS {
#endif
int nProcs = -1);
static void readMeta(string filename,
Mesh *mesh,
DOFVector<double>* vec0 = NULL,
DOFVector<double>* vec1 = NULL,
DOFVector<double>* vec2 = NULL);
static void readMeta(string filename,
Mesh *mesh,
vector<DOFVector<double>*> vecs);
static void readFromMemoryBlock(vector<char> &data, Mesh *mesh,
DOFVector<double>* vec0 = NULL,
DOFVector<double>* vec1 = NULL,
......
......@@ -131,7 +131,6 @@ namespace AMDiS {
{
FUNCNAME("ArhWriter::writeMacroElement()");
MSG("WRITE INDEX: %d\n", elIndex);
file.write(reinterpret_cast<char*>(&elIndex), 4);
uint32_t nStructureCodes = code.getCode().size();
......
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