positionOrdered.cpp
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 #include "positionOrdered.hpp"
22 #include "error.hpp"
23 
24 
25 #include "streams.hpp"
26 
27 
29 {
30  if( axisOrder_.size() != 3 )
31  {
33  "axisOrder should have 3 components, but " << axisOrder_.size() <<
34  " has been provided. \n";
35  return false;
36  }
37 
38 
39  if( axisOrder_[0] == axisOrder_[1] ||
40  axisOrder_[0] == axisOrder_[2] ||
41  axisOrder_[1] == axisOrder_[2] )
42  {
44  "invalid/repeated axis names in axisOrder. This is provided: " << axisOrder_ <<endl;
45  return false;
46  }
47 
48  realx3 uV[3];
49  size_t i=0;
50  for(auto& ca: axisOrder_)
51  {
52  if(ca == "x")
53  {
54  uV[i] = realx3(1.0, 0.0, 0.0);
55  }
56  else if(ca == "y")
57  {
58  uV[i] = realx3(0.0, 1.0, 0.0);
59  }
60  else if(ca == "z")
61  {
62  uV[i] = realx3(0.0, 0.0, 1.0);
63  }
64  else
65  {
67  "unknown name for axis in axisOrder: " << ca <<endl;
68  return false;
69  }
70  i++;
71  }
72 
73  uVector1_ = uV[0];
74  uVector2_ = uV[1];
75  uVector3_ = uV[2];
76 
77  return true;
78 }
79 
81 {
82  position_.clear();
83 
84  realx3 dl(diameter_);
85  auto minP = region_->minPoint();
86  auto maxP = region_->maxPoint();
87 
88  auto cntr = minP;
89 
90  size_t n = 0;
91  while( n < numPoints_ )
92  {
93  if(region_->isInside(cntr))
94  {
95  position_.push_back(cntr);
96  n++;
97  }
98 
99  cntr += dl*uVector1_;
100 
101  if( dot(uVector1_, cntr) > dot(uVector1_, maxP) )
102  {
103  cntr = (minP*uVector1_) + ( (cntr+dl) * uVector2_) + (cntr*uVector3_);
104 
105  if( dot(uVector2_, cntr) > dot(uVector2_, maxP) )
106  {
107  cntr = (cntr*uVector1_) + (minP*uVector2_) + ((cntr+dl)*uVector3_);
108 
109  if( dot(uVector3_,cntr) > dot(uVector3_, maxP) )
110  {
112  "positioned " << n << " points in the domain and it is full. \n" <<
113  "request to position "<< numPoints_<< " points has failed.\n";
114  return false;
115  }
116  }
117  }
118 
119  }
120 
121  return true;
122 }
123 
125 (
126  const dictionary& dict
127 )
128 :
129  positionParticles(dict),
130  poDict_
131  (
132  dict.subDict("positionOrderedInfo")
133  ),
134  diameter_
135  (
136  poDict_.getVal<real>("diameter")
137  ),
138  numPoints_
139  (
140  poDict_.getVal<size_t>("numPoints")
141  ),
142  axisOrder_
143  (
144  poDict_.getValOrSet("axisOrder", wordList{"x", "y", "z"})
145  ),
146  position_
147  (
148  maxNumberOfParticles_, RESERVE()
149  )
150 {
151 
152  if( !findAxisIndex() )
153  {
154  fatalExit;
155  }
156 
157  if(!region_)
158  {
159  fatalErrorInFunction<<"You must provided a region (box, cylinder, ...) for positioning particles in dictionary "<<
160  dict.globalName()<<endl;
161  fatalExit;
162  }
163 
164  if(!positionPointsOrdered())
165  {
166  fatalExit;
167  }
168 }
pFlow::positionOrdered::axisOrder_
wordList axisOrder_
Definition: positionOrdered.hpp:42
pFlow::List< word >
pFlow::positionOrdered::positionOrdered
positionOrdered(const dictionary &dict)
Definition: positionOrdered.cpp:125
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::positionOrdered::findAxisIndex
bool findAxisIndex()
Definition: positionOrdered.cpp:28
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::positionOrdered::positionPointsOrdered
bool positionPointsOrdered()
Definition: positionOrdered.cpp:80
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::realx3
triple< real > realx3
Definition: types.hpp:48
pFlow::positionOrdered::uVector1_
realx3 uVector1_
Definition: positionOrdered.hpp:45
RESERVE
Definition: Vector.hpp:38
dot
INLINE_FUNCTION_HD T dot(const quadruple< T > &oprnd1, const quadruple< T > &oprnd2)
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::positionOrdered::uVector2_
realx3 uVector2_
Definition: positionOrdered.hpp:48
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
Definition: dictionary.cpp:547
streams.hpp
positionOrdered.hpp
pFlow::positionParticles
Definition: positionParticles.hpp:102
pFlow::List::size
size_t size() const
Definition: ListI.hpp:66
pFlow::positionOrdered::uVector3_
realx3 uVector3_
Definition: positionOrdered.hpp:51
pFlow::triple< real >
pFlow::dictionary
Definition: dictionary.hpp:38
error.hpp