Newer
Older
#include "FileWriter.h"
#include "SystemVector.h"
#include "Parameters.h"
#include "TecPlotWriter.h"
#include "ValueWriter.h"
#include "MacroWriter.h"
#include "VtkWriter.h"
#include "FiniteElemSpace.h"
#include "AdaptInfo.h"
#include "Flag.h"
#include "ElInfo.h"
#include "Mesh.h"
FileWriter::FileWriter(const std::string &name_,
Mesh *mesh_,
DOFVector<double> *vec)
: name(name_),
mesh(mesh_)
{

Thomas Witkowski
committed
FUNCNAME("FileWriter::FileWriter()");
initialize();
feSpace = vec->getFESpace();
solutionVecs_.resize(1);
solutionVecs_[0] = vec;

Thomas Witkowski
committed
FileWriter::FileWriter(const std::string &name_,
std::vector< DOFVector<double>* > vecs)
: name(name_),
mesh(mesh_)
{
FUNCNAME("FileWriter::FileWriter()");

Thomas Witkowski
committed
initialize();
for (int i = 0; i < static_cast<int>(vecs.size()); i++) {
TEST_EXIT(vecs[0]->getFESpace() == vecs[i]->getFESpace())
("All FESpace have to be equal!\n");
}
feSpace = vecs[0]->getFESpace();
solutionVecs_ = vecs;

Thomas Witkowski
committed
FileWriter::FileWriter(const std::string &name_,

Thomas Witkowski
committed
Mesh *mesh_,
DOFVector< WorldVector<double> > *vec)
: name(name_),
mesh(mesh_)
{
FUNCNAME("FileWriter::FileWriter()");
initialize();
// Create the temporal DOFVectors for all components of WorldVector.
nTmpSolutions_ = (*vec)[0].getSize();
solutionVecs_.resize(nTmpSolutions_);
for (int i = 0; i < nTmpSolutions_; i++) {
solutionVecs_[i] = NEW DOFVector<double>(vec->getFESpace(), "");
}
// Copy the components of the WorldVectors to different DOFVectors
// of double values.
DOFVector< WorldVector<double> >::Iterator it(vec, USED_DOFS);
int counter = 0;
for (it.reset(); !it.end(); ++it, counter++) {
for (int i = 0; i < nTmpSolutions_; i++) {
(*solutionVecs_[i])[counter] = (*it)[i];
}
}
feSpace = vec->getFESpace();

Thomas Witkowski
committed
}
FileWriter::~FileWriter()
{
// Do not forget to delete temporal solution vector, if there have been
// some created in the constructor.
if (nTmpSolutions_ > 0) {
for (int i = 0; i < nTmpSolutions_; i++) {
DELETE solutionVecs_[i];
}
}
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
if (dataCollectors_[i]) {
DELETE dataCollectors_[i];
}
}

Thomas Witkowski
committed
}
void FileWriter::initialize()
{
tecplotExt = ".tec";
amdisMeshExt = ".mesh";
amdisDataExt = ".dat";
paraViewFileExt = ".vtu";
periodicFileExt = ".per";
writeTecPlotFormat = 0;
writeAMDiSFormat = 0;
writeParaViewFormat = 0;

Thomas Witkowski
committed
writePeriodicFormat = 0;
appendIndex = 0;
indexLength = 5;
indexDecimals = 3;
tsModulo = 1;
nTmpSolutions_ = 0;
delayWriting_ = 0;
writingIsDelayed_ = false;
delayedFilename_ = "";
paraViewAnimationFrames_.resize(0);
readParameters();

Thomas Witkowski
committed
}
void FileWriter::readParameters()
{
FUNCNAME("FileWriter::readParamters()");
GET_PARAMETER(0, name + "->filename", &filename);
GET_PARAMETER(0, name + "->TecPlot format", "%d", &writeTecPlotFormat);
GET_PARAMETER(0, name + "->TecPlot ext", &tecplotExt);
GET_PARAMETER(0, name + "->AMDiS format", "%d", &writeAMDiSFormat);
GET_PARAMETER(0, name + "->AMDiS mesh ext", &amdisMeshExt);
GET_PARAMETER(0, name + "->AMDiS data ext", &amdisDataExt);
GET_PARAMETER(0, name + "->ParaView format", "%d", &writeParaViewFormat);
GET_PARAMETER(0, name + "->ParaView animation", "%d", &writeParaViewAnimation);
GET_PARAMETER(0, name + "->ParaView ext", ¶ViewFileExt);
GET_PARAMETER(0, name + "->Periodic format", "%d", &writePeriodicFormat);
GET_PARAMETER(0, name + "->Periodic ext", &periodicFileExt);
GET_PARAMETER(0, name + "->append index", "%d", &appendIndex);
GET_PARAMETER(0, name + "->index length", "%d", &indexLength);
GET_PARAMETER(0, name + "->index decimals", "%d", &indexDecimals);
GET_PARAMETER(0, name + "->write every i-th timestep", "%d", &tsModulo);
GET_PARAMETER(0, name + "->delay", "%d", &delayWriting_);
TEST_EXIT(!delayWriting_ || amdisHaveOpenMP)
("Delayed writing only possible with OpenMP support!\n");
}
void FileWriter::writeFiles(AdaptInfo *adaptInfo,
bool force,
int level,
Flag flag,
bool (*writeElem)(ElInfo*))
{
FUNCNAME("FileWriter::writeFiles()");
if ((adaptInfo->getTimestepNumber() % tsModulo != 0) && !force)
return;
if (writingIsDelayed_) {
ERROR_EXIT("This should not happen!\n");
}
if (writeElem) {
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
dataCollectors_[i] = NEW DataCollector(feSpace, solutionVecs_[i],
level, flag, writeElem);
}
} else {
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
dataCollectors_[i] = NEW DataCollector(feSpace, solutionVecs_[i],
traverseLevel, flag | traverseFlag, writeElement);
}
}
if (appendIndex) {
TEST_EXIT(indexLength <= 99)("index lenght > 99\n");
TEST_EXIT(indexDecimals <= 97)("index decimals > 97\n");
TEST_EXIT(indexDecimals < indexLength)("index length <= index decimals\n");
char formatStr[9];
char timeStr[20];
sprintf(formatStr, "%%0%d.%df", indexLength, indexDecimals);
sprintf(timeStr, formatStr, adaptInfo ? adaptInfo->getTime() : 0.0);
fn += timeStr;
}
if (delayWriting_) {
if (writeTecPlotFormat || writeAMDiSFormat || writePeriodicFormat) {
ERROR_EXIT("Delay writing only supported for ParaView file format!\n");
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
dataCollectors_[i]->fillAllData();
writingIsDelayed_ = true;
delayedFilename_ = fn;
MSG("Delayed writing of ParaView file %s\n", (fn + paraViewFileExt).c_str());
if (writeTecPlotFormat) {
TecPlotWriter<DOFVector<double> >::writeValues(solutionVecs_[0],
const_cast<char*>((fn + tecplotExt).c_str()),
solutionVecs_[0]->getName().c_str());
MSG("TecPlot file written to %s\n", (fn + tecplotExt).c_str());
}
if (writeAMDiSFormat) {
TEST_EXIT(mesh)("no mesh\n");
MacroWriter::writeMacro(dataCollectors_[0],
const_cast<char*>((fn + amdisMeshExt).c_str()),
adaptInfo ? adaptInfo->getTime() : 0.0);
MSG("macro file written to %s\n", (fn + amdisMeshExt).c_str());
(fn + amdisDataExt).c_str(),
adaptInfo ? adaptInfo->getTime() : 0.0);
MSG("value file written to %s\n", (fn + amdisDataExt).c_str());
}
if (writePeriodicFormat) {
MacroWriter::writePeriodicFile(dataCollectors_[0],
(fn + periodicFileExt).c_str());
MSG("periodic file written to %s\n", (fn + periodicFileExt).c_str());
}
if (writeParaViewFormat) {
VtkWriter vtkWriter(&dataCollectors_);
vtkWriter.writeFile(const_cast<char*>((fn + paraViewFileExt).c_str()));
MSG("ParaView file written to %s\n", (fn + paraViewFileExt).c_str());
}
vtkWriter.updateAnimationFile(fn + paraViewFileExt,
¶ViewAnimationFrames_,
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
DELETE dataCollectors_[i];
}
}
void FileWriter::writeDelayedFiles()
{
if (!writingIsDelayed_) {
return;
}
if (writeParaViewFormat) {
VtkWriter vtkWriter(&dataCollectors_);
vtkWriter.writeFile(const_cast<char*>((delayedFilename_ + paraViewFileExt).c_str()));
}
if (writeParaViewAnimation) {
VtkWriter vtkWriter(&dataCollectors_);
vtkWriter.updateAnimationFile(delayedFilename_ + paraViewFileExt,
¶ViewAnimationFrames_,
const_cast<char*>((filename + ".pvd").c_str()));
for (int i = 0; i < static_cast<int>(dataCollectors_.size()); i++) {
DELETE dataCollectors_[i];
}
writingIsDelayed_ = false;
delayedFilename_ = "";