# PhasicFlow: src/phasicFlow/repository/systemControl/timeFolder.hpp Source File

timeFolder.hpp
Go to the documentation of this file.
/*------------------------------- 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 __timeFolder_hpp__
#define __timeFolder_hpp__
#include "systemControl.hpp"
namespace pFlow
{
Map<real, fileSystem> getTimeFolders(const fileSystem& path);
class timeFolder
{
using timeList = Map<real, fileSystem>;
protected:
timeList folders_;
timeList::iterator currentFolder_;
public:
timeFolder(const systemControl& control )
:
timeFolder(control.path())
{}
timeFolder(const fileSystem& path)
:
folders_(getTimeFolders(path)),
currentFolder_(folders_.begin())
{
}
real time()const
{
return currentFolder_->first;
}
fileSystem folder()const
{
return currentFolder_->second;
}
word timeName()const
{
auto tName = tailName(folder().wordPath(), '/');
return tName;
}
fileSystem localFolder()const
{
return fileSystem(timeName());
}
bool operator ++(int)
{
if(!finished()) currentFolder_++;
return !finished();
}
explicit operator bool()const
{
return !finished();
}
bool operator !()const
{
return finished();
}
void rewind()
{
currentFolder_ = folders_.begin();
}
bool finished()const
{
if(currentFolder_ == folders_.end()) return true;
return false;
}
real startTime()const
{
auto [t,f] = *folders_.begin();
return t;
}
real endTime()const
{
auto [t,f] = *(--folders_.end());
return t;
}
};
inline
Map<real, fileSystem> getTimeFolders(const fileSystem& path)
{
Map<real, fileSystem> tFolders;
auto subDirs = subDirectories(path);
for(auto& subD: subDirs)
{
auto timeName = tailName(subD.wordPath(), '/');
real TIME;
if( auto success = readReal(timeName, TIME); success)
{
if(!tFolders.insertIf(TIME, subD))
{
fatalErrorInFunction<<
" duplicate time folder! time = " << TIME <<endl;
fatalExit;
}
}
}
return tFolders;
}
} // pFlow
#endif // __Control_hpp__
pFlow::tailName
word tailName(const word &w, char sep='.')
Definition: bTypesFunctions.cpp:168
pFlow::timeFolder::timeFolder
timeFolder(const systemControl &control)
Definition: timeFolder.hpp:44
pFlow::timeFolder::time
real time() const
Definition: timeFolder.hpp:57
pFlow::Map< real, fileSystem >::iterator
typename mapType::iterator iterator
Definition: Map.hpp:46
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::timeFolder::operator!
bool operator!() const
Definition: timeFolder.hpp:89
pFlow::timeFolder::finished
bool finished() const
Definition: timeFolder.hpp:99
pFlow::timeFolder::folders_
timeList folders_
Definition: timeFolder.hpp:37
systemControl.hpp
pFlow::timeFolder::rewind
void rewind()
Definition: timeFolder.hpp:94
pFlow::readReal
bool readReal(const word &w, real &val)
Definition: bTypesFunctions.cpp:335
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::timeFolder::timeName
word timeName() const
Definition: timeFolder.hpp:67
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow
Definition: demComponent.hpp:28
pFlow::timeFolder::startTime
real startTime() const
Definition: timeFolder.hpp:105
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::subDirectories
fileSystemList subDirectories(const fileSystem &path)
Definition: fileSystem.cpp:313
pFlow::timeFolder::timeFolder
timeFolder(const fileSystem &path)
Definition: timeFolder.hpp:49
pFlow::timeFolder::localFolder
fileSystem localFolder() const
Definition: timeFolder.hpp:73
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::Map::insertIf
bool insertIf(const keyType &k, const mappedType &v)
Definition: MapI.hpp:23
pFlow::timeFolder::currentFolder_
timeList::iterator currentFolder_
Definition: timeFolder.hpp:39
pFlow::getTimeFolders
Map< real, fileSystem > getTimeFolders(const fileSystem &path)
Definition: timeFolder.hpp:119
pFlow::Map< real, fileSystem >
pFlow::timeFolder::endTime
real endTime() const
Definition: timeFolder.hpp:111
pFlow::timeFolder::operator++
bool operator++(int)
Definition: timeFolder.hpp:78
pFlow::timeFolder::folder
fileSystem folder() const
Definition: timeFolder.hpp:62
pFlow::timeFolder
Definition: timeFolder.hpp:32