positionParticles.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 "positionParticles.hpp"
22 #include "box.hpp"
23 #include "cylinder.hpp"
24 #include "sphere.hpp"
25 #include "cells.hpp"
27 
28 #include "streams.hpp"
29 
30 
32 {
33  struct indexMorton
34  {
35  size_t morton;
36  size_t index;
37  };
38 
39  realx3 minP = min(position);
40  realx3 maxP = max(position);
41  real cellsize = maxDiameter();
42  cells<size_t> allCells( box(minP, maxP), cellsize);
43 
45 
46  indMor.clear();
47 
48  size_t ind=0;
49  for(const auto& p:position)
50  {
51  auto cellInd = allCells.pointIndex(p);
52  indMor.push_back(
53  { xyzToMortonCode64(cellInd.x(), cellInd.y(), cellInd.z()),
54  ind++});
55  }
56 
57  INFORMATION<<"Performing morton sorting."<<endINFO;
58  std::sort(
59  indMor.begin(),
60  indMor.end(),
61  []( const indexMorton &lhs, const indexMorton &rhs){
62  return lhs.morton < rhs.morton; } );
63 
64  realx3Vector sortedPos(position.capacity(), RESERVE());
65  sortedPos.clear();
66 
67 
68  for(auto& ind:indMor)
69  {
70  sortedPos.push_back( position[ind.index] );
71  }
72 
73  return sortedPos;
74 }
75 
76 
78 (
79  const dictionary& dict
80 )
81 {
82  maxNumberOfParticles_ = dict.getValOrSet("maxNumberOfParticles", static_cast<size_t>(10000));
83 
84  mortonSorting_ = dict.getValOrSet("mortonSorting", Logical("Yes"));
85 
86  if( dict.containsDictionay("box") )
87  {
88  region_ = makeUnique<region<box>>(dict.subDict("box"));
89  }
90  else if(dict.containsDictionay("cylinder"))
91  {
92  region_ = makeUnique<region<cylinder>>(dict.subDict("cylinder"));
93  }
94  else if(dict.containsDictionay("sphere"))
95  {
96  region_ = makeUnique<region<sphere>>(dict.subDict("sphere"));
97  }
98 }
99 
100 
102 {
103  if(mortonSorting_)
104  {
105  return sortByMortonCode(position());
106  }
107  else
108  {
109  realx3Vector vec(position().capacity(), RESERVE());
110  vec.assign( position().begin(), position().end());
111 
112  return std::move(vec);
113  }
114 }
115 
118 {
119 
120  word method = dict.getVal<word>("method");
121 
122 
123  if( dictionaryvCtorSelector_.search(method) )
124  {
125  return dictionaryvCtorSelector_[method] (dict);
126  }
127  else
128  {
129  printKeys
130  (
131  fatalError << "Ctor Selector "<< method << " dose not exist. \n"
132  <<"Avaiable ones are: \n\n"
133  ,
134  dictionaryvCtorSelector_
135  );
136  fatalExit;
137  }
138 
139  return nullptr;
140 }
pFlow::dictionary::getValOrSet
T getValOrSet(const word &keyword, const T &setVal) const
Definition: dictionary.hpp:325
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::positionParticles::create
static uniquePtr< positionParticles > create(const dictionary &dict)
Definition: positionParticles.cpp:117
contactSearchFunctions.hpp
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
box.hpp
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::dictionary::containsDictionay
bool containsDictionay(const word &name) const
Definition: dictionary.cpp:736
RESERVE
Definition: Vector.hpp:38
pFlow::positionParticles::positionParticles
positionParticles(const dictionary &dict)
Definition: positionParticles.cpp:78
pFlow::Vector::capacity
auto capacity() const
Definition: Vector.hpp:304
pFlow::positionParticles::position
virtual const realx3Vector & position() const =0
pFlow::positionParticles::maxDiameter
virtual real maxDiameter() const =0
cells.hpp
fatalError
#define fatalError
Definition: error.hpp:36
pFlow::dictionary::subDict
dictionary & subDict(const word &keyword)
Definition: dictionary.cpp:547
streams.hpp
sort
void sort(Vector< T, Allocator > &vec)
sphere.hpp
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::Logical
Definition: Logical.hpp:35
pFlow::box
Definition: box.hpp:32
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::positionParticles::getFinalPosition
virtual realx3Vector getFinalPosition()
Definition: positionParticles.cpp:101
pFlow::positionParticles::sortByMortonCode
realx3Vector sortByMortonCode(realx3Vector &position) const
Definition: positionParticles.cpp:31
cylinder.hpp
pFlow::cells
Definition: cells.hpp:32
pFlow::triple< real >
pFlow::cells::pointIndex
INLINE_FUNCTION_HD CellType pointIndex(const realx3 &p) const
Definition: cells.hpp:158
pFlow::Vector< realx3 >
endINFO
#define endINFO
Definition: streams.hpp:38
positionParticles.hpp
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::xyzToMortonCode64
INLINE_FUNCTION_HD uint64_t xyzToMortonCode64(uint64_t x, uint64_t y, uint64_t z)
Definition: contactSearchFunctions.hpp:42
INFORMATION
#define INFORMATION
Definition: streams.hpp:37