From a9290e911ba86cc363a9e57c13f4a509b758bb79 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Fri, 5 Apr 2024 05:31:09 -0700 Subject: [PATCH 1/2] Reflective boundary condition is added and tested. It requires messaging integration when changing velocity. --- .../AdamsBashforth2/AdamsBashforth2.hpp | 2 +- src/phasicFlow/CMakeLists.txt | 1 + .../boundaryField/boundaryField.cpp | 2 +- .../boundaryField/createBoundaryFields.hpp | 18 ++- .../reflectiveBoundaryField.cpp | 31 ++++ .../reflectiveBoundaryField.hpp | 90 +++++++++++ .../pointField/pointField/pointFields.cpp | 67 ++------ .../repository/repository/repository.hpp | 13 +- .../repository/repositoryTemplates.cpp | 71 ++++++--- .../boundaries/boundaryBase/boundaryBase.cpp | 19 ++- .../boundaries/boundaryBase/boundaryBase.hpp | 6 + .../boundaryReflective/boundaryReflective.cpp | 149 ++++++++++++++++++ .../boundaryReflective/boundaryReflective.hpp | 73 +++++++++ 13 files changed, 453 insertions(+), 89 deletions(-) create mode 100644 src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.cpp create mode 100644 src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.hpp create mode 100644 src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.cpp create mode 100644 src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.hpp diff --git a/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp b/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp index 863bd8a1..21e857cb 100644 --- a/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp +++ b/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp @@ -41,11 +41,11 @@ class AdamsBashforth2 { private: - auto& dy1() { return static_cast(*this); } + public: /// Type info diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 3efe0d7e..49772f57 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -78,6 +78,7 @@ structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp structuredData/boundaries/boundaryExit/boundaryExit.cpp structuredData/boundaries/boundaryNone/boundaryNone.cpp structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.cpp +structuredData/boundaries/boundaryReflective/boundaryReflective.cpp structuredData/boundaries/boundaryList.cpp structuredData/pointStructure/pointStructure/pointStructure.cpp structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp diff --git a/src/phasicFlow/containers/pointField/boundaryField/boundaryField/boundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField/boundaryField/boundaryField.cpp index ecdb524f..2d2cc3bf 100644 --- a/src/phasicFlow/containers/pointField/boundaryField/boundaryField/boundaryField.cpp +++ b/src/phasicFlow/containers/pointField/boundaryField/boundaryField/boundaryField.cpp @@ -68,7 +68,7 @@ pFlow::uniquePtr> printKeys ( fatalError << "Ctor Selector "<< bType << "for type "<< - Yellow_Text(getTypeName()) << " dose not exist.\n" + Yellow_Text(getTypeName()) << " does not exist.\n" <<"Avaiable ones are: \n\n" , boundaryBasevCtorSelector_ diff --git a/src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp b/src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp index 8167a6ef..3b00050f 100644 --- a/src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp +++ b/src/phasicFlow/containers/pointField/boundaryField/createBoundaryFields.hpp @@ -21,15 +21,23 @@ Licence: #ifndef __createBoundaryFields_hpp__ #define __createBoundaryFields_hpp__ -#include "boundaryField.hpp" -#include "exitBoundaryField.hpp" +#include "boundaryField/boundaryField.hpp" +#include "exitBoundaryField/exitBoundaryField.hpp" +#include "periodicBoundaryField/periodicBoundaryField.hpp" +#include "reflectiveBoundaryField/reflectiveBoundaryField.hpp" + +#define createDerivedBoundary(DataType, MemorySpaceType) \ + template class pFlow::exitBoundaryField; \ + template class pFlow::periodicBoundaryField; \ + template class pFlow::reflectiveBoundaryField; #define createBaseBoundary(DataType, MemorySpaceType) \ - template class pFlow::boundaryField; + template class pFlow::boundaryField; -#define createBoundary(DataType, MemorySpaceType, BoundaryType) \ - template class pFlow::BoundaryType##BoundaryField; +#define createBoundaryFields(DataType, MemorySpaceType) \ + createBaseBoundary(DataType, MemorySpaceType); \ + createDerivedBoundary(DataType, MemorySpaceType); #endif //__createBoundaryFields_hpp__ diff --git a/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.cpp new file mode 100644 index 00000000..91bcc7b5 --- /dev/null +++ b/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.cpp @@ -0,0 +1,31 @@ +/*------------------------------- 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. +-----------------------------------------------------------------------------*/ + +template + pFlow::reflectiveBoundaryField::reflectiveBoundaryField +( + const boundaryBase& boundary, + const pointStructure& pStruct, + InternalFieldType& internal +) +: + BoundaryFieldType(boundary, pStruct, internal) +{ + //this->addEvent(message::BNDR_DELETE); +} \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.hpp new file mode 100644 index 00000000..e79f4fe6 --- /dev/null +++ b/src/phasicFlow/containers/pointField/boundaryField/reflectiveBoundaryField/reflectiveBoundaryField.hpp @@ -0,0 +1,90 @@ +/*------------------------------- 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 __reflectiveBoundaryField_hpp__ +#define __reflectiveBoundaryField_hpp__ + +#include "boundaryField.hpp" + +namespace pFlow +{ + +template< class T, class MemorySpace = void> +class reflectiveBoundaryField +: + public boundaryField +{ +public: + + using ReflectiveBoundaryFieldType = reflectiveBoundaryField; + + using BoundaryFieldType = boundaryField; + + using InternalFieldType = typename BoundaryFieldType::InternalFieldType; + + using memory_space = typename BoundaryFieldType::memory_space; + + using execution_space = typename BoundaryFieldType::execution_space; + + + +public: + + TypeInfoTemplate211("boundaryField","reflective", T, memory_space::name()); + + reflectiveBoundaryField( + const boundaryBase& boundary, + const pointStructure& pStruct, + InternalFieldType& internal); + + + add_vCtor + ( + BoundaryFieldType, + ReflectiveBoundaryFieldType, + boundaryBase + ); + + + bool hearChanges + ( + real t, + real dt, + uint32 iter, + const message& msg, + const anyList& varList + ) override + { + BoundaryFieldType::hearChanges(t,dt,iter, msg,varList); + + if(msg.equivalentTo(message::BNDR_DELETE)) + { + // do nothing; + } + + return true; + } + +}; + +} + +#include "reflectiveBoundaryField.cpp" + +#endif diff --git a/src/phasicFlow/containers/pointField/pointField/pointFields.cpp b/src/phasicFlow/containers/pointField/pointField/pointFields.cpp index 6f3cf375..032f6b2d 100644 --- a/src/phasicFlow/containers/pointField/pointField/pointFields.cpp +++ b/src/phasicFlow/containers/pointField/pointField/pointFields.cpp @@ -18,76 +18,37 @@ Licence: -----------------------------------------------------------------------------*/ - #include "pointFields.hpp" #include "createBoundaryFields.hpp" -#include "periodicBoundaryField.hpp" - -#define createAllBoundary(DataType, MemorySpaceType) \ - template class pFlow::exitBoundaryField; \ - template class pFlow::periodicBoundaryField; +#define createPointFields(DataType) \ + template class pFlow::pointField; \ + createBoundaryFields(DataType, pFlow::HostSpace); \ + \ + template class pFlow::pointField; \ + createBoundaryFields(DataType, void); // uint8 -template class pFlow::pointField; -createBaseBoundary(pFlow::uint8, pFlow::HostSpace); -createAllBoundary(pFlow::uint8, pFlow::HostSpace); - -template class pFlow::pointField; -createBaseBoundary(pFlow::uint8, void); -createAllBoundary(pFlow::uint8, void); +createPointFields(pFlow::uint8); /// uint32 -template class pFlow::pointField; -createBaseBoundary(pFlow::uint32, pFlow::HostSpace); -createAllBoundary(pFlow::uint32, pFlow::HostSpace); - -template class pFlow::pointField; -createBaseBoundary(pFlow::uint32, void); -createAllBoundary(pFlow::uint32, void); +createPointFields(pFlow::uint32); /// uint64 -template class pFlow::pointField; -createBaseBoundary(pFlow::uint64, pFlow::HostSpace); -createAllBoundary(pFlow::uint64, pFlow::HostSpace); - -template class pFlow::pointField; -createBaseBoundary(pFlow::uint64, void); -createAllBoundary(pFlow::uint64, void); +createPointFields(pFlow::uint64); /// real -template class pFlow::pointField; -createBaseBoundary(pFlow::real, pFlow::HostSpace); -createAllBoundary(pFlow::real, pFlow::HostSpace); - -template class pFlow::pointField; -createBaseBoundary(pFlow::real, void); -createAllBoundary(pFlow::real, void); +createPointFields(pFlow::real); /// realx3 -template class pFlow::pointField; -createBaseBoundary(pFlow::realx3, pFlow::HostSpace); -createAllBoundary(pFlow::realx3, pFlow::HostSpace); - - -template class pFlow::pointField; -createBaseBoundary(pFlow::realx3, void); -createAllBoundary(pFlow::realx3, void); +createPointFields(pFlow::realx3); /// realx4 -template class pFlow::pointField; -createBaseBoundary(pFlow::realx4, pFlow::HostSpace); -createAllBoundary(pFlow::realx4, pFlow::HostSpace); +createPointFields(pFlow::realx4); -template class pFlow::pointField; -createBaseBoundary(pFlow::realx4, void); -createAllBoundary(pFlow::realx4, void); - - -/// word +/// word, only on host template class pFlow::pointField; -createBaseBoundary(pFlow::word, pFlow::HostSpace); -createAllBoundary(pFlow::word, pFlow::HostSpace); \ No newline at end of file +createBoundaryFields(pFlow::word, pFlow::HostSpace); diff --git a/src/phasicFlow/repository/repository/repository.hpp b/src/phasicFlow/repository/repository/repository.hpp index 93698ab7..5e712c16 100644 --- a/src/phasicFlow/repository/repository/repository.hpp +++ b/src/phasicFlow/repository/repository/repository.hpp @@ -33,7 +33,7 @@ namespace pFlow class repository { -protected: +private: // - repository name word name_; @@ -53,10 +53,11 @@ protected: template - word reportTypeError (IOobject& object); + word reportTypeError (IOobject& object)const; template - bool checkForObjectType(IOobject& object); + static + bool checkForObjectType(IOobject& object); public: @@ -167,9 +168,13 @@ public: } } - // - return a ref to the underlaying data in the object + /// return a ref to the underlaying data in the object template T& lookupObject(const word& name); + + /// return a const ref to the underlaying data in the object + template + const T& lookupObject(const word& name)const; // - search the name and return a ref to repository repository& lookupRepository(const word& name); diff --git a/src/phasicFlow/repository/repository/repositoryTemplates.cpp b/src/phasicFlow/repository/repository/repositoryTemplates.cpp index a4c9ee1e..c1525430 100644 --- a/src/phasicFlow/repository/repository/repositoryTemplates.cpp +++ b/src/phasicFlow/repository/repository/repositoryTemplates.cpp @@ -20,7 +20,7 @@ Licence: template -pFlow::word pFlow::repository::reportTypeError(IOobject& object) +pFlow::word pFlow::repository::reportTypeError(IOobject& object)const { word err; err = "Object " + object.name() + " with type " + Type1::TYPENAME() + @@ -40,28 +40,57 @@ template T& pFlow::repository::lookupObject(const word& name) { if( auto [iter, success] = objects_.findIf(name); success ) - { + { - if( checkType(iter->second) ) - { - return static_cast(*iter->second); - + if( checkType(iter->second) ) + { + return static_cast(*iter->second); + - }else - { - fatalErrorInFunction << - reportTypeError(*iter->second)<(*iter->second); - } - - } - else - { - fatalErrorInFunction << + }else + { + fatalErrorInFunction << + reportTypeError(*iter->second)<(*iter->second); + } + + } + else + { + fatalErrorInFunction << "Object with name " << name << " is not found in repository " << this->name()<(*iter->second); - } + fatalExit; + return static_cast(*iter->second); + } +} + +template +const T& pFlow::repository::lookupObject(const word& name)const +{ + if( auto [iter, success] = objects_.findIf(name); success ) + { + + if( checkType(iter->second) ) + { + return static_cast(*iter->second); + } + else + { + fatalErrorInFunction << + reportTypeError(*iter->second)<(*iter->second); + } + + } + else + { + fatalErrorInFunction << + "Object with name " << name << " is not found in repository " << this->name()<(*iter->second); + } } \ No newline at end of file diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp index a7f6c96d..7a39276a 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.cpp @@ -24,6 +24,7 @@ Licence: #include "internalPoints.hpp" #include "anyList.hpp" #include "Time.hpp" +#include "pointStructure.hpp" #include "boundaryBaseKernels.hpp" void pFlow::boundaryBase::setSize(uint32 newSize) @@ -114,9 +115,9 @@ bool pFlow::boundaryBase::removeIndices message msgBndry = message::BNDR_RESET; - uint32 iter = internal_.time().currentIter(); - real t = internal_.time().currentTime(); - real dt = internal_.time().dt(); + uint32 iter = time().currentIter(); + real t = time().currentTime(); + real dt = time().dt(); if( !this->notify(iter, t, dt, msgBndry, aList) ) { @@ -197,6 +198,16 @@ pFlow::boundaryBase::boundaryBase unSyncLists(); } +const pFlow::pointStructure &pFlow::boundaryBase::pStruct() const +{ + return boundaries_.pStruct(); +} + +const pFlow::Time &pFlow::boundaryBase::time() const +{ + return boundaries_.pStruct().time(); +} + pFlow::boundaryBase &pFlow::boundaryBase::mirrorBoundary() { return boundaries_[mirrorBoundaryIndex()]; @@ -256,7 +267,7 @@ pFlow::uniquePtr pFlow::boundaryBase::create { printKeys ( - fatalError << "Ctor Selector "<< bType << " dose not exist. \n" + fatalError << "Ctor Selector "<< bType << " does not exist. \n" <<"Avaiable ones are: \n\n" , dictionaryvCtorSelector_ diff --git a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp index 261b7f94..06766b97 100644 --- a/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp +++ b/src/phasicFlow/structuredData/boundaries/boundaryBase/boundaryBase.hpp @@ -37,6 +37,8 @@ namespace pFlow class internalPoints; class dictionary; class boundaryList; +class pointStructure; +class Time; class boundaryBase : @@ -217,6 +219,10 @@ public: return internal_; } + const pointStructure& pStruct()const; + + const Time& time()const; + inline const auto& indexList()const { diff --git a/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.cpp b/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.cpp new file mode 100644 index 00000000..6d818a23 --- /dev/null +++ b/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.cpp @@ -0,0 +1,149 @@ +/*------------------------------- 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 "boundaryReflective.hpp" +#include "pointFields.hpp" +#include "dictionary.hpp" +#include "Time.hpp" + +pFlow::boundaryReflective::boundaryReflective +( + const dictionary &dict, + const plane &bplane, + internalPoints &internal, + boundaryList &bndrs, + uint32 thisIndex +) +: + boundaryBase + ( + dict, + bplane, + internal, + bndrs, + thisIndex + ) +{ + restitution_ = dict.getValOrSet("restitution", restitution_); + velocityName_ = dict.getValOrSet("velocityName",velocityName_); + diameterName_ = dict.getValOrSet("diameterName", diameterName_); +} + +bool pFlow::boundaryReflective::beforeIteration( + uint32 iterNum, + real t, + real dt) +{ + return true; +} + +bool pFlow::boundaryReflective::iterate +( + uint32 iterNum, + real t, + real dt +) +{ + return true; +} + +bool pFlow::boundaryReflective::afterIteration +( + uint32 iterNum, + real t, + real dt +) +{ + if(empty())return true; + + uint32 s = size(); + uint32Vector_D inContactFlags("inContactFlags",s+1, s+1, RESERVE()); + inContactFlags.fill(0u); + auto inContactFlagsD = inContactFlags.deviceViewAll(); + + auto points = thisPoints(); + + auto p = boundaryPlane().infPlane(); + const auto &diam = time().lookupObject(diameterName_); + auto diams = diam.BoundaryField(thisBoundaryIndex()).thisField(); + + uint32 numInContact = 0; + + Kokkos::parallel_reduce + ( + "pFlow::boundaryReflective::afterIteration", + deviceRPolicyStatic(0u,s), + LAMBDA_HD(uint32 i, uint32& nContactToUpdate) + { + if(p.inPositiveDistance(points(i), 0.5*diams(i))) + { + inContactFlagsD(i)=1; + nContactToUpdate++; + } + }, + numInContact + ); + + // no particle in contact + if(numInContact == 0 ) + { + return true; + } + + uint32Vector_D inContactList("inContactList", numInContact); + const auto& inContactListD = inContactList.deviceViewAll(); + + exclusiveScan(inContactFlagsD, 0u, s+1, inContactFlagsD, 0u); + + Kokkos::parallel_for + ( + "pFlow::boundaryReflective::afterIteration", + deviceRPolicyStatic(0, s), + LAMBDA_HD(uint32 i) + { + if(inContactFlagsD(i)!= inContactFlagsD(i+1)) + inContactListD(inContactFlagsD(i)) = points.index(i); + } + ); + Kokkos::fence(); + + const auto& velocity = time().lookupObject(velocityName_); + const auto& velocityD = velocity.deviceViewAll(); + + Kokkos::parallel_for( + "pFlow::boundaryReflective::velocityChange", + deviceRPolicyStatic(0,numInContact), + LAMBDA_HD(uint32 i) + { + auto& vel = velocityD(inContactListD(i)); + real vn = dot(p.normal(), vel); + + if(vn < 0) + { + realx3 vt = vel - vn*p.normal(); + vel = restitution_*(vt - vn*p.normal()); + } + } + ); + Kokkos::fence(); + + // TODO: notify integration for changes in the velocity + + return true; +} diff --git a/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.hpp b/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.hpp new file mode 100644 index 00000000..43e1ce13 --- /dev/null +++ b/src/phasicFlow/structuredData/boundaries/boundaryReflective/boundaryReflective.hpp @@ -0,0 +1,73 @@ +/*------------------------------- 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 __boundaryReflective_hpp__ +#define __boundaryReflective_hpp__ + + +#include "boundaryBase.hpp" + +namespace pFlow +{ + +class boundaryReflective +: + public boundaryBase +{ +private: + + real restitution_ = 0.95; + + word velocityName_{"velocity"}; + + word diameterName_{"diameter"}; + +public: + + TypeInfo("boundary"); + + boundaryReflective( + const dictionary &dict, + const plane &bplane, + internalPoints &internal, + boundaryList &bndrs, + uint32 thisIndex); + + + ~boundaryReflective()override = default; + + add_vCtor + ( + boundaryBase, + boundaryReflective, + dictionary + ); + + bool beforeIteration(uint32 iterNum, real t, real dt) override; + + bool iterate(uint32 iterNum, real t, real dt) override; + + bool afterIteration(uint32 iterNum, real t, real dt) override; + + +}; + +} + +#endif \ No newline at end of file From ff8968e5951b1ab93ab4cfcf0a270084f3aaec9e Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Mon, 8 Apr 2024 12:33:08 -0700 Subject: [PATCH 2/2] format clang-format --- src/phasicFlow/Kokkos/KokkosTypes.hpp | 162 ++--- src/phasicFlow/Kokkos/KokkosUtilities.hpp | 214 +++--- src/phasicFlow/Kokkos/Range.hpp | 188 +++-- src/phasicFlow/Kokkos/ViewAlgorithms.hpp | 681 ++++++++---------- src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp | 52 +- src/phasicFlow/Kokkos/baseAlgorithms_.hpp | 244 +++---- src/phasicFlow/Timer/Timer.cpp | 85 +-- src/phasicFlow/Timer/Timer.hpp | 100 ++- .../boundaryField/createBoundaryFields.hpp | 26 +- src/phasicFlow/globals/error.cpp | 132 ++-- src/phasicFlow/globals/error.hpp | 98 ++- src/phasicFlow/globals/vocabs.hpp | 60 +- src/phasicFlow/repository/Time/Time.cpp | 109 ++- src/phasicFlow/repository/Time/Time.hpp | 101 ++- .../repository/Time/baseTimeControl.cpp | 87 +++ .../repository/Time/baseTimeControl.hpp | 21 +- .../systemControl/systemControl.cpp | 333 ++++----- src/phasicFlow/typeSelection/typeInfo.hpp | 363 ++++++---- .../typeSelection/virtualConstructor.hpp | 106 ++- src/phasicFlow/types/basicTypes/Logical.cpp | 137 ++-- src/phasicFlow/types/basicTypes/Logical.hpp | 155 ++-- .../types/basicTypes/bTypesFunctions.cpp | 521 ++++++++------ .../types/basicTypes/bTypesFunctions.hpp | 276 ++++--- .../types/basicTypes/builtinTypes.hpp | 56 +- src/phasicFlow/types/basicTypes/math.hpp | 210 +++--- .../types/basicTypes/numericConstants.hpp | 81 +-- src/phasicFlow/types/quadruple/quadruple.hpp | 289 ++++---- .../types/quadruple/quadrupleFwd.hpp | 170 ++--- src/phasicFlow/types/quadruple/quadrupleI.hpp | 404 ++++------- .../types/quadruple/quadrupleMath.hpp | 61 +- src/phasicFlow/types/triple/triple.hpp | 395 +++++----- src/phasicFlow/types/triple/tripleFwd.hpp | 218 ++---- src/phasicFlow/types/triple/tripleI.hpp | 510 +++++-------- src/phasicFlow/types/triple/tripleMath.hpp | 64 +- src/phasicFlow/types/types.cpp | 29 +- src/phasicFlow/types/types.hpp | 120 ++- 36 files changed, 3353 insertions(+), 3505 deletions(-) diff --git a/src/phasicFlow/Kokkos/KokkosTypes.hpp b/src/phasicFlow/Kokkos/KokkosTypes.hpp index 6597b5b7..c902abef 100644 --- a/src/phasicFlow/Kokkos/KokkosTypes.hpp +++ b/src/phasicFlow/Kokkos/KokkosTypes.hpp @@ -2,17 +2,17 @@ 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. @@ -22,155 +22,141 @@ Licence: /** * \file KokkosType.hpp - * - * \brief name aliases and typedesf for Kokkos entities that are + * + * \brief name aliases and typedesf for Kokkos entities that are * frequently used in PhasicFlow. - * + * */ - #include #include #include #include "builtinTypes.hpp" - namespace pFlow { +/// Host memory space +using HostSpace = Kokkos::HostSpace; -/// Host memory space -using HostSpace = Kokkos::HostSpace; - -/// Serial execution space -using Serial = Kokkos::Serial; +/// Serial execution space +using Serial = Kokkos::Serial; #ifdef _OPENMP -/// OpenMp execution space -using OpenMP = Kokkos::OpenMP; +/// OpenMp execution space +using OpenMP = Kokkos::OpenMP; #endif #ifdef __CUDACC__ -/// Cuda execution space -using Cuda = Kokkos::Cuda; +/// Cuda execution space +using Cuda = Kokkos::Cuda; #endif -/// Default Host execution space, on top of all host execution spaces -using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace; +/// Default Host execution space, on top of all host execution spaces +using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace; -/// Default execution space, it can be device exe. space, if a device space is -/// activated. -using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace; +/// Default execution space, it can be device exe. space, if a device space is +/// activated. +using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace; +using deviceRPolicyStatic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; -using deviceRPolicyStatic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; +using hostRPolicyStatic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; +using deviceRPolicyDynamic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; -using hostRPolicyStatic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - -using deviceRPolicyDynamic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - - -using hostRPolicyDynamic = - Kokkos::RangePolicy< - Kokkos::DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType >; - +using hostRPolicyDynamic = Kokkos::RangePolicy< + Kokkos::DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType>; /// Pair of two variables template -using Pair = Kokkos::pair; +using Pair = Kokkos::pair; /// View for a scalar template - using ViewTypeScalar = Kokkos::View; +using ViewTypeScalar = Kokkos::View; -/// 1D veiw as a vector +/// 1D veiw as a vector template - using ViewType1D = Kokkos::View; +using ViewType1D = Kokkos::View; /// 2D view as an array template - using ViewType2D = Kokkos::View; +using ViewType2D = Kokkos::View; /// 3D view as an array template - using ViewType3D = Kokkos::View; +using ViewType3D = Kokkos::View; -/// 1D dual view as a vector +/// 1D dual view as a vector template - using DualViewType1D = Kokkos::DualView; +using DualViewType1D = Kokkos::DualView; /// unordered map template - using unorderedMap = Kokkos::UnorderedMap; +using unorderedMap = Kokkos::UnorderedMap; -/// unordered set +/// unordered set template - using unorderedSet = Kokkos::UnorderedMap; +using unorderedSet = Kokkos::UnorderedMap; -/// Scalar on device +/// Scalar on device template - using deviceViewTypeScalar = Kokkos::View; +using deviceViewTypeScalar = Kokkos::View; /// 1D array (vector) with default device (memory space and execution space) template - using deviceViewType1D = Kokkos::View; - -/// 2D view on device as an array on device -template - using deviceViewType2D = Kokkos::View; - -/// 3D view on device as an array on device -template - using deviceViewType3D = Kokkos::View; +using deviceViewType1D = Kokkos::View; +/// 2D view on device as an array on device +template +using deviceViewType2D = Kokkos::View; +/// 3D view on device as an array on device +template +using deviceViewType3D = Kokkos::View; template - using hostViewTypeScalar = Kokkos::View; +using hostViewTypeScalar = Kokkos::View; /// 1D array (vector with host memeory space) template - using hostViewType1D = Kokkos::View; +using hostViewType1D = Kokkos::View; -/// 2D array on host -template - using hostViewType2D = Kokkos::View; +/// 2D array on host +template +using hostViewType2D = Kokkos::View; /// 3D array on host -template - using hostViewType3D = Kokkos::View; +template +using hostViewType3D = Kokkos::View; /// 1D vector on device with atomic capabilities template -using deviceAtomicViewType1D = - Kokkos::View< - T*, - Kokkos::MemoryTraits::value?0:Kokkos::Atomic>>; +using deviceAtomicViewType1D = Kokkos::View< + T*, + Kokkos::MemoryTraits< + std::is_same_v ? 0 : Kokkos::Atomic>>; /// 3D array on device with atomic capabilities template -using deviceAtomicViewType3D = - Kokkos::View< - T***, - Kokkos::MemoryTraits::value?0:Kokkos::Atomic>>; - +using deviceAtomicViewType3D = Kokkos::View< + T***, + Kokkos::MemoryTraits< + std::is_same_v ? 0 : Kokkos::Atomic>>; } // pFlow -#endif //__KokkosTypes_hpp__ +#endif //__KokkosTypes_hpp__ diff --git a/src/phasicFlow/Kokkos/KokkosUtilities.hpp b/src/phasicFlow/Kokkos/KokkosUtilities.hpp index 6d1c7f46..7669ba1f 100644 --- a/src/phasicFlow/Kokkos/KokkosUtilities.hpp +++ b/src/phasicFlow/Kokkos/KokkosUtilities.hpp @@ -2,17 +2,17 @@ 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. @@ -21,209 +21,205 @@ Licence: #ifndef __KokkosUtilities_hpp__ #define __KokkosUtilities_hpp__ - #include "KokkosTypes.hpp" -#include "pFlowMacros.hpp" -#include "types.hpp" -#include "span.hpp" #include "dataIO.hpp" #include "iOstream.hpp" +#include "pFlowMacros.hpp" +#include "span.hpp" +#include "types.hpp" namespace pFlow { template -INLINE_FUNCTION_H -bool constexpr isHostAccessible() +INLINE_FUNCTION_H bool constexpr isHostAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility::accessible; } template -INLINE_FUNCTION_H -bool constexpr isDeviceAccessible() +INLINE_FUNCTION_H bool constexpr isDeviceAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility< + ExecutionSpace, + DefaultExecutionSpace::memory_space>::accessible; } /// Is MemoerySpace accessible from ExecutionSpace template -INLINE_FUNCTION_H -bool constexpr areAccessible() +INLINE_FUNCTION_H bool constexpr areAccessible() { - return Kokkos::SpaceAccessibility::accessible; + return Kokkos::SpaceAccessibility::accessible; } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType1D& view, uint32 len) -{ - Kokkos::realloc(Kokkos::WithoutInitializing, view, len); -} - -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType1D& view, uint32 len) +template +INLINE_FUNCTION_H void +reallocInit(ViewType1D& view, uint32 len) { Kokkos::realloc(Kokkos::WithoutInitializing, view, len); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType1D& view, uint32 len, Type val) +template +INLINE_FUNCTION_H void +reallocNoInit(ViewType1D& view, uint32 len) +{ + Kokkos::realloc(Kokkos::WithoutInitializing, view, len); +} + +template +INLINE_FUNCTION_H void +reallocFill(ViewType1D& view, uint32 len, Type val) { reallocNoInit(view, len); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType2D& view, uint32 len1, uint32 len2) +template +INLINE_FUNCTION_H void +reallocInit(ViewType2D& view, uint32 len1, uint32 len2) { Kokkos::realloc(view, len1, len2); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType2D& view, uint32 len1, uint32 len2) -{ - Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2); +template +INLINE_FUNCTION_H void +reallocNoInit(ViewType2D& view, uint32 len1, uint32 len2) +{ + Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType2D& view, uint32 len1, uint32 len2, Type val) +template +INLINE_FUNCTION_H void +reallocFill( + ViewType2D& view, + uint32 len1, + uint32 len2, + Type val +) { reallocNoInit(view, len1, len2); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocInit( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) +template +INLINE_FUNCTION_H void +reallocInit( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3 +) { Kokkos::realloc(view, len1, len2, len3); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocNoInit(ViewType3D& view, uint32 len1, uint32 len2, uint32 len3) +template +INLINE_FUNCTION_H void +reallocNoInit( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3 +) { - - Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3); + Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void reallocFill( ViewType3D& view, uint32 len1, uint32 len2, uint32 len3, Type val) +template +INLINE_FUNCTION_H void +reallocFill( + ViewType3D& view, + uint32 len1, + uint32 len2, + uint32 len3, + Type val +) { reallocNoInit(view, len1, len2, len3); Kokkos::deep_copy(view, val); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void resizeInit(ViewType1D& view, uint32 newLen) +template +INLINE_FUNCTION_H void +resizeInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(view, newLen); } -template < - typename Type, - typename... Properties> -INLINE_FUNCTION_H -void resizeNoInit(ViewType1D& view, uint32 newLen) +template +INLINE_FUNCTION_H void +resizeNoInit(ViewType1D& view, uint32 newLen) { Kokkos::resize(Kokkos::WithoutInitializing, view, newLen); } template -INLINE_FUNCTION_H -void swapViews(ViewType& v1, ViewType &v2) +INLINE_FUNCTION_H void +swapViews(ViewType& v1, ViewType& v2) { static_assert( - std::is_move_assignable::value && std::is_move_constructible::value, - "swapViews arguments must be move assignable and move constructible"); + std::is_move_assignable_v && + std::is_move_constructible_v, + "swapViews arguments must be move assignable and move constructible" + ); ViewType tmp = std::move(v1); - v1 = std::move(v2); - v2 = std::move(tmp); + v1 = std::move(v2); + v2 = std::move(tmp); } - template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const Pair& p) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const Pair& p) { - os<<'('< -INLINE_FUNCTION_H -span makeSpan(ViewType1D & v) +INLINE_FUNCTION_H span + makeSpan(ViewType1D& v) { return span(v.data(), v.size()); } template -INLINE_FUNCTION_H -span makeSpan(ViewType1D & v, uint32 size) +INLINE_FUNCTION_H span + makeSpan(ViewType1D& v, uint32 size) { return span(v.data(), size); } template -INLINE_FUNCTION_H -span makeSpan(const ViewType1D & v) +INLINE_FUNCTION_H span + makeSpan(const ViewType1D& v) { return span(const_cast(v.data()), v.size()); } template -INLINE_FUNCTION_H -span makeSpan(const ViewType1D & v, uint32 size) +INLINE_FUNCTION_H span + makeSpan(const ViewType1D& v, uint32 size) { return span(const_cast(v.data()), size); } - template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const ViewType1D & v) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const ViewType1D& v) { - using ExSpace = typename ViewType1D::execution_space; - static_assert(isHostAccessible(), "View memory is not accessible from Host"); + static_assert( + isHostAccessible(), "View memory is not accessible from Host" + ); span spn(v.data(), v.size()); - os< -#include "pFlowMacros.hpp" -#include "typeInfo.hpp" #include "builtinTypes.hpp" #include "iOstream.hpp" - +#include "pFlowMacros.hpp" +#include "typeInfo.hpp" namespace pFlow { - /** * Range for elements in an vector [start,end) - * + * */ template -struct Range -: -public Kokkos::pair +struct Range : public Kokkos::pair { - using Pair = Kokkos::pair; + using Pair = Kokkos::pair; TypeInfoTemplateNV11("Range", T) - //// - Constructors + //// - Constructors - /// Default - INLINE_FUNCTION_HD - Range(){} + /// Default + INLINE_FUNCTION_HD Range() + { + } - /// From end, set start to 0 - INLINE_FUNCTION_HD - Range(const T& e) - : - Range(0,e) - {} - - /// From componeents - INLINE_FUNCTION_HD - Range(const T& s, const T& e) - : - Range::Pair(s,e) - {} + /// From end, set start to 0 + INLINE_FUNCTION_HD + Range(const T& e) + : Range(0, e) + { + } - /// From pair - INLINE_FUNCTION_HD - Range(const Range::Pair &src ) - : - Range::Pair(src) - {} + /// From componeents + INLINE_FUNCTION_HD + Range(const T& s, const T& e) + : Range::Pair(s, e) + { + } - /// Copy - INLINE_FUNCTION_HD - Range(const Range&) = default; + /// From pair + INLINE_FUNCTION_HD + Range(const Range::Pair& src) + : Range::Pair(src) + { + } - /// Move - INLINE_FUNCTION_HD - Range(Range&&) = default; + /// Copy + INLINE_FUNCTION_HD + Range(const Range&) = default; - /// Copy assignment - INLINE_FUNCTION_HD - Range& operator=(const Range&) = default; + /// Move + INLINE_FUNCTION_HD + Range(Range&&) = default; - /// Move assignment - INLINE_FUNCTION_HD - Range& operator=(Range&&) = default; + /// Copy assignment + INLINE_FUNCTION_HD + Range& operator=(const Range&) = default; - /// Destructor - INLINE_FUNCTION_HD - ~Range()=default; + /// Move assignment + INLINE_FUNCTION_HD + Range& operator=(Range&&) = default; + + /// Destructor + INLINE_FUNCTION_HD + ~Range() = default; //// - Methods - /// Start - INLINE_FUNCTION_HD - T& start() - { - return this->first; - } + /// Start + INLINE_FUNCTION_HD + T& start() + { + return this->first; + } - /// End - INLINE_FUNCTION_HD - T& end() - { - return this->second; - } + /// End + INLINE_FUNCTION_HD + T& end() + { + return this->second; + } - INLINE_FUNCTION_HD - const T& start()const - { - return this->first; - } + INLINE_FUNCTION_HD + const T& start() const + { + return this->first; + } - INLINE_FUNCTION_HD - const T& end()const - { - return this->second; - } + INLINE_FUNCTION_HD + const T& end() const + { + return this->second; + } - INLINE_FUNCTION_HD - T numElements() - { - return end()-start(); - } - - INLINE_FUNCTION_HD - auto getPair()const - { - return Pair(this->first, this->second); - } + INLINE_FUNCTION_HD + T numElements() + { + return end() - start(); + } + INLINE_FUNCTION_HD + auto getPair() const + { + return Pair(this->first, this->second); + } }; template -INLINE_FUNCTION_H -iOstream& operator <<(iOstream& os, const Range& rng) +INLINE_FUNCTION_H iOstream& +operator<<(iOstream& os, const Range& rng) { - os<<"["<; +using range32 = Range; -using range64 = Range; +using range64 = Range; -using rangeU32 = Range; - -using rangeU64 = Range; +using rangeU32 = Range; +using rangeU64 = Range; } // pFlow -#endif //__KokkosTypes_hpp__ +#endif //__KokkosTypes_hpp__ diff --git a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp index d765e014..025534c9 100644 --- a/src/phasicFlow/Kokkos/ViewAlgorithms.hpp +++ b/src/phasicFlow/Kokkos/ViewAlgorithms.hpp @@ -2,17 +2,17 @@ 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. @@ -21,57 +21,48 @@ Licence: #ifndef __ViewAlgorithms_hpp__ #define __ViewAlgorithms_hpp__ - -#include "numericConstants.hpp" -#include "Range.hpp" #include "KokkosUtilities.hpp" +#include "Range.hpp" +#include "numericConstants.hpp" +#include "cudaAlgorithms.hpp" #include "kokkosAlgorithms.hpp" #include "stdAlgorithms.hpp" -#include "cudaAlgorithms.hpp" - namespace pFlow -{ -template -INLINE_FUNCTION_H -uint32 count( - const ViewType1D& view, - uint32 start, - uint32 end, - const T& val) { - - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - return pFlow::algorithms::KOKKOS::count - ( - view.data()+start, - numElems, - val - ); -} - template -INLINE_FUNCTION_H -void fill -( - ViewType1D& view, - rangeU32 span, - T val +INLINE_FUNCTION_H uint32 +count( + const ViewType1D& view, + uint32 start, + uint32 end, + const T& val ) +{ + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + return pFlow::algorithms::KOKKOS::count( + view.data() + start, numElems, val + ); +} + +template +INLINE_FUNCTION_H void +fill(ViewType1D& view, rangeU32 span, T val) { using exe_space = typename ViewType1D::execution_space; - auto subV = Kokkos::subview(view, span.getPair() ); - if constexpr ( std::is_trivially_copyable_v) + auto subV = Kokkos::subview(view, span.getPair()); + if constexpr (std::is_trivially_copyable_v) { Kokkos::deep_copy(subV, val); } - else if constexpr( isHostAccessible()) + else if constexpr (isHostAccessible()) { - for(auto i=span.start(); i -void fill -( - ViewType1D& view, - uint32 start, - uint32 end, - T val -) +void +fill(ViewType1D& view, uint32 start, uint32 end, T val) { - fill(view, rangeU32(start, end),val); + fill(view, rangeU32(start, end), val); } template -void fill -( - ViewType3D& view, - rangeU32 range1, - rangeU32 range2, - rangeU32 range3, - const T& val +void +fill( + ViewType3D& view, + rangeU32 range1, + rangeU32 range2, + rangeU32 range3, + const T& val ) { static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); @@ -111,222 +96,201 @@ void fill } template -void fill -( - ViewType3D& view, - const T& val -) +void +fill(ViewType3D& view, const T& val) { static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); Kokkos::deep_copy(view, val); } -template< - typename Type, - typename... properties> -void fillSequence( - ViewType1D& view, - uint32 start, - uint32 end, - const Type startVal - ) -{ - static_assert(std::is_trivially_copyable_v, "Not valid type for fill"); - using ExecutionSpace = typename ViewType1D::execution_space; - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::fillSequence( - view.data()+start, - numElems, - startVal); - - return ; -} - - -template< - typename Type, - typename... properties, - typename indexType, - typename... indexProperties> -bool fillSelected -( - ViewType1D view, - ViewType1D indices, - uint32 numElems, - Type val +template +void +fillSequence( + ViewType1D& view, + uint32 start, + uint32 end, + const Type startVal ) { - - static_assert(std::is_trivially_copyable_v, "Not valid type for fillSelected"); static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In fillSelected, arguments view and indices must have similar spaces"); + std::is_trivially_copyable_v, "Not valid type for fill" + ); + using ExecutionSpace = + typename ViewType1D::execution_space; + uint32 numElems = end - start; + + pFlow::algorithms::KOKKOS::fillSequence( + view.data() + start, numElems, startVal + ); + + return; +} + +template< + typename Type, + typename... properties, + typename indexType, + typename... indexProperties> +bool +fillSelected( + ViewType1D view, + ViewType1D indices, + uint32 numElems, + Type val +) +{ + static_assert( + std::is_trivially_copyable_v, "Not valid type for fillSelected" + ); + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In fillSelected, arguments view and indices must have similar spaces" + ); using ExSpace = typename ViewType1D::execution_space; - using policy = Kokkos::RangePolicy >; + using policy = Kokkos::RangePolicy>; Kokkos::parallel_for( - "ViewAlgorithms::fillSelected", - policy(0,numElems), - LAMBDA_HD(uint32 i){ - //view[indices[i]]= val; - }); + "ViewAlgorithms::fillSelected", + policy(0, numElems), + LAMBDA_HD(uint32 i){ + // view[indices[i]]= val; + } + ); Kokkos::fence(); return true; } template< - typename Type, - typename... properties, - typename indexType, - typename... indexProperties> -bool fillSelected( - ViewType1D view, - const ViewType1D indices, - const ViewType1D vals, - const uint32 numElems ) + typename Type, + typename... properties, + typename indexType, + typename... indexProperties> +bool +fillSelected( + ViewType1D view, + const ViewType1D indices, + const ViewType1D vals, + const uint32 numElems +) { - static_assert(std::is_trivially_copyable_v, "Not valid type for fillSelected"); static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In fillSelected arguments view and indices must have similar spaces"); + std::is_trivially_copyable_v, "Not valid type for fillSelected" + ); + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In fillSelected arguments view and indices must have similar spaces" + ); + + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - pFlow::algorithms::KOKKOS::fillSelected( - view.data(), - indices.data(), - vals.data(), - numElems - ); + view.data(), indices.data(), vals.data(), numElems + ); return true; } - template -INLINE_FUNCTION_H -T min( - const ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H T +min(const ViewType1D& view, uint32 start, uint32 end) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - return - pFlow::algorithms::KOKKOS::min( - view.data()+start, - numElems); + uint32 numElems = end - start; + + return pFlow::algorithms::KOKKOS::min( + view.data() + start, numElems + ); } template -INLINE_FUNCTION_H -T max( - const ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H T +max(const ViewType1D& view, uint32 start, uint32 end) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + uint32 numElems = end - start; - return - pFlow::algorithms::KOKKOS::max( - view.data()+start, - numElems); -} - -template < - typename dType, - typename... dProperties, - typename sType, - typename... sProperties> -INLINE_FUNCTION_H -void copy( - const ViewType1D& dst, - const ViewType1D& src - ) -{ - Kokkos::deep_copy(dst,src); + return pFlow::algorithms::KOKKOS::max( + view.data() + start, numElems + ); } -template < - typename dType, - typename... dProperties, - typename sType, - typename... sProperties> -INLINE_FUNCTION_H -void copy( - const ViewType1D& dst, - uint32 dStart, - const ViewType1D& src, - uint32 sStart, - uint32 sEnd - ) +template< + typename dType, + typename... dProperties, + typename sType, + typename... sProperties> +INLINE_FUNCTION_H void +copy( + const ViewType1D& dst, + const ViewType1D& src +) { - - range32 sSpan(sStart,sEnd); - range32 dSpan(dStart,dStart+(sEnd-sStart)); - - auto srcSub = Kokkos::subview(src, sSpan); - auto dstSub = Kokkos::subview(dst, dSpan); - - Kokkos::deep_copy(dstSub,srcSub); + Kokkos::deep_copy(dst, src); } -template < - typename Type, - typename... sProperties> -INLINE_FUNCTION_H -void getNth( - Type& dst, - const ViewType1D& src, - const uint32 n - ) +template< + typename dType, + typename... dProperties, + typename sType, + typename... sProperties> +INLINE_FUNCTION_H void +copy( + const ViewType1D& dst, + uint32 dStart, + const ViewType1D& src, + uint32 sStart, + uint32 sEnd +) { - - auto subV = Kokkos::subview(src, Kokkos::make_pair(n,n+1)); - hostViewType1D dstView("getNth",1); - //hostViewTypeScalar - Kokkos::deep_copy(dstView,subV); + range32 sSpan(sStart, sEnd); + range32 dSpan(dStart, dStart + (sEnd - sStart)); + + auto srcSub = Kokkos::subview(src, sSpan); + auto dstSub = Kokkos::subview(dst, dSpan); + + Kokkos::deep_copy(dstSub, srcSub); +} + +template +INLINE_FUNCTION_H void +getNth(Type& dst, const ViewType1D& src, const uint32 n) +{ + auto subV = Kokkos::subview(src, Kokkos::make_pair(n, n + 1)); + hostViewType1D dstView("getNth", 1); + // hostViewTypeScalar + Kokkos::deep_copy(dstView, subV); dst = *dstView.data(); } - template -INLINE_FUNCTION_H -void sort( - ViewType1D& view, - uint32 start, - uint32 end) +INLINE_FUNCTION_H void +sort(ViewType1D& view, uint32 start, uint32 end) { - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + using ExecutionSpace = + typename ViewType1D::execution_space; - if constexpr( isHostAccessible()) - { - pFlow::algorithms::STD::sort( - view.data()+start, - numElems); + uint32 numElems = end - start; + + if constexpr (isHostAccessible()) + { + pFlow::algorithms::STD::sort(view.data() + start, numElems); return; } #ifdef __CUDACC__ - - pFlow::algorithms::CUDA::sort( - view.data()+start, - numElems); + + pFlow::algorithms::CUDA::sort(view.data() + start, numElems); #else static_assert("sort on device is not defined!"); @@ -336,33 +300,32 @@ void sort( } template -INLINE_FUNCTION_H -void sort( - ViewType1D& view, - uint32 start, - uint32 end, - CompareFunc compare) +INLINE_FUNCTION_H void +sort( + ViewType1D& view, + uint32 start, + uint32 end, + CompareFunc compare +) { + using ExecutionSpace = + typename ViewType1D::execution_space; - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; + uint32 numElems = end - start; - if constexpr( isHostAccessible()) + if constexpr (isHostAccessible()) { - pFlow::algorithms::STD::sort( - view.data()+start, - numElems, - compare); - return; + pFlow::algorithms::STD::sort( + view.data() + start, numElems, compare + ); + return; } #ifdef __CUDACC__ - + pFlow::algorithms::CUDA::sort( - view.data()+start, - numElems, - compare); + view.data() + start, numElems, compare + ); #else static_assert("sort on device is not defined!"); @@ -372,163 +335,157 @@ void sort( } template< - typename Type, - typename... properties, - typename permType, - typename... permProperties> -void permuteSort( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& permuteView, - uint32 permStart ) + typename Type, + typename... properties, + typename permType, + typename... permProperties> +void +permuteSort( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& permuteView, + uint32 permStart +) { static_assert( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In permuteSort, view and permuteView should have the same space"); + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In permuteSort, view and permuteView should have the same space" + ); - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - pFlow::algorithms::STD::permuteSort( - view.data()+start, - permuteView.data()+permStart, - numElems); + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + pFlow::algorithms::STD::permuteSort( + view.data() + start, permuteView.data() + permStart, numElems + ); return; - #ifdef __CUDACC__ - + pFlow::algorithms::CUDA::permuteSort( - view.data()+start, - permuteView.data()+permStart, - numElems); + view.data() + start, permuteView.data() + permStart, numElems + ); #else static_assert("sort on device is not defined!"); #endif - } template -INLINE_FUNCTION_HD -int32 binarySearch_(const T* array, int32 length, const T& val) +INLINE_FUNCTION_HD int32 +binarySearch_(const T* array, int32 length, const T& val) { - if(length <= 0) return -1; - - int low = 0; - int high = length - 1; + if (length <= 0) + return -1; - while (low <= high) - { - int mid = low + (high - low)/2; - - if ( array[mid] > val) - { - high = mid - 1; - } - else if ( array[mid] < val) - { - low = mid + 1; - } - else - { - return mid; - } - } + int low = 0; + int high = length - 1; - return -1; // val not found in array[0, length) + while (low <= high) + { + int mid = low + (high - low) / 2; + + if (array[mid] > val) + { + high = mid - 1; + } + else if (array[mid] < val) + { + low = mid + 1; + } + else + { + return mid; + } + } + + return -1; // val not found in array[0, length) } -/// On DEVICE and HOST calls -template< - typename Type, - typename... properties> -INLINE_FUNCTION_HD -uint32 binarySearch( - const ViewType1D& view, - uint32 start, - uint32 end, - const Type& val) +/// On DEVICE and HOST calls +template +INLINE_FUNCTION_HD uint32 +binarySearch( + const ViewType1D& view, + uint32 start, + uint32 end, + const Type& val +) { - - if(end<=start)return -1; + if (end <= start) + return -1; - if(auto res = - binarySearch_(view.data()+start,end-start,val); res!=-1) { - return res+start; + if (auto res = binarySearch_(view.data() + start, end - start, val); + res != -1) + { + return res + start; } - else{ + else + { return res; } } -template< - typename Type, - typename... properties, - typename... dProperties> -void exclusiveScan( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& dView, - uint32 dStart ) +template +void +exclusiveScan( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& dView, + uint32 dStart +) { - - static_assert - ( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In exclusiveScan, view and dView should have the same space" + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In exclusiveScan, view and dView should have the same space" ); - using ExecutionSpace = typename ViewType1D::execution_space; - - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::exclusiveScan( - view.data()+start, - dView.data()+dStart, - numElems); + using ExecutionSpace = + typename ViewType1D::execution_space; + + uint32 numElems = end - start; + + pFlow::algorithms::KOKKOS::exclusiveScan( + view.data() + start, dView.data() + dStart, numElems + ); } - -template< - typename Type, - typename... properties, - typename... dProperties> -void inclusiveScan( - const ViewType1D& view, - uint32 start, - uint32 end, - ViewType1D& dView, - uint32 dStart) +template +void +inclusiveScan( + const ViewType1D& view, + uint32 start, + uint32 end, + ViewType1D& dView, + uint32 dStart +) { - using ExecutionSpace = typename ViewType1D::execution_space; - - static_assert - ( - areAccessible< - typename ViewType1D::execution_space, - typename ViewType1D::memory_space>(), - "In exclusiveScan, view and dView should have the same space" + using ExecutionSpace = + typename ViewType1D::execution_space; + + static_assert( + areAccessible< + typename ViewType1D::execution_space, + typename ViewType1D::memory_space>(), + "In exclusiveScan, view and dView should have the same space" ); + uint32 numElems = end - start; - uint32 numElems = end-start; - - pFlow::algorithms::KOKKOS::inclusiveScan( - view.data()+start, - dView.data()+dStart, - numElems); + pFlow::algorithms::KOKKOS::inclusiveScan( + view.data() + start, dView.data() + dStart, numElems + ); } } // pFlow - -#endif // Viewalgorithms +#endif // __ViewAlgorithms_hpp__ diff --git a/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp b/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp index c4fa96ad..779c0b03 100644 --- a/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp +++ b/src/phasicFlow/Kokkos/baseAlgorithmsFwd_.hpp @@ -2,50 +2,50 @@ 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. -----------------------------------------------------------------------------*/ template -void insertSetElementH -( - ViewType1D& view, - hostViewType1D