triSurface.hpp
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 #ifndef __triSurface_hpp__
23 #define __triSurface_hpp__
24 
25 #include "eventSubscriber.hpp"
26 #include "types.hpp"
27 #include "Vectors.hpp"
28 #include "VectorSingles.hpp"
29 #include "Fields.hpp"
30 
31 namespace pFlow
32 {
33 
34 
35 class iIstream;
36 class iOstream;
37 
39 :
40  public eventSubscriber
41 {
42 public:
43 
45  {
46  public:
47 
48  protected:
50 
52 
54 
56  public:
57 
64  :
69  {}
70 
72  triangleAccessor(const triangleAccessor&)= default;
73 
76 
79 
82 
84  ~triangleAccessor()=default;
85 
88  auto v = dVectices_[i];
89  return realx3x3(
90  dPoints_[v.x_],
91  dPoints_[v.y_],
92  dPoints_[v.z_]);
93  }
94 
96  realx3x3 operator()(int32 i)const { return triangle(i); }
97 
99  realx3x3 operator[](int32 i)const { return triangle(i); }
100 
102  int32 numPoints()const { return numPoints_; }
103 
105  int32 numTrianlges()const { return numTriangles_;}
106  };
107 
108 protected:
109 
112 
115 
118 
120 
121 
122  // protected methods
123 
124 
126 
127  // - check if the range of indices in vectors match
128  bool check();
129 
130 public:
131 
132  // - type info
133  TypeInfo("triSurface");
134 
136 
137  // - empty
138  triSurface();
139 
140  // - construct from components
142 
143  // - construct from vertices of triangles
144  triSurface(const realx3x3Vector& triangles);
145 
146  virtual ~triSurface() = default;
147 
149  size_t numPoints() const
150  {
151  return points_.size();
152  }
153 
154  size_t numTriangles()const
155  {
156  return vertices_.size();
157  }
158 
159  size_t size()const
160  {
161  return numTriangles();
162  }
163 
164  size_t capacity()const
165  {
166  return vertices_.capacity();
167  }
168 
170  {
171  return maxIndex_;
172  }
173 
175  {
176  return triangleAccessor(
177  numPoints(),
179  numTriangles(),
181  );
182  }
183 
184  const realx3Vector_D& points() const
185  {
186  return points_;
187  }
188 
190  {
191  return points_;
192  }
193 
194  const realVector_D& area()const
195  {
196  return area_;
197  }
198 
200  {
201  return area_;
202  }
203 
204  const realx3* pointsData_D()const
205  {
206  return points_.deviceVectorAll().data();
207  }
208 
210  {
211  return points_.deviceVectorAll().data();
212  }
213 
214  const int32x3Vector_D& vertices() const
215  {
216  return vertices_;
217  }
218 
220  {
221  return vertices_;
222  }
223 
225  {
226  return vertices_.deviceVectorAll().data();
227  }
228 
229  const int32x3* verticesData_D()const
230  {
231  return vertices_.deviceVectorAll().data();
232  }
233 
234  void clear()
235  {
236  points_.clear();
237  vertices_.clear();
238  area_.clear();
239  }
240 
241  int32 calcMaxIndex()const;
242 
244 
245  bool readTriSurface(iIstream& is);
246 
247  bool writeTriSurface(iOstream& os)const;
248 
249  bool read(iIstream& is)
250  {
251  return readTriSurface(is);
252  }
253 
254  bool write(iOstream& os)const
255  {
256  return writeTriSurface(os);
257  }
258 
259 };
260 
262 {
263  if(!tri.readTriSurface(is))
264  {
265  ioErrorInFile(is.name(), is.lineNumber())<<
266  " error in reading triSurface from file.\n";
267  fatalExit;
268  }
269  return is;
270 }
271 
272 inline iOstream& operator << (iOstream& os, const triSurface& tri)
273 {
274  if( !tri.writeTriSurface(os) )
275  {
276  ioErrorInFile(os.name(), os.lineNumber())<<
277  " error in writing triSurface to file.\n";
278  fatalExit;
279  }
280  return os;
281 }
282 
283 
284 } // pFlow
285 
286 
287 
288 #endif
pFlow::triSurface::verticesData_D
const int32x3 * verticesData_D() const
Definition: triSurface.hpp:229
pFlow::triSurface::triangleAccessor::dVectices_
deviceViewType1D< int32x3 > dVectices_
Definition: triSurface.hpp:55
pFlow::triSurface::getTriangleAccessor
auto getTriangleAccessor() const
Definition: triSurface.hpp:174
pFlow::triSurface::clear
void clear()
Definition: triSurface.hpp:234
pFlow::eventSubscriber
Definition: eventSubscriber.hpp:34
pFlow::triSurface::maxIndex_
int32 maxIndex_
Definition: triSurface.hpp:119
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::triSurface::triangleAccessor::numPoints_
int32 numPoints_
Definition: triSurface.hpp:49
pFlow::triSurface::points
realx3Vector_D & points()
Definition: triSurface.hpp:189
pFlow::triSurface::triangleAccessor::dPoints_
deviceViewType1D< realx3 > dPoints_
Definition: triSurface.hpp:53
types.hpp
pFlow::triSurface::triangleAccessor::operator[]
INLINE_FUNCTION_HD realx3x3 operator[](int32 i) const
Definition: triSurface.hpp:99
pFlow::VectorSingle::clear
INLINE_FUNCTION_H void clear()
Definition: VectorSingle.hpp:418
pFlow::triSurface::calcMaxIndex
int32 calcMaxIndex() const
Definition: triSurface.cpp:81
pFlow::triSurface::area
const realVector_D & area() const
Definition: triSurface.hpp:194
Vectors.hpp
pFlow::triSurface::triangleAccessor::numTriangles_
int32 numTriangles_
Definition: triSurface.hpp:51
pFlow::triSurface::triangleAccessor::triangle
INLINE_FUNCTION_HD realx3x3 triangle(int32 i) const
Definition: triSurface.hpp:87
pFlow::Field< VectorSingle, realx3 >
pFlow::VectorSingle::capacity
INLINE_FUNCTION_H size_t capacity() const
Definition: VectorSingle.hpp:367
pFlow::triSurface::points_
realx3Field_D points_
points of triangles
Definition: triSurface.hpp:111
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
Definition: KokkosTypes.hpp:93
pFlow::triSurface::writeTriSurface
bool writeTriSurface(iOstream &os) const
Definition: triSurface.cpp:219
pFlow::triSurface::points
const realx3Vector_D & points() const
Definition: triSurface.hpp:184
pFlow
Definition: demComponent.hpp:28
VectorSingles.hpp
pFlow::triSurface::vertices_
int32x3Field_D vertices_
vectices indices of triangles
Definition: triSurface.hpp:114
pFlow::triSurface::check
bool check()
Definition: triSurface.cpp:103
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::triSurface::read
bool read(iIstream &is)
Definition: triSurface.hpp:249
pFlow::triSurface::maxIndex
int32 maxIndex() const
Definition: triSurface.hpp:169
pFlow::triSurface::verticesData_D
int32x3 * verticesData_D()
Definition: triSurface.hpp:224
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::triSurface::numTriangles
size_t numTriangles() const
Definition: triSurface.hpp:154
Fields.hpp
pFlow::triSurface::area
realVector_D & area()
Definition: triSurface.hpp:199
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::triSurface::vertices
int32x3Vector_D & vertices()
Definition: triSurface.hpp:219
pFlow::triSurface::pointsData_D
realx3 * pointsData_D()
Definition: triSurface.hpp:209
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::triSurface::numPoints
size_t numPoints() const
Definition: triSurface.hpp:149
pFlow::VectorSingle
Definition: VectorSingle.hpp:45
pFlow::realx3x3
triple< realx3 > realx3x3
Definition: types.hpp:54
pFlow::triSurface::pointsData_D
const realx3 * pointsData_D() const
Definition: triSurface.hpp:204
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::triSurface::triangleAccessor::numPoints
INLINE_FUNCTION_HD int32 numPoints() const
Definition: triSurface.hpp:102
pFlow::triSurface::~triSurface
virtual ~triSurface()=default
pFlow::triSurface::capacity
size_t capacity() const
Definition: triSurface.hpp:164
pFlow::triSurface::TypeInfo
TypeInfo("triSurface")
pFlow::triSurface::triSurface
triSurface()
Definition: triSurface.cpp:114
pFlow::triSurface::triangleAccessor::triangleAccessor
INLINE_FUNCTION_H triangleAccessor(int32 numPoints, deviceViewType1D< realx3 > points, int32 numTrianlges, deviceViewType1D< int32x3 > vertices)
Definition: triSurface.hpp:59
pFlow::triSurface::vertices
const int32x3Vector_D & vertices() const
Definition: triSurface.hpp:214
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
eventSubscriber.hpp
pFlow::triSurface::write
bool write(iOstream &os) const
Definition: triSurface.hpp:254
pFlow::triSurface::triangleAccessor::operator()
INLINE_FUNCTION_HD realx3x3 operator()(int32 i) const
Definition: triSurface.hpp:96
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::triSurface::area_
realField_D area_
area of each triangle
Definition: triSurface.hpp:117
pFlow::triSurface
Definition: triSurface.hpp:38
pFlow::VectorSingle::size
INLINE_FUNCTION_H size_t size() const
Definition: VectorSingle.hpp:360
pFlow::VectorSingle::deviceVectorAll
INLINE_FUNCTION_H viewType & deviceVectorAll()
Definition: VectorSingle.hpp:295
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::triple
Definition: triple.hpp:37
pFlow::Vector< realx3 >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::triSurface::readTriSurface
bool readTriSurface(iIstream &is)
Definition: triSurface.cpp:191
pFlow::triSurface::triangleAccessor::operator=
INLINE_FUNCTION_HD triangleAccessor & operator=(const triangleAccessor &)=default
pFlow::triSurface::addTriangle
int32 addTriangle(const realx3x3 &tri, realx3Vector &points, int32x3Vector &vertices)
Definition: triSurface.cpp:29
pFlow::triSurface::size
size_t size() const
Definition: triSurface.hpp:159
pFlow::triSurface::triangleAccessor::numTrianlges
INLINE_FUNCTION_HD int32 numTrianlges() const
Definition: triSurface.hpp:105
pFlow::triSurface::triangleAccessor
Definition: triSurface.hpp:44
pFlow::triSurface::triangleAccessor::~triangleAccessor
INLINE_FUNCTION_HD ~triangleAccessor()=default