From 789e5863d4947564c711c9922a1cb90cb393433b Mon Sep 17 00:00:00 2001 From: HenrikAsmuth <henrik.asmuth@geo.uu.se> Date: Wed, 12 Oct 2022 17:55:26 +0200 Subject: [PATCH] Add sorting and clean up of fluidNodeIncies* --- src/gpu/GridGenerator/grid/Grid.h | 4 ++ .../grid/GridBuilder/GridBuilder.h | 3 + .../grid/GridBuilder/LevelGridBuilder.cpp | 15 +++++ .../grid/GridBuilder/LevelGridBuilder.h | 3 + src/gpu/GridGenerator/grid/GridImp.cpp | 65 +++++++++++++++++++ src/gpu/GridGenerator/grid/GridImp.h | 3 + .../DataStructureInitializer/GridProvider.h | 1 + .../GridReaderFiles/GridReader.cpp | 5 ++ .../GridReaderFiles/GridReader.h | 1 + .../GridReaderGenerator/GridGenerator.cpp | 7 ++ .../GridReaderGenerator/GridGenerator.h | 1 + 11 files changed, 108 insertions(+) diff --git a/src/gpu/GridGenerator/grid/Grid.h b/src/gpu/GridGenerator/grid/Grid.h index ef21f1e22..2c4a8b63e 100644 --- a/src/gpu/GridGenerator/grid/Grid.h +++ b/src/gpu/GridGenerator/grid/Grid.h @@ -182,6 +182,10 @@ public: virtual void addFluidNodeIndicesMacroVars(std::vector<uint> _fluidNodeIndicesMacroVars) = 0; virtual void addFluidNodeIndicesApplyBodyForce(std::vector<uint> _fluidNodeIndicesApplyBodyForce) = 0; virtual void addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndicesAllFeatures) = 0; + virtual void sortFluidNodeIndicesMacroVars() = 0; + virtual void sortFluidNodeIndicesApplyBodyForce() = 0; + virtual void sortFluidNodeIndicesAllFeatures() = 0; + }; #endif diff --git a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h index 448737e90..c1aad5a33 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/GridBuilder.h @@ -140,6 +140,9 @@ public: virtual void addFluidNodeIndicesMacroVars(std::vector<uint> fluidNodeIndicesMacroVars, uint level) = 0; virtual void addFluidNodeIndicesApplyBodyForce(std::vector<uint> fluidNodeIndicesApplyBodyForce, uint level) = 0; virtual void addFluidNodeIndicesAllFeatures(std::vector<uint> fluidNodeIndicesAllFeatures, uint level) = 0; + virtual void sortFluidNodeIndicesMacroVars(uint level) = 0; + virtual void sortFluidNodeIndicesApplyBodyForce(uint level) = 0; + virtual void sortFluidNodeIndicesAllFeatures(uint level) = 0; }; diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp index e29ef28c2..9c5f439b5 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.cpp @@ -690,4 +690,19 @@ void LevelGridBuilder::addFluidNodeIndicesApplyBodyForce(std::vector<uint> fluid void LevelGridBuilder::addFluidNodeIndicesAllFeatures(std::vector<uint> fluidNodeIndicesAllFeatures, uint level) { grids[level]->addFluidNodeIndicesAllFeatures(fluidNodeIndicesAllFeatures); +} + +void LevelGridBuilder::sortFluidNodeIndicesMacroVars(uint level) +{ + +} + +void LevelGridBuilder::sortFluidNodeIndicesApplyBodyForce(uint level) +{ + +} + +void LevelGridBuilder::sortFluidNodeIndicesAllFeatures(uint level) +{ + } \ No newline at end of file diff --git a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h index 8efb3de4c..214829524 100644 --- a/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h +++ b/src/gpu/GridGenerator/grid/GridBuilder/LevelGridBuilder.h @@ -198,6 +198,9 @@ public: void addFluidNodeIndicesMacroVars(std::vector<uint> fluidNodeIndicesMacroVars, uint level) override; void addFluidNodeIndicesApplyBodyForce(std::vector<uint> fluidNodeIndicesApplyBodyForce, uint level) override; void addFluidNodeIndicesAllFeatures(std::vector<uint> fluidNodeIndicesAllFeatures, uint level) override; + void sortFluidNodeIndicesMacroVars(uint level) override; + void sortFluidNodeIndicesApplyBodyForce(uint level) override; + void sortFluidNodeIndicesAllFeatures(uint level) override; }; #endif diff --git a/src/gpu/GridGenerator/grid/GridImp.cpp b/src/gpu/GridGenerator/grid/GridImp.cpp index b79ace78c..e886cac20 100644 --- a/src/gpu/GridGenerator/grid/GridImp.cpp +++ b/src/gpu/GridGenerator/grid/GridImp.cpp @@ -2114,6 +2114,71 @@ void GridImp::addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndices this->fluidNodeIndicesAllFeatures.insert(fluidNodeIndicesAllFeatures.end(), fluidNodeIndicesAllFeatures.begin(), _fluidNodeIndicesAllFeatures.end()); } +void GridImp::sortFluidNodeIndicesMacroVars() +{ + if(this->fluidNodeIndicesMacroVars.size()>0) + { + sort(this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end()); + // Remove duplicates + this->fluidNodeIndicesMacroVars.erase( unique( this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end() ), this->fluidNodeIndicesMacroVars.end() ); + + // Remove indices of fluidNodeIndicesAllFeatures from fluidNodeIndicesMacroVars + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + this->fluidNodeIndicesMacroVars.erase( std::remove_if( this->fluidNodeIndicesMacroVars.begin(), this->fluidNodeIndicesMacroVars.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndicesMacroVars.end() + ); + } + + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesMacroVars.begin(),fluidNodeIndicesMacroVars.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + +void GridImp::sortFluidNodeIndicesApplyBodyForce() +{ + if(this->fluidNodeIndicesApplyBodyForce.size()>0) + { + sort(this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end()); + // Remove duplicates + this->fluidNodeIndicesApplyBodyForce.erase( unique( this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end() ), this->fluidNodeIndicesApplyBodyForce.end() ); + + // Remove indices of fluidNodeIndicesAllFeatures from fluidNodeIndicesMacroVars + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + this->fluidNodeIndicesApplyBodyForce.erase( std::remove_if( this->fluidNodeIndicesApplyBodyForce.begin(), this->fluidNodeIndicesApplyBodyForce.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndicesApplyBodyForce.end() + ); + } + + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesApplyBodyForce.begin(),fluidNodeIndicesApplyBodyForce.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + +void GridImp::sortFluidNodeIndicesAllFeatures() +{ + if(this->fluidNodeIndicesAllFeatures.size()>0) + { + sort(this->fluidNodeIndicesAllFeatures.begin(), this->fluidNodeIndicesAllFeatures.end()); + // Remove duplicates + this->fluidNodeIndicesAllFeatures.erase( unique( this->fluidNodeIndicesAllFeatures.begin(), this->fluidNodeIndicesAllFeatures.end() ), this->fluidNodeIndicesAllFeatures.end() ); + // Remove indices of fluidNodeIndicesMacroVars from fluidNodeIndices + this->fluidNodeIndices.erase( std::remove_if( this->fluidNodeIndices.begin(), this->fluidNodeIndices.end(), + [&](auto x){return binary_search(fluidNodeIndicesAllFeatures.begin(),fluidNodeIndicesAllFeatures.end(),x);} ), + this->fluidNodeIndices.end() + ); + } +} + void GridImp::print() const { printf("min: (%2.4f, %2.4f, %2.4f), max: (%2.4f, %2.4f, %2.4f), size: %d, delta: %2.4f\n", startX, startY, startZ, diff --git a/src/gpu/GridGenerator/grid/GridImp.h b/src/gpu/GridGenerator/grid/GridImp.h index 51510a90e..d368f68e4 100644 --- a/src/gpu/GridGenerator/grid/GridImp.h +++ b/src/gpu/GridGenerator/grid/GridImp.h @@ -369,6 +369,9 @@ public: void addFluidNodeIndicesMacroVars(std::vector<uint> _fluidNodeIndicesMacroVars) override; void addFluidNodeIndicesApplyBodyForce(std::vector<uint> _fluidNodeIndicesApplyBodyForce) override; void addFluidNodeIndicesAllFeatures(std::vector<uint> _fluidNodeIndicesAllFeatures) override; + void sortFluidNodeIndicesMacroVars() override; + void sortFluidNodeIndicesApplyBodyForce() override; + void sortFluidNodeIndicesAllFeatures() override; public: struct CommunicationIndices { diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h index c6c703cd3..0ba30d121 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridProvider.h @@ -32,6 +32,7 @@ public: virtual void allocArrays_fluidNodeIndicesBorder() = 0; virtual void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) = 0; + virtual void sortFluidNodeTags() = 0; virtual void setDimensions() = 0; virtual void setBoundingBox() = 0; diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp index 92c9688d9..e423cf871 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.cpp @@ -233,6 +233,11 @@ void GridReader::tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, C // TODO } +void GridReader::sortFluidNodeTags(){ + std::cout << "GridReader::sortFluidNodeTags not implemented" << std::endl; + // TODO +} + void GridReader::setPressureValues(int channelSide) const { for (unsigned int level = 0; level <= BC_Values[channelSide]->getLevel(); level++) diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h index 128e90222..70ddb1f47 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderFiles/GridReader.h @@ -43,6 +43,7 @@ public: void allocArrays_fluidNodeIndicesBorder() override; void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) override; + void sortFluidNodeTags() override; void initalValuesDomainDecompostion(int level); diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp index 1975f9a6c..c9aaa1d1b 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.cpp @@ -135,6 +135,13 @@ void GridGenerator::tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices } +void GridGenerator::sortFluidNodeTags() { + for (uint level = 0; level < builder->getNumberOfGridLevels(); level++) + { + + } +} + void GridGenerator::allocArrays_BoundaryValues() { std::cout << "------read BoundaryValues------" << std::endl; diff --git a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h index 7b72564f3..fed5ac7f4 100644 --- a/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h +++ b/src/gpu/VirtualFluids_GPU/DataStructureInitializer/GridReaderGenerator/GridGenerator.h @@ -75,6 +75,7 @@ public: void allocArrays_fluidNodeIndicesBorder() override; void tagFluidNodeIndices(std::vector<uint> taggedFluidNodeIndices, CollisionTemplate tag, uint level) override; + void sortFluidNodeTags() override; virtual void setDimensions() override; virtual void setBoundingBox() override; -- GitLab