mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-12 16:26:23 +00:00
utilities added
This commit is contained in:
9
utilities/pFlowToVTK/CMakeLists.txt
Normal file
9
utilities/pFlowToVTK/CMakeLists.txt
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
set(source_files
|
||||
pFlowToVTK.C
|
||||
vtkFile.C
|
||||
geometric.C
|
||||
)
|
||||
set(link_lib phasicFlow Kokkos::kokkos)
|
||||
|
||||
pFlow_make_executable_install(pFlowToVTK source_files link_lib)
|
87
utilities/pFlowToVTK/geometric.C
Executable file
87
utilities/pFlowToVTK/geometric.C
Executable file
@ -0,0 +1,87 @@
|
||||
/*------------------------------- 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.H"
|
||||
|
||||
|
||||
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;
|
||||
|
||||
}
|
78
utilities/pFlowToVTK/geometric.H
Executable file
78
utilities/pFlowToVTK/geometric.H
Executable file
@ -0,0 +1,78 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __geometric_H__
|
||||
|
||||
#include "vtkFile.H"
|
||||
#include "triSurface.H"
|
||||
#include "multiTriSurface.H"
|
||||
#include "IOobject.H"
|
||||
|
||||
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_H__
|
142
utilities/pFlowToVTK/pFlowToVTK.C
Executable file
142
utilities/pFlowToVTK/pFlowToVTK.C
Executable file
@ -0,0 +1,142 @@
|
||||
/*------------------------------- 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 "systemControl.H"
|
||||
#include "pointFieldToVTK.H"
|
||||
#include "triSurfaceFieldToVTK.H"
|
||||
#include "timeFolder.H"
|
||||
#include "commandLine.H"
|
||||
#include "ranges.H"
|
||||
|
||||
using pFlow::word;
|
||||
using pFlow::wordVector;
|
||||
using pFlow::geometryFolder__;
|
||||
using pFlow::timeFolder;
|
||||
using pFlow::fileSystem;
|
||||
using pFlow::wordList;
|
||||
using pFlow::IOfileHeader;
|
||||
using pFlow::objectFile;
|
||||
using pFlow::output;
|
||||
using pFlow::endl;
|
||||
using pFlow::multiTriSurface;
|
||||
using pFlow::commandLine;
|
||||
using pFlow::realCombinedRange;
|
||||
|
||||
int main(int argc, char** argv )
|
||||
{
|
||||
word outFolder = (pFlow::CWD()/word("VTK")).wordPath();
|
||||
|
||||
commandLine cmds(
|
||||
"pFlowToVTK",
|
||||
"Convrtes the saved pointField and geometry"
|
||||
" date in time folders into vtk file format.");
|
||||
|
||||
wordVector times;
|
||||
|
||||
bool noGoem = false;
|
||||
cmds.add_flag(
|
||||
"--no-geometry",
|
||||
noGoem,
|
||||
"Do not convert geometry to VTK file");
|
||||
|
||||
bool noParticle = false;
|
||||
cmds.add_flag("--no-particles",
|
||||
noParticle,
|
||||
"Do not convert particle fields to VTK file");
|
||||
|
||||
cmds.addOption("-o,--out-folder",
|
||||
outFolder,
|
||||
"path to output folder of VTK",
|
||||
"path");
|
||||
|
||||
cmds.addOption(
|
||||
"-t,--time",
|
||||
times.vectorField(),
|
||||
"a space separated lits of time folders, or a strided range begin:stride:end, or an interval begin:end",
|
||||
" ");
|
||||
|
||||
if(!cmds.parse(argc, argv)) return 0;
|
||||
|
||||
|
||||
// this should be palced in each main
|
||||
#include "initialize_Control.H"
|
||||
|
||||
|
||||
timeFolder folders(Control);
|
||||
fileSystem destFolder = fileSystem(outFolder)/geometryFolder__;
|
||||
fileSystem destFolderField = fileSystem(outFolder);
|
||||
wordList geomfiles{"triSurface"};
|
||||
|
||||
realCombinedRange validRange;
|
||||
if( cmds.count("--time") )
|
||||
{
|
||||
if(!validRange.addRanges(times))
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
validRange.addIntervalRange(folders.startTime(), folders.endTime());
|
||||
}
|
||||
|
||||
do
|
||||
{
|
||||
|
||||
if( !validRange.isMember( folders.time() ) )continue;
|
||||
|
||||
output<< "time: " << cyanText( folders.time() )<<" s" <<endl;
|
||||
if(!noGoem)
|
||||
{
|
||||
fileSystem geomFolder = folders.folder()/geometryFolder__;
|
||||
if(!pFlow::TSFtoVTK::convertTimeFolderTriSurfaceFields(geomFolder, folders.time(), destFolder, "surface"))
|
||||
{
|
||||
fatalExit;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
|
||||
if(!noParticle)
|
||||
{
|
||||
if( !pFlow::PFtoVTK::convertTimeFolderPointFields(
|
||||
folders.folder(),
|
||||
folders.time(),
|
||||
destFolderField,
|
||||
"sphereFields" )
|
||||
)
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
||||
output<<endl;
|
||||
|
||||
}
|
||||
while( folders++ );
|
||||
|
||||
|
||||
output<< "\nFinished successfully.\n";
|
||||
|
||||
|
||||
// this should be palced in each main
|
||||
#include "finalize.H"
|
||||
return 0;
|
||||
}
|
361
utilities/pFlowToVTK/pointFieldToVTK.H
Executable file
361
utilities/pFlowToVTK/pointFieldToVTK.H
Executable file
@ -0,0 +1,361 @@
|
||||
/*------------------------------- 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_H__
|
||||
#define __pointFieldToVTK_H__
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include "vtkFile.H"
|
||||
#include "pointFields.H"
|
||||
#include "IOobject.H"
|
||||
|
||||
namespace pFlow::PFtoVTK
|
||||
{
|
||||
|
||||
template<typename IncludeMaskType>
|
||||
bool addInt64PointField(
|
||||
iOstream& os,
|
||||
word fieldName,
|
||||
int32 numActivePoints,
|
||||
int64* 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)
|
||||
{
|
||||
//if( pointField<VectorSingle,Type>::TYPENAME() == objectType )return true;
|
||||
//if( pointField<VectorSingle,Type, HostSpace>::TYPENAME() == objectType ) return true;
|
||||
//if( pointField<VectorDual, Type>::TYPENAME() == objectType )return true;
|
||||
return regexCheck(pointField<VectorSingle,Type>::TYPENAME(), objectType);
|
||||
|
||||
}
|
||||
|
||||
bool convertIntTypesPointField(
|
||||
iOstream& os,
|
||||
const IOfileHeader& header,
|
||||
const pointStructure& pStruct )
|
||||
{
|
||||
word objectType = header.objectType();
|
||||
|
||||
if( !(checkFieldType<int8>(objectType) ||
|
||||
checkFieldType<int16>(objectType) ||
|
||||
checkFieldType<int32>(objectType) ||
|
||||
checkFieldType<int64>(objectType) ||
|
||||
checkFieldType<uint32>(objectType) ||
|
||||
checkFieldType<label>(objectType))
|
||||
)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
auto objField = IOobject::make<int64PointField_H>
|
||||
(
|
||||
header,
|
||||
pStruct,
|
||||
static_cast<int64>(0)
|
||||
);
|
||||
|
||||
auto& Field = objField().getObject<int64PointField_H>();
|
||||
|
||||
int64* data = Field.hostVectorAll().data();
|
||||
|
||||
Report(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk.\n";
|
||||
|
||||
return addInt64PointField(
|
||||
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() );
|
||||
}
|
||||
|
||||
|
||||
template<typename IncludeMaskType>
|
||||
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<iLast; ++i)
|
||||
{
|
||||
if(includeMask(i))
|
||||
os<< position[i].x()<<' '<< position[i].y()<<' '<<position[i].z()<<'\n';
|
||||
}
|
||||
|
||||
os<<"CELLS "<< numActivePoints<<' '<< 2*numActivePoints<<'\n';
|
||||
for(int32 i=0; i<numActivePoints; i++)
|
||||
{
|
||||
os<< 1 <<' '<< i<<'\n';
|
||||
}
|
||||
|
||||
os<<"CELL_TYPES "<< numActivePoints<<'\n';
|
||||
|
||||
for(int32 i=0; i<numActivePoints; i++)
|
||||
{
|
||||
os<< 1 <<'\n';
|
||||
}
|
||||
|
||||
os << "POINT_DATA " << numActivePoints << endl;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template<typename IncludeMaskType>
|
||||
bool addInt64PointField(
|
||||
iOstream& os,
|
||||
word fieldName,
|
||||
int32 numActivePoints,
|
||||
int64* 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<iLast; ++i)
|
||||
{
|
||||
if(includeMask(i))
|
||||
os<< field[i] <<'\n';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename IncludeMaskType>
|
||||
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<iLast; ++i)
|
||||
{
|
||||
if(includeMask(i))
|
||||
os<< field[i] <<'\n';
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename IncludeMaskType>
|
||||
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<iLast; ++i)
|
||||
{
|
||||
if(includeMask(i))
|
||||
os<< field[i].x()<<' '<< field[i].y()<<' '<<field[i].z()<<'\n';
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool convertTimeFolderPointFields(
|
||||
fileSystem timeFolder,
|
||||
real time,
|
||||
fileSystem destPath,
|
||||
word bName)
|
||||
{
|
||||
|
||||
// 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."<<endReport;
|
||||
addUndstrcuturedGridField(
|
||||
vtk(),
|
||||
pStruct.numActive(),
|
||||
pos,
|
||||
pStruct.activePointsMaskH());
|
||||
|
||||
auto fileList = containingFiles(timeFolder);
|
||||
|
||||
|
||||
for(auto& file:fileList)
|
||||
{
|
||||
IOfileHeader fieldHeader(
|
||||
objectFile(
|
||||
file.wordPath(),
|
||||
"",
|
||||
objectFile::READ_ALWAYS,
|
||||
objectFile::WRITE_ALWAYS) );
|
||||
|
||||
if( fieldHeader.headerOk(true) )
|
||||
{
|
||||
convertIntTypesPointField(vtk(), fieldHeader, pStruct);
|
||||
convertRealTypePointField(vtk(), fieldHeader, pStruct);
|
||||
convertRealx3TypePointField(vtk(), fieldHeader, pStruct);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif
|
245
utilities/pFlowToVTK/triSurfaceFieldToVTK.H
Normal file
245
utilities/pFlowToVTK/triSurfaceFieldToVTK.H
Normal file
@ -0,0 +1,245 @@
|
||||
/*------------------------------- 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 __triSurfaceFieldToVTK_H__
|
||||
#define __triSurfaceFieldToVTK_H__
|
||||
|
||||
#include <regex>
|
||||
|
||||
#include "vtkFile.H"
|
||||
#include "triSurface.H"
|
||||
#include "multiTriSurface.H"
|
||||
#include "triSurfaceFields.H"
|
||||
#include "IOobject.H"
|
||||
|
||||
namespace pFlow::TSFtoVTK
|
||||
{
|
||||
|
||||
bool regexCheck(word TYPENAME, word fieldType)
|
||||
{
|
||||
std::regex match("triSurfaceField\\<([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)
|
||||
{
|
||||
//if( pointField<VectorSingle,Type>::TYPENAME() == objectType )return true;
|
||||
//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(
|
||||
iOstream& os,
|
||||
const IOfileHeader& header,
|
||||
const multiTriSurface& tSurface)
|
||||
{
|
||||
word objectType = header.objectType();
|
||||
|
||||
if(!checkFieldType<realx3>(objectType))return false;
|
||||
|
||||
auto objField = IOobject::make<realx3TriSurfaceField_H>
|
||||
(
|
||||
header,
|
||||
tSurface,
|
||||
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
|
75
utilities/pFlowToVTK/vtkFile.C
Executable file
75
utilities/pFlowToVTK/vtkFile.C
Executable file
@ -0,0 +1,75 @@
|
||||
/*------------------------------- 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 "vtkFile.H"
|
||||
|
||||
bool pFlow::vtkFile::openStream()
|
||||
{
|
||||
oStream_ = makeUnique<oFstream>( fileName() );
|
||||
if( !oStream_ )return false;
|
||||
return writeHeader();
|
||||
}
|
||||
|
||||
bool pFlow::vtkFile::vtkFile::writeHeader()
|
||||
{
|
||||
|
||||
if(!oStream_) return false;
|
||||
|
||||
oStream_() << "# vtk DataFile Version 2.0" << endl;
|
||||
|
||||
oStream_() << "vtk file for time : " << time_ << endl;
|
||||
|
||||
oStream_() << "ASCII" << endl;
|
||||
|
||||
if( oStream_().fail() ) return false;
|
||||
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
pFlow::vtkFile::vtkFile
|
||||
(
|
||||
const fileSystem dir,
|
||||
const word& bName,
|
||||
real time
|
||||
)
|
||||
:
|
||||
dirPath_(dir),
|
||||
baseName_(bName),
|
||||
time_(time)
|
||||
{
|
||||
|
||||
if(!openStream())
|
||||
{
|
||||
fatalErrorInFunction <<
|
||||
" error in creating vtkFile "<<fileName()<<endl;
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
pFlow::fileSystem pFlow::vtkFile::fileName()const
|
||||
{
|
||||
word fName = baseName_ +"-" + int322Word(10000*time_) + ".vtk";
|
||||
return dirPath_ +fName;
|
||||
}
|
||||
|
90
utilities/pFlowToVTK/vtkFile.H
Executable file
90
utilities/pFlowToVTK/vtkFile.H
Executable file
@ -0,0 +1,90 @@
|
||||
/*------------------------------- 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 __vtkFile_H__
|
||||
#define __vtkFile_H__
|
||||
|
||||
#include "types.H"
|
||||
#include "uniquePtr.H"
|
||||
#include "fileSystem.H"
|
||||
#include "streams.H"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
|
||||
class vtkFile
|
||||
{
|
||||
protected:
|
||||
|
||||
fileSystem dirPath_;
|
||||
|
||||
word baseName_;
|
||||
|
||||
real time_ = 0.0;
|
||||
|
||||
uniquePtr<oFstream> oStream_= nullptr;
|
||||
|
||||
bool openStream();
|
||||
|
||||
virtual bool writeHeader();
|
||||
|
||||
public:
|
||||
|
||||
vtkFile(const fileSystem dir, const word& bName, real time);
|
||||
|
||||
virtual ~vtkFile() = default;
|
||||
|
||||
inline oFstream& operator ()()
|
||||
{
|
||||
if(!oStream_)
|
||||
{
|
||||
if(!openStream())
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in opening vtkFile "<< fileName() <<endl;
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
return oStream_();
|
||||
}
|
||||
|
||||
inline explicit operator bool() const
|
||||
{
|
||||
if(!oStream_)return false;
|
||||
if(oStream_().fail())return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool operator!()const
|
||||
{
|
||||
if( !oStream_) return true;
|
||||
if( oStream_().fail() )return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
virtual fileSystem fileName()const;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif //__vtkFile_H__
|
Reference in New Issue
Block a user