# PhasicFlow: src/phasicFlow/ranges/stridedRange.hpp 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.

stridedRange.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 __stridedRange_hpp__
#define __stridedRange_hpp__
#include "types.hpp"
#include "typeInfo.hpp"
#include "dictionary.hpp"
#include "streams.hpp"
namespace pFlow
{
template<typename T>
class
stridedRange
{
protected:
T begin_ = 0;
T end_ = 1;
T stride_ = 1;
static inline const T maxVal = largestPositive<T>();
static inline const T minVal = largestNegative<T>();
public:
TypeInfoTemplateNV11("stridedRange",T);
stridedRange()=default;
stridedRange(T begin, T end, T stride)
:
begin_(begin),
end_(end),
stride_(stride)
{}
stridedRange(T begin, T stride)
:
begin_(begin),
end_(maxVal),
stride_(stride)
{}
// it should be in the form of begin:stride:end
stridedRange(const word& rangeString)
{
if(!parseRange(rangeString,begin_,end_, stride_))
{
fatalErrorInFunction<<
"bad input for the range. It should have the form of begin:stride:end \n";
fatalExit;
}
}
stridedRange(const dictionary& dict)
:
begin_(dict.getVal<T>("begin")),
end_(dict.getVal<T>("end")),
stride_(dict.getVal<T>("stride"))
{}
inline
T begin()const
{
return begin_;
}
T end()const
{
return end_;
}
T stride()const
{
return stride_;
}
inline
bool isInRange(T val)const
{
return val>= begin_ && val<= end_;
}
inline
bool isMember(T val, T epsilon = 0)const
{
if(!isInRange(val)) return false;
if(T dist = val-begin_; abs(dist%stride_)<= epsilon) return true;
if(equal(val,begin_))return true;
if(equal(val,end_))return true;
return false;
}
static
bool parseRange(const word& rangeString, T& begin, T& end, T& stride)
{
if(std::count(
rangeString.begin(),
rangeString.end(),
':') != 2)
return false;
auto col1 = rangeString.find_first_of(":");
if(col1 == 0 || col1==std::string::npos)return false;
auto beginCh = rangeString.substr(0,col1);
auto col2 = rangeString.find_first_of(":",col1+1);
if(col1 == col2 || col2==std::string::npos)return false;
auto strideCh = rangeString.substr(col1+1,col2-col1-1);
auto endCh = rangeString.substr(col2+1);
if(!readValue(beginCh,begin))return false;
if(!readValue(strideCh, stride))return false;
if(!readValue(endCh, end))return false;
return true;
}
};
template<>
inline
bool stridedRange<real>::isMember(real val, real epsilon)const
{
if(!isInRange(val)) return false;
real dist = val-begin_;
if(abs(
(dist-(static_cast< uint64 >((dist+0.01*epsilon)/stride_)*stride_))
)<= epsilon) return true;
if(equal(val,begin_))return true;
if(equal(val,end_))return true;
return false;
}
}
#endif //__stridedRange_hpp__
count
auto count(const Vector< T, Allocator > &vec, const T &val)
pFlow::readValue
bool readValue(const word &w, real &val)
Definition: bTypesFunctions.hpp:191
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::stridedRange::stridedRange
stridedRange(T begin, T end, T stride)
Definition: stridedRange.hpp:54
types.hpp
pFlow::stridedRange::begin
T begin() const
Definition: stridedRange.hpp:88
pFlow::equal
INLINE_FUNCTION_HD bool equal(const box &b1, const box &b2, real tol=smallValue)
Definition: box.hpp:135
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::stridedRange
Definition: stridedRange.hpp:34
pFlow::stridedRange::stridedRange
stridedRange(T begin, T stride)
Definition: stridedRange.hpp:61
pFlow
Definition: demGeometry.hpp:27
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::stridedRange::isInRange
bool isInRange(T val) const
Definition: stridedRange.hpp:104
dictionary.hpp
pFlow::stridedRange::end
T end() const
Definition: stridedRange.hpp:93
pFlow::abs
Vector< T, Allocator > abs(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:84
pFlow::stridedRange::stride
T stride() const
Definition: stridedRange.hpp:98
streams.hpp
pFlow::stridedRange::stridedRange
stridedRange(const dictionary &dict)
Definition: stridedRange.hpp:80
TypeInfoTemplateNV11
#define TypeInfoTemplateNV11(tName, Type)
Definition: typeInfo.hpp:242
pFlow::stridedRange::isMember
bool isMember(T val, T epsilon=0) const
Definition: stridedRange.hpp:110
pFlow::uint64
unsigned long long int uint64
Definition: builtinTypes.hpp:58
typeInfo.hpp
pFlow::stridedRange::stridedRange
stridedRange(const word &rangeString)
Definition: stridedRange.hpp:70
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67
pFlow::stridedRange::parseRange
static bool parseRange(const word &rangeString, T &begin, T &end, T &stride)
Definition: stridedRange.hpp:121