multiTriSurface.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 "multiTriSurface.hpp"
23 
25 {
27 
28  // make sure the host and device are sync
30 
32 
33  int32 last = 0;
34  for(auto& pi:lastPointIndex_)
35  {
36  surfaceNumPoints_.push_back(pi+1-last);
37  last = pi+1;
38  }
39 
40  // update views
42 
44  last = 0;
45 
47 
48 
49  for(auto& vi:lastVertexIndex_)
50  {
51  surfaceNumVertices_.push_back(vi+1-last);
52  last = vi+1;
53  }
55 
58 
60 
62  {
63  if(i==0)continue;
64 
66  }
67 
69 
70 
73 
76  {
77  if(i==0)continue;
79  }
81 
82 
83 }
84 
86 :
87  triSurface(),
88  lastPointIndex_("lastPointIndex", "lastPointIndex"),
89  lastVertexIndex_("lastVertexIndex", "lastVertexIndex"),
90  surfaceNames_("surfaceNames", "surfaceNames")
91 {
92  calculateVars();
93 }
94 
96 (
97  const word& name,
98  const triSurface& tSurf
99 )
100 {
101 
102  const auto& newPoints = tSurf.points();
103  const auto& newVertices = tSurf.vertices();
104  const auto& newAreas = tSurf.area();
105 
106  //
107 
108 
109  points_.append(newPoints);
110 
111 
112  // add new vertices to the existing one
113  auto vOldSize = vertices_.size();
114  auto vNewSize = vOldSize + newVertices.size();
115  vertices_.resize(vNewSize);
116  area_.resize(vNewSize);
117 
118  auto verVec = vertices_.deviceVectorAll();
119  auto areaVec = area_.deviceVectorAll();
120 
121  auto newVerVec = newVertices.deviceVectorAll();
122  auto newArea = newAreas.deviceVectorAll();
123 
124  auto maxIdx = maxIndex();
125 
126  Kokkos::parallel_for(
127  "multiTriSurface::addTriSurface",
128  newVertices.size(),
129  LAMBDA_HD(int32 i){
130  verVec[vOldSize+i] = newVerVec[i]+(maxIdx+1);
131  areaVec[vOldSize+i] = newArea[i];
132  }
133  );
134  Kokkos::fence();
135 
136  if( !check() )
137  {
139  "the indices and number of points do not match. \n";
140  return false;
141  }
142 
143  lastPointIndex_.push_back(points_.size()-1);
144  lastPointIndex_.syncViews();
145 
146  lastVertexIndex_.push_back(vertices_.size()-1);
147  lastVertexIndex_.syncViews();
148 
149  surfaceNames_.push_back(name);
150 
151  calculateVars();
152 
153  return true;
154 
155 }
156 
158 (
159  const word& name,
160  const realx3x3Vector& vertices
161 )
162 {
163  triSurface newSurf(vertices);
164 
165  return addTriSurface(name, newSurf);
166 }
167 
168 /*pFlow::real3*
169  pFlow::multiTriSurface::beginSurfacePoint
170 (
171  unit i
172 )
173 {
174  if(i== 0) return points_.data();
175  if(i>=numSurfaces())return points_.data()+numPoints();
176  return points_.data()+lastPointIndex_[i-1]+1;
177 }
178 
179 const pFlow::real3*
180  pFlow::multiTriSurface::beginSurfacePoint
181 (
182  unit i
183 )const
184 {
185  if(i== 0) return points_.data();
186  if(i>=numSurfaces())return points_.data()+numPoints();
187  return points_.data()+lastPointIndex_[i-1]+1;
188 }
189 
190 pFlow::real3*
191  pFlow::multiTriSurface::endSurfacePoint
192 (
193  unit i
194 )
195 {
196  if(i>=numSurfaces())return points_.data()+numPoints();
197  return points_.data()+lastPointIndex_[i]+1;
198 }
199 
200 const pFlow::real3*
201  pFlow::multiTriSurface::endSurfacePoint
202 (
203  unit i
204 )const
205 {
206  if(i>=numSurfaces())return points_.data()+numPoints();
207  return points_.data()+lastPointIndex_[i]+1;
208 }*/
209 
211 (
212  iIstream& is
213 )
214 {
215  if( !readTriSurface(is) )return false;
216 
217  is >> lastPointIndex_;
218  if(!is.check(FUNCTION_NAME) ) return false;
219 
220  is >> lastVertexIndex_;
221  if(!is.check(FUNCTION_NAME) ) return false;
222 
223  is >> surfaceNames_;
224  if( !is.check(FUNCTION_NAME)) return false;
225 
226  calculateVars();
227 
228  return true;
229 }
230 
232 (
233  iOstream& os
234 )const
235 {
236  if(!writeTriSurface(os)) return false;
237 
238  os << lastPointIndex_;
239  os << lastVertexIndex_;
240  os << surfaceNames_;
241 
242  return os.check(FUNCTION_NAME);
243 }
pFlow::multiTriSurface::multiTriSurface
multiTriSurface()
Definition: multiTriSurface.cpp:85
pFlow::VectorDual::syncViews
INLINE_FUNCTION_H void syncViews()
Definition: VectorDual.hpp:875
pFlow::multiTriSurface::readMultiTriSurface
bool readMultiTriSurface(iIstream &is)
Definition: multiTriSurface.cpp:211
pFlow::VectorDual::push_back
void push_back(const T &val)
Definition: VectorDual.hpp:741
pFlow::multiTriSurface::lastVertexIndex_
int32Field_HD lastVertexIndex_
Definition: multiTriSurface.hpp:43
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::triSurface::area
const realVector_D & area() const
Definition: triSurface.hpp:194
pFlow::multiTriSurface::numSurfaces_
int32 numSurfaces_
Definition: multiTriSurface.hpp:56
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::VectorDual::capacity
INLINE_FUNCTION_H size_t capacity() const
Definition: VectorDual.hpp:396
pFlow::multiTriSurface::surfaceNumVertices_
int32Field_HD surfaceNumVertices_
Definition: multiTriSurface.hpp:52
pFlow::multiTriSurface::lastPointIndex_
int32Field_HD lastPointIndex_
Definition: multiTriSurface.hpp:40
pFlow::multiTriSurface::surfaceNames_
wordField surfaceNames_
Definition: multiTriSurface.hpp:46
pFlow::triSurface::points
const realx3Vector_D & points() const
Definition: triSurface.hpp:184
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::VectorDual::clear
INLINE_FUNCTION_H void clear()
Definition: VectorDual.hpp:448
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
multiTriSurface.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::multiTriSurface::pointsStartPos_
int32Vector_HD pointsStartPos_
Definition: multiTriSurface.hpp:50
pFlow::VectorDual::reallocate
INLINE_FUNCTION_H void reallocate(size_t cap)
Definition: VectorDual.hpp:419
pFlow::multiTriSurface::verticesStartPos_
int32Vector_HD verticesStartPos_
Definition: multiTriSurface.hpp:54
pFlow::VectorSingle::append
INLINE_FUNCTION_H bool append(const deviceViewType1D< T > &dVec, size_t numElems)
Definition: VectorSingle.hpp:672
pFlow::multiTriSurface::surfaceNumPoints_
int32Field_HD surfaceNumPoints_
Definition: multiTriSurface.hpp:48
pFlow::multiTriSurface::addTriSurface
bool addTriSurface(const word &name, const triSurface &tSurf)
Definition: multiTriSurface.cpp:96
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::multiTriSurface::writeMultiTriSurface
bool writeMultiTriSurface(iOstream &os) const
Definition: multiTriSurface.cpp:232
pFlow::triSurface::vertices
const int32x3Vector_D & vertices() const
Definition: triSurface.hpp:214
pFlow::triSurface
Definition: triSurface.hpp:38
pFlow::multiTriSurface::calculateVars
void calculateVars()
Definition: multiTriSurface.cpp:24
pFlow::Vector
Definition: Vector.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53