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

triSurface.cpp
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.
-----------------------------------------------------------------------------*/
#include "triSurface.hpp"
#include "error.hpp"
#include "iOstream.hpp"
#include "triSurfaceKernels.hpp"
pFlow::int32 pFlow::triSurface::addTriangle
(
const realx3x3 & tri,
realx3Vector& points,
int32x3Vector& vertices
)
{
int32x3 newTri;
// first point
if ( int32 i = find(points, tri.x()) ; i > -1)
{
newTri.x() = i; // existing point
}
else
{
points.push_back(tri.x()); // new point
newTri.x() = static_cast< int32 >(points.size()) - 1;
}
// second point
if ( int32 j = find(points, tri.y()) ; j > -1)
{
newTri.y() = j; // existing point
}
else
{
points.push_back(tri.y()); // new point
newTri.y() = static_cast< int32 >(points.size()) - 1;
}
// third point
if ( int32 k = find(points, tri.z()) ; k > -1)
{
newTri.z() = k; // existing point
}
else
{
points.push_back(tri.z()); // new point
newTri.z() = static_cast< int32 >(points.size()) - 1;
}
// adds the new tirple vertices to the list
vertices.push_back( newTri );
//output<< " points " <<points << endl;
//output<< " vertices "<<vertices <<endl;
return static_cast< int32 >(vertices.size()) -1;
}
pFlow::int32 pFlow::triSurface::calcMaxIndex()const
{
int32 maxIdx = -1;
if(vertices_.size()>0)
{
auto verDeviceVec = vertices_.deviceVectorAll();
Kokkos::parallel_reduce(
"triSurface::calcMaxIndex",
vertices_.size(),
LAMBDA_HD(int32 i, int32& valueToUpdate){
valueToUpdate = max(valueToUpdate, max(verDeviceVec[i]));
},
Kokkos::Max<int32>( maxIdx )
);
}
return maxIdx;
}
bool pFlow::triSurface::check()
{
auto maxIdx = calcMaxIndex();
maxIndex_ = maxIdx;
if( maxIdx >= static_cast< int32 >(points_.size())) return false;
return true;
}
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *//
pFlow::triSurface::triSurface()
:
points_("points"),
vertices_("vertices"),
area_("area"),
maxIndex_(-1)
{}
pFlow::triSurface::triSurface
(
const realx3Vector& points,
const int32x3Vector& vertices
)
:
points_("points", "points", points),
vertices_("vertices", "vertices", vertices),
area_("area", "area"),
maxIndex_(-1)
{
if( check() )
{
fatalErrorInFunction<<
"the indices and number of points do not match. \n";
fatalExit;
}
area_.reallocate(vertices_.capacity(), vertices_.size());
pFlow::triSurfaceKernels::calculateArea(points_, vertices_, area_);
}
pFlow::triSurface::triSurface
(
const realx3x3Vector& triangles
)
:
points_("points"),
vertices_("vertices"),
area_("area")
{
Vector<realx3> points;
Vector<int32x3> vertices;
points.clear();
vertices.clear();
for( const auto& tr: triangles)
{
if(auto i= addTriangle(tr, points, vertices); i < 0 )
{
fatalErrorInFunction <<
"failed to insert a triangle into triSurface. \n";
fatalExit;
}
}
points_.assign(points);
vertices_.assign(vertices);
area_.reallocate(vertices_.capacity(), vertices_.size());
pFlow::triSurfaceKernels::calculateArea(points_, vertices_, area_);
if( !check() )
{
fatalErrorInFunction<<
"the indices and number of points do not match. \n";
fatalExit;
}
}
bool pFlow::triSurface::readTriSurface
(
iIstream& is
)
{
is.fatalCheck(FUNCTION_NAME);
is >> points_;
is.fatalCheck(FUNCTION_NAME);
is >> vertices_;
is.fatalCheck(FUNCTION_NAME);
if( !check() )
{
ioErrorInFile( is.name(), is.lineNumber() ) <<
"the indices and number of points do not match. \n";
return false;
}
area_.reallocate(vertices_.capacity(), vertices_.size());
pFlow::triSurfaceKernels::calculateArea(points_, vertices_, area_);
return true;
}
bool pFlow::triSurface::writeTriSurface
(
iOstream& os
)const
{
os << points_;
os << vertices_;
return os.check(FUNCTION_NAME);;
}
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::find
int64 find(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:69
pFlow::triSurface::calcMaxIndex
int32 calcMaxIndex() const
Definition: triSurface.cpp:81
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::triSurface::writeTriSurface
bool writeTriSurface(iOstream &os) const
Definition: triSurface.cpp:219
pFlow::triple::y
INLINE_FUNCTION_HD T & y()
Definition: triple.hpp:141
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
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
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
triSurfaceKernels.hpp
pFlow::IOstream::fatalCheck
bool fatalCheck(const char *operation) const
Definition: IOstream.cpp:48
pFlow::triSurfaceKernels::calculateArea
INLINE_FUNCTION_H bool calculateArea(const realx3Field_D &points, const int32x3Field_D &vertices, realField_D &area)
Definition: triSurfaceKernels.hpp:32
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
pFlow::triple::z
INLINE_FUNCTION_HD T & z()
Definition: triple.hpp:144
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::triSurface::triSurface
triSurface()
Definition: triSurface.cpp:114
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
iOstream.hpp
pFlow::triple::x
INLINE_FUNCTION_HD T & x()
Definition: triple.hpp:138
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
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
triSurface.hpp
pFlow::triSurface::addTriangle
int32 addTriangle(const realx3x3 &tri, realx3Vector &points, int32x3Vector &vertices)
Definition: triSurface.cpp:29
error.hpp