Commit 167413c4 authored by Thomas Witkowski's avatar Thomas Witkowski
Browse files

* Faster VTK output

parent e6cd8e18
......@@ -28,69 +28,69 @@ namespace AMDiS {
nElements *= 16;
}
::std::ofstream file;
std::ofstream file;
file.open(name);
file << "<?xml version=\"1.0\"?>" << ::std::endl;
file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << ::std::endl;
file << " <UnstructuredGrid>" << ::std::endl;
file << "<?xml version=\"1.0\"?>\n";
file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
file << " <UnstructuredGrid>\n";
file << " <Piece NumberOfPoints=\"" << nVertices
<< "\" NumberOfCells=\"" << nElements << "\">" << ::std::endl;
file << " <Points>" << ::std::endl;
file << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << ::std::endl;
<< "\" NumberOfCells=\"" << nElements << "\">\n";
file << " <Points>\n";
file << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
writeVertexCoords(file);
file << " </DataArray>" << ::std::endl;
file << " </Points>" << ::std::endl;
file << " <Cells>" << ::std::endl;
file << " <DataArray type=\"Int32\" Name=\"offsets\">" << ::std::endl;
file << " </DataArray>\n";
file << " </Points>\n";
file << " <Cells>\n";
file << " <DataArray type=\"Int32\" Name=\"offsets\">\n";
for (int i = 0; i < nElements; i++) {
file << " " << (i + 1) * vertices << ::std::endl;
file << " " << (i + 1) * vertices << "\n";
}
file << " </DataArray>" << ::std::endl;
file << " <DataArray type=\"UInt8\" Name=\"types\">" << ::std::endl;
file << " </DataArray>\n";
file << " <DataArray type=\"UInt8\" Name=\"types\">\n";
for (int i = 0; i < nElements; i++) {
switch (vertices) {
case 2:
file << " 3" << ::std::endl;
file << " 3\n";
break;
case 3:
file << " 5" << ::std::endl;
file << " 5\n";
break;
case 4:
file << " 10" << ::std::endl;
file << " 10\n";
break;
default:
break;
}
}
file << " </DataArray>" << ::std::endl;
file << " <DataArray type=\"Int32\" Name=\"connectivity\">" << ::std::endl;
file << " </DataArray>\n";
file << " <DataArray type=\"Int32\" Name=\"connectivity\">\n";
writeConnectivity(file);
file << " </DataArray>" << ::std::endl;
file << " </Cells>" << ::std::endl;
file << " <PointData>" << ::std::endl;
file << " </DataArray>\n";
file << " </Cells>\n";
file << " <PointData>\n";
for (int i = 0; i < static_cast<int>(dc_->size()); i++) {
file << " <DataArray type=\"Float32\" Name=\"value" << i
<< "\" format=\"ascii\">" << ::std::endl;
<< "\" format=\"ascii\">\n";
writeVertexValues(file, i);
file << " </DataArray>" << ::std::endl;
file << " </DataArray>\n";
}
file << " </PointData>" << ::std::endl;
file << " </Piece>" << ::std::endl;
file << " </UnstructuredGrid>" << ::std::endl;
file << "</VTKFile>" << ::std::endl;
file << " </PointData>\n";
file << " </Piece>\n";
file << " </UnstructuredGrid>\n";
file << "</VTKFile>\n";
file.close();
......@@ -99,16 +99,16 @@ namespace AMDiS {
}
void VtkWriter::writeVertexCoords(::std::ofstream &file)
void VtkWriter::writeVertexCoords(std::ofstream &file)
{
DOFVector< ::std::list<VertexInfo> > *vertexInfos = (*dc_)[0]->getVertexInfos();
DOFVector< ::std::list<VertexInfo> >::Iterator it(vertexInfos, USED_DOFS);
DOFVector< std::list<VertexInfo> > *vertexInfos = (*dc_)[0]->getVertexInfos();
DOFVector< std::list<VertexInfo> >::Iterator it(vertexInfos, USED_DOFS);
int counter = 0;
// For all DOFs of vertices, write the coordinates.
for (it.reset(); !it.end(); ++it) {
// for all vertex infos of this DOF
::std::list<VertexInfo>::iterator it2;
std::list<VertexInfo>::iterator it2;
for (it2 = it->begin(); it2 != it->end(); ++it2) {
it2->outputIndex = counter++;
writeCoord(file, it2->coords);
......@@ -117,11 +117,11 @@ namespace AMDiS {
// For the second dim case, write also the interpolation points.
if ((dim_ == 2) && (degree_ > 1)) {
DOFVector< ::std::list< WorldVector<double> > > *interpPointCoords = (*dc_)[0]->getInterpPointCoords();
DOFVector< ::std::list< WorldVector<double> > >::Iterator pointIt(interpPointCoords, USED_DOFS);
DOFVector< std::list< WorldVector<double> > > *interpPointCoords = (*dc_)[0]->getInterpPointCoords();
DOFVector< std::list< WorldVector<double> > >::Iterator pointIt(interpPointCoords, USED_DOFS);
for (pointIt.reset(); !pointIt.end(); ++pointIt) {
::std::list< WorldVector<double> >::iterator it2;
std::list< WorldVector<double> >::iterator it2;
for (it2 = pointIt->begin(); it2 != pointIt->end(); ++it2) {
writeCoord(file, *it2);
}
......@@ -130,15 +130,15 @@ namespace AMDiS {
}
void VtkWriter::writeVertexValues(::std::ofstream &file, int componentNo)
void VtkWriter::writeVertexValues(std::ofstream &file, int componentNo)
{
// DOFVector<int> *interpPointInd;
// DOFVector<double> *values;
// DOFVector< ::std::list<WorldVector<double> > > *dofCoords;
// DOFVector< std::list<WorldVector<double> > > *dofCoords;
DOFVector<int> *interpPointInd = (*dc_)[componentNo]->getInterpPointInd();
DOFVector<double> *values = (*dc_)[componentNo]->getValues();
DOFVector< ::std::list<WorldVector<double> > > *dofCoords = (*dc_)[componentNo]->getDofCoords();
DOFVector< std::list<WorldVector<double> > > *dofCoords = (*dc_)[componentNo]->getDofCoords();
/*
#ifdef _OPENMP
......@@ -152,7 +152,7 @@ namespace AMDiS {
*/
DOFVector<int>::Iterator intPointIt(interpPointInd, USED_DOFS);
DOFVector<double>::Iterator valueIt(values, USED_DOFS);
DOFVector< ::std::list<WorldVector<double> > >::Iterator coordIt(dofCoords, USED_DOFS);
DOFVector< std::list<WorldVector<double> > >::Iterator coordIt(dofCoords, USED_DOFS);
// Write the values for all vertex DOFs.
for (intPointIt.reset(), valueIt.reset(), coordIt.reset();
......@@ -161,14 +161,14 @@ namespace AMDiS {
if (*intPointIt == -2) {
for (int i = 0; i < static_cast<int>(coordIt->size()); i++) {
file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << ::std::endl;
file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << "\n";
}
}
}
// For the second dim case, write also the values of the interpolation points.
if ((dim_ == 2) && (degree_ > 1)) {
DOFVector< ::std::list<WorldVector<double> > >::Iterator
DOFVector< std::list<WorldVector<double> > >::Iterator
interpCoordIt((*dc_)[componentNo]->getInterpPointCoords(), USED_DOFS);
for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset();
......@@ -177,7 +177,7 @@ namespace AMDiS {
if (*intPointIt >= 0) {
for (int i = 0; i < static_cast<int>(interpCoordIt->size()); i++) {
file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << ::std::endl;
file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << "\n";
}
}
}
......@@ -185,7 +185,7 @@ namespace AMDiS {
}
void VtkWriter::writeConnectivity(::std::ofstream &file)
void VtkWriter::writeConnectivity(std::ofstream &file)
{
// For the second dim case, and if higher order Lagrange elements are used,
// write the connectivity by extra functions.
......@@ -196,8 +196,8 @@ namespace AMDiS {
} else if ((dim_ == 2) && (degree_ == 4)) {
writeConnectivity_dim2_degree4(file);
} else {
::std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt;
std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
std::list<ElementInfo>::iterator elementIt;
int vertices = (*dc_)[0]->getMesh()->getGeo(VERTEX);
for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
......@@ -205,19 +205,19 @@ namespace AMDiS {
for (int i = 0; i < vertices; i++) {
file << " " << elementIt->vertexInfo[i]->outputIndex;
}
file << ::std::endl;
file << "\n";
}
}
}
void VtkWriter::writeConnectivity_dim2_degree2(::std::ofstream &file)
void VtkWriter::writeConnectivity_dim2_degree2(std::ofstream &file)
{
::std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt;
std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt;
std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices();
......@@ -227,31 +227,31 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl;
<< " " << (*pointIt)[2] + nVertices << "\n";
file << " " << elementIt->vertexInfo[2]->outputIndex
<< " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices << ::std::endl;
<< " " << (*pointIt)[1] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl;
<< " " << (*pointIt)[2] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl;
<< " " << (*pointIt)[2] + nVertices << "\n";
}
}
void VtkWriter::writeConnectivity_dim2_degree3(::std::ofstream &file)
void VtkWriter::writeConnectivity_dim2_degree3(std::ofstream &file)
{
::std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt;
std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt;
std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices();
......@@ -261,39 +261,39 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices << ::std::endl;
<< " " << (*pointIt)[4] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[5] + nVertices << ::std::endl;
<< " " << (*pointIt)[5] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[6] + nVertices
<< " " << (*pointIt)[5] + nVertices << ::std::endl;
<< " " << (*pointIt)[5] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << elementIt->vertexInfo[2]->outputIndex
<< " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl;
<< " " << (*pointIt)[2] + nVertices << "\n";
}
......@@ -301,13 +301,13 @@ namespace AMDiS {
}
void VtkWriter::writeConnectivity_dim2_degree4(::std::ofstream &file)
void VtkWriter::writeConnectivity_dim2_degree4(std::ofstream &file)
{
::std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt;
std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt;
std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices();
......@@ -317,96 +317,96 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl;
<< " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[6] + nVertices
<< " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[9] + nVertices << ::std::endl;
<< " " << (*pointIt)[9] + nVertices << "\n";
file << " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl;
<< " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[8] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl;
<< " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[8] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl;
<< " " << (*pointIt)[10] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[8] + nVertices << ::std::endl;
<< " " << (*pointIt)[8] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[9] + nVertices << ::std::endl;
<< " " << (*pointIt)[9] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[10] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[10] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl;
<< " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl;
<< " " << (*pointIt)[11] + nVertices << "\n";
file << " " << elementIt->vertexInfo[2]->outputIndex
<< " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[3] + nVertices << ::std::endl;
<< " " << (*pointIt)[3] + nVertices << "\n";
}
}
int VtkWriter::updateAnimationFile(::std::string valueFilename,
::std::vector< ::std::string > *paraViewAnimationFrames,
int VtkWriter::updateAnimationFile(std::string valueFilename,
std::vector< std::string > *paraViewAnimationFrames,
const char *animationFilename)
{
size_t found = valueFilename.find_last_of("/\\");
paraViewAnimationFrames->push_back(valueFilename.substr(found + 1));
::std::ofstream file;
std::ofstream file;
file.open(animationFilename);
file << "<?xml version=\"1.0\"?>" << ::std::endl;
file << "<VTKFile type=\"Collection\" version=\"0.1\" >" << ::std::endl;
file << "<Collection>" << ::std::endl;
file << "<?xml version=\"1.0\"?>\n";
file << "<VTKFile type=\"Collection\" version=\"0.1\" >" << "\n";
file << "<Collection>\n";
int counter = 0;
::std::vector< ::std::string >::iterator it;
std::vector< std::string >::iterator it;
for (it = paraViewAnimationFrames->begin();
it < paraViewAnimationFrames->end();
++it, counter++) {
file << "<DataSet timestep=\"" << counter
<< "\" part=\"0\" file=\"" << (*it) << "\"/>" << ::std::endl;
<< "\" part=\"0\" file=\"" << (*it) << "\"/>\n";
}
file << "</Collection>" << ::std::endl;
file << "</VTKFile>" << ::std::endl;
file << "</Collection>\n";
file << "</VTKFile>\n";
file.close();
......
......@@ -32,7 +32,7 @@ namespace AMDiS {
class VtkWriter
{
public:
VtkWriter(::std::vector<DataCollector*> *dc)
VtkWriter(std::vector<DataCollector*> *dc)
: dc_(dc)
{
degree_ = (*dc_)[0]->getFeSpace()->getBasisFcts()->getDegree();
......@@ -49,68 +49,68 @@ namespace AMDiS {
/** \brief
* Adds a new entry to a ParaView animation file.
*/
int updateAnimationFile(::std::string valueFilename,
::std::vector< ::std::string > *paraViewAnimationFrames,
int updateAnimationFile(std::string valueFilename,
std::vector< std::string > *paraViewAnimationFrames,
const char *animationFilename);
protected:
/** \brief
* Writes all coordinates of vertices and interpolation points to an
* output file.
*/
void writeVertexCoords(::std::ofstream &file);
void writeVertexCoords(std::ofstream &file);
/** \brief
* Writes all values of vertices and interpolation point to an output
* file.
*/
void writeVertexValues(::std::ofstream &file, int componentNo);
void writeVertexValues(std::ofstream &file, int componentNo);
/** \brief
* Writes the connectivity of all simplices to an output file.
*/
void writeConnectivity(::std::ofstream &file);
void writeConnectivity(std::ofstream &file);
/** \brief
* Writes the connectivity for the case dim = 2 and degree = 2 to
* an output file.
*/
void writeConnectivity_dim2_degree2(::std::ofstream &file);
void writeConnectivity_dim2_degree2(std::ofstream &file);
/** \brief
* Writes the connectivity for the case dim = 2 and degree = 3 to
* an output file.
*/
void writeConnectivity_dim2_degree3(::std::ofstream &file);
void writeConnectivity_dim2_degree3(std::ofstream &file);
/** \brief
* Writes the connectivity for the case dim = 2 and degree = 4 to
* an output file.
*/
void writeConnectivity_dim2_degree4(::std::ofstream &file);
void writeConnectivity_dim2_degree4(std::ofstream &file);
/** \brief
* Writes a world coordinate to a given file.
*/
inline void writeCoord(::std::ofstream &file, WorldVector<double> coord) {
inline void writeCoord(std::ofstream &file, WorldVector<double> coord) {
for (int i = 0; i < Global::getGeo(WORLD); i++) {
file << " " << ::std::scientific << coord[i];
file << " " << std::scientific << coord[i];
}
for (int i = Global::getGeo(WORLD); i < 3; i++) {
file << " 0.0";
}
file << ::std::endl;
file << std::endl;
}
private:
/**
* List of DataCollectors, for each component of the problem one.
*/
::std::vector<DataCollector*> *dc_;
std::vector<DataCollector*> *dc_;
/** \brief
......
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