combinedRange.hpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #ifndef __combinedRange_hpp__
22 #define __combinedRange_hpp__
23 
24 #include <vector>
25 
26 #include "stridedRange.hpp"
27 #include "intervalRange.hpp"
28 #include "Lists.hpp"
29 
30 #include "Set.hpp"
31 
32 namespace pFlow
33 {
34 
35 template<typename T>
37 {
38 public:
39 
41 
43 
44 protected:
45 
47 
49 
51 
52 public:
53 
55 
56  combinedRange(const std::vector<word>& strRanges)
57  {
58  if(!addRanges(strRanges))
59  {
60  fatalExit;
61  }
62  }
63 
64  bool addRanges(const std::vector<word>& strRanges)
65  {
66  for(auto& sR: strRanges)
67  {
68  if( !(addStridedRange(sR) ||
69  addIntervalRange(sR)||
70  addIndividual(sR)) )
71  {
73  "bad systax for range defintion "<< sR<<endl;
74  return false;
75  }
76  }
77  return true;
78  }
79 
80  bool addStridedRange(const word& strRange)
81  {
82  T begin, end, stride;
83  if(StridedRangeType::parseRange(strRange, begin, end, stride))
84  {
85  sRanges_.emplace_back(begin, end, stride);
86  return true;
87  }
88  return false;
89  }
90 
91  bool addStridedRange(T begin, T end, T stride)
92  {
93  sRanges_.emplace_back(begin, end, stride);
94  return true;
95  }
96 
97  bool addIntervalRange(const word& strRange)
98  {
99  T begin, end;
100  if( IntervalRangeType::parseRange(strRange, begin, end) )
101  {
102  iRanges_.emplace_back(begin,end);
103  return true;
104  }
105 
106  return false;
107  }
108 
109  bool addIntervalRange(T begin, T end)
110  {
111  iRanges_.emplace_back(begin,end);
112  return true;
113  }
114 
115  bool addIndividual(const T& val)
116  {
117  individuals_.insert(val);
118  return true;
119  }
120 
121  bool addIndividual(const word& strVal)
122  {
123  T val;
124  if(readValue(strVal , val))
125  {
126  return addIndividual(val);
127  }
128  return false;
129  }
130 
131  bool isMember(T val)const
132  {
133  for(auto& sR:sRanges_)
134  {
135  if(sR.isMember(val))return true;
136  }
137 
138  for(auto& iR:iRanges_)
139  {
140  if(iR.isMember(val)) return true;
141  }
142 
143  if( individuals_.count(val) ) return true;
144 
145  return false;
146  }
147 };
148 
149 }
150 
151 
152 #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