/****************************************************************************** * * 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 VtkVectorWriter.hh */ #ifndef AMDIS_VTKVECTORWRITER_DETAIL_HH #define AMDIS_VTKVECTORWRITER_DETAIL_HH #include #include #include #include #include #include #include #ifdef HAVE_PARALLEL_DOMAIN_AMDIS #include #endif #include #include #include #include #include #ifdef HAVE_COMPRESSION // #include // #include #endif #include "DOFVector.h" #include "io/DataCollector.h" // #include "SurfaceRegion_ED.h" // #include "ElementRegion_ED.h" #include "io/detail/VtkWriter.h" namespace AMDiS { namespace io { namespace VtkVectorWriter { template int Aux::writeFile(std::string name) { FUNCNAME("Aux::writeFile()"); boost::iostreams::filtering_ostream file; #ifdef HAVE_COMPRESSION // switch (compress) { // case GZIP: // file.push(boost::iostreams::gzip_compressor()); // name.append(".gz"); // break; // case BZIP2: // file.push(boost::iostreams::bzip2_compressor()); // name.append(".bz2"); // break; // default: // break; // } #endif { std::ofstream swapfile(name.c_str(), std::ios::out | std::ios::trunc); TEST_EXIT(swapfile.is_open()) ("Cannot open file %s for writing!\n", name.c_str()); swapfile.close(); } file.push(boost::iostreams::file_descriptor_sink(name, std::ios::trunc)); writeFileToStream(file); return 0; } template void Aux::writeParallelFile(std::string name, int nRanks, std::string fnPrefix, std::string fnPostfix) { FUNCNAME("Aux::writeParallelFile()"); boost::iostreams::filtering_ostream file; { std::ofstream swapfile(name.c_str(), std::ios::out | std::ios::trunc); TEST_EXIT(swapfile.is_open()) ("Cannot open file %s for writing!\n", name.c_str()); swapfile.close(); } file.push(boost::iostreams::file_descriptor_sink(name, std::ios::trunc)); file << "\n"; file << "\n"; file << " \n"; file << " \n" << " \n" << " \n"; file << " \n" << " \n" << " \n" << " \n" << " \n"; file << " \n"; for (int i = 0; i < static_cast(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(i); file << " 1 ? " NumberOfComponents=\"" + boost::lexical_cast(numComponent) + "\"" : "") << "/>\n"; } file << " \n"; for (int i = 0; i < nRanks; i++) { std::stringstream oss; oss << fnPrefix << "-p" << i << "-" << fnPostfix; boost::filesystem::path filepath(oss.str()); file << " \n"; } file << " \n"; file << "\n"; } template 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"; for (int i = 0; i < static_cast(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(i); file << " 1 ? " NumberOfComponents=\"" + boost::lexical_cast(numComponent) + "\"" : "") << ">\n"; writeVertexValues(file, i); file << " \n"; } file << " \n"; file << " \n"; file << " \n"; file << "\n"; } // template template void Aux::writeVertexCoords(T &file) { using ::AMDiS::io::VtkWriter::detail::writeCoord; 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 for (std::list::iterator 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); counter = 0; for (pointIt.reset(); !pointIt.end(); ++pointIt) { for (std::list< WorldVector >::iterator it2 = pointIt->begin(); it2 != pointIt->end(); ++it2) { counter++; writeCoord(file, *it2); } } } } template template void Aux::writeVertexValues(T &file, int componentNo) { DOFVector *interpPointInd = (*dataCollector)[componentNo]->getInterpPointInd(); DOFVector *values = (*dataCollector)[componentNo]->getValues(); DOFVector< std::list > > *dofCoords = (*dataCollector)[componentNo]->getDofCoords(); DOFVector::Iterator intPointIt(interpPointInd, USED_DOFS); typename DOFVector::Iterator valueIt(values, USED_DOFS); DOFVector< std::list > >::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 << " " ; 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)[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 << " "; print(*valueIt,file); file << "\n"; } } } } } template template void Aux::writeConnectivity(T &file) { using ::AMDiS::io::VtkWriter::detail::writeConnectivity_dim2_degree2; using ::AMDiS::io::VtkWriter::detail::writeConnectivity_dim2_degree3; using ::AMDiS::io::VtkWriter::detail::writeConnectivity_dim2_degree4; // 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((*dataCollector)[0], file); } else if ((dim == 2) && (degree == 3)) { writeConnectivity_dim2_degree3((*dataCollector)[0], file); } else if ((dim == 2) && (degree == 4)) { 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"; } } } } // end namespace VtkVectorWriter } // end namespace io } // end namespace AMDiS #endif // AMDIS_VTKVECTORWRITER_HH