/*------------------------------- phasicFlow --------------------------------- O C enter of O O E ngineering and O O M ultiscale modeling of OOOOOOO F luid flow ------------------------------------------------------------------------------ Copyright (C): www.cemf.ir email: hamid.r.norouzi AT gmail.com ------------------------------------------------------------------------------ Licence: This file is part of phasicFlow code. It is a free software for simulating granular and multiphase flows. You can redistribute it and/or modify it under the terms of GNU General Public License v3 or any other later versions. phasicFlow is distributed to help others in their research in the field of granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ #ifndef __pointFieldToVTK_hpp__ #define __pointFieldToVTK_hpp__ #include #include "vtkFile.hpp" #include "pointFields.hpp" #include "IOobject.hpp" namespace pFlow::PFtoVTK { template bool addIntPointField( iOstream& os, word fieldName, int32 numActivePoints, IntType* field, IncludeMaskType includeMask ); template bool addRealPointField( iOstream& os, word fieldName, int32 numActivePoints, real* field, IncludeMaskType includeMask ); template bool addRealx3PointField( iOstream& os, word fieldName, int32 numActivePoints, realx3* field, IncludeMaskType includeMask ); bool regexCheck(word TYPENAME, word fieldType) { std::regex match("pointField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>"); std::smatch search1, search2; if(!std::regex_match(fieldType, search1, match))return false; if(!std::regex_match(TYPENAME, search2, match))return false; if(search1.size()!=3)return false; if(search1.size()!=search2.size())return false; return search1[1] == search2[1]; } template bool checkFieldType(word objectType) { //if( pointField::TYPENAME() == objectType )return true; //if( pointField::TYPENAME() == objectType ) return true; //if( pointField::TYPENAME() == objectType )return true; return regexCheck(pointField::TYPENAME(), objectType); } template bool convertIntPointField ( iOstream& os, const IOfileHeader& header, const pointStructure& pStruct ) { using PointFieldType = pointField; word objectType = header.objectType(); if(!checkFieldType(objectType)) { return false; } auto objField = IOobject::make ( header, pStruct, static_cast(0) ); auto& Field = objField().template getObject(); T* data = Field.deviceVectorAll().data(); REPORT(2)<<"writing "<< greenColor <(objectType))return false; auto objField = IOobject::make ( header, pStruct, static_cast(0) ); auto& Field = objField().getObject(); real* data = Field.hostVectorAll().data(); REPORT(2)<<"writing "<< greenColor <(objectType))return false; auto objField = IOobject::make ( header, pStruct, static_cast(0) ); auto& Field = objField().getObject(); realx3* data = Field.hostVectorAll().data(); REPORT(2)<<"writing "<< greenColor < bool addUndstrcuturedGridField( iOstream& os, int32 numActivePoints, realx3* position, IncludeMaskType includeMask) { auto [iFirst, iLast] = includeMask.activeRange(); os<< "DATASET UNSTRUCTURED_GRID\n"; os<< "POINTS "<< numActivePoints << " float\n"; if(numActivePoints==0) return true; for(int32 i=iFirst; i bool addIntPointField( iOstream& os, word fieldName, int32 numActivePoints, IntType* field, IncludeMaskType includeMask ) { if(numActivePoints==0) return true; auto [iFirst, iLast] = includeMask.activeRange(); os << "FIELD FieldData 1\n"<< fieldName << " 1 " << numActivePoints << " int\n"; for(int32 i=iFirst; i bool addRealPointField( iOstream& os, word fieldName, int32 numActivePoints, real* field, IncludeMaskType includeMask ) { if(numActivePoints==0) return true; auto [iFirst, iLast] = includeMask.activeRange(); os << "FIELD FieldData 1\n"<< fieldName << " 1 " << numActivePoints << " float\n"; for(int32 i=iFirst; i bool addRealx3PointField( iOstream& os, word fieldName, int32 numActivePoints, realx3* field, IncludeMaskType includeMask ) { if(numActivePoints==0) return true; auto [iFirst, iLast] = includeMask.activeRange(); os << "FIELD FieldData 1\n"<< fieldName << " 3 " << numActivePoints << " float\n"; for(int32 i=iFirst; i(pStructHeader); auto& pStruct = pStructObjPtr().getObject(); // get a list of files in this timeFolder; auto posVec = std::as_const(pStruct).pointPosition().hostVectorAll(); auto* pos = posVec.data(); REPORT(1)<<"Writing pointStructure to vtk file with "<< yellowText(pStruct.numActive()) <<" active particles"<(vtk(), fieldHeader, pStruct); convertIntPointField(vtk(), fieldHeader, pStruct); convertIntPointField(vtk(), fieldHeader, pStruct); convertRealTypePointField(vtk(), fieldHeader, pStruct); convertRealx3TypePointField(vtk(), fieldHeader, pStruct); } } return true; } bool convertTimeFolderPointFieldsSelected( fileSystem timeFolder, real time, fileSystem destPath, word bName, wordVector fieldsName, bool mustExist) { // check if pointStructure exist in this folder IOfileHeader pStructHeader( objectFile( pointStructureFile__, timeFolder, objectFile::READ_ALWAYS, objectFile::WRITE_ALWAYS) ); if( !pStructHeader.headerOk(true) ) { output<(pStructHeader); auto& pStruct = pStructObjPtr().getObject(); // get a list of files in this timeFolder; auto posVec = std::as_const(pStruct).pointPosition().hostVectorAll(); auto* pos = posVec.data(); REPORT(1)<<"Writing pointStructure to vtk file with "<< yellowText(pStruct.numActive()) <<" active particles"<(vtk(), fieldHeader, pStruct); convertIntPointField(vtk(), fieldHeader, pStruct); convertIntPointField(vtk(), fieldHeader, pStruct); convertRealTypePointField(vtk(), fieldHeader, pStruct); convertRealx3TypePointField(vtk(), fieldHeader, pStruct); } else { if(mustExist) { fatalErrorInFunction<<"Field " << fieldAddress << " does not exist."<