# PhasicFlow: src/phasicFlow/structuredData/pointStructure/pointStructure.hpp Source File

pointStructure.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 __pointStructure_hpp__
#define __pointStructure_hpp__
#include "Vectors.hpp"
#include "VectorSingles.hpp"
#include "VectorDuals.hpp"
#include "Fields.hpp"
#include "eventSubscriber.hpp"
#include "indexContainer.hpp"
namespace pFlow
{
//forward
class box;
class setFieldList;
class repository;
class pointStructure
:
public eventSubscriber
{
public:
enum PointFlag: int8
{
DELETED = -1,
ACTIVE = 1
};
inline static const size_t maxSizeDefault_ = 10000;
class activePointsDevice
{
protected:
ViewType1D<int8> flag_;
bool allActive_;
range activeRange_;
public:
INLINE_FUNCTION_H
activePointsDevice(bool allActive, range active, const ViewType1D<int8>& flag)
:
flag_(flag),
allActive_(allActive),
activeRange_(active)
{}
INLINE_FUNCTION_HD
activePointsDevice(const activePointsDevice&) = default;
INLINE_FUNCTION_HD
activePointsDevice& operator=(const activePointsDevice&) = default;
INLINE_FUNCTION_HD
bool operator()(int32 i)const {
if(i<activeRange_.second && flag_[i] == 1)return true;
return false;
}
INLINE_FUNCTION_HD
auto activeRange()const {
return activeRange_;
}
INLINE_FUNCTION_HD
auto allActive()const {
return allActive_;
}
};
class activePointsHost
{
protected:
ViewType1D<int8, HostSpace> flag_;
bool allActive_;
range activeRange_;
public:
INLINE_FUNCTION_H
activePointsHost(bool allActive, range active, const ViewType1D<int8, HostSpace>& flag)
:
flag_(flag),
allActive_(allActive),
activeRange_(active){}
INLINE_FUNCTION_H
activePointsHost(const activePointsHost&) = default;
INLINE_FUNCTION_H
activePointsHost& operator=(const activePointsHost&) = default;
INLINE_FUNCTION_H
bool operator()(int32 i)const {
if(i <activeRange_.second && flag_[i] == PointFlag::ACTIVE)return true;
return false;
}
INLINE_FUNCTION_H
auto activeRange()const{
return activeRange_;
}
INLINE_FUNCTION_H
bool allActive()const {
return allActive_;
}
};
protected:
// number of points / size of structure
size_t numPoints_ = 0;
// maximum number of points
size_t maxPoints_ = maxSizeDefault_;
// flag of points on device
int8Field_HD pointFlag_;
// position of points on device
realx3Field_D pointPosition_;
// number of active points
size_t numActivePoints_ = 0;
// index range of active points (half-open range)
range activeRange_;
// - index vector for points to be inserted
int32IndexContainer tobeInsertedIndex_;
FUNCTION_H
bool evaluatePointStructure();
FUNCTION_H
void setNumMaxPoints();
// - access to pointPosition
FUNCTION_H
realx3Field_D& pointPosition();
// - access to pointFlag
FUNCTION_H
int8Field_HD& pointFlag();
FUNCTION_H
uniquePtr<int32IndexContainer>
getNewPointsIndices(int32 numNewPoints)const;
public:
friend class dynamicPointStructure;
// - type info
TypeInfo("pointStructure");
// - an empty pointStructure, good for reading from file
pointStructure();
// - construct from components
pointStructure(const int8Vector& flgVec, const realx3Vector& posVec);
// - construct from point positions, assume all points are active
pointStructure(const realx3Vector& posVec);
// - copy construct
//
// should be changed, may causs undefined behavior
pointStructure(const pointStructure&) = default;
// - no move construct
pointStructure(pointStructure&&) = delete;
// - copy assignment
//
// should be changed, may causs undefined behavior
pointStructure& operator=(const pointStructure&) = default;
// - no move assignment
pointStructure& operator=(pointStructure&&) = delete;
// - destructor
virtual ~pointStructure() = default;
activePointsDevice activePointsMaskD()const
{
return activePointsDevice(
this->allActive(),
activeRange(),
pointFlag_.deviceVectorAll()
);
}
activePointsHost activePointsMaskH()const
{
return activePointsHost(
this->allActive(),
activeRange(),
pointFlag_.hostVectorAll()
);
}
// - const access pointPosition
FUNCTION_H
const realx3Field_D& pointPosition()const;
// - const access to pointFlag
FUNCTION_H
const int8Field_HD& pointFlag()const;
INLINE_FUNCTION_H
auto pointPositionHostAll()
{
return pointPosition_.hostVectorAll();
}
// - size of data structure
FUNCTION_H
label size()const;
// - maximum capacity of data structure
FUNCTION_H
label capacity()const;
// - number of active points
FUNCTION_H
label numActive() const;
// - if all points are active
FUNCTION_H
bool allActive()const;
INLINE_FUNCTION_H
range activeRange()const
{
return activeRange_;
}
INLINE_FUNCTION_H
bool isActive(label i)const
{
return pointFlag_[i] == ACTIVE;
}
FUNCTION_H
size_t markDeleteOutOfBox(const box& domain);
// - update data structure by removing the marked points
// Notifies all the fields that are built based on this data structure
// and then apply removing to the pointPosition_ and pointFlag_
FUNCTION_H
virtual bool updateForDelete();
// - const access to points to be newly inserted
FUNCTION_H
auto insertedPointIndex()const
{
return tobeInsertedIndex_;
}
FUNCTION_H
auto insertedPointIndexH()const
{
return tobeInsertedIndex_.hostView();
}
FUNCTION_H
auto insertedPointIndexD()const
{
return tobeInsertedIndex_.deviceView();
}
// - update data structure by inserting/setting new points
// Notifies all the fields in the registered list of data structure
// and exclude the fields that re in the exclusionList
// retrun nullptr if it fails
FUNCTION_H
virtual uniquePtr<int32IndexContainer> insertPoints(
const realx3Vector& pos,
const setFieldList& setField,
repository& owner,
const List<eventObserver*>& exclusionList={nullptr}
);
// - read pointStructure from is
FUNCTION_H
bool readPointStructure(iIstream& is);
// - write pointStructure to os
FUNCTION_H
bool writePointStructure(iOstream& os)const;
// - read
FUNCTION_H
bool read(iIstream& is)
{
return readPointStructure(is);
}
// - write
FUNCTION_H
bool write(iOstream& os)const
{
return writePointStructure(os);
}
};
} // pFlow
#endif //__pointStructure_hpp__
pFlow::pointStructure::evaluatePointStructure
FUNCTION_H bool evaluatePointStructure()
Definition: pointStructure.cpp:30
pFlow::pointStructure::activePointsDevice::allActive_
bool allActive_
Definition: pointStructure.hpp:64
pFlow::pointStructure::activePointsHost
Definition: pointStructure.hpp:102
pFlow::List
Definition: List.hpp:39
pFlow::pointStructure::activePointsHost::allActive
INLINE_FUNCTION_H bool allActive() const
Definition: pointStructure.hpp:139
pFlow::pointStructure::numActivePoints_
size_t numActivePoints_
Definition: pointStructure.hpp:161
pFlow::eventSubscriber
Definition: eventSubscriber.hpp:34
pFlow::pointStructure::maxPoints_
size_t maxPoints_
Definition: pointStructure.hpp:152
pFlow::pointStructure::PointFlag
PointFlag
Definition: pointStructure.hpp:50
pFlow::pointStructure::pointPosition_
realx3Field_D pointPosition_
Definition: pointStructure.hpp:158
pFlow::pointStructure::DELETED
@ DELETED
Definition: pointStructure.hpp:52
pFlow::pointStructure::activePointsDevice::allActive
INLINE_FUNCTION_HD auto allActive() const
Definition: pointStructure.hpp:96
pFlow::pointStructure::activePointsDevice::activeRange_
range activeRange_
Definition: pointStructure.hpp:66
pFlow::pointStructure::activePointsDevice::flag_
ViewType1D< int8 > flag_
Definition: pointStructure.hpp:62
pFlow::pointStructure::write
FUNCTION_H bool write(iOstream &os) const
Definition: pointStructure.hpp:354
pFlow::VectorDual::hostVectorAll
INLINE_FUNCTION_H hostViewType & hostVectorAll()
Definition: VectorDual.hpp:345
pFlow::pointStructure::activePointsMaskH
activePointsHost activePointsMaskH() const
Definition: pointStructure.hpp:241
pFlow::VectorSingle::hostVectorAll
const INLINE_FUNCTION_H auto hostVectorAll() const
Definition: VectorSingle.hpp:320
pFlow::pointStructure::insertedPointIndexD
FUNCTION_H auto insertedPointIndexD() const
Definition: pointStructure.hpp:317
pFlow::pointStructure::markDeleteOutOfBox
FUNCTION_H size_t markDeleteOutOfBox(const box &domain)
Definition: pointStructure.cpp:235
pFlow::pointStructure::pointFlag
FUNCTION_H int8Field_HD & pointFlag()
Definition: pointStructure.cpp:70
pFlow::pointStructure::readPointStructure
FUNCTION_H bool readPointStructure(iIstream &is)
Definition: pointStructure.cpp:389
pFlow::pointStructure::activeRange
INLINE_FUNCTION_H range activeRange() const
Definition: pointStructure.hpp:281
pFlow::pointStructure::pointPositionHostAll
INLINE_FUNCTION_H auto pointPositionHostAll()
Definition: pointStructure.hpp:259
pFlow::pointStructure::activePointsHost::activePointsHost
INLINE_FUNCTION_H activePointsHost(bool allActive, range active, const ViewType1D< int8, HostSpace > &flag)
Definition: pointStructure.hpp:115
pFlow::pointStructure::ACTIVE
@ ACTIVE
Definition: pointStructure.hpp:53
pFlow::pointStructure::writePointStructure
FUNCTION_H bool writePointStructure(iOstream &os) const
Definition: pointStructure.cpp:417
Vectors.hpp
pFlow::pointStructure::operator=
pointStructure & operator=(const pointStructure &)=default
pFlow::Field< VectorDual, int8 >
pFlow::pointStructure::activePointsHost::allActive_
bool allActive_
Definition: pointStructure.hpp:108
pFlow::pointStructure::maxSizeDefault_
static const size_t maxSizeDefault_
Definition: pointStructure.hpp:57
pFlow::dynamicPointStructure
Definition: dynamicPointStructure.hpp:33
pFlow::pointStructure::insertedPointIndex
FUNCTION_H auto insertedPointIndex() const
Definition: pointStructure.hpp:305
pFlow::pointStructure::updateForDelete
virtual FUNCTION_H bool updateForDelete()
Definition: pointStructure.cpp:291
pFlow::pointStructure::activePointsDevice
Definition: pointStructure.hpp:59
pFlow::pointStructure::pointPosition
FUNCTION_H realx3Field_D & pointPosition()
Definition: pointStructure.cpp:64
pFlow::pointStructure::numActive
FUNCTION_H label numActive() const
Definition: pointStructure.cpp:222
pFlow::pointStructure::activePointsHost::activeRange
INLINE_FUNCTION_H auto activeRange() const
Definition: pointStructure.hpp:134
pFlow
Definition: demComponent.hpp:28
VectorSingles.hpp
pFlow::pointStructure::isActive
INLINE_FUNCTION_H bool isActive(label i) const
Definition: pointStructure.hpp:287
FUNCTION_H
#define FUNCTION_H
Definition: pFlowMacros.hpp:58
pFlow::pointStructure::allActive
FUNCTION_H bool allActive() const
Definition: pointStructure.cpp:228
pFlow::VectorDual::deviceVectorAll
INLINE_FUNCTION_H deviceViewType & deviceVectorAll()
Definition: VectorDual.hpp:335
pFlow::pointStructure::activePointsDevice::operator()
INLINE_FUNCTION_HD bool operator()(int32 i) const
Definition: pointStructure.hpp:85
pFlow::pointStructure
Definition: pointStructure.hpp:44
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::pointStructure::~pointStructure
virtual ~pointStructure()=default
pFlow::indexContainer::hostView
const HostViewType & hostView() const
Definition: indexContainer.hpp:143
pFlow::pointStructure::activePointsDevice::activeRange
INLINE_FUNCTION_HD auto activeRange() const
Definition: pointStructure.hpp:91
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::setFieldList
Definition: setFieldList.hpp:32
Fields.hpp
pFlow::pointStructure::activePointsHost::flag_
ViewType1D< int8, HostSpace > flag_
Definition: pointStructure.hpp:106
pFlow::pointStructure::insertedPointIndexH
FUNCTION_H auto insertedPointIndexH() const
Definition: pointStructure.hpp:311
pFlow::pointStructure::getNewPointsIndices
FUNCTION_H uniquePtr< int32IndexContainer > getNewPointsIndices(int32 numNewPoints) const
Definition: pointStructure.cpp:76
pFlow::pointStructure::activeRange_
range activeRange_
Definition: pointStructure.hpp:164
INLINE_FUNCTION_H
#define INLINE_FUNCTION_H
Definition: pFlowMacros.hpp:53
pFlow::pointStructure::activePointsHost::operator=
INLINE_FUNCTION_H activePointsHost & operator=(const activePointsHost &)=default
pFlow::pointStructure::activePointsHost::activeRange_
range activeRange_
Definition: pointStructure.hpp:110
pFlow::pointStructure::read
FUNCTION_H bool read(iIstream &is)
Definition: pointStructure.hpp:347
pFlow::pointStructure::activePointsDevice::activePointsDevice
INLINE_FUNCTION_H activePointsDevice(bool allActive, range active, const ViewType1D< int8 > &flag)
Definition: pointStructure.hpp:71
pFlow::pointStructure::capacity
FUNCTION_H label capacity() const
Definition: pointStructure.cpp:216
pFlow::pointStructure::activePointsDevice::operator=
INLINE_FUNCTION_HD activePointsDevice & operator=(const activePointsDevice &)=default
pFlow::pointStructure::tobeInsertedIndex_
int32IndexContainer tobeInsertedIndex_
Definition: pointStructure.hpp:167
pFlow::box
Definition: box.hpp:32
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
eventSubscriber.hpp
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::ViewType1D
Kokkos::View< T *, properties... > ViewType1D
Definition: KokkosTypes.hpp:62
pFlow::pointStructure::insertPoints
virtual FUNCTION_H uniquePtr< int32IndexContainer > insertPoints(const realx3Vector &pos, const setFieldList &setField, repository &owner, const List< eventObserver * > &exclusionList={nullptr})
Definition: pointStructure.cpp:300
pFlow::pointStructure::pointStructure
pointStructure()
Definition: pointStructure.cpp:142
pFlow::pointStructure::activePointsMaskD
activePointsDevice activePointsMaskD() const
Definition: pointStructure.hpp:232
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::repository
Definition: repository.hpp:34
pFlow::pointStructure::size
FUNCTION_H label size() const
Definition: pointStructure.cpp:210
pFlow::pointStructure::activePointsHost::operator()
INLINE_FUNCTION_H bool operator()(int32 i) const
Definition: pointStructure.hpp:128
pFlow::pointStructure::numPoints_
size_t numPoints_
Definition: pointStructure.hpp:149
INLINE_FUNCTION_HD
#define INLINE_FUNCTION_HD
Definition: pFlowMacros.hpp:51
pFlow::pointStructure::TypeInfo
TypeInfo("pointStructure")
pFlow::Vector
Definition: Vector.hpp:46
pFlow::iOstream
Definition: iOstream.hpp:53
indexContainer.hpp
pFlow::range
kPair< int, int > range
Definition: KokkosTypes.hpp:54
VectorDuals.hpp
pFlow::indexContainer< int32 >
pFlow::indexContainer::deviceView
const DeviceViewType & deviceView() const
Definition: indexContainer.hpp:148
pFlow::pointStructure::setNumMaxPoints
FUNCTION_H void setNumMaxPoints()
Definition: pointStructure.cpp:57
pFlow::pointStructure::pointFlag_
int8Field_HD pointFlag_
Definition: pointStructure.hpp:155