From 6a66f1edfdc30222d98ae1a0ed642544e5bea74c Mon Sep 17 00:00:00 2001 From: HRN Date: Fri, 24 May 2024 22:02:46 +0330 Subject: [PATCH 1/2] bug fix for binary file read when dealing with multiple Fields reading from a single file --- src/phasicFlow/containers/Field/Field.cpp | 19 +++++++++++++++---- src/phasicFlow/containers/Field/Field.hpp | 4 ++-- .../repository/IOobject/IOobject.cpp | 2 -- src/phasicFlow/triSurface/triSurface.cpp | 4 ++-- 4 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/phasicFlow/containers/Field/Field.cpp b/src/phasicFlow/containers/Field/Field.cpp index 335fbe49..10e14df8 100644 --- a/src/phasicFlow/containers/Field/Field.cpp +++ b/src/phasicFlow/containers/Field/Field.cpp @@ -21,13 +21,17 @@ Licence: template bool pFlow::Field::read ( - iIstream& is + iIstream& is, + bool resume ) { bool tokenFound = true; - tokenFound = is.findToken(fieldKey_); + if(resume) + tokenFound = is.findTokenResume(fieldKey_); + else + tokenFound = is.findToken(fieldKey_); if( !tokenFound ) { @@ -53,14 +57,21 @@ template bool pFlow::Field::read ( iIstream& is, - const IOPattern& iop + const IOPattern& iop, + bool resume ) { bool tokenFound = true; if(iop.thisProcReadData()) - tokenFound = is.findToken(fieldKey_); + { + if(resume) + tokenFound = is.findTokenResume(fieldKey_); + else + tokenFound = is.findToken(fieldKey_); + } + if( !tokenFound ) { diff --git a/src/phasicFlow/containers/Field/Field.hpp b/src/phasicFlow/containers/Field/Field.hpp index 738811bc..b38d3017 100644 --- a/src/phasicFlow/containers/Field/Field.hpp +++ b/src/phasicFlow/containers/Field/Field.hpp @@ -197,12 +197,12 @@ public: //// - IO operations - bool read(iIstream& is); + bool read(iIstream& is, bool resume = false); bool write(iOstream& os)const; - bool read(iIstream& is, const IOPattern& iop); + bool read(iIstream& is, const IOPattern& iop, bool resume = false); bool write(iOstream& os, const IOPattern& iop )const; diff --git a/src/phasicFlow/repository/IOobject/IOobject.cpp b/src/phasicFlow/repository/IOobject/IOobject.cpp index 4442332f..6fae2f0a 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.cpp +++ b/src/phasicFlow/repository/IOobject/IOobject.cpp @@ -126,7 +126,6 @@ bool pFlow::IOobject::writeObject() const { if(auto ptrOS = outStream(); ptrOS ) { - pOutput<<"Should write field "<name()<name()< Date: Sat, 21 Sep 2024 13:37:03 +0330 Subject: [PATCH 2/2] first commit after code loss - develop branch --- .../AdamsBashforth2/AB2Kernels.hpp | 63 +++++++++++++ .../boundaries/boundaryIntegration.cpp | 55 +++++++++++ .../boundaries/boundaryIntegration.hpp | 91 +++++++++++++++++++ .../boundaries/boundaryIntegrationList.cpp | 41 +++++++++ .../boundaries/boundaryIntegrationList.hpp | 45 +++++++++ src/Interaction/CMakeLists.txt | 5 +- .../boundarySphereParticles.cpp | 64 +++++++++++++ .../boundarySphereParticles.hpp | 80 ++++++++++++++++ .../boundarySphereParticlesList.cpp | 19 ++++ .../boundarySphereParticlesList.hpp | 36 ++++++++ src/phasicFlow/globals/boundaryConfigs.hpp | 10 ++ src/phasicFlow/processors/MPITimer.cpp | 88 ++++++++++++++++++ src/phasicFlow/processors/MPITimer.hpp | 55 +++++++++++ .../boundaries/boundariesMask.hpp | 50 ++++++++++ 14 files changed, 700 insertions(+), 2 deletions(-) create mode 100644 src/Integration/AdamsBashforth2/AB2Kernels.hpp create mode 100644 src/Integration/boundaries/boundaryIntegration.cpp create mode 100644 src/Integration/boundaries/boundaryIntegration.hpp create mode 100644 src/Integration/boundaries/boundaryIntegrationList.cpp create mode 100644 src/Integration/boundaries/boundaryIntegrationList.hpp create mode 100644 src/Particles/SphereParticles/boundarySphereParticles.cpp create mode 100644 src/Particles/SphereParticles/boundarySphereParticles.hpp create mode 100644 src/Particles/SphereParticles/boundarySphereParticlesList.cpp create mode 100644 src/Particles/SphereParticles/boundarySphereParticlesList.hpp create mode 100644 src/phasicFlow/globals/boundaryConfigs.hpp create mode 100644 src/phasicFlow/processors/MPITimer.cpp create mode 100644 src/phasicFlow/processors/MPITimer.hpp create mode 100644 src/phasicFlow/structuredData/boundaries/boundariesMask.hpp diff --git a/src/Integration/AdamsBashforth2/AB2Kernels.hpp b/src/Integration/AdamsBashforth2/AB2Kernels.hpp new file mode 100644 index 00000000..578cf07e --- /dev/null +++ b/src/Integration/AdamsBashforth2/AB2Kernels.hpp @@ -0,0 +1,63 @@ + + +#ifndef __AB2Kernels_hpp__ +#define __AB2Kernels_hpp__ + +#include "KokkosTypes.hpp" +#include "types.hpp" + +namespace pFlow::AB2Kernels +{ +inline +bool intAllActive( + const word& name, + real dt, + rangeU32 activeRng, + const deviceViewType1D& y, + const deviceViewType1D& dy, + const deviceViewType1D& dy1 +) +{ + Kokkos::parallel_for( + name, + deviceRPolicyStatic (activeRng.start(), activeRng.end()), + LAMBDA_HD(uint32 i){ + y[i] += dt*(static_cast(1.5) * dy[i] - static_cast(0.5) * dy1[i]); + dy1[i] = dy[i]; + }); + Kokkos::fence(); + + return true; +} + +inline +bool intScattered +( + const word& name, + real dt, + const pFlagTypeDevice& activePoints, + const deviceViewType1D& y, + const deviceViewType1D& dy, + const deviceViewType1D& dy1 +) +{ + + Kokkos::parallel_for( + name, + deviceRPolicyStatic (activePoints.activeRange().start(), activePoints.activeRange().end()), + LAMBDA_HD(uint32 i){ + if( activePoints(i)) + { + y[i] += dt*(static_cast(1.5) * dy[i] - static_cast(0.5) * dy1[i]); + dy1[i] = dy[i]; + } + }); + Kokkos::fence(); + + + return true; +} + +} + +#endif \ No newline at end of file diff --git a/src/Integration/boundaries/boundaryIntegration.cpp b/src/Integration/boundaries/boundaryIntegration.cpp new file mode 100644 index 00000000..e13a5624 --- /dev/null +++ b/src/Integration/boundaries/boundaryIntegration.cpp @@ -0,0 +1,55 @@ +#include "boundaryIntegration.hpp" +#include "pointStructure.hpp" + + +pFlow::boundaryIntegration::boundaryIntegration( + const boundaryBase &boundary, + const pointStructure &pStruct, + const word &method, + integration& intgrtn +) +: + generalBoundary(boundary, pStruct, "", method), + integration_(intgrtn) +{} + +pFlow::uniquePtr pFlow::boundaryIntegration::create( + const boundaryBase &boundary, + const pointStructure &pStruct, + const word &method, + integration& intgrtn +) +{ + + word bType = angleBracketsNames2( + "boundaryIntegration", + boundary.type(), + method); + + word altBType{"boundaryIntegration"}; + + if( boundaryBasevCtorSelector_.search(bType) ) + { + pOutput.space(4)<<"Creating boundary "<< Green_Text(bType)<< + " for "<"); + + boundaryIntegration( + const boundaryBase& boundary, + const pointStructure& pStruct, + const word& method, + integration& intgrtn); + + ~boundaryIntegration()override = default; + + create_vCtor( + boundaryIntegration, + boundaryBase, + ( + const boundaryBase& boundary, + const pointStructure& pStruct, + const word& method, + integration& intgrtn + ), + (boundary, pStruct, method, intgrtn) + ); + + add_vCtor( + boundaryIntegration, + boundaryIntegration, + boundaryBase + ); + + bool hearChanges( + real t, + real dt, + uint32 iter, + const message &msg, + const anyList &varList) override + { + return true; + } + + const integration& Integration()const + { + return integration_; + } + + virtual + bool correct(real dt, const realx3PointField_D& y, const realx3PointField_D& dy) + { + return true; + } + + virtual + bool correctPStruct(real dt, const realx3PointField_D& vel) + { + return true; + } + + static + uniquePtr create( + const boundaryBase& boundary, + const pointStructure& pStruct, + const word& method, + integration& intgrtn); + +}; + +} + +#endif \ No newline at end of file diff --git a/src/Integration/boundaries/boundaryIntegrationList.cpp b/src/Integration/boundaries/boundaryIntegrationList.cpp new file mode 100644 index 00000000..c7e2ad3b --- /dev/null +++ b/src/Integration/boundaries/boundaryIntegrationList.cpp @@ -0,0 +1,41 @@ +#include "boundaryIntegrationList.hpp" +#include "integration.hpp" + +pFlow::boundaryIntegrationList::boundaryIntegrationList( + const pointStructure &pStruct, + const word &method, + integration &intgrtn +) +: + ListPtr(6), + boundaries_(pStruct.boundaries()) +{ + + for(uint32 i=0; i<6; i++) + { + this->set( + i, + boundaryIntegration::create( + boundaries_[i], + pStruct, + method, + intgrtn + ) + ); + } + +} + +bool pFlow::boundaryIntegrationList::correct(real dt, realx3PointField_D &y, realx3PointField_D &dy) +{ + for(auto& bndry:*this) + { + if(!bndry->correct(dt, y, dy)) + { + fatalErrorInFunction; + return false; + } + + } + return true; +} diff --git a/src/Integration/boundaries/boundaryIntegrationList.hpp b/src/Integration/boundaries/boundaryIntegrationList.hpp new file mode 100644 index 00000000..a4e262a0 --- /dev/null +++ b/src/Integration/boundaries/boundaryIntegrationList.hpp @@ -0,0 +1,45 @@ + +#ifndef __boundaryIntegrationList_hpp__ +#define __boundaryIntegrationList_hpp__ + + +#include "boundaryList.hpp" +#include "ListPtr.hpp" +#include "boundaryIntegration.hpp" + + +namespace pFlow +{ + +class integration; + +class boundaryIntegrationList +: + public ListPtr +{ +private: + + const boundaryList& boundaries_; + +public: + + boundaryIntegrationList( + const pointStructure& pStruct, + const word& method, + integration& intgrtn + ); + + ~boundaryIntegrationList()=default; + + bool correct( + real dt, + realx3PointField_D& y, + realx3PointField_D& dy); +}; + + + +} + + +#endif //__boundaryIntegrationList_hpp__ \ No newline at end of file diff --git a/src/Interaction/CMakeLists.txt b/src/Interaction/CMakeLists.txt index c0265808..3b985647 100644 --- a/src/Interaction/CMakeLists.txt +++ b/src/Interaction/CMakeLists.txt @@ -7,8 +7,7 @@ contactSearch/methods/cellBased/NBS/NBS.cpp contactSearch/methods/cellBased/NBS/cellsWallLevel0.cpp contactSearch/boundaries/boundaryContactSearch/boundaryContactSearch.cpp -contactSearch/boundaries/twoPartContactSearch/twoPartContactSearchKernels.cpp -contactSearch/boundaries/twoPartContactSearch/twoPartContactSearch.cpp + contactSearch/boundaries/periodicBoundaryContactSearch/ppwBndryContactSearchKernels.cpp contactSearch/boundaries/periodicBoundaryContactSearch/ppwBndryContactSearch.cpp contactSearch/boundaries/periodicBoundaryContactSearch/wallBoundaryContactSearch.cpp @@ -28,6 +27,8 @@ if(pFlow_Build_MPI) list(APPEND SourceFiles contactSearch/boundaries/processorBoundaryContactSearch/processorBoundaryContactSearch.cpp sphereInteraction/boundaries/processorBoundarySphereInteraction/processorBoundarySphereInteractions.cpp + contactSearch/boundaries/twoPartContactSearch/twoPartContactSearchKernels.cpp + contactSearch/boundaries/twoPartContactSearch/twoPartContactSearch.cpp ) endif() diff --git a/src/Particles/SphereParticles/boundarySphereParticles.cpp b/src/Particles/SphereParticles/boundarySphereParticles.cpp new file mode 100644 index 00000000..8eb5eaa0 --- /dev/null +++ b/src/Particles/SphereParticles/boundarySphereParticles.cpp @@ -0,0 +1,64 @@ +#include "boundarySphereParticles.hpp" +#include "boundaryBase.hpp" +#include "sphereParticles.hpp" + + +pFlow::boundarySphereParticles::boundarySphereParticles( + const boundaryBase &boundary, + sphereParticles &prtcls +) +: + generalBoundary(boundary, prtcls.pStruct(), "", ""), + particles_(prtcls) +{ + +} + +pFlow::sphereParticles &pFlow::boundarySphereParticles::Particles() +{ + return particles_; +} + +const pFlow::sphereParticles &pFlow::boundarySphereParticles::Particles() const +{ + return particles_; +} + +pFlow::uniquePtr pFlow::boundarySphereParticles::create( + const boundaryBase &boundary, + sphereParticles &prtcls +) +{ + + word bType = angleBracketsNames2( + "boundarySphereParticles", + pFlowProcessors().localRunTypeName(), + boundary.type()); + + word altBType{"boundarySphereParticles"}; + + if( boundaryBasevCtorSelector_.search(bType) ) + { + pOutput.space(4)<<"Creating boundary "<< Green_Text(bType)<< + " for "<"); + + boundarySphereParticles( + const boundaryBase &boundary, + sphereParticles& prtcls + ); + + create_vCtor( + boundarySphereParticles, + boundaryBase, + ( + const boundaryBase &boundary, + sphereParticles& prtcls + ), + (boundary, prtcls) + ); + + add_vCtor( + boundarySphereParticles, + boundarySphereParticles, + boundaryBase + ); + + sphereParticles& Particles(); + + const sphereParticles& Particles()const; + + bool hearChanges( + real t, + real dt, + uint32 iter, + const message &msg, + const anyList &varList) override + { + return true; + } + + virtual + bool acceleration(const timeInfo& ti, const realx3& g) + { + return true; + } + + static + uniquePtr create( + const boundaryBase &boundary, + sphereParticles& prtcls); + +}; + + +} + + + +#endif diff --git a/src/Particles/SphereParticles/boundarySphereParticlesList.cpp b/src/Particles/SphereParticles/boundarySphereParticlesList.cpp new file mode 100644 index 00000000..5cbebc32 --- /dev/null +++ b/src/Particles/SphereParticles/boundarySphereParticlesList.cpp @@ -0,0 +1,19 @@ +#include "boundarySphereParticlesList.hpp" + +pFlow::boundarySphereParticlesList::boundarySphereParticlesList( + const boundaryList &bndrs, + sphereParticles &prtcls +) +: + ListPtr(bndrs.size()), + boundaries_(bndrs) +{ + for(auto i=0; iset + ( + i, + boundarySphereParticles::create(boundaries_[i], prtcls) + ); + } +} \ No newline at end of file diff --git a/src/Particles/SphereParticles/boundarySphereParticlesList.hpp b/src/Particles/SphereParticles/boundarySphereParticlesList.hpp new file mode 100644 index 00000000..cd6770df --- /dev/null +++ b/src/Particles/SphereParticles/boundarySphereParticlesList.hpp @@ -0,0 +1,36 @@ + + +#ifndef __boundarySphereParticlesList_hpp__ +#define __boundarySphereParticlesList_hpp__ + +#include "ListPtr.hpp" +#include "boundaryList.hpp" +#include "boundarySphereParticles.hpp" + +namespace pFlow +{ + +class boundarySphereParticlesList +: + public ListPtr +{ +private: + + const boundaryList& boundaries_; + +public: + + boundarySphereParticlesList( + const boundaryList& bndrs, + sphereParticles& prtcls + ); + + ~boundarySphereParticlesList()=default; + +}; + +} + + + +#endif \ No newline at end of file diff --git a/src/phasicFlow/globals/boundaryConfigs.hpp b/src/phasicFlow/globals/boundaryConfigs.hpp new file mode 100644 index 00000000..11574957 --- /dev/null +++ b/src/phasicFlow/globals/boundaryConfigs.hpp @@ -0,0 +1,10 @@ +#ifndef __boundaryConfigs_hpp__ +#define __boundaryConfigs_hpp__ + + +#ifndef BoundaryModel1 +//#define BoundaryModel1 +#endif + + +#endif //__boundaryConfigs_hpp__ \ No newline at end of file diff --git a/src/phasicFlow/processors/MPITimer.cpp b/src/phasicFlow/processors/MPITimer.cpp new file mode 100644 index 00000000..cfa55631 --- /dev/null +++ b/src/phasicFlow/processors/MPITimer.cpp @@ -0,0 +1,88 @@ +#include "MPITimer.hpp" + +#ifdef pFlow_Build_MPI + #include "pFlowProcessors.hpp" + #include "procCommunication.hpp" +#endif + +pFlow::real pFlow::MPITimer::totalTimeMax() const +{ + return accTimersTotalMax(); +} + +std::vector pFlow::MPITimer::totalTimeAllToAll() const +{ +#ifdef pFlow_Build_MPI + MPI::procCommunication comm(pFlowProcessors()); + auto [totTime, succs] = comm.collectAllToAll(totalTime()); + return totTime; +#else + return std::vector(1, totalTime()); +#endif +} + +std::vector pFlow::MPITimer::totalTimeAllToMaster() const +{ +#ifdef pFlow_Build_MPI + MPI::procCommunication comm(pFlowProcessors()); + auto [totTime, succs] = comm.collectAllToMaster(totalTime()); + return totTime; +#else + return std::vector(1, totalTime()); +#endif +} + +pFlow::real pFlow::MPITimer::averageTimeMax() const +{ + return Timer::averageTimeMax(); +} + +std::vector pFlow::MPITimer::averageTimeAllToAll() const +{ +#ifdef pFlow_Build_MPI + MPI::procCommunication comm(pFlowProcessors()); + auto [totTime, succs] = comm.collectAllToAll(averageTime()); + return totTime; +#else + return std::vector(1, averageTime()); +#endif +} + +std::vector pFlow::MPITimer::averageTimeAllAtoMaster() const +{ +#ifdef pFlow_Build_MPI + MPI::procCommunication comm(pFlowProcessors()); + auto [totTime, succs] = comm.collectAllToMaster(averageTime()); + return totTime; +#else + return std::vector(1, averageTime()); +#endif +} + +bool pFlow::MPITimer::write(iOstream &os) const +{ + const auto ts = totalTimeAllToAll(); + auto maxloc = std::distance(ts.begin(), std::max_element(ts.begin(), ts.end())); + os<<'('; + for(auto i=0; i totalTimeAllToAll()const; + + std::vector totalTimeAllToMaster()const; + + real averageTimeMax()const; + + std::vector averageTimeAllToAll()const; + + std::vector averageTimeAllAtoMaster()const; + + // call this from all processors in pFlowProcessors + bool write(iOstream& os)const; + +}; + +MPITimer& ComputationTimer(); + +} + + + +#endif \ No newline at end of file diff --git a/src/phasicFlow/structuredData/boundaries/boundariesMask.hpp b/src/phasicFlow/structuredData/boundaries/boundariesMask.hpp new file mode 100644 index 00000000..13875f2b --- /dev/null +++ b/src/phasicFlow/structuredData/boundaries/boundariesMask.hpp @@ -0,0 +1,50 @@ + +#ifndef __boundariesMask_hpp__ +#define __boundariesMask_hpp__ + +#include + +namespace pFlow +{ + +template +class boundariesMask +: + public std::array +{ +public: + + boundariesMask()=default; + + boundariesMask(bool val) + { + this->fill(val); + } + + boundariesMask(std::initializer_list l) + : + std::array(l) + {} + + inline + bool allElements(bool val) + { + return std::all_of(this->begin(), this->end(), [val](bool v) { return v==val;} ); + } + + inline + bool anyElement(bool val) + { + return std::any_of(this->begin(), this->end(), [val](bool v) { return v==val;} ); + } + + inline + bool noElement(bool val) + { + return std::none_of(this->begin(), this->end(), [val](bool v) { return v==val;} ); + } +}; + +} + +#endif //__boundariesMask_hpp__ \ No newline at end of file