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<<
"Type of field "<< name << " in time repository does not match with"<<
FieldType::TYEPANME()<<endl;
FieldType::TYPENAME()<<endl;
fatalExit;
}

View File

@ -32,6 +32,16 @@ pFlow::pStructSelector::pStructSelector
pStruct_(pStruct)
{}
pFlow::pStructSelector::pStructSelector(
const word& ,
const pointStructure& pStruct,
const dictionary&
)
:
pStruct_(pStruct)
{
}
const pFlow::pointStructure& pFlow::pStructSelector::pStruct()const
{
return pStruct_;
@ -63,7 +73,6 @@ pFlow::pStructSelector::create(
const dictionary& dict
)
{
word selectorMethod = angleBracketsNames("selector", dict.getVal<word>("selector"));
if( dictionaryvCtorSelector_.search(selectorMethod) )
@ -74,7 +83,7 @@ pFlow::pStructSelector::create(
{
printKeys
(
fatalError << "Ctor Selector "<< selectorMethod << " dose not exist. \n"
fatalError << "Ctor Selector "<< selectorMethod << " does not exist. \n"
<<"Avaiable ones are: \n\n"
,
dictionaryvCtorSelector_
@ -83,3 +92,31 @@ pFlow::pStructSelector::create(
}
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
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));
/// 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
(
pStructSelector,
@ -55,6 +62,18 @@ public:
(pStruct, dict)
);
create_vCtor
(
pStructSelector,
word,
(
const word& type,
const pointStructure& pStruct,
const dictionary& dict
),
(type, pStruct, dict)
);
virtual ~pStructSelector() = default;
//// - Methods
@ -71,6 +90,11 @@ public:
static
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>
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++)
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);
}
@ -32,10 +30,24 @@ pFlow::selectorGeometric<GeomType>::selectorGeometric(
type_(dict.getVal<word>("selector")),
pRegion_(type_, dict.subDict(type_ + "Info"))
{
if(!selectPoints())
if (!selectPoints())
{
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 word& type,
const pointStructure& pStruct,
const dictionary& dict);
add_vCtor
(
pStructSelector,
@ -57,6 +62,13 @@ public:
dictionary
);
add_vCtor
(
pStructSelector,
selectorGeometric,
word
);
~selectorGeometric() override = default;
const uint32Vector& selectedPoints()const override

View File

@ -18,24 +18,22 @@ Licence:
-----------------------------------------------------------------------------*/
#include "selectorRandomPoints.hpp"
#include "Set.hpp"
#include "dictionary.hpp"
#include "uniformRandomUint32.hpp"
#include "Set.hpp"
bool pFlow::selectorRandomPoints::selectAllPointsInRange()
bool
pFlow::selectorRandomPoints::selectAllPointsInRange()
{
// to reduct allocations
uint32 maxNum = number_+1;
uint32 maxNum = number_ + 1;
selectedPoints_.reserve (maxNum);
selectedPoints_.reserve(maxNum);
selectedPoints_.clear();
uniformRandomUint32 intRand (begin_, end_);
uniformRandomUint32 intRand(begin_, end_);
uint32 n = 0;
uint32 iter = 0;
@ -43,15 +41,15 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
Set<uint32> selctedIndices;
while( iter < number_*100)
while (iter < number_ * 100)
{
uint32 newInd = intRand.randomNumber();
if( auto [it, inserted] = selctedIndices.insert(newInd); inserted )
if (auto [it, inserted] = selctedIndices.insert(newInd); inserted)
{
n++;
if(n == number_)
if (n == number_)
{
finished = true;
break;
@ -60,62 +58,61 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
iter++;
}
if(finished)
if (finished)
{
for(auto& ind:selctedIndices)
for (auto& ind : selctedIndices)
{
selectedPoints_.push_back(ind);
}
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;
}
}
pFlow::selectorRandomPoints::selectorRandomPoints
(
pFlow::selectorRandomPoints::selectorRandomPoints(
const pointStructure& pStruct,
const dictionary& dict
)
:
pStructSelector
(
pStruct, dict
),
begin_
(
dict.subDict("randomPointsInfo").getVal<uint32>("begin")
),
end_
(
dict.subDict("randomPointsInfo").getValOrSet("end", pStruct.size())
),
number_
(
dict.subDict("randomPointsInfo").getValOrSet("number", 1)
: selectorRandomPoints(
"randomPoints",
pStruct,
dict.subDict("randomPointsInfo")
)
{
begin_ = max(begin_,1u);
}
pFlow::selectorRandomPoints::selectorRandomPoints(
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_)
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 is greater than the interval defined by begine and end ["<<
begin_<<" "<<end_<<"), resetting it to "<<end_-begin_<<endl;
number_ = end_-begin_;
number_ = end_ - begin_;
}
if(!selectAllPointsInRange())
if (!selectAllPointsInRange())
{
fatalExit;
}

View File

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

View File

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

View File

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