From 651c74313cba0d7ce67151a90b8070be8a15e782 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Sun, 2 Apr 2023 23:34:37 -0700 Subject: [PATCH] bug fix for particle insertion and id handling --- src/Particles/CMakeLists.txt | 1 + .../sphereParticles/sphereParticles.cpp | 24 +++++--- .../sphereParticles/sphereParticles.hpp | 5 +- src/Particles/particles/particleIdHandler.cpp | 58 +++++++++++++++++++ src/Particles/particles/particleIdHandler.hpp | 35 +---------- src/Particles/particles/particles.hpp | 5 +- .../containers/VectorHD/VectorDual.hpp | 2 +- .../containers/VectorHD/VectorSingle.hpp | 7 ++- .../pointStructure/pointStructure.cpp | 3 +- 9 files changed, 88 insertions(+), 52 deletions(-) create mode 100644 src/Particles/particles/particleIdHandler.cpp diff --git a/src/Particles/CMakeLists.txt b/src/Particles/CMakeLists.txt index 09257ef9..9c23631f 100644 --- a/src/Particles/CMakeLists.txt +++ b/src/Particles/CMakeLists.txt @@ -2,6 +2,7 @@ set(SourceFiles dynamicPointStructure/dynamicPointStructure.cpp particles/particles.cpp +particles/particleIdHandler.cpp SphereParticles/sphereShape/sphereShape.cpp SphereParticles/sphereParticles/sphereParticles.cpp Insertion/shapeMixture/shapeMixture.cpp diff --git a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp index f4908782..cfa0ea80 100644 --- a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp +++ b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp @@ -77,7 +77,7 @@ bool pFlow::sphereParticles::initializeParticles() 0, static_cast(shapeName_.size())); - return insertSphereParticles(shapeName_, indices); + return insertSphereParticles(shapeName_, indices, false); } @@ -119,11 +119,11 @@ bool pFlow::sphereParticles::iterate() accelerationTimer_.end(); intCorrectTimer_.start(); - //INFO<<"before correct dyn "<dt(), accelertion_); - //INFO<<"after correct dyn "<dt(), rVelocity_, rAcceleration_); - //INFO<<"after correct rvel "<> getFieldObjectList()const override; diff --git a/src/Particles/particles/particleIdHandler.cpp b/src/Particles/particles/particleIdHandler.cpp new file mode 100644 index 00000000..71dec22a --- /dev/null +++ b/src/Particles/particles/particleIdHandler.cpp @@ -0,0 +1,58 @@ +/*------------------------------- 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 "particleIdHandler.hpp" + + + +pFlow::particleIdHandler::particleIdHandler(int32PointField_HD & id) +{ + int32 maxID = maxActive(id); + + if( maxID != -1 && id.size() == 0 ) + { + 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; + } + else + { + nextId_ = id.size(); + } +} + diff --git a/src/Particles/particles/particleIdHandler.hpp b/src/Particles/particles/particleIdHandler.hpp index abe708b4..d93e6b1f 100644 --- a/src/Particles/particles/particleIdHandler.hpp +++ b/src/Particles/particles/particleIdHandler.hpp @@ -32,39 +32,8 @@ class particleIdHandler protected: int32 nextId_=0; public: - particleIdHandler(int32PointField_HD & id) - { - int32 maxID = maxActive(id); - - if( maxID != -1 && id.size() == 0 ) - { - 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; - } - else - { - nextId_ = id.size(); - } - } - + particleIdHandler(int32PointField_HD & id); + int32 getNextId() { return nextId_++; diff --git a/src/Particles/particles/particles.hpp b/src/Particles/particles/particles.hpp index 0cfcdf57..0341ef5a 100644 --- a/src/Particles/particles/particles.hpp +++ b/src/Particles/particles/particles.hpp @@ -246,10 +246,7 @@ public: auto domain = this->control().domain(); auto numMarked = dynPointStruct_.markDeleteOutOfBox(domain); - /*if(numMarked) - { - output<<"\nNumber of deleted points/particles that are out of domain box: "<zeroForce(); this->zeroTorque(); diff --git a/src/phasicFlow/containers/VectorHD/VectorDual.hpp b/src/phasicFlow/containers/VectorHD/VectorDual.hpp index a5310bd7..c4f29fe1 100644 --- a/src/phasicFlow/containers/VectorHD/VectorDual.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorDual.hpp @@ -128,7 +128,7 @@ protected: // use actualCap = true only for reserve INLINE_FUNCTION_H void changeSize(size_t n, bool actualCap=false) { - if(n >= capacity_ ) + if(n > capacity_ ) { if(actualCap) capacity_ = n; diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index ab6df542..f2e35fa6 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -28,6 +28,8 @@ Licence: #include "Vector.hpp" #include "indexContainer.hpp" +#include "streams.hpp" + #include "KokkosTypes.hpp" #include "ViewAlgorithms.hpp" @@ -106,7 +108,7 @@ protected: // use actualCap = true only for reserve INLINE_FUNCTION_H void changeSize(size_t n, bool actualCap=false) { - if(n >= capacity_ ) + if(n > capacity_ ) { if(actualCap) capacity_ = n; @@ -565,7 +567,8 @@ public: if(indices.size() != vals.size())return false; auto maxInd = indices.max(); - + /*output<<"maxInd "<< maxInd<empty() || maxInd > size()-1 ) { resize(maxInd+1); diff --git a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp index 6a21e808..cacb6280 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp +++ b/src/phasicFlow/structuredData/pointStructure/pointStructure.cpp @@ -83,6 +83,7 @@ pFlow::uniquePtr return makeUnique( activeRange_.second, activeRange_.second+numNewPoints); + } // second, check if there is space at the beginning @@ -334,8 +335,6 @@ pFlow::uniquePtr pFlow::pointStructure::insertPoints static_cast(PointFlag::ACTIVE)) )return nullptr; - - setNumMaxPoints(); auto minInd = newPointsPtr().min(); auto maxInd = newPointsPtr().max();