pointStruture selectors refactored

- geometricRegion was added as selector(for now, box, sphere, and cylinder)
- base class upgraded and new method is added to allow accessing point positions in a vector
- selection is modified to account for inactive points when selection is done based on position
- file interface for particlesPhasicFlow changed.

- TODO
- Tutorials should be updated in new version.
This commit is contained in:
Hamidreza Norouzi 2024-04-13 13:13:53 -07:00
parent e395c379cb
commit 07bb9e9003
14 changed files with 271 additions and 41 deletions

View File

@ -90,9 +90,10 @@ structuredData/boundaries/boundaryReflective/boundaryReflective.cpp
structuredData/boundaries/boundaryList.cpp structuredData/boundaries/boundaryList.cpp
structuredData/pointStructure/pointStructure/pointStructure.cpp structuredData/pointStructure/pointStructure/pointStructure.cpp
structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp
structuredData/pointStructure/selectors/selectRange/selectRange.cpp structuredData/pointStructure/selectors/selectorStridedRange/selectorStridedRange.cpp
structuredData/pointStructure/selectors/selectRandom/selectRandom.cpp structuredData/pointStructure/selectors/selectorRandomPoints/selectorRandomPoints.cpp
structuredData/pointStructure/selectors/selectBox/selectBox.cpp structuredData/pointStructure/selectors/selectBox/selectBox.cpp
structuredData/pointStructure/selectors/selectorGeometric/selectorGeometrics.cpp
triSurface/subSurface.cpp triSurface/subSurface.cpp
triSurface/triSurface.cpp triSurface/triSurface.cpp

View File

@ -458,9 +458,6 @@ bool pFlow::internalPoints::read
return true; return true;
} }
bool pFlow::internalPoints::write bool pFlow::internalPoints::write
( (
iOstream& os, iOstream& os,

View File

@ -0,0 +1,60 @@
#ifndef __fieldSelector_hpp__
#define __fieldSelector_hpp__
#include "pStructSelector.hpp"
#include "pointFields.hpp"
#include "Time.hpp"
namespace pFlow
{
template<typename T>
inline
Vector<T> selectedFieldVals(const pStructSelector& selector, const word& name)
{
using FieldType = pointField_D<T>;
if(selector.selectedPoints().empty() )
{
return Vector<T>("selected-"+name);
}
if(!selector.pStruct().time().lookupObjectName(name))
{
fatalErrorInFunction<<
"Field "<< name << " does not exist in time repository"<<endl;
fatalExit;
}
if(
selector.pStruct().time().lookupObjectTypeName(name) !=
FieldType::TYPENAME())
{
fatalErrorInFunction<<
"Type of field "<< name << " in time repository does not match with"<<
FieldType::TYEPANME()<<endl;
fatalExit;
}
const FieldType& field = selector.pStruct().time().lookupObject<FieldType>(name);
auto fieldH = field.hostView();
const auto& selected = selector.selectedPoints();
Vector<T> selectedField(
"selected-"+name,
selected.size(),
selected.size(),
RESERVE());
for(uint32 i=0; i<selected.size(); i++)
{
selectedField[i] = fieldH[selected[i]];
}
return selectedField;
}
} // pFlow
#endif //__fieldSelector_hpp__

View File

@ -37,11 +37,34 @@ const pFlow::pointStructure& pFlow::pStructSelector::pStruct()const
return pStruct_; return pStruct_;
} }
pFlow::realx3Vector
pFlow::pStructSelector::selectedPointPositions() const
{
const auto& slctd = selectedPoints();
if(slctd.empty()) return realx3Vector("selectedPointPositions");
realx3Vector slctdPoints("selectedPointPositions", slctd.size());
auto pPos = pStruct().pointPositionHost();
for(uint32 i=0; i<slctd.size(); i++)
{
slctdPoints[i] = pPos[slctd[i]];
}
return slctdPoints;
}
pFlow::uniquePtr<pFlow::pStructSelector> pFlow::uniquePtr<pFlow::pStructSelector>
pFlow::pStructSelector::create(const pointStructure& pStruct, const dictionary& dict) pFlow::pStructSelector::create(
const pointStructure& pStruct,
const dictionary& dict
)
{ {
word selectorMethod = dict.getVal<word>("selector");
word selectorMethod = angleBracketsNames("selector", dict.getVal<word>("selector"));
if( dictionaryvCtorSelector_.search(selectorMethod) ) if( dictionaryvCtorSelector_.search(selectorMethod) )
{ {

View File

@ -18,7 +18,6 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#ifndef __pStructSelector_hpp__ #ifndef __pStructSelector_hpp__
#define __pStructSelector_hpp__ #define __pStructSelector_hpp__
@ -26,6 +25,7 @@ Licence:
#include "Vectors.hpp" #include "Vectors.hpp"
#include "virtualConstructor.hpp" #include "virtualConstructor.hpp"
namespace pFlow namespace pFlow
{ {
@ -62,16 +62,19 @@ public:
const pointStructure& pStruct()const; const pointStructure& pStruct()const;
virtual const uint32Vector& selectedPoinsts()const = 0; virtual const uint32Vector& selectedPoints()const = 0;
virtual uint32Vector& selectedPoinsts() = 0; virtual uint32Vector& selectedPoints() = 0;
realx3Vector selectedPointPositions()const;
static static
uniquePtr<pStructSelector> create(const pointStructure& pStruct, const dictionary& dict); uniquePtr<pStructSelector> create(const pointStructure& pStruct, const dictionary& dict);
}; };
} // pFlow } // pFlow

View File

@ -63,12 +63,12 @@ public:
//// - Methods //// - Methods
virtual const uint32Vector& selectedPoinsts()const override const uint32Vector& selectedPoints()const override
{ {
return selectedPoints_; return selectedPoints_;
} }
virtual uint32Vector& selectedPoinsts() override uint32Vector& selectedPoints() override
{ {
return selectedPoints_; return selectedPoints_;
} }

View File

@ -0,0 +1,41 @@
template<typename GeomType>
bool
pFlow::selectorGeometric<GeomType>::selectPoints()
{
selectedPoints_.clear();
auto maskH = pStruct().activePointsMaskHost();
const auto aRange = maskH.activeRange();
auto pPos = pStruct().pointPositionHost();
for(uint32 i=aRange.start(); i<aRange.end();i++)
{
if(maskH.isActive(i)&& pRegion_.isInside( pPos[i] ))
{
selectedPoints_.push_back(i);
}
}
return true;
}
template<typename GeomType>
pFlow::selectorGeometric<GeomType>::selectorGeometric(
const pointStructure& pStruct,
const dictionary& dict
)
: pStructSelector(pStruct, dict),
type_(dict.getVal<word>("selector")),
pRegion_(type_, dict.subDict(type_ + "Info"))
{
if(!selectPoints())
{
fatalExit;
}
}

View File

@ -0,0 +1,77 @@
/*------------------------------- 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 __selectorGeometric_hpp__
#define __selectorGeometric_hpp__
#include "pStructSelector.hpp"
#include "PeakableRegion.hpp"
#include "pointStructure.hpp"
#include "dictionary.hpp"
namespace pFlow
{
template<typename GeomType>
class selectorGeometric
:
public pStructSelector
{
private:
word type_;
PeakableRegion<GeomType> pRegion_;
uint32Vector selectedPoints_{"selectedPoints"};
bool selectPoints();
public:
TypeInfoTemplate11("selector", GeomType);
selectorGeometric(const pointStructure& pStruct, const dictionary& dict);
add_vCtor
(
pStructSelector,
selectorGeometric,
dictionary
);
~selectorGeometric() override = default;
const uint32Vector& selectedPoints()const override
{
return selectedPoints_;
}
uint32Vector& selectedPoints() override
{
return selectedPoints_;
}
};
}
#include "selectorGeometric.cpp"
#endif //__selectorGeometric_hpp__

View File

@ -0,0 +1,28 @@
/*------------------------------- 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 "selectorGeometric.hpp"
#include "box.hpp"
#include "sphere.hpp"
#include "cylinder.hpp"
template class pFlow::selectorGeometric<pFlow::box>;
template class pFlow::selectorGeometric<pFlow::sphere>;
template class pFlow::selectorGeometric<pFlow::cylinder>;

View File

@ -19,13 +19,13 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#include "selectRandom.hpp" #include "selectorRandomPoints.hpp"
#include "dictionary.hpp" #include "dictionary.hpp"
#include "uniformRandomUint32.hpp" #include "uniformRandomUint32.hpp"
#include "Set.hpp" #include "Set.hpp"
bool pFlow::selectRandom::selectAllPointsInRange() bool pFlow::selectorRandomPoints::selectAllPointsInRange()
{ {
// to reduct allocations // to reduct allocations
uint32 maxNum = number_+1; uint32 maxNum = number_+1;
@ -79,7 +79,7 @@ bool pFlow::selectRandom::selectAllPointsInRange()
} }
pFlow::selectRandom::selectRandom pFlow::selectorRandomPoints::selectorRandomPoints
( (
const pointStructure& pStruct, const pointStructure& pStruct,
const dictionary& dict const dictionary& dict
@ -91,15 +91,15 @@ pFlow::selectRandom::selectRandom
), ),
begin_ begin_
( (
dict.subDict("selectRandomInfo").getVal<uint32>("begin") dict.subDict("randomPointsInfo").getVal<uint32>("begin")
), ),
end_ end_
( (
dict.subDict("selectRandomInfo").getValOrSet("end", pStruct.size()) dict.subDict("randomPointsInfo").getValOrSet("end", pStruct.size())
), ),
number_ number_
( (
dict.subDict("selectRandomInfo").getValOrSet("number", 1) dict.subDict("randomPointsInfo").getValOrSet("number", 1)
) )
{ {
begin_ = max(begin_,1u); begin_ = max(begin_,1u);

View File

@ -31,11 +31,11 @@ namespace pFlow
class dictionary; class dictionary;
class selectRandom class selectorRandomPoints
: :
public pStructSelector public pStructSelector
{ {
protected: private:
uint32Vector selectedPoints_; uint32Vector selectedPoints_;
@ -53,28 +53,28 @@ protected:
public: public:
// - type info // - type info
TypeInfo("selectRandom"); TypeInfo("selector<randomPoints>");
selectRandom(const pointStructure& pStruct, const dictionary& dict); selectorRandomPoints(const pointStructure& pStruct, const dictionary& dict);
add_vCtor add_vCtor
( (
pStructSelector, pStructSelector,
selectRandom, selectorRandomPoints,
dictionary dictionary
); );
virtual ~selectRandom() = default; ~selectorRandomPoints() final = default;
//// - Methods //// - Methods
virtual const uint32Vector& selectedPoinsts()const override const uint32Vector& selectedPoints()const final
{ {
return selectedPoints_; return selectedPoints_;
} }
virtual uint32Vector& selectedPoinsts() override uint32Vector& selectedPoints() final
{ {
return selectedPoints_; return selectedPoints_;
} }

View File

@ -19,10 +19,10 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#include "selectRange.hpp" #include "selectorStridedRange.hpp"
#include "dictionary.hpp" #include "dictionary.hpp"
void pFlow::selectRange::selectAllPointsInRange() void pFlow::selectorStridedRange::selectAllPointsInRange()
{ {
// to reduct allocations // to reduct allocations
uint32 maxNum = (end_ - begin_)/stride_+2; uint32 maxNum = (end_ - begin_)/stride_+2;
@ -37,7 +37,7 @@ void pFlow::selectRange::selectAllPointsInRange()
} }
} }
pFlow::selectRange::selectRange pFlow::selectorStridedRange::selectorStridedRange
( (
const pointStructure& pStruct, const pointStructure& pStruct,
const dictionary& dict const dictionary& dict
@ -49,15 +49,15 @@ pFlow::selectRange::selectRange
), ),
begin_ begin_
( (
dict.subDict("selectRangeInfo").getVal<uint32>("begin") dict.subDict("stridedRangeInfo").getVal<uint32>("begin")
), ),
end_ end_
( (
dict.subDict("selectRangeInfo").getValOrSet<uint32>("end", pStruct.size()) dict.subDict("stridedRangeInfo").getValOrSet<uint32>("end", pStruct.size())
), ),
stride_ stride_
( (
dict.subDict("selectRangeInfo").getValOrSet<uint32>("stride", 1u) dict.subDict("stridedRangeInfo").getValOrSet<uint32>("stride", 1u)
) )
{ {
begin_ = max(begin_,1u); begin_ = max(begin_,1u);

View File

@ -31,11 +31,11 @@ namespace pFlow
class dictionary; class dictionary;
class selectRange class selectorStridedRange
: :
public pStructSelector public pStructSelector
{ {
protected: private:
uint32Vector selectedPoints_; uint32Vector selectedPoints_;
@ -53,28 +53,28 @@ protected:
public: public:
// - type info // - type info
TypeInfo("selectRange"); TypeInfo("selector<stridedRange>");
selectRange(const pointStructure& pStruct, const dictionary& dict); selectorStridedRange(const pointStructure& pStruct, const dictionary& dict);
add_vCtor add_vCtor
( (
pStructSelector, pStructSelector,
selectRange, selectorStridedRange,
dictionary dictionary
); );
virtual ~selectRange() = default; ~selectorStridedRange() final = default;
//// - Methods //// - Methods
virtual const uint32Vector& selectedPoinsts()const override const uint32Vector& selectedPoints()const final
{ {
return selectedPoints_; return selectedPoints_;
} }
virtual uint32Vector& selectedPoinsts() override uint32Vector& selectedPoints() final
{ {
return selectedPoints_; return selectedPoints_;
} }

View File

@ -37,7 +37,7 @@ bool applySelector(systemControl& control, const pointStructure& pStruct, const
auto selector = pStructSelector::create(pStruct, selDict); auto selector = pStructSelector::create(pStruct, selDict);
auto& selected = selector().selectedPoinsts(); auto& selected = selector().selectedPoints();
uint32IndexContainer selIndex(selected.data(), selected.size()); uint32IndexContainer selIndex(selected.data(), selected.size());