www.cemf.ir
positionRandom.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 
22 #include "positionRandom.hpp"
23 #include "collisionCheck.hpp"
24 
25 
26 
28 {
29 
30  auto const& region = pRegion();
31 
32  auto n = static_cast<uint32>(position_.size());
33 
34  for(uint32 iter = 0; iter<numPoints_; iter++)
35  {
36  realx3 p = region.peek();
37 
38  if( collCheck.checkPoint(p, diameter_) )
39  {
40  position_.push_back(p);
41  diameters_.push_back(diameter_);
42 
43  if(!collCheck.mapLastAddedParticle())
44  {
46  return false;
47  }
48  n++;
49 
50  if(n == numPoints_) break;
51  }
52  }
53 
54  return true;
55 }
56 
58 {
59 
60  position_.clear();
61  diameters_.clear();
62  if(numPoints_ == 0)return true;
63 
64  uint32 pass = 0;
65  collisionCheck collCheck(
66  box(pRegion().minPoint(), pRegion().maxPoint()),
67  diameter_,
68  position_,
69  diameters_);
70 
71 
72  while ( pass <maxIterations_)
73  {
74  if( !positionOnePass(collCheck) )
75  {
76  return false;
77  }
78  pass++;
79  REPORT(1)<<"Positioning "<< Green_Text("(Pass #"<< pass<<")")<<
80  ": number of non-colliding spheres is "<<
81  Yellow_Text(position_.size())<<END_REPORT;
82 
83  if( position_.size() == numPoints_ )
84  {
85  REPORT(0)<<END_REPORT;
86  return true;
87  }
88  }
89 
91  " Cannot position "<< numPoints_ << " in the domain in " <<
92  maxIterations_ << " iterations.\n" <<
93  " you may increase maxIterations for positioning points.\n";
94 
95  return false;
96 }
97 
98 
100 (
101  systemControl& control,
102  const dictionary& dict
103 )
104 :
105  positionParticles(control, dict),
106  prDict_
107  (
108  dict.subDict("randomInfo")
109  ),
110  diameter_
111  (
112  prDict_.getVal<real>("diameter")
113  ),
114  numPoints_
115  (
116  prDict_.getVal<uint32>("numPoints")
117  ),
118  maxIterations_
119  (
120  prDict_.getValOrSet("maxIterations", 10u)
121  ),
122  position_
123  (
124  "position",
125  maxNumberOfParticles(),
126  0,
127  RESERVE()
128  ),
129  diameters_
130  (
131  "diameters",
132  maxNumberOfParticles(),
133  0,
134  RESERVE()
135  )
136 {
137 
138  reportInterval_ = max(numPoints_/numReports_, static_cast<uint32>(2));
139 
140  if( !positionPointsRandom() )
141  {
142  fatalExit;
143  }
144 
145 }
146 
147 
Green_Text
#define Green_Text(text)
Definition: iOstream.hpp:42
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
REPORT
#define REPORT(n)
Definition: streams.hpp:39
pFlow::collisionCheck
Definition: collisionCheck.hpp:13
positionRandom.hpp
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::positionRandom::position_
realx3Vector position_
Definition: positionRandom.hpp:43
pFlow::positionRandom::positionOnePass
bool positionOnePass(collisionCheck &collCheck)
Definition: positionRandom.cpp:27
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::positionRandom::positionRandom
positionRandom(systemControl &control, const dictionary &dict)
Definition: positionRandom.cpp:100
Yellow_Text
#define Yellow_Text(text)
Definition: iOstream.hpp:40
pFlow::positionRandom::numPoints_
uint32 numPoints_
Definition: positionRandom.hpp:39
RESERVE
Definition: Vector.hpp:40
pFlow::positionParticles::pRegion
const auto & pRegion() const
Definition: positionParticles.hpp:55
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::positionRandom::positionPointsRandom
bool positionPointsRandom()
Definition: positionRandom.cpp:57
pFlow::collisionCheck::mapLastAddedParticle
bool mapLastAddedParticle()
Definition: collisionCheck.cpp:79
collisionCheck.hpp
pFlow::positionRandom::diameter_
real diameter_
Definition: positionRandom.hpp:37
pFlow::collisionCheck::checkPoint
bool checkPoint(const realx3 &p, const real d) const
Definition: collisionCheck.cpp:46
END_REPORT
#define END_REPORT
Definition: streams.hpp:40
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
ref to a subdictioanry fatalExit if not found
Definition: dictionary.cpp:560
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::box
Definition: box.hpp:32
pFlow::positionRandom::diameters_
realVector diameters_
Definition: positionRandom.hpp:45
pFlow::positionParticles
Definition: positionParticles.hpp:35
pFlow::triple< real >
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