diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/fieldSelector.hpp b/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/fieldSelector.hpp index f69025dc..3e850624 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/fieldSelector.hpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/fieldSelector.hpp @@ -33,7 +33,7 @@ Vector selectedFieldVals(const pStructSelector& selector, const word& name) { fatalErrorInFunction<< "Type of field "<< name << " in time repository does not match with"<< - FieldType::TYEPANME()<("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::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; + +} diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/pStructSelector.hpp b/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/pStructSelector.hpp index ef0882f1..84bf48e1 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/pStructSelector.hpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/pStructSelector/pStructSelector.hpp @@ -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 create(const pointStructure& pStruct, const dictionary& dict); + static + uniquePtr create( + const word& type, + const pointStructure& pStruct, + const dictionary& dict); }; diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.cpp b/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.cpp index 652a55cb..6a31e28b 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.cpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.cpp @@ -1,20 +1,18 @@ - template bool pFlow::selectorGeometric::selectPoints() { - selectedPoints_.clear(); - auto maskH = pStruct().activePointsMaskHost(); + auto maskH = pStruct().activePointsMaskHost(); const auto aRange = maskH.activeRange(); - auto pPos = pStruct().pointPositionHost(); - - for(uint32 i=aRange.start(); i::selectorGeometric( type_(dict.getVal("selector")), pRegion_(type_, dict.subDict(type_ + "Info")) { - - if(!selectPoints()) + if (!selectPoints()) { fatalExit; } } +template +pFlow::selectorGeometric::selectorGeometric( + const word& type, + const pointStructure& pStruct, + const dictionary& dict +) + : pStructSelector(type, pStruct, dict), + type_(type), + pRegion_(type_, dict) +{ + if (!selectPoints()) + { + fatalExit; + } +} \ No newline at end of file diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.hpp b/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.hpp index feb69d3f..d1a96541 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.hpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectorGeometric/selectorGeometric.hpp @@ -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 diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/selectorRandomPoints/selectorRandomPoints.cpp b/src/phasicFlow/structuredData/pointStructure/selectors/selectorRandomPoints/selectorRandomPoints.cpp index a0556a09..3a4a28f0 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/selectorRandomPoints/selectorRandomPoints.cpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectorRandomPoints/selectorRandomPoints.cpp @@ -2,56 +2,54 @@ O C enter of O O E ngineering and O O M ultiscale modeling of - OOOOOOO F luid flow + 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 + 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 + 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 "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; - - selectedPoints_.reserve (maxNum); + uint32 maxNum = number_ + 1; + + selectedPoints_.reserve(maxNum); selectedPoints_.clear(); - - uniformRandomUint32 intRand (begin_, end_); + uniformRandomUint32 intRand(begin_, end_); - uint32 n = 0; - uint32 iter = 0; - bool finished = false; + uint32 n = 0; + uint32 iter = 0; + bool finished = false; - Set selctedIndices; + Set 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 - { - fatalErrorInFunction<< "Could not find random indices in the range."<("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); - end_ = min(end_, static_cast(pStruct.size())); - number_ = max(number_,0u); - if(end_-begin_ < number_) +} + +pFlow::selectorRandomPoints::selectorRandomPoints( + const word& type, + const pointStructure& pStruct, + const dictionary& dict +) + : pStructSelector(type, pStruct, dict), + begin_(dict.getVal("begin")), + end_(dict.getValOrSet("end", pStruct.size())), + number_(dict.getValOrSet("number", 1)) +{ + begin_ = max(begin_, 1u); + end_ = min(end_, static_cast(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_<<" "<("begin") - ), - end_ - ( - dict.subDict("stridedRangeInfo").getValOrSet("end", pStruct.size()) - ), - stride_ - ( - dict.subDict("stridedRangeInfo").getValOrSet("stride", 1u) - ) + : selectorStridedRange( + "stridedRange", + pStruct, + dict.subDict("stridedRangeInfo") + ) { - begin_ = max(begin_,1u); - end_ = min(end_, static_cast(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("begin")), + end_(dict.getValOrSet("end", pStruct.size())), + stride_(dict.getValOrSet("stride", 1u)) +{ + begin_ = max(begin_, 1u); + end_ = min(end_, static_cast(pStruct.size())); + stride_ = max(stride_, 1u); selectAllPointsInRange(); } diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/selectorStridedRange/selectorStridedRange.hpp b/src/phasicFlow/structuredData/pointStructure/selectors/selectorStridedRange/selectorStridedRange.hpp index 23e36684..cb36ac98 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/selectorStridedRange/selectorStridedRange.hpp +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectorStridedRange/selectorStridedRange.hpp @@ -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