Newer
Older

Thomas Witkowski
committed
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.

Thomas Witkowski
committed
#include "boost/lexical_cast.hpp"
#include "Initfile.h"
#include "ValueWriter.h"
#include "MacroWriter.h"
#include "VtkWriter.h"
#include "VtkVectorWriter.h"
#include "VtkVectorWriter.hh"
#include "PngWriter.h"
#include "FiniteElemSpace.h"
#include "AdaptInfo.h"
#include "Flag.h"
#include "ElInfo.h"
#include "Mesh.h"
#include "DataCollector.hh"
#if HAVE_PARALLEL_DOMAIN_AMDIS

Thomas Witkowski
committed
using boost::lexical_cast;

Thomas Witkowski
committed
template<>
FileWriterTemplated<double>::FileWriterTemplated(std::string name_,
Mesh *mesh_,
SystemVector *vecs)
: name(name_),
mesh(mesh_)
{
FUNCNAME("FileWriterTemplated<T>::FileWriterTemplated()");
initialize();
for (int i = 0; i < static_cast<int>(vecs->getSize()); i++)
TEST_EXIT(vecs->getDOFVector(0)->getFeSpace() == vecs->getDOFVector(i)->getFeSpace())
("All FeSpace have to be equal!\n");
feSpace = vecs->getDOFVector(0)->getFeSpace();
solutionVecs.resize(vecs->getSize());
for (int i = 0; i < static_cast<int>(vecs->getSize()); i++)
solutionVecs[i] = vecs->getDOFVector(i);
}

Thomas Witkowski
committed
template<>
void FileWriterTemplated<double>::writeFiles(AdaptInfo *adaptInfo,
bool force,
int level,
Flag flag,
bool (*writeElem)(ElInfo*))
{
FUNCNAME("FileWriterTemplated<T>::writeFiles()");
if ((adaptInfo->getTimestepNumber() % tsModulo != 0) && !force)
// Containers, which store the data to be written;
std::vector<DataCollector<>*> dataCollectors(solutionVecs.size());
for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
dataCollectors[i] = new DataCollector<>(feSpace, solutionVecs[i],
for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
dataCollectors[i] = new DataCollector<>(feSpace, solutionVecs[i],
traverseLevel,
flag | traverseFlag,
writeElement);
#if HAVE_PARALLEL_DOMAIN_AMDIS

Thomas Witkowski
committed
fn += "-p" + lexical_cast<std::string>(MPI::COMM_WORLD.Get_rank()) + "-";
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 HAVE_PARALLEL_DOMAIN_AMDIS
paraFilename += timeStr;

Thomas Witkowski
committed
postfix += timeStr + paraviewFileExt;

Thomas Witkowski
committed
#endif
} else {
#if HAVE_PARALLEL_DOMAIN_AMDIS
postfix += paraviewFileExt;
}
if (writeAMDiSFormat) {
MacroWriter::writeMacro(dataCollectors[0],
const_cast<char*>((fn + amdisMeshExt).c_str()),

Thomas Witkowski
committed
adaptInfo ? adaptInfo->getTime() : 0.0);
MSG("macro file written to %s\n", (fn + amdisMeshExt).c_str());
ValueWriter::writeValues(dataCollectors[0],
(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.setCompression(compression);
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0)
vtkWriter.writeParallelFile(paraFilename + paraviewParallelFileExt,
MPI::COMM_WORLD.Get_size(),
filename, postfix,
dataCollectors.size());
MSG("ParaView file written to %s\n", (fn + paraviewFileExt).c_str());
if (writeParaViewVectorFormat) {
VtkVectorWriter::writeFile(solutionVecs, fn + paraviewFileExt, true, writeAs3dVector);
// VtkVectorWriter::Impl<double> vtkVectorWriter(&dataCollectors, writeAs3dVector);
// vtkVectorWriter.setCompression(compression);
// vtkVectorWriter.setWriteAs3dVector(writeAs3dVector);
// vtkVectorWriter.writeFile(fn + paraviewFileExt);
MSG("ParaView file written to %s\n", (fn + paraviewFileExt).c_str());
}
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0) {
VtkWriter::updateAnimationFile(adaptInfo,
paraFilename + paraviewParallelFileExt,
¶viewAnimationFrames,
filename + ".pvd");
}
#else
VtkWriter::updateAnimationFile(adaptInfo,
fn + paraviewFileExt,
if (writeDofFormat) {
DofWriter dofWriter(feSpace);
dofWriter.writeFile(fn + ".dof", solutionVecs);
}
if (writeArhFormat)
ArhWriter::write(fn + ".arh", feSpace->getMesh(), solutionVecs);

Thomas Witkowski
committed
#ifdef HAVE_PNG
if (writePngFormat) {
PngWriter pngWriter(dataCollectors[0]);
pngWriter.writeFile(fn + ".png", pngType);
MSG("PNG image file written to %s\n", (fn + ".png").c_str());

Thomas Witkowski
committed
#endif
if (writePovrayFormat) {
PovrayWriter povrayWriter(this, dataCollectors[0]);
povrayWriter.writeFile(fn + ".pov");
MSG("Povray script written to %s\n", (fn + ".pov").c_str());
}
for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)