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,11 +1,9 @@
template<typename GeomType>
bool
pFlow::selectorGeometric<GeomType>::selectPoints()
{
selectedPoints_.clear();
auto maskH = pStruct().activePointsMaskHost();
@ -32,10 +30,24 @@ pFlow::selectorGeometric<GeomType>::selectorGeometric(
type_(dict.getVal<word>("selector")),
pRegion_(type_, dict.subDict(type_ + "Info"))
{
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,14 +18,13 @@ 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;
@ -36,7 +35,6 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
uniformRandomUint32 intRand(begin_, end_);
uint32 n = 0;
uint32 iter = 0;
bool finished = false;
@ -60,7 +58,6 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
iter++;
}
if (finished)
{
for (auto& ind : selctedIndices)
@ -69,48 +66,48 @@ bool pFlow::selectorRandomPoints::selectAllPointsInRange()
}
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")
)
{
}
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_)
{
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_;
}

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,11 +18,11 @@ Licence:
-----------------------------------------------------------------------------*/
#include "selectorStridedRange.hpp"
#include "dictionary.hpp"
void pFlow::selectorStridedRange::selectAllPointsInRange()
void
pFlow::selectorStridedRange::selectAllPointsInRange()
{
// to reduct allocations
uint32 maxNum = (end_ - begin_) / stride_ + 2;
@ -37,28 +37,27 @@ void pFlow::selectorStridedRange::selectAllPointsInRange()
}
}
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")
)
{
}
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()));

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