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

* Faster VTK output

parent e6cd8e18
...@@ -28,69 +28,69 @@ namespace AMDiS { ...@@ -28,69 +28,69 @@ namespace AMDiS {
nElements *= 16; nElements *= 16;
} }
::std::ofstream file; std::ofstream file;
file.open(name); file.open(name);
file << "<?xml version=\"1.0\"?>" << ::std::endl; file << "<?xml version=\"1.0\"?>\n";
file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">" << ::std::endl; file << "<VTKFile type=\"UnstructuredGrid\" version=\"0.1\" byte_order=\"LittleEndian\">\n";
file << " <UnstructuredGrid>" << ::std::endl; file << " <UnstructuredGrid>\n";
file << " <Piece NumberOfPoints=\"" << nVertices file << " <Piece NumberOfPoints=\"" << nVertices
<< "\" NumberOfCells=\"" << nElements << "\">" << ::std::endl; << "\" NumberOfCells=\"" << nElements << "\">\n";
file << " <Points>" << ::std::endl; file << " <Points>\n";
file << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">" << ::std::endl; file << " <DataArray type=\"Float32\" NumberOfComponents=\"3\" format=\"ascii\">\n";
writeVertexCoords(file); writeVertexCoords(file);
file << " </DataArray>" << ::std::endl; file << " </DataArray>\n";
file << " </Points>" << ::std::endl; file << " </Points>\n";
file << " <Cells>" << ::std::endl; file << " <Cells>\n";
file << " <DataArray type=\"Int32\" Name=\"offsets\">" << ::std::endl; file << " <DataArray type=\"Int32\" Name=\"offsets\">\n";
for (int i = 0; i < nElements; i++) { for (int i = 0; i < nElements; i++) {
file << " " << (i + 1) * vertices << ::std::endl; file << " " << (i + 1) * vertices << "\n";
} }
file << " </DataArray>" << ::std::endl; file << " </DataArray>\n";
file << " <DataArray type=\"UInt8\" Name=\"types\">" << ::std::endl; file << " <DataArray type=\"UInt8\" Name=\"types\">\n";
for (int i = 0; i < nElements; i++) { for (int i = 0; i < nElements; i++) {
switch (vertices) { switch (vertices) {
case 2: case 2:
file << " 3" << ::std::endl; file << " 3\n";
break; break;
case 3: case 3:
file << " 5" << ::std::endl; file << " 5\n";
break; break;
case 4: case 4:
file << " 10" << ::std::endl; file << " 10\n";
break; break;
default: default:
break; break;
} }
} }
file << " </DataArray>" << ::std::endl; file << " </DataArray>\n";
file << " <DataArray type=\"Int32\" Name=\"connectivity\">" << ::std::endl; file << " <DataArray type=\"Int32\" Name=\"connectivity\">\n";
writeConnectivity(file); writeConnectivity(file);
file << " </DataArray>" << ::std::endl; file << " </DataArray>\n";
file << " </Cells>" << ::std::endl; file << " </Cells>\n";
file << " <PointData>" << ::std::endl; file << " <PointData>\n";
for (int i = 0; i < static_cast<int>(dc_->size()); i++) { for (int i = 0; i < static_cast<int>(dc_->size()); i++) {
file << " <DataArray type=\"Float32\" Name=\"value" << i file << " <DataArray type=\"Float32\" Name=\"value" << i
<< "\" format=\"ascii\">" << ::std::endl; << "\" format=\"ascii\">\n";
writeVertexValues(file, i); writeVertexValues(file, i);
file << " </DataArray>" << ::std::endl; file << " </DataArray>\n";
} }
file << " </PointData>" << ::std::endl; file << " </PointData>\n";
file << " </Piece>" << ::std::endl; file << " </Piece>\n";
file << " </UnstructuredGrid>" << ::std::endl; file << " </UnstructuredGrid>\n";
file << "</VTKFile>" << ::std::endl; file << "</VTKFile>\n";
file.close(); file.close();
...@@ -99,16 +99,16 @@ namespace AMDiS { ...@@ -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> > *vertexInfos = (*dc_)[0]->getVertexInfos();
DOFVector< ::std::list<VertexInfo> >::Iterator it(vertexInfos, USED_DOFS); DOFVector< std::list<VertexInfo> >::Iterator it(vertexInfos, USED_DOFS);
int counter = 0; int counter = 0;
// For all DOFs of vertices, write the coordinates. // For all DOFs of vertices, write the coordinates.
for (it.reset(); !it.end(); ++it) { for (it.reset(); !it.end(); ++it) {
// for all vertex infos of this DOF // 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) { for (it2 = it->begin(); it2 != it->end(); ++it2) {
it2->outputIndex = counter++; it2->outputIndex = counter++;
writeCoord(file, it2->coords); writeCoord(file, it2->coords);
...@@ -117,11 +117,11 @@ namespace AMDiS { ...@@ -117,11 +117,11 @@ namespace AMDiS {
// For the second dim case, write also the interpolation points. // For the second dim case, write also the interpolation points.
if ((dim_ == 2) && (degree_ > 1)) { if ((dim_ == 2) && (degree_ > 1)) {
DOFVector< ::std::list< WorldVector<double> > > *interpPointCoords = (*dc_)[0]->getInterpPointCoords(); DOFVector< std::list< WorldVector<double> > > *interpPointCoords = (*dc_)[0]->getInterpPointCoords();
DOFVector< ::std::list< WorldVector<double> > >::Iterator pointIt(interpPointCoords, USED_DOFS); DOFVector< std::list< WorldVector<double> > >::Iterator pointIt(interpPointCoords, USED_DOFS);
for (pointIt.reset(); !pointIt.end(); ++pointIt) { 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) { for (it2 = pointIt->begin(); it2 != pointIt->end(); ++it2) {
writeCoord(file, *it2); writeCoord(file, *it2);
} }
...@@ -130,15 +130,15 @@ namespace AMDiS { ...@@ -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<int> *interpPointInd;
// DOFVector<double> *values; // DOFVector<double> *values;
// DOFVector< ::std::list<WorldVector<double> > > *dofCoords; // DOFVector< std::list<WorldVector<double> > > *dofCoords;
DOFVector<int> *interpPointInd = (*dc_)[componentNo]->getInterpPointInd(); DOFVector<int> *interpPointInd = (*dc_)[componentNo]->getInterpPointInd();
DOFVector<double> *values = (*dc_)[componentNo]->getValues(); 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 #ifdef _OPENMP
...@@ -152,7 +152,7 @@ namespace AMDiS { ...@@ -152,7 +152,7 @@ namespace AMDiS {
*/ */
DOFVector<int>::Iterator intPointIt(interpPointInd, USED_DOFS); DOFVector<int>::Iterator intPointIt(interpPointInd, USED_DOFS);
DOFVector<double>::Iterator valueIt(values, 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. // Write the values for all vertex DOFs.
for (intPointIt.reset(), valueIt.reset(), coordIt.reset(); for (intPointIt.reset(), valueIt.reset(), coordIt.reset();
...@@ -161,14 +161,14 @@ namespace AMDiS { ...@@ -161,14 +161,14 @@ namespace AMDiS {
if (*intPointIt == -2) { if (*intPointIt == -2) {
for (int i = 0; i < static_cast<int>(coordIt->size()); i++) { 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. // For the second dim case, write also the values of the interpolation points.
if ((dim_ == 2) && (degree_ > 1)) { if ((dim_ == 2) && (degree_ > 1)) {
DOFVector< ::std::list<WorldVector<double> > >::Iterator DOFVector< std::list<WorldVector<double> > >::Iterator
interpCoordIt((*dc_)[componentNo]->getInterpPointCoords(), USED_DOFS); interpCoordIt((*dc_)[componentNo]->getInterpPointCoords(), USED_DOFS);
for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset(); for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset();
...@@ -177,7 +177,7 @@ namespace AMDiS { ...@@ -177,7 +177,7 @@ namespace AMDiS {
if (*intPointIt >= 0) { if (*intPointIt >= 0) {
for (int i = 0; i < static_cast<int>(interpCoordIt->size()); i++) { 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 { ...@@ -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, // For the second dim case, and if higher order Lagrange elements are used,
// write the connectivity by extra functions. // write the connectivity by extra functions.
...@@ -196,8 +196,8 @@ namespace AMDiS { ...@@ -196,8 +196,8 @@ namespace AMDiS {
} else if ((dim_ == 2) && (degree_ == 4)) { } else if ((dim_ == 2) && (degree_ == 4)) {
writeConnectivity_dim2_degree4(file); writeConnectivity_dim2_degree4(file);
} else { } else {
::std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos(); std::list<ElementInfo> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt; std::list<ElementInfo>::iterator elementIt;
int vertices = (*dc_)[0]->getMesh()->getGeo(VERTEX); int vertices = (*dc_)[0]->getMesh()->getGeo(VERTEX);
for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) { for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) {
...@@ -205,19 +205,19 @@ namespace AMDiS { ...@@ -205,19 +205,19 @@ namespace AMDiS {
for (int i = 0; i < vertices; i++) { for (int i = 0; i < vertices; i++) {
file << " " << elementIt->vertexInfo[i]->outputIndex; 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> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt; std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints(); std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt; std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices(); int nVertices = (*dc_)[0]->getNumberVertices();
...@@ -227,31 +227,31 @@ namespace AMDiS { ...@@ -227,31 +227,31 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl; << " " << (*pointIt)[2] + nVertices << "\n";
file << " " << elementIt->vertexInfo[2]->outputIndex file << " " << elementIt->vertexInfo[2]->outputIndex
<< " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices << ::std::endl; << " " << (*pointIt)[1] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl; << " " << (*pointIt)[2] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + 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> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt; std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints(); std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt; std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices(); int nVertices = (*dc_)[0]->getNumberVertices();
...@@ -261,39 +261,39 @@ namespace AMDiS { ...@@ -261,39 +261,39 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices << ::std::endl; << " " << (*pointIt)[4] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[3] + nVertices file << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[2] + nVertices file << " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[5] + nVertices << ::std::endl; << " " << (*pointIt)[5] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[6] + nVertices << " " << (*pointIt)[6] + nVertices
<< " " << (*pointIt)[5] + nVertices << ::std::endl; << " " << (*pointIt)[5] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices file << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << elementIt->vertexInfo[2]->outputIndex file << " " << elementIt->vertexInfo[2]->outputIndex
<< " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[2] + nVertices << ::std::endl; << " " << (*pointIt)[2] + nVertices << "\n";
} }
...@@ -301,13 +301,13 @@ namespace AMDiS { ...@@ -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> *elements = (*dc_)[0]->getElementInfos();
::std::list<ElementInfo>::iterator elementIt; std::list<ElementInfo>::iterator elementIt;
::std::vector< ::std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints(); std::vector< std::vector<int> > *interpPoints = (*dc_)[0]->getInterpPoints();
::std::vector< ::std::vector<int> >::iterator pointIt; std::vector< std::vector<int> >::iterator pointIt;
int nVertices = (*dc_)[0]->getNumberVertices(); int nVertices = (*dc_)[0]->getNumberVertices();
...@@ -317,96 +317,96 @@ namespace AMDiS { ...@@ -317,96 +317,96 @@ namespace AMDiS {
file << " " << elementIt->vertexInfo[0]->outputIndex file << " " << elementIt->vertexInfo[0]->outputIndex
<< " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[5] + nVertices file << " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[6] + nVertices << ::std::endl; << " " << (*pointIt)[6] + nVertices << "\n";
file << " " << (*pointIt)[6] + nVertices file << " " << (*pointIt)[6] + nVertices
<< " " << (*pointIt)[7] + nVertices << " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[9] + nVertices << ::std::endl; << " " << (*pointIt)[9] + nVertices << "\n";
file << " " << (*pointIt)[7] + nVertices file << " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl; << " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[7] + nVertices file << " " << (*pointIt)[7] + nVertices
<< " " << (*pointIt)[8] + nVertices << " " << (*pointIt)[8] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl; << " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[8] + nVertices << " " << (*pointIt)[8] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl; << " " << (*pointIt)[10] + nVertices << "\n";
file << " " << elementIt->vertexInfo[1]->outputIndex file << " " << elementIt->vertexInfo[1]->outputIndex
<< " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[8] + nVertices << ::std::endl; << " " << (*pointIt)[8] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[5] + nVertices
<< " " << (*pointIt)[9] + nVertices << ::std::endl; << " " << (*pointIt)[9] + nVertices << "\n";
file << " " << (*pointIt)[4] + nVertices file << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl; << " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[9] + nVertices file << " " << (*pointIt)[9] + nVertices
<< " " << (*pointIt)[10] + nVertices << " " << (*pointIt)[10] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl; << " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices file << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[10] + nVertices << " " << (*pointIt)[10] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl; << " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[0] + nVertices file << " " << (*pointIt)[0] + nVertices
<< " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[1] + nVertices
<< " " << (*pointIt)[10] + nVertices << ::std::endl; << " " << (*pointIt)[10] + nVertices << "\n";
file << " " << (*pointIt)[3] + nVertices file << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[4] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl; << " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[2] + nVertices file << " " << (*pointIt)[2] + nVertices
<< " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[3] + nVertices
<< " " << (*pointIt)[11] + nVertices << ::std::endl; << " " << (*pointIt)[11] + nVertices << "\n";
file << " " << (*pointIt)[1] + nVertices