# PhasicFlow: src/phasicFlow/structuredData/trisurfaceStructure/triSurface.hpp Source File

triSurface.hpp
Go to the documentation of this file.
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __triSurface_hpp__
#define __triSurface_hpp__
#include "eventSubscriber.hpp"
#include "types.hpp"
#include "Vectors.hpp"
#include "VectorSingles.hpp"
#include "Fields.hpp"
namespace pFlow
{
class iIstream;
class iOstream;
class triSurface
:
public eventSubscriber
{
public:
class triangleAccessor
{
public:
protected:
int32 numPoints_;
int32 numTriangles_;
deviceViewType1D<realx3> dPoints_;
deviceViewType1D<int32x3> dVectices_;
public:
INLINE_FUNCTION_H
triangleAccessor(
int32 numPoints,
deviceViewType1D<realx3> points,
int32 numTrianlges,
deviceViewType1D<int32x3> vertices )
:
numPoints_(numPoints),
numTriangles_(numTrianlges),
dPoints_(points),
dVectices_(vertices)
{}
INLINE_FUNCTION_HD
triangleAccessor(const triangleAccessor&)= default;
INLINE_FUNCTION_HD
triangleAccessor& operator=(const triangleAccessor&)= default;
INLINE_FUNCTION_HD
triangleAccessor(triangleAccessor&&)= default;
INLINE_FUNCTION_HD
triangleAccessor& operator=(triangleAccessor&&)= default;
INLINE_FUNCTION_HD
~triangleAccessor()=default;
INLINE_FUNCTION_HD
realx3x3 triangle(int32 i)const {
auto v = dVectices_[i];
return realx3x3(
dPoints_[v.x_],
dPoints_[v.y_],
dPoints_[v.z_]);
}
INLINE_FUNCTION_HD
realx3x3 operator()(int32 i)const { return triangle(i); }
INLINE_FUNCTION_HD
realx3x3 operator[](int32 i)const { return triangle(i); }
INLINE_FUNCTION_HD
int32 numPoints()const { return numPoints_; }
INLINE_FUNCTION_HD
int32 numTrianlges()const { return numTriangles_;}
};
protected:
realx3Field_D points_;
int32x3Field_D vertices_;
realField_D area_;
int32 maxIndex_ = -1;
// protected methods
int32 addTriangle(const realx3x3 & tri, realx3Vector& points, int32x3Vector& vertices);
// - check if the range of indices in vectors match
bool check();
public:
// - type info
TypeInfo("triSurface");
// - empty
triSurface();
// - construct from components
triSurface(const realx3Vector& points, const int32x3Vector& vertices);
// - construct from vertices of triangles
triSurface(const realx3x3Vector& triangles);
virtual ~triSurface() = default;
size_t numPoints() const
{
return points_.size();
}
size_t numTriangles()const
{
return vertices_.size();
}
size_t size()const
{
return numTriangles();
}
size_t capacity()const
{
return vertices_.capacity();
}
int32 maxIndex()const
{
return maxIndex_;
}
auto getTriangleAccessor()const
{
return triangleAccessor(
numPoints(),
points_.deviceVectorAll(),
numTriangles(),
vertices_.deviceVectorAll()
);
}
const realx3Vector_D& points() const
{
return points_;
}
realx3Vector_D& points()
{
return points_;
}
const realVector_D& area()const
{
return area_;
}
realVector_D& area()
{
return area_;
}
const realx3* pointsData_D()const
{
return points_.deviceVectorAll().data();
}
realx3* pointsData_D()
{
return points_.deviceVectorAll().data();
}
const int32x3Vector_D& vertices() const
{
return vertices_;
}
int32x3Vector_D& vertices()
{
return vertices_;
}
int32x3* verticesData_D()
{
return vertices_.deviceVectorAll().data();
}
const int32x3* verticesData_D()const
{
return vertices_.deviceVectorAll().data();
}
void clear()
{
points_.clear();
vertices_.clear();
area_.clear();
}
int32 calcMaxIndex()const;
bool readTriSurface(iIstream& is);
bool writeTriSurface(iOstream& os)const;
bool read(iIstream& is)
{
return readTriSurface(is);
}
bool write(iOstream& os)const
{
return writeTriSurface(os);
}
};
inline iIstream& operator >> (iIstream & is, triSurface & tri )
{
if(!tri.readTriSurface(is))
{
ioErrorInFile(is.name(), is.lineNumber())<<
" error in reading triSurface from file.\n";
fatalExit;
}
return is;
}
inline iOstream& operator << (iOstream& os, const triSurface& tri)
{
if( !tri.writeTriSurface(os) )
{
ioErrorInFile(os.name(), os.lineNumber())<<
" error in writing triSurface to file.\n";
fatalExit;
}
return os;
}
} // pFlow
#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