/****************************************************************************** * * AMDiS - Adaptive multidimensional simulations * * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved. * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis * * Authors: * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al. * * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * * * This file is part of AMDiS * * See also license.opensource.txt in the distribution. * ******************************************************************************/ /** \file VtkVector.hh */ #ifndef AMDIS_VTKWRITER_DETAIL_HH #define AMDIS_VTKWRITER_DETAIL_HH #include "BasisFunction.h" #include "io/DataCollector.h" namespace AMDiS { namespace io { namespace VtkWriter { template void Aux::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"; int nValues = static_cast(dataCollector->size()); nValues = writeAsVector ? std::min(nValues,1) : nValues; for (int i = 0; i < nValues; i++) { file << " size() > 1) file << " NumberOfComponents=\"" << std::max(3,static_cast(dataCollector->size())) << "\""; file << ">\n"; writeVertexValues(file, i); file << " \n"; } file << " \n"; file << " \n"; file << " \n"; file << "\n"; } template void Aux::writeFileToStreamAppended(T &file) { using namespace std; bstream.str(""); int valueSize = writeAsVector ? 1 : static_cast(dataCollector->size()); valueSize = std::min(valueSize, static_cast(dataCollector->size())); int nDataArray = 4 + valueSize; vector dataBase64Vec(nDataArray, ""); vector dataOffsetVec(nDataArray, 0); string finalData = ""; 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; } //DataArray for (int i = 0; i < valueSize; i++) { writeVertexValues(bstream, i); dataBase64Vec[i] = getStreamData(); } //DataArray writeVertexCoords(bstream); dataBase64Vec[valueSize] = getStreamData(); //DataArray writeConnectivity(bstream); dataBase64Vec[valueSize + 1] = getStreamData(); //DataArray uint32_t tmp32 = 0; for (int i = 1; i <= nElements; i++) { tmp32 = i * vertices; bstream << tmp32; } dataBase64Vec[valueSize + 2] = getStreamData(); //DataArray uint8_t tmp8 = 0; for (int i = 0; i < nElements; i++) { switch (vertices) { case 2: tmp8 = 3; break; case 3: tmp8 = 5; break; case 4: tmp8 = 10; break; default: tmp8 = 0; break; } if(tmp8) bstream << tmp8; } dataBase64Vec[valueSize + 3] = getStreamData(); finalData = dataBase64Vec[0]; for(int i = 1; i < nDataArray; i++) { dataOffsetVec[i] = dataBase64Vec[i - 1].length() + dataOffsetVec[i - 1]; finalData += dataBase64Vec[i]; } file << "\n"; file << "\n"; file << " \n"; file << " \n"; file << " \n"; for (int i = 0; i < valueSize; i++) { if(bstream.isHighPrecision()) file << " size() > 1) file << " NumberOfComponents=\"" << std::max(3,static_cast(dataCollector->size())) << "\""; file << "/>\n"; } file << " \n"; file << " \n"; file << " \n"; file << " \n"; if(bstream.isHighPrecision()) file << " \n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; file << " \n"; // file << " \n"; file << " \n"; file << " _" << finalData << "\n"; file << " \n"; file << "\n"; } template void Aux::writeVertexCoords(T &file) { DOFVector > *vertexInfos = (*dataCollector)[0]->getVertexInfos(); DOFVector >::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 for (std::list::iterator it2 = it->begin(); it2 != it->end(); ++it2) { it2->outputIndex = counter++; detail::writeCoord(file, it2->coords); } } // For the second dim case, write also the interpolation points. if ((dim == 2) && (degree > 1)) { DOFVector > > *interpPointCoords = (*dataCollector)[0]->getInterpPointCoords(); DOFVector > >::Iterator pointIt(interpPointCoords, USED_DOFS); counter = 0; for (pointIt.reset(); !pointIt.end(); ++pointIt) { for (std::list< WorldVector >::iterator it2 = pointIt->begin(); it2 != pointIt->end(); ++it2) { counter++; detail::writeCoord(file, *it2); } } } } template void Aux::writeVertexValues(T &file, int componentNo) { if (writeAsVector) { writeVertexValues(file); return; } DOFVector *interpPointInd = (*dataCollector)[componentNo]->getInterpPointInd(); DOFVector *values = (*dataCollector)[componentNo]->getValues(); DOFVector > > *dofCoords = (*dataCollector)[componentNo]->getDofCoords(); DOFVector::Iterator intPointIt(interpPointInd, USED_DOFS); DOFVector::Iterator valueIt(values, USED_DOFS); DOFVector > >::Iterator coordIt(dofCoords, USED_DOFS); file << std::scientific; file.precision(15); // 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 > >::Iterator interpCoordIt((*dataCollector)[componentNo]->getInterpPointCoords(), USED_DOFS); for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset(); !intPointIt.end(); ++intPointIt, ++valueIt, ++interpCoordIt) { if (*intPointIt >= 0) { for (unsigned int i = 0; i < interpCoordIt->size(); i++) file << " " << (fabs(*valueIt) < 1e-40 ? 0.0 : *valueIt) << "\n"; } } } } template void Aux::writeVertexValues(T &file) { DOFVector *interpPointInd = (*dataCollector)[0]->getInterpPointInd(); std::vector*> values(dataCollector->size()); DOFVector > > *dofCoords = (*dataCollector)[0]->getDofCoords(); for (size_t i = 0; i < dataCollector->size(); i++) values[i] = (*dataCollector)[i]->getValues(); DOFIterator intPointIt(interpPointInd, USED_DOFS); DOFVectorIterator valueIt(values, USED_DOFS); DOFIterator > > coordIt(dofCoords, USED_DOFS); file << std::scientific; file.precision(15); // 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 << " " ; print(*valueIt, file); file << "\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)[0]->getInterpPointCoords(), USED_DOFS); for (intPointIt.reset(), valueIt.reset(), interpCoordIt.reset(); !intPointIt.end(); ++intPointIt, ++valueIt, ++interpCoordIt) { if (*intPointIt >= 0) { for (unsigned int i = 0; i < interpCoordIt->size(); i++) { file << " "; print(*valueIt, file); file << "\n"; } } } } } template void Aux::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)) { detail::writeConnectivity_dim2_degree2((*dataCollector)[0], file); } else if ((dim == 2) && (degree == 3)) { detail::writeConnectivity_dim2_degree3((*dataCollector)[0], file); } else if ((dim == 2) && (degree == 4)) { detail::writeConnectivity_dim2_degree4((*dataCollector)[0], 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"; } } } // __________________________________________________________________________ // namespace detail { template void writeConnectivity_dim2_degree2(DataCollector* dataCollector, T &file) { std::list *elements = dataCollector->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = dataCollector->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = dataCollector->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 writeConnectivity_dim2_degree3(DataCollector* dataCollector, T &file) { std::list *elements = dataCollector->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = dataCollector->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = dataCollector->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 writeConnectivity_dim2_degree4(DataCollector* dataCollector, T &file) { std::list *elements = dataCollector->getElementInfos(); std::list::iterator elementIt; std::vector< std::vector > *interpPoints = dataCollector->getInterpPoints(); std::vector< std::vector >::iterator pointIt; int nVertices = dataCollector->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"; } } } // end namespace detail } // end namespace VtkWriter } } // end namespace io, AMDiS #endif // AMDIS_VTKWRITER_DETAIL_HH