From 49af1119f917f72ad9a7c0d4c5a03e1e382e2b58 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Fri, 22 Mar 2024 08:26:14 -0700 Subject: [PATCH] particles and sphereParticles classes were tested for exit boundary --- src/Particles/CMakeLists.txt | 3 +- .../sphereParticles/sphereParticles.cpp | 23 +++---- .../sphereParticles/sphereParticles.hpp | 4 +- .../sphereParticlesKernels.cpp | 16 ++--- .../sphereParticlesKernels.hpp | 18 +++--- .../dynamicPointStructure.cpp | 19 ++++++ .../dynamicPointStructure.hpp | 9 +-- src/Particles/particles/baseShapeNames.cpp | 5 ++ src/Particles/particles/baseShapeNames.hpp | 29 ++++++++- src/Particles/particles/particleIdHandler.cpp | 53 ++++++++-------- src/Particles/particles/particleIdHandler.hpp | 44 ++++++++++---- src/Particles/particles/particles.cpp | 10 +++- src/Particles/particles/particles.hpp | 36 +++++++---- .../particles/regularParticleHandler.cpp | 50 ++++++++++++++++ .../particles/regularParticleHandler.hpp | 60 +++++++++++++++++++ 15 files changed, 287 insertions(+), 92 deletions(-) create mode 100644 src/Particles/particles/regularParticleHandler.cpp create mode 100644 src/Particles/particles/regularParticleHandler.hpp diff --git a/src/Particles/CMakeLists.txt b/src/Particles/CMakeLists.txt index b5c78045..c1008f82 100644 --- a/src/Particles/CMakeLists.txt +++ b/src/Particles/CMakeLists.txt @@ -4,7 +4,8 @@ dynamicPointStructure/dynamicPointStructure.cpp particles/baseShapeNames.cpp particles/shape.cpp particles/particles.cpp -#particles/particleIdHandler.cpp +particles/particleIdHandler.cpp +particles/regularParticleHandler.cpp SphereParticles/sphereShape/sphereShape.cpp SphereParticles/sphereParticles/sphereParticles.cpp SphereParticles/sphereParticles/sphereParticlesKernels.cpp diff --git a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp index 03373f87..01579677 100644 --- a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp +++ b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp @@ -460,11 +460,11 @@ bool pFlow::sphereParticles::beforeIteration() { particles::beforeIteration(); intPredictTimer_.start(); - dynPointStruct().predict(dt(), accelertion()); - rVelIntegration_().predict(dt(),rVelocity_, rAcceleration_); + auto dt = this->dt(); + dynPointStruct().predict(dt, accelertion()); + rVelIntegration_().predict(dt,rVelocity_, rAcceleration_); intPredictTimer_.end(); - //WARNING<<"pFlow::sphereParticles::beforeIteration()"< mass, - deviceViewType1D force, - deviceViewType1D I, - deviceViewType1D torque, - pFlagTypeDevice incld, - deviceViewType1D lAcc, - deviceViewType1D rAcc + const realx3& g, + const deviceViewType1D& mass, + const deviceViewType1D& force, + const deviceViewType1D& I, + const deviceViewType1D& torque, + const pFlagTypeDevice& incld, + deviceViewType1D lAcc, + deviceViewType1D rAcc ) { diff --git a/src/Particles/SphereParticles/sphereParticles/sphereParticlesKernels.hpp b/src/Particles/SphereParticles/sphereParticles/sphereParticlesKernels.hpp index f2ebbe22..628b1c49 100644 --- a/src/Particles/SphereParticles/sphereParticles/sphereParticlesKernels.hpp +++ b/src/Particles/SphereParticles/sphereParticles/sphereParticlesKernels.hpp @@ -30,7 +30,7 @@ namespace pFlow::sphereParticlesKernels void addMassDiamInertiaProp( deviceViewType1D shapeIndex, deviceViewType1D mass, - deviceViewType1D diameter, + deviceViewType1D diameter, deviceViewType1D I, deviceViewType1D propertyId, pFlagTypeDevice incld, @@ -41,14 +41,14 @@ void addMassDiamInertiaProp( ); void acceleration( - realx3 g, - deviceViewType1D mass, - deviceViewType1D force, - deviceViewType1D I, - deviceViewType1D torque, - pFlagTypeDevice incld, - deviceViewType1D lAcc, - deviceViewType1D rAcc + const realx3& g, + const deviceViewType1D& mass, + const deviceViewType1D& force, + const deviceViewType1D& I, + const deviceViewType1D& torque, + const pFlagTypeDevice& incld, + deviceViewType1D lAcc, + deviceViewType1D rAcc ); diff --git a/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp b/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp index 4fbeeecb..593ca168 100644 --- a/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp +++ b/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp @@ -93,6 +93,25 @@ pFlow::dynamicPointStructure::dynamicPointStructure }*/ +bool pFlow::dynamicPointStructure::beforeIteration() +{ + return pointStructure::beforeIteration(); + /*real dt = this->dt(); + + auto& acc = time().lookupObject("acceleration"); + return predict(dt, acc);*/ +} + +bool pFlow::dynamicPointStructure::iterate() +{ + return pointStructure::iterate(); + + /*real dt = this->dt(); + + auto& acc = time().lookupObject("acceleration"); + return correct(dt, acc);*/ +} + bool pFlow::dynamicPointStructure::predict( real dt, realx3PointField_D &acceleration) diff --git a/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp b/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp index 80f006a1..1195f389 100644 --- a/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp +++ b/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp @@ -51,7 +51,7 @@ public: TypeInfo("dynamicPointStructure"); - dynamicPointStructure(systemControl& control); + explicit dynamicPointStructure(systemControl& control); dynamicPointStructure(const dynamicPointStructure& ps) = delete; @@ -81,14 +81,15 @@ public: } /// In the time loop before iterate - //bool beforeIteration() override; + bool beforeIteration() override; /// @brief This is called in time loop. Perform the main calculations /// when the component should evolve along time. - //bool iterate() override; - + bool iterate() override; + + bool predict(real dt, realx3PointField_D& acceleration); bool correct(real dt, realx3PointField_D& acceleration); diff --git a/src/Particles/particles/baseShapeNames.cpp b/src/Particles/particles/baseShapeNames.cpp index f20efc06..eaef39cb 100644 --- a/src/Particles/particles/baseShapeNames.cpp +++ b/src/Particles/particles/baseShapeNames.cpp @@ -23,6 +23,10 @@ Licence: bool pFlow::baseShapeNames::createHashNames() { hashNames_.clear(); + hashes_.clear(); + + std::hash hasher; + uint32 i=0; for(const auto& nm:shapeNames_) { @@ -32,6 +36,7 @@ bool pFlow::baseShapeNames::createHashNames() " repeated name in the list of shape names: " << shapeNames_; return false; } + hashes_.push_back(hasher(nm)); i++; } hashNames_.rehash(0); diff --git a/src/Particles/particles/baseShapeNames.hpp b/src/Particles/particles/baseShapeNames.hpp index 8f4ca44e..bc513b06 100644 --- a/src/Particles/particles/baseShapeNames.hpp +++ b/src/Particles/particles/baseShapeNames.hpp @@ -36,18 +36,23 @@ class baseShapeNames { private: - size_t numShapes_; + size_t numShapes_ = 0; // - hashed list of spheres names wordHashMap hashNames_; /// list of shape names - wordVector shapeNames_; + wordVector shapeNames_{"shapeNames"}; + + /// hash for names + Vector hashes_{"hashes"}; bool createHashNames(); bool readFromDictionary1(); + using hasher = typename wordHashMap::hasher; + protected: virtual @@ -78,6 +83,12 @@ public: return wl; } + inline + const auto& hashes()const + { + return hashes_; + } + inline size_t numShapes()const { @@ -111,6 +122,20 @@ public: return false; } + inline bool hashToIndex(const size_t& hs, uint32& idx) + { + for(auto i=0; i(id); +} - if( maxID != -1 && id.size() == 0 ) +pFlow::uniquePtr + pFlow::particleIdHandler::create(uint32PointField_D &id) +{ + word idHType = angleBracketsNames( + "particleIdHandler", + pFlowProcessors().localRunTypeName()); + + + if( pointFieldvCtorSelector_.search(idHType) ) { - nextId_ = 0; - } - else if( maxID == -1 && id.size()>0 ) - { - - nextId_ = 0; - id.modifyOnHost(); - - ForAll(i,id) - { - if(id.isActive(i)) - { - id[i] = getNextId(); - } - } - - id.syncViews(); - } - else if( maxID >= static_cast(id.size()) ) - { - nextId_ = maxID + 1; + REPORT(1)<<"Creating particle id handler "<< + Green_Text(idHType)< getIdRange(uint32 nNewParticles)=0; + + virtual + bool initialIdCheck()=0; + + static + uniquePtr create( + uint32PointField_D & id); + }; } diff --git a/src/Particles/particles/particles.cpp b/src/Particles/particles/particles.cpp index cbda5c61..7b3a41d6 100644 --- a/src/Particles/particles/particles.cpp +++ b/src/Particles/particles/particles.cpp @@ -40,6 +40,7 @@ pFlow::particles::particles objectFile::WRITE_ALWAYS ), dynPointStruct_, + static_cast(-1), static_cast(-1) ), shapeIndex_ @@ -79,19 +80,22 @@ pFlow::particles::particles objectFile::READ_IF_PRESENT, objectFile::WRITE_ALWAYS), dynPointStruct_, - zero3) + zero3), + idHandler_(particleIdHandler::create(id_)) { this->addToSubscriber(dynPointStruct_); + + idHandler_().initialIdCheck(); + } bool pFlow::particles::beforeIteration() { - dynPointStruct_.beforeIteration(); zeroForce(); zeroTorque(); - return true; + return dynPointStruct_.beforeIteration(); } bool pFlow::particles::iterate() diff --git a/src/Particles/particles/particles.hpp b/src/Particles/particles/particles.hpp index 847b89ac..8ba1cfce 100644 --- a/src/Particles/particles/particles.hpp +++ b/src/Particles/particles/particles.hpp @@ -25,11 +25,11 @@ Licence: #include "dynamicPointStructure.hpp" #include "demComponent.hpp" #include "shape.hpp" +#include "particleIdHandler.hpp" namespace pFlow { - class particles : public observer, @@ -55,14 +55,11 @@ private: /// contact torque field realx3PointField_D contactTorque_; + uniquePtr idHandler_ = nullptr; + static inline - const message defaultMessage_ = - ( - message::CAP_CHANGED+ - message::SIZE_CHANGED+ - message::ITEM_INSERT+ - message::ITEM_DELETE - ); + const message defaultMessage_{message::DEFAULT}; + void zeroForce() @@ -107,10 +104,29 @@ public: explicit particles(systemControl& control); - inline const auto& dynPointStruct()const + inline + const auto& dynPointStruct()const { return dynPointStruct_; - } + } + + inline + const pointStructure& pStruct()const + { + return dynPointStruct_; + } + + inline + const auto& simDomain()const + { + return dynPointStruct_.simDomain(); + } + + inline + const auto& thisDomain()const + { + return dynPointStruct_.thisDomain(); + } inline auto size()const{ return dynPointStruct_.size(); diff --git a/src/Particles/particles/regularParticleHandler.cpp b/src/Particles/particles/regularParticleHandler.cpp new file mode 100644 index 00000000..429ac0b2 --- /dev/null +++ b/src/Particles/particles/regularParticleHandler.cpp @@ -0,0 +1,50 @@ +#include "regularParticleHandler.hpp" + + + +pFlow::regularParticleHandler::regularParticleHandler +( + uint32PointField_D & id +) +: + particleIdHandler(id) +{ +} + +pFlow::Pair + pFlow::regularParticleHandler::getIdRange(uint32 nNewParticles) +{ + uint32 startId; + if(maxId_==-1) + { + startId = 0; + } + else + { + startId = maxId_+1; + } + uint32 endId = startId+nNewParticles-1; + maxId_ = endId; + return {startId, endId}; +} + +bool pFlow::regularParticleHandler::initialIdCheck() +{ + /// empty point structure / no particles in simulation + if( id().pStruct().empty() ) return true; + + uint32 maxId = max(id()); + + /// particles should get ids from 0 to size-1 + if(maxId == -1) + { + fillSequence(id(),0u); + maxId_ = id().size()-1; + } + else + { + maxId_ = maxId; + } + + return true; +} diff --git a/src/Particles/particles/regularParticleHandler.hpp b/src/Particles/particles/regularParticleHandler.hpp new file mode 100644 index 00000000..9c4ee1dd --- /dev/null +++ b/src/Particles/particles/regularParticleHandler.hpp @@ -0,0 +1,60 @@ +/*------------------------------- 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 __regularParticleHandler_hpp__ +#define __regularParticleHandler_hpp__ + +#include "particleIdHandler.hpp" + +namespace pFlow +{ + +class regularParticleHandler +: + public particleIdHandler +{ +private: + + uint32 maxId_ = -1; + +public: + + TypeInfo("particleIdHandler"); + + explicit regularParticleHandler(uint32PointField_D & id); + + ~regularParticleHandler()override = default; + + add_vCtor + ( + particleIdHandler, + regularParticleHandler, + pointField + ); + + Pair getIdRange(uint32 nNewParticles)override; + + bool initialIdCheck()override; + +}; + +} + + +#endif //__regularParticleHandler_hpp__ \ No newline at end of file