#include #include #include "DOFVector.h" namespace AMDiS { template void VtkWriter::writeFileToStream(T &file) { int nVertices = (*dataCollector)[0]->getNumberVertices(); int nElements = (*dataCollector)[0]->getNumberElements(); int vertices = (*dataCollector)[0]->getMesh()->getGeo(VERTEX); if ((dim == 2) && (degree == 2)) { nVertices += (*dataCollector)[0]->getNumberInterpPoints(); nElements *= 4; } else if ((dim == 2) && (degree == 3)) { nVertices += (*dataCollector)[0]->getNumberInterpPoints(); nElements *= 9; } else if ((dim == 2) && (degree == 4)) { nVertices += (*dataCollector)[0]->getNumberInterpPoints(); nElements *= 16; } file << "\n"; file << "\n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; writeVertexCoords(file); file << " \n"; file << " \n"; file << " \n"; file << " \n"; for (int i = 0; i < nElements; i++) { file << " " << (i + 1) * vertices << "\n"; } file << " \n"; file << " \n"; for (int i = 0; i < nElements; i++) { switch (vertices) { case 2: file << " 3\n"; break; case 3: file << " 5\n"; break; case 4: file << " 10\n"; break; default: break; } } file << " \n"; file << " \n"; writeConnectivity(file); file << " \n"; file << " \n"; file << " \n"; for (int i = 0; i < static_cast(dataCollector->size()); i++) { file << " \n"; writeVertexValues(file, i); file << " \n"; } file << " \n"; file << " \n"; file << " \n"; file << "\n"; } template void VtkWriter::writeVertexCoords(T &file) { DOFVector< std::list > *vertexInfos = (*dataCollector)[0]->getVertexInfos(); DOFVector< std::list >::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::iterator it2; for (it2 = it->begin(); it2 != it->end(); ++it2) { it2->outputIndex = counter++; writeCoord(file, it2->coords); } } // For the second dim case, write also the interpolation points. if ((dim == 2) && (degree > 1)) { DOFVector< std::list< WorldVector > > *interpPointCoords = (*dataCollector)[0]->getInterpPointCoords(); DOFVector< std::list< WorldVector > >::Iterator pointIt(interpPointCoords, USED_DOFS); for (pointIt.reset(); !pointIt.end(); ++pointIt) { std::list< WorldVector >::iterator it2; for (it2 = pointIt->begin(); it2 != pointIt->end(); ++it2) writeCoord(file, *it2); } } } template void VtkWriter::writeVertexValues(T &file, int componentNo) { // DOFVector *interpPointInd; // DOFVector *values; // DOFVector< std::list > > *dofCoords; DOFVector *interpPointInd = (*dataCollector)[componentNo]->getInterpPointInd(); DOFVector *values = (*dataCollector)[componentNo]->getValues(); DOFVector< std::list > > *dofCoords = (*dataCollector)[componentNo]->getDofCoords(); /* #ifdef _OPENMP #pragma omp critical #endif { interpPointInd = (*dataCollector)[componentNo]->getInterpPointInd(); values = (*dataCollector)[componentNo]->getValues(); dofCoords = (*dataCollector)[componentNo]->getDofCoords(); } */ DOFVector::Iterator intPointIt(interpPointInd, USED_DOFS); DOFVector::Iterator valueIt(values, USED_DOFS); DOFVector< std::list > >::Iterator coordIt(dofCoords, USED_DOFS); file << std::fixed; // Write the values for all vertex DOFs. for (intPointIt.reset(), valueIt.reset(), coordIt.reset(); !intPointIt.end(); ++intPointIt, ++valueIt, ++coordIt) { if (*intPointIt == -2) for (int i = 0; i < static_cast(coordIt->size()); i++) 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 > >::Iterator interpCoordIt((*dataCollector)[componentNo]->getInterpPointCoords(), USED_DOFS); for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset(); !intPointIt.end(); ++intPointIt, ++valueIt, ++interpCoordIt) { if (*intPointIt >= 0) { for (int i = 0; i < static_cast(interpCoordIt->size()); i++) file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << "\n"; } } } } template void VtkWriter::writeConnectivity(T &file) { // For the second dim case, and if higher order Lagrange elements are used, // write the connectivity by extra functions. if ((dim == 2) && (degree == 2)) { writeConnectivity_dim2_degree2(file); } else if ((dim == 2) && (degree == 3)) { writeConnectivity_dim2_degree3(file); } else if ((dim == 2) && (degree == 4)) { writeConnectivity_dim2_degree4(file); } else { std::list *elements = (*dataCollector)[0]->getElementInfos(); std::list::iterator elementIt; int vertices = (*dataCollector)[0]->getMesh()->getGeo(VERTEX); for (elementIt = elements->begin(); elementIt != elements->end(); ++elementIt) { // for all vertices for (int i = 0; i < vertices; i++) { file << " " << elementIt->vertexInfo[i]->outputIndex; } file << "\n"; } } } template void VtkWriter::writeConnectivity_dim2_degree2(T &file) { std::list *elements = (*dataCollector)[0]->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = (*dataCollector)[0]->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = (*dataCollector)[0]->getNumberVertices(); for (pointIt = interpPoints->begin(), elementIt = elements->begin(); pointIt != interpPoints->end(); ++pointIt, ++elementIt) { file << " " << elementIt->vertexInfo[0]->outputIndex << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[2] + nVertices << "\n"; file << " " << elementIt->vertexInfo[2]->outputIndex << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[1] + nVertices << "\n"; file << " " << elementIt->vertexInfo[1]->outputIndex << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[2] + nVertices << "\n"; file << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[2] + nVertices << "\n"; } } template void VtkWriter::writeConnectivity_dim2_degree3(T &file) { std::list *elements = (*dataCollector)[0]->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = (*dataCollector)[0]->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = (*dataCollector)[0]->getNumberVertices(); for (pointIt = interpPoints->begin(), elementIt = elements->begin(); pointIt != interpPoints->end(); ++pointIt, ++elementIt) { file << " " << elementIt->vertexInfo[0]->outputIndex << " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[4] + nVertices << "\n"; file << " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << elementIt->vertexInfo[1]->outputIndex << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[5] + nVertices << "\n"; file << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[6] + nVertices << " " << (*pointIt)[5] + nVertices << "\n"; file << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << elementIt->vertexInfo[2]->outputIndex << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[2] + nVertices << "\n"; } } template void VtkWriter::writeConnectivity_dim2_degree4(T &file) { std::list *elements = (*dataCollector)[0]->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = (*dataCollector)[0]->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = (*dataCollector)[0]->getNumberVertices(); for (pointIt = interpPoints->begin(), elementIt = elements->begin(); pointIt != interpPoints->end(); ++pointIt, ++elementIt) { file << " " << elementIt->vertexInfo[0]->outputIndex << " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[6] + nVertices << "\n"; file << " " << (*pointIt)[6] + nVertices << " " << (*pointIt)[7] + nVertices << " " << (*pointIt)[9] + nVertices << "\n"; file << " " << (*pointIt)[7] + nVertices << " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[10] + nVertices << "\n"; file << " " << (*pointIt)[7] + nVertices << " " << (*pointIt)[8] + nVertices << " " << (*pointIt)[10] + nVertices << "\n"; file << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[8] + nVertices << " " << (*pointIt)[10] + nVertices << "\n"; file << " " << elementIt->vertexInfo[1]->outputIndex << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[8] + nVertices << "\n"; file << " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[5] + nVertices << " " << (*pointIt)[9] + nVertices << "\n"; file << " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << (*pointIt)[9] + nVertices << " " << (*pointIt)[10] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[10] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << (*pointIt)[0] + nVertices << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[10] + nVertices << "\n"; file << " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[4] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[3] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << (*pointIt)[1] + nVertices << " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[11] + nVertices << "\n"; file << " " << elementIt->vertexInfo[2]->outputIndex << " " << (*pointIt)[2] + nVertices << " " << (*pointIt)[3] + nVertices << "\n"; } } }