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 dictionary& dict,
43  const ShapeType& shapes
44 )
45 :
46  insertionRegion(dict),
47  shapes_(shapes)
48 {
49 
50 }
51 
52 
53 template<typename ShapeType>
55 (
56  real currentTime,
57  real dt,
58  wordVector& names,
59  realx3Vector& pos,
60  bool& insertionOccured
61 )
62 {
63  insertionOccured = false;
64 
65  if(!insertionTime( currentTime, dt)) return true;
66 
67  size_t newNum = numberToBeInserted(currentTime);
68 
69  if(newNum == 0) return true;
70 
71  names.reserve(max(newNum,names.capacity()));
72  pos.reserve(max(newNum,pos.capacity()));
73  names.clear();
74  pos.clear();
75 
76  realVector diams(newNum, RESERVE());
77 
78  mixture_->getNextShapeNameN(newNum, names);
79 
80  if(!shapes_.shapeToDiameter(names,diams))
81  {
83  " error occured in insertion region "<< name() <<
84  " while converting shapes to diameter. \n";
85  return false;
86  }
87 
88  size_t n = 0;
89 
90  for(label iter=0; iter< 10*newNum ; ++iter)
91  {
92  if( !(n < newNum) )
93  {
94  addToNumInserted(newNum);
95  insertionOccured = true;
96  return true;
97  }
98  realx3 p = pRegion_().peek();
99  real d = diams[pos.size()];
100  if( !checkForContact(pos, diams, p, d) )
101  {
102  pos.push_back(p);
103  n++;
104  }
105 
106  }
107 
109  " Cannot insert "<< newNum << " new particles from region "<< name()<<". \n"
110  " pFlow could position only "<< n<< " particles in this region. \n";
111  addToNumInserted(n);
112  insertionOccured = false;
113  return false;
114 
115 }
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::InsertionRegion::insertParticles
bool insertParticles(real currentTime, real dt, wordVector &names, realx3Vector &pos, bool &insertionOccured)
Definition: InsertionRegion.cpp:55
pFlow::InsertionRegion::checkForContact
static bool checkForContact(const realx3Vector &pos, const realVector &diams, const realx3 &p, const real &d)
Definition: InsertionRegion.cpp:23
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::insertionRegion
Definition: insertionRegion.hpp:34
RESERVE
Definition: Vector.hpp:38
n
int32 n
Definition: NBSCrossLoop.hpp:24
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
length
INLINE_FUNCTION_HD T length(const triple< T > &v1)
pFlow::algorithms::KOKKOS::max
INLINE_FUNCTION_H Type max(const Type *first, int32 numElems)
Definition: kokkosAlgorithms.hpp:104
pFlow::Vector::capacity
auto capacity() const
Definition: Vector.hpp:304
pFlow::Vector::reserve
auto reserve(label len)
Definition: Vector.hpp:309
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::InsertionRegion::InsertionRegion
InsertionRegion(const dictionary &dict, const ShapeType &shapes)
Definition: InsertionRegion.cpp:41
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::triple< real >
pFlow::Vector< realx3 >
pFlow::dictionary
Definition: dictionary.hpp:38