# PhasicFlow: src/phasicFlow/ranges/combinedRange.hpp Source File

combinedRange.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 __combinedRange_hpp__
#define __combinedRange_hpp__
#include <vector>
#include "stridedRange.hpp"
#include "intervalRange.hpp"
#include "Lists.hpp"
#include "Set.hpp"
namespace pFlow
{
template<typename T>
class combinedRange
{
public:
using StridedRangeType = stridedRange<T>;
using IntervalRangeType = intervalRange<T>;
protected:
List<StridedRangeType> sRanges_;
List<IntervalRangeType> iRanges_;
Set<T> individuals_;
public:
combinedRange(){}
combinedRange(const std::vector<word>& strRanges)
{
if(!addRanges(strRanges))
{
fatalExit;
}
}
bool addRanges(const std::vector<word>& strRanges)
{
for(auto& sR: strRanges)
{
if( !(addStridedRange(sR) ||
addIntervalRange(sR)||
addIndividual(sR)) )
{
fatalErrorInFunction<<
"bad systax for range defintion "<< sR<<endl;
return false;
}
}
return true;
}
bool addStridedRange(const word& strRange)
{
T begin, end, stride;
if(StridedRangeType::parseRange(strRange, begin, end, stride))
{
sRanges_.emplace_back(begin, end, stride);
return true;
}
return false;
}
bool addStridedRange(T begin, T end, T stride)
{
sRanges_.emplace_back(begin, end, stride);
return true;
}
bool addIntervalRange(const word& strRange)
{
T begin, end;
if( IntervalRangeType::parseRange(strRange, begin, end) )
{
iRanges_.emplace_back(begin,end);
return true;
}
return false;
}
bool addIntervalRange(T begin, T end)
{
iRanges_.emplace_back(begin,end);
return true;
}
bool addIndividual(const T& val)
{
individuals_.insert(val);
return true;
}
bool addIndividual(const word& strVal)
{
T val;
if(readValue(strVal , val))
{
return addIndividual(val);
}
return false;
}
bool isMember(T val)const
{
for(auto& sR:sRanges_)
{
if(sR.isMember(val))return true;
}
for(auto& iR:iRanges_)
{
if(iR.isMember(val)) return true;
}
if( individuals_.count(val) ) return true;
return false;
}
};
}
#endif //__combinedRange_hpp__
pFlow::intervalRange::parseRange
static bool parseRange(const word &rangeString, T &begin, T &end)
Definition: intervalRange.hpp:80
pFlow::combinedRange::individuals_
Set< T > individuals_
Definition: combinedRange.hpp:50
pFlow::List
Definition: List.hpp:39
pFlow::readValue
bool readValue(const word &w, real &val)
Definition: bTypesFunctions.hpp:140
Lists.hpp
fatalExit
#define fatalExit
Definition: error.hpp:57
Set.hpp
pFlow::combinedRange::addStridedRange
bool addStridedRange(const word &strRange)
Definition: combinedRange.hpp:80
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::Set
std::set< Key, std::less< Key >, std::allocator< Key > > Set
Definition: Set.hpp:31
pFlow::stridedRange
Definition: stridedRange.hpp:33
pFlow::combinedRange::addIndividual
bool addIndividual(const word &strVal)
Definition: combinedRange.hpp:121
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::combinedRange::combinedRange
combinedRange(const std::vector< word > &strRanges)
Definition: combinedRange.hpp:56
pFlow
Definition: demComponent.hpp:28
pFlow::combinedRange::combinedRange
combinedRange()
Definition: combinedRange.hpp:54
pFlow::combinedRange
Definition: combinedRange.hpp:36
pFlow::combinedRange::addIntervalRange
bool addIntervalRange(const word &strRange)
Definition: combinedRange.hpp:97
stridedRange.hpp
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::combinedRange::addRanges
bool addRanges(const std::vector< word > &strRanges)
Definition: combinedRange.hpp:64
pFlow::combinedRange::addIndividual
bool addIndividual(const T &val)
Definition: combinedRange.hpp:115
pFlow::combinedRange::isMember
bool isMember(T val) const
Definition: combinedRange.hpp:131
pFlow::combinedRange::sRanges_
List< StridedRangeType > sRanges_
Definition: combinedRange.hpp:46
pFlow::intervalRange
Definition: intervalRange.hpp:33
pFlow::combinedRange::iRanges_
List< IntervalRangeType > iRanges_
Definition: combinedRange.hpp:48
pFlow::combinedRange::addIntervalRange
bool addIntervalRange(T begin, T end)
Definition: combinedRange.hpp:109
pFlow::combinedRange::addStridedRange
bool addStridedRange(T begin, T end, T stride)
Definition: combinedRange.hpp:91
intervalRange.hpp
pFlow::stridedRange::parseRange
static bool parseRange(const word &rangeString, T &begin, T &end, T &stride)
Definition: stridedRange.hpp:109