www.cemf.ir
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 
26 #include "Vectors.hpp"
27 #include "Fields.hpp"
28 #include "IOobject.hpp"
29 
30 namespace pFlow
31 {
32 
33 
34 class iIstream;
35 class iOstream;
36 class repository;
37 
38 
40 {
41 private:
43 
45 
47 
49 public:
50 
57  :
60  dPoints_(points),
61  dVectices_(vertices)
62  {}
63 
65  triangleAccessor(const triangleAccessor&)= default;
66 
69 
72 
75 
77  ~triangleAccessor()=default;
78 
81  auto v = dVectices_[i];
82  return realx3x3(
83  dPoints_[v.x_],
84  dPoints_[v.y_],
85  dPoints_[v.z_]);
86  }
87 
89  realx3x3 operator()(uint32 i)const { return triangle(i); }
90 
92  realx3x3 operator[](uint32 i)const { return triangle(i); }
93 
95  uint32 numPoints()const { return numPoints_; }
96 
98  uint32 numTrianlges()const { return numTriangles_;}
99 };
100 
101 
102 
104 :
105  public IOobject
106 {
107 private:
108 
110  realx3Field_D points_{"points", "points"};
111 
113  uint32x3Field_D vertices_{"vertices", "vertices"};
114 
116  realField_D area_{"area", "area"};
117 
119  realx3Field_D normals_{"normals", "normals"};
120 
121 protected:
122 
123  bool calculateNormals();
124 
125  bool calculateArea();
126 
127  bool append(const realx3x3Field_H& triangles);
128 
129  bool append(const realx3x3Vector& triangles);
130 
131 
132  // to be used by multiTriSurface
133  triSurface(const objectFile& obj, repository* owner);
134 
135 public:
136 
137  // - type info
138  TypeInfo("triSurface");
139 
140  triSurface(
141  const objectFile& objf,
142  repository* owner,
143  const triSurface& surf);
144 
146 
147  // - construct from vertices of triangles
148  explicit triSurface(const realx3x3Field_H& triangles, repository* owner=nullptr);
149 
150  // - construct from components
151  //triSurface(const realx3Vector& points, const uint32x3Vector& vertices);
152 
153  ~triSurface() override = default;
154 
155 
158  {
159  return points_.size();
160  }
161 
162  uint32 size()const
163  {
164  return vertices_.size();
165  }
166 
168  {
169  return vertices_.capacity();
170  }
171 
172  const realx3Field_D& points() const
173  {
174  return points_;
175  }
176 
178  {
179  return points_;
180  }
181 
182  const auto& area()const
183  {
184  return area_;
185  }
186 
187  auto& area()
188  {
189  return area_;
190  }
191 
192  const uint32x3Field_D& vertices() const
193  {
194  return vertices_;
195  }
196 
198  {
199  return vertices_;
200  }
201 
202  auto& normals()
203  {
204  return normals_;
205  }
206 
207  const auto& normals()const
208  {
209  return normals_;
210  }
211 
212  void clear()
213  {
214  points_.clear();
215  vertices_.clear();
216  area_.clear();
217  normals_.clear();
218  }
219 
222  {
223  return triangleAccessor(
224  points_.size(),
226  vertices_.size(),
228  }
229 
231 
232  bool read(iIstream& is, const IOPattern& iop) override;
233 
234  bool write(iOstream& os, const IOPattern& iop)const override;
235 };
236 
238 {
240  {
241  ioErrorInFile(is.name(), is.lineNumber())<<
242  " error in reading triSurface from file.\n";
243  fatalExit;
244  }
245  return is;
246 }
247 
248 inline iOstream& operator << (iOstream& os, const triSurface& tri)
249 {
251  {
252  ioErrorInFile(os.name(), os.lineNumber())<<
253  " error in writing triSurface to file.\n";
254  fatalExit;
255  }
256  return os;
257 }
258 
259 
260 } // pFlow
261 
262 
263 
264 #endif
pFlow::triSurface::getTriangleAccessor
auto getTriangleAccessor() const
Obtain an object for accessing triangles.
Definition: triSurface.hpp:221
pFlow::triangleAccessor::operator=
INLINE_FUNCTION_HD triangleAccessor & operator=(const triangleAccessor &)=default
pFlow::triSurface::capacity
uint32 capacity() const
Definition: triSurface.hpp:167
pFlow::triSurface::clear
void clear()
Definition: triSurface.hpp:212
pFlow::triSurface::vertices
const uint32x3Field_D & vertices() const
Definition: triSurface.hpp:192
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
IOobject.hpp
pFlow::triangleAccessor::operator()
INLINE_FUNCTION_HD realx3x3 operator()(uint32 i) const
Definition: triSurface.hpp:89
pFlow::triSurface::normals_
realx3Field_D normals_
normal vector of triangles
Definition: triSurface.hpp:119
pFlow::VectorSingle::clear
INLINE_FUNCTION_H void clear()
Clear the vector, but keep the allocated memory unchanged.
Definition: VectorSingle.cpp:358
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::triangleAccessor::~triangleAccessor
INLINE_FUNCTION_HD ~triangleAccessor()=default
pFlow::triSurface::normals
const auto & normals() const
Definition: triSurface.hpp:207
pFlow::triSurface::calculateNormals
bool calculateNormals()
Definition: triSurface.cpp:107
pFlow::triangleAccessor::numTrianlges
INLINE_FUNCTION_HD uint32 numTrianlges() const
Definition: triSurface.hpp:98
Vectors.hpp
pFlow::triSurface::write
bool write(iOstream &os, const IOPattern &iop) const override
Definition: triSurface.cpp:282
pFlow::triangleAccessor::numTriangles_
uint32 numTriangles_
Definition: triSurface.hpp:44
pFlow::Field< realx3 >
pFlow::triSurface::points_
realx3Field_D points_
points of triangles
Definition: triSurface.hpp:110
pFlow::triSurface::numPoints
uint32 numPoints() const
Definition: triSurface.hpp:157
pFlow::deviceViewType1D
Kokkos::View< T * > deviceViewType1D
1D array (vector) with default device (memory space and execution space)
Definition: KokkosTypes.hpp:121
pFlow
Definition: demGeometry.hpp:27
pFlow::triangleAccessor::triangleAccessor
INLINE_FUNCTION_H triangleAccessor(uint32 numPoints, deviceViewType1D< realx3 > points, uint32 numTrianlges, deviceViewType1D< uint32x3 > vertices)
Definition: triSurface.hpp:52
pFlow::IOobject
Definition: IOobject.hpp:35
pFlow::triangleAccessor::triangle
INLINE_FUNCTION_HD realx3x3 triangle(uint32 i) const
Definition: triSurface.hpp:80
pFlow::iIstream
Interface class for any input stream
Definition: iIstream.hpp:37
pFlow::triSurface::size
uint32 size() const
Definition: triSurface.hpp:162
pFlow::IOPattern::AllProcessorsDifferent
@ AllProcessorsDifferent
Definition: IOPattern.hpp:57
pFlow::triSurface::points
const realx3Field_D & points() const
Definition: triSurface.hpp:172
pFlow::triangleAccessor::dVectices_
deviceViewType1D< uint32x3 > dVectices_
Definition: triSurface.hpp:48
pFlow::triSurface::~triSurface
~triSurface() override=default
pFlow::triSurface::vertices_
uint32x3Field_D vertices_
vectices indices of triangles
Definition: triSurface.hpp:113
Fields.hpp
pFlow::triangleAccessor::operator[]
INLINE_FUNCTION_HD realx3x3 operator[](uint32 i) const
Definition: triSurface.hpp:92
pFlow::triangleAccessor::dPoints_
deviceViewType1D< realx3 > dPoints_
Definition: triSurface.hpp:46
pFlow::operator>>
INLINE_FUNCTION iIstream & operator>>(iIstream &str, AB3History &ab3)
Definition: AdamsBashforth3.hpp:41
pFlow::IOPattern
Definition: IOPattern.hpp:32
pFlow::triangleAccessor::numPoints
INLINE_FUNCTION_HD uint32 numPoints() const
Definition: triSurface.hpp:95
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:57
pFlow::IOobject::owner
const repository * owner() const override
Definition: IOobject.hpp:76
pFlow::operator<<
INLINE_FUNCTION iOstream & operator<<(iOstream &str, const AB3History &ab3)
Definition: AdamsBashforth3.hpp:57
pFlow::realx3x3
triple< realx3 > realx3x3
Definition: types.hpp:47
pFlow::triSurface::vertices
uint32x3Field_D & vertices()
Definition: triSurface.hpp:197
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::VectorSingle::deviceViewAll
INLINE_FUNCTION_H auto & deviceViewAll()
Device view range [0,capcity)
Definition: VectorSingle.cpp:249
pFlow::triSurface::TypeInfo
TypeInfo("triSurface")
pFlow::triSurface::normals
auto & normals()
Definition: triSurface.hpp:202
pFlow::triSurface::area
auto & area()
Definition: triSurface.hpp:187
pFlow::triSurface::points
realx3Field_D & points()
Definition: triSurface.hpp:177
pFlow::triSurface::read
bool read(iIstream &is, const IOPattern &iop) override
Definition: triSurface.cpp:257
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Report an error in file operation with supplied fileName and lineNumber.
Definition: error.hpp:87
pFlow::VectorSingle::capacity
INLINE_FUNCTION_H uint32 capacity() const
Definition: VectorSingle.cpp:304
pFlow::repository
Definition: repository.hpp:34
pFlow::IOstream::lineNumber
int32 lineNumber() const
Const access to the current stream line number.
Definition: IOstream.hpp:223
pFlow::triSurface::area_
realField_D area_
area of each triangle
Definition: triSurface.hpp:116
pFlow::triSurface::triSurface
triSurface(const objectFile &obj, repository *owner)
Definition: triSurface.cpp:191
pFlow::triSurface
Definition: triSurface.hpp:103
pFlow::triSurface::area
const auto & area() const
Definition: triSurface.hpp:182
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:55
pFlow::triple
A set of 3 variables that can be used for vector variables.
Definition: triple.hpp:36
pFlow::triSurface::calculateArea
bool calculateArea()
Definition: triSurface.cpp:115
pFlow::Vector
Definition: Vector.hpp:48
pFlow::triangleAccessor
Definition: triSurface.hpp:39
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::triSurface::append
bool append(const realx3x3Field_H &triangles)
Definition: triSurface.cpp:124
pFlow::VectorSingle::size
INLINE_FUNCTION_H uint32 size() const
Size of the vector.
Definition: VectorSingle.cpp:297
pFlow::triangleAccessor::numPoints_
uint32 numPoints_
Definition: triSurface.hpp:42