data read and write in binary

This commit is contained in:
Hamidreza Norouzi
2023-04-11 22:19:36 -07:00
parent b5572d3f7f
commit c46aaab2db
31 changed files with 873 additions and 442 deletions

View File

@ -31,12 +31,12 @@ Licence:
namespace pFlow::PFtoVTK
{
template<typename IncludeMaskType>
bool addInt64PointField(
template<typename IntType, typename IncludeMaskType>
bool addIntPointField(
iOstream& os,
word fieldName,
int32 numActivePoints,
int64* field,
IntType* field,
IncludeMaskType includeMask );
template<typename IncludeMaskType>
@ -76,6 +76,41 @@ bool checkFieldType(word objectType)
}
bool convertInt32PointField
(
iOstream& os,
const IOfileHeader& header,
const pointStructure& pStruct
)
{
word objectType = header.objectType();
if(!checkFieldType<int32>(objectType))
{
return false;
}
auto objField = IOobject::make<int32PointField_H>
(
header,
pStruct,
static_cast<int64>(0)
);
auto& Field = objField().getObject<int32PointField_H>();
auto* data = Field.hostVectorAll().data();
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk.\n";
return addIntPointField(
os,
header.objectName(),
pStruct.numActive(),
data,
pStruct.activePointsMaskH() );
}
bool convertIntTypesPointField(
iOstream& os,
const IOfileHeader& header,
@ -85,7 +120,6 @@ bool convertIntTypesPointField(
if( !(checkFieldType<int8>(objectType) ||
checkFieldType<int16>(objectType) ||
checkFieldType<int32>(objectType) ||
checkFieldType<int64>(objectType) ||
checkFieldType<uint32>(objectType) ||
checkFieldType<label>(objectType))
@ -107,7 +141,7 @@ bool convertIntTypesPointField(
REPORT(2)<<"writing "<< greenColor <<header.objectName()<<defaultColor<<" field to vtk.\n";
return addInt64PointField(
return addIntPointField(
os,
header.objectName(),
pStruct.numActive(),
@ -219,12 +253,12 @@ bool addUndstrcuturedGridField(
}
template<typename IncludeMaskType>
bool addInt64PointField(
template<typename IntType, typename IncludeMaskType>
bool addIntPointField(
iOstream& os,
word fieldName,
int32 numActivePoints,
int64* field,
IntType* field,
IncludeMaskType includeMask )
{
if(numActivePoints==0) return true;
@ -346,7 +380,7 @@ bool convertTimeFolderPointFields(
if( fieldHeader.headerOk(true) )
{
convertIntTypesPointField(vtk(), fieldHeader, pStruct);
convertInt32PointField(vtk(), fieldHeader, pStruct);
convertRealTypePointField(vtk(), fieldHeader, pStruct);
convertRealx3TypePointField(vtk(), fieldHeader, pStruct);
}

View File

@ -96,7 +96,120 @@ int main( int argc, char* argv[] )
auto& cpDict = objCPDict().getObject<dictionary>();
uniquePtr<IOobject> pStructObj{nullptr};
pointStructure* pStructPtr = nullptr;
if(!setOnly)
{
// position particles based on the dict content
REPORT(0)<< "Positioning points . . . \n"<<endREPORT;
auto pointPosition = positionParticles::create(cpDict.subDict("positionParticles"));
fileSystem pStructPath = Control.time().path()+pointStructureFile__;
auto finalPos = pointPosition().getFinalPosition();
auto& pStruct = Control.time().emplaceObject<pointStructure>
(
objectFile
(
pointStructureFile__,
Control.time().path(),
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
finalPos
);
pStructPtr = &pStruct;
REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<<
pStruct.capacity()<<" . . ."<< endREPORT;
REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< endREPORT<<endl<<endl;
if( !Control.time().write())
{
fatalErrorInFunction<<
"ERRor in writing to file. \n ";
return 1;
}
}else
{
auto& pStruct = Control.time().emplaceObject<pointStructure>
(
objectFile
(
pointStructureFile__,
Control.time().path(),
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
)
);
pStructPtr = &pStruct;
}
if(!positionOnly)
{
auto& pStruct = *pStructPtr;
auto& sfDict = cpDict.subDict("setFields");
setFieldList defValueList(sfDict.subDict("defaultValue"));
for(auto& sfEntry: defValueList)
{
if( !sfEntry.setPointFieldDefaultValueNewAll(Control.time(), pStruct, true))
{
ERR<< "\n error occured in setting default value fields.\n"<<endERR;
return 1;
}
}
output<<endl;
auto& selectorsDict = sfDict.subDict("selectors");
auto selNames = selectorsDict.dictionaryKeywords();
for(auto name: selNames)
{
REPORT(1)<< "Applying selector " << greenText(name) <<endREPORT;
if(
!applySelector(Control, pStruct, selectorsDict.subDict(name))
)
{
ERR<<"\n error occured in setting selector. \n"<<endERR;
return 1;
}
output<<endl;
}
}
Control.time().write(true);
REPORT(0)<< greenText("\nFinished successfully.\n")<<endREPORT;
// this should be palced in each main
#include "finalize.hpp"
return 0;
}
/*
uniquePtr<IOobject> pStructObj{nullptr};
if(!setOnly)
{
@ -189,13 +302,4 @@ int main( int argc, char* argv[] )
output<<endl;
}
}
Control.time().write(true);
REPORT(0)<< greenText("\nFinished successfully.\n")<<endREPORT;
// this should be palced in each main
#include "finalize.hpp"
return 0;
}
*/