Commit 7acfe3ad authored by Siqi Ling's avatar Siqi Ling
Browse files

add write tarh

parent 96d0b4bc
...@@ -25,6 +25,10 @@ namespace AMDiS { namespace io { ...@@ -25,6 +25,10 @@ namespace AMDiS { namespace io {
{ {
const uint8_t MAJOR = 3; const uint8_t MAJOR = 3;
const uint8_t MINOR = 0; const uint8_t MINOR = 0;
const uint8_t PARH_MAJOR = 1;
const uint8_t PARH_MINOR = 0;
const uint8_t TARH_MAJOR = 1;
const uint8_t TARH_MINOR = 0;
/** /**
* \brief Read MeshStructure, refine the mesh and read dof values to sysVec by order. * \brief Read MeshStructure, refine the mesh and read dof values to sysVec by order.
......
...@@ -198,6 +198,20 @@ namespace AMDiS ...@@ -198,6 +198,20 @@ namespace AMDiS
} }
} }
if (writeArhAnimation) {
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0)
#endif
{
Arh3Writer::detail::updateAnimationFile(adaptInfo,
&arhAnimationFrames,
createSubDir > 0,
indexLength,
indexDecimals,
filename + ".tarh");
}
}
if (writeDofFormat) { if (writeDofFormat) {
DofWriter::writeFile(solutionVecs, fn + ".dof"); DofWriter::writeFile(solutionVecs, fn + ".dof");
......
...@@ -84,6 +84,11 @@ namespace AMDiS { ...@@ -84,6 +84,11 @@ namespace AMDiS {
return paraviewAnimationFrames; return paraviewAnimationFrames;
} }
std::vector<double>& getArhAnimationFrames()
{
return arhAnimationFrames;
}
bool getWriteParaViewFormat() const bool getWriteParaViewFormat() const
{ {
return writeParaViewFormat; return writeParaViewFormat;
...@@ -178,6 +183,9 @@ namespace AMDiS { ...@@ -178,6 +183,9 @@ namespace AMDiS {
/// write Arh2 version 3.0, prior to writeArhFormat /// write Arh2 version 3.0, prior to writeArhFormat
int writeArh3; int writeArh3;
/// 0: Don't write Arh animation file; 1: Write Arh animation file.
int writeArhAnimation;
/// camera position for povray script files /// camera position for povray script files
std::string povrayCameraLocation; std::string povrayCameraLocation;
...@@ -192,6 +200,9 @@ namespace AMDiS { ...@@ -192,6 +200,9 @@ namespace AMDiS {
/// animation file. /// animation file.
std::vector<std::pair<double, std::string> > paraviewAnimationFrames; std::vector<std::pair<double, std::string> > paraviewAnimationFrames;
/// Stores a set of timepoint to write a ParaView animation file.
std::vector<double> arhAnimationFrames;
/// ///
int timestepNumber; int timestepNumber;
......
...@@ -142,9 +142,11 @@ namespace AMDiS ...@@ -142,9 +142,11 @@ namespace AMDiS
writeArh1 = 0; writeArh1 = 0;
writeArh2 = 0; writeArh2 = 0;
writeArh3 = 0; writeArh3 = 0;
writeArhAnimation = 0;
pngType = 0; pngType = 0;
nTmpSolutions = 0; nTmpSolutions = 0;
paraviewAnimationFrames.resize(0), paraviewAnimationFrames.resize(0);
arhAnimationFrames.resize(0);
compression = NONE; compression = NONE;
readParameters(name); readParameters(name);
...@@ -181,6 +183,7 @@ namespace AMDiS ...@@ -181,6 +183,7 @@ namespace AMDiS
Parameters::get(name + "->ARH1 format", writeArh1); Parameters::get(name + "->ARH1 format", writeArh1);
Parameters::get(name + "->ARH2 format", writeArh2); Parameters::get(name + "->ARH2 format", writeArh2);
Parameters::get(name + "->ARH3 format", writeArh3); Parameters::get(name + "->ARH3 format", writeArh3);
Parameters::get(name + "->Arh animation", writeArhAnimation);
std::string compressionStr = ""; std::string compressionStr = "";
Parameters::get(name + "->compression", compressionStr); Parameters::get(name + "->compression", compressionStr);
......
...@@ -573,7 +573,7 @@ namespace AMDiS { namespace io { ...@@ -573,7 +573,7 @@ namespace AMDiS { namespace io {
sPos = file_onlyname.string().find(".arh"); sPos = file_onlyname.string().find(".arh");
string onlynameWithoutExt = file_onlyname.string().substr(0, sPos); string onlynameWithoutExt = file_onlyname.string().substr(0, sPos);
string parh = filenameWithoutExt + ".parh"; string parh = filenameWithoutExt + ".parh";
string basedir = ""; string basedir = "./";
path file_path = file_name.remove_filename(); path file_path = file_name.remove_filename();
int nProcs_ = 0, nMacros_ = 0, nMacros = 0; int nProcs_ = 0, nMacros_ = 0, nMacros = 0;
...@@ -583,7 +583,6 @@ namespace AMDiS { namespace io { ...@@ -583,7 +583,6 @@ namespace AMDiS { namespace io {
if (parhExists) if (parhExists)
basedir = readParallelFile(parh, partition, nProcs_, nMacros_); basedir = readParallelFile(parh, partition, nProcs_, nMacros_);
if (basedir != "")
filenameWithoutExt = file_path.string() + '/' + basedir + onlynameWithoutExt; filenameWithoutExt = file_path.string() + '/' + basedir + onlynameWithoutExt;
if (nProcs == -1) { if (nProcs == -1) {
...@@ -848,7 +847,7 @@ namespace AMDiS { namespace io { ...@@ -848,7 +847,7 @@ namespace AMDiS { namespace io {
string Id = fd.substr(0, 4); string Id = fd.substr(0, 4);
int major = boost::lexical_cast<int>(fd.substr(5, 1)); int major = boost::lexical_cast<int>(fd.substr(5, 1));
int minor = boost::lexical_cast<int>(fd.substr(7, 1)); int minor = boost::lexical_cast<int>(fd.substr(7, 1));
firstRead(Id, major, minor, "parh", 1, 0); firstRead(Id, major, minor, "parh", PARH_MAJOR, PARH_MINOR);
uint32_t baseDirLen = 0, macroFile_nl = 0; uint32_t baseDirLen = 0, macroFile_nl = 0;
string baseDir, macroFilename; string baseDir, macroFilename;
......
...@@ -10,7 +10,9 @@ ...@@ -10,7 +10,9 @@
#include "DOFVector.h" #include "DOFVector.h"
#include "../Arh3Reader.h" #include "../Arh3Reader.h"
#include <boost/iostreams/filtering_stream.hpp>
#include <boost/iostreams/filtering_streambuf.hpp> #include <boost/iostreams/filtering_streambuf.hpp>
#include <boost/iostreams/device/file_descriptor.hpp>
#include <boost/iostreams/copy.hpp> #include <boost/iostreams/copy.hpp>
#ifdef HAVE_COMPRESSION #ifdef HAVE_COMPRESSION
#include <boost/iostreams/filter/zlib.hpp> #include <boost/iostreams/filter/zlib.hpp>
...@@ -45,6 +47,55 @@ namespace AMDiS { namespace io { ...@@ -45,6 +47,55 @@ namespace AMDiS { namespace io {
write(filename, NULL, vecs, writeParallel, cps, dataformat, writeMacro); write(filename, NULL, vecs, writeParallel, cps, dataformat, writeMacro);
} }
void updateAnimationFile(AdaptInfo *adaptInfo,
std::vector<double>* arhAnimationFrames,
bool createSubDir,
int indexLength,
int indexDecimals,
std::string animationFilename)
{
FUNCNAME("updateAnimationFile()");
arhAnimationFrames->push_back(adaptInfo->getTime());
boost::iostreams::filtering_ostream file;
{
ofstream swapfile(animationFilename.c_str(),
ios::out | ios::trunc | ios::binary);
TEST_EXIT(swapfile.is_open())
("Cannot open file %s for writing!\n", animationFilename.c_str());
swapfile.close();
}
file.push(boost::iostreams::file_descriptor_sink(animationFilename,
ios::trunc | ios::binary));
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS
string typeId = "tparh";
#else
string typeId = "tarh";
#endif
string baseDir = createSubDir ? "./data/" : "./";
uint32_t baseDirLen = baseDir.length();
int major = AMDiS::io::Arh3Reader::TARH_MAJOR;
int minor = AMDiS::io::Arh3Reader::TARH_MINOR;
typeId += '_' + boost::lexical_cast<string>(major) + '.' + boost::lexical_cast<string>(minor);
if (typeId.length() <= 16) { // 16 is the Id size
string rest(16 - typeId.length(), ' ');
typeId.append(rest);
}
uint32_t indexLength_ = indexLength;
uint32_t indexDecimals_ = indexDecimals;
file.write(typeId.c_str(), 16);
file.write(reinterpret_cast<char*>(&baseDirLen), 4);
file.write(baseDir.c_str(), baseDirLen);
file.write(reinterpret_cast<char*>(&indexLength_), 4);
file.write(reinterpret_cast<char*>(&indexDecimals_), 4);
for (size_t i = 0; i < arhAnimationFrames->size(); i++)
file.write(reinterpret_cast<char*>(&arhAnimationFrames[i]), 8);
}
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
void writeParallelFile(string filename, Mesh* mesh, bool createSubDir, bool writeMacro) void writeParallelFile(string filename, Mesh* mesh, bool createSubDir, bool writeMacro)
{ {
...@@ -52,13 +103,14 @@ namespace AMDiS { namespace io { ...@@ -52,13 +103,14 @@ namespace AMDiS { namespace io {
file.open(filename.c_str(), ios::out | ios::binary | ios::trunc); file.open(filename.c_str(), ios::out | ios::binary | ios::trunc);
string typeId = "parh", macroFilename = "", perFilename = ""; string typeId = "parh", macroFilename = "", perFilename = "";
string baseDir = createSubDir ? "./data/" : ""; string baseDir = createSubDir ? "./data/" : "./";
string macroData = "", periodicData = ""; string macroData = "", periodicData = "";
uint32_t baseDirLen = baseDir.length(); uint32_t baseDirLen = baseDir.length();
Parameters::get(mesh->getName() + "->macro file name", macroFilename); Parameters::get(mesh->getName() + "->macro file name", macroFilename);
Parameters::get(mesh->getName() + "->periodic file", perFilename); Parameters::get(mesh->getName() + "->periodic file", perFilename);
int major = 1, minor = 0; int major = AMDiS::io::Arh3Reader::PARH_MAJOR;
int minor = AMDiS::io::Arh3Reader::PARH_MINOR;
uint32_t nFiles = MPI::COMM_WORLD.Get_size(); uint32_t nFiles = MPI::COMM_WORLD.Get_size();
uint32_t macroFile_nl = 0; uint32_t macroFile_nl = 0;
map<int, int> partitionMap = map<int, int> partitionMap =
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "MeshStructure.h" #include "MeshStructure.h"
#include "DOFVector.h" #include "DOFVector.h"
#include "SystemVector.h" #include "SystemVector.h"
#include "AdaptInfo.h"
#include "boost/assign.hpp" #include "boost/assign.hpp"
namespace AMDiS { namespace io { namespace AMDiS { namespace io {
...@@ -111,6 +112,13 @@ namespace AMDiS { namespace io { ...@@ -111,6 +112,13 @@ namespace AMDiS { namespace io {
void readFileToString(std::string filename, std::string& data); void readFileToString(std::string filename, std::string& data);
void updateAnimationFile(AdaptInfo *adaptInfo,
std::vector<double>* arhAnimationFrames,
bool createSubDir,
int indexLength,
int indexDecimals,
std::string animationFilename);
#ifdef HAVE_PARALLEL_DOMAIN_AMDIS #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
void writeParallelFile(std::string filename, void writeParallelFile(std::string filename,
Mesh* mesh, Mesh* mesh,
......
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