pointStructure selector

- selectors for pointStructure are updated and geometric selector is added. With this, any geometric region can also be used as a selector region for particles.
- Also, a pointField selector is added as a free funtion that can be used anywhere that is needed.
This commit is contained in:
Hamidreza Norouzi 2024-04-15 13:14:29 -07:00
parent 07bb9e9003
commit d6798b5097
9 changed files with 218 additions and 114 deletions

View File

@ -33,7 +33,7 @@ Vector<T> selectedFieldVals(const pStructSelector& selector, const word& name)
{ {
fatalErrorInFunction<< fatalErrorInFunction<<
"Type of field "<< name << " in time repository does not match with"<< "Type of field "<< name << " in time repository does not match with"<<
FieldType::TYEPANME()<<endl; FieldType::TYPENAME()<<endl;
fatalExit; fatalExit;
} }

View File

@ -32,6 +32,16 @@ pFlow::pStructSelector::pStructSelector
pStruct_(pStruct) pStruct_(pStruct)
{} {}
pFlow::pStructSelector::pStructSelector(
const word& ,
const pointStructure& pStruct,
const dictionary&
)
:
pStruct_(pStruct)
{
}
const pFlow::pointStructure& pFlow::pStructSelector::pStruct()const const pFlow::pointStructure& pFlow::pStructSelector::pStruct()const
{ {
return pStruct_; return pStruct_;
@ -63,7 +73,6 @@ pFlow::pStructSelector::create(
const dictionary& dict const dictionary& dict
) )
{ {
word selectorMethod = angleBracketsNames("selector", dict.getVal<word>("selector")); word selectorMethod = angleBracketsNames("selector", dict.getVal<word>("selector"));
if( dictionaryvCtorSelector_.search(selectorMethod) ) if( dictionaryvCtorSelector_.search(selectorMethod) )
@ -74,7 +83,7 @@ pFlow::pStructSelector::create(
{ {
printKeys printKeys
( (
fatalError << "Ctor Selector "<< selectorMethod << " dose not exist. \n" fatalError << "Ctor Selector "<< selectorMethod << " does not exist. \n"
<<"Avaiable ones are: \n\n" <<"Avaiable ones are: \n\n"
, ,
dictionaryvCtorSelector_ dictionaryvCtorSelector_
@ -83,3 +92,31 @@ pFlow::pStructSelector::create(
} }
return nullptr; return nullptr;
} }
pFlow::uniquePtr<pFlow::pStructSelector>
pFlow::pStructSelector::create(
const word& type,
const pointStructure& pStruct,
const dictionary& dict
)
{
word selectorMethod = angleBracketsNames("selector", type);
if( wordvCtorSelector_.search(selectorMethod) )
{
return wordvCtorSelector_[selectorMethod] (type, pStruct, dict);
}
else
{
printKeys
(
fatalError << "Ctor Selector "<< selectorMethod << " does not exist. \n"
<<"Avaiable ones are: \n\n"
,
wordvCtorSelector_
);
fatalExit;
}
return nullptr;
}

View File

@ -44,9 +44,16 @@ public:
// - type info // - type info
TypeInfo("pStructSelector"); TypeInfo("pStructSelector");
/// the dictionary contains the selector keyword and another dictionary which is
/// used for creating selector
pStructSelector(const pointStructure& pStruct, const dictionary& UNUSED(dict)); pStructSelector(const pointStructure& pStruct, const dictionary& UNUSED(dict));
/// construct using selector type and a dictionary that contains info of selector
pStructSelector(
const word& type,
const pointStructure& pStruct,
const dictionary& UNUSED(dict));
create_vCtor create_vCtor
( (
pStructSelector, pStructSelector,
@ -55,6 +62,18 @@ public:
(pStruct, dict) (pStruct, dict)
); );
create_vCtor
(
pStructSelector,
word,
(
const word& type,
const pointStructure& pStruct,
const dictionary& dict
),
(type, pStruct, dict)
);
virtual ~pStructSelector() = default; virtual ~pStructSelector() = default;
//// - Methods //// - Methods
@ -71,6 +90,11 @@ public:
static static
uniquePtr<pStructSelector> create(const pointStructure& pStruct, const dictionary& dict); uniquePtr<pStructSelector> create(const pointStructure& pStruct, const dictionary& dict);
static
uniquePtr<pStructSelector> create(
const word& type,
const pointStructure& pStruct,
const dictionary& dict);
}; };

View File

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

View File

@ -50,6 +50,11 @@ public:
selectorGeometric(const pointStructure& pStruct, const dictionary& dict); selectorGeometric(const pointStructure& pStruct, const dictionary& dict);
selectorGeometric(
const word& type,
const pointStructure& pStruct,
const dictionary& dict);
add_vCtor add_vCtor
( (
pStructSelector, pStructSelector,
@ -57,6 +62,13 @@ public:
dictionary dictionary
); );
add_vCtor
(
pStructSelector,
selectorGeometric,
word
);
~selectorGeometric() override = default; ~selectorGeometric() override = default;
const uint32Vector& selectedPoints()const override const uint32Vector& selectedPoints()const override

View File

@ -18,40 +18,38 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#include "selectorRandomPoints.hpp" #include "selectorRandomPoints.hpp"
#include "Set.hpp"
#include "dictionary.hpp" #include "dictionary.hpp"
#include "uniformRandomUint32.hpp" #include "uniformRandomUint32.hpp"
#include "Set.hpp"
bool
bool pFlow::selectorRandomPoints::selectAllPointsInRange() pFlow::selectorRandomPoints::selectAllPointsInRange()
{ {
// to reduct allocations // to reduct allocations
uint32 maxNum = number_+1; uint32 maxNum = number_ + 1;
selectedPoints_.reserve (maxNum); selectedPoints_.reserve(maxNum);
selectedPoints_.clear(); selectedPoints_.clear();
uniformRandomUint32 intRand (begin_, end_); uniformRandomUint32 intRand(begin_, end_);
uint32 n = 0;
uint32 iter = 0;
bool finished = false;
uint32 n = 0; Set<uint32> selctedIndices;
uint32 iter = 0;
bool finished = false;
Set<uint32> selctedIndices; while (iter < number_ * 100)
while( iter < number_*100)
{ {
uint32 newInd = intRand.randomNumber(); uint32 newInd = intRand.randomNumber();
if( auto [it, inserted] = selctedIndices.insert(newInd); inserted ) if (auto [it, inserted] = selctedIndices.insert(newInd); inserted)
{ {
n++; n++;
if(n == number_) if (n == number_)
{ {
finished = true; finished = true;
break; break;
@ -60,62 +58,61 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
iter++; iter++;
} }
if (finished)
if(finished)
{ {
for(auto& ind:selctedIndices) for (auto& ind : selctedIndices)
{ {
selectedPoints_.push_back(ind); selectedPoints_.push_back(ind);
} }
return true; return true;
}
}else else
{ {
fatalErrorInFunction<< "Could not find random indices in the range."<<endl; fatalErrorInFunction << "Could not find random indices in the range."
<< endl;
return false; return false;
} }
} }
pFlow::selectorRandomPoints::selectorRandomPoints pFlow::selectorRandomPoints::selectorRandomPoints(
( const pointStructure& pStruct,
const pointStructure& pStruct, const dictionary& dict
const dictionary& dict
) )
: : selectorRandomPoints(
pStructSelector "randomPoints",
( pStruct,
pStruct, dict dict.subDict("randomPointsInfo")
), )
begin_
(
dict.subDict("randomPointsInfo").getVal<uint32>("begin")
),
end_
(
dict.subDict("randomPointsInfo").getValOrSet("end", pStruct.size())
),
number_
(
dict.subDict("randomPointsInfo").getValOrSet("number", 1)
)
{ {
begin_ = max(begin_,1u); }
end_ = min(end_, static_cast<uint32>(pStruct.size()));
number_ = max(number_,0u); pFlow::selectorRandomPoints::selectorRandomPoints(
if(end_-begin_ < number_) const word& type,
const pointStructure& pStruct,
const dictionary& dict
)
: pStructSelector(type, pStruct, dict),
begin_(dict.getVal<uint32>("begin")),
end_(dict.getValOrSet("end", pStruct.size())),
number_(dict.getValOrSet("number", 1))
{
begin_ = max(begin_, 1u);
end_ = min(end_, static_cast<uint32>(pStruct.size()));
number_ = max(number_, 0u);
if (end_ - begin_ < number_)
{ {
warningInFunction
<< "In dictionary " << dict.globalName()
<< " number is greater than the interval defined by begine and end ["
<< begin_ << " " << end_ << "), resetting it to " << end_ - begin_
<< endl;
warningInFunction<< "In dictionary " << dict.globalName()<< number_ = end_ - begin_;
" number is greater than the interval defined by begine and end ["<<
begin_<<" "<<end_<<"), resetting it to "<<end_-begin_<<endl;
number_ = end_-begin_;
} }
if(!selectAllPointsInRange()) if (!selectAllPointsInRange())
{ {
fatalExit; fatalExit;
} }

View File

@ -58,6 +58,11 @@ public:
selectorRandomPoints(const pointStructure& pStruct, const dictionary& dict); selectorRandomPoints(const pointStructure& pStruct, const dictionary& dict);
selectorRandomPoints(
const word& type,
const pointStructure& pStruct,
const dictionary& UNUSED(dict));
add_vCtor add_vCtor
( (
pStructSelector, pStructSelector,
@ -65,6 +70,12 @@ public:
dictionary dictionary
); );
add_vCtor
(
pStructSelector,
selectorRandomPoints,
word
);
~selectorRandomPoints() final = default; ~selectorRandomPoints() final = default;
//// - Methods //// - Methods

View File

@ -18,51 +18,50 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#include "selectorStridedRange.hpp" #include "selectorStridedRange.hpp"
#include "dictionary.hpp" #include "dictionary.hpp"
void pFlow::selectorStridedRange::selectAllPointsInRange() void
pFlow::selectorStridedRange::selectAllPointsInRange()
{ {
// to reduct allocations // to reduct allocations
uint32 maxNum = (end_ - begin_)/stride_+2; uint32 maxNum = (end_ - begin_) / stride_ + 2;
selectedPoints_.reserve (maxNum); selectedPoints_.reserve(maxNum);
selectedPoints_.clear(); selectedPoints_.clear();
for(uint32 i = begin_; i<end_; i+= stride_) for (uint32 i = begin_; i < end_; i += stride_)
{ {
selectedPoints_.push_back(i); selectedPoints_.push_back(i);
} }
} }
pFlow::selectorStridedRange::selectorStridedRange pFlow::selectorStridedRange::selectorStridedRange(
( const pointStructure& pStruct,
const pointStructure& pStruct, const dictionary& dict
const dictionary& dict
) )
: : selectorStridedRange(
pStructSelector "stridedRange",
( pStruct,
pStruct, dict dict.subDict("stridedRangeInfo")
), )
begin_
(
dict.subDict("stridedRangeInfo").getVal<uint32>("begin")
),
end_
(
dict.subDict("stridedRangeInfo").getValOrSet<uint32>("end", pStruct.size())
),
stride_
(
dict.subDict("stridedRangeInfo").getValOrSet<uint32>("stride", 1u)
)
{ {
begin_ = max(begin_,1u); }
end_ = min(end_, static_cast<uint32>(pStruct.size()));
stride_ = max(stride_,1u); pFlow::selectorStridedRange::selectorStridedRange(
const word& type,
const pointStructure& pStruct,
const dictionary& dict
)
: pStructSelector(type, pStruct, dict),
begin_(dict.getVal<uint32>("begin")),
end_(dict.getValOrSet<uint32>("end", pStruct.size())),
stride_(dict.getValOrSet<uint32>("stride", 1u))
{
begin_ = max(begin_, 1u);
end_ = min(end_, static_cast<uint32>(pStruct.size()));
stride_ = max(stride_, 1u);
selectAllPointsInRange(); selectAllPointsInRange();
} }

View File

@ -58,6 +58,11 @@ public:
selectorStridedRange(const pointStructure& pStruct, const dictionary& dict); selectorStridedRange(const pointStructure& pStruct, const dictionary& dict);
selectorStridedRange(
const word& type,
const pointStructure& pStruct,
const dictionary& dict);
add_vCtor add_vCtor
( (
pStructSelector, pStructSelector,
@ -65,6 +70,13 @@ public:
dictionary dictionary
); );
add_vCtor
(
pStructSelector,
selectorStridedRange,
word
);
~selectorStridedRange() final = default; ~selectorStridedRange() final = default;
//// - Methods //// - Methods