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

multiTriSurface.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 "multiTriSurface.hpp"
void pFlow::multiTriSurface::calculateVars()
{
numSurfaces_ = surfaceNames_.size();
// make sure the host and device are sync
lastPointIndex_.syncViews();
surfaceNumPoints_.clear();
int32 last = 0;
for(auto& pi:lastPointIndex_)
{
surfaceNumPoints_.push_back(pi+1-last);
last = pi+1;
}
// update views
surfaceNumPoints_.syncViews();
surfaceNumVertices_.clear();
last = 0;
lastVertexIndex_.syncViews();
for(auto& vi:lastVertexIndex_)
{
surfaceNumVertices_.push_back(vi+1-last);
last = vi+1;
}
surfaceNumVertices_.syncViews();
pointsStartPos_.reallocate(surfaceNumPoints_.capacity());
pointsStartPos_.clear();
pointsStartPos_.push_back(0);
ForAll( i, surfaceNumPoints_)
{
if(i==0)continue;
pointsStartPos_.push_back( pointsStartPos_[i-1] + surfaceNumPoints_[i-1] );
}
pointsStartPos_.syncViews();
verticesStartPos_.reallocate(surfaceNumVertices_.capacity());
verticesStartPos_.clear();
verticesStartPos_.push_back(0);
ForAll(i, surfaceNumVertices_)
{
if(i==0)continue;
verticesStartPos_.push_back(verticesStartPos_[i-1] + surfaceNumVertices_[i-1]);
}
verticesStartPos_.syncViews();
}
pFlow::multiTriSurface::multiTriSurface()
:
triSurface(),
lastPointIndex_("lastPointIndex", "lastPointIndex"),
lastVertexIndex_("lastVertexIndex", "lastVertexIndex"),
surfaceNames_("surfaceNames", "surfaceNames")
{
calculateVars();
}
bool pFlow::multiTriSurface::addTriSurface
(
const word& name,
const triSurface& tSurf
)
{
const auto& newPoints = tSurf.points();
const auto& newVertices = tSurf.vertices();
const auto& newAreas = tSurf.area();
//
points_.append(newPoints);
// add new vertices to the existing one
auto vOldSize = vertices_.size();
auto vNewSize = vOldSize + newVertices.size();
vertices_.resize(vNewSize);
area_.resize(vNewSize);
auto verVec = vertices_.deviceVectorAll();
auto areaVec = area_.deviceVectorAll();
auto newVerVec = newVertices.deviceVectorAll();
auto newArea = newAreas.deviceVectorAll();
auto maxIdx = maxIndex();
Kokkos::parallel_for(
"multiTriSurface::addTriSurface",
newVertices.size(),
LAMBDA_HD(int32 i){
verVec[vOldSize+i] = newVerVec[i]+(maxIdx+1);
areaVec[vOldSize+i] = newArea[i];
}
);
Kokkos::fence();
if( !check() )
{
fatalErrorInFunction<<
"the indices and number of points do not match. \n";
return false;
}
lastPointIndex_.push_back(points_.size()-1);
lastPointIndex_.syncViews();
lastVertexIndex_.push_back(vertices_.size()-1);
lastVertexIndex_.syncViews();
surfaceNames_.push_back(name);
calculateVars();
return true;
}
bool pFlow::multiTriSurface::addTriSurface
(
const word& name,
const realx3x3Vector& vertices
)
{
triSurface newSurf(vertices);
return addTriSurface(name, newSurf);
}
/*pFlow::real3*
pFlow::multiTriSurface::beginSurfacePoint
(
unit i
)
{
if(i== 0) return points_.data();
if(i>=numSurfaces())return points_.data()+numPoints();
return points_.data()+lastPointIndex_[i-1]+1;
}
const pFlow::real3*
pFlow::multiTriSurface::beginSurfacePoint
(
unit i
)const
{
if(i== 0) return points_.data();
if(i>=numSurfaces())return points_.data()+numPoints();
return points_.data()+lastPointIndex_[i-1]+1;
}
pFlow::real3*
pFlow::multiTriSurface::endSurfacePoint
(
unit i
)
{
if(i>=numSurfaces())return points_.data()+numPoints();
return points_.data()+lastPointIndex_[i]+1;
}
const pFlow::real3*
pFlow::multiTriSurface::endSurfacePoint
(
unit i
)const
{
if(i>=numSurfaces())return points_.data()+numPoints();
return points_.data()+lastPointIndex_[i]+1;
}*/
bool pFlow::multiTriSurface::readMultiTriSurface
(
iIstream& is
)
{
if( !readTriSurface(is) )return false;
is >> lastPointIndex_;
if(!is.check(FUNCTION_NAME) ) return false;
is >> lastVertexIndex_;
if(!is.check(FUNCTION_NAME) ) return false;
is >> surfaceNames_;
if( !is.check(FUNCTION_NAME)) return false;
calculateVars();
return true;
}
bool pFlow::multiTriSurface::writeMultiTriSurface
(
iOstream& os
)const
{
if(!writeTriSurface(os)) return false;
os << lastPointIndex_;
os << lastVertexIndex_;
os << surfaceNames_;
return os.check(FUNCTION_NAME);
}
pFlow::multiTriSurface::multiTriSurface
multiTriSurface()
Definition: multiTriSurface.cpp:85
pFlow::VectorDual::syncViews
INLINE_FUNCTION_H void syncViews()
Definition: VectorDual.hpp:875
pFlow::multiTriSurface::readMultiTriSurface
bool readMultiTriSurface(iIstream &is)
Definition: multiTriSurface.cpp:211
pFlow::VectorDual::push_back
void push_back(const T &val)
Definition: VectorDual.hpp:741
pFlow::multiTriSurface::lastVertexIndex_
int32Field_HD lastVertexIndex_
Definition: multiTriSurface.hpp:43
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
FUNCTION_NAME
#define FUNCTION_NAME
Definition: pFlowMacros.hpp:29
pFlow::triSurface::area
const realVector_D & area() const
Definition: triSurface.hpp:194
pFlow::multiTriSurface::numSurfaces_
int32 numSurfaces_
Definition: multiTriSurface.hpp:56
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::VectorDual::capacity
INLINE_FUNCTION_H size_t capacity() const
Definition: VectorDual.hpp:396
pFlow::multiTriSurface::surfaceNumVertices_
int32Field_HD surfaceNumVertices_
Definition: multiTriSurface.hpp:52
pFlow::multiTriSurface::lastPointIndex_
int32Field_HD lastPointIndex_
Definition: multiTriSurface.hpp:40
pFlow::multiTriSurface::surfaceNames_
wordField surfaceNames_
Definition: multiTriSurface.hpp:46
pFlow::triSurface::points
const realx3Vector_D & points() const
Definition: triSurface.hpp:184
pFlow::IOstream::check
virtual bool check(const char *operation) const
Definition: IOstream.cpp:42
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::VectorDual::clear
INLINE_FUNCTION_H void clear()
Definition: VectorDual.hpp:448
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
multiTriSurface.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::multiTriSurface::pointsStartPos_
int32Vector_HD pointsStartPos_
Definition: multiTriSurface.hpp:50
pFlow::VectorDual::reallocate
INLINE_FUNCTION_H void reallocate(size_t cap)
Definition: VectorDual.hpp:419
pFlow::multiTriSurface::verticesStartPos_
int32Vector_HD verticesStartPos_
Definition: multiTriSurface.hpp:54
pFlow::VectorSingle::append
INLINE_FUNCTION_H bool append(const deviceViewType1D< T > &dVec, size_t numElems)
Definition: VectorSingle.hpp:672
pFlow::multiTriSurface::surfaceNumPoints_
int32Field_HD surfaceNumPoints_
Definition: multiTriSurface.hpp:48
pFlow::multiTriSurface::addTriSurface
bool addTriSurface(const word &name, const triSurface &tSurf)
Definition: multiTriSurface.cpp:96
LAMBDA_HD
#define LAMBDA_HD
Definition: pFlowMacros.hpp:54
pFlow::multiTriSurface::writeMultiTriSurface
bool writeMultiTriSurface(iOstream &os) const
Definition: multiTriSurface.cpp:232
pFlow::triSurface::vertices
const int32x3Vector_D & vertices() const
Definition: triSurface.hpp:214
pFlow::triSurface
Definition: triSurface.hpp:38
pFlow::multiTriSurface::calculateVars
void calculateVars()
Definition: multiTriSurface.cpp:24
pFlow::Vector
Definition: Vector.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53