Commit 398d1d8e authored by Praetorius, Simon's avatar Praetorius, Simon

FileWriter templated

parent b115e944
......@@ -126,6 +126,7 @@
#include "io/VtkVectorWriter.h"
#include "io/DataCollector.hh"
#include "io/FileWriter.hh"
#include "io/VtkVectorWriter.hh"
#include "nonlin/ProblemNonLin.h"
......
......@@ -59,6 +59,7 @@ namespace AMDiS {
virtual void addProblem(ProblemStat* prob)
{
problems.push_back(prob);
nComponents += prob->getNumComponents();
};
/// Initialisation of the problem.
......@@ -96,7 +97,6 @@ namespace AMDiS {
std::map<std::pair<Mesh*, int>, FiniteElemSpace*> feSpaceMap;
for (size_t i = 0; i < problems.size(); ++i) {
TEST_EXIT(problems[i])("problem[%d] does not exist!\n",i);
nComponents += problems[i]->getNumComponents();
for (size_t j = 0; j < problems[i]->getNumComponents(); j++) {
// mesh
......
......@@ -908,6 +908,10 @@ namespace AMDiS {
template<typename T>
T integrate_VecAndCoords(const DOFVector<double> &vec,
BinaryAbstractFunction<T, double, WorldVector<double> > *fct);
template<typename T1, typename T2>
T2 integrate_Vec(const DOFVector<T1> &vec,
AbstractFunction<T2, T1> *fct);
}
#include "DOFVector.hh"
......
......@@ -578,6 +578,49 @@ namespace AMDiS {
elInfo = stack.traverseNext(elInfo);
}
// #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
// double localValue = value;
// MPI::COMM_WORLD.Allreduce(&localValue, &value, 1, MPI_DOUBLE, MPI_SUM);
// #endif
return value;
}
template<typename T1, typename T2>
T2 integrate_Vec(const DOFVector<T1> &vec,
AbstractFunction<T2, T1> *fct)
{
FUNCNAME("integrate_VecAndCoords()");
TEST_EXIT(fct)("No function defined!\n");
int deg = std::max(fct->getDegree(),
2 * vec.getFeSpace()->getBasisFcts()->getDegree());
Quadrature* quad =
Quadrature::provideQuadrature(vec.getFeSpace()->getMesh()->getDim(), deg);
FastQuadrature *fastQuad =
FastQuadrature::provideFastQuadrature(vec.getFeSpace()->getBasisFcts(), *quad, INIT_PHI);
mtl::dense_vector<T1> qp(fastQuad->getNumPoints());
T2 value;
nullify(value);
Flag traverseFlag = Mesh::CALL_LEAF_EL | Mesh::FILL_COORDS | Mesh::FILL_DET;
TraverseStack stack;
ElInfo *elInfo = stack.traverseFirst(vec.getFeSpace()->getMesh(), -1, traverseFlag);
while (elInfo) {
vec.getVecAtQPs(elInfo, quad, fastQuad, qp);
T2 tmp;
nullify(tmp);
for (int iq = 0; iq < fastQuad->getNumPoints(); iq++) {
tmp += fastQuad->getWeight(iq) * (*fct)(qp[iq]);
}
value += tmp * elInfo->getDet();
elInfo = stack.traverseNext(elInfo);
}
// #ifdef HAVE_PARALLEL_DOMAIN_AMDIS
// double localValue = value;
// MPI::COMM_WORLD.Allreduce(&localValue, &value, 1, MPI_DOUBLE, MPI_SUM);
......
......@@ -19,6 +19,7 @@
#include "StandardProblemIteration.h"
#include "est/Estimator.h"
#include "io/FileWriter.h"
#include "io/FileWriter.hh"
namespace AMDiS {
......
......@@ -23,6 +23,7 @@
#include "Marker.h"
#include "AdaptInfo.h"
#include "io/FileWriter.h"
#include "io/FileWriter.hh"
#include "CoarseningManager.h"
#include "RefinementManager.h"
#include "DualTraverse.h"
......
......@@ -12,6 +12,7 @@
#include "boost/lexical_cast.hpp"
#include "FileWriter.h"
#include "FileWriter.hh"
#include "Initfile.h"
#include "ValueWriter.h"
#include "MacroWriter.h"
......@@ -37,47 +38,15 @@ namespace AMDiS {
using boost::lexical_cast;
FileWriter::FileWriter(std::string str, Mesh *m, DOFVector<double> *vec)
: name(str),
mesh(m)
{
FUNCNAME("FileWriter::FileWriter()");
initialize();
feSpace = vec->getFeSpace();
solutionVecs.resize(1);
solutionVecs[0] = vec;
}
FileWriter::FileWriter(std::string name_,
Mesh *mesh_,
std::vector<DOFVector<double>*> vecs)
: name(name_),
mesh(mesh_)
{
FUNCNAME("FileWriter::FileWriter()");
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;
}
FileWriter::FileWriter(std::string name_,
template<>
FileWriterTemplated<double>::FileWriterTemplated(std::string name_,
Mesh *mesh_,
SystemVector *vecs)
: name(name_),
mesh(mesh_)
{
FUNCNAME("FileWriter::FileWriter()");
FUNCNAME("FileWriterTemplated<T>::FileWriterTemplated()");
initialize();
......@@ -90,125 +59,18 @@ namespace AMDiS {
for (int i = 0; i < static_cast<int>(vecs->getSize()); i++)
solutionVecs[i] = vecs->getDOFVector(i);
}
FileWriter::FileWriter(std::string name_,
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();
}
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];
}
void FileWriter::initialize()
{
amdisMeshExt = ".mesh";
amdisDataExt = ".dat";
paraviewFileExt = ".vtu";
paraviewParallelFileExt = ".pvtu";
periodicFileExt = ".per";
writeAMDiSFormat = 0;
writeParaViewFormat = 0;
writeParaViewVectorFormat = 0;
writeAs3dVector = false;
writeParaViewAnimation = 0;
writePeriodicFormat = 0;
writePngFormat = 0;
writePovrayFormat = 0;
writeDofFormat = 0;
writeArhFormat = 0;
pngType = 0;
appendIndex = 0;
indexLength = 5;
indexDecimals = 3;
tsModulo = 1;
nTmpSolutions = 0;
paraviewAnimationFrames.resize(0),
compression = NONE;
readParameters();
}
void FileWriter::readParameters()
{
FUNCNAME("FileWriter::readParamters()");
Parameters::get(name + "->filename", filename);
Parameters::get(name + "->AMDiS format", writeAMDiSFormat);
Parameters::get(name + "->AMDiS mesh ext", amdisMeshExt);
Parameters::get(name + "->AMDiS data ext", amdisDataExt);
Parameters::get(name + "->ParaView format", writeParaViewFormat);
Parameters::get(name + "->ParaView vector format", writeParaViewVectorFormat);
Parameters::get(name + "->write vector as 3d vector", writeAs3dVector);
Parameters::get(name + "->ParaView animation", writeParaViewAnimation);
Parameters::get(name + "->ParaView ext", paraviewFileExt);
Parameters::get(name + "->Periodic format", writePeriodicFormat);
Parameters::get(name + "->Periodic ext", periodicFileExt);
Parameters::get(name + "->PNG format", writePngFormat);
Parameters::get(name + "->PNG type", pngType);
Parameters::get(name + "->append index", appendIndex);
Parameters::get(name + "->index length", indexLength);
Parameters::get(name + "->index decimals", indexDecimals);
Parameters::get(name + "->write every i-th timestep", tsModulo);
Parameters::get(name + "->Povray format", writePovrayFormat);
Parameters::get(name + "->Povray template", povrayTemplate);
Parameters::get(name + "->Povray camera location", povrayCameraLocation);
Parameters::get(name + "->Povray camera look_at", povrayCameraLookAt);
Parameters::get(name + "->DOF format", writeDofFormat);
Parameters::get(name + "->ARH format", writeArhFormat);
std::string compressionStr = "";
Parameters::get(name + "->compression", compressionStr);
if (compressionStr == "gzip" || compressionStr == "gz") {
compression = GZIP;
} else if (compressionStr == "bzip2" || compressionStr == "bz2") {
compression = BZIP2;
}
}
void FileWriter::writeFiles(AdaptInfo *adaptInfo,
template<>
void FileWriterTemplated<double>::writeFiles(AdaptInfo *adaptInfo,
bool force,
int level,
Flag flag,
bool (*writeElem)(ElInfo*))
{
FUNCNAME("FileWriter::writeFiles()");
FUNCNAME("FileWriterTemplated<T>::writeFiles()");
if ((adaptInfo->getTimestepNumber() % tsModulo != 0) && !force)
if ((adaptInfo->getTimestepNumber() % tsModulo != 0) && !force)
return;
// Containers, which store the data to be written;
......@@ -216,13 +78,13 @@ namespace AMDiS {
if (writeElem) {
for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
dataCollectors[i] = new DataCollector<>(feSpace, solutionVecs[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,
dataCollectors[i] = new DataCollector<>(feSpace, solutionVecs[i],
traverseLevel,
flag | traverseFlag,
writeElement);
}
......@@ -238,7 +100,7 @@ namespace AMDiS {
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];
......@@ -257,27 +119,27 @@ namespace AMDiS {
}
if (writeAMDiSFormat) {
MacroWriter::writeMacro(dataCollectors[0],
const_cast<char*>((fn + amdisMeshExt).c_str()),
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());
ValueWriter::writeValues(dataCollectors[0],
(fn + amdisDataExt).c_str(),
adaptInfo ? adaptInfo->getTime() : 0.0);
MSG("value file written to %s\n", (fn + amdisDataExt).c_str());
MSG("value file written to %s\n", (fn + amdisDataExt).c_str());
}
if (writePeriodicFormat) {
MacroWriter::writePeriodicFile(dataCollectors[0],
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 vtkWriter(&dataCollectors);
vtkWriter.setCompression(compression);
vtkWriter.writeFile(fn + paraviewFileExt);
vtkWriter.writeFile(fn + paraviewFileExt);
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0)
......@@ -290,11 +152,23 @@ namespace AMDiS {
}
if (writeParaViewVectorFormat) {
VtkVectorWriter::writeFile(solutionVecs, fn + paraviewFileExt, true, writeAs3dVector);
// VtkVectorWriter::writeFile(solutionVecs, fn + paraviewFileExt, true, writeAs3dVector);
VtkVectorWriter::Impl<double> vtkVectorWriter(&dataCollectors, writeAs3dVector);
vtkVectorWriter.setCompression(compression);
vtkVectorWriter.setWriteAs3dVector(writeAs3dVector);
vtkVectorWriter.writeFile(fn + paraviewFileExt);
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0)
vtkVectorWriter.writeParallelFile(paraFilename + paraviewParallelFileExt,
MPI::COMM_WORLD.Get_size(),
filename, postfix);
#endif
MSG("ParaView file written to %s\n", (fn + paraviewFileExt).c_str());
}
if (writeParaViewAnimation) {
#if HAVE_PARALLEL_DOMAIN_AMDIS
if (MPI::COMM_WORLD.Get_rank() == 0) {
......@@ -339,7 +213,7 @@ namespace AMDiS {
MSG("Povray script written to %s\n", (fn + ".pov").c_str());
}
for (int i = 0; i < static_cast<int>(dataCollectors.size()); i++)
delete dataCollectors[i];
}
......
......@@ -103,32 +103,25 @@ namespace AMDiS {
* Base class of FileWriterScal and FileWriterVec. Manages the file output
* of solution vectors.
*/
class FileWriter : public FileWriterInterface
template<typename T>
class FileWriterTemplated : public FileWriterInterface
{
public:
/// Constructor for a filewriter for one data component.
FileWriter(string name, Mesh *mesh, DOFVector<double> *vec);
FileWriterTemplated(string name, Mesh *mesh, DOFVector<T> *vec);
/// Constructor for a filewriter with more than one data component.
FileWriter(string name,
FileWriterTemplated(string name,
Mesh *mesh,
vector< DOFVector<double>* > vecs);
vector< DOFVector<T>* > vecs);
/// Constructor for a filewriter with more than one data component.
FileWriter(std::string name,
FileWriterTemplated(std::string name,
Mesh *mesh,
SystemVector *vecs);
/** \brief
* Constructor for a filewriter, when the solution vector is a vector
* of WorldVectors.
*/
FileWriter(string name,
Mesh *mesh,
DOFVector< WorldVector<double> > *vec);
/// Destructor
virtual ~FileWriter();
virtual ~FileWriterTemplated();
/// Implementation of FileWriterInterface::writeFiles().
virtual void writeFiles(AdaptInfo *adaptInfo, bool force,
......@@ -230,7 +223,7 @@ namespace AMDiS {
const FiniteElemSpace *feSpace;
/// Pointers to the vectors which store the solution.
vector<DOFVector<double>*> solutionVecs;
vector<DOFVector<T>*> solutionVecs;
/** \brief
* Stores the number of temporal solutions vectors, which have been created
......@@ -246,6 +239,21 @@ namespace AMDiS {
FileCompression compression;
};
template<>
FileWriterTemplated<double>::FileWriterTemplated(std::string name_,
Mesh *mesh_,
SystemVector *vecs);
template<>
void FileWriterTemplated<double>::writeFiles(AdaptInfo *adaptInfo,
bool force,
int level,
Flag flag,
bool (*writeElem)(ElInfo*));
typedef FileWriterTemplated<double> FileWriter;
typedef FileWriterTemplated<WorldVector<double> > FileVectorWriter;
}
#endif // AMDIS_FILEWRITER_H
......@@ -39,7 +39,9 @@ namespace AMDiS {
class VtkVectorWriter
{
template<typename S>
public:
template<typename S>
struct Impl {
Impl(std::vector<DataCollector<S>*> *dc, bool writeAs3dVector_=false)
: dataCollector(dc),
......@@ -63,7 +65,11 @@ namespace AMDiS {
{
compress = c;
}
void setWriteAs3dVector(bool w) {
writeAs3dVector = w;
}
protected:
/// Writes the VTK file to an arbitrary stream.
template<typename T>
......
......@@ -185,8 +185,12 @@ namespace AMDiS {
for (int i = 0; i < static_cast<int>(dataCollector->size()); i++) {
S temp = (*((*dataCollector)[i]->getValues()))[0];
int numComponent = num_rows(temp);
std::string name = (*dataCollector)[i]->getValues()->getName();
if (name.find_first_not_of(" \n\r\t") == std::string::npos)
name = "value" + boost::lexical_cast<std::string>(i);
file << " <DataArray type=\"Float32\" Name=\""
<< (*dataCollector)[i]->getValues()->getName()
<< name
<< "\" format=\"ascii\"" << (numComponent > 1 ? " NumberOfComponents=\"" + boost::lexical_cast<std::string>(numComponent) + "\"" : "") << ">\n";
writeVertexValues(file, i);
......
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