# PhasicFlow: src/phasicFlow/triSurface/triSurface.hpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

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 "Vectors.hpp"
#include "Fields.hpp"
#include "IOobject.hpp"
namespace pFlow
{
class iIstream;
class iOstream;
class repository;
class triangleAccessor
{
private:
uint32 numPoints_;
uint32 numTriangles_;
deviceViewType1D<realx3> dPoints_;
deviceViewType1D<uint32x3> dVectices_;
public:
INLINE_FUNCTION_H
triangleAccessor(
uint32 numPoints,
deviceViewType1D<realx3> points,
uint32 numTrianlges,
deviceViewType1D<uint32x3> 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(uint32 i)const {
auto v = dVectices_[i];
return realx3x3(
dPoints_[v.x_],
dPoints_[v.y_],
dPoints_[v.z_]);
}
INLINE_FUNCTION_HD
realx3x3 operator()(uint32 i)const { return triangle(i); }
INLINE_FUNCTION_HD
realx3x3 operator[](uint32 i)const { return triangle(i); }
INLINE_FUNCTION_HD
uint32 numPoints()const { return numPoints_; }
INLINE_FUNCTION_HD
uint32 numTrianlges()const { return numTriangles_;}
};
class triSurface
:
public IOobject
{
private:
realx3Field_D points_{"points", "points"};
uint32x3Field_D vertices_{"vertices", "vertices"};
realField_D area_{"area", "area"};
realx3Field_D normals_{"normals", "normals"};
protected:
bool calculateNormals();
bool calculateArea();
bool append(const realx3x3Field_H& triangles);
bool append(const realx3x3Vector& triangles);
// to be used by multiTriSurface
triSurface(const objectFile& obj, repository* owner);
public:
// - type info
TypeInfo("triSurface");
triSurface(
const objectFile& objf,
repository* owner,
const triSurface& surf);
// - construct from vertices of triangles
explicit triSurface(const realx3x3Field_H& triangles, repository* owner=nullptr);
// - construct from components
//triSurface(const realx3Vector& points, const uint32x3Vector& vertices);
~triSurface() override = default;
uint32 numPoints() const
{
return points_.size();
}
uint32 size()const
{
return vertices_.size();
}
uint32 capacity()const
{
return vertices_.capacity();
}
const realx3Field_D& points() const
{
return points_;
}
realx3Field_D& points()
{
return points_;
}
const auto& area()const
{
return area_;
}
auto& area()
{
return area_;
}
const uint32x3Field_D& vertices() const
{
return vertices_;
}
uint32x3Field_D& vertices()
{
return vertices_;
}
auto& normals()
{
return normals_;
}
const auto& normals()const
{
return normals_;
}
void clear()
{
points_.clear();
vertices_.clear();
area_.clear();
normals_.clear();
}
auto getTriangleAccessor()const
{
return triangleAccessor(
points_.size(),
points_.deviceViewAll(),
vertices_.size(),
vertices_.deviceViewAll());
}
bool read(iIstream& is, const IOPattern& iop) override;
bool write(iOstream& os, const IOPattern& iop)const override;
};
inline iIstream& operator >> (iIstream & is, triSurface & tri )
{
if(!tri.read(is, IOPattern::AllProcessorsDifferent))
{
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.write(os, IOPattern::AllProcessorsDifferent) )
{
ioErrorInFile(os.name(), os.lineNumber())<<
" error in writing triSurface to file.\n";
fatalExit;
}
return os;
}
} // pFlow
#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