cells.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 __cells_hpp__
22 #define __cells_hpp__
23 
24 
25 #include "types.hpp"
26 #include "box.hpp"
27 
28 namespace pFlow
29 {
30 
31 template<typename indexType>
32 class cells
33 {
34 public:
35 
37 
38 protected:
39 
40  // - domain
41  box domain_{realx3(0.0), realx3(1.0)};
42 
43  // - cell size
44  realx3 cellSize_{1,1,1};
45 
47 
48 
49  // - protected methods
51  void calculate()
52  {
54  numCells_ = max( numCells_ , CellType(static_cast<indexType>(1)) );
55  }
56 
57 public:
58 
61  {}
62 
65  :
66  domain_(domain),
68  {
69  calculate();
70  }
71 
72 
75  :
76  domain_(domain),
77  cellSize_(
78  (domain_.maxPoint() - domain_.minPoint())/realx3(nx, ny, nz)
79  ),
80  numCells_(nx, ny, nz)
81  {}
82 
84  cells(const cells&) = default;
85 
87  cells& operator = (const cells&) = default;
88 
90  cells(cells &&) = default;
91 
93  cells& operator=(cells&&) = default;
94 
95  cells getCells()const
96  {
97  return *this;
98  }
99 
102  {
104  calculate();
105  }
106 
109  {
111  calculate();
112  }
113 
116  {
117  return cellSize_;
118  }
119 
121  const CellType& numCells()const
122  {
123  return numCells_;
124  }
125 
127  indexType nx()const
128  {
129  return numCells_.x();
130  }
131 
133  indexType ny()const
134  {
135  return numCells_.y();
136  }
137 
139  indexType nz()const
140  {
141  return numCells_.z();
142  }
143 
146  {
147  return static_cast<int64>(numCells_.x())*
148  static_cast<int64>(numCells_.y())*
149  static_cast<int64>(numCells_.z());
150  }
151 
152  const auto& domain()const
153  {
154  return domain_;
155  }
156 
158  CellType pointIndex(const realx3& p)const
159  {
160  return CellType( (p - domain_.minPoint())/cellSize_ );
161  }
162 
164  bool pointIndexInDomain(const realx3 p, CellType& index)const
165  {
166  if( !domain_.isInside(p) ) return false;
167 
168  index = this->pointIndex(p);
169  return true;
170  }
171 
173  bool inDomain(const realx3& p)const
174  {
175  return domain_.isInside(p);
176  }
177 
179  bool isInRange(const CellType& cell)const
180  {
181  if(cell.x()<0)return false;
182  if(cell.y()<0)return false;
183  if(cell.z()<0)return false;
184  if(cell.x()>numCells_.x()-1) return false;
185  if(cell.y()>numCells_.y()-1) return false;
186  if(cell.z()>numCells_.z()-1) return false;
187  return true;
188  }
189 
191  bool isInRange(indexType i, indexType j, indexType k)const
192  {
193  if(i<0)return false;
194  if(j<0)return false;
195  if(k<0)return false;
196  if(i>numCells_.x()-1) return false;
197  if(j>numCells_.y()-1) return false;
198  if(k>numCells_.z()-1) return false;
199  return true;
200  }
201 
203  void extendBox(
204  const CellType& p1,
205  const CellType& p2,
206  const CellType& p3,
207  indexType extent,
208  CellType& minP,
209  CellType& maxP)const
210  {
211  minP = min( min( p1, p2), p3)-extent;
212  maxP = max( max( p1, p2), p3)+extent;
213 
214  minP = bound(minP);
215  maxP = bound(maxP);
216  }
217 
219  void extendBox(
220  const realx3& p1,
221  const realx3& p2,
222  const realx3& p3,
223  real extent,
224  realx3& minP,
225  realx3& maxP)const
226  {
227  minP = min(min(p1,p2),p3) - extent*cellSize_ ;
228  maxP = max(max(p1,p2),p3) + extent*cellSize_ ;
229 
230  minP = bound(minP);
231  maxP = bound(maxP);
232  }
233 
236  {
237  return CellType(
238  min( numCells_.x()-1, max(0,p.x())),
239  min( numCells_.y()-1, max(0,p.y())),
240  min( numCells_.z()-1, max(0,p.z()))
241  );
242  }
243 
246  {
247  return realx3(
248  min( domain_.maxPoint().x(), max(domain_.minPoint().x(),p.x())),
249  min( domain_.maxPoint().y(), max(domain_.minPoint().y(),p.y())),
250  min( domain_.maxPoint().z(), max(domain_.minPoint().z(),p.z()))
251  );
252  }
253 };
254 
255 
256 }
257 
258 
259 #endif
pFlow::cells::setCellSize
INLINE_FUNCTION_H void setCellSize(realx3 cellSize)
Definition: cells.hpp:108
pFlow::cells::nz
INLINE_FUNCTION_HD indexType nz() const
Definition: cells.hpp:139
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::cells::numCells_
CellType numCells_
Definition: cells.hpp:46
pFlow::cells::isInRange
INLINE_FUNCTION_HD bool isInRange(indexType i, indexType j, indexType k) const
Definition: cells.hpp:191
types.hpp
pFlow::cells::operator=
INLINE_FUNCTION_HD cells & operator=(const cells &)=default
box.hpp
pFlow::cells::cells
INLINE_FUNCTION_H cells(const box &domain, real cellSize)
Definition: cells.hpp:64
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:55
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const CellType &p1, const CellType &p2, const CellType &p3, indexType extent, CellType &minP, CellType &maxP) const
Definition: cells.hpp:203
pFlow::cells::nx
INLINE_FUNCTION_HD indexType nx() const
Definition: cells.hpp:127
pFlow::cells::isInRange
INLINE_FUNCTION_HD bool isInRange(const CellType &cell) const
Definition: cells.hpp:179
pFlow::cells::extendBox
INLINE_FUNCTION_HD void extendBox(const realx3 &p1, const realx3 &p2, const realx3 &p3, real extent, realx3 &minP, realx3 &maxP) const
Definition: cells.hpp:219
pFlow::box::maxPoint
INLINE_FUNCTION_HD realx3 maxPoint() const
Definition: box.hpp:94
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::cells::pointIndexInDomain
INLINE_FUNCTION_HD bool pointIndexInDomain(const realx3 p, CellType &index) const
Definition: cells.hpp:164
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow
Definition: demComponent.hpp:28
pFlow::cells::CellType
triple< indexType > CellType
Definition: cells.hpp:36
pFlow::cells::calculate
INLINE_FUNCTION_H void calculate()
Definition: cells.hpp:51
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::cells::domain_
box domain_
Definition: cells.hpp:41
pFlow::cells::bound
INLINE_FUNCTION_HD CellType bound(CellType p) const
Definition: cells.hpp:235
pFlow::cells::domain
const auto & domain() const
Definition: cells.hpp:152
pFlow::cells::cellSize_
realx3 cellSize_
Definition: cells.hpp:44
pFlow::cells::cells
INLINE_FUNCTION_HD cells()
Definition: cells.hpp:60
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::cells::inDomain
INLINE_FUNCTION_HD bool inDomain(const realx3 &p) const
Definition: cells.hpp:173
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::box
Definition: box.hpp:32
pFlow::cells::ny
INLINE_FUNCTION_HD indexType ny() const
Definition: cells.hpp:133
pFlow::cells::bound
INLINE_FUNCTION_HD realx3 bound(realx3 p) const
Definition: cells.hpp:245
pFlow::cells::cellSize
INLINE_FUNCTION_HD realx3 cellSize() const
Definition: cells.hpp:115
pFlow::box::minPoint
INLINE_FUNCTION_HD realx3 minPoint() const
Definition: box.hpp:88
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
pFlow::cells
Definition: cells.hpp:32
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple< int32 >
pFlow::cells::setCellSize
INLINE_FUNCTION_H void setCellSize(real cellSize)
Definition: cells.hpp:101
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
pFlow::box::isInside
INLINE_FUNCTION_HD bool isInside(const realx3 &point) const
Definition: box.hpp:82
pFlow::cells::totalCells
INLINE_FUNCTION_HD int64 totalCells() const
Definition: cells.hpp:145
pFlow::cells::cells
INLINE_FUNCTION_H cells(const box &domain, int32 nx, int32 ny, int32 nz)
Definition: cells.hpp:74
pFlow::cells::numCells
const INLINE_FUNCTION_HD CellType & numCells() const
Definition: cells.hpp:121
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::cells::getCells
cells getCells() const
Definition: cells.hpp:95