From fb3763004df2679c3d4775871b5cf3b711d823ca Mon Sep 17 00:00:00 2001 From: hamidrezanorouzi Date: Thu, 29 Sep 2022 17:52:37 +0330 Subject: [PATCH 1/2] bug fixes for builiding with float for postpropcessPhasicFlow --- utilities/postprocessPhasicFlow/ProcessField.H | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utilities/postprocessPhasicFlow/ProcessField.H b/utilities/postprocessPhasicFlow/ProcessField.H index 702ef866..56e10b11 100644 --- a/utilities/postprocessPhasicFlow/ProcessField.H +++ b/utilities/postprocessPhasicFlow/ProcessField.H @@ -110,13 +110,13 @@ public: }else if(action() == "average") { - pointField_H oneFld(field_.pStruct(), 1.0, 1.0); + pointField_H oneFld(field_.pStruct(), static_cast(1.0), static_cast(1.0)); denomerator = sumOp(oneFld, this->pointToCell()); }else if(action() == "averageMask") { - pointField_H oneFld(field_.pStruct(), 1.0, 1.0); + pointField_H oneFld(field_.pStruct(), static_cast(1.0), static_cast(1.0)); denomerator = sumMaksOp(oneFld, this->pointToCell(), incMask); }else From 77408f16afd255bb2ed2a8daa730a50ce167da3e Mon Sep 17 00:00:00 2001 From: hamidrezanorouzi Date: Fri, 30 Sep 2022 11:43:19 +0330 Subject: [PATCH 2/2] change of selctors, cmake config for float compilation --- CMakeLists.txt | 1 + phasicFlowConfig.H.in | 3 +- src/phasicFlow/CMakeLists.txt | 5 +- .../random/randomInt32/uniformRandomInt32.H | 79 ++++++++++++ .../boxAll.C => selectBox/selectBox.C} | 8 +- .../boxAll.H => selectBox/selectBox.H} | 14 +- .../selectors/selectRandom/selectRandom.C | 122 ++++++++++++++++++ .../selectors/selectRandom/selectRandom.H | 87 +++++++++++++ .../rangeAll.C => selectRange/selectRange.C} | 12 +- .../rangeAll.H => selectRange/selectRange.H} | 14 +- .../types/basicTypes/builtinTypes.H | 9 +- 11 files changed, 325 insertions(+), 29 deletions(-) create mode 100644 src/phasicFlow/random/randomInt32/uniformRandomInt32.H rename src/phasicFlow/structuredData/pointStructure/selectors/{boxAll/boxAll.C => selectBox/selectBox.C} (91%) rename src/phasicFlow/structuredData/pointStructure/selectors/{boxAll/boxAll.H => selectBox/selectBox.H} (88%) create mode 100644 src/phasicFlow/structuredData/pointStructure/selectors/selectRandom/selectRandom.C create mode 100644 src/phasicFlow/structuredData/pointStructure/selectors/selectRandom/selectRandom.H rename src/phasicFlow/structuredData/pointStructure/selectors/{rangeAll/rangeAll.C => selectRange/selectRange.C} (83%) rename src/phasicFlow/structuredData/pointStructure/selectors/{rangeAll/rangeAll.H => selectRange/selectRange.H} (88%) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7815b7a9..a45621d8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -20,6 +20,7 @@ option(USE_STD_PARALLEL_ALG "Use TTB std parallel algorithms" ON) option(pFlow_Build_Serial "Build phasicFlow and backends for serial execution" OFF) option(pFlow_Build_OpenMP "Build phasicFlow and backends for OpenMP execution" OFF) option(pFlow_Build_Cuda "Build phasicFlow and backends for Cuda execution" OFF) +option(pFlow_Build_Double "Build phasicFlow with double precision variables" ON) set(BUILD_SHARED_LIBS ON CACHE BOOL "Build using shared libraries" FORCE) diff --git a/phasicFlowConfig.H.in b/phasicFlowConfig.H.in index b4445bf0..919867e4 100644 --- a/phasicFlowConfig.H.in +++ b/phasicFlowConfig.H.in @@ -5,4 +5,5 @@ #cmakedefine pFlow_Build_Serial #cmakedefine pFlow_Build_OpenMP #cmakedefine pFlow_Build_Cuda -#cmakedefine USE_STD_PARALLEL_ALG \ No newline at end of file +#cmakedefine USE_STD_PARALLEL_ALG +#cmakedefine pFlow_Build_Double \ No newline at end of file diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 70d96a57..6f9b3f5f 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -51,8 +51,9 @@ structuredData/line/line.C structuredData/zAxis/zAxis.C structuredData/pointStructure/pointStructure.C structuredData/pointStructure/selectors/pStructSelector/pStructSelector.C -structuredData/pointStructure/selectors/boxAll/boxAll.C -structuredData/pointStructure/selectors/rangeAll/rangeAll.C +structuredData/pointStructure/selectors/selectBox/selectBox.C +structuredData/pointStructure/selectors/selectRange/selectRange.C +structuredData/pointStructure/selectors/selectRandom/selectRandom.C structuredData/trisurfaceStructure/triSurface.C structuredData/trisurfaceStructure/multiTriSurface.C structuredData/trisurfaceStructure/stlFile.C diff --git a/src/phasicFlow/random/randomInt32/uniformRandomInt32.H b/src/phasicFlow/random/randomInt32/uniformRandomInt32.H new file mode 100644 index 00000000..32013599 --- /dev/null +++ b/src/phasicFlow/random/randomInt32/uniformRandomInt32.H @@ -0,0 +1,79 @@ +/*------------------------------- 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 __uniformRandomInt32_H__ +#define __uniformRandomInt32_H__ + +#include + +#include "types.H" +#include "typeInfo.H" + +namespace pFlow +{ + +class uniformRandomInt32 +{ +protected: + + std::mt19937_64 engineGen_; + + std::uniform_int_distribution distrbution_; + +public: + + // type info + TypeNameNV("uniform"); + + explicit uniformRandomInt32(int32 min, int32 max) + : + engineGen_(std::random_device()()), + distrbution_(min, max) + {} + + ~uniformRandomInt32()= default; + + inline real randomNumber() + { + return distrbution_(engineGen_); + } + + inline int32x3 randomNumber3() + { + return int32x3 + ( + randomNumber(), + randomNumber(), + randomNumber() + ); + } + + inline realx3 operator()() + { + return randomNumber(); + } + + + +}; + +} + +#endif diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.C b/src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.C similarity index 91% rename from src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.C rename to src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.C index 847ea3f5..433ceb19 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.C +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.C @@ -19,10 +19,10 @@ Licence: -----------------------------------------------------------------------------*/ -#include "boxAll.H" +#include "selectBox.H" -void pFlow::boxAll::selectAllPointsInBox() +void pFlow::selectBox::selectAllPointsInBox() { // to reduct allocations selectedPoints_.reserve @@ -39,7 +39,7 @@ void pFlow::boxAll::selectAllPointsInBox() } } -pFlow::boxAll::boxAll +pFlow::selectBox::selectBox ( const pointStructure& pStruct, const dictionary& dict @@ -51,7 +51,7 @@ pFlow::boxAll::boxAll ), box_ ( - dict.subDict("boxAllInfo") + dict.subDict("selectBoxInfo") ) { selectAllPointsInBox(); diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.H b/src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.H similarity index 88% rename from src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.H rename to src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.H index 10e088e5..11b78192 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/boxAll/boxAll.H +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectBox/selectBox.H @@ -19,8 +19,8 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __boxAll_H__ -#define __boxAll_H__ +#ifndef __selectBox_H__ +#define __selectBox_H__ #include "pStructSelector.H" #include "pointStructure.H" @@ -32,7 +32,7 @@ namespace pFlow class dictionary; -class boxAll +class selectBox : public pStructSelector { @@ -47,19 +47,19 @@ protected: public: // - type info - TypeName("boxAll"); + TypeName("selectBox"); - boxAll(const pointStructure& pStruct, const dictionary& dict); + selectBox(const pointStructure& pStruct, const dictionary& dict); add_vCtor ( pStructSelector, - boxAll, + selectBox, dictionary ); - virtual ~boxAll() = default; + virtual ~selectBox() = default; //// - Methods diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/selectRandom/selectRandom.C b/src/phasicFlow/structuredData/pointStructure/selectors/selectRandom/selectRandom.C new file mode 100644 index 00000000..c872ec98 --- /dev/null +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectRandom/selectRandom.C @@ -0,0 +1,122 @@ +/*------------------------------- 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 "selectRandom.H" +#include "dictionary.H" +#include "uniformRandomInt32.H" +#include "Set.H" + + +bool pFlow::selectRandom::selectAllPointsInRange() +{ + // to reduct allocations + int32 maxNum = number_+1; + + selectedPoints_.reserve (maxNum); + + selectedPoints_.clear(); + + uniformRandomInt32 intRand (begin_, end_); + + + int32 n = 0; + int32 iter = 0; + bool finished = false; + + Set selctedIndices; + + while( iter < number_*100) + { + int32 newInd = intRand.randomNumber(); + + if( auto [it, inserted] = selctedIndices.insert(newInd); inserted ) + { + n++; + + if(n == number_) + { + finished = true; + break; + } + } + iter++; + } + + + if(finished) + { + for(auto& ind:selctedIndices) + { + selectedPoints_.push_back(ind); + } + + return true; + + }else + { + fatalErrorInFunction<< "Could not find random indices in the range."<("begin") + ), + end_ + ( + dict.subDict("selectRandomInfo").getValOrSet("end", pStruct.size()) + ), + number_ + ( + dict.subDict("selectRandomInfo").getValOrSet("number", 1) + ) +{ + begin_ = max(begin_,1); + end_ = min(end_, static_cast(pStruct.size())); + number_ = max(number_,0); + if(end_-begin_ < number_) + { + + warningInFunction<< "In dictionary " << dict.globalName()<< + " number is greater than the interval defined by begine and end ["<< + begin_<<" "<("begin") + dict.subDict("selectRangeInfo").getVal("begin") ), end_ ( - dict.subDict("rangeAllInfo").getValOrSet("end", pStruct.size()) + dict.subDict("selectRangeInfo").getValOrSet("end", pStruct.size()) ), stride_ ( - dict.subDict("rangeAllInfo").getValOrSet("stride", 1) + dict.subDict("selectRangeInfo").getValOrSet("stride", 1) ) { begin_ = max(begin_,1); diff --git a/src/phasicFlow/structuredData/pointStructure/selectors/rangeAll/rangeAll.H b/src/phasicFlow/structuredData/pointStructure/selectors/selectRange/selectRange.H similarity index 88% rename from src/phasicFlow/structuredData/pointStructure/selectors/rangeAll/rangeAll.H rename to src/phasicFlow/structuredData/pointStructure/selectors/selectRange/selectRange.H index 169802f5..f995a815 100644 --- a/src/phasicFlow/structuredData/pointStructure/selectors/rangeAll/rangeAll.H +++ b/src/phasicFlow/structuredData/pointStructure/selectors/selectRange/selectRange.H @@ -19,8 +19,8 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __rangeAll_H__ -#define __rangeAll_H__ +#ifndef __selectRange_H__ +#define __selectRange_H__ #include "pStructSelector.H" #include "pointStructure.H" @@ -31,7 +31,7 @@ namespace pFlow class dictionary; -class rangeAll +class selectRange : public pStructSelector { @@ -53,19 +53,19 @@ protected: public: // - type info - TypeName("rangeAll"); + TypeName("selectRange"); - rangeAll(const pointStructure& pStruct, const dictionary& dict); + selectRange(const pointStructure& pStruct, const dictionary& dict); add_vCtor ( pStructSelector, - rangeAll, + selectRange, dictionary ); - virtual ~rangeAll() = default; + virtual ~selectRange() = default; //// - Methods diff --git a/src/phasicFlow/types/basicTypes/builtinTypes.H b/src/phasicFlow/types/basicTypes/builtinTypes.H index d4d418d1..7078c9a5 100755 --- a/src/phasicFlow/types/basicTypes/builtinTypes.H +++ b/src/phasicFlow/types/basicTypes/builtinTypes.H @@ -23,11 +23,16 @@ Licence: #include +#include "phasicFlowConfig.H" namespace pFlow { -#define useDouble 1 +#ifdef pFlow_Build_Double + #define useDouble 1 +#else + #define useDouble 0 +#endif // scalars #if useDouble @@ -36,7 +41,7 @@ namespace pFlow using real = float; #endif -using int8 = signed char; +using int8 = signed char; using int16 = short int;