modified pFlowToVTK to accept a supset of fields

This commit is contained in:
hamidrezanorouzi 2022-10-07 16:41:15 +03:30
parent 4f23bbbd8e
commit 0eae4ef319
2 changed files with 125 additions and 8 deletions

View File

@ -67,10 +67,17 @@ int main(int argc, char** argv )
"path to output folder of VTK", "path to output folder of VTK",
"path"); "path");
wordVector fields;
bool allFields = true;
cmds.addOption("-f,--fields",
fields.vectorField(),
"a space-separated list of fields names to be converted to VTK",
"word");
cmds.addOption( cmds.addOption(
"-t,--time", "-t,--time",
times.vectorField(), times.vectorField(),
"a space separated lits 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",
" "); " ");
if(!cmds.parse(argc, argv)) return 0; if(!cmds.parse(argc, argv)) return 0;
@ -85,6 +92,12 @@ int main(int argc, char** argv )
fileSystem destFolderField = fileSystem(outFolder); fileSystem destFolderField = fileSystem(outFolder);
wordList geomfiles{"triSurface"}; wordList geomfiles{"triSurface"};
if(cmds.count("--fields"))
{
allFields = false;
}
realCombinedRange validRange; realCombinedRange validRange;
if( cmds.count("--time") ) if( cmds.count("--time") )
{ {
@ -116,14 +129,31 @@ int main(int argc, char** argv )
if(!noParticle) if(!noParticle)
{ {
if( !pFlow::PFtoVTK::convertTimeFolderPointFields(
folders.folder(), if(allFields)
folders.time(),
destFolderField,
"sphereFields" )
)
{ {
fatalExit; if( !pFlow::PFtoVTK::convertTimeFolderPointFields(
folders.folder(),
folders.time(),
destFolderField,
"sphereFields" )
)
{
fatalExit;
}
}else
{
if(!pFlow::PFtoVTK::convertTimeFolderPointFieldsSelected(
folders.folder(),
folders.time(),
destFolderField,
"sphereFields",
fields,
!pFlow::equal(folders.time(),static_cast<pFlow::real>(0.0)) )
)
{
fatalExit;
}
} }
} }

View File

@ -355,6 +355,93 @@ bool convertTimeFolderPointFields(
return true; 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) )
{
convertIntTypesPointField(vtk(), fieldHeader, pStruct);
convertRealTypePointField(vtk(), fieldHeader, pStruct);
convertRealx3TypePointField(vtk(), fieldHeader, pStruct);
}
else
{
if(mustExist)
{
fatalErrorInFunction<<"Field " << fieldAddress <<
" does not exist."<<endl;
return false;
}
else
{
Report(1)<<"Could not find "<<yellowText(fieldAddress) <<" skipping . . ."<<endReport;
}
}
}
return true;
}
} }