commit
89c7be0a20
|
@ -33,7 +33,6 @@ bool pFlow::fileSystem::checkFileName(const word& name)
|
||||||
"Invalid file name supplied " << name <<
|
"Invalid file name supplied " << name <<
|
||||||
"the following characters are not allowd: " <<
|
"the following characters are not allowd: " <<
|
||||||
notPermittedCharsFile << endl;
|
notPermittedCharsFile << endl;
|
||||||
fatalExit;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +56,9 @@ pFlow::fileSystem::fileSystem( const word& dir, const word& file)
|
||||||
{
|
{
|
||||||
isDir_ = file.empty();
|
isDir_ = file.empty();
|
||||||
|
|
||||||
if( !isDir_)
|
if( !isDir_ && !checkFileName(file))
|
||||||
{
|
{
|
||||||
checkFileName(file);
|
fatalExit;
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -240,7 +239,10 @@ pFlow::fileSystem pFlow::fileSystem::operator()
|
||||||
|
|
||||||
void pFlow::fileSystem::operator += (const word& fileName)
|
void pFlow::fileSystem::operator += (const word& fileName)
|
||||||
{
|
{
|
||||||
checkFileName(fileName);
|
if(!checkFileName(fileName))
|
||||||
|
{
|
||||||
|
fatalExit;
|
||||||
|
}
|
||||||
|
|
||||||
if( isDir())
|
if( isDir())
|
||||||
{
|
{
|
||||||
|
|
|
@ -69,14 +69,31 @@ void pFlow::fileStream::openOutFile
|
||||||
}
|
}
|
||||||
|
|
||||||
if(binary_)
|
if(binary_)
|
||||||
|
{
|
||||||
|
if(append_)
|
||||||
|
{
|
||||||
|
outStream_ = makeUnique< std::ofstream>(
|
||||||
|
path.wordPath(), std::ios_base::out| std::ios::binary|std::ios::app);
|
||||||
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
outStream_ = makeUnique< std::ofstream>(
|
outStream_ = makeUnique< std::ofstream>(
|
||||||
path.wordPath(), std::ios_base::out| std::ios::binary);
|
path.wordPath(), std::ios_base::out| std::ios::binary);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
|
if(append_)
|
||||||
|
{
|
||||||
|
outStream_ = makeUnique< std::ofstream>(
|
||||||
|
path.wordPath(), std::ios_base::out|std::ios::app);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
outStream_ = makeUnique< std::ofstream>(
|
outStream_ = makeUnique< std::ofstream>(
|
||||||
path.wordPath(), std::ios_base::out);
|
path.wordPath(), std::ios_base::out);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if(!outStream_->is_open())
|
if(!outStream_->is_open())
|
||||||
{
|
{
|
||||||
|
@ -103,12 +120,14 @@ pFlow::fileStream::fileStream
|
||||||
(
|
(
|
||||||
const fileSystem& path,
|
const fileSystem& path,
|
||||||
bool outStream,
|
bool outStream,
|
||||||
bool binary
|
bool binary,
|
||||||
|
bool append
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
inStream_(nullptr),
|
inStream_(nullptr),
|
||||||
outStream_(nullptr),
|
outStream_(nullptr),
|
||||||
binary_(binary)
|
binary_(binary),
|
||||||
|
append_(append)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(outStream)
|
if(outStream)
|
||||||
|
|
|
@ -52,6 +52,8 @@ protected:
|
||||||
|
|
||||||
bool binary_ = false;
|
bool binary_ = false;
|
||||||
|
|
||||||
|
bool append_ = false;
|
||||||
|
|
||||||
/// open input file
|
/// open input file
|
||||||
void openInFile(const fileSystem& path);
|
void openInFile(const fileSystem& path);
|
||||||
|
|
||||||
|
@ -66,7 +68,7 @@ public:
|
||||||
//// - Constructors
|
//// - Constructors
|
||||||
|
|
||||||
/// From file path and input type and format.
|
/// From file path and input type and format.
|
||||||
fileStream( const fileSystem& path, bool outStream = false, bool binary = false);
|
fileStream( const fileSystem& path, bool outStream = false, bool binary = false, bool append = false);
|
||||||
|
|
||||||
/// No copy
|
/// No copy
|
||||||
fileStream(const fileStream&)= delete;
|
fileStream(const fileStream&)= delete;
|
||||||
|
|
|
@ -22,9 +22,9 @@ Licence:
|
||||||
#include "oFstream.hpp"
|
#include "oFstream.hpp"
|
||||||
|
|
||||||
|
|
||||||
pFlow::oFstream::oFstream (const fileSystem& path, bool binary)
|
pFlow::oFstream::oFstream (const fileSystem& path, bool binary, bool append)
|
||||||
:
|
:
|
||||||
fileStream(path, true, binary),
|
fileStream(path, true, binary, append),
|
||||||
Ostream
|
Ostream
|
||||||
(
|
(
|
||||||
fileStream::outStream(),
|
fileStream::outStream(),
|
||||||
|
|
|
@ -45,7 +45,7 @@ public:
|
||||||
//// - Constructors
|
//// - Constructors
|
||||||
|
|
||||||
/// From file path and format
|
/// From file path and format
|
||||||
oFstream (const fileSystem& path, bool binary = false);
|
oFstream (const fileSystem& path, bool binary = false, bool append = false);
|
||||||
|
|
||||||
/// No copy constructor
|
/// No copy constructor
|
||||||
oFstream( const oFstream& src) = delete;
|
oFstream( const oFstream& src) = delete;
|
||||||
|
|
|
@ -21,11 +21,14 @@ Licence:
|
||||||
|
|
||||||
#include "vtkFile.hpp"
|
#include "vtkFile.hpp"
|
||||||
|
|
||||||
bool pFlow::vtkFile::openStream()
|
bool pFlow::vtkFile::openStream(bool wHeader)
|
||||||
{
|
{
|
||||||
oStream_ = makeUnique<oFstream>( fileName() );
|
oStream_ = makeUnique<oFstream>( fileName(), false, append_ );
|
||||||
if( !oStream_ )return false;
|
if( !oStream_ )return false;
|
||||||
|
if(wHeader)
|
||||||
return writeHeader();
|
return writeHeader();
|
||||||
|
else
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool pFlow::vtkFile::vtkFile::writeHeader()
|
bool pFlow::vtkFile::vtkFile::writeHeader()
|
||||||
|
@ -49,15 +52,17 @@ pFlow::vtkFile::vtkFile
|
||||||
(
|
(
|
||||||
const fileSystem dir,
|
const fileSystem dir,
|
||||||
const word& bName,
|
const word& bName,
|
||||||
real time
|
real time,
|
||||||
|
bool append
|
||||||
)
|
)
|
||||||
:
|
:
|
||||||
dirPath_(dir),
|
dirPath_(dir),
|
||||||
baseName_(bName),
|
baseName_(bName),
|
||||||
time_(time)
|
time_(time),
|
||||||
|
append_(append)
|
||||||
{
|
{
|
||||||
|
|
||||||
if(!openStream())
|
if(!openStream(!append))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction <<
|
fatalErrorInFunction <<
|
||||||
" error in creating vtkFile "<<fileName()<<endl;
|
" error in creating vtkFile "<<fileName()<<endl;
|
||||||
|
|
|
@ -40,15 +40,21 @@ protected:
|
||||||
|
|
||||||
real time_ = 0.0;
|
real time_ = 0.0;
|
||||||
|
|
||||||
|
bool append_=false;
|
||||||
|
|
||||||
uniquePtr<oFstream> oStream_= nullptr;
|
uniquePtr<oFstream> oStream_= nullptr;
|
||||||
|
|
||||||
bool openStream();
|
bool openStream(bool wHeader);
|
||||||
|
|
||||||
virtual bool writeHeader();
|
virtual bool writeHeader();
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
vtkFile(const fileSystem dir, const word& bName, real time);
|
vtkFile(
|
||||||
|
const fileSystem dir,
|
||||||
|
const word& bName,
|
||||||
|
real time,
|
||||||
|
bool append = false);
|
||||||
|
|
||||||
virtual ~vtkFile() = default;
|
virtual ~vtkFile() = default;
|
||||||
|
|
||||||
|
@ -56,7 +62,7 @@ public:
|
||||||
{
|
{
|
||||||
if(!oStream_)
|
if(!oStream_)
|
||||||
{
|
{
|
||||||
if(!openStream())
|
if(!openStream(!append_))
|
||||||
{
|
{
|
||||||
fatalErrorInFunction<<
|
fatalErrorInFunction<<
|
||||||
" error in opening vtkFile "<< fileName() <<endl;
|
" error in opening vtkFile "<< fileName() <<endl;
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
|
|
||||||
set(source_files
|
set(source_files
|
||||||
|
pointFieldToVTK.cpp
|
||||||
|
triSurfaceFieldToVTK.cpp
|
||||||
pFlowToVTK.cpp
|
pFlowToVTK.cpp
|
||||||
#geometric.cpp
|
#geometric.cpp
|
||||||
)
|
)
|
||||||
|
|
|
@ -1,87 +0,0 @@
|
||||||
/*------------------------------- 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.
|
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
|
||||||
|
|
||||||
|
|
||||||
#include "geometric.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool pFlow::dataToVTK( vtkFile& vtk, const triSurface& surface )
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
auto nP = surface.numPoints();
|
|
||||||
auto hPoints = surface.points().hostVector();
|
|
||||||
|
|
||||||
vtk() << "DATASET POLYDATA" << endl;
|
|
||||||
vtk() << "POINTS " << nP << " float" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
for ( auto i=0; i<nP; i++ )
|
|
||||||
{
|
|
||||||
vtk() << hPoints[i].x() << " " << hPoints[i].y() << " " << hPoints[i].z() << endl;
|
|
||||||
if (!vtk) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nV = surface.numTriangles();
|
|
||||||
auto hVertices = surface.vertices().hostVector();
|
|
||||||
|
|
||||||
vtk() << "POLYGONS " << nV << " " << 4*nV << endl;
|
|
||||||
|
|
||||||
for(auto i=0; i<nV; i++)
|
|
||||||
{
|
|
||||||
vtk()<< 3 <<" "<< hVertices[i].x() << " " << hVertices[i].y() <<" "<<hVertices[i].z()<<endl;
|
|
||||||
if (!vtk) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool pFlow::dataToVTK( vtkFile& vtk, const multiTriSurface& surface )
|
|
||||||
{
|
|
||||||
|
|
||||||
auto nP = surface.numPoints();
|
|
||||||
auto hPoints = surface.points().hostVector();
|
|
||||||
|
|
||||||
vtk() << "DATASET POLYDATA" << endl;
|
|
||||||
vtk() << "POINTS " << nP << " float" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
for ( auto i=0; i<nP; i++ )
|
|
||||||
{
|
|
||||||
vtk() << hPoints[i].x() << " " << hPoints[i].y() << " " << hPoints[i].z() << endl;
|
|
||||||
if (!vtk) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nV = surface.numTriangles();
|
|
||||||
auto hVertices = surface.vertices().hostVector();
|
|
||||||
|
|
||||||
vtk() << "POLYGONS " << nV << " " << 4*nV << endl;
|
|
||||||
|
|
||||||
for(auto i=0; i<nV; i++)
|
|
||||||
{
|
|
||||||
vtk()<< 3 <<" "<< hVertices[i].x() << " " << hVertices[i].y() <<" "<<hVertices[i].z()<<endl;
|
|
||||||
if (!vtk) return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,78 +0,0 @@
|
||||||
/*------------------------------- 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 __geometric_hpp__
|
|
||||||
#define __geometric_hpp__
|
|
||||||
|
|
||||||
#include "vtkFile.hpp"
|
|
||||||
#include "triSurface.hpp"
|
|
||||||
#include "multiTriSurface.hpp"
|
|
||||||
#include "IOobject.hpp"
|
|
||||||
|
|
||||||
namespace pFlow
|
|
||||||
{
|
|
||||||
|
|
||||||
|
|
||||||
template<typename ObjType>
|
|
||||||
bool geomObjectToVTK(IOfileHeader& header, real time, fileSystem destPath, word bName)
|
|
||||||
{
|
|
||||||
|
|
||||||
if( ObjType::TYPENAME() != header.objectType() )return false;
|
|
||||||
|
|
||||||
auto ioObjPtr = IOobject::make<ObjType>(header);
|
|
||||||
|
|
||||||
auto& data = ioObjPtr().template getObject<ObjType>();
|
|
||||||
|
|
||||||
vtkFile vtk(destPath, bName, time);
|
|
||||||
|
|
||||||
if(!vtk) return false;
|
|
||||||
|
|
||||||
REPORT(1)<<"Converting geometry to vtk."<<endREPORT;
|
|
||||||
|
|
||||||
if(!dataToVTK(vtk, data) )
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
" error in writing object "<<ioObjPtr().typeName() << " to folder " << destPath<<endl;
|
|
||||||
fatalExit;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
bool dataToVTK(vtkFile& vtk, const Type& dataEntity)
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"not implemented function!";
|
|
||||||
fatalExit;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool dataToVTK( vtkFile& vtk, const triSurface& surface );
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool dataToVTK( vtkFile& vtk, const multiTriSurface& surface );
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif //__geometric_hpp__
|
|
|
@ -26,7 +26,7 @@ Licence:
|
||||||
#include "Vectors.hpp"
|
#include "Vectors.hpp"
|
||||||
#include "phasicFlowKokkos.hpp"
|
#include "phasicFlowKokkos.hpp"
|
||||||
#include "pointFieldToVTK.hpp"
|
#include "pointFieldToVTK.hpp"
|
||||||
//#include "triSurfaceFieldToVTK.hpp"
|
#include "triSurfaceFieldToVTK.hpp"
|
||||||
//#include "readControlDict.hpp"
|
//#include "readControlDict.hpp"
|
||||||
|
|
||||||
|
|
||||||
|
@ -60,10 +60,10 @@ int main(int argc, char** argv )
|
||||||
"path");
|
"path");
|
||||||
|
|
||||||
bool separateSurfaces = false;
|
bool separateSurfaces = false;
|
||||||
cmds.addOption(
|
cmds.add_flag(
|
||||||
"-s,--separate-surfaces",
|
"-s,--separate-surfaces",
|
||||||
separateSurfaces,
|
separateSurfaces,
|
||||||
"surfaces in the geometry are converted separatedly");
|
"use this when you want to have sub-surfaces in separate files");
|
||||||
|
|
||||||
wordVector fields;
|
wordVector fields;
|
||||||
bool allFields = true;
|
bool allFields = true;
|
||||||
|
@ -78,7 +78,7 @@ int main(int argc, char** argv )
|
||||||
"a space separated lists of time folders, or a strided range begin:stride:end, or an interval begin:end",
|
"a space separated lists of time folders, or a strided range begin:stride:end, or an interval begin:end",
|
||||||
" ");
|
" ");
|
||||||
|
|
||||||
bool isCoupling = false;
|
//bool isCoupling = false;
|
||||||
|
|
||||||
if(!cmds.parse(argc, argv)) return 0;
|
if(!cmds.parse(argc, argv)) return 0;
|
||||||
|
|
||||||
|
@ -88,8 +88,8 @@ int main(int argc, char** argv )
|
||||||
|
|
||||||
|
|
||||||
timeFolder folders(Control);
|
timeFolder folders(Control);
|
||||||
fileSystem destFolder = fileSystem(outFolder)/word(geometryFolder__);
|
auto destFolder = fileSystem(outFolder)/word(geometryFolder__);
|
||||||
fileSystem destFolderField = fileSystem(outFolder);
|
auto destFolderField = fileSystem(outFolder);
|
||||||
wordList geomfiles{"triSurface"};
|
wordList geomfiles{"triSurface"};
|
||||||
|
|
||||||
|
|
||||||
|
@ -117,15 +117,16 @@ int main(int argc, char** argv )
|
||||||
if( !validRange.isMember( folders.time() ) )continue;
|
if( !validRange.isMember( folders.time() ) )continue;
|
||||||
|
|
||||||
output<< "time: " << Cyan_Text( folders.time() )<<" s" <<endl;
|
output<< "time: " << Cyan_Text( folders.time() )<<" s" <<endl;
|
||||||
/*if(!noGoem)
|
if(!noGoem)
|
||||||
{
|
{
|
||||||
fileSystem geomFolder = folders.folder()/geometryFolder__;
|
|
||||||
if(!pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields(geomFolder, folders.time(), destFolder, "surface"))
|
if(!pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields(
|
||||||
|
Control, destFolder, "surface", separateSurfaces))
|
||||||
{
|
{
|
||||||
fatalExit;
|
fatalExit;
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
}*/
|
}
|
||||||
|
|
||||||
if(!noParticle)
|
if(!noParticle)
|
||||||
{
|
{
|
||||||
|
@ -141,9 +142,8 @@ int main(int argc, char** argv )
|
||||||
}
|
}
|
||||||
}else
|
}else
|
||||||
{
|
{
|
||||||
/*if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected(
|
if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected(
|
||||||
folders.folder(),
|
Control,
|
||||||
folders.time(),
|
|
||||||
destFolderField,
|
destFolderField,
|
||||||
"sphereFields",
|
"sphereFields",
|
||||||
fields,
|
fields,
|
||||||
|
@ -151,7 +151,7 @@ int main(int argc, char** argv )
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
fatalExit;
|
fatalExit;
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,332 @@
|
||||||
|
#include <regex>
|
||||||
|
|
||||||
|
#include "vtkFile.hpp"
|
||||||
|
#include "vocabs.hpp"
|
||||||
|
#include "pointFieldToVTK.hpp"
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::convertTimeFolderPointFields(
|
||||||
|
systemControl &control,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
const word &bName)
|
||||||
|
{
|
||||||
|
|
||||||
|
fileSystem timeFolder = control.time().path();
|
||||||
|
// check if pointStructure exist in this folder
|
||||||
|
IOfileHeader pStructHeader(
|
||||||
|
objectFile(
|
||||||
|
pointStructureFile__,
|
||||||
|
timeFolder,
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS));
|
||||||
|
|
||||||
|
if (!pStructHeader.headerOk(true))
|
||||||
|
{
|
||||||
|
output << yellowColor << "Time folder " <<
|
||||||
|
control.time().path() << " does not contain any pStructure data file."<<
|
||||||
|
" Skipping this folder . . ."<< defaultColor << nl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkFile vtk(destPath, bName, control.time().currentTime());
|
||||||
|
|
||||||
|
if (!vtk)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto pStruct = pointStructure(control);
|
||||||
|
|
||||||
|
// get a list of files in this timeFolder;
|
||||||
|
|
||||||
|
auto posVec = pStruct.pointPositionHost();
|
||||||
|
auto *pos = posVec.data();
|
||||||
|
|
||||||
|
REPORT(1) << "Writing pointStructure to vtk file with " <<
|
||||||
|
Yellow_Text(pStruct.numActive())<<
|
||||||
|
" active particles" << END_REPORT;
|
||||||
|
|
||||||
|
addUndstrcuturedGridField(
|
||||||
|
vtk(),
|
||||||
|
pos,
|
||||||
|
pStruct.numActive());
|
||||||
|
|
||||||
|
auto fileList = containingFiles(timeFolder);
|
||||||
|
|
||||||
|
for (const auto &file : fileList)
|
||||||
|
{
|
||||||
|
|
||||||
|
IOfileHeader fieldHeader(
|
||||||
|
objectFile(
|
||||||
|
file.fileName(),
|
||||||
|
file.dirPath(),
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS));
|
||||||
|
|
||||||
|
if (fieldHeader.headerOk(true))
|
||||||
|
{
|
||||||
|
if(
|
||||||
|
convertRealx3TypePointField(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertRealTypePointField(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<uint32>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<int32>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<int64>(vtk(), fieldHeader, pStruct)||
|
||||||
|
fieldHeader.objectName() == pointStructureFile__ )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
WARNING << " This object type, " <<
|
||||||
|
fieldHeader.objectType() << " is not supported" <<
|
||||||
|
END_WARNING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
output << endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected(
|
||||||
|
systemControl &control,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
const word &bName,
|
||||||
|
const wordVector &fieldsName,
|
||||||
|
bool mustExist)
|
||||||
|
{
|
||||||
|
fileSystem timeFolder = control.time().path();
|
||||||
|
// check if pointStructure exist in this folder
|
||||||
|
IOfileHeader pStructHeader(
|
||||||
|
objectFile(
|
||||||
|
pointStructureFile__,
|
||||||
|
timeFolder,
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS));
|
||||||
|
|
||||||
|
if (!pStructHeader.headerOk(true))
|
||||||
|
{
|
||||||
|
output << yellowColor << "Time folder " <<
|
||||||
|
control.time().path() <<
|
||||||
|
" does not contain any pStructure data file."<<
|
||||||
|
" Skipping this folder . . ."<< defaultColor << nl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
vtkFile vtk(destPath, bName, control.time().currentTime());
|
||||||
|
|
||||||
|
if (!vtk)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto pStruct = pointStructure(control);
|
||||||
|
|
||||||
|
// get a list of files in this timeFolder;
|
||||||
|
|
||||||
|
auto posVec = pStruct.pointPositionHost();
|
||||||
|
auto *pos = posVec.data();
|
||||||
|
|
||||||
|
REPORT(1) << "Writing pointStructure to vtk file with " <<
|
||||||
|
Yellow_Text(pStruct.numActive())
|
||||||
|
<< " active particles" << END_REPORT;
|
||||||
|
|
||||||
|
addUndstrcuturedGridField(
|
||||||
|
vtk(),
|
||||||
|
pos,
|
||||||
|
pStruct.numActive());
|
||||||
|
|
||||||
|
auto fileList = containingFiles(timeFolder);
|
||||||
|
|
||||||
|
for (const auto &fname : fieldsName)
|
||||||
|
{
|
||||||
|
fileSystem fieldAddress = timeFolder + fname;
|
||||||
|
|
||||||
|
IOfileHeader fieldHeader(
|
||||||
|
objectFile(
|
||||||
|
fname,
|
||||||
|
timeFolder,
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS));
|
||||||
|
|
||||||
|
if (fieldHeader.headerOk(true))
|
||||||
|
{
|
||||||
|
if (
|
||||||
|
convertRealx3TypePointField(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertRealTypePointField(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<uint32>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<uint64>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<int32>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
convertIntPointField<int64>(vtk(), fieldHeader, pStruct) ||
|
||||||
|
fieldHeader.objectName() == pointStructureFile__ )
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
|
||||||
|
WARNING << " This object type, " <<
|
||||||
|
fieldHeader.objectType() << " is not supported" <<
|
||||||
|
END_WARNING;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (mustExist)
|
||||||
|
{
|
||||||
|
fatalErrorInFunction << "Field " << fieldAddress <<
|
||||||
|
" does not exist." << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
REPORT(1) << "Could not find " << Yellow_Text(fieldAddress) <<
|
||||||
|
". Skipping this field . . ." << END_REPORT;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::addUndstrcuturedGridField(
|
||||||
|
iOstream &os,
|
||||||
|
realx3 *position,
|
||||||
|
uint32 numPoints)
|
||||||
|
{
|
||||||
|
|
||||||
|
os << "DATASET UNSTRUCTURED_GRID\n";
|
||||||
|
os << "POINTS " << numPoints << " float\n";
|
||||||
|
|
||||||
|
if (numPoints == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
for (uint32 i = 0; i < numPoints; i++)
|
||||||
|
{
|
||||||
|
os << position[i].x() <<
|
||||||
|
' ' << position[i].y() <<
|
||||||
|
' ' << position[i].z() << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "CELLS " << numPoints << ' ' << 2 * numPoints << '\n';
|
||||||
|
for (uint32 i = 0; i < numPoints; i++)
|
||||||
|
{
|
||||||
|
os << 1 << ' ' << i << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "CELL_TYPES " << numPoints << '\n';
|
||||||
|
|
||||||
|
for (int32 i = 0; i < numPoints; i++)
|
||||||
|
{
|
||||||
|
os << 1 << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "POINT_DATA " << numPoints << endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::convertRealTypePointField(
|
||||||
|
iOstream &os,
|
||||||
|
const IOfileHeader &header,
|
||||||
|
pointStructure &pStruct)
|
||||||
|
{
|
||||||
|
word objectType = header.objectType();
|
||||||
|
|
||||||
|
if (!checkFieldType<real>(objectType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto field = realPointField_H(
|
||||||
|
header,
|
||||||
|
pStruct,
|
||||||
|
static_cast<real>(0));
|
||||||
|
|
||||||
|
real const *data = field.deviceViewAll().data();
|
||||||
|
|
||||||
|
REPORT(1) << "writing " << Green_Text(header.objectName()) <<
|
||||||
|
" field to vtk." << END_REPORT;
|
||||||
|
|
||||||
|
return addRealPointField(
|
||||||
|
os,
|
||||||
|
header.objectName(),
|
||||||
|
data,
|
||||||
|
pStruct.numActive());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::convertRealx3TypePointField(
|
||||||
|
iOstream &os,
|
||||||
|
const IOfileHeader &header,
|
||||||
|
pointStructure &pStruct)
|
||||||
|
{
|
||||||
|
word objectType = header.objectType();
|
||||||
|
|
||||||
|
if (!checkFieldType<realx3>(objectType))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto field = realx3PointField_H(
|
||||||
|
header,
|
||||||
|
pStruct,
|
||||||
|
{0.0, 0.0, 0.0});
|
||||||
|
|
||||||
|
realx3 const *data = field.deviceViewAll().data();
|
||||||
|
|
||||||
|
REPORT(1) << "writing " << Green_Text(header.objectName()) <<
|
||||||
|
" field to vtk." << END_REPORT;
|
||||||
|
|
||||||
|
return addRealx3PointField(
|
||||||
|
os,
|
||||||
|
header.objectName(),
|
||||||
|
data,
|
||||||
|
pStruct.numActive());
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::addRealPointField(
|
||||||
|
iOstream &os,
|
||||||
|
const word &fieldName,
|
||||||
|
const real *field,
|
||||||
|
uint32 numData)
|
||||||
|
{
|
||||||
|
if (numData == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
os << "FIELD FieldData 1\n"
|
||||||
|
<< fieldName << " 1 " << numData << " float\n";
|
||||||
|
for (uint32 i = 0; i < numData; ++i)
|
||||||
|
{
|
||||||
|
os << field[i] << '\n';
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::addRealx3PointField(
|
||||||
|
iOstream &os,
|
||||||
|
const word &fieldName,
|
||||||
|
const realx3 *field,
|
||||||
|
uint32 numData)
|
||||||
|
{
|
||||||
|
if (numData == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
os << "FIELD FieldData 1\n"
|
||||||
|
<< fieldName << " 3 " << numData << " float\n";
|
||||||
|
for (uint32 i = 0; i < numData; ++i)
|
||||||
|
{
|
||||||
|
os << field[i].x() <<
|
||||||
|
' ' << field[i].y() <<
|
||||||
|
' ' << field[i].z() << '\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::PFtoVTK::regexCheck(const word &TYPENAME, const word &fieldType)
|
||||||
|
{
|
||||||
|
std::regex match("pointField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>");
|
||||||
|
std::smatch search1;
|
||||||
|
std::smatch 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];
|
||||||
|
}
|
|
@ -18,426 +18,125 @@ Licence:
|
||||||
|
|
||||||
-----------------------------------------------------------------------------*/
|
-----------------------------------------------------------------------------*/
|
||||||
|
|
||||||
|
|
||||||
#ifndef __pointFieldToVTK_hpp__
|
#ifndef __pointFieldToVTK_hpp__
|
||||||
#define __pointFieldToVTK_hpp__
|
#define __pointFieldToVTK_hpp__
|
||||||
|
|
||||||
#include <regex>
|
|
||||||
|
|
||||||
#include "vtkFile.hpp"
|
|
||||||
#include "systemControl.hpp"
|
#include "systemControl.hpp"
|
||||||
#include "pointStructure.hpp"
|
#include "pointStructure.hpp"
|
||||||
#include "pointFields.hpp"
|
#include "pointFields.hpp"
|
||||||
|
|
||||||
|
|
||||||
namespace pFlow::PFtoVTK
|
namespace pFlow::PFtoVTK
|
||||||
{
|
{
|
||||||
|
|
||||||
/*template<typename IntType, typename IncludeMaskType>
|
bool convertTimeFolderPointFields(
|
||||||
bool addIntPointField(
|
systemControl &control,
|
||||||
iOstream& os,
|
const fileSystem &destPath,
|
||||||
word fieldName,
|
const word &bName);
|
||||||
int32 numActivePoints,
|
|
||||||
IntType* field,
|
|
||||||
IncludeMaskType includeMask );
|
|
||||||
|
|
||||||
template<typename IncludeMaskType>
|
|
||||||
bool addRealPointField(
|
|
||||||
iOstream& os,
|
|
||||||
word fieldName,
|
|
||||||
int32 numActivePoints,
|
|
||||||
real* field,
|
|
||||||
IncludeMaskType includeMask );
|
|
||||||
|
|
||||||
template<typename IncludeMaskType>
|
|
||||||
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<typename Type>
|
|
||||||
bool checkFieldType(word objectType)
|
|
||||||
{
|
|
||||||
return regexCheck(pointField<Type>::TYPENAME(), objectType);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*template<typename T>
|
|
||||||
bool convertIntPointField
|
|
||||||
(
|
|
||||||
iOstream& os,
|
|
||||||
const IOfileHeader& header,
|
|
||||||
const pointStructure& pStruct
|
|
||||||
)
|
|
||||||
{
|
|
||||||
|
|
||||||
using PointFieldType = pointField<VectorSingle, T, HostSpace>;
|
|
||||||
|
|
||||||
word objectType = header.objectType();
|
|
||||||
|
|
||||||
if(!checkFieldType<T>(objectType))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto objField = IOobject::make<PointFieldType>
|
|
||||||
(
|
|
||||||
header,
|
|
||||||
pStruct,
|
|
||||||
static_cast<T>(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto& Field = objField().template getObject<PointFieldType>();
|
|
||||||
|
|
||||||
T* data = Field.deviceVectorAll().data();
|
|
||||||
|
|
||||||
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk.\n";
|
|
||||||
|
|
||||||
return addIntPointField(
|
|
||||||
os,
|
|
||||||
header.objectName(),
|
|
||||||
pStruct.numActive(),
|
|
||||||
data,
|
|
||||||
pStruct.activePointsMaskH() );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*bool convertRealTypePointField(
|
|
||||||
iOstream& os,
|
|
||||||
const IOfileHeader& header,
|
|
||||||
const pointStructure& pStruct)
|
|
||||||
{
|
|
||||||
word objectType = header.objectType();
|
|
||||||
|
|
||||||
if(!checkFieldType<real>(objectType))return false;
|
|
||||||
|
|
||||||
auto objField = IOobject::make<realPointField_H>
|
|
||||||
(
|
|
||||||
header,
|
|
||||||
pStruct,
|
|
||||||
static_cast<real>(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto& Field = objField().getObject<realPointField_H>();
|
|
||||||
|
|
||||||
real* data = Field.hostVectorAll().data();
|
|
||||||
|
|
||||||
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk."<<endREPORT;
|
|
||||||
|
|
||||||
return addRealPointField(
|
|
||||||
os,
|
|
||||||
header.objectName(),
|
|
||||||
pStruct.numActive(),
|
|
||||||
data,
|
|
||||||
pStruct.activePointsMaskH() );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*bool convertRealx3TypePointField(
|
|
||||||
iOstream& os,
|
|
||||||
const IOfileHeader& header,
|
|
||||||
const pointStructure& pStruct)
|
|
||||||
{
|
|
||||||
word objectType = header.objectType();
|
|
||||||
|
|
||||||
if(!checkFieldType<realx3>(objectType))return false;
|
|
||||||
|
|
||||||
auto objField = IOobject::make<realx3PointField_H>
|
|
||||||
(
|
|
||||||
header,
|
|
||||||
pStruct,
|
|
||||||
static_cast<real>(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto& Field = objField().getObject<realx3PointField_H>();
|
|
||||||
|
|
||||||
realx3* data = Field.hostVectorAll().data();
|
|
||||||
|
|
||||||
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk."<<endREPORT;
|
|
||||||
|
|
||||||
return addRealx3PointField(
|
|
||||||
os,
|
|
||||||
header.objectName(),
|
|
||||||
pStruct.numActive(),
|
|
||||||
data,
|
|
||||||
pStruct.activePointsMaskH() );
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
bool convertTimeFolderPointFieldsSelected(
|
||||||
|
systemControl &control,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
const word &bName,
|
||||||
|
const wordVector &fieldsName,
|
||||||
|
bool mustExist);
|
||||||
|
|
||||||
bool addUndstrcuturedGridField(
|
bool addUndstrcuturedGridField(
|
||||||
iOstream &os,
|
iOstream &os,
|
||||||
realx3 *position,
|
realx3 *position,
|
||||||
uint32 numPoints)
|
uint32 numPoints);
|
||||||
{
|
|
||||||
|
|
||||||
os<< "DATASET UNSTRUCTURED_GRID\n";
|
bool convertRealTypePointField(
|
||||||
os<< "POINTS "<< numPoints << " float\n";
|
iOstream &os,
|
||||||
|
const IOfileHeader &header,
|
||||||
|
pointStructure &pStruct);
|
||||||
|
|
||||||
if(numPoints==0) return true;
|
bool convertRealx3TypePointField(
|
||||||
|
iOstream &os,
|
||||||
|
const IOfileHeader &header,
|
||||||
|
pointStructure &pStruct);
|
||||||
|
|
||||||
for(uint32 i=0; i<numPoints; i++)
|
template <typename IntType>
|
||||||
{
|
|
||||||
os<< position[i].x()<<' '<< position[i].y()<<' '<<position[i].z()<<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
os<<"CELLS "<< numPoints<<' '<< 2*numPoints<<'\n';
|
|
||||||
for(uint32 i=0; i<numPoints; i++)
|
|
||||||
{
|
|
||||||
os<< 1 <<' '<< i<<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
os<<"CELL_TYPES "<< numPoints<<'\n';
|
|
||||||
|
|
||||||
for(int32 i=0; i<numPoints; i++)
|
|
||||||
{
|
|
||||||
os<< 1 <<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
os << "POINT_DATA " << numPoints << endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*template<typename IntType, typename IncludeMaskType>
|
|
||||||
bool addIntPointField(
|
bool addIntPointField(
|
||||||
iOstream &os,
|
iOstream &os,
|
||||||
word fieldName,
|
const word &fieldName,
|
||||||
int32 numActivePoints,
|
|
||||||
IntType *field,
|
IntType *field,
|
||||||
IncludeMaskType includeMask )
|
uint32 numData);
|
||||||
{
|
|
||||||
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<iLast; ++i)
|
|
||||||
{
|
|
||||||
if(includeMask(i))
|
|
||||||
os<< field[i] <<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*template<typename IncludeMaskType>
|
|
||||||
bool addRealPointField(
|
bool addRealPointField(
|
||||||
iOstream &os,
|
iOstream &os,
|
||||||
word fieldName,
|
const word &fieldName,
|
||||||
int32 numActivePoints,
|
const real *field,
|
||||||
real* field,
|
uint32 numData);
|
||||||
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<iLast; ++i)
|
|
||||||
{
|
|
||||||
if(includeMask(i))
|
|
||||||
os<< field[i] <<'\n';
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}*/
|
|
||||||
|
|
||||||
/*template<typename IncludeMaskType>
|
|
||||||
bool addRealx3PointField(
|
bool addRealx3PointField(
|
||||||
iOstream &os,
|
iOstream &os,
|
||||||
word fieldName,
|
const word &fieldName,
|
||||||
int32 numActivePoints,
|
const realx3 *field,
|
||||||
realx3* field,
|
uint32 numData);
|
||||||
IncludeMaskType includeMask )
|
|
||||||
{
|
|
||||||
if(numActivePoints==0) return true;
|
|
||||||
|
|
||||||
auto [iFirst, iLast] = includeMask.activeRange();
|
template <typename Type>
|
||||||
|
bool checkFieldType(word objectType);
|
||||||
|
|
||||||
os << "FIELD FieldData 1\n"<<
|
bool regexCheck(const word &TYPENAME, const word &fieldType);
|
||||||
fieldName << " 3 " << numActivePoints << " float\n";
|
|
||||||
for(int32 i=iFirst; i<iLast; ++i)
|
template <typename Type>
|
||||||
|
inline bool checkFieldType(word objectType)
|
||||||
{
|
{
|
||||||
if(includeMask(i))
|
return regexCheck(pointField<Type>::TYPENAME(), objectType);
|
||||||
os<< field[i].x()<<' '<< field[i].y()<<' '<<field[i].z()<<'\n';
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
template <typename IntType>
|
||||||
}*/
|
inline bool convertIntPointField(
|
||||||
|
iOstream &os,
|
||||||
|
const IOfileHeader &header,
|
||||||
bool convertTimeFolderPointFields(
|
pointStructure &pStruct)
|
||||||
systemControl& control,
|
|
||||||
fileSystem destPath,
|
|
||||||
word bName)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
fileSystem timeFolder = control.time().path();
|
using PointFieldType = pointField<IntType, HostSpace>;
|
||||||
// check if pointStructure exist in this folder
|
|
||||||
IOfileHeader pStructHeader(
|
|
||||||
objectFile(
|
|
||||||
pointStructureFile__,
|
|
||||||
timeFolder,
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_ALWAYS)
|
|
||||||
);
|
|
||||||
|
|
||||||
if( !pStructHeader.headerOk(true) )
|
word objectType = header.objectType();
|
||||||
|
|
||||||
|
if (!checkFieldType<IntType>(objectType))
|
||||||
{
|
{
|
||||||
output<<yellowColor<<"Time folder "<< control.time().path() <<
|
|
||||||
" does not contain any pStructure data file. Skipping this folder . . ."
|
|
||||||
<<defaultColor<<nl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkFile vtk(destPath, bName, control.time().currentTime());
|
|
||||||
|
|
||||||
if(!vtk) return false;
|
|
||||||
|
|
||||||
|
|
||||||
auto pStruct = pointStructure(control);
|
|
||||||
|
|
||||||
// get a list of files in this timeFolder;
|
|
||||||
|
|
||||||
auto posVec = pStruct.pointPositionHost();
|
|
||||||
auto* pos = posVec.data();
|
|
||||||
|
|
||||||
REPORT(1)<<"Writing pointStructure to vtk file with "<< Yellow_Text(pStruct.numActive())
|
|
||||||
<<" active particles"<<END_REPORT;
|
|
||||||
addUndstrcuturedGridField(
|
|
||||||
vtk(),
|
|
||||||
pos,
|
|
||||||
pStruct.numActive());
|
|
||||||
|
|
||||||
//auto fileList = containingFiles(timeFolder);
|
|
||||||
|
|
||||||
|
|
||||||
/*for(auto& file:fileList)
|
|
||||||
{
|
|
||||||
IOfileHeader fieldHeader(
|
|
||||||
objectFile(
|
|
||||||
file.wordPath(),
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_ALWAYS) );
|
|
||||||
|
|
||||||
if( fieldHeader.headerOk(true) )
|
|
||||||
{
|
|
||||||
convertIntPointField<int32>(vtk(), fieldHeader, pStruct);
|
|
||||||
convertIntPointField<int64>(vtk(), fieldHeader, pStruct);
|
|
||||||
convertIntPointField<int8>(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<<yellowColor<<"Time folder "<< timeFolder <<
|
|
||||||
" does not contain any pStructure data file. Skipping this folder . . ."
|
|
||||||
<<defaultColor<<nl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkFile vtk(destPath, bName, time);
|
|
||||||
|
|
||||||
if(!vtk) return false;
|
|
||||||
|
|
||||||
auto pStructObjPtr = IOobject::make<pointStructure>(pStructHeader);
|
|
||||||
auto& pStruct = pStructObjPtr().getObject<pointStructure>();
|
|
||||||
|
|
||||||
// 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"<<endREPORT;
|
|
||||||
addUndstrcuturedGridField(
|
|
||||||
vtk(),
|
|
||||||
pStruct.numActive(),
|
|
||||||
pos,
|
|
||||||
pStruct.activePointsMaskH());
|
|
||||||
|
|
||||||
auto fileList = containingFiles(timeFolder);
|
|
||||||
|
|
||||||
|
|
||||||
for(auto& fname:fieldsName)
|
|
||||||
{
|
|
||||||
fileSystem fieldAddress = timeFolder+fname;
|
|
||||||
|
|
||||||
IOfileHeader fieldHeader(
|
|
||||||
objectFile(
|
|
||||||
fieldAddress.wordPath(),
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_ALWAYS) );
|
|
||||||
|
|
||||||
if( fieldHeader.headerOk(true) )
|
|
||||||
{
|
|
||||||
convertIntPointField<int32>(vtk(), fieldHeader, pStruct);
|
|
||||||
convertIntPointField<int64>(vtk(), fieldHeader, pStruct);
|
|
||||||
convertIntPointField<int8>(vtk(), fieldHeader, pStruct);
|
|
||||||
convertRealTypePointField(vtk(), fieldHeader, pStruct);
|
|
||||||
convertRealx3TypePointField(vtk(), fieldHeader, pStruct);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if(mustExist)
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<"Field " << fieldAddress <<
|
|
||||||
" does not exist."<<endl;
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
|
auto field = PointFieldType(
|
||||||
|
header,
|
||||||
|
pStruct,
|
||||||
|
static_cast<IntType>(0));
|
||||||
|
|
||||||
|
const IntType *data = field.deviceViewAll().data();
|
||||||
|
|
||||||
|
REPORT(1) << "writing " << Green_Text(header.objectName()) << " field to vtk.\n";
|
||||||
|
|
||||||
|
return addIntPointField(
|
||||||
|
os,
|
||||||
|
header.objectName(),
|
||||||
|
data,
|
||||||
|
pStruct.numActive());
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename IntType>
|
||||||
|
inline bool addIntPointField(
|
||||||
|
iOstream &os,
|
||||||
|
const word &fieldName,
|
||||||
|
IntType *field,
|
||||||
|
uint32 numData)
|
||||||
{
|
{
|
||||||
REPORT(1)<<"Could not find "<<yellowText(fieldAddress) <<" skipping . . ."<<endREPORT;
|
if (numData == 0)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
os << "FIELD FieldData 1\n"
|
||||||
|
<< fieldName << " 1 " << numData << " int\n";
|
||||||
|
for (uint32 i = 0; i < numData; ++i)
|
||||||
|
{
|
||||||
|
os << field[i] << '\n';
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -0,0 +1,349 @@
|
||||||
|
#include "vocabs.hpp"
|
||||||
|
#include "vtkFile.hpp"
|
||||||
|
#include "triSurfaceFieldToVTK.hpp"
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields(
|
||||||
|
systemControl &control,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
const word &bName,
|
||||||
|
bool separate)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto timeFolder = control.geometry().path();
|
||||||
|
|
||||||
|
// check if pointStructure exist in this folder
|
||||||
|
IOfileHeader triSurfaeHeader(
|
||||||
|
objectFile(
|
||||||
|
triSurfaceFile__,
|
||||||
|
timeFolder,
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS));
|
||||||
|
|
||||||
|
if (!triSurfaeHeader.headerOk(true))
|
||||||
|
{
|
||||||
|
WARNING << "Time folder " << timeFolder << " does not contain any triSurface data file."
|
||||||
|
<< " Skipping this folder . . ." << END_WARNING;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto triSurfaceObj = multiTriSurface(
|
||||||
|
objectFile(
|
||||||
|
triSurfaceFile__,
|
||||||
|
"",
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS),
|
||||||
|
&control.geometry());
|
||||||
|
|
||||||
|
if(separate)
|
||||||
|
{
|
||||||
|
return convertTimeFolderTriSurfaceFieldsSeparate(
|
||||||
|
triSurfaceObj,
|
||||||
|
destPath,
|
||||||
|
control.time().currentTime(),
|
||||||
|
bName);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return convertTimeFolderTriSurfaceFieldsSingle(
|
||||||
|
triSurfaceObj,
|
||||||
|
destPath,
|
||||||
|
control.time().currentTime(),
|
||||||
|
bName );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::triSurfaceToVTK(
|
||||||
|
iOstream &os,
|
||||||
|
const realx3 *points,
|
||||||
|
const uint32x3 *vertices,
|
||||||
|
const subSurface &subSurf)
|
||||||
|
{
|
||||||
|
auto nP = subSurf.numPoints();
|
||||||
|
|
||||||
|
os << "DATASET UNSTRUCTURED_GRID" << endl;
|
||||||
|
os << "POINTS " << nP << " float" << endl;
|
||||||
|
|
||||||
|
for ( auto i=subSurf.pointStart(); i<subSurf.pointEnd(); i++ )
|
||||||
|
{
|
||||||
|
os << points[i].x() <<
|
||||||
|
" " << points[i].y() <<
|
||||||
|
" " << points[i].z() << endl;
|
||||||
|
if (!os) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto nTri = subSurf.size();
|
||||||
|
|
||||||
|
os << "CELLS " << nTri << " " << 4*nTri << endl;
|
||||||
|
|
||||||
|
for(auto i=subSurf.start(); i<subSurf.end(); i++)
|
||||||
|
{
|
||||||
|
os<< 3 <<
|
||||||
|
" "<< vertices[i].x()-subSurf.pointStart() <<
|
||||||
|
" "<< vertices[i].y()-subSurf.pointStart() <<
|
||||||
|
" "<< vertices[i].z()-subSurf.pointStart()<<endl;
|
||||||
|
if (!os) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
os<<"CELL_TYPES "<< nTri<<'\n';
|
||||||
|
|
||||||
|
for(uint32 i=0; i<nTri; i++)
|
||||||
|
{
|
||||||
|
os<< 5 <<'\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "CELL_DATA " << nTri << endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::triSurfaceToVTK(
|
||||||
|
iOstream &os,
|
||||||
|
const realx3 *points,
|
||||||
|
const uint32x3 *vertices,
|
||||||
|
uint32 numPoints,
|
||||||
|
uint32 numTris)
|
||||||
|
{
|
||||||
|
|
||||||
|
os << "DATASET UNSTRUCTURED_GRID" << endl;
|
||||||
|
os << "POINTS " << numPoints << " float" << endl;
|
||||||
|
|
||||||
|
for ( auto i=0; i<numPoints; i++ )
|
||||||
|
{
|
||||||
|
os << points[i].x() <<
|
||||||
|
" " << points[i].y() <<
|
||||||
|
" " << points[i].z() << endl;
|
||||||
|
if (!os) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "CELLS " << numTris << " " << 4*numTris << endl;
|
||||||
|
|
||||||
|
for(auto i=0; i<numTris; i++)
|
||||||
|
{
|
||||||
|
os<< 3 <<
|
||||||
|
" "<< vertices[i].x()<<
|
||||||
|
" "<< vertices[i].y()<<
|
||||||
|
" "<< vertices[i].z()<<endl;
|
||||||
|
if (!os) return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
os<<"CELL_TYPES "<< numTris<<'\n';
|
||||||
|
|
||||||
|
for(uint32 i=0; i<numTris; i++)
|
||||||
|
{
|
||||||
|
os<< 5 <<'\n';
|
||||||
|
}
|
||||||
|
|
||||||
|
os << "CELL_DATA " << numTris << endl;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSingle
|
||||||
|
(
|
||||||
|
multiTriSurface &surface,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
real time,
|
||||||
|
const word &bName
|
||||||
|
)
|
||||||
|
{
|
||||||
|
vtkFile vtk(destPath, bName, time);
|
||||||
|
|
||||||
|
if (!vtk)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
auto hPoints = surface.points().hostView();
|
||||||
|
auto hVertices = surface.vertices().hostView();
|
||||||
|
|
||||||
|
realx3 const* pData = hPoints.data();
|
||||||
|
uint32x3 const* vData = hVertices.data();
|
||||||
|
|
||||||
|
REPORT(1) << "Wrting triSurface geometry to vtk file "<<
|
||||||
|
Green_Text(vtk.fileName()) << END_REPORT;
|
||||||
|
|
||||||
|
if (! triSurfaceToVTK(
|
||||||
|
vtk(),
|
||||||
|
pData,
|
||||||
|
vData,
|
||||||
|
surface.numPoints(),
|
||||||
|
surface.size()))
|
||||||
|
{
|
||||||
|
fatalErrorInFunction <<
|
||||||
|
"error in writing triSurface data to vtk file " <<
|
||||||
|
vtk.fileName() << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fileList = containingFiles(surface.path().dirPath());
|
||||||
|
|
||||||
|
for(const auto& file:fileList)
|
||||||
|
{
|
||||||
|
IOfileHeader fieldHeader(
|
||||||
|
objectFile(
|
||||||
|
file.fileName(),
|
||||||
|
file.dirPath(),
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS) );
|
||||||
|
|
||||||
|
if( fieldHeader.headerOk(true) )
|
||||||
|
{
|
||||||
|
convertRealx3TypetriSurfaceField(vtk(), fieldHeader, surface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
output<<endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFieldsSeparate(
|
||||||
|
multiTriSurface &surface,
|
||||||
|
const fileSystem &destPath,
|
||||||
|
real time,
|
||||||
|
const word &bName)
|
||||||
|
{
|
||||||
|
|
||||||
|
auto hPoints = surface.points().hostView();
|
||||||
|
auto hVertices = surface.vertices().hostView();
|
||||||
|
|
||||||
|
realx3 const* pData = hPoints.data();
|
||||||
|
uint32x3 const* vData = hVertices.data();
|
||||||
|
|
||||||
|
REPORT(1) << "Wrting triSurface geometry to vtk file . . ."<<
|
||||||
|
END_REPORT;
|
||||||
|
|
||||||
|
auto nSurf = surface.numSurfaces();
|
||||||
|
for(auto nS=0; nS<nSurf; nS++)
|
||||||
|
{
|
||||||
|
auto sName = surface.subSurfaceName(nS);
|
||||||
|
vtkFile vtk(destPath, groupNames(bName,sName), time);
|
||||||
|
REPORT(2) << "Wrting sub-surface to "<<
|
||||||
|
Green_Text(vtk.fileName())<<END_REPORT;
|
||||||
|
|
||||||
|
if (!vtk)
|
||||||
|
return false;
|
||||||
|
|
||||||
|
if (! triSurfaceToVTK(
|
||||||
|
vtk(),
|
||||||
|
pData,
|
||||||
|
vData,
|
||||||
|
surface.subSurfaces()[nS]) )
|
||||||
|
{
|
||||||
|
fatalErrorInFunction <<
|
||||||
|
"error in writing triSurface data to vtk file " <<
|
||||||
|
vtk.fileName() << endl;
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
auto fileList = containingFiles(surface.path().dirPath());
|
||||||
|
|
||||||
|
for(const auto& file:fileList)
|
||||||
|
{
|
||||||
|
IOfileHeader fieldHeader(
|
||||||
|
objectFile(
|
||||||
|
file.fileName(),
|
||||||
|
file.dirPath(),
|
||||||
|
objectFile::READ_ALWAYS,
|
||||||
|
objectFile::WRITE_ALWAYS) );
|
||||||
|
|
||||||
|
if( fieldHeader.headerOk(true) )
|
||||||
|
{
|
||||||
|
convertRealx3TypetriSurfaceFieldSeparate(
|
||||||
|
destPath,
|
||||||
|
fieldHeader,
|
||||||
|
surface,
|
||||||
|
bName,
|
||||||
|
time);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
output<<endl;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::convertRealx3TypetriSurfaceField(
|
||||||
|
iOstream& os,
|
||||||
|
const IOfileHeader& header,
|
||||||
|
multiTriSurface& tSurface)
|
||||||
|
{
|
||||||
|
word objectType = header.objectType();
|
||||||
|
|
||||||
|
if(!checkTriFieldType<realx3>(objectType))return false;
|
||||||
|
|
||||||
|
auto field = realx3TriSurfaceField_H
|
||||||
|
(
|
||||||
|
header,
|
||||||
|
tSurface,
|
||||||
|
static_cast<real>(0)
|
||||||
|
);
|
||||||
|
|
||||||
|
const realx3* data = field.deviceViewAll().data();
|
||||||
|
|
||||||
|
REPORT(1)<<"writing "<< greenColor <<header.objectName()<<
|
||||||
|
defaultColor<<" field to vtk."<<END_REPORT;
|
||||||
|
|
||||||
|
return pFlow::PFtoVTK::addRealx3PointField
|
||||||
|
(
|
||||||
|
os,
|
||||||
|
header.objectName(),
|
||||||
|
data,
|
||||||
|
field.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
bool pFlow::TSFtoVTK::convertRealx3TypetriSurfaceFieldSeparate
|
||||||
|
(
|
||||||
|
const fileSystem& destPath,
|
||||||
|
const IOfileHeader& header,
|
||||||
|
multiTriSurface& tSurface,
|
||||||
|
const word& bName,
|
||||||
|
real time
|
||||||
|
)
|
||||||
|
{
|
||||||
|
word objectType = header.objectType();
|
||||||
|
|
||||||
|
if(!checkTriFieldType<realx3>(objectType))return false;
|
||||||
|
|
||||||
|
auto field = realx3TriSurfaceField_H
|
||||||
|
(
|
||||||
|
header,
|
||||||
|
tSurface,
|
||||||
|
static_cast<real>(0)
|
||||||
|
);
|
||||||
|
|
||||||
|
const realx3* data = field.deviceViewAll().data();
|
||||||
|
|
||||||
|
/*REPORT(1)<<"writing "<< greenColor <<header.objectName()<<
|
||||||
|
defaultColor<<" field to vtk."<<END_REPORT;*/
|
||||||
|
|
||||||
|
auto nSurf = tSurface.numSurfaces();
|
||||||
|
|
||||||
|
for(auto nS=0; nS<nSurf; nS++)
|
||||||
|
{
|
||||||
|
auto& subSurf = tSurface.subSurfaces()[nS];
|
||||||
|
|
||||||
|
auto sName = subSurf.name();
|
||||||
|
vtkFile vtk(destPath, groupNames(bName,sName), time, true);
|
||||||
|
REPORT(2) << "Wrting sub-surface to "<<
|
||||||
|
Green_Text(vtk.fileName())<<END_REPORT;
|
||||||
|
|
||||||
|
pFlow::PFtoVTK::addRealx3PointField
|
||||||
|
(
|
||||||
|
vtk(),
|
||||||
|
header.objectName(),
|
||||||
|
data+subSurf.start(),
|
||||||
|
subSurf.size()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
/*return pFlow::PFtoVTK::addRealx3PointField
|
||||||
|
(
|
||||||
|
os,
|
||||||
|
header.objectName(),
|
||||||
|
data,
|
||||||
|
field.size()
|
||||||
|
);*/
|
||||||
|
}
|
|
@ -24,19 +24,51 @@ Licence:
|
||||||
|
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include "vtkFile.hpp"
|
#include "pointFieldToVTK.hpp"
|
||||||
#include "triSurface.hpp"
|
#include "triSurface.hpp"
|
||||||
#include "multiTriSurface.hpp"
|
#include "multiTriSurface.hpp"
|
||||||
#include "triSurfaceFields.hpp"
|
#include "triSurfaceFields.hpp"
|
||||||
#include "IOobject.hpp"
|
|
||||||
|
|
||||||
namespace pFlow::TSFtoVTK
|
namespace pFlow::TSFtoVTK
|
||||||
{
|
{
|
||||||
|
|
||||||
bool regexCheck(word TYPENAME, word fieldType)
|
bool convertTimeFolderTriSurfaceFields(
|
||||||
|
systemControl& control,
|
||||||
|
const fileSystem& destPath,
|
||||||
|
const word& bName,
|
||||||
|
bool separate);
|
||||||
|
|
||||||
|
|
||||||
|
bool triSurfaceToVTK(iOstream &os,
|
||||||
|
const realx3 *points,
|
||||||
|
const uint32x3 *vertices,
|
||||||
|
const subSurface &subSurf);
|
||||||
|
|
||||||
|
bool triSurfaceToVTK(iOstream &os,
|
||||||
|
const realx3* points,
|
||||||
|
const uint32x3* vertices,
|
||||||
|
uint32 numPoints,
|
||||||
|
uint32 numTris);
|
||||||
|
|
||||||
|
bool convertTimeFolderTriSurfaceFieldsSingle(
|
||||||
|
multiTriSurface& surface,
|
||||||
|
const fileSystem& destPath,
|
||||||
|
real time,
|
||||||
|
const word& bName);
|
||||||
|
|
||||||
|
bool convertTimeFolderTriSurfaceFieldsSeparate(
|
||||||
|
multiTriSurface& surface,
|
||||||
|
const fileSystem& destPath,
|
||||||
|
real time,
|
||||||
|
const word& bName);
|
||||||
|
|
||||||
|
inline
|
||||||
|
bool regexCheck(const word& TYPENAME, const word& fieldType)
|
||||||
{
|
{
|
||||||
std::regex match("triSurfaceField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>");
|
std::regex match("triSurfaceField\\<([A-Za-z1-9_]*)\\,([A-Za-z1-9_]*)\\>");
|
||||||
std::smatch search1, search2;
|
std::smatch search1;
|
||||||
|
std::smatch search2;
|
||||||
if(!std::regex_match(fieldType, search1, match))return false;
|
if(!std::regex_match(fieldType, search1, match))return false;
|
||||||
if(!std::regex_match(TYPENAME, search2, match))return false;
|
if(!std::regex_match(TYPENAME, search2, match))return false;
|
||||||
if(search1.size()!=3)return false;
|
if(search1.size()!=3)return false;
|
||||||
|
@ -45,201 +77,27 @@ bool regexCheck(word TYPENAME, word fieldType)
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename Type>
|
template<typename Type>
|
||||||
bool checkFieldType(word objectType)
|
inline
|
||||||
|
bool checkTriFieldType(word objectType)
|
||||||
{
|
{
|
||||||
//if( pointField<VectorSingle,Type>::TYPENAME() == objectType )return true;
|
return regexCheck(triSurfaceField<Type>::TYPENAME(), objectType);
|
||||||
//if( pointField<VectorSingle,Type, HostSpace>::TYPENAME() == objectType ) return true;
|
|
||||||
//if( pointField<VectorDual, Type>::TYPENAME() == objectType )return true;
|
|
||||||
return regexCheck(triSurfaceField<VectorSingle,Type>::TYPENAME(), objectType);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
template<typename Type>
|
|
||||||
bool triDataToVTK(iOstream& os, const Type& dataEntity)
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"not implemented function!";
|
|
||||||
fatalExit;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool triDataToVTK(iOstream& os, const triSurface& surface )
|
|
||||||
{
|
|
||||||
auto nP = surface.numPoints();
|
|
||||||
auto hPoints = surface.points().hostVector();
|
|
||||||
|
|
||||||
os << "DATASET POLYDATA" << endl;
|
|
||||||
os << "POINTS " << nP << " float" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
for ( auto i=0; i<nP; i++ )
|
|
||||||
{
|
|
||||||
os << hPoints[i].x() << " " << hPoints[i].y() << " " << hPoints[i].z() << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nV = surface.numTriangles();
|
|
||||||
auto hVertices = surface.vertices().hostVector();
|
|
||||||
|
|
||||||
os << "POLYGONS " << nV << " " << 4*nV << endl;
|
|
||||||
|
|
||||||
for(auto i=0; i<nV; i++)
|
|
||||||
{
|
|
||||||
os<< 3 <<" "<< hVertices[i].x() << " " << hVertices[i].y() <<" "<<hVertices[i].z()<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
template<>
|
|
||||||
bool triDataToVTK(iOstream& os, const multiTriSurface& surface )
|
|
||||||
{
|
|
||||||
auto nP = surface.numPoints();
|
|
||||||
auto hPoints = surface.points().hostVector();
|
|
||||||
|
|
||||||
os << "DATASET UNSTRUCTURED_GRID" << endl;
|
|
||||||
os << "POINTS " << nP << " float" << endl;
|
|
||||||
|
|
||||||
|
|
||||||
for ( auto i=0; i<nP; i++ )
|
|
||||||
{
|
|
||||||
os << hPoints[i].x() << " " << hPoints[i].y() << " " << hPoints[i].z() << endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
auto nV = surface.numTriangles();
|
|
||||||
auto hVertices = surface.vertices().hostVector();
|
|
||||||
|
|
||||||
os<<"CELLS "<< nV<<' '<< 4*nV<<'\n';
|
|
||||||
//os << "POLYGONS " << nV << " " << 4*nV << endl;
|
|
||||||
|
|
||||||
for(auto i=0; i<nV; i++)
|
|
||||||
{
|
|
||||||
os<< 3 <<" "<< hVertices[i].x() << " " << hVertices[i].y() <<" "<<hVertices[i].z()<<endl;
|
|
||||||
}
|
|
||||||
|
|
||||||
os<<"CELL_TYPES "<< nV<<'\n';
|
|
||||||
|
|
||||||
for(int32 i=0; i<nV; i++)
|
|
||||||
{
|
|
||||||
os<< 5 <<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
os << "CELL_DATA " << nV << endl;
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool addRealx3TriSurfaceField(
|
|
||||||
iOstream& os,
|
|
||||||
word fieldName,
|
|
||||||
int32 size,
|
|
||||||
realx3* field )
|
|
||||||
{
|
|
||||||
if(size==0) return true;
|
|
||||||
|
|
||||||
|
|
||||||
os << "FIELD FieldData 1\n"<<
|
|
||||||
fieldName << " 3 " << size << " float\n";
|
|
||||||
for(int32 i=0; i<size; ++i)
|
|
||||||
{
|
|
||||||
os<< field[i].x()<<' '<< field[i].y()<<' '<<field[i].z()<<'\n';
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool convertRealx3TypetriSurfaceField(
|
bool convertRealx3TypetriSurfaceField(
|
||||||
iOstream& os,
|
iOstream& os,
|
||||||
const IOfileHeader& header,
|
const IOfileHeader& header,
|
||||||
const multiTriSurface& tSurface)
|
multiTriSurface& tSurface);
|
||||||
{
|
|
||||||
word objectType = header.objectType();
|
|
||||||
|
|
||||||
if(!checkFieldType<realx3>(objectType))return false;
|
bool convertRealx3TypetriSurfaceFieldSeparate(
|
||||||
|
const fileSystem& destPath,
|
||||||
auto objField = IOobject::make<realx3TriSurfaceField_H>
|
const IOfileHeader& header,
|
||||||
(
|
multiTriSurface& tSurface,
|
||||||
header,
|
const word& bName,
|
||||||
tSurface,
|
real time);
|
||||||
static_cast<real>(0)
|
|
||||||
);
|
|
||||||
|
|
||||||
auto& Field = objField().getObject<realx3TriSurfaceField_H>();
|
|
||||||
|
|
||||||
realx3* data = Field.hostVectorAll().data();
|
|
||||||
|
|
||||||
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk."<<endREPORT;
|
|
||||||
|
|
||||||
return addRealx3TriSurfaceField(
|
|
||||||
os,
|
|
||||||
header.objectName(),
|
|
||||||
tSurface.size(),
|
|
||||||
data );
|
|
||||||
}
|
|
||||||
|
|
||||||
bool convertTimeFolderTriSurfaceFields(
|
|
||||||
fileSystem timeFolder,
|
|
||||||
real time,
|
|
||||||
fileSystem destPath,
|
|
||||||
word bName)
|
|
||||||
{
|
|
||||||
|
|
||||||
// check if pointStructure exist in this folder
|
|
||||||
IOfileHeader triSurfaeHeader(
|
|
||||||
objectFile(
|
|
||||||
triSurfaceFile__,
|
|
||||||
timeFolder,
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_ALWAYS)
|
|
||||||
);
|
|
||||||
|
|
||||||
if( !triSurfaeHeader.headerOk(true) )
|
|
||||||
{
|
|
||||||
output<<yellowText("Time folder "<< timeFolder <<
|
|
||||||
" does not contain any triSurface data file. Skipping this folder . . ."
|
|
||||||
)<<nl;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
vtkFile vtk(destPath, bName, time);
|
|
||||||
|
|
||||||
if(!vtk) return false;
|
|
||||||
|
|
||||||
auto triSurfaceObjPtr = IOobject::make<multiTriSurface>(triSurfaeHeader);
|
|
||||||
auto& tSurface = triSurfaceObjPtr().getObject<multiTriSurface>();
|
|
||||||
|
|
||||||
// get a list of files in this timeFolder;
|
|
||||||
REPORT(1)<<"Wrting triSurface mesh/Geometry to vtk file."<<endREPORT;
|
|
||||||
if(!triDataToVTK(vtk(), tSurface))
|
|
||||||
{
|
|
||||||
fatalErrorInFunction<<
|
|
||||||
"error in writing triSurface data to vtk file "<< vtk.fileName()<<endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
auto fileList = containingFiles(timeFolder);
|
|
||||||
|
|
||||||
|
|
||||||
for(auto& file:fileList)
|
|
||||||
{
|
|
||||||
IOfileHeader fieldHeader(
|
|
||||||
objectFile(
|
|
||||||
file.wordPath(),
|
|
||||||
"",
|
|
||||||
objectFile::READ_ALWAYS,
|
|
||||||
objectFile::WRITE_ALWAYS) );
|
|
||||||
|
|
||||||
if( fieldHeader.headerOk(true) )
|
|
||||||
{
|
|
||||||
//output<<"object file type is "<<fieldHeader.objectType()<<endl;
|
|
||||||
convertRealx3TypetriSurfaceField(vtk(), fieldHeader, tSurface);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue