www.cemf.ir
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 class cells
32 {
33 private:
34 
35  // - domain
36  box domainBox_{realx3(0.0), realx3(1.0)};
37 
38  // - cell size
39  real celldx_{1};
40 
41  int32x3 numCells_{1,1,1};
42 
43  // - protected methods
45  void calculate()
46  {
48  numCells_ = max( numCells_ , int32x3(1) );
49  }
50 
51 public:
52 
54  cells() = default;
55 
58  :
61  {
62  calculate();
63  }
64 
66  cells(const cells&) = default;
67 
69  cells& operator = (const cells&) = default;
70 
72  cells(cells &&) = default;
73 
75  cells& operator=(cells&&) = default;
76 
77  cells getCells()const
78  {
79  return *this;
80  }
81 
84  {
85  celldx_ = cellSize;
86  calculate();
87  }
88 
90  real cellSize()const
91  {
92  return celldx_;
93  }
94 
96  const int32x3& numCells()const
97  {
98  return numCells_;
99  }
100 
102  int32 nx()const
103  {
104  return numCells_.x();
105  }
106 
108  int32 ny()const
109  {
110  return numCells_.y();
111  }
112 
114  int32 nz()const
115  {
116  return numCells_.z();
117  }
118 
121  {
122  return static_cast<int64>(numCells_.x())*
123  static_cast<int64>(numCells_.y())*
124  static_cast<int64>(numCells_.z());
125  }
126 
127  const auto& domainBox()const
128  {
129  return domainBox_;
130  }
131 
133  int32x3 pointIndex(const realx3& p)const
134  {
135  return int32x3( (p - domainBox_.minPoint())/celldx_ );
136  }
137 
139  bool pointIndexInDomain(const realx3 p, int32x3& index)const
140  {
141  if(!inDomain(p))return false;
142  index = this->pointIndex(p);
143  return true;
144  }
145 
147  bool inDomain(const realx3& p)const
148  {
149  return domainBox_.isInside(p);
150  }
151 
153  bool inCellRange(const int32x3& cell)const
154  {
155  if(cell.x()<0)return false;
156  if(cell.y()<0)return false;
157  if(cell.z()<0)return false;
158  if(cell.x()>numCells_.x()-1) return false;
159  if(cell.y()>numCells_.y()-1) return false;
160  if(cell.z()>numCells_.z()-1) return false;
161  return true;
162  }
163 
165  bool inCellRange(int32 i, int32 j, int32 k)const
166  {
167  if(i<0)return false;
168  if(j<0)return false;
169  if(k<0)return false;
170  if(i>numCells_.x()-1) return false;
171  if(j>numCells_.y()-1) return false;
172  if(k>numCells_.z()-1) return false;
173  return true;
174  }
175 
176 
178  void extendBox(
179  const realx3& p1,
180  const realx3& p2,
181  const realx3& p3,
182  real extent,
183  realx3& minP,
184  realx3& maxP)const
185  {
186  minP = min(min(p1,p2),p3) - extent*celldx_ ;
187  maxP = max(max(p1,p2),p3) + extent*celldx_ ;
188 
189  minP = bound(minP);
190  maxP = bound(maxP);
191  }
192 
195  {
196  return int32x3(
197  min( numCells_.x()-1, max(0,p.x())),
198  min( numCells_.y()-1, max(0,p.y())),
199  min( numCells_.z()-1, max(0,p.z()))
200  );
201  }
202 
205  {
206  return realx3(
207  min( domainBox_.maxPoint().x(), max(domainBox_.minPoint().x(),p.x())),
208  min( domainBox_.maxPoint().y(), max(domainBox_.minPoint().y(),p.y())),
209  min( domainBox_.maxPoint().z(), max(domainBox_.minPoint().z(),p.z()))
210  );
211  }
212 };
213 
214 
215 }
216 
217 
218 #endif
pFlow::cells::numCells_
int32x3 numCells_
Definition: cells.hpp:41
pFlow::cells::nz
INLINE_FUNCTION_HD int32 nz() const
Definition: cells.hpp:114
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::cells::ny
INLINE_FUNCTION_HD int32 ny() const
Definition: cells.hpp:108
types.hpp
pFlow::cells::operator=
INLINE_FUNCTION_HD cells & operator=(const cells &)=default
pFlow::cells::pointIndexInDomain
INLINE_FUNCTION_HD bool pointIndexInDomain(const realx3 p, int32x3 &index) const
Definition: cells.hpp:139
pFlow::cells::inCellRange
INLINE_FUNCTION_HD bool inCellRange(int32 i, int32 j, int32 k) const
Definition: cells.hpp:165
box.hpp
pFlow::cells::domainBox
const auto & domainBox() const
Definition: cells.hpp:127
pFlow::cells::cells
INLINE_FUNCTION_H cells(const box &domain, real cellSize)
Definition: cells.hpp:57
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::int64
long long int int64
Definition: builtinTypes.hpp:52
pFlow::cells::nx
INLINE_FUNCTION_HD int32 nx() const
Definition: cells.hpp:102
pFlow::cells::cellSize
INLINE_FUNCTION_HD real cellSize() const
Definition: cells.hpp:90
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:178
pFlow::box::maxPoint
const INLINE_FUNCTION_HD realx3 & maxPoint() const
Definition: box.hpp:97
pFlow::realx3
triple< real > realx3
Definition: types.hpp:43
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
access component
Definition: triple.hpp:144
pFlow
Definition: demGeometry.hpp:27
pFlow::cells::calculate
INLINE_FUNCTION_H void calculate()
Definition: cells.hpp:45
pFlow::cells::inCellRange
INLINE_FUNCTION_HD bool inCellRange(const int32x3 &cell) const
Definition: cells.hpp:153
pFlow::int32
int int32
Definition: builtinTypes.hpp:50
pFlow::cells::numCells
const INLINE_FUNCTION_HD int32x3 & numCells() const
Definition: cells.hpp:96
pFlow::cells::celldx_
real celldx_
Definition: cells.hpp:39
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::int32x3
triple< int32 > int32x3
Definition: types.hpp:38
pFlow::cells::inDomain
INLINE_FUNCTION_HD bool inDomain(const realx3 &p) const
Definition: cells.hpp:147
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
access component
Definition: triple.hpp:156
pFlow::cells::pointIndex
INLINE_FUNCTION_HD int32x3 pointIndex(const realx3 &p) const
Definition: cells.hpp:133
pFlow::box::minPoint
const INLINE_FUNCTION_HD realx3 & minPoint() const
Definition: box.hpp:91
pFlow::box
Definition: box.hpp:32
pFlow::cells::bound
INLINE_FUNCTION_HD int32x3 bound(int32x3 p) const
Definition: cells.hpp:194
pFlow::cells::cells
INLINE_FUNCTION_HD cells()=default
pFlow::cells::bound
INLINE_FUNCTION_HD realx3 bound(realx3 p) const
Definition: cells.hpp:204
pFlow::domain
Definition: domain.hpp:31
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
access component
Definition: triple.hpp:132
pFlow::cells
Definition: cells.hpp:31
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple< int32 >
pFlow::cells::setCellSize
INLINE_FUNCTION_H void setCellSize(real cellSize)
Definition: cells.hpp:83
pFlow::box::isInside
INLINE_FUNCTION_HD bool isInside(const realx3 &point) const
Definition: box.hpp:84
pFlow::cells::totalCells
INLINE_FUNCTION_HD int64 totalCells() const
Definition: cells.hpp:120
pFlow::cells::domainBox_
box domainBox_
Definition: cells.hpp:36
pFlow::cells::getCells
cells getCells() const
Definition: cells.hpp:77