www.cemf.ir
InsertionRegion.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 template<typename ShapeType>
23 (
24  const realx3Vector& pos,
25  const realVector& diams,
26  const realx3& p,
27  const real& d
28 )
29 {
30 
31  ForAll(i, pos)
32  {
33  if( length(pos[i]-p) < 0.5*(diams[i]+d) ) return true;
34  }
35 
36  return false;
37 }
38 
39 template<typename ShapeType>
41 (
42  const word& name,
43  const insertion& instn,
44  const ShapeType& shapes
45 )
46 :
47  insertionRegion(name, instn),
48  shapes_(shapes)
49 {}
50 
51 
52 template<typename ShapeType>
54 (
55  uint32 iter,
56  real t,
57  real dt,
58  wordVector& names,
59  realx3Vector& positions,
60  bool& insertionOccured
61 )
62 {
63  insertionOccured = false;
64 
65  if(!insertionTime(iter, t, dt)) return true;
66 
67  uint32 newNum = numberToBeInserted(iter, t, dt);
68  if(newNum == 0) return true;
69 
70  // get the internal box
71  auto internalBox = pStruct().internalDomainBox();
72  if( !(internalBox.minPoint() < internalBox.maxPoint()))
73  {
74  WARNING<<"Minimum point of internal point is not lower than "<<
75  "the maximum point \n"<<
76  "minimum point: "<< internalBox.minPoint()<<
77  "\nmaximum point:"<<internalBox.maxPoint()<<END_WARNING;
78 
79  return false;
80  }
81 
82 
83 
85  names.reserve(max(newNum,names.capacity()));
86  names.clear();
87 
88  positions.reserve(max(newNum,positions.capacity()));
89  positions.clear();
90 
91  auto allPositions = realx3Vector("allPositions");
92  auto allDiameters = realVector("allDiameters");
93 
94  auto& mix = mixture();
95  auto& pReg = pRegion();
96 
97  real maxDiam = shapes_.maxBoundingSphere();
98  auto minP = pReg.minPoint() - maxDiam;
99  auto maxP = pReg.maxPoint() + maxDiam;
100 
101  if(Insertion().checkForCollision())
102  {
103  // check for collision with already inserted particles
104  // so, use selector to select particles in the simulation
105  auto bDict = dictionary("boxInfo");
106  bDict.add("min", minP);
107  bDict.add("max", maxP);
108 
109  auto selector = pStructSelector::create(
110  "box",
111  pStruct(),
112  bDict);
113 
114  allPositions = selector().selectedPointPositions();
115  allDiameters = selectedFieldVals<real>
116  (
117  selector(),
118  Insertion().diameterName()
119  );
120  }
121 
122  auto collCheck = collisionCheck(
123  {minP, maxP},
124  maxDiam,
125  allPositions,
126  allDiameters);
127 
128  uint32 numInserted = 0;
129 
130  uint32 idx;
131  word name = mix.getNextShapeName();
132  shapes_.shapeNameToIndex(name, idx);
133  real d = shapes_.boundingDiameter(idx);
134 
135  for(uint32 i=0; i< 100*newNum ; ++i)
136  {
137  realx3 p = pReg.peek();
138  // check if point is inside internal box
139  if(!internalBox.isInside(p))continue;
140 
141  if( collCheck.checkPoint( p, d) )
142  {
143  names.push_back(name);
144  positions.push_back(p);
145  numInserted++;
146  if( numInserted == newNum ) break;
147 
148  // add this new particle to collision check set
149  allDiameters.push_back(d);
150  allPositions.push_back(p);
151  collCheck.mapLastAddedParticle();
152 
153  // obtain next shape name and diameter
154  name = mix.getNextShapeName();
155  shapes_.shapeNameToIndex(name, idx);
156  d = shapes_.boundingDiameter(idx);
157  }
158 
159  }
160 
161  insertionOccured = true;
162  addToNumInserted(numInserted);
163  return numInserted == newNum;
164 }
165 
166 
167 
168 /*if(!checkForCollision)
169  {
170  realVector diams("diams", newNum, 0, RESERVE());
171 
172  uint32 idx;
173  word name = mix.getNextShapeName();
174  shapes_.shapeNameToIndex(name, idx);
175  real d = shapes_.boundingDiameter(idx);
176 
177  for(uint32 i=0; i< 100*newNum ; ++i)
178  {
179  realx3 p = pReg.peek();
180  // check if point is inside internal box
181  if(!internalBox.isInside(p))continue;
182 
183  if( !checkForContact(positions, diams, p, d) )
184  {
185  names.push_back(name);
186  positions.push_back(p);
187  diams.push_back(d);
188  numInserted++;
189 
190  if( numInserted == newNum ) break;
191 
192  name = mix.getNextShapeName();
193  shapes_.shapeNameToIndex(name, idx);
194  d = shapes_.boundingDiameter(idx);
195  }
196  }
197  }
198  else
199  {
200  real maxDiam = shapes_.maxBoundingSphere();
201  auto minP = pReg.minPoint() - maxDiam;
202  auto maxP = pReg.maxPoint() + maxDiam;
203  auto bDict = dictionary("boxInfo");
204  bDict.add("min", minP);
205  bDict.add("max", maxP);
206  auto selector = pStructSelector::create(
207  "box",
208  pStruct(),
209  bDict);
210 
211  auto allPositions = selector().selectedPointPositions();
212  auto allDiameters = selectedFieldVals<real>(selector(), "diameter");
213  auto collCheck = collisionCheck(
214  {minP, maxP},
215  maxDiam,
216  allPositions,
217  allDiameters);
218 
219  uint32 idx;
220  word name = mix.getNextShapeName();
221  shapes_.shapeNameToIndex(name, idx);
222  real d = shapes_.boundingDiameter(idx);
223 
224  for(uint32 i=0; i< 100*newNum ; ++i)
225  {
226  realx3 p = pReg.peek();
227  // check if point is inside internal box
228  if(!internalBox.isInside(p))continue;
229 
230  if( collCheck.checkPoint( p, d) )
231  {
232  names.push_back(name);
233  positions.push_back(p);
234  numInserted++;
235  if( numInserted == newNum ) break;
236 
237  // add this new particle to collision check set
238  allDiameters.push_back(d);
239  allPositions.push_back(p);
240  collCheck.mapLastAddedParticle();
241 
242  // obtain next shape name and diameter
243  name = mix.getNextShapeName();
244  shapes_.shapeNameToIndex(name, idx);
245  d = shapes_.boundingDiameter(idx);
246  }
247 
248  }
249  }*/
pFlow::realVector
Vector< real > realVector
Definition: Vectors.hpp:46
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::collisionCheck
Definition: collisionCheck.hpp:13
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, uint32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::Vector::reserve
void reserve(size_t cap)
Reserve capacity for vector Preserve the content.
Definition: Vector.hpp:284
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::InsertionRegion::checkForContact
static bool checkForContact(const realx3Vector &pos, const realVector &diams, const realx3 &p, const real &d)
Definition: InsertionRegion.cpp:23
pFlow::insertionRegion
This class defines all the necessary enteties for defining an insertion region.
Definition: insertionRegion.hpp:86
END_WARNING
#define END_WARNING
Definition: streams.hpp:44
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::Vector::capacity
auto capacity() const
Capacity of the vector.
Definition: Vector.hpp:271
pFlow::InsertionRegion::InsertionRegion
InsertionRegion(const word &name, const insertion &instn, const ShapeType &shapes)
Construct from dictionary.
Definition: InsertionRegion.cpp:41
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::realx3Vector
Vector< realx3 > realx3Vector
Definition: Vectors.hpp:48
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::InsertionRegion::insertParticles
bool insertParticles(uint32 iter, real t, real dt, wordVector &names, realx3Vector &pos, bool &insertionOccured)
Insert particles at current time t Check if currentTime is the right moment for particle insertion.
Definition: InsertionRegion.cpp:54
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::Insertion
This class manages all the insertion regions for particles insertion in the simulation.
Definition: Insertion.hpp:56
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
pFlow::insertion
Base class for particle insertion.
Definition: insertion.hpp:35
WARNING
#define WARNING
Definition: streams.hpp:43