# PhasicFlow: utilities/pFlowToVTK/fileSeries.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

fileSeries.cpp
Go to the documentation of this file.
#include "fileSeries.hpp"
#include "oFstream.hpp"
#include "streams.hpp"
void pFlow::PFtoVTK::fileSeries::writeOneBaseName(const word &baseName)
{
auto& fList = timeFiles_[baseName];
word fileName = baseName + ".vtk.series";
oFstream os(destDir_+fileName);
REPORT(1)<<"Writing to "<<os.name()<<END_REPORT;
os<<"{\n";
os<<" \"file-series-version\" : \"1.0\",\n";
os<<" \"files\" : [\n";
const auto lastItem = std::prev(fList.end());
for(auto iter = fList.begin(); iter != fList.end(); ++iter)
{
os<<" {\"name\" : \"";
os<< iter->second;
os<<"\", \"time\" :";
os<<iter->first;
if(iter == lastItem)
os<<"}\n";
else
os<<"},\n";
}
os<<" ]\n";
os<<"}\n";
}
pFlow::PFtoVTK::fileSeries::fileSeries(const fileSystem dest)
: destDir_(dest)
{
}
pFlow::PFtoVTK::fileSeries::~fileSeries()
{
REPORT(0)<<"Writing time series files..."<<END_REPORT;
for(const auto& fSeries:timeFiles_)
{
writeOneBaseName(fSeries.first);
}
}
bool pFlow::PFtoVTK::fileSeries::addTimeFile(const word& baseName, real time, const word &fileName)
{
fileSystem fs(fileName);
word relFileName = fs.relative(destDir_).wordPath();
if( auto [iter, found]=timeFiles_.findIf(baseName); found )
{
return iter->second.insertIf(time, relFileName);
}
else
{
TimeFileType newList;
newList.insertIf(time, relFileName);
return timeFiles_.insertIf(baseName, newList);
}
}
bool pFlow::PFtoVTK::fileSeries::addTimeFile(const wordList &baseNames, real time, const wordList &fileNames)
{
if(baseNames.size()!= fileNames.size() )
{
fatalErrorInFunction<<"sizes of base names and file names are not equal\n";
return false;
}
for(size_t i=0; i<baseNames.size(); i++)
{
if(!addTimeFile(baseNames[i], time, fileNames[i]))
{
fatalErrorInFunction<<"Error in adding multiple time files\n";
return false;
}
}
return true;
}
pFlow::List< word >
pFlow::PFtoVTK::fileSeries::writeOneBaseName
void writeOneBaseName(const word &baseName)
Definition: fileSeries.cpp:5
pFlow::real
float real
Definition: builtinTypes.hpp:45
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::PFtoVTK::fileSeries::destDir_
fileSystem destDir_
Definition: fileSeries.hpp:22
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
fileSeries.hpp
oFstream.hpp
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::baseName
word baseName(const word &w, char sep='.')
Find the base in a group separated by "." and return it.
Definition: bTypesFunctions.cpp:185
pFlow::Ostream::name
virtual const word & name() const
Return the name of the stream.
Definition: Ostream.hpp:71
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::Map::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: MapI.hpp:23
pFlow::PFtoVTK::fileSeries::fileSeries
fileSeries(const fileSystem dest)
Definition: fileSeries.cpp:33
pFlow::PFtoVTK::fileSeries::timeFiles_
Map< word, TimeFileType > timeFiles_
Definition: fileSeries.hpp:20
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
streams.hpp
pFlow::oFstream
Output file stream to send binary or ascii data to a file.
Definition: oFstream.hpp:38
pFlow::PFtoVTK::fileSeries::~fileSeries
~fileSeries()
Definition: fileSeries.cpp:40
pFlow::List::size
size_t size() const
Definition: ListI.hpp:82
pFlow::PFtoVTK::fileSeries::addTimeFile
bool addTimeFile(const word &baseName, real time, const word &fileName)
Definition: fileSeries.cpp:49
pFlow::Map
Definition: Map.hpp:36
pFlow::fileSystem::relative
fileSystem relative(const fileSystem &base) const
relative path of this this with respect to base
Definition: fileSystem.cpp:170
pFlow::fileSystem::wordPath
word wordPath() const
Path in word type.
Definition: fileSystem.hpp:160