From d268cf9966492c37acea6c03cb880ac43b239d57 Mon Sep 17 00:00:00 2001 From: Soeren Peters <peters@irmb.tu-bs.de> Date: Tue, 20 Oct 2020 10:27:22 +0200 Subject: [PATCH] Apply clang format to cpu, except for the kernel files. --- .../metis/metis-5.1.1/libmetis/CMakeLists.txt | 2 + .../CreateDemObjectsCoProcessor.cpp | 152 +- .../DemCoupling/CreateDemObjectsCoProcessor.h | 42 +- src/cpu/DemCoupling/DemCoProcessor.cpp | 781 ++- src/cpu/DemCoupling/DemCoProcessor.h | 53 +- .../DemCoupling/MovableObjectInteractor.cpp | 220 +- src/cpu/DemCoupling/MovableObjectInteractor.h | 26 +- .../DemCoupling/PePartitioningGridVisitor.cpp | 120 +- .../DemCoupling/PePartitioningGridVisitor.h | 45 +- .../RestartDemObjectsCoProcessor.cpp | 164 +- .../RestartDemObjectsCoProcessor.h | 35 +- .../WriteDemObjectsCoProcessor.cpp | 107 +- .../DemCoupling/WriteDemObjectsCoProcessor.h | 17 +- .../DemCoupling/WritePeBlocksCoProcessor.cpp | 128 +- .../DemCoupling/WritePeBlocksCoProcessor.h | 32 +- .../PhysicsEngineGeometryAdapter.h | 37 +- .../PhysicsEngineMaterialAdapter.h | 24 +- .../PhysicsEngineSolverAdapter.h | 16 +- .../DummyPhysicsEngineGeometryAdapter.cpp | 78 +- .../dummy/DummyPhysicsEngineGeometryAdapter.h | 26 +- .../dummy/DummyPhysicsEngineMaterialAdapter.h | 18 +- .../dummy/DummyPhysicsEngineSolverAdapter.cpp | 12 +- .../dummy/DummyPhysicsEngineSolverAdapter.h | 16 +- .../physicsEngineAdapter/pe/PeAdapter.h | 23 +- .../physicsEngineAdapter/pe/PeAdapterTest.cpp | 5 +- .../pe/PeLoadBalancerAdapter.cpp | 59 +- .../pe/PeLoadBalancerAdapter.h | 21 +- .../pe/PePhysicsEngineGeometryAdapter.cpp | 104 +- .../pe/PePhysicsEngineGeometryAdapter.h | 47 +- .../pe/PePhysicsEngineMaterialAdapter.cpp | 5 +- .../pe/PePhysicsEngineMaterialAdapter.h | 18 +- .../pe/PePhysicsEngineSolverAdapter.cpp | 240 +- .../pe/PePhysicsEngineSolverAdapter.h | 76 +- .../EquilibriumReconstructor.cpp | 28 +- .../reconstructor/EquilibriumReconstructor.h | 16 +- .../ExtrapolationReconstructor.cpp | 81 +- .../ExtrapolationReconstructor.h | 27 +- .../reconstructor/LBMReconstructor.cpp | 232 +- .../reconstructor/LBMReconstructor.h | 24 +- .../DemCoupling/reconstructor/Reconstructor.h | 14 +- .../reconstructor/VelocityBcReconstructor.cpp | 42 +- .../reconstructor/VelocityBcReconstructor.h | 14 +- src/cpu/VirtualFluids.h | 156 +- .../BoundaryConditions/BCAdapter.h | 95 +- .../BoundaryConditions/BCAlgorithm.cpp | 99 +- .../BoundaryConditions/BCAlgorithm.h | 118 +- .../BoundaryConditions/BCArray3D.cpp | 288 +- .../BoundaryConditions/BCArray3D.h | 263 +- .../BoundaryConditions/BCFunction.cpp | 39 +- .../BoundaryConditions/BCFunction.h | 161 +- .../BoundaryConditions/BCProcessor.cpp | 90 +- .../BoundaryConditions/BCProcessor.h | 68 +- .../BoundaryConditions/BoundaryConditions.cpp | 41 +- .../BoundaryConditions/BoundaryConditions.h | 528 +- .../BoundaryConditions/DensityBCAdapter.cpp | 219 +- .../BoundaryConditions/DensityBCAdapter.h | 72 +- .../EqDensityBCAlgorithm.cpp | 73 +- .../BoundaryConditions/EqDensityBCAlgorithm.h | 10 +- .../HighViscosityNoSlipBCAlgorithm.cpp | 52 +- .../HighViscosityNoSlipBCAlgorithm.h | 11 +- .../BoundaryConditions/NoSlipBCAdapter.cpp | 38 +- .../BoundaryConditions/NoSlipBCAdapter.h | 76 +- .../BoundaryConditions/NoSlipBCAlgorithm.cpp | 85 +- .../BoundaryConditions/NoSlipBCAlgorithm.h | 49 +- .../NonEqDensityBCAlgorithm.cpp | 86 +- .../NonEqDensityBCAlgorithm.h | 10 +- .../NonReflectingOutflowBCAlgorithm.cpp | 344 +- .../NonReflectingOutflowBCAlgorithm.h | 10 +- .../BoundaryConditions/SlipBCAdapter.cpp | 44 +- .../BoundaryConditions/SlipBCAdapter.h | 64 +- .../BoundaryConditions/SlipBCAlgorithm.cpp | 181 +- .../BoundaryConditions/SlipBCAlgorithm.h | 10 +- .../ThinWallBCProcessor.cpp | 29 +- .../BoundaryConditions/ThinWallBCProcessor.h | 9 +- .../ThinWallNoSlipBCAlgorithm.cpp | 79 +- .../ThinWallNoSlipBCAlgorithm.h | 19 +- .../BoundaryConditions/VelocityBCAdapter.cpp | 530 +- .../BoundaryConditions/VelocityBCAdapter.h | 170 +- .../VelocityBCAlgorithm.cpp | 89 +- .../BoundaryConditions/VelocityBCAlgorithm.h | 49 +- .../VelocityWithDensityBCAlgorithm.cpp | 115 +- .../VelocityWithDensityBCAlgorithm.h | 13 +- .../CoProcessors/AdjustForcingCoProcessor.cpp | 296 +- .../CoProcessors/AdjustForcingCoProcessor.h | 66 +- .../CoProcessors/AverageValuesCoProcessor.cpp | 853 ++-- .../CoProcessors/AverageValuesCoProcessor.h | 111 +- .../CalculateForcesCoProcessor.cpp | 414 +- .../CoProcessors/CalculateForcesCoProcessor.h | 54 +- .../CoProcessors/CoProcessor.cpp | 50 +- .../CoProcessors/CoProcessor.h | 73 +- .../DecreaseViscosityCoProcessor.cpp | 98 +- .../DecreaseViscosityCoProcessor.h | 44 +- .../CoProcessors/EmergencyExitCoProcessor.cpp | 87 +- .../CoProcessors/EmergencyExitCoProcessor.h | 4 +- .../CoProcessors/ForceCalculator.cpp | 100 +- .../CoProcessors/ForceCalculator.h | 11 +- .../InSituCatalystCoProcessor.cpp | 572 ++- .../CoProcessors/InSituCatalystCoProcessor.h | 58 +- .../CoProcessors/InSituVTKCoProcessor.cpp | 499 +- .../CoProcessors/InSituVTKCoProcessor.h | 53 +- .../CoProcessors/IntegrateValuesHelper.cpp | 442 +- .../CoProcessors/IntegrateValuesHelper.h | 108 +- .../LineTimeSeriesCoProcessor.cpp | 401 +- .../CoProcessors/LineTimeSeriesCoProcessor.h | 59 +- .../CoProcessors/MPIIOCoProcessor.cpp | 822 ++-- .../CoProcessors/MPIIOCoProcessor.h | 42 +- .../MPIIOMigrationBECoProcessor.cpp | 2752 ++++++----- .../MPIIOMigrationBECoProcessor.h | 125 +- .../MPIIOMigrationCoProcessor.cpp | 3040 ++++++------ .../CoProcessors/MPIIOMigrationCoProcessor.h | 114 +- .../CoProcessors/MPIIORestartCoProcessor.cpp | 4306 +++++++++-------- .../CoProcessors/MPIIORestartCoProcessor.h | 98 +- .../MicrophoneArrayCoProcessor.cpp | 186 +- .../CoProcessors/MicrophoneArrayCoProcessor.h | 52 +- .../CoProcessors/NUPSCounterCoProcessor.cpp | 114 +- .../CoProcessors/NUPSCounterCoProcessor.h | 83 +- .../PressureCoefficientCoProcessor.cpp | 342 +- .../PressureCoefficientCoProcessor.h | 45 +- .../PressureDifferenceCoProcessor.cpp | 160 +- .../PressureDifferenceCoProcessor.h | 28 +- .../CoProcessors/QCriterionCoProcessor.cpp | 667 ++- .../CoProcessors/QCriterionCoProcessor.h | 64 +- .../CoProcessors/ShearStressCoProcessor.cpp | 1527 +++--- .../CoProcessors/ShearStressCoProcessor.h | 98 +- .../TimeAveragedValuesCoProcessor.cpp | 1762 ++++--- .../TimeAveragedValuesCoProcessor.h | 188 +- .../TimeDependentBCCoProcessor.cpp | 28 +- .../CoProcessors/TimeDependentBCCoProcessor.h | 17 +- .../CoProcessors/TimeseriesCoProcessor.cpp | 118 +- .../CoProcessors/TimeseriesCoProcessor.h | 4 +- .../TurbulenceIntensityCoProcessor.cpp | 438 +- .../TurbulenceIntensityCoProcessor.h | 42 +- .../CoProcessors/WriteBlocksCoProcessor.cpp | 298 +- .../CoProcessors/WriteBlocksCoProcessor.h | 76 +- .../WriteBoundaryConditionsCoProcessor.cpp | 398 +- .../WriteBoundaryConditionsCoProcessor.h | 95 +- .../WriteGbObjectsCoProcessor.cpp | 101 +- .../CoProcessors/WriteGbObjectsCoProcessor.h | 27 +- .../WriteMQFromSelectionCoProcessor.cpp | 380 +- .../WriteMQFromSelectionCoProcessor.h | 56 +- .../WriteMacroscopicQuantitiesCoProcessor.cpp | 413 +- .../WriteMacroscopicQuantitiesCoProcessor.h | 114 +- .../Connectors/Block3DConnector.h | 138 +- .../Connectors/Block3DConnectorFactory.cpp | 51 +- .../Connectors/Block3DConnectorFactory.h | 44 +- .../CoarseToFineBlock3DConnector.cpp | 187 +- .../Connectors/CoarseToFineBlock3DConnector.h | 103 +- .../CoarseToFineNodeSetBlock3DConnector.cpp | 2575 +++++----- .../CoarseToFineNodeSetBlock3DConnector.h | 137 +- .../Connectors/ConnectorFactory.h | 41 +- .../Connectors/D3Q27ETCFOffVectorConnector.h | 3727 +++++++------- .../D3Q27ETFCOffVectorConnector.cpp | 2 - .../Connectors/D3Q27ETFCOffVectorConnector.h | 2762 ++++++----- .../Connectors/D3Q27ETFullDirectConnector.cpp | 360 +- .../Connectors/D3Q27ETFullDirectConnector.h | 159 +- .../Connectors/D3Q27ETFullVectorConnector.cpp | 856 ++-- .../Connectors/D3Q27ETFullVectorConnector.h | 173 +- .../Connectors/D3Q27ETOffConnectorFactory.cpp | 8 +- .../Connectors/D3Q27ETOffConnectorFactory.h | 11 +- .../FineToCoarseBlock3DConnector.cpp | 77 +- .../Connectors/FineToCoarseBlock3DConnector.h | 96 +- .../FineToCoarseNodeSetBlock3DConnector.cpp | 2064 ++++---- .../FineToCoarseNodeSetBlock3DConnector.h | 84 +- .../Connectors/LocalBlock3DConnector.h | 111 +- .../Connectors/RemoteBlock3DConnector.cpp | 41 +- .../Connectors/RemoteBlock3DConnector.h | 83 +- .../Connectors/TransmitterType.h | 12 +- .../Data/D3Q27EsoTwist3DSoA.cpp | 1091 +++-- .../Data/D3Q27EsoTwist3DSoA.h | 140 +- .../Data/D3Q27EsoTwist3DSplittedVector.cpp | 1142 +++-- .../Data/D3Q27EsoTwist3DSplittedVector.h | 158 +- .../Data/D3Q27EsoTwist3DSplittedVectorEx.cpp | 17 +- .../Data/D3Q27EsoTwist3DSplittedVectorEx.h | 4 +- src/cpu/VirtualFluidsCore/Data/DataSet3D.h | 177 +- .../Data/DistributionArray3D.h | 39 +- src/cpu/VirtualFluidsCore/Data/EsoTwist3D.h | 131 +- .../Data/EsoTwistD3Q27System.cpp | 173 +- .../Data/EsoTwistD3Q27System.h | 226 +- src/cpu/VirtualFluidsCore/Data/VoidData3D.h | 61 +- .../Grid/BasicCalculator.cpp | 545 +-- .../VirtualFluidsCore/Grid/BasicCalculator.h | 78 +- src/cpu/VirtualFluidsCore/Grid/Block3D.cpp | 626 +-- src/cpu/VirtualFluidsCore/Grid/Block3D.h | 269 +- src/cpu/VirtualFluidsCore/Grid/Calculator.cpp | 371 +- src/cpu/VirtualFluidsCore/Grid/Calculator.h | 105 +- src/cpu/VirtualFluidsCore/Grid/Grid3D.cpp | 3721 +++++++------- src/cpu/VirtualFluidsCore/Grid/Grid3D.h | 474 +- .../VirtualFluidsCore/Grid/Grid3DSystem.cpp | 91 +- src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.h | 405 +- .../Interactors/D3Q27Interactor.cpp | 1555 +++--- .../Interactors/D3Q27Interactor.h | 128 +- .../D3Q27TriFaceMeshInteractor.cpp | 3530 +++++++------- .../Interactors/D3Q27TriFaceMeshInteractor.h | 192 +- .../Interactors/Interactor3D.cpp | 476 +- .../Interactors/Interactor3D.h | 204 +- .../Interactors/InteractorsHelper.cpp | 100 +- .../Interactors/InteractorsHelper.h | 71 +- .../VirtualFluidsCore/LBM/BGKLBMKernel.cpp | 503 +- src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.h | 42 +- src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp | 399 +- src/cpu/VirtualFluidsCore/LBM/D3Q27System.h | 1347 +++--- src/cpu/VirtualFluidsCore/LBM/ICell.h | 37 +- src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h | 60 +- .../LBM/InterpolationHelper.cpp | 43 +- .../LBM/InterpolationHelper.h | 20 +- .../LBM/InterpolationProcessor.cpp | 584 +-- .../LBM/InterpolationProcessor.h | 85 +- src/cpu/VirtualFluidsCore/LBM/LBMKernel.cpp | 276 +- src/cpu/VirtualFluidsCore/LBM/LBMKernel.h | 79 +- src/cpu/VirtualFluidsCore/LBM/LBMSystem.cpp | 40 +- src/cpu/VirtualFluidsCore/LBM/LBMSystem.h | 106 +- .../VirtualFluidsCore/LBM/LBMUnitConverter.h | 334 +- .../VirtualFluidsCore/LBM/VoidLBMKernel.cpp | 46 +- src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.h | 14 +- .../Parallel/BlocksDistributor.cpp | 6 +- .../Parallel/BlocksDistributor.h | 10 +- .../Parallel/Communicator.cpp | 46 +- .../VirtualFluidsCore/Parallel/Communicator.h | 118 +- .../Parallel/MPICommunicator.cpp | 276 +- .../Parallel/MPICommunicator.h | 312 +- .../Parallel/MPIIODataStructures.h | 310 +- .../Parallel/MetisPartitioner.cpp | 116 +- .../Parallel/MetisPartitioner.h | 82 +- .../Parallel/NullCommunicator.cpp | 110 +- .../Parallel/NullCommunicator.h | 69 +- .../Parallel/PriorityQueueDecompositor.cpp | 1 - .../Parallel/PriorityQueueDecompositor.h | 82 +- .../Parallel/SimpleGeometricPartitioner.h | 143 +- .../Parallel/ZoltanPartitioner.cpp | 290 +- .../Parallel/ZoltanPartitioner.h | 90 +- .../Utilities/CheckpointConverter.cpp | 1111 +++-- .../Utilities/CheckpointConverter.h | 38 +- .../VirtualFluidsCore/Utilities/MemoryUtil.h | 231 +- .../Visitors/Block3DVisitor.h | 86 +- .../BoundaryConditionsBlockVisitor.cpp | 159 +- .../Visitors/BoundaryConditionsBlockVisitor.h | 54 +- .../ChangeBoundaryDensityBlockVisitor.cpp | 79 +- .../ChangeBoundaryDensityBlockVisitor.h | 13 +- .../Visitors/CheckRatioBlockVisitor.cpp | 99 +- .../Visitors/CheckRatioBlockVisitor.h | 25 +- ...rsenCrossAndInsideGbObjectBlockVisitor.cpp | 42 +- ...oarsenCrossAndInsideGbObjectBlockVisitor.h | 28 +- .../Visitors/ConnectorBlockVisitor.cpp | 859 ++-- .../Visitors/ConnectorBlockVisitor.h | 44 +- .../Visitors/CreateTransmittersHelper.cpp | 250 +- .../Visitors/CreateTransmittersHelper.h | 37 +- .../Visitors/GenBlocksGridVisitor.cpp | 110 +- .../Visitors/GenBlocksGridVisitor.h | 56 +- .../Visitors/Grid3DVisitor.h | 47 +- .../InitDistributionsBlockVisitor.cpp | 547 ++- .../Visitors/InitDistributionsBlockVisitor.h | 96 +- .../InitDistributionsFromFileBlockVisitor.cpp | 468 +- .../InitDistributionsFromFileBlockVisitor.h | 14 +- ...tributionsWithInterpolationGridVisitor.cpp | 1147 ++--- ...istributionsWithInterpolationGridVisitor.h | 32 +- .../Visitors/MetisPartitioningGridVisitor.cpp | 280 +- .../Visitors/MetisPartitioningGridVisitor.h | 83 +- .../Visitors/OverlapBlockVisitor.cpp | 80 +- .../Visitors/OverlapBlockVisitor.h | 19 +- .../PQueuePartitioningGridVisitor.cpp | 77 +- .../Visitors/PQueuePartitioningGridVisitor.h | 18 +- .../Visitors/RatioBlockVisitor.cpp | 181 +- .../Visitors/RatioBlockVisitor.h | 40 +- .../Visitors/RatioSmoothBlockVisitor.cpp | 204 +- .../Visitors/RatioSmoothBlockVisitor.h | 41 +- .../Visitors/RefineAroundGbObjectHelper.cpp | 60 +- .../Visitors/RefineAroundGbObjectHelper.h | 30 +- ...fineCrossAndInsideGbObjectBlockVisitor.cpp | 47 +- ...RefineCrossAndInsideGbObjectBlockVisitor.h | 27 +- .../RefineCrossAndInsideGbObjectHelper.cpp | 93 +- .../RefineCrossAndInsideGbObjectHelper.h | 35 +- .../Visitors/RefineInterGbObjectsVisitor.cpp | 97 +- .../Visitors/RefineInterGbObjectsVisitor.h | 18 +- .../Visitors/RenumberBlockVisitor.cpp | 19 +- .../Visitors/RenumberBlockVisitor.h | 22 +- .../Visitors/RenumberGridVisitor.cpp | 61 +- .../Visitors/RenumberGridVisitor.h | 24 +- .../Visitors/SetBcBlocksBlockVisitor.cpp | 62 +- .../Visitors/SetBcBlocksBlockVisitor.h | 49 +- .../Visitors/SetConnectorsBlockVisitor.cpp | 929 ++-- .../Visitors/SetConnectorsBlockVisitor.h | 77 +- .../Visitors/SetForcingBlockVisitor.cpp | 96 +- .../Visitors/SetForcingBlockVisitor.h | 36 +- .../SetInterpolationDirsBlockVisitor.cpp | 281 +- .../SetInterpolationDirsBlockVisitor.h | 15 +- .../Visitors/SetKernelBlockVisitor.cpp | 146 +- .../Visitors/SetKernelBlockVisitor.h | 49 +- .../Visitors/SetSolidBlocksBlockVisitor.cpp | 61 +- .../Visitors/SetSolidBlocksBlockVisitor.h | 46 +- .../Visitors/SetSpongeLayerBlockVisitor.cpp | 30 +- .../Visitors/SetSpongeLayerBlockVisitor.h | 13 +- .../SetUndefinedNodesBlockVisitor.cpp | 1290 +++-- .../Visitors/SetUndefinedNodesBlockVisitor.h | 14 +- .../Visitors/SpongeLayerBlockVisitor.cpp | 185 +- .../Visitors/SpongeLayerBlockVisitor.h | 8 +- .../Visitors/ViscosityBlockVisitor.cpp | 20 +- .../Visitors/ViscosityBlockVisitor.h | 8 +- .../ZoltanPartitioningGridVisitor.cpp | 222 +- .../Visitors/ZoltanPartitioningGridVisitor.h | 40 +- 299 files changed, 39530 insertions(+), 39035 deletions(-) diff --git a/3rdParty/metis/metis-5.1.1/libmetis/CMakeLists.txt b/3rdParty/metis/metis-5.1.1/libmetis/CMakeLists.txt index 4732b645e..356afd750 100644 --- a/3rdParty/metis/metis-5.1.1/libmetis/CMakeLists.txt +++ b/3rdParty/metis/metis-5.1.1/libmetis/CMakeLists.txt @@ -6,6 +6,8 @@ file(GLOB metis_sources *.c) add_library(metis ${METIS_LIBRARY_TYPE} ${GKlib_sources} ${metis_sources}) if(UNIX) target_link_libraries(metis m) + + target_compile_options(metis PRIVATE "-Wno-format") endif() if(MSVC) diff --git a/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.cpp b/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.cpp index 6e99b35f5..dacf8cfc8 100644 --- a/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.cpp +++ b/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.cpp @@ -1,119 +1,121 @@ #include "CreateDemObjectsCoProcessor.h" -#include "UbScheduler.h" +#include "Communicator.h" #include "DemCoProcessor.h" +#include "EquilibriumReconstructor.h" +#include "ExtrapolationReconstructor.h" #include "GbSphere3D.h" +#include "Grid3D.h" +#include "LBMReconstructor.h" +#include "MovableObjectInteractor.h" #include "NoSlipBCAlgorithm.h" +#include "PePhysicsEngineMaterialAdapter.h" +#include "PhysicsEngineMaterialAdapter.h" +#include "SetBcBlocksBlockVisitor.h" +#include "UbScheduler.h" #include "VelocityBCAdapter.h" -#include "VelocityWithDensityBCAlgorithm.h" #include "VelocityBCAlgorithm.h" -#include "MovableObjectInteractor.h" -#include "LBMReconstructor.h" -#include "EquilibriumReconstructor.h" #include "VelocityBcReconstructor.h" -#include "ExtrapolationReconstructor.h" -#include "PePhysicsEngineMaterialAdapter.h" +#include "VelocityWithDensityBCAlgorithm.h" #include "muParser.h" -#include "PhysicsEngineMaterialAdapter.h" -#include "SetBcBlocksBlockVisitor.h" -#include "Grid3D.h" -#include "Communicator.h" - - -CreateDemObjectsCoProcessor::CreateDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::shared_ptr<Communicator> comm, SPtr<DemCoProcessor> demCoProcessor, SPtr<PhysicsEngineMaterialAdapter> demObjectMaterial, double tolerance) : - CoProcessor(grid, s), - comm(comm), - demCoProcessor(demCoProcessor), - demObjectMaterial(demObjectMaterial), - tolerance(tolerance) +CreateDemObjectsCoProcessor::CreateDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, + std::shared_ptr<Communicator> comm, + SPtr<DemCoProcessor> demCoProcessor, + SPtr<PhysicsEngineMaterialAdapter> demObjectMaterial, + double tolerance) + : CoProcessor(grid, s), comm(comm), demCoProcessor(demCoProcessor), demObjectMaterial(demObjectMaterial), + tolerance(tolerance) { - mu::Parser fct; - fct.SetExpr("U"); - fct.DefineConst("U", 0.0); - velocityBcParticleAdapter = SPtr<BCAdapter>(new VelocityBCAdapter(true, false, false, fct, 0, BCFunction::INFCONST)); - velocityBcParticleAdapter->setBcAlgorithm(SPtr<BCAlgorithm>(new VelocityWithDensityBCAlgorithm())); - - //const std::shared_ptr<Reconstructor> velocityReconstructor(new VelocityBcReconstructor()); - std::shared_ptr<Reconstructor> equilibriumReconstructor(new EquilibriumReconstructor()); - //const std::shared_ptr<Reconstructor> lbmReconstructor(new LBMReconstructor(false)); - extrapolationReconstructor = SPtr<Reconstructor>(new ExtrapolationReconstructor(equilibriumReconstructor)); - demCounter = 0; + mu::Parser fct; + fct.SetExpr("U"); + fct.DefineConst("U", 0.0); + velocityBcParticleAdapter = + SPtr<BCAdapter>(new VelocityBCAdapter(true, false, false, fct, 0, BCFunction::INFCONST)); + velocityBcParticleAdapter->setBcAlgorithm(SPtr<BCAlgorithm>(new VelocityWithDensityBCAlgorithm())); + + // const std::shared_ptr<Reconstructor> velocityReconstructor(new VelocityBcReconstructor()); + std::shared_ptr<Reconstructor> equilibriumReconstructor(new EquilibriumReconstructor()); + // const std::shared_ptr<Reconstructor> lbmReconstructor(new LBMReconstructor(false)); + extrapolationReconstructor = SPtr<Reconstructor>(new ExtrapolationReconstructor(equilibriumReconstructor)); + demCounter = 0; } ////////////////////////////////////////////////////////////////////////// void CreateDemObjectsCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - int istep = static_cast<int>(step); - + if (scheduler->isDue(step)) { + int istep = static_cast<int>(step); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "CreateDemObjectsCoProcessor::process start step: " << istep); - timer.resetAndStart(); + if (comm->isRoot()) + UBLOG(logINFO, "CreateDemObjectsCoProcessor::process start step: " << istep); + timer.resetAndStart(); #endif - - createGeoObjects(); + + createGeoObjects(); #ifdef TIMING -// if (comm->isRoot()) UBLOG(logINFO, "createGeoObjects() time = "<<timer.stop()<<" s"); -// if (comm->isRoot()) UBLOG(logINFO, "number of objects = "<<(int)(geoObjectPrototypeVector.size())); -// if (comm->isRoot()) UBLOG(logINFO, "total number of objects = "<<demCounter); - if (comm->isRoot()) UBLOG(logINFO, "CreateDemObjectsCoProcessor::process stop step: " << istep); + // if (comm->isRoot()) UBLOG(logINFO, "createGeoObjects() time = "<<timer.stop()<<" s"); + // if (comm->isRoot()) UBLOG(logINFO, "number of objects = "<<(int)(geoObjectPrototypeVector.size())); + // if (comm->isRoot()) UBLOG(logINFO, "total number of objects = "<<demCounter); + if (comm->isRoot()) + UBLOG(logINFO, "CreateDemObjectsCoProcessor::process stop step: " << istep); #endif - - //demCoProcessor->distributeIDs(); -//#ifdef TIMING -// if (comm->isRoot()) UBLOG(logINFO, "demCoProcessor->distributeIDs() time = "<<timer.stop()<<" s"); -//#endif + // demCoProcessor->distributeIDs(); - - } + //#ifdef TIMING + // if (comm->isRoot()) UBLOG(logINFO, "demCoProcessor->distributeIDs() time = "<<timer.stop()<<" s"); + //#endif + } } ////////////////////////////////////////////////////////////////////////// -void CreateDemObjectsCoProcessor::addGeoObject(SPtr<GbObject3D> geoObjectPrototype, Vector3D initalVelocity) +void CreateDemObjectsCoProcessor::addGeoObject(SPtr<GbObject3D> geoObjectPrototype, Vector3D initalVelocity) { - geoObjectPrototypeVector.push_back(geoObjectPrototype); - this->initalVelocity.push_back(initalVelocity); + geoObjectPrototypeVector.push_back(geoObjectPrototype); + this->initalVelocity.push_back(initalVelocity); } void CreateDemObjectsCoProcessor::clearGeoObjects() { - geoObjectPrototypeVector.clear(); - initalVelocity.clear(); + geoObjectPrototypeVector.clear(); + initalVelocity.clear(); } void CreateDemObjectsCoProcessor::createGeoObjects() { - int size = (int)(geoObjectPrototypeVector.size()); + int size = (int)(geoObjectPrototypeVector.size()); - std::vector< std::shared_ptr<Block3D> > blockVector; + std::vector<std::shared_ptr<Block3D>> blockVector; - for (int i = 0; i < size; i++) - { - SPtr<GbSphere3D> sphere = std::dynamic_pointer_cast<GbSphere3D>(geoObjectPrototypeVector[i]); - if (demCoProcessor->isSpheresIntersection(sphere->getX1Centroid(), sphere->getX2Centroid(), sphere->getX3Centroid(), sphere->getRadius()*2.0*(1.0-tolerance))) - { - continue; - } + for (int i = 0; i < size; i++) { + SPtr<GbSphere3D> sphere = std::dynamic_pointer_cast<GbSphere3D>(geoObjectPrototypeVector[i]); + if (demCoProcessor->isSpheresIntersection(sphere->getX1Centroid(), sphere->getX2Centroid(), + sphere->getX3Centroid(), + sphere->getRadius() * 2.0 * (1.0 - tolerance))) { + continue; + } - SPtr<GbObject3D> geoObject((GbObject3D*)(geoObjectPrototypeVector[i]->clone())); - SPtr<MovableObjectInteractor> geoObjectInt = SPtr<MovableObjectInteractor>(new MovableObjectInteractor(geoObject, grid, velocityBcParticleAdapter, Interactor3D::SOLID, extrapolationReconstructor, State::UNPIN)); - demCoProcessor->addInteractor(geoObjectInt, demObjectMaterial, initalVelocity[i]); - demCounter++; - } + SPtr<GbObject3D> geoObject((GbObject3D *)(geoObjectPrototypeVector[i]->clone())); + SPtr<MovableObjectInteractor> geoObjectInt = SPtr<MovableObjectInteractor>(new MovableObjectInteractor( + geoObject, grid, velocityBcParticleAdapter, Interactor3D::SOLID, extrapolationReconstructor, State::UNPIN)); + demCoProcessor->addInteractor(geoObjectInt, demObjectMaterial, initalVelocity[i]); + demCounter++; + } #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "createGeoObjects() time = "<<timer.stop()<<" s"); - if (comm->isRoot()) UBLOG(logINFO, "number of objects = "<<(int)(geoObjectPrototypeVector.size())); - if (comm->isRoot()) UBLOG(logINFO, "total number of objects = "<<demCounter); - //if (comm->isRoot()) UBLOG(logINFO, "CreateDemObjectsCoProcessor::process stop step: " << istep); + if (comm->isRoot()) + UBLOG(logINFO, "createGeoObjects() time = " << timer.stop() << " s"); + if (comm->isRoot()) + UBLOG(logINFO, "number of objects = " << (int)(geoObjectPrototypeVector.size())); + if (comm->isRoot()) + UBLOG(logINFO, "total number of objects = " << demCounter); + // if (comm->isRoot()) UBLOG(logINFO, "CreateDemObjectsCoProcessor::process stop step: " << istep); #endif - demCoProcessor->distributeIDs(); + demCoProcessor->distributeIDs(); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "demCoProcessor->distributeIDs() time = "<<timer.stop()<<" s"); + if (comm->isRoot()) + UBLOG(logINFO, "demCoProcessor->distributeIDs() time = " << timer.stop() << " s"); #endif } - diff --git a/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.h b/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.h index 38ce7c2f5..c8ecc6842 100644 --- a/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.h +++ b/src/cpu/DemCoupling/CreateDemObjectsCoProcessor.h @@ -3,9 +3,8 @@ #include "CoProcessor.h" #include "Vector3D.h" -#include <vector> #include <array> - +#include <vector> //#define TIMING @@ -13,7 +12,6 @@ #include "UbTiming.h" #endif - class Grid3D; class UbScheduler; class Communicator; @@ -23,30 +21,32 @@ class BCAdapter; class Reconstructor; class PhysicsEngineMaterialAdapter; - class CreateDemObjectsCoProcessor : public CoProcessor { public: - CreateDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::shared_ptr<Communicator> comm, SPtr<DemCoProcessor> demCoProcessor, SPtr<PhysicsEngineMaterialAdapter> geoObjectMaterial, double tolerance = 0); - void process(double step) override; - void addGeoObject(SPtr<GbObject3D> geoObjectPrototype, Vector3D initalVelocity); - void clearGeoObjects(); - void createGeoObjects(); - double getToleranz() const { return tolerance; } - void setToleranz(double val) { tolerance = val; } + CreateDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::shared_ptr<Communicator> comm, + SPtr<DemCoProcessor> demCoProcessor, + SPtr<PhysicsEngineMaterialAdapter> geoObjectMaterial, double tolerance = 0); + void process(double step) override; + void addGeoObject(SPtr<GbObject3D> geoObjectPrototype, Vector3D initalVelocity); + void clearGeoObjects(); + void createGeoObjects(); + double getToleranz() const { return tolerance; } + void setToleranz(double val) { tolerance = val; } + protected: private: - SPtr<Communicator> comm; - SPtr<DemCoProcessor> demCoProcessor; - std::vector< SPtr<GbObject3D> > geoObjectPrototypeVector; - SPtr<PhysicsEngineMaterialAdapter> demObjectMaterial; - std::vector<Vector3D> initalVelocity; - SPtr<BCAdapter> velocityBcParticleAdapter; - SPtr<Reconstructor> extrapolationReconstructor; - int demCounter; - double tolerance; + SPtr<Communicator> comm; + SPtr<DemCoProcessor> demCoProcessor; + std::vector<SPtr<GbObject3D>> geoObjectPrototypeVector; + SPtr<PhysicsEngineMaterialAdapter> demObjectMaterial; + std::vector<Vector3D> initalVelocity; + SPtr<BCAdapter> velocityBcParticleAdapter; + SPtr<Reconstructor> extrapolationReconstructor; + int demCounter; + double tolerance; #ifdef TIMING - UbTimer timer; + UbTimer timer; #endif }; #endif // CreateSphereCoProcessor_h__ diff --git a/src/cpu/DemCoupling/DemCoProcessor.cpp b/src/cpu/DemCoupling/DemCoProcessor.cpp index 09deb9165..554ffaa6c 100644 --- a/src/cpu/DemCoupling/DemCoProcessor.cpp +++ b/src/cpu/DemCoupling/DemCoProcessor.cpp @@ -1,516 +1,515 @@ #include "DemCoProcessor.h" -#include "GbSphere3D.h" -#include "MovableObjectInteractor.h" +#include "BCProcessor.h" #include "Communicator.h" +#include "DataSet3D.h" +#include "DistributionArray3D.h" #include "ForceCalculator.h" +#include "GbSphere3D.h" #include "Grid3D.h" -#include "UbScheduler.h" #include "ILBMKernel.h" -#include "DistributionArray3D.h" -#include "BCProcessor.h" -#include "DataSet3D.h" +#include "MovableObjectInteractor.h" #include "SetBcBlocksBlockVisitor.h" +#include "UbScheduler.h" -#include "PhysicsEngineMaterialAdapter.h" +#include "PePhysicsEngineGeometryAdapter.h" +#include "PePhysicsEngineSolverAdapter.h" #include "PhysicsEngineGeometryAdapter.h" +#include "PhysicsEngineMaterialAdapter.h" #include "PhysicsEngineSolverAdapter.h" -#include "PePhysicsEngineSolverAdapter.h" -#include "PePhysicsEngineGeometryAdapter.h" -#include "BoundaryConditions.h" -#include "Block3D.h" #include "BCArray3D.h" -#include "MPICommunicator.h" +#include "Block3D.h" +#include "BoundaryConditions.h" #include "BoundaryConditionsBlockVisitor.h" +#include "MPICommunicator.h" #include "UbLogger.h" - #include <array> #include <functional> -DemCoProcessor::DemCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<Communicator> comm, std::shared_ptr<ForceCalculator> forceCalculator, std::shared_ptr<PhysicsEngineSolverAdapter> physicsEngineSolver, double intermediatePeSteps) : - CoProcessor(grid, s), comm(comm), forceCalculator(forceCalculator), physicsEngineSolver(std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)), intermediateDemSteps(intermediatePeSteps) +DemCoProcessor::DemCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<Communicator> comm, + std::shared_ptr<ForceCalculator> forceCalculator, + std::shared_ptr<PhysicsEngineSolverAdapter> physicsEngineSolver, + double intermediatePeSteps) + : CoProcessor(grid, s), comm(comm), forceCalculator(forceCalculator), + physicsEngineSolver(std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)), + intermediateDemSteps(intermediatePeSteps) { #ifdef TIMING - timer.resetAndStart(); + timer.resetAndStart(); #endif - std::shared_ptr<walberla::blockforest::BlockForest> forest = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); - std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); - - - for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) - { - walberla::pe::Storage* storage = blockIt->getData< walberla::pe::Storage >(*storageId.get()); - walberla::pe::BodyStorage* bodyStorage = &(*storage)[0]; - walberla::pe::BodyStorage* bodyStorageShadowCopies = &(*storage)[1]; - - bodyStorage->registerAddCallback("DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::addPeGeo), this)); - bodyStorage->registerRemoveCallback("DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::removePeGeo), this)); - - bodyStorageShadowCopies->registerAddCallback("DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::addPeShadowGeo), this)); - bodyStorageShadowCopies->registerRemoveCallback("DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::removePeShadowGeo), this)); - } + std::shared_ptr<walberla::blockforest::BlockForest> forest = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); + std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); + + for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) { + walberla::pe::Storage *storage = blockIt->getData<walberla::pe::Storage>(*storageId.get()); + walberla::pe::BodyStorage *bodyStorage = &(*storage)[0]; + walberla::pe::BodyStorage *bodyStorageShadowCopies = &(*storage)[1]; + + bodyStorage->registerAddCallback("DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::addPeGeo), this)); + bodyStorage->registerRemoveCallback("DemCoProcessor", + std::bind1st(std::mem_fun(&DemCoProcessor::removePeGeo), this)); + + bodyStorageShadowCopies->registerAddCallback("DemCoProcessor", + std::bind1st(std::mem_fun(&DemCoProcessor::addPeShadowGeo), this)); + bodyStorageShadowCopies->registerRemoveCallback( + "DemCoProcessor", std::bind1st(std::mem_fun(&DemCoProcessor::removePeShadowGeo), this)); + } } DemCoProcessor::~DemCoProcessor() { - std::shared_ptr<walberla::blockforest::BlockForest> forest = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); - std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); - - for (auto& currentBlock : *forest) - { - walberla::pe::Storage * storage = currentBlock.getData< walberla::pe::Storage >(*storageId.get()); - walberla::pe::BodyStorage& localStorage = (*storage)[0]; - walberla::pe::BodyStorage& shadowStorage = (*storage)[1]; - - localStorage.clearAddCallbacks(); - localStorage.clearRemoveCallbacks(); - - shadowStorage.clearAddCallbacks(); - shadowStorage.clearRemoveCallbacks(); - } + std::shared_ptr<walberla::blockforest::BlockForest> forest = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); + std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); + + for (auto ¤tBlock : *forest) { + walberla::pe::Storage *storage = currentBlock.getData<walberla::pe::Storage>(*storageId.get()); + walberla::pe::BodyStorage &localStorage = (*storage)[0]; + walberla::pe::BodyStorage &shadowStorage = (*storage)[1]; + + localStorage.clearAddCallbacks(); + localStorage.clearRemoveCallbacks(); + + shadowStorage.clearAddCallbacks(); + shadowStorage.clearRemoveCallbacks(); + } } -void DemCoProcessor::addInteractor(std::shared_ptr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial, Vector3D initalVelocity) +void DemCoProcessor::addInteractor(std::shared_ptr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial, + Vector3D initalVelocity) { - interactors.push_back(interactor); - const int id = static_cast<int>(interactors.size()-1); - interactor->setID(id); - const auto peGeometryAdapter = this->createPhysicsEngineGeometryAdapter(interactor, physicsEngineMaterial); - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter)->isActive()) - { - peGeometryAdapter->setLinearVelolocity(initalVelocity); - geoIdMap.insert(std::make_pair(std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter)->getSystemID(), std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter))); - } - SetBcBlocksBlockVisitor setBcVisitor(interactor); - grid->accept(setBcVisitor); - - //std::vector< std::shared_ptr<Block3D> > blockVector; - //UbTupleInt3 blockNX=grid->getBlockNX(); - //SPtr<GbObject3D> geoObject(interactor->getGbObject3D()); - //double ext = 0.0; - //std::array<double, 6> AABB ={ geoObject->getX1Minimum(),geoObject->getX2Minimum(),geoObject->getX3Minimum(),geoObject->getX1Maximum(),geoObject->getX2Maximum(),geoObject->getX3Maximum() }; - //grid->getBlocksByCuboid(AABB[0]-(double)val<1>(blockNX)*ext, AABB[1]-(double)val<2>(blockNX)*ext, AABB[2]-(double)val<3>(blockNX)*ext, AABB[3]+(double)val<1>(blockNX)*ext, AABB[4]+(double)val<2>(blockNX)*ext, AABB[5]+(double)val<3>(blockNX)*ext, blockVector); - //for (std::shared_ptr<Block3D> block : blockVector) - //{ - // if (block->getKernel()) - // { - // interactor->setBCBlock(block); - // //UBLOG(logINFO, "DemCoProcessor::addInteractor() rank = "<<comm->getProcessID()); - // } - //} - - interactor->initInteractor(); - - physicsEngineGeometrieAdapters.push_back(peGeometryAdapter); + interactors.push_back(interactor); + const int id = static_cast<int>(interactors.size() - 1); + interactor->setID(id); + const auto peGeometryAdapter = this->createPhysicsEngineGeometryAdapter(interactor, physicsEngineMaterial); + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter)->isActive()) { + peGeometryAdapter->setLinearVelolocity(initalVelocity); + geoIdMap.insert( + std::make_pair(std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter)->getSystemID(), + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(peGeometryAdapter))); + } + SetBcBlocksBlockVisitor setBcVisitor(interactor); + grid->accept(setBcVisitor); + + // std::vector< std::shared_ptr<Block3D> > blockVector; + // UbTupleInt3 blockNX=grid->getBlockNX(); + // SPtr<GbObject3D> geoObject(interactor->getGbObject3D()); + // double ext = 0.0; + // std::array<double, 6> AABB ={ + // geoObject->getX1Minimum(),geoObject->getX2Minimum(),geoObject->getX3Minimum(),geoObject->getX1Maximum(),geoObject->getX2Maximum(),geoObject->getX3Maximum() + // }; grid->getBlocksByCuboid(AABB[0]-(double)val<1>(blockNX)*ext, AABB[1]-(double)val<2>(blockNX)*ext, + // AABB[2]-(double)val<3>(blockNX)*ext, AABB[3]+(double)val<1>(blockNX)*ext, AABB[4]+(double)val<2>(blockNX)*ext, + // AABB[5]+(double)val<3>(blockNX)*ext, blockVector); for (std::shared_ptr<Block3D> block : blockVector) + //{ + // if (block->getKernel()) + // { + // interactor->setBCBlock(block); + // //UBLOG(logINFO, "DemCoProcessor::addInteractor() rank = "<<comm->getProcessID()); + // } + //} + + interactor->initInteractor(); + + physicsEngineGeometrieAdapters.push_back(peGeometryAdapter); } - -std::shared_ptr<PhysicsEngineGeometryAdapter> DemCoProcessor::createPhysicsEngineGeometryAdapter(std::shared_ptr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial) const +std::shared_ptr<PhysicsEngineGeometryAdapter> DemCoProcessor::createPhysicsEngineGeometryAdapter( + std::shared_ptr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial) const { - const int id = static_cast<int>(interactors.size()-1); - SPtr<GbSphere3D> vfSphere = std::static_pointer_cast<GbSphere3D>(interactor->getGbObject3D()); - const Vector3D position(vfSphere->getX1Centroid(), vfSphere->getX2Centroid(), vfSphere->getX3Centroid()); - auto peGeometryAdapter = this->physicsEngineSolver->createPhysicsEngineGeometryAdapter(id, position, vfSphere->getRadius(), physicsEngineMaterial); - interactor->setPhysicsEngineGeometry(peGeometryAdapter); - return peGeometryAdapter; + const int id = static_cast<int>(interactors.size() - 1); + SPtr<GbSphere3D> vfSphere = std::static_pointer_cast<GbSphere3D>(interactor->getGbObject3D()); + const Vector3D position(vfSphere->getX1Centroid(), vfSphere->getX2Centroid(), vfSphere->getX3Centroid()); + auto peGeometryAdapter = this->physicsEngineSolver->createPhysicsEngineGeometryAdapter( + id, position, vfSphere->getRadius(), physicsEngineMaterial); + interactor->setPhysicsEngineGeometry(peGeometryAdapter); + return peGeometryAdapter; } void DemCoProcessor::process(double actualTimeStep) { #ifdef TIMING - timer.resetAndStart(); + timer.resetAndStart(); #endif - this->applyForcesOnGeometries(); + this->applyForcesOnGeometries(); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::process start step: " << actualTimeStep); - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::applyForcesOnGeometries() time = "<<timer.stop()<<" s"); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::process start step: " << actualTimeStep); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::applyForcesOnGeometries() time = " << timer.stop() << " s"); #endif - if (scheduler->isDue(actualTimeStep)) - { - //UBLOG(logINFO, "DemCoProcessor::update - START - timestep = " << actualTimeStep); - const double demTimeStepsPerIteration = scheduler->getMinStep(); + if (scheduler->isDue(actualTimeStep)) { + // UBLOG(logINFO, "DemCoProcessor::update - START - timestep = " << actualTimeStep); + const double demTimeStepsPerIteration = scheduler->getMinStep(); - if (demTimeStepsPerIteration != 1) - this->scaleForcesAndTorques(1.0 / demTimeStepsPerIteration); + if (demTimeStepsPerIteration != 1) + this->scaleForcesAndTorques(1.0 / demTimeStepsPerIteration); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::scaleForcesAndTorques() time = "<<timer.stop()<<" s"); - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::calculateDemTimeStep():"); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::scaleForcesAndTorques() time = " << timer.stop() << " s"); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::calculateDemTimeStep():"); #endif - if (this->intermediateDemSteps == 1) - this->calculateDemTimeStep(demTimeStepsPerIteration); - - //#ifdef TIMING - // if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::calculateDemTimeStep() time = "<<timer.stop()<<" s"); - //#endif - //if ((int)actualTimeStep % 100 == 0) - //{ - // if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[0])->isActive()) - // { - // //UBLOG(logINFO, "v: (x,y,z) " << physicsEngineGeometries[0]->getLinearVelocity() << " actualTimeStep = " << UbSystem::toString(actualTimeStep)); - // } - //} - - // during the intermediate time steps of the collision response, the currently acting forces - // (interaction forces, gravitational force, ...) have to remain constant. - // Since they are reset after the call to collision response, they have to be stored explicitly before. - // Then they are set again after each intermediate step. - - this->moveVfGeoObjects(); + if (this->intermediateDemSteps == 1) + this->calculateDemTimeStep(demTimeStepsPerIteration); + + //#ifdef TIMING + // if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::calculateDemTimeStep() time = "<<timer.stop()<<" + // s"); + //#endif + // if ((int)actualTimeStep % 100 == 0) + //{ + // if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometries[0])->isActive()) + // { + // //UBLOG(logINFO, "v: (x,y,z) " << physicsEngineGeometries[0]->getLinearVelocity() << " actualTimeStep + // = " << UbSystem::toString(actualTimeStep)); + // } + //} + + // during the intermediate time steps of the collision response, the currently acting forces + // (interaction forces, gravitational force, ...) have to remain constant. + // Since they are reset after the call to collision response, they have to be stored explicitly before. + // Then they are set again after each intermediate step. + + this->moveVfGeoObjects(); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::moveVfGeoObject() time = "<<timer.stop()<<" s"); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::moveVfGeoObject() time = " << timer.stop() << " s"); #endif - grid->accept(*boundaryConditionsBlockVisitor.get()); + grid->accept(*boundaryConditionsBlockVisitor.get()); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "grid->accept(*boundaryConditionsBlockVisitor.get()) time = "<<timer.stop()<<" s"); + if (comm->isRoot()) + UBLOG(logINFO, "grid->accept(*boundaryConditionsBlockVisitor.get()) time = " << timer.stop() << " s"); #endif - //UBLOG(logINFO, "DemCoProcessor::update - END - timestep = " << actualTimeStep); - } + // UBLOG(logINFO, "DemCoProcessor::update - END - timestep = " << actualTimeStep); + } #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, "DemCoProcessor::process stop step: " << actualTimeStep); + if (comm->isRoot()) + UBLOG(logINFO, "DemCoProcessor::process stop step: " << actualTimeStep); #endif } ////////////////////////////////////////////////////////////////////////// -std::shared_ptr<PhysicsEngineSolverAdapter> DemCoProcessor::getPhysicsEngineSolver() -{ - return physicsEngineSolver; -} +std::shared_ptr<PhysicsEngineSolverAdapter> DemCoProcessor::getPhysicsEngineSolver() { return physicsEngineSolver; } void DemCoProcessor::applyForcesOnGeometries() { - for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - this->setForcesToObject(grid, interactors[i], physicsEngineGeometrieAdapters[i]); - - //physicsEngineGeometries[i]->setLinearVelolocity(Vector3D(-0.001, 0.0, 0.0)); - //physicsEngineGeometries[i]->setAngularVelocity(Vector3D(0.01, 0.01, 0.01)); - //UBLOG(logINFO, "v: (x,y,z) " << physicsEngineGeometries[i]->getLinearVelocity()); - } - } + for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + this->setForcesToObject(grid, interactors[i], physicsEngineGeometrieAdapters[i]); + + // physicsEngineGeometries[i]->setLinearVelolocity(Vector3D(-0.001, 0.0, 0.0)); + // physicsEngineGeometries[i]->setAngularVelocity(Vector3D(0.01, 0.01, 0.01)); + // UBLOG(logINFO, "v: (x,y,z) " << physicsEngineGeometries[i]->getLinearVelocity()); + } + } } -void DemCoProcessor::setForcesToObject(SPtr<Grid3D> grid, SPtr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) +void DemCoProcessor::setForcesToObject(SPtr<Grid3D> grid, SPtr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) { - for (BcNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - distributions->swap(); - - std::set< std::vector<int> >& transNodeIndicesSet = t.second; - for (std::vector<int> node : transNodeIndicesSet) - { - int x1 = node[0]; - int x2 = node[1]; - int x3 = node[2]; - - if (kernel->isInsideOfDomain(x1, x2, x3) && bcArray->isFluid(x1, x2, x3)) - { - //TODO: calculate assumed boundary position - - const Vector3D worldCoordinates = grid->getNodeCoordinates(block, x1, x2, x3); - const auto boundaryVelocity = physicsEngineGeometry->getVelocityAtPosition(worldCoordinates); - - SPtr<BoundaryConditions> bc = bcArray->getBC(x1, x2, x3); - const Vector3D force = forceCalculator->getForces(x1, x2, x3, distributions, bc, boundaryVelocity); - physicsEngineGeometry->addForceAtPosition(force, worldCoordinates); - } - } - distributions->swap(); - } + for (BcNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + distributions->swap(); + + std::set<std::vector<int>> &transNodeIndicesSet = t.second; + for (std::vector<int> node : transNodeIndicesSet) { + int x1 = node[0]; + int x2 = node[1]; + int x3 = node[2]; + + if (kernel->isInsideOfDomain(x1, x2, x3) && bcArray->isFluid(x1, x2, x3)) { + // TODO: calculate assumed boundary position + + const Vector3D worldCoordinates = grid->getNodeCoordinates(block, x1, x2, x3); + const auto boundaryVelocity = physicsEngineGeometry->getVelocityAtPosition(worldCoordinates); + + SPtr<BoundaryConditions> bc = bcArray->getBC(x1, x2, x3); + const Vector3D force = forceCalculator->getForces(x1, x2, x3, distributions, bc, boundaryVelocity); + physicsEngineGeometry->addForceAtPosition(force, worldCoordinates); + } + } + distributions->swap(); + } } - void DemCoProcessor::scaleForcesAndTorques(double scalingFactor) { - for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - const Vector3D force = physicsEngineGeometrieAdapters[i]->getForce() * scalingFactor; - const Vector3D torque = physicsEngineGeometrieAdapters[i]->getTorque() * scalingFactor; - - physicsEngineGeometrieAdapters[i]->resetForceAndTorque(); - - physicsEngineGeometrieAdapters[i]->setForce(force); - physicsEngineGeometrieAdapters[i]->setTorque(torque); - - //UBLOG(logINFO, "F: (x,y,z) " << force); - //UBLOG(logINFO, "T: (x,y,z) " << torque); - } - } -} + for (int i = 0; i < physicsEngineGeometrieAdapters.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + const Vector3D force = physicsEngineGeometrieAdapters[i]->getForce() * scalingFactor; + const Vector3D torque = physicsEngineGeometrieAdapters[i]->getTorque() * scalingFactor; + + physicsEngineGeometrieAdapters[i]->resetForceAndTorque(); + physicsEngineGeometrieAdapters[i]->setForce(force); + physicsEngineGeometrieAdapters[i]->setTorque(torque); + + // UBLOG(logINFO, "F: (x,y,z) " << force); + // UBLOG(logINFO, "T: (x,y,z) " << torque); + } + } +} void DemCoProcessor::calculateDemTimeStep(double step) { - physicsEngineSolver->runTimestep(step); + physicsEngineSolver->runTimestep(step); #ifdef TIMING - if (comm->isRoot()) UBLOG(logINFO, " physicsEngineSolver->runTimestep() time = "<< timer.stop() <<" s"); + if (comm->isRoot()) + UBLOG(logINFO, " physicsEngineSolver->runTimestep() time = " << timer.stop() << " s"); #endif } void DemCoProcessor::moveVfGeoObjects() { - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->getSemiactive()) - { - walberla::pe::RigidBody* peGeoObject = getPeGeoObject(std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->getSystemID()); - if (peGeoObject != nullptr) - { - std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setGeometry(peGeoObject); - interactors[i]->moveGbObjectTo(physicsEngineGeometrieAdapters[i]->getPosition()); - std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setSemiactive(false); - } - else - { - std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setInactive(); + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->getSemiactive()) { + walberla::pe::RigidBody *peGeoObject = getPeGeoObject( + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->getSystemID()); + if (peGeoObject != nullptr) { + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->setGeometry(peGeoObject); + interactors[i]->moveGbObjectTo(physicsEngineGeometrieAdapters[i]->getPosition()); + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->setSemiactive(false); + } else { + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->setInactive(); + } + } else { + interactors[i]->moveGbObjectTo(physicsEngineGeometrieAdapters[i]->getPosition()); } - } - else - { - interactors[i]->moveGbObjectTo(physicsEngineGeometrieAdapters[i]->getPosition()); - } - } - } + } + } } -bool DemCoProcessor::isDemObjectInAABB(std::array<double, 6> AABB) +bool DemCoProcessor::isDemObjectInAABB(std::array<double, 6> AABB) { - bool result = false; - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - SPtr<GbObject3D> geoObject = interactors[i]->getGbObject3D(); - std::array <double, 2> minMax1; - std::array <double, 2> minMax2; - std::array <double, 2> minMax3; - minMax1[0] = geoObject->getX1Minimum(); - minMax2[0] = geoObject->getX2Minimum(); - minMax3[0] = geoObject->getX3Minimum(); - minMax1[1] = geoObject->getX1Maximum(); - minMax2[1] = geoObject->getX2Maximum(); - minMax3[1] = geoObject->getX3Maximum(); - - for (int x3 = 0; x3 < 2; x3++) - for (int x2 = 0; x2 < 2; x2++) - for (int x1 = 0; x1 < 2; x1++) - { - result = result || (minMax1[x1] >= AABB[0] && minMax2[x2] >= AABB[1] && minMax3[x3] >= AABB[2] && minMax1[x1] <= AABB[3] && minMax2[x2] <= AABB[4] && minMax3[x3] <= AABB[5]); - } - } - } - - std::vector<int> values; - values.push_back((int)result); - std::vector<int> rvalues = comm->gather(values); - - if (comm->isRoot()) - { - for (int i = 0; i < (int)rvalues.size(); i++) - { - result = result || (bool)rvalues[i]; - } - } - int iresult = (int)result; - comm->broadcast(iresult); - result = (bool)iresult; - - return result; + bool result = false; + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + SPtr<GbObject3D> geoObject = interactors[i]->getGbObject3D(); + std::array<double, 2> minMax1; + std::array<double, 2> minMax2; + std::array<double, 2> minMax3; + minMax1[0] = geoObject->getX1Minimum(); + minMax2[0] = geoObject->getX2Minimum(); + minMax3[0] = geoObject->getX3Minimum(); + minMax1[1] = geoObject->getX1Maximum(); + minMax2[1] = geoObject->getX2Maximum(); + minMax3[1] = geoObject->getX3Maximum(); + + for (int x3 = 0; x3 < 2; x3++) + for (int x2 = 0; x2 < 2; x2++) + for (int x1 = 0; x1 < 2; x1++) { + result = + result || (minMax1[x1] >= AABB[0] && minMax2[x2] >= AABB[1] && minMax3[x3] >= AABB[2] && + minMax1[x1] <= AABB[3] && minMax2[x2] <= AABB[4] && minMax3[x3] <= AABB[5]); + } + } + } + + std::vector<int> values; + values.push_back((int)result); + std::vector<int> rvalues = comm->gather(values); + + if (comm->isRoot()) { + for (int i = 0; i < (int)rvalues.size(); i++) { + result = result || (bool)rvalues[i]; + } + } + int iresult = (int)result; + comm->broadcast(iresult); + result = (bool)iresult; + + return result; } -int DemCoProcessor::addSurfaceTriangleSet(std::vector<UbTupleFloat3>& nodes, std::vector<UbTupleInt3>& triangles) +int DemCoProcessor::addSurfaceTriangleSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt3> &triangles) { - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - interactors[i]->getGbObject3D()->addSurfaceTriangleSet(nodes, triangles); - } - } - return (int)interactors.size(); + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + interactors[i]->getGbObject3D()->addSurfaceTriangleSet(nodes, triangles); + } + } + return (int)interactors.size(); } -void DemCoProcessor::getObjectsPropertiesVector(std::vector<double>& p) +void DemCoProcessor::getObjectsPropertiesVector(std::vector<double> &p) { - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - p.push_back(i); - p.push_back(interactors[i]->getGbObject3D()->getX1Centroid()); - p.push_back(interactors[i]->getGbObject3D()->getX2Centroid()); - p.push_back(interactors[i]->getGbObject3D()->getX3Centroid()); - Vector3D v = physicsEngineGeometrieAdapters[i]->getLinearVelocity(); - p.push_back(v[0]); - p.push_back(v[1]); - p.push_back(v[2]); - } - } + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + p.push_back(i); + p.push_back(interactors[i]->getGbObject3D()->getX1Centroid()); + p.push_back(interactors[i]->getGbObject3D()->getX2Centroid()); + p.push_back(interactors[i]->getGbObject3D()->getX3Centroid()); + Vector3D v = physicsEngineGeometrieAdapters[i]->getLinearVelocity(); + p.push_back(v[0]); + p.push_back(v[1]); + p.push_back(v[2]); + } + } } -void DemCoProcessor::addPeGeo(walberla::pe::RigidBody * peGeo) +void DemCoProcessor::addPeGeo(walberla::pe::RigidBody *peGeo) { - auto geometry = getPeGeoAdapter(peGeo->getSystemID()); - if (geometry != nullptr) - { - geometry->setActive(); - geometry->setGeometry(peGeo); - return; - } - else - return; + auto geometry = getPeGeoAdapter(peGeo->getSystemID()); + if (geometry != nullptr) { + geometry->setActive(); + geometry->setGeometry(peGeo); + return; + } else + return; } -void DemCoProcessor::removePeGeo(walberla::pe::RigidBody * peGeo) +void DemCoProcessor::removePeGeo(walberla::pe::RigidBody *peGeo) { - auto geometry = getPeGeoAdapter(peGeo->getSystemID()); - if (geometry != nullptr) - { - geometry->setSemiactive(true); - } - else - throw UbException(UB_EXARGS, "PeGeo SystemId="+UbSystem::toString(peGeo->getSystemID())+" is not matching geometry ID"); + auto geometry = getPeGeoAdapter(peGeo->getSystemID()); + if (geometry != nullptr) { + geometry->setSemiactive(true); + } else + throw UbException(UB_EXARGS, "PeGeo SystemId=" + UbSystem::toString(peGeo->getSystemID()) + + " is not matching geometry ID"); } -void DemCoProcessor::addPeShadowGeo(walberla::pe::RigidBody * peGeo) +void DemCoProcessor::addPeShadowGeo(walberla::pe::RigidBody *peGeo) { - auto geometry = getPeGeoAdapter(peGeo->getSystemID()); - if (geometry != nullptr) - { - geometry->setActive(); - geometry->setGeometry(peGeo); - return; - } - else - throw UbException(UB_EXARGS, "PeGeo ID="+UbSystem::toString(peGeo->getSystemID())+" is not matching geometry ID"); + auto geometry = getPeGeoAdapter(peGeo->getSystemID()); + if (geometry != nullptr) { + geometry->setActive(); + geometry->setGeometry(peGeo); + return; + } else + throw UbException(UB_EXARGS, + "PeGeo ID=" + UbSystem::toString(peGeo->getSystemID()) + " is not matching geometry ID"); } -void DemCoProcessor::removePeShadowGeo(walberla::pe::RigidBody * peGeo) +void DemCoProcessor::removePeShadowGeo(walberla::pe::RigidBody *peGeo) { - auto geometry = getPeGeoAdapter(peGeo->getSystemID()); - - if (geometry != nullptr) - { - geometry->setSemiactive(true); - } - else - throw UbException(UB_EXARGS, "PeGeo ID="+UbSystem::toString(peGeo->getSystemID())+" is not matching geometry ID"); + auto geometry = getPeGeoAdapter(peGeo->getSystemID()); + + if (geometry != nullptr) { + geometry->setSemiactive(true); + } else + throw UbException(UB_EXARGS, + "PeGeo ID=" + UbSystem::toString(peGeo->getSystemID()) + " is not matching geometry ID"); } bool DemCoProcessor::isSpheresIntersection(double centerX1, double centerX2, double centerX3, double d) { - bool result = false; - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - SPtr<GbObject3D> sphere = interactors[i]->getGbObject3D(); - result = result || (sqrt(pow(sphere->getX1Centroid()-centerX1, 2.0)+pow(sphere->getX2Centroid()-centerX2, 2.0)+pow(sphere->getX3Centroid()-centerX3, 2.0)) <= d); - } - } - std::vector<int> values; - values.push_back((int)result); - std::vector<int> rvalues = comm->gather(values); - - if (comm->isRoot()) - { - for (int i = 0; i < (int)rvalues.size(); i++) - { - result = result || (bool)rvalues[i]; - } - } - int iresult = (int)result; - comm->broadcast(iresult); - result = (bool)iresult; - - return result; + bool result = false; + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + SPtr<GbObject3D> sphere = interactors[i]->getGbObject3D(); + result = result || + (sqrt(pow(sphere->getX1Centroid() - centerX1, 2.0) + pow(sphere->getX2Centroid() - centerX2, 2.0) + + pow(sphere->getX3Centroid() - centerX3, 2.0)) <= d); + } + } + std::vector<int> values; + values.push_back((int)result); + std::vector<int> rvalues = comm->gather(values); + + if (comm->isRoot()) { + for (int i = 0; i < (int)rvalues.size(); i++) { + result = result || (bool)rvalues[i]; + } + } + int iresult = (int)result; + comm->broadcast(iresult); + result = (bool)iresult; + + return result; } void DemCoProcessor::distributeIDs() { - std::vector<unsigned long long> peIDsSend; - std::vector<int> vfIDsSend; - - for (int i = 0; i < interactors.size(); i++) - { - if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) - { - peIDsSend.push_back(std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->getSystemID()); - vfIDsSend.push_back(interactors[i]->getID()); - } - } - - std::vector<unsigned long long> peIDsRecv; - std::vector<int> vfIDsRecv; - - comm->allGather(peIDsSend, peIDsRecv); - comm->allGather(vfIDsSend, vfIDsRecv); - - std::map<int, unsigned long long> idMap; - - for (int i = 0; i < peIDsRecv.size(); i++) - { - idMap.insert(std::make_pair(vfIDsRecv[i], peIDsRecv[i])); - } - - for (int i = 0; i < interactors.size(); i++) - { - std::map<int, unsigned long long>::const_iterator it; - if ((it=idMap.find(interactors[i]->getID())) == idMap.end()) - { - throw UbException(UB_EXARGS, "Interactor ID = "+UbSystem::toString(interactors[i]->getID())+" is invalid! The DEM object may be not in PE domain!"); - } - - std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->setSystemID(it->second); - - geoIdMap.insert(std::make_pair(it->second, std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]))); - } + std::vector<unsigned long long> peIDsSend; + std::vector<int> vfIDsSend; + + for (int i = 0; i < interactors.size(); i++) { + if (std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i])->isActive()) { + peIDsSend.push_back( + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->getSystemID()); + vfIDsSend.push_back(interactors[i]->getID()); + } + } + + std::vector<unsigned long long> peIDsRecv; + std::vector<int> vfIDsRecv; + + comm->allGather(peIDsSend, peIDsRecv); + comm->allGather(vfIDsSend, vfIDsRecv); + + std::map<int, unsigned long long> idMap; + + for (int i = 0; i < peIDsRecv.size(); i++) { + idMap.insert(std::make_pair(vfIDsRecv[i], peIDsRecv[i])); + } + + for (int i = 0; i < interactors.size(); i++) { + std::map<int, unsigned long long>::const_iterator it; + if ((it = idMap.find(interactors[i]->getID())) == idMap.end()) { + throw UbException(UB_EXARGS, "Interactor ID = " + UbSystem::toString(interactors[i]->getID()) + + " is invalid! The DEM object may be not in PE domain!"); + } + + std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]) + ->setSystemID(it->second); + + geoIdMap.insert(std::make_pair( + it->second, std::dynamic_pointer_cast<PePhysicsEngineGeometryAdapter>(physicsEngineGeometrieAdapters[i]))); + } } ////////////////////////////////////////////////////////////////////////// void DemCoProcessor::setBlockVisitor(std::shared_ptr<BoundaryConditionsBlockVisitor> boundaryConditionsBlockVisitor) { - this->boundaryConditionsBlockVisitor = boundaryConditionsBlockVisitor; + this->boundaryConditionsBlockVisitor = boundaryConditionsBlockVisitor; } ////////////////////////////////////////////////////////////////////////// -walberla::pe::RigidBody* DemCoProcessor::getPeGeoObject(walberla::id_t id) +walberla::pe::RigidBody *DemCoProcessor::getPeGeoObject(walberla::id_t id) { - std::shared_ptr<walberla::blockforest::BlockForest> forest = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); - std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); - std::shared_ptr<walberla::pe::BodyStorage> globalBodyStorage = std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getGlobalBodyStorage(); - - return walberla::pe::getBody(*globalBodyStorage, *forest, *storageId, id, walberla::pe::StorageSelect::LOCAL | walberla::pe::StorageSelect::SHADOW); + std::shared_ptr<walberla::blockforest::BlockForest> forest = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getBlockForest(); + std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getStorageId(); + std::shared_ptr<walberla::pe::BodyStorage> globalBodyStorage = + std::dynamic_pointer_cast<PePhysicsEngineSolverAdapter>(physicsEngineSolver)->getGlobalBodyStorage(); + + return walberla::pe::getBody(*globalBodyStorage, *forest, *storageId, id, + walberla::pe::StorageSelect::LOCAL | walberla::pe::StorageSelect::SHADOW); } //////////////////////////////////////////////////////////////////////////// std::shared_ptr<PePhysicsEngineGeometryAdapter> DemCoProcessor::getPeGeoAdapter(unsigned long long systemId) { - std::map< unsigned long long, std::shared_ptr<PePhysicsEngineGeometryAdapter> >::const_iterator it; - if ((it=geoIdMap.find(systemId)) == geoIdMap.end()) - { - return nullptr; - } - else - return it->second; + std::map<unsigned long long, std::shared_ptr<PePhysicsEngineGeometryAdapter>>::const_iterator it; + if ((it = geoIdMap.find(systemId)) == geoIdMap.end()) { + return nullptr; + } else + return it->second; } diff --git a/src/cpu/DemCoupling/DemCoProcessor.h b/src/cpu/DemCoupling/DemCoProcessor.h index 74718a911..64fe24361 100644 --- a/src/cpu/DemCoupling/DemCoProcessor.h +++ b/src/cpu/DemCoupling/DemCoProcessor.h @@ -5,9 +5,9 @@ #ifndef DEM_CO_PROCESSOR_H #define DEM_CO_PROCESSOR_H +#include <map> #include <memory> #include <vector> -#include <map> #include "Vector3D.h" @@ -19,9 +19,8 @@ //#define TIMING #ifdef TIMING - #include "UbTiming.h" +#include "UbTiming.h" #endif - class PhysicsEngineGeometryAdapter; class PhysicsEngineSolverAdapter; @@ -37,54 +36,60 @@ class MovableObjectInteractor; class Communicator; class BoundaryConditionsBlockVisitor; - class DemCoProcessor : public CoProcessor { public: - DemCoProcessor(std::shared_ptr<Grid3D> grid, std::shared_ptr<UbScheduler> s, std::shared_ptr<Communicator> comm, std::shared_ptr<ForceCalculator> forceCalculator, std::shared_ptr<PhysicsEngineSolverAdapter> physicsEngineSolver, double intermediatePeSteps = 1.0); + DemCoProcessor(std::shared_ptr<Grid3D> grid, std::shared_ptr<UbScheduler> s, std::shared_ptr<Communicator> comm, + std::shared_ptr<ForceCalculator> forceCalculator, + std::shared_ptr<PhysicsEngineSolverAdapter> physicsEngineSolver, double intermediatePeSteps = 1.0); virtual ~DemCoProcessor(); - void addInteractor(std::shared_ptr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial, Vector3D initalVelocity = Vector3D(0.0, 0.0, 0.0)); + void addInteractor(std::shared_ptr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial, + Vector3D initalVelocity = Vector3D(0.0, 0.0, 0.0)); void process(double step) override; std::shared_ptr<PhysicsEngineSolverAdapter> getPhysicsEngineSolver(); void distributeIDs(); void setBlockVisitor(std::shared_ptr<BoundaryConditionsBlockVisitor> blockVisitor); - bool isDemObjectInAABB(std::array<double,6> AABB); - int addSurfaceTriangleSet(std::vector<UbTupleFloat3>& nodes, std::vector<UbTupleInt3>& triangles); - void getObjectsPropertiesVector(std::vector<double>& p); - void addPeGeo(walberla::pe::RigidBody* peGeo); - void removePeGeo(walberla::pe::RigidBody* peGeo); - void addPeShadowGeo(walberla::pe::RigidBody* peGeo); - void removePeShadowGeo(walberla::pe::RigidBody* peGeo); + bool isDemObjectInAABB(std::array<double, 6> AABB); + int addSurfaceTriangleSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt3> &triangles); + void getObjectsPropertiesVector(std::vector<double> &p); + void addPeGeo(walberla::pe::RigidBody *peGeo); + void removePeGeo(walberla::pe::RigidBody *peGeo); + void addPeShadowGeo(walberla::pe::RigidBody *peGeo); + void removePeShadowGeo(walberla::pe::RigidBody *peGeo); bool isSpheresIntersection(double centerX1, double centerX2, double centerX3, double d); - + private: - std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(std::shared_ptr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial) const; + std::shared_ptr<PhysicsEngineGeometryAdapter> + createPhysicsEngineGeometryAdapter(std::shared_ptr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineMaterialAdapter> physicsEngineMaterial) const; void applyForcesOnGeometries(); - void setForcesToObject(SPtr<Grid3D> grid, std::shared_ptr<MovableObjectInteractor> interactor, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry); + void setForcesToObject(SPtr<Grid3D> grid, std::shared_ptr<MovableObjectInteractor> interactor, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry); void scaleForcesAndTorques(double scalingFactor); void calculateDemTimeStep(double step); void moveVfGeoObjects(); - walberla::pe::RigidBody* getPeGeoObject(walberla::id_t id); + walberla::pe::RigidBody *getPeGeoObject(walberla::id_t id); std::shared_ptr<PePhysicsEngineGeometryAdapter> getPeGeoAdapter(unsigned long long systemId); + private: std::shared_ptr<Communicator> comm; - std::vector<std::shared_ptr<MovableObjectInteractor> > interactors; + std::vector<std::shared_ptr<MovableObjectInteractor>> interactors; std::shared_ptr<ForceCalculator> forceCalculator; std::shared_ptr<PePhysicsEngineSolverAdapter> physicsEngineSolver; - std::vector<std::shared_ptr<PhysicsEngineGeometryAdapter> > physicsEngineGeometrieAdapters; + std::vector<std::shared_ptr<PhysicsEngineGeometryAdapter>> physicsEngineGeometrieAdapters; double intermediateDemSteps; SPtr<BoundaryConditionsBlockVisitor> boundaryConditionsBlockVisitor; - //walberla::pe::BodyStorage* bodyStorage; //!< Reference to the central body storage. - //walberla::pe::BodyStorage* bodyStorageShadowCopies; //!< Reference to the body storage containing body shadow copies. + // walberla::pe::BodyStorage* bodyStorage; //!< Reference to the central body storage. + // walberla::pe::BodyStorage* bodyStorageShadowCopies; //!< Reference to the body storage containing body shadow + // copies. - std::map< unsigned long long, std::shared_ptr<PePhysicsEngineGeometryAdapter> > geoIdMap; + std::map<unsigned long long, std::shared_ptr<PePhysicsEngineGeometryAdapter>> geoIdMap; #ifdef TIMING UbTimer timer; #endif }; - #endif - diff --git a/src/cpu/DemCoupling/MovableObjectInteractor.cpp b/src/cpu/DemCoupling/MovableObjectInteractor.cpp index 49a9ece51..17185c8bb 100644 --- a/src/cpu/DemCoupling/MovableObjectInteractor.cpp +++ b/src/cpu/DemCoupling/MovableObjectInteractor.cpp @@ -1,19 +1,19 @@ #include "MovableObjectInteractor.h" -#include "UbLogger.h" #include "GbObject3D.h" +#include "UbLogger.h" #include "Vector3D.h" -#include "Block3D.h" -#include "Grid3D.h" -#include "BCArray3D.h" #include "BCAdapter.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "ILBMKernel.h" +#include "Block3D.h" #include "CoordinateTransformation3D.h" +#include "Grid3D.h" +#include "ILBMKernel.h" -#include "SetBcBlocksBlockVisitor.h" #include "BoundaryConditionsBlockVisitor.h" +#include "SetBcBlocksBlockVisitor.h" #include "PhysicsEngineGeometryAdapter.h" #include "Reconstructor.h" @@ -23,30 +23,30 @@ //#define TIMING #ifdef TIMING - #include "UbTiming.h" +#include "UbTiming.h" #endif - -MovableObjectInteractor::MovableObjectInteractor(std::shared_ptr<GbObject3D> geoObject3D, std::shared_ptr<Grid3D> grid, std::shared_ptr<BCAdapter> bcAdapter, int type, std::shared_ptr<Reconstructor> reconstructor, State state) - : D3Q27Interactor(geoObject3D, grid, bcAdapter, type), reconstructor(reconstructor), state(state) +MovableObjectInteractor::MovableObjectInteractor(std::shared_ptr<GbObject3D> geoObject3D, std::shared_ptr<Grid3D> grid, + std::shared_ptr<BCAdapter> bcAdapter, int type, + std::shared_ptr<Reconstructor> reconstructor, State state) + : D3Q27Interactor(geoObject3D, grid, bcAdapter, type), reconstructor(reconstructor), state(state) { - //grid->getBlocks(0, grid->getRank(), true, blockVector); + // grid->getBlocks(0, grid->getRank(), true, blockVector); } -MovableObjectInteractor::~MovableObjectInteractor() -{ - -} +MovableObjectInteractor::~MovableObjectInteractor() {} -void MovableObjectInteractor::setPhysicsEngineGeometry(std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) +void MovableObjectInteractor::setPhysicsEngineGeometry( + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) { this->physicsEngineGeometry = physicsEngineGeometry; physicsEngineGeometry->changeState(this->state); } -void MovableObjectInteractor::moveGbObjectTo(const Vector3D& position) +void MovableObjectInteractor::moveGbObjectTo(const Vector3D &position) { - //UBLOG(logINFO, "new position: (x,y,z) " << val<1>(position) << ", " << val<2>(position) << ", " << val<3>(position)); + // UBLOG(logINFO, "new position: (x,y,z) " << val<1>(position) << ", " << val<2>(position) << ", " << + // val<3>(position)); this->getGbObject3D()->setCenterCoordinates(UbTupleDouble3(position[0], position[1], position[2])); this->rearrangeGrid(); @@ -55,98 +55,94 @@ void MovableObjectInteractor::moveGbObjectTo(const Vector3D& position) void MovableObjectInteractor::rearrangeGrid() { #ifdef TIMING - UbTimer timer; - timer.resetAndStart(); + UbTimer timer; + timer.resetAndStart(); #endif #ifdef TIMING - UBLOG(logINFO, "MovableObjectInteractor::rearrangeGrid():start"); + UBLOG(logINFO, "MovableObjectInteractor::rearrangeGrid():start"); #endif this->reconstructDistributionOnSolidNodes(); #ifdef TIMING - UBLOG(logINFO, "reconstructDistributionOnSolidNodes() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "reconstructDistributionOnSolidNodes() time = " << timer.stop() << " s"); #endif this->setSolidNodesToFluid(); #ifdef TIMING - UBLOG(logINFO, "setSolidNodesToFluid() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "setSolidNodesToFluid() time = " << timer.stop() << " s"); #endif this->setBcNodesToFluid(); #ifdef TIMING - UBLOG(logINFO, "setBcNodesToFluid() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "setBcNodesToFluid() time = " << timer.stop() << " s"); #endif this->removeSolidBlocks(); #ifdef TIMING - UBLOG(logINFO, "removeSolidBlocks() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "removeSolidBlocks() time = " << timer.stop() << " s"); #endif this->removeBcBlocks(); #ifdef TIMING - UBLOG(logINFO, "removeBcBlocks() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "removeBcBlocks() time = " << timer.stop() << " s"); #endif this->setBcBlocks(); #ifdef TIMING - UBLOG(logINFO, "setBcBlocks() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "setBcBlocks() time = " << timer.stop() << " s"); #endif this->initInteractor(); #ifdef TIMING - UBLOG(logINFO, "initInteractor() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "initInteractor() time = " << timer.stop() << " s"); #endif this->updateVelocityBc(); #ifdef TIMING - UBLOG(logINFO, "updateVelocityBc() time = "<<timer.stop()<<" s"); + UBLOG(logINFO, "updateVelocityBc() time = " << timer.stop() << " s"); #endif } void MovableObjectInteractor::updateNodeLists() { - //for (BcNodeIndicesMap::value_type t : bcNodeIndicesMap) - //{ - // SPtr<Block3D> block = t.first; - // std::set< UbTupleInt3 >& bcNodeIndices = t.second; - + // for (BcNodeIndicesMap::value_type t : bcNodeIndicesMap) + //{ + // SPtr<Block3D> block = t.first; + // std::set< UbTupleInt3 >& bcNodeIndices = t.second; - // SPtr<ILBMKernel> kernel = block->getKernel(); + // SPtr<ILBMKernel> kernel = block->getKernel(); - // for (UbTupleInt3 node : bcNodeIndices) - // { + // for (UbTupleInt3 node : bcNodeIndices) + // { - // } - //} + // } + //} } void MovableObjectInteractor::reconstructDistributionOnSolidNodes() { - for(SolidNodeIndicesMap::value_type t : solidNodeIndicesMap) - { - SPtr<Block3D> block = t.first; - std::set< UbTupleInt3 >& solidNodeIndices = t.second; + for (SolidNodeIndicesMap::value_type t : solidNodeIndicesMap) { + SPtr<Block3D> block = t.first; + std::set<UbTupleInt3> &solidNodeIndices = t.second; - SPtr<ILBMKernel> kernel = block->getKernel(); - for (UbTupleInt3 node : solidNodeIndices) - { + for (UbTupleInt3 node : solidNodeIndices) { const int x1 = val<1>(node); const int x2 = val<2>(node); const int x3 = val<3>(node); const Vector3D worldCoordinates = this->grid.lock()->getNodeCoordinates(block, x1, x2, x3); - + if (kernel->isInsideOfDomain(x1, x2, x3)) reconstructor->reconstructNode(x1, x2, x3, worldCoordinates, physicsEngineGeometry, kernel); } @@ -155,10 +151,9 @@ void MovableObjectInteractor::reconstructDistributionOnSolidNodes() void MovableObjectInteractor::setSolidNodesToFluid() { - for (SolidNodeIndicesMap::value_type t : solidNodeIndicesMap) - { - SPtr<Block3D> block = t.first; - std::set< UbTupleInt3 >& solidNodeIndices = t.second; + for (SolidNodeIndicesMap::value_type t : solidNodeIndicesMap) { + SPtr<Block3D> block = t.first; + std::set<UbTupleInt3> &solidNodeIndices = t.second; SPtr<ILBMKernel> kernel = block->getKernel(); SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); @@ -170,17 +165,16 @@ void MovableObjectInteractor::setSolidNodesToFluid() void MovableObjectInteractor::setBcNodesToFluid() { - for (BcNodeIndicesMap::value_type t : bcNodeIndicesMap) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& bcNodeIndices = t.second; + for (BcNodeIndicesMap::value_type t : bcNodeIndicesMap) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &bcNodeIndices = t.second; - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - for (std::vector<int> node : bcNodeIndices) - bcArray->setFluid(node[0], node[1], node[2]); - } + for (std::vector<int> node : bcNodeIndices) + bcArray->setFluid(node[0], node[1], node[2]); + } } void MovableObjectInteractor::setBcBlocks() @@ -189,72 +183,72 @@ void MovableObjectInteractor::setBcBlocks() this->grid.lock()->accept(v); ////////////////////////////////////////////////////////////////////////// - //SPtr<GbObject3D> geoObject = this->getGbObject3D(); - //std::array<double, 6> AABB ={ geoObject->getX1Minimum(),geoObject->getX2Minimum(),geoObject->getX3Minimum(),geoObject->getX1Maximum(),geoObject->getX2Maximum(),geoObject->getX3Maximum() }; - //blockVector.clear(); - //UbTupleInt3 blockNX=grid.lock()->getBlockNX(); - //double ext = 0.0; - //grid.lock()->getBlocksByCuboid(AABB[0]-(double)val<1>(blockNX)*ext, AABB[1]-(double)val<2>(blockNX)*ext, AABB[2]-(double)val<3>(blockNX)*ext, AABB[3]+(double)val<1>(blockNX)*ext, AABB[4]+(double)val<2>(blockNX)*ext, AABB[5]+(double)val<3>(blockNX)*ext, blockVector); - - //for(std::shared_ptr<Block3D> block : this->blockVector) - //{ - // if (block->getKernel()) - // { - // setBCBlock(block); - // } - //} - ////////////////////////////////////////////////////////////////////////// - //SPtr<GbObject3D> geoObject = this->getGbObject3D(); - //std::array <double, 2> minMax1; - //std::array <double, 2> minMax2; - //std::array <double, 2> minMax3; - //minMax1[0] = geoObject->getX1Minimum(); - //minMax2[0] = geoObject->getX2Minimum(); - //minMax3[0] = geoObject->getX3Minimum(); - //minMax1[1] = geoObject->getX1Maximum(); - //minMax2[1] = geoObject->getX2Maximum(); - //minMax3[1] = geoObject->getX3Maximum(); - - //SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); - - //for (int x3 = 0; x3 < 2; x3++) - // for (int x2 = 0; x2 < 2; x2++) - // for (int x1 = 0; x1 < 2; x1++) - // { - // int ix1 = (int)trafo->transformForwardToX1Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); - // int ix2 = (int)trafo->transformForwardToX2Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); - // int ix3 = (int)trafo->transformForwardToX3Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); - // blockVector.push_back(grid.lock()->getBlock(ix1, ix2, ix3, 0)); - // } - //for(std::shared_ptr<Block3D> block : this->blockVector) - //{ - // if (block->getKernel()) - // { - // setBCBlock(block); - // } - //} + // SPtr<GbObject3D> geoObject = this->getGbObject3D(); + // std::array<double, 6> AABB ={ + // geoObject->getX1Minimum(),geoObject->getX2Minimum(),geoObject->getX3Minimum(),geoObject->getX1Maximum(),geoObject->getX2Maximum(),geoObject->getX3Maximum() + // }; blockVector.clear(); UbTupleInt3 blockNX=grid.lock()->getBlockNX(); double ext = 0.0; + // grid.lock()->getBlocksByCuboid(AABB[0]-(double)val<1>(blockNX)*ext, AABB[1]-(double)val<2>(blockNX)*ext, + // AABB[2]-(double)val<3>(blockNX)*ext, AABB[3]+(double)val<1>(blockNX)*ext, AABB[4]+(double)val<2>(blockNX)*ext, + // AABB[5]+(double)val<3>(blockNX)*ext, blockVector); + + // for(std::shared_ptr<Block3D> block : this->blockVector) + //{ + // if (block->getKernel()) + // { + // setBCBlock(block); + // } + //} + ////////////////////////////////////////////////////////////////////////// + // SPtr<GbObject3D> geoObject = this->getGbObject3D(); + // std::array <double, 2> minMax1; + // std::array <double, 2> minMax2; + // std::array <double, 2> minMax3; + // minMax1[0] = geoObject->getX1Minimum(); + // minMax2[0] = geoObject->getX2Minimum(); + // minMax3[0] = geoObject->getX3Minimum(); + // minMax1[1] = geoObject->getX1Maximum(); + // minMax2[1] = geoObject->getX2Maximum(); + // minMax3[1] = geoObject->getX3Maximum(); + + // SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); + + // for (int x3 = 0; x3 < 2; x3++) + // for (int x2 = 0; x2 < 2; x2++) + // for (int x1 = 0; x1 < 2; x1++) + // { + // int ix1 = (int)trafo->transformForwardToX1Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); + // int ix2 = (int)trafo->transformForwardToX2Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); + // int ix3 = (int)trafo->transformForwardToX3Coordinate(minMax1[x1], minMax2[x2], minMax3[x3]); + // blockVector.push_back(grid.lock()->getBlock(ix1, ix2, ix3, 0)); + // } + // for(std::shared_ptr<Block3D> block : this->blockVector) + //{ + // if (block->getKernel()) + // { + // setBCBlock(block); + // } + //} } void MovableObjectInteractor::updateVelocityBc() { - for(BcNodeIndicesMap::value_type t : this->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& bcNodeIndices = t.second; + for (BcNodeIndicesMap::value_type t : this->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &bcNodeIndices = t.second; SPtr<BCArray3D> bcArray = block->getKernel()->getBCProcessor()->getBCArray(); - for(std::vector<int> node : bcNodeIndices) + for (std::vector<int> node : bcNodeIndices) setGeometryVelocityToBoundaryCondition(node, block, bcArray); } } - -void MovableObjectInteractor::setGeometryVelocityToBoundaryCondition(std::vector<int> node, SPtr<Block3D> block, SPtr<BCArray3D> bcArray) const +void MovableObjectInteractor::setGeometryVelocityToBoundaryCondition(std::vector<int> node, SPtr<Block3D> block, + SPtr<BCArray3D> bcArray) const { const SPtr<BoundaryConditions> bc = bcArray->getBC(node[0], node[1], node[2]); - const Vector3D worldCoordinates = this->grid.lock()->getNodeCoordinates(block, node[0], node[1], node[2]); - const Vector3D velocity = this->physicsEngineGeometry->getVelocityAtPosition(worldCoordinates); + const Vector3D worldCoordinates = this->grid.lock()->getNodeCoordinates(block, node[0], node[1], node[2]); + const Vector3D velocity = this->physicsEngineGeometry->getVelocityAtPosition(worldCoordinates); bc->setBoundaryVelocity(velocity); } diff --git a/src/cpu/DemCoupling/MovableObjectInteractor.h b/src/cpu/DemCoupling/MovableObjectInteractor.h index 0aeb22bbd..e0e4343a0 100644 --- a/src/cpu/DemCoupling/MovableObjectInteractor.h +++ b/src/cpu/DemCoupling/MovableObjectInteractor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef D3Q27_MOVABLE_OBJECT_INTERACTOR_H #define D3Q27_MOVABLE_OBJECT_INTERACTOR_H @@ -10,9 +10,8 @@ #include "D3Q27Interactor.h" -#include "Vector3D.h" #include "PhysicsEngineGeometryAdapter.h" - +#include "Vector3D.h" class Grid3D; class Block3D; @@ -26,15 +25,18 @@ class Reconstructor; class MovableObjectInteractor : public D3Q27Interactor { public: - typedef std::map<SPtr<Block3D>, std::set< std::array<int,3> > > InBcNodeIndicesMap; - typedef std::map<SPtr<Block3D>, std::set< std::array<int,3> > > OutBcNodeIndicesMap; + typedef std::map<SPtr<Block3D>, std::set<std::array<int, 3>>> InBcNodeIndicesMap; + typedef std::map<SPtr<Block3D>, std::set<std::array<int, 3>>> OutBcNodeIndicesMap; + public: - MovableObjectInteractor(std::shared_ptr<GbObject3D> geoObject3D, std::shared_ptr<Grid3D> grid, std::shared_ptr<BCAdapter> bcAdapter, int type, std::shared_ptr<Reconstructor> reconstructor, State isPinned); + MovableObjectInteractor(std::shared_ptr<GbObject3D> geoObject3D, std::shared_ptr<Grid3D> grid, + std::shared_ptr<BCAdapter> bcAdapter, int type, + std::shared_ptr<Reconstructor> reconstructor, State isPinned); virtual ~MovableObjectInteractor(); void setPhysicsEngineGeometry(std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry); - void moveGbObjectTo(const Vector3D& position); + void moveGbObjectTo(const Vector3D &position); private: void rearrangeGrid(); @@ -45,14 +47,14 @@ private: void setBcBlocks(); void updateVelocityBc(); - void setGeometryVelocityToBoundaryCondition(std::vector<int> node, std::shared_ptr<Block3D> block, std::shared_ptr<BCArray3D> bcArray) const; + void setGeometryVelocityToBoundaryCondition(std::vector<int> node, std::shared_ptr<Block3D> block, + std::shared_ptr<BCArray3D> bcArray) const; std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry; std::shared_ptr<Reconstructor> reconstructor; State state; - std::vector< std::shared_ptr<Block3D> > blockVector; + std::vector<std::shared_ptr<Block3D>> blockVector; }; - #endif diff --git a/src/cpu/DemCoupling/PePartitioningGridVisitor.cpp b/src/cpu/DemCoupling/PePartitioningGridVisitor.cpp index b52d3ba57..8dbe680a8 100644 --- a/src/cpu/DemCoupling/PePartitioningGridVisitor.cpp +++ b/src/cpu/DemCoupling/PePartitioningGridVisitor.cpp @@ -1,70 +1,64 @@ #if defined VF_METIS && defined VF_MPI -#include <shared_mutex> #include "PePartitioningGridVisitor.h" -#include <math.h> #include "Block3D.h" -#include "Grid3D.h" #include "Communicator.h" -#include "UbLogger.h" #include "CoordinateTransformation3D.h" +#include "Grid3D.h" +#include "UbLogger.h" +#include <math.h> +#include <shared_mutex> #include "DemCoProcessor.h" using namespace std; PePartitioningGridVisitor::PePartitioningGridVisitor(SPtr<Communicator> comm, std::shared_ptr<DemCoProcessor> dem) - : Grid3DVisitor(), - comm(comm), - dem(dem) + : Grid3DVisitor(), comm(comm), dem(dem) { - forest = dynamicPointerCast<PePhysicsEngineSolverAdapter>(dem->getPhysicsEngineSolver())->getForest(); + forest = dynamicPointerCast<PePhysicsEngineSolverAdapter>(dem->getPhysicsEngineSolver())->getForest(); } ////////////////////////////////////////////////////////////////////////// -PePartitioningGridVisitor::~PePartitioningGridVisitor() -{ - -} +PePartitioningGridVisitor::~PePartitioningGridVisitor() {} ////////////////////////////////////////////////////////////////////////// void PePartitioningGridVisitor::visit(SPtr<Grid3D> grid) { - UBLOG(logDEBUG1, "PePartitioningGridVisitor::visit() - start"); + UBLOG(logDEBUG1, "PePartitioningGridVisitor::visit() - start"); - collectData(grid); - distributePartitionData(grid); + collectData(grid); + distributePartitionData(grid); - UBLOG(logDEBUG1, "PePartitioningGridVisitor::visit() - end"); + UBLOG(logDEBUG1, "PePartitioningGridVisitor::visit() - end"); } ////////////////////////////////////////////////////////////////////////// void PePartitioningGridVisitor::collectData(SPtr<Grid3D> grid) { - //int minInitLevel = grid->getCoarsestInitializedLevel(); - //int maxInitLevel = grid->getFinestInitializedLevel(); - - walberla::uint_t peRank; - - for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) - { - forest->getProcessRank(peRank, blockIt->getId()); - vector<SPtr<Block3D>> blocks; - walberla::AABB aabb = blockIt->getAABB(); - - //getBlocksByCuboid((double)aabb.xMin(), (double)aabb.yMin(), (double)aabb.zMin(), (double)aabb.xMax(), (double)aabb.yMax(), (double)aabb.zMax(), blocks, grid); - //for (SPtr<Block3D> block : blocks) - //{ - // ids.push_back(block->getGlobalID()); - // ranks.push_back((int)peRank); - //} - SPtr<Block3D> block = getBlockByMinUniform((double)aabb.xMin(), (double)aabb.yMin(), (double)aabb.zMin(), grid); - if (block) - { - ids.push_back(block->getGlobalID()); - ranks.push_back((int)peRank); - } - } + // int minInitLevel = grid->getCoarsestInitializedLevel(); + // int maxInitLevel = grid->getFinestInitializedLevel(); + + walberla::uint_t peRank; + + for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) { + forest->getProcessRank(peRank, blockIt->getId()); + vector<SPtr<Block3D>> blocks; + walberla::AABB aabb = blockIt->getAABB(); + + // getBlocksByCuboid((double)aabb.xMin(), (double)aabb.yMin(), (double)aabb.zMin(), (double)aabb.xMax(), + // (double)aabb.yMax(), (double)aabb.zMax(), blocks, grid); for (SPtr<Block3D> block : blocks) + //{ + // ids.push_back(block->getGlobalID()); + // ranks.push_back((int)peRank); + //} + SPtr<Block3D> block = getBlockByMinUniform((double)aabb.xMin(), (double)aabb.yMin(), (double)aabb.zMin(), grid); + if (block) { + ids.push_back(block->getGlobalID()); + ranks.push_back((int)peRank); + } + } } ////////////////////////////////////////////////////////////////////////// -//void PePartitioningGridVisitor::getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks, SPtr<Grid3D> grid) +// void PePartitioningGridVisitor::getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double +// maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks, SPtr<Grid3D> grid) //{ // int coarsestLevel = grid->getCoarsestInitializedLevel(); // int finestLevel = grid->getFinestInitializedLevel(); @@ -73,7 +67,7 @@ void PePartitioningGridVisitor::collectData(SPtr<Grid3D> grid) // // ////////////////////////////////////////////////////////////////////////// // //MINIMALE BLOCK-INDIZES BESTIMMEN -// // +// // // //min: // double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3)*(1<<finestLevel); // double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3)*(1<<finestLevel); @@ -118,39 +112,37 @@ void PePartitioningGridVisitor::collectData(SPtr<Grid3D> grid) // std::copy(blockset.begin(), blockset.end(), blocks.begin()); //} -SPtr<Block3D> PePartitioningGridVisitor::getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid) +SPtr<Block3D> PePartitioningGridVisitor::getBlockByMinUniform(double minX1, double minX2, double minX3, + SPtr<Grid3D> grid) { - SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); + SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); - int ix1 = (int)trafo->transformForwardToX1Coordinate(minX1, minX2, minX3); - int ix2 = (int)trafo->transformForwardToX2Coordinate(minX1, minX2, minX3); - int ix3 = (int)trafo->transformForwardToX3Coordinate(minX1, minX2, minX3); + int ix1 = (int)trafo->transformForwardToX1Coordinate(minX1, minX2, minX3); + int ix2 = (int)trafo->transformForwardToX2Coordinate(minX1, minX2, minX3); + int ix3 = (int)trafo->transformForwardToX3Coordinate(minX1, minX2, minX3); - return grid->getBlock(ix1, ix2, ix3, 0); + return grid->getBlock(ix1, ix2, ix3, 0); } ////////////////////////////////////////////////////////////////////////// void PePartitioningGridVisitor::distributePartitionData(SPtr<Grid3D> grid) { - std::vector<int> totalIDs; - std::vector<int> totalRanks; + std::vector<int> totalIDs; + std::vector<int> totalRanks; - assert(ids.size() != 0); - assert(ranks.size() != 0); + assert(ids.size() != 0); + assert(ranks.size() != 0); - comm->allGather(ids, totalIDs); - comm->allGather(ranks, totalRanks); + comm->allGather(ids, totalIDs); + comm->allGather(ranks, totalRanks); - - assert(totalIDs.size() == totalRanks.size()); - for (int i = 0; i < totalIDs.size(); i++) - { - SPtr<Block3D> block = grid->getBlock(totalIDs[i]); - if (block) block->setRank(totalRanks[i]); - } + assert(totalIDs.size() == totalRanks.size()); + for (int i = 0; i < totalIDs.size(); i++) { + SPtr<Block3D> block = grid->getBlock(totalIDs[i]); + if (block) + block->setRank(totalRanks[i]); + } } ////////////////////////////////////////////////////////////////////////// - - -#endif //VF_METIS +#endif // VF_METIS diff --git a/src/cpu/DemCoupling/PePartitioningGridVisitor.h b/src/cpu/DemCoupling/PePartitioningGridVisitor.h index bce2ca0d2..ff97d531d 100644 --- a/src/cpu/DemCoupling/PePartitioningGridVisitor.h +++ b/src/cpu/DemCoupling/PePartitioningGridVisitor.h @@ -1,10 +1,10 @@ -#ifndef PePartitioningGridVisitor_h +#ifndef PePartitioningGridVisitor_h #define PePartitioningGridVisitor_h #if defined VF_MPI -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "Grid3DVisitor.h" @@ -20,37 +20,38 @@ class Communicator; class Grid3D; class Block3D; class DemCoProcessor; -//class walberla::blockforest::BlockForest; +// class walberla::blockforest::BlockForest; class PePartitioningGridVisitor : public Grid3DVisitor -{ +{ public: - //! This describe different types of decomposition - enum GraphType{LevelIntersected, LevelBased}; + //! This describe different types of decomposition + enum GraphType { LevelIntersected, LevelBased }; public: - //! Constructor - //! \param comm - communicator + //! Constructor + //! \param comm - communicator - PePartitioningGridVisitor(SPtr<Communicator> comm, std::shared_ptr<DemCoProcessor> dem); - virtual ~PePartitioningGridVisitor(); - void visit(SPtr<Grid3D> grid) override; + PePartitioningGridVisitor(SPtr<Communicator> comm, std::shared_ptr<DemCoProcessor> dem); + virtual ~PePartitioningGridVisitor(); + void visit(SPtr<Grid3D> grid) override; protected: - void collectData(SPtr<Grid3D> grid); - void distributePartitionData(SPtr<Grid3D> grid); - //void getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks, SPtr<Grid3D> grid); - SPtr<Block3D> getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid); + void collectData(SPtr<Grid3D> grid); + void distributePartitionData(SPtr<Grid3D> grid); + // void getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + // std::vector<SPtr<Block3D>>& blocks, SPtr<Grid3D> grid); + SPtr<Block3D> getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid); private: - SPtr<Communicator> comm; - std::shared_ptr<DemCoProcessor> dem; + SPtr<Communicator> comm; + std::shared_ptr<DemCoProcessor> dem; - std::vector<int> ids; - std::vector<int> ranks; + std::vector<int> ids; + std::vector<int> ranks; - std::shared_ptr< walberla::blockforest::BlockForest > forest; + std::shared_ptr<walberla::blockforest::BlockForest> forest; }; -#endif //VF_MPI -#endif +#endif // VF_MPI +#endif diff --git a/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.cpp b/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.cpp index 1cc39ad6e..1d0183763 100644 --- a/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.cpp +++ b/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.cpp @@ -1,119 +1,119 @@ #include "RestartDemObjectsCoProcessor.h" -#include "Vector3D.h" #include "Communicator.h" -#include "UbScheduler.h" -#include "Grid3D.h" -#include "UbSystem.h" -#include "GbSphere3D.h" +#include "CreateDemObjectsCoProcessor.h" #include "DemCoProcessor.h" +#include "GbSphere3D.h" +#include "Grid3D.h" #include "UbFileInputBinary.h" #include "UbFileOutputBinary.h" -#include "CreateDemObjectsCoProcessor.h" +#include "UbScheduler.h" +#include "UbSystem.h" +#include "Vector3D.h" -RestartDemObjectsCoProcessor::RestartDemObjectsCoProcessor() -{ -} +RestartDemObjectsCoProcessor::RestartDemObjectsCoProcessor() {} -RestartDemObjectsCoProcessor::RestartDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string & path, SPtr<DemCoProcessor> demCoProcessor, SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor, double radius, SPtr<Communicator> comm) : CoProcessor(grid, s), path(path), demCoProcessor(demCoProcessor), createDemObjectsCoProcessor(createDemObjectsCoProcessor), radius(radius), comm(comm) +RestartDemObjectsCoProcessor::RestartDemObjectsCoProcessor( + SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<DemCoProcessor> demCoProcessor, + SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor, double radius, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), demCoProcessor(demCoProcessor), + createDemObjectsCoProcessor(createDemObjectsCoProcessor), radius(radius), comm(comm) { } void RestartDemObjectsCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - int istep = static_cast<int>(step); + if (scheduler->isDue(step)) { + int istep = static_cast<int>(step); - if (comm->isRoot()) - UBLOG(logINFO, "RestartDemObjectsCoProcessor::write step: " << istep); + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::write step: " << istep); - write(istep); - } + write(istep); + } } void RestartDemObjectsCoProcessor::restart(double step) { - if (comm->isRoot()) - UBLOG(logINFO, "RestartDemObjectsCoProcessor::read step: " << (int)step); + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::read step: " << (int)step); - read((int)step); + read((int)step); } void RestartDemObjectsCoProcessor::write(int step) { - if (comm->isRoot()) UBLOG(logINFO, "RestartDemObjectsCoProcessor::write start "); - std::vector<double> p; - - demCoProcessor->getObjectsPropertiesVector(p); - - //TODO implement getherv - std::vector<double> rvalues; - comm->allGather(p, rvalues); - - if (comm->isRoot()) - { - std::map< int, std::vector< double> > infMap; - int size = (int)rvalues.size(); - for (int i = 0; i < size; i += 7) - { - std::vector< double> infVector(6); - for (int j = 0; j < 6; j ++) - { - infVector[j] = rvalues[i+1+j]; - } - infMap.insert(std::make_pair((int)rvalues[i], infVector)); - } - std::vector< double> wvalues; - typedef std::map< int, std::vector< double> >::iterator it_type; - for (it_type iterator = infMap.begin(); iterator != infMap.end(); iterator++) - { - // iterator->first = key - // iterator->second = value - std::vector<double>::iterator it = wvalues.end(); - it = wvalues.insert(it, iterator->second.begin(), iterator->second.end()); - } - std::string subfolder = "dem_cp_"+UbSystem::toString(step); - std::string filePath = path+"/dem_cp/"+subfolder+"/dem_cp.bin"; - UbFileOutputBinary fo(filePath); - fo.writeInteger((int)wvalues.size()); - fo.writeVector<double>(wvalues); - UBLOG(logINFO, "RestartDemObjectsCoProcessor::write number of objects = " << wvalues.size()/6); - } - if (comm->isRoot()) UBLOG(logINFO, "RestartDemObjectsCoProcessor::write stop "); + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::write start "); + std::vector<double> p; + + demCoProcessor->getObjectsPropertiesVector(p); + + // TODO implement getherv + std::vector<double> rvalues; + comm->allGather(p, rvalues); + + if (comm->isRoot()) { + std::map<int, std::vector<double>> infMap; + int size = (int)rvalues.size(); + for (int i = 0; i < size; i += 7) { + std::vector<double> infVector(6); + for (int j = 0; j < 6; j++) { + infVector[j] = rvalues[i + 1 + j]; + } + infMap.insert(std::make_pair((int)rvalues[i], infVector)); + } + std::vector<double> wvalues; + typedef std::map<int, std::vector<double>>::iterator it_type; + for (it_type iterator = infMap.begin(); iterator != infMap.end(); iterator++) { + // iterator->first = key + // iterator->second = value + std::vector<double>::iterator it = wvalues.end(); + it = wvalues.insert(it, iterator->second.begin(), iterator->second.end()); + } + std::string subfolder = "dem_cp_" + UbSystem::toString(step); + std::string filePath = path + "/dem_cp/" + subfolder + "/dem_cp.bin"; + UbFileOutputBinary fo(filePath); + fo.writeInteger((int)wvalues.size()); + fo.writeVector<double>(wvalues); + UBLOG(logINFO, "RestartDemObjectsCoProcessor::write number of objects = " << wvalues.size() / 6); + } + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::write stop "); } void RestartDemObjectsCoProcessor::read(int step) { - if (comm->isRoot()) UBLOG(logINFO, "RestartDemObjectsCoProcessor::read start "); - std::vector<double> p; + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::read start "); + std::vector<double> p; - if (comm->isRoot()) - { - std::string subfolder = "dem_cp_"+UbSystem::toString(step); - std::string filePath = path+"/dem_cp/"+subfolder+"/dem_cp.bin"; - UbFileInputBinary fi(filePath); - int size = fi.readInteger(); - p.resize(size); - fi.readVector<double>(p); - } - comm->broadcast(p); + if (comm->isRoot()) { + std::string subfolder = "dem_cp_" + UbSystem::toString(step); + std::string filePath = path + "/dem_cp/" + subfolder + "/dem_cp.bin"; + UbFileInputBinary fi(filePath); + int size = fi.readInteger(); + p.resize(size); + fi.readVector<double>(p); + } + comm->broadcast(p); - if (comm->isRoot()) UBLOG(logINFO, "RestartDemObjectsCoProcessor::read number of objects = " << p.size()/6); + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::read number of objects = " << p.size() / 6); - createDemObjectsCoProcessor->clearGeoObjects(); + createDemObjectsCoProcessor->clearGeoObjects(); - int size = (int)p.size(); + int size = (int)p.size(); - for (int i = 0; i < size; i += 6) - { - SPtr<GbObject3D> sphere(new GbSphere3D(p[i], p[i+1], p[i+2], radius)); - createDemObjectsCoProcessor->addGeoObject(sphere, Vector3D(p[i+3], p[i+4], p[i+5])); - } + for (int i = 0; i < size; i += 6) { + SPtr<GbObject3D> sphere(new GbSphere3D(p[i], p[i + 1], p[i + 2], radius)); + createDemObjectsCoProcessor->addGeoObject(sphere, Vector3D(p[i + 3], p[i + 4], p[i + 5])); + } - createDemObjectsCoProcessor->createGeoObjects(); + createDemObjectsCoProcessor->createGeoObjects(); - createDemObjectsCoProcessor->clearGeoObjects(); + createDemObjectsCoProcessor->clearGeoObjects(); - if (comm->isRoot()) UBLOG(logINFO, "RestartDemObjectsCoProcessor::read stop "); + if (comm->isRoot()) + UBLOG(logINFO, "RestartDemObjectsCoProcessor::read stop "); } diff --git a/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.h b/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.h index 8a1fdb721..08fb70ef5 100644 --- a/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.h +++ b/src/cpu/DemCoupling/RestartDemObjectsCoProcessor.h @@ -1,7 +1,7 @@ /* -* Author: K. Kutscher -* mail: kutscher@irmb.tu-bs.de -*/ + * Author: K. Kutscher + * mail: kutscher@irmb.tu-bs.de + */ #ifndef RestartDemObjectsCoProcessor_H #define RestartDemObjectsCoProcessor_H @@ -17,22 +17,25 @@ class UbScheduler; class DemCoProcessor; class CreateDemObjectsCoProcessor; -class RestartDemObjectsCoProcessor : public CoProcessor +class RestartDemObjectsCoProcessor : public CoProcessor { public: - RestartDemObjectsCoProcessor(); - RestartDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<DemCoProcessor> demCoProcessor, SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor, double radius, SPtr<Communicator> comm); - ~RestartDemObjectsCoProcessor() {} - void process(double step) override; - void restart(double step); - void write(int step); - void read(int step); + RestartDemObjectsCoProcessor(); + RestartDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<DemCoProcessor> demCoProcessor, + SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor, double radius, + SPtr<Communicator> comm); + ~RestartDemObjectsCoProcessor() {} + void process(double step) override; + void restart(double step); + void write(int step); + void read(int step); private: - std::string path; - double radius; - SPtr<Communicator> comm; - SPtr<DemCoProcessor> demCoProcessor; - SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor; + std::string path; + double radius; + SPtr<Communicator> comm; + SPtr<DemCoProcessor> demCoProcessor; + SPtr<CreateDemObjectsCoProcessor> createDemObjectsCoProcessor; }; #endif diff --git a/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.cpp b/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.cpp index 30b25c0de..03b0c2783 100644 --- a/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.cpp +++ b/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.cpp @@ -1,74 +1,63 @@ #include "WriteDemObjectsCoProcessor.h" -#include "basics/writer/WbWriterVtkXmlBinary.h" #include "basics/writer/WbWriterVtkXmlASCII.h" +#include "basics/writer/WbWriterVtkXmlBinary.h" #include "Communicator.h" -#include "UbScheduler.h" +#include "DemCoProcessor.h" #include "Grid3D.h" +#include "UbScheduler.h" #include "UbSystem.h" -#include "DemCoProcessor.h" - -WriteDemObjectsCoProcessor::WriteDemObjectsCoProcessor() -{ -} +WriteDemObjectsCoProcessor::WriteDemObjectsCoProcessor() {} ////////////////////////////////////////////////////////////////////////// -WriteDemObjectsCoProcessor::WriteDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<DemCoProcessor> demCoProcessor, SPtr<Communicator> comm) - : CoProcessor(grid, s), - path(path), - writer(writer), - demCoProcessor(demCoProcessor), - comm(comm) +WriteDemObjectsCoProcessor::WriteDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<DemCoProcessor> demCoProcessor, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), writer(writer), demCoProcessor(demCoProcessor), comm(comm) { - } ////////////////////////////////////////////////////////////////////////// void WriteDemObjectsCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; - - int numObjcts = demCoProcessor->addSurfaceTriangleSet(nodes, triangles); - - int istep = static_cast<int>(step); - - std::string pfilePath, partPath, subfolder, cfilePath; - - subfolder = "dem"+UbSystem::toString(istep); - pfilePath = path+"/dem/"+subfolder; - cfilePath = path+"/dem/dem_collection"; - partPath = pfilePath+"/dem"+UbSystem::toString(comm->getProcessID())+ "_" + UbSystem::toString(istep); - - - std::string partName = writer->writeTriangles(partPath, nodes, triangles); - size_t found=partName.find_last_of("/"); - std::string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; - - std::vector<std::string> datanames; - std::vector<std::string> cellDataNames; - std::vector<std::string> pieces = comm->gather(piece); - if (comm->isRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); - - std::vector<std::string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); - } - UBLOG(logINFO, "WriteDemObjectsCoProcessor number of objects: " << numObjcts); - UBLOG(logINFO, "WriteDemObjectsCoProcessor step: " << istep); - } - } + if (scheduler->isDue(step)) { + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; + + int numObjcts = demCoProcessor->addSurfaceTriangleSet(nodes, triangles); + + int istep = static_cast<int>(step); + + std::string pfilePath, partPath, subfolder, cfilePath; + + subfolder = "dem" + UbSystem::toString(istep); + pfilePath = path + "/dem/" + subfolder; + cfilePath = path + "/dem/dem_collection"; + partPath = pfilePath + "/dem" + UbSystem::toString(comm->getProcessID()) + "_" + UbSystem::toString(istep); + + std::string partName = writer->writeTriangles(partPath, nodes, triangles); + size_t found = partName.find_last_of("/"); + std::string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + std::vector<std::string> datanames; + std::vector<std::string> cellDataNames; + std::vector<std::string> pieces = comm->gather(piece); + if (comm->isRoot()) { + std::string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); + + std::vector<std::string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "WriteDemObjectsCoProcessor number of objects: " << numObjcts); + UBLOG(logINFO, "WriteDemObjectsCoProcessor step: " << istep); + } + } } diff --git a/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.h b/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.h index 93d87bcf8..6c45b8632 100644 --- a/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.h +++ b/src/cpu/DemCoupling/WriteDemObjectsCoProcessor.h @@ -1,7 +1,7 @@ /* -* Author: K. Kutscher -* mail: kutscher@irmb.tu-bs.de -*/ + * Author: K. Kutscher + * mail: kutscher@irmb.tu-bs.de + */ #ifndef WriteDemObjectsCoProcessor_H #define WriteDemObjectsCoProcessor_H @@ -17,17 +17,18 @@ class UbScheduler; class DemCoProcessor; class WbWriter; -class WriteDemObjectsCoProcessor : public CoProcessor +class WriteDemObjectsCoProcessor : public CoProcessor { public: WriteDemObjectsCoProcessor(); - WriteDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<DemCoProcessor> demCoProcessor, SPtr<Communicator> comm); - ~WriteDemObjectsCoProcessor() {} - void process(double step) override; + WriteDemObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, WbWriter *const writer, + SPtr<DemCoProcessor> demCoProcessor, SPtr<Communicator> comm); + ~WriteDemObjectsCoProcessor() {} + void process(double step) override; private: std::string path; - WbWriter* writer; + WbWriter *writer; SPtr<Communicator> comm; SPtr<DemCoProcessor> demCoProcessor; }; diff --git a/src/cpu/DemCoupling/WritePeBlocksCoProcessor.cpp b/src/cpu/DemCoupling/WritePeBlocksCoProcessor.cpp index f46208ac9..693a23c5c 100644 --- a/src/cpu/DemCoupling/WritePeBlocksCoProcessor.cpp +++ b/src/cpu/DemCoupling/WritePeBlocksCoProcessor.cpp @@ -2,87 +2,77 @@ #include "basics/writer/WbWriterVtkXmlASCII.h" -#include "D3Q27System.h" #include "Block3D.h" -#include "UbScheduler.h" #include "Communicator.h" +#include "D3Q27System.h" #include "Grid3D.h" +#include "UbScheduler.h" -WritePeBlocksCoProcessor::WritePeBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm, SPtr<walberla::blockforest::BlockForest> forest) : - CoProcessor(grid, s), - path(path), - writer(writer), - comm(comm), - forest(forest) +WritePeBlocksCoProcessor::WritePeBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<Communicator> comm, + SPtr<walberla::blockforest::BlockForest> forest) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm), forest(forest) { - } -WritePeBlocksCoProcessor::~WritePeBlocksCoProcessor() -{ - -} +WritePeBlocksCoProcessor::~WritePeBlocksCoProcessor() {} void WritePeBlocksCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } void WritePeBlocksCoProcessor::collectData(double step) { - if (comm->getProcessID() == comm->getRoot()) - { - int istep = int(step); - std::vector<std::string> filenames; - std::vector< UbTupleFloat3 > nodes; - std::vector< UbTupleInt8 > cells; - std::vector<std::string> celldatanames; - - celldatanames.push_back("ID"); - celldatanames.push_back("rank"); - - walberla::uint_t rank = 0; - - - std::vector< std::vector< double > > celldata(celldatanames.size()); - - int nr=0; - - for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) - { - walberla::AABB aabb = blockIt->getAABB(); - - nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMin(), (float)aabb.zMin())); - nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMin(), (float)aabb.zMin())); - nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMax(), (float)aabb.zMin())); - nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMax(), (float)aabb.zMin())); - nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMin(), (float)aabb.zMax())); - nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMin(), (float)aabb.zMax())); - nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMax(), (float)aabb.zMax())); - nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMax(), (float)aabb.zMax())); - cells.push_back(makeUbTuple(nr, nr+1, nr+2, nr+3, nr+4, nr+5, nr+6, nr+7)); - nr += 8; - - //data - celldata[0].push_back((double)blockIt->getId().getID()); - forest->getProcessRank(rank,blockIt->getId()); - celldata[1].push_back((double)rank); - } - - filenames.push_back(writer->writeOctsWithCellData(path+"/peBlocks/peBlocks_" + UbSystem::toString(grid->getRank()) + "_" + UbSystem::toString(istep), nodes, cells, celldatanames, celldata)); - - if (istep == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"/peBlocks/peBlocks_collection", filenames, istep, false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "/peBlocks/peBlocks_collection", filenames, istep, false); - } - - UBLOG(logINFO, "WritePeBlocksCoProcessor step: " << istep); - - } - + if (comm->getProcessID() == comm->getRoot()) { + int istep = int(step); + std::vector<std::string> filenames; + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt8> cells; + std::vector<std::string> celldatanames; + + celldatanames.push_back("ID"); + celldatanames.push_back("rank"); + + walberla::uint_t rank = 0; + + std::vector<std::vector<double>> celldata(celldatanames.size()); + + int nr = 0; + + for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) { + walberla::AABB aabb = blockIt->getAABB(); + + nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMin(), (float)aabb.zMin())); + nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMin(), (float)aabb.zMin())); + nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMax(), (float)aabb.zMin())); + nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMax(), (float)aabb.zMin())); + nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMin(), (float)aabb.zMax())); + nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMin(), (float)aabb.zMax())); + nodes.push_back(makeUbTuple((float)aabb.xMax(), (float)aabb.yMax(), (float)aabb.zMax())); + nodes.push_back(makeUbTuple((float)aabb.xMin(), (float)aabb.yMax(), (float)aabb.zMax())); + cells.push_back(makeUbTuple(nr, nr + 1, nr + 2, nr + 3, nr + 4, nr + 5, nr + 6, nr + 7)); + nr += 8; + + // data + celldata[0].push_back((double)blockIt->getId().getID()); + forest->getProcessRank(rank, blockIt->getId()); + celldata[1].push_back((double)rank); + } + + filenames.push_back(writer->writeOctsWithCellData( + path + "/peBlocks/peBlocks_" + UbSystem::toString(grid->getRank()) + "_" + UbSystem::toString(istep), nodes, + cells, celldatanames, celldata)); + + if (istep == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(path + "/peBlocks/peBlocks_collection", filenames, + istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "/peBlocks/peBlocks_collection", filenames, + istep, false); + } + + UBLOG(logINFO, "WritePeBlocksCoProcessor step: " << istep); + } } \ No newline at end of file diff --git a/src/cpu/DemCoupling/WritePeBlocksCoProcessor.h b/src/cpu/DemCoupling/WritePeBlocksCoProcessor.h index 6d1022566..72334abd5 100644 --- a/src/cpu/DemCoupling/WritePeBlocksCoProcessor.h +++ b/src/cpu/DemCoupling/WritePeBlocksCoProcessor.h @@ -1,9 +1,9 @@ /* -* WritePeBlocksCoProcessor.h -* -* Created on: 07.09.2018 -* Author: K. Kutscher -*/ + * WritePeBlocksCoProcessor.h + * + * Created on: 07.09.2018 + * Author: K. Kutscher + */ #ifndef WritePeBlocksCoProcessor_H_ #define WritePeBlocksCoProcessor_H_ @@ -23,21 +23,19 @@ class WbWriter; class WritePeBlocksCoProcessor : public CoProcessor { public: - WritePeBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm, SPtr<walberla::blockforest::BlockForest> forest); - virtual ~WritePeBlocksCoProcessor(); + WritePeBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, WbWriter *const writer, + SPtr<Communicator> comm, SPtr<walberla::blockforest::BlockForest> forest); + virtual ~WritePeBlocksCoProcessor(); - void process(double step) override; + void process(double step) override; protected: - void collectData(double step); + void collectData(double step); - std::string path; - WbWriter* writer; - SPtr<Communicator> comm; - SPtr<walberla::blockforest::BlockForest> forest; + std::string path; + WbWriter *writer; + SPtr<Communicator> comm; + SPtr<walberla::blockforest::BlockForest> forest; }; - - -#endif - +#endif diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineGeometryAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineGeometryAdapter.h index a7eb5c6bc..490c1f979 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineGeometryAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineGeometryAdapter.h @@ -1,45 +1,40 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PHYSICS_ENGINE_GEOMETRY_ADAPTER_H #define PHYSICS_ENGINE_GEOMETRY_ADAPTER_H #include "Vector3D.h" -enum class State -{ - PIN, UNPIN -}; +enum class State { PIN, UNPIN }; class PhysicsEngineGeometryAdapter { public: virtual ~PhysicsEngineGeometryAdapter() {} - virtual void addForce(const Vector3D& force) = 0; - virtual void addTorque(const Vector3D& torque) = 0; + virtual void addForce(const Vector3D &force) = 0; + virtual void addTorque(const Vector3D &torque) = 0; - virtual void setForce(const Vector3D& force) = 0; - virtual void setTorque(const Vector3D& torque) = 0; + virtual void setForce(const Vector3D &force) = 0; + virtual void setTorque(const Vector3D &torque) = 0; - virtual void addForceAtPosition(const Vector3D& force, const Vector3D& position) = 0; - virtual void setLinearVelolocity(const Vector3D& velocity) = 0; - virtual void setAngularVelocity(const Vector3D& velocity) = 0; + virtual void addForceAtPosition(const Vector3D &force, const Vector3D &position) = 0; + virtual void setLinearVelolocity(const Vector3D &velocity) = 0; + virtual void setAngularVelocity(const Vector3D &velocity) = 0; virtual void resetForceAndTorque() = 0; - virtual Vector3D getPosition() const = 0; - virtual Vector3D getVelocityAtPosition(const Vector3D& position) const = 0; - virtual Vector3D getLinearVelocity() const = 0; - virtual Vector3D getAngularVelocity() const = 0; + virtual Vector3D getPosition() const = 0; + virtual Vector3D getVelocityAtPosition(const Vector3D &position) const = 0; + virtual Vector3D getLinearVelocity() const = 0; + virtual Vector3D getAngularVelocity() const = 0; - virtual Vector3D getForce() const = 0; + virtual Vector3D getForce() const = 0; virtual Vector3D getTorque() const = 0; virtual void changeState(State state) = 0; }; - #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineMaterialAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineMaterialAdapter.h index 1b887cda1..30504bee9 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineMaterialAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineMaterialAdapter.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PHYSICS_ENGINE_MATERIAL_ADAPTER_H #define PHYSICS_ENGINE_MATERIAL_ADAPTER_H @@ -10,16 +10,24 @@ class PhysicsEngineMaterialAdapter { public: - PhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, double dynamicFriction, double poissonRatio, double youngModul, double stiffnessInNormalDirection, double dampingoefficientNormalDirection, double dampingTangentialDirection) - : name(name), density(density), restitution(restitution), staticFriction(staticFriction), dynamicFriction(dynamicFriction), poissonRatio(poissonRatio), youngModul(youngModul), stiffnessInNormalDirection(stiffnessInNormalDirection), dampingoefficientNormalDirection(dampingoefficientNormalDirection), dampingTangentialDirection(dampingTangentialDirection) - {} + PhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, + double dynamicFriction, double poissonRatio, double youngModul, + double stiffnessInNormalDirection, double dampingoefficientNormalDirection, + double dampingTangentialDirection) + : name(name), density(density), restitution(restitution), staticFriction(staticFriction), + dynamicFriction(dynamicFriction), poissonRatio(poissonRatio), youngModul(youngModul), + stiffnessInNormalDirection(stiffnessInNormalDirection), + dampingoefficientNormalDirection(dampingoefficientNormalDirection), + dampingTangentialDirection(dampingTangentialDirection) + { + } virtual ~PhysicsEngineMaterialAdapter() {} protected: std::string name; double density; double restitution; - double staticFriction; // Note: pe doubles the input coefficient of friction for material-material contacts. + double staticFriction; // Note: pe doubles the input coefficient of friction for material-material contacts. double dynamicFriction; // Similar to static friction for low speed friction. double poissonRatio; double youngModul; @@ -28,6 +36,4 @@ protected: double dampingTangentialDirection; }; - #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h index bb035ab31..8e03bf1d6 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/PhysicsEngineSolverAdapter.h @@ -1,13 +1,12 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PHYSICS_ENGINE_SOLVER_ADAPTER_H #define PHYSICS_ENGINE_SOLVER_ADAPTER_H #include "Vector3D.h" - class PhysicsEngineGeometryAdapter; class PhysicsEngineMaterialAdapter; @@ -16,11 +15,10 @@ class PhysicsEngineSolverAdapter public: virtual ~PhysicsEngineSolverAdapter() {} - virtual std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const = 0; - virtual void runTimestep(double step) = 0; + virtual std::shared_ptr<PhysicsEngineGeometryAdapter> + createPhysicsEngineGeometryAdapter(int id, const Vector3D &position, double radius, + std::shared_ptr<PhysicsEngineMaterialAdapter> material) const = 0; + virtual void runTimestep(double step) = 0; }; - - #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.cpp index ababa676a..b18a57532 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.cpp @@ -1,79 +1,31 @@ #include "DummyPhysicsEngineGeometryAdapter.h" +void DummyPhysicsEngineGeometryAdapter::addForce(const Vector3D &force) {} +void DummyPhysicsEngineGeometryAdapter::addTorque(const Vector3D &torque) {} -void DummyPhysicsEngineGeometryAdapter::addForce(const Vector3D& force) -{ +void DummyPhysicsEngineGeometryAdapter::setForce(const Vector3D &force) {} -} +void DummyPhysicsEngineGeometryAdapter::setTorque(const Vector3D &torque) {} -void DummyPhysicsEngineGeometryAdapter::addTorque(const Vector3D& torque) -{ +void DummyPhysicsEngineGeometryAdapter::addForceAtPosition(const Vector3D &force, const Vector3D &position) {} -} +void DummyPhysicsEngineGeometryAdapter::setLinearVelolocity(const Vector3D &velocity) { this->velocity = velocity; } -void DummyPhysicsEngineGeometryAdapter::setForce(const Vector3D& force) -{ +void DummyPhysicsEngineGeometryAdapter::setAngularVelocity(const Vector3D &velocity) {} -} +void DummyPhysicsEngineGeometryAdapter::resetForceAndTorque() {} -void DummyPhysicsEngineGeometryAdapter::setTorque(const Vector3D& torque) -{ +Vector3D DummyPhysicsEngineGeometryAdapter::getVelocityAtPosition(const Vector3D &position) const { return velocity; } -} +Vector3D DummyPhysicsEngineGeometryAdapter::getLinearVelocity() const { return Vector3D(); } -void DummyPhysicsEngineGeometryAdapter::addForceAtPosition(const Vector3D& force, const Vector3D& position) -{ +Vector3D DummyPhysicsEngineGeometryAdapter::getAngularVelocity() const { return Vector3D(); } -} +Vector3D DummyPhysicsEngineGeometryAdapter::getPosition() const { return Vector3D(); } -void DummyPhysicsEngineGeometryAdapter::setLinearVelolocity(const Vector3D& velocity) -{ - this->velocity = velocity; -} +Vector3D DummyPhysicsEngineGeometryAdapter::getForce() const { return Vector3D(); } -void DummyPhysicsEngineGeometryAdapter::setAngularVelocity(const Vector3D& velocity) -{ - -} - -void DummyPhysicsEngineGeometryAdapter::resetForceAndTorque() -{ - -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getVelocityAtPosition(const Vector3D& position) const -{ - return velocity; -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getLinearVelocity() const -{ - return Vector3D(); -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getAngularVelocity() const -{ - return Vector3D(); -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getPosition() const -{ - return Vector3D(); -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getForce() const -{ - return Vector3D(); -} - -Vector3D DummyPhysicsEngineGeometryAdapter::getTorque() const -{ - return Vector3D(); -} - -void DummyPhysicsEngineGeometryAdapter::changeState(State state) -{ - -} +Vector3D DummyPhysicsEngineGeometryAdapter::getTorque() const { return Vector3D(); } +void DummyPhysicsEngineGeometryAdapter::changeState(State state) {} diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.h index 2f37f466b..70620d3c0 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineGeometryAdapter.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef DUMMY_PHYSICS_ENGINE_GEOMETRY_ADAPTER_H #define DUMMY_PHYSICS_ENGINE_GEOMETRY_ADAPTER_H @@ -9,27 +9,25 @@ #include "PhysicsEngineGeometryAdapter.h" - - class DummyPhysicsEngineGeometryAdapter : public PhysicsEngineGeometryAdapter { public: DummyPhysicsEngineGeometryAdapter() {} virtual ~DummyPhysicsEngineGeometryAdapter() {} - void addForce(const Vector3D& force) override; - void addTorque(const Vector3D& torque) override; + void addForce(const Vector3D &force) override; + void addTorque(const Vector3D &torque) override; - void setForce(const Vector3D& force) override; - void setTorque(const Vector3D& torque) override; + void setForce(const Vector3D &force) override; + void setTorque(const Vector3D &torque) override; - void addForceAtPosition(const Vector3D& force, const Vector3D& position) override; - void setLinearVelolocity(const Vector3D& velocity) override; - void setAngularVelocity(const Vector3D& velocity) override; + void addForceAtPosition(const Vector3D &force, const Vector3D &position) override; + void setLinearVelolocity(const Vector3D &velocity) override; + void setAngularVelocity(const Vector3D &velocity) override; void resetForceAndTorque() override; - Vector3D getVelocityAtPosition(const Vector3D& position) const override; + Vector3D getVelocityAtPosition(const Vector3D &position) const override; Vector3D getLinearVelocity() const override; Vector3D getAngularVelocity() const override; Vector3D getPosition() const override; @@ -37,9 +35,9 @@ public: Vector3D getTorque() const override; void changeState(State state) override; + private: Vector3D velocity; }; #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineMaterialAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineMaterialAdapter.h index c9b8a44a1..e84e0f108 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineMaterialAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineMaterialAdapter.h @@ -1,23 +1,25 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef DUMMY_PHYSICS_ENGINE_MATERIAL_ADAPTER #define DUMMY_PHYSICS_ENGINE_MATERIAL_ADAPTER #include "PhysicsEngineMaterialAdapter.h" - class DummyPhysicsEngineMaterialAdapter : public PhysicsEngineMaterialAdapter { public: - DummyPhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, double dynamicFriction, double poissonRatio, double youngModul, double stiffnessInNormalDirection, double dampingoefficientNormalDirection, double dampingTangentialDirection) - : PhysicsEngineMaterialAdapter(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, dampingTangentialDirection) + DummyPhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, + double dynamicFriction, double poissonRatio, double youngModul, + double stiffnessInNormalDirection, double dampingoefficientNormalDirection, + double dampingTangentialDirection) + : PhysicsEngineMaterialAdapter(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, + youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, + dampingTangentialDirection) { } virtual ~DummyPhysicsEngineMaterialAdapter() {} - }; #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.cpp index 8053942b9..321b523ea 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.cpp @@ -2,13 +2,11 @@ #include "DummyPhysicsEngineGeometryAdapter.h" - -std::shared_ptr<PhysicsEngineGeometryAdapter> DummyPhysicsEngineSolverAdapter::createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const +std::shared_ptr<PhysicsEngineGeometryAdapter> DummyPhysicsEngineSolverAdapter::createPhysicsEngineGeometryAdapter( + int id, const Vector3D &position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const { - return std::static_pointer_cast<PhysicsEngineGeometryAdapter>(std::make_shared<DummyPhysicsEngineGeometryAdapter>()); + return std::static_pointer_cast<PhysicsEngineGeometryAdapter>( + std::make_shared<DummyPhysicsEngineGeometryAdapter>()); } -void DummyPhysicsEngineSolverAdapter::runTimestep(double step) -{ - -} +void DummyPhysicsEngineSolverAdapter::runTimestep(double step) {} diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.h index 38975727e..38e9e7f05 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/dummy/DummyPhysicsEngineSolverAdapter.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef DUMMY_PHYSICS_ENGINE_SOLVER_ADAPTER_H #define DUMMY_PHYSICS_ENGINE_SOLVER_ADAPTER_H @@ -11,18 +11,16 @@ #include "PhysicsEngineSolverAdapter.h" - - class DummyPhysicsEngineSolverAdapter : public PhysicsEngineSolverAdapter { public: - DummyPhysicsEngineSolverAdapter() {}; + DummyPhysicsEngineSolverAdapter(){}; virtual ~DummyPhysicsEngineSolverAdapter() {} - std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const override; + std::shared_ptr<PhysicsEngineGeometryAdapter> + createPhysicsEngineGeometryAdapter(int id, const Vector3D &position, double radius, + std::shared_ptr<PhysicsEngineMaterialAdapter> material) const override; void runTimestep(double step) override; - }; #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapter.h index 6f0416685..0373281d6 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapter.h @@ -1,28 +1,19 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PE_ADAPTER_H #define PE_ADAPTER_H -#include <pe/basic.h> #include "Vector3D.h" - +#include <pe/basic.h> class PeConverter { -public: - static Vector3D convert(walberla::pe::Vec3 vec3) - { - return Vector3D(vec3[0], vec3[1], vec3[2]); - } +public: + static Vector3D convert(walberla::pe::Vec3 vec3) { return Vector3D(vec3[0], vec3[1], vec3[2]); } - static walberla::pe::Vec3 convert(const Vector3D& vec3) - { - return walberla::pe::Vec3(vec3[0], vec3[1], vec3[2]); - } + static walberla::pe::Vec3 convert(const Vector3D &vec3) { return walberla::pe::Vec3(vec3[0], vec3[1], vec3[2]); } }; - #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapterTest.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapterTest.cpp index 1deffe629..a92127c3f 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapterTest.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeAdapterTest.cpp @@ -6,7 +6,7 @@ //#include "UbTuple.h" // // -//TEST(PeAdapterTest, convert_WalberlaVec3_to_Vector3D) +// TEST(PeAdapterTest, convert_WalberlaVec3_to_Vector3D) //{ // walberla::pe::Vec3 walberlaVec(1.0, -2.0, 3.4); // Vector3D ubTuple = PeConverter::convert(walberlaVec); @@ -16,7 +16,7 @@ // EXPECT_THAT(ubTuple[2], testing::DoubleEq(walberlaVec[2])); //} // -//TEST(PeAdapterTest, convert_Vector3D_to_WalberlaVec3) +// TEST(PeAdapterTest, convert_Vector3D_to_WalberlaVec3) //{ // Vector3D ubTuple(1.0, -2.0, 3.4); // walberla::pe::Vec3 walberlaVec = PeConverter::convert(ubTuple); @@ -25,4 +25,3 @@ // EXPECT_THAT(ubTuple[1], testing::DoubleEq(walberlaVec[1])); // EXPECT_THAT(ubTuple[2], testing::DoubleEq(walberlaVec[2])); //} - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.cpp index 75d2c2850..6c597698d 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.cpp @@ -1,48 +1,47 @@ #include "PeLoadBalancerAdapter.h" -#include "Grid3D.h" #include "Block3D.h" #include "CoordinateTransformation3D.h" +#include "Grid3D.h" #include "UbLogger.h" #include "core/debug/CheckFunctions.h" - -PeLoadBalancerAdapter::PeLoadBalancerAdapter(SPtr<Grid3D> grid, unsigned numberOfProcesses, int rank) : grid(grid), numberOfProcesses(numberOfProcesses), rank(rank) +PeLoadBalancerAdapter::PeLoadBalancerAdapter(SPtr<Grid3D> grid, unsigned numberOfProcesses, int rank) + : grid(grid), numberOfProcesses(numberOfProcesses), rank(rank) { - } -walberla::uint_t PeLoadBalancerAdapter::operator()(walberla::SetupBlockForest & forest, const walberla::uint_t numberOfProcesses, const walberla::memory_t perProcessMemoryLimit) +walberla::uint_t PeLoadBalancerAdapter::operator()(walberla::SetupBlockForest &forest, + const walberla::uint_t numberOfProcesses, + const walberla::memory_t perProcessMemoryLimit) { - std::vector< walberla::SetupBlock * > peBlocks; - forest.getBlocks(peBlocks); - - for (auto peBlock = peBlocks.begin(); peBlock != peBlocks.end(); ++peBlock) - { - walberla::AABB aabb = (*peBlock)->getAABB(); - SPtr<Block3D> block = getBlockByMinUniform(aabb.xMin()+0.5*(aabb.xMax()-aabb.xMin()), aabb.yMin()+0.5*(aabb.yMax()-aabb.yMin()), aabb.zMin()+0.5*(aabb.zMax()-aabb.zMin()), grid); - if (block) - { - (*peBlock)->assignTargetProcess((walberla::uint_t)block->getRank()); - } - else - { - //TODO: the rank of pe blocks is not consistent with VF blocks - (*peBlock)->assignTargetProcess(0); - //UBLOG(logINFO, "PeLoadBalancerAdapter::operator() peBlockId="<<(*peBlock)->getId()); - } - } - - return numberOfProcesses; + std::vector<walberla::SetupBlock *> peBlocks; + forest.getBlocks(peBlocks); + + for (auto peBlock = peBlocks.begin(); peBlock != peBlocks.end(); ++peBlock) { + walberla::AABB aabb = (*peBlock)->getAABB(); + SPtr<Block3D> block = getBlockByMinUniform(aabb.xMin() + 0.5 * (aabb.xMax() - aabb.xMin()), + aabb.yMin() + 0.5 * (aabb.yMax() - aabb.yMin()), + aabb.zMin() + 0.5 * (aabb.zMax() - aabb.zMin()), grid); + if (block) { + (*peBlock)->assignTargetProcess((walberla::uint_t)block->getRank()); + } else { + // TODO: the rank of pe blocks is not consistent with VF blocks + (*peBlock)->assignTargetProcess(0); + // UBLOG(logINFO, "PeLoadBalancerAdapter::operator() peBlockId="<<(*peBlock)->getId()); + } + } + + return numberOfProcesses; } SPtr<Block3D> PeLoadBalancerAdapter::getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid) { - SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); + SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); - int ix1 = (int)trafo->transformForwardToX1Coordinate(minX1, minX2, minX3); - int ix2 = (int)trafo->transformForwardToX2Coordinate(minX1, minX2, minX3); - int ix3 = (int)trafo->transformForwardToX3Coordinate(minX1, minX2, minX3); + int ix1 = (int)trafo->transformForwardToX1Coordinate(minX1, minX2, minX3); + int ix2 = (int)trafo->transformForwardToX2Coordinate(minX1, minX2, minX3); + int ix3 = (int)trafo->transformForwardToX3Coordinate(minX1, minX2, minX3); - return grid->getBlock(ix1, ix2, ix3, 0); + return grid->getBlock(ix1, ix2, ix3, 0); } diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.h index 6b904d994..9e1c64dd3 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PeLoadBalancerAdapter.h @@ -1,8 +1,8 @@ #ifndef PeLoadBalancerAdapter_h__ #define PeLoadBalancerAdapter_h__ -#include "blockforest/SetupBlockForest.h" #include "PointerDefinitions.h" +#include "blockforest/SetupBlockForest.h" class Grid3D; class Block3D; @@ -10,16 +10,19 @@ class Block3D; class PeLoadBalancerAdapter { public: - PeLoadBalancerAdapter(SPtr<Grid3D> grid, unsigned numberOfProcesses, int rank); - walberla::uint_t operator()( walberla::SetupBlockForest & forest, const walberla::uint_t numberOfProcesses, const walberla::memory_t perProcessMemoryLimit ); - unsigned getNumberOfProcesses() const { return numberOfProcesses; } - int getRank() const { return rank; } + PeLoadBalancerAdapter(SPtr<Grid3D> grid, unsigned numberOfProcesses, int rank); + walberla::uint_t operator()(walberla::SetupBlockForest &forest, const walberla::uint_t numberOfProcesses, + const walberla::memory_t perProcessMemoryLimit); + unsigned getNumberOfProcesses() const { return numberOfProcesses; } + int getRank() const { return rank; } + protected: - SPtr<Block3D> getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid); + SPtr<Block3D> getBlockByMinUniform(double minX1, double minX2, double minX3, SPtr<Grid3D> grid); + private: - SPtr<Grid3D> grid; - unsigned numberOfProcesses; - int rank; + SPtr<Grid3D> grid; + unsigned numberOfProcesses; + int rank; }; #endif // PeLoadBalancerAdapter_h__ \ No newline at end of file diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.cpp index a044a6ea2..9800d75b1 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.cpp @@ -4,8 +4,8 @@ #include "PeAdapter.h" - -//PePhysicsEngineGeometryAdapter::PePhysicsEngineGeometryAdapter(walberla::pe::RigidBody* peGeoObject) : peGeoObject(peGeoObject) +// PePhysicsEngineGeometryAdapter::PePhysicsEngineGeometryAdapter(walberla::pe::RigidBody* peGeoObject) : +// peGeoObject(peGeoObject) //{ // this->id = peGeoObject->getID(); // this->active = true; @@ -13,119 +13,93 @@ PePhysicsEngineGeometryAdapter::PePhysicsEngineGeometryAdapter() { - this->id = -999; - this->systemID = -999; - this->active = false; - this->semiactive = false; - shadowCounter = 0; - counter = 0; + this->id = -999; + this->systemID = -999; + this->active = false; + this->semiactive = false; + shadowCounter = 0; + counter = 0; } -void PePhysicsEngineGeometryAdapter::addForce(const Vector3D& force) +void PePhysicsEngineGeometryAdapter::addForce(const Vector3D &force) { - peGeoObject->addForce(PeConverter::convert(force)); + peGeoObject->addForce(PeConverter::convert(force)); } -void PePhysicsEngineGeometryAdapter::addTorque(const Vector3D& torque) +void PePhysicsEngineGeometryAdapter::addTorque(const Vector3D &torque) { - peGeoObject->addTorque(PeConverter::convert(torque)); + peGeoObject->addTorque(PeConverter::convert(torque)); } -void PePhysicsEngineGeometryAdapter::setForce(const Vector3D& force) +void PePhysicsEngineGeometryAdapter::setForce(const Vector3D &force) { - peGeoObject->setForce(PeConverter::convert(force)); + peGeoObject->setForce(PeConverter::convert(force)); } -void PePhysicsEngineGeometryAdapter::setTorque(const Vector3D& torque) +void PePhysicsEngineGeometryAdapter::setTorque(const Vector3D &torque) { - peGeoObject->setTorque(PeConverter::convert(torque)); + peGeoObject->setTorque(PeConverter::convert(torque)); } -void PePhysicsEngineGeometryAdapter::addForceAtPosition(const Vector3D& force, const Vector3D& position) +void PePhysicsEngineGeometryAdapter::addForceAtPosition(const Vector3D &force, const Vector3D &position) { - peGeoObject->addForceAtPos(PeConverter::convert(force), PeConverter::convert(position)); + peGeoObject->addForceAtPos(PeConverter::convert(force), PeConverter::convert(position)); } -void PePhysicsEngineGeometryAdapter::setLinearVelolocity(const Vector3D& velocity) +void PePhysicsEngineGeometryAdapter::setLinearVelolocity(const Vector3D &velocity) { - peGeoObject->setLinearVel(PeConverter::convert(velocity)); + peGeoObject->setLinearVel(PeConverter::convert(velocity)); } -void PePhysicsEngineGeometryAdapter::setAngularVelocity(const Vector3D& velocity) +void PePhysicsEngineGeometryAdapter::setAngularVelocity(const Vector3D &velocity) { - peGeoObject->setAngularVel(PeConverter::convert(velocity)); + peGeoObject->setAngularVel(PeConverter::convert(velocity)); } -void PePhysicsEngineGeometryAdapter::resetForceAndTorque() -{ - peGeoObject->resetForceAndTorque(); -} +void PePhysicsEngineGeometryAdapter::resetForceAndTorque() { peGeoObject->resetForceAndTorque(); } -Vector3D PePhysicsEngineGeometryAdapter::getVelocityAtPosition(const Vector3D& position) const +Vector3D PePhysicsEngineGeometryAdapter::getVelocityAtPosition(const Vector3D &position) const { - return PeConverter::convert(peGeoObject->velFromWF(PeConverter::convert(position))); + return PeConverter::convert(peGeoObject->velFromWF(PeConverter::convert(position))); } Vector3D PePhysicsEngineGeometryAdapter::getLinearVelocity() const { - return PeConverter::convert(peGeoObject->getLinearVel()); + return PeConverter::convert(peGeoObject->getLinearVel()); } Vector3D PePhysicsEngineGeometryAdapter::getAngularVelocity() const { - return PeConverter::convert(peGeoObject->getAngularVel()); + return PeConverter::convert(peGeoObject->getAngularVel()); } Vector3D PePhysicsEngineGeometryAdapter::getPosition() const { - return PeConverter::convert(peGeoObject->getPosition()); + return PeConverter::convert(peGeoObject->getPosition()); } -Vector3D PePhysicsEngineGeometryAdapter::getForce() const -{ - return PeConverter::convert(peGeoObject->getForce()); -} +Vector3D PePhysicsEngineGeometryAdapter::getForce() const { return PeConverter::convert(peGeoObject->getForce()); } -Vector3D PePhysicsEngineGeometryAdapter::getTorque() const -{ - return PeConverter::convert(peGeoObject->getTorque()); -} +Vector3D PePhysicsEngineGeometryAdapter::getTorque() const { return PeConverter::convert(peGeoObject->getTorque()); } void PePhysicsEngineGeometryAdapter::changeState(State state) { - if (state == State::PIN) - peGeoObject->setMassAndInertiaToInfinity(); + if (state == State::PIN) + peGeoObject->setMassAndInertiaToInfinity(); } -int PePhysicsEngineGeometryAdapter::getId() const -{ - return id; -} +int PePhysicsEngineGeometryAdapter::getId() const { return id; } -void PePhysicsEngineGeometryAdapter::setId(int id) -{ - this->id = id; -} +void PePhysicsEngineGeometryAdapter::setId(int id) { this->id = id; } -void PePhysicsEngineGeometryAdapter::setGeometry(walberla::pe::RigidBody* peGeoObject) +void PePhysicsEngineGeometryAdapter::setGeometry(walberla::pe::RigidBody *peGeoObject) { - this->peGeoObject = peGeoObject; + this->peGeoObject = peGeoObject; } ////////////////////////////////////////////////////////////////////////// -void PePhysicsEngineGeometryAdapter::setActive() -{ - active = true; -} +void PePhysicsEngineGeometryAdapter::setActive() { active = true; } ////////////////////////////////////////////////////////////////////////// -void PePhysicsEngineGeometryAdapter::setInactive() -{ - active = false; -} +void PePhysicsEngineGeometryAdapter::setInactive() { active = false; } ////////////////////////////////////////////////////////////////////////// -bool PePhysicsEngineGeometryAdapter::isActive() -{ - - - return active; -} +bool PePhysicsEngineGeometryAdapter::isActive() { return active; } diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h index 13c830a41..a8eaa7d33 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineGeometryAdapter.h @@ -1,42 +1,41 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PE_PHYSICS_ENGINE_GEOMETRY_ADAPTER_H #define PE_PHYSICS_ENGINE_GEOMETRY_ADAPTER_H - #include "PhysicsEngineGeometryAdapter.h" #include <core/DataTypes.h> namespace walberla { - namespace pe - { - class RigidBody; - } +namespace pe +{ +class RigidBody; } +} // namespace walberla class PePhysicsEngineGeometryAdapter : public PhysicsEngineGeometryAdapter { public: PePhysicsEngineGeometryAdapter(); - //PePhysicsEngineGeometryAdapter(walberla::pe::RigidBody* peGeoObject); + // PePhysicsEngineGeometryAdapter(walberla::pe::RigidBody* peGeoObject); virtual ~PePhysicsEngineGeometryAdapter() {} - void addForce(const Vector3D& force) override; - void addTorque(const Vector3D& torque) override; + void addForce(const Vector3D &force) override; + void addTorque(const Vector3D &torque) override; - void setForce(const Vector3D& force) override; - void setTorque(const Vector3D& torque) override; + void setForce(const Vector3D &force) override; + void setTorque(const Vector3D &torque) override; - void addForceAtPosition(const Vector3D& force, const Vector3D& position) override; - void setLinearVelolocity(const Vector3D& velocity) override; - void setAngularVelocity(const Vector3D& velocity) override; + void addForceAtPosition(const Vector3D &force, const Vector3D &position) override; + void setLinearVelolocity(const Vector3D &velocity) override; + void setAngularVelocity(const Vector3D &velocity) override; void resetForceAndTorque() override; - Vector3D getVelocityAtPosition(const Vector3D& position) const override; + Vector3D getVelocityAtPosition(const Vector3D &position) const override; Vector3D getLinearVelocity() const override; Vector3D getAngularVelocity() const override; Vector3D getPosition() const override; @@ -47,13 +46,13 @@ public: int getId() const; void setId(int id); - void setGeometry(walberla::pe::RigidBody* peGeoObject); + void setGeometry(walberla::pe::RigidBody *peGeoObject); void setActive(); void setInactive(); bool isActive(); - //void increaseShadowCounter(); - //void decreaseShad + // void increaseShadowCounter(); + // void decreaseShad int shadowCounter; int counter; @@ -61,15 +60,15 @@ public: void setSystemID(unsigned long long val) { systemID = val; } bool getSemiactive() const { return semiactive; } void setSemiactive(bool val) { semiactive = val; } + private: - walberla::pe::RigidBody* peGeoObject; - //unsigned long long id; + walberla::pe::RigidBody *peGeoObject; + // unsigned long long id; int id; - //walberla::id_t systemId; + // walberla::id_t systemId; unsigned long long systemID; bool active; bool semiactive; }; #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.cpp index fcd4e6eee..6a36fa1a3 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.cpp @@ -1,10 +1,11 @@ #include "PePhysicsEngineMaterialAdapter.h" - walberla::pe::MaterialID PePhysicsEngineMaterialAdapter::getPeMaterial() const { if (walberla::pe::Material::find(name) != -1) return walberla::pe::Material::find(name); - return walberla::pe::createMaterial(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, dampingTangentialDirection); + return walberla::pe::createMaterial(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, + youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, + dampingTangentialDirection); } diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.h index b99afaa38..6ebfa8d1d 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineMaterialAdapter.h @@ -1,26 +1,28 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PE_PHYSICS_ENGINE_MATERIAL_ADAPTER #define PE_PHYSICS_ENGINE_MATERIAL_ADAPTER #include "../PhysicsEngineMaterialAdapter.h" #include <pe/basic.h> - class PePhysicsEngineMaterialAdapter : public PhysicsEngineMaterialAdapter { public: - PePhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, double dynamicFriction, double poissonRatio, double youngModul, double stiffnessInNormalDirection, double dampingoefficientNormalDirection, double dampingTangentialDirection) - : PhysicsEngineMaterialAdapter(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, dampingTangentialDirection) + PePhysicsEngineMaterialAdapter(std::string name, double density, double restitution, double staticFriction, + double dynamicFriction, double poissonRatio, double youngModul, + double stiffnessInNormalDirection, double dampingoefficientNormalDirection, + double dampingTangentialDirection) + : PhysicsEngineMaterialAdapter(name, density, restitution, staticFriction, dynamicFriction, poissonRatio, + youngModul, stiffnessInNormalDirection, dampingoefficientNormalDirection, + dampingTangentialDirection) { } virtual ~PePhysicsEngineMaterialAdapter() {} virtual walberla::pe::MaterialID getPeMaterial() const; - }; #endif - diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp index 9aa16a081..dd78dc143 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.cpp @@ -2,21 +2,21 @@ #include <exception> -#include <pe/basic.h> -#include <pe/rigidbody/UnionFactory.h> #include "pe/rigidbody/BoxFactory.h" -#include "pe/rigidbody/SphereFactory.h" #include "pe/rigidbody/PlaneFactory.h" +#include "pe/rigidbody/SphereFactory.h" +#include <pe/basic.h> +#include <pe/rigidbody/UnionFactory.h> //#include "geometry/GeometricalFunctions.h" +#include "Communicator.h" #include "PeAdapter.h" +#include "PeLoadBalancerAdapter.h" #include "PePhysicsEngineGeometryAdapter.h" #include "PePhysicsEngineMaterialAdapter.h" -#include "PeLoadBalancerAdapter.h" -#include "Communicator.h" -#include "UbLogger.h" -#include <boost/tuple/tuple.hpp> #include "UbException.h" +#include "UbLogger.h" #include "UbSystem.h" +#include <boost/tuple/tuple.hpp> #include <memory> using namespace walberla; @@ -24,7 +24,9 @@ using namespace walberla::pe; typedef boost::tuple<walberla::pe::Box, walberla::pe::Sphere, walberla::pe::Plane> BodyTypeTuple; -PePhysicsEngineSolverAdapter::PePhysicsEngineSolverAdapter(std::shared_ptr<PeParameter> peParameter, std::shared_ptr<PeLoadBalancerAdapter> loadBalancer) : peParameter(peParameter), loadBalancer(loadBalancer) +PePhysicsEngineSolverAdapter::PePhysicsEngineSolverAdapter(std::shared_ptr<PeParameter> peParameter, + std::shared_ptr<PeLoadBalancerAdapter> loadBalancer) + : peParameter(peParameter), loadBalancer(loadBalancer) { this->initalizePeEnvironment(); } @@ -39,29 +41,28 @@ void PePhysicsEngineSolverAdapter::initalizePeEnvironment() this->initialPeChannel(); } - -std::shared_ptr<PhysicsEngineGeometryAdapter> PePhysicsEngineSolverAdapter::createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const +std::shared_ptr<PhysicsEngineGeometryAdapter> PePhysicsEngineSolverAdapter::createPhysicsEngineGeometryAdapter( + int id, const Vector3D &position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const { - const std::shared_ptr<PePhysicsEngineMaterialAdapter> peMaterial = std::dynamic_pointer_cast<PePhysicsEngineMaterialAdapter>(material); + const std::shared_ptr<PePhysicsEngineMaterialAdapter> peMaterial = + std::dynamic_pointer_cast<PePhysicsEngineMaterialAdapter>(material); std::shared_ptr<PePhysicsEngineGeometryAdapter> peGeometryAdapter(new PePhysicsEngineGeometryAdapter()); - //UBLOG(logINFO, "PePhysicsEngineSolverAdapter::createSphere():start"); - walberla::pe::GeomID peGeometry = createSphere(*globalBodyStorage, *forest, *storageId, id, PeConverter::convert(position), radius, peMaterial->getPeMaterial()); - //UBLOG(logINFO, "PePhysicsEngineSolverAdapter::createSphere():end"); - - if (peGeometry) - { - peGeometryAdapter->setId(id); - peGeometryAdapter->setSystemID(peGeometry->getSystemID()); - peGeometryAdapter->setActive(); - peGeometryAdapter->setGeometry(peGeometry); - return peGeometryAdapter; - } - else - { - peGeometryAdapter->setId(id); - peGeometryAdapter->setInactive(); - return peGeometryAdapter; + // UBLOG(logINFO, "PePhysicsEngineSolverAdapter::createSphere():start"); + walberla::pe::GeomID peGeometry = createSphere(*globalBodyStorage, *forest, *storageId, id, + PeConverter::convert(position), radius, peMaterial->getPeMaterial()); + // UBLOG(logINFO, "PePhysicsEngineSolverAdapter::createSphere():end"); + + if (peGeometry) { + peGeometryAdapter->setId(id); + peGeometryAdapter->setSystemID(peGeometry->getSystemID()); + peGeometryAdapter->setActive(); + peGeometryAdapter->setGeometry(peGeometry); + return peGeometryAdapter; + } else { + peGeometryAdapter->setId(id); + peGeometryAdapter->setInactive(); + return peGeometryAdapter; } walberla::pe::syncNextNeighbors<BodyTypeTuple>(*forest, *storageId); @@ -73,8 +74,6 @@ void PePhysicsEngineSolverAdapter::runTimestep(double step) walberla::pe::syncNextNeighbors<BodyTypeTuple>(*forest, *storageId); } - - void PePhysicsEngineSolverAdapter::initialPeBodyStorage() { globalBodyStorage = std::make_shared<walberla::pe::BodyStorage>(); @@ -83,48 +82,57 @@ void PePhysicsEngineSolverAdapter::initialPeBodyStorage() void PePhysicsEngineSolverAdapter::initialPeBlockForest() { - //walberla::SetupBlockForest sforest = walberla::blockforest::createUniformBlockGrid(walberla::AABB(peParameter->simulationDomain[0], peParameter->simulationDomain[1], peParameter->simulationDomain[2], - // peParameter->simulationDomain[3], peParameter->simulationDomain[4], peParameter->simulationDomain[5]), // simulationDomain - // walberla::uint_t(val<1>(peParameter->numberOfBlocks)), walberla::uint_t(val<2>(peParameter->numberOfBlocks)), walberla::uint_t(val<3>(peParameter->numberOfBlocks)),walberla::uint_t(10),walberla::uint_t(10),walberla::uint_t(10), 5.0,false); + // walberla::SetupBlockForest sforest = + // walberla::blockforest::createUniformBlockGrid(walberla::AABB(peParameter->simulationDomain[0], + // peParameter->simulationDomain[1], peParameter->simulationDomain[2], + // peParameter->simulationDomain[3], peParameter->simulationDomain[4], peParameter->simulationDomain[5]), // + // simulationDomain walberla::uint_t(val<1>(peParameter->numberOfBlocks)), + // walberla::uint_t(val<2>(peParameter->numberOfBlocks)), + // walberla::uint_t(val<3>(peParameter->numberOfBlocks)),walberla::uint_t(10),walberla::uint_t(10),walberla::uint_t(10), + // 5.0,false); walberla::SetupBlockForest sforest; - //sforest.addWorkloadMemorySUIDAssignmentFunction( uniformWorkloadAndMemoryAssignment ); - sforest.init(walberla::AABB(peParameter->simulationDomain[0], peParameter->simulationDomain[1], peParameter->simulationDomain[2], - peParameter->simulationDomain[3], peParameter->simulationDomain[4], peParameter->simulationDomain[5]), // simulationDomain - walberla::uint_t(val<1>(peParameter->numberOfBlocks)), walberla::uint_t(val<2>(peParameter->numberOfBlocks)), walberla::uint_t(val<3>(peParameter->numberOfBlocks)), // blocks in each direction - val<1>(peParameter->isPeriodic), val<2>(peParameter->isPeriodic), val<3>(peParameter->isPeriodic)); + // sforest.addWorkloadMemorySUIDAssignmentFunction( uniformWorkloadAndMemoryAssignment ); + sforest.init(walberla::AABB(peParameter->simulationDomain[0], peParameter->simulationDomain[1], + peParameter->simulationDomain[2], peParameter->simulationDomain[3], + peParameter->simulationDomain[4], peParameter->simulationDomain[5]), // simulationDomain + walberla::uint_t(val<1>(peParameter->numberOfBlocks)), + walberla::uint_t(val<2>(peParameter->numberOfBlocks)), + walberla::uint_t(val<3>(peParameter->numberOfBlocks)), // blocks in each direction + val<1>(peParameter->isPeriodic), val<2>(peParameter->isPeriodic), val<3>(peParameter->isPeriodic)); sforest.balanceLoad(*loadBalancer.get(), loadBalancer->getNumberOfProcesses()); - forest = std::shared_ptr< walberla::blockforest::BlockForest >( new walberla::blockforest::BlockForest( walberla::uint_c( loadBalancer->getRank() ), sforest) ); + forest = std::shared_ptr<walberla::blockforest::BlockForest>( + new walberla::blockforest::BlockForest(walberla::uint_c(loadBalancer->getRank()), sforest)); - auto mpiManager = walberla::MPIManager::instance(); - mpiManager->useWorldComm(); + auto mpiManager = walberla::MPIManager::instance(); + mpiManager->useWorldComm(); if (!forest) - throw std::runtime_error("No PE BlockForest created ... "); + throw std::runtime_error("No PE BlockForest created ... "); } void PePhysicsEngineSolverAdapter::initalBlockData() { - storageId = std::make_shared<walberla::domain_decomposition::BlockDataID> - ( - forest->addBlockData(walberla::pe::createStorageDataHandling<BodyTypeTuple>(), "Storage") - ); + storageId = std::make_shared<walberla::domain_decomposition::BlockDataID>( + forest->addBlockData(walberla::pe::createStorageDataHandling<BodyTypeTuple>(), "Storage")); } void PePhysicsEngineSolverAdapter::initalPeIntegrator() { - auto ccdID = forest->addBlockData(walberla::pe::ccd::createHashGridsDataHandling(globalBodyStorage, *storageId), "CCD"); - auto fcdID = forest->addBlockData(walberla::pe::fcd::createGenericFCDDataHandling<BodyTypeTuple, walberla::pe::fcd::AnalyticCollideFunctor>(), "FCD"); + auto ccdID = + forest->addBlockData(walberla::pe::ccd::createHashGridsDataHandling(globalBodyStorage, *storageId), "CCD"); + auto fcdID = forest->addBlockData( + walberla::pe::fcd::createGenericFCDDataHandling<BodyTypeTuple, walberla::pe::fcd::AnalyticCollideFunctor>(), + "FCD"); - cr = std::make_shared<walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers>(globalBodyStorage, forest, *storageId, ccdID, fcdID); + cr = std::make_shared<walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers>(globalBodyStorage, forest, + *storageId, ccdID, fcdID); cr->setMaxIterations(peParameter->maxPeIterations); - cr->setRelaxationModel(walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers::ApproximateInelasticCoulombContactByDecoupling); + cr->setRelaxationModel( + walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers::ApproximateInelasticCoulombContactByDecoupling); cr->setRelaxationParameter(walberla::real_t(peParameter->relaxationParameter)); cr->setGlobalLinearAcceleration(PeConverter::convert(peParameter->globalLinearAcceleration)); } -void PePhysicsEngineSolverAdapter::executePeBodyTypeTuple() -{ - walberla::pe::SetBodyTypeIDs<BodyTypeTuple>::execute(); -} +void PePhysicsEngineSolverAdapter::executePeBodyTypeTuple() { walberla::pe::SetBodyTypeIDs<BodyTypeTuple>::execute(); } void PePhysicsEngineSolverAdapter::initialPeChannel() const { @@ -132,94 +140,96 @@ void PePhysicsEngineSolverAdapter::initialPeChannel() const auto simulationDomain = forest->getDomain(); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(1, 0, 0), simulationDomain.minCorner(), material); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(-1, 0, 0), simulationDomain.maxCorner(), material); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 1, 0), simulationDomain.minCorner(), material); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, -1, 0), simulationDomain.maxCorner(), material); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, 1), simulationDomain.minCorner(), material); - //createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, -1), simulationDomain.maxCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(1, 0, 0), simulationDomain.minCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(-1, 0, 0), simulationDomain.maxCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 1, 0), simulationDomain.minCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, -1, 0), simulationDomain.maxCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, 1), simulationDomain.minCorner(), material); + // createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, -1), simulationDomain.maxCorner(), material); Vector3D minOffset = peParameter->minOffset; Vector3D maxOffset = peParameter->maxOffset; - walberla::pe::Vec3 minX1_Offset( minOffset.X1(), 0, 0); - walberla::pe::Vec3 maxX1_Offset( maxOffset.X1(), 0, 0); - walberla::pe::Vec3 minX2_Offset( 0, minOffset.X2(), 0); - walberla::pe::Vec3 maxX2_Offset( 0, maxOffset.X2(), 0); - walberla::pe::Vec3 minX3_Offset( 0, 0, minOffset.X3()); - walberla::pe::Vec3 maxX3_Offset( 0, 0, maxOffset.X3()); + walberla::pe::Vec3 minX1_Offset(minOffset.X1(), 0, 0); + walberla::pe::Vec3 maxX1_Offset(maxOffset.X1(), 0, 0); + walberla::pe::Vec3 minX2_Offset(0, minOffset.X2(), 0); + walberla::pe::Vec3 maxX2_Offset(0, maxOffset.X2(), 0); + walberla::pe::Vec3 minX3_Offset(0, 0, minOffset.X3()); + walberla::pe::Vec3 maxX3_Offset(0, 0, maxOffset.X3()); walberla::pe::Vec3 minCorner = simulationDomain.minCorner(); walberla::pe::Vec3 maxCorner = simulationDomain.maxCorner(); - createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 1, 0, 0), minCorner + minX1_Offset, material); + createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(1, 0, 0), minCorner + minX1_Offset, material); createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(-1, 0, 0), maxCorner + maxX1_Offset, material); - createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 0, 1, 0), minCorner + minX2_Offset, material); - createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 0,-1, 0), maxCorner + maxX2_Offset, material); - createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 0, 0, 1), minCorner + minX3_Offset, material); - createPlane(*globalBodyStorage, 0, walberla::pe::Vec3( 0, 0,-1), maxCorner + maxX3_Offset, material); + createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 1, 0), minCorner + minX2_Offset, material); + createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, -1, 0), maxCorner + maxX2_Offset, material); + createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, 1), minCorner + minX3_Offset, material); + createPlane(*globalBodyStorage, 0, walberla::pe::Vec3(0, 0, -1), maxCorner + maxX3_Offset, material); } -std::shared_ptr< walberla::blockforest::BlockForest > PePhysicsEngineSolverAdapter::getForest() -{ - return forest; -} +std::shared_ptr<walberla::blockforest::BlockForest> PePhysicsEngineSolverAdapter::getForest() { return forest; } -void PePhysicsEngineSolverAdapter::saveToFile(const std::string & path) +void PePhysicsEngineSolverAdapter::saveToFile(const std::string &path) { - forest->saveToFile(path+"SerializeDeserialize.sbf"); - forest->saveBlockData("SerializeDeserialize.dump", *storageId.get()); + forest->saveToFile(path + "SerializeDeserialize.sbf"); + forest->saveBlockData("SerializeDeserialize.dump", *storageId.get()); } -void PePhysicsEngineSolverAdapter::loadFromFile(const std::string & path) +void PePhysicsEngineSolverAdapter::loadFromFile(const std::string &path) { - //forest = std::make_shared< walberla::blockforest::BlockForest >( walberla::uint_c( walberla::MPIManager::instance()->rank() ), path+"SerializeDeserialize.sbf", true, false ); - std::string file = path+"SerializeDeserialize.sbf"; - forest = std::shared_ptr < walberla::blockforest::BlockForest > (new walberla::blockforest::BlockForest( walberla::uint_c( walberla::MPIManager::instance()->rank() ), file.c_str(), true, false )); - storageId = std::make_shared< walberla::domain_decomposition::BlockDataID >(forest->loadBlockData(path+"SerializeDeserialize.dump", walberla::pe::createStorageDataHandling<BodyTypeTuple>(), "Storage")); - - this->initalPeIntegrator(); - - auto ccdID = forest->addBlockData(walberla::pe::ccd::createHashGridsDataHandling(globalBodyStorage, *storageId), "CCD"); - auto fcdID = forest->addBlockData(walberla::pe::fcd::createGenericFCDDataHandling<BodyTypeTuple, walberla::pe::fcd::AnalyticCollideFunctor>(), "FCD"); - - cr = std::make_shared<walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers>(globalBodyStorage, forest, *storageId, ccdID, fcdID); - cr->setMaxIterations(peParameter->maxPeIterations); - cr->setRelaxationModel(walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers::ApproximateInelasticCoulombContactByDecoupling); - cr->setRelaxationParameter(walberla::real_t(peParameter->relaxationParameter)); - cr->setGlobalLinearAcceleration(PeConverter::convert(peParameter->globalLinearAcceleration)); - - this->executePeBodyTypeTuple(); - this->initialPeChannel(); - - for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) - { - walberla::pe::ccd::ICCD* ccd = blockIt->getData< walberla::pe::ccd::ICCD >(ccdID); - ccd->reloadBodies(); - } -} + // forest = std::make_shared< walberla::blockforest::BlockForest >( walberla::uint_c( + // walberla::MPIManager::instance()->rank() ), path+"SerializeDeserialize.sbf", true, false ); + std::string file = path + "SerializeDeserialize.sbf"; + forest = std::shared_ptr<walberla::blockforest::BlockForest>(new walberla::blockforest::BlockForest( + walberla::uint_c(walberla::MPIManager::instance()->rank()), file.c_str(), true, false)); + storageId = std::make_shared<walberla::domain_decomposition::BlockDataID>(forest->loadBlockData( + path + "SerializeDeserialize.dump", walberla::pe::createStorageDataHandling<BodyTypeTuple>(), "Storage")); -std::shared_ptr<walberla::blockforest::BlockForest> PePhysicsEngineSolverAdapter::getBlockForest() -{ - return forest; + this->initalPeIntegrator(); + + auto ccdID = + forest->addBlockData(walberla::pe::ccd::createHashGridsDataHandling(globalBodyStorage, *storageId), "CCD"); + auto fcdID = forest->addBlockData( + walberla::pe::fcd::createGenericFCDDataHandling<BodyTypeTuple, walberla::pe::fcd::AnalyticCollideFunctor>(), + "FCD"); + + cr = std::make_shared<walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers>(globalBodyStorage, forest, + *storageId, ccdID, fcdID); + cr->setMaxIterations(peParameter->maxPeIterations); + cr->setRelaxationModel( + walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers::ApproximateInelasticCoulombContactByDecoupling); + cr->setRelaxationParameter(walberla::real_t(peParameter->relaxationParameter)); + cr->setGlobalLinearAcceleration(PeConverter::convert(peParameter->globalLinearAcceleration)); + + this->executePeBodyTypeTuple(); + this->initialPeChannel(); + + for (auto blockIt = forest->begin(); blockIt != forest->end(); ++blockIt) { + walberla::pe::ccd::ICCD *ccd = blockIt->getData<walberla::pe::ccd::ICCD>(ccdID); + ccd->reloadBodies(); + } } +std::shared_ptr<walberla::blockforest::BlockForest> PePhysicsEngineSolverAdapter::getBlockForest() { return forest; } + std::shared_ptr<walberla::domain_decomposition::BlockDataID> PePhysicsEngineSolverAdapter::getStorageId() { - return storageId; + return storageId; } std::shared_ptr<walberla::pe::BodyStorage> PePhysicsEngineSolverAdapter::getGlobalBodyStorage() { - return globalBodyStorage; + return globalBodyStorage; } -void PePhysicsEngineSolverAdapter::createObstacle(const Vector3D & center, const Vector3D & lengths) +void PePhysicsEngineSolverAdapter::createObstacle(const Vector3D ¢er, const Vector3D &lengths) { - const walberla::pe::MaterialID material = peParameter->planes->getPeMaterial(); - bool global = true; - bool communicating = false; - bool infiniteMass = true; + const walberla::pe::MaterialID material = peParameter->planes->getPeMaterial(); + bool global = true; + bool communicating = false; + bool infiniteMass = true; - walberla::pe::createBox(*globalBodyStorage, *forest, *storageId, 0, PeConverter::convert(center), PeConverter::convert(lengths), material, global, communicating, infiniteMass); + walberla::pe::createBox(*globalBodyStorage, *forest, *storageId, 0, PeConverter::convert(center), + PeConverter::convert(lengths), material, global, communicating, infiniteMass); } diff --git a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h index b1274ce3a..5b2ef94b8 100644 --- a/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h +++ b/src/cpu/DemCoupling/physicsEngineAdapter/pe/PePhysicsEngineSolverAdapter.h @@ -1,19 +1,18 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef PE_PHYSICS_ENGINE_SOLVER_ADAPTER_H #define PE_PHYSICS_ENGINE_SOLVER_ADAPTER_H #include <memory> #include <shared_mutex> -#include <pe/basic.h> #include "UbTuple.h" +#include <pe/basic.h> -#include "PhysicsEngineSolverAdapter.h" #include "PePhysicsEngineSolverAdapter.h" - +#include "PhysicsEngineSolverAdapter.h" class PePhysicsEngineMaterialAdapter; class PhysicsEngineGeometryAdapter; @@ -22,29 +21,33 @@ class PeLoadBalancerAdapter; namespace walberla { - namespace domain_decomposition - { - class BlockDataID; - } - namespace blockforest - { - class BlockForest; - } - namespace pe - { - class BodyStorage; - class RigidBody; - namespace cr - { - class HardContactSemiImplicitTimesteppingSolvers; - } - } +namespace domain_decomposition +{ +class BlockDataID; } - -struct PeParameter +namespace blockforest +{ +class BlockForest; +} +namespace pe { - PeParameter(double relaxationParameter, int maxPeIterations, Vector3D globalLinearAcceleration, std::shared_ptr<PePhysicsEngineMaterialAdapter> planes, std::array<double, 6> simulationDomain, UbTupleInt3 numberOfBlocks, UbTupleBool3 isPeriodic, Vector3D minOffset, Vector3D maxOffset) - : relaxationParameter(relaxationParameter), maxPeIterations(maxPeIterations), globalLinearAcceleration(globalLinearAcceleration), simulationDomain(simulationDomain), numberOfBlocks(numberOfBlocks), isPeriodic(isPeriodic), planes(planes), minOffset(minOffset), maxOffset(maxOffset) +class BodyStorage; +class RigidBody; +namespace cr +{ +class HardContactSemiImplicitTimesteppingSolvers; +} +} // namespace pe +} // namespace walberla + +struct PeParameter { + PeParameter(double relaxationParameter, int maxPeIterations, Vector3D globalLinearAcceleration, + std::shared_ptr<PePhysicsEngineMaterialAdapter> planes, std::array<double, 6> simulationDomain, + UbTupleInt3 numberOfBlocks, UbTupleBool3 isPeriodic, Vector3D minOffset, Vector3D maxOffset) + : relaxationParameter(relaxationParameter), maxPeIterations(maxPeIterations), + globalLinearAcceleration(globalLinearAcceleration), simulationDomain(simulationDomain), + numberOfBlocks(numberOfBlocks), isPeriodic(isPeriodic), planes(planes), minOffset(minOffset), + maxOffset(maxOffset) { } @@ -60,24 +63,26 @@ struct PeParameter Vector3D minOffset; Vector3D maxOffset; - }; class PePhysicsEngineSolverAdapter : public PhysicsEngineSolverAdapter { public: - PePhysicsEngineSolverAdapter(std::shared_ptr<PeParameter> peParameter, std::shared_ptr<PeLoadBalancerAdapter> loadBalancer); + PePhysicsEngineSolverAdapter(std::shared_ptr<PeParameter> peParameter, + std::shared_ptr<PeLoadBalancerAdapter> loadBalancer); virtual ~PePhysicsEngineSolverAdapter() {} - std::shared_ptr<PhysicsEngineGeometryAdapter> createPhysicsEngineGeometryAdapter(int id, const Vector3D& position, double radius, std::shared_ptr<PhysicsEngineMaterialAdapter> material) const override; + std::shared_ptr<PhysicsEngineGeometryAdapter> + createPhysicsEngineGeometryAdapter(int id, const Vector3D &position, double radius, + std::shared_ptr<PhysicsEngineMaterialAdapter> material) const override; void runTimestep(double step) override; - std::shared_ptr< walberla::blockforest::BlockForest > getForest(); - void saveToFile(const std::string& path); - void loadFromFile(const std::string& path); + std::shared_ptr<walberla::blockforest::BlockForest> getForest(); + void saveToFile(const std::string &path); + void loadFromFile(const std::string &path); std::shared_ptr<walberla::blockforest::BlockForest> getBlockForest(); std::shared_ptr<walberla::domain_decomposition::BlockDataID> getStorageId(); std::shared_ptr<walberla::pe::BodyStorage> getGlobalBodyStorage(); - void createObstacle(const Vector3D& center, const Vector3D& lengths); + void createObstacle(const Vector3D ¢er, const Vector3D &lengths); private: void initalizePeEnvironment(); @@ -94,10 +99,9 @@ private: std::shared_ptr<PeLoadBalancerAdapter> loadBalancer; std::shared_ptr<walberla::pe::BodyStorage> globalBodyStorage; - std::shared_ptr< walberla::blockforest::BlockForest > forest; + std::shared_ptr<walberla::blockforest::BlockForest> forest; std::shared_ptr<walberla::domain_decomposition::BlockDataID> storageId; std::shared_ptr<walberla::pe::cr::HardContactSemiImplicitTimesteppingSolvers> cr; }; #endif - diff --git a/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.cpp b/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.cpp index ad4db58f1..c5486db0e 100644 --- a/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.cpp +++ b/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.cpp @@ -1,15 +1,17 @@ #include "EquilibriumReconstructor.h" -#include "ILBMKernel.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "D3Q27System.h" #include "DataSet3D.h" -#include "BCProcessor.h" -#include "BCArray3D.h" +#include "ILBMKernel.h" #include "PhysicsEngineGeometryAdapter.h" -void EquilibriumReconstructor::reconstructNode(const int& x1, const int& x2, const int& x3, - const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const +void EquilibriumReconstructor::reconstructNode(const int &x1, const int &x2, const int &x3, + const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const { const double averageDensity = this->getLocalAverageDensity(x1, x2, x3, kernel); LBMReal feq[27]; @@ -20,16 +22,15 @@ void EquilibriumReconstructor::reconstructNode(const int& x1, const int& x2, con else D3Q27System::calcIncompFeq(feq, averageDensity, boundaryVelocity[0], boundaryVelocity[1], boundaryVelocity[2]); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - //distributions->setDistribution(feq, x1, x2, x3); + // distributions->setDistribution(feq, x1, x2, x3); distributions->setDistributionInv(feq, x1, x2, x3); } - -double EquilibriumReconstructor::getLocalAverageDensity(const int &x1, const int &x2, const int &x3, std::shared_ptr<ILBMKernel> kernel) const +double EquilibriumReconstructor::getLocalAverageDensity(const int &x1, const int &x2, const int &x3, + std::shared_ptr<ILBMKernel> kernel) const { - int nAverage = 0; + int nAverage = 0; double averageDensity = 0.0; SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); @@ -38,14 +39,12 @@ double EquilibriumReconstructor::getLocalAverageDensity(const int &x1, const int SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); int neighborX1, neighborX2, neighborX3; - for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) - { + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { neighborX1 = x1 + D3Q27System::DX1[fDir]; neighborX2 = x2 + D3Q27System::DX2[fDir]; neighborX3 = x3 + D3Q27System::DX3[fDir]; - if (bcArray->isFluid(neighborX1, neighborX2, neighborX3)) - { + if (bcArray->isFluid(neighborX1, neighborX2, neighborX3)) { distributions->getDistribution(f, neighborX1, neighborX2, neighborX3); averageDensity += D3Q27System::getDensity(f); ++nAverage; @@ -53,4 +52,3 @@ double EquilibriumReconstructor::getLocalAverageDensity(const int &x1, const int } return (nAverage > 0) ? averageDensity / nAverage : 0.0; } - diff --git a/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.h b/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.h index e75297ddb..4a5c00719 100644 --- a/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.h +++ b/src/cpu/DemCoupling/reconstructor/EquilibriumReconstructor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef EQUILIBRIUM_RECONSTRUCTOR_H #define EQUILIBRIUM_RECONSTRUCTOR_H @@ -17,13 +17,13 @@ class EquilibriumReconstructor : public Reconstructor public: virtual ~EquilibriumReconstructor() {} - void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const override; + void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const override; private: - double getLocalAverageDensity(const int &x1, const int &x2, const int &x3, std::shared_ptr<ILBMKernel> kernel) const; + double getLocalAverageDensity(const int &x1, const int &x2, const int &x3, + std::shared_ptr<ILBMKernel> kernel) const; }; - - #endif - diff --git a/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.cpp b/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.cpp index 72cc555a6..8bd915b6c 100644 --- a/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.cpp +++ b/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.cpp @@ -1,82 +1,89 @@ #include "ExtrapolationReconstructor.h" -#include "ILBMKernel.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "D3Q27System.h" #include "DataSet3D.h" -#include "BCProcessor.h" -#include "BCArray3D.h" +#include "ILBMKernel.h" -#include "PhysicsEngineGeometryAdapter.h" #include "DistributionArray3D.h" +#include "PhysicsEngineGeometryAdapter.h" void ExtrapolationReconstructor::setAlternativeReconstructor(std::shared_ptr<Reconstructor> alternativeReconstructor) { this->alternativeReconstructor = alternativeReconstructor; } - -ExtrapolationReconstructor::ExtrapolationReconstructor(std::shared_ptr<Reconstructor> alternativeReconstructor) : alternativeReconstructor(alternativeReconstructor) +ExtrapolationReconstructor::ExtrapolationReconstructor(std::shared_ptr<Reconstructor> alternativeReconstructor) + : alternativeReconstructor(alternativeReconstructor) { } -void ExtrapolationReconstructor::reconstructNode(const int& x1, const int& x2, const int& x3, - const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const +void ExtrapolationReconstructor::reconstructNode(const int &x1, const int &x2, const int &x3, + const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const { const UbTupleInt3 extrapolationDirection = getSphereDirection(worldCoordinates, physicsEngineGeometry); const int numberOfCellsForExtrapolation = getNumberOfExtrapolationCells(x1, x2, x3, extrapolationDirection, kernel); - //if (numberOfCellsForExtrapolation < 2) - alternativeReconstructor->reconstructNode(x1, x2, x3, worldCoordinates, physicsEngineGeometry, kernel); - //else + // if (numberOfCellsForExtrapolation < 2) + alternativeReconstructor->reconstructNode(x1, x2, x3, worldCoordinates, physicsEngineGeometry, kernel); + // else //{ - // //UBLOG(logINFO, "point (x,y,z) " << val<1>(worldCoordinates) << ", " << val<2>(worldCoordinates) << ", " << val<3>(worldCoordinates)); - // //UBLOG(logINFO, "extradir (x,y,z) " << val<1>(extrapolationDirection) << ", " << val<2>(extrapolationDirection) << ", " << val<3>(extrapolationDirection)); + // //UBLOG(logINFO, "point (x,y,z) " << val<1>(worldCoordinates) << ", " << val<2>(worldCoordinates) << ", " << + // val<3>(worldCoordinates)); + // //UBLOG(logINFO, "extradir (x,y,z) " << val<1>(extrapolationDirection) << ", " << + // val<2>(extrapolationDirection) << ", " << val<3>(extrapolationDirection)); // //UBLOG(logINFO, "numberOfCellsForExtrapolation: " << numberOfCellsForExtrapolation ); // this->extrapolatePdFs(x1, x2, x3, extrapolationDirection, numberOfCellsForExtrapolation, kernel); //} - } -UbTupleInt3 ExtrapolationReconstructor::getSphereDirection(const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) const +UbTupleInt3 ExtrapolationReconstructor::getSphereDirection( + const Vector3D &worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) const { const Vector3D spherePosition = physicsEngineGeometry->getPosition(); - const Vector3D bodyNormal = worldCoordinates - spherePosition; + const Vector3D bodyNormal = worldCoordinates - spherePosition; return this->getCorrespondingLatticeDirection(bodyNormal); } -UbTupleInt3 ExtrapolationReconstructor::getCorrespondingLatticeDirection(const Vector3D& direction) const +UbTupleInt3 ExtrapolationReconstructor::getCorrespondingLatticeDirection(const Vector3D &direction) const { int correspondingDirection = 0; - double innerProduct = 0.0; - for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) - { + double innerProduct = 0.0; + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { // compute inner product <dir,c_i> - const double temporaryInnerProduct = direction[0] * D3Q27System::cNorm[0][fDir] + direction[1] * D3Q27System::cNorm[1][fDir] + direction[2] * D3Q27System::cNorm[2][fDir]; - if (temporaryInnerProduct > innerProduct) - { - innerProduct = temporaryInnerProduct; + const double temporaryInnerProduct = direction[0] * D3Q27System::cNorm[0][fDir] + + direction[1] * D3Q27System::cNorm[1][fDir] + + direction[2] * D3Q27System::cNorm[2][fDir]; + if (temporaryInnerProduct > innerProduct) { + innerProduct = temporaryInnerProduct; correspondingDirection = fDir; } } - return UbTupleInt3(D3Q27System::DX1[correspondingDirection], D3Q27System::DX2[correspondingDirection], D3Q27System::DX3[correspondingDirection]); + return UbTupleInt3(D3Q27System::DX1[correspondingDirection], D3Q27System::DX2[correspondingDirection], + D3Q27System::DX3[correspondingDirection]); } -int ExtrapolationReconstructor::getNumberOfExtrapolationCells(const int x1, const int x2, const int x3, const UbTupleInt3& extrapolationDirection, std::shared_ptr<ILBMKernel> kernel) const +int ExtrapolationReconstructor::getNumberOfExtrapolationCells(const int x1, const int x2, const int x3, + const UbTupleInt3 &extrapolationDirection, + std::shared_ptr<ILBMKernel> kernel) const { if (extrapolationDirection == UbTupleInt3(0, 0, 0)) return 0; const int desiredCellsInExtrapolationDirection = 3; - - for (int numCells = 1; numCells <= desiredCellsInExtrapolationDirection; ++numCells) - { - UbTupleInt3 neighbor(x1 + numCells * val<1>(extrapolationDirection), x2 + numCells * val<2>(extrapolationDirection), x3 + numCells * val<3>(extrapolationDirection)); - if(!kernel->isInsideOfDomain(val<1>(neighbor), val<2>(neighbor), val<3>(neighbor))) - return numCells - 1; + for (int numCells = 1; numCells <= desiredCellsInExtrapolationDirection; ++numCells) { + UbTupleInt3 neighbor(x1 + numCells * val<1>(extrapolationDirection), + x2 + numCells * val<2>(extrapolationDirection), + x3 + numCells * val<3>(extrapolationDirection)); + if (!kernel->isInsideOfDomain(val<1>(neighbor), val<2>(neighbor), val<3>(neighbor))) + return numCells - 1; if (!kernel->getBCProcessor()->getBCArray()->isFluid(val<1>(neighbor), val<2>(neighbor), val<3>(neighbor))) return numCells - 1; @@ -84,9 +91,10 @@ int ExtrapolationReconstructor::getNumberOfExtrapolationCells(const int x1, cons return desiredCellsInExtrapolationDirection; } - void ExtrapolationReconstructor::extrapolatePdFs(const int x1, const int x2, const int x3, - const UbTupleInt3& extrapolationDirection, int numberOfCellsForExtrapolation, std::shared_ptr<ILBMKernel> kernel) const + const UbTupleInt3 &extrapolationDirection, + int numberOfCellsForExtrapolation, + std::shared_ptr<ILBMKernel> kernel) const { SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); @@ -109,9 +117,8 @@ void ExtrapolationReconstructor::extrapolatePdFs(const int x1, const int x2, con for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) pdf[fDir] = 3 * pdfNeighbor1[fDir] - 3 * pdfNeighbor2[fDir] + pdfNeighbor3[fDir]; - } - else // numberOfCellsForExtrapolation == 2 // linear normal extrapolation - { + } else // numberOfCellsForExtrapolation == 2 // linear normal extrapolation + { for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) pdf[fDir] = 2 * pdfNeighbor1[fDir] - pdfNeighbor2[fDir]; } diff --git a/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.h b/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.h index ec60da39e..2844fdf24 100644 --- a/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.h +++ b/src/cpu/DemCoupling/reconstructor/ExtrapolationReconstructor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef EXTRAPOLATION_RECONSTRUCTOR_H #define EXTRAPOLATION_RECONSTRUCTOR_H @@ -20,23 +20,22 @@ public: ExtrapolationReconstructor(std::shared_ptr<Reconstructor> alternativeReconstructor); virtual ~ExtrapolationReconstructor() {} - - void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const override; + void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const override; void setAlternativeReconstructor(std::shared_ptr<Reconstructor> alternativeReconstructor); private: - int getNumberOfExtrapolationCells(const int x1, const int x2, const int x3, const UbTupleInt3& ubTuple, std::shared_ptr<ILBMKernel> kernel) const; - UbTupleInt3 getSphereDirection(const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) const; - UbTupleInt3 getCorrespondingLatticeDirection(const Vector3D& direction) const; - void extrapolatePdFs(const int x1, const int x2, const int x3, const UbTupleInt3& ubTuple, int numberOfCellsForExtrapolation, std::shared_ptr<ILBMKernel> kernel) const; - + int getNumberOfExtrapolationCells(const int x1, const int x2, const int x3, const UbTupleInt3 &ubTuple, + std::shared_ptr<ILBMKernel> kernel) const; + UbTupleInt3 getSphereDirection(const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry) const; + UbTupleInt3 getCorrespondingLatticeDirection(const Vector3D &direction) const; + void extrapolatePdFs(const int x1, const int x2, const int x3, const UbTupleInt3 &ubTuple, + int numberOfCellsForExtrapolation, std::shared_ptr<ILBMKernel> kernel) const; std::shared_ptr<Reconstructor> alternativeReconstructor; - }; - - #endif - diff --git a/src/cpu/DemCoupling/reconstructor/LBMReconstructor.cpp b/src/cpu/DemCoupling/reconstructor/LBMReconstructor.cpp index 1cef0c2f0..c6dfdc6df 100644 --- a/src/cpu/DemCoupling/reconstructor/LBMReconstructor.cpp +++ b/src/cpu/DemCoupling/reconstructor/LBMReconstructor.cpp @@ -1,10 +1,10 @@ #include "LBMReconstructor.h" -#include "ILBMKernel.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "D3Q27System.h" #include "DataSet3D.h" -#include "BCProcessor.h" -#include "BCArray3D.h" +#include "ILBMKernel.h" #include "PhysicsEngineGeometryAdapter.h" @@ -12,138 +12,122 @@ using namespace D3Q27System; LBMReconstructor::LBMReconstructor(bool compressible) { - if (compressible) - { - calcMacrosFct = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacrosFct = &D3Q27System::calcIncompMacroscopicValues; - } + if (compressible) { + calcMacrosFct = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacrosFct = &D3Q27System::calcIncompMacroscopicValues; + } } -void LBMReconstructor::reconstructNode(const int& x1, const int& x2, const int& x3, - const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const +void LBMReconstructor::reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const { - LBMReal pdf[D3Q27System::ENDF + 1]; - - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(pdf, rho, vx1, vx2, vx3); - - LBMReal rho_dif = 1; + LBMReal pdf[D3Q27System::ENDF + 1]; - while (rho_dif > 1e-5) - { - for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) - { + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(pdf, rho, vx1, vx2, vx3); - UbTupleInt3 neighbor(x1 + D3Q27System::DX1[fDir], x2 + D3Q27System::DX2[fDir], x3 + D3Q27System::DX3[fDir]); - - if (!kernel->getBCProcessor()->getBCArray()->isFluid(val<1>(neighbor), val<2>(neighbor), val<3>(neighbor))) - { - LBMReal pdfNeighbor[D3Q27System::ENDF + 1]; - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - const int invDir = D3Q27System::INVDIR[fDir]; - distributions->getDistributionForDirection(pdfNeighbor[invDir], val<1>(neighbor), val<2>(neighbor), val<3>(neighbor)); - distributions->setDistributionInvForDirection(pdf[invDir], x1, x2, x3, invDir); - } - - - } - } - - - - LBMReal collFactor = kernel->getCollisionFactor(); - collide(pdf, collFactor); + LBMReal rho_dif = 1; + while (rho_dif > 1e-5) { + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { + UbTupleInt3 neighbor(x1 + D3Q27System::DX1[fDir], x2 + D3Q27System::DX2[fDir], x3 + D3Q27System::DX3[fDir]); + if (!kernel->getBCProcessor()->getBCArray()->isFluid(val<1>(neighbor), val<2>(neighbor), + val<3>(neighbor))) { + LBMReal pdfNeighbor[D3Q27System::ENDF + 1]; + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + const int invDir = D3Q27System::INVDIR[fDir]; + distributions->getDistributionForDirection(pdfNeighbor[invDir], val<1>(neighbor), val<2>(neighbor), + val<3>(neighbor)); + distributions->setDistributionInvForDirection(pdf[invDir], x1, x2, x3, invDir); + } + } + } + LBMReal collFactor = kernel->getCollisionFactor(); + collide(pdf, collFactor); } - -void LBMReconstructor::collide(LBMReal* f, LBMReal collFactor) +void LBMReconstructor::collide(LBMReal *f, LBMReal collFactor) { - LBMReal drho, vx1, vx2, vx3; - LBMReal feq[D3Q27System::ENDF+1]; - - - drho = ((f[TNE]+f[BSW])+(f[TSE]+f[BNW]))+((f[BSE]+f[TNW])+(f[TSW]+f[BNE])) - +(((f[NE]+f[SW])+(f[SE]+f[NW]))+((f[TE]+f[BW])+(f[BE]+f[TW])) - +((f[BN]+f[TS])+(f[TN]+f[BS])))+((f[E]+f[W])+(f[N]+f[S]) - +(f[T]+f[B]))+f[ZERO]; - - vx1 = ((((f[TNE]-f[BSW])+(f[TSE]-f[BNW]))+((f[BSE]-f[TNW])+(f[BNE]-f[TSW])))+ - (((f[BE]-f[TW])+(f[TE]-f[BW]))+((f[SE]-f[NW])+(f[NE]-f[SW])))+ - (f[E]-f[W])); - - vx2 = ((((f[TNE]-f[BSW])+(f[BNW]-f[TSE]))+((f[TNW]-f[BSE])+(f[BNE]-f[TSW])))+ - (((f[BN]-f[TS])+(f[TN]-f[BS]))+((f[NW]-f[SE])+(f[NE]-f[SW])))+ - (f[N]-f[S])); - - vx3 = ((((f[TNE]-f[BSW])+(f[TSE]-f[BNW]))+((f[TNW]-f[BSE])+(f[TSW]-f[BNE])))+ - (((f[TS]-f[BN])+(f[TN]-f[BS]))+((f[TW]-f[BE])+(f[TE]-f[BW])))+ - (f[T]-f[B])); - - LBMReal cu_sq = 1.5*(vx1*vx1+vx2*vx2+vx3*vx3); - - feq[ZERO] = c8o27*(drho-cu_sq); - feq[E] = c2o27*(drho+3.0*(vx1)+c9o2*(vx1)*(vx1)-cu_sq); - feq[W] = c2o27*(drho+3.0*(-vx1)+c9o2*(-vx1)*(-vx1)-cu_sq); - feq[N] = c2o27*(drho+3.0*(vx2)+c9o2*(vx2)*(vx2)-cu_sq); - feq[S] = c2o27*(drho+3.0*(-vx2)+c9o2*(-vx2)*(-vx2)-cu_sq); - feq[T] = c2o27*(drho+3.0*(vx3)+c9o2*(vx3)*(vx3)-cu_sq); - feq[B] = c2o27*(drho+3.0*(-vx3)+c9o2*(-vx3)*(-vx3)-cu_sq); - feq[NE] = c1o54*(drho+3.0*(vx1+vx2)+c9o2*(vx1+vx2)*(vx1+vx2)-cu_sq); - feq[SW] = c1o54*(drho+3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq); - feq[SE] = c1o54*(drho+3.0*(vx1-vx2)+c9o2*(vx1-vx2)*(vx1-vx2)-cu_sq); - feq[NW] = c1o54*(drho+3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq); - feq[TE] = c1o54*(drho+3.0*(vx1+vx3)+c9o2*(vx1+vx3)*(vx1+vx3)-cu_sq); - feq[BW] = c1o54*(drho+3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq); - feq[BE] = c1o54*(drho+3.0*(vx1-vx3)+c9o2*(vx1-vx3)*(vx1-vx3)-cu_sq); - feq[TW] = c1o54*(drho+3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq); - feq[TN] = c1o54*(drho+3.0*(vx2+vx3)+c9o2*(vx2+vx3)*(vx2+vx3)-cu_sq); - feq[BS] = c1o54*(drho+3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq); - feq[BN] = c1o54*(drho+3.0*(vx2-vx3)+c9o2*(vx2-vx3)*(vx2-vx3)-cu_sq); - feq[TS] = c1o54*(drho+3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq); - feq[TNE] = c1o216*(drho+3.0*(vx1+vx2+vx3)+c9o2*(vx1+vx2+vx3)*(vx1+vx2+vx3)-cu_sq); - feq[BSW] = c1o216*(drho+3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq); - feq[BNE] = c1o216*(drho+3.0*(vx1+vx2-vx3)+c9o2*(vx1+vx2-vx3)*(vx1+vx2-vx3)-cu_sq); - feq[TSW] = c1o216*(drho+3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq); - feq[TSE] = c1o216*(drho+3.0*(vx1-vx2+vx3)+c9o2*(vx1-vx2+vx3)*(vx1-vx2+vx3)-cu_sq); - feq[BNW] = c1o216*(drho+3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq); - feq[BSE] = c1o216*(drho+3.0*(vx1-vx2-vx3)+c9o2*(vx1-vx2-vx3)*(vx1-vx2-vx3)-cu_sq); - feq[TNW] = c1o216*(drho+3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq); - - //Relaxation - f[ZERO] += (feq[ZERO]-f[ZERO])*collFactor; - f[E] += (feq[E]-f[E])*collFactor; - f[W] += (feq[W]-f[W])*collFactor; - f[N] += (feq[N]-f[N])*collFactor; - f[S] += (feq[S]-f[S])*collFactor; - f[T] += (feq[T]-f[T])*collFactor; - f[B] += (feq[B]-f[B])*collFactor; - f[NE] += (feq[NE]-f[NE])*collFactor; - f[SW] += (feq[SW]-f[SW])*collFactor; - f[SE] += (feq[SE]-f[SE])*collFactor; - f[NW] += (feq[NW]-f[NW])*collFactor; - f[TE] += (feq[TE]-f[TE])*collFactor; - f[BW] += (feq[BW]-f[BW])*collFactor; - f[BE] += (feq[BE]-f[BE])*collFactor; - f[TW] += (feq[TW]-f[TW])*collFactor; - f[TN] += (feq[TN]-f[TN])*collFactor; - f[BS] += (feq[BS]-f[BS])*collFactor; - f[BN] += (feq[BN]-f[BN])*collFactor; - f[TS] += (feq[TS]-f[TS])*collFactor; - - f[TNE] += (feq[TNE]-f[TNE])*collFactor; - f[BSW] += (feq[BSW]-f[BSW])*collFactor; - f[BNE] += (feq[BNE]-f[BNE])*collFactor; - f[TSW] += (feq[TSW]-f[TSW])*collFactor; - f[TSE] += (feq[TSE]-f[TSE])*collFactor; - f[BNW] += (feq[BNW]-f[BNW])*collFactor; - f[BSE] += (feq[BSE]-f[BSE])*collFactor; - f[TNW] += (feq[TNW]-f[TNW])*collFactor; + LBMReal drho, vx1, vx2, vx3; + LBMReal feq[D3Q27System::ENDF + 1]; + + drho = ((f[TNE] + f[BSW]) + (f[TSE] + f[BNW])) + ((f[BSE] + f[TNW]) + (f[TSW] + f[BNE])) + + (((f[NE] + f[SW]) + (f[SE] + f[NW])) + ((f[TE] + f[BW]) + (f[BE] + f[TW])) + + ((f[BN] + f[TS]) + (f[TN] + f[BS]))) + + ((f[E] + f[W]) + (f[N] + f[S]) + (f[T] + f[B])) + f[ZERO]; + + vx1 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])); + + vx2 = ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])); + + vx3 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])); + + LBMReal cu_sq = 1.5 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); + + feq[ZERO] = c8o27 * (drho - cu_sq); + feq[E] = c2o27 * (drho + 3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq); + feq[W] = c2o27 * (drho + 3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq); + feq[N] = c2o27 * (drho + 3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq); + feq[S] = c2o27 * (drho + 3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq); + feq[T] = c2o27 * (drho + 3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq); + feq[B] = c2o27 * (drho + 3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq); + feq[NE] = c1o54 * (drho + 3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq); + feq[SW] = c1o54 * (drho + 3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq); + feq[SE] = c1o54 * (drho + 3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq); + feq[NW] = c1o54 * (drho + 3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq); + feq[TE] = c1o54 * (drho + 3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq); + feq[BW] = c1o54 * (drho + 3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq); + feq[BE] = c1o54 * (drho + 3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq); + feq[TW] = c1o54 * (drho + 3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq); + feq[TN] = c1o54 * (drho + 3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq); + feq[BS] = c1o54 * (drho + 3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq); + feq[BN] = c1o54 * (drho + 3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq); + feq[TS] = c1o54 * (drho + 3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq); + feq[TNE] = c1o216 * (drho + 3.0 * (vx1 + vx2 + vx3) + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq); + feq[BSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 - vx3) + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq); + feq[BNE] = c1o216 * (drho + 3.0 * (vx1 + vx2 - vx3) + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq); + feq[TSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 + vx3) + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq); + feq[TSE] = c1o216 * (drho + 3.0 * (vx1 - vx2 + vx3) + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq); + feq[BNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 - vx3) + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq); + feq[BSE] = c1o216 * (drho + 3.0 * (vx1 - vx2 - vx3) + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq); + feq[TNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 + vx3) + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq); + + // Relaxation + f[ZERO] += (feq[ZERO] - f[ZERO]) * collFactor; + f[E] += (feq[E] - f[E]) * collFactor; + f[W] += (feq[W] - f[W]) * collFactor; + f[N] += (feq[N] - f[N]) * collFactor; + f[S] += (feq[S] - f[S]) * collFactor; + f[T] += (feq[T] - f[T]) * collFactor; + f[B] += (feq[B] - f[B]) * collFactor; + f[NE] += (feq[NE] - f[NE]) * collFactor; + f[SW] += (feq[SW] - f[SW]) * collFactor; + f[SE] += (feq[SE] - f[SE]) * collFactor; + f[NW] += (feq[NW] - f[NW]) * collFactor; + f[TE] += (feq[TE] - f[TE]) * collFactor; + f[BW] += (feq[BW] - f[BW]) * collFactor; + f[BE] += (feq[BE] - f[BE]) * collFactor; + f[TW] += (feq[TW] - f[TW]) * collFactor; + f[TN] += (feq[TN] - f[TN]) * collFactor; + f[BS] += (feq[BS] - f[BS]) * collFactor; + f[BN] += (feq[BN] - f[BN]) * collFactor; + f[TS] += (feq[TS] - f[TS]) * collFactor; + + f[TNE] += (feq[TNE] - f[TNE]) * collFactor; + f[BSW] += (feq[BSW] - f[BSW]) * collFactor; + f[BNE] += (feq[BNE] - f[BNE]) * collFactor; + f[TSW] += (feq[TSW] - f[TSW]) * collFactor; + f[TSE] += (feq[TSE] - f[TSE]) * collFactor; + f[BNW] += (feq[BNW] - f[BNW]) * collFactor; + f[BSE] += (feq[BSE] - f[BSE]) * collFactor; + f[TNW] += (feq[TNW] - f[TNW]) * collFactor; } \ No newline at end of file diff --git a/src/cpu/DemCoupling/reconstructor/LBMReconstructor.h b/src/cpu/DemCoupling/reconstructor/LBMReconstructor.h index 0ba24f898..173f008a3 100644 --- a/src/cpu/DemCoupling/reconstructor/LBMReconstructor.h +++ b/src/cpu/DemCoupling/reconstructor/LBMReconstructor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef LBM_RECONSTRUCTOR_H #define LBM_RECONSTRUCTOR_H @@ -14,24 +14,22 @@ class ILBMKernel; class PhysicsEngineGeometryAdapter; - class LBMReconstructor : public Reconstructor { public: LBMReconstructor(bool compressible); virtual ~LBMReconstructor() {} - - void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const override; -private: - static void collide(LBMReal* f, LBMReal collFactor); + void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const override; - typedef void(*CalcMacrosFct)(const LBMReal* const& /*f[27]*/, LBMReal& /*rho*/, LBMReal& /*vx1*/, LBMReal& /*vx2*/, LBMReal& /*vx3*/); - CalcMacrosFct calcMacrosFct; +private: + static void collide(LBMReal *f, LBMReal collFactor); + typedef void (*CalcMacrosFct)(const LBMReal *const & /*f[27]*/, LBMReal & /*rho*/, LBMReal & /*vx1*/, + LBMReal & /*vx2*/, LBMReal & /*vx3*/); + CalcMacrosFct calcMacrosFct; }; - - #endif - diff --git a/src/cpu/DemCoupling/reconstructor/Reconstructor.h b/src/cpu/DemCoupling/reconstructor/Reconstructor.h index cbcb49ba2..15355d515 100644 --- a/src/cpu/DemCoupling/reconstructor/Reconstructor.h +++ b/src/cpu/DemCoupling/reconstructor/Reconstructor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef RECONSTRCUTOR_H #define RECONSTRCUTOR_H @@ -17,11 +17,9 @@ class Reconstructor public: virtual ~Reconstructor() {} - virtual void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D& worldCoordinates, SPtr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const = 0; - + virtual void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + SPtr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const = 0; }; - - #endif - diff --git a/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.cpp b/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.cpp index 1b9282730..c48586ca4 100644 --- a/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.cpp +++ b/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.cpp @@ -2,23 +2,25 @@ #include <exception> -#include "ILBMKernel.h" -#include "D3Q27System.h" #include "BCArray3D.h" -#include "EsoTwist3D.h" #include "BCProcessor.h" +#include "D3Q27System.h" #include "DataSet3D.h" +#include "EsoTwist3D.h" +#include "ILBMKernel.h" #include "PhysicsEngineGeometryAdapter.h" -void VelocityBcReconstructor::reconstructNode(const int& x1, const int& x2, const int& x3, - const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const +void VelocityBcReconstructor::reconstructNode(const int &x1, const int &x2, const int &x3, + const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const { if (kernel->getCompressible()) throw std::runtime_error("not implemented yet!"); const Vector3D boundaryVelocity = physicsEngineGeometry->getVelocityAtPosition(worldCoordinates); - //TODO: move to D3Q27 system + // TODO: move to D3Q27 system LBMReal wijk[D3Q27System::ENDF + 1]; D3Q27System::calcIncompFeq(wijk, 1, 0, 0, 0); @@ -47,31 +49,27 @@ void VelocityBcReconstructor::reconstructNode(const int& x1, const int& x2, cons double sumRho = 0, sumWijk = 0; double collFactor = kernel->getCollisionFactor(); - for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) - { + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { neighborX1 = x1 + D3Q27System::DX1[fDir]; neighborX2 = x2 + D3Q27System::DX2[fDir]; neighborX3 = x3 + D3Q27System::DX3[fDir]; - if (bcArray->isFluid(neighborX1, neighborX2, neighborX3)) - { + if (bcArray->isFluid(neighborX1, neighborX2, neighborX3)) { int invDir = D3Q27System::INVDIR[fDir]; neighborX1Inv = x1 + D3Q27System::DX1[invDir]; neighborX2Inv = x2 + D3Q27System::DX2[invDir]; neighborX3Inv = x3 + D3Q27System::DX3[invDir]; - if (!bcArray->isFluid(neighborX1Inv, neighborX2Inv, neighborX3Inv)) - { + if (!bcArray->isFluid(neighborX1Inv, neighborX2Inv, neighborX3Inv)) { double velocity = bc->getBoundaryVelocity(invDir); - fpre[fDir] = fpre[invDir] - velocity; + fpre[fDir] = fpre[invDir] - velocity; double Omega = fpost[fDir] - fpre[fDir]; sumRho += Omega / collFactor + fpre[fDir] - feqNullRho[fDir]; sumWijk += wijk[fDir]; } - } } @@ -79,24 +77,20 @@ void VelocityBcReconstructor::reconstructNode(const int& x1, const int& x2, cons if (sumWijk > 0.0) rho = sumRho / sumWijk; - for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) - { + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { neighborX1 = x1 + D3Q27System::DX1[fDir]; neighborX2 = x2 + D3Q27System::DX2[fDir]; neighborX3 = x3 + D3Q27System::DX3[fDir]; - if (!bcArray->isFluid(neighborX1, neighborX2, neighborX3)) - { - int invDir = D3Q27System::INVDIR[fDir]; + if (!bcArray->isFluid(neighborX1, neighborX2, neighborX3)) { + int invDir = D3Q27System::INVDIR[fDir]; neighborX1Inv = x1 + D3Q27System::DX1[invDir]; neighborX2Inv = x2 + D3Q27System::DX2[invDir]; neighborX3Inv = x3 + D3Q27System::DX3[invDir]; - if (!bcArray->isFluid(neighborX1Inv, neighborX2Inv, neighborX3Inv)) - { - fpre[fDir] = D3Q27System::getIncompFeqForDirection(fDir, rho, bc->getBoundaryVelocityX1(), bc->getBoundaryVelocityX2(), bc->getBoundaryVelocityX3()); + if (!bcArray->isFluid(neighborX1Inv, neighborX2Inv, neighborX3Inv)) { + fpre[fDir] = D3Q27System::getIncompFeqForDirection( + fDir, rho, bc->getBoundaryVelocityX1(), bc->getBoundaryVelocityX2(), bc->getBoundaryVelocityX3()); } - } } - } diff --git a/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.h b/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.h index 8be5bcb65..9f5b3f0b6 100644 --- a/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.h +++ b/src/cpu/DemCoupling/reconstructor/VelocityBcReconstructor.h @@ -1,7 +1,7 @@ /* -* Author: S. Peters -* mail: peters@irmb.tu-bs.de -*/ + * Author: S. Peters + * mail: peters@irmb.tu-bs.de + */ #ifndef VELOCITY_BC_RECONSTRUCTOR_H #define VELOCITY_BC_RECONSTRUCTOR_H @@ -17,11 +17,9 @@ class VelocityBcReconstructor : public Reconstructor public: virtual ~VelocityBcReconstructor() {} - void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D& worldCoordinates, std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, std::shared_ptr<ILBMKernel> kernel) const override; - + void reconstructNode(const int &x1, const int &x2, const int &x3, const Vector3D &worldCoordinates, + std::shared_ptr<PhysicsEngineGeometryAdapter> physicsEngineGeometry, + std::shared_ptr<ILBMKernel> kernel) const override; }; - - #endif - diff --git a/src/cpu/VirtualFluids.h b/src/cpu/VirtualFluids.h index faae5c778..576687d69 100644 --- a/src/cpu/VirtualFluids.h +++ b/src/cpu/VirtualFluids.h @@ -34,7 +34,7 @@ #ifndef VirtualFluids_h__ #define VirtualFluids_h__ -//VirtualFluids header files +// VirtualFluids header files #ifdef _OPENMP #include <omp.h> @@ -42,19 +42,6 @@ #include <basics/PointerDefinitions.h> -#include <muParser.h> -#include <muParserBase.h> -#include <muParserBytecode.h> -#include <muParserCallback.h> -#include <muParserDef.h> -#include <muParserDLL.h> -#include <muParserError.h> -#include <muParserFixes.h> -#include <muParserInt.h> -#include <muParserTemplateMagic.h> -#include <muParserTest.h> -#include <muParserToken.h> -#include <muParserTokenReader.h> #include <basics/container/CbArray2D.h> #include <basics/container/CbArray3D.h> #include <basics/container/CbArray4D.h> @@ -100,43 +87,54 @@ #include <basics/writer/WbWriterVtkXmlASCII.h> #include <basics/writer/WbWriterVtkXmlBinary.h> #include <basics/writer/WbWriterX3D.h> +#include <muParser.h> +#include <muParserBase.h> +#include <muParserBytecode.h> +#include <muParserCallback.h> +#include <muParserDLL.h> +#include <muParserDef.h> +#include <muParserError.h> +#include <muParserFixes.h> +#include <muParserInt.h> +#include <muParserTemplateMagic.h> +#include <muParserTest.h> +#include <muParserToken.h> +#include <muParserTokenReader.h> -#include <BoundaryConditions/BCArray3D.h> -#include <BoundaryConditions/BCProcessor.h> +#include <BoundaryConditions/BCAdapter.h> #include <BoundaryConditions/BCAlgorithm.h> +#include <BoundaryConditions/BCArray3D.h> #include <BoundaryConditions/BCFunction.h> +#include <BoundaryConditions/BCProcessor.h> #include <BoundaryConditions/BoundaryConditions.h> -#include <BoundaryConditions/BCAdapter.h> #include <BoundaryConditions/DensityBCAdapter.h> -#include <BoundaryConditions/BCProcessor.h> -#include <BoundaryConditions/ThinWallBCProcessor.h> +#include <BoundaryConditions/EqDensityBCAlgorithm.h> +#include <BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h> #include <BoundaryConditions/NoSlipBCAdapter.h> +#include <BoundaryConditions/NoSlipBCAlgorithm.h> +#include <BoundaryConditions/NonEqDensityBCAlgorithm.h> +#include <BoundaryConditions/NonReflectingOutflowBCAlgorithm.h> #include <BoundaryConditions/SlipBCAdapter.h> +#include <BoundaryConditions/SlipBCAlgorithm.h> +#include <BoundaryConditions/ThinWallBCProcessor.h> +#include <BoundaryConditions/ThinWallNoSlipBCAlgorithm.h> #include <BoundaryConditions/VelocityBCAdapter.h> -#include <BoundaryConditions/BCAlgorithm.h> #include <BoundaryConditions/VelocityBCAlgorithm.h> -#include <BoundaryConditions/NonEqDensityBCAlgorithm.h> -#include <BoundaryConditions/EqDensityBCAlgorithm.h> -#include <BoundaryConditions/NoSlipBCAlgorithm.h> -#include <BoundaryConditions/ThinWallNoSlipBCAlgorithm.h> -#include <BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h> -#include <BoundaryConditions/SlipBCAlgorithm.h> -#include <BoundaryConditions/NonReflectingOutflowBCAlgorithm.h> #include <BoundaryConditions/VelocityWithDensityBCAlgorithm.h> #include <Connectors/Block3DConnector.h> +#include <Connectors/Block3DConnectorFactory.h> +#include <Connectors/CoarseToFineBlock3DConnector.h> +#include <Connectors/CoarseToFineNodeSetBlock3DConnector.h> +#include <Connectors/ConnectorFactory.h> #include <Connectors/D3Q27ETCFOffVectorConnector.h> #include <Connectors/D3Q27ETFCOffVectorConnector.h> #include <Connectors/D3Q27ETFullDirectConnector.h> #include <Connectors/D3Q27ETFullVectorConnector.h> -#include <Connectors/LocalBlock3DConnector.h> -#include <Connectors/RemoteBlock3DConnector.h> -#include <Connectors/CoarseToFineBlock3DConnector.h> -#include <Connectors/CoarseToFineNodeSetBlock3DConnector.h> #include <Connectors/FineToCoarseBlock3DConnector.h> #include <Connectors/FineToCoarseNodeSetBlock3DConnector.h> -#include <Connectors/ConnectorFactory.h> -#include <Connectors/Block3DConnectorFactory.h> +#include <Connectors/LocalBlock3DConnector.h> +#include <Connectors/RemoteBlock3DConnector.h> #include <Data/D3Q27EsoTwist3DSplittedVector.h> #include <Data/D3Q27EsoTwist3DSplittedVectorEx.h> @@ -146,9 +144,9 @@ #include <Data/EsoTwistD3Q27System.h> #include <Data/VoidData3D.h> +#include <Grid/BasicCalculator.h> #include <Grid/Block3D.h> #include <Grid/Calculator.h> -#include <Grid/BasicCalculator.h> #include <Grid/Grid3D.h> #include <Grid/Grid3DSystem.h> @@ -157,59 +155,58 @@ #include <Interactors/Interactor3D.h> #include <Interactors/InteractorsHelper.h> -#include <CoProcessors/WriteBlocksCoProcessor.h> #include <CoProcessors/AdjustForcingCoProcessor.h> #include <CoProcessors/CalculateForcesCoProcessor.h> -#include <CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h> -#include <CoProcessors/WriteMQFromSelectionCoProcessor.h> +#include <CoProcessors/WriteBlocksCoProcessor.h> #include <CoProcessors/WriteBoundaryConditionsCoProcessor.h> +#include <CoProcessors/WriteMQFromSelectionCoProcessor.h> +#include <CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h> //#include <CoProcessors/PathLineCoProcessor.h> //#include <CoProcessors/PathLineCoProcessorMcpart.h> -#include <CoProcessors/PressureDifferenceCoProcessor.h> #include <CoProcessors/EmergencyExitCoProcessor.h> #include <CoProcessors/NUPSCounterCoProcessor.h> +#include <CoProcessors/PressureDifferenceCoProcessor.h> //#include <CoProcessors/Particles.h> -#include <CoProcessors/CoProcessor.h> -#include <CoProcessors/TurbulenceIntensityCoProcessor.h> #include <CoProcessors/AverageValuesCoProcessor.h> +#include <CoProcessors/CoProcessor.h> #include <CoProcessors/DecreaseViscosityCoProcessor.h> -#include <CoProcessors/TimeseriesCoProcessor.h> -#include <CoProcessors/ShearStressCoProcessor.h> -#include <CoProcessors/QCriterionCoProcessor.h> #include <CoProcessors/InSituVTKCoProcessor.h> +#include <CoProcessors/QCriterionCoProcessor.h> +#include <CoProcessors/ShearStressCoProcessor.h> +#include <CoProcessors/TimeseriesCoProcessor.h> +#include <CoProcessors/TurbulenceIntensityCoProcessor.h> //#include <CoProcessors/MeanValuesCoProcessor.h> -#include <CoProcessors/TimeAveragedValuesCoProcessor.h> #include <CoProcessors/InSituCatalystCoProcessor.h> -#include <CoProcessors/MPIIORestartCoProcessor.h> -#include <CoProcessors/MPIIOMigrationCoProcessor.h> -#include <CoProcessors/MPIIOMigrationBECoProcessor.h> -#include <CoProcessors/PressureCoefficientCoProcessor.h> #include <CoProcessors/LineTimeSeriesCoProcessor.h> +#include <CoProcessors/MPIIOMigrationBECoProcessor.h> +#include <CoProcessors/MPIIOMigrationCoProcessor.h> +#include <CoProcessors/MPIIORestartCoProcessor.h> #include <CoProcessors/MicrophoneArrayCoProcessor.h> +#include <CoProcessors/PressureCoefficientCoProcessor.h> +#include <CoProcessors/TimeAveragedValuesCoProcessor.h> #include <IntegrateValuesHelper.h> //#include <LBM/D3Q27CompactInterpolationProcessor.h> -#include <LBM/IncompressibleOffsetInterpolationProcessor.h> #include <LBM/CompressibleOffsetInterpolationProcessor.h> #include <LBM/CompressibleOffsetMomentsInterpolationProcessor.h> #include <LBM/CompressibleOffsetSquarePressureInterpolationProcessor.h> +#include <LBM/IncompressibleOffsetInterpolationProcessor.h> #include <LBM/InterpolationHelper.h> #include <LBM/InterpolationProcessor.h> //#include <LBM/D3Q27OffsetInterpolationProcessor.h> +#include <IncompressibleCumulantWithSpongeLayerLBMKernel.h> +#include <LBM/CompressibleCumulant4thOrderViscosityLBMKernel.h> +#include <LBM/CompressibleCumulantLBMKernel.h> #include <LBM/D3Q27System.h> #include <LBM/ICell.h> -#include <LBM/InterpolationProcessor.h> -#include <LBM/LBMKernel.h> -#include <IncompressibleCumulantWithSpongeLayerLBMKernel.h> -#include <LBM/LBMKernel.h> #include <LBM/IncompressibleCumulantLBMKernel.h> -#include <LBM/CompressibleCumulantLBMKernel.h> -#include <LBM/CompressibleCumulant4thOrderViscosityLBMKernel.h> #include <LBM/InitDensityLBMKernel.h> -#include <LBM/VoidLBMKernel.h> +#include <LBM/InterpolationProcessor.h> +#include <LBM/LBMKernel.h> +#include <LBM/LBMKernelETD3Q27BGK.h> #include <LBM/LBMSystem.h> #include <LBM/LBMUnitConverter.h> -#include <LBM/LBMKernelETD3Q27BGK.h> +#include <LBM/VoidLBMKernel.h> #include <geometry3d/CoordinateTransformation3D.h> #include <geometry3d/GbCuboid3D.h> @@ -225,9 +222,9 @@ #include <geometry3d/GbQuadFaceMesh3D.h> #include <geometry3d/GbSphere3D.h> #include <geometry3d/GbSystem3D.h> +#include <geometry3d/GbTriFaceMesh3D.h> #include <geometry3d/GbTriangle3D.h> #include <geometry3d/GbTriangularMesh3D.h> -#include <geometry3d/GbTriFaceMesh3D.h> #include <geometry3d/GbVector3D.h> #include <geometry3d/GbVoxelMatrix3D.h> #include <geometry3d/KdTree/KdNode.h> @@ -244,29 +241,35 @@ #include <geometry3d/KdTree/splitalgorithms/KdSpatiallMedianSplit.h> #include <geometry3d/KdTree/splitalgorithms/KdSplitAlgorithm.h> +#include <Parallel/BlocksDistributor.h> #include <Parallel/Communicator.h> -#include <Parallel/MetisPartitioner.h> #include <Parallel/MPICommunicator.h> +#include <Parallel/MetisPartitioner.h> #include <Parallel/NullCommunicator.h> #include <Parallel/PriorityQueueDecompositor.h> #include <Parallel/SimpleGeometricPartitioner.h> #include <Parallel/ZoltanPartitioner.h> -#include <Parallel/BlocksDistributor.h> +#include <Utilities/ChangeRandomQs.hpp> +#include <Utilities/CheckpointConverter.h> +#include <Utilities/ConfigurationFile.hpp> #include <Utilities/MathUtil.hpp> #include <Utilities/MemoryUtil.h> -#include <Utilities/ConfigurationFile.hpp> #include <Utilities/VoxelMatrixUtil.hpp> -#include <Utilities/ChangeRandomQs.hpp> -#include <Utilities/CheckpointConverter.h> +#include <CheckRatioBlockVisitor.h> +#include <InitDistributionsFromFileBlockVisitor.h> +#include <InitDistributionsWithInterpolationGridVisitor.h> +#include <SpongeLayerBlockVisitor.h> #include <Visitors/Block3DVisitor.h> +#include <Visitors/BoundaryConditionsBlockVisitor.h> +#include <Visitors/ChangeBoundaryDensityBlockVisitor.h> +#include <Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h> +#include <Visitors/ConnectorBlockVisitor.h> #include <Visitors/CreateTransmittersHelper.h> -#include <Visitors/InitDistributionsBlockVisitor.h> -#include <Visitors/SetConnectorsBlockVisitor.h> -#include <Visitors/SetUndefinedNodesBlockVisitor.h> #include <Visitors/GenBlocksGridVisitor.h> #include <Visitors/Grid3DVisitor.h> +#include <Visitors/InitDistributionsBlockVisitor.h> #include <Visitors/MetisPartitioningGridVisitor.h> #include <Visitors/OverlapBlockVisitor.h> #include <Visitors/PQueuePartitioningGridVisitor.h> @@ -274,26 +277,19 @@ #include <Visitors/RatioSmoothBlockVisitor.h> #include <Visitors/RefineCrossAndInsideGbObjectBlockVisitor.h> #include <Visitors/RefineInterGbObjectsVisitor.h> -#include <Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h> +#include <Visitors/RenumberBlockVisitor.h> +#include <Visitors/SetBcBlocksBlockVisitor.h> +#include <Visitors/SetConnectorsBlockVisitor.h> +#include <Visitors/SetForcingBlockVisitor.h> #include <Visitors/SetInterpolationDirsBlockVisitor.h> #include <Visitors/SetKernelBlockVisitor.h> -#include <Visitors/SetForcingBlockVisitor.h> -#include <Visitors/SetSpongeLayerBlockVisitor.h> #include <Visitors/SetSolidBlocksBlockVisitor.h> -#include <Visitors/SetBcBlocksBlockVisitor.h> -#include <Visitors/RenumberBlockVisitor.h> -#include <Visitors/ConnectorBlockVisitor.h> +#include <Visitors/SetSpongeLayerBlockVisitor.h> +#include <Visitors/SetUndefinedNodesBlockVisitor.h> #include <Visitors/ViscosityBlockVisitor.h> -#include <Visitors/BoundaryConditionsBlockVisitor.h> -#include <Visitors/BoundaryConditionsBlockVisitor.h> -#include <Visitors/ChangeBoundaryDensityBlockVisitor.h> -#include <InitDistributionsFromFileBlockVisitor.h> -#include <InitDistributionsWithInterpolationGridVisitor.h> -#include <CheckRatioBlockVisitor.h> -#include <SpongeLayerBlockVisitor.h> #include <ZoltanPartitioningGridVisitor.h> -#include <Visitors/RefineCrossAndInsideGbObjectHelper.h> #include <RefineAroundGbObjectHelper.h> +#include <Visitors/RefineCrossAndInsideGbObjectHelper.h> #endif // VirtualFluids_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h index b4f08b200..d66dd3bc6 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAdapter.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,8 +35,8 @@ #include <PointerDefinitions.h> -#include "BoundaryConditions.h" #include "BCAlgorithm.h" +#include "BoundaryConditions.h" class D3Q27Interactor; @@ -45,42 +45,45 @@ class D3Q27Interactor; class BCAdapter { public: - BCAdapter() = default; + BCAdapter() = default; - //! \param secondaryBcOption additional option of boundary conditions - BCAdapter(const short& secondaryBcOption) - : secondaryBcOption(secondaryBcOption) - { - } - virtual ~BCAdapter() = default; + //! \param secondaryBcOption additional option of boundary conditions + BCAdapter(const short &secondaryBcOption) : secondaryBcOption(secondaryBcOption) {} + virtual ~BCAdapter() = default; - //methods - bool isTimeDependent() { return((this->type & TIMEDEPENDENT) == TIMEDEPENDENT); } + // methods + bool isTimeDependent() { return ((this->type & TIMEDEPENDENT) == TIMEDEPENDENT); } - virtual short getSecondaryBcOption() { return this->secondaryBcOption; } - virtual void setSecondaryBcOption(const short& val) { this->secondaryBcOption=val; } + virtual short getSecondaryBcOption() { return this->secondaryBcOption; } + virtual void setSecondaryBcOption(const short &val) { this->secondaryBcOption = val; } - virtual void init(const D3Q27Interactor* const& interactor, const double& time=0) = 0; - virtual void update(const D3Q27Interactor* const& interactor, const double& time=0) = 0; + virtual void init(const D3Q27Interactor *const &interactor, const double &time = 0) = 0; + virtual void update(const D3Q27Interactor *const &interactor, const double &time = 0) = 0; - virtual void adaptBC( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time=0 ) = 0; - virtual void adaptBCForDirection( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& q, const int& fdirection, const double& time=0 ) = 0; + virtual void adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time = 0) = 0; + virtual void adaptBCForDirection(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, + const double &worldX1, const double &worldX2, const double &worldX3, + const double &q, const int &fdirection, const double &time = 0) = 0; - void setBcAlgorithm(SPtr<BCAlgorithm> alg) {algorithmType = alg->getType(); algorithm = alg;} - SPtr<BCAlgorithm> getAlgorithm() {return algorithm;} - char getBcAlgorithmType() {return algorithmType;} + void setBcAlgorithm(SPtr<BCAlgorithm> alg) + { + algorithmType = alg->getType(); + algorithm = alg; + } + SPtr<BCAlgorithm> getAlgorithm() { return algorithm; } + char getBcAlgorithmType() { return algorithmType; } protected: - short secondaryBcOption{0}; + short secondaryBcOption{ 0 }; - char type{0}; + char type{ 0 }; - SPtr<BCAlgorithm> algorithm; - char algorithmType{-1}; + SPtr<BCAlgorithm> algorithm; + char algorithmType{ -1 }; - static const char TIMEDEPENDENT = 1<<0;//'1'; - static const char TIMEPERIODIC = 1<<1;//'2'; + static const char TIMEDEPENDENT = 1 << 0; //'1'; + static const char TIMEPERIODIC = 1 << 1; //'2'; }; - -#endif //D3Q27BOUNDARYCONDITIONADAPTER_H +#endif // D3Q27BOUNDARYCONDITIONADAPTER_H diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.cpp index ffc8679ac..61b427e32 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,10 +33,9 @@ #include "BCAlgorithm.h" +#include "BCArray3D.h" #include "BoundaryConditions.h" #include "EsoTwist3D.h" -#include "BCArray3D.h" - ////////////////////////////////////////////////////////////////////////// void BCAlgorithm::setNodeIndex(int x1, int x2, int x3) @@ -46,54 +45,32 @@ void BCAlgorithm::setNodeIndex(int x1, int x2, int x3) this->x3 = x3; } ////////////////////////////////////////////////////////////////////////// -void BCAlgorithm::setBcPointer(SPtr<BoundaryConditions> bcPtr) -{ - this->bcPtr = bcPtr; -} +void BCAlgorithm::setBcPointer(SPtr<BoundaryConditions> bcPtr) { this->bcPtr = bcPtr; } ////////////////////////////////////////////////////////////////////////// void BCAlgorithm::setCompressible(bool c) { - compressible = c; + compressible = c; - if (this->compressible) - { - calcFeqsForDirFct = &D3Q27System::getCompFeqForDirection; - calcMacrosFct = &D3Q27System::calcCompMacroscopicValues; - calcFeqFct = &D3Q27System::calcCompFeq; - compressibleFactor = 1.0; - } - else - { - calcFeqsForDirFct = &D3Q27System::getIncompFeqForDirection; - calcMacrosFct = &D3Q27System::calcIncompMacroscopicValues; - calcFeqFct = &D3Q27System::calcIncompFeq; - compressibleFactor = 0.0; - } + if (this->compressible) { + calcFeqsForDirFct = &D3Q27System::getCompFeqForDirection; + calcMacrosFct = &D3Q27System::calcCompMacroscopicValues; + calcFeqFct = &D3Q27System::calcCompFeq; + compressibleFactor = 1.0; + } else { + calcFeqsForDirFct = &D3Q27System::getIncompFeqForDirection; + calcMacrosFct = &D3Q27System::calcIncompMacroscopicValues; + calcFeqFct = &D3Q27System::calcIncompFeq; + compressibleFactor = 0.0; + } } ////////////////////////////////////////////////////////////////////////// -void BCAlgorithm::setCollFactor(LBMReal cf) -{ - collFactor = cf; -} +void BCAlgorithm::setCollFactor(LBMReal cf) { collFactor = cf; } ////////////////////////////////////////////////////////////////////////// -char BCAlgorithm::getType() -{ - return type; -} +char BCAlgorithm::getType() { return type; } ////////////////////////////////////////////////////////////////////////// -bool BCAlgorithm::isPreCollision() -{ - return preCollision; -} +bool BCAlgorithm::isPreCollision() { return preCollision; } ////////////////////////////////////////////////////////////////////////// -SPtr<BCArray3D> BCAlgorithm::getBcArray() -{ - return bcArray; -} +SPtr<BCArray3D> BCAlgorithm::getBcArray() { return bcArray; } ////////////////////////////////////////////////////////////////////////// -void BCAlgorithm::setBcArray(SPtr<BCArray3D> bcarray) -{ - bcArray = bcarray; -} - +void BCAlgorithm::setBcArray(SPtr<BCArray3D> bcarray) { bcArray = bcarray; } diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.h index 0b4110fe9..7cef8205c 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCAlgorithm.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -47,54 +47,54 @@ class BoundaryConditions; class BCAlgorithm { public: - static const char VelocityBCAlgorithm = 0; - static const char EqDensityBCAlgorithm = 1; - static const char NonEqDensityBCAlgorithm = 2; - static const char NoSlipBCAlgorithm = 3; - static const char SlipBCAlgorithm = 4; - static const char HighViscosityNoSlipBCAlgorithm = 5; - static const char ThinWallNoSlipBCAlgorithm = 6; - static const char VelocityWithDensityBCAlgorithm = 7; - static const char NonReflectingOutflowBCAlgorithm = 8; + static const char VelocityBCAlgorithm = 0; + static const char EqDensityBCAlgorithm = 1; + static const char NonEqDensityBCAlgorithm = 2; + static const char NoSlipBCAlgorithm = 3; + static const char SlipBCAlgorithm = 4; + static const char HighViscosityNoSlipBCAlgorithm = 5; + static const char ThinWallNoSlipBCAlgorithm = 6; + static const char VelocityWithDensityBCAlgorithm = 7; + static const char NonReflectingOutflowBCAlgorithm = 8; public: - BCAlgorithm() = default; - virtual ~BCAlgorithm() = default; - - virtual void addDistributions(SPtr<DistributionArray3D> distributions) = 0; - void setNodeIndex(int x1, int x2, int x3); - void setBcPointer(SPtr<BoundaryConditions> bcPtr); - void setCompressible(bool c); - void setCollFactor(LBMReal cf); - char getType(); - bool isPreCollision(); - virtual SPtr<BCAlgorithm> clone() = 0; - SPtr<BCArray3D> getBcArray(); - void setBcArray(SPtr<BCArray3D> bcarray); - virtual void applyBC() = 0; + BCAlgorithm() = default; + virtual ~BCAlgorithm() = default; + + virtual void addDistributions(SPtr<DistributionArray3D> distributions) = 0; + void setNodeIndex(int x1, int x2, int x3); + void setBcPointer(SPtr<BoundaryConditions> bcPtr); + void setCompressible(bool c); + void setCollFactor(LBMReal cf); + char getType(); + bool isPreCollision(); + virtual SPtr<BCAlgorithm> clone() = 0; + SPtr<BCArray3D> getBcArray(); + void setBcArray(SPtr<BCArray3D> bcarray); + virtual void applyBC() = 0; protected: - bool compressible{false}; - char type; - bool preCollision; + bool compressible{ false }; + char type; + bool preCollision; - SPtr<BoundaryConditions> bcPtr; - SPtr<DistributionArray3D> distributions; - SPtr<BCArray3D> bcArray; + SPtr<BoundaryConditions> bcPtr; + SPtr<DistributionArray3D> distributions; + SPtr<BCArray3D> bcArray; - LBMReal collFactor; - int x1, x2, x3; + LBMReal collFactor; + int x1, x2, x3; - LBMReal compressibleFactor; + LBMReal compressibleFactor; - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - using CalcFeqForDirFct = LBMReal (*)(const int &, const LBMReal &, const LBMReal &, const LBMReal &, const LBMReal &); + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + using CalcFeqForDirFct = LBMReal (*)(const int &, const LBMReal &, const LBMReal &, const LBMReal &, + const LBMReal &); using CalcFeqFct = void (*)(LBMReal *const &, const LBMReal &, const LBMReal &, const LBMReal &, const LBMReal &); - - CalcFeqForDirFct calcFeqsForDirFct ; - CalcMacrosFct calcMacrosFct; - CalcFeqFct calcFeqFct; -}; + CalcFeqForDirFct calcFeqsForDirFct; + CalcMacrosFct calcMacrosFct; + CalcFeqFct calcFeqFct; +}; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.cpp index 913967fab..87606eecf 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,204 +33,206 @@ #include "BCArray3D.h" -const int BCArray3D::SOLID = -1; -const int BCArray3D::FLUID = -2; +const int BCArray3D::SOLID = -1; +const int BCArray3D::FLUID = -2; const int BCArray3D::INTERFACECF = -3; const int BCArray3D::INTERFACEFC = -4; -const int BCArray3D::UNDEFINED = -5; +const int BCArray3D::UNDEFINED = -5; ////////////////////////////////////////////////////////////////////////// BCArray3D::BCArray3D() = default; ////////////////////////////////////////////////////////////////////////// BCArray3D::BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3) { - bcindexmatrix.resize(nx1, nx2, nx3, UNDEFINED); + bcindexmatrix.resize(nx1, nx2, nx3, UNDEFINED); } ////////////////////////////////////////////////////////////////////////// BCArray3D::BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val) { - bcindexmatrix.resize(nx1, nx2, nx3, val); + bcindexmatrix.resize(nx1, nx2, nx3, val); } ////////////////////////////////////////////////////////////////////////// BCArray3D::~BCArray3D() = default; ////////////////////////////////////////////////////////////////////////// -void BCArray3D::resize(std::size_t nx1, std::size_t nx2, std::size_t nx3) -{ - bcindexmatrix.resize(nx1, nx2, nx3); -} +void BCArray3D::resize(std::size_t nx1, std::size_t nx2, std::size_t nx3) { bcindexmatrix.resize(nx1, nx2, nx3); } ////////////////////////////////////////////////////////////////////////// void BCArray3D::resize(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val) { - bcindexmatrix.resize(nx1, nx2, nx3, val); + bcindexmatrix.resize(nx1, nx2, nx3, val); } ////////////////////////////////////////////////////////////////////////// -bool BCArray3D::validIndices(std::size_t x1, std::size_t x2, std::size_t x3) const +bool BCArray3D::validIndices(std::size_t x1, std::size_t x2, std::size_t x3) const { - if (x1 < 0 || x1 >= this->bcindexmatrix.getNX1()) return false; - if (x2 < 0 || x2 >= this->bcindexmatrix.getNX2()) return false; - if (x3 < 0 || x3 >= this->bcindexmatrix.getNX3()) return false; - return true; + if (x1 < 0 || x1 >= this->bcindexmatrix.getNX1()) + return false; + if (x2 < 0 || x2 >= this->bcindexmatrix.getNX2()) + return false; + if (x3 < 0 || x3 >= this->bcindexmatrix.getNX3()) + return false; + return true; } ////////////////////////////////////////////////////////////////////////// -void BCArray3D::setBC(std::size_t x1, std::size_t x2, std::size_t x3, SPtr<BoundaryConditions> const& bc) +void BCArray3D::setBC(std::size_t x1, std::size_t x2, std::size_t x3, SPtr<BoundaryConditions> const &bc) { - if (this->hasBC(x1, x2, x3)) - { - if (this->getBC(x1, x2, x3) == bc) return; - else this->deleteBC(x1, x2, x3); - } + if (this->hasBC(x1, x2, x3)) { + if (this->getBC(x1, x2, x3) == bc) + return; + else + this->deleteBC(x1, x2, x3); + } - //if no vacant BCs available - if (indexContainer.empty()) - { - bcvector.push_back(bc); - bcindexmatrix(x1, x2, x3) = (int)bcvector.size() - 1; - } - else - { - int index = indexContainer.back(); - bcindexmatrix(x1, x2, x3) = index; - bcvector[index] = bc; - indexContainer.pop_back(); - } + // if no vacant BCs available + if (indexContainer.empty()) { + bcvector.push_back(bc); + bcindexmatrix(x1, x2, x3) = (int)bcvector.size() - 1; + } else { + int index = indexContainer.back(); + bcindexmatrix(x1, x2, x3) = index; + bcvector[index] = bc; + indexContainer.pop_back(); + } } ////////////////////////////////////////////////////////////////////////// void BCArray3D::setSolid(std::size_t x1, std::size_t x2, std::size_t x3) { - if (this->hasBC(x1, x2, x3)) this->deleteBC(x1, x2, x3); - bcindexmatrix(x1, x2, x3) = SOLID; + if (this->hasBC(x1, x2, x3)) + this->deleteBC(x1, x2, x3); + bcindexmatrix(x1, x2, x3) = SOLID; } ////////////////////////////////////////////////////////////////////////// void BCArray3D::setFluid(std::size_t x1, std::size_t x2, std::size_t x3) { - if (this->hasBC(x1, x2, x3)) this->deleteBC(x1, x2, x3); - bcindexmatrix(x1, x2, x3) = FLUID; + if (this->hasBC(x1, x2, x3)) + this->deleteBC(x1, x2, x3); + bcindexmatrix(x1, x2, x3) = FLUID; } ////////////////////////////////////////////////////////////////////////// void BCArray3D::setUndefined(std::size_t x1, std::size_t x2, std::size_t x3) { - if (this->hasBC(x1, x2, x3)) this->deleteBC(x1, x2, x3); - bcindexmatrix(x1, x2, x3) = UNDEFINED; + if (this->hasBC(x1, x2, x3)) + this->deleteBC(x1, x2, x3); + bcindexmatrix(x1, x2, x3) = UNDEFINED; } ////////////////////////////////////////////////////////////////////////// std::size_t BCArray3D::getNumberOfSolidEntries() const { - const std::vector<int>& data = bcindexmatrix.getDataVector(); - std::size_t counter = 0; - for (std::size_t i = 0; i < data.size(); i++) - if (data[i] == SOLID) counter++; - return counter; + const std::vector<int> &data = bcindexmatrix.getDataVector(); + std::size_t counter = 0; + for (std::size_t i = 0; i < data.size(); i++) + if (data[i] == SOLID) + counter++; + return counter; } ////////////////////////////////////////////////////////////////////////// std::size_t BCArray3D::getNumberOfFluidEntries() const { - const std::vector<int>& data = bcindexmatrix.getDataVector(); - std::size_t counter = 0; - for (std::size_t i = 0; i < data.size(); i++) - { - int tmp = data[i]; - if (tmp == FLUID || tmp >= 0) counter++; - } - return counter; + const std::vector<int> &data = bcindexmatrix.getDataVector(); + std::size_t counter = 0; + for (std::size_t i = 0; i < data.size(); i++) { + int tmp = data[i]; + if (tmp == FLUID || tmp >= 0) + counter++; + } + return counter; } ////////////////////////////////////////////////////////////////////////// std::size_t BCArray3D::getNumberOfFluidWithoutBCEntries() const { - const std::vector<int>& data = bcindexmatrix.getDataVector(); - std::size_t counter = 0; - for (std::size_t i = 0; i < data.size(); i++) - if (data[i] == FLUID) counter++; - return counter; + const std::vector<int> &data = bcindexmatrix.getDataVector(); + std::size_t counter = 0; + for (std::size_t i = 0; i < data.size(); i++) + if (data[i] == FLUID) + counter++; + return counter; } ////////////////////////////////////////////////////////////////////////// std::size_t BCArray3D::getNumberOfBCEntries() const { - const std::vector<int>& data = bcindexmatrix.getDataVector(); - std::size_t counter = 0; - for (std::size_t i = 0; i < data.size(); i++) - if (data[i] >= 0) counter++; - return counter; + const std::vector<int> &data = bcindexmatrix.getDataVector(); + std::size_t counter = 0; + for (std::size_t i = 0; i < data.size(); i++) + if (data[i] >= 0) + counter++; + return counter; } ////////////////////////////////////////////////////////////////////////// std::size_t BCArray3D::getNumberOfUndefinedEntries() const { - const std::vector<int>& data = bcindexmatrix.getDataVector(); - std::size_t counter = 0; - for (std::size_t i = 0; i < data.size(); i++) - if (data[i] == UNDEFINED) counter++; - return counter; + const std::vector<int> &data = bcindexmatrix.getDataVector(); + std::size_t counter = 0; + for (std::size_t i = 0; i < data.size(); i++) + if (data[i] == UNDEFINED) + counter++; + return counter; } ////////////////////////////////////////////////////////////////////////// -std::size_t BCArray3D::getBCVectorSize() const -{ - return this->bcvector.size(); -} +std::size_t BCArray3D::getBCVectorSize() const { return this->bcvector.size(); } ////////////////////////////////////////////////////////////////////////// std::string BCArray3D::toString() const { - std::size_t solidCounter = 0; - std::size_t fluidCounter = 0; - std::size_t bcCounter = 0; - std::size_t undefCounter = 0; + std::size_t solidCounter = 0; + std::size_t fluidCounter = 0; + std::size_t bcCounter = 0; + std::size_t undefCounter = 0; - for (size_t x1 = 0; x1 < bcindexmatrix.getNX1(); x1++) - { - for (size_t x2 = 0; x2 < bcindexmatrix.getNX2(); x2++) - { - for (size_t x3 = 0; x3 < bcindexmatrix.getNX3(); x3++) - { - if (bcindexmatrix(x1, x2, x3) >= 0) bcCounter++; - else if (bcindexmatrix(x1, x2, x3) == FLUID) fluidCounter++; - else if (bcindexmatrix(x1, x2, x3) == SOLID) solidCounter++; - else if (bcindexmatrix(x1, x2, x3) == UNDEFINED) undefCounter++; - else throw UbException(UB_EXARGS, "invalid matrixEntry"); - } - } - } + for (size_t x1 = 0; x1 < bcindexmatrix.getNX1(); x1++) { + for (size_t x2 = 0; x2 < bcindexmatrix.getNX2(); x2++) { + for (size_t x3 = 0; x3 < bcindexmatrix.getNX3(); x3++) { + if (bcindexmatrix(x1, x2, x3) >= 0) + bcCounter++; + else if (bcindexmatrix(x1, x2, x3) == FLUID) + fluidCounter++; + else if (bcindexmatrix(x1, x2, x3) == SOLID) + solidCounter++; + else if (bcindexmatrix(x1, x2, x3) == UNDEFINED) + undefCounter++; + else + throw UbException(UB_EXARGS, "invalid matrixEntry"); + } + } + } - std::size_t unrefEntriesInBcVector = 0; - for (std::size_t i = 0; i < bcvector.size(); i++) if (!bcvector[i]) unrefEntriesInBcVector++; + std::size_t unrefEntriesInBcVector = 0; + for (std::size_t i = 0; i < bcvector.size(); i++) + if (!bcvector[i]) + unrefEntriesInBcVector++; - std::stringstream text; - text << "BCArray<" << typeid(SPtr<BoundaryConditions>).name() << "," << typeid(int).name() << ">"; - text << "[ entries: " << bcindexmatrix.getNX1() << "x" << bcindexmatrix.getNX2(); - text << "x" << bcindexmatrix.getNX3() << "="; - text << bcindexmatrix.getNX1()*bcindexmatrix.getNX2()*bcindexmatrix.getNX3() << " ]:\n"; - text << " - #fluid entries : " << fluidCounter << std::endl; - text << " - #bc entries : " << bcCounter << std::endl; - text << " - #solid entries : " << solidCounter << std::endl; - text << " - #undef entries : " << undefCounter << std::endl; - text << " - bcvector-entries : " << bcvector.size() << " (empty ones: " << unrefEntriesInBcVector << ")\n"; - text << " - indexContainer-entries: " << indexContainer.size() << std::endl; + std::stringstream text; + text << "BCArray<" << typeid(SPtr<BoundaryConditions>).name() << "," << typeid(int).name() << ">"; + text << "[ entries: " << bcindexmatrix.getNX1() << "x" << bcindexmatrix.getNX2(); + text << "x" << bcindexmatrix.getNX3() << "="; + text << bcindexmatrix.getNX1() * bcindexmatrix.getNX2() * bcindexmatrix.getNX3() << " ]:\n"; + text << " - #fluid entries : " << fluidCounter << std::endl; + text << " - #bc entries : " << bcCounter << std::endl; + text << " - #solid entries : " << solidCounter << std::endl; + text << " - #undef entries : " << undefCounter << std::endl; + text << " - bcvector-entries : " << bcvector.size() << " (empty ones: " << unrefEntriesInBcVector << ")\n"; + text << " - indexContainer-entries: " << indexContainer.size() << std::endl; - return text.str(); + return text.str(); } ////////////////////////////////////////////////////////////////////////// -std::vector< int >& BCArray3D::getBcindexmatrixDataVector() -{ - return bcindexmatrix.getDataVector(); -} - +std::vector<int> &BCArray3D::getBcindexmatrixDataVector() { return bcindexmatrix.getDataVector(); } ////////////////////////////////////////////////////////////////////////// void BCArray3D::deleteBCAndSetType(std::size_t x1, std::size_t x2, std::size_t x3, int type) - { - this->deleteBC(x1, x2, x3); +{ + this->deleteBC(x1, x2, x3); - //Assign matrix to new type - bcindexmatrix(x1, x2, x3) = type; - } + // Assign matrix to new type + bcindexmatrix(x1, x2, x3) = type; +} ////////////////////////////////////////////////////////////////////////// void BCArray3D::deleteBC(std::size_t x1, std::size_t x2, std::size_t x3) - { - //check if BC exists at all - int index = bcindexmatrix(x1, x2, x3); - if (index < 0) return; +{ + // check if BC exists at all + int index = bcindexmatrix(x1, x2, x3); + if (index < 0) + return; - //slide the released index into the index container - indexContainer.push_back(index); + // slide the released index into the index container + indexContainer.push_back(index); - //"delete" element - bcvector[index] = SPtr<BoundaryConditions>(); - } - \ No newline at end of file + //"delete" element + bcvector[index] = SPtr<BoundaryConditions>(); +} diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.h index a189737f0..835e5b1c9 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCArray3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -41,108 +41,107 @@ #include <PointerDefinitions.h> -//! A class implements array to store boundary conditions flags +//! A class implements array to store boundary conditions flags class BCArray3D { public: - ////////////////////////////////////////////////////////////////////////// - BCArray3D(); - ////////////////////////////////////////////////////////////////////////// - BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3); - ////////////////////////////////////////////////////////////////////////// - BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val); - ////////////////////////////////////////////////////////////////////////// - virtual ~BCArray3D(); - ////////////////////////////////////////////////////////////////////////// - inline std::size_t getNX1() const; - ////////////////////////////////////////////////////////////////////////// - inline std::size_t getNX2() const; - ////////////////////////////////////////////////////////////////////////// - inline std::size_t getNX3() const; - ////////////////////////////////////////////////////////////////////////// - void resize(std::size_t nx1, std::size_t nx2, std::size_t nx3); - ////////////////////////////////////////////////////////////////////////// - void resize(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val); - ////////////////////////////////////////////////////////////////////////// - bool validIndices(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - inline bool hasBC(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - void setBC(std::size_t x1, std::size_t x2, std::size_t x3, SPtr<BoundaryConditions> const& bc); - ////////////////////////////////////////////////////////////////////////// - inline int getBCVectorIndex(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - inline const SPtr<BoundaryConditions> getBC(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - inline SPtr<BoundaryConditions> getBC(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - void setSolid(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - inline bool isSolid(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - void setFluid(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - //true : FLUID or BC - //false: UNDEFINED or SOLID - inline bool isFluid(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - inline bool isFluidWithoutBC(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - inline bool isUndefined(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - void setUndefined(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - inline bool isInterfaceCF(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - void setInterfaceCF(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - inline bool isInterfaceFC(std::size_t x1, std::size_t x2, std::size_t x3) const; - ////////////////////////////////////////////////////////////////////////// - void setInterfaceFC(std::size_t x1, std::size_t x2, std::size_t x3); - ////////////////////////////////////////////////////////////////////////// - std::size_t getNumberOfSolidEntries() const; - ////////////////////////////////////////////////////////////////////////// - std::size_t getNumberOfFluidEntries() const; - ////////////////////////////////////////////////////////////////////////// - std::size_t getNumberOfFluidWithoutBCEntries() const; - ////////////////////////////////////////////////////////////////////////// - std::size_t getNumberOfBCEntries() const; - ////////////////////////////////////////////////////////////////////////// - std::size_t getNumberOfUndefinedEntries() const; - ////////////////////////////////////////////////////////////////////////// - std::size_t getBCVectorSize() const; - ////////////////////////////////////////////////////////////////////////// - std::string toString() const; - ////////////////////////////////////////////////////////////////////////// - std::vector< int >& getBcindexmatrixDataVector(); - ////////////////////////////////////////////////////////////////////////// - bool isInsideOfDomain(const int &x1, const int &x2, const int &x3, const int& ghostLayerWidth) const; + ////////////////////////////////////////////////////////////////////////// + BCArray3D(); + ////////////////////////////////////////////////////////////////////////// + BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3); + ////////////////////////////////////////////////////////////////////////// + BCArray3D(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val); + ////////////////////////////////////////////////////////////////////////// + virtual ~BCArray3D(); + ////////////////////////////////////////////////////////////////////////// + inline std::size_t getNX1() const; + ////////////////////////////////////////////////////////////////////////// + inline std::size_t getNX2() const; + ////////////////////////////////////////////////////////////////////////// + inline std::size_t getNX3() const; + ////////////////////////////////////////////////////////////////////////// + void resize(std::size_t nx1, std::size_t nx2, std::size_t nx3); + ////////////////////////////////////////////////////////////////////////// + void resize(std::size_t nx1, std::size_t nx2, std::size_t nx3, int val); + ////////////////////////////////////////////////////////////////////////// + bool validIndices(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + inline bool hasBC(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + void setBC(std::size_t x1, std::size_t x2, std::size_t x3, SPtr<BoundaryConditions> const &bc); + ////////////////////////////////////////////////////////////////////////// + inline int getBCVectorIndex(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + inline const SPtr<BoundaryConditions> getBC(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + inline SPtr<BoundaryConditions> getBC(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + void setSolid(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + inline bool isSolid(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + void setFluid(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + // true : FLUID or BC + // false: UNDEFINED or SOLID + inline bool isFluid(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + inline bool isFluidWithoutBC(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + inline bool isUndefined(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + void setUndefined(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + inline bool isInterfaceCF(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + void setInterfaceCF(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + inline bool isInterfaceFC(std::size_t x1, std::size_t x2, std::size_t x3) const; + ////////////////////////////////////////////////////////////////////////// + void setInterfaceFC(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + std::size_t getNumberOfSolidEntries() const; + ////////////////////////////////////////////////////////////////////////// + std::size_t getNumberOfFluidEntries() const; + ////////////////////////////////////////////////////////////////////////// + std::size_t getNumberOfFluidWithoutBCEntries() const; + ////////////////////////////////////////////////////////////////////////// + std::size_t getNumberOfBCEntries() const; + ////////////////////////////////////////////////////////////////////////// + std::size_t getNumberOfUndefinedEntries() const; + ////////////////////////////////////////////////////////////////////////// + std::size_t getBCVectorSize() const; + ////////////////////////////////////////////////////////////////////////// + std::string toString() const; + ////////////////////////////////////////////////////////////////////////// + std::vector<int> &getBcindexmatrixDataVector(); + ////////////////////////////////////////////////////////////////////////// + bool isInsideOfDomain(const int &x1, const int &x2, const int &x3, const int &ghostLayerWidth) const; - static const int SOLID; - static const int FLUID; - static const int INTERFACECF; - static const int INTERFACEFC; - static const int UNDEFINED; + static const int SOLID; + static const int FLUID; + static const int INTERFACECF; + static const int INTERFACEFC; + static const int UNDEFINED; private: - ////////////////////////////////////////////////////////////////////////// - void deleteBCAndSetType(std::size_t x1, std::size_t x2, std::size_t x3, int type); - ////////////////////////////////////////////////////////////////////////// - void deleteBC(std::size_t x1, std::size_t x2, std::size_t x3); + ////////////////////////////////////////////////////////////////////////// + void deleteBCAndSetType(std::size_t x1, std::size_t x2, std::size_t x3, int type); + ////////////////////////////////////////////////////////////////////////// + void deleteBC(std::size_t x1, std::size_t x2, std::size_t x3); - friend class MPIIORestartCoProcessor; - friend class MPIIOMigrationCoProcessor; - friend class MPIIOMigrationBECoProcessor; + friend class MPIIORestartCoProcessor; + friend class MPIIOMigrationCoProcessor; + friend class MPIIOMigrationBECoProcessor; protected: - ////////////////////////////////////////////////////////////////////////// - //-1 solid // -2 fluid -... - CbArray3D<int, IndexerX3X2X1> bcindexmatrix; - std::vector<SPtr<BoundaryConditions>> bcvector; - std::vector<int> indexContainer; + ////////////////////////////////////////////////////////////////////////// + //-1 solid // -2 fluid -... + CbArray3D<int, IndexerX3X2X1> bcindexmatrix; + std::vector<SPtr<BoundaryConditions>> bcvector; + std::vector<int> indexContainer; }; - ////////////////////////////////////////////////////////////////////////// inline std::size_t BCArray3D::getNX1() const { return bcindexmatrix.getNX1(); } ////////////////////////////////////////////////////////////////////////// @@ -150,66 +149,68 @@ inline std::size_t BCArray3D::getNX2() const { return bcindexmatrix.getNX2(); } ////////////////////////////////////////////////////////////////////////// inline std::size_t BCArray3D::getNX3() const { return bcindexmatrix.getNX3(); } ////////////////////////////////////////////////////////////////////////// -inline bool BCArray3D::hasBC(std::size_t x1, std::size_t x2, std::size_t x3) const +inline bool BCArray3D::hasBC(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) >= 0; + return bcindexmatrix(x1, x2, x3) >= 0; } ////////////////////////////////////////////////////////////////////////// inline int BCArray3D::getBCVectorIndex(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3); + return bcindexmatrix(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -inline const SPtr<BoundaryConditions> BCArray3D::getBC(std::size_t x1, std::size_t x2, std::size_t x3) const +inline const SPtr<BoundaryConditions> BCArray3D::getBC(std::size_t x1, std::size_t x2, std::size_t x3) const { - int index = bcindexmatrix(x1, x2, x3); - if (index < 0) return SPtr<BoundaryConditions>(); //=> NULL Pointer + int index = bcindexmatrix(x1, x2, x3); + if (index < 0) + return SPtr<BoundaryConditions>(); //=> NULL Pointer - return bcvector[index]; + return bcvector[index]; } ////////////////////////////////////////////////////////////////////////// inline SPtr<BoundaryConditions> BCArray3D::getBC(std::size_t x1, std::size_t x2, std::size_t x3) { - int index = bcindexmatrix(x1, x2, x3); - if (index < 0) return SPtr<BoundaryConditions>(); //=> NULL Pointer + int index = bcindexmatrix(x1, x2, x3); + if (index < 0) + return SPtr<BoundaryConditions>(); //=> NULL Pointer - return bcvector[index]; + return bcvector[index]; } ////////////////////////////////////////////////////////////////////////// inline bool BCArray3D::isSolid(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) == SOLID; + return bcindexmatrix(x1, x2, x3) == SOLID; } ////////////////////////////////////////////////////////////////////////// -//true : FLUID or BC -//false: UNDEFINED or SOLID +// true : FLUID or BC +// false: UNDEFINED or SOLID inline bool BCArray3D::isFluid(std::size_t x1, std::size_t x2, std::size_t x3) const { - int tmp = bcindexmatrix(x1, x2, x3); - return (tmp == FLUID || tmp >= 0); + int tmp = bcindexmatrix(x1, x2, x3); + return (tmp == FLUID || tmp >= 0); } ////////////////////////////////////////////////////////////////////////// inline bool BCArray3D::isFluidWithoutBC(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) == FLUID; + return bcindexmatrix(x1, x2, x3) == FLUID; } ////////////////////////////////////////////////////////////////////////// inline bool BCArray3D::isUndefined(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) == UNDEFINED; + return bcindexmatrix(x1, x2, x3) == UNDEFINED; } ////////////////////////////////////////////////////////////////////////// inline bool BCArray3D::isInterfaceCF(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) == INTERFACECF; + return bcindexmatrix(x1, x2, x3) == INTERFACECF; } ////////////////////////////////////////////////////////////////////////// inline bool BCArray3D::isInterfaceFC(std::size_t x1, std::size_t x2, std::size_t x3) const { - return bcindexmatrix(x1, x2, x3) == INTERFACEFC; + return bcindexmatrix(x1, x2, x3) == INTERFACEFC; } ////////////////////////////////////////////////////////////////////////// -inline bool BCArray3D::isInsideOfDomain(const int& x1, const int& x2, const int& x3, const int& ghostLayerWidth) const +inline bool BCArray3D::isInsideOfDomain(const int &x1, const int &x2, const int &x3, const int &ghostLayerWidth) const { const int minX1 = ghostLayerWidth; const int maxX1 = (int)this->getNX1() - 1 - ghostLayerWidth; @@ -221,4 +222,4 @@ inline bool BCArray3D::isInsideOfDomain(const int& x1, const int& x2, const int& return (!(x1 < minX1 || x1 > maxX1 || x2 < minX2 || x2 > maxX2 || x3 < minX3 || x3 > maxX3)); } -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.cpp index 34c536c8e..781958f85 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,4 +35,3 @@ const double BCFunction::INFTIMEDEPENDENT = -1.0; const double BCFunction::INFCONST = -10.0; - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h index 96102f82a..cf1a5a578 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCFunction.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,76 +38,81 @@ #include <muParser.h> -//! A class implements function parcer for boundary conditions +//! A class implements function parcer for boundary conditions class BCFunction { public: - static const double INFTIMEDEPENDENT; - static const double INFCONST; + static const double INFTIMEDEPENDENT; + static const double INFCONST; public: - BCFunction() - : starttime(-Ub::inf ), endtime(-Ub::inf ) - { - - } - BCFunction( const mu::Parser& function, const double& starttime, const double& endtime ) - : function(function), starttime(starttime), endtime(endtime) - { + BCFunction() : starttime(-Ub::inf), endtime(-Ub::inf) {} + BCFunction(const mu::Parser &function, const double &starttime, const double &endtime) + : function(function), starttime(starttime), endtime(endtime) + { + } + BCFunction(const std::string &functionstring, const double &starttime, const double &endtime) + : starttime(starttime), endtime(endtime) + { + this->setFunction(functionstring); + } + BCFunction(const double &velocity, const double &starttime, const double &endtime) + : starttime(starttime), endtime(endtime) + { + this->setFunction(velocity); + } - } - BCFunction( const std::string& functionstring, const double& starttime, const double& endtime ) - : starttime(starttime), endtime(endtime) - { - this->setFunction(functionstring); - } - BCFunction( const double& velocity, const double& starttime, const double& endtime ) - : starttime(starttime), endtime(endtime) - { - this->setFunction(velocity); - } + void setFunction(const mu::Parser &function) { this->function = function; } + void setFunction(const std::string &functionstring) { this->function.SetExpr(functionstring); } + void setFunction(const double &constVelocity) + { + std::stringstream dummy; + dummy << constVelocity; + function.SetExpr(dummy.str()); + } + void setStartTime(const double &starttime) { this->starttime = starttime; } + void setEndTime(const double &endtime) { this->endtime = endtime; } - void setFunction(const mu::Parser& function) { this->function = function; } - void setFunction(const std::string& functionstring) { this->function.SetExpr(functionstring); } - void setFunction(const double& constVelocity) { std::stringstream dummy; dummy<<constVelocity; function.SetExpr(dummy.str()); } - void setStartTime(const double& starttime) {this->starttime = starttime; } - void setEndTime(const double& endtime) {this->endtime = endtime; } + mu::Parser &getFunction() { return function; } + const mu::Parser &getFunction() const { return function; } + const double &getStartTime() const { return starttime; } + const double &getEndTime() const { return endtime; } - mu::Parser& getFunction() { return function; } - const mu::Parser& getFunction() const { return function; } - const double& getStartTime() const { return starttime; } - const double& getEndTime() const { return endtime; } - - std::string toString() const - { - std::stringstream info; - if (starttime==INFTIMEDEPENDENT) info<<"start=inf. timedep., "; - else if(starttime==INFCONST ) info<<"start=inf. const., "; - else info<<"start="<<starttime<<", "; - if (endtime==INFTIMEDEPENDENT) info<<"end=inf. timedep."<<std::endl; - else if(endtime==INFCONST ) info<<"end=inf. const."<<std::endl; - else info<<"end="<<endtime<<std::endl; - info<<"expr="<<function.GetExpr()<<std::endl; - info<<"with constants: "; - mu::valmap_type cmap = function.GetConst(); - for(mu::valmap_type::const_iterator item = cmap.begin(); item!=cmap.end(); ++item) - info<<item->first<<"="<<item->second<<", "; - return info.str(); - } - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, const BCFunction& bc) - { - os<<bc.toString(); - return os; - } + std::string toString() const + { + std::stringstream info; + if (starttime == INFTIMEDEPENDENT) + info << "start=inf. timedep., "; + else if (starttime == INFCONST) + info << "start=inf. const., "; + else + info << "start=" << starttime << ", "; + if (endtime == INFTIMEDEPENDENT) + info << "end=inf. timedep." << std::endl; + else if (endtime == INFCONST) + info << "end=inf. const." << std::endl; + else + info << "end=" << endtime << std::endl; + info << "expr=" << function.GetExpr() << std::endl; + info << "with constants: "; + mu::valmap_type cmap = function.GetConst(); + for (mu::valmap_type::const_iterator item = cmap.begin(); item != cmap.end(); ++item) + info << item->first << "=" << item->second << ", "; + return info.str(); + } + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, const BCFunction &bc) + { + os << bc.toString(); + return os; + } protected: - mu::Parser function; - double starttime; - double endtime; + mu::Parser function; + double starttime; + double endtime; private: - }; -#endif //D3Q27BCFUNCTION_H +#endif // D3Q27BCFUNCTION_H diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.cpp index 020f4d60d..de647a842 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,56 +32,47 @@ //======================================================================================= #include "BCProcessor.h" +#include "BCAlgorithm.h" +#include "BCArray3D.h" #include "D3Q27EsoTwist3DSplittedVector.h" #include "DataSet3D.h" #include "ILBMKernel.h" -#include "BCArray3D.h" -#include "BCAlgorithm.h" -BCProcessor::BCProcessor() -= default; +BCProcessor::BCProcessor() = default; ////////////////////////////////////////////////////////////////////////// BCProcessor::BCProcessor(SPtr<ILBMKernel> kernel) { - SPtr<DistributionArray3D> distributions = std::dynamic_pointer_cast<EsoTwist3D>(kernel->getDataSet()->getFdistributions()); - bcArray = std::make_shared<BCArray3D>(distributions->getNX1(), distributions->getNX2(), distributions->getNX3(), BCArray3D::FLUID); + SPtr<DistributionArray3D> distributions = + std::dynamic_pointer_cast<EsoTwist3D>(kernel->getDataSet()->getFdistributions()); + bcArray = std::make_shared<BCArray3D>(distributions->getNX1(), distributions->getNX2(), distributions->getNX3(), + BCArray3D::FLUID); } ////////////////////////////////////////////////////////////////////////// -BCProcessor::~BCProcessor() -= default; +BCProcessor::~BCProcessor() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCProcessor> BCProcessor::clone(SPtr<ILBMKernel> kernel) { - SPtr<BCProcessor> bcProcessor(new BCProcessor(kernel)); - return bcProcessor; + SPtr<BCProcessor> bcProcessor(new BCProcessor(kernel)); + return bcProcessor; } ////////////////////////////////////////////////////////////////////////// -SPtr<BCArray3D> BCProcessor::getBCArray() -{ - return bcArray; -} +SPtr<BCArray3D> BCProcessor::getBCArray() { return bcArray; } ////////////////////////////////////////////////////////////////////////// -void BCProcessor::setBCArray(SPtr<BCArray3D> bcarray) -{ - bcArray = bcarray; -} +void BCProcessor::setBCArray(SPtr<BCArray3D> bcarray) { bcArray = bcarray; } ////////////////////////////////////////////////////////////////////////// void BCProcessor::addBC(SPtr<BCAlgorithm> bc) { - if (bc->isPreCollision()) - { - preBC.push_back(bc); - } - else - { - postBC.push_back(bc); - } + if (bc->isPreCollision()) { + preBC.push_back(bc); + } else { + postBC.push_back(bc); + } } ////////////////////////////////////////////////////////////////////////// void BCProcessor::applyPreCollisionBC() { - for(SPtr<BCAlgorithm> bc : preBC) - bc->applyBC(); + for (SPtr<BCAlgorithm> bc : preBC) + bc->applyBC(); } ////////////////////////////////////////////////////////////////////////// void BCProcessor::applyPostCollisionBC() @@ -92,7 +83,6 @@ void BCProcessor::applyPostCollisionBC() ////////////////////////////////////////////////////////////////////////// void BCProcessor::clearBC() { - preBC.clear(); - postBC.clear(); + preBC.clear(); + postBC.clear(); } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.h index 4c3f66ac2..266307305 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BCProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -41,28 +41,28 @@ class BCArray3D; class BCAlgorithm; class ILBMKernel; -//! A class provides an interface for boundary conditions in the calculation loop. +//! A class provides an interface for boundary conditions in the calculation loop. class BCProcessor { public: - BCProcessor(); - BCProcessor(SPtr<ILBMKernel> kernel); - virtual ~BCProcessor(); - virtual SPtr<BCArray3D> getBCArray(); - virtual void setBCArray(SPtr<BCArray3D> bcarray); - virtual SPtr<BCProcessor> clone(SPtr<ILBMKernel> kernel); + BCProcessor(); + BCProcessor(SPtr<ILBMKernel> kernel); + virtual ~BCProcessor(); + virtual SPtr<BCArray3D> getBCArray(); + virtual void setBCArray(SPtr<BCArray3D> bcarray); + virtual SPtr<BCProcessor> clone(SPtr<ILBMKernel> kernel); + + void addBC(SPtr<BCAlgorithm> bc); + void applyPreCollisionBC(); + void applyPostCollisionBC(); + void clearBC(); - void addBC(SPtr<BCAlgorithm> bc); - void applyPreCollisionBC(); - void applyPostCollisionBC(); - void clearBC(); protected: - std::vector<SPtr<BCAlgorithm> > preBC; - std::vector<SPtr<BCAlgorithm> > postBC; - SPtr<BCArray3D> bcArray; + std::vector<SPtr<BCAlgorithm>> preBC; + std::vector<SPtr<BCAlgorithm>> postBC; + SPtr<BCArray3D> bcArray; private: - }; #endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.cpp index 23ffad85e..d66094dcc 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,5 +33,4 @@ #include "BoundaryConditions.h" -const long long BoundaryConditions::maxOptionVal = ( 1<<optionDigits ) - 1; //2^3-1 -> 7 - +const long long BoundaryConditions::maxOptionVal = (1 << optionDigits) - 1; // 2^3-1 -> 7 diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.h index 1f740776e..886d1ee2d 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/BoundaryConditions.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,240 +33,336 @@ #ifndef BoundaryConditions_H #define BoundaryConditions_H -#include <vector> #include <string> +#include <vector> -#include "Vector3D.h" -#include "UbException.h" +#include "D3Q27System.h" +#include "UbException.h" #include "UbSystem.h" #include "UbTuple.h" -#include "D3Q27System.h" +#include "Vector3D.h" #include <PointerDefinitions.h> //! Difenition of baundary conditions in grid generation -class BoundaryConditions +class BoundaryConditions { public: - BoundaryConditions() - - { - UB_STATIC_ASSERT( sizeof(long long) >= 8); - UB_STATIC_ASSERT( (sizeof(long long)*8) >= (D3Q27System::FENDDIR+1)*BoundaryConditions::optionDigits ); + BoundaryConditions() + + { + UB_STATIC_ASSERT(sizeof(long long) >= 8); + UB_STATIC_ASSERT((sizeof(long long) * 8) >= (D3Q27System::FENDDIR + 1) * BoundaryConditions::optionDigits); + + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) + q[fdir] = -999.; + } + virtual ~BoundaryConditions() = default; - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - q[fdir] = -999.; - } - virtual ~BoundaryConditions() = default; + virtual bool isEmpty() + { + return (noslipBoundaryFlags & slipBoundaryFlags & velocityBoundaryFlags & densityBoundaryFlags) == 0; + } + virtual bool hasBoundaryCondition() + { + return (hasNoSlipBoundary() || hasSlipBoundary() || hasDensityBoundary() || hasVelocityBoundary() || + hasWallModelBoundary()); + } - virtual bool isEmpty() { return (noslipBoundaryFlags&slipBoundaryFlags&velocityBoundaryFlags&densityBoundaryFlags)==0;} - virtual bool hasBoundaryCondition() - { - return ( hasNoSlipBoundary() || hasSlipBoundary() - || hasDensityBoundary() || hasVelocityBoundary() || hasWallModelBoundary() ); - } + virtual bool hasBoundaryConditionFlag(const int &direction) + { + assert(direction >= D3Q27System::FSTARTDIR && direction <= D3Q27System::FENDDIR); - virtual bool hasBoundaryConditionFlag(const int& direction) - { - assert( direction >= D3Q27System::FSTARTDIR && direction <= D3Q27System::FENDDIR ); + return (hasNoSlipBoundaryFlag(direction) || hasSlipBoundaryFlag(direction) || + hasDensityBoundaryFlag(direction) || hasVelocityBoundaryFlag(direction) || + hasWallModelBoundaryFlag(direction)); + } - return ( hasNoSlipBoundaryFlag(direction) || hasSlipBoundaryFlag(direction) - || hasDensityBoundaryFlag(direction) || hasVelocityBoundaryFlag(direction) || hasWallModelBoundaryFlag(direction)); - } protected: - void setFlagBits(long long& flag, const int& direction, const short& secOpt) - { - if( (secOpt+1)>maxOptionVal ) - throw UbException(UB_EXARGS,"error: option > "+UbSystem::toString(maxOptionVal-1)); - - //all digits at the respective positions to "0" - flag &= ~( maxOptionVal<<(direction*optionDigits) ); - //set all digits according to the flag at the respective positions - flag |= ((long long)(secOpt+1)<<(direction*optionDigits)); - } + void setFlagBits(long long &flag, const int &direction, const short &secOpt) + { + if ((secOpt + 1) > maxOptionVal) + throw UbException(UB_EXARGS, "error: option > " + UbSystem::toString(maxOptionVal - 1)); + + // all digits at the respective positions to "0" + flag &= ~(maxOptionVal << (direction * optionDigits)); + // set all digits according to the flag at the respective positions + flag |= ((long long)(secOpt + 1) << (direction * optionDigits)); + } + public: - /*===================== NoSlip Boundary ==================================================*/ - void setNoSlipBoundaryFlag(const int& direction, const short& secOpt=0) { this->setFlagBits(noslipBoundaryFlags,direction,secOpt); } - void unsetNoSlipBoundaryFlag(const int& direction) { this->noslipBoundaryFlags &= ~( maxOptionVal<<(direction*optionDigits) ); } - void unsetNoSlipBoundary() { this->noslipBoundaryFlags = 0; } - long long getNoSlipBoundary() { return this->noslipBoundaryFlags; } - bool hasNoSlipBoundary() { return (noslipBoundaryFlags!=0); } - bool hasNoSlipBoundaryFlag(const int& direction) { return ( ( ( noslipBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) != 0); } - short getNoSlipSecondaryOption(const int& direction) { return (short)( ( ( noslipBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) - 1 ); } - /*===================== WallModel Boundary ==================================================*/ - void setWallModelBoundaryFlag(const int& direction, const short& secOpt=0) { this->setFlagBits(wallModelBoundaryFlags,direction,secOpt); } - void unsetWallModelBoundaryFlag(const int& direction) { this->wallModelBoundaryFlags &= ~( maxOptionVal<<(direction*optionDigits) ); } - void unsetWallModelBoundary() { this->wallModelBoundaryFlags = 0; } - long long getWallModelBoundary() { return this->wallModelBoundaryFlags; } - bool hasWallModelBoundary() { return (wallModelBoundaryFlags!=0); } - bool hasWallModelBoundaryFlag(const int& direction) { return ( ( ( wallModelBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) != 0); } - short getWallModelSecondaryOption(const int& direction) { return (short)( ( ( wallModelBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) - 1 ); } - /*===================== Slip-Solid Boundary ==================================================*/ - void setSlipBoundaryFlag(const int& direction, const short& secOpt=0) { this->setFlagBits(slipBoundaryFlags,direction,secOpt); } - void unsetSlipBoundaryFlag(const int& direction) { this->slipBoundaryFlags &= ~( maxOptionVal<<(direction*optionDigits) ); } - void unsetSlipBoundary() { this->slipBoundaryFlags = 0; } - long long getSlipBoundary() { return this->slipBoundaryFlags; } - bool hasSlipBoundary() { return (slipBoundaryFlags!=0); } - bool hasSlipBoundaryFlag(const int& direction) { return ( ( ( slipBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) != 0); } - short getSlipSecondaryOption(const int& direction) { return (short)( ( ( slipBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) - 1 ); } - void setNormalVector(const LBMReal& nx1,const LBMReal& nx2,const LBMReal& nx3) { this->nx1 = nx1; this->nx2 = nx2; this->nx3 = nx3;} - UbTupleDouble3 getNormalVector() { return makeUbTuple(nx1,nx2,nx3); } + /*===================== NoSlip Boundary ==================================================*/ + void setNoSlipBoundaryFlag(const int &direction, const short &secOpt = 0) + { + this->setFlagBits(noslipBoundaryFlags, direction, secOpt); + } + void unsetNoSlipBoundaryFlag(const int &direction) + { + this->noslipBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits)); + } + void unsetNoSlipBoundary() { this->noslipBoundaryFlags = 0; } + long long getNoSlipBoundary() { return this->noslipBoundaryFlags; } + bool hasNoSlipBoundary() { return (noslipBoundaryFlags != 0); } + bool hasNoSlipBoundaryFlag(const int &direction) + { + return (((noslipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0); + } + short getNoSlipSecondaryOption(const int &direction) + { + return (short)(((noslipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1); + } + /*===================== WallModel Boundary ==================================================*/ + void setWallModelBoundaryFlag(const int &direction, const short &secOpt = 0) + { + this->setFlagBits(wallModelBoundaryFlags, direction, secOpt); + } + void unsetWallModelBoundaryFlag(const int &direction) + { + this->wallModelBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits)); + } + void unsetWallModelBoundary() { this->wallModelBoundaryFlags = 0; } + long long getWallModelBoundary() { return this->wallModelBoundaryFlags; } + bool hasWallModelBoundary() { return (wallModelBoundaryFlags != 0); } + bool hasWallModelBoundaryFlag(const int &direction) + { + return (((wallModelBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0); + } + short getWallModelSecondaryOption(const int &direction) + { + return (short)(((wallModelBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1); + } + /*===================== Slip-Solid Boundary ==================================================*/ + void setSlipBoundaryFlag(const int &direction, const short &secOpt = 0) + { + this->setFlagBits(slipBoundaryFlags, direction, secOpt); + } + void unsetSlipBoundaryFlag(const int &direction) + { + this->slipBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits)); + } + void unsetSlipBoundary() { this->slipBoundaryFlags = 0; } + long long getSlipBoundary() { return this->slipBoundaryFlags; } + bool hasSlipBoundary() { return (slipBoundaryFlags != 0); } + bool hasSlipBoundaryFlag(const int &direction) + { + return (((slipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0); + } + short getSlipSecondaryOption(const int &direction) + { + return (short)(((slipBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1); + } + void setNormalVector(const LBMReal &nx1, const LBMReal &nx2, const LBMReal &nx3) + { + this->nx1 = nx1; + this->nx2 = nx2; + this->nx3 = nx3; + } + UbTupleDouble3 getNormalVector() { return makeUbTuple(nx1, nx2, nx3); } - /*============== Velocity Boundary ========================*/ - void setVelocityBoundaryFlag(const int& direction, const short& secOpt=0) { this->setFlagBits(velocityBoundaryFlags,direction,secOpt); } - void unsetVelocityBoundaryFlag(const int& direction) { this->velocityBoundaryFlags &= ~( maxOptionVal<<(direction*optionDigits) ); } - void unsetVelocityBoundary() { this->velocityBoundaryFlags = 0; } - long long getVelocityBoundary() { return this->velocityBoundaryFlags; } - bool hasVelocityBoundary() { return this->velocityBoundaryFlags!=0; } - bool hasVelocityBoundaryFlag(const int& direction) { return ( ( ( velocityBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) != 0); } - short getVelocitySecondaryOption(const int& direction) { return (short)( ( ( velocityBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) - 1 ); } + /*============== Velocity Boundary ========================*/ + void setVelocityBoundaryFlag(const int &direction, const short &secOpt = 0) + { + this->setFlagBits(velocityBoundaryFlags, direction, secOpt); + } + void unsetVelocityBoundaryFlag(const int &direction) + { + this->velocityBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits)); + } + void unsetVelocityBoundary() { this->velocityBoundaryFlags = 0; } + long long getVelocityBoundary() { return this->velocityBoundaryFlags; } + bool hasVelocityBoundary() { return this->velocityBoundaryFlags != 0; } + bool hasVelocityBoundaryFlag(const int &direction) + { + return (((velocityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0); + } + short getVelocitySecondaryOption(const int &direction) + { + return (short)(((velocityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1); + } - void setBoundaryVelocity(const Vector3D& vx) + void setBoundaryVelocity(const Vector3D &vx) + { + setBoundaryVelocityX1((LBMReal)vx[0]); + setBoundaryVelocityX2((LBMReal)vx[1]); + setBoundaryVelocityX3((LBMReal)vx[2]); + } + void setBoundaryVelocityX1(const LBMReal &vx1) { this->bcVelocityX1 = vx1; } + void setBoundaryVelocityX2(const LBMReal &vx2) { this->bcVelocityX2 = vx2; } + void setBoundaryVelocityX3(const LBMReal &vx3) { this->bcVelocityX3 = vx3; } + LBMReal getBoundaryVelocityX1() { return this->bcVelocityX1; } + LBMReal getBoundaryVelocityX2() { return this->bcVelocityX2; } + LBMReal getBoundaryVelocityX3() { return this->bcVelocityX3; } + LBMReal getBoundaryVelocity(const int &direction) { - setBoundaryVelocityX1((LBMReal)vx[0]); - setBoundaryVelocityX2((LBMReal)vx[1]); - setBoundaryVelocityX3((LBMReal)vx[2]); - } - void setBoundaryVelocityX1(const LBMReal& vx1) { this->bcVelocityX1 = vx1; } - void setBoundaryVelocityX2(const LBMReal& vx2) { this->bcVelocityX2 = vx2; } - void setBoundaryVelocityX3(const LBMReal& vx3) { this->bcVelocityX3 = vx3; } - LBMReal getBoundaryVelocityX1() { return this->bcVelocityX1; } - LBMReal getBoundaryVelocityX2() { return this->bcVelocityX2; } - LBMReal getBoundaryVelocityX3() { return this->bcVelocityX3; } - LBMReal getBoundaryVelocity(const int& direction) - { - switch(direction) - { - case D3Q27System::E : return (LBMReal)( UbMath::c4o9*(+bcVelocityX1) ); //(2/cs^2)(=6)*rho_0(=1 for incompressible)*wi*u*ei with cs=1/sqrt(3) - case D3Q27System::W : return (LBMReal)( UbMath::c4o9*(-bcVelocityX1) ); - case D3Q27System::N : return (LBMReal)( UbMath::c4o9*(+bcVelocityX2) ); - case D3Q27System::S : return (LBMReal)( UbMath::c4o9*(-bcVelocityX2) ); - case D3Q27System::T : return (LBMReal)( UbMath::c4o9*(+bcVelocityX3) ); - case D3Q27System::B : return (LBMReal)( UbMath::c4o9*(-bcVelocityX3) ); - case D3Q27System::NE: return (LBMReal)( UbMath::c1o9*(+bcVelocityX1+bcVelocityX2 ) ); - case D3Q27System::SW: return (LBMReal)( UbMath::c1o9*(-bcVelocityX1-bcVelocityX2 ) ); - case D3Q27System::SE: return (LBMReal)( UbMath::c1o9*(+bcVelocityX1-bcVelocityX2 ) ); - case D3Q27System::NW: return (LBMReal)( UbMath::c1o9*(-bcVelocityX1+bcVelocityX2 ) ); - case D3Q27System::TE: return (LBMReal)( UbMath::c1o9*(+bcVelocityX1 +bcVelocityX3) ); - case D3Q27System::BW: return (LBMReal)( UbMath::c1o9*(-bcVelocityX1 -bcVelocityX3) ); - case D3Q27System::BE: return (LBMReal)( UbMath::c1o9*(+bcVelocityX1 -bcVelocityX3) ); - case D3Q27System::TW: return (LBMReal)( UbMath::c1o9*(-bcVelocityX1 +bcVelocityX3) ); - case D3Q27System::TN: return (LBMReal)( UbMath::c1o9*( +bcVelocityX2+bcVelocityX3) ); - case D3Q27System::BS: return (LBMReal)( UbMath::c1o9*( -bcVelocityX2-bcVelocityX3) ); - case D3Q27System::BN: return (LBMReal)( UbMath::c1o9*( +bcVelocityX2-bcVelocityX3) ); - case D3Q27System::TS: return (LBMReal)( UbMath::c1o9*( -bcVelocityX2+bcVelocityX3) ); - case D3Q27System::TNE: return (LBMReal)( UbMath::c1o36*(+bcVelocityX1+bcVelocityX2+bcVelocityX3) ); - case D3Q27System::BSW: return (LBMReal)( UbMath::c1o36*(-bcVelocityX1-bcVelocityX2-bcVelocityX3) ); - case D3Q27System::BNE: return (LBMReal)( UbMath::c1o36*(+bcVelocityX1+bcVelocityX2-bcVelocityX3) ); - case D3Q27System::TSW: return (LBMReal)( UbMath::c1o36*(-bcVelocityX1-bcVelocityX2+bcVelocityX3) ); - case D3Q27System::TSE: return (LBMReal)( UbMath::c1o36*(+bcVelocityX1-bcVelocityX2+bcVelocityX3) ); - case D3Q27System::BNW: return (LBMReal)( UbMath::c1o36*(-bcVelocityX1+bcVelocityX2-bcVelocityX3) ); - case D3Q27System::BSE: return (LBMReal)( UbMath::c1o36*(+bcVelocityX1-bcVelocityX2-bcVelocityX3) ); - case D3Q27System::TNW: return (LBMReal)( UbMath::c1o36*(-bcVelocityX1+bcVelocityX2+bcVelocityX3) ); - default: throw UbException(UB_EXARGS,"unknown error"); - } - } + switch (direction) { + case D3Q27System::E: + return (LBMReal)(UbMath::c4o9 * + (+bcVelocityX1)); //(2/cs^2)(=6)*rho_0(=1 for incompressible)*wi*u*ei with cs=1/sqrt(3) + case D3Q27System::W: + return (LBMReal)(UbMath::c4o9 * (-bcVelocityX1)); + case D3Q27System::N: + return (LBMReal)(UbMath::c4o9 * (+bcVelocityX2)); + case D3Q27System::S: + return (LBMReal)(UbMath::c4o9 * (-bcVelocityX2)); + case D3Q27System::T: + return (LBMReal)(UbMath::c4o9 * (+bcVelocityX3)); + case D3Q27System::B: + return (LBMReal)(UbMath::c4o9 * (-bcVelocityX3)); + case D3Q27System::NE: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX1 + bcVelocityX2)); + case D3Q27System::SW: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX1 - bcVelocityX2)); + case D3Q27System::SE: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX1 - bcVelocityX2)); + case D3Q27System::NW: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX1 + bcVelocityX2)); + case D3Q27System::TE: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX1 + bcVelocityX3)); + case D3Q27System::BW: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX1 - bcVelocityX3)); + case D3Q27System::BE: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX1 - bcVelocityX3)); + case D3Q27System::TW: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX1 + bcVelocityX3)); + case D3Q27System::TN: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX2 + bcVelocityX3)); + case D3Q27System::BS: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX2 - bcVelocityX3)); + case D3Q27System::BN: + return (LBMReal)(UbMath::c1o9 * (+bcVelocityX2 - bcVelocityX3)); + case D3Q27System::TS: + return (LBMReal)(UbMath::c1o9 * (-bcVelocityX2 + bcVelocityX3)); + case D3Q27System::TNE: + return (LBMReal)(UbMath::c1o36 * (+bcVelocityX1 + bcVelocityX2 + bcVelocityX3)); + case D3Q27System::BSW: + return (LBMReal)(UbMath::c1o36 * (-bcVelocityX1 - bcVelocityX2 - bcVelocityX3)); + case D3Q27System::BNE: + return (LBMReal)(UbMath::c1o36 * (+bcVelocityX1 + bcVelocityX2 - bcVelocityX3)); + case D3Q27System::TSW: + return (LBMReal)(UbMath::c1o36 * (-bcVelocityX1 - bcVelocityX2 + bcVelocityX3)); + case D3Q27System::TSE: + return (LBMReal)(UbMath::c1o36 * (+bcVelocityX1 - bcVelocityX2 + bcVelocityX3)); + case D3Q27System::BNW: + return (LBMReal)(UbMath::c1o36 * (-bcVelocityX1 + bcVelocityX2 - bcVelocityX3)); + case D3Q27System::BSE: + return (LBMReal)(UbMath::c1o36 * (+bcVelocityX1 - bcVelocityX2 - bcVelocityX3)); + case D3Q27System::TNW: + return (LBMReal)(UbMath::c1o36 * (-bcVelocityX1 + bcVelocityX2 + bcVelocityX3)); + default: + throw UbException(UB_EXARGS, "unknown error"); + } + } - /*============== Density Boundary ========================*/ - void setDensityBoundaryFlag(const int& direction, const short& secOpt=0) { this->setFlagBits(densityBoundaryFlags,direction,secOpt); } - void unsetDensityBoundaryFlag(const int& direction) { this->densityBoundaryFlags &= ~( maxOptionVal<<(direction*optionDigits) ); } - void unsetDensityBoundary() { this->densityBoundaryFlags = 0; } - long long getDensityBoundary() { return this->densityBoundaryFlags; } - bool hasDensityBoundary() { return (this->densityBoundaryFlags!=0); } - bool hasDensityBoundaryFlag(const int& direction) { return ( ( ( densityBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) != 0); } - short getDensitySecondaryOption(const int& direction) { return (short)( ( ( densityBoundaryFlags>>(optionDigits*direction) ) & maxOptionVal ) - 1 ); } + /*============== Density Boundary ========================*/ + void setDensityBoundaryFlag(const int &direction, const short &secOpt = 0) + { + this->setFlagBits(densityBoundaryFlags, direction, secOpt); + } + void unsetDensityBoundaryFlag(const int &direction) + { + this->densityBoundaryFlags &= ~(maxOptionVal << (direction * optionDigits)); + } + void unsetDensityBoundary() { this->densityBoundaryFlags = 0; } + long long getDensityBoundary() { return this->densityBoundaryFlags; } + bool hasDensityBoundary() { return (this->densityBoundaryFlags != 0); } + bool hasDensityBoundaryFlag(const int &direction) + { + return (((densityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) != 0); + } + short getDensitySecondaryOption(const int &direction) + { + return (short)(((densityBoundaryFlags >> (optionDigits * direction)) & maxOptionVal) - 1); + } - void setBoundaryDensity(LBMReal density) { this->bcDensity = density; } - LBMReal getBoundaryDensity() { return this->bcDensity; } + void setBoundaryDensity(LBMReal density) { this->bcDensity = density; } + LBMReal getBoundaryDensity() { return this->bcDensity; } - //Lodi extension - void setDensityLodiDensity(const LBMReal& bcLodiDensity) { this->bcLodiDensity = bcLodiDensity; } - void setDensityLodiVelocityX1(const LBMReal& bcLodiVelocityX1) { this->bcLodiVelocityX1 = bcLodiVelocityX1; } - void setDensityLodiVelocityX2(const LBMReal& bcLodiVelocityX2) { this->bcLodiVelocityX2 = bcLodiVelocityX2; } - void setDensityLodiVelocityX3(const LBMReal& bcLodiVelocityX3) { this->bcLodiVelocityX3 = bcLodiVelocityX3; } - void setDensityLodiLength(const LBMReal& bcLodiLentgh) { this->bcLodiLentgh = bcLodiLentgh; } - LBMReal getDensityLodiDensity() const { return this->bcLodiDensity; } - LBMReal getDensityLodiVelocityX1() const { return this->bcLodiVelocityX1; } - LBMReal getDensityLodiVelocityX2() const { return this->bcLodiVelocityX2; } - LBMReal getDensityLodiVelocityX3() const { return this->bcLodiVelocityX3; } - LBMReal getDensityLodiLength() const { return this->bcLodiLentgh; } + // Lodi extension + void setDensityLodiDensity(const LBMReal &bcLodiDensity) { this->bcLodiDensity = bcLodiDensity; } + void setDensityLodiVelocityX1(const LBMReal &bcLodiVelocityX1) { this->bcLodiVelocityX1 = bcLodiVelocityX1; } + void setDensityLodiVelocityX2(const LBMReal &bcLodiVelocityX2) { this->bcLodiVelocityX2 = bcLodiVelocityX2; } + void setDensityLodiVelocityX3(const LBMReal &bcLodiVelocityX3) { this->bcLodiVelocityX3 = bcLodiVelocityX3; } + void setDensityLodiLength(const LBMReal &bcLodiLentgh) { this->bcLodiLentgh = bcLodiLentgh; } + LBMReal getDensityLodiDensity() const { return this->bcLodiDensity; } + LBMReal getDensityLodiVelocityX1() const { return this->bcLodiVelocityX1; } + LBMReal getDensityLodiVelocityX2() const { return this->bcLodiVelocityX2; } + LBMReal getDensityLodiVelocityX3() const { return this->bcLodiVelocityX3; } + LBMReal getDensityLodiLength() const { return this->bcLodiLentgh; } - LBMReal& densityLodiDensity() { return this->bcLodiDensity; } - LBMReal& densityLodiVelocityX1() { return this->bcLodiVelocityX1; } - LBMReal& densityLodiVelocityX2() { return this->bcLodiVelocityX2; } - LBMReal& densityLodiVelocityX3() { return this->bcLodiVelocityX3; } - LBMReal& densityLodiLentgh() { return this->bcLodiLentgh; } + LBMReal &densityLodiDensity() { return this->bcLodiDensity; } + LBMReal &densityLodiVelocityX1() { return this->bcLodiVelocityX1; } + LBMReal &densityLodiVelocityX2() { return this->bcLodiVelocityX2; } + LBMReal &densityLodiVelocityX3() { return this->bcLodiVelocityX3; } + LBMReal &densityLodiLentgh() { return this->bcLodiLentgh; } - const LBMReal& densityLodiDensity() const { return this->bcLodiDensity; } - const LBMReal& densityLodiVelocityX1() const { return this->bcLodiVelocityX1; } - const LBMReal& densityLodiVelocityX2() const { return this->bcLodiVelocityX2; } - const LBMReal& densityLodiVelocityX3() const { return this->bcLodiVelocityX3; } - const LBMReal& densityLodiLentgh() const { return this->bcLodiLentgh; } + const LBMReal &densityLodiDensity() const { return this->bcLodiDensity; } + const LBMReal &densityLodiVelocityX1() const { return this->bcLodiVelocityX1; } + const LBMReal &densityLodiVelocityX2() const { return this->bcLodiVelocityX2; } + const LBMReal &densityLodiVelocityX3() const { return this->bcLodiVelocityX3; } + const LBMReal &densityLodiLentgh() const { return this->bcLodiLentgh; } + /*======================= Qs =============================*/ + void setQ(const LBMReal &val, const int &direction) { q[direction] = val; } + LBMReal getQ(const int &direction) { return q[direction]; } - /*======================= Qs =============================*/ - void setQ(const LBMReal& val, const int& direction) { q[direction] = val; } - LBMReal getQ(const int& direction) { return q[direction]; } - - virtual std::vector< std::string > getBCNames() - { - std::vector< std::string > tmp; - tmp.emplace_back("NoSlipBC" ); - tmp.emplace_back("SlipBC" ); - tmp.emplace_back("VelocityBC" ); - tmp.emplace_back("DensityBC" ); - return tmp; - } - virtual std::vector< long long > getBCFlags() - { - std::vector< long long > tmp; - tmp.push_back( noslipBoundaryFlags ); - tmp.push_back( slipBoundaryFlags ); - tmp.push_back( velocityBoundaryFlags ); - tmp.push_back( densityBoundaryFlags ); - return tmp; - } + virtual std::vector<std::string> getBCNames() + { + std::vector<std::string> tmp; + tmp.emplace_back("NoSlipBC"); + tmp.emplace_back("SlipBC"); + tmp.emplace_back("VelocityBC"); + tmp.emplace_back("DensityBC"); + return tmp; + } + virtual std::vector<long long> getBCFlags() + { + std::vector<long long> tmp; + tmp.push_back(noslipBoundaryFlags); + tmp.push_back(slipBoundaryFlags); + tmp.push_back(velocityBoundaryFlags); + tmp.push_back(densityBoundaryFlags); + return tmp; + } - static bool hasFlagForDirection(const long long& flag, const int& direction) - { - return ( ( ( flag>>(optionDigits*direction) ) & maxOptionVal ) != 0); - } + static bool hasFlagForDirection(const long long &flag, const int &direction) + { + return (((flag >> (optionDigits * direction)) & maxOptionVal) != 0); + } - void setBcAlgorithmType(char alg) { algorithmType = alg; } - char getBcAlgorithmType() { return algorithmType; } + void setBcAlgorithmType(char alg) { algorithmType = alg; } + char getBcAlgorithmType() { return algorithmType; } public: - static const int optionDigits = 2; //--> 2 bits for secondary Option --> maxOptionVal = 7 - static const long long maxOptionVal;// = ( 1<<optionDigits ) - 1; //2^3-1 -> 7 + static const int optionDigits = 2; //--> 2 bits for secondary Option --> maxOptionVal = 7 + static const long long maxOptionVal; // = ( 1<<optionDigits ) - 1; //2^3-1 -> 7 protected: - LBMReal q[D3Q27System::FENDDIR+1]; - - long long noslipBoundaryFlags{0}; - long long slipBoundaryFlags{0}; - long long velocityBoundaryFlags{0}; - long long densityBoundaryFlags{0}; - long long wallModelBoundaryFlags{0}; + LBMReal q[D3Q27System::FENDDIR + 1]; - LBMReal bcVelocityX1{0.0f}; - LBMReal bcVelocityX2{0.0f}; - LBMReal bcVelocityX3{0.0f}; - LBMReal bcDensity{0.0f}; + long long noslipBoundaryFlags{ 0 }; + long long slipBoundaryFlags{ 0 }; + long long velocityBoundaryFlags{ 0 }; + long long densityBoundaryFlags{ 0 }; + long long wallModelBoundaryFlags{ 0 }; - LBMReal bcLodiDensity{0.0f}; - LBMReal bcLodiVelocityX1{0.0f}; - LBMReal bcLodiVelocityX2{0.0f}; - LBMReal bcLodiVelocityX3{0.0f}; - LBMReal bcLodiLentgh{0.0f}; + LBMReal bcVelocityX1{ 0.0f }; + LBMReal bcVelocityX2{ 0.0f }; + LBMReal bcVelocityX3{ 0.0f }; + LBMReal bcDensity{ 0.0f }; - LBMReal nx1{0.0f},nx2{0.0f},nx3{0.0f}; + LBMReal bcLodiDensity{ 0.0f }; + LBMReal bcLodiVelocityX1{ 0.0f }; + LBMReal bcLodiVelocityX2{ 0.0f }; + LBMReal bcLodiVelocityX3{ 0.0f }; + LBMReal bcLodiLentgh{ 0.0f }; - char algorithmType{-1}; + LBMReal nx1{ 0.0f }, nx2{ 0.0f }, nx3{ 0.0f }; - private: - friend class MPIIORestartCoProcessor; - friend class MPIIOMigrationCoProcessor; - friend class MPIIOMigrationBECoProcessor; + char algorithmType{ -1 }; +private: + friend class MPIIORestartCoProcessor; + friend class MPIIOMigrationCoProcessor; + friend class MPIIOMigrationBECoProcessor; }; #endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.cpp index dcdfd989d..49a4960a1 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.cpp @@ -1,157 +1,172 @@ #include "DensityBCAdapter.h" -#include "basics/utilities/UbLogger.h" #include "basics/utilities/UbInfinity.h" +#include "basics/utilities/UbLogger.h" using namespace std; /*==========================================================*/ -DensityBCAdapter::DensityBCAdapter(const double& dens, const double& startTime, const double& endTime ) +DensityBCAdapter::DensityBCAdapter(const double &dens, const double &startTime, const double &endTime) { - this->densBCs.emplace_back(dens,startTime,endTime ); - this->init(); + this->densBCs.emplace_back(dens, startTime, endTime); + this->init(); } /*==========================================================*/ -DensityBCAdapter::DensityBCAdapter(const BCFunction& densBC ) +DensityBCAdapter::DensityBCAdapter(const BCFunction &densBC) { - this->densBCs.push_back(densBC); - this->init(); + this->densBCs.push_back(densBC); + this->init(); } /*==========================================================*/ -DensityBCAdapter::DensityBCAdapter(const std::vector< BCFunction >& densBCs) +DensityBCAdapter::DensityBCAdapter(const std::vector<BCFunction> &densBCs) { - this->densBCs = densBCs; - this->init(); + this->densBCs = densBCs; + this->init(); } /*==========================================================*/ -DensityBCAdapter::DensityBCAdapter(const mu::Parser& function, const double& startTime, const double& endTime ) +DensityBCAdapter::DensityBCAdapter(const mu::Parser &function, const double &startTime, const double &endTime) { - this->densBCs.emplace_back(function,startTime,endTime); - this->init(); + this->densBCs.emplace_back(function, startTime, endTime); + this->init(); } /*==========================================================*/ void DensityBCAdapter::init() { - this->timeStep = 0.0; + this->timeStep = 0.0; - this->x1 = 0.0; - this->x2 = 0.0; - this->x3 = 0.0; + this->x1 = 0.0; + this->x2 = 0.0; + this->x3 = 0.0; - this->tmpDensityFunction = NULL; + this->tmpDensityFunction = NULL; - try //initilialization and validation of functions - { - for(size_t pos=0; pos<densBCs.size(); ++pos) - { - if( !( UbMath::equal( BCFunction::INFCONST, densBCs[pos].getEndTime() ) - && UbMath::greaterEqual( this->timeStep, densBCs[pos].getStartTime() ) ) ) - { - this->setTimeDependent(); - } + try // initilialization and validation of functions + { + for (size_t pos = 0; pos < densBCs.size(); ++pos) { + if (!(UbMath::equal(BCFunction::INFCONST, densBCs[pos].getEndTime()) && + UbMath::greaterEqual(this->timeStep, densBCs[pos].getStartTime()))) { + this->setTimeDependent(); + } - densBCs[pos].getFunction().DefineVar("t" , &this->timeStep); - densBCs[pos].getFunction().DefineVar("x1", &this->x1 ); - densBCs[pos].getFunction().DefineVar("x2", &this->x2 ); - densBCs[pos].getFunction().DefineVar("x3", &this->x3 ); + densBCs[pos].getFunction().DefineVar("t", &this->timeStep); + densBCs[pos].getFunction().DefineVar("x1", &this->x1); + densBCs[pos].getFunction().DefineVar("x2", &this->x2); + densBCs[pos].getFunction().DefineVar("x3", &this->x3); - densBCs[pos].getFunction().Eval(); //<-- validation - } - } - catch(mu::Parser::exception_type& e){ stringstream error; error<<"mu::parser exception occurs, message("<<e.GetMsg()<<"), formula("<<e.GetExpr()+"), token("+e.GetToken()<<")" - <<", pos("<<e.GetPos()<<"), error code("<<e.GetCode(); throw UbException(error.str()); } - catch(...) { throw UbException(UB_EXARGS,"unknown exception" ); } + densBCs[pos].getFunction().Eval(); //<-- validation + } + } catch (mu::Parser::exception_type &e) { + stringstream error; + error << "mu::parser exception occurs, message(" << e.GetMsg() << "), formula(" + << e.GetExpr() + "), token(" + e.GetToken() << ")" + << ", pos(" << e.GetPos() << "), error code(" << e.GetCode(); + throw UbException(error.str()); + } catch (...) { + throw UbException(UB_EXARGS, "unknown exception"); + } } /*==========================================================*/ -void DensityBCAdapter::init(const D3Q27Interactor* const& /*interactor*/, const double& time) +void DensityBCAdapter::init(const D3Q27Interactor *const & /*interactor*/, const double &time) { - this->timeStep = time; - this->tmpDensityFunction = NULL; - double maxEndtime = -Ub::inf; + this->timeStep = time; + this->tmpDensityFunction = NULL; + double maxEndtime = -Ub::inf; - //aktuelle Densityfunction bestimmen - for(size_t pos=0; pos<densBCs.size(); ++pos) - { - if( UbMath::equal(densBCs[pos].getEndTime(),BCFunction::INFTIMEDEPENDENT)) maxEndtime=Ub::inf; - maxEndtime = UbMath::max(maxEndtime,densBCs[pos].getStartTime(),densBCs[pos].getEndTime()); //startTime abfragen, da INFCONST=-10 + // aktuelle Densityfunction bestimmen + for (size_t pos = 0; pos < densBCs.size(); ++pos) { + if (UbMath::equal(densBCs[pos].getEndTime(), BCFunction::INFTIMEDEPENDENT)) + maxEndtime = Ub::inf; + maxEndtime = UbMath::max(maxEndtime, densBCs[pos].getStartTime(), + densBCs[pos].getEndTime()); // startTime abfragen, da INFCONST=-10 - if( UbMath::greaterEqual(this->timeStep,densBCs[pos].getStartTime()) ) - { - if( UbMath::lessEqual(this->timeStep,densBCs[pos].getEndTime()) - || UbMath::equal(densBCs[pos].getEndTime(),(double)BCFunction::INFCONST) - || UbMath::equal(densBCs[pos].getEndTime(),(double)BCFunction::INFTIMEDEPENDENT) ) - { - tmpDensityFunction = &densBCs[pos].getFunction(); - break; - } - } - } + if (UbMath::greaterEqual(this->timeStep, densBCs[pos].getStartTime())) { + if (UbMath::lessEqual(this->timeStep, densBCs[pos].getEndTime()) || + UbMath::equal(densBCs[pos].getEndTime(), (double)BCFunction::INFCONST) || + UbMath::equal(densBCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT)) { + tmpDensityFunction = &densBCs[pos].getFunction(); + break; + } + } + } - //wenn funktionen zweitlich konstant sind und bis t=unendlich gelten - //kann man zeitabhaengigkeit deaktivieren - if( UbMath::greaterEqual(time,maxEndtime) ) this->unsetTimeDependent(); + // wenn funktionen zweitlich konstant sind und bis t=unendlich gelten + // kann man zeitabhaengigkeit deaktivieren + if (UbMath::greaterEqual(time, maxEndtime)) + this->unsetTimeDependent(); - UBLOG(logDEBUG4,"D3Q27DensityBCAdapter::init(time="<<time<<") " - <<", rho= \""<<(tmpDensityFunction ? tmpDensityFunction->GetExpr() : "-") - <<"\", timedependant="<<(this->isTimeDependent() ? "true" : "false") ); + UBLOG(logDEBUG4, "D3Q27DensityBCAdapter::init(time=" + << time << ") " + << ", rho= \"" << (tmpDensityFunction ? tmpDensityFunction->GetExpr() : "-") + << "\", timedependant=" << (this->isTimeDependent() ? "true" : "false")); } /*==========================================================*/ -void DensityBCAdapter::update( const D3Q27Interactor* const& interactor, const double& time ) +void DensityBCAdapter::update(const D3Q27Interactor *const &interactor, const double &time) { - this->init(interactor,time); + this->init(interactor, time); } /*==========================================================*/ -void DensityBCAdapter::adaptBCForDirection( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& q, const int& fdirection, const double& /*time*/ ) +void DensityBCAdapter::adaptBCForDirection(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double & /*worldX1*/, const double & /*worldX2*/, + const double & /*worldX3*/, const double &q, const int &fdirection, + const double & /*time*/) { - bc->setDensityBoundaryFlag(D3Q27System::INVDIR[fdirection],secondaryBcOption); - bc->setQ((float)q,fdirection); + bc->setDensityBoundaryFlag(D3Q27System::INVDIR[fdirection], secondaryBcOption); + bc->setQ((float)q, fdirection); } /*==========================================================*/ -void DensityBCAdapter::adaptBC( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time ) +void DensityBCAdapter::adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time) { - this->setNodeDensity(interactor,bc,worldX1,worldX2,worldX3,time); - bc->setBcAlgorithmType(algorithmType); + this->setNodeDensity(interactor, bc, worldX1, worldX2, worldX3, time); + bc->setBcAlgorithmType(algorithmType); } /*==========================================================*/ -void DensityBCAdapter::setNodeDensity( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& timestep) +void DensityBCAdapter::setNodeDensity(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double &worldX1, const double &worldX2, const double &worldX3, + const double ×tep) { - //Geschwindigkeiten setzen - try - { - //PunktKoordinaten bestimmen - this->x1 = worldX1; - this->x2 = worldX2; - this->x3 = worldX3; - this->timeStep = timestep; + // Geschwindigkeiten setzen + try { + // PunktKoordinaten bestimmen + this->x1 = worldX1; + this->x2 = worldX2; + this->x3 = worldX3; + this->timeStep = timestep; - if(tmpDensityFunction) bc->setBoundaryDensity((float)tmpDensityFunction->Eval()); - } - catch(mu::Parser::exception_type& e){ stringstream error; error<<"mu::parser exception occurs, message("<<e.GetMsg()<<"), formula("<<e.GetExpr()+"), token("+e.GetToken()<<")" - <<", pos("<<e.GetPos()<<"), error code("<<e.GetCode(); throw UbException(error.str()); } - catch(...) { throw UbException(UB_EXARGS,"unknown exception" ); } + if (tmpDensityFunction) + bc->setBoundaryDensity((float)tmpDensityFunction->Eval()); + } catch (mu::Parser::exception_type &e) { + stringstream error; + error << "mu::parser exception occurs, message(" << e.GetMsg() << "), formula(" + << e.GetExpr() + "), token(" + e.GetToken() << ")" + << ", pos(" << e.GetPos() << "), error code(" << e.GetCode(); + throw UbException(error.str()); + } catch (...) { + throw UbException(UB_EXARGS, "unknown exception"); + } } /*==========================================================*/ -double DensityBCAdapter::getDensity(const double& x1, const double& x2, const double& x3, const double& timeStep) +double DensityBCAdapter::getDensity(const double &x1, const double &x2, const double &x3, const double &timeStep) { - this->x1 = x1; - this->x2 = x2; - this->x3 = x3; - this->timeStep = timeStep; + this->x1 = x1; + this->x2 = x2; + this->x3 = x3; + this->timeStep = timeStep; - if(!tmpDensityFunction) return 0.0; + if (!tmpDensityFunction) + return 0.0; - return tmpDensityFunction->Eval(); + return tmpDensityFunction->Eval(); } /*==========================================================*/ string DensityBCAdapter::toString() { - stringstream info; - info<<"D3Q27DensityBCAdapter:\n"; - info<<" #dens-functions = "<<(int)densBCs.size()<<endl; - info<<" protected variables: x1, x2, x3, t"<<endl; + stringstream info; + info << "D3Q27DensityBCAdapter:\n"; + info << " #dens-functions = " << (int)densBCs.size() << endl; + info << " protected variables: x1, x2, x3, t" << endl; - for(size_t i=0; i<densBCs.size(); ++i) - { - info<<"\n dens-function nr."<<i<<":"<<endl; - info<<densBCs[i].toString()<<endl; - } - return info.str(); + for (size_t i = 0; i < densBCs.size(); ++i) { + info << "\n dens-function nr." << i << ":" << endl; + info << densBCs[i].toString() << endl; + } + return info.str(); } diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.h index 02bf08a45..a52e06060 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/DensityBCAdapter.h @@ -1,9 +1,9 @@ #ifndef DensityBCAdapter_H #define DensityBCAdapter_H - + #include <iostream> -#include <string> #include <sstream> +#include <string> #include <vector> #include "basics/utilities/UbMath.h" @@ -18,57 +18,59 @@ //<BR><BR> //@author <A HREF="mailto:muffmolch@gmx.de">S. Freudiger</A> //@version 1.0 - 06.09.06 -//*/ +//*/ // //* -//usage: ... +// usage: ... //*/ - class DensityBCAdapter : public BCAdapter { public: - //constructors - DensityBCAdapter() { this->init(); } - DensityBCAdapter(const double& dens, const double& startTime=0.0, const double& endTime = BCFunction::INFCONST ); - DensityBCAdapter(const BCFunction& densBC ); - DensityBCAdapter(const std::vector< BCFunction >& densBCs); - DensityBCAdapter(const mu::Parser& function, const double& startTime=0.0, const double& endTime = BCFunction::INFCONST ); + // constructors + DensityBCAdapter() { this->init(); } + DensityBCAdapter(const double &dens, const double &startTime = 0.0, const double &endTime = BCFunction::INFCONST); + DensityBCAdapter(const BCFunction &densBC); + DensityBCAdapter(const std::vector<BCFunction> &densBCs); + DensityBCAdapter(const mu::Parser &function, const double &startTime = 0.0, + const double &endTime = BCFunction::INFCONST); - //------------- implements D3Q27BoundaryConditionAdapter ----- start - std::string toString(); + //------------- implements D3Q27BoundaryConditionAdapter ----- start + std::string toString(); - void init(const D3Q27Interactor* const& interactor, const double& time=0) override; - void update(const D3Q27Interactor* const& interactor, const double& time=0) override; + void init(const D3Q27Interactor *const &interactor, const double &time = 0) override; + void update(const D3Q27Interactor *const &interactor, const double &time = 0) override; - void adaptBCForDirection( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& q, const int& fdirection, const double& time=0 ) override; - void adaptBC( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time=0 ) override; + void adaptBCForDirection(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &q, const int &fdirection, + const double &time = 0) override; + void adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time = 0) override; - double getDensity(const double& x1, const double& x2, const double& x3, const double& timeStep); - - //------------- implements D3Q27BoundaryConditionAdapter ----- end + double getDensity(const double &x1, const double &x2, const double &x3, const double &timeStep); + //------------- implements D3Q27BoundaryConditionAdapter ----- end protected: - void init(); - - //time dependency wird automatisch ueber D3Q27BCFunction Intervalle ermittelt! - void setTimeDependent() { (this->type |= TIMEDEPENDENT);} - void unsetTimeDependent() { (this->type &= ~TIMEDEPENDENT);} - - void clear() { densBCs.clear(); } - void setNodeDensity(const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& timestep); + void init(); -private: - mu::value_type x1, x2, x3; //brauch man nicht serialisieren! - mu::value_type timeStep; //brauch man nicht serialisieren! + // time dependency wird automatisch ueber D3Q27BCFunction Intervalle ermittelt! + void setTimeDependent() { (this->type |= TIMEDEPENDENT); } + void unsetTimeDependent() { (this->type &= ~TIMEDEPENDENT); } - mu::Parser* tmpDensityFunction; //brauch man nicht serialisieren! - - std::vector<BCFunction> densBCs; + void clear() { densBCs.clear(); } + void setNodeDensity(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double ×tep); private: + mu::value_type x1, x2, x3; // brauch man nicht serialisieren! + mu::value_type timeStep; // brauch man nicht serialisieren! + + mu::Parser *tmpDensityFunction; // brauch man nicht serialisieren! + std::vector<BCFunction> densBCs; + +private: }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.cpp index 05d31244a..0f809955d 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.cpp @@ -1,58 +1,59 @@ #include "EqDensityBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" - +#include "DistributionArray3D.h" EqDensityBCAlgorithm::EqDensityBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::EqDensityBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::EqDensityBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// -EqDensityBCAlgorithm::~EqDensityBCAlgorithm() -= default; +EqDensityBCAlgorithm::~EqDensityBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> EqDensityBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new EqDensityBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new EqDensityBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void EqDensityBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void EqDensityBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; + LBMReal f[D3Q27System::ENDF + 1]; - distributions->getDistributionInv(f, x1, x2, x3); - int nx1 = x1; - int nx2 = x2; - int nx3 = x3; + distributions->getDistributionInv(f, x1, x2, x3); + int nx1 = x1; + int nx2 = x2; + int nx3 = x3; - //flag points in direction of fluid - if (bcPtr->hasDensityBoundaryFlag(D3Q27System::E)) { nx1 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::W)) { nx1 += 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::N)) { nx2 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::S)) { nx2 += 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::T)) { nx3 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::B)) { nx3 += 1;} - else UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); - - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - LBMReal rhoBC = bcPtr->getBoundaryDensity(); - for (int fdir = D3Q27System::STARTF; fdir<=D3Q27System::ENDF; fdir++) - { - if (bcPtr->hasDensityBoundaryFlag(fdir)) - { - //Ehsan: 15.2.2013: - LBMReal ftemp = calcFeqsForDirFct(fdir, rhoBC, vx1, vx2, vx3); - distributions->setDistributionForDirection(ftemp, nx1, nx2, nx3, fdir); - } - } + // flag points in direction of fluid + if (bcPtr->hasDensityBoundaryFlag(D3Q27System::E)) { + nx1 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::W)) { + nx1 += 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::N)) { + nx2 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::S)) { + nx2 += 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::T)) { + nx3 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::B)) { + nx3 += 1; + } else + UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + LBMReal rhoBC = bcPtr->getBoundaryDensity(); + for (int fdir = D3Q27System::STARTF; fdir <= D3Q27System::ENDF; fdir++) { + if (bcPtr->hasDensityBoundaryFlag(fdir)) { + // Ehsan: 15.2.2013: + LBMReal ftemp = calcFeqsForDirFct(fdir, rhoBC, vx1, vx2, vx3); + distributions->setDistributionForDirection(ftemp, nx1, nx2, nx3, fdir); + } + } } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.h index 576864170..4d6cab77e 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/EqDensityBCAlgorithm.h @@ -9,10 +9,10 @@ class DistributionArray3D; class EqDensityBCAlgorithm : public BCAlgorithm { public: - EqDensityBCAlgorithm(); - ~EqDensityBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + EqDensityBCAlgorithm(); + ~EqDensityBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // EqDensityBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.cpp index d8e866904..2568a6467 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.cpp @@ -1,46 +1,46 @@ #include "HighViscosityNoSlipBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" +#include "DistributionArray3D.h" HighViscosityNoSlipBCAlgorithm::HighViscosityNoSlipBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::HighViscosityNoSlipBCAlgorithm; - BCAlgorithm::preCollision = true; + BCAlgorithm::type = BCAlgorithm::HighViscosityNoSlipBCAlgorithm; + BCAlgorithm::preCollision = true; } ////////////////////////////////////////////////////////////////////////// -HighViscosityNoSlipBCAlgorithm::~HighViscosityNoSlipBCAlgorithm() -= default; +HighViscosityNoSlipBCAlgorithm::~HighViscosityNoSlipBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> HighViscosityNoSlipBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new HighViscosityNoSlipBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new HighViscosityNoSlipBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void HighViscosityNoSlipBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void HighViscosityNoSlipBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - distributions->getDistribution(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - calcFeqFct(feq, rho, vx1, vx2, vx3); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistribution(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + calcFeqFct(feq, rho, vx1, vx2, vx3); - for (int fDir = D3Q27System::FSTARTDIR; fDir<=D3Q27System::FENDDIR; fDir++) - { - if (bcPtr->hasNoSlipBoundaryFlag(fDir)) - { - //quadratic bounce back - const int invDir = D3Q27System::INVDIR[fDir]; - LBMReal q = bcPtr->getQ(invDir); - LBMReal fReturn = (f[invDir]+q*f[fDir]+q*collFactor*(feq[invDir]-f[invDir]+feq[fDir]-f[fDir]))/(1.0+q); - distributions->setDistributionInvForDirection(fReturn, x1+D3Q27System::DX1[invDir], x2+D3Q27System::DX2[invDir], x3+D3Q27System::DX3[invDir], invDir); - } - } + for (int fDir = D3Q27System::FSTARTDIR; fDir <= D3Q27System::FENDDIR; fDir++) { + if (bcPtr->hasNoSlipBoundaryFlag(fDir)) { + // quadratic bounce back + const int invDir = D3Q27System::INVDIR[fDir]; + LBMReal q = bcPtr->getQ(invDir); + LBMReal fReturn = + (f[invDir] + q * f[fDir] + q * collFactor * (feq[invDir] - f[invDir] + feq[fDir] - f[fDir])) / + (1.0 + q); + distributions->setDistributionInvForDirection(fReturn, x1 + D3Q27System::DX1[invDir], + x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], + invDir); + } + } } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h index 78b27969b..02cf215f7 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/HighViscosityNoSlipBCAlgorithm.h @@ -9,11 +9,10 @@ class DistributionArray3D; class HighViscosityNoSlipBCAlgorithm : public BCAlgorithm { public: - HighViscosityNoSlipBCAlgorithm(); - ~HighViscosityNoSlipBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + HighViscosityNoSlipBCAlgorithm(); + ~HighViscosityNoSlipBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // HighViscosityNoSlipBCAlgorithm_h__ - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.cpp index 335583be2..4b272878a 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.h index 53dfd8d58..68ebf73ff 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAdapter.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -40,29 +40,25 @@ class NoSlipBCAdapter : public BCAdapter { public: - NoSlipBCAdapter() - : BCAdapter() - { - } - NoSlipBCAdapter(const short& secondaryBcOption) - : BCAdapter(secondaryBcOption) - { - } + NoSlipBCAdapter() : BCAdapter() {} + NoSlipBCAdapter(const short &secondaryBcOption) : BCAdapter(secondaryBcOption) {} - void init(const D3Q27Interactor* const& interactor, const double& time=0) override {} - void update(const D3Q27Interactor* const& interactor, const double& time=0) override {} + void init(const D3Q27Interactor *const &interactor, const double &time = 0) override {} + void update(const D3Q27Interactor *const &interactor, const double &time = 0) override {} - void adaptBCForDirection( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& q, const int& fdirection, const double& /*time*/=0 ) override - { - bc->setNoSlipBoundaryFlag(D3Q27System::INVDIR[fdirection],secondaryBcOption); - bc->setQ((float)q,fdirection); - } - void adaptBC( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& /*time*/=0 ) override - { - bc->setBcAlgorithmType(algorithmType); - } + void adaptBCForDirection(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double & /*worldX1*/, const double & /*worldX2*/, const double & /*worldX3*/, + const double &q, const int &fdirection, const double & /*time*/ = 0) override + { + bc->setNoSlipBoundaryFlag(D3Q27System::INVDIR[fdirection], secondaryBcOption); + bc->setQ((float)q, fdirection); + } + void adaptBC(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, const double & /*worldX1*/, + const double & /*worldX2*/, const double & /*worldX3*/, const double & /*time*/ = 0) override + { + bc->setBcAlgorithmType(algorithmType); + } private: - }; -#endif //NoSlipBCAdapter_H +#endif // NoSlipBCAdapter_H diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.cpp index b5b8e54c1..d82a7865b 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,44 +32,45 @@ //======================================================================================= #include "NoSlipBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" +#include "DistributionArray3D.h" NoSlipBCAlgorithm::NoSlipBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::NoSlipBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::NoSlipBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> NoSlipBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new NoSlipBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new NoSlipBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void NoSlipBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void NoSlipBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - distributions->getDistributionInv(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - calcFeqFct(feq, rho, vx1, vx2, vx3); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + calcFeqFct(feq, rho, vx1, vx2, vx3); - for (int fdir = D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if (bcPtr->hasNoSlipBoundaryFlag(fdir)) - { - //quadratic bounce back - const int invDir = D3Q27System::INVDIR[fdir]; - LBMReal q = bcPtr->getQ(invDir); - LBMReal fReturn = ((1.0-q)/(1.0+q))*((f[invDir]-feq[invDir])/(1.0-collFactor)+feq[invDir])+((q/(1.0+q))*(f[invDir]+f[fdir])); - distributions->setDistributionForDirection(fReturn, x1+D3Q27System::DX1[invDir], x2+D3Q27System::DX2[invDir], x3+D3Q27System::DX3[invDir], fdir); - } - } + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bcPtr->hasNoSlipBoundaryFlag(fdir)) { + // quadratic bounce back + const int invDir = D3Q27System::INVDIR[fdir]; + LBMReal q = bcPtr->getQ(invDir); + LBMReal fReturn = ((1.0 - q) / (1.0 + q)) * ((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + + ((q / (1.0 + q)) * (f[invDir] + f[fdir])); + distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], + x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], + fdir); + } + } } diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.h index 163ec5ae8..dcf678b4f 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NoSlipBCAlgorithm.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -43,10 +43,11 @@ class DistributionArray3D; class NoSlipBCAlgorithm : public BCAlgorithm { public: - NoSlipBCAlgorithm(); - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + NoSlipBCAlgorithm(); + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; + private: }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.cpp index 87994c736..24d2ed4ef 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.cpp @@ -1,64 +1,66 @@ #include "NonEqDensityBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" +#include "DistributionArray3D.h" NonEqDensityBCAlgorithm::NonEqDensityBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::NonEqDensityBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::NonEqDensityBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// -NonEqDensityBCAlgorithm::~NonEqDensityBCAlgorithm() -= default; +NonEqDensityBCAlgorithm::~NonEqDensityBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> NonEqDensityBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new NonEqDensityBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new NonEqDensityBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void NonEqDensityBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void NonEqDensityBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; - distributions->getDistributionInv(f, x1, x2, x3); - int nx1 = x1; - int nx2 = x2; - int nx3 = x3; + LBMReal f[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + int nx1 = x1; + int nx2 = x2; + int nx3 = x3; - //flag points in direction of fluid - if (bcPtr->hasDensityBoundaryFlag(D3Q27System::E)) { nx1 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::W)) { nx1 += 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::N)) { nx2 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::S)) { nx2 += 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::T)) { nx3 -= 1;} - else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::B)) { nx3 += 1;} - else return; //UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); - - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - //LBMReal vlimit=0.01; - //vx1=(fabs(vx1)>vlimit) ? vx1/fabs(vx1)*vlimit : vx1; - //vx2=(fabs(vx2)>vlimit) ? vx2/fabs(vx2)*vlimit : vx2; - //vx3=(fabs(vx3)>vlimit) ? vx3/fabs(vx3)*vlimit : vx3; - LBMReal rhoBC = bcPtr->getBoundaryDensity(); - for (int fdir = D3Q27System::STARTF; fdir<=D3Q27System::ENDF; fdir++) - { - if (bcPtr->hasDensityBoundaryFlag(fdir)) - { - // Martins NEQ ADDON - ////original: 15.2.2013: - LBMReal ftemp = calcFeqsForDirFct(fdir, rho, vx1, vx2, vx3); - //rhoBC=(rho>rhoBC)? rhoBC : rho; //Limiter 08.08.2018 - ftemp = calcFeqsForDirFct(fdir, rhoBC, vx1, vx2, vx3)+f[fdir]-ftemp; - distributions->setDistributionForDirection(ftemp, nx1, nx2, nx3, fdir); - } - } + // flag points in direction of fluid + if (bcPtr->hasDensityBoundaryFlag(D3Q27System::E)) { + nx1 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::W)) { + nx1 += 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::N)) { + nx2 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::S)) { + nx2 += 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::T)) { + nx3 -= 1; + } else if (bcPtr->hasDensityBoundaryFlag(D3Q27System::B)) { + nx3 += 1; + } else + return; // UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + // LBMReal vlimit=0.01; + // vx1=(fabs(vx1)>vlimit) ? vx1/fabs(vx1)*vlimit : vx1; + // vx2=(fabs(vx2)>vlimit) ? vx2/fabs(vx2)*vlimit : vx2; + // vx3=(fabs(vx3)>vlimit) ? vx3/fabs(vx3)*vlimit : vx3; + LBMReal rhoBC = bcPtr->getBoundaryDensity(); + for (int fdir = D3Q27System::STARTF; fdir <= D3Q27System::ENDF; fdir++) { + if (bcPtr->hasDensityBoundaryFlag(fdir)) { + // Martins NEQ ADDON + ////original: 15.2.2013: + LBMReal ftemp = calcFeqsForDirFct(fdir, rho, vx1, vx2, vx3); + // rhoBC=(rho>rhoBC)? rhoBC : rho; //Limiter 08.08.2018 + ftemp = calcFeqsForDirFct(fdir, rhoBC, vx1, vx2, vx3) + f[fdir] - ftemp; + distributions->setDistributionForDirection(ftemp, nx1, nx2, nx3, fdir); + } + } } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.h index 12ffa4fdc..ecdc70338 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonEqDensityBCAlgorithm.h @@ -9,10 +9,10 @@ class DistributionArray3D; class NonEqDensityBCAlgorithm : public BCAlgorithm { public: - NonEqDensityBCAlgorithm(); - ~NonEqDensityBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + NonEqDensityBCAlgorithm(); + ~NonEqDensityBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // NonEqDensityBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.cpp index 6cf262bd6..0b5884d12 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.cpp @@ -1,188 +1,198 @@ #include "NonReflectingOutflowBCAlgorithm.h" +#include "BoundaryConditions.h" #include "D3Q27System.h" #include "DistributionArray3D.h" -#include "BoundaryConditions.h" - NonReflectingOutflowBCAlgorithm::NonReflectingOutflowBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::NonReflectingOutflowBCAlgorithm; - BCAlgorithm::preCollision = true; + BCAlgorithm::type = BCAlgorithm::NonReflectingOutflowBCAlgorithm; + BCAlgorithm::preCollision = true; } ////////////////////////////////////////////////////////////////////////// -NonReflectingOutflowBCAlgorithm::~NonReflectingOutflowBCAlgorithm() -= default; +NonReflectingOutflowBCAlgorithm::~NonReflectingOutflowBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> NonReflectingOutflowBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new NonReflectingOutflowBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new NonReflectingOutflowBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void NonReflectingOutflowBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void NonReflectingOutflowBCAlgorithm::applyBC() { - using namespace D3Q27System; - using namespace UbMath; - - LBMReal f[ENDF+1]; - LBMReal ftemp[ENDF+1]; - - int nx1 = x1; - int nx2 = x2; - int nx3 = x3; - int direction = -1; - - //flag points in direction of fluid - if (bcPtr->hasDensityBoundaryFlag(E)) { nx1 += 1; direction = E; } - else if (bcPtr->hasDensityBoundaryFlag(W)) { nx1 -= 1; direction = W; } - else if (bcPtr->hasDensityBoundaryFlag(N)) { nx2 += 1; direction = N; } - else if (bcPtr->hasDensityBoundaryFlag(S)) { nx2 -= 1; direction = S; } - else if (bcPtr->hasDensityBoundaryFlag(T)) { nx3 += 1; direction = T; } - else if (bcPtr->hasDensityBoundaryFlag(B)) { nx3 -= 1; direction = B; } - else UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); - - distributions->getDistribution(f, x1, x2, x3); - distributions->getDistribution(ftemp, nx1, nx2, nx3); - - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - - switch (direction) - { - case E: - f[E] = ftemp[E] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[E] ; - f[NE] = ftemp[NE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[NE] ; - f[SE] = ftemp[SE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[SE] ; - f[TE] = ftemp[TE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[TE] ; - f[BE] = ftemp[BE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[BE] ; - f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[TNE] ; - f[TSE] = ftemp[TSE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[TSE] ; - f[BNE] = ftemp[BNE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[BNE] ; - f[BSE] = ftemp[BSE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1)*f[BSE] ; - - distributions->setDistributionInvForDirection(f[E], x1+DX1[W], x2+DX2[W], x3+DX3[W], W); - distributions->setDistributionInvForDirection(f[NE], x1+DX1[SW], x2+DX2[SW], x3+DX3[SW], SW); - distributions->setDistributionInvForDirection(f[SE], x1+DX1[NW], x2+DX2[NW], x3+DX3[NW], NW); - distributions->setDistributionInvForDirection(f[TE], x1+DX1[BW], x2+DX2[BW], x3+DX3[BW], BW); - distributions->setDistributionInvForDirection(f[BE], x1+DX1[TW], x2+DX2[TW], x3+DX3[TW], TW); - distributions->setDistributionInvForDirection(f[TNE], x1+DX1[BSW], x2+DX2[BSW], x3+DX3[BSW], BSW); - distributions->setDistributionInvForDirection(f[TSE], x1+DX1[BNW], x2+DX2[BNW], x3+DX3[BNW], BNW); - distributions->setDistributionInvForDirection(f[BNE], x1+DX1[TSW], x2+DX2[TSW], x3+DX3[TSW], TSW); - distributions->setDistributionInvForDirection(f[BSE], x1+DX1[TNW], x2+DX2[TNW], x3+DX3[TNW], TNW); - break; - case W: - f[W] = ftemp[W] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[W] ; - f[NW] = ftemp[NW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[NW] ; - f[SW] = ftemp[SW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[SW] ; - f[TW] = ftemp[TW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[TW] ; - f[BW] = ftemp[BW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[BW] ; - f[TNW] = ftemp[TNW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[TNW]; - f[TSW] = ftemp[TSW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[TSW]; - f[BNW] = ftemp[BNW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[BNW]; - f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1)*f[BSW]; - - distributions->setDistributionInvForDirection(f[W], x1+DX1[E], x2+DX2[E], x3+DX3[E], E); - distributions->setDistributionInvForDirection(f[NW], x1+DX1[SE], x2+DX2[SE], x3+DX3[SE], SE); - distributions->setDistributionInvForDirection(f[SW], x1+DX1[NE], x2+DX2[NE], x3+DX3[NE], NE); - distributions->setDistributionInvForDirection(f[TW], x1+DX1[BE], x2+DX2[BE], x3+DX3[BE], BE); - distributions->setDistributionInvForDirection(f[BW], x1+DX1[TE], x2+DX2[TE], x3+DX3[TE], TE); - distributions->setDistributionInvForDirection(f[TNW], x1+DX1[BSE], x2+DX2[BSE], x3+DX3[BSE], BSE); - distributions->setDistributionInvForDirection(f[TSW], x1+DX1[BNE], x2+DX2[BNE], x3+DX3[BNE], BNE); - distributions->setDistributionInvForDirection(f[BNW], x1+DX1[TSE], x2+DX2[TSE], x3+DX3[TSE], TSE); - distributions->setDistributionInvForDirection(f[BSW], x1+DX1[TNE], x2+DX2[TNE], x3+DX3[TNE], TNE); - break; - case N: - f[N] = ftemp[N] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[N] ; - f[NE] = ftemp[NE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[NE] ; - f[NW] = ftemp[NW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[NW] ; - f[TN] = ftemp[TN] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[TN] ; - f[BN] = ftemp[BN] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[BN] ; - f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[TNE] ; - f[TNW] = ftemp[TNW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[TNW] ; - f[BNE] = ftemp[BNE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[BNE] ; - f[BNW] = ftemp[BNW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2)*f[BNW] ; - - distributions->setDistributionInvForDirection(f[N], x1+DX1[S], x2+DX2[S], x3+DX3[S], S); - distributions->setDistributionInvForDirection(f[NE], x1+DX1[SW], x2+DX2[SW], x3+DX3[SW], SW); - distributions->setDistributionInvForDirection(f[NW], x1+DX1[SE], x2+DX2[SE], x3+DX3[SE], SE); - distributions->setDistributionInvForDirection(f[TN], x1+DX1[BS], x2+DX2[BS], x3+DX3[BS], BS); - distributions->setDistributionInvForDirection(f[BN], x1+DX1[TS], x2+DX2[TS], x3+DX3[TS], TS); - distributions->setDistributionInvForDirection(f[TNE], x1+DX1[BSW], x2+DX2[BSW], x3+DX3[BSW], BSW); - distributions->setDistributionInvForDirection(f[TNW], x1+DX1[BSE], x2+DX2[BSE], x3+DX3[BSE], BSE); - distributions->setDistributionInvForDirection(f[BNE], x1+DX1[TSW], x2+DX2[TSW], x3+DX3[TSW], TSW); - distributions->setDistributionInvForDirection(f[BNW], x1+DX1[TSE], x2+DX2[TSE], x3+DX3[TSE], TSE); - break; - case S: - f[S] = ftemp[S] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[S] ; - f[SE] = ftemp[SE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[SE] ; - f[SW] = ftemp[SW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[SW] ; - f[TS] = ftemp[TS] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[TS] ; - f[BS] = ftemp[BS] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[BS] ; - f[TSE] = ftemp[TSE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[TSE] ; - f[TSW] = ftemp[TSW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[TSW] ; - f[BSE] = ftemp[BSE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[BSE] ; - f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2)*f[BSW] ; - - distributions->setDistributionInvForDirection(f[S], x1+DX1[N], x2+DX2[N], x3+DX3[N], N); - distributions->setDistributionInvForDirection(f[SE], x1+DX1[NW], x2+DX2[NW], x3+DX3[NW], NW); - distributions->setDistributionInvForDirection(f[SW], x1+DX1[NE], x2+DX2[NE], x3+DX3[NE], NE); - distributions->setDistributionInvForDirection(f[TS], x1+DX1[BN], x2+DX2[BN], x3+DX3[BN], BN); - distributions->setDistributionInvForDirection(f[BS], x1+DX1[TN], x2+DX2[TN], x3+DX3[TN], TN); - distributions->setDistributionInvForDirection(f[TSE], x1+DX1[BNW], x2+DX2[BNW], x3+DX3[BNW], BNW); - distributions->setDistributionInvForDirection(f[TSW], x1+DX1[BNE], x2+DX2[BNE], x3+DX3[BNE], BNE); - distributions->setDistributionInvForDirection(f[BSE], x1+DX1[TNW], x2+DX2[TNW], x3+DX3[TNW], TNW); - distributions->setDistributionInvForDirection(f[BSW], x1+DX1[TNE], x2+DX2[TNE], x3+DX3[TNE], TNE); - break; - case T: - f[T] = ftemp[T] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[T] ; - f[TE] = ftemp[TE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TE] ; - f[TW] = ftemp[TW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TW] ; - f[TN] = ftemp[TN] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TN] ; - f[TS] = ftemp[TS] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TS] ; - f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TNE] ; - f[TNW] = ftemp[TNW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TNW] ; - f[TSE] = ftemp[TSE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TSE] ; - f[TSW] = ftemp[TSW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3)*f[TSW] ; - - distributions->setDistributionInvForDirection(f[T], x1+DX1[B], x2+DX2[B], x3+DX3[B], B); - distributions->setDistributionInvForDirection(f[TE], x1+DX1[BW], x2+DX2[BW], x3+DX3[BW], BW); - distributions->setDistributionInvForDirection(f[TW], x1+DX1[BE], x2+DX2[BE], x3+DX3[BE], BE); - distributions->setDistributionInvForDirection(f[TN], x1+DX1[BS], x2+DX2[BS], x3+DX3[BS], BS); - distributions->setDistributionInvForDirection(f[TS], x1+DX1[BN], x2+DX2[BN], x3+DX3[BN], BN); - distributions->setDistributionInvForDirection(f[TNE], x1+DX1[BSW], x2+DX2[BSW], x3+DX3[BSW], BSW); - distributions->setDistributionInvForDirection(f[TNW], x1+DX1[BSE], x2+DX2[BSE], x3+DX3[BSE], BSE); - distributions->setDistributionInvForDirection(f[TSE], x1+DX1[BNW], x2+DX2[BNW], x3+DX3[BNW], BNW); - distributions->setDistributionInvForDirection(f[TSW], x1+DX1[BNE], x2+DX2[BNE], x3+DX3[BNE], BNE); - break; - case B: - f[B] = ftemp[B] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[B] ; - f[BE] = ftemp[BE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BE] ; - f[BW] = ftemp[BW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BW] ; - f[BN] = ftemp[BN] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BN] ; - f[BS] = ftemp[BS] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BS] ; - f[BNE] = ftemp[BNE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BNE] ; - f[BNW] = ftemp[BNW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BNW] ; - f[BSE] = ftemp[BSE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BSE] ; - f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3)*f[BSW] ; - - distributions->setDistributionInvForDirection(f[B], x1+DX1[T], x2+DX2[T], x3+DX3[T], T); - distributions->setDistributionInvForDirection(f[BE], x1+DX1[TW], x2+DX2[TW], x3+DX3[TW], TW); - distributions->setDistributionInvForDirection(f[BW], x1+DX1[TE], x2+DX2[TE], x3+DX3[TE], TE); - distributions->setDistributionInvForDirection(f[BN], x1+DX1[TS], x2+DX2[TS], x3+DX3[TS], TS); - distributions->setDistributionInvForDirection(f[BS], x1+DX1[TN], x2+DX2[TN], x3+DX3[TN], TN); - distributions->setDistributionInvForDirection(f[BNE], x1+DX1[TSW], x2+DX2[TSW], x3+DX3[TSW], TSW); - distributions->setDistributionInvForDirection(f[BNW], x1+DX1[TSE], x2+DX2[TSE], x3+DX3[TSE], TSE); - distributions->setDistributionInvForDirection(f[BSE], x1+DX1[TNW], x2+DX2[TNW], x3+DX3[TNW], TNW); - distributions->setDistributionInvForDirection(f[BSW], x1+DX1[TNE], x2+DX2[TNE], x3+DX3[TNE], TNE); - break; - default: - UB_THROW(UbException(UB_EXARGS, "It isn't implemented non reflecting density boundary for this direction!")); - } + using namespace D3Q27System; + using namespace UbMath; + + LBMReal f[ENDF + 1]; + LBMReal ftemp[ENDF + 1]; + + int nx1 = x1; + int nx2 = x2; + int nx3 = x3; + int direction = -1; + + // flag points in direction of fluid + if (bcPtr->hasDensityBoundaryFlag(E)) { + nx1 += 1; + direction = E; + } else if (bcPtr->hasDensityBoundaryFlag(W)) { + nx1 -= 1; + direction = W; + } else if (bcPtr->hasDensityBoundaryFlag(N)) { + nx2 += 1; + direction = N; + } else if (bcPtr->hasDensityBoundaryFlag(S)) { + nx2 -= 1; + direction = S; + } else if (bcPtr->hasDensityBoundaryFlag(T)) { + nx3 += 1; + direction = T; + } else if (bcPtr->hasDensityBoundaryFlag(B)) { + nx3 -= 1; + direction = B; + } else + UB_THROW(UbException(UB_EXARGS, "Danger...no orthogonal BC-Flag on density boundary...")); + + distributions->getDistribution(f, x1, x2, x3); + distributions->getDistribution(ftemp, nx1, nx2, nx3); + + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + + switch (direction) { + case E: + f[E] = ftemp[E] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[E]; + f[NE] = ftemp[NE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[NE]; + f[SE] = ftemp[SE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[SE]; + f[TE] = ftemp[TE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[TE]; + f[BE] = ftemp[BE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[BE]; + f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[TNE]; + f[TSE] = ftemp[TSE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[TSE]; + f[BNE] = ftemp[BNE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[BNE]; + f[BSE] = ftemp[BSE] * (one_over_sqrt3 + vx1) + (1.0 - one_over_sqrt3 - vx1) * f[BSE]; + + distributions->setDistributionInvForDirection(f[E], x1 + DX1[W], x2 + DX2[W], x3 + DX3[W], W); + distributions->setDistributionInvForDirection(f[NE], x1 + DX1[SW], x2 + DX2[SW], x3 + DX3[SW], SW); + distributions->setDistributionInvForDirection(f[SE], x1 + DX1[NW], x2 + DX2[NW], x3 + DX3[NW], NW); + distributions->setDistributionInvForDirection(f[TE], x1 + DX1[BW], x2 + DX2[BW], x3 + DX3[BW], BW); + distributions->setDistributionInvForDirection(f[BE], x1 + DX1[TW], x2 + DX2[TW], x3 + DX3[TW], TW); + distributions->setDistributionInvForDirection(f[TNE], x1 + DX1[BSW], x2 + DX2[BSW], x3 + DX3[BSW], BSW); + distributions->setDistributionInvForDirection(f[TSE], x1 + DX1[BNW], x2 + DX2[BNW], x3 + DX3[BNW], BNW); + distributions->setDistributionInvForDirection(f[BNE], x1 + DX1[TSW], x2 + DX2[TSW], x3 + DX3[TSW], TSW); + distributions->setDistributionInvForDirection(f[BSE], x1 + DX1[TNW], x2 + DX2[TNW], x3 + DX3[TNW], TNW); + break; + case W: + f[W] = ftemp[W] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[W]; + f[NW] = ftemp[NW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[NW]; + f[SW] = ftemp[SW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[SW]; + f[TW] = ftemp[TW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[TW]; + f[BW] = ftemp[BW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[BW]; + f[TNW] = ftemp[TNW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[TNW]; + f[TSW] = ftemp[TSW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[TSW]; + f[BNW] = ftemp[BNW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[BNW]; + f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx1) + (1.0 - one_over_sqrt3 + vx1) * f[BSW]; + + distributions->setDistributionInvForDirection(f[W], x1 + DX1[E], x2 + DX2[E], x3 + DX3[E], E); + distributions->setDistributionInvForDirection(f[NW], x1 + DX1[SE], x2 + DX2[SE], x3 + DX3[SE], SE); + distributions->setDistributionInvForDirection(f[SW], x1 + DX1[NE], x2 + DX2[NE], x3 + DX3[NE], NE); + distributions->setDistributionInvForDirection(f[TW], x1 + DX1[BE], x2 + DX2[BE], x3 + DX3[BE], BE); + distributions->setDistributionInvForDirection(f[BW], x1 + DX1[TE], x2 + DX2[TE], x3 + DX3[TE], TE); + distributions->setDistributionInvForDirection(f[TNW], x1 + DX1[BSE], x2 + DX2[BSE], x3 + DX3[BSE], BSE); + distributions->setDistributionInvForDirection(f[TSW], x1 + DX1[BNE], x2 + DX2[BNE], x3 + DX3[BNE], BNE); + distributions->setDistributionInvForDirection(f[BNW], x1 + DX1[TSE], x2 + DX2[TSE], x3 + DX3[TSE], TSE); + distributions->setDistributionInvForDirection(f[BSW], x1 + DX1[TNE], x2 + DX2[TNE], x3 + DX3[TNE], TNE); + break; + case N: + f[N] = ftemp[N] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[N]; + f[NE] = ftemp[NE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[NE]; + f[NW] = ftemp[NW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[NW]; + f[TN] = ftemp[TN] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[TN]; + f[BN] = ftemp[BN] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[BN]; + f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[TNE]; + f[TNW] = ftemp[TNW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[TNW]; + f[BNE] = ftemp[BNE] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[BNE]; + f[BNW] = ftemp[BNW] * (one_over_sqrt3 + vx2) + (1.0 - one_over_sqrt3 - vx2) * f[BNW]; + + distributions->setDistributionInvForDirection(f[N], x1 + DX1[S], x2 + DX2[S], x3 + DX3[S], S); + distributions->setDistributionInvForDirection(f[NE], x1 + DX1[SW], x2 + DX2[SW], x3 + DX3[SW], SW); + distributions->setDistributionInvForDirection(f[NW], x1 + DX1[SE], x2 + DX2[SE], x3 + DX3[SE], SE); + distributions->setDistributionInvForDirection(f[TN], x1 + DX1[BS], x2 + DX2[BS], x3 + DX3[BS], BS); + distributions->setDistributionInvForDirection(f[BN], x1 + DX1[TS], x2 + DX2[TS], x3 + DX3[TS], TS); + distributions->setDistributionInvForDirection(f[TNE], x1 + DX1[BSW], x2 + DX2[BSW], x3 + DX3[BSW], BSW); + distributions->setDistributionInvForDirection(f[TNW], x1 + DX1[BSE], x2 + DX2[BSE], x3 + DX3[BSE], BSE); + distributions->setDistributionInvForDirection(f[BNE], x1 + DX1[TSW], x2 + DX2[TSW], x3 + DX3[TSW], TSW); + distributions->setDistributionInvForDirection(f[BNW], x1 + DX1[TSE], x2 + DX2[TSE], x3 + DX3[TSE], TSE); + break; + case S: + f[S] = ftemp[S] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[S]; + f[SE] = ftemp[SE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[SE]; + f[SW] = ftemp[SW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[SW]; + f[TS] = ftemp[TS] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[TS]; + f[BS] = ftemp[BS] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[BS]; + f[TSE] = ftemp[TSE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[TSE]; + f[TSW] = ftemp[TSW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[TSW]; + f[BSE] = ftemp[BSE] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[BSE]; + f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx2) + (1.0 - one_over_sqrt3 + vx2) * f[BSW]; + + distributions->setDistributionInvForDirection(f[S], x1 + DX1[N], x2 + DX2[N], x3 + DX3[N], N); + distributions->setDistributionInvForDirection(f[SE], x1 + DX1[NW], x2 + DX2[NW], x3 + DX3[NW], NW); + distributions->setDistributionInvForDirection(f[SW], x1 + DX1[NE], x2 + DX2[NE], x3 + DX3[NE], NE); + distributions->setDistributionInvForDirection(f[TS], x1 + DX1[BN], x2 + DX2[BN], x3 + DX3[BN], BN); + distributions->setDistributionInvForDirection(f[BS], x1 + DX1[TN], x2 + DX2[TN], x3 + DX3[TN], TN); + distributions->setDistributionInvForDirection(f[TSE], x1 + DX1[BNW], x2 + DX2[BNW], x3 + DX3[BNW], BNW); + distributions->setDistributionInvForDirection(f[TSW], x1 + DX1[BNE], x2 + DX2[BNE], x3 + DX3[BNE], BNE); + distributions->setDistributionInvForDirection(f[BSE], x1 + DX1[TNW], x2 + DX2[TNW], x3 + DX3[TNW], TNW); + distributions->setDistributionInvForDirection(f[BSW], x1 + DX1[TNE], x2 + DX2[TNE], x3 + DX3[TNE], TNE); + break; + case T: + f[T] = ftemp[T] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[T]; + f[TE] = ftemp[TE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TE]; + f[TW] = ftemp[TW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TW]; + f[TN] = ftemp[TN] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TN]; + f[TS] = ftemp[TS] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TS]; + f[TNE] = ftemp[TNE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TNE]; + f[TNW] = ftemp[TNW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TNW]; + f[TSE] = ftemp[TSE] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TSE]; + f[TSW] = ftemp[TSW] * (one_over_sqrt3 + vx3) + (1.0 - one_over_sqrt3 - vx3) * f[TSW]; + + distributions->setDistributionInvForDirection(f[T], x1 + DX1[B], x2 + DX2[B], x3 + DX3[B], B); + distributions->setDistributionInvForDirection(f[TE], x1 + DX1[BW], x2 + DX2[BW], x3 + DX3[BW], BW); + distributions->setDistributionInvForDirection(f[TW], x1 + DX1[BE], x2 + DX2[BE], x3 + DX3[BE], BE); + distributions->setDistributionInvForDirection(f[TN], x1 + DX1[BS], x2 + DX2[BS], x3 + DX3[BS], BS); + distributions->setDistributionInvForDirection(f[TS], x1 + DX1[BN], x2 + DX2[BN], x3 + DX3[BN], BN); + distributions->setDistributionInvForDirection(f[TNE], x1 + DX1[BSW], x2 + DX2[BSW], x3 + DX3[BSW], BSW); + distributions->setDistributionInvForDirection(f[TNW], x1 + DX1[BSE], x2 + DX2[BSE], x3 + DX3[BSE], BSE); + distributions->setDistributionInvForDirection(f[TSE], x1 + DX1[BNW], x2 + DX2[BNW], x3 + DX3[BNW], BNW); + distributions->setDistributionInvForDirection(f[TSW], x1 + DX1[BNE], x2 + DX2[BNE], x3 + DX3[BNE], BNE); + break; + case B: + f[B] = ftemp[B] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[B]; + f[BE] = ftemp[BE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BE]; + f[BW] = ftemp[BW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BW]; + f[BN] = ftemp[BN] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BN]; + f[BS] = ftemp[BS] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BS]; + f[BNE] = ftemp[BNE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BNE]; + f[BNW] = ftemp[BNW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BNW]; + f[BSE] = ftemp[BSE] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BSE]; + f[BSW] = ftemp[BSW] * (one_over_sqrt3 - vx3) + (1.0 - one_over_sqrt3 + vx3) * f[BSW]; + + distributions->setDistributionInvForDirection(f[B], x1 + DX1[T], x2 + DX2[T], x3 + DX3[T], T); + distributions->setDistributionInvForDirection(f[BE], x1 + DX1[TW], x2 + DX2[TW], x3 + DX3[TW], TW); + distributions->setDistributionInvForDirection(f[BW], x1 + DX1[TE], x2 + DX2[TE], x3 + DX3[TE], TE); + distributions->setDistributionInvForDirection(f[BN], x1 + DX1[TS], x2 + DX2[TS], x3 + DX3[TS], TS); + distributions->setDistributionInvForDirection(f[BS], x1 + DX1[TN], x2 + DX2[TN], x3 + DX3[TN], TN); + distributions->setDistributionInvForDirection(f[BNE], x1 + DX1[TSW], x2 + DX2[TSW], x3 + DX3[TSW], TSW); + distributions->setDistributionInvForDirection(f[BNW], x1 + DX1[TSE], x2 + DX2[TSE], x3 + DX3[TSE], TSE); + distributions->setDistributionInvForDirection(f[BSE], x1 + DX1[TNW], x2 + DX2[TNW], x3 + DX3[TNW], TNW); + distributions->setDistributionInvForDirection(f[BSW], x1 + DX1[TNE], x2 + DX2[TNE], x3 + DX3[TNE], TNE); + break; + default: + UB_THROW( + UbException(UB_EXARGS, "It isn't implemented non reflecting density boundary for this direction!")); + } } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.h index d41cdc05a..e968d69b3 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/NonReflectingOutflowBCAlgorithm.h @@ -9,10 +9,10 @@ class DistributionArray3D; class NonReflectingOutflowBCAlgorithm : public BCAlgorithm { public: - NonReflectingOutflowBCAlgorithm(); - ~NonReflectingOutflowBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + NonReflectingOutflowBCAlgorithm(); + ~NonReflectingOutflowBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // NonReflectingDensityBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.cpp index 1cb54321d..1954a4338 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.cpp @@ -1,35 +1,41 @@ #include "SlipBCAdapter.h" -#include "D3Q27System.h" #include "D3Q27Interactor.h" +#include "D3Q27System.h" #include "geometry3d/GbCuboid3D.h" - //*==========================================================*/ -//ObObject* D3Q27SlipBCAdapterCreator::createObObject() +// ObObject* D3Q27SlipBCAdapterCreator::createObObject() //{ -// return new D3Q27SlipBCAdapter; +// return new D3Q27SlipBCAdapter; //} //*==========================================================*/ -//ObObjectCreator* D3Q27SlipBCAdapter::getCreator() +// ObObjectCreator* D3Q27SlipBCAdapter::getCreator() //{ // return D3Q27SlipBCAdapterCreator::getInstance(); //} //*==========================================================*/ -void SlipBCAdapter::adaptBC(const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& /*time*/) +void SlipBCAdapter::adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double & /*worldX1*/, + const double & /*worldX2*/, const double & /*worldX3*/, const double & /*time*/) { - ////////////////////////////////////////////////////////////////////////// - //>>> nur workaround! -> Hendrick nach normalen berechnung aus qs fragen - - GbCuboid3DPtr geo = dynamicPointerCast<GbCuboid3D>(interactor.getGbObject3D()); - if(!geo) throw UbException(UB_EXARGS,"derzeit nur fuer Cubes valide"); + ////////////////////////////////////////////////////////////////////////// + //>>> nur workaround! -> Hendrick nach normalen berechnung aus qs fragen - if ( bc->hasSlipBoundaryFlag(D3Q27System::E) ) bc->setNormalVector( 1.0, 0.0, 0.0); - else if( bc->hasSlipBoundaryFlag(D3Q27System::W) ) bc->setNormalVector(-1.0, 0.0, 0.0); - else if( bc->hasSlipBoundaryFlag(D3Q27System::N) ) bc->setNormalVector( 0.0, 1.0, 0.0); - else if( bc->hasSlipBoundaryFlag(D3Q27System::S) ) bc->setNormalVector( 0.0,-1.0, 0.0); - else if( bc->hasSlipBoundaryFlag(D3Q27System::T) ) bc->setNormalVector( 0.0, 0.0, 1.0); - else if( bc->hasSlipBoundaryFlag(D3Q27System::B) ) bc->setNormalVector( 0.0, 0.0,-1.0); + GbCuboid3DPtr geo = dynamicPointerCast<GbCuboid3D>(interactor.getGbObject3D()); + if (!geo) + throw UbException(UB_EXARGS, "derzeit nur fuer Cubes valide"); - bc->setBcAlgorithmType(algorithmType); -} + if (bc->hasSlipBoundaryFlag(D3Q27System::E)) + bc->setNormalVector(1.0, 0.0, 0.0); + else if (bc->hasSlipBoundaryFlag(D3Q27System::W)) + bc->setNormalVector(-1.0, 0.0, 0.0); + else if (bc->hasSlipBoundaryFlag(D3Q27System::N)) + bc->setNormalVector(0.0, 1.0, 0.0); + else if (bc->hasSlipBoundaryFlag(D3Q27System::S)) + bc->setNormalVector(0.0, -1.0, 0.0); + else if (bc->hasSlipBoundaryFlag(D3Q27System::T)) + bc->setNormalVector(0.0, 0.0, 1.0); + else if (bc->hasSlipBoundaryFlag(D3Q27System::B)) + bc->setNormalVector(0.0, 0.0, -1.0); + bc->setBcAlgorithmType(algorithmType); +} diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.h index 18bda0190..f9b452990 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAdapter.h @@ -8,37 +8,37 @@ #define SlipBCAdapter_H #ifdef CAB_RCF - #include <3rdParty/rcf/RcfSerializationIncludes.h> +#include <3rdParty/rcf/RcfSerializationIncludes.h> #endif #include "BCAdapter.h" - /*=======================================================*/ -//D3Q27SlipBCAdapterCreator -//class D3Q27SlipBCAdapterCreator : public ObObjectCreator +// D3Q27SlipBCAdapterCreator +// class D3Q27SlipBCAdapterCreator : public ObObjectCreator //{ -//public: +// public: // static D3Q27SlipBCAdapterCreator* getInstance() // { // static D3Q27SlipBCAdapterCreator instance; // return &instance; // } -// -// ObObject* createObObject(); // -// std::string getTypeID() { return "D3Q27SlipBCAdapter";} +// ObObject* createObObject(); +// +// std::string getTypeID() { return "D3Q27SlipBCAdapter";} // std::string toString() { return "D3Q27SlipBCAdapterCreator"; } // -//private: -// D3Q27SlipBCAdapterCreator( const D3Q27SlipBCAdapterCreator& ); //no copy allowed +// private: +// D3Q27SlipBCAdapterCreator( const D3Q27SlipBCAdapterCreator& ); //no copy allowed // const D3Q27SlipBCAdapterCreator& operator=( const D3Q27SlipBCAdapterCreator& ); //no copy allowed // D3Q27SlipBCAdapterCreator() : ObObjectCreator() {} //}; // //#ifndef SWIG -//UB_AUTO_RUN_NAMED( D3Q27BCAdapterFactory::getInstance()->addObObjectCreator(D3Q27SlipBCAdapterCreator::getInstance()), CAB_D3Q27SlipBCAdapterCreator); -//#endif +// UB_AUTO_RUN_NAMED( +// D3Q27BCAdapterFactory::getInstance()->addObObjectCreator(D3Q27SlipBCAdapterCreator::getInstance()), +// CAB_D3Q27SlipBCAdapterCreator); #endif /*=========================================================================*/ /* D3Q27SlipBCAdapter */ @@ -47,7 +47,7 @@ <BR><BR> @author <A HREF="mailto:muffmolch@gmx.de">S. Freudiger</A> @version 1.0 - 06.09.06 -*/ +*/ /* usage: ... @@ -56,33 +56,27 @@ usage: ... class SlipBCAdapter : public BCAdapter { public: - SlipBCAdapter() - : BCAdapter() - { - } - SlipBCAdapter(const short& secondaryBcOption) - : BCAdapter(secondaryBcOption) - { - } + SlipBCAdapter() : BCAdapter() {} + SlipBCAdapter(const short &secondaryBcOption) : BCAdapter(secondaryBcOption) {} - //------------- implements D3Q27BoundaryConditionAdapter ----- start + //------------- implements D3Q27BoundaryConditionAdapter ----- start - void init(const D3Q27Interactor* const& interactor, const double& timestep=0) override {} - void update(const D3Q27Interactor* const& interactor, const double& timestep=0) override {} + void init(const D3Q27Interactor *const &interactor, const double ×tep = 0) override {} + void update(const D3Q27Interactor *const &interactor, const double ×tep = 0) override {} - void adaptBCForDirection( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& q, const int& fdirection, const double& /*time*/=0 ) override - { - bc->setSlipBoundaryFlag(D3Q27System::INVDIR[fdirection],secondaryBcOption); - bc->setQ((float)q,fdirection); - } - void adaptBC(const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time=0) override; - - //------------- implements D3Q27BoundaryConditionAdapter ----- end - -private: + void adaptBCForDirection(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double & /*worldX1*/, const double & /*worldX2*/, const double & /*worldX3*/, + const double &q, const int &fdirection, const double & /*time*/ = 0) override + { + bc->setSlipBoundaryFlag(D3Q27System::INVDIR[fdirection], secondaryBcOption); + bc->setQ((float)q, fdirection); + } + void adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time = 0) override; + //------------- implements D3Q27BoundaryConditionAdapter ----- end +private: }; #endif - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.cpp index f61b1fcfb..0dbbcd8f0 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.cpp @@ -1,86 +1,135 @@ #include "SlipBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" +#include "DistributionArray3D.h" SlipBCAlgorithm::SlipBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::SlipBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::SlipBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// -SlipBCAlgorithm::~SlipBCAlgorithm() -= default; +SlipBCAlgorithm::~SlipBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> SlipBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new SlipBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new SlipBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// -void SlipBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) -{ - this->distributions = distributions; -} +void SlipBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void SlipBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - distributions->getDistributionInv(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3, drho; - calcMacrosFct(f, drho, vx1, vx2, vx3); - calcFeqFct(feq, drho, vx1, vx2, vx3); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3, drho; + calcMacrosFct(f, drho, vx1, vx2, vx3); + calcFeqFct(feq, drho, vx1, vx2, vx3); - UbTupleDouble3 normale = bcPtr->getNormalVector(); - LBMReal amp = vx1*val<1>(normale)+vx2*val<2>(normale)+vx3*val<3>(normale); + UbTupleDouble3 normale = bcPtr->getNormalVector(); + LBMReal amp = vx1 * val<1>(normale) + vx2 * val<2>(normale) + vx3 * val<3>(normale); - vx1 = vx1 - amp * val<1>(normale); //normale zeigt von struktur weg! - vx2 = vx2 - amp * val<2>(normale); //normale zeigt von struktur weg! - vx3 = vx3 - amp * val<3>(normale); //normale zeigt von struktur weg! + vx1 = vx1 - amp * val<1>(normale); // normale zeigt von struktur weg! + vx2 = vx2 - amp * val<2>(normale); // normale zeigt von struktur weg! + vx3 = vx3 - amp * val<3>(normale); // normale zeigt von struktur weg! - rho = 1.0+drho*compressibleFactor; + rho = 1.0 + drho * compressibleFactor; - for (int fdir = D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if (bcPtr->hasSlipBoundaryFlag(fdir)) - { - //quadratic bounce back - const int invDir = D3Q27System::INVDIR[fdir]; - LBMReal q = bcPtr->getQ(invDir);// m+m q=0 stabiler - //vx3=0; - LBMReal velocity = 0.0; - switch (invDir) - { - case D3Q27System::E: velocity = (UbMath::c4o9*(+vx1)); break; //(2/cs^2)(=6)*rho_0(=1 bei imkompr)*wi*u*ei mit cs=1/sqrt(3) - case D3Q27System::W: velocity = (UbMath::c4o9*(-vx1)); break; //z.B. aus paper manfred MRT LB models in three dimensions (2002) - case D3Q27System::N: velocity = (UbMath::c4o9*(+vx2)); break; - case D3Q27System::S: velocity = (UbMath::c4o9*(-vx2)); break; - case D3Q27System::T: velocity = (UbMath::c4o9*(+vx3)); break; - case D3Q27System::B: velocity = (UbMath::c4o9*(-vx3)); break; - case D3Q27System::NE: velocity = (UbMath::c1o9*(+vx1+vx2)); break; - case D3Q27System::SW: velocity = (UbMath::c1o9*(-vx1-vx2)); break; - case D3Q27System::SE: velocity = (UbMath::c1o9*(+vx1-vx2)); break; - case D3Q27System::NW: velocity = (UbMath::c1o9*(-vx1+vx2)); break; - case D3Q27System::TE: velocity = (UbMath::c1o9*(+vx1 +vx3)); break; - case D3Q27System::BW: velocity = (UbMath::c1o9*(-vx1 -vx3)); break; - case D3Q27System::BE: velocity = (UbMath::c1o9*(+vx1 -vx3)); break; - case D3Q27System::TW: velocity = (UbMath::c1o9*(-vx1 +vx3)); break; - case D3Q27System::TN: velocity = (UbMath::c1o9*(+vx2+vx3)); break; - case D3Q27System::BS: velocity = (UbMath::c1o9*(-vx2-vx3)); break; - case D3Q27System::BN: velocity = (UbMath::c1o9*(+vx2-vx3)); break; - case D3Q27System::TS: velocity = (UbMath::c1o9*(-vx2+vx3)); break; - case D3Q27System::TNE: velocity = (UbMath::c1o36*(+vx1+vx2+vx3)); break; - case D3Q27System::BSW: velocity = (UbMath::c1o36*(-vx1-vx2-vx3)); break; - case D3Q27System::BNE: velocity = (UbMath::c1o36*(+vx1+vx2-vx3)); break; - case D3Q27System::TSW: velocity = (UbMath::c1o36*(-vx1-vx2+vx3)); break; - case D3Q27System::TSE: velocity = (UbMath::c1o36*(+vx1-vx2+vx3)); break; - case D3Q27System::BNW: velocity = (UbMath::c1o36*(-vx1+vx2-vx3)); break; - case D3Q27System::BSE: velocity = (UbMath::c1o36*(+vx1-vx2-vx3)); break; - case D3Q27System::TNW: velocity = (UbMath::c1o36*(-vx1+vx2+vx3)); break; - default: throw UbException(UB_EXARGS, "unknown error"); - } - LBMReal fReturn = ((1.0-q)/(1.0+q))*((f[invDir]-feq[invDir])/(1.0-collFactor)+feq[invDir])+((q*(f[invDir]+f[fdir])-velocity*rho)/(1.0+q)); - distributions->setDistributionForDirection(fReturn, x1+D3Q27System::DX1[invDir], x2+D3Q27System::DX2[invDir], x3+D3Q27System::DX3[invDir], fdir); - } - } + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bcPtr->hasSlipBoundaryFlag(fdir)) { + // quadratic bounce back + const int invDir = D3Q27System::INVDIR[fdir]; + LBMReal q = bcPtr->getQ(invDir); // m+m q=0 stabiler + // vx3=0; + LBMReal velocity = 0.0; + switch (invDir) { + case D3Q27System::E: + velocity = (UbMath::c4o9 * (+vx1)); + break; //(2/cs^2)(=6)*rho_0(=1 bei imkompr)*wi*u*ei mit cs=1/sqrt(3) + case D3Q27System::W: + velocity = (UbMath::c4o9 * (-vx1)); + break; // z.B. aus paper manfred MRT LB models in three dimensions (2002) + case D3Q27System::N: + velocity = (UbMath::c4o9 * (+vx2)); + break; + case D3Q27System::S: + velocity = (UbMath::c4o9 * (-vx2)); + break; + case D3Q27System::T: + velocity = (UbMath::c4o9 * (+vx3)); + break; + case D3Q27System::B: + velocity = (UbMath::c4o9 * (-vx3)); + break; + case D3Q27System::NE: + velocity = (UbMath::c1o9 * (+vx1 + vx2)); + break; + case D3Q27System::SW: + velocity = (UbMath::c1o9 * (-vx1 - vx2)); + break; + case D3Q27System::SE: + velocity = (UbMath::c1o9 * (+vx1 - vx2)); + break; + case D3Q27System::NW: + velocity = (UbMath::c1o9 * (-vx1 + vx2)); + break; + case D3Q27System::TE: + velocity = (UbMath::c1o9 * (+vx1 + vx3)); + break; + case D3Q27System::BW: + velocity = (UbMath::c1o9 * (-vx1 - vx3)); + break; + case D3Q27System::BE: + velocity = (UbMath::c1o9 * (+vx1 - vx3)); + break; + case D3Q27System::TW: + velocity = (UbMath::c1o9 * (-vx1 + vx3)); + break; + case D3Q27System::TN: + velocity = (UbMath::c1o9 * (+vx2 + vx3)); + break; + case D3Q27System::BS: + velocity = (UbMath::c1o9 * (-vx2 - vx3)); + break; + case D3Q27System::BN: + velocity = (UbMath::c1o9 * (+vx2 - vx3)); + break; + case D3Q27System::TS: + velocity = (UbMath::c1o9 * (-vx2 + vx3)); + break; + case D3Q27System::TNE: + velocity = (UbMath::c1o36 * (+vx1 + vx2 + vx3)); + break; + case D3Q27System::BSW: + velocity = (UbMath::c1o36 * (-vx1 - vx2 - vx3)); + break; + case D3Q27System::BNE: + velocity = (UbMath::c1o36 * (+vx1 + vx2 - vx3)); + break; + case D3Q27System::TSW: + velocity = (UbMath::c1o36 * (-vx1 - vx2 + vx3)); + break; + case D3Q27System::TSE: + velocity = (UbMath::c1o36 * (+vx1 - vx2 + vx3)); + break; + case D3Q27System::BNW: + velocity = (UbMath::c1o36 * (-vx1 + vx2 - vx3)); + break; + case D3Q27System::BSE: + velocity = (UbMath::c1o36 * (+vx1 - vx2 - vx3)); + break; + case D3Q27System::TNW: + velocity = (UbMath::c1o36 * (-vx1 + vx2 + vx3)); + break; + default: + throw UbException(UB_EXARGS, "unknown error"); + } + LBMReal fReturn = ((1.0 - q) / (1.0 + q)) * ((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + + ((q * (f[invDir] + f[fdir]) - velocity * rho) / (1.0 + q)); + distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], + x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], + fdir); + } + } } \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.h index 7f4e39c73..b7a75969f 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/SlipBCAlgorithm.h @@ -9,10 +9,10 @@ class DistributionArray3D; class SlipBCAlgorithm : public BCAlgorithm { public: - SlipBCAlgorithm(); - ~SlipBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + SlipBCAlgorithm(); + ~SlipBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // SlipBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.cpp index bdb9bf261..1be8fea8b 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.cpp @@ -5,30 +5,23 @@ #include "LBMKernel.h" ////////////////////////////////////////////////////////////////////////// -ThinWallBCProcessor::ThinWallBCProcessor(SPtr<ILBMKernel> kernel) : BCProcessor(kernel) -{ - -} +ThinWallBCProcessor::ThinWallBCProcessor(SPtr<ILBMKernel> kernel) : BCProcessor(kernel) {} ////////////////////////////////////////////////////////////////////////// SPtr<BCProcessor> ThinWallBCProcessor::clone(SPtr<ILBMKernel> kernel) { - SPtr<BCProcessor> bcProcessor(new ThinWallBCProcessor(kernel)); - return bcProcessor; + SPtr<BCProcessor> bcProcessor(new ThinWallBCProcessor(kernel)); + return bcProcessor; } ////////////////////////////////////////////////////////////////////////// void ThinWallBCProcessor::applyPostCollisionBC() { - BCProcessor::applyPostCollisionBC(); + BCProcessor::applyPostCollisionBC(); - for(SPtr<BCAlgorithm> bc : postBC) - { - if (bc->getType() == BCAlgorithm::ThinWallNoSlipBCAlgorithm) - { - dynamicPointerCast<ThinWallNoSlipBCAlgorithm>(bc)->setPass(2); - bc->applyBC(); - dynamicPointerCast<ThinWallNoSlipBCAlgorithm>(bc)->setPass(1); - } - } + for (SPtr<BCAlgorithm> bc : postBC) { + if (bc->getType() == BCAlgorithm::ThinWallNoSlipBCAlgorithm) { + dynamicPointerCast<ThinWallNoSlipBCAlgorithm>(bc)->setPass(2); + bc->applyBC(); + dynamicPointerCast<ThinWallNoSlipBCAlgorithm>(bc)->setPass(1); + } + } } - - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.h index cd3ac5c49..6bed45c21 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallBCProcessor.h @@ -10,13 +10,12 @@ class ILBMKernel; class ThinWallBCProcessor : public BCProcessor { public: - ThinWallBCProcessor() = default; - explicit ThinWallBCProcessor(SPtr<ILBMKernel> kernel); - SPtr<BCProcessor> clone(SPtr<ILBMKernel> kernel) override; - void applyPostCollisionBC(); //FIXME: should the base method virtual?? + ThinWallBCProcessor() = default; + explicit ThinWallBCProcessor(SPtr<ILBMKernel> kernel); + SPtr<BCProcessor> clone(SPtr<ILBMKernel> kernel) override; + void applyPostCollisionBC(); // FIXME: should the base method virtual?? protected: private: - }; #endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.cpp index 39c427a53..c1ad04256 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.cpp @@ -1,64 +1,61 @@ #include "ThinWallNoSlipBCAlgorithm.h" -#include "D3Q27EsoTwist3DSplittedVector.h" #include "BoundaryConditions.h" +#include "D3Q27EsoTwist3DSplittedVector.h" ThinWallNoSlipBCAlgorithm::ThinWallNoSlipBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::ThinWallNoSlipBCAlgorithm; - BCAlgorithm::preCollision = false; - pass = 1; + BCAlgorithm::type = BCAlgorithm::ThinWallNoSlipBCAlgorithm; + BCAlgorithm::preCollision = false; + pass = 1; } ////////////////////////////////////////////////////////////////////////// -ThinWallNoSlipBCAlgorithm::~ThinWallNoSlipBCAlgorithm() -= default; +ThinWallNoSlipBCAlgorithm::~ThinWallNoSlipBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> ThinWallNoSlipBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new ThinWallNoSlipBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new ThinWallNoSlipBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void ThinWallNoSlipBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF + 1]; - LBMReal feq[D3Q27System::ENDF + 1]; - distributions->getDistributionInv(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3; - calcMacrosFct(f, rho, vx1, vx2, vx3); - calcFeqFct(feq, rho, vx1, vx2, vx3); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3; + calcMacrosFct(f, rho, vx1, vx2, vx3); + calcFeqFct(feq, rho, vx1, vx2, vx3); - LBMReal fReturn; + LBMReal fReturn; - for (int fdir = D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if (bcPtr->hasNoSlipBoundaryFlag(fdir)) - { - const int invDir = D3Q27System::INVDIR[fdir]; - if (pass == 1) - { - LBMReal q = bcPtr->getQ(invDir); - fReturn = ((1.0 - q) / (1.0 + q))*0.5*(f[invDir] - f[fdir] + (f[invDir] + f[fdir] - collFactor*(feq[fdir] + feq[invDir])) / (1.0 - collFactor)); - //distributionsTemp->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); - fTemp[fdir] = fReturn; - } - else - { - //quadratic bounce back with for thin walls - //fReturn = distributionsTemp->getDistributionInvForDirection(x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); - fReturn = fTemp[fdir]; - distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); - } - } - } + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bcPtr->hasNoSlipBoundaryFlag(fdir)) { + const int invDir = D3Q27System::INVDIR[fdir]; + if (pass == 1) { + LBMReal q = bcPtr->getQ(invDir); + fReturn = ((1.0 - q) / (1.0 + q)) * 0.5 * + (f[invDir] - f[fdir] + + (f[invDir] + f[fdir] - collFactor * (feq[fdir] + feq[invDir])) / (1.0 - collFactor)); + // distributionsTemp->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], x2 + + // D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); + fTemp[fdir] = fReturn; + } else { + // quadratic bounce back with for thin walls + // fReturn = distributionsTemp->getDistributionInvForDirection(x1 + D3Q27System::DX1[invDir], x2 + + // D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); + fReturn = fTemp[fdir]; + distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], + x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], + fdir); + } + } + } } ////////////////////////////////////////////////////////////////////////// void ThinWallNoSlipBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// -void ThinWallNoSlipBCAlgorithm::setPass(int pass) -{ - this->pass = pass; -} +void ThinWallNoSlipBCAlgorithm::setPass(int pass) { this->pass = pass; } diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.h index db9244d10..1ba18185e 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/ThinWallNoSlipBCAlgorithm.h @@ -9,17 +9,18 @@ class DistributionArray3D; class ThinWallNoSlipBCAlgorithm : public BCAlgorithm { public: - ThinWallNoSlipBCAlgorithm(); - ~ThinWallNoSlipBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void setPass(int pass); - void applyBC() override; + ThinWallNoSlipBCAlgorithm(); + ~ThinWallNoSlipBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void setPass(int pass); + void applyBC() override; protected: - SPtr<DistributionArray3D> distributionsTemp; + SPtr<DistributionArray3D> distributionsTemp; + private: - int pass; - LBMReal fTemp[D3Q27System::ENDF + 1]; + int pass; + LBMReal fTemp[D3Q27System::ENDF + 1]; }; #endif // ThinWallNoSlipBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.cpp index f80cb1e2b..55d65f629 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,302 +38,338 @@ using namespace std; - -VelocityBCAdapter::VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const BCFunction& velVxBC) +VelocityBCAdapter::VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const BCFunction &velVxBC) { - if(vx1) this->vx1BCs.push_back(velVxBC); - if(vx2) this->vx2BCs.push_back(velVxBC); - if(vx3) this->vx3BCs.push_back(velVxBC); - this->init(); + if (vx1) + this->vx1BCs.push_back(velVxBC); + if (vx2) + this->vx2BCs.push_back(velVxBC); + if (vx3) + this->vx3BCs.push_back(velVxBC); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const mu::Parser& function, const double& startTime, const double& endTime ) +VelocityBCAdapter::VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const mu::Parser &function, + const double &startTime, const double &endTime) { - if(vx1) this->vx1BCs.emplace_back(function,startTime,endTime); - if(vx2) this->vx2BCs.emplace_back(function,startTime,endTime); - if(vx3) this->vx3BCs.emplace_back(function,startTime,endTime); - this->init(); + if (vx1) + this->vx1BCs.emplace_back(function, startTime, endTime); + if (vx2) + this->vx2BCs.emplace_back(function, startTime, endTime); + if (vx3) + this->vx3BCs.emplace_back(function, startTime, endTime); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const mu::Parser& function1, const mu::Parser& function2, const mu::Parser& function3, const double& startTime, const double& endTime ) +VelocityBCAdapter::VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const mu::Parser &function1, + const mu::Parser &function2, const mu::Parser &function3, const double &startTime, + const double &endTime) { - if(vx1) this->vx1BCs.emplace_back(function1,startTime,endTime); - if(vx2) this->vx2BCs.emplace_back(function2,startTime,endTime); - if(vx3) this->vx3BCs.emplace_back(function3,startTime,endTime); - this->init(); + if (vx1) + this->vx1BCs.emplace_back(function1, startTime, endTime); + if (vx2) + this->vx2BCs.emplace_back(function2, startTime, endTime); + if (vx3) + this->vx3BCs.emplace_back(function3, startTime, endTime); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const string& functionstring, const double& startTime, const double& endTime ) +VelocityBCAdapter::VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const string &functionstring, + const double &startTime, const double &endTime) { - if(vx1) this->vx1BCs.emplace_back(functionstring,startTime,endTime); - if(vx2) this->vx2BCs.emplace_back(functionstring,startTime,endTime); - if(vx3) this->vx3BCs.emplace_back(functionstring,startTime,endTime); - this->init(); + if (vx1) + this->vx1BCs.emplace_back(functionstring, startTime, endTime); + if (vx2) + this->vx2BCs.emplace_back(functionstring, startTime, endTime); + if (vx3) + this->vx3BCs.emplace_back(functionstring, startTime, endTime); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const BCFunction& velBC, bool x1Dir, bool x2Dir, bool x3Dir) +VelocityBCAdapter::VelocityBCAdapter(const BCFunction &velBC, bool x1Dir, bool x2Dir, bool x3Dir) { - if(x1Dir) this->vx1BCs.push_back(velBC); - if(x2Dir) this->vx2BCs.push_back(velBC); - if(x3Dir) this->vx3BCs.push_back(velBC); - this->init(); + if (x1Dir) + this->vx1BCs.push_back(velBC); + if (x2Dir) + this->vx2BCs.push_back(velBC); + if (x3Dir) + this->vx3BCs.push_back(velBC); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const BCFunction& velVx1BC, const BCFunction& velVx2BC, const BCFunction& velVx3BC) +VelocityBCAdapter::VelocityBCAdapter(const BCFunction &velVx1BC, const BCFunction &velVx2BC, const BCFunction &velVx3BC) { - if( velVx1BC.getEndTime()!=-Ub::inf ) this->vx1BCs.push_back(velVx1BC); - if( velVx2BC.getEndTime()!=-Ub::inf ) this->vx2BCs.push_back(velVx2BC); - if( velVx3BC.getEndTime()!=-Ub::inf ) this->vx3BCs.push_back(velVx3BC); - this->init(); + if (velVx1BC.getEndTime() != -Ub::inf) + this->vx1BCs.push_back(velVx1BC); + if (velVx2BC.getEndTime() != -Ub::inf) + this->vx2BCs.push_back(velVx2BC); + if (velVx3BC.getEndTime() != -Ub::inf) + this->vx3BCs.push_back(velVx3BC); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const vector< BCFunction >& velVx1BCs, const vector< BCFunction >& velVx2BCs, const vector< BCFunction >& velVx3BCs) +VelocityBCAdapter::VelocityBCAdapter(const vector<BCFunction> &velVx1BCs, const vector<BCFunction> &velVx2BCs, + const vector<BCFunction> &velVx3BCs) { - this->vx1BCs = velVx1BCs; - this->vx2BCs = velVx2BCs; - this->vx3BCs = velVx3BCs; - this->init(); + this->vx1BCs = velVx1BCs; + this->vx2BCs = velVx2BCs; + this->vx3BCs = velVx3BCs; + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const double& vx1, const double& vx1StartTime, const double& vx1EndTime, - const double& vx2, const double& vx2StartTime, const double& vx2EndTime, - const double& vx3, const double& vx3StartTime, const double& vx3EndTime ) +VelocityBCAdapter::VelocityBCAdapter(const double &vx1, const double &vx1StartTime, const double &vx1EndTime, + const double &vx2, const double &vx2StartTime, const double &vx2EndTime, + const double &vx3, const double &vx3StartTime, const double &vx3EndTime) { - this->vx1BCs.emplace_back(vx1,vx1StartTime,vx1EndTime); - this->vx2BCs.emplace_back(vx2,vx2StartTime,vx2EndTime); - this->vx3BCs.emplace_back(vx3,vx3StartTime,vx3EndTime); - this->init(); + this->vx1BCs.emplace_back(vx1, vx1StartTime, vx1EndTime); + this->vx2BCs.emplace_back(vx2, vx2StartTime, vx2EndTime); + this->vx3BCs.emplace_back(vx3, vx3StartTime, vx3EndTime); + this->init(); } /*==========================================================*/ -VelocityBCAdapter::VelocityBCAdapter(const string& vx1Function, const double& vx1StartTime, const double& vx1EndTime, - const string& vx2Function, const double& vx2StartTime, const double& vx2EndTime, - const string& vx3Function, const double& vx3StartTime, const double& vx3EndTime ) +VelocityBCAdapter::VelocityBCAdapter(const string &vx1Function, const double &vx1StartTime, const double &vx1EndTime, + const string &vx2Function, const double &vx2StartTime, const double &vx2EndTime, + const string &vx3Function, const double &vx3StartTime, const double &vx3EndTime) { - if(vx1Function.size()) this->vx1BCs.emplace_back(vx1Function,vx1StartTime,vx1EndTime); - if(vx2Function.size()) this->vx2BCs.emplace_back(vx2Function,vx2StartTime,vx2EndTime); - if(vx3Function.size()) this->vx3BCs.emplace_back(vx3Function,vx3StartTime,vx3EndTime); - this->init(); + if (vx1Function.size()) + this->vx1BCs.emplace_back(vx1Function, vx1StartTime, vx1EndTime); + if (vx2Function.size()) + this->vx2BCs.emplace_back(vx2Function, vx2StartTime, vx2EndTime); + if (vx3Function.size()) + this->vx3BCs.emplace_back(vx3Function, vx3StartTime, vx3EndTime); + this->init(); } /*==========================================================*/ -void VelocityBCAdapter::setNewVelocities(const double& vx1, const double& vx1StartTime, const double& vx1EndTime, - const double& vx2, const double& vx2StartTime, const double& vx2EndTime, - const double& vx3, const double& vx3StartTime, const double& vx3EndTime ) +void VelocityBCAdapter::setNewVelocities(const double &vx1, const double &vx1StartTime, const double &vx1EndTime, + const double &vx2, const double &vx2StartTime, const double &vx2EndTime, + const double &vx3, const double &vx3StartTime, const double &vx3EndTime) { - this->clear(); - this->vx1BCs.emplace_back(vx1,vx1StartTime,vx1EndTime); - this->vx2BCs.emplace_back(vx2,vx2StartTime,vx2EndTime); - this->vx3BCs.emplace_back(vx3,vx3StartTime,vx3EndTime); - this->init(); + this->clear(); + this->vx1BCs.emplace_back(vx1, vx1StartTime, vx1EndTime); + this->vx2BCs.emplace_back(vx2, vx2StartTime, vx2EndTime); + this->vx3BCs.emplace_back(vx3, vx3StartTime, vx3EndTime); + this->init(); } /*==========================================================*/ void VelocityBCAdapter::init() { - this->unsetTimeDependent(); - - this->timeStep = 0.0; + this->unsetTimeDependent(); + + this->timeStep = 0.0; - this->x1 = 0.0; - this->x2 = 0.0; - this->x3 = 0.0; + this->x1 = 0.0; + this->x2 = 0.0; + this->x3 = 0.0; - this->tmpVx1Function = NULL; - this->tmpVx2Function = NULL; - this->tmpVx3Function = NULL; + this->tmpVx1Function = NULL; + this->tmpVx2Function = NULL; + this->tmpVx3Function = NULL; - try //initilialization and validation of functions - { - this->init(vx1BCs); - this->init(vx2BCs); - this->init(vx3BCs); - } - catch(mu::Parser::exception_type& e){ stringstream error; error<<"mu::parser exception occurs, message("<<e.GetMsg()<<"), formula("<<e.GetExpr()+"), token("+e.GetToken()<<")" - <<", pos("<<e.GetPos()<<"), error code("<<e.GetCode(); throw UbException(error.str()); } - catch(...) { throw UbException(UB_EXARGS,"unknown exception" ); } + try // initilialization and validation of functions + { + this->init(vx1BCs); + this->init(vx2BCs); + this->init(vx3BCs); + } catch (mu::Parser::exception_type &e) { + stringstream error; + error << "mu::parser exception occurs, message(" << e.GetMsg() << "), formula(" + << e.GetExpr() + "), token(" + e.GetToken() << ")" + << ", pos(" << e.GetPos() << "), error code(" << e.GetCode(); + throw UbException(error.str()); + } catch (...) { + throw UbException(UB_EXARGS, "unknown exception"); + } } /*==========================================================*/ -void VelocityBCAdapter::init(std::vector<BCFunction>& vxBCs) +void VelocityBCAdapter::init(std::vector<BCFunction> &vxBCs) { - for(size_t pos=0; pos<vxBCs.size(); ++pos) - { - if( !( UbMath::equal( BCFunction::INFCONST, vxBCs[pos].getEndTime() ) - && UbMath::greaterEqual( this->timeStep, vxBCs[pos].getStartTime() ) ) ) - { - this->setTimeDependent(); - } + for (size_t pos = 0; pos < vxBCs.size(); ++pos) { + if (!(UbMath::equal(BCFunction::INFCONST, vxBCs[pos].getEndTime()) && + UbMath::greaterEqual(this->timeStep, vxBCs[pos].getStartTime()))) { + this->setTimeDependent(); + } - vxBCs[pos].getFunction().DefineVar("t" , &this->timeStep); - vxBCs[pos].getFunction().DefineVar("x1", &this->x1 ); - vxBCs[pos].getFunction().DefineVar("x2", &this->x2 ); - vxBCs[pos].getFunction().DefineVar("x3", &this->x3 ); + vxBCs[pos].getFunction().DefineVar("t", &this->timeStep); + vxBCs[pos].getFunction().DefineVar("x1", &this->x1); + vxBCs[pos].getFunction().DefineVar("x2", &this->x2); + vxBCs[pos].getFunction().DefineVar("x3", &this->x3); - vxBCs[pos].getFunction().Eval(); //<-- validation - } + vxBCs[pos].getFunction().Eval(); //<-- validation + } } /*==========================================================*/ -void VelocityBCAdapter::init(const D3Q27Interactor* const& interactor, const double& time) +void VelocityBCAdapter::init(const D3Q27Interactor *const &interactor, const double &time) { - this->timeStep = time; - this->tmpVx1Function = this->tmpVx2Function = this->tmpVx3Function = NULL; + this->timeStep = time; + this->tmpVx1Function = this->tmpVx2Function = this->tmpVx3Function = NULL; - //aktuelle velocityfunction bestimmen - double maxEndtime = -Ub::inf; - - for(size_t pos=0; pos<vx1BCs.size(); ++pos) - { - if( UbMath::equal(vx1BCs[pos].getEndTime(),BCFunction::INFTIMEDEPENDENT) ) maxEndtime=Ub::inf; - maxEndtime = UbMath::max(maxEndtime,vx1BCs[pos].getStartTime(),vx1BCs[pos].getEndTime()); //startTime abfragen, da INFCONST=-10 - - if( UbMath::greaterEqual(this->timeStep,vx1BCs[pos].getStartTime()) ) - { - if( UbMath::lessEqual( this->timeStep , vx1BCs[pos].getEndTime() ) - || UbMath::equal( vx1BCs[pos].getEndTime(), (double)BCFunction::INFCONST ) - || UbMath::equal( vx1BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT) ) - { - tmpVx1Function = &vx1BCs[pos].getFunction(); - break; - } - } - } - for(size_t pos=0; pos<vx2BCs.size(); ++pos) - { - if( UbMath::equal(vx2BCs[pos].getEndTime(),BCFunction::INFTIMEDEPENDENT)) maxEndtime=Ub::inf; - maxEndtime = UbMath::max(maxEndtime,vx2BCs[pos].getStartTime(),vx2BCs[pos].getEndTime()); //startTime abfragen, da INFCONST=-10 + // aktuelle velocityfunction bestimmen + double maxEndtime = -Ub::inf; - if( UbMath::greaterEqual(this->timeStep,vx2BCs[pos].getStartTime()) ) - { - if( UbMath::lessEqual( this->timeStep , vx2BCs[pos].getEndTime() ) - || UbMath::equal( vx2BCs[pos].getEndTime(), (double)BCFunction::INFCONST ) - || UbMath::equal( vx2BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT ) ) - { - tmpVx2Function = &vx2BCs[pos].getFunction(); - break; - } - } - } - for(size_t pos=0; pos<vx3BCs.size(); ++pos) - { - if( UbMath::equal(vx3BCs[pos].getEndTime(),BCFunction::INFTIMEDEPENDENT)) maxEndtime=Ub::inf; - maxEndtime = UbMath::max(maxEndtime,vx3BCs[pos].getStartTime(),vx3BCs[pos].getEndTime()); //startTime abfragen, da INFCONST=-10 + for (size_t pos = 0; pos < vx1BCs.size(); ++pos) { + if (UbMath::equal(vx1BCs[pos].getEndTime(), BCFunction::INFTIMEDEPENDENT)) + maxEndtime = Ub::inf; + maxEndtime = UbMath::max(maxEndtime, vx1BCs[pos].getStartTime(), + vx1BCs[pos].getEndTime()); // startTime abfragen, da INFCONST=-10 - if( UbMath::greaterEqual(this->timeStep,vx3BCs[pos].getStartTime()) ) - { - if( UbMath::lessEqual( this->timeStep , vx3BCs[pos].getEndTime() ) - || UbMath::equal( vx3BCs[pos].getEndTime(), (double)BCFunction::INFCONST ) - || UbMath::equal( vx3BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT ) ) - { - tmpVx3Function = &vx3BCs[pos].getFunction(); - break; - } - } - } - - if( UbMath::greaterEqual(time,maxEndtime) ) - { - if( !this->isTimePeriodic() ) this->unsetTimeDependent(); - else //bei peridoic die interavalle neu setzen: - { - if( UbMath::equal(maxEndtime,BCFunction::INFCONST) ) - for(size_t pos=0; pos<vx1BCs.size(); ++pos) - { - vx1BCs[pos].setStartTime( vx1BCs[pos].getStartTime() + timeStep ); - vx1BCs[pos].setEndTime( vx1BCs[pos].getEndTime() + timeStep ); + if (UbMath::greaterEqual(this->timeStep, vx1BCs[pos].getStartTime())) { + if (UbMath::lessEqual(this->timeStep, vx1BCs[pos].getEndTime()) || + UbMath::equal(vx1BCs[pos].getEndTime(), (double)BCFunction::INFCONST) || + UbMath::equal(vx1BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT)) { + tmpVx1Function = &vx1BCs[pos].getFunction(); + break; } - if( UbMath::equal(maxEndtime,BCFunction::INFCONST) ) - for(size_t pos=0; pos<vx2BCs.size(); ++pos) - { - vx2BCs[pos].setStartTime( vx2BCs[pos].getStartTime() + timeStep ); - vx2BCs[pos].setEndTime( vx2BCs[pos].getEndTime() + timeStep ); + } + } + for (size_t pos = 0; pos < vx2BCs.size(); ++pos) { + if (UbMath::equal(vx2BCs[pos].getEndTime(), BCFunction::INFTIMEDEPENDENT)) + maxEndtime = Ub::inf; + maxEndtime = UbMath::max(maxEndtime, vx2BCs[pos].getStartTime(), + vx2BCs[pos].getEndTime()); // startTime abfragen, da INFCONST=-10 + + if (UbMath::greaterEqual(this->timeStep, vx2BCs[pos].getStartTime())) { + if (UbMath::lessEqual(this->timeStep, vx2BCs[pos].getEndTime()) || + UbMath::equal(vx2BCs[pos].getEndTime(), (double)BCFunction::INFCONST) || + UbMath::equal(vx2BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT)) { + tmpVx2Function = &vx2BCs[pos].getFunction(); + break; } - if( UbMath::equal(maxEndtime,BCFunction::INFCONST) ) - for(size_t pos=0; pos<vx3BCs.size(); ++pos) - { - vx3BCs[pos].setStartTime( vx3BCs[pos].getStartTime() + timeStep ); - vx3BCs[pos].setEndTime( vx3BCs[pos].getEndTime() + timeStep ); + } + } + for (size_t pos = 0; pos < vx3BCs.size(); ++pos) { + if (UbMath::equal(vx3BCs[pos].getEndTime(), BCFunction::INFTIMEDEPENDENT)) + maxEndtime = Ub::inf; + maxEndtime = UbMath::max(maxEndtime, vx3BCs[pos].getStartTime(), + vx3BCs[pos].getEndTime()); // startTime abfragen, da INFCONST=-10 + + if (UbMath::greaterEqual(this->timeStep, vx3BCs[pos].getStartTime())) { + if (UbMath::lessEqual(this->timeStep, vx3BCs[pos].getEndTime()) || + UbMath::equal(vx3BCs[pos].getEndTime(), (double)BCFunction::INFCONST) || + UbMath::equal(vx3BCs[pos].getEndTime(), (double)BCFunction::INFTIMEDEPENDENT)) { + tmpVx3Function = &vx3BCs[pos].getFunction(); + break; } - this->init(interactor,time); - } - } + } + } - UBLOG(logDEBUG4,"D3Q27VelocityBCAdapter::init(time="<<time<<") " - <<", vx1= \""<<(tmpVx1Function ? tmpVx1Function->GetExpr() : "-")<<"\"" - <<", vx2= \""<<(tmpVx2Function ? tmpVx2Function->GetExpr() : "-")<<"\"" - <<", vx3= \""<<(tmpVx3Function ? tmpVx3Function->GetExpr() : "-")<<"\"" - <<", timedependent="<<boolalpha<<this->isTimeDependent() ); + if (UbMath::greaterEqual(time, maxEndtime)) { + if (!this->isTimePeriodic()) + this->unsetTimeDependent(); + else // bei peridoic die interavalle neu setzen: + { + if (UbMath::equal(maxEndtime, BCFunction::INFCONST)) + for (size_t pos = 0; pos < vx1BCs.size(); ++pos) { + vx1BCs[pos].setStartTime(vx1BCs[pos].getStartTime() + timeStep); + vx1BCs[pos].setEndTime(vx1BCs[pos].getEndTime() + timeStep); + } + if (UbMath::equal(maxEndtime, BCFunction::INFCONST)) + for (size_t pos = 0; pos < vx2BCs.size(); ++pos) { + vx2BCs[pos].setStartTime(vx2BCs[pos].getStartTime() + timeStep); + vx2BCs[pos].setEndTime(vx2BCs[pos].getEndTime() + timeStep); + } + if (UbMath::equal(maxEndtime, BCFunction::INFCONST)) + for (size_t pos = 0; pos < vx3BCs.size(); ++pos) { + vx3BCs[pos].setStartTime(vx3BCs[pos].getStartTime() + timeStep); + vx3BCs[pos].setEndTime(vx3BCs[pos].getEndTime() + timeStep); + } + this->init(interactor, time); + } + } + + UBLOG(logDEBUG4, "D3Q27VelocityBCAdapter::init(time=" + << time << ") " + << ", vx1= \"" << (tmpVx1Function ? tmpVx1Function->GetExpr() : "-") << "\"" + << ", vx2= \"" << (tmpVx2Function ? tmpVx2Function->GetExpr() : "-") << "\"" + << ", vx3= \"" << (tmpVx3Function ? tmpVx3Function->GetExpr() : "-") << "\"" + << ", timedependent=" << boolalpha << this->isTimeDependent()); } /*==========================================================*/ -void VelocityBCAdapter::update( const D3Q27Interactor* const& interactor, const double& time ) +void VelocityBCAdapter::update(const D3Q27Interactor *const &interactor, const double &time) { - this->init(interactor,time); + this->init(interactor, time); } /*==========================================================*/ -void VelocityBCAdapter::adaptBCForDirection( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& /*worldX1*/, const double& /*worldX2*/, const double& /*worldX3*/, const double& q, const int& fdirection, const double& /*time*/ ) +void VelocityBCAdapter::adaptBCForDirection(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double & /*worldX1*/, const double & /*worldX2*/, + const double & /*worldX3*/, const double &q, const int &fdirection, + const double & /*time*/) { - bc->setVelocityBoundaryFlag(D3Q27System::INVDIR[fdirection],secondaryBcOption); - bc->setQ((float)q,fdirection); + bc->setVelocityBoundaryFlag(D3Q27System::INVDIR[fdirection], secondaryBcOption); + bc->setQ((float)q, fdirection); } /*==========================================================*/ -void VelocityBCAdapter::adaptBC( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time ) +void VelocityBCAdapter::adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time) { - this->setNodeVelocity(interactor,bc,worldX1,worldX2,worldX3,time); - bc->setBcAlgorithmType(algorithmType); + this->setNodeVelocity(interactor, bc, worldX1, worldX2, worldX3, time); + bc->setBcAlgorithmType(algorithmType); } /*==========================================================*/ -void VelocityBCAdapter::setNodeVelocity( const D3Q27Interactor& /*interactor*/, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& timestep) +void VelocityBCAdapter::setNodeVelocity(const D3Q27Interactor & /*interactor*/, SPtr<BoundaryConditions> bc, + const double &worldX1, const double &worldX2, const double &worldX3, + const double ×tep) { - //Geschwindigkeiten setzen - try - { - //PunktKoordinaten bestimmen - this->x1 = worldX1; - this->x2 = worldX2; - this->x3 = worldX3; - this->timeStep = timestep; + // Geschwindigkeiten setzen + try { + // PunktKoordinaten bestimmen + this->x1 = worldX1; + this->x2 = worldX2; + this->x3 = worldX3; + this->timeStep = timestep; - if(tmpVx1Function) bc->setBoundaryVelocityX1((LBMReal)tmpVx1Function->Eval()); - if(tmpVx2Function) bc->setBoundaryVelocityX2((LBMReal)tmpVx2Function->Eval()); - if(tmpVx3Function) bc->setBoundaryVelocityX3((LBMReal)tmpVx3Function->Eval()); - } - catch(mu::Parser::exception_type& e){ stringstream error; error<<"mu::parser exception occurs, message("<<e.GetMsg()<<"), formula("<<e.GetExpr()+"), token("+e.GetToken()<<")" - <<", pos("<<e.GetPos()<<"), error code("<<e.GetCode(); throw UbException(error.str()); } - catch(...) { throw UbException(UB_EXARGS,"unknown exception" ); } + if (tmpVx1Function) + bc->setBoundaryVelocityX1((LBMReal)tmpVx1Function->Eval()); + if (tmpVx2Function) + bc->setBoundaryVelocityX2((LBMReal)tmpVx2Function->Eval()); + if (tmpVx3Function) + bc->setBoundaryVelocityX3((LBMReal)tmpVx3Function->Eval()); + } catch (mu::Parser::exception_type &e) { + stringstream error; + error << "mu::parser exception occurs, message(" << e.GetMsg() << "), formula(" + << e.GetExpr() + "), token(" + e.GetToken() << ")" + << ", pos(" << e.GetPos() << "), error code(" << e.GetCode(); + throw UbException(error.str()); + } catch (...) { + throw UbException(UB_EXARGS, "unknown exception"); + } } /*==========================================================*/ -UbTupleDouble3 VelocityBCAdapter::getVelocity(const double& x1, const double& x2, const double& x3, const double& timeStep) const +UbTupleDouble3 VelocityBCAdapter::getVelocity(const double &x1, const double &x2, const double &x3, + const double &timeStep) const { - double vx1 = 0.0; - double vx2 = 0.0; - double vx3 = 0.0; - this->x1 = x1; - this->x2 = x2; - this->x3 = x3; - this->timeStep = timeStep; - - if(tmpVx1Function) vx1 = tmpVx1Function->Eval(); - if(tmpVx2Function) vx2 = tmpVx2Function->Eval(); - if(tmpVx3Function) vx3 = tmpVx3Function->Eval(); - - return { vx1,vx2,vx3 }; + double vx1 = 0.0; + double vx2 = 0.0; + double vx3 = 0.0; + this->x1 = x1; + this->x2 = x2; + this->x3 = x3; + this->timeStep = timeStep; + + if (tmpVx1Function) + vx1 = tmpVx1Function->Eval(); + if (tmpVx2Function) + vx2 = tmpVx2Function->Eval(); + if (tmpVx3Function) + vx3 = tmpVx3Function->Eval(); + + return { vx1, vx2, vx3 }; } /*==========================================================*/ string VelocityBCAdapter::toString() { - stringstream info; - info<<"D3Q27VelocityBCAdapter:\n"; - info<<" #vx1-functions = "<<(int)vx1BCs.size()<<endl; - info<<" #vx2-functions = "<<(int)vx2BCs.size()<<endl; - info<<" #vx3-functions = "<<(int)vx3BCs.size()<<endl; - info<<" protected variables: x1, x2, x3, t"<<endl; - - const vector<BCFunction>* bcvecs[3] = { &vx1BCs, &vx2BCs, &vx3BCs }; - for(int i=0; i<3; i++) - { - for(size_t pos=0; pos<bcvecs[i]->size(); ++pos) - { - info<<"\n vx"<<(i+1)<<"-function nr."<<pos<<":"<<endl; - info<<(*bcvecs[i])[pos]<<endl; - } - } - return info.str(); -} - + stringstream info; + info << "D3Q27VelocityBCAdapter:\n"; + info << " #vx1-functions = " << (int)vx1BCs.size() << endl; + info << " #vx2-functions = " << (int)vx2BCs.size() << endl; + info << " #vx3-functions = " << (int)vx3BCs.size() << endl; + info << " protected variables: x1, x2, x3, t" << endl; + const vector<BCFunction> *bcvecs[3] = { &vx1BCs, &vx2BCs, &vx3BCs }; + for (int i = 0; i < 3; i++) { + for (size_t pos = 0; pos < bcvecs[i]->size(); ++pos) { + info << "\n vx" << (i + 1) << "-function nr." << pos << ":" << endl; + info << (*bcvecs[i])[pos] << endl; + } + } + return info.str(); +} diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.h index 4c2b666fc..c6f5039a3 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAdapter.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,8 +34,8 @@ #define VelocityBCAdapter_H #include <iostream> -#include <string> #include <sstream> +#include <string> #include <vector> #include <basics/utilities/UbInfinity.h> @@ -45,17 +45,17 @@ //! \brief A class provides an interface for velocity boundary condition in grid generator. -//! \details +//! \details //! Example: //! \code{.cpp} vector<BCFunction> vx1BCs,vx2BCs,vx3BCs; //! vx1BCs.push_back(BCFunction(0.01 , 0 , 100) ); //t=[0 ..100[ -> vx1 = 0.01 //! vx1BCs.push_back(BCFunction(0.004, 100, 200) ); //t=[100..200[ -> vx1 = 0.004 //! vx1BCs.push_back(BCFunction(0.03 , 200, 400) ); //t=[200..400] -> vx1 = 0.03 -//! +//! //! vx2BCs.push_back(BCFunction(0.02 , 0 , 200) ); //t=[0 ..200[ -> vx2 = 0.02 //! vx2BCs.push_back(BCFunction(0.002, 200, 300) ); //t=[200..300[ -> vx2 = 0.002 //! vx2BCs.push_back(BCFunction(0.043, 300, 600) ); //t=[300..600] -> vx2 = 0.043 -//! +//! //! VelocityBCAdapter bcAdapter(vx1BCs,vx2BCs,vx3BCs); //! bcAdapter.setTimePeriodic(); //-> t=[0 ..100[ -> vx1 = 0.01 //! // t=[100..200[ -> vx1 = 0.004 @@ -73,90 +73,100 @@ //! Example of parabolic inflow: //! \code{.cpp} //! mu::Parser fct; -//! fct.SetExpr("max(vmax*(1.0-4.0*((x2-x2_vmax)^2+(x3-x3_vmax)^2)/H^2),0.0)"); //paraboloid (with vmax for (0/x2_vmax/x3_vmax) -//! fct.DefineConst("x2Vmax", 0.0 ); //x2-Pos für vmax -//! fct.DefineConst("x3Vmax", 0.0 ); //x3-Pos für vmax -//! fct.DefineConst("H" , diameterOfPipe); -//! fct.DefineConst("vmax" , vmax ); +//! fct.SetExpr("max(vmax*(1.0-4.0*((x2-x2_vmax)^2+(x3-x3_vmax)^2)/H^2),0.0)"); //paraboloid (with vmax for +//! (0/x2_vmax/x3_vmax) fct.DefineConst("x2Vmax", 0.0 ); //x2-Pos für vmax fct.DefineConst("x3Vmax", 0.0 +//! ); //x3-Pos für vmax fct.DefineConst("H" , diameterOfPipe); fct.DefineConst("vmax" , vmax ); //! VelocityBCAdapter velBC(true, false ,false ,fct, 0, BCFunction::INFCONST); //! \endcode class VelocityBCAdapter : public BCAdapter { public: - //constructors - VelocityBCAdapter() { this->init(); } - - VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const BCFunction& velVxBC ); + // constructors + VelocityBCAdapter() { this->init(); } - VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const mu::Parser& function, const double& startTime, const double& endTime ); + VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const BCFunction &velVxBC); - VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const mu::Parser& function1, const mu::Parser& function2, const mu::Parser& function3, const double& startTime, const double& endTime ); - - VelocityBCAdapter(const bool& vx1, const bool& vx2, const bool& vx3, const std::string& functionstring, const double& startTime, const double& endTime ); + VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const mu::Parser &function, + const double &startTime, const double &endTime); - VelocityBCAdapter(const BCFunction& velBC, bool x1Dir, bool x2Dir, bool x3Dir); + VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const mu::Parser &function1, + const mu::Parser &function2, const mu::Parser &function3, const double &startTime, + const double &endTime); - VelocityBCAdapter(const BCFunction& velVx1BC, const BCFunction& velVx2BC, const BCFunction& velVx3BC); + VelocityBCAdapter(const bool &vx1, const bool &vx2, const bool &vx3, const std::string &functionstring, + const double &startTime, const double &endTime); - VelocityBCAdapter(const std::vector< BCFunction >& velVx1BCs, const std::vector< BCFunction >& velVx2BCs, const std::vector< BCFunction >& velVx3BCs); + VelocityBCAdapter(const BCFunction &velBC, bool x1Dir, bool x2Dir, bool x3Dir); - VelocityBCAdapter(const double& vx1, const double& vx1StartTime, const double& vx1EndTime, - const double& vx2, const double& vx2StartTime, const double& vx2EndTime, - const double& vx3, const double& vx3StartTime, const double& vx3EndTime); + VelocityBCAdapter(const BCFunction &velVx1BC, const BCFunction &velVx2BC, const BCFunction &velVx3BC); - VelocityBCAdapter(const std::string& vx1Function, const double& vx1StartTime, const double& vx1EndTime, - const std::string& vx2Function, const double& vx2StartTime, const double& vx2EndTime, - const std::string& vx3Function, const double& vx3StartTime, const double& vx3EndTime ); + VelocityBCAdapter(const std::vector<BCFunction> &velVx1BCs, const std::vector<BCFunction> &velVx2BCs, + const std::vector<BCFunction> &velVx3BCs); - //methods - void setTimePeriodic() { (this->type |= TIMEPERIODIC); } - void unsetTimePeriodic() { (this->type &= ~TIMEPERIODIC); } - bool isTimePeriodic() { return ((this->type & TIMEPERIODIC) == TIMEPERIODIC); } + VelocityBCAdapter(const double &vx1, const double &vx1StartTime, const double &vx1EndTime, const double &vx2, + const double &vx2StartTime, const double &vx2EndTime, const double &vx3, + const double &vx3StartTime, const double &vx3EndTime); - //The following is meant for moving objects... - void setNewVelocities(const double& vx1, const double& vx1StartTime, const double& vx1EndTime, - const double& vx2, const double& vx2StartTime, const double& vx2EndTime, - const double& vx3, const double& vx3StartTime, const double& vx3EndTime); + VelocityBCAdapter(const std::string &vx1Function, const double &vx1StartTime, const double &vx1EndTime, + const std::string &vx2Function, const double &vx2StartTime, const double &vx2EndTime, + const std::string &vx3Function, const double &vx3StartTime, const double &vx3EndTime); - - //------------- implements BCAdapter ----- start - std::string toString(); - - void init(const D3Q27Interactor* const& interactor, const double& time=0) override; - void update(const D3Q27Interactor* const& interactor, const double& time=0) override; + // methods + void setTimePeriodic() { (this->type |= TIMEPERIODIC); } + void unsetTimePeriodic() { (this->type &= ~TIMEPERIODIC); } + bool isTimePeriodic() { return ((this->type & TIMEPERIODIC) == TIMEPERIODIC); } - void adaptBCForDirection( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& q, const int& fdirection, const double& time=0 ) override; - void adaptBC( const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& time=0 ) override; + // The following is meant for moving objects... + void setNewVelocities(const double &vx1, const double &vx1StartTime, const double &vx1EndTime, const double &vx2, + const double &vx2StartTime, const double &vx2EndTime, const double &vx3, + const double &vx3StartTime, const double &vx3EndTime); - //------------- implements BCAdapter ----- end + //------------- implements BCAdapter ----- start + std::string toString(); - UbTupleDouble3 getVelocity(const double& x1, const double& x2, const double& x3, const double& timeStep) const; + void init(const D3Q27Interactor *const &interactor, const double &time = 0) override; + void update(const D3Q27Interactor *const &interactor, const double &time = 0) override; + void adaptBCForDirection(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &q, const int &fdirection, + const double &time = 0) override; + void adaptBC(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double &time = 0) override; -protected: - void init(); - void init(std::vector<BCFunction>& vxBCs); + //------------- implements BCAdapter ----- end - //time dependency is determined automatically via BCFunction intervals! - void setTimeDependent() { (this->type |= TIMEDEPENDENT); } - void unsetTimeDependent() { (this->type &= ~TIMEDEPENDENT); } + UbTupleDouble3 getVelocity(const double &x1, const double &x2, const double &x3, const double &timeStep) const; - void clear() { vx1BCs.clear(); vx2BCs.clear(); vx3BCs.clear(); this->init(); } - void setNodeVelocity(const D3Q27Interactor& interactor, SPtr<BoundaryConditions> bc, const double& worldX1, const double& worldX2, const double& worldX3, const double& timestep); +protected: + void init(); + void init(std::vector<BCFunction> &vxBCs); + + // time dependency is determined automatically via BCFunction intervals! + void setTimeDependent() { (this->type |= TIMEDEPENDENT); } + void unsetTimeDependent() { (this->type &= ~TIMEDEPENDENT); } + + void clear() + { + vx1BCs.clear(); + vx2BCs.clear(); + vx3BCs.clear(); + this->init(); + } + void setNodeVelocity(const D3Q27Interactor &interactor, SPtr<BoundaryConditions> bc, const double &worldX1, + const double &worldX2, const double &worldX3, const double ×tep); private: - mutable mu::value_type x1, x2, x3; - mutable mu::value_type timeStep; - - mu::Parser* tmpVx1Function; - mu::Parser* tmpVx2Function; - mu::Parser* tmpVx3Function; + mutable mu::value_type x1, x2, x3; + mutable mu::value_type timeStep; - std::vector<BCFunction> vx1BCs; - std::vector<BCFunction> vx2BCs; - std::vector<BCFunction> vx3BCs; + mu::Parser *tmpVx1Function; + mu::Parser *tmpVx2Function; + mu::Parser *tmpVx3Function; + std::vector<BCFunction> vx1BCs; + std::vector<BCFunction> vx2BCs; + std::vector<BCFunction> vx3BCs; }; #endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.cpp index b08a5bb85..4905e76a9 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,48 +32,47 @@ //======================================================================================= #include "VelocityBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BoundaryConditions.h" +#include "DistributionArray3D.h" VelocityBCAlgorithm::VelocityBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::VelocityBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::VelocityBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> VelocityBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new VelocityBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new VelocityBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void VelocityBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void VelocityBCAlgorithm::applyBC() { - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - distributions->getDistributionInv(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3, drho; - calcMacrosFct(f, drho, vx1, vx2, vx3); - calcFeqFct(feq, drho, vx1, vx2, vx3); - - rho = 1.0+drho*compressibleFactor; + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3, drho; + calcMacrosFct(f, drho, vx1, vx2, vx3); + calcFeqFct(feq, drho, vx1, vx2, vx3); - for (int fdir = D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if (bcPtr->hasVelocityBoundaryFlag(fdir)) - { - const int invDir = D3Q27System::INVDIR[fdir]; - LBMReal q = bcPtr->getQ(invDir); - LBMReal velocity = bcPtr->getBoundaryVelocity(invDir); - LBMReal fReturn = ((1.0-q)/(1.0+q))*((f[invDir]-feq[invDir])/(1.0-collFactor)+feq[invDir])+((q*(f[invDir]+f[fdir])-velocity*rho)/(1.0+q)); - distributions->setDistributionForDirection(fReturn, x1+D3Q27System::DX1[invDir], x2+D3Q27System::DX2[invDir], x3+D3Q27System::DX3[invDir], fdir); - } - } + rho = 1.0 + drho * compressibleFactor; + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bcPtr->hasVelocityBoundaryFlag(fdir)) { + const int invDir = D3Q27System::INVDIR[fdir]; + LBMReal q = bcPtr->getQ(invDir); + LBMReal velocity = bcPtr->getBoundaryVelocity(invDir); + LBMReal fReturn = ((1.0 - q) / (1.0 + q)) * ((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + + ((q * (f[invDir] + f[fdir]) - velocity * rho) / (1.0 + q)); + distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], + x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], + fdir); + } + } } - diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.h index fedd86982..44bbd2cee 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityBCAlgorithm.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -43,11 +43,10 @@ class DistributionArray3D; class VelocityBCAlgorithm : public BCAlgorithm { public: - VelocityBCAlgorithm(); - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + VelocityBCAlgorithm(); + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; -#endif - +#endif diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.cpp b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.cpp index 7ebad4fa0..98ead1e2d 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.cpp +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.cpp @@ -1,82 +1,85 @@ #include "VelocityWithDensityBCAlgorithm.h" -#include "DistributionArray3D.h" #include "BCArray3D.h" +#include "DistributionArray3D.h" VelocityWithDensityBCAlgorithm::VelocityWithDensityBCAlgorithm() { - BCAlgorithm::type = BCAlgorithm::VelocityWithDensityBCAlgorithm; - BCAlgorithm::preCollision = false; + BCAlgorithm::type = BCAlgorithm::VelocityWithDensityBCAlgorithm; + BCAlgorithm::preCollision = false; } ////////////////////////////////////////////////////////////////////////// -VelocityWithDensityBCAlgorithm::~VelocityWithDensityBCAlgorithm() -= default; +VelocityWithDensityBCAlgorithm::~VelocityWithDensityBCAlgorithm() = default; ////////////////////////////////////////////////////////////////////////// SPtr<BCAlgorithm> VelocityWithDensityBCAlgorithm::clone() { - SPtr<BCAlgorithm> bc(new VelocityWithDensityBCAlgorithm()); - return bc; + SPtr<BCAlgorithm> bc(new VelocityWithDensityBCAlgorithm()); + return bc; } ////////////////////////////////////////////////////////////////////////// void VelocityWithDensityBCAlgorithm::addDistributions(SPtr<DistributionArray3D> distributions) { - this->distributions = distributions; + this->distributions = distributions; } ////////////////////////////////////////////////////////////////////////// void VelocityWithDensityBCAlgorithm::applyBC() { - //velocity bc for non reflecting pressure bc - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - distributions->getDistributionInv(f, x1, x2, x3); - LBMReal rho, vx1, vx2, vx3, drho; - calcMacrosFct(f, drho, vx1, vx2, vx3); - calcFeqFct(feq, drho, vx1, vx2, vx3); - - rho = 1.0+drho*compressibleFactor; + // velocity bc for non reflecting pressure bc + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + distributions->getDistributionInv(f, x1, x2, x3); + LBMReal rho, vx1, vx2, vx3, drho; + calcMacrosFct(f, drho, vx1, vx2, vx3); + calcFeqFct(feq, drho, vx1, vx2, vx3); + + rho = 1.0 + drho * compressibleFactor; - for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) - { - //if (bcPtr->hasVelocityBoundaryFlag(fdir)) - //{ - // const int invDir = D3Q27System::INVDIR[fdir]; - // LBMReal q = bcPtr->getQ(invDir);// m+m q=0 stabiler - // LBMReal velocity = bcPtr->getBoundaryVelocity(invDir); - // //normal velocity bc: LBMReal fReturn = ((1.0-q)/(1.0+q))*((f[invDir]-feq[invDir])/(1.0-collFactor)+feq[invDir])+((q*(f[invDir]+f[fdir])-velocity*rho)/(1.0+q)); - // //LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + ((q*(f[invDir] + f[fdir]) - velocity) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; - // //LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + ((q*(f[invDir] + f[fdir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; - // LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]*collFactor) / (1.0 - collFactor)) + ((q*(f[invDir] + f[fdir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; - // - // distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); - //} - - int nX1 = x1 + D3Q27System::DX1[fdir]; - int nX2 = x2 + D3Q27System::DX2[fdir]; - int nX3 = x3 + D3Q27System::DX3[fdir]; + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + // if (bcPtr->hasVelocityBoundaryFlag(fdir)) + //{ + // const int invDir = D3Q27System::INVDIR[fdir]; + // LBMReal q = bcPtr->getQ(invDir);// m+m q=0 stabiler + // LBMReal velocity = bcPtr->getBoundaryVelocity(invDir); + // //normal velocity bc: LBMReal fReturn = + // ((1.0-q)/(1.0+q))*((f[invDir]-feq[invDir])/(1.0-collFactor)+feq[invDir])+((q*(f[invDir]+f[fdir])-velocity*rho)/(1.0+q)); + // //LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + // + ((q*(f[invDir] + f[fdir]) - velocity) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; + // //LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]) / (1.0 - collFactor) + feq[invDir]) + // + ((q*(f[invDir] + f[fdir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; LBMReal fReturn + // = ((1.0 - q) / (1.0 + q))*((f[invDir] - feq[invDir]*collFactor) / (1.0 - collFactor)) + ((q*(f[invDir] + + // f[fdir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; + // + // distributions->setDistributionForDirection(fReturn, x1 + D3Q27System::DX1[invDir], x2 + + // D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); + //} - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; + int nX1 = x1 + D3Q27System::DX1[fdir]; + int nX2 = x2 + D3Q27System::DX2[fdir]; + int nX3 = x3 + D3Q27System::DX3[fdir]; - int maxX1 = (int)bcArray->getNX1(); - int maxX2 = (int)bcArray->getNX2(); - int maxX3 = (int)bcArray->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; - if (minX1 <= nX1 && maxX1 > nX1 && minX2 <= nX2 && maxX2 > nX2 && minX3 <= nX3 && maxX3 > nX3) - { - if (bcArray->isSolid(nX1,nX2,nX3)) - { - const int invDir = D3Q27System::INVDIR[fdir]; -// LBMReal q =1.0;// bcPtr->getQ(invDir);// m+m q=0 stabiler - LBMReal velocity = bcPtr->getBoundaryVelocity(fdir); -// LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[fdir] - feq[fdir]*collFactor) / (1.0 - collFactor)) + ((q*(f[fdir] + f[invDir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; + int maxX1 = (int)bcArray->getNX1(); + int maxX2 = (int)bcArray->getNX2(); + int maxX3 = (int)bcArray->getNX3(); - //if q=1 - //LBMReal fReturn = ((q*(f[fdir] + f[invDir]) - velocity*rho) / (1.0 + q))-drho*D3Q27System::WEIGTH[invDir]; - LBMReal fReturn = (f[fdir] + f[invDir] - velocity*rho) / 2.0 - drho*D3Q27System::WEIGTH[invDir]; + if (minX1 <= nX1 && maxX1 > nX1 && minX2 <= nX2 && maxX2 > nX2 && minX3 <= nX3 && maxX3 > nX3) { + if (bcArray->isSolid(nX1, nX2, nX3)) { + const int invDir = D3Q27System::INVDIR[fdir]; + // LBMReal q =1.0;// bcPtr->getQ(invDir);// m+m q=0 stabiler + LBMReal velocity = bcPtr->getBoundaryVelocity(fdir); + // LBMReal fReturn = ((1.0 - q) / (1.0 + q))*((f[fdir] - feq[fdir]*collFactor) / (1.0 - + // collFactor)) + ((q*(f[fdir] + f[invDir]) - velocity*rho) / (1.0 + + // q))-drho*D3Q27System::WEIGTH[invDir]; - distributions->setDistributionForDirection(fReturn, nX1, nX2, nX3, invDir); - } - } + // if q=1 + // LBMReal fReturn = ((q*(f[fdir] + f[invDir]) - velocity*rho) / (1.0 + + // q))-drho*D3Q27System::WEIGTH[invDir]; + LBMReal fReturn = (f[fdir] + f[invDir] - velocity * rho) / 2.0 - drho * D3Q27System::WEIGTH[invDir]; - } + distributions->setDistributionForDirection(fReturn, nX1, nX2, nX3, invDir); + } + } + } } diff --git a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.h b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.h index 2216501db..c590bd4a9 100644 --- a/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.h +++ b/src/cpu/VirtualFluidsCore/BoundaryConditions/VelocityWithDensityBCAlgorithm.h @@ -10,15 +10,16 @@ class DistributionArray3D; -//! \brief Class implements Dirichlet boundary condition for velocity. Set density in system. It is used together with non reflecting outflow. +//! \brief Class implements Dirichlet boundary condition for velocity. Set density in system. It is used together with +//! non reflecting outflow. class VelocityWithDensityBCAlgorithm : public BCAlgorithm { public: - VelocityWithDensityBCAlgorithm(); - ~VelocityWithDensityBCAlgorithm() override; - SPtr<BCAlgorithm> clone() override; - void addDistributions(SPtr<DistributionArray3D> distributions) override; - void applyBC() override; + VelocityWithDensityBCAlgorithm(); + ~VelocityWithDensityBCAlgorithm() override; + SPtr<BCAlgorithm> clone() override; + void addDistributions(SPtr<DistributionArray3D> distributions) override; + void applyBC() override; }; #endif // NonReflectingVelocityBCAlgorithm_h__ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.cpp index eda63069e..217409010 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.cpp @@ -1,168 +1,166 @@ /* -* D3Q27AdjustForcingCoProcessor.cpp -* Author: Konstantin Kutscher -*/ + * D3Q27AdjustForcingCoProcessor.cpp + * Author: Konstantin Kutscher + */ #include "AdjustForcingCoProcessor.h" #include <fstream> -#include <SetForcingBlockVisitor.h> -#include "IntegrateValuesHelper.h" #include "Communicator.h" -#include "UbScheduler.h" #include "Grid3D.h" +#include "IntegrateValuesHelper.h" +#include "UbScheduler.h" +#include <SetForcingBlockVisitor.h> + +AdjustForcingCoProcessor::AdjustForcingCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<IntegrateValuesHelper> integrateValues, double vTarged, + SPtr<Communicator> comm) -AdjustForcingCoProcessor::AdjustForcingCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, - SPtr<IntegrateValuesHelper> integrateValues, - double vTarged, - SPtr<Communicator> comm) - - : CoProcessor(grid, s), - path(path), - integrateValues(integrateValues), - comm(comm), - vx1Targed(vTarged) + : CoProcessor(grid, s), path(path), integrateValues(integrateValues), comm(comm), vx1Targed(vTarged) { - //cnodes = integrateValues->getCNodes(); - root = comm->isRoot(); - - Ta = scheduler->getMaxStep(); - - Kpcrit = 3.0 / Ta;// 0.3; - Tcrit = 3.0 * Ta; // 30.0; - Tn = 0.5 * Tcrit; - Tv = 0.12 * Tcrit; - - Kp = 0.6 * Kpcrit; - Ki = Kp / Tn; - Kd = Kp * Tv; - - y = 0; - e = 0; - esum = 0; - eold = 0; - forcing = 0; - - if (root) - { - std::string fname = path + "/forcing/forcing.csv"; - std::ofstream ostr; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if (!ostr) - { - ostr.clear(); - std::string file_path = UbSystem::getPathFromString(fname); - if (file_path.size() > 0) { UbSystem::makeDirectory(file_path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file " + fname); - } - ostr << "step;volume;vx1average;forcing\n"; - ostr.close(); - - ////////////////////////////////////////////////////////////////////////////////////////////////// - //temporary solution - std::string fNameCfg = path + "/forcing/forcing.cfg"; - std::ifstream istr2; - istr2.open(fNameCfg.c_str(), std::ios_base::in); - if (istr2) - { - istr2 >> forcing; - //istr2 >> esum; - //istr2 >> eold; - } - istr2.close(); - } - //////////////////////////////////////////////////////////////////////////////////////////////////////// + // cnodes = integrateValues->getCNodes(); + root = comm->isRoot(); + + Ta = scheduler->getMaxStep(); + + Kpcrit = 3.0 / Ta; // 0.3; + Tcrit = 3.0 * Ta; // 30.0; + Tn = 0.5 * Tcrit; + Tv = 0.12 * Tcrit; + + Kp = 0.6 * Kpcrit; + Ki = Kp / Tn; + Kd = Kp * Tv; + + y = 0; + e = 0; + esum = 0; + eold = 0; + forcing = 0; + + if (root) { + std::string fname = path + "/forcing/forcing.csv"; + std::ofstream ostr; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string file_path = UbSystem::getPathFromString(fname); + if (file_path.size() > 0) { + UbSystem::makeDirectory(file_path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr << "step;volume;vx1average;forcing\n"; + ostr.close(); + + ////////////////////////////////////////////////////////////////////////////////////////////////// + // temporary solution + std::string fNameCfg = path + "/forcing/forcing.cfg"; + std::ifstream istr2; + istr2.open(fNameCfg.c_str(), std::ios_base::in); + if (istr2) { + istr2 >> forcing; + // istr2 >> esum; + // istr2 >> eold; + } + istr2.close(); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////// } ////////////////////////////////////////////////////////////////////////// void AdjustForcingCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// void AdjustForcingCoProcessor::collectData(double step) { - ////////////////////////////////////////////////////////////////////////////////////////////////// - //temporary solution - if (root) - { - std::string fNameCfg = path + "/forcing/forcing.cfg"; - std::ofstream ostr2; - ostr2.open(fNameCfg.c_str(), std::ios_base::out); - if (!ostr2) - { - ostr2.clear(); - std::string path = UbSystem::getPathFromString(fNameCfg); - if (path.size() > 0) { UbSystem::makeDirectory(path); ostr2.open(fNameCfg.c_str(), std::ios_base::out); } - if (!ostr2) throw UbException(UB_EXARGS, "couldn't open file " + fNameCfg); - } - ostr2 << forcing << " " << esum << " " << eold; - ostr2.close(); - } - //////////////////////////////////////////////////////////////////////////////////////////////////////// - - integrateValues->calculateMQ(); - - if (root) - { - cellsVolume = integrateValues->getCellsVolume(); - double vx1 = integrateValues->getVx1(); - vx1Average = (vx1 / cellsVolume); - - ////////////////////////////////////////////////////////////////////////// - //PID-Controller (PID-Regler) - e = vx1Targed - vx1Average; - esum = esum + e; - y = Kp * e + Ki * Ta * esum + Kd * (e - eold) / Ta; - eold = e; - - forcing = forcing + y; - ////////////////////////////////////////////////////////////////////////// - } - ////////////////////////////////////////////////////////////////////////// - comm->broadcast(forcing); - - mu::Parser fctForcingX1, fctForcingX2, fctForcingX3; - fctForcingX1.SetExpr("Fx1"); - fctForcingX1.DefineConst("Fx1", forcing); - fctForcingX2.SetExpr("0.0"); - fctForcingX3.SetExpr("0.0"); - SetForcingBlockVisitor forcingVisitor(fctForcingX1, fctForcingX2, fctForcingX3); - grid->accept(forcingVisitor); - - //for(CalcNodes cn : cnodes) - //{ - // LBMKernel3DPtr kernel = cn.block->getKernel(); - // if (kernel) - // { - // kernel->setForcingX1(fctForcingX1); - // kernel->setWithForcing(true); - // } - // - //} - - if (root) - { - //UBLOG(logINFO, "D3Q27AdjustForcingCoProcessor step: " << static_cast<int>(step)); - //UBLOG(logINFO, "new forcing is: " << forcing); - std::string fname = path + "/forcing/forcing.csv"; - //std::string fname = path + "/forcing/forcing_"+UbSystem::toString(comm->getProcessID())+".csv"; - std::ofstream ostr; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size() > 0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file " + fname); - } - int istep = static_cast<int>(step); - - //ostr << istep << ";" << cellsVolume << ";" << vx1Average << "; " << forcing << "\n"; - ostr << istep << ";" << cellsVolume << ";" << vx1Average << "; " << forcing << "; " << e << "; " << esum << "; " << y <<"\n"; - ostr.close(); - - } + ////////////////////////////////////////////////////////////////////////////////////////////////// + // temporary solution + if (root) { + std::string fNameCfg = path + "/forcing/forcing.cfg"; + std::ofstream ostr2; + ostr2.open(fNameCfg.c_str(), std::ios_base::out); + if (!ostr2) { + ostr2.clear(); + std::string path = UbSystem::getPathFromString(fNameCfg); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr2.open(fNameCfg.c_str(), std::ios_base::out); + } + if (!ostr2) + throw UbException(UB_EXARGS, "couldn't open file " + fNameCfg); + } + ostr2 << forcing << " " << esum << " " << eold; + ostr2.close(); + } + //////////////////////////////////////////////////////////////////////////////////////////////////////// + + integrateValues->calculateMQ(); + + if (root) { + cellsVolume = integrateValues->getCellsVolume(); + double vx1 = integrateValues->getVx1(); + vx1Average = (vx1 / cellsVolume); + + ////////////////////////////////////////////////////////////////////////// + // PID-Controller (PID-Regler) + e = vx1Targed - vx1Average; + esum = esum + e; + y = Kp * e + Ki * Ta * esum + Kd * (e - eold) / Ta; + eold = e; + + forcing = forcing + y; + ////////////////////////////////////////////////////////////////////////// + } + ////////////////////////////////////////////////////////////////////////// + comm->broadcast(forcing); + + mu::Parser fctForcingX1, fctForcingX2, fctForcingX3; + fctForcingX1.SetExpr("Fx1"); + fctForcingX1.DefineConst("Fx1", forcing); + fctForcingX2.SetExpr("0.0"); + fctForcingX3.SetExpr("0.0"); + SetForcingBlockVisitor forcingVisitor(fctForcingX1, fctForcingX2, fctForcingX3); + grid->accept(forcingVisitor); + + // for(CalcNodes cn : cnodes) + //{ + // LBMKernel3DPtr kernel = cn.block->getKernel(); + // if (kernel) + // { + // kernel->setForcingX1(fctForcingX1); + // kernel->setWithForcing(true); + // } + // + //} + + if (root) { + // UBLOG(logINFO, "D3Q27AdjustForcingCoProcessor step: " << static_cast<int>(step)); + // UBLOG(logINFO, "new forcing is: " << forcing); + std::string fname = path + "/forcing/forcing.csv"; + // std::string fname = path + "/forcing/forcing_"+UbSystem::toString(comm->getProcessID())+".csv"; + std::ofstream ostr; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + int istep = static_cast<int>(step); + + // ostr << istep << ";" << cellsVolume << ";" << vx1Average << "; " << forcing << "\n"; + ostr << istep << ";" << cellsVolume << ";" << vx1Average << "; " << forcing << "; " << e << "; " << esum << "; " + << y << "\n"; + ostr.close(); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.h index 87962f89e..93b99dada 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/AdjustForcingCoProcessor.h @@ -6,52 +6,52 @@ #include "CoProcessor.h" - class Communicator; class UbScheduler; class Grid3D; class IntegrateValuesHelper; -//! \brief Computes forcing such that a given velocity (vx1Targed) is reached inside an averaging domain (h1). -//! \details Algorithm based on PID controller (proportional_integral_derivative controller). The parameters of PID controller estimation based on Ziegler�Nichols method. +//! \brief Computes forcing such that a given velocity (vx1Targed) is reached inside an averaging domain (h1). +//! \details Algorithm based on PID controller (proportional_integral_derivative controller). The parameters of PID +//! controller estimation based on Ziegler�Nichols method. //! Integrate values helper, scheduler must be set in test case. //! \author: Konstantin Kutscher -class AdjustForcingCoProcessor: public CoProcessor { +class AdjustForcingCoProcessor : public CoProcessor +{ public: - AdjustForcingCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, - SPtr<IntegrateValuesHelper> integrateValues, - double vTarged, SPtr<Communicator> comm); - //!< calls collect PostprocessData - void process(double step) override; + AdjustForcingCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<IntegrateValuesHelper> integrateValues, double vTarged, SPtr<Communicator> comm); + //!< calls collect PostprocessData + void process(double step) override; + protected: - //!< object that can compute spacial average values in 3D-subdomain. + //!< object that can compute spacial average values in 3D-subdomain. SPtr<IntegrateValuesHelper> integrateValues; - //!< compares velocity in integrateValues with target velocity and adjusts forcing accordingly. - void collectData(double step); + //!< compares velocity in integrateValues with target velocity and adjusts forcing accordingly. + void collectData(double step); SPtr<Communicator> comm; + private: - double vx1Targed; //!< target velocity. - double forcing; //!< forcing at previous update step. - double cellsVolume; - double vx1Average; - bool root; - double Kpcrit; //Kp critical - double Tcrit; //the oscillation period - double Tn; - double Tv; - double e; - double Ta; - double Kp; - double Ki; - double Kd; - double y; - double esum; - double eold; - //std::vector<CalcNodes> cnodes; - std::string path; + double vx1Targed; //!< target velocity. + double forcing; //!< forcing at previous update step. + double cellsVolume; + double vx1Average; + bool root; + double Kpcrit; // Kp critical + double Tcrit; // the oscillation period + double Tn; + double Tv; + double e; + double Ta; + double Kp; + double Ki; + double Kd; + double y; + double esum; + double eold; + // std::vector<CalcNodes> cnodes; + std::string path; }; - #endif /* D3Q27RHODIFFERENCECoProcessor_H_ */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.cpp index 3cc990b96..3684a5791 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.cpp @@ -1,486 +1,460 @@ #include "AverageValuesCoProcessor.h" -#include "LBMKernel.h" #include "BCProcessor.h" +#include "LBMKernel.h" #include "basics/writer/WbWriterVtkXmlASCII.h" +#include "BCArray3D.h" +#include "Block3D.h" +#include "Communicator.h" #include "DataSet3D.h" -#include "WbWriter.h" #include "Grid3D.h" -#include "Block3D.h" #include "UbScheduler.h" -#include "Communicator.h" -#include "BCArray3D.h" +#include "WbWriter.h" using namespace std; -AverageValuesCoProcessor::AverageValuesCoProcessor() -= default; +AverageValuesCoProcessor::AverageValuesCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// -AverageValuesCoProcessor::AverageValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<UbScheduler> Avs, SPtr<UbScheduler> rsMeans, SPtr<UbScheduler> rsRMS, bool restart) - : CoProcessor(grid, s), - averageScheduler(Avs), - resetSchedulerMeans(rsMeans), - resetSchedulerRMS(rsRMS), - path(path), - writer(writer) +AverageValuesCoProcessor::AverageValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<UbScheduler> Avs, + SPtr<UbScheduler> rsMeans, SPtr<UbScheduler> rsRMS, bool restart) + : CoProcessor(grid, s), averageScheduler(Avs), resetSchedulerMeans(rsMeans), resetSchedulerRMS(rsRMS), path(path), + writer(writer) { - resetStepMeans = (int)rsMeans->getMinBegin(); - resetStepRMS = (int)rsRMS->getMinBegin(); - averageInterval = (double)Avs->getMinStep(); - - gridRank = grid->getRank(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); - - blockVector.resize(maxInitLevel+1); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - - if (blockVector[level].size() > 0) - compressible = blockVector[level][0]->getKernel()->getCompressible(); - - if (!restart) - { - for(SPtr<Block3D> block : blockVector[level]) - { - UbTupleInt3 nx = grid->getBlockNX(); - SPtr<AverageValuesArray3D> averageValues = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(11, val<1>(nx)+1, val<2>(nx)+1, val<3>(nx)+1, 0.0)); - block->getKernel()->getDataSet()->setAverageValues(averageValues); - } - } - } - - // for musis special use - //initPlotDataZ(0.0); - //restartStep = 0.0; + resetStepMeans = (int)rsMeans->getMinBegin(); + resetStepRMS = (int)rsRMS->getMinBegin(); + averageInterval = (double)Avs->getMinStep(); + + gridRank = grid->getRank(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); + + blockVector.resize(maxInitLevel + 1); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + + if (blockVector[level].size() > 0) + compressible = blockVector[level][0]->getKernel()->getCompressible(); + + if (!restart) { + for (SPtr<Block3D> block : blockVector[level]) { + UbTupleInt3 nx = grid->getBlockNX(); + SPtr<AverageValuesArray3D> averageValues = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(11, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setAverageValues(averageValues); + } + } + } + + // for musis special use + // initPlotDataZ(0.0); + // restartStep = 0.0; } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::process(double step) { - //resetRMS(step); - if(resetSchedulerRMS->isDue(step) ) - resetDataRMS(step); - - //reset(step); - if(resetSchedulerMeans->isDue(step) ) - resetDataMeans(step); - - if(averageScheduler->isDue(step) ){ - calculateAverageValues(step); - // for musis special use - //collectPlotDataZ(step); - } - if(scheduler->isDue(step) ){ - collectData(step); - - } - - UBLOG(logDEBUG3, "AverageValuesCoProcessor::update:" << step); + // resetRMS(step); + if (resetSchedulerRMS->isDue(step)) + resetDataRMS(step); + + // reset(step); + if (resetSchedulerMeans->isDue(step)) + resetDataMeans(step); + + if (averageScheduler->isDue(step)) { + calculateAverageValues(step); + // for musis special use + // collectPlotDataZ(step); + } + if (scheduler->isDue(step)) { + collectData(step); + } + + UBLOG(logDEBUG3, "AverageValuesCoProcessor::update:" << step); } void AverageValuesCoProcessor::resetDataRMS(double step) { - resetStepRMS=(int)step; - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - (*av)(AvVxx,ix1,ix2,ix3) = 0.0; - (*av)(AvVyy,ix1,ix2,ix3) = 0.0; - (*av)(AvVzz,ix1,ix2,ix3) = 0.0; - (*av)(AvVxy,ix1,ix2,ix3) = 0.0; - (*av)(AvVxz,ix1,ix2,ix3) = 0.0; - (*av)(AvVyz,ix1,ix2,ix3) = 0.0; - (*av)(AvPrms,ix1,ix2,ix3) = 0.0; - ////////////////////////////////////////////////////////////////////////// - } - } - } - } - } - } - } + resetStepRMS = (int)step; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + (*av)(AvVxx, ix1, ix2, ix3) = 0.0; + (*av)(AvVyy, ix1, ix2, ix3) = 0.0; + (*av)(AvVzz, ix1, ix2, ix3) = 0.0; + (*av)(AvVxy, ix1, ix2, ix3) = 0.0; + (*av)(AvVxz, ix1, ix2, ix3) = 0.0; + (*av)(AvVyz, ix1, ix2, ix3) = 0.0; + (*av)(AvPrms, ix1, ix2, ix3) = 0.0; + ////////////////////////////////////////////////////////////////////////// + } + } + } + } + } + } + } } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::resetDataMeans(double step) { - resetStepMeans=(int)step; - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - (*av)(AvVx,ix1,ix2,ix3) = 0.0; - (*av)(AvVy,ix1,ix2,ix3) = 0.0; - (*av)(AvVz,ix1,ix2,ix3) = 0.0; - (*av)(AvP,ix1,ix2,ix3) = 0.0; - ////////////////////////////////////////////////////////////////////////// - } - } - } - } - } - } - } + resetStepMeans = (int)step; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + (*av)(AvVx, ix1, ix2, ix3) = 0.0; + (*av)(AvVy, ix1, ix2, ix3) = 0.0; + (*av)(AvVz, ix1, ix2, ix3) = 0.0; + (*av)(AvP, ix1, ix2, ix3) = 0.0; + ////////////////////////////////////////////////////////////////////////// + } + } + } + } + } + } + } } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::collectData(double step) { - int istep = int(step); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); - } - } - } - - string pfilePath, partPath, subfolder, cfilePath; - subfolder = "av"+UbSystem::toString(istep); - pfilePath = path+"/av/"+subfolder; - cfilePath = path+"/av/av_collection"; - partPath = pfilePath+"/av"+UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep); - - string partName = writer->writeOctsWithNodeData(partPath,nodes,cells,datanames,data); - size_t found=partName.find_last_of("/"); - string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; - - vector<string> cellDataNames; - SPtr<Communicator> comm = Communicator::getInstance(); - vector<string> pieces = comm->gather(piece); - if (comm->getProcessID() == comm->getRoot()) - { - string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath,pieces,datanames,cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); - - vector<string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath,filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath,filenames,istep,false); - } - UBLOG(logINFO,"AverageValuesCoProcessor step: " << istep); - } - - clearData(); + int istep = int(step); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } + } + } + + string pfilePath, partPath, subfolder, cfilePath; + subfolder = "av" + UbSystem::toString(istep); + pfilePath = path + "/av/" + subfolder; + cfilePath = path + "/av/av_collection"; + partPath = pfilePath + "/av" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); + + string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); + size_t found = partName.find_last_of("/"); + string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + vector<string> cellDataNames; + SPtr<Communicator> comm = Communicator::getInstance(); + vector<string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); + + vector<string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "AverageValuesCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::addData(const SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("AvVx"); - datanames.emplace_back("AvVy"); - datanames.emplace_back("AvVz"); - datanames.emplace_back("AvVxx"); - datanames.emplace_back("AvVyy"); - datanames.emplace_back("AvVzz"); - datanames.emplace_back("AvVxy"); - datanames.emplace_back("AvVxz"); - datanames.emplace_back("AvVyz"); - datanames.emplace_back("AvP"); - datanames.emplace_back("AvPrms"); - - - data.resize(datanames.size()); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - //int ghostLayerWidth = kernel->getGhostLayerWidth(); - - //knotennummerierung faengt immer bei 0 an! - unsigned int SWB,SEB,NEB,NWB,SWT,SET,NET,NWT; - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - //D3Q27BoundaryConditionPtr bcPtr; - - int nr = (int)nodes.size(); - - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - int index = 0; - nodeNumbers(ix1,ix2,ix3) = nr++; - nodes.push_back( makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1*dx), - float(val<2>(org) - val<2>(nodeOffset) + ix2*dx), - float(val<3>(org) - val<3>(nodeOffset) + ix3*dx)) ); - - LBMReal vx=(*av)(AvVx,ix1,ix2,ix3); - LBMReal vy=(*av)(AvVy,ix1,ix2,ix3); - LBMReal vz=(*av)(AvVz,ix1,ix2,ix3); - - LBMReal vxx=(*av)(AvVxx,ix1,ix2,ix3); - LBMReal vyy=(*av)(AvVyy,ix1,ix2,ix3); - LBMReal vzz=(*av)(AvVzz,ix1,ix2,ix3); - - LBMReal vxy=(*av)(AvVxy,ix1,ix2,ix3); - LBMReal vxz=(*av)(AvVxz,ix1,ix2,ix3); - LBMReal vyz=(*av)(AvVyz,ix1,ix2,ix3); - - LBMReal vp=(*av)(AvP,ix1,ix2,ix3); - LBMReal vprms=(*av)(AvPrms,ix1,ix2,ix3); - - - data[index++].push_back(vx); - data[index++].push_back(vy); - data[index++].push_back(vz); - - data[index++].push_back(vxx); - data[index++].push_back(vyy); - data[index++].push_back(vzz); - - data[index++].push_back(vxy); - data[index++].push_back(vxz); - data[index++].push_back(vyz); - - data[index++].push_back(vp); - data[index++].push_back(vprms); - } - } - } - } - - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - //cell vector erstellen - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if( (SWB=nodeNumbers( ix1 , ix2, ix3 )) >= 0 - && (SEB=nodeNumbers( ix1+1, ix2, ix3 )) >= 0 - && (NEB=nodeNumbers( ix1+1, ix2+1, ix3 )) >= 0 - && (NWB=nodeNumbers( ix1 , ix2+1, ix3 )) >= 0 - && (SWT=nodeNumbers( ix1 , ix2, ix3+1 )) >= 0 - && (SET=nodeNumbers( ix1+1, ix2, ix3+1 )) >= 0 - && (NET=nodeNumbers( ix1+1, ix2+1, ix3+1 )) >= 0 - && (NWT=nodeNumbers( ix1 , ix2+1, ix3+1 )) >= 0 ) - { - cells.push_back( makeUbTuple(SWB,SEB,NEB,NWB,SWT,SET,NET,NWT) ); - } - } - } - } + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("AvVx"); + datanames.emplace_back("AvVy"); + datanames.emplace_back("AvVz"); + datanames.emplace_back("AvVxx"); + datanames.emplace_back("AvVyy"); + datanames.emplace_back("AvVzz"); + datanames.emplace_back("AvVxy"); + datanames.emplace_back("AvVxz"); + datanames.emplace_back("AvVyz"); + datanames.emplace_back("AvP"); + datanames.emplace_back("AvPrms"); + + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + // int ghostLayerWidth = kernel->getGhostLayerWidth(); + + // knotennummerierung faengt immer bei 0 an! + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + // D3Q27BoundaryConditionPtr bcPtr; + + int nr = (int)nodes.size(); + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + LBMReal vx = (*av)(AvVx, ix1, ix2, ix3); + LBMReal vy = (*av)(AvVy, ix1, ix2, ix3); + LBMReal vz = (*av)(AvVz, ix1, ix2, ix3); + + LBMReal vxx = (*av)(AvVxx, ix1, ix2, ix3); + LBMReal vyy = (*av)(AvVyy, ix1, ix2, ix3); + LBMReal vzz = (*av)(AvVzz, ix1, ix2, ix3); + + LBMReal vxy = (*av)(AvVxy, ix1, ix2, ix3); + LBMReal vxz = (*av)(AvVxz, ix1, ix2, ix3); + LBMReal vyz = (*av)(AvVyz, ix1, ix2, ix3); + + LBMReal vp = (*av)(AvP, ix1, ix2, ix3); + LBMReal vprms = (*av)(AvPrms, ix1, ix2, ix3); + + data[index++].push_back(vx); + data[index++].push_back(vy); + data[index++].push_back(vz); + + data[index++].push_back(vxx); + data[index++].push_back(vyy); + data[index++].push_back(vzz); + + data[index++].push_back(vxy); + data[index++].push_back(vxz); + data[index++].push_back(vyz); + + data[index++].push_back(vp); + data[index++].push_back(vprms); + } + } + } + } + + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } + } + } + } } ////////////////////////////////////////////////////////////////////////// void AverageValuesCoProcessor::calculateAverageValues(double timeStep) { - using namespace D3Q27System; - - //Funktionszeiger - calcMacros = NULL; - if (compressible) - { - calcMacros = &calcCompMacroscopicValues; - } - else - { - calcMacros = &calcIncompMacroscopicValues; - } - - LBMReal f[27]; - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //read distribution - //////////////////////////////////////////////////////////////////////////// - distributions->getDistribution(f, ix1, ix2, ix3); - ////////////////////////////////////////////////////////////////////////// - //compute velocity - ////////////////////////////////////////////////////////////////////////// - LBMReal vx,vy,vz,rho; - calcMacros(f,rho,vx,vy,vz); - double press = D3Q27System::calcPress(f,rho,vx,vy,vz); - - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - - LBMReal timeStepAfterResetRMS=(double)(timeStep-resetStepRMS)/((double)averageInterval); - LBMReal timeStepAfterResetMeans=(double)(timeStep-resetStepMeans)/((double)averageInterval); - - //mean velocity - (*av)(AvVx,ix1,ix2,ix3) = ((*av)(AvVx,ix1,ix2,ix3)*timeStepAfterResetMeans + vx)/(timeStepAfterResetMeans+1.0); - (*av)(AvVy,ix1,ix2,ix3) = ((*av)(AvVy,ix1,ix2,ix3)*timeStepAfterResetMeans + vy)/(timeStepAfterResetMeans+1.0); - (*av)(AvVz,ix1,ix2,ix3) = ((*av)(AvVz,ix1,ix2,ix3)*timeStepAfterResetMeans + vz)/(timeStepAfterResetMeans+1.0); - - //rms - (*av)(AvVxx,ix1,ix2,ix3) = ((vx-(*av)(AvVx,ix1,ix2,ix3))*(vx-(*av)(AvVx,ix1,ix2,ix3)) + - (*av)(AvVxx,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - (*av)(AvVyy,ix1,ix2,ix3) = ((vy-(*av)(AvVy,ix1,ix2,ix3))*(vy-(*av)(AvVy,ix1,ix2,ix3)) + - (*av)(AvVyy,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - (*av)(AvVzz,ix1,ix2,ix3) = ((vz-(*av)(AvVz,ix1,ix2,ix3))*(vz-(*av)(AvVz,ix1,ix2,ix3)) + - (*av)(AvVzz,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - - //cross-correlations - (*av)(AvVxy,ix1,ix2,ix3) = ((vx-(*av)(AvVx,ix1,ix2,ix3))*(vy-(*av)(AvVy,ix1,ix2,ix3)) + - (*av)(AvVxy,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - (*av)(AvVxz,ix1,ix2,ix3) = ((vx-(*av)(AvVx,ix1,ix2,ix3))*(vz-(*av)(AvVz,ix1,ix2,ix3)) + - (*av)(AvVxz,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - (*av)(AvVyz,ix1,ix2,ix3) = ((vy-(*av)(AvVy,ix1,ix2,ix3))*(vz-(*av)(AvVz,ix1,ix2,ix3)) + - (*av)(AvVyz,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - - //mean and rms press - (*av)(AvP,ix1,ix2,ix3) = ((*av)(AvP,ix1,ix2,ix3)*timeStepAfterResetMeans + press)/(timeStepAfterResetMeans+1.0); - (*av)(AvPrms,ix1,ix2,ix3) = ((press-(*av)(AvP,ix1,ix2,ix3))*(press-(*av)(AvP,ix1,ix2,ix3)) + - (*av)(AvPrms,ix1,ix2,ix3)*timeStepAfterResetRMS)/(timeStepAfterResetRMS+1.0); - - ////////////////////////////////////////////////////////////////////////// - } - } - } - } - } - } - } + using namespace D3Q27System; + + // Funktionszeiger + calcMacros = NULL; + if (compressible) { + calcMacros = &calcCompMacroscopicValues; + } else { + calcMacros = &calcIncompMacroscopicValues; + } + + LBMReal f[27]; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // read distribution + //////////////////////////////////////////////////////////////////////////// + distributions->getDistribution(f, ix1, ix2, ix3); + ////////////////////////////////////////////////////////////////////////// + // compute velocity + ////////////////////////////////////////////////////////////////////////// + LBMReal vx, vy, vz, rho; + calcMacros(f, rho, vx, vy, vz); + double press = D3Q27System::calcPress(f, rho, vx, vy, vz); + + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + + LBMReal timeStepAfterResetRMS = + (double)(timeStep - resetStepRMS) / ((double)averageInterval); + LBMReal timeStepAfterResetMeans = + (double)(timeStep - resetStepMeans) / ((double)averageInterval); + + // mean velocity + (*av)(AvVx, ix1, ix2, ix3) = + ((*av)(AvVx, ix1, ix2, ix3) * timeStepAfterResetMeans + vx) / + (timeStepAfterResetMeans + 1.0); + (*av)(AvVy, ix1, ix2, ix3) = + ((*av)(AvVy, ix1, ix2, ix3) * timeStepAfterResetMeans + vy) / + (timeStepAfterResetMeans + 1.0); + (*av)(AvVz, ix1, ix2, ix3) = + ((*av)(AvVz, ix1, ix2, ix3) * timeStepAfterResetMeans + vz) / + (timeStepAfterResetMeans + 1.0); + + // rms + (*av)(AvVxx, ix1, ix2, ix3) = + ((vx - (*av)(AvVx, ix1, ix2, ix3)) * (vx - (*av)(AvVx, ix1, ix2, ix3)) + + (*av)(AvVxx, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + (*av)(AvVyy, ix1, ix2, ix3) = + ((vy - (*av)(AvVy, ix1, ix2, ix3)) * (vy - (*av)(AvVy, ix1, ix2, ix3)) + + (*av)(AvVyy, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + (*av)(AvVzz, ix1, ix2, ix3) = + ((vz - (*av)(AvVz, ix1, ix2, ix3)) * (vz - (*av)(AvVz, ix1, ix2, ix3)) + + (*av)(AvVzz, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + + // cross-correlations + (*av)(AvVxy, ix1, ix2, ix3) = + ((vx - (*av)(AvVx, ix1, ix2, ix3)) * (vy - (*av)(AvVy, ix1, ix2, ix3)) + + (*av)(AvVxy, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + (*av)(AvVxz, ix1, ix2, ix3) = + ((vx - (*av)(AvVx, ix1, ix2, ix3)) * (vz - (*av)(AvVz, ix1, ix2, ix3)) + + (*av)(AvVxz, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + (*av)(AvVyz, ix1, ix2, ix3) = + ((vy - (*av)(AvVy, ix1, ix2, ix3)) * (vz - (*av)(AvVz, ix1, ix2, ix3)) + + (*av)(AvVyz, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + + // mean and rms press + (*av)(AvP, ix1, ix2, ix3) = + ((*av)(AvP, ix1, ix2, ix3) * timeStepAfterResetMeans + press) / + (timeStepAfterResetMeans + 1.0); + (*av)(AvPrms, ix1, ix2, ix3) = + ((press - (*av)(AvP, ix1, ix2, ix3)) * (press - (*av)(AvP, ix1, ix2, ix3)) + + (*av)(AvPrms, ix1, ix2, ix3) * timeStepAfterResetRMS) / + (timeStepAfterResetRMS + 1.0); + + ////////////////////////////////////////////////////////////////////////// + } + } + } + } + } + } + } } //////////////////////////////////////////////////////////////////////////// -//void AverageValuesCoProcessor::initPlotData(double step) +// void AverageValuesCoProcessor::initPlotData(double step) //{ // SPtr<Communicator> comm = Communicator::getInstance(); // if (comm->getProcessID() == comm->getRoot()) // { // std::ofstream ostr; -// string fname = path + "_PlotData_" + UbSystem::toString(step) + ".txt"; +// string fname = path + "_PlotData_" + UbSystem::toString(step) + ".txt"; // ostr.open(fname.c_str(), std::ios_base::out); // if(!ostr) -// { +// { // ostr.clear(); // string path = UbSystem::getPathFromString(fname); // if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out);} @@ -494,7 +468,7 @@ void AverageValuesCoProcessor::calculateAverageValues(double timeStep) // } //} ////////////////////////////////////////////////////////////////////////////// -//void AverageValuesCoProcessor::collectPlotData(double step) +// void AverageValuesCoProcessor::collectPlotData(double step) //{ // // double hminX1 = 0.9; @@ -516,7 +490,7 @@ void AverageValuesCoProcessor::calculateAverageValues(double timeStep) // ostringstream Str; // Str << step; // string step2string(Str.str()); -// string fname = path + "_PlotZ_" + step2string + ".txt"; +// string fname = path + "_PlotZ_" + step2string + ".txt"; // // // for(int level = minInitLevel; level<=maxInitLevel;level++) @@ -524,8 +498,8 @@ void AverageValuesCoProcessor::calculateAverageValues(double timeStep) // double dx = grid->getDeltaX(level); // // for (double hi =hX3_level[level]; hi >= hX3_level[level+1]; hi=hi-dx ){ -// D3Q27IntegrateValuesHelper h1(grid, comm, -// hminX1, hminX2, hi, +// D3Q27IntegrateValuesHelper h1(grid, comm, +// hminX1, hminX2, hi, // hmaxX1, hmaxX2, hi-dx); // // h1.calculateAV(); @@ -550,11 +524,11 @@ void AverageValuesCoProcessor::calculateAverageValues(double timeStep) // // ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); // if(!ostr) -// { +// { // ostr.clear(); // string path = UbSystem::getPathFromString(fname); -// if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app);} -// if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); +// if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | +//std::ios_base::app);} if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); // } // ostr << istep << "\t" << resetStep << "\t" << hi+0.5*dx << "\t" << nn1/(nn1+ns1)*100.0 << "%\t"; // ostr << AvVx1 << "\t" << AvVx2 << "\t" << AvVx3 << "\t"; @@ -568,4 +542,3 @@ void AverageValuesCoProcessor::calculateAverageValues(double timeStep) // // } //} - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.h index 8fadba91a..5ba922824 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/AverageValuesCoProcessor.h @@ -2,8 +2,8 @@ #define AverageValuesCoProcessor_H #include <PointerDefinitions.h> -#include <vector> #include <string> +#include <vector> #include "CoProcessor.h" #include "LBMSystem.h" @@ -15,60 +15,75 @@ class Grid3D; class Block3D; //! \brief Computes the time averaged mean velocity and RMS values and writes to parallel .vtk -//! \details writes at given time intervals specified in scheduler (s), does averaging according to scheduler (Avs) and resets according to scheduler (rs). <br> -//! Computes the time averaged mean velocity \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ and RMS of fluctuations. You need to calculate a square root before plotting RMS. <br> -// -//! \author Sonja Uphoff, Kostyantyn Kucher +//! \details writes at given time intervals specified in scheduler (s), does averaging according to scheduler (Avs) and +//! resets according to scheduler (rs). <br> +//! Computes the time averaged mean velocity \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ and RMS of +//! fluctuations. You need to calculate a square root before plotting RMS. <br> +// +//! \author Sonja Uphoff, Kostyantyn Kucher // \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ class AverageValuesCoProcessor : public CoProcessor { public: - AverageValuesCoProcessor(); - AverageValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<UbScheduler> Avs, SPtr<UbScheduler> rsMeans, SPtr<UbScheduler> rsRMS, bool restart); - //! Make update - void process(double step) override; - //! Resets averaged velocity and RMS-values according to ResetSceduler - void reset(double step); + AverageValuesCoProcessor(); + AverageValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<UbScheduler> Avs, SPtr<UbScheduler> rsMeans, SPtr<UbScheduler> rsRMS, bool restart); + //! Make update + void process(double step) override; + //! Resets averaged velocity and RMS-values according to ResetSceduler + void reset(double step); + protected: - //! Prepare data and write in .vtk file - void collectData(double step); - //! Reset data - void resetDataRMS(double step); - void resetDataMeans(double step); - //! prepare data - void addData(const SPtr<Block3D> block); - void clearData(); - //! Computes average and RMS values of macroscopic quantities - void calculateAverageValues(double timeStep); - ////! write .txt file spatial intergrated averaged value, fluctuation, porous features - //void collectPlotDataZ(double step); - ////! create txt file and write head line - //void initPlotDataZ(double step); + //! Prepare data and write in .vtk file + void collectData(double step); + //! Reset data + void resetDataRMS(double step); + void resetDataMeans(double step); + //! prepare data + void addData(const SPtr<Block3D> block); + void clearData(); + //! Computes average and RMS values of macroscopic quantities + void calculateAverageValues(double timeStep); + ////! write .txt file spatial intergrated averaged value, fluctuation, porous features + // void collectPlotDataZ(double step); + ////! create txt file and write head line + // void initPlotDataZ(double step); private: - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::vector<std::vector<SPtr<Block3D>> > blockVector; - int minInitLevel; //min init level - int maxInitLevel; - int gridRank; - int resetStepRMS; - int resetStepMeans; - double averageInterval; - std::string path; - WbWriter* writer; - bool restart, compressible; - SPtr<UbScheduler> averageScheduler; //additional scheduler to averaging after a given interval - SPtr<UbScheduler> resetSchedulerRMS; //additional scheduler to restart averaging after a given interval - SPtr<UbScheduler> resetSchedulerMeans; //additional scheduler to restart averaging after a given interval - //labels for the different components, e.g. AvVxx for time averaged RMS: 1/n SUM((U-Umean)^2) - //you need to calculate a square root before plotting RMS - enum Values{AvVx = 0, AvVy = 1, AvVz = 2, AvVxx = 3, AvVyy = 4, AvVzz = 5, AvVxy = 6, AvVxz = 7, AvVyz = 8, AvP = 9, AvPrms = 10}; + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; // min init level + int maxInitLevel; + int gridRank; + int resetStepRMS; + int resetStepMeans; + double averageInterval; + std::string path; + WbWriter *writer; + bool restart, compressible; + SPtr<UbScheduler> averageScheduler; // additional scheduler to averaging after a given interval + SPtr<UbScheduler> resetSchedulerRMS; // additional scheduler to restart averaging after a given interval + SPtr<UbScheduler> resetSchedulerMeans; // additional scheduler to restart averaging after a given interval + // labels for the different components, e.g. AvVxx for time averaged RMS: 1/n SUM((U-Umean)^2) + // you need to calculate a square root before plotting RMS + enum Values { + AvVx = 0, + AvVy = 1, + AvVz = 2, + AvVxx = 3, + AvVyy = 4, + AvVzz = 5, + AvVxy = 6, + AvVxz = 7, + AvVyz = 8, + AvP = 9, + AvPrms = 10 + }; - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.cpp index d66562b2d..fe347d786 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.cpp @@ -1,241 +1,239 @@ #include "CalculateForcesCoProcessor.h" #include "BCProcessor.h" +#include "BCArray3D.h" +#include "Block3D.h" +#include "BoundaryConditions.h" #include "Communicator.h" #include "D3Q27Interactor.h" -#include "UbScheduler.h" -#include "Grid3D.h" -#include "BoundaryConditions.h" #include "DataSet3D.h" -#include "Block3D.h" -#include "LBMKernel.h" -#include "BCArray3D.h" -#include "EsoTwist3D.h" #include "DistributionArray3D.h" +#include "EsoTwist3D.h" +#include "Grid3D.h" +#include "LBMKernel.h" +#include "UbScheduler.h" -CalculateForcesCoProcessor::CalculateForcesCoProcessor( SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string &path, - SPtr<Communicator> comm , - double v, double a) : - CoProcessor(grid, s), - path(path), comm(comm), - v(v), a(a), - forceX1global(0), forceX2global(0), forceX3global(0) +CalculateForcesCoProcessor::CalculateForcesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm, double v, double a) + : CoProcessor(grid, s), path(path), comm(comm), v(v), a(a), forceX1global(0), forceX2global(0), forceX3global(0) { - if (comm->getProcessID() == comm->getRoot()) - { - std::ofstream ostr; - std::string fname = path; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if(!ostr) - { - ostr.clear(); - std::string file_path = UbSystem::getPathFromString(fname); - if(file_path.size()>0){ UbSystem::makeDirectory(file_path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app);} - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } - ostr.width(12); - ostr << "step" << "\t"; - ostr.width(12); - ostr << "Cx" << "\t"; - ostr.width(12); - ostr << "Cy" << "\t"; - ostr.width(12); - ostr << "Cz" << "\t"; - ostr.width(12); - ostr << "Fx" << "\t"; - ostr.width(12); - ostr << "Fy" << "\t"; - ostr.width(12); - ostr << "Fz" << std::endl; - ostr.close(); - } + if (comm->getProcessID() == comm->getRoot()) { + std::ofstream ostr; + std::string fname = path; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string file_path = UbSystem::getPathFromString(fname); + if (file_path.size() > 0) { + UbSystem::makeDirectory(file_path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr.width(12); + ostr << "step" + << "\t"; + ostr.width(12); + ostr << "Cx" + << "\t"; + ostr.width(12); + ostr << "Cy" + << "\t"; + ostr.width(12); + ostr << "Cz" + << "\t"; + ostr.width(12); + ostr << "Fx" + << "\t"; + ostr.width(12); + ostr << "Fy" + << "\t"; + ostr.width(12); + ostr << "Fz" << std::endl; + ostr.close(); + } } ////////////////////////////////////////////////////////////////////////// -CalculateForcesCoProcessor::~CalculateForcesCoProcessor() -= default; +CalculateForcesCoProcessor::~CalculateForcesCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// -void CalculateForcesCoProcessor::process( double step ) +void CalculateForcesCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "D3Q27ForcesCoProcessor::update:" << step); + UBLOG(logDEBUG3, "D3Q27ForcesCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// -void CalculateForcesCoProcessor::collectData( double step ) +void CalculateForcesCoProcessor::collectData(double step) { - calculateForces(); - - if (comm->getProcessID() == comm->getRoot()) - { - int istep = static_cast<int>(step); - std::ofstream ostr; - std::string fname = path; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if(!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app);} - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } - - calculateCoefficients(); - - ostr.width(12); - ostr.setf(std::ios::fixed); - ostr << istep << "\t"; - write(&ostr, C1, (char*)"\t"); - write(&ostr, C2, (char*)"\t"); - write(&ostr, C3, (char*)"\t"); - write(&ostr, forceX1global, (char*)"\t"); - write(&ostr, forceX2global, (char*)"\t"); - write(&ostr, forceX3global, (char*)"\t"); - ostr << std::endl; - ostr.close(); - } + calculateForces(); + + if (comm->getProcessID() == comm->getRoot()) { + int istep = static_cast<int>(step); + std::ofstream ostr; + std::string fname = path; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + + calculateCoefficients(); + + ostr.width(12); + ostr.setf(std::ios::fixed); + ostr << istep << "\t"; + write(&ostr, C1, (char *)"\t"); + write(&ostr, C2, (char *)"\t"); + write(&ostr, C3, (char *)"\t"); + write(&ostr, forceX1global, (char *)"\t"); + write(&ostr, forceX2global, (char *)"\t"); + write(&ostr, forceX3global, (char *)"\t"); + ostr << std::endl; + ostr.close(); + } } ////////////////////////////////////////////////////////////////////////// void CalculateForcesCoProcessor::calculateForces() { - forceX1global = 0.0; - forceX2global = 0.0; - forceX3global = 0.0; - - for(SPtr<D3Q27Interactor> interactor : interactors) - { - for(BcNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) - { - double forceX1 = 0.0; - double forceX2 = 0.0; - double forceX3 = 0.0; - - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& transNodeIndicesSet = t.second; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - distributions->swap(); - - int ghostLayerWidth = kernel->getGhostLayerWidth(); - int minX1 = ghostLayerWidth; - int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayerWidth; - int minX2 = ghostLayerWidth; - int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayerWidth; - int minX3 = ghostLayerWidth; - int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayerWidth; - - for(std::vector<int> node : transNodeIndicesSet) - { - int x1 = node[0]; - int x2 = node[1]; - int x3 = node[2]; - - //without ghost nodes - if (x1 < minX1 || x1 > maxX1 || x2 < minX2 || x2 > maxX2 ||x3 < minX3 || x3 > maxX3 ) continue; - - if(bcArray->isFluid(x1,x2,x3)) //es kann sein, dass der node von einem anderen interactor z.B. als solid gemarkt wurde!!! - { - SPtr<BoundaryConditions> bc = bcArray->getBC(x1,x2,x3); - UbTupleDouble3 forceVec = getForces(x1,x2,x3,distributions,bc); - forceX1 += val<1>(forceVec); - forceX2 += val<2>(forceVec); - forceX3 += val<3>(forceVec); + forceX1global = 0.0; + forceX2global = 0.0; + forceX3global = 0.0; + + for (SPtr<D3Q27Interactor> interactor : interactors) { + for (BcNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) { + double forceX1 = 0.0; + double forceX2 = 0.0; + double forceX3 = 0.0; + + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &transNodeIndicesSet = t.second; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + distributions->swap(); + + int ghostLayerWidth = kernel->getGhostLayerWidth(); + int minX1 = ghostLayerWidth; + int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayerWidth; + int minX2 = ghostLayerWidth; + int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayerWidth; + int minX3 = ghostLayerWidth; + int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayerWidth; + + for (std::vector<int> node : transNodeIndicesSet) { + int x1 = node[0]; + int x2 = node[1]; + int x3 = node[2]; + + // without ghost nodes + if (x1 < minX1 || x1 > maxX1 || x2 < minX2 || x2 > maxX2 || x3 < minX3 || x3 > maxX3) + continue; + + if (bcArray->isFluid( + x1, x2, + x3)) // es kann sein, dass der node von einem anderen interactor z.B. als solid gemarkt wurde!!! + { + SPtr<BoundaryConditions> bc = bcArray->getBC(x1, x2, x3); + UbTupleDouble3 forceVec = getForces(x1, x2, x3, distributions, bc); + forceX1 += val<1>(forceVec); + forceX2 += val<2>(forceVec); + forceX3 += val<3>(forceVec); + } } - } - //if we have got discretization with more level - // deltaX is LBM deltaX and equal LBM deltaT - double deltaX = LBMSystem::getDeltaT(block->getLevel()); //grid->getDeltaT(block); - double deltaXquadrat = deltaX*deltaX; - forceX1 *= deltaXquadrat; - forceX2 *= deltaXquadrat; - forceX3 *= deltaXquadrat; - - distributions->swap(); - - forceX1global += forceX1; - forceX2global += forceX2; - forceX3global += forceX3; - } - } - std::vector<double> values; - std::vector<double> rvalues; - values.push_back(forceX1global); - values.push_back(forceX2global); - values.push_back(forceX3global); - - rvalues = comm->gather(values); - if (comm->getProcessID() == comm->getRoot()) - { - forceX1global = 0.0; - forceX2global = 0.0; - forceX3global = 0.0; - - for (int i = 0; i < (int)rvalues.size(); i+=3) - { - forceX1global += rvalues[i]; - forceX2global += rvalues[i+1]; - forceX3global += rvalues[i+2]; - } - } + // if we have got discretization with more level + // deltaX is LBM deltaX and equal LBM deltaT + double deltaX = LBMSystem::getDeltaT(block->getLevel()); // grid->getDeltaT(block); + double deltaXquadrat = deltaX * deltaX; + forceX1 *= deltaXquadrat; + forceX2 *= deltaXquadrat; + forceX3 *= deltaXquadrat; + + distributions->swap(); + + forceX1global += forceX1; + forceX2global += forceX2; + forceX3global += forceX3; + } + } + std::vector<double> values; + std::vector<double> rvalues; + values.push_back(forceX1global); + values.push_back(forceX2global); + values.push_back(forceX3global); + + rvalues = comm->gather(values); + if (comm->getProcessID() == comm->getRoot()) { + forceX1global = 0.0; + forceX2global = 0.0; + forceX3global = 0.0; + + for (int i = 0; i < (int)rvalues.size(); i += 3) { + forceX1global += rvalues[i]; + forceX2global += rvalues[i + 1]; + forceX3global += rvalues[i + 2]; + } + } } ////////////////////////////////////////////////////////////////////////// -UbTupleDouble3 CalculateForcesCoProcessor::getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, SPtr<BoundaryConditions> bc) +UbTupleDouble3 CalculateForcesCoProcessor::getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, + SPtr<BoundaryConditions> bc) { - UbTupleDouble3 force(0.0,0.0,0.0); - - if(bc) - { - //references to tuple "force" - double& forceX1 = val<1>(force); - double& forceX2 = val<2>(force); - double& forceX3 = val<3>(force); - double f, fnbr; - - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if(bc->hasNoSlipBoundaryFlag(fdir)) - { - const int invDir = D3Q27System::INVDIR[fdir]; - f = dynamicPointerCast<EsoTwist3D>(distributions)->getDistributionInvForDirection(x1, x2, x3, invDir); - fnbr = dynamicPointerCast<EsoTwist3D>(distributions)->getDistributionInvForDirection(x1+D3Q27System::DX1[invDir], x2+D3Q27System::DX2[invDir], x3+D3Q27System::DX3[invDir], fdir); - - forceX1 += (f + fnbr)*D3Q27System::DX1[invDir]; - forceX2 += (f + fnbr)*D3Q27System::DX2[invDir]; - forceX3 += (f + fnbr)*D3Q27System::DX3[invDir]; - } - } - } - - return force; + UbTupleDouble3 force(0.0, 0.0, 0.0); + + if (bc) { + // references to tuple "force" + double &forceX1 = val<1>(force); + double &forceX2 = val<2>(force); + double &forceX3 = val<3>(force); + double f, fnbr; + + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bc->hasNoSlipBoundaryFlag(fdir)) { + const int invDir = D3Q27System::INVDIR[fdir]; + f = dynamicPointerCast<EsoTwist3D>(distributions)->getDistributionInvForDirection(x1, x2, x3, invDir); + fnbr = + dynamicPointerCast<EsoTwist3D>(distributions) + ->getDistributionInvForDirection(x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], + x3 + D3Q27System::DX3[invDir], fdir); + + forceX1 += (f + fnbr) * D3Q27System::DX1[invDir]; + forceX2 += (f + fnbr) * D3Q27System::DX2[invDir]; + forceX3 += (f + fnbr) * D3Q27System::DX3[invDir]; + } + } + } + + return force; } ////////////////////////////////////////////////////////////////////////// void CalculateForcesCoProcessor::calculateCoefficients() { - double F1 = forceX1global; - double F2 = forceX2global; - double F3 = forceX3global; - - //return 2*F/(rho*v*v*a); - C1 = 2.0*F1/(v*v*a); - C2 = 2.0*F2/(v*v*a); - C3 = 2.0*F3/(v*v*a); + double F1 = forceX1global; + double F2 = forceX2global; + double F3 = forceX3global; + + // return 2*F/(rho*v*v*a); + C1 = 2.0 * F1 / (v * v * a); + C2 = 2.0 * F2 / (v * v * a); + C3 = 2.0 * F3 / (v * v * a); } ////////////////////////////////////////////////////////////////////////// -void CalculateForcesCoProcessor::addInteractor( SPtr<D3Q27Interactor> interactor ) +void CalculateForcesCoProcessor::addInteractor(SPtr<D3Q27Interactor> interactor) { interactors.push_back(interactor); } +////////////////////////////////////////////////////////////////////////// +void CalculateForcesCoProcessor::write(std::ofstream *fileObject, double value, char *separator) { - interactors.push_back(interactor); + (*fileObject).width(12); + //(*fileObject).precision(2); + (*fileObject).setf(std::ios::fixed); + (*fileObject) << value; + (*fileObject) << separator; } -////////////////////////////////////////////////////////////////////////// -void CalculateForcesCoProcessor::write(std::ofstream *fileObject, double value, char *separator) -{ - (*fileObject).width(12); - //(*fileObject).precision(2); - (*fileObject).setf(std::ios::fixed); - (*fileObject) << value; - (*fileObject) << separator; -} - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.h index 6c2288dc5..c3004cf16 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/CalculateForcesCoProcessor.h @@ -23,36 +23,38 @@ class D3Q27Interactor; class DistributionArray3D; class BoundaryConditions; -class CalculateForcesCoProcessor: public CoProcessor +class CalculateForcesCoProcessor : public CoProcessor { public: - //! Constructor - //! \param v - velocity of fluid in LB units - //! \param a - area of object in LB units - CalculateForcesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, - SPtr<Communicator> comm, double v, double a); - ~CalculateForcesCoProcessor() override; - void process(double step) override; - void addInteractor(SPtr<D3Q27Interactor> interactor); + //! Constructor + //! \param v - velocity of fluid in LB units + //! \param a - area of object in LB units + CalculateForcesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<Communicator> comm, + double v, double a); + ~CalculateForcesCoProcessor() override; + void process(double step) override; + void addInteractor(SPtr<D3Q27Interactor> interactor); + protected: - void collectData(double step); - void calculateForces(); - UbTupleDouble3 getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, SPtr<BoundaryConditions> bc); - void calculateCoefficients(); - void write(std::ofstream *fileObject, double value, char *separator); + void collectData(double step); + void calculateForces(); + UbTupleDouble3 getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, + SPtr<BoundaryConditions> bc); + void calculateCoefficients(); + void write(std::ofstream *fileObject, double value, char *separator); + private: - std::string path; - SPtr<Communicator> comm; - std::vector<SPtr<D3Q27Interactor> > interactors; - double forceX1global; - double forceX2global; - double forceX3global; - double v; //!< is the speed of the object relative to the fluid - double a; //!< is the reference area - double C1; - double C2; - double C3; + std::string path; + SPtr<Communicator> comm; + std::vector<SPtr<D3Q27Interactor>> interactors; + double forceX1global; + double forceX2global; + double forceX3global; + double v; //!< is the speed of the object relative to the fluid + double a; //!< is the reference area + double C1; + double C2; + double C3; }; - #endif /* D3Q27ForcesCoProcessor_H */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.cpp index 081aac982..6572ac8b5 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,14 +36,8 @@ #include "Grid3D.h" #include "UbScheduler.h" -CoProcessor::CoProcessor() -= default; - -CoProcessor::CoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s): grid(grid), scheduler(s) -{ - -} +CoProcessor::CoProcessor() = default; -CoProcessor::~CoProcessor() -= default; +CoProcessor::CoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s) : grid(grid), scheduler(s) {} +CoProcessor::~CoProcessor() = default; diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.h index 6abcda31a..7d8efad76 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/CoProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -44,23 +44,24 @@ class UbScheduler; class CoProcessor { public: - //! Class default constructor - CoProcessor(); - //! \brief Construct CoProcessor object for grid object and scheduler object. - //! \pre The Grid3D and UbScheduler objects must exist. - //! \param grid is observable Grid3D object - //! \param s is UbScheduler object for scheduling of observer - //! \details - //! Class CoProcessor implements the observer design pettern. CoProcessor object is observer. Grid3D object is observable. - CoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s); - //! Class destructor - virtual ~CoProcessor(); - //! \brief Updates observer - //! \param step is the actual time step - virtual void process(double step) = 0; + //! Class default constructor + CoProcessor(); + //! \brief Construct CoProcessor object for grid object and scheduler object. + //! \pre The Grid3D and UbScheduler objects must exist. + //! \param grid is observable Grid3D object + //! \param s is UbScheduler object for scheduling of observer + //! \details + //! Class CoProcessor implements the observer design pettern. CoProcessor object is observer. Grid3D object is + //! observable. + CoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s); + //! Class destructor + virtual ~CoProcessor(); + //! \brief Updates observer + //! \param step is the actual time step + virtual void process(double step) = 0; + protected: - SPtr<Grid3D> grid; - SPtr<UbScheduler> scheduler; + SPtr<Grid3D> grid; + SPtr<UbScheduler> scheduler; }; #endif - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.cpp index 040d5f944..f7061e9c8 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.cpp @@ -1,82 +1,70 @@ /* -* DecreaseViscosityCoProcessor -* -* Created on: 10.05.2013 -* Author: uphoff -*/ + * DecreaseViscosityCoProcessor + * + * Created on: 10.05.2013 + * Author: uphoff + */ #include "DecreaseViscosityCoProcessor.h" #include <vector> -#include "LBMKernel.h" +#include "Block3D.h" #include "Communicator.h" -#include "UbScheduler.h" #include "Grid3D.h" -#include "Block3D.h" +#include "LBMKernel.h" +#include "UbScheduler.h" -DecreaseViscosityCoProcessor::DecreaseViscosityCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - mu::Parser* nueFunc, SPtr<Communicator> comm) +DecreaseViscosityCoProcessor::DecreaseViscosityCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, mu::Parser *nueFunc, + SPtr<Communicator> comm) - : CoProcessor(grid, s) - ,nueFunc(nueFunc) - ,comm(comm) + : CoProcessor(grid, s), nueFunc(nueFunc), comm(comm) { - if (comm->getProcessID() == comm->getRoot()) - { - - } + if (comm->getProcessID() == comm->getRoot()) { + } } ////////////////////////////////////////////////////////////////////////// -DecreaseViscosityCoProcessor::~DecreaseViscosityCoProcessor() -= default; +DecreaseViscosityCoProcessor::~DecreaseViscosityCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void DecreaseViscosityCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - setViscosity(step); + if (scheduler->isDue(step)) + setViscosity(step); } ////////////////////////////////////////////////////////////////////////// void DecreaseViscosityCoProcessor::setViscosity(double step) { - UBLOG(logDEBUG3, "DecreaseViscosityCoProcessor::update:" << step); - int gridRank = grid->getRank(); - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); + UBLOG(logDEBUG3, "DecreaseViscosityCoProcessor::update:" << step); + int gridRank = grid->getRank(); + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); - if (comm->getProcessID() == comm->getRoot()) - { + if (comm->getProcessID() == comm->getRoot()) { - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, gridRank, blockVector); - for(SPtr<Block3D> block : blockVector) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - } - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, gridRank, blockVector); + for (SPtr<Block3D> block : blockVector) { + SPtr<ILBMKernel> kernel = block->getKernel(); + } + } - int istep = static_cast<int>(step); - this->timeStep = istep; - nueFunc->DefineVar("t" , &this->timeStep); - double nue=nueFunc->Eval(); + int istep = static_cast<int>(step); + this->timeStep = istep; + nueFunc->DefineVar("t", &this->timeStep); + double nue = nueFunc->Eval(); - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, gridRank, blockVector); - for(SPtr<Block3D> block : blockVector) - { - SPtr<ILBMKernel> kernel =block->getKernel(); - if(kernel) - { - LBMReal collFactor = LBMSystem::calcCollisionFactor(nue, block->getLevel()); - kernel->setCollisionFactor(collFactor); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, gridRank, blockVector); + for (SPtr<Block3D> block : blockVector) { + SPtr<ILBMKernel> kernel = block->getKernel(); + if (kernel) { + LBMReal collFactor = LBMSystem::calcCollisionFactor(nue, block->getLevel()); + kernel->setCollisionFactor(collFactor); + } } - } - } - - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.h index 3885ac399..75a833be7 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/DecreaseViscosityCoProcessor.h @@ -9,40 +9,38 @@ #include "muParser.h" - class UbScheduler; class Grid3D; class Communicator; -//! \brief The class sets viscosity/collision factor according to a previously defined function in time. -//! \details initialization in test case (example): +//! \brief The class sets viscosity/collision factor according to a previously defined function in time. +//! \details initialization in test case (example): //! \code{.cpp} -//! mu::Parser decrViscFunc; //define a mu-parser function -//! decrViscFunc.SetExpr("nue0+c0/(t+1)/(t+1)"); //this function is time-dependent, the viscosity decreases a 1/t^2 -//! decrViscFunc.DefineConst("nue0", nueLB); -//! decrViscFunc.DefineConst("c0", 0.1); //constants such as c0 controll how fast the viscosity decreasis +//! mu::Parser decrViscFunc; //define a mu-parser function +//! decrViscFunc.SetExpr("nue0+c0/(t+1)/(t+1)"); //this function is time-dependent, the viscosity decreases a 1/t^2 +//! decrViscFunc.DefineConst("nue0", nueLB); +//! decrViscFunc.DefineConst("c0", 0.1); //constants such as c0 controll how fast the viscosity decreasis //! SPtr<UbScheduler> DecrViscSch(new UbScheduler()); //the CoProcessor is called according to a Scheduler -//! DecrViscSch->addSchedule(10,10,1000); //in this case the viscosity is reset every 10 timesteps for the first 1000 timesteps -//! DecreaseViscosityCoProcessor decrViscPPPtr(grid, DecrViscSch,&decrViscFunc, comm); -//! \endcode +//! DecrViscSch->addSchedule(10,10,1000); //in this case the viscosity is reset every 10 timesteps for the +//! first 1000 timesteps DecreaseViscosityCoProcessor decrViscPPPtr(grid, DecrViscSch,&decrViscFunc, comm); \endcode //! \author Sonja Uphoff -class DecreaseViscosityCoProcessor: public CoProcessor -{ +class DecreaseViscosityCoProcessor : public CoProcessor +{ public: - DecreaseViscosityCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - mu::Parser* nueFunc, SPtr<Communicator> comm); - ~DecreaseViscosityCoProcessor() override; - //! calls collect PostprocessData. - void process(double step) override; + DecreaseViscosityCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, mu::Parser *nueFunc, SPtr<Communicator> comm); + ~DecreaseViscosityCoProcessor() override; + //! calls collect PostprocessData. + void process(double step) override; + protected: - //! resets the collision factor depending on the current timestep. - void setViscosity(double step); - SPtr<Communicator> comm; + //! resets the collision factor depending on the current timestep. + void setViscosity(double step); + SPtr<Communicator> comm; + private: - mutable mu::value_type timeStep; - mu::Parser* nueFunc; + mutable mu::value_type timeStep; + mu::Parser *nueFunc; }; - #endif /* DecreaseViscosityCoProcessor_H_ */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.cpp index f8d103396..11251a336 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.cpp @@ -1,73 +1,64 @@ #include "EmergencyExitCoProcessor.h" -#include <basics/utilities/UbFileOutputASCII.h> -#include <basics/utilities/UbFileInputASCII.h> -#include "UbLogger.h" -#include "UbScheduler.h" #include "Communicator.h" -#include "MPIIORestartCoProcessor.h" #include "Grid3D.h" +#include "MPIIORestartCoProcessor.h" +#include "UbLogger.h" +#include "UbScheduler.h" +#include <basics/utilities/UbFileInputASCII.h> +#include <basics/utilities/UbFileOutputASCII.h> -EmergencyExitCoProcessor::EmergencyExitCoProcessor( SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, - SPtr<MPIIORestartCoProcessor> rp, SPtr<Communicator> comm) : - CoProcessor(grid, s), - path(path), - rp(rp), - comm(comm) +EmergencyExitCoProcessor::EmergencyExitCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<MPIIORestartCoProcessor> rp, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), rp(rp), comm(comm) { - this->path = path + "/exit"; - metafile = this->path + "/stop.txt"; - if (comm->getProcessID() == comm->getRoot()) - { - //checkMetafile(); - writeMetafile(false); - } - comm->barrier(); + this->path = path + "/exit"; + metafile = this->path + "/stop.txt"; + if (comm->getProcessID() == comm->getRoot()) { + // checkMetafile(); + writeMetafile(false); + } + comm->barrier(); } ////////////////////////////////////////////////////////////////////////// -EmergencyExitCoProcessor::~EmergencyExitCoProcessor() -= default; +EmergencyExitCoProcessor::~EmergencyExitCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// -void EmergencyExitCoProcessor::process( double step ) +void EmergencyExitCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "EmergencyExitCoProcessor::update:" << step); + UBLOG(logDEBUG3, "EmergencyExitCoProcessor::update:" << step); } -void EmergencyExitCoProcessor::collectData( double step ) +void EmergencyExitCoProcessor::collectData(double step) { - if(readMetafile()) - { - rp->process((int)step); - if(comm->getProcessID() == comm->getRoot()) UBLOG(logINFO,"EmergencyExitCoProcessor save step: " << step); - comm->barrier(); - exit(EXIT_SUCCESS); - } + if (readMetafile()) { + rp->process((int)step); + if (comm->getProcessID() == comm->getRoot()) + UBLOG(logINFO, "EmergencyExitCoProcessor save step: " << step); + comm->barrier(); + exit(EXIT_SUCCESS); + } } ////////////////////////////////////////////////////////////////////////// -void EmergencyExitCoProcessor::writeMetafile(int /*status*/ ) +void EmergencyExitCoProcessor::writeMetafile(int /*status*/) { - UbFileOutputASCII out(metafile); - out.writeBool(false); + UbFileOutputASCII out(metafile); + out.writeBool(false); } ////////////////////////////////////////////////////////////////////////// bool EmergencyExitCoProcessor::readMetafile() { - UbFileInputASCII in(metafile); - return in.readBool(); + UbFileInputASCII in(metafile); + return in.readBool(); } ////////////////////////////////////////////////////////////////////////// void EmergencyExitCoProcessor::checkMetafile() { - std::ifstream file(metafile.c_str()); - if (!file.is_open()) - { - writeMetafile(false); - return; - } - file.close(); + std::ifstream file(metafile.c_str()); + if (!file.is_open()) { + writeMetafile(false); + return; + } + file.close(); } - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.h index 4dd768a59..382083c07 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/EmergencyExitCoProcessor.h @@ -21,7 +21,8 @@ class UbScheduler; class EmergencyExitCoProcessor : public CoProcessor { public: - EmergencyExitCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<MPIIORestartCoProcessor> rp, SPtr<Communicator> comm); + EmergencyExitCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<MPIIORestartCoProcessor> rp, SPtr<Communicator> comm); ~EmergencyExitCoProcessor() override; void process(double step) override; @@ -39,5 +40,4 @@ private: std::string metafile; }; - #endif /* EmergencyExitCoProcessor_H */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.cpp index 40a8a61f3..7e04fd4b6 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.cpp @@ -1,105 +1,93 @@ #include "ForceCalculator.h" #include "BCProcessor.h" -#include "Communicator.h" -#include "D3Q27Interactor.h" -#include "DataSet3D.h" -#include "LBMKernel.h" +#include "BCArray3D.h" #include "Block3D.h" #include "BoundaryConditions.h" -#include "BCArray3D.h" #include "Communicator.h" -#include "DistributionArray3D.h" -#include "BoundaryConditions.h" #include "D3Q27Interactor.h" +#include "DataSet3D.h" +#include "DistributionArray3D.h" +#include "LBMKernel.h" -ForceCalculator::ForceCalculator(SPtr<Communicator> comm) : comm(comm), forceX1global(0), forceX2global(0), forceX3global(0) +ForceCalculator::ForceCalculator(SPtr<Communicator> comm) + : comm(comm), forceX1global(0), forceX2global(0), forceX3global(0) { - } -ForceCalculator::~ForceCalculator() -= default; - - +ForceCalculator::~ForceCalculator() = default; - -Vector3D ForceCalculator::getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, SPtr<BoundaryConditions> bc, const Vector3D& boundaryVelocity) const +Vector3D ForceCalculator::getForces(int x1, int x2, int x3, SPtr<DistributionArray3D> distributions, + SPtr<BoundaryConditions> bc, const Vector3D &boundaryVelocity) const { double forceX1 = 0; double forceX2 = 0; double forceX3 = 0; - if (bc) - { - for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) - { - if (bc->hasNoSlipBoundaryFlag(fdir) || bc->hasVelocityBoundaryFlag(fdir)) - { - const int invDir = D3Q27System::INVDIR[fdir]; - const double f = distributions->getDistributionInvForDirection(x1, x2, x3, invDir); - const double fnbr = distributions->getDistributionInvForDirection(x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); + if (bc) { + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (bc->hasNoSlipBoundaryFlag(fdir) || bc->hasVelocityBoundaryFlag(fdir)) { + const int invDir = D3Q27System::INVDIR[fdir]; + const double f = distributions->getDistributionInvForDirection(x1, x2, x3, invDir); + const double fnbr = distributions->getDistributionInvForDirection( + x1 + D3Q27System::DX1[invDir], x2 + D3Q27System::DX2[invDir], x3 + D3Q27System::DX3[invDir], fdir); double correction[3] = { 0.0, 0.0, 0.0 }; - if(bc->hasVelocityBoundaryFlag(fdir)) - { + if (bc->hasVelocityBoundaryFlag(fdir)) { const double forceTerm = f - fnbr; - correction[0] = forceTerm * boundaryVelocity[0]; - correction[1] = forceTerm * boundaryVelocity[1]; - correction[2] = forceTerm * boundaryVelocity[2]; + correction[0] = forceTerm * boundaryVelocity[0]; + correction[1] = forceTerm * boundaryVelocity[1]; + correction[2] = forceTerm * boundaryVelocity[2]; } - //UBLOG(logINFO, "c, c * bv(x,y,z): " << correction << ", " << correction * val<1>(boundaryVelocity) << ", " << correction * val<2>(boundaryVelocity) << ", " << correction * val<3>(boundaryVelocity)); + // UBLOG(logINFO, "c, c * bv(x,y,z): " << correction << ", " << correction * val<1>(boundaryVelocity) << + // ", " << correction * val<2>(boundaryVelocity) << ", " << correction * val<3>(boundaryVelocity)); // force consists of the MEM part and the galilean invariance correction including the boundary velocity forceX1 += (f + fnbr) * D3Q27System::DX1[invDir] - correction[0]; forceX2 += (f + fnbr) * D3Q27System::DX2[invDir] - correction[1]; forceX3 += (f + fnbr) * D3Q27System::DX3[invDir] - correction[2]; } - } + } } return Vector3D(forceX1, forceX2, forceX3); } -void ForceCalculator::calculateForces(std::vector<SPtr<D3Q27Interactor> > interactors) +void ForceCalculator::calculateForces(std::vector<SPtr<D3Q27Interactor>> interactors) { forceX1global = 0.0; forceX2global = 0.0; forceX3global = 0.0; - for (const auto& interactor : interactors) - { - for (const auto& t : interactor->getBcNodeIndicesMap()) - { + for (const auto &interactor : interactors) { + for (const auto &t : interactor->getBcNodeIndicesMap()) { double forceX1 = 0.0; double forceX2 = 0.0; double forceX3 = 0.0; - SPtr<Block3D>block = t.first; - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<Block3D> block = t.first; + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); distributions->swap(); - const std::set< std::vector<int> >& transNodeIndices = t.second; - for (std::vector<int> node : transNodeIndices) - { + const std::set<std::vector<int>> &transNodeIndices = t.second; + for (std::vector<int> node : transNodeIndices) { int x1 = node[0]; int x2 = node[1]; int x3 = node[2]; - if (kernel->isInsideOfDomain(x1, x2, x3) && bcArray->isFluid(x1, x2, x3)) - { + if (kernel->isInsideOfDomain(x1, x2, x3) && bcArray->isFluid(x1, x2, x3)) { SPtr<BoundaryConditions> bc = bcArray->getBC(x1, x2, x3); - Vector3D forceVec = getForces(x1, x2, x3, distributions, bc); + Vector3D forceVec = getForces(x1, x2, x3, distributions, bc); forceX1 += forceVec[0]; forceX2 += forceVec[1]; forceX3 += forceVec[2]; } } - //if we have got discretization with more level - // deltaX is LBM deltaX and equal LBM deltaT - double deltaX = LBMSystem::getDeltaT(block->getLevel()); //grid->getDeltaT(block); - double deltaXquadrat = deltaX*deltaX; + // if we have got discretization with more level + // deltaX is LBM deltaX and equal LBM deltaT + double deltaX = LBMSystem::getDeltaT(block->getLevel()); // grid->getDeltaT(block); + double deltaXquadrat = deltaX * deltaX; forceX1 *= deltaXquadrat; forceX2 *= deltaXquadrat; forceX3 *= deltaXquadrat; @@ -116,20 +104,19 @@ void ForceCalculator::calculateForces(std::vector<SPtr<D3Q27Interactor> > intera void ForceCalculator::gatherGlobalForces() { - std::vector<double> values;// intel compiler 17 dasn't support this { forceX1global , forceX2global, forceX3global }; + std::vector<double> + values; // intel compiler 17 dasn't support this { forceX1global , forceX2global, forceX3global }; values.push_back(forceX1global); values.push_back(forceX2global); values.push_back(forceX3global); std::vector<double> rvalues = comm->gather(values); - if (comm->isRoot()) - { + if (comm->isRoot()) { forceX1global = 0.0; forceX2global = 0.0; forceX3global = 0.0; - for (int i = 0; i < (int)rvalues.size(); i += 3) - { + for (int i = 0; i < (int)rvalues.size(); i += 3) { forceX1global += rvalues[i]; forceX2global += rvalues[i + 1]; forceX3global += rvalues[i + 2]; @@ -137,7 +124,4 @@ void ForceCalculator::gatherGlobalForces() } } -Vector3D ForceCalculator::getGlobalForces() const -{ - return Vector3D(forceX1global, forceX2global, forceX3global); -} +Vector3D ForceCalculator::getGlobalForces() const { return Vector3D(forceX1global, forceX2global, forceX3global); } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.h b/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.h index 8d90d09d8..432cc4522 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/ForceCalculator.h @@ -8,8 +8,8 @@ #ifndef ForceCalculator_H #define ForceCalculator_H -#include <vector> #include <memory> +#include <vector> #include "Vector3D.h" @@ -24,8 +24,10 @@ public: ForceCalculator(std::shared_ptr<Communicator> comm); virtual ~ForceCalculator(); - void calculateForces(std::vector<std::shared_ptr<D3Q27Interactor> > interactors); - Vector3D getForces(int x1, int x2, int x3, std::shared_ptr<DistributionArray3D> distributions, std::shared_ptr<BoundaryConditions> bc, const Vector3D& boundaryVelocity = Vector3D(0.0, 0.0, 0.0)) const; + void calculateForces(std::vector<std::shared_ptr<D3Q27Interactor>> interactors); + Vector3D getForces(int x1, int x2, int x3, std::shared_ptr<DistributionArray3D> distributions, + std::shared_ptr<BoundaryConditions> bc, + const Vector3D &boundaryVelocity = Vector3D(0.0, 0.0, 0.0)) const; Vector3D getGlobalForces() const; @@ -39,5 +41,4 @@ private: double forceX3global; }; - -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.cpp index 53916a56e..6955c55dd 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.cpp @@ -1,349 +1,337 @@ #ifdef VF_CATALYST #include "InSituCatalystCoProcessor.h" -#include <LBMKernel.h> #include <D3Q27ETBCProcessor.h> -#include <vector> +#include <LBMKernel.h> #include <string> +#include <vector> #include <vtkCellType.h> #include <vtkPointData.h> #include <vtkXMLUnstructuredGridWriter.h> -#include <iostream> #include <fstream> +#include <iostream> using namespace std; -InSituCatalystCoProcessor::InSituCatalystCoProcessor() -{ - -} +InSituCatalystCoProcessor::InSituCatalystCoProcessor() {} ////////////////////////////////////////////////////////////////////////// -InSituCatalystCoProcessor::InSituCatalystCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::string script) : CoProcessor(grid, s) +InSituCatalystCoProcessor::InSituCatalystCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::string script) + : CoProcessor(grid, s) { - gridRank = Communicator::getInstance()->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = Communicator::getInstance()->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - blockVector.resize(maxInitLevel + 1); + blockVector.resize(maxInitLevel + 1); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + } - Processor = vtkSmartPointer<vtkCPProcessor>::New(); - Processor->Initialize(); + Processor = vtkSmartPointer<vtkCPProcessor>::New(); + Processor->Initialize(); - vtkNew<vtkCPPythonScriptPipeline> pipeline; - pipeline->Initialize(script.c_str()); - Processor->AddPipeline(pipeline.GetPointer()); + vtkNew<vtkCPPythonScriptPipeline> pipeline; + pipeline->Initialize(script.c_str()); + Processor->AddPipeline(pipeline.GetPointer()); - buildVTKGrid(); + buildVTKGrid(); } ////////////////////////////////////////////////////////////////////////// -InSituCatalystCoProcessor::~InSituCatalystCoProcessor() -{ - -} +InSituCatalystCoProcessor::~InSituCatalystCoProcessor() {} ////////////////////////////////////////////////////////////////////////// void InSituCatalystCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "InSituCatalystCoProcessor::update:" << step); + UBLOG(logDEBUG3, "InSituCatalystCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void InSituCatalystCoProcessor::collectData(double step) { - unsigned int istep = static_cast<int>(step); - - vtkNew<vtkCPDataDescription> dataDescription; - dataDescription->AddInput("input"); - dataDescription->SetTimeData(step, istep); - - if (Processor->RequestDataDescription(dataDescription.GetPointer()) != 0) - { - - index = 0; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); + unsigned int istep = static_cast<int>(step); + + vtkNew<vtkCPDataDescription> dataDescription; + dataDescription->AddInput("input"); + dataDescription->SetTimeData(step, istep); + + if (Processor->RequestDataDescription(dataDescription.GetPointer()) != 0) { + + index = 0; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } } - } - } + } - vtkDoubleArray* rho = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Rho")); - rho->SetArray(&rhoArray[0], static_cast<vtkIdType>(rhoArray.size()), 1); + vtkDoubleArray *rho = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Rho")); + rho->SetArray(&rhoArray[0], static_cast<vtkIdType>(rhoArray.size()), 1); - vtkDoubleArray* vx1 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vx")); - vx1->SetArray(&vx1Array[0], static_cast<vtkIdType>(vx1Array.size()), 1); + vtkDoubleArray *vx1 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vx")); + vx1->SetArray(&vx1Array[0], static_cast<vtkIdType>(vx1Array.size()), 1); - vtkDoubleArray* vx2 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vy")); - vx2->SetArray(&vx2Array[0], static_cast<vtkIdType>(vx2Array.size()), 1); + vtkDoubleArray *vx2 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vy")); + vx2->SetArray(&vx2Array[0], static_cast<vtkIdType>(vx2Array.size()), 1); - vtkDoubleArray* vx3 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vz")); - vx3->SetArray(&vx3Array[0], static_cast<vtkIdType>(vx3Array.size()), 1); + vtkDoubleArray *vx3 = vtkDoubleArray::SafeDownCast(unstructuredGrid->GetPointData()->GetArray("Vz")); + vx3->SetArray(&vx3Array[0], static_cast<vtkIdType>(vx3Array.size()), 1); - dataDescription->GetInputDescriptionByName("input")->SetGrid(unstructuredGrid); - Processor->CoProcess(dataDescription.GetPointer()); - } + dataDescription->GetInputDescriptionByName("input")->SetGrid(unstructuredGrid); + Processor->CoProcess(dataDescription.GetPointer()); + } - UBLOG(logINFO, "InSituCatalystCoProcessor step: " << istep); + UBLOG(logINFO, "InSituCatalystCoProcessor step: " << istep); } ////////////////////////////////////////////////////////////////////////// void InSituCatalystCoProcessor::addData(SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - SPtr<LBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - LBMReal f[D3Q27System::ENDF + 1]; - LBMReal vx1, vx2, vx3, rho; - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - - - for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) - { - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f, rho, vx1, vx2, vx3); - double press = D3Q27System::calcPress(f, rho, vx1, vx2, vx3); - - if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) - UB_THROW(UbException(UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //rho=999.0; - if (UbMath::isNaN(press) || UbMath::isInfinity(press)) - UB_THROW(UbException(UB_EXARGS, "press is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //press=999.0; - if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) - UB_THROW(UbException(UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx1=999.0; - if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) - UB_THROW(UbException(UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx2=999.0; - if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) - UB_THROW(UbException(UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx3=999.0; - - rhoArray[index] = rho; - vx1Array[index] = vx1; - vx2Array[index] = vx2; - vx3Array[index] = vx3; - index++; + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + SPtr<LBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) { + for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) { + for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + double press = D3Q27System::calcPress(f, rho, vx1, vx2, vx3); + + if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) + UB_THROW(UbException( + UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // rho=999.0; + if (UbMath::isNaN(press) || UbMath::isInfinity(press)) + UB_THROW(UbException( + UB_EXARGS, "press is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // press=999.0; + if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) + UB_THROW(UbException( + UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx1=999.0; + if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) + UB_THROW(UbException( + UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx2=999.0; + if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) + UB_THROW(UbException( + UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx3=999.0; + + rhoArray[index] = rho; + vx1Array[index] = vx1; + vx2Array[index] = vx2; + vx3Array[index] = vx3; + index++; + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void InSituCatalystCoProcessor::buildVTKGrid() { - unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); - points = vtkPoints::New(); - unstructuredGrid->SetPoints(points); - arrays[0] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[0]->SetNumberOfComponents(1); - arrays[0]->SetName("Rho"); - arrays[1] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[1]->SetNumberOfComponents(1); - arrays[1]->SetName("Vx"); - arrays[2] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[2]->SetNumberOfComponents(1); - arrays[2]->SetName("Vy"); - arrays[3] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[3]->SetNumberOfComponents(1); - arrays[3]->SetName("Vz"); - - numOfPoints = 0; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addVTKGridData(block); - } - } - } - - unstructuredGrid->GetPointData()->AddArray(arrays[0]); - unstructuredGrid->GetPointData()->AddArray(arrays[1]); - unstructuredGrid->GetPointData()->AddArray(arrays[2]); - unstructuredGrid->GetPointData()->AddArray(arrays[3]); - unstructuredGrid->GetPointData()->SetScalars(arrays[1]); - - rhoArray.resize(numOfPoints); - vx1Array.resize(numOfPoints); - vx2Array.resize(numOfPoints); - vx3Array.resize(numOfPoints); + unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); + points = vtkPoints::New(); + unstructuredGrid->SetPoints(points); + arrays[0] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[0]->SetNumberOfComponents(1); + arrays[0]->SetName("Rho"); + arrays[1] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[1]->SetNumberOfComponents(1); + arrays[1]->SetName("Vx"); + arrays[2] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[2]->SetNumberOfComponents(1); + arrays[2]->SetName("Vy"); + arrays[3] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[3]->SetNumberOfComponents(1); + arrays[3]->SetName("Vz"); + + numOfPoints = 0; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addVTKGridData(block); + } + } + } + + unstructuredGrid->GetPointData()->AddArray(arrays[0]); + unstructuredGrid->GetPointData()->AddArray(arrays[1]); + unstructuredGrid->GetPointData()->AddArray(arrays[2]); + unstructuredGrid->GetPointData()->AddArray(arrays[3]); + unstructuredGrid->GetPointData()->SetScalars(arrays[1]); + + rhoArray.resize(numOfPoints); + vx1Array.resize(numOfPoints); + vx2Array.resize(numOfPoints); + vx3Array.resize(numOfPoints); } ////////////////////////////////////////////////////////////////////////// void InSituCatalystCoProcessor::addVTKGridData(SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - SPtr<LBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - LBMReal f[D3Q27System::ENDF + 1]; - LBMReal vx1, vx2, vx3, rho; - - //knotennummerierung faengt immer bei 0 an! - int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; - - //Funktionszeiger - //typedef void(*CalcMacrosFct)(const LBMReal* const& /*feq[27]*/, LBMReal& /*(d)rho*/, LBMReal& /*vx1*/, LBMReal& /*vx2*/, LBMReal& /*vx3*/); - - //CalcMacrosFct calcMacros = NULL; - - if (block->getKernel()->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - SPtr<BoundaryConditions> bcPtr; - int nr = points->GetNumberOfPoints(); - - double x[3]; - - for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) - { - x[0] = double(val<1>(org) -val<1>(nodeOffset) +ix1*dx); - x[1] = double(val<2>(org) -val<2>(nodeOffset) +ix2*dx); - x[2] = double(val<3>(org) -val<3>(nodeOffset) +ix3*dx); - - points->InsertPoint((vtkIdType)nr, x); - - nodeNumbers(ix1, ix2, ix3) = nr++; - - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f, rho, vx1, vx2, vx3); - double press = D3Q27System::calcPress(f, rho, vx1, vx2, vx3); - - if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) - UB_THROW(UbException(UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //rho=999.0; - if (UbMath::isNaN(press) || UbMath::isInfinity(press)) - UB_THROW(UbException(UB_EXARGS, "press is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //press=999.0; - if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) - UB_THROW(UbException(UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx1=999.0; - if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) - UB_THROW(UbException(UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx2=999.0; - if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) - UB_THROW(UbException(UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + block->toString() + - ", node=" + UbSystem::toString(ix1) + "," + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - //vx3=999.0; - - arrays[0]->InsertNextValue(rho); - arrays[1]->InsertNextValue(vx1); - arrays[2]->InsertNextValue(vx2); - arrays[3]->InsertNextValue(vx3); - numOfPoints++; + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + SPtr<LBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + + // knotennummerierung faengt immer bei 0 an! + int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + // Funktionszeiger + // typedef void(*CalcMacrosFct)(const LBMReal* const& /*feq[27]*/, LBMReal& /*(d)rho*/, LBMReal& /*vx1*/, LBMReal& + // /*vx2*/, LBMReal& /*vx3*/); + + // CalcMacrosFct calcMacros = NULL; + + if (block->getKernel()->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + SPtr<BoundaryConditions> bcPtr; + int nr = points->GetNumberOfPoints(); + + double x[3]; + + for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) { + for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) { + for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + x[0] = double(val<1>(org) - val<1>(nodeOffset) + ix1 * dx); + x[1] = double(val<2>(org) - val<2>(nodeOffset) + ix2 * dx); + x[2] = double(val<3>(org) - val<3>(nodeOffset) + ix3 * dx); + + points->InsertPoint((vtkIdType)nr, x); + + nodeNumbers(ix1, ix2, ix3) = nr++; + + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + double press = D3Q27System::calcPress(f, rho, vx1, vx2, vx3); + + if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) + UB_THROW(UbException( + UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // rho=999.0; + if (UbMath::isNaN(press) || UbMath::isInfinity(press)) + UB_THROW(UbException( + UB_EXARGS, "press is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // press=999.0; + if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) + UB_THROW(UbException( + UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx1=999.0; + if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) + UB_THROW(UbException( + UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx2=999.0; + if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) + UB_THROW(UbException( + UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx3=999.0; + + arrays[0]->InsertNextValue(rho); + arrays[1]->InsertNextValue(vx1); + arrays[2]->InsertNextValue(vx2); + arrays[3]->InsertNextValue(vx3); + numOfPoints++; + } } - } - } - } - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - vtkIdType ptIds[8]; - //cell vector erstellen - for (int ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (int ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (int ix1 = minX1; ix1 <= maxX1; ix1++) - { - if ((ptIds[0] = SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 - && (ptIds[1] = SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 - && (ptIds[2] = NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 - && (ptIds[3] = NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 - && (ptIds[4] = SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 - && (ptIds[5] = SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 - && (ptIds[6] = NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0 - && (ptIds[7] = NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 - ) - { - unstructuredGrid->InsertNextCell((int)VTK_VOXEL, (vtkIdType)8, ptIds); + } + } + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + vtkIdType ptIds[8]; + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((ptIds[0] = SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && + (ptIds[1] = SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (ptIds[2] = NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (ptIds[3] = NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && + (ptIds[4] = SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && + (ptIds[5] = SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (ptIds[6] = NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0 && + (ptIds[7] = NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0) { + unstructuredGrid->InsertNextCell((int)VTK_VOXEL, (vtkIdType)8, ptIds); + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// - #endif - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.h index 3d4bb25c6..5fa6d3fd1 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/InSituCatalystCoProcessor.h @@ -3,51 +3,53 @@ #ifndef InSituCatalystCoProcessor_h__ #define InSituCatalystCoProcessor_h__ - #include <CoProcessor.h> #include <Grid3D.h> #include <LBMUnitConverter.h> #include <string> -#include <vtkSmartPointer.h> -#include <vtkUnstructuredGrid.h> -#include <vtkDoubleArray.h> #include <vtkCPDataDescription.h> #include <vtkCPInputDataDescription.h> #include <vtkCPProcessor.h> #include <vtkCPPythonScriptPipeline.h> +#include <vtkDoubleArray.h> #include <vtkNew.h> +#include <vtkSmartPointer.h> +#include <vtkUnstructuredGrid.h> class InSituCatalystCoProcessor : public CoProcessor { public: - InSituCatalystCoProcessor(); - InSituCatalystCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::string script); - virtual ~InSituCatalystCoProcessor(); - void process(double step); + InSituCatalystCoProcessor(); + InSituCatalystCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, std::string script); + virtual ~InSituCatalystCoProcessor(); + void process(double step); + protected: - void collectData(double step); - void addData(SPtr<Block3D> block); - void buildVTKGrid(); - void addVTKGridData(SPtr<Block3D> block); + void collectData(double step); + void addData(SPtr<Block3D> block); + void buildVTKGrid(); + void addVTKGridData(SPtr<Block3D> block); + private: - std::vector<std::vector<SPtr<Block3D>> > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - vtkSmartPointer<vtkCPProcessor> Processor; - vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid; - vtkSmartPointer<vtkPoints> points; - vtkSmartPointer<vtkDoubleArray> arrays[4]; - std::vector<double> vx1Array; - std::vector<double> vx2Array; - std::vector<double> vx3Array; - std::vector<double> rhoArray; - int index; - int numOfPoints; - typedef void(*CalcMacrosFct)(const LBMReal* const& /*feq[27]*/, LBMReal& /*(d)rho*/, LBMReal& /*vx1*/, LBMReal& /*vx2*/, LBMReal& /*vx3*/); - CalcMacrosFct calcMacros; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + vtkSmartPointer<vtkCPProcessor> Processor; + vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid; + vtkSmartPointer<vtkPoints> points; + vtkSmartPointer<vtkDoubleArray> arrays[4]; + std::vector<double> vx1Array; + std::vector<double> vx2Array; + std::vector<double> vx3Array; + std::vector<double> rhoArray; + int index; + int numOfPoints; + typedef void (*CalcMacrosFct)(const LBMReal *const & /*feq[27]*/, LBMReal & /*(d)rho*/, LBMReal & /*vx1*/, + LBMReal & /*vx2*/, LBMReal & /*vx3*/); + CalcMacrosFct calcMacros; }; #endif // InSituCatalystCoProcessor_h__ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.cpp index 600488d58..8d5cec105 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.cpp @@ -1,304 +1,289 @@ #ifdef VF_VTK #include "InSituVTKCoProcessor.h" -#include <LBMKernel.h> +#include <BCArray3D.h> #include <BCProcessor.h> +#include <Block3D.h> +#include <BoundaryConditions.h> #include <Communicator.h> -#include <UbScheduler.h> -#include <DistributionArray3D.h> #include <D3Q27System.h> -#include <BoundaryConditions.h> -#include <Block3D.h> -#include <LBMKernel.h> #include <DataSet3D.h> -#include <BCArray3D.h> +#include <DistributionArray3D.h> +#include <LBMKernel.h> +#include <UbScheduler.h> -#include <vector> #include <string> +#include <vector> #include <vtkCellType.h> #include <vtkPointData.h> #include <vtkXMLUnstructuredGridWriter.h> -#include <iostream> #include <fstream> +#include <iostream> using namespace std; -InSituVTKCoProcessor::InSituVTKCoProcessor() -{ - -} +InSituVTKCoProcessor::InSituVTKCoProcessor() {} ////////////////////////////////////////////////////////////////////////// -InSituVTKCoProcessor::InSituVTKCoProcessor( SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& configFile, SPtr<LBMUnitConverter> conv ) : CoProcessor(grid, s), conv(conv) +InSituVTKCoProcessor::InSituVTKCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &configFile, + SPtr<LBMUnitConverter> conv) + : CoProcessor(grid, s), conv(conv) { - gridRank = Communicator::getInstance()->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = Communicator::getInstance()->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - readConfigFile(configFile); + readConfigFile(configFile); - blockVector.resize(maxInitLevel+1); + blockVector.resize(maxInitLevel + 1); - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + } - //initialization of communicator - contr = vtkSmartPointer<vtkSocketController>::New(); - contr->Initialize(); + // initialization of communicator + contr = vtkSmartPointer<vtkSocketController>::New(); + contr->Initialize(); - comm = vtkSmartPointer<vtkSocketCommunicator>::New(); + comm = vtkSmartPointer<vtkSocketCommunicator>::New(); - // Establish connection - if (!comm->ConnectTo(wHostname.c_str(), wPort)) - { - cerr << "Client error: Could not connect to the server."<< endl; - return; - } - + // Establish connection + if (!comm->ConnectTo(wHostname.c_str(), wPort)) { + cerr << "Client error: Could not connect to the server." << endl; + return; + } } ////////////////////////////////////////////////////////////////////////// -InSituVTKCoProcessor::~InSituVTKCoProcessor() -{ - comm->CloseConnection(); -} +InSituVTKCoProcessor::~InSituVTKCoProcessor() { comm->CloseConnection(); } ////////////////////////////////////////////////////////////////////////// -void InSituVTKCoProcessor::process( double step ) +void InSituVTKCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "InSituVTKCoProcessor::update:" << step); + UBLOG(logDEBUG3, "InSituVTKCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// -void InSituVTKCoProcessor::collectData( double step ) +void InSituVTKCoProcessor::collectData(double step) { - int istep = static_cast<int>(step); - - unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); - points = vtkPoints::New(); - unstructuredGrid->SetPoints(points); - arrays[0] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[0]->SetNumberOfComponents(1); - arrays[0]->SetName( "Rho" ); - arrays[1] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[1]->SetNumberOfComponents(1); - arrays[1]->SetName( "Vx" ); - arrays[2] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[2]->SetNumberOfComponents(1); - arrays[2]->SetName( "Vy" ); - arrays[3] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[3]->SetNumberOfComponents(1); - arrays[3]->SetName( "Vz" ); - arrays[4] = vtkSmartPointer<vtkDoubleArray>::New(); - arrays[4]->SetNumberOfComponents(1); - arrays[4]->SetName( "Press" ); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); - } - } - } - - unstructuredGrid->GetPointData()->AddArray(arrays[0]); - unstructuredGrid->GetPointData()->AddArray(arrays[1]); - unstructuredGrid->GetPointData()->AddArray(arrays[2]); - unstructuredGrid->GetPointData()->AddArray(arrays[3]); - unstructuredGrid->GetPointData()->AddArray(arrays[4]); - unstructuredGrid->GetPointData()->SetScalars(arrays[1]); - - if (!comm->Send(&istep, 1, 1, 11)) - { - cerr << "Client error: Error sending data." << endl; - return; - } - - if (!comm->Send(unstructuredGrid, 1, 9)) - { - cerr << "Server error: Error sending data." << endl; - return; - } - - //vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New(); - //writer->SetInput(unstructuredGrid); - //writer->SetFileName("test.vtu"); - //writer->SetDataModeToAscii(); - //writer->Update(); - - UBLOG(logINFO,"InSituVTKCoProcessor step: " << istep); + int istep = static_cast<int>(step); + + unstructuredGrid = vtkSmartPointer<vtkUnstructuredGrid>::New(); + points = vtkPoints::New(); + unstructuredGrid->SetPoints(points); + arrays[0] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[0]->SetNumberOfComponents(1); + arrays[0]->SetName("Rho"); + arrays[1] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[1]->SetNumberOfComponents(1); + arrays[1]->SetName("Vx"); + arrays[2] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[2]->SetNumberOfComponents(1); + arrays[2]->SetName("Vy"); + arrays[3] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[3]->SetNumberOfComponents(1); + arrays[3]->SetName("Vz"); + arrays[4] = vtkSmartPointer<vtkDoubleArray>::New(); + arrays[4]->SetNumberOfComponents(1); + arrays[4]->SetName("Press"); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } + } + } + + unstructuredGrid->GetPointData()->AddArray(arrays[0]); + unstructuredGrid->GetPointData()->AddArray(arrays[1]); + unstructuredGrid->GetPointData()->AddArray(arrays[2]); + unstructuredGrid->GetPointData()->AddArray(arrays[3]); + unstructuredGrid->GetPointData()->AddArray(arrays[4]); + unstructuredGrid->GetPointData()->SetScalars(arrays[1]); + + if (!comm->Send(&istep, 1, 1, 11)) { + cerr << "Client error: Error sending data." << endl; + return; + } + + if (!comm->Send(unstructuredGrid, 1, 9)) { + cerr << "Server error: Error sending data." << endl; + return; + } + + // vtkSmartPointer<vtkXMLUnstructuredGridWriter> writer = vtkSmartPointer<vtkXMLUnstructuredGridWriter>::New(); + // writer->SetInput(unstructuredGrid); + // writer->SetFileName("test.vtu"); + // writer->SetDataModeToAscii(); + // writer->Update(); + + UBLOG(logINFO, "InSituVTKCoProcessor step: " << istep); } ////////////////////////////////////////////////////////////////////////// -void InSituVTKCoProcessor::addData( SPtr<Block3D> block ) +void InSituVTKCoProcessor::addData(SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - LBMReal f[D3Q27System::ENDF+1]; - LBMReal vx1,vx2,vx3,rho; - - //knotennummerierung faengt immer bei 0 an! - int SWB,SEB,NEB,NWB,SWT,SET,NET,NWT; - - //Funktionszeiger - typedef void (*CalcMacrosFct)(const LBMReal* const& /*feq[27]*/,LBMReal& /*(d)rho*/, LBMReal& /*vx1*/, LBMReal& /*vx2*/, LBMReal& /*vx3*/); - - CalcMacrosFct calcMacros = NULL; - - if(block->getKernel()->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - - //int minX1 = 1; - //int minX2 = 1; - //int minX3 = 1; - - //int maxX1 = (int)(distributions->getNX1()); - //int maxX2 = (int)(distributions->getNX2()); - //int maxX3 = (int)(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - SPtr<BoundaryConditions> bcPtr; - int nr = points->GetNumberOfPoints(); - - double x[3]; - - for(size_t ix3=minX3; ix3<=maxX3; ix3++) - { - for(size_t ix2=minX2; ix2<=maxX2; ix2++) - { - for(size_t ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - int index = 0; - - x[0] = double(val<1>(org) - val<1>(nodeOffset) + ix1*dx); - x[1] = double(val<2>(org) - val<2>(nodeOffset) + ix2*dx); - x[2] = double(val<3>(org) - val<3>(nodeOffset) + ix3*dx); - - points->InsertPoint((vtkIdType)nr, x); - - nodeNumbers(ix1,ix2,ix3) = nr++; - - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f,rho,vx1,vx2,vx3); - double press = D3Q27System::calcPress(f,rho,vx1,vx2,vx3); - - if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) - UB_THROW( UbException(UB_EXARGS,"rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //rho=999.0; - if (UbMath::isNaN(press) || UbMath::isInfinity(press)) - UB_THROW( UbException(UB_EXARGS,"press is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //press=999.0; - if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) - UB_THROW( UbException(UB_EXARGS,"vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx1=999.0; - if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) - UB_THROW( UbException(UB_EXARGS,"vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx2=999.0; - if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) - UB_THROW( UbException(UB_EXARGS,"vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx3=999.0; - - arrays[0]->InsertNextValue(rho * conv->getFactorDensityLbToW2()); - arrays[1]->InsertNextValue(vx1 * conv->getFactorVelocityLbToW2()); - arrays[2]->InsertNextValue(vx2 * conv->getFactorVelocityLbToW2()); - arrays[3]->InsertNextValue(vx3 * conv->getFactorVelocityLbToW2()); - arrays[4]->InsertNextValue(press * conv->getFactorPressureLbToW2()); + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + + // knotennummerierung faengt immer bei 0 an! + int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + // Funktionszeiger + typedef void (*CalcMacrosFct)(const LBMReal *const & /*feq[27]*/, LBMReal & /*(d)rho*/, LBMReal & /*vx1*/, + LBMReal & /*vx2*/, LBMReal & /*vx3*/); + + CalcMacrosFct calcMacros = NULL; + + if (block->getKernel()->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + + // int minX1 = 1; + // int minX2 = 1; + // int minX3 = 1; + + // int maxX1 = (int)(distributions->getNX1()); + // int maxX2 = (int)(distributions->getNX2()); + // int maxX3 = (int)(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + SPtr<BoundaryConditions> bcPtr; + int nr = points->GetNumberOfPoints(); + + double x[3]; + + for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) { + for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) { + for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + int index = 0; + + x[0] = double(val<1>(org) - val<1>(nodeOffset) + ix1 * dx); + x[1] = double(val<2>(org) - val<2>(nodeOffset) + ix2 * dx); + x[2] = double(val<3>(org) - val<3>(nodeOffset) + ix3 * dx); + + points->InsertPoint((vtkIdType)nr, x); + + nodeNumbers(ix1, ix2, ix3) = nr++; + + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + double press = D3Q27System::calcPress(f, rho, vx1, vx2, vx3); + + if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) + UB_THROW(UbException( + UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // rho=999.0; + if (UbMath::isNaN(press) || UbMath::isInfinity(press)) + UB_THROW(UbException( + UB_EXARGS, "press is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // press=999.0; + if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) + UB_THROW(UbException( + UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx1=999.0; + if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) + UB_THROW(UbException( + UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx2=999.0; + if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) + UB_THROW(UbException( + UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx3=999.0; + + arrays[0]->InsertNextValue(rho * conv->getFactorDensityLbToW2()); + arrays[1]->InsertNextValue(vx1 * conv->getFactorVelocityLbToW2()); + arrays[2]->InsertNextValue(vx2 * conv->getFactorVelocityLbToW2()); + arrays[3]->InsertNextValue(vx3 * conv->getFactorVelocityLbToW2()); + arrays[4]->InsertNextValue(press * conv->getFactorPressureLbToW2()); + } } - } - } - } - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - vtkIdType ptIds[8]; - //cell vector erstellen - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if( (ptIds[0]=SWB=nodeNumbers( ix1 , ix2, ix3 )) >= 0 - && (ptIds[1]=SEB=nodeNumbers( ix1+1, ix2, ix3 )) >= 0 - && (ptIds[2]=NWB=nodeNumbers( ix1 , ix2+1, ix3 )) >= 0 - && (ptIds[3]=NEB=nodeNumbers( ix1+1, ix2+1, ix3 )) >= 0 - && (ptIds[4]=SWT=nodeNumbers( ix1 , ix2, ix3+1 )) >= 0 - && (ptIds[5]=SET=nodeNumbers( ix1+1, ix2, ix3+1 )) >= 0 - && (ptIds[6]=NWT=nodeNumbers( ix1 , ix2+1, ix3+1 )) >= 0 - && (ptIds[7]=NET=nodeNumbers( ix1+1, ix2+1, ix3+1 )) >= 0 - ) - { - unstructuredGrid->InsertNextCell((int)VTK_VOXEL, (vtkIdType)8, ptIds); + } + } + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + vtkIdType ptIds[8]; + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((ptIds[0] = SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && + (ptIds[1] = SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (ptIds[2] = NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (ptIds[3] = NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && + (ptIds[4] = SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && + (ptIds[5] = SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (ptIds[6] = NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0 && + (ptIds[7] = NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0) { + unstructuredGrid->InsertNextCell((int)VTK_VOXEL, (vtkIdType)8, ptIds); + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -void InSituVTKCoProcessor::readConfigFile( const std::string& configFile ) +void InSituVTKCoProcessor::readConfigFile(const std::string &configFile) { - ifstream ifs; - ifs.open (configFile, ifstream::in); - if(!ifs) throw UbException(UB_EXARGS,"can not open "+configFile); - - string dummy; - int wRank = 0; - getline(ifs, dummy); - int np = Communicator::getInstance()->getNumberOfProcesses(); - - while (ifs.good()) - { - getline(ifs, dummy, ';'); - getline(ifs, wIP, ';'); - getline(ifs, wHostname, ';'); - getline(ifs, dummy); - wPort = stoi(dummy); - if(wRank == gridRank) break; - wRank++; - } - ifs.close(); + ifstream ifs; + ifs.open(configFile, ifstream::in); + if (!ifs) + throw UbException(UB_EXARGS, "can not open " + configFile); + + string dummy; + int wRank = 0; + getline(ifs, dummy); + int np = Communicator::getInstance()->getNumberOfProcesses(); + + while (ifs.good()) { + getline(ifs, dummy, ';'); + getline(ifs, wIP, ';'); + getline(ifs, wHostname, ';'); + getline(ifs, dummy); + wPort = stoi(dummy); + if (wRank == gridRank) + break; + wRank++; + } + ifs.close(); } ////////////////////////////////////////////////////////////////////////// #endif - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.h index 0b3b440c4..678950956 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/InSituVTKCoProcessor.h @@ -9,44 +9,45 @@ #include <string> -//VTK headers +// VTK headers +#include <vtkDoubleArray.h> +#include <vtkSmartPointer.h> #include <vtkSocketCommunicator.h> #include <vtkSocketController.h> -#include <vtkSmartPointer.h> #include <vtkUnstructuredGrid.h> -#include <vtkDoubleArray.h> class InSituVTKCoProcessor : public CoProcessor { public: - InSituVTKCoProcessor(); - InSituVTKCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& configFile, SPtr<LBMUnitConverter> conv); - virtual ~InSituVTKCoProcessor(); - void process(double step); + InSituVTKCoProcessor(); + InSituVTKCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &configFile, + SPtr<LBMUnitConverter> conv); + virtual ~InSituVTKCoProcessor(); + void process(double step); + protected: - void collectData(double step); - void addData(SPtr<Block3D> block); - void readConfigFile(const std::string& configFile); + void collectData(double step); + void addData(SPtr<Block3D> block); + void readConfigFile(const std::string &configFile); - //void clearData(); + // void clearData(); private: - std::string path; - SPtr<LBMUnitConverter> conv; - std::vector<std::vector<SPtr<Block3D>> > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - vtkSmartPointer<vtkSocketCommunicator> comm; - vtkSmartPointer<vtkSocketController> contr; - vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid; - vtkSmartPointer<vtkPoints> points; - vtkSmartPointer<vtkDoubleArray> arrays[5]; - int wPort; - std::string wHostname; - std::string wIP; + std::string path; + SPtr<LBMUnitConverter> conv; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + vtkSmartPointer<vtkSocketCommunicator> comm; + vtkSmartPointer<vtkSocketController> contr; + vtkSmartPointer<vtkUnstructuredGrid> unstructuredGrid; + vtkSmartPointer<vtkPoints> points; + vtkSmartPointer<vtkDoubleArray> arrays[5]; + int wPort; + std::string wHostname; + std::string wIP; }; #endif // InSituVTKCoProcessor_h__ #endif - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.cpp index 93802d6fc..76895f1be 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.cpp @@ -1,304 +1,256 @@ #include "IntegrateValuesHelper.h" - -#include <geometry3d/GbCuboid3D.h> #include <geometry3d/CoordinateTransformation3D.h> +#include <geometry3d/GbCuboid3D.h> #include <vector> -#include "LBMKernel.h" +#include "BCArray3D.h" #include "BCProcessor.h" #include "DataSet3D.h" -#include "BCArray3D.h" +#include "LBMKernel.h" ////////////////////////////////////////////////////////////////////////// -IntegrateValuesHelper::IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, - double minX1, double minX2, - double minX3, double maxX1, - double maxX2, double maxX3) : +IntegrateValuesHelper::IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, double minX1, double minX2, + double minX3, double maxX1, double maxX2, double maxX3) + : - grid(grid), - comm(comm), - sVx1(0.0), sVx2(0.0), sVx3(0.0), sRho(0.0), sCellVolume(0.0), - numberOfFluidsNodes(0), - numberOfSolidNodes(0) + grid(grid), comm(comm), sVx1(0.0), sVx2(0.0), sVx3(0.0), sRho(0.0), sCellVolume(0.0), numberOfFluidsNodes(0), + numberOfSolidNodes(0) { - boundingBox = GbCuboid3DPtr(new GbCuboid3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)); - init(-1); + boundingBox = GbCuboid3DPtr(new GbCuboid3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)); + init(-1); } ////////////////////////////////////////////////////////////////////////// -IntegrateValuesHelper::IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, - double minX1, double minX2, - double minX3, double maxX1, - double maxX2, double maxX3, - int level) : +IntegrateValuesHelper::IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, double minX1, double minX2, + double minX3, double maxX1, double maxX2, double maxX3, int level) + : - grid(grid), - comm(comm), - sVx1(0.0), sVx2(0.0), sVx3(0.0), sRho(0.0), sCellVolume(0.0), - numberOfFluidsNodes(0), - numberOfSolidNodes(0) + grid(grid), comm(comm), sVx1(0.0), sVx2(0.0), sVx3(0.0), sRho(0.0), sCellVolume(0.0), numberOfFluidsNodes(0), + numberOfSolidNodes(0) { - boundingBox = GbCuboid3DPtr(new GbCuboid3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)); - init(level); + boundingBox = GbCuboid3DPtr(new GbCuboid3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)); + init(level); } ////////////////////////////////////////////////////////////////////////// -IntegrateValuesHelper::~IntegrateValuesHelper() -= default; +IntegrateValuesHelper::~IntegrateValuesHelper() = default; ////////////////////////////////////////////////////////////////////////// void IntegrateValuesHelper::init(int level) { - root = comm->isRoot(); + root = comm->isRoot(); - double orgX1, orgX2, orgX3; - int gridRank = grid->getRank(); - int minInitLevel, maxInitLevel; - if (level < 0) - { - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); - } - else - { - minInitLevel = level; - maxInitLevel = level; - } + double orgX1, orgX2, orgX3; + int gridRank = grid->getRank(); + int minInitLevel, maxInitLevel; + if (level < 0) { + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); + } else { + minInitLevel = level; + maxInitLevel = level; + } - double numSolids = 0.0; - double numFluids = 0.0; - for (int level_it = minInitLevel; level_it <= maxInitLevel; level_it++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level_it, gridRank, blockVector); - for(SPtr<Block3D> block : blockVector) - { - CalcNodes cn; - cn.block = block; - //Koords bestimmen - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + double numSolids = 0.0; + double numFluids = 0.0; + for (int level_it = minInitLevel; level_it <= maxInitLevel; level_it++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level_it, gridRank, blockVector); + for (SPtr<Block3D> block : blockVector) { + CalcNodes cn; + cn.block = block; + // Koords bestimmen + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - orgX1 = val<1>(org); - orgX2 = val<2>(org); - orgX3 = val<3>(org); + orgX1 = val<1>(org); + orgX2 = val<2>(org); + orgX3 = val<3>(org); - SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - int ghostLayerWitdh = kernel->getGhostLayerWidth(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - double internX1, internX2, internX3; + SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + int ghostLayerWitdh = kernel->getGhostLayerWidth(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + double internX1, internX2, internX3; - double dx = grid->getDeltaX(block); - UbTupleDouble3 orgDelta = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + UbTupleDouble3 orgDelta = grid->getNodeOffset(block); - for (int ix3 = ghostLayerWitdh; ix3 < (int)distributions->getNX3() - ghostLayerWitdh; ix3++) - { - for (int ix2 = ghostLayerWitdh; ix2 < (int)distributions->getNX2() - ghostLayerWitdh; ix2++) - { - for (int ix1 = ghostLayerWitdh; ix1 < (int)distributions->getNX1() - ghostLayerWitdh; ix1++) - { - internX1 = orgX1 - val<1>(orgDelta) + ix1 * dx; - internX2 = orgX2 - val<2>(orgDelta) + ix2 * dx; - internX3 = orgX3 - val<3>(orgDelta) + ix3 * dx; - if (boundingBox->isPointInGbObject3D(internX1, internX2, internX3)) - { - if (!bcArray->isSolid(ix1, ix2, ix3) && !bcArray->isUndefined(ix1, ix2, ix3)) - { - cn.nodes.emplace_back(ix1, ix2, ix3); - numFluids++; - } - else if (bcArray->isSolid(ix1, ix2, ix3)) - { - numSolids++; - } - } - } + for (int ix3 = ghostLayerWitdh; ix3 < (int)distributions->getNX3() - ghostLayerWitdh; ix3++) { + for (int ix2 = ghostLayerWitdh; ix2 < (int)distributions->getNX2() - ghostLayerWitdh; ix2++) { + for (int ix1 = ghostLayerWitdh; ix1 < (int)distributions->getNX1() - ghostLayerWitdh; ix1++) { + internX1 = orgX1 - val<1>(orgDelta) + ix1 * dx; + internX2 = orgX2 - val<2>(orgDelta) + ix2 * dx; + internX3 = orgX3 - val<3>(orgDelta) + ix3 * dx; + if (boundingBox->isPointInGbObject3D(internX1, internX2, internX3)) { + if (!bcArray->isSolid(ix1, ix2, ix3) && !bcArray->isUndefined(ix1, ix2, ix3)) { + cn.nodes.emplace_back(ix1, ix2, ix3); + numFluids++; + } else if (bcArray->isSolid(ix1, ix2, ix3)) { + numSolids++; + } + } + } + } } - } - if (cn.nodes.size() > 0) - cnodes.push_back(cn); - } - } - std::vector<double> rvalues; - std::vector<double> values; - values.push_back(numSolids); - values.push_back(numFluids); - rvalues = comm->gather(values); - - if (root) - { - numberOfSolidNodes = 0.0; - numberOfFluidsNodes = 0.0; - int rsize = (int)rvalues.size(); - int vsize = (int)values.size(); - for (int i = 0; i < rsize; i += vsize) - { - numberOfSolidNodes += rvalues[i]; - numberOfFluidsNodes += rvalues[i + 1]; - } - } + if (cn.nodes.size() > 0) + cnodes.push_back(cn); + } + } + std::vector<double> rvalues; + std::vector<double> values; + values.push_back(numSolids); + values.push_back(numFluids); + rvalues = comm->gather(values); + if (root) { + numberOfSolidNodes = 0.0; + numberOfFluidsNodes = 0.0; + int rsize = (int)rvalues.size(); + int vsize = (int)values.size(); + for (int i = 0; i < rsize; i += vsize) { + numberOfSolidNodes += rvalues[i]; + numberOfFluidsNodes += rvalues[i + 1]; + } + } } ////////////////////////////////////////////////////////////////////////// // calculation conventional rho, velocity and averaged data void IntegrateValuesHelper::calculateAV() { - clearData(); + clearData(); - for(CalcNodes cn : cnodes) - { - SPtr<ILBMKernel> kernel = cn.block->getKernel(); - SPtr<AverageValuesArray3D> averagedValues = kernel->getDataSet()->getAverageValues(); + for (CalcNodes cn : cnodes) { + SPtr<ILBMKernel> kernel = cn.block->getKernel(); + SPtr<AverageValuesArray3D> averagedValues = kernel->getDataSet()->getAverageValues(); - for(UbTupleInt3 node : cn.nodes) - { - double Avx = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVx); - double Avy = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVy); - double Avz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVz); + for (UbTupleInt3 node : cn.nodes) { + double Avx = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVx); + double Avy = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVy); + double Avz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVz); - double Avxx = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVxx); - double Avyy = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVyy); - double Avzz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVzz); + double Avxx = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVxx); + double Avyy = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVyy); + double Avzz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVzz); - double Avxz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVxz); - sAvVx1 += abs(Avx); - sAvVx2 += abs(Avy); - sAvVx3 += abs(Avz); + double Avxz = (*averagedValues)(val<1>(node), val<2>(node), val<3>(node), AvVxz); + sAvVx1 += abs(Avx); + sAvVx2 += abs(Avy); + sAvVx3 += abs(Avz); - sTSx1 += sqrt(Avxx); - sTSx2 += sqrt(Avyy); - sTSx3 += sqrt(Avzz); + sTSx1 += sqrt(Avxx); + sTSx2 += sqrt(Avyy); + sTSx3 += sqrt(Avzz); - sTSx1x3 += Avxz; - numberOfFluidsNodes++; - } - } - std::vector<double> values; - std::vector<double> rvalues; - values.push_back(sAvVx1); - values.push_back(sAvVx2); - values.push_back(sAvVx3); - values.push_back(sTSx1); - values.push_back(sTSx2); - values.push_back(sTSx3); - values.push_back(sTSx1x3); - values.push_back(numberOfFluidsNodes); + sTSx1x3 += Avxz; + numberOfFluidsNodes++; + } + } + std::vector<double> values; + std::vector<double> rvalues; + values.push_back(sAvVx1); + values.push_back(sAvVx2); + values.push_back(sAvVx3); + values.push_back(sTSx1); + values.push_back(sTSx2); + values.push_back(sTSx3); + values.push_back(sTSx1x3); + values.push_back(numberOfFluidsNodes); - rvalues = comm->gather(values); - if (root) - { - clearData(); - for (int i = 0; i < (int)rvalues.size(); i += 8) - { - sAvVx1 += rvalues[i]; - sAvVx2 += rvalues[i + 1]; - sAvVx3 += rvalues[i + 2]; - sTSx1 += rvalues[i + 3]; - sTSx2 += rvalues[i + 4]; - sTSx3 += rvalues[i + 5]; - sTSx1x3 += rvalues[i + 6]; - numberOfFluidsNodes += rvalues[i + 7]; - } - } + rvalues = comm->gather(values); + if (root) { + clearData(); + for (int i = 0; i < (int)rvalues.size(); i += 8) { + sAvVx1 += rvalues[i]; + sAvVx2 += rvalues[i + 1]; + sAvVx3 += rvalues[i + 2]; + sTSx1 += rvalues[i + 3]; + sTSx2 += rvalues[i + 4]; + sTSx3 += rvalues[i + 5]; + sTSx1x3 += rvalues[i + 6]; + numberOfFluidsNodes += rvalues[i + 7]; + } + } } ////////////////////////////////////////////////////////////////////////// void IntegrateValuesHelper::calculateMQ() { - LBMReal f[D3Q27System::ENDF + 1]; - LBMReal vx1, vx2, vx3, rho; - clearData(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + clearData(); - //Funktionszeiger - typedef void(*CalcMacrosFct)(const LBMReal* const& /*feq[27]*/, LBMReal& /*(d)rho*/, LBMReal& /*vx1*/, LBMReal& /*vx2*/, LBMReal& /*vx3*/); + // Funktionszeiger + typedef void (*CalcMacrosFct)(const LBMReal *const & /*feq[27]*/, LBMReal & /*(d)rho*/, LBMReal & /*vx1*/, + LBMReal & /*vx2*/, LBMReal & /*vx3*/); - CalcMacrosFct calcMacros = NULL; + CalcMacrosFct calcMacros = NULL; - for(CalcNodes cn : cnodes) - { - SPtr<ILBMKernel> kernel = cn.block->getKernel(); - LBMReal dx = 1.0 / (LBMReal)(1 << cn.block->getLevel()); - LBMReal cellVolume = dx*dx*dx; + for (CalcNodes cn : cnodes) { + SPtr<ILBMKernel> kernel = cn.block->getKernel(); + LBMReal dx = 1.0 / (LBMReal)(1 << cn.block->getLevel()); + LBMReal cellVolume = dx * dx * dx; - if (kernel->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } + if (kernel->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - for(UbTupleInt3 node : cn.nodes) - { - distributions->getDistribution(f, val<1>(node), val<2>(node), val<3>(node)); - calcMacros(f, rho, vx1, vx2, vx3); - sRho += rho*cellVolume; - sVx1 += vx1*cellVolume; - sVx2 += vx2*cellVolume; - sVx3 += vx3*cellVolume; - sCellVolume += cellVolume; - } - } - std::vector<double> values(5); - std::vector<double> rvalues; - values[0] = sRho; - values[1] = sVx1; - values[2] = sVx2; - values[3] = sVx3; - values[4] = sCellVolume; + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + for (UbTupleInt3 node : cn.nodes) { + distributions->getDistribution(f, val<1>(node), val<2>(node), val<3>(node)); + calcMacros(f, rho, vx1, vx2, vx3); + sRho += rho * cellVolume; + sVx1 += vx1 * cellVolume; + sVx2 += vx2 * cellVolume; + sVx3 += vx3 * cellVolume; + sCellVolume += cellVolume; + } + } + std::vector<double> values(5); + std::vector<double> rvalues; + values[0] = sRho; + values[1] = sVx1; + values[2] = sVx2; + values[3] = sVx3; + values[4] = sCellVolume; - rvalues = comm->gather(values); - if (root) - { - clearData(); - int rsize = (int)rvalues.size(); - int vsize = (int)values.size(); - for (int i = 0; i < rsize; i += vsize) - { - sRho += rvalues[i]; - sVx1 += rvalues[i + 1]; - sVx2 += rvalues[i + 2]; - sVx3 += rvalues[i + 3]; - sCellVolume += rvalues[i + 4]; - } - } + rvalues = comm->gather(values); + if (root) { + clearData(); + int rsize = (int)rvalues.size(); + int vsize = (int)values.size(); + for (int i = 0; i < rsize; i += vsize) { + sRho += rvalues[i]; + sVx1 += rvalues[i + 1]; + sVx2 += rvalues[i + 2]; + sVx3 += rvalues[i + 3]; + sCellVolume += rvalues[i + 4]; + } + } } ////////////////////////////////////////////////////////////////////////// void IntegrateValuesHelper::clearData() { - sRho = 0.0; - sVx1 = 0.0; - sVx2 = 0.0; - sVx3 = 0.0; - sCellVolume = 0.0; - //sVm = 0.0; - //sPress = 0.0; - //numberOfFluidsNodes = 0.0; - sAvVx1 = 0.0; - sAvVx2 = 0.0; - sAvVx3 = 0.0; - sTSx1 = 0.0; - sTSx2 = 0.0; - sTSx3 = 0.0; - sTSx1x3 = 0.0; + sRho = 0.0; + sVx1 = 0.0; + sVx2 = 0.0; + sVx3 = 0.0; + sCellVolume = 0.0; + // sVm = 0.0; + // sPress = 0.0; + // numberOfFluidsNodes = 0.0; + sAvVx1 = 0.0; + sAvVx2 = 0.0; + sAvVx3 = 0.0; + sTSx1 = 0.0; + sTSx2 = 0.0; + sTSx3 = 0.0; + sTSx1x3 = 0.0; } ////////////////////////////////////////////////////////////////////////// -LBMReal IntegrateValuesHelper::getNumberOfFluidsNodes() -{ - return this->numberOfFluidsNodes; -} +LBMReal IntegrateValuesHelper::getNumberOfFluidsNodes() { return this->numberOfFluidsNodes; } ////////////////////////////////////////////////////////////////////////// -LBMReal IntegrateValuesHelper::getNumberOfSolidNodes() -{ - return this->numberOfSolidNodes; -} +LBMReal IntegrateValuesHelper::getNumberOfSolidNodes() { return this->numberOfSolidNodes; } ////////////////////////////////////////////////////////////////////////// -GbCuboid3DPtr IntegrateValuesHelper::getBoundingBox() -{ - return this->boundingBox; -} +GbCuboid3DPtr IntegrateValuesHelper::getBoundingBox() { return this->boundingBox; } ////////////////////////////////////////////////////////////////////////// -std::vector<IntegrateValuesHelper::CalcNodes> IntegrateValuesHelper::getCNodes() -{ - return cnodes; -} +std::vector<IntegrateValuesHelper::CalcNodes> IntegrateValuesHelper::getCNodes() { return cnodes; } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.h b/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.h index 457d24ef5..f5d846f98 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/IntegrateValuesHelper.h @@ -3,87 +3,83 @@ #include <PointerDefinitions.h> -#include "Grid3D.h" -#include "D3Q27System.h" +#include "Block3D.h" +#include "CbArray2D.h" #include "Communicator.h" +#include "D3Q27System.h" #include "GbCuboid3D.h" -#include "CbArray2D.h" -#include "Block3D.h" +#include "Grid3D.h" -//struct CalcNodes +// struct CalcNodes //{ // SPtr<Block3D> block; // std::vector<UbTupleInt3> nodes; //}; // -//struct Nodes +// struct Nodes //{ // SPtr<Block3D> block; // UbTupleInt3 nodes; //}; - class IntegrateValuesHelper { public: - struct CalcNodes - { - SPtr<Block3D> block; - std::vector<UbTupleInt3> nodes; - }; + struct CalcNodes { + SPtr<Block3D> block; + std::vector<UbTupleInt3> nodes; + }; + + struct Node { + SPtr<Block3D> block; + UbTupleInt3 node; + }; - struct Node - { - SPtr<Block3D> block; - UbTupleInt3 node; - }; public: - IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, - double minX1, double minX2, double minX3, - double maxX1, double maxX2, double maxX3); - IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, - double minX1, double minX2, double minX3, - double maxX1, double maxX2, double maxX3, int level); - virtual ~IntegrateValuesHelper(); + IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, double minX1, double minX2, double minX3, + double maxX1, double maxX2, double maxX3); + IntegrateValuesHelper(SPtr<Grid3D> grid, SPtr<Communicator> comm, double minX1, double minX2, double minX3, + double maxX1, double maxX2, double maxX3, int level); + virtual ~IntegrateValuesHelper(); - void calculateMQ(); - void calculateAV(); - void clearData(); + void calculateMQ(); + void calculateAV(); + void clearData(); - double getRho() {return sRho;} - double getVx1() {return sVx1;} - double getVx2() {return sVx2;} - double getVx3() {return sVx3;} - double getCellsVolume() { return sCellVolume; } - // LBMReal getVm() { return sVm; } - //LBMReal getPress() {return sPress;} - double getAvVx1(){return sAvVx1;} - double getAvVx2(){return sAvVx2;} - double getAvVx3(){return sAvVx3;} - double getTSx1(){return sTSx1;} - double getTSx2(){return sTSx2;} - double getTSx3(){return sTSx3;} - double getTSx1x3(){return sTSx1x3;} + double getRho() { return sRho; } + double getVx1() { return sVx1; } + double getVx2() { return sVx2; } + double getVx3() { return sVx3; } + double getCellsVolume() { return sCellVolume; } + // LBMReal getVm() { return sVm; } + // LBMReal getPress() {return sPress;} + double getAvVx1() { return sAvVx1; } + double getAvVx2() { return sAvVx2; } + double getAvVx3() { return sAvVx3; } + double getTSx1() { return sTSx1; } + double getTSx2() { return sTSx2; } + double getTSx3() { return sTSx3; } + double getTSx1x3() { return sTSx1x3; } - LBMReal getNumberOfFluidsNodes(); - LBMReal getNumberOfSolidNodes(); - GbCuboid3DPtr getBoundingBox(); - std::vector<CalcNodes> getCNodes(); + LBMReal getNumberOfFluidsNodes(); + LBMReal getNumberOfSolidNodes(); + GbCuboid3DPtr getBoundingBox(); + std::vector<CalcNodes> getCNodes(); protected: private: - void init(int level); + void init(int level); - bool root; - SPtr<Grid3D> grid; - double sVx1, sVx2, sVx3, sRho, sCellVolume;// sPress, sVm; - double numberOfFluidsNodes, numberOfSolidNodes; - double sAvVx1, sAvVx2, sAvVx3, sTSx1, sTSx2, sTSx3, sTSx1x3; - std::vector<CalcNodes> cnodes; - GbCuboid3DPtr boundingBox; - SPtr<Communicator> comm; - CbArray2D<Node> cnodes2DMatrix; - enum Values{AvVx = 0, AvVy = 1, AvVz = 2, AvVxx = 3, AvVyy = 4, AvVzz = 5, AvVxy = 6, AvVyz = 7, AvVxz = 8}; + bool root; + SPtr<Grid3D> grid; + double sVx1, sVx2, sVx3, sRho, sCellVolume; // sPress, sVm; + double numberOfFluidsNodes, numberOfSolidNodes; + double sAvVx1, sAvVx2, sAvVx3, sTSx1, sTSx2, sTSx3, sTSx1x3; + std::vector<CalcNodes> cnodes; + GbCuboid3DPtr boundingBox; + SPtr<Communicator> comm; + CbArray2D<Node> cnodes2DMatrix; + enum Values { AvVx = 0, AvVy = 1, AvVz = 2, AvVxx = 3, AvVyy = 4, AvVzz = 5, AvVxy = 6, AvVyz = 7, AvVxz = 8 }; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.cpp index 559303616..fe04f4f9c 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.cpp @@ -2,246 +2,203 @@ #include "BCProcessor.h" #include "WbWriterVtkXmlASCII.h" -#include "DataSet3D.h" -#include "LBMKernel.h" -#include "CoordinateTransformation3D.h" #include "Block3D.h" -#include "GbLine3D.h" -#include "UbScheduler.h" -#include "Grid3D.h" #include "Communicator.h" #include "CompressibleCumulantLBMKernel.h" +#include "CoordinateTransformation3D.h" +#include "DataSet3D.h" +#include "GbLine3D.h" +#include "Grid3D.h" +#include "LBMKernel.h" +#include "UbScheduler.h" -LineTimeSeriesCoProcessor::LineTimeSeriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<GbLine3D> line, int level, SPtr<Communicator> comm) : - CoProcessor(grid, s), - path(path), - length(0), - ix1(0), - ix2(0), - ix3(0), - level(level), - line(line) +LineTimeSeriesCoProcessor::LineTimeSeriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<GbLine3D> line, int level, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), length(0), ix1(0), ix2(0), ix3(0), level(level), line(line) { - root = comm->isRoot(); - fname = path; - - mpi_comm = *((MPI_Comm*)comm->getNativeCommunicator()); - numOfProc = comm->getNumberOfProcesses(); - gridRank = comm->getProcessID(); - - double dx = CoProcessor::grid->getDeltaX(level); - - SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); - double orgX1 = trafo->getX1CoordinateOffset(); - double orgX2 = trafo->getX2CoordinateOffset(); - double orgX3 = trafo->getX3CoordinateOffset(); - - - int x1min = (int)((line->getX1Minimum()-orgX1)/dx); - int x1max = (int)((line->getX1Maximum()-orgX1)/dx); - int x2min = (int)((line->getX2Minimum()-orgX2)/dx); - int x2max = (int)((line->getX2Maximum()-orgX2)/dx); - int x3min = (int)((line->getX3Minimum()-orgX3)/dx); - int x3max = (int)((line->getX3Maximum()-orgX3)/dx); - - UbTupleInt3 blockNx = grid->getBlockNX(); - - if (x1min!=x1max) - { - dir = X1; - blocknx = val<1>(blockNx); - length = x1max; - } - else if (x2min!=x2max) - { - dir = X2; - blocknx = val<2>(blockNx); - length = x2max; - } - else if (x3min!=x3max) - { - dir = X3; - blocknx = val<3>(blockNx); - length = x3max; - } - blockix1 = x1min/val<1>(blockNx); - blockix2 = x2min/val<2>(blockNx); - blockix3 = x3min/val<3>(blockNx); - - ix1 = x1min%val<1>(blockNx)+1; - ix2 = x2min%val<2>(blockNx)+1; - ix3 = x3min%val<3>(blockNx)+1; + root = comm->isRoot(); + fname = path; + + mpi_comm = *((MPI_Comm *)comm->getNativeCommunicator()); + numOfProc = comm->getNumberOfProcesses(); + gridRank = comm->getProcessID(); + + double dx = CoProcessor::grid->getDeltaX(level); + + SPtr<CoordinateTransformation3D> trafo = grid->getCoordinateTransformator(); + double orgX1 = trafo->getX1CoordinateOffset(); + double orgX2 = trafo->getX2CoordinateOffset(); + double orgX3 = trafo->getX3CoordinateOffset(); + + int x1min = (int)((line->getX1Minimum() - orgX1) / dx); + int x1max = (int)((line->getX1Maximum() - orgX1) / dx); + int x2min = (int)((line->getX2Minimum() - orgX2) / dx); + int x2max = (int)((line->getX2Maximum() - orgX2) / dx); + int x3min = (int)((line->getX3Minimum() - orgX3) / dx); + int x3max = (int)((line->getX3Maximum() - orgX3) / dx); + + UbTupleInt3 blockNx = grid->getBlockNX(); + + if (x1min != x1max) { + dir = X1; + blocknx = val<1>(blockNx); + length = x1max; + } else if (x2min != x2max) { + dir = X2; + blocknx = val<2>(blockNx); + length = x2max; + } else if (x3min != x3max) { + dir = X3; + blocknx = val<3>(blockNx); + length = x3max; + } + blockix1 = x1min / val<1>(blockNx); + blockix2 = x2min / val<2>(blockNx); + blockix3 = x3min / val<3>(blockNx); + + ix1 = x1min % val<1>(blockNx) + 1; + ix2 = x2min % val<2>(blockNx) + 1; + ix3 = x3min % val<3>(blockNx) + 1; } ////////////////////////////////////////////////////////////////////////// void LineTimeSeriesCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - collectData(); - } + if (scheduler->isDue(step)) { + collectData(); + } - UBLOG(logDEBUG3, "MacroscopicQuantitiesCoProcessor::update:"<<step); + UBLOG(logDEBUG3, "MacroscopicQuantitiesCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// -void LineTimeSeriesCoProcessor::writeLine(const std::string& path) +void LineTimeSeriesCoProcessor::writeLine(const std::string &path) { - std::vector<UbTupleFloat3 > nodes(2); - std::vector<UbTupleInt2 > lines(1); - val<1>(nodes[0]) = (float)line->getX1Minimum(); - val<2>(nodes[0]) = (float)line->getX2Minimum(); - val<3>(nodes[0]) = (float)line->getX3Minimum(); - val<1>(nodes[1]) = (float)line->getX1Maximum(); - val<2>(nodes[1]) = (float)line->getX2Maximum(); - val<3>(nodes[1]) = (float)line->getX3Maximum(); - val<1>(lines[0]) = 0; - val<1>(lines[0]) = 1; - WbWriterVtkXmlASCII *writer = WbWriterVtkXmlASCII::getInstance(); - writer->writeLines(path, nodes, lines); + std::vector<UbTupleFloat3> nodes(2); + std::vector<UbTupleInt2> lines(1); + val<1>(nodes[0]) = (float)line->getX1Minimum(); + val<2>(nodes[0]) = (float)line->getX2Minimum(); + val<3>(nodes[0]) = (float)line->getX3Minimum(); + val<1>(nodes[1]) = (float)line->getX1Maximum(); + val<2>(nodes[1]) = (float)line->getX2Maximum(); + val<3>(nodes[1]) = (float)line->getX3Maximum(); + val<1>(lines[0]) = 0; + val<1>(lines[0]) = 1; + WbWriterVtkXmlASCII *writer = WbWriterVtkXmlASCII::getInstance(); + writer->writeLines(path, nodes, lines); } ////////////////////////////////////////////////////////////////////////// void LineTimeSeriesCoProcessor::collectData() { - LBMReal f[27]; - LBMReal vx1, vx2, vx3, rho; - MPI_Status status; - std::vector<double> v1(length, 0); - std::vector<double> v2(length, 0); - std::vector<double> v3(length, 0); - std::vector<double> p(length, 0); - for (int x = 0; x<length; x += blocknx) - { - if (dir == X1) - { - blockix1 = x/blocknx; - } - else if (dir == X2) - { - blockix2 = x/blocknx; - } - else if (dir == X3) - { - blockix3 = x/blocknx; - } - - SPtr<Block3D> block = CoProcessor::grid->getBlock(blockix1, blockix2, blockix3, level); - if (block) - { - if (block->getRank()==gridRank) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - calcMacros = NULL; - if (kernel->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; + LBMReal f[27]; + LBMReal vx1, vx2, vx3, rho; + MPI_Status status; + std::vector<double> v1(length, 0); + std::vector<double> v2(length, 0); + std::vector<double> v3(length, 0); + std::vector<double> p(length, 0); + for (int x = 0; x < length; x += blocknx) { + if (dir == X1) { + blockix1 = x / blocknx; + } else if (dir == X2) { + blockix2 = x / blocknx; + } else if (dir == X3) { + blockix3 = x / blocknx; + } + + SPtr<Block3D> block = CoProcessor::grid->getBlock(blockix1, blockix2, blockix3, level); + if (block) { + if (block->getRank() == gridRank) { + SPtr<ILBMKernel> kernel = block->getKernel(); + calcMacros = NULL; + if (kernel->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + + for (int ix = 1; ix <= blocknx; ix++) { + if (dir == X1) { + ix1 = ix; + } else if (dir == X2) { + ix2 = ix; + } else if (dir == X3) { + ix3 = ix; + } + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + v1[x + (ix - 1)] = vx1; + v2[x + (ix - 1)] = vx2; + v3[x + (ix - 1)] = vx3; + p[x + (ix - 1)] = rho; + } } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + } + + if (root) { + for (int i = 1; i < numOfProc; i++) { + std::vector<double> v1temp(length, 0); + std::vector<double> v2temp(length, 0); + std::vector<double> v3temp(length, 0); + std::vector<double> ptemp(length, 0); + MPI_Recv(&v1temp[0], length, MPI_DOUBLE, i, 1, mpi_comm, &status); + MPI_Recv(&v2temp[0], length, MPI_DOUBLE, i, 2, mpi_comm, &status); + MPI_Recv(&v3temp[0], length, MPI_DOUBLE, i, 3, mpi_comm, &status); + MPI_Recv(&ptemp[0], length, MPI_DOUBLE, i, 4, mpi_comm, &status); + for (int j = 0; j < length; j++) { + v1[j] += v1temp[j]; + v2[j] += v2temp[j]; + v3[j] += v3temp[j]; + p[j] += ptemp[j]; } - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - - for (int ix = 1; ix<=blocknx; ix++) - { - if (dir==X1) - { - ix1 = ix; - } - else if (dir==X2) - { - ix2 = ix; - } - else if (dir==X3) - { - ix3 = ix; - } - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f, rho, vx1, vx2, vx3); - v1[x+(ix-1)] = vx1; - v2[x+(ix-1)] = vx2; - v3[x+(ix-1)] = vx3; - p[x+(ix-1)] = rho; + } + + std::ofstream ostr; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - } - } - - } - - if (root) - { - for (int i = 1; i<numOfProc; i++) - { - std::vector<double> v1temp(length, 0); - std::vector<double> v2temp(length, 0); - std::vector<double> v3temp(length, 0); - std::vector<double> ptemp(length, 0); - MPI_Recv(&v1temp[0], length, MPI_DOUBLE, i, 1, mpi_comm, &status); - MPI_Recv(&v2temp[0], length, MPI_DOUBLE, i, 2, mpi_comm, &status); - MPI_Recv(&v3temp[0], length, MPI_DOUBLE, i, 3, mpi_comm, &status); - MPI_Recv( &ptemp[0], length, MPI_DOUBLE, i, 4, mpi_comm, &status); - for (int j = 0; j<length; j++) - { - v1[j] += v1temp[j]; - v2[j] += v2temp[j]; - v3[j] += v3temp[j]; - p[j] += ptemp[j]; - } - } - - std::ofstream ostr; - ostr.open(fname.c_str(), std::ios_base::out|std::ios_base::app); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size()>0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out|std::ios_base::app); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file "+fname); - } - - for (int x = 0; x<length; x++) - { - ostr<<v1[x]; - if (x<length-1) - { - ostr<<";"; - } - } - ostr<<"\n"; - for (int x = 0; x<length; x++) - { - ostr<<v2[x]; - if (x<length-1) - { - ostr<<";"; - } - } - ostr<<"\n"; - for (int x = 0; x<length; x++) - { - ostr<<v3[x]; - if (x<length-1) - { - ostr<<";"; - } - } - ostr<<"\n"; - for (int x = 0; x<length; x++) - { - ostr<<p[x]; - if (x<length-1) - { - ostr<<";"; - } - } - ostr<<"\n"; - ostr.close(); - } - else - { - MPI_Send(&v1[0], length, MPI_DOUBLE, 0, 1, mpi_comm); - MPI_Send(&v2[0], length, MPI_DOUBLE, 0, 2, mpi_comm); - MPI_Send(&v3[0], length, MPI_DOUBLE, 0, 3, mpi_comm); - MPI_Send( &p[0], length, MPI_DOUBLE, 0, 4, mpi_comm); - } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + + for (int x = 0; x < length; x++) { + ostr << v1[x]; + if (x < length - 1) { + ostr << ";"; + } + } + ostr << "\n"; + for (int x = 0; x < length; x++) { + ostr << v2[x]; + if (x < length - 1) { + ostr << ";"; + } + } + ostr << "\n"; + for (int x = 0; x < length; x++) { + ostr << v3[x]; + if (x < length - 1) { + ostr << ";"; + } + } + ostr << "\n"; + for (int x = 0; x < length; x++) { + ostr << p[x]; + if (x < length - 1) { + ostr << ";"; + } + } + ostr << "\n"; + ostr.close(); + } else { + MPI_Send(&v1[0], length, MPI_DOUBLE, 0, 1, mpi_comm); + MPI_Send(&v2[0], length, MPI_DOUBLE, 0, 2, mpi_comm); + MPI_Send(&v3[0], length, MPI_DOUBLE, 0, 3, mpi_comm); + MPI_Send(&p[0], length, MPI_DOUBLE, 0, 4, mpi_comm); + } } - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.h index ba8ec0ecf..76f933c05 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/LineTimeSeriesCoProcessor.h @@ -17,42 +17,45 @@ class GbLine3D; //! \brief Writes to .csv file time series for a line in x1 direction. //! \details It can be used to compute for given time range the time averaged two-point correlations for a line. <br> //! \f$ R_{ij}(x_{a},x{b},t) = <u_{i}(x_{a},t)u_{j}(x_{a}+r,t)> \f$ <br> -// -//! \author Konstantin Kutscher +// +//! \author Konstantin Kutscher class LineTimeSeriesCoProcessor : public CoProcessor { public: -enum Direction {X1, X2, X3}; + enum Direction { X1, X2, X3 }; + public: - LineTimeSeriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<GbLine3D> line, int level,SPtr<Communicator> comm); - ~LineTimeSeriesCoProcessor() override= default; + LineTimeSeriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<GbLine3D> line, + int level, SPtr<Communicator> comm); + ~LineTimeSeriesCoProcessor() override = default; - void process(double step) override; - void writeLine(const std::string& path); + void process(double step) override; + void writeLine(const std::string &path); protected: - void collectData(); + void collectData(); + private: - std::string path; - std::string fname; - bool root; - SPtr<GbLine3D> line; - //function pointer - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; - int blocknx; - int blockix1; - int blockix2; - int blockix3; - int level; - int ix1; - int ix2; - int ix3; - int length; - MPI_Comm mpi_comm; - int numOfProc; - int gridRank; - Direction dir; + std::string path; + std::string fname; + bool root; + SPtr<GbLine3D> line; + // function pointer + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; + int blocknx; + int blockix1; + int blockix2; + int blockix3; + int level; + int ix1; + int ix2; + int ix3; + int length; + MPI_Comm mpi_comm; + int numOfProc; + int gridRank; + Direction dir; }; #endif // LineTimeSeriesCoProcessor_h__ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.cpp index 2c032d6dc..74c8e22b7 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.cpp @@ -1,461 +1,471 @@ #include "MPIIOCoProcessor.h" #include "Block3D.h" +#include "Communicator.h" #include "CoordinateTransformation3D.h" #include "Grid3D.h" -#include "Communicator.h" -#include "UbScheduler.h" #include "MPIIODataStructures.h" -#include "UbLogger.h" #include "MemoryUtil.h" -#include "UbFileOutputASCII.h" #include "UbFileInputASCII.h" +#include "UbFileOutputASCII.h" +#include "UbLogger.h" +#include "UbScheduler.h" using namespace MPIIODataStructures; -MPIIOCoProcessor::MPIIOCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm) : - CoProcessor(grid, s), - path(path), - comm(comm) +MPIIOCoProcessor::MPIIOCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), comm(comm) { - UbSystem::makeDirectory(path + "/mpi_io_cp"); - - //------------------------- define MPI types --------------------------------- + UbSystem::makeDirectory(path + "/mpi_io_cp"); - MPI_Datatype typesGP[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksGP[3] = { 34, 6, 5 }; - MPI_Aint offsetsGP[3], lbGP, extentGP; + //------------------------- define MPI types --------------------------------- - offsetsGP[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbGP, &extentGP); - offsetsGP[1] = blocksGP[0] * extentGP; + MPI_Datatype typesGP[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksGP[3] = { 34, 6, 5 }; + MPI_Aint offsetsGP[3], lbGP, extentGP; - MPI_Type_get_extent(MPI_INT, &lbGP, &extentGP); - offsetsGP[2] = offsetsGP[1] + blocksGP[1] * extentGP; + offsetsGP[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbGP, &extentGP); + offsetsGP[1] = blocksGP[0] * extentGP; - MPI_Type_create_struct(3, blocksGP, offsetsGP, typesGP, &gridParamType); - MPI_Type_commit(&gridParamType); + MPI_Type_get_extent(MPI_INT, &lbGP, &extentGP); + offsetsGP[2] = offsetsGP[1] + blocksGP[1] * extentGP; - //----------------------------------------------------------------------- + MPI_Type_create_struct(3, blocksGP, offsetsGP, typesGP, &gridParamType); + MPI_Type_commit(&gridParamType); - MPI_Datatype typesBlock[2] = { MPI_INT, MPI_CHAR }; - int blocksBlock[2] = { 13, 1 }; - MPI_Aint offsetsBlock[2], lbBlock, extentBlock; + //----------------------------------------------------------------------- - offsetsBlock[0] = 0; - MPI_Type_get_extent(MPI_INT, &lbBlock, &extentBlock); - offsetsBlock[1] = blocksBlock[0] * extentBlock; + MPI_Datatype typesBlock[2] = { MPI_INT, MPI_CHAR }; + int blocksBlock[2] = { 13, 1 }; + MPI_Aint offsetsBlock[2], lbBlock, extentBlock; - MPI_Type_create_struct(2, blocksBlock, offsetsBlock, typesBlock, &block3dType); - MPI_Type_commit(&block3dType); + offsetsBlock[0] = 0; + MPI_Type_get_extent(MPI_INT, &lbBlock, &extentBlock); + offsetsBlock[1] = blocksBlock[0] * extentBlock; - //--------------------------------------- + MPI_Type_create_struct(2, blocksBlock, offsetsBlock, typesBlock, &block3dType); + MPI_Type_commit(&block3dType); - MPI_Type_contiguous(7, MPI_INT, &dataSetParamType); - MPI_Type_commit(&dataSetParamType); + //--------------------------------------- - //----------------------------------------------------------------------- + MPI_Type_contiguous(7, MPI_INT, &dataSetParamType); + MPI_Type_commit(&dataSetParamType); - MPI_Datatype typesBC[3] = { MPI_LONG_LONG_INT, MPI_FLOAT, MPI_CHAR }; - int blocksBC[3] = { 5, 38, 1 }; - MPI_Aint offsetsBC[3], lbBC, extentBC; + //----------------------------------------------------------------------- - offsetsBC[0] = 0; - MPI_Type_get_extent(MPI_LONG_LONG_INT, &lbBC, &extentBC); - offsetsBC[1] = blocksBC[0] * extentBC; + MPI_Datatype typesBC[3] = { MPI_LONG_LONG_INT, MPI_FLOAT, MPI_CHAR }; + int blocksBC[3] = { 5, 38, 1 }; + MPI_Aint offsetsBC[3], lbBC, extentBC; - MPI_Type_get_extent(MPI_FLOAT, &lbBC, &extentBC); - offsetsBC[2] = offsetsBC[1] + blocksBC[1] * extentBC; + offsetsBC[0] = 0; + MPI_Type_get_extent(MPI_LONG_LONG_INT, &lbBC, &extentBC); + offsetsBC[1] = blocksBC[0] * extentBC; - MPI_Type_create_struct(3, blocksBC, offsetsBC, typesBC, &boundCondType); - MPI_Type_commit(&boundCondType); + MPI_Type_get_extent(MPI_FLOAT, &lbBC, &extentBC); + offsetsBC[2] = offsetsBC[1] + blocksBC[1] * extentBC; - //--------------------------------------- + MPI_Type_create_struct(3, blocksBC, offsetsBC, typesBC, &boundCondType); + MPI_Type_commit(&boundCondType); - MPI_Type_contiguous(6, MPI_CHAR, &arrayPresenceType); - MPI_Type_commit(&arrayPresenceType); + //--------------------------------------- + MPI_Type_contiguous(6, MPI_CHAR, &arrayPresenceType); + MPI_Type_commit(&arrayPresenceType); } MPIIOCoProcessor::~MPIIOCoProcessor() { - MPI_Type_free(&gridParamType); - MPI_Type_free(&block3dType); - MPI_Type_free(&dataSetParamType); - MPI_Type_free(&boundCondType); - MPI_Type_free(&arrayPresenceType); + MPI_Type_free(&gridParamType); + MPI_Type_free(&block3dType); + MPI_Type_free(&dataSetParamType); + MPI_Type_free(&boundCondType); + MPI_Type_free(&arrayPresenceType); } void MPIIOCoProcessor::writeBlocks(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - //MPI_Comm_size(MPI_COMM_WORLD, &size); - size = 1; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - int blocksCount = 0; // quantity of all the blocks in the grid, max 2147483648 blocks! - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - - std::vector<SPtr<Block3D>> blocksVector[25]; // max 25 levels - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - //grid->getBlocks(level, rank, blockVector[level]); - grid->getBlocks(level, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - GridParam* gridParameters = new GridParam; - gridParameters->trafoParams[0] = grid->getCoordinateTransformator()->Tx1; - gridParameters->trafoParams[1] = grid->getCoordinateTransformator()->Tx2; - gridParameters->trafoParams[2] = grid->getCoordinateTransformator()->Tx3; - gridParameters->trafoParams[3] = grid->getCoordinateTransformator()->Sx1; - gridParameters->trafoParams[4] = grid->getCoordinateTransformator()->Sx2; - gridParameters->trafoParams[5] = grid->getCoordinateTransformator()->Sx3; - gridParameters->trafoParams[6] = grid->getCoordinateTransformator()->alpha; - gridParameters->trafoParams[7] = grid->getCoordinateTransformator()->beta; - gridParameters->trafoParams[8] = grid->getCoordinateTransformator()->gamma; - - gridParameters->trafoParams[9] = grid->getCoordinateTransformator()->toX1factorX1; - gridParameters->trafoParams[10] = grid->getCoordinateTransformator()->toX1factorX2; - gridParameters->trafoParams[11] = grid->getCoordinateTransformator()->toX1factorX3; - gridParameters->trafoParams[12] = grid->getCoordinateTransformator()->toX1delta; - gridParameters->trafoParams[13] = grid->getCoordinateTransformator()->toX2factorX1; - gridParameters->trafoParams[14] = grid->getCoordinateTransformator()->toX2factorX2; - gridParameters->trafoParams[15] = grid->getCoordinateTransformator()->toX2factorX3; - gridParameters->trafoParams[16] = grid->getCoordinateTransformator()->toX2delta; - gridParameters->trafoParams[17] = grid->getCoordinateTransformator()->toX3factorX1; - gridParameters->trafoParams[18] = grid->getCoordinateTransformator()->toX3factorX2; - gridParameters->trafoParams[19] = grid->getCoordinateTransformator()->toX3factorX3; - gridParameters->trafoParams[20] = grid->getCoordinateTransformator()->toX3delta; - - gridParameters->trafoParams[21] = grid->getCoordinateTransformator()->fromX1factorX1; - gridParameters->trafoParams[22] = grid->getCoordinateTransformator()->fromX1factorX2; - gridParameters->trafoParams[23] = grid->getCoordinateTransformator()->fromX1factorX3; - gridParameters->trafoParams[24] = grid->getCoordinateTransformator()->fromX1delta; - gridParameters->trafoParams[25] = grid->getCoordinateTransformator()->fromX2factorX1; - gridParameters->trafoParams[26] = grid->getCoordinateTransformator()->fromX2factorX2; - gridParameters->trafoParams[27] = grid->getCoordinateTransformator()->fromX2factorX3; - gridParameters->trafoParams[28] = grid->getCoordinateTransformator()->fromX2delta; - gridParameters->trafoParams[29] = grid->getCoordinateTransformator()->fromX3factorX1; - gridParameters->trafoParams[30] = grid->getCoordinateTransformator()->fromX3factorX2; - gridParameters->trafoParams[31] = grid->getCoordinateTransformator()->fromX3factorX3; - gridParameters->trafoParams[32] = grid->getCoordinateTransformator()->fromX3delta; - - gridParameters->active = grid->getCoordinateTransformator()->active; - gridParameters->transformation = grid->getCoordinateTransformator()->transformation; - - gridParameters->deltaX = grid->getDeltaX(minInitLevel); - UbTupleInt3 blocknx = grid->getBlockNX(); - gridParameters->blockNx1 = val<1>(blocknx); - gridParameters->blockNx2 = val<2>(blocknx); - gridParameters->blockNx3 = val<3>(blocknx); - gridParameters->nx1 = grid->getNX1(); - gridParameters->nx2 = grid->getNX2(); - gridParameters->nx3 = grid->getNX3(); - gridParameters->periodicX1 = grid->isPeriodicX1(); - gridParameters->periodicX2 = grid->isPeriodicX2(); - gridParameters->periodicX3 = grid->isPeriodicX3(); - - //---------------------------------------------------------------------- - - Block3d* block3dArray = new Block3d[blocksCount]; - int ic = 0; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level - { - // save data describing the block - block3dArray[ic].x1 = block->getX1(); - block3dArray[ic].x2 = block->getX2(); - block3dArray[ic].x3 = block->getX3(); - block3dArray[ic].bundle = block->getBundle(); - block3dArray[ic].rank = block->getRank(); - block3dArray[ic].lrank = block->getLocalRank(); - block3dArray[ic].part = block->getPart(); - block3dArray[ic].globalID = block->getGlobalID(); - block3dArray[ic].localID = block->getLocalID(); - block3dArray[ic].level = block->getLevel(); - block3dArray[ic].interpolationFlagCF = block->getCollectionOfInterpolationFlagCF(); - block3dArray[ic].interpolationFlagFC = block->getCollectionOfInterpolationFlagFC(); - block3dArray[ic].counter = block->getMaxGlobalID(); - block3dArray[ic].active = block->isActive(); - - ic++; - } - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - MPI_File file_handler; -// MPI_Info info = MPI_INFO_NULL; - - UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - double start, finish; - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - - if (comm->isRoot()) - { - start = MPI_Wtime(); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, 0/*rank*sizeof(int)*/, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes parameters of the grid - MPI_File_write_at(file_handler, write_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); - // each process writes it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, block3dType, MPI_STATUS_IGNORE); - //MPI_File_sync(file_handler); - } - MPI_File_close(&file_handler); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks time: " << finish - start << " s"); - } - - delete[] block3dArray; - delete gridParameters; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + // MPI_Comm_size(MPI_COMM_WORLD, &size); + size = 1; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + int blocksCount = 0; // quantity of all the blocks in the grid, max 2147483648 blocks! + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + + std::vector<SPtr<Block3D>> blocksVector[25]; // max 25 levels + for (int level = minInitLevel; level <= maxInitLevel; level++) { + // grid->getBlocks(level, rank, blockVector[level]); + grid->getBlocks(level, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + GridParam *gridParameters = new GridParam; + gridParameters->trafoParams[0] = grid->getCoordinateTransformator()->Tx1; + gridParameters->trafoParams[1] = grid->getCoordinateTransformator()->Tx2; + gridParameters->trafoParams[2] = grid->getCoordinateTransformator()->Tx3; + gridParameters->trafoParams[3] = grid->getCoordinateTransformator()->Sx1; + gridParameters->trafoParams[4] = grid->getCoordinateTransformator()->Sx2; + gridParameters->trafoParams[5] = grid->getCoordinateTransformator()->Sx3; + gridParameters->trafoParams[6] = grid->getCoordinateTransformator()->alpha; + gridParameters->trafoParams[7] = grid->getCoordinateTransformator()->beta; + gridParameters->trafoParams[8] = grid->getCoordinateTransformator()->gamma; + + gridParameters->trafoParams[9] = grid->getCoordinateTransformator()->toX1factorX1; + gridParameters->trafoParams[10] = grid->getCoordinateTransformator()->toX1factorX2; + gridParameters->trafoParams[11] = grid->getCoordinateTransformator()->toX1factorX3; + gridParameters->trafoParams[12] = grid->getCoordinateTransformator()->toX1delta; + gridParameters->trafoParams[13] = grid->getCoordinateTransformator()->toX2factorX1; + gridParameters->trafoParams[14] = grid->getCoordinateTransformator()->toX2factorX2; + gridParameters->trafoParams[15] = grid->getCoordinateTransformator()->toX2factorX3; + gridParameters->trafoParams[16] = grid->getCoordinateTransformator()->toX2delta; + gridParameters->trafoParams[17] = grid->getCoordinateTransformator()->toX3factorX1; + gridParameters->trafoParams[18] = grid->getCoordinateTransformator()->toX3factorX2; + gridParameters->trafoParams[19] = grid->getCoordinateTransformator()->toX3factorX3; + gridParameters->trafoParams[20] = grid->getCoordinateTransformator()->toX3delta; + + gridParameters->trafoParams[21] = grid->getCoordinateTransformator()->fromX1factorX1; + gridParameters->trafoParams[22] = grid->getCoordinateTransformator()->fromX1factorX2; + gridParameters->trafoParams[23] = grid->getCoordinateTransformator()->fromX1factorX3; + gridParameters->trafoParams[24] = grid->getCoordinateTransformator()->fromX1delta; + gridParameters->trafoParams[25] = grid->getCoordinateTransformator()->fromX2factorX1; + gridParameters->trafoParams[26] = grid->getCoordinateTransformator()->fromX2factorX2; + gridParameters->trafoParams[27] = grid->getCoordinateTransformator()->fromX2factorX3; + gridParameters->trafoParams[28] = grid->getCoordinateTransformator()->fromX2delta; + gridParameters->trafoParams[29] = grid->getCoordinateTransformator()->fromX3factorX1; + gridParameters->trafoParams[30] = grid->getCoordinateTransformator()->fromX3factorX2; + gridParameters->trafoParams[31] = grid->getCoordinateTransformator()->fromX3factorX3; + gridParameters->trafoParams[32] = grid->getCoordinateTransformator()->fromX3delta; + + gridParameters->active = grid->getCoordinateTransformator()->active; + gridParameters->transformation = grid->getCoordinateTransformator()->transformation; + + gridParameters->deltaX = grid->getDeltaX(minInitLevel); + UbTupleInt3 blocknx = grid->getBlockNX(); + gridParameters->blockNx1 = val<1>(blocknx); + gridParameters->blockNx2 = val<2>(blocknx); + gridParameters->blockNx3 = val<3>(blocknx); + gridParameters->nx1 = grid->getNX1(); + gridParameters->nx2 = grid->getNX2(); + gridParameters->nx3 = grid->getNX3(); + gridParameters->periodicX1 = grid->isPeriodicX1(); + gridParameters->periodicX2 = grid->isPeriodicX2(); + gridParameters->periodicX3 = grid->isPeriodicX3(); + + //---------------------------------------------------------------------- + + Block3d *block3dArray = new Block3d[blocksCount]; + int ic = 0; + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level + { + // save data describing the block + block3dArray[ic].x1 = block->getX1(); + block3dArray[ic].x2 = block->getX2(); + block3dArray[ic].x3 = block->getX3(); + block3dArray[ic].bundle = block->getBundle(); + block3dArray[ic].rank = block->getRank(); + block3dArray[ic].lrank = block->getLocalRank(); + block3dArray[ic].part = block->getPart(); + block3dArray[ic].globalID = block->getGlobalID(); + block3dArray[ic].localID = block->getLocalID(); + block3dArray[ic].level = block->getLevel(); + block3dArray[ic].interpolationFlagCF = block->getCollectionOfInterpolationFlagCF(); + block3dArray[ic].interpolationFlagFC = block->getCollectionOfInterpolationFlagFC(); + block3dArray[ic].counter = block->getMaxGlobalID(); + block3dArray[ic].active = block->isActive(); + + ic++; + } + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + MPI_File file_handler; + // MPI_Info info = MPI_INFO_NULL; + + UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + double start, finish; + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + + if (comm->isRoot()) { + start = MPI_Wtime(); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, 0 /*rank*sizeof(int)*/, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes parameters of the grid + MPI_File_write_at(file_handler, write_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); + // each process writes it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, + block3dType, MPI_STATUS_IGNORE); + // MPI_File_sync(file_handler); + } + MPI_File_close(&file_handler); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOCoProcessor::writeBlocks time: " << finish - start << " s"); + } + + delete[] block3dArray; + delete gridParameters; } void MPIIOCoProcessor::readBlocks(int step) { - int rank; -// int size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); -// size = 1; - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOCoProcessor::readBlocks start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - MPI_File_read_at(file_handler, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - Block3d* block3dArray = new Block3d[blocksCount]; - - GridParam* gridParameters = new GridParam; - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(sizeof(int)); - - // read parameters of the grid - MPI_File_read_at(file_handler, read_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); - // read all the blocks - if (comm->isRoot()) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, block3dType, MPI_STATUS_IGNORE); - - MPI_Bcast(block3dArray, blocksCount, block3dType, comm->getRoot(), MPI_COMM_WORLD); - - MPI_File_close(&file_handler); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOCoProcessor::readBlocks time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOCoProcessor::readBlocks start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // clear the grid - grid->deleteBlocks(); - - // restore the grid - SPtr<CoordinateTransformation3D> trafo(new CoordinateTransformation3D()); - trafo->Tx1 = gridParameters->trafoParams[0]; - trafo->Tx2 = gridParameters->trafoParams[1]; - trafo->Tx3 = gridParameters->trafoParams[2]; - trafo->Sx1 = gridParameters->trafoParams[3]; - trafo->Sx2 = gridParameters->trafoParams[4]; - trafo->Sx3 = gridParameters->trafoParams[5]; - trafo->alpha = gridParameters->trafoParams[6]; - trafo->beta = gridParameters->trafoParams[7]; - trafo->gamma = gridParameters->trafoParams[8]; - - trafo->toX1factorX1 = gridParameters->trafoParams[9]; - trafo->toX1factorX2 = gridParameters->trafoParams[10]; - trafo->toX1factorX3 = gridParameters->trafoParams[11]; - trafo->toX1delta = gridParameters->trafoParams[12]; - trafo->toX2factorX1 = gridParameters->trafoParams[13]; - trafo->toX2factorX2 = gridParameters->trafoParams[14]; - trafo->toX2factorX3 = gridParameters->trafoParams[15]; - trafo->toX2delta = gridParameters->trafoParams[16]; - trafo->toX3factorX1 = gridParameters->trafoParams[17]; - trafo->toX3factorX2 = gridParameters->trafoParams[18]; - trafo->toX3factorX3 = gridParameters->trafoParams[19]; - trafo->toX3delta = gridParameters->trafoParams[20]; - - trafo->fromX1factorX1 = gridParameters->trafoParams[21]; - trafo->fromX1factorX2 = gridParameters->trafoParams[22]; - trafo->fromX1factorX3 = gridParameters->trafoParams[23]; - trafo->fromX1delta = gridParameters->trafoParams[24]; - trafo->fromX2factorX1 = gridParameters->trafoParams[25]; - trafo->fromX2factorX2 = gridParameters->trafoParams[26]; - trafo->fromX2factorX3 = gridParameters->trafoParams[27]; - trafo->fromX2delta = gridParameters->trafoParams[28]; - trafo->fromX3factorX1 = gridParameters->trafoParams[29]; - trafo->fromX3factorX2 = gridParameters->trafoParams[30]; - trafo->fromX3factorX3 = gridParameters->trafoParams[31]; - trafo->fromX3delta = gridParameters->trafoParams[32]; - - trafo->active = gridParameters->active; - trafo->transformation = gridParameters->transformation; - - grid->setCoordinateTransformator(trafo); - - grid->setDeltaX(gridParameters->deltaX); - grid->setBlockNX(gridParameters->blockNx1, gridParameters->blockNx2, gridParameters->blockNx3); - grid->setNX1(gridParameters->nx1); - grid->setNX2(gridParameters->nx2); - grid->setNX3(gridParameters->nx3); - grid->setPeriodicX1(gridParameters->periodicX1); - grid->setPeriodicX2(gridParameters->periodicX2); - grid->setPeriodicX3(gridParameters->periodicX3); - - // regenerate blocks - for (int n = 0; n < blocksCount; n++) - { - SPtr<Block3D> block(new Block3D(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level)); - block->setActive(block3dArray[n].active); - block->setBundle(block3dArray[n].bundle); - block->setRank(block3dArray[n].rank); - block->setLocalRank(block3dArray[n].lrank); - block->setGlobalID(block3dArray[n].globalID); - block->setLocalID(block3dArray[n].localID); - block->setPart(block3dArray[n].part); - block->setLevel(block3dArray[n].level); - block->setCollectionOfInterpolationFlagCF(block3dArray[n].interpolationFlagCF); - block->setCollectionOfInterpolationFlagFC(block3dArray[n].interpolationFlagFC); - - grid->addBlock(block); - } - - delete gridParameters; - delete[] block3dArray; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOCoProcessor::readBlocks end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + int rank; + // int size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + // size = 1; + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOCoProcessor::readBlocks start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + MPI_File_read_at(file_handler, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + Block3d *block3dArray = new Block3d[blocksCount]; + + GridParam *gridParameters = new GridParam; + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(sizeof(int)); + + // read parameters of the grid + MPI_File_read_at(file_handler, read_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); + // read all the blocks + if (comm->isRoot()) + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, + block3dType, MPI_STATUS_IGNORE); + + MPI_Bcast(block3dArray, blocksCount, block3dType, comm->getRoot(), MPI_COMM_WORLD); + + MPI_File_close(&file_handler); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOCoProcessor::readBlocks time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOCoProcessor::readBlocks start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // clear the grid + grid->deleteBlocks(); + + // restore the grid + SPtr<CoordinateTransformation3D> trafo(new CoordinateTransformation3D()); + trafo->Tx1 = gridParameters->trafoParams[0]; + trafo->Tx2 = gridParameters->trafoParams[1]; + trafo->Tx3 = gridParameters->trafoParams[2]; + trafo->Sx1 = gridParameters->trafoParams[3]; + trafo->Sx2 = gridParameters->trafoParams[4]; + trafo->Sx3 = gridParameters->trafoParams[5]; + trafo->alpha = gridParameters->trafoParams[6]; + trafo->beta = gridParameters->trafoParams[7]; + trafo->gamma = gridParameters->trafoParams[8]; + + trafo->toX1factorX1 = gridParameters->trafoParams[9]; + trafo->toX1factorX2 = gridParameters->trafoParams[10]; + trafo->toX1factorX3 = gridParameters->trafoParams[11]; + trafo->toX1delta = gridParameters->trafoParams[12]; + trafo->toX2factorX1 = gridParameters->trafoParams[13]; + trafo->toX2factorX2 = gridParameters->trafoParams[14]; + trafo->toX2factorX3 = gridParameters->trafoParams[15]; + trafo->toX2delta = gridParameters->trafoParams[16]; + trafo->toX3factorX1 = gridParameters->trafoParams[17]; + trafo->toX3factorX2 = gridParameters->trafoParams[18]; + trafo->toX3factorX3 = gridParameters->trafoParams[19]; + trafo->toX3delta = gridParameters->trafoParams[20]; + + trafo->fromX1factorX1 = gridParameters->trafoParams[21]; + trafo->fromX1factorX2 = gridParameters->trafoParams[22]; + trafo->fromX1factorX3 = gridParameters->trafoParams[23]; + trafo->fromX1delta = gridParameters->trafoParams[24]; + trafo->fromX2factorX1 = gridParameters->trafoParams[25]; + trafo->fromX2factorX2 = gridParameters->trafoParams[26]; + trafo->fromX2factorX3 = gridParameters->trafoParams[27]; + trafo->fromX2delta = gridParameters->trafoParams[28]; + trafo->fromX3factorX1 = gridParameters->trafoParams[29]; + trafo->fromX3factorX2 = gridParameters->trafoParams[30]; + trafo->fromX3factorX3 = gridParameters->trafoParams[31]; + trafo->fromX3delta = gridParameters->trafoParams[32]; + + trafo->active = gridParameters->active; + trafo->transformation = gridParameters->transformation; + + grid->setCoordinateTransformator(trafo); + + grid->setDeltaX(gridParameters->deltaX); + grid->setBlockNX(gridParameters->blockNx1, gridParameters->blockNx2, gridParameters->blockNx3); + grid->setNX1(gridParameters->nx1); + grid->setNX2(gridParameters->nx2); + grid->setNX3(gridParameters->nx3); + grid->setPeriodicX1(gridParameters->periodicX1); + grid->setPeriodicX2(gridParameters->periodicX2); + grid->setPeriodicX3(gridParameters->periodicX3); + + // regenerate blocks + for (int n = 0; n < blocksCount; n++) { + SPtr<Block3D> block( + new Block3D(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level)); + block->setActive(block3dArray[n].active); + block->setBundle(block3dArray[n].bundle); + block->setRank(block3dArray[n].rank); + block->setLocalRank(block3dArray[n].lrank); + block->setGlobalID(block3dArray[n].globalID); + block->setLocalID(block3dArray[n].localID); + block->setPart(block3dArray[n].part); + block->setLevel(block3dArray[n].level); + block->setCollectionOfInterpolationFlagCF(block3dArray[n].interpolationFlagCF); + block->setCollectionOfInterpolationFlagFC(block3dArray[n].interpolationFlagFC); + + grid->addBlock(block); + } + + delete gridParameters; + delete[] block3dArray; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOCoProcessor::readBlocks end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } } void MPIIOCoProcessor::clearAllFiles(int step) { - MPI_File file_handler; - MPI_Info info = MPI_INFO_NULL; - MPI_Offset new_size = 0; - - UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); - - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; - int rc1 = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handler); - if (rc1 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename2 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc2 = MPI_File_open(MPI_COMM_WORLD, filename2.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc2 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename2); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename3 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - int rc3 = MPI_File_open(MPI_COMM_WORLD, filename3.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc3 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename3); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename4 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; - //MPI_File_delete(filename4.c_str(), info); - int rc4 = MPI_File_open(MPI_COMM_WORLD, filename4.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc4 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename4); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename5 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; - //MPI_File_delete(filename5.c_str(), info); - int rc5 = MPI_File_open(MPI_COMM_WORLD, filename5.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc5 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename5); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename6 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; - //MPI_File_delete(filename6.c_str(), info); - int rc6 = MPI_File_open(MPI_COMM_WORLD, filename6.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc6 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename6); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename7 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; - //MPI_File_delete(filename7.c_str(), info); - int rc7 = MPI_File_open(MPI_COMM_WORLD, filename7.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc7 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename7); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename8 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; - //MPI_File_delete(filename8.c_str(), info); - int rc8 = MPI_File_open(MPI_COMM_WORLD, filename8.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc8 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename8); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename9 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; - //MPI_File_delete(filename9.c_str(), info); - int rc9 = MPI_File_open(MPI_COMM_WORLD, filename9.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc9 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename9); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - /*std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; - int rc10 = MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc10 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename10); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename11 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; - int rc11 = MPI_File_open(MPI_COMM_WORLD, filename11.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc11 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename11); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler);*/ + MPI_File file_handler; + MPI_Info info = MPI_INFO_NULL; + MPI_Offset new_size = 0; + + UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; + int rc1 = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handler); + if (rc1 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename2 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc2 = MPI_File_open(MPI_COMM_WORLD, filename2.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc2 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename2); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename3 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + int rc3 = MPI_File_open(MPI_COMM_WORLD, filename3.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc3 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename3); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename4 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; + // MPI_File_delete(filename4.c_str(), info); + int rc4 = MPI_File_open(MPI_COMM_WORLD, filename4.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc4 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename4); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename5 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; + // MPI_File_delete(filename5.c_str(), info); + int rc5 = MPI_File_open(MPI_COMM_WORLD, filename5.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc5 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename5); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename6 = + path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; + // MPI_File_delete(filename6.c_str(), info); + int rc6 = MPI_File_open(MPI_COMM_WORLD, filename6.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc6 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename6); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename7 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; + // MPI_File_delete(filename7.c_str(), info); + int rc7 = MPI_File_open(MPI_COMM_WORLD, filename7.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc7 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename7); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename8 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; + // MPI_File_delete(filename8.c_str(), info); + int rc8 = MPI_File_open(MPI_COMM_WORLD, filename8.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc8 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename8); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename9 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; + // MPI_File_delete(filename9.c_str(), info); + int rc9 = MPI_File_open(MPI_COMM_WORLD, filename9.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc9 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename9); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + /*std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; + int rc10 = MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, + &file_handler); if (rc10 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename10); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename11 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; + int rc11 = MPI_File_open(MPI_COMM_WORLD, filename11.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, + &file_handler); if (rc11 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename11); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler);*/ } void MPIIOCoProcessor::writeCpTimeStep(int step) { - if (comm->isRoot()) - { - UbFileOutputASCII f(path + "/mpi_io_cp/cp.txt"); - f.writeInteger(step); - } + if (comm->isRoot()) { + UbFileOutputASCII f(path + "/mpi_io_cp/cp.txt"); + f.writeInteger(step); + } } ////////////////////////////////////////////////////////////////////////// int MPIIOCoProcessor::readCpTimeStep() { - UbFileInputASCII f(path + "/mpi_io_cp/cp.txt"); - int step = f.readInteger(); - return step; + UbFileInputASCII f(path + "/mpi_io_cp/cp.txt"); + int step = f.readInteger(); + return step; } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.h index 33a63f02c..8997a39d1 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOCoProcessor.h @@ -1,44 +1,44 @@ -#ifndef _MPIIOCoProcessor_H_ +#ifndef _MPIIOCoProcessor_H_ #define _MPIIOCoProcessor_H_ #include "CoProcessor.h" #include <PointerDefinitions.h> -#include <string> #include <mpi.h> +#include <string> class Grid3D; class UbScheduler; class Communicator; -//! \class MPIWriteBlocksBECoProcessor -//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating +//! \class MPIWriteBlocksBECoProcessor +//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating class MPIIOCoProcessor : public CoProcessor { public: - MPIIOCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm); - ~MPIIOCoProcessor() override; + MPIIOCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<Communicator> comm); + ~MPIIOCoProcessor() override; - //! Each timestep writes the grid into the files - void process(double step) override = 0; + //! Each timestep writes the grid into the files + void process(double step) override = 0; - //! Writes the blocks of the grid into the file cpBlocks.bin - void writeBlocks(int step); + //! Writes the blocks of the grid into the file cpBlocks.bin + void writeBlocks(int step); - //! Reads the blocks of the grid from the file cpBlocks.bin - void readBlocks(int step); + //! Reads the blocks of the grid from the file cpBlocks.bin + void readBlocks(int step); - //!The function truncates the data files - void clearAllFiles(int step); + //! The function truncates the data files + void clearAllFiles(int step); - //!The function write a time step of last check point - void writeCpTimeStep(int step); - //!The function read a time step of last check point - int readCpTimeStep(); + //! The function write a time step of last check point + void writeCpTimeStep(int step); + //! The function read a time step of last check point + int readCpTimeStep(); protected: - std::string path; - SPtr<Communicator> comm; - MPI_Datatype gridParamType, block3dType, dataSetParamType, boundCondType, arrayPresenceType; + std::string path; + SPtr<Communicator> comm; + MPI_Datatype gridParamType, block3dType, dataSetParamType, boundCondType, arrayPresenceType; }; #endif // ! _MPIIOCoProcessor_H_ #define _MPIIOCoProcessor_H_ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.cpp index 5d864a190..6461e847a 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.cpp @@ -1,1449 +1,1513 @@ #include "MPIIOMigrationBECoProcessor.h" -#include "D3Q27System.h" -#include "LBMKernel.h" -#include "D3Q27EsoTwist3DSplittedVector.h" -#include <UbSystem.h> -#include <MemoryUtil.h> -#include "BoundaryConditions.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "Block3D.h" +#include "BoundaryConditions.h" +#include "Communicator.h" #include "CoordinateTransformation3D.h" +#include "D3Q27EsoTwist3DSplittedVector.h" +#include "D3Q27System.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "BCArray3D.h" -#include "Communicator.h" -#include "WbWriter.h" -#include "UbScheduler.h" #include "LBMKernel.h" -#include "BCProcessor.h" #include "MetisPartitioningGridVisitor.h" #include "PointerDefinitions.h" #include "RenumberGridVisitor.h" -#include "UbFileOutputASCII.h" #include "UbFileInputASCII.h" +#include "UbFileOutputASCII.h" +#include "UbScheduler.h" +#include "WbWriter.h" +#include <MemoryUtil.h> +#include <UbSystem.h> using namespace MPIIODataStructures; #define MESSAGE_TAG 80 #define SEND_BLOCK_SIZE 100000 -MPIIOMigrationBECoProcessor::MPIIOMigrationBECoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm) : MPIIOCoProcessor(grid, s, path, comm), nue(-999.999) +MPIIOMigrationBECoProcessor::MPIIOMigrationBECoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, + const std::string &path, SPtr<Communicator> comm) + : MPIIOCoProcessor(grid, s, path, comm), nue(-999.999) { - memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); + memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); - //------------------------- define MPI types --------------------------------- - - MPI_Type_contiguous(SEND_BLOCK_SIZE, MPI_INT, &sendBlockIntType); - MPI_Type_commit(&sendBlockIntType); + //------------------------- define MPI types --------------------------------- + MPI_Type_contiguous(SEND_BLOCK_SIZE, MPI_INT, &sendBlockIntType); + MPI_Type_commit(&sendBlockIntType); } ////////////////////////////////////////////////////////////////////////// -MPIIOMigrationBECoProcessor::~MPIIOMigrationBECoProcessor() -{ - MPI_Type_free(&sendBlockIntType); -} +MPIIOMigrationBECoProcessor::~MPIIOMigrationBECoProcessor() { MPI_Type_free(&sendBlockIntType); } void MPIIOMigrationBECoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - if (comm->isRoot()) UBLOG(logINFO, "MPIIOMigrationBECoProcessor save step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Save check point - start"); - clearAllFiles((int)step); + if (scheduler->isDue(step)) { + if (comm->isRoot()) + UBLOG(logINFO, "MPIIOMigrationBECoProcessor save step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - start"); + clearAllFiles((int)step); - writeBlocks((int)step); - writeDataSet((int)step); - writeBoundaryConds((int)step); + writeBlocks((int)step); + writeDataSet((int)step); + writeBoundaryConds((int)step); - writeCpTimeStep((int)step); + writeCpTimeStep((int)step); - if (comm->isRoot()) UBLOG(logINFO, "Save check point - end"); - } + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - end"); + } } void MPIIOMigrationBECoProcessor::clearAllFiles(int step) { - MPI_File file_handler; - MPI_Info info = MPI_INFO_NULL; - MPI_Offset new_size = 0; - - MPIIOCoProcessor::clearAllFiles(step); - - UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); - - std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; - int rc10 = MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc10 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename10); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); - - std::string filename11 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; - int rc11 = MPI_File_open(MPI_COMM_WORLD, filename11.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc11 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename11); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); + MPI_File file_handler; + MPI_Info info = MPI_INFO_NULL; + MPI_Offset new_size = 0; + + MPIIOCoProcessor::clearAllFiles(step); + + UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + + std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; + int rc10 = + MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc10 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename10); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); + + std::string filename11 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; + int rc11 = + MPI_File_open(MPI_COMM_WORLD, filename11.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc11 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename11); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); } void MPIIOMigrationBECoProcessor::writeBlocks(int step) { - grid->deleteBlockIDs(); - RenumberGridVisitor renumber(comm); - grid->accept(renumber); + grid->deleteBlockIDs(); + RenumberGridVisitor renumber(comm); + grid->accept(renumber); - MPIIOCoProcessor::writeBlocks(step); + MPIIOCoProcessor::writeBlocks(step); } void MPIIOMigrationBECoProcessor::writeDataSet(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks, that belong to this process - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - int firstGlobalID; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - DSArraysPresence arrPresence; - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< D3Q27EsoTwist3DSplittedVector > D3Q27EsoTwist3DSplittedVectorPtr; - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(block->getKernel()->getDataSet()->getFdistributions()); - localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); - nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); - zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); - - if (firstBlock)// && block->getKernel()) // when first (any) valid block... - { - firstGlobalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - if (localDistributions) - { - dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); - dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); - dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); - dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); - } + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks, that belong to this process + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } - if (nonLocalDistributions) - { - dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); - dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); - dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); - dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); - } - if (zeroDistributions) + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + int firstGlobalID; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + DSArraysPresence arrPresence; + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<D3Q27EsoTwist3DSplittedVector> D3Q27EsoTwist3DSplittedVectorPtr; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>( + block->getKernel()->getDataSet()->getFdistributions()); + localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); + nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); + zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); + + if (firstBlock) // && block->getKernel()) // when first (any) valid block... { - dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); - dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); - dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); - dataSetParamStr3.nx[3] = 1; + firstGlobalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid + + if (localDistributions) { + dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); + dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); + dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); + dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); + } + + if (nonLocalDistributions) { + dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); + dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); + dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); + dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); + } + if (zeroDistributions) { + dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); + dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); + dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); + dataSetParamStr3.nx[3] = 1; + } + + // ... than save some parameters that are equal in all blocks + dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); + dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); + dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); + + doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> averageDensityArray = + block->getKernel()->getDataSet()->getAverageDensity(); + if (averageDensityArray) + arrPresence.isAverageDensityArrayPresent = true; + else + arrPresence.isAverageDensityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageVelocityArray3DPtr = + block->getKernel()->getDataSet()->getAverageVelocity(); + if (AverageVelocityArray3DPtr) + arrPresence.isAverageVelocityArrayPresent = true; + else + arrPresence.isAverageVelocityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageFluctArray3DPtr = + block->getKernel()->getDataSet()->getAverageFluctuations(); + if (AverageFluctArray3DPtr) + arrPresence.isAverageFluktuationsArrayPresent = true; + else + arrPresence.isAverageFluktuationsArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageTripleArray3DPtr = + block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + if (AverageTripleArray3DPtr) + arrPresence.isAverageTripleArrayPresent = true; + else + arrPresence.isAverageTripleArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ShearStressValArray3DPtr = + block->getKernel()->getDataSet()->getShearStressValues(); + if (ShearStressValArray3DPtr) + arrPresence.isShearStressValArrayPresent = true; + else + arrPresence.isShearStressValArrayPresent = false; + + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> relaxationFactor3DPtr = + block->getKernel()->getDataSet()->getRelaxationFactor(); + if (relaxationFactor3DPtr) + arrPresence.isRelaxationFactorPresent = true; + else + arrPresence.isRelaxationFactorPresent = false; + + firstBlock = false; } - // ... than save some parameters that are equal in all blocks - dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); - dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); - dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); - - doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); - if (averageDensityArray) - arrPresence.isAverageDensityArrayPresent = true; - else - arrPresence.isAverageDensityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); - if (AverageVelocityArray3DPtr) - arrPresence.isAverageVelocityArrayPresent = true; - else - arrPresence.isAverageVelocityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); - if (AverageFluctArray3DPtr) - arrPresence.isAverageFluktuationsArrayPresent = true; - else - arrPresence.isAverageFluktuationsArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - if (AverageTripleArray3DPtr) - arrPresence.isAverageTripleArrayPresent = true; - else - arrPresence.isAverageTripleArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); - if (ShearStressValArray3DPtr) - arrPresence.isShearStressValArrayPresent = true; - else - arrPresence.isShearStressValArrayPresent = false; - - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > relaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); - if (relaxationFactor3DPtr) - arrPresence.isRelaxationFactorPresent = true; - else - arrPresence.isRelaxationFactorPresent = false; - - firstBlock = false; - } - - if (localDistributions && (dataSetParamStr1.nx[0]>0) && (dataSetParamStr1.nx[1]>0) && (dataSetParamStr1.nx[2]>0) && (dataSetParamStr1.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), localDistributions->getDataVector().end()); - if (nonLocalDistributions && (dataSetParamStr2.nx[0]>0) && (dataSetParamStr2.nx[1]>0) && (dataSetParamStr2.nx[2]>0) && (dataSetParamStr2.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), nonLocalDistributions->getDataVector().end()); - if (zeroDistributions && (dataSetParamStr3.nx[0]>0) && (dataSetParamStr3.nx[1]>0) && (dataSetParamStr3.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), zeroDistributions->getDataVector().end()); - - ic++; - } - } - - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + if (localDistributions && (dataSetParamStr1.nx[0] > 0) && (dataSetParamStr1.nx[1] > 0) && + (dataSetParamStr1.nx[2] > 0) && (dataSetParamStr1.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), + localDistributions->getDataVector().end()); + if (nonLocalDistributions && (dataSetParamStr2.nx[0] > 0) && (dataSetParamStr2.nx[1] > 0) && + (dataSetParamStr2.nx[2] > 0) && (dataSetParamStr2.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), + nonLocalDistributions->getDataVector().end()); + if (zeroDistributions && (dataSetParamStr3.nx[0] > 0) && (dataSetParamStr3.nx[1] > 0) && + (dataSetParamStr3.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), + zeroDistributions->getDataVector().end()); + + ic++; + } + } + + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - // write to the file - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset = (MPI_Offset)(3 * sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * (MPI_Offset)(doubleCountInBlock) * (MPI_Offset)(sizeof(double)); - - MPI_File_write_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet time: " << finish - start << " s"); - } - - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_sync(file_handler1); - MPI_File_close(&file_handler1); - - if (arrPresence.isAverageDensityArrayPresent) - write4DArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); - //writeAverageDensityArray(step); - - if (arrPresence.isAverageVelocityArrayPresent) - write4DArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); - //writeAverageVelocityArray(step); - - if (arrPresence.isAverageFluktuationsArrayPresent) - write4DArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); - //writeAverageFluktuationsArray(step); - - if (arrPresence.isAverageTripleArrayPresent) - write4DArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); - //writeAverageTripleArray(step); - - if (arrPresence.isShearStressValArrayPresent) - write4DArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); - //writeShearStressValArray(step); - - if (arrPresence.isRelaxationFactorPresent) - write3DArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); - //writeRelaxationFactor(step); + // write to the file + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset = (MPI_Offset)(3 * sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * + (MPI_Offset)(doubleCountInBlock) * + (MPI_Offset)(sizeof(double)); + + MPI_File_write_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, + MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeDataSet time: " << finish - start << " s"); + } + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_sync(file_handler1); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + write4DArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); + // writeAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + write4DArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); + // writeAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + write4DArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); + // writeAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + write4DArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); + // writeAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + write4DArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); + // writeShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + write3DArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); + // writeRelaxationFactor(step); } void MPIIOMigrationBECoProcessor::write4DArray(int step, Arrays arrayType, std::string fname) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - int firstGlobalID; - std::vector<double> doubleValuesArray; // double-values of the data array in all blocks - dataSetParam dataSetParamStr; - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ___Array; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - switch (arrayType) { - case AverageDensity: - ___Array = block->getKernel()->getDataSet()->getAverageDensity(); - break; - case AverageVelocity: - ___Array = block->getKernel()->getDataSet()->getAverageVelocity(); - break; - case AverageFluktuations: - ___Array = block->getKernel()->getDataSet()->getAverageFluctuations(); - break; - case AverageTriple: - ___Array = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - break; - case ShearStressVal: - ___Array = block->getKernel()->getDataSet()->getShearStressValues(); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationBECoProcessor::write4DArray : 4D array type does not exist!")); - break; - } - - if (firstBlock) // when first (any) valid block... - { - firstGlobalID = block->getGlobalID(); - - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(___Array->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && (dataSetParamStr.nx[3] > 0)) - doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), ___Array->getDataVector().end()); - - ic++; - } - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // register new MPI-type depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset = (MPI_Offset)(sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * (MPI_Offset)(doubleCountInBlock) * (MPI_Offset)(sizeof(double)); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray time: " << finish - start << " s"); - } + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + int firstGlobalID; + std::vector<double> doubleValuesArray; // double-values of the data array in all blocks + dataSetParam dataSetParamStr; + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___Array; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + switch (arrayType) { + case AverageDensity: + ___Array = block->getKernel()->getDataSet()->getAverageDensity(); + break; + case AverageVelocity: + ___Array = block->getKernel()->getDataSet()->getAverageVelocity(); + break; + case AverageFluktuations: + ___Array = block->getKernel()->getDataSet()->getAverageFluctuations(); + break; + case AverageTriple: + ___Array = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + break; + case ShearStressVal: + ___Array = block->getKernel()->getDataSet()->getShearStressValues(); + break; + default: + UB_THROW(UbException(UB_EXARGS, + "MPIIOMigrationBECoProcessor::write4DArray : 4D array type does not exist!")); + break; + } + + if (firstBlock) // when first (any) valid block... + { + firstGlobalID = block->getGlobalID(); + + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(___Array->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), + ___Array->getDataVector().end()); + + ic++; + } + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // register new MPI-type depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset = (MPI_Offset)(sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * + (MPI_Offset)(doubleCountInBlock) * + (MPI_Offset)(sizeof(double)); + + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, + MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write4DArray time: " << finish - start << " s"); + } } void MPIIOMigrationBECoProcessor::write3DArray(int step, Arrays arrayType, std::string fname) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - int firstGlobalID; - std::vector<double> doubleValuesArray; // double-values of the data array in all blocks - dataSetParam dataSetParamStr; - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > ___Array; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - switch (arrayType) { - case RelaxationFactor: - ___Array = block->getKernel()->getDataSet()->getRelaxationFactor(); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationBECoProcessor::write3DArray : 3D array type does not exist!")); - break; - } - - if (firstBlock) // when first (any) valid block... - { - firstGlobalID = block->getGlobalID(); - - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); - dataSetParamStr.nx[3] = 1; - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0)) - doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), ___Array->getDataVector().end()); - - ic++; - } - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // register new MPI-type depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset = (MPI_Offset)(sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * (MPI_Offset)(doubleCountInBlock) * (MPI_Offset)(sizeof(double)); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray time: " << finish - start << " s"); - } -} + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } -//--------------------------------------------------------------------------------- + int firstGlobalID; + std::vector<double> doubleValuesArray; // double-values of the data array in all blocks + dataSetParam dataSetParamStr; + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___Array; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } -void MPIIOMigrationBECoProcessor::writeBoundaryConds(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - int blocksCount = 0; // quantity of blocks, that belong to this process - size_t allBytesCount = 0; // quantity of bytes, that one process writes to the file - size_t count_boundCond = 0; // how many BoundaryConditions in all blocks - int count_indexContainer = 0; // how many indexContainer-values in all blocks - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - BCAddMigration* bcAddArray = new BCAddMigration[blocksCount]; - size_t* bytesCount = new size_t[blocksCount]; // quantity of bytes, that each block writes to the file - std::vector<BoundaryCondition>* bcVector = new std::vector<BoundaryCondition>[blocksCount]; - std::vector<int>* indexContainerVector = new std::vector<int>[blocksCount]; - std::vector<int> bcindexmatrixVector; - - bool bcindexmatrixCountNotInit = true; - int ic = 0; - SPtr<BCArray3D> bcArr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level - { - bcArr = block->getKernel()->getBCProcessor()->getBCArray(); - - bcAddArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block - bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block - bytesCount[ic] = sizeof(BCAddMigration); - bcVector[ic].resize(0); - indexContainerVector[ic].resize(0); - - for (int bc = 0; bc<bcArr->getBCVectorSize(); bc++) - { - BoundaryCondition* bouCond = new BoundaryCondition(); - if (bcArr->bcvector[bc] == NULL) - memset(bouCond, 0, sizeof(BoundaryCondition)); - else + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + switch (arrayType) { + case RelaxationFactor: + ___Array = block->getKernel()->getDataSet()->getRelaxationFactor(); + break; + default: + UB_THROW(UbException(UB_EXARGS, + "MPIIOMigrationBECoProcessor::write3DArray : 3D array type does not exist!")); + break; + } + + if (firstBlock) // when first (any) valid block... { - bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); - bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); - bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); - bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); - bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); - bouCond->bcVelocityX1 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX1(); - bouCond->bcVelocityX2 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX2(); - bouCond->bcVelocityX3 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX3(); - bouCond->bcDensity = (float) bcArr->bcvector[bc]->getBoundaryDensity(); - bouCond->bcLodiDensity = (float) bcArr->bcvector[bc]->getDensityLodiDensity(); - bouCond->bcLodiVelocityX1 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX1(); - bouCond->bcLodiVelocityX2 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX2(); - bouCond->bcLodiVelocityX3 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX3(); - bouCond->bcLodiLentgh = (float) bcArr->bcvector[bc]->getDensityLodiLength(); - bouCond->nx1 = (float) bcArr->bcvector[bc]->nx1; - bouCond->nx2 = (float) bcArr->bcvector[bc]->nx2; - bouCond->nx3 = (float) bcArr->bcvector[bc]->nx3; - for (int iq = 0; iq<26; iq++) - bouCond->q[iq] = (float) bcArr->bcvector[bc]->getQ(iq); - bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); + firstGlobalID = block->getGlobalID(); + + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); + dataSetParamStr.nx[3] = 1; + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; } - bcVector[ic].push_back(*bouCond); - bcAddArray[ic].boundCond_count++; - count_boundCond++; - bytesCount[ic] += sizeof(BoundaryCondition); - } - - if (bcindexmatrixCountNotInit) - { - boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); - boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); - boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); - boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); - bcindexmatrixCountNotInit = false; - } - - bcindexmatrixVector.insert(bcindexmatrixVector.end(), bcArr->bcindexmatrix.getDataVector().begin(), bcArr->bcindexmatrix.getDataVector().end()); - - indexContainerVector[ic].insert(indexContainerVector[ic].begin(), bcArr->indexContainer.begin(), bcArr->indexContainer.end()); - bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); - count_indexContainer += bcAddArray[ic].indexContainer_count; - bytesCount[ic] += bcAddArray[ic].indexContainer_count * sizeof(int); - - allBytesCount += bytesCount[ic]; - - ic++; - } - } - - MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - //MPI_Info_create (&info); - //MPI_Info_set(info,"romio_cb_write","enable"); - //MPI_Info_set(info,"cb_buffer_size","4194304"); - //MPI_Info_set(info,"striping_unit","4194304"); - -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset = (MPI_Offset)(sizeof(int)) + (MPI_Offset)(bcAddArray[0].globalID) * (MPI_Offset)(boundCondParamStr.bcindexmatrixCount) * (MPI_Offset)(sizeof(int)); - - MPI_File_write_at(file_handler, 0, &boundCondParamStr.bcindexmatrixCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, write_offset, &bcindexmatrixVector[0], blocksCount, bcindexmatrixType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); - -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_File_write_at(file_handler, 0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); - - write_offset = (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(grid->getNumberOfBlocks()) * (MPI_Offset)(sizeof(size_t)); - size_t next_file_offset = 0; - if (size > 1) - { - if (rank == 0) - { - next_file_offset = write_offset + allBytesCount; - MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_file_offset = write_offset + allBytesCount; - if (rank < size - 1) - MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_Offset write_offsetIndex; - - for (int nb = 0; nb < blocksCount; nb++) - { - write_offsetIndex = (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(bcAddArray[nb].globalID) * (MPI_Offset)(sizeof(size_t)); - MPI_File_write_at(file_handler, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); - - MPI_File_write_at(file_handler, write_offset, &bcAddArray[nb], 3, MPI_INT, MPI_STATUS_IGNORE); - if (bcVector[nb].size() > 0) - MPI_File_write_at(file_handler, write_offset + (MPI_Offset)(sizeof(BCAddMigration)), &bcVector[nb][0], bcAddArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); - - if (indexContainerVector[nb].size() > 0) - MPI_File_write_at(file_handler, write_offset + (MPI_Offset)(sizeof(BCAddMigration)) + (MPI_Offset)(bcAddArray[nb].boundCond_count) * (MPI_Offset)(sizeof(BoundaryCondition)), - &indexContainerVector[nb][0], bcAddArray[nb].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - - write_offset += bytesCount[nb]; - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds time: " << finish - start << " s"); - } - - delete[] bcAddArray; - delete[] bytesCount; - delete[] bcVector; - delete[] indexContainerVector; + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), + ___Array->getDataVector().end()); + + ic++; + } + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // register new MPI-type depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset = (MPI_Offset)(sizeof(dataSetParam)) + (MPI_Offset)(firstGlobalID) * + (MPI_Offset)(doubleCountInBlock) * + (MPI_Offset)(sizeof(double)); + + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, write_offset, &doubleValuesArray[0], blocksCount, dataSetDoubleType, + MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::write3DArray time: " << finish - start << " s"); + } } -//------------------------------------------- READ ----------------------------------------------- -void MPIIOMigrationBECoProcessor::restart(int step) +//--------------------------------------------------------------------------------- + +void MPIIOMigrationBECoProcessor::writeBoundaryConds(int step) { - if (comm->isRoot()) UBLOG(logINFO, "MPIIOMigrationBECoProcessor restart step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Load check point - start"); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + int blocksCount = 0; // quantity of blocks, that belong to this process + size_t allBytesCount = 0; // quantity of bytes, that one process writes to the file + size_t count_boundCond = 0; // how many BoundaryConditions in all blocks + int count_indexContainer = 0; // how many indexContainer-values in all blocks + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + BCAddMigration *bcAddArray = new BCAddMigration[blocksCount]; + size_t *bytesCount = new size_t[blocksCount]; // quantity of bytes, that each block writes to the file + std::vector<BoundaryCondition> *bcVector = new std::vector<BoundaryCondition>[blocksCount]; + std::vector<int> *indexContainerVector = new std::vector<int>[blocksCount]; + std::vector<int> bcindexmatrixVector; + + bool bcindexmatrixCountNotInit = true; + int ic = 0; + SPtr<BCArray3D> bcArr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level + { + bcArr = block->getKernel()->getBCProcessor()->getBCArray(); + + bcAddArray[ic].globalID = + block->getGlobalID(); // id of the block needed to find it while regenerating the grid + bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block + bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block + bytesCount[ic] = sizeof(BCAddMigration); + bcVector[ic].resize(0); + indexContainerVector[ic].resize(0); + + for (int bc = 0; bc < bcArr->getBCVectorSize(); bc++) { + BoundaryCondition *bouCond = new BoundaryCondition(); + if (bcArr->bcvector[bc] == NULL) + memset(bouCond, 0, sizeof(BoundaryCondition)); + else { + bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); + bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); + bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); + bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); + bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); + bouCond->bcVelocityX1 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX1(); + bouCond->bcVelocityX2 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX2(); + bouCond->bcVelocityX3 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX3(); + bouCond->bcDensity = (float)bcArr->bcvector[bc]->getBoundaryDensity(); + bouCond->bcLodiDensity = (float)bcArr->bcvector[bc]->getDensityLodiDensity(); + bouCond->bcLodiVelocityX1 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX1(); + bouCond->bcLodiVelocityX2 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX2(); + bouCond->bcLodiVelocityX3 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX3(); + bouCond->bcLodiLentgh = (float)bcArr->bcvector[bc]->getDensityLodiLength(); + bouCond->nx1 = (float)bcArr->bcvector[bc]->nx1; + bouCond->nx2 = (float)bcArr->bcvector[bc]->nx2; + bouCond->nx3 = (float)bcArr->bcvector[bc]->nx3; + for (int iq = 0; iq < 26; iq++) + bouCond->q[iq] = (float)bcArr->bcvector[bc]->getQ(iq); + bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); + } + + bcVector[ic].push_back(*bouCond); + bcAddArray[ic].boundCond_count++; + count_boundCond++; + bytesCount[ic] += sizeof(BoundaryCondition); + } + + if (bcindexmatrixCountNotInit) { + boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); + boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); + boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); + boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); + bcindexmatrixCountNotInit = false; + } + + bcindexmatrixVector.insert(bcindexmatrixVector.end(), bcArr->bcindexmatrix.getDataVector().begin(), + bcArr->bcindexmatrix.getDataVector().end()); + + indexContainerVector[ic].insert(indexContainerVector[ic].begin(), bcArr->indexContainer.begin(), + bcArr->indexContainer.end()); + bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); + count_indexContainer += bcAddArray[ic].indexContainer_count; + bytesCount[ic] += bcAddArray[ic].indexContainer_count * sizeof(int); + + allBytesCount += bytesCount[ic]; + + ic++; + } + } + + MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); - readBlocks(step); - SPtr<Grid3DVisitor> newMetisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, D3Q27System::BSW, MetisPartitioner::KWAY)); - grid->accept(newMetisVisitor); + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; + // MPI_Info_create (&info); + // MPI_Info_set(info,"romio_cb_write","enable"); + // MPI_Info_set(info,"cb_buffer_size","4194304"); + // MPI_Info_set(info,"striping_unit","4194304"); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset = (MPI_Offset)(sizeof(int)) + (MPI_Offset)(bcAddArray[0].globalID) * + (MPI_Offset)(boundCondParamStr.bcindexmatrixCount) * + (MPI_Offset)(sizeof(int)); + + MPI_File_write_at(file_handler, 0, &boundCondParamStr.bcindexmatrixCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, write_offset, &bcindexmatrixVector[0], blocksCount, bcindexmatrixType, + MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_write_at(file_handler, 0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); + + write_offset = + (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(grid->getNumberOfBlocks()) * (MPI_Offset)(sizeof(size_t)); + size_t next_file_offset = 0; + if (size > 1) { + if (rank == 0) { + next_file_offset = write_offset + allBytesCount; + MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_file_offset = write_offset + allBytesCount; + if (rank < size - 1) + MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_Offset write_offsetIndex; + + for (int nb = 0; nb < blocksCount; nb++) { + write_offsetIndex = + (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(bcAddArray[nb].globalID) * (MPI_Offset)(sizeof(size_t)); + MPI_File_write_at(file_handler, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); + + MPI_File_write_at(file_handler, write_offset, &bcAddArray[nb], 3, MPI_INT, MPI_STATUS_IGNORE); + if (bcVector[nb].size() > 0) + MPI_File_write_at(file_handler, write_offset + (MPI_Offset)(sizeof(BCAddMigration)), &bcVector[nb][0], + bcAddArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); + + if (indexContainerVector[nb].size() > 0) + MPI_File_write_at( + file_handler, + write_offset + (MPI_Offset)(sizeof(BCAddMigration)) + + (MPI_Offset)(bcAddArray[nb].boundCond_count) * (MPI_Offset)(sizeof(BoundaryCondition)), + &indexContainerVector[nb][0], bcAddArray[nb].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - readDataSet(step); - readBoundaryConds(step); + write_offset += bytesCount[nb]; + } + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::writeBoundaryConds time: " << finish - start << " s"); + } - grid->setTimeStep(step); - if (comm->isRoot()) UBLOG(logINFO, "Load check point - end"); + delete[] bcAddArray; + delete[] bytesCount; + delete[] bcVector; + delete[] indexContainerVector; } -void MPIIOMigrationBECoProcessor::readBlocks(int step) +//------------------------------------------- READ ----------------------------------------------- +void MPIIOMigrationBECoProcessor::restart(int step) { - MPIIOCoProcessor::readBlocks(step); + if (comm->isRoot()) + UBLOG(logINFO, "MPIIOMigrationBECoProcessor restart step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - start"); + + readBlocks(step); + SPtr<Grid3DVisitor> newMetisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, + D3Q27System::BSW, MetisPartitioner::KWAY)); + grid->accept(newMetisVisitor); + + readDataSet(step); + readBoundaryConds(step); + + grid->setTimeStep(step); + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - end"); } -void MPIIOMigrationBECoProcessor::blocksExchange(int tagN, int ind1, int ind2, int doubleCountInBlock, std::vector<double>& pV, std::vector<double>* rawDataReceive) +void MPIIOMigrationBECoProcessor::readBlocks(int step) { MPIIOCoProcessor::readBlocks(step); } + +void MPIIOMigrationBECoProcessor::blocksExchange(int tagN, int ind1, int ind2, int doubleCountInBlock, + std::vector<double> &pV, std::vector<double> *rawDataReceive) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int indexB = ind1; - int indexE = ind2; -// int myBlocksCount = indexE - indexB; - - int* blocksCounterSend = new int[size]; - int* blocksCounterRec = new int[size]; - - std::vector<double>* rawDataSend = new std::vector<double>[size]; - for (int r = 0; r < size; r++) - { - rawDataSend[r].resize(0); - blocksCounterSend[r] = 0; - blocksCounterRec[r] = 0; - } - - SPtr<Block3D> tempBlock; - int tempRank; - - for(size_t ind = indexB - indexB; ind < indexE - indexB; ind++) // FIXME: both sides of operator are equivalent - { - tempBlock = grid->getBlock(indexB + int(ind)); - if(!tempBlock) throw UbException(UB_EXARGS,"MPIIOMigrationBECoProcessor::blocksExchange -- null block pointer!!!" ); - - tempRank = tempBlock->getRank(); - - if (tempRank == rank) // no need to send data, the process already has it - { - blocksCounterRec[tempRank]++; - rawDataReceive[tempRank].push_back(double(indexB + ind)); - rawDataReceive[tempRank].insert(rawDataReceive[tempRank].end(), pV.begin() + ind * size_t(doubleCountInBlock), pV.begin() + ind * size_t(doubleCountInBlock) + size_t(doubleCountInBlock)); - } - else // we must send data to other processes - { - blocksCounterSend[tempRank]++; - rawDataSend[tempRank].push_back(double(indexB + ind)); - rawDataSend[tempRank].insert(rawDataSend[tempRank].end(), pV.begin() + ind * size_t(doubleCountInBlock), pV.begin() + ind * size_t(doubleCountInBlock) + size_t(doubleCountInBlock)); - } - } - - MPI_Request* requests = new MPI_Request[size * 2]; // send + receive - int requestCount = 0; -// MPI_Status status; - - for (int r = 0; r < size; r++) - { - if (r != rank) - { - MPI_Irecv(&blocksCounterRec[r], 1, MPI_INT, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } - - for (int r = 0; r < size; r++) - { - if (r != rank) - { - MPI_Isend(&blocksCounterSend[r], 1, MPI_INT, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } - - MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); - - MPI_Type_contiguous(doubleCountInBlock + 1, MPI_DOUBLE, &sendBlockDoubleType); - MPI_Type_commit(&sendBlockDoubleType); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int indexB = ind1; + int indexE = ind2; + // int myBlocksCount = indexE - indexB; + + int *blocksCounterSend = new int[size]; + int *blocksCounterRec = new int[size]; + + std::vector<double> *rawDataSend = new std::vector<double>[size]; + for (int r = 0; r < size; r++) { + rawDataSend[r].resize(0); + blocksCounterSend[r] = 0; + blocksCounterRec[r] = 0; + } - for (int r = 0; r < size; r++) + SPtr<Block3D> tempBlock; + int tempRank; + + for (size_t ind = indexB - indexB; ind < indexE - indexB; ind++) // FIXME: both sides of operator are equivalent { - if (r != rank) - rawDataReceive[r].resize(size_t(blocksCounterRec[r]) * size_t(doubleCountInBlock + 1)); + tempBlock = grid->getBlock(indexB + int(ind)); + if (!tempBlock) + throw UbException(UB_EXARGS, "MPIIOMigrationBECoProcessor::blocksExchange -- null block pointer!!!"); + + tempRank = tempBlock->getRank(); + + if (tempRank == rank) // no need to send data, the process already has it + { + blocksCounterRec[tempRank]++; + rawDataReceive[tempRank].push_back(double(indexB + ind)); + rawDataReceive[tempRank].insert(rawDataReceive[tempRank].end(), + pV.begin() + ind * size_t(doubleCountInBlock), + pV.begin() + ind * size_t(doubleCountInBlock) + size_t(doubleCountInBlock)); + } else // we must send data to other processes + { + blocksCounterSend[tempRank]++; + rawDataSend[tempRank].push_back(double(indexB + ind)); + rawDataSend[tempRank].insert(rawDataSend[tempRank].end(), pV.begin() + ind * size_t(doubleCountInBlock), + pV.begin() + ind * size_t(doubleCountInBlock) + size_t(doubleCountInBlock)); + } } - requestCount = 0; - int sendRecCount = 0; - size_t sendRecOffset = 0; - const int maxQuant = 400; - int restQuant; + MPI_Request *requests = new MPI_Request[size * 2]; // send + receive + int requestCount = 0; + // MPI_Status status; - for (int r = 0; r < size; r++) - { - if (r != rank) - { - sendRecCount = int(blocksCounterRec[r] / maxQuant); - if(sendRecCount * maxQuant < blocksCounterRec[r]) - sendRecCount++; - requests = (MPI_Request*)realloc(requests, (requestCount + sendRecCount) * sizeof(MPI_Request)); - - for(int sc = 0; sc < sendRecCount; sc++) - { - restQuant = (sc < sendRecCount - 1) ? maxQuant : blocksCounterRec[r] - sc * maxQuant; - sendRecOffset = size_t(sc) * size_t(maxQuant) * size_t((doubleCountInBlock + 1)); - MPI_Irecv(&rawDataReceive[r][sendRecOffset], restQuant, sendBlockDoubleType, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } + for (int r = 0; r < size; r++) { + if (r != rank) { + MPI_Irecv(&blocksCounterRec[r], 1, MPI_INT, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); + requestCount++; + } } - for (int r = 0; r < size; r++) - { - if (r != rank) - { - sendRecCount = int(blocksCounterSend[r] / maxQuant); - if(sendRecCount * maxQuant < blocksCounterSend[r]) - sendRecCount++; - requests = (MPI_Request*)realloc(requests, (requestCount + sendRecCount) * sizeof(MPI_Request)); - - for(int sc = 0; sc < sendRecCount; sc++) - { - restQuant = (sc < sendRecCount - 1) ? maxQuant : blocksCounterSend[r] - sc * maxQuant; - sendRecOffset = size_t(sc) * size_t(maxQuant) * size_t((doubleCountInBlock + 1)); - MPI_Isend(&rawDataSend[r][sendRecOffset], restQuant, sendBlockDoubleType, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } + for (int r = 0; r < size; r++) { + if (r != rank) { + MPI_Isend(&blocksCounterSend[r], 1, MPI_INT, r, tagN, MPI_COMM_WORLD, &requests[requestCount]); + requestCount++; + } } - MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); + MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); - delete [] blocksCounterSend; - delete [] blocksCounterRec; - delete [] rawDataSend; - delete [] requests; + MPI_Type_contiguous(doubleCountInBlock + 1, MPI_DOUBLE, &sendBlockDoubleType); + MPI_Type_commit(&sendBlockDoubleType); + for (int r = 0; r < size; r++) { + if (r != rank) + rawDataReceive[r].resize(size_t(blocksCounterRec[r]) * size_t(doubleCountInBlock + 1)); + } + + requestCount = 0; + int sendRecCount = 0; + size_t sendRecOffset = 0; + const int maxQuant = 400; + int restQuant; + + for (int r = 0; r < size; r++) { + if (r != rank) { + sendRecCount = int(blocksCounterRec[r] / maxQuant); + if (sendRecCount * maxQuant < blocksCounterRec[r]) + sendRecCount++; + requests = (MPI_Request *)realloc(requests, (requestCount + sendRecCount) * sizeof(MPI_Request)); + + for (int sc = 0; sc < sendRecCount; sc++) { + restQuant = (sc < sendRecCount - 1) ? maxQuant : blocksCounterRec[r] - sc * maxQuant; + sendRecOffset = size_t(sc) * size_t(maxQuant) * size_t((doubleCountInBlock + 1)); + MPI_Irecv(&rawDataReceive[r][sendRecOffset], restQuant, sendBlockDoubleType, r, tagN, MPI_COMM_WORLD, + &requests[requestCount]); + requestCount++; + } + } + } + + for (int r = 0; r < size; r++) { + if (r != rank) { + sendRecCount = int(blocksCounterSend[r] / maxQuant); + if (sendRecCount * maxQuant < blocksCounterSend[r]) + sendRecCount++; + requests = (MPI_Request *)realloc(requests, (requestCount + sendRecCount) * sizeof(MPI_Request)); + + for (int sc = 0; sc < sendRecCount; sc++) { + restQuant = (sc < sendRecCount - 1) ? maxQuant : blocksCounterSend[r] - sc * maxQuant; + sendRecOffset = size_t(sc) * size_t(maxQuant) * size_t((doubleCountInBlock + 1)); + MPI_Isend(&rawDataSend[r][sendRecOffset], restQuant, sendBlockDoubleType, r, tagN, MPI_COMM_WORLD, + &requests[requestCount]); + requestCount++; + } + } + } + + MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); + + delete[] blocksCounterSend; + delete[] blocksCounterRec; + delete[] rawDataSend; + delete[] requests; } void MPIIOMigrationBECoProcessor::readDataSet(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (!lbmKernel) - UB_THROW(UbException(UB_EXARGS, "lbmKernel does not exist!")); - if (!bcProcessor) - UB_THROW(UbException(UB_EXARGS, "bcProcessor does not exist!")); - if (nue == -999.999) - UB_THROW(UbException(UB_EXARGS, "nue is not initialised!")); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - - int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid - int blocksPerProcess = blocksCountAll / size; // how many blocks has each process - - size_t myBlocksCount; - if (rank < (size - 1)) - myBlocksCount = blocksPerProcess; - else - myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); - - int indexB = rank * blocksPerProcess; // the first "my" block - int indexE = indexB + int(myBlocksCount); // the latest "my" block - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - - size_t doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - std::vector<double> doubleValuesArray(myBlocksCount * doubleCountInBlock); // double-values in all blocks - - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - MPI_Offset read_offset = (MPI_Offset)(3 * sizeof(dataSetParam)) + (MPI_Offset)(indexB * doubleCountInBlock * sizeof(double)); - MPI_File_read_at(file_handler, read_offset, &doubleValuesArray[0], int(myBlocksCount), dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start of exchange of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - std::vector<double>* rawDataReceive = new std::vector<double>[size]; - for (int r = 0; r < size; r++) - rawDataReceive[r].resize(0); - - blocksExchange(MESSAGE_TAG, indexB, indexE, int(doubleCountInBlock), doubleValuesArray, rawDataReceive); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - //-------------------------------------- restore blocks --------------------------------- - int blockID; - std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; - - size_t vectorSize1 = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; - size_t vectorSize2 = dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; - size_t vectorSize3 = dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - - size_t index; - for (int r = 0; r < size; r++) - { - index = 0; - for (int ii = 0; ii < int(rawDataReceive[r].size() / doubleCountInBlock); ii++) - { - blockID = (int)(rawDataReceive[r][index]); - index += 1; - - vectorsOfValues1.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize1); - index += vectorSize1; - - vectorsOfValues2.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize2); - index += vectorSize2; - - vectorsOfValues3.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize3); - index += vectorSize3; - - SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], dataSetParamStr1.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], dataSetParamStr2.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); - - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(blockID); - this->lbmKernel->setBlock(block); - SPtr<LBMKernel> kernel = this->lbmKernel->clone(); - LBMReal collFactor = LBMSystem::calcCollisionFactor(this->nue, block->getLevel()); - kernel->setCollisionFactor(collFactor); - kernel->setIndex(block->getX1(), block->getX2(), block->getX3()); - kernel->setDeltaT(LBMSystem::getDeltaT(block->getLevel())); - SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); - dataSetPtr->setFdistributions(mFdistributions); - kernel->setDataSet(dataSetPtr); - block->setKernel(kernel); - } - } - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - //------------------------------------------------------------- - - DSArraysPresence arrPresence; - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); - if (rc != MPI_SUCCESS) return;// throw UbException(UB_EXARGS, "couldn't open file " + filename1); - - MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler1); - - if (arrPresence.isAverageDensityArrayPresent) - readArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); - //readAverageDensityArray(step); - - if (arrPresence.isAverageVelocityArrayPresent) - readArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); - // readAverageVelocityArray(step); - - if (arrPresence.isAverageFluktuationsArrayPresent) - readArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); - // readAverageFluktuationsArray(step); - - if (arrPresence.isAverageTripleArrayPresent) - readArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); - // readAverageTripleArray(step); - - if (arrPresence.isShearStressValArrayPresent) - readArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); - // readShearStressValArray(step); - - if (arrPresence.isRelaxationFactorPresent) - readArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); - // readRelaxationFactor(step); - - delete [] rawDataReceive; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (!lbmKernel) + UB_THROW(UbException(UB_EXARGS, "lbmKernel does not exist!")); + if (!bcProcessor) + UB_THROW(UbException(UB_EXARGS, "bcProcessor does not exist!")); + if (nue == -999.999) + UB_THROW(UbException(UB_EXARGS, "nue is not initialised!")); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + + int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid + int blocksPerProcess = blocksCountAll / size; // how many blocks has each process + + size_t myBlocksCount; + if (rank < (size - 1)) + myBlocksCount = blocksPerProcess; + else + myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); + + int indexB = rank * blocksPerProcess; // the first "my" block + int indexE = indexB + int(myBlocksCount); // the latest "my" block + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + size_t doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + std::vector<double> doubleValuesArray(myBlocksCount * doubleCountInBlock); // double-values in all blocks + + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + MPI_Offset read_offset = + (MPI_Offset)(3 * sizeof(dataSetParam)) + (MPI_Offset)(indexB * doubleCountInBlock * sizeof(double)); + MPI_File_read_at(file_handler, read_offset, &doubleValuesArray[0], int(myBlocksCount), dataSetDoubleType, + MPI_STATUS_IGNORE); + + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start of exchange of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + std::vector<double> *rawDataReceive = new std::vector<double>[size]; + for (int r = 0; r < size; r++) + rawDataReceive[r].resize(0); + + blocksExchange(MESSAGE_TAG, indexB, indexE, int(doubleCountInBlock), doubleValuesArray, rawDataReceive); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + //-------------------------------------- restore blocks --------------------------------- + int blockID; + std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; + + size_t vectorSize1 = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; + size_t vectorSize2 = + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; + size_t vectorSize3 = + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + + size_t index; + for (int r = 0; r < size; r++) { + index = 0; + for (int ii = 0; ii < int(rawDataReceive[r].size() / doubleCountInBlock); ii++) { + blockID = (int)(rawDataReceive[r][index]); + index += 1; + + vectorsOfValues1.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize1); + index += vectorSize1; + + vectorsOfValues2.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize2); + index += vectorSize2; + + vectorsOfValues3.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + vectorSize3); + index += vectorSize3; + + SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], + dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], + dataSetParamStr1.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], + dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], + dataSetParamStr2.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setZeroDistributions( + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); + + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(blockID); + this->lbmKernel->setBlock(block); + SPtr<LBMKernel> kernel = this->lbmKernel->clone(); + LBMReal collFactor = LBMSystem::calcCollisionFactor(this->nue, block->getLevel()); + kernel->setCollisionFactor(collFactor); + kernel->setIndex(block->getX1(), block->getX2(), block->getX3()); + kernel->setDeltaT(LBMSystem::getDeltaT(block->getLevel())); + SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); + dataSetPtr->setFdistributions(mFdistributions); + kernel->setDataSet(dataSetPtr); + block->setKernel(kernel); + } + } + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readDataSet end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + //------------------------------------------------------------- + + DSArraysPresence arrPresence; + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); + if (rc != MPI_SUCCESS) + return; // throw UbException(UB_EXARGS, "couldn't open file " + filename1); + + MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + readArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); + // readAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + readArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); + // readAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + readArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); + // readAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + readArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); + // readAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + readArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); + // readShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + readArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); + // readRelaxationFactor(step); + + delete[] rawDataReceive; } void MPIIOMigrationBECoProcessor::readArray(int step, Arrays arrType, std::string fname) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - dataSetParam dataSetParamStr; - memset(&dataSetParamStr, 0, sizeof(dataSetParam)); - - int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid - int blocksPerProcess = blocksCountAll / size; // how many blocks has each process - - size_t myBlocksCount; - if (rank < (size - 1)) - myBlocksCount = blocksPerProcess; - else - myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); - - int indexB = rank * blocksPerProcess; // the first "my" block - int indexE = indexB + int(myBlocksCount); // the latest "my" block - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(myBlocksCount * doubleCountInBlock); // double-values in all blocks - - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - MPI_Offset read_offset = (MPI_Offset)(sizeof(dataSetParam)) + (MPI_Offset)(indexB) * (MPI_Offset)(doubleCountInBlock) * (MPI_Offset)(sizeof(double)); - MPI_File_read_at(file_handler, read_offset, &doubleValuesArray[0], int(myBlocksCount), dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start of exchange of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - std::vector<double>* rawDataReceive = new std::vector<double>[size]; - for (int r = 0; r < size; r++) - rawDataReceive[r].resize(0); - - blocksExchange(MESSAGE_TAG + int(arrType), indexB, indexE, int(doubleCountInBlock), doubleValuesArray, rawDataReceive); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray end of exchange of data, rank = " << rank); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - //----------------------------- restore data --------------------------------- - int blockID; - std::vector<double> vectorsOfValues; - size_t index; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - for (int r = 0; r < size; r++) - { - index = 0; - for (int ii = 0; ii < int(rawDataReceive[r].size() / doubleCountInBlock); ii++) - { - blockID = (int)(rawDataReceive[r][index]); - SPtr<Block3D> block = grid->getBlock(blockID); - index += 1; - - vectorsOfValues.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + nextVectorSize); - index += nextVectorSize; - - // fill arrays - SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___4DArray; - SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___3DArray; - - switch (arrType) { - case AverageDensity: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageDensity(___4DArray); - break; - case AverageVelocity: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageVelocity(___4DArray); - break; - case AverageFluktuations: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageFluctuations(___4DArray); - break; - case AverageTriple: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageTriplecorrelations(___4DArray); - break; - case ShearStressVal: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setShearStressValues(___4DArray); - break; - case RelaxationFactor: - ___3DArray = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); - block->getKernel()->getDataSet()->setRelaxationFactor(___3DArray); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationBECoProcessor::readArray : array type does not exist!")); - break; - } - } - } - - delete [] rawDataReceive; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + dataSetParam dataSetParamStr; + memset(&dataSetParamStr, 0, sizeof(dataSetParam)); + + int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid + int blocksPerProcess = blocksCountAll / size; // how many blocks has each process + + size_t myBlocksCount; + if (rank < (size - 1)) + myBlocksCount = blocksPerProcess; + else + myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); + + int indexB = rank * blocksPerProcess; // the first "my" block + int indexE = indexB + int(myBlocksCount); // the latest "my" block + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + + size_t doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(myBlocksCount * doubleCountInBlock); // double-values in all blocks + + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + MPI_Offset read_offset = (MPI_Offset)(sizeof(dataSetParam)) + + (MPI_Offset)(indexB) * (MPI_Offset)(doubleCountInBlock) * (MPI_Offset)(sizeof(double)); + MPI_File_read_at(file_handler, read_offset, &doubleValuesArray[0], int(myBlocksCount), dataSetDoubleType, + MPI_STATUS_IGNORE); + + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start of exchange of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + std::vector<double> *rawDataReceive = new std::vector<double>[size]; + for (int r = 0; r < size; r++) + rawDataReceive[r].resize(0); + + blocksExchange(MESSAGE_TAG + int(arrType), indexB, indexE, int(doubleCountInBlock), doubleValuesArray, + rawDataReceive); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray end of exchange of data, rank = " << rank); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + //----------------------------- restore data --------------------------------- + int blockID; + std::vector<double> vectorsOfValues; + size_t index; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + for (int r = 0; r < size; r++) { + index = 0; + for (int ii = 0; ii < int(rawDataReceive[r].size() / doubleCountInBlock); ii++) { + blockID = (int)(rawDataReceive[r][index]); + SPtr<Block3D> block = grid->getBlock(blockID); + index += 1; + + vectorsOfValues.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + nextVectorSize); + index += nextVectorSize; + + // fill arrays + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___4DArray; + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___3DArray; + + switch (arrType) { + case AverageDensity: + ___4DArray = + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageDensity(___4DArray); + break; + case AverageVelocity: + ___4DArray = + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageVelocity(___4DArray); + break; + case AverageFluktuations: + ___4DArray = + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageFluctuations(___4DArray); + break; + case AverageTriple: + ___4DArray = + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageTriplecorrelations(___4DArray); + break; + case ShearStressVal: + ___4DArray = + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setShearStressValues(___4DArray); + break; + case RelaxationFactor: + ___3DArray = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); + block->getKernel()->getDataSet()->setRelaxationFactor(___3DArray); + break; + default: + UB_THROW( + UbException(UB_EXARGS, "MPIIOMigrationBECoProcessor::readArray : array type does not exist!")); + break; + } + } + } + + delete[] rawDataReceive; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } } void MPIIOMigrationBECoProcessor::readBoundaryConds(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid - size_t myBlocksCount; - int blocksPerProcess = blocksCountAll / size; // how many blocks has each process - - if (rank < (size - 1)) - myBlocksCount = blocksPerProcess; - else - myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); - - int indexB = rank * blocksPerProcess; // the first "my" block - int indexE = indexB + int(myBlocksCount); // the latest "my" block - - std::vector<int> bcindexmatrixVAll; - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - int sizeOfBIM; - MPI_File_read_at(file_handler, (MPI_Offset)0, &sizeOfBIM, 1, MPI_INT, MPI_STATUS_IGNORE); - bcindexmatrixVAll.resize(myBlocksCount * sizeOfBIM); - - MPI_Type_contiguous(sizeOfBIM, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - MPI_Offset read_offset = (MPI_Offset)(sizeof(int)) + (MPI_Offset)(indexB) * (MPI_Offset)(sizeOfBIM) * (MPI_Offset)(sizeof(int)); - MPI_File_read_at(file_handler, read_offset, &bcindexmatrixVAll[0], int(myBlocksCount), bcindexmatrixType, MPI_STATUS_IGNORE); - - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start of exchange of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - std::vector<int>* rawDataReceive = new std::vector<int>[size]; - std::vector<int>* rawDataSend = new std::vector<int>[size]; - for (int r = 0; r < size; r++) - { - rawDataReceive[r].resize(0); - rawDataSend[r].resize(0); - rawDataReceive[r].push_back(0); - rawDataSend[r].push_back(0); - } - - SPtr<Block3D> tempBlock; - int tempRank; - for (int ind = indexB - indexB; ind < indexE - indexB; ind++) // FIXME: both sides of operator are equivalent - { - tempBlock = grid->getBlock(indexB + ind); - tempRank = tempBlock->getRank(); - - if (tempRank == rank) // no need to send data, the process already has it - { - rawDataReceive[tempRank][0]++; - rawDataReceive[tempRank].push_back(indexB + ind); - rawDataReceive[tempRank].insert(rawDataReceive[tempRank].end(), bcindexmatrixVAll.begin() + ind * sizeOfBIM, - bcindexmatrixVAll.begin() + ind * sizeOfBIM + sizeOfBIM); - } - else // we must send data to other processes - { - rawDataSend[tempRank][0]++; - rawDataSend[tempRank].push_back(indexB + ind); - rawDataSend[tempRank].insert(rawDataSend[tempRank].end(), bcindexmatrixVAll.begin() + ind * sizeOfBIM, - bcindexmatrixVAll.begin() + ind * sizeOfBIM + sizeOfBIM); - } - } - - MPI_Request* requests = new MPI_Request[size * 2]; // send + receive - int requestCount = 0; - MPI_Status status; - int quant; - int intBlockCount; - int rds; - - for (int r = 0; r < size; r++) - { - if (r != rank) - { - rds = int(rawDataSend[r].size()); - intBlockCount = (int)(rds / SEND_BLOCK_SIZE); - if (intBlockCount * SEND_BLOCK_SIZE < rds) - intBlockCount += 1; - - for (int i = rds; i < intBlockCount * SEND_BLOCK_SIZE; i++) - rawDataSend[r].push_back(0); - - MPI_Isend(&rawDataSend[r][0], intBlockCount, sendBlockIntType, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, &requests[requestCount]); - //MPI_Isend(&rawDataSend[r][0], rawDataSend[r].size(), MPI_INT, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } - - for (int r = 0; r < size; r++) - { - if (r != rank) - { - MPI_Probe(r, MESSAGE_TAG + 7, MPI_COMM_WORLD, &status); - MPI_Get_count(&status, sendBlockIntType, &quant); - rawDataReceive[r].resize(quant * SEND_BLOCK_SIZE); - MPI_Irecv(&rawDataReceive[r][0], quant, sendBlockIntType, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, &requests[requestCount]); - requestCount++; - } - } - - MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); - -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds end of exchange of data, rank = " << rank); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_File_read_at(file_handler, (MPI_Offset)0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); - - int blockID; - size_t index; - MPI_Offset read_offset1, read_offset2; - - BCAddMigration bcAddArray; - BoundaryCondition* nullBouCond = new BoundaryCondition(); - memset(nullBouCond, 0, sizeof(BoundaryCondition)); - BoundaryCondition* bcArray; - std::vector<SPtr<BoundaryConditions>> bcVector; - std::vector<int> indexContainerV; - std::vector<int> bcindexmatrixV; - - for (int r = 0; r < size; r++) - { - index = 1; - - for (int ii = 0; ii < rawDataReceive[r][0]; ii++) - { - blockID = (int)(rawDataReceive[r][index]); - index += 1; - - bcindexmatrixV.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + sizeOfBIM); - index += sizeOfBIM; - - read_offset1 = (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(blockID) * (MPI_Offset)(sizeof(size_t)); - - MPI_File_read_at(file_handler, read_offset1, &read_offset2, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, read_offset2, &bcAddArray, 3, MPI_INT, MPI_STATUS_IGNORE); - - bcArray = new BoundaryCondition[bcAddArray.boundCond_count]; - indexContainerV.resize(bcAddArray.indexContainer_count); - - if (bcAddArray.boundCond_count > 0) - MPI_File_read_at(file_handler, read_offset2 + (MPI_Offset)(sizeof(BCAddMigration)), &bcArray[0], bcAddArray.boundCond_count, boundCondType, MPI_STATUS_IGNORE); - - if (bcAddArray.indexContainer_count > 0) - MPI_File_read_at(file_handler, read_offset2 + (MPI_Offset)(sizeof(BCAddMigration)) + (MPI_Offset)(bcAddArray.boundCond_count) * (MPI_Offset)(sizeof(BoundaryCondition)), - &indexContainerV[0], bcAddArray.indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - - bcVector.resize(0); - - for (size_t ibc = 0; ibc<bcAddArray.boundCond_count; ibc++) - { - SPtr<BoundaryConditions> bc; - if (memcmp(&bcArray[ibc], nullBouCond, sizeof(BoundaryCondition)) == 0) - bc = SPtr<BoundaryConditions>(); - else - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions); - bc->noslipBoundaryFlags = bcArray[ibc].noslipBoundaryFlags; - bc->slipBoundaryFlags = bcArray[ibc].slipBoundaryFlags; - bc->densityBoundaryFlags = bcArray[ibc].densityBoundaryFlags; - bc->velocityBoundaryFlags = bcArray[ibc].velocityBoundaryFlags; - bc->wallModelBoundaryFlags = bcArray[ibc].wallModelBoundaryFlags; - bc->bcVelocityX1 = bcArray[ibc].bcVelocityX1; - bc->bcVelocityX2 = bcArray[ibc].bcVelocityX2; - bc->bcVelocityX3 = bcArray[ibc].bcVelocityX3; - bc->bcDensity = bcArray[ibc].bcDensity; - bc->bcLodiDensity = bcArray[ibc].bcLodiDensity; - bc->bcLodiVelocityX1 = bcArray[ibc].bcLodiVelocityX1; - bc->bcLodiVelocityX2 = bcArray[ibc].bcLodiVelocityX2; - bc->bcLodiVelocityX3 = bcArray[ibc].bcLodiVelocityX3; - bc->bcLodiLentgh = bcArray[ibc].bcLodiLentgh; - - bc->nx1 = bcArray[ibc].nx1; - bc->nx2 = bcArray[ibc].nx2; - bc->nx3 = bcArray[ibc].nx3; - for (int iq = 0; iq<26; iq++) - bc->setQ(bcArray[ibc].q[iq], iq); - bc->setBcAlgorithmType(bcArray[ibc].algorithmType); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + int blocksCountAll = grid->getNumberOfBlocks(); // quantity of all blocks in the grid + size_t myBlocksCount; + int blocksPerProcess = blocksCountAll / size; // how many blocks has each process + + if (rank < (size - 1)) + myBlocksCount = blocksPerProcess; + else + myBlocksCount = blocksPerProcess + (blocksCountAll - blocksPerProcess * size); + + int indexB = rank * blocksPerProcess; // the first "my" block + int indexE = indexB + int(myBlocksCount); // the latest "my" block + + std::vector<int> bcindexmatrixVAll; + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC1.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + int sizeOfBIM; + MPI_File_read_at(file_handler, (MPI_Offset)0, &sizeOfBIM, 1, MPI_INT, MPI_STATUS_IGNORE); + bcindexmatrixVAll.resize(myBlocksCount * sizeOfBIM); + + MPI_Type_contiguous(sizeOfBIM, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); + + MPI_Offset read_offset = + (MPI_Offset)(sizeof(int)) + (MPI_Offset)(indexB) * (MPI_Offset)(sizeOfBIM) * (MPI_Offset)(sizeof(int)); + MPI_File_read_at(file_handler, read_offset, &bcindexmatrixVAll[0], int(myBlocksCount), bcindexmatrixType, + MPI_STATUS_IGNORE); + + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start of exchange of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + std::vector<int> *rawDataReceive = new std::vector<int>[size]; + std::vector<int> *rawDataSend = new std::vector<int>[size]; + for (int r = 0; r < size; r++) { + rawDataReceive[r].resize(0); + rawDataSend[r].resize(0); + rawDataReceive[r].push_back(0); + rawDataSend[r].push_back(0); + } + + SPtr<Block3D> tempBlock; + int tempRank; + for (int ind = indexB - indexB; ind < indexE - indexB; ind++) // FIXME: both sides of operator are equivalent + { + tempBlock = grid->getBlock(indexB + ind); + tempRank = tempBlock->getRank(); + + if (tempRank == rank) // no need to send data, the process already has it + { + rawDataReceive[tempRank][0]++; + rawDataReceive[tempRank].push_back(indexB + ind); + rawDataReceive[tempRank].insert(rawDataReceive[tempRank].end(), bcindexmatrixVAll.begin() + ind * sizeOfBIM, + bcindexmatrixVAll.begin() + ind * sizeOfBIM + sizeOfBIM); + } else // we must send data to other processes + { + rawDataSend[tempRank][0]++; + rawDataSend[tempRank].push_back(indexB + ind); + rawDataSend[tempRank].insert(rawDataSend[tempRank].end(), bcindexmatrixVAll.begin() + ind * sizeOfBIM, + bcindexmatrixVAll.begin() + ind * sizeOfBIM + sizeOfBIM); + } + } + + MPI_Request *requests = new MPI_Request[size * 2]; // send + receive + int requestCount = 0; + MPI_Status status; + int quant; + int intBlockCount; + int rds; + + for (int r = 0; r < size; r++) { + if (r != rank) { + rds = int(rawDataSend[r].size()); + intBlockCount = (int)(rds / SEND_BLOCK_SIZE); + if (intBlockCount * SEND_BLOCK_SIZE < rds) + intBlockCount += 1; + + for (int i = rds; i < intBlockCount * SEND_BLOCK_SIZE; i++) + rawDataSend[r].push_back(0); + + MPI_Isend(&rawDataSend[r][0], intBlockCount, sendBlockIntType, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, + &requests[requestCount]); + // MPI_Isend(&rawDataSend[r][0], rawDataSend[r].size(), MPI_INT, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, + // &requests[requestCount]); + requestCount++; + } + } + + for (int r = 0; r < size; r++) { + if (r != rank) { + MPI_Probe(r, MESSAGE_TAG + 7, MPI_COMM_WORLD, &status); + MPI_Get_count(&status, sendBlockIntType, &quant); + rawDataReceive[r].resize(quant * SEND_BLOCK_SIZE); + MPI_Irecv(&rawDataReceive[r][0], quant, sendBlockIntType, r, MESSAGE_TAG + 7, MPI_COMM_WORLD, + &requests[requestCount]); + requestCount++; + } + } + + MPI_Waitall(requestCount, &requests[0], MPI_STATUSES_IGNORE); + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds end of exchange of data, rank = " << rank); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC2.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_read_at(file_handler, (MPI_Offset)0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); + + int blockID; + size_t index; + MPI_Offset read_offset1, read_offset2; + + BCAddMigration bcAddArray; + BoundaryCondition *nullBouCond = new BoundaryCondition(); + memset(nullBouCond, 0, sizeof(BoundaryCondition)); + BoundaryCondition *bcArray; + std::vector<SPtr<BoundaryConditions>> bcVector; + std::vector<int> indexContainerV; + std::vector<int> bcindexmatrixV; + + for (int r = 0; r < size; r++) { + index = 1; + + for (int ii = 0; ii < rawDataReceive[r][0]; ii++) { + blockID = (int)(rawDataReceive[r][index]); + index += 1; + + bcindexmatrixV.assign(rawDataReceive[r].data() + index, rawDataReceive[r].data() + index + sizeOfBIM); + index += sizeOfBIM; + + read_offset1 = (MPI_Offset)(sizeof(boundCondParam)) + (MPI_Offset)(blockID) * (MPI_Offset)(sizeof(size_t)); + + MPI_File_read_at(file_handler, read_offset1, &read_offset2, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, read_offset2, &bcAddArray, 3, MPI_INT, MPI_STATUS_IGNORE); + + bcArray = new BoundaryCondition[bcAddArray.boundCond_count]; + indexContainerV.resize(bcAddArray.indexContainer_count); + + if (bcAddArray.boundCond_count > 0) + MPI_File_read_at(file_handler, read_offset2 + (MPI_Offset)(sizeof(BCAddMigration)), &bcArray[0], + bcAddArray.boundCond_count, boundCondType, MPI_STATUS_IGNORE); + + if (bcAddArray.indexContainer_count > 0) + MPI_File_read_at(file_handler, + read_offset2 + (MPI_Offset)(sizeof(BCAddMigration)) + + (MPI_Offset)(bcAddArray.boundCond_count) * (MPI_Offset)(sizeof(BoundaryCondition)), + &indexContainerV[0], bcAddArray.indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); + + bcVector.resize(0); + + for (size_t ibc = 0; ibc < bcAddArray.boundCond_count; ibc++) { + SPtr<BoundaryConditions> bc; + if (memcmp(&bcArray[ibc], nullBouCond, sizeof(BoundaryCondition)) == 0) + bc = SPtr<BoundaryConditions>(); + else { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + bc->noslipBoundaryFlags = bcArray[ibc].noslipBoundaryFlags; + bc->slipBoundaryFlags = bcArray[ibc].slipBoundaryFlags; + bc->densityBoundaryFlags = bcArray[ibc].densityBoundaryFlags; + bc->velocityBoundaryFlags = bcArray[ibc].velocityBoundaryFlags; + bc->wallModelBoundaryFlags = bcArray[ibc].wallModelBoundaryFlags; + bc->bcVelocityX1 = bcArray[ibc].bcVelocityX1; + bc->bcVelocityX2 = bcArray[ibc].bcVelocityX2; + bc->bcVelocityX3 = bcArray[ibc].bcVelocityX3; + bc->bcDensity = bcArray[ibc].bcDensity; + bc->bcLodiDensity = bcArray[ibc].bcLodiDensity; + bc->bcLodiVelocityX1 = bcArray[ibc].bcLodiVelocityX1; + bc->bcLodiVelocityX2 = bcArray[ibc].bcLodiVelocityX2; + bc->bcLodiVelocityX3 = bcArray[ibc].bcLodiVelocityX3; + bc->bcLodiLentgh = bcArray[ibc].bcLodiLentgh; + + bc->nx1 = bcArray[ibc].nx1; + bc->nx2 = bcArray[ibc].nx2; + bc->nx3 = bcArray[ibc].nx3; + for (int iq = 0; iq < 26; iq++) + bc->setQ(bcArray[ibc].q[iq], iq); + bc->setBcAlgorithmType(bcArray[ibc].algorithmType); + } + + bcVector.push_back(bc); } - bcVector.push_back(bc); - } - - CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, boundCondParamStr.nx3); - SPtr<Block3D> block1 = grid->getBlock(blockID); - - SPtr<BCProcessor> bcProc = bcProcessor->clone(block1->getKernel()); - SPtr<BCArray3D> bcArr(new BCArray3D()); - bcArr->bcindexmatrix = bcim; - bcArr->bcvector = bcVector; - bcArr->indexContainer = indexContainerV; - bcProc->setBCArray(bcArr); - - block1->getKernel()->setBCProcessor(bcProc); - } - } - -//- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - MPI_File_close(&file_handler); - - delete nullBouCond; - if(bcArray) - delete bcArray; - delete [] rawDataReceive; - delete [] rawDataSend; - delete [] requests; - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds end of restore of data, rank = " << rank); - UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, + boundCondParamStr.nx3); + SPtr<Block3D> block1 = grid->getBlock(blockID); + + SPtr<BCProcessor> bcProc = bcProcessor->clone(block1->getKernel()); + SPtr<BCArray3D> bcArr(new BCArray3D()); + bcArr->bcindexmatrix = bcim; + bcArr->bcvector = bcVector; + bcArr->indexContainer = indexContainerV; + bcProc->setBCArray(bcArr); + + block1->getKernel()->setBCProcessor(bcProc); + } + } + + //- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + MPI_File_close(&file_handler); + + delete nullBouCond; + if (bcArray) + delete bcArray; + delete[] rawDataReceive; + delete[] rawDataSend; + delete[] requests; + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds end of restore of data, rank = " << rank); + UBLOG(logINFO, "MPIIOMigrationBECoProcessor::readBoundaryConds time: " << finish - start << " s"); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } } ////////////////////////////////////////////////////////////////////////// -void MPIIOMigrationBECoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) -{ - this->lbmKernel = kernel; -} +void MPIIOMigrationBECoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) { this->lbmKernel = kernel; } ////////////////////////////////////////////////////////////////////////// -void MPIIOMigrationBECoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) -{ - this->bcProcessor = bcProcessor; -} +void MPIIOMigrationBECoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) { this->bcProcessor = bcProcessor; } ////////////////////////////////////////////////////////////////////////// -void MPIIOMigrationBECoProcessor::setNu(double nu) -{ - this->nue = nu; -} - +void MPIIOMigrationBECoProcessor::setNu(double nu) { this->nue = nu; } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.h index 90ad1a928..5eb83b27a 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationBECoProcessor.h @@ -14,75 +14,82 @@ class Communicator; class BCProcessor; class LBMKernel; -//! \class MPIWriteBlocksBECoProcessor -//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating +//! \class MPIWriteBlocksBECoProcessor +//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating class MPIIOMigrationBECoProcessor : public MPIIOCoProcessor { - enum Arrays { AverageDensity = 1, AverageVelocity = 2, AverageFluktuations = 3, AverageTriple = 4, ShearStressVal = 5, RelaxationFactor = 6}; + enum Arrays { + AverageDensity = 1, + AverageVelocity = 2, + AverageFluktuations = 3, + AverageTriple = 4, + ShearStressVal = 5, + RelaxationFactor = 6 + }; public: + MPIIOMigrationBECoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm); + ~MPIIOMigrationBECoProcessor() override; + //! Each timestep writes the grid into the files + void process(double step) override; + //! Reads the grid from the files before grid reconstruction + void restart(int step); + //! Writes the blocks of the grid into the file cpBlocks.bin + void writeBlocks(int step); + //! Writes the datasets of the blocks into the file cpDataSet.bin + void writeDataSet(int step); + void write4DArray(int step, Arrays arrType, std::string fname); + void write3DArray(int step, Arrays arrType, std::string fname); + // void writeAverageDensityArray(int step); + // void writeAverageVelocityArray(int step); + // void writeAverageFluktuationsArray(int step); + // void writeAverageTripleArray(int step); + // void writeShearStressValArray(int step); + // void writeRelaxationFactor(int step); + //! Writes the boundary conditions of the blocks into the file cpBC.bin + void writeBoundaryConds(int step); - MPIIOMigrationBECoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm); - ~MPIIOMigrationBECoProcessor() override; - //! Each timestep writes the grid into the files - void process(double step) override; - //! Reads the grid from the files before grid reconstruction - void restart(int step); - //! Writes the blocks of the grid into the file cpBlocks.bin - void writeBlocks(int step); - //! Writes the datasets of the blocks into the file cpDataSet.bin - void writeDataSet(int step); - void write4DArray(int step, Arrays arrType, std::string fname); - void write3DArray(int step, Arrays arrType, std::string fname); - // void writeAverageDensityArray(int step); - //void writeAverageVelocityArray(int step); - //void writeAverageFluktuationsArray(int step); - //void writeAverageTripleArray(int step); - //void writeShearStressValArray(int step); - //void writeRelaxationFactor(int step); - //! Writes the boundary conditions of the blocks into the file cpBC.bin - void writeBoundaryConds(int step); + //! Reads the blocks of the grid from the file cpBlocks.bin + void readBlocks(int step); + //! Reads the datasets of the blocks from the file cpDataSet.bin + void readDataSet(int step); + void readArray(int step, Arrays arrType, std::string fname); + // void readAverageDensityArray(int step); + // void readAverageVelocityArray(int step); + // void readAverageFluktuationsArray(int step); + // void readAverageTripleArray(int step); + // void readShearStressValArray(int step); + // void readRelaxationFactor(int step); + //! Reads the boundary conditions of the blocks from the file cpBC.bin + void readBoundaryConds(int step); + //! The function sets LBMKernel + void setLBMKernel(SPtr<LBMKernel> kernel); + //! The function sets BCProcessor + void setBCProcessor(SPtr<BCProcessor> bcProcessor); + //! The function truncates the data files + void clearAllFiles(int step); + void setNu(double nu); - //! Reads the blocks of the grid from the file cpBlocks.bin - void readBlocks(int step); - //! Reads the datasets of the blocks from the file cpDataSet.bin - void readDataSet(int step); - void readArray(int step, Arrays arrType, std::string fname); -// void readAverageDensityArray(int step); -// void readAverageVelocityArray(int step); -// void readAverageFluktuationsArray(int step); -// void readAverageTripleArray(int step); -// void readShearStressValArray(int step); -// void readRelaxationFactor(int step); - //! Reads the boundary conditions of the blocks from the file cpBC.bin - void readBoundaryConds(int step); - //! The function sets LBMKernel - void setLBMKernel(SPtr<LBMKernel> kernel); - //!The function sets BCProcessor - void setBCProcessor(SPtr<BCProcessor> bcProcessor); - //!The function truncates the data files - void clearAllFiles(int step); - void setNu(double nu); - - void blocksExchange(int tagN, int ind1, int ind2, int doubleCountInBlock, std::vector<double>& pV, std::vector<double>* rawDataReceive); + void blocksExchange(int tagN, int ind1, int ind2, int doubleCountInBlock, std::vector<double> &pV, + std::vector<double> *rawDataReceive); protected: - //std::string path; - //SPtr<Communicator> comm; + // std::string path; + // SPtr<Communicator> comm; private: - //MPI_Datatype gridParamType, block3dType; -// MPI_Datatype dataSetType, dataSetSmallType; - MPI_Datatype dataSetDoubleType; -// MPI_Datatype boundCondParamType, boundCondTypeAdd; - MPI_Datatype bcindexmatrixType; - MPI_Datatype sendBlockDoubleType, sendBlockIntType; - - MPIIODataStructures::boundCondParam boundCondParamStr; - SPtr<LBMKernel> lbmKernel; - SPtr<BCProcessor> bcProcessor; - double nue; + // MPI_Datatype gridParamType, block3dType; + // MPI_Datatype dataSetType, dataSetSmallType; + MPI_Datatype dataSetDoubleType; + // MPI_Datatype boundCondParamType, boundCondTypeAdd; + MPI_Datatype bcindexmatrixType; + MPI_Datatype sendBlockDoubleType, sendBlockIntType; + MPIIODataStructures::boundCondParam boundCondParamStr; + SPtr<LBMKernel> lbmKernel; + SPtr<BCProcessor> bcProcessor; + double nue; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.cpp index e989bbf62..94c33e5ba 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.cpp @@ -1,336 +1,607 @@ #include "MPIIOMigrationCoProcessor.h" -#include "D3Q27System.h" -#include "LBMKernel.h" -#include "D3Q27EsoTwist3DSplittedVector.h" -#include <UbSystem.h> -#include <MemoryUtil.h> -#include "BoundaryConditions.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "Block3D.h" +#include "BoundaryConditions.h" +#include "Communicator.h" #include "CoordinateTransformation3D.h" +#include "D3Q27EsoTwist3DSplittedVector.h" +#include "D3Q27System.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "BCArray3D.h" -#include "Communicator.h" -#include "WbWriter.h" -#include "UbScheduler.h" #include "LBMKernel.h" -#include "BCProcessor.h" -#include "RenumberBlockVisitor.h" #include "MetisPartitioningGridVisitor.h" #include "PointerDefinitions.h" -#include "UbFileOutputASCII.h" +#include "RenumberBlockVisitor.h" #include "UbFileInputASCII.h" +#include "UbFileOutputASCII.h" +#include "UbScheduler.h" +#include "WbWriter.h" +#include <MemoryUtil.h> +#include <UbSystem.h> using namespace MPIIODataStructures; -MPIIOMigrationCoProcessor::MPIIOMigrationCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm) : MPIIOCoProcessor(grid, s, path, comm) +MPIIOMigrationCoProcessor::MPIIOMigrationCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm) + : MPIIOCoProcessor(grid, s, path, comm) { - memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); - - //------------------------- define MPI types --------------------------------- + memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); - MPI_Datatype typesDataSet[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksDataSet[3] = { 2, 2, 2 }; - MPI_Aint offsetsDatatSet[3], lbDataSet, extentDataSet; + //------------------------- define MPI types --------------------------------- - offsetsDatatSet[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbDataSet, &extentDataSet); - offsetsDatatSet[1] = blocksDataSet[0] * extentDataSet; + MPI_Datatype typesDataSet[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksDataSet[3] = { 2, 2, 2 }; + MPI_Aint offsetsDatatSet[3], lbDataSet, extentDataSet; - MPI_Type_get_extent(MPI_INT, &lbDataSet, &extentDataSet); - offsetsDatatSet[2] = offsetsDatatSet[1] + blocksDataSet[1] * extentDataSet; + offsetsDatatSet[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbDataSet, &extentDataSet); + offsetsDatatSet[1] = blocksDataSet[0] * extentDataSet; - MPI_Type_create_struct(3, blocksDataSet, offsetsDatatSet, typesDataSet, &dataSetType); - MPI_Type_commit(&dataSetType); + MPI_Type_get_extent(MPI_INT, &lbDataSet, &extentDataSet); + offsetsDatatSet[2] = offsetsDatatSet[1] + blocksDataSet[1] * extentDataSet; - //----------------------------------------------------------------------- + MPI_Type_create_struct(3, blocksDataSet, offsetsDatatSet, typesDataSet, &dataSetType); + MPI_Type_commit(&dataSetType); - MPI_Type_contiguous(1, MPI_INT, &dataSetSmallType); - MPI_Type_commit(&dataSetSmallType); + //----------------------------------------------------------------------- - //----------------------------------------------------------------------- + MPI_Type_contiguous(1, MPI_INT, &dataSetSmallType); + MPI_Type_commit(&dataSetSmallType); - MPI_Type_contiguous(4, MPI_INT, &boundCondParamType); - MPI_Type_commit(&boundCondParamType); + //----------------------------------------------------------------------- - //--------------------------------------- + MPI_Type_contiguous(4, MPI_INT, &boundCondParamType); + MPI_Type_commit(&boundCondParamType); - MPI_Type_contiguous(3, MPI_INT, &boundCondTypeAdd); - MPI_Type_commit(&boundCondTypeAdd); + //--------------------------------------- + MPI_Type_contiguous(3, MPI_INT, &boundCondTypeAdd); + MPI_Type_commit(&boundCondTypeAdd); } ////////////////////////////////////////////////////////////////////////// MPIIOMigrationCoProcessor::~MPIIOMigrationCoProcessor() { - MPI_Type_free(&dataSetType); - MPI_Type_free(&dataSetSmallType); - MPI_Type_free(&boundCondParamType); - MPI_Type_free(&boundCondTypeAdd); + MPI_Type_free(&dataSetType); + MPI_Type_free(&dataSetSmallType); + MPI_Type_free(&boundCondParamType); + MPI_Type_free(&boundCondTypeAdd); } ////////////////////////////////////////////////////////////////////////// void MPIIOMigrationCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - if (comm->isRoot()) UBLOG(logINFO, "MPIIOMigrationCoProcessor save step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Save check point - start"); - /*if (comm->isRoot())*/ clearAllFiles((int)step); - - writeBlocks((int)step); - writeDataSet((int)step); - writeBoundaryConds((int)step); - - writeCpTimeStep((int)step); - - if (comm->isRoot()) UBLOG(logINFO, "Save check point - end"); - } + if (scheduler->isDue(step)) { + if (comm->isRoot()) + UBLOG(logINFO, "MPIIOMigrationCoProcessor save step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - start"); + /*if (comm->isRoot())*/ clearAllFiles((int)step); + + writeBlocks((int)step); + writeDataSet((int)step); + writeBoundaryConds((int)step); + + writeCpTimeStep((int)step); + + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - end"); + } } void MPIIOMigrationCoProcessor::clearAllFiles(int step) { - MPI_File file_handler; - MPI_Info info = MPI_INFO_NULL; - MPI_Offset new_size = 0; + MPI_File file_handler; + MPI_Info info = MPI_INFO_NULL; + MPI_Offset new_size = 0; - MPIIOCoProcessor::clearAllFiles(step); - - UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + MPIIOCoProcessor::clearAllFiles(step); - std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc10 = MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc10 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename10); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); + UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + + std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc10 = + MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc10 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename10); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); } void MPIIOMigrationCoProcessor::writeBlocks(int step) { - grid->renumberBlockIDs(); - MPIIOCoProcessor::writeBlocks(step); + grid->renumberBlockIDs(); + MPIIOCoProcessor::writeBlocks(step); } void MPIIOMigrationCoProcessor::writeDataSet(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks, that belong to this process - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - DataSetMigration* dataSetArray = new DataSetMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks, that belong to this process + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + DataSetMigration *dataSetArray = new DataSetMigration[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + DSArraysPresence arrPresence; + bool firstBlock = true; + size_t doubleCountInBlock = 0; + int ic = 0; + SPtr<D3Q27EsoTwist3DSplittedVector> D3Q27EsoTwist3DSplittedVectorPtr; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetArray[ic].globalID = + block->getGlobalID(); // id of the block needed to find it while regenerating the grid + dataSetArray[ic].ghostLayerWidth = block->getKernel()->getGhostLayerWidth(); + dataSetArray[ic].collFactor = block->getKernel()->getCollisionFactor(); + dataSetArray[ic].deltaT = block->getKernel()->getDeltaT(); + dataSetArray[ic].compressible = block->getKernel()->getCompressible(); + dataSetArray[ic].withForcing = block->getKernel()->getWithForcing(); + + D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>( + block->getKernel()->getDataSet()->getFdistributions()); + localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); + nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); + zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); + + if (firstBlock) // && block->getKernel()) // when first (any) valid block... + { + if (localDistributions) { + dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); + dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); + dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); + dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); + } + + if (nonLocalDistributions) { + dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); + dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); + dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); + dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); + } + if (zeroDistributions) { + dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); + dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); + dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); + dataSetParamStr3.nx[3] = 1; + } + + // ... than save some parameters that are equal in all blocks + dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); + dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); + dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); + + doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> averageDensityArray = + block->getKernel()->getDataSet()->getAverageDensity(); + if (averageDensityArray) + arrPresence.isAverageDensityArrayPresent = true; + else + arrPresence.isAverageDensityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageVelocityArray3DPtr = + block->getKernel()->getDataSet()->getAverageVelocity(); + if (AverageVelocityArray3DPtr) + arrPresence.isAverageVelocityArrayPresent = true; + else + arrPresence.isAverageVelocityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageFluctArray3DPtr = + block->getKernel()->getDataSet()->getAverageFluctuations(); + if (AverageFluctArray3DPtr) + arrPresence.isAverageFluktuationsArrayPresent = true; + else + arrPresence.isAverageFluktuationsArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageTripleArray3DPtr = + block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + if (AverageTripleArray3DPtr) + arrPresence.isAverageTripleArrayPresent = true; + else + arrPresence.isAverageTripleArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ShearStressValArray3DPtr = + block->getKernel()->getDataSet()->getShearStressValues(); + if (ShearStressValArray3DPtr) + arrPresence.isShearStressValArrayPresent = true; + else + arrPresence.isShearStressValArrayPresent = false; + + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> relaxationFactor3DPtr = + block->getKernel()->getDataSet()->getRelaxationFactor(); + if (relaxationFactor3DPtr) + arrPresence.isRelaxationFactorPresent = true; + else + arrPresence.isRelaxationFactorPresent = false; + + firstBlock = false; + } - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + if (localDistributions && (dataSetParamStr1.nx[0] > 0) && (dataSetParamStr1.nx[1] > 0) && + (dataSetParamStr1.nx[2] > 0) && (dataSetParamStr1.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), + localDistributions->getDataVector().end()); + if (nonLocalDistributions && (dataSetParamStr2.nx[0] > 0) && (dataSetParamStr2.nx[1] > 0) && + (dataSetParamStr2.nx[2] > 0) && (dataSetParamStr2.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), + nonLocalDistributions->getDataVector().end()); + if (zeroDistributions && (dataSetParamStr3.nx[0] > 0) && (dataSetParamStr3.nx[1] > 0) && + (dataSetParamStr3.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), + zeroDistributions->getDataVector().end()); + + ic++; + } + } + + // register new MPI-type depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif - DSArraysPresence arrPresence; - bool firstBlock = true; - size_t doubleCountInBlock = 0; - int ic = 0; - SPtr< D3Q27EsoTwist3DSplittedVector > D3Q27EsoTwist3DSplittedVectorPtr; - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + // write to the file + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_write_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + MPI_Offset write_offset; + size_t sizeofOneDataSet = sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double); + + for (size_t nb = 0; nb < blocksCount; nb++) { + write_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + dataSetArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handler, write_offset, &dataSetArray[nb], 1, dataSetType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetMigration)), + &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + } + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet time: " << finish - start << " s"); + } + + delete[] dataSetArray; + + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_sync(file_handler1); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + write4DArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); + // writeAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + write4DArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); + // writeAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + write4DArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); + // writeAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + write4DArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); + // writeAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + write4DArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); + // writeShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + write3DArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); +} - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - dataSetArray[ic].ghostLayerWidth = block->getKernel()->getGhostLayerWidth(); - dataSetArray[ic].collFactor = block->getKernel()->getCollisionFactor(); - dataSetArray[ic].deltaT = block->getKernel()->getDeltaT(); - dataSetArray[ic].compressible = block->getKernel()->getCompressible(); - dataSetArray[ic].withForcing = block->getKernel()->getWithForcing(); - - D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(block->getKernel()->getDataSet()->getFdistributions()); - localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); - nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); - zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); - - if (firstBlock)// && block->getKernel()) // when first (any) valid block... - { - if (localDistributions) - { - dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); - dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); - dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); - dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); +void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::string fname) +{ + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallMigration *dataSetSmallArray = new DataSetSmallMigration[blocksCount]; + std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + size_t doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___Array; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].globalID = + block->getGlobalID(); // id of the block needed to find it while regenerating the grid + + switch (arrayType) { + case AverageDensity: + ___Array = block->getKernel()->getDataSet()->getAverageDensity(); + break; + case AverageVelocity: + ___Array = block->getKernel()->getDataSet()->getAverageVelocity(); + break; + case AverageFluktuations: + ___Array = block->getKernel()->getDataSet()->getAverageFluctuations(); + break; + case AverageTriple: + ___Array = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + break; + case ShearStressVal: + ___Array = block->getKernel()->getDataSet()->getShearStressValues(); + break; + default: + UB_THROW(UbException(UB_EXARGS, + "MPIIOMigrationCoProcessor::write4DArray : 4D array type does not exist!")); + break; } - if (nonLocalDistributions) - { - dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); - dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); - dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); - dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); - } - if (zeroDistributions) + if (firstBlock) // when first (any) valid block... { - dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); - dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); - dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); - dataSetParamStr3.nx[3] = 1; + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(___Array->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; } - // ... than save some parameters that are equal in all blocks - dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); - dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); - dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); - - doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); - if (averageDensityArray) - arrPresence.isAverageDensityArrayPresent = true; - else - arrPresence.isAverageDensityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); - if (AverageVelocityArray3DPtr) - arrPresence.isAverageVelocityArrayPresent = true; - else - arrPresence.isAverageVelocityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); - if (AverageFluctArray3DPtr) - arrPresence.isAverageFluktuationsArrayPresent = true; - else - arrPresence.isAverageFluktuationsArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - if (AverageTripleArray3DPtr) - arrPresence.isAverageTripleArrayPresent = true; - else - arrPresence.isAverageTripleArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); - if (ShearStressValArray3DPtr) - arrPresence.isShearStressValArrayPresent = true; - else - arrPresence.isShearStressValArrayPresent = false; - - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > relaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); - if (relaxationFactor3DPtr) - arrPresence.isRelaxationFactorPresent = true; - else - arrPresence.isRelaxationFactorPresent = false; + if (___Array && (dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), + ___Array->getDataVector().end()); - firstBlock = false; - } + ic++; + } + } - if (localDistributions && (dataSetParamStr1.nx[0]>0) && (dataSetParamStr1.nx[1]>0) && (dataSetParamStr1.nx[2]>0) && (dataSetParamStr1.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), localDistributions->getDataVector().end()); - if (nonLocalDistributions && (dataSetParamStr2.nx[0]>0) && (dataSetParamStr2.nx[1]>0) && (dataSetParamStr2.nx[2]>0) && (dataSetParamStr2.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), nonLocalDistributions->getDataVector().end()); - if (zeroDistributions && (dataSetParamStr3.nx[0]>0) && (dataSetParamStr3.nx[1]>0) && (dataSetParamStr3.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), zeroDistributions->getDataVector().end()); + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); - ic++; - } - } + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::write4DArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } - // register new MPI-type depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + MPI_Info info = MPI_INFO_NULL; - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); - MPI_Info info = MPI_INFO_NULL; -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // write to the file - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); + MPI_Offset write_offset; + size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - MPI_File_write_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); + for (size_t nb = 0; nb < blocksCount; nb++) { + write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), + &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + } - MPI_Offset write_offset; - size_t sizeofOneDataSet = sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double); + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); - for (size_t nb = 0; nb < blocksCount; nb++) - { - write_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + dataSetArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handler, write_offset, &dataSetArray[nb], 1, dataSetType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - } + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::write4DArray time: " << finish - start << " s"); + } - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); + delete[] dataSetSmallArray; +} - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeDataSet time: " << finish - start << " s"); - } +void MPIIOMigrationCoProcessor::write3DArray(int step, Arrays arrayType, std::string fname) +{ + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallMigration *dataSetSmallArray = new DataSetSmallMigration[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + size_t doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___Array; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].globalID = + block->getGlobalID(); // id of the block needed to find it while regenerating the grid + + switch (arrayType) { + case RelaxationFactor: + ___Array = block->getKernel()->getDataSet()->getRelaxationFactor(); + break; + default: + UB_THROW(UbException(UB_EXARGS, + "MPIIOMigrationCoProcessor::write3DArray : 3D array type does not exist!")); + break; + } + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); + dataSetParamStr.nx[3] = 1; + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if (___Array && (dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), + ___Array->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); - delete[] dataSetArray; + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_sync(file_handler1); - MPI_File_close(&file_handler1); + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); - if (arrPresence.isAverageDensityArrayPresent) - write4DArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); - //writeAverageDensityArray(step); + MPI_Info info = MPI_INFO_NULL; - if (arrPresence.isAverageVelocityArrayPresent) - write4DArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); - //writeAverageVelocityArray(step); +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - if (arrPresence.isAverageFluktuationsArrayPresent) - write4DArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); - //writeAverageFluktuationsArray(step); + size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - if (arrPresence.isAverageTripleArrayPresent) - write4DArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); - //writeAverageTripleArray(step); + MPI_Offset write_offset; + for (size_t nb = 0; nb < blocksCount; nb++) { + write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), + &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + } - if (arrPresence.isShearStressValArrayPresent) - write4DArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); - //writeShearStressValArray(step); + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); - if (arrPresence.isRelaxationFactorPresent) - write3DArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } -void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::string fname) +/* +void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -348,74 +619,64 @@ void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::st } DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks + std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks dataSetParam dataSetParamStr; if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } bool firstBlock = true; size_t doubleCountInBlock = 0; int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ___Array; - for (int level = minInitLevel; level <= maxInitLevel; level++) { for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - switch (arrayType) { - case AverageDensity: - ___Array = block->getKernel()->getDataSet()->getAverageDensity(); - break; - case AverageVelocity: - ___Array = block->getKernel()->getDataSet()->getAverageVelocity(); - break; - case AverageFluktuations: - ___Array = block->getKernel()->getDataSet()->getAverageFluctuations(); - break; - case AverageTriple: - ___Array = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - break; - case ShearStressVal: - ___Array = block->getKernel()->getDataSet()->getShearStressValues(); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationCoProcessor::write4DArray : 4D array type does not exist!")); - break; - } + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid + + SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray = +block->getKernel()->getDataSet()->getAverageDensity(); if (firstBlock) // when first (any) valid block... { + //if (averageDensityArray) + //{ dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(___Array->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + dataSetParamStr.nx[0] = static_cast<int>(averageDensityArray->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(averageDensityArray->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(averageDensityArray->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(averageDensityArray->getNX4()); + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; + //} + //else + // break; firstBlock = false; } - if (___Array && (dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && (dataSetParamStr.nx[3] > 0)) - doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), ___Array->getDataVector().end()); + if (averageDensityArray && (dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] +> 0) && (dataSetParamStr.nx[3] > 0)) doubleValuesArray.insert(doubleValuesArray.end(), +averageDensityArray->getDataVector().begin(), averageDensityArray->getDataVector().end()); ic++; } } // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); MPI_Type_commit(&dataSetDoubleType); if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::write4DArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; @@ -424,7 +685,7 @@ void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::st MPI_Info info = MPI_INFO_NULL; MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); @@ -438,7 +699,8 @@ void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::st { write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); } MPI_File_sync(file_handler); @@ -448,13 +710,13 @@ void MPIIOMigrationCoProcessor::write4DArray(int step, Arrays arrayType, std::st if (comm->isRoot()) { finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::write4DArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray time: " << finish - start << " s"); } delete[] dataSetSmallArray; } -void MPIIOMigrationCoProcessor::write3DArray(int step, Arrays arrayType, std::string fname) +void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -472,62 +734,64 @@ void MPIIOMigrationCoProcessor::write3DArray(int step, Arrays arrayType, std::st } DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks dataSetParam dataSetParamStr; if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } bool firstBlock = true; size_t doubleCountInBlock = 0; int ic = 0; - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > ___Array; - for (int level = minInitLevel; level <= maxInitLevel; level++) { for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - switch (arrayType) { - case RelaxationFactor: - ___Array = block->getKernel()->getDataSet()->getRelaxationFactor(); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationCoProcessor::write3DArray : 3D array type does not exist!")); - break; - } + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid + + SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr = +block->getKernel()->getDataSet()->getAverageVelocity(); if (firstBlock) // when first (any) valid block... { + //if (AverageVelocityArray3DPtr) + //{ dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(___Array->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(___Array->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(___Array->getNX3()); - dataSetParamStr.nx[3] = 1; - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + dataSetParamStr.nx[0] = static_cast<int>(AverageVelocityArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageVelocityArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageVelocityArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageVelocityArray3DPtr->getNX4()); + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; + //} + //else + // break; firstBlock = false; } - if (___Array && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), ___Array->getDataVector().begin(), ___Array->getDataVector().end()); + if (AverageVelocityArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && +(dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) doubleValuesArray.insert(doubleValuesArray.end(), +AverageVelocityArray3DPtr->getDataVector().begin(), AverageVelocityArray3DPtr->getDataVector().end()); ic++; } } // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); MPI_Type_commit(&dataSetDoubleType); if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; @@ -535,28 +799,23 @@ void MPIIOMigrationCoProcessor::write3DArray(int step, Arrays arrayType, std::st MPI_Info info = MPI_INFO_NULL; -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); // each process writes common parameters of a dataSet MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_Offset write_offset; size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - MPI_Offset write_offset; for (size_t nb = 0; nb < blocksCount; nb++) { write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); } MPI_File_sync(file_handler); @@ -566,14 +825,13 @@ void MPIIOMigrationCoProcessor::write3DArray(int step, Arrays arrayType, std::st if (comm->isRoot()) { finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::write3DArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray time: " << finish - start << " s"); } delete[] dataSetSmallArray; } -/* -void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) +void MPIIOMigrationCoProcessor::writeAverageFluktuationsArray(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -591,13 +849,14 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) } DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks dataSetParam dataSetParamStr; if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } bool firstBlock = true; @@ -607,20 +866,23 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) { for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); + SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr = +block->getKernel()->getDataSet()->getAverageFluctuations(); if (firstBlock) // when first (any) valid block... { - //if (averageDensityArray) + //if (AverageFluctArray3DPtr) //{ dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(averageDensityArray->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(averageDensityArray->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(averageDensityArray->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(averageDensityArray->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + dataSetParamStr.nx[0] = static_cast<int>(AverageFluctArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageFluctArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageFluctArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageFluctArray3DPtr->getNX4()); + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; //} //else // break; @@ -628,8 +890,9 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) firstBlock = false; } - if (averageDensityArray && (dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && (dataSetParamStr.nx[3] > 0)) - doubleValuesArray.insert(doubleValuesArray.end(), averageDensityArray->getDataVector().begin(), averageDensityArray->getDataVector().end()); + if (AverageFluctArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && +(dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) doubleValuesArray.insert(doubleValuesArray.end(), +AverageFluctArray3DPtr->getDataVector().begin(), AverageFluctArray3DPtr->getDataVector().end()); ic++; } @@ -641,17 +904,23 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); MPI_Info info = MPI_INFO_NULL; +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); @@ -665,7 +934,8 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) { write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); } MPI_File_sync(file_handler); @@ -675,13 +945,13 @@ void MPIIOMigrationCoProcessor::writeAverageDensityArray(int step) if (comm->isRoot()) { finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageDensityArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray time: " << finish - start << " s"); } delete[] dataSetSmallArray; } -void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) +void MPIIOMigrationCoProcessor::writeAverageTripleArray(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -699,13 +969,14 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) } DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks dataSetParam dataSetParamStr; if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } bool firstBlock = true; @@ -715,20 +986,23 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) { for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); + SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr = +block->getKernel()->getDataSet()->getAverageTriplecorrelations(); if (firstBlock) // when first (any) valid block... { - //if (AverageVelocityArray3DPtr) + //if (AverageTripleArray3DPtr) //{ dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageVelocityArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageVelocityArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageVelocityArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageVelocityArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + dataSetParamStr.nx[0] = static_cast<int>(AverageTripleArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageTripleArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageTripleArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageTripleArray3DPtr->getNX4()); + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; //} //else // break; @@ -736,8 +1010,9 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) firstBlock = false; } - if (AverageVelocityArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageVelocityArray3DPtr->getDataVector().begin(), AverageVelocityArray3DPtr->getDataVector().end()); + if (AverageTripleArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && +(dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) doubleValuesArray.insert(doubleValuesArray.end(), +AverageTripleArray3DPtr->getDataVector().begin(), AverageTripleArray3DPtr->getDataVector().end()); ic++; } @@ -749,8 +1024,9 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; @@ -758,8 +1034,14 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) MPI_Info info = MPI_INFO_NULL; +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif + MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); @@ -773,7 +1055,8 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) { write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); } MPI_File_sync(file_handler); @@ -783,13 +1066,13 @@ void MPIIOMigrationCoProcessor::writeAverageVelocityArray(int step) if (comm->isRoot()) { finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageVelocityArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray time: " << finish - start << " s"); } delete[] dataSetSmallArray; } -void MPIIOMigrationCoProcessor::writeAverageFluktuationsArray(int step) +void MPIIOMigrationCoProcessor::writeShearStressValArray(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); @@ -807,841 +1090,117 @@ void MPIIOMigrationCoProcessor::writeAverageFluktuationsArray(int step) } DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - size_t doubleCountInBlock = 0; - int ic = 0; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); - - if (firstBlock) // when first (any) valid block... - { - //if (AverageFluctArray3DPtr) - //{ - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageFluctArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageFluctArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageFluctArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageFluctArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - //} - //else - // break; - - firstBlock = false; - } - - if (AverageFluctArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageFluctArray3DPtr->getDataVector().begin(), AverageFluctArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - MPI_Offset write_offset; - size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - - for (size_t nb = 0; nb < blocksCount; nb++) - { - write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageFluktuationsArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; -} - -void MPIIOMigrationCoProcessor::writeAverageTripleArray(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - size_t doubleCountInBlock = 0; - int ic = 0; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - - if (firstBlock) // when first (any) valid block... - { - //if (AverageTripleArray3DPtr) - //{ - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageTripleArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageTripleArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageTripleArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageTripleArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - //} - //else - // break; - - firstBlock = false; - } - - if (AverageTripleArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageTripleArray3DPtr->getDataVector().begin(), AverageTripleArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - MPI_Offset write_offset; - size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - - for (size_t nb = 0; nb < blocksCount; nb++) - { - write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeAverageTripleArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; -} - -void MPIIOMigrationCoProcessor::writeShearStressValArray(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - size_t doubleCountInBlock = 0; - int ic = 0; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); - - if (firstBlock) // when first (any) valid block... - { - //if (ShearStressValArray3DPtr) - //{ - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(ShearStressValArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(ShearStressValArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(ShearStressValArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(ShearStressValArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - //} - //else - // break; - - firstBlock = false; - } - - if (ShearStressValArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), ShearStressValArray3DPtr->getDataVector().begin(), ShearStressValArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - MPI_Offset write_offset; - size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - - for (size_t nb = 0; nb < blocksCount; nb++) - { - write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; -} - -void MPIIOMigrationCoProcessor::writeRelaxationFactor(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - size_t doubleCountInBlock = 0; - int ic = 0; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > relaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); - - if (firstBlock) // when first (any) valid block... - { - //if (relaxationFactor3DPtr) - //{ - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(relaxationFactor3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(relaxationFactor3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(relaxationFactor3DPtr->getNX3()); - dataSetParamStr.nx[3] = 1; - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - //} - //else - // break; - - firstBlock = false; - } - - if (relaxationFactor3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), relaxationFactor3DPtr->getDataVector().begin(), relaxationFactor3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - -#ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); -#endif - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - MPI_Offset write_offset; - size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - - for (size_t nb = 0; nb < blocksCount; nb++) - { - write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; -} -*/ -void MPIIOMigrationCoProcessor::writeBoundaryConds(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - int blocksCount = 0; // quantity of blocks, that belong to this process - size_t allBytesCount = 0; // quantity of bytes, that one process writes to the file - size_t count_boundCond = 0; // how many BoundaryConditions in all blocks - int count_indexContainer = 0; // how many indexContainer-values in all blocks - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - BCAddMigration* bcAddArray = new BCAddMigration[blocksCount]; - size_t* bytesCount = new size_t[blocksCount]; // quantity of bytes, that each block writes to the file - std::vector<BoundaryCondition>* bcVector = new std::vector<BoundaryCondition>[blocksCount]; - std::vector<int>* bcindexmatrixVector = new std::vector<int>[blocksCount]; - std::vector<int>* indexContainerVector = new std::vector<int>[blocksCount]; - - bool bcindexmatrixCountNotInit = true; - int ic = 0; - SPtr<BCArray3D> bcArr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level - { - bcArr = block->getKernel()->getBCProcessor()->getBCArray(); - - bcAddArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while regenerating the grid - bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block - bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block - bytesCount[ic] = sizeof(BCAddMigration); - bcVector[ic].resize(0); - bcindexmatrixVector[ic].resize(0); - indexContainerVector[ic].resize(0); - - for (int bc = 0; bc<bcArr->getBCVectorSize(); bc++) - { - BoundaryCondition* bouCond = new BoundaryCondition(); - if (bcArr->bcvector[bc] == NULL) - { - memset(bouCond, 0, sizeof(BoundaryCondition)); - } - else - { - bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); - bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); - bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); - bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); - bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); - bouCond->bcVelocityX1 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX1(); - bouCond->bcVelocityX2 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX2(); - bouCond->bcVelocityX3 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX3(); - bouCond->bcDensity = (float) bcArr->bcvector[bc]->getBoundaryDensity(); - bouCond->bcLodiDensity = (float) bcArr->bcvector[bc]->getDensityLodiDensity(); - bouCond->bcLodiVelocityX1 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX1(); - bouCond->bcLodiVelocityX2 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX2(); - bouCond->bcLodiVelocityX3 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX3(); - bouCond->bcLodiLentgh = (float) bcArr->bcvector[bc]->getDensityLodiLength(); - bouCond->nx1 = (float) bcArr->bcvector[bc]->nx1; - bouCond->nx2 = (float) bcArr->bcvector[bc]->nx2; - bouCond->nx3 = (float) bcArr->bcvector[bc]->nx3; - for (int iq = 0; iq<26; iq++) - bouCond->q[iq] = (float) bcArr->bcvector[bc]->getQ(iq); - bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); - } - - bcVector[ic].push_back(*bouCond); - bcAddArray[ic].boundCond_count++; - count_boundCond++; - bytesCount[ic] += sizeof(BoundaryCondition); - } - - if (bcindexmatrixCountNotInit) - { - boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); - boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); - boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); - boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); - bcindexmatrixCountNotInit = false; - } - bcindexmatrixVector[ic].insert(bcindexmatrixVector[ic].begin(), bcArr->bcindexmatrix.getDataVector().begin(), bcArr->bcindexmatrix.getDataVector().end()); - bytesCount[ic] += boundCondParamStr.bcindexmatrixCount * sizeof(int); - - indexContainerVector[ic].insert(indexContainerVector[ic].begin(), bcArr->indexContainer.begin(), bcArr->indexContainer.end()); - bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); - count_indexContainer += bcAddArray[ic].indexContainer_count; - bytesCount[ic] += bcAddArray[ic].indexContainer_count * sizeof(int); - - allBytesCount += bytesCount[ic]; - - ic++; - } - } - - MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; - //MPI_Info_create (&info); - //MPI_Info_set(info,"romio_cb_write","enable"); - //MPI_Info_set(info,"cb_buffer_size","4194304"); - //MPI_Info_set(info,"striping_unit","4194304"); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset = (MPI_Offset)(sizeof(boundCondParam) + grid->getNumberOfBlocks() * sizeof(size_t)); - size_t next_file_offset = 0; - if (size > 1) - { - if (rank == 0) - { - next_file_offset = write_offset + allBytesCount; - MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_file_offset = write_offset + allBytesCount; - if (rank < size - 1) - MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_write_at(file_handler, 0, &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); - - MPI_Offset write_offsetIndex; - - for (int nb = 0; nb < blocksCount; nb++) - { - write_offsetIndex = (MPI_Offset)(sizeof(boundCondParam) + bcAddArray[nb].globalID * sizeof(size_t)); - MPI_File_write_at(file_handler, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); - - MPI_File_write_at(file_handler, write_offset, &bcAddArray[nb], 1, boundCondTypeAdd, MPI_STATUS_IGNORE); - if (bcVector[nb].size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(BCAddMigration)), &bcVector[nb][0], bcAddArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); - - if (bcindexmatrixVector[nb].size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(BCAddMigration) + bcAddArray[nb].boundCond_count * sizeof(BoundaryCondition)), - &bcindexmatrixVector[nb][0], 1, bcindexmatrixType, MPI_STATUS_IGNORE); - - if (indexContainerVector[nb].size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(BCAddMigration) + bcAddArray[nb].boundCond_count * sizeof(BoundaryCondition) + boundCondParamStr.bcindexmatrixCount * sizeof(int)), - &indexContainerVector[nb][0], bcAddArray[nb].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - - write_offset += bytesCount[nb]; - } - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds time: " << finish - start << " s"); - } - - delete[] bcAddArray; - delete[] bytesCount; - delete[] bcVector; - delete[] bcindexmatrixVector; - delete[] indexContainerVector; -} - -//------------------------------------------- READ ----------------------------------------------- -void MPIIOMigrationCoProcessor::restart(int step) -{ - if (comm->isRoot()) UBLOG(logINFO, "MPIIOMigrationCoProcessor restart step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Load check point - start"); - - readBlocks(step); - - SPtr<Grid3DVisitor> metisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, D3Q27System::BSW, MetisPartitioner::KWAY)); - grid->accept(metisVisitor); - - readDataSet(step); - readBoundaryConds(step); - - grid->setTimeStep(step); - - if (comm->isRoot()) UBLOG(logINFO, "Load check point - end"); -} - -void MPIIOMigrationCoProcessor::readBlocks(int step) -{ - MPIIOCoProcessor::readBlocks(step); -} - -void MPIIOMigrationCoProcessor::readDataSet(int step) -{ - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - size_t blocksCount = 0; // quantity of the blocks, that belong to this process - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - - // read from the grid the blocks, that belong to this process - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetMigration* dataSetArray = new DataSetMigration[blocksCount]; - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - - size_t doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - size_t ic = 0; - MPI_Offset read_offset; - size_t sizeofOneDataSet = size_t(sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double)); - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - read_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); - MPI_File_read_at(file_handler, read_offset, &dataSetArray[ic], 1, dataSetType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; - } - } - - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; if (comm->isRoot()) { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } - size_t index = 0, vectorSize = 0; - std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; - - for (int n = 0; n < blocksCount; n++) + bool firstBlock = true; + size_t doubleCountInBlock = 0; + int ic = 0; + for (int level = minInitLevel; level <= maxInitLevel; level++) { - vectorSize = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; - vectorsOfValues1.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; - - vectorSize = dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; - vectorsOfValues2.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid - vectorSize = dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - vectorsOfValues3.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; + SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr = +block->getKernel()->getDataSet()->getShearStressValues(); - SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); + if (firstBlock) // when first (any) valid block... + { + //if (ShearStressValArray3DPtr) + //{ + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(ShearStressValArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(ShearStressValArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(ShearStressValArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(ShearStressValArray3DPtr->getNX4()); + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; + //} + //else + // break; - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], dataSetParamStr1.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], dataSetParamStr2.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); + firstBlock = false; + } - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); + if (ShearStressValArray3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && +(dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) doubleValuesArray.insert(doubleValuesArray.end(), +ShearStressValArray3DPtr->getDataVector().begin(), ShearStressValArray3DPtr->getDataVector().end()); - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetArray[n].globalID); - this->lbmKernel->setBlock(block); - SPtr<LBMKernel> kernel = this->lbmKernel->clone(); - kernel->setGhostLayerWidth(dataSetArray[n].ghostLayerWidth); - kernel->setCollisionFactor(dataSetArray[n].collFactor); - kernel->setDeltaT(dataSetArray[n].deltaT); - kernel->setCompressible(dataSetArray[n].compressible); - kernel->setWithForcing(dataSetArray[n].withForcing); - SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); - dataSetPtr->setFdistributions(mFdistributions); - kernel->setDataSet(dataSetPtr); - block->setKernel(kernel); + ic++; + } } + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } - delete[] dataSetArray; + double start, finish; + if (comm->isRoot()) start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; - //------------------------------------------------------------- +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif - DSArraysPresence arrPresence; - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler1); + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - if (arrPresence.isAverageDensityArrayPresent) - readArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); - //readAverageDensityArray(step); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - if (arrPresence.isAverageVelocityArrayPresent) - readArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); - // readAverageVelocityArray(step); + MPI_Offset write_offset; + size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - if (arrPresence.isAverageFluktuationsArrayPresent) - readArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); - // readAverageFluktuationsArray(step); + for (size_t nb = 0; nb < blocksCount; nb++) + { + write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + } - if (arrPresence.isAverageTripleArrayPresent) - readArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); - // readAverageTripleArray(step); + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); - if (arrPresence.isShearStressValArrayPresent) - readArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); - // readShearStressValArray(step); + if (comm->isRoot()) + { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeShearStressValArray time: " << finish - start << " s"); + } - if (arrPresence.isRelaxationFactorPresent) - readArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); - // readRelaxationFactor(step); + delete[] dataSetSmallArray; } -void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string fname) +void MPIIOMigrationCoProcessor::writeRelaxationFactor(int step) { int rank, size; MPI_Comm_rank(MPI_COMM_WORLD, &rank); MPI_Comm_size(MPI_COMM_WORLD, &size); - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - size_t blocksCount = 0; - dataSetParam dataSetParamStr; - memset(&dataSetParamStr, 0, sizeof(dataSetParam)); + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - // read from the grid the blocks, that belong to this process std::vector<SPtr<Block3D>> blocksVector[25]; int minInitLevel = this->grid->getCoarsestInitializedLevel(); int maxInitLevel = this->grid->getFinestInitializedLevel(); @@ -1651,96 +1210,635 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string blocksCount += static_cast<int>(blocksVector[level].size()); } - MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; - size_t ic = 0; - MPI_Offset read_offset; - size_t sizeofOneDataSet = size_t(sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double)); + if (comm->isRoot()) + { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); + } + bool firstBlock = true; + size_t doubleCountInBlock = 0; + int ic = 0; for (int level = minInitLevel; level <= maxInitLevel; level++) { for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level { - read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); - MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + dataSetSmallArray[ic].globalID = block->getGlobalID(); // id of the block needed to find it while +regenerating the grid + + SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > relaxationFactor3DPtr = +block->getKernel()->getDataSet()->getRelaxationFactor(); + + if (firstBlock) // when first (any) valid block... + { + //if (relaxationFactor3DPtr) + //{ + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(relaxationFactor3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(relaxationFactor3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(relaxationFactor3DPtr->getNX3()); + dataSetParamStr.nx[3] = 1; + doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; + //} + //else + // break; + + firstBlock = false; + } + + if (relaxationFactor3DPtr && (dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && +(dataSetParamStr.nx[2]>0)) doubleValuesArray.insert(doubleValuesArray.end(), +relaxationFactor3DPtr->getDataVector().begin(), relaxationFactor3DPtr->getDataVector().end()); + ic++; } } - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); if (comm->isRoot()) { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray readArray: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } - //----------------------------- restore data --------------------------------- - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); + double start, finish; + if (comm->isRoot()) start = MPI_Wtime(); - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; + MPI_Info info = MPI_INFO_NULL; - // fill arrays - SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___4DArray; - SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___3DArray; - - switch (arrType) { - case AverageDensity: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageDensity(___4DArray); - break; - case AverageVelocity: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageVelocity(___4DArray); - break; - case AverageFluktuations: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageFluctuations(___4DArray); - break; - case AverageTriple: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setAverageTriplecorrelations(___4DArray); - break; - case ShearStressVal: - ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - block->getKernel()->getDataSet()->setShearStressValues(___4DArray); - break; - case RelaxationFactor: - ___3DArray = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); - block->getKernel()->getDataSet()->setRelaxationFactor(___3DArray); - break; - default: - UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationCoProcessor::readArray : array type does not exist!")); - break; - } +#ifdef HLRN_LUSTRE + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); +#endif + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + + MPI_Offset write_offset; + size_t sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); + + for (size_t nb = 0; nb < blocksCount; nb++) + { + write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handler, write_offset, &dataSetSmallArray[nb], 1, dataSetSmallType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[nb +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); } + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + if (comm->isRoot()) { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeRelaxationFactor time: " << finish - start << " s"); } delete[] dataSetSmallArray; } +*/ +void MPIIOMigrationCoProcessor::writeBoundaryConds(int step) +{ + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + int blocksCount = 0; // quantity of blocks, that belong to this process + size_t allBytesCount = 0; // quantity of bytes, that one process writes to the file + size_t count_boundCond = 0; // how many BoundaryConditions in all blocks + int count_indexContainer = 0; // how many indexContainer-values in all blocks + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + BCAddMigration *bcAddArray = new BCAddMigration[blocksCount]; + size_t *bytesCount = new size_t[blocksCount]; // quantity of bytes, that each block writes to the file + std::vector<BoundaryCondition> *bcVector = new std::vector<BoundaryCondition>[blocksCount]; + std::vector<int> *bcindexmatrixVector = new std::vector<int>[blocksCount]; + std::vector<int> *indexContainerVector = new std::vector<int>[blocksCount]; + + bool bcindexmatrixCountNotInit = true; + int ic = 0; + SPtr<BCArray3D> bcArr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level + { + bcArr = block->getKernel()->getBCProcessor()->getBCArray(); + + bcAddArray[ic].globalID = + block->getGlobalID(); // id of the block needed to find it while regenerating the grid + bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block + bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block + bytesCount[ic] = sizeof(BCAddMigration); + bcVector[ic].resize(0); + bcindexmatrixVector[ic].resize(0); + indexContainerVector[ic].resize(0); + + for (int bc = 0; bc < bcArr->getBCVectorSize(); bc++) { + BoundaryCondition *bouCond = new BoundaryCondition(); + if (bcArr->bcvector[bc] == NULL) { + memset(bouCond, 0, sizeof(BoundaryCondition)); + } else { + bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); + bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); + bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); + bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); + bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); + bouCond->bcVelocityX1 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX1(); + bouCond->bcVelocityX2 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX2(); + bouCond->bcVelocityX3 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX3(); + bouCond->bcDensity = (float)bcArr->bcvector[bc]->getBoundaryDensity(); + bouCond->bcLodiDensity = (float)bcArr->bcvector[bc]->getDensityLodiDensity(); + bouCond->bcLodiVelocityX1 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX1(); + bouCond->bcLodiVelocityX2 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX2(); + bouCond->bcLodiVelocityX3 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX3(); + bouCond->bcLodiLentgh = (float)bcArr->bcvector[bc]->getDensityLodiLength(); + bouCond->nx1 = (float)bcArr->bcvector[bc]->nx1; + bouCond->nx2 = (float)bcArr->bcvector[bc]->nx2; + bouCond->nx3 = (float)bcArr->bcvector[bc]->nx3; + for (int iq = 0; iq < 26; iq++) + bouCond->q[iq] = (float)bcArr->bcvector[bc]->getQ(iq); + bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); + } + + bcVector[ic].push_back(*bouCond); + bcAddArray[ic].boundCond_count++; + count_boundCond++; + bytesCount[ic] += sizeof(BoundaryCondition); + } + + if (bcindexmatrixCountNotInit) { + boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); + boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); + boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); + boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); + bcindexmatrixCountNotInit = false; + } + bcindexmatrixVector[ic].insert(bcindexmatrixVector[ic].begin(), + bcArr->bcindexmatrix.getDataVector().begin(), + bcArr->bcindexmatrix.getDataVector().end()); + bytesCount[ic] += boundCondParamStr.bcindexmatrixCount * sizeof(int); + + indexContainerVector[ic].insert(indexContainerVector[ic].begin(), bcArr->indexContainer.begin(), + bcArr->indexContainer.end()); + bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); + count_indexContainer += bcAddArray[ic].indexContainer_count; + bytesCount[ic] += bcAddArray[ic].indexContainer_count * sizeof(int); + + allBytesCount += bytesCount[ic]; + + ic++; + } + } + + MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; + // MPI_Info_create (&info); + // MPI_Info_set(info,"romio_cb_write","enable"); + // MPI_Info_set(info,"cb_buffer_size","4194304"); + // MPI_Info_set(info,"striping_unit","4194304"); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset = (MPI_Offset)(sizeof(boundCondParam) + grid->getNumberOfBlocks() * sizeof(size_t)); + size_t next_file_offset = 0; + if (size > 1) { + if (rank == 0) { + next_file_offset = write_offset + allBytesCount; + MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_file_offset = write_offset + allBytesCount; + if (rank < size - 1) + MPI_Send(&next_file_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_write_at(file_handler, 0, &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); + + MPI_Offset write_offsetIndex; + + for (int nb = 0; nb < blocksCount; nb++) { + write_offsetIndex = (MPI_Offset)(sizeof(boundCondParam) + bcAddArray[nb].globalID * sizeof(size_t)); + MPI_File_write_at(file_handler, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); + + MPI_File_write_at(file_handler, write_offset, &bcAddArray[nb], 1, boundCondTypeAdd, MPI_STATUS_IGNORE); + if (bcVector[nb].size() > 0) + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(BCAddMigration)), &bcVector[nb][0], + bcAddArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); + + if (bcindexmatrixVector[nb].size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(BCAddMigration) + + bcAddArray[nb].boundCond_count * sizeof(BoundaryCondition)), + &bcindexmatrixVector[nb][0], 1, bcindexmatrixType, MPI_STATUS_IGNORE); + + if (indexContainerVector[nb].size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(BCAddMigration) + + bcAddArray[nb].boundCond_count * sizeof(BoundaryCondition) + + boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &indexContainerVector[nb][0], bcAddArray[nb].indexContainer_count, MPI_INT, + MPI_STATUS_IGNORE); + + write_offset += bytesCount[nb]; + } + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::writeBoundaryConds time: " << finish - start << " s"); + } + + delete[] bcAddArray; + delete[] bytesCount; + delete[] bcVector; + delete[] bcindexmatrixVector; + delete[] indexContainerVector; +} + +//------------------------------------------- READ ----------------------------------------------- +void MPIIOMigrationCoProcessor::restart(int step) +{ + if (comm->isRoot()) + UBLOG(logINFO, "MPIIOMigrationCoProcessor restart step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - start"); + + readBlocks(step); + + SPtr<Grid3DVisitor> metisVisitor(new MetisPartitioningGridVisitor(comm, MetisPartitioningGridVisitor::LevelBased, + D3Q27System::BSW, MetisPartitioner::KWAY)); + grid->accept(metisVisitor); + + readDataSet(step); + readBoundaryConds(step); + + grid->setTimeStep(step); + + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - end"); +} + +void MPIIOMigrationCoProcessor::readBlocks(int step) { MPIIOCoProcessor::readBlocks(step); } + +void MPIIOMigrationCoProcessor::readDataSet(int step) +{ + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + size_t blocksCount = 0; // quantity of the blocks, that belong to this process + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + + // read from the grid the blocks, that belong to this process + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetMigration *dataSetArray = new DataSetMigration[blocksCount]; + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + size_t doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + size_t ic = 0; + MPI_Offset read_offset; + size_t sizeofOneDataSet = size_t(sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double)); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + read_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); + MPI_File_read_at(file_handler, read_offset, &dataSetArray[ic], 1, dataSetType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetMigration)), + &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + ic++; + } + } + + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0, vectorSize = 0; + std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; + + for (int n = 0; n < blocksCount; n++) { + vectorSize = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; + vectorsOfValues1.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + vectorSize = dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; + vectorsOfValues2.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + vectorSize = dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + vectorsOfValues3.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); + + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], + dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], + dataSetParamStr1.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], + dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], + dataSetParamStr2.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setZeroDistributions( + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); + + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetArray[n].globalID); + this->lbmKernel->setBlock(block); + SPtr<LBMKernel> kernel = this->lbmKernel->clone(); + kernel->setGhostLayerWidth(dataSetArray[n].ghostLayerWidth); + kernel->setCollisionFactor(dataSetArray[n].collFactor); + kernel->setDeltaT(dataSetArray[n].deltaT); + kernel->setCompressible(dataSetArray[n].compressible); + kernel->setWithForcing(dataSetArray[n].withForcing); + SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); + dataSetPtr->setFdistributions(mFdistributions); + kernel->setDataSet(dataSetPtr); + block->setKernel(kernel); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readDataSet end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetArray; + + //------------------------------------------------------------- + + DSArraysPresence arrPresence; + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + readArray(step, AverageDensity, std::string("/cpAverageDensityArray.bin")); + // readAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + readArray(step, AverageVelocity, std::string("/cpAverageVelocityArray.bin")); + // readAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + readArray(step, AverageFluktuations, std::string("/cpAverageFluktuationsArray.bin")); + // readAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + readArray(step, AverageTriple, std::string("/cpAverageTripleArray.bin")); + // readAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + readArray(step, ShearStressVal, std::string("/cpShearStressValArray.bin")); + // readShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + readArray(step, RelaxationFactor, std::string("/cpRelaxationFactor.bin")); + // readRelaxationFactor(step); +} + +void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string fname) +{ + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + fname; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + size_t blocksCount = 0; + dataSetParam dataSetParamStr; + memset(&dataSetParamStr, 0, sizeof(dataSetParam)); + + // read from the grid the blocks, that belong to this process + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + + DataSetSmallMigration *dataSetSmallArray = new DataSetSmallMigration[blocksCount]; + size_t doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + size_t ic = 0; + MPI_Offset read_offset; + size_t sizeofOneDataSet = size_t(sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double)); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); + MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), + &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); + ic++; + } + } + + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray readArray: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + //----------------------------- restore data --------------------------------- + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); + + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill arrays + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ___4DArray; + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> ___3DArray; + + switch (arrType) { + case AverageDensity: + ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageDensity(___4DArray); + break; + case AverageVelocity: + ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageVelocity(___4DArray); + break; + case AverageFluktuations: + ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageFluctuations(___4DArray); + break; + case AverageTriple: + ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setAverageTriplecorrelations(___4DArray); + break; + case ShearStressVal: + ___4DArray = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], + dataSetParamStr.nx[3])); + block->getKernel()->getDataSet()->setShearStressValues(___4DArray); + break; + case RelaxationFactor: + ___3DArray = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); + block->getKernel()->getDataSet()->setRelaxationFactor(___3DArray); + break; + default: + UB_THROW(UbException(UB_EXARGS, "MPIIOMigrationCoProcessor::readArray : array type does not exist!")); + break; + } + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; +} /*void MPIIOMigrationCoProcessor::readAverageDensityArray(int step) { @@ -1751,7 +1849,8 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageDensityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -1779,8 +1878,9 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -1796,8 +1896,8 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -1809,23 +1909,26 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageDensityArray time: " << finish - start << " s"); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageDensityArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; // fill mAverageDensity arrays SPtr<AverageValuesArray3D> mAverageDensity; - //if ((dataSetParamStr.nx[0]==0)&&(dataSetParamStr.nx[1]==0)&&(dataSetParamStr.nx[2]==0)&&(dataSetParamStr.nx[3]==0)) + //if +((dataSetParamStr.nx[0]==0)&&(dataSetParamStr.nx[1]==0)&&(dataSetParamStr.nx[2]==0)&&(dataSetParamStr.nx[3]==0)) // mAverageDensity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(); //else - mAverageDensity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + mAverageDensity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, +IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], +dataSetParamStr.nx[3])); //std::cout << "rank=" << rank << ", dataSetArray[n].globalID=" << dataSetSmallArray[n].globalID << std::endl; // find the nesessary block and fill it @@ -1836,7 +1939,8 @@ void MPIIOMigrationCoProcessor::readArray(int step, Arrays arrType, std::string if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageDensityArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -1851,7 +1955,8 @@ void MPIIOMigrationCoProcessor::readAverageVelocityArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageVelocityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -1879,8 +1984,9 @@ void MPIIOMigrationCoProcessor::readAverageVelocityArray(int step) MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -1896,8 +2002,8 @@ void MPIIOMigrationCoProcessor::readAverageVelocityArray(int step) { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -1909,23 +2015,26 @@ void MPIIOMigrationCoProcessor::readAverageVelocityArray(int step) finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageVelocityArray time: " << finish - start << " s"); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageVelocityArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; // fill mAverageVelocity array SPtr<AverageValuesArray3D> mAverageVelocity; - //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && (dataSetParamStr.nx[3] == 0)) + //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && +(dataSetParamStr.nx[3] == 0)) // mAverageVelocity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(); //else - mAverageVelocity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + mAverageVelocity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, +IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], +dataSetParamStr.nx[3])); // find the nesessary block and fill it SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); @@ -1935,7 +2044,8 @@ void MPIIOMigrationCoProcessor::readAverageVelocityArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageVelocityArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -1950,7 +2060,8 @@ void MPIIOMigrationCoProcessor::readAverageFluktuationsArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageFluktuationsArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -1978,8 +2089,9 @@ void MPIIOMigrationCoProcessor::readAverageFluktuationsArray(int step) MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -1995,8 +2107,8 @@ void MPIIOMigrationCoProcessor::readAverageFluktuationsArray(int step) { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -2007,24 +2119,27 @@ void MPIIOMigrationCoProcessor::readAverageFluktuationsArray(int step) { finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageFluktuationsArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageFluktuationsArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageFluktuationsArray start of restore of data, rank = " << +rank); UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; // fill AverageFluktuations array SPtr<AverageValuesArray3D> mAverageFluktuations; - //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && (dataSetParamStr.nx[3] == 0)) + //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && +(dataSetParamStr.nx[3] == 0)) // mAverageFluktuations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(); //else - mAverageFluktuations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + mAverageFluktuations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, +IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], +dataSetParamStr.nx[3])); // find the nesessary block and fill it SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); @@ -2034,7 +2149,8 @@ void MPIIOMigrationCoProcessor::readAverageFluktuationsArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageFluktuationsArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -2049,7 +2165,8 @@ void MPIIOMigrationCoProcessor::readAverageTripleArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageTripleArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -2077,8 +2194,9 @@ void MPIIOMigrationCoProcessor::readAverageTripleArray(int step) MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -2094,8 +2212,8 @@ void MPIIOMigrationCoProcessor::readAverageTripleArray(int step) { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -2107,23 +2225,26 @@ void MPIIOMigrationCoProcessor::readAverageTripleArray(int step) finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageTripleArray time: " << finish - start << " s"); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageTripleArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; // fill AverageTriplecorrelations array SPtr<AverageValuesArray3D> mAverageTriplecorrelations; - //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && (dataSetParamStr.nx[3] == 0)) + //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && +(dataSetParamStr.nx[3] == 0)) // mAverageTriplecorrelations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(); //else - mAverageTriplecorrelations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + mAverageTriplecorrelations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, +IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], +dataSetParamStr.nx[3])); // find the nesessary block and fill it SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); @@ -2133,7 +2254,8 @@ void MPIIOMigrationCoProcessor::readAverageTripleArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readAverageTripleArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -2148,7 +2270,8 @@ void MPIIOMigrationCoProcessor::readShearStressValArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readShearStressValArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -2176,8 +2299,9 @@ void MPIIOMigrationCoProcessor::readShearStressValArray(int step) MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -2193,8 +2317,8 @@ void MPIIOMigrationCoProcessor::readShearStressValArray(int step) { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -2206,23 +2330,26 @@ void MPIIOMigrationCoProcessor::readShearStressValArray(int step) finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readShearStressValArray time: " << finish - start << " s"); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readShearStressValArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; // fill ShearStressValuesArray array SPtr<ShearStressValuesArray3D> mShearStressValues; - //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && (dataSetParamStr.nx[3] == 0)) + //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0) && +(dataSetParamStr.nx[3] == 0)) // mShearStressValues = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(); //else - mShearStressValues = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + mShearStressValues = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, +IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], +dataSetParamStr.nx[3])); // find the nesessary block and fill it SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); @@ -2232,7 +2359,8 @@ void MPIIOMigrationCoProcessor::readShearStressValArray(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readShearStressValArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -2247,7 +2375,8 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readRelaxationFactor start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } double start, finish; if (comm->isRoot()) start = MPI_Wtime(); @@ -2275,8 +2404,9 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) MPI_File_read_at(file_handler, (MPI_Offset)0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); DataSetSmallMigration* dataSetSmallArray = new DataSetSmallMigration[blocksCount]; - size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + size_t doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all +blocks // define MPI_types depending on the block-specific information MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); @@ -2292,8 +2422,8 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) { read_offset = (MPI_Offset)(sizeof(dataSetParam) + block->getGlobalID() * sizeofOneDataSet); MPI_File_read_at(file_handler, read_offset, &dataSetSmallArray[ic], 1, dataSetSmallType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic * doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); - ic++; + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(DataSetSmallMigration)), &doubleValuesArray[ic +* doubleCountInBlock], 1, dataSetDoubleType, MPI_STATUS_IGNORE); ic++; } } @@ -2305,13 +2435,13 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) finish = MPI_Wtime(); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readRelaxationFactor time: " << finish - start << " s"); UBLOG(logINFO, "MPIIOMigrationCoProcessor::readRelaxationFactor start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) + size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * +dataSetParamStr.nx[3]; std::vector<double> vectorsOfValues; for (int n = 0; n < blocksCount; n++) { vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); index += nextVectorSize; @@ -2321,7 +2451,8 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) //if ((dataSetParamStr.nx[0] == 0) && (dataSetParamStr.nx[1] == 0) && (dataSetParamStr.nx[2] == 0)) // mRelaxationFactor = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(); //else - mRelaxationFactor = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); + mRelaxationFactor = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, +IndexerX3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); // find the nesessary block and fill it SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].globalID); @@ -2331,7 +2462,8 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) if (comm->isRoot()) { UBLOG(logINFO, "MPIIOMigrationCoProcessor::readRelaxationFactor end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / +1073741824.0 << " GB"); } delete[] dataSetSmallArray; @@ -2340,168 +2472,164 @@ void MPIIOMigrationCoProcessor::readRelaxationFactor(int step) void MPIIOMigrationCoProcessor::readBoundaryConds(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - int blocksCount = 0; // quantity of the blocks, that belong to this process - - // read from the grid the blocks, that belong to this process - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - BCAddMigration* bcAddArray = new BCAddMigration[blocksCount]; - BoundaryCondition* nullBouCond = new BoundaryCondition(); - memset(nullBouCond, 0, sizeof(BoundaryCondition)); - BoundaryCondition* bcArray; - int* intArray1; - int* intArray2; - std::vector<SPtr<BoundaryConditions>> bcVector; - std::vector<int> bcindexmatrixV; - std::vector<int> indexContainerV; - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - MPI_File_read_at(file_handler, (MPI_Offset)0, &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); - MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - int ic = 0; - MPI_Offset read_offset1, read_offset2; - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - read_offset1 = (MPI_Offset)(sizeof(boundCondParam) + block->getGlobalID() * sizeof(size_t)); - - MPI_File_read_at(file_handler, read_offset1, &read_offset2, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, read_offset2, &bcAddArray[ic], 1, boundCondTypeAdd, MPI_STATUS_IGNORE); - - bcArray = new BoundaryCondition[bcAddArray[ic].boundCond_count]; - intArray1 = new int[boundCondParamStr.bcindexmatrixCount]; - intArray2 = new int[bcAddArray[ic].indexContainer_count]; - - if (bcAddArray[ic].boundCond_count > 0) - { - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset2 + sizeof(BCAddMigration)), &bcArray[0], bcAddArray[ic].boundCond_count, boundCondType, MPI_STATUS_IGNORE); - } - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset2 + sizeof(BCAddMigration) + bcAddArray[ic].boundCond_count * sizeof(BoundaryCondition)), - &intArray1[0], 1, bcindexmatrixType, MPI_STATUS_IGNORE); - if (bcAddArray[ic].indexContainer_count > 0) - { - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset2 + sizeof(BCAddMigration) + bcAddArray[ic].boundCond_count * sizeof(BoundaryCondition) + boundCondParamStr.bcindexmatrixCount * sizeof(int)), - &intArray2[0], bcAddArray[ic].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - } - - bcindexmatrixV.resize(0); - indexContainerV.resize(0); - bcVector.resize(0); - - for (size_t ibc = 0; ibc<bcAddArray[ic].boundCond_count; ibc++) - { - SPtr<BoundaryConditions> bc; - if (memcmp(&bcArray[ibc], nullBouCond, sizeof(BoundaryCondition)) == 0) - bc = SPtr<BoundaryConditions>(); - else - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions); - bc->noslipBoundaryFlags = bcArray[ibc].noslipBoundaryFlags; - bc->slipBoundaryFlags = bcArray[ibc].slipBoundaryFlags; - bc->densityBoundaryFlags = bcArray[ibc].densityBoundaryFlags; - bc->velocityBoundaryFlags = bcArray[ibc].velocityBoundaryFlags; - bc->wallModelBoundaryFlags = bcArray[ibc].wallModelBoundaryFlags; - bc->bcVelocityX1 = bcArray[ibc].bcVelocityX1; - bc->bcVelocityX2 = bcArray[ibc].bcVelocityX2; - bc->bcVelocityX3 = bcArray[ibc].bcVelocityX3; - bc->bcDensity = bcArray[ibc].bcDensity; - bc->bcLodiDensity = bcArray[ibc].bcLodiDensity; - bc->bcLodiVelocityX1 = bcArray[ibc].bcLodiVelocityX1; - bc->bcLodiVelocityX2 = bcArray[ibc].bcLodiVelocityX2; - bc->bcLodiVelocityX3 = bcArray[ibc].bcLodiVelocityX3; - bc->bcLodiLentgh = bcArray[ibc].bcLodiLentgh; - - bc->nx1 = bcArray[ibc].nx1; - bc->nx2 = bcArray[ibc].nx2; - bc->nx3 = bcArray[ibc].nx3; - for (int iq = 0; iq<26; iq++) - bc->setQ(bcArray[ibc].q[iq], iq); - bc->setBcAlgorithmType(bcArray[ibc].algorithmType); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + int blocksCount = 0; // quantity of the blocks, that belong to this process + + // read from the grid the blocks, that belong to this process + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + BCAddMigration *bcAddArray = new BCAddMigration[blocksCount]; + BoundaryCondition *nullBouCond = new BoundaryCondition(); + memset(nullBouCond, 0, sizeof(BoundaryCondition)); + BoundaryCondition *bcArray; + int *intArray1; + int *intArray2; + std::vector<SPtr<BoundaryConditions>> bcVector; + std::vector<int> bcindexmatrixV; + std::vector<int> indexContainerV; + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + MPI_File_read_at(file_handler, (MPI_Offset)0, &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); + MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); + + int ic = 0; + MPI_Offset read_offset1, read_offset2; + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + read_offset1 = (MPI_Offset)(sizeof(boundCondParam) + block->getGlobalID() * sizeof(size_t)); + + MPI_File_read_at(file_handler, read_offset1, &read_offset2, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, read_offset2, &bcAddArray[ic], 1, boundCondTypeAdd, MPI_STATUS_IGNORE); + + bcArray = new BoundaryCondition[bcAddArray[ic].boundCond_count]; + intArray1 = new int[boundCondParamStr.bcindexmatrixCount]; + intArray2 = new int[bcAddArray[ic].indexContainer_count]; + + if (bcAddArray[ic].boundCond_count > 0) { + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset2 + sizeof(BCAddMigration)), &bcArray[0], + bcAddArray[ic].boundCond_count, boundCondType, MPI_STATUS_IGNORE); + } + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset2 + sizeof(BCAddMigration) + + bcAddArray[ic].boundCond_count * sizeof(BoundaryCondition)), + &intArray1[0], 1, bcindexmatrixType, MPI_STATUS_IGNORE); + if (bcAddArray[ic].indexContainer_count > 0) { + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset2 + sizeof(BCAddMigration) + + bcAddArray[ic].boundCond_count * sizeof(BoundaryCondition) + + boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &intArray2[0], bcAddArray[ic].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); } - bcVector.push_back(bc); - } + bcindexmatrixV.resize(0); + indexContainerV.resize(0); + bcVector.resize(0); + + for (size_t ibc = 0; ibc < bcAddArray[ic].boundCond_count; ibc++) { + SPtr<BoundaryConditions> bc; + if (memcmp(&bcArray[ibc], nullBouCond, sizeof(BoundaryCondition)) == 0) + bc = SPtr<BoundaryConditions>(); + else { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + bc->noslipBoundaryFlags = bcArray[ibc].noslipBoundaryFlags; + bc->slipBoundaryFlags = bcArray[ibc].slipBoundaryFlags; + bc->densityBoundaryFlags = bcArray[ibc].densityBoundaryFlags; + bc->velocityBoundaryFlags = bcArray[ibc].velocityBoundaryFlags; + bc->wallModelBoundaryFlags = bcArray[ibc].wallModelBoundaryFlags; + bc->bcVelocityX1 = bcArray[ibc].bcVelocityX1; + bc->bcVelocityX2 = bcArray[ibc].bcVelocityX2; + bc->bcVelocityX3 = bcArray[ibc].bcVelocityX3; + bc->bcDensity = bcArray[ibc].bcDensity; + bc->bcLodiDensity = bcArray[ibc].bcLodiDensity; + bc->bcLodiVelocityX1 = bcArray[ibc].bcLodiVelocityX1; + bc->bcLodiVelocityX2 = bcArray[ibc].bcLodiVelocityX2; + bc->bcLodiVelocityX3 = bcArray[ibc].bcLodiVelocityX3; + bc->bcLodiLentgh = bcArray[ibc].bcLodiLentgh; + + bc->nx1 = bcArray[ibc].nx1; + bc->nx2 = bcArray[ibc].nx2; + bc->nx3 = bcArray[ibc].nx3; + for (int iq = 0; iq < 26; iq++) + bc->setQ(bcArray[ibc].q[iq], iq); + bc->setBcAlgorithmType(bcArray[ibc].algorithmType); + } + + bcVector.push_back(bc); + } - for (int b1 = 0; b1 < boundCondParamStr.bcindexmatrixCount; b1++) - bcindexmatrixV.push_back(intArray1[b1]); + for (int b1 = 0; b1 < boundCondParamStr.bcindexmatrixCount; b1++) + bcindexmatrixV.push_back(intArray1[b1]); - for (int b2 = 0; b2 < bcAddArray[ic].indexContainer_count; b2++) - indexContainerV.push_back(intArray2[b2]); + for (int b2 = 0; b2 < bcAddArray[ic].indexContainer_count; b2++) + indexContainerV.push_back(intArray2[b2]); - CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, boundCondParamStr.nx3); - SPtr<Block3D> block1 = grid->getBlock(bcAddArray[ic].globalID); + CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, + boundCondParamStr.nx3); + SPtr<Block3D> block1 = grid->getBlock(bcAddArray[ic].globalID); - SPtr<BCProcessor> bcProc = bcProcessor->clone(block1->getKernel()); - SPtr<BCArray3D> bcArr(new BCArray3D()); - bcArr->bcindexmatrix = bcim; - bcArr->bcvector = bcVector; - bcArr->indexContainer = indexContainerV; - bcProc->setBCArray(bcArr); + SPtr<BCProcessor> bcProc = bcProcessor->clone(block1->getKernel()); + SPtr<BCArray3D> bcArr(new BCArray3D()); + bcArr->bcindexmatrix = bcim; + bcArr->bcvector = bcVector; + bcArr->indexContainer = indexContainerV; + bcProc->setBCArray(bcArr); - block1->getKernel()->setBCProcessor(bcProc); + block1->getKernel()->setBCProcessor(bcProc); - delete bcArray; - delete intArray1; + delete bcArray; + delete intArray1; - ic++; - } - } + ic++; + } + } - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); - delete nullBouCond; + delete nullBouCond; - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIOMigrationCoProcessor::readBoundaryConds end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } } ////////////////////////////////////////////////////////////////////////// -void MPIIOMigrationCoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) -{ - this->lbmKernel = kernel; -} +void MPIIOMigrationCoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) { this->lbmKernel = kernel; } ////////////////////////////////////////////////////////////////////////// -void MPIIOMigrationCoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) -{ - this->bcProcessor = bcProcessor; -} - +void MPIIOMigrationCoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) { this->bcProcessor = bcProcessor; } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.h index 1f0932569..428407d37 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIOMigrationCoProcessor.h @@ -13,69 +13,75 @@ class Communicator; class BCProcessor; class LBMKernel; - -//! \class MPIWriteBlocksCoProcessor -//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating +//! \class MPIWriteBlocksCoProcessor +//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating class MPIIOMigrationCoProcessor : public MPIIOCoProcessor { public: - enum Arrays { AverageDensity = 1, AverageVelocity = 2, AverageFluktuations = 3, AverageTriple = 4, ShearStressVal = 5, RelaxationFactor = 6 }; + enum Arrays { + AverageDensity = 1, + AverageVelocity = 2, + AverageFluktuations = 3, + AverageTriple = 4, + ShearStressVal = 5, + RelaxationFactor = 6 + }; - MPIIOMigrationCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm); - ~MPIIOMigrationCoProcessor() override; - //! Each timestep writes the grid into the files - void process(double step) override; - //! Reads the grid from the files before grid reconstruction - void restart(int step); - //! Writes the blocks of the grid into the file cpBlocks.bin - void writeBlocks(int step); - //! Writes the datasets of the blocks into the file cpDataSet.bin - void writeDataSet(int step); - void write4DArray(int step, Arrays arrType, std::string fname); - void write3DArray(int step, Arrays arrType, std::string fname); -// void writeAverageDensityArray(int step); -// void writeAverageVelocityArray(int step); -// void writeAverageFluktuationsArray(int step); -// void writeAverageTripleArray(int step); -// void writeShearStressValArray(int step); -// void writeRelaxationFactor(int step); - //! Writes the boundary conditions of the blocks into the file cpBC.bin - void writeBoundaryConds(int step); + MPIIOMigrationCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<Communicator> comm); + ~MPIIOMigrationCoProcessor() override; + //! Each timestep writes the grid into the files + void process(double step) override; + //! Reads the grid from the files before grid reconstruction + void restart(int step); + //! Writes the blocks of the grid into the file cpBlocks.bin + void writeBlocks(int step); + //! Writes the datasets of the blocks into the file cpDataSet.bin + void writeDataSet(int step); + void write4DArray(int step, Arrays arrType, std::string fname); + void write3DArray(int step, Arrays arrType, std::string fname); + // void writeAverageDensityArray(int step); + // void writeAverageVelocityArray(int step); + // void writeAverageFluktuationsArray(int step); + // void writeAverageTripleArray(int step); + // void writeShearStressValArray(int step); + // void writeRelaxationFactor(int step); + //! Writes the boundary conditions of the blocks into the file cpBC.bin + void writeBoundaryConds(int step); - //! Reads the blocks of the grid from the file cpBlocks.bin - void readBlocks(int step); - //! Reads the datasets of the blocks from the file cpDataSet.bin - void readDataSet(int step); - void readArray(int step, Arrays arrType, std::string fname); -// void readAverageDensityArray(int step); -// void readAverageVelocityArray(int step); -// void readAverageFluktuationsArray(int step); -// void readAverageTripleArray(int step); -// void readShearStressValArray(int step); -// void readRelaxationFactor(int step); - //! Reads the boundary conditions of the blocks from the file cpBC.bin - void readBoundaryConds(int step); - //! The function sets LBMKernel - void setLBMKernel(SPtr<LBMKernel> kernel); - //!The function sets BCProcessor - void setBCProcessor(SPtr<BCProcessor> bcProcessor); - //!The function truncates the data files - void clearAllFiles(int step); - //void setNu(double nu); + //! Reads the blocks of the grid from the file cpBlocks.bin + void readBlocks(int step); + //! Reads the datasets of the blocks from the file cpDataSet.bin + void readDataSet(int step); + void readArray(int step, Arrays arrType, std::string fname); + // void readAverageDensityArray(int step); + // void readAverageVelocityArray(int step); + // void readAverageFluktuationsArray(int step); + // void readAverageTripleArray(int step); + // void readShearStressValArray(int step); + // void readRelaxationFactor(int step); + //! Reads the boundary conditions of the blocks from the file cpBC.bin + void readBoundaryConds(int step); + //! The function sets LBMKernel + void setLBMKernel(SPtr<LBMKernel> kernel); + //! The function sets BCProcessor + void setBCProcessor(SPtr<BCProcessor> bcProcessor); + //! The function truncates the data files + void clearAllFiles(int step); + // void setNu(double nu); protected: - //std::string path; - //SPtr<Communicator> comm; + // std::string path; + // SPtr<Communicator> comm; private: - //MPI_Datatype gridParamType, block3dType; - MPI_Datatype dataSetType, dataSetSmallType, dataSetDoubleType; - MPI_Datatype boundCondParamType, boundCondTypeAdd, bcindexmatrixType; + // MPI_Datatype gridParamType, block3dType; + MPI_Datatype dataSetType, dataSetSmallType, dataSetDoubleType; + MPI_Datatype boundCondParamType, boundCondTypeAdd, bcindexmatrixType; - MPIIODataStructures::boundCondParam boundCondParamStr; - SPtr<LBMKernel> lbmKernel; - SPtr<BCProcessor> bcProcessor; - //double nue; + MPIIODataStructures::boundCondParam boundCondParamStr; + SPtr<LBMKernel> lbmKernel; + SPtr<BCProcessor> bcProcessor; + // double nue; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.cpp index b7bcb0464..abcf2bf7a 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.cpp @@ -1,2254 +1,2370 @@ #include "MPIIORestartCoProcessor.h" -#include "D3Q27System.h" -#include "LBMKernel.h" -#include "D3Q27EsoTwist3DSplittedVector.h" -#include <UbSystem.h> -#include <MemoryUtil.h> -#include "BoundaryConditions.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "Block3D.h" +#include "BoundaryConditions.h" +#include "Communicator.h" #include "CoordinateTransformation3D.h" +#include "D3Q27EsoTwist3DSplittedVector.h" +#include "D3Q27System.h" #include "DataSet3D.h" #include "Grid3D.h" #include "Grid3DSystem.h" -#include "BCArray3D.h" -#include "Communicator.h" -#include "WbWriter.h" -#include "UbScheduler.h" #include "LBMKernel.h" -#include "BCProcessor.h" -#include "UbFileOutputASCII.h" #include "UbFileInputASCII.h" +#include "UbFileOutputASCII.h" +#include "UbScheduler.h" +#include "WbWriter.h" +#include <MemoryUtil.h> +#include <UbSystem.h> //! BLOCK_SIZE defines the quantity of the BoundaryCondition-structures written as one block to the file -//! To avoid overflow in the parameter \a count of the function MPI_File_write_at +//! To avoid overflow in the parameter \a count of the function MPI_File_write_at //! structures BoundaryCondition are being written in blocks containing each of them BLOCK_SIZE structures #define BLOCK_SIZE 1024 using namespace MPIIODataStructures; -MPIIORestartCoProcessor::MPIIORestartCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm) : MPIIOCoProcessor(grid, s, path, comm) +MPIIORestartCoProcessor::MPIIORestartCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm) + : MPIIOCoProcessor(grid, s, path, comm) { - memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); + memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); - //------------------------- define MPI types --------------------------------- + //------------------------- define MPI types --------------------------------- - MPI_Datatype typesDataSet[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksDataSet[3] = { 2, 5, 2 }; - MPI_Aint offsetsDatatSet[3], lbDataSet, extentDataSet; + MPI_Datatype typesDataSet[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksDataSet[3] = { 2, 5, 2 }; + MPI_Aint offsetsDatatSet[3], lbDataSet, extentDataSet; - offsetsDatatSet[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbDataSet, &extentDataSet); - offsetsDatatSet[1] = blocksDataSet[0] * extentDataSet; + offsetsDatatSet[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbDataSet, &extentDataSet); + offsetsDatatSet[1] = blocksDataSet[0] * extentDataSet; - MPI_Type_get_extent(MPI_INT, &lbDataSet, &extentDataSet); - offsetsDatatSet[2] = offsetsDatatSet[1] + blocksDataSet[1] * extentDataSet; + MPI_Type_get_extent(MPI_INT, &lbDataSet, &extentDataSet); + offsetsDatatSet[2] = offsetsDatatSet[1] + blocksDataSet[1] * extentDataSet; - MPI_Type_create_struct(3, blocksDataSet, offsetsDatatSet, typesDataSet, &dataSetType); - MPI_Type_commit(&dataSetType); + MPI_Type_create_struct(3, blocksDataSet, offsetsDatatSet, typesDataSet, &dataSetType); + MPI_Type_commit(&dataSetType); - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- - MPI_Type_contiguous(4, MPI_INT, &dataSetSmallType); - MPI_Type_commit(&dataSetSmallType); + MPI_Type_contiguous(4, MPI_INT, &dataSetSmallType); + MPI_Type_commit(&dataSetSmallType); - //----------------------------------------------------------------------- + //----------------------------------------------------------------------- - MPI_Type_contiguous(4, MPI_INT, &boundCondParamType); - MPI_Type_commit(&boundCondParamType); + MPI_Type_contiguous(4, MPI_INT, &boundCondParamType); + MPI_Type_commit(&boundCondParamType); - //--------------------------------------- + //--------------------------------------- - MPI_Type_contiguous(BLOCK_SIZE, boundCondType, &boundCondType1000); - MPI_Type_commit(&boundCondType1000); + MPI_Type_contiguous(BLOCK_SIZE, boundCondType, &boundCondType1000); + MPI_Type_commit(&boundCondType1000); - //--------------------------------------- - - MPI_Type_contiguous(6, MPI_INT, &boundCondTypeAdd); - MPI_Type_commit(&boundCondTypeAdd); + //--------------------------------------- + MPI_Type_contiguous(6, MPI_INT, &boundCondTypeAdd); + MPI_Type_commit(&boundCondTypeAdd); } ////////////////////////////////////////////////////////////////////////// MPIIORestartCoProcessor::~MPIIORestartCoProcessor() { - MPI_Type_free(&dataSetType); - MPI_Type_free(&dataSetSmallType); - MPI_Type_free(&boundCondParamType); - MPI_Type_free(&boundCondType1000); - MPI_Type_free(&boundCondTypeAdd); + MPI_Type_free(&dataSetType); + MPI_Type_free(&dataSetSmallType); + MPI_Type_free(&boundCondParamType); + MPI_Type_free(&boundCondType1000); + MPI_Type_free(&boundCondTypeAdd); } ////////////////////////////////////////////////////////////////////////// void MPIIORestartCoProcessor::process(double step) { - if (scheduler->isDue(step)) - { - if (comm->isRoot()) UBLOG(logINFO, "MPIIORestartCoProcessor save step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Save check point - start"); - /*if (comm->isRoot())*/ clearAllFiles((int)step); - - writeBlocks((int)step); - writeDataSet((int)step); - writeBoundaryConds((int)step); - - writeCpTimeStep((int)step); - - if (comm->isRoot()) UBLOG(logINFO, "Save check point - end"); - } + if (scheduler->isDue(step)) { + if (comm->isRoot()) + UBLOG(logINFO, "MPIIORestartCoProcessor save step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - start"); + /*if (comm->isRoot())*/ clearAllFiles((int)step); + + writeBlocks((int)step); + writeDataSet((int)step); + writeBoundaryConds((int)step); + + writeCpTimeStep((int)step); + + if (comm->isRoot()) + UBLOG(logINFO, "Save check point - end"); + } } ////////////////////////////////////////////////////////////////////////// void MPIIORestartCoProcessor::clearAllFiles(int step) { - MPI_File file_handler; - MPI_Info info = MPI_INFO_NULL; - MPI_Offset new_size = 0; + MPI_File file_handler; + MPI_Info info = MPI_INFO_NULL; + MPI_Offset new_size = 0; - UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + UbSystem::makeDirectory(path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); - MPIIOCoProcessor::clearAllFiles(step); + MPIIOCoProcessor::clearAllFiles(step); - std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc10 = MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc10 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename10); - MPI_File_set_size(file_handler, new_size); - MPI_File_close(&file_handler); + std::string filename10 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc10 = + MPI_File_open(MPI_COMM_WORLD, filename10.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc10 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename10); + MPI_File_set_size(file_handler, new_size); + MPI_File_close(&file_handler); } ////////////////////////////////////////////////////////////////////////// -void MPIIORestartCoProcessor::writeBlocks(int step) -{ - MPIIOCoProcessor::writeBlocks(step); -} +void MPIIORestartCoProcessor::writeBlocks(int step) { MPIIOCoProcessor::writeBlocks(step); } void MPIIORestartCoProcessor::writeDataSet(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - DataSetRestart* dataSetArray = new DataSetRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - DSArraysPresence arrPresence; - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< D3Q27EsoTwist3DSplittedVector > D3Q27EsoTwist3DSplittedVectorPtr; - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetArray[ic].x2 = block->getX2(); - dataSetArray[ic].x3 = block->getX3(); - dataSetArray[ic].level = block->getLevel(); - dataSetArray[ic].ghostLayerWidth = block->getKernel()->getGhostLayerWidth(); - dataSetArray[ic].collFactor = block->getKernel()->getCollisionFactor(); - dataSetArray[ic].deltaT = block->getKernel()->getDeltaT(); - dataSetArray[ic].compressible = block->getKernel()->getCompressible(); - dataSetArray[ic].withForcing = block->getKernel()->getWithForcing(); - - D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(block->getKernel()->getDataSet()->getFdistributions()); - localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); - nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); - zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); - - if (firstBlock) // when first (any) valid block... - { - if (localDistributions) + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + DataSetRestart *dataSetArray = new DataSetRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + DSArraysPresence arrPresence; + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<D3Q27EsoTwist3DSplittedVector> D3Q27EsoTwist3DSplittedVectorPtr; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetArray[ic].x2 = block->getX2(); + dataSetArray[ic].x3 = block->getX3(); + dataSetArray[ic].level = block->getLevel(); + dataSetArray[ic].ghostLayerWidth = block->getKernel()->getGhostLayerWidth(); + dataSetArray[ic].collFactor = block->getKernel()->getCollisionFactor(); + dataSetArray[ic].deltaT = block->getKernel()->getDeltaT(); + dataSetArray[ic].compressible = block->getKernel()->getCompressible(); + dataSetArray[ic].withForcing = block->getKernel()->getWithForcing(); + + D3Q27EsoTwist3DSplittedVectorPtr = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>( + block->getKernel()->getDataSet()->getFdistributions()); + localDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getLocalDistributions(); + nonLocalDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getNonLocalDistributions(); + zeroDistributions = D3Q27EsoTwist3DSplittedVectorPtr->getZeroDistributions(); + + if (firstBlock) // when first (any) valid block... { - dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); - dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); - dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); - dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); - } - if (nonLocalDistributions) - { - dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); - dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); - dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); - dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); - } - if (zeroDistributions) - { - dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); - dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); - dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); - dataSetParamStr3.nx[3] = 1; + if (localDistributions) { + dataSetParamStr1.nx[0] = static_cast<int>(localDistributions->getNX1()); + dataSetParamStr1.nx[1] = static_cast<int>(localDistributions->getNX2()); + dataSetParamStr1.nx[2] = static_cast<int>(localDistributions->getNX3()); + dataSetParamStr1.nx[3] = static_cast<int>(localDistributions->getNX4()); + } + if (nonLocalDistributions) { + dataSetParamStr2.nx[0] = static_cast<int>(nonLocalDistributions->getNX1()); + dataSetParamStr2.nx[1] = static_cast<int>(nonLocalDistributions->getNX2()); + dataSetParamStr2.nx[2] = static_cast<int>(nonLocalDistributions->getNX3()); + dataSetParamStr2.nx[3] = static_cast<int>(nonLocalDistributions->getNX4()); + } + if (zeroDistributions) { + dataSetParamStr3.nx[0] = static_cast<int>(zeroDistributions->getNX1()); + dataSetParamStr3.nx[1] = static_cast<int>(zeroDistributions->getNX2()); + dataSetParamStr3.nx[2] = static_cast<int>(zeroDistributions->getNX3()); + dataSetParamStr3.nx[3] = 1; + } + + // ... than save some parameters that are equal in all dataSets + dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); + dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); + dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = + static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); + + doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> averageDensityArray = + block->getKernel()->getDataSet()->getAverageDensity(); + if (averageDensityArray) + arrPresence.isAverageDensityArrayPresent = true; + else + arrPresence.isAverageDensityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageVelocityArray3DPtr = + block->getKernel()->getDataSet()->getAverageVelocity(); + if (AverageVelocityArray3DPtr) + arrPresence.isAverageVelocityArrayPresent = true; + else + arrPresence.isAverageVelocityArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageFluctArray3DPtr = + block->getKernel()->getDataSet()->getAverageFluctuations(); + if (AverageFluctArray3DPtr) + arrPresence.isAverageFluktuationsArrayPresent = true; + else + arrPresence.isAverageFluktuationsArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageTripleArray3DPtr = + block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + if (AverageTripleArray3DPtr) + arrPresence.isAverageTripleArrayPresent = true; + else + arrPresence.isAverageTripleArrayPresent = false; + + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ShearStressValArray3DPtr = + block->getKernel()->getDataSet()->getShearStressValues(); + if (ShearStressValArray3DPtr) + arrPresence.isShearStressValArrayPresent = true; + else + arrPresence.isShearStressValArrayPresent = false; + + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> relaxationFactor3DPtr = + block->getKernel()->getDataSet()->getRelaxationFactor(); + if (relaxationFactor3DPtr) + arrPresence.isRelaxationFactorPresent = true; + else + arrPresence.isRelaxationFactorPresent = false; + + firstBlock = false; } - // ... than save some parameters that are equal in all dataSets - dataSetParamStr1.nx1 = dataSetParamStr2.nx1 = dataSetParamStr3.nx1 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX1()); - dataSetParamStr1.nx2 = dataSetParamStr2.nx2 = dataSetParamStr3.nx2 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX2()); - dataSetParamStr1.nx3 = dataSetParamStr2.nx3 = dataSetParamStr3.nx3 = static_cast<int>(block->getKernel()->getDataSet()->getFdistributions()->getNX3()); - - doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); - if (averageDensityArray) - arrPresence.isAverageDensityArrayPresent = true; - else - arrPresence.isAverageDensityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); - if (AverageVelocityArray3DPtr) - arrPresence.isAverageVelocityArrayPresent = true; - else - arrPresence.isAverageVelocityArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); - if (AverageFluctArray3DPtr) - arrPresence.isAverageFluktuationsArrayPresent = true; - else - arrPresence.isAverageFluktuationsArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - if (AverageTripleArray3DPtr) - arrPresence.isAverageTripleArrayPresent = true; - else - arrPresence.isAverageTripleArrayPresent = false; - - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); - if (ShearStressValArray3DPtr) - arrPresence.isShearStressValArrayPresent = true; - else - arrPresence.isShearStressValArrayPresent = false; - - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > relaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); - if (relaxationFactor3DPtr) - arrPresence.isRelaxationFactorPresent = true; - else - arrPresence.isRelaxationFactorPresent = false; - - firstBlock = false; - } - - if (localDistributions && (dataSetParamStr1.nx[0]>0) && (dataSetParamStr1.nx[1]>0) && (dataSetParamStr1.nx[2]>0) && (dataSetParamStr1.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), localDistributions->getDataVector().end()); - if (nonLocalDistributions && (dataSetParamStr2.nx[0]>0) && (dataSetParamStr2.nx[1]>0) && (dataSetParamStr2.nx[2]>0) && (dataSetParamStr2.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), nonLocalDistributions->getDataVector().end()); - if (zeroDistributions && (dataSetParamStr3.nx[0]>0) && (dataSetParamStr3.nx[1]>0) && (dataSetParamStr3.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), zeroDistributions->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size>1) - { - if (rank == 0) - { - next_write_offset = write_offset + 3 * sizeof(dataSetParam) + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + 3 * sizeof(dataSetParam) + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + if (localDistributions && (dataSetParamStr1.nx[0] > 0) && (dataSetParamStr1.nx[1] > 0) && + (dataSetParamStr1.nx[2] > 0) && (dataSetParamStr1.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), localDistributions->getDataVector().begin(), + localDistributions->getDataVector().end()); + if (nonLocalDistributions && (dataSetParamStr2.nx[0] > 0) && (dataSetParamStr2.nx[1] > 0) && + (dataSetParamStr2.nx[2] > 0) && (dataSetParamStr2.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), nonLocalDistributions->getDataVector().begin(), + nonLocalDistributions->getDataVector().end()); + if (zeroDistributions && (dataSetParamStr3.nx[0] > 0) && (dataSetParamStr3.nx[1] > 0) && + (dataSetParamStr3.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), zeroDistributions->getDataVector().begin(), + zeroDistributions->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + 3 * sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + 3 * sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + 3 * sizeof(dataSetParam)), dataSetArray, blocksCount, dataSetType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - - MPI_Type_free(&dataSetDoubleType); - - delete[] dataSetArray; - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet time: " << finish - start << " s"); - } - - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_sync(file_handler1); - MPI_File_close(&file_handler1); - - if (arrPresence.isAverageDensityArrayPresent) - writeAverageDensityArray(step); - - if (arrPresence.isAverageVelocityArrayPresent) - writeAverageVelocityArray(step); - - if (arrPresence.isAverageFluktuationsArrayPresent) - writeAverageFluktuationsArray(step); - - if (arrPresence.isAverageTripleArrayPresent) - writeAverageTripleArray(step); - - if (arrPresence.isShearStressValArrayPresent) - writeShearStressValArray(step); - - if (arrPresence.isRelaxationFactorPresent) - writeRelaxationFactor(step); - + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, + dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, + dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + 3 * sizeof(dataSetParam)), dataSetArray, blocksCount, + dataSetType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + + MPI_Type_free(&dataSetDoubleType); + + delete[] dataSetArray; + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeDataSet time: " << finish - start << " s"); + } + + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_write_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_sync(file_handler1); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + writeAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + writeAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + writeAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + writeAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + writeShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + writeRelaxationFactor(step); } void MPIIORestartCoProcessor::writeAverageDensityArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > averageDensityArray; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(averageDensityArray->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(averageDensityArray->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(averageDensityArray->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(averageDensityArray->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && (dataSetParamStr.nx[3] > 0)) - doubleValuesArray.insert(doubleValuesArray.end(), averageDensityArray->getDataVector().begin(), averageDensityArray->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values of the AverageDensityArray in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> averageDensityArray; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + averageDensityArray = block->getKernel()->getDataSet()->getAverageDensity(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(averageDensityArray->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(averageDensityArray->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(averageDensityArray->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(averageDensityArray->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), averageDensityArray->getDataVector().begin(), + averageDensityArray->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageDensityArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeAverageVelocityArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageVelocityArray3DPtr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageVelocityArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageVelocityArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageVelocityArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageVelocityArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageVelocityArray3DPtr->getDataVector().begin(), AverageVelocityArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageVelocityArray3DPtr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + AverageVelocityArray3DPtr = block->getKernel()->getDataSet()->getAverageVelocity(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(AverageVelocityArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageVelocityArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageVelocityArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageVelocityArray3DPtr->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), AverageVelocityArray3DPtr->getDataVector().begin(), + AverageVelocityArray3DPtr->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - - MPI_Type_free(&dataSetDoubleType); - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + + MPI_Type_free(&dataSetDoubleType); + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageVelocityArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeAverageFluktuationsArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageFluctArray3DPtr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageFluctArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageFluctArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageFluctArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageFluctArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageFluctArray3DPtr->getDataVector().begin(), AverageFluctArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageFluctArray3DPtr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + AverageFluctArray3DPtr = block->getKernel()->getDataSet()->getAverageFluctuations(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(AverageFluctArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageFluctArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageFluctArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageFluctArray3DPtr->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), AverageFluctArray3DPtr->getDataVector().begin(), + AverageFluctArray3DPtr->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = + path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageFluktuationsArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeAverageTripleArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > AverageTripleArray3DPtr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(AverageTripleArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(AverageTripleArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(AverageTripleArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(AverageTripleArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), AverageTripleArray3DPtr->getDataVector().begin(), AverageTripleArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> AverageTripleArray3DPtr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + AverageTripleArray3DPtr = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(AverageTripleArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(AverageTripleArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(AverageTripleArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(AverageTripleArray3DPtr->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), AverageTripleArray3DPtr->getDataVector().begin(), + AverageTripleArray3DPtr->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeAverageTripleArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeShearStressValArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray4D<LBMReal, IndexerX4X3X2X1> > ShearStressValArray3DPtr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(ShearStressValArray3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(ShearStressValArray3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(ShearStressValArray3DPtr->getNX3()); - dataSetParamStr.nx[3] = static_cast<int>(ShearStressValArray3DPtr->getNX4()); - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0) && (dataSetParamStr.nx[3]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), ShearStressValArray3DPtr->getDataVector().begin(), ShearStressValArray3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray4D<LBMReal, IndexerX4X3X2X1>> ShearStressValArray3DPtr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + ShearStressValArray3DPtr = block->getKernel()->getDataSet()->getShearStressValues(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(ShearStressValArray3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(ShearStressValArray3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(ShearStressValArray3DPtr->getNX3()); + dataSetParamStr.nx[3] = static_cast<int>(ShearStressValArray3DPtr->getNX4()); + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0) && + (dataSetParamStr.nx[3] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), ShearStressValArray3DPtr->getDataVector().begin(), + ShearStressValArray3DPtr->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeShearStressValArray time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeRelaxationFactor(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks - dataSetParam dataSetParamStr; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - bool firstBlock = true; - int doubleCountInBlock = 0; - int ic = 0; - SPtr< CbArray3D<LBMReal, IndexerX3X2X1> > RelaxationFactor3DPtr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - { - dataSetSmallArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - dataSetSmallArray[ic].x2 = block->getX2(); - dataSetSmallArray[ic].x3 = block->getX3(); - dataSetSmallArray[ic].level = block->getLevel(); - - RelaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); - - if (firstBlock) // when first (any) valid block... - { - dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; - dataSetParamStr.nx[0] = static_cast<int>(RelaxationFactor3DPtr->getNX1()); - dataSetParamStr.nx[1] = static_cast<int>(RelaxationFactor3DPtr->getNX2()); - dataSetParamStr.nx[2] = static_cast<int>(RelaxationFactor3DPtr->getNX3()); - dataSetParamStr.nx[3] = 1; - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - - firstBlock = false; - } - - if ((dataSetParamStr.nx[0]>0) && (dataSetParamStr.nx[1]>0) && (dataSetParamStr.nx[2]>0)) - doubleValuesArray.insert(doubleValuesArray.end(), RelaxationFactor3DPtr->getDataVector().begin(), RelaxationFactor3DPtr->getDataVector().end()); - - ic++; - } - } - - // register new MPI-types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_write_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + std::vector<double> doubleValuesArray; // double-values (arrays of f's) in all blocks + dataSetParam dataSetParamStr; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + bool firstBlock = true; + int doubleCountInBlock = 0; + int ic = 0; + SPtr<CbArray3D<LBMReal, IndexerX3X2X1>> RelaxationFactor3DPtr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + { + dataSetSmallArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + dataSetSmallArray[ic].x2 = block->getX2(); + dataSetSmallArray[ic].x3 = block->getX3(); + dataSetSmallArray[ic].level = block->getLevel(); + + RelaxationFactor3DPtr = block->getKernel()->getDataSet()->getRelaxationFactor(); + + if (firstBlock) // when first (any) valid block... + { + dataSetParamStr.nx1 = dataSetParamStr.nx2 = dataSetParamStr.nx3 = 0; + dataSetParamStr.nx[0] = static_cast<int>(RelaxationFactor3DPtr->getNX1()); + dataSetParamStr.nx[1] = static_cast<int>(RelaxationFactor3DPtr->getNX2()); + dataSetParamStr.nx[2] = static_cast<int>(RelaxationFactor3DPtr->getNX3()); + dataSetParamStr.nx[3] = 1; + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + + firstBlock = false; + } + + if ((dataSetParamStr.nx[0] > 0) && (dataSetParamStr.nx[1] > 0) && (dataSetParamStr.nx[2] > 0)) + doubleValuesArray.insert(doubleValuesArray.end(), RelaxationFactor3DPtr->getDataVector().begin(), + RelaxationFactor3DPtr->getDataVector().end()); + + ic++; + } + } + + // register new MPI-types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes common parameters of a dataSet - MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - // each process writes data identifying blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - // each process writes the dataSet arrays - if (doubleValuesArray.size() > 0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor time: " << finish - start << " s"); - } - - delete[] dataSetSmallArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes common parameters of a dataSet + MPI_File_write_at(file_handler, write_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + // each process writes data identifying blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + // each process writes the dataSet arrays + if (doubleValuesArray.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeRelaxationFactor time: " << finish - start << " s"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::writeBoundaryConds(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds start collect data rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! - size_t count_boundCond = 0; // how many BoundaryConditions in all blocks - int count_indexContainer = 0; // how many indexContainer-values in all blocks - size_t byteCount = 0; // how many bytes writes this process in the file - - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, rank, blocksVector[level]); - blocksCount += static_cast<int>(blocksVector[level].size()); - } - - BCAddRestart* bcAddArray = new BCAddRestart[blocksCount]; - std::vector<BoundaryCondition> bcVector; - std::vector<int> bcindexmatrixV; - std::vector<int> indexContainerV; - bool bcindexmatrixCountNotInit = true; - int ic = 0; - SPtr<BCArray3D> bcArr; - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level - { - bcArr = block->getKernel()->getBCProcessor()->getBCArray(); - - bcAddArray[ic].x1 = block->getX1(); // coordinates of the block needed to find it while regenerating the grid - bcAddArray[ic].x2 = block->getX2(); - bcAddArray[ic].x3 = block->getX3(); - bcAddArray[ic].level = block->getLevel(); - bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block - bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block - - for (int bc = 0; bc<bcArr->getBCVectorSize(); bc++) - { - BoundaryCondition* bouCond = new BoundaryCondition(); - if (bcArr->bcvector[bc] == NULL) - { - memset(bouCond, 0, sizeof(BoundaryCondition)); - } - else - { - bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); - bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); - bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); - bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); - bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); - bouCond->bcVelocityX1 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX1(); - bouCond->bcVelocityX2 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX2(); - bouCond->bcVelocityX3 = (float) bcArr->bcvector[bc]->getBoundaryVelocityX3(); - bouCond->bcDensity = (float) bcArr->bcvector[bc]->getBoundaryDensity(); - bouCond->bcLodiDensity = (float) bcArr->bcvector[bc]->getDensityLodiDensity(); - bouCond->bcLodiVelocityX1 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX1(); - bouCond->bcLodiVelocityX2 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX2(); - bouCond->bcLodiVelocityX3 = (float) bcArr->bcvector[bc]->getDensityLodiVelocityX3(); - bouCond->bcLodiLentgh = (float) bcArr->bcvector[bc]->getDensityLodiLength(); - bouCond->nx1 = (float) bcArr->bcvector[bc]->nx1; - bouCond->nx2 = (float) bcArr->bcvector[bc]->nx2; - bouCond->nx3 = (float) bcArr->bcvector[bc]->nx3; - for (int iq = 0; iq<26; iq++) - bouCond->q[iq] = (float) bcArr->bcvector[bc]->getQ(iq); - bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds start collect data rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + int blocksCount = 0; // quantity of blocks in the grid, max 2147483648 blocks! + size_t count_boundCond = 0; // how many BoundaryConditions in all blocks + int count_indexContainer = 0; // how many indexContainer-values in all blocks + size_t byteCount = 0; // how many bytes writes this process in the file + + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, rank, blocksVector[level]); + blocksCount += static_cast<int>(blocksVector[level].size()); + } + + BCAddRestart *bcAddArray = new BCAddRestart[blocksCount]; + std::vector<BoundaryCondition> bcVector; + std::vector<int> bcindexmatrixV; + std::vector<int> indexContainerV; + bool bcindexmatrixCountNotInit = true; + int ic = 0; + SPtr<BCArray3D> bcArr; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blocksVector[level]) // all the blocks of the current level + { + bcArr = block->getKernel()->getBCProcessor()->getBCArray(); + + bcAddArray[ic].x1 = + block->getX1(); // coordinates of the block needed to find it while regenerating the grid + bcAddArray[ic].x2 = block->getX2(); + bcAddArray[ic].x3 = block->getX3(); + bcAddArray[ic].level = block->getLevel(); + bcAddArray[ic].boundCond_count = 0; // how many BoundaryConditions in this block + bcAddArray[ic].indexContainer_count = 0; // how many indexContainer-values in this block + + for (int bc = 0; bc < bcArr->getBCVectorSize(); bc++) { + BoundaryCondition *bouCond = new BoundaryCondition(); + if (bcArr->bcvector[bc] == NULL) { + memset(bouCond, 0, sizeof(BoundaryCondition)); + } else { + bouCond->noslipBoundaryFlags = bcArr->bcvector[bc]->getNoSlipBoundary(); + bouCond->slipBoundaryFlags = bcArr->bcvector[bc]->getSlipBoundary(); + bouCond->velocityBoundaryFlags = bcArr->bcvector[bc]->getVelocityBoundary(); + bouCond->densityBoundaryFlags = bcArr->bcvector[bc]->getDensityBoundary(); + bouCond->wallModelBoundaryFlags = bcArr->bcvector[bc]->getWallModelBoundary(); + bouCond->bcVelocityX1 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX1(); + bouCond->bcVelocityX2 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX2(); + bouCond->bcVelocityX3 = (float)bcArr->bcvector[bc]->getBoundaryVelocityX3(); + bouCond->bcDensity = (float)bcArr->bcvector[bc]->getBoundaryDensity(); + bouCond->bcLodiDensity = (float)bcArr->bcvector[bc]->getDensityLodiDensity(); + bouCond->bcLodiVelocityX1 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX1(); + bouCond->bcLodiVelocityX2 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX2(); + bouCond->bcLodiVelocityX3 = (float)bcArr->bcvector[bc]->getDensityLodiVelocityX3(); + bouCond->bcLodiLentgh = (float)bcArr->bcvector[bc]->getDensityLodiLength(); + bouCond->nx1 = (float)bcArr->bcvector[bc]->nx1; + bouCond->nx2 = (float)bcArr->bcvector[bc]->nx2; + bouCond->nx3 = (float)bcArr->bcvector[bc]->nx3; + for (int iq = 0; iq < 26; iq++) + bouCond->q[iq] = (float)bcArr->bcvector[bc]->getQ(iq); + bouCond->algorithmType = bcArr->bcvector[bc]->getBcAlgorithmType(); + } + + bcVector.push_back(*bouCond); + bcAddArray[ic].boundCond_count++; + count_boundCond++; } - bcVector.push_back(*bouCond); - bcAddArray[ic].boundCond_count++; - count_boundCond++; - } - - // the quantity of elements in the bcindexmatrix array (CbArray3D<int, IndexerX3X2X1>) in bcArray(BCArray3D) is always equal, - // this will be the size of the "write-read-block" in MPI_write_.../MPI_read-functions when writing/reading BoundConds - if (bcindexmatrixCountNotInit) - { - boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); - boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); - boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); - boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); - bcindexmatrixCountNotInit = false; - } - bcindexmatrixV.insert(bcindexmatrixV.end(), bcArr->bcindexmatrix.getDataVector().begin(), bcArr->bcindexmatrix.getDataVector().end()); - - indexContainerV.insert(indexContainerV.end(), bcArr->indexContainer.begin(), bcArr->indexContainer.end()); - bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); - count_indexContainer += bcAddArray[ic].indexContainer_count; - - ic++; - } - } - - MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - //how many "big blocks" of BLOCK_SIZE size can by formed - int bcBlockCount = (int)(count_boundCond / BLOCK_SIZE); - if (bcBlockCount * BLOCK_SIZE<count_boundCond) - bcBlockCount += 1; - for (int i = (int)count_boundCond; i<bcBlockCount * BLOCK_SIZE; i++) - { - BoundaryCondition* bouCond = new BoundaryCondition(); - memset(bouCond, 0, sizeof(BoundaryCondition)); - bcVector.push_back(*bouCond); - } - - byteCount = bcBlockCount * BLOCK_SIZE * sizeof(BoundaryCondition) + blocksCount * sizeof(BCAddRestart) + sizeof(int) * (blocksCount * boundCondParamStr.bcindexmatrixCount + count_indexContainer); - - // write to the file - // all processes calculate their offsets (quantity of bytes that the process is going to write) - // and notify the next process (with the rank = rank + 1) - MPI_Offset write_offset = (MPI_Offset)(size * (3 * sizeof(int) + sizeof(boundCondParam))); - size_t next_write_offset = 0; - - if (size>1) - { - if (rank == 0) - { - next_write_offset = write_offset + byteCount; - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_write_offset = write_offset + byteCount; - if (rank<size - 1) - MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_Info info = MPI_INFO_NULL; + // the quantity of elements in the bcindexmatrix array (CbArray3D<int, IndexerX3X2X1>) in bcArray(BCArray3D) + // is always equal, this will be the size of the "write-read-block" in MPI_write_.../MPI_read-functions when + // writing/reading BoundConds + if (bcindexmatrixCountNotInit) { + boundCondParamStr.nx1 = static_cast<int>(bcArr->bcindexmatrix.getNX1()); + boundCondParamStr.nx2 = static_cast<int>(bcArr->bcindexmatrix.getNX2()); + boundCondParamStr.nx3 = static_cast<int>(bcArr->bcindexmatrix.getNX3()); + boundCondParamStr.bcindexmatrixCount = static_cast<int>(bcArr->bcindexmatrix.getDataVector().size()); + bcindexmatrixCountNotInit = false; + } + bcindexmatrixV.insert(bcindexmatrixV.end(), bcArr->bcindexmatrix.getDataVector().begin(), + bcArr->bcindexmatrix.getDataVector().end()); + + indexContainerV.insert(indexContainerV.end(), bcArr->indexContainer.begin(), bcArr->indexContainer.end()); + bcAddArray[ic].indexContainer_count = static_cast<int>(bcArr->indexContainer.size()); + count_indexContainer += bcAddArray[ic].indexContainer_count; + + ic++; + } + } + + MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); + + // how many "big blocks" of BLOCK_SIZE size can by formed + int bcBlockCount = (int)(count_boundCond / BLOCK_SIZE); + if (bcBlockCount * BLOCK_SIZE < count_boundCond) + bcBlockCount += 1; + for (int i = (int)count_boundCond; i < bcBlockCount * BLOCK_SIZE; i++) { + BoundaryCondition *bouCond = new BoundaryCondition(); + memset(bouCond, 0, sizeof(BoundaryCondition)); + bcVector.push_back(*bouCond); + } + + byteCount = bcBlockCount * BLOCK_SIZE * sizeof(BoundaryCondition) + blocksCount * sizeof(BCAddRestart) + + sizeof(int) * (blocksCount * boundCondParamStr.bcindexmatrixCount + count_indexContainer); + + // write to the file + // all processes calculate their offsets (quantity of bytes that the process is going to write) + // and notify the next process (with the rank = rank + 1) + MPI_Offset write_offset = (MPI_Offset)(size * (3 * sizeof(int) + sizeof(boundCondParam))); + size_t next_write_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_write_offset = write_offset + byteCount; + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&write_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_write_offset = write_offset + byteCount; + if (rank < size - 1) + MPI_Send(&next_write_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_Info info = MPI_INFO_NULL; #ifdef HLRN_LUSTRE - MPI_Info_create(&info); - MPI_Info_set(info, "striping_factor", "40"); - MPI_Info_set(info, "striping_unit", "4M"); + MPI_Info_create(&info); + MPI_Info_set(info, "striping_factor", "40"); + MPI_Info_set(info, "striping_unit", "4M"); #endif - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - MPI_Offset write_offset1 = (MPI_Offset)(rank * (3 * sizeof(int) + sizeof(boundCondParam))); - - // each process writes the quantity of it's blocks - MPI_File_write_at(file_handler, write_offset1, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes the quantity of "big blocks" of BLOCK_SIZE of boundary conditions - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + sizeof(int)), &bcBlockCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes the quantity of indexContainer elements in all blocks - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + 2 * sizeof(int)), &count_indexContainer, 1, MPI_INT, MPI_STATUS_IGNORE); - // each process writes the quantity of bcindexmatrix elements in every block - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + 3 * sizeof(int)), &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); - - // each process writes data identifying the blocks - MPI_File_write_at(file_handler, write_offset, bcAddArray, blocksCount, boundCondTypeAdd, MPI_STATUS_IGNORE); - // each process writes boundary conditions - if (bcVector.size()>0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart)), &bcVector[0], bcBlockCount, boundCondType1000, MPI_STATUS_IGNORE); - // each process writes bcindexmatrix values - if (bcindexmatrixV.size()>0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart) + bcBlockCount*BLOCK_SIZE * sizeof(BoundaryCondition)), &bcindexmatrixV[0], blocksCount, bcindexmatrixType, MPI_STATUS_IGNORE); - // each process writes indexContainer values - if (indexContainerV.size()>0) - MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart) + bcBlockCount*BLOCK_SIZE * sizeof(BoundaryCondition) + blocksCount*boundCondParamStr.bcindexmatrixCount * sizeof(int)), &indexContainerV[0], count_indexContainer, MPI_INT, MPI_STATUS_IGNORE); - - MPI_File_sync(file_handler); - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds time: " << finish - start << " s"); - } - - delete[] bcAddArray; + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, info, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + MPI_Offset write_offset1 = (MPI_Offset)(rank * (3 * sizeof(int) + sizeof(boundCondParam))); + + // each process writes the quantity of it's blocks + MPI_File_write_at(file_handler, write_offset1, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // each process writes the quantity of "big blocks" of BLOCK_SIZE of boundary conditions + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + sizeof(int)), &bcBlockCount, 1, MPI_INT, + MPI_STATUS_IGNORE); + // each process writes the quantity of indexContainer elements in all blocks + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + 2 * sizeof(int)), &count_indexContainer, 1, MPI_INT, + MPI_STATUS_IGNORE); + // each process writes the quantity of bcindexmatrix elements in every block + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset1 + 3 * sizeof(int)), &boundCondParamStr, 1, + boundCondParamType, MPI_STATUS_IGNORE); + + // each process writes data identifying the blocks + MPI_File_write_at(file_handler, write_offset, bcAddArray, blocksCount, boundCondTypeAdd, MPI_STATUS_IGNORE); + // each process writes boundary conditions + if (bcVector.size() > 0) + MPI_File_write_at(file_handler, (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart)), &bcVector[0], + bcBlockCount, boundCondType1000, MPI_STATUS_IGNORE); + // each process writes bcindexmatrix values + if (bcindexmatrixV.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart) + + bcBlockCount * BLOCK_SIZE * sizeof(BoundaryCondition)), + &bcindexmatrixV[0], blocksCount, bcindexmatrixType, MPI_STATUS_IGNORE); + // each process writes indexContainer values + if (indexContainerV.size() > 0) + MPI_File_write_at(file_handler, + (MPI_Offset)(write_offset + blocksCount * sizeof(BCAddRestart) + + bcBlockCount * BLOCK_SIZE * sizeof(BoundaryCondition) + + blocksCount * boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &indexContainerV[0], count_indexContainer, MPI_INT, MPI_STATUS_IGNORE); + + MPI_File_sync(file_handler); + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::writeBoundaryConds time: " << finish - start << " s"); + } + + delete[] bcAddArray; } //------------------------------------------- READ ----------------------------------------------- void MPIIORestartCoProcessor::restart(int step) { - if (comm->isRoot()) UBLOG(logINFO, "MPIIORestartCoProcessor restart step: " << step); - if (comm->isRoot()) UBLOG(logINFO, "Load check point - start"); + if (comm->isRoot()) + UBLOG(logINFO, "MPIIORestartCoProcessor restart step: " << step); + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - start"); - readBlocks(step); - readDataSet(step); - readBoundaryConds(step); + readBlocks(step); + readDataSet(step); + readBoundaryConds(step); - grid->setTimeStep(step); + grid->setTimeStep(step); - if (comm->isRoot()) UBLOG(logINFO, "Load check point - end"); + if (comm->isRoot()) + UBLOG(logINFO, "Load check point - end"); } -void MPIIORestartCoProcessor::readBlocks(int step) -{ - MPIIOCoProcessor::readBlocks(step); -} +void MPIIORestartCoProcessor::readBlocks(int step) { MPIIOCoProcessor::readBlocks(step); } void MPIIORestartCoProcessor::readDataSet(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, read_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetRestart* dataSetArray = new DataSetRestart[blocksCount]; - double doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - std::vector<double> doubleValuesArray(size_t(blocksCount * doubleCountInBlock)); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + 3 * sizeof(dataSetParam) + blocksCount * (sizeof(DataSetRestart) + size_t(doubleCountInBlock) * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + 3 * sizeof(dataSetParam) + blocksCount * (sizeof(DataSetRestart) + size_t(doubleCountInBlock) * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam)), dataSetArray, blocksCount, dataSetType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0, vectorSize = 0; - std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; - - for (int n = 0; n < blocksCount; n++) - { - vectorSize = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; - vectorsOfValues1.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; - - vectorSize = dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; - vectorsOfValues2.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; - - vectorSize = dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - vectorsOfValues3.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); - index += vectorSize; - - SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); - - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], dataSetParamStr1.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], dataSetParamStr2.nx[3]))); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); - - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); - dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetArray[n].x1, dataSetArray[n].x2, dataSetArray[n].x3, dataSetArray[n].level); - this->lbmKernel->setBlock(block); - SPtr<LBMKernel> kernel = this->lbmKernel->clone(); - kernel->setGhostLayerWidth(dataSetArray[n].ghostLayerWidth); - kernel->setCollisionFactor(dataSetArray[n].collFactor); - kernel->setDeltaT(dataSetArray[n].deltaT); - kernel->setCompressible(dataSetArray[n].compressible); - kernel->setWithForcing(dataSetArray[n].withForcing); - SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); - dataSetPtr->setFdistributions(mFdistributions); - kernel->setDataSet(dataSetPtr); - block->setKernel(kernel); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetArray; - - //------------------------------------------------------------- - - DSArraysPresence arrPresence; - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler1); - - if (arrPresence.isAverageDensityArrayPresent) - readAverageDensityArray(step); - - if (arrPresence.isAverageVelocityArrayPresent) - readAverageVelocityArray(step); - - if (arrPresence.isAverageFluktuationsArrayPresent) - readAverageFluktuationsArray(step); - - if (arrPresence.isAverageTripleArrayPresent) - readAverageTripleArray(step); - - if (arrPresence.isShearStressValArrayPresent) - readShearStressValArray(step); - - if (arrPresence.isRelaxationFactorPresent) - readRelaxationFactor(step); - + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, read_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, + dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, + dataSetParamType, MPI_STATUS_IGNORE); + + DataSetRestart *dataSetArray = new DataSetRestart[blocksCount]; + double doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + std::vector<double> doubleValuesArray(size_t(blocksCount * doubleCountInBlock)); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(int(doubleCountInBlock), MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + 3 * sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetRestart) + size_t(doubleCountInBlock) * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + 3 * sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetRestart) + size_t(doubleCountInBlock) * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam)), dataSetArray, blocksCount, + dataSetType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0, vectorSize = 0; + std::vector<double> vectorsOfValues1, vectorsOfValues2, vectorsOfValues3; + + for (int n = 0; n < blocksCount; n++) { + vectorSize = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3]; + vectorsOfValues1.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + vectorSize = dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3]; + vectorsOfValues2.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + vectorSize = dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + vectorsOfValues3.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + vectorSize); + index += vectorSize; + + SPtr<DistributionArray3D> mFdistributions(new D3Q27EsoTwist3DSplittedVector()); + + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues1, dataSetParamStr1.nx[0], + dataSetParamStr1.nx[1], dataSetParamStr1.nx[2], + dataSetParamStr1.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues2, dataSetParamStr2.nx[0], + dataSetParamStr2.nx[1], dataSetParamStr2.nx[2], + dataSetParamStr2.nx[3]))); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions) + ->setZeroDistributions( + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues3, dataSetParamStr3.nx[0], dataSetParamStr3.nx[1], dataSetParamStr3.nx[2]))); + + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX1(dataSetParamStr1.nx1); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX2(dataSetParamStr1.nx2); + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(mFdistributions)->setNX3(dataSetParamStr1.nx3); + + // find the nesessary block and fill it + SPtr<Block3D> block = + grid->getBlock(dataSetArray[n].x1, dataSetArray[n].x2, dataSetArray[n].x3, dataSetArray[n].level); + this->lbmKernel->setBlock(block); + SPtr<LBMKernel> kernel = this->lbmKernel->clone(); + kernel->setGhostLayerWidth(dataSetArray[n].ghostLayerWidth); + kernel->setCollisionFactor(dataSetArray[n].collFactor); + kernel->setDeltaT(dataSetArray[n].deltaT); + kernel->setCompressible(dataSetArray[n].compressible); + kernel->setWithForcing(dataSetArray[n].withForcing); + SPtr<DataSet3D> dataSetPtr = SPtr<DataSet3D>(new DataSet3D()); + dataSetPtr->setFdistributions(mFdistributions); + kernel->setDataSet(dataSetPtr); + block->setKernel(kernel); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readDataSet end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetArray; + + //------------------------------------------------------------- + + DSArraysPresence arrPresence; + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 1, arrayPresenceType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler1); + + if (arrPresence.isAverageDensityArrayPresent) + readAverageDensityArray(step); + + if (arrPresence.isAverageVelocityArrayPresent) + readAverageVelocityArray(step); + + if (arrPresence.isAverageFluktuationsArrayPresent) + readAverageFluktuationsArray(step); + + if (arrPresence.isAverageTripleArrayPresent) + readAverageTripleArray(step); + + if (arrPresence.isShearStressValArrayPresent) + readShearStressValArray(step); + + if (arrPresence.isRelaxationFactorPresent) + readRelaxationFactor(step); } void MPIIORestartCoProcessor::readAverageDensityArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - memset(&dataSetParamStr, 0, sizeof(dataSetParam)); - - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill mAverageDensity arrays - SPtr<AverageValuesArray3D> mAverageDensity; - mAverageDensity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setAverageDensity(mAverageDensity); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageDensityArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + memset(&dataSetParamStr, 0, sizeof(dataSetParam)); + + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill mAverageDensity arrays + SPtr<AverageValuesArray3D> mAverageDensity; + mAverageDensity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], + dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setAverageDensity(mAverageDensity); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageDensityArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readAverageVelocityArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill mAverageVelocity array - SPtr<AverageValuesArray3D> mAverageVelocity; - mAverageVelocity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setAverageVelocity(mAverageVelocity); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageVelocityArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill mAverageVelocity array + SPtr<AverageValuesArray3D> mAverageVelocity; + mAverageVelocity = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], + dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setAverageVelocity(mAverageVelocity); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageVelocityArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readAverageFluktuationsArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill AverageFluktuations array - SPtr<AverageValuesArray3D> mAverageFluktuations; - mAverageFluktuations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setAverageFluctuations(mAverageFluktuations); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = + path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageFluktuationsArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray time: " << finish - start << " s"); + UBLOG(logINFO, + "MPIIORestartCoProcessor::readAverageFluktuationsArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill AverageFluktuations array + SPtr<AverageValuesArray3D> mAverageFluktuations; + mAverageFluktuations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], + dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setAverageFluctuations(mAverageFluktuations); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageFluktuationsArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readAverageTripleArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill AverageTriplecorrelations array - SPtr<AverageValuesArray3D> mAverageTriplecorrelations; - mAverageTriplecorrelations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setAverageTriplecorrelations(mAverageTriplecorrelations); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpAverageTripleArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill AverageTriplecorrelations array + SPtr<AverageValuesArray3D> mAverageTriplecorrelations; + mAverageTriplecorrelations = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], + dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setAverageTriplecorrelations(mAverageTriplecorrelations); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readAverageTripleArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readShearStressValArray(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill ShearStressValuesArray array - SPtr<ShearStressValuesArray3D> mShearStressValues; - mShearStressValues = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2], dataSetParamStr.nx[3])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setShearStressValues(mShearStressValues); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpShearStressValArray.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill ShearStressValuesArray array + SPtr<ShearStressValuesArray3D> mShearStressValues; + mShearStressValues = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], + dataSetParamStr.nx[2], dataSetParamStr.nx[3])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setShearStressValues(mShearStressValues); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readShearStressValArray end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readRelaxationFactor(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - // read count of blocks - int blocksCount = 0; - dataSetParam dataSetParamStr; - MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - DataSetSmallRestart* dataSetSmallArray = new DataSetSmallRestart[blocksCount]; - int doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks - - // define MPI_types depending on the block-specific information - MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); - MPI_Type_commit(&dataSetDoubleType); - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); - size_t next_read_offset = 0; - - if (size > 1) - { - if (rank == 0) - { - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + sizeof(dataSetParam) + blocksCount*(sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - if (rank < size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, dataSetSmallType, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler); - MPI_Type_free(&dataSetDoubleType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - size_t index = 0; - size_t nextVectorSize = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - std::vector<double> vectorsOfValues; - for (int n = 0; n < blocksCount; n++) - { - vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); - index += nextVectorSize; - - // fill RelaxationFactor array - SPtr<RelaxationFactorArray3D> mRelaxationFactor; - mRelaxationFactor = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); - - // find the nesessary block and fill it - SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, dataSetSmallArray[n].level); - block->getKernel()->getDataSet()->setRelaxationFactor(mRelaxationFactor); - } - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - delete[] dataSetSmallArray; + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpRelaxationFactor.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + // read count of blocks + int blocksCount = 0; + dataSetParam dataSetParamStr; + MPI_File_read_at(file_handler, (MPI_Offset)(rank * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(size * sizeof(int)), &dataSetParamStr, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + DataSetSmallRestart *dataSetSmallArray = new DataSetSmallRestart[blocksCount]; + int doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> doubleValuesArray(blocksCount * doubleCountInBlock); // double-values in all blocks + + // define MPI_types depending on the block-specific information + MPI_Type_contiguous(doubleCountInBlock, MPI_DOUBLE, &dataSetDoubleType); + MPI_Type_commit(&dataSetDoubleType); + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(size * sizeof(int)); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallArray, blocksCount, + dataSetSmallType, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount, dataSetDoubleType, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler); + MPI_Type_free(&dataSetDoubleType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + size_t index = 0; + size_t nextVectorSize = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + std::vector<double> vectorsOfValues; + for (int n = 0; n < blocksCount; n++) { + vectorsOfValues.assign(doubleValuesArray.data() + index, doubleValuesArray.data() + index + nextVectorSize); + index += nextVectorSize; + + // fill RelaxationFactor array + SPtr<RelaxationFactorArray3D> mRelaxationFactor; + mRelaxationFactor = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>( + vectorsOfValues, dataSetParamStr.nx[0], dataSetParamStr.nx[1], dataSetParamStr.nx[2])); + + // find the nesessary block and fill it + SPtr<Block3D> block = grid->getBlock(dataSetSmallArray[n].x1, dataSetSmallArray[n].x2, dataSetSmallArray[n].x3, + dataSetSmallArray[n].level); + block->getKernel()->getDataSet()->setRelaxationFactor(mRelaxationFactor); + } + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readRelaxationFactor end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + delete[] dataSetSmallArray; } void MPIIORestartCoProcessor::readBoundaryConds(int step) { - int rank, size; - MPI_Comm_rank(MPI_COMM_WORLD, &rank); - MPI_Comm_size(MPI_COMM_WORLD, &size); - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds start MPI IO rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handler; - std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename); - - int blocksCount = 0; - int dataCount1000 = 0; - int dataCount2 = 0; - MPI_Offset read_offset1 = (MPI_Offset)(rank * (3 * sizeof(int) + sizeof(boundCondParam))); - - // read count of blocks - MPI_File_read_at(file_handler, read_offset1, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of big BoundaryCondition blocks - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + sizeof(int)), &dataCount1000, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of indexContainer values in all blocks - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + 2 * sizeof(int)), &dataCount2, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of bcindexmatrix values in every block - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + 3 * sizeof(int)), &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); - - MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); - MPI_Type_commit(&bcindexmatrixType); - - size_t dataCount = dataCount1000 * BLOCK_SIZE; - BCAddRestart* bcAddArray = new BCAddRestart[blocksCount]; - BoundaryCondition* bcArray = new BoundaryCondition[dataCount]; - BoundaryCondition* nullBouCond = new BoundaryCondition(); - memset(nullBouCond, 0, sizeof(BoundaryCondition)); - int* intArray1 = new int[blocksCount * boundCondParamStr.bcindexmatrixCount]; - int* intArray2 = new int[dataCount2]; - - MPI_Offset read_offset = (MPI_Offset)(size * (3 * sizeof(int) + sizeof(boundCondParam))); - size_t next_read_offset = 0; - - if (size>1) - { - if (rank == 0) - { - next_read_offset = read_offset + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); - } - else - { - MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - next_read_offset = read_offset + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); - if (rank<size - 1) - MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); - } - } - - MPI_File_read_at(file_handler, read_offset, bcAddArray, blocksCount, boundCondTypeAdd, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart)), &bcArray[0], dataCount1000, boundCondType1000, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition)), &intArray1[0], blocksCount, bcindexmatrixType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + blocksCount * boundCondParamStr.bcindexmatrixCount * sizeof(int)), &intArray2[0], dataCount2, MPI_INT, MPI_STATUS_IGNORE); - - MPI_File_close(&file_handler); - MPI_Type_free(&bcindexmatrixType); - - if (comm->isRoot()) - { - finish = MPI_Wtime(); - UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds time: " << finish - start << " s"); - UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds start of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } - - int index = 0, index1 = 0, index2 = 0; - std::vector<SPtr<BoundaryConditions>> bcVector; - std::vector<int> bcindexmatrixV; - std::vector<int> indexContainerV; - - for (size_t n = 0; n<blocksCount; n++) - { - bcVector.resize(0); - bcindexmatrixV.resize(0); - indexContainerV.resize(0); - - for (size_t ibc = 0; ibc<bcAddArray[n].boundCond_count; ibc++) - { - SPtr<BoundaryConditions> bc; - if (memcmp(&bcArray[index], nullBouCond, sizeof(BoundaryCondition)) == 0) - bc = SPtr<BoundaryConditions>(); - else - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions); - bc->noslipBoundaryFlags = bcArray[index].noslipBoundaryFlags; - bc->slipBoundaryFlags = bcArray[index].slipBoundaryFlags; - bc->densityBoundaryFlags = bcArray[index].densityBoundaryFlags; - bc->velocityBoundaryFlags = bcArray[index].velocityBoundaryFlags; - bc->wallModelBoundaryFlags = bcArray[index].wallModelBoundaryFlags; - bc->bcVelocityX1 = bcArray[index].bcVelocityX1; - bc->bcVelocityX2 = bcArray[index].bcVelocityX2; - bc->bcVelocityX3 = bcArray[index].bcVelocityX3; - bc->bcDensity = bcArray[index].bcDensity; - bc->bcLodiDensity = bcArray[index].bcLodiDensity; - bc->bcLodiVelocityX1 = bcArray[index].bcLodiVelocityX1; - bc->bcLodiVelocityX2 = bcArray[index].bcLodiVelocityX2; - bc->bcLodiVelocityX3 = bcArray[index].bcLodiVelocityX3; - bc->bcLodiLentgh = bcArray[index].bcLodiLentgh; - - bc->nx1 = bcArray[index].nx1; - bc->nx2 = bcArray[index].nx2; - bc->nx3 = bcArray[index].nx3; - for (int iq = 0; iq<26; iq++) - bc->setQ(bcArray[index].q[iq], iq); - bc->setBcAlgorithmType(bcArray[index].algorithmType); - } - - bcVector.push_back(bc); - index++; - } - - for (int b1 = 0; b1 < boundCondParamStr.bcindexmatrixCount; b1++) - bcindexmatrixV.push_back(intArray1[index1++]); - - for (int b2 = 0; b2 < bcAddArray[n].indexContainer_count; b2++) - indexContainerV.push_back(intArray2[index2++]); - - CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, boundCondParamStr.nx3); - - SPtr<Block3D> block = grid->getBlock(bcAddArray[n].x1, bcAddArray[n].x2, bcAddArray[n].x3, bcAddArray[n].level); - SPtr<BCProcessor> bcProc = bcProcessor->clone(block->getKernel()); - SPtr<BCArray3D> bcArr(new BCArray3D()); - bcArr->bcindexmatrix = bcim; - bcArr->bcvector = bcVector; - bcArr->indexContainer = indexContainerV; - bcProc->setBCArray(bcArr); - - block->getKernel()->setBCProcessor(bcProc); - } - - delete nullBouCond; - delete[] bcArray; - delete[] bcAddArray; - delete[] intArray1; - delete[] intArray2; - - if (comm->isRoot()) - { - UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds end of restore of data, rank = " << rank); - UBLOG(logINFO, "Physical Memory currently used by current process: " << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); - } + int rank, size; + MPI_Comm_rank(MPI_COMM_WORLD, &rank); + MPI_Comm_size(MPI_COMM_WORLD, &size); + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds start MPI IO rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handler; + std::string filename = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + int blocksCount = 0; + int dataCount1000 = 0; + int dataCount2 = 0; + MPI_Offset read_offset1 = (MPI_Offset)(rank * (3 * sizeof(int) + sizeof(boundCondParam))); + + // read count of blocks + MPI_File_read_at(file_handler, read_offset1, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // read count of big BoundaryCondition blocks + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + sizeof(int)), &dataCount1000, 1, MPI_INT, + MPI_STATUS_IGNORE); + // read count of indexContainer values in all blocks + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + 2 * sizeof(int)), &dataCount2, 1, MPI_INT, + MPI_STATUS_IGNORE); + // read count of bcindexmatrix values in every block + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset1 + 3 * sizeof(int)), &boundCondParamStr, 1, + boundCondParamType, MPI_STATUS_IGNORE); + + MPI_Type_contiguous(boundCondParamStr.bcindexmatrixCount, MPI_INT, &bcindexmatrixType); + MPI_Type_commit(&bcindexmatrixType); + + size_t dataCount = dataCount1000 * BLOCK_SIZE; + BCAddRestart *bcAddArray = new BCAddRestart[blocksCount]; + BoundaryCondition *bcArray = new BoundaryCondition[dataCount]; + BoundaryCondition *nullBouCond = new BoundaryCondition(); + memset(nullBouCond, 0, sizeof(BoundaryCondition)); + int *intArray1 = new int[blocksCount * boundCondParamStr.bcindexmatrixCount]; + int *intArray2 = new int[dataCount2]; + + MPI_Offset read_offset = (MPI_Offset)(size * (3 * sizeof(int) + sizeof(boundCondParam))); + size_t next_read_offset = 0; + + if (size > 1) { + if (rank == 0) { + next_read_offset = read_offset + blocksCount * sizeof(BCAddRestart) + + dataCount * sizeof(BoundaryCondition) + + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, 1, 5, MPI_COMM_WORLD); + } else { + MPI_Recv(&read_offset, 1, MPI_LONG_LONG_INT, rank - 1, 5, MPI_COMM_WORLD, MPI_STATUS_IGNORE); + next_read_offset = read_offset + blocksCount * sizeof(BCAddRestart) + + dataCount * sizeof(BoundaryCondition) + + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); + if (rank < size - 1) + MPI_Send(&next_read_offset, 1, MPI_LONG_LONG_INT, rank + 1, 5, MPI_COMM_WORLD); + } + } + + MPI_File_read_at(file_handler, read_offset, bcAddArray, blocksCount, boundCondTypeAdd, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart)), &bcArray[0], + dataCount1000, boundCondType1000, MPI_STATUS_IGNORE); + MPI_File_read_at( + file_handler, + (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition)), + &intArray1[0], blocksCount, bcindexmatrixType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handler, + (MPI_Offset)(read_offset + blocksCount * sizeof(BCAddRestart) + + dataCount * sizeof(BoundaryCondition) + + blocksCount * boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &intArray2[0], dataCount2, MPI_INT, MPI_STATUS_IGNORE); + + MPI_File_close(&file_handler); + MPI_Type_free(&bcindexmatrixType); + + if (comm->isRoot()) { + finish = MPI_Wtime(); + UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds time: " << finish - start << " s"); + UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds start of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } + + int index = 0, index1 = 0, index2 = 0; + std::vector<SPtr<BoundaryConditions>> bcVector; + std::vector<int> bcindexmatrixV; + std::vector<int> indexContainerV; + + for (size_t n = 0; n < blocksCount; n++) { + bcVector.resize(0); + bcindexmatrixV.resize(0); + indexContainerV.resize(0); + + for (size_t ibc = 0; ibc < bcAddArray[n].boundCond_count; ibc++) { + SPtr<BoundaryConditions> bc; + if (memcmp(&bcArray[index], nullBouCond, sizeof(BoundaryCondition)) == 0) + bc = SPtr<BoundaryConditions>(); + else { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + bc->noslipBoundaryFlags = bcArray[index].noslipBoundaryFlags; + bc->slipBoundaryFlags = bcArray[index].slipBoundaryFlags; + bc->densityBoundaryFlags = bcArray[index].densityBoundaryFlags; + bc->velocityBoundaryFlags = bcArray[index].velocityBoundaryFlags; + bc->wallModelBoundaryFlags = bcArray[index].wallModelBoundaryFlags; + bc->bcVelocityX1 = bcArray[index].bcVelocityX1; + bc->bcVelocityX2 = bcArray[index].bcVelocityX2; + bc->bcVelocityX3 = bcArray[index].bcVelocityX3; + bc->bcDensity = bcArray[index].bcDensity; + bc->bcLodiDensity = bcArray[index].bcLodiDensity; + bc->bcLodiVelocityX1 = bcArray[index].bcLodiVelocityX1; + bc->bcLodiVelocityX2 = bcArray[index].bcLodiVelocityX2; + bc->bcLodiVelocityX3 = bcArray[index].bcLodiVelocityX3; + bc->bcLodiLentgh = bcArray[index].bcLodiLentgh; + + bc->nx1 = bcArray[index].nx1; + bc->nx2 = bcArray[index].nx2; + bc->nx3 = bcArray[index].nx3; + for (int iq = 0; iq < 26; iq++) + bc->setQ(bcArray[index].q[iq], iq); + bc->setBcAlgorithmType(bcArray[index].algorithmType); + } + + bcVector.push_back(bc); + index++; + } + + for (int b1 = 0; b1 < boundCondParamStr.bcindexmatrixCount; b1++) + bcindexmatrixV.push_back(intArray1[index1++]); + + for (int b2 = 0; b2 < bcAddArray[n].indexContainer_count; b2++) + indexContainerV.push_back(intArray2[index2++]); + + CbArray3D<int, IndexerX3X2X1> bcim(bcindexmatrixV, boundCondParamStr.nx1, boundCondParamStr.nx2, + boundCondParamStr.nx3); + + SPtr<Block3D> block = grid->getBlock(bcAddArray[n].x1, bcAddArray[n].x2, bcAddArray[n].x3, bcAddArray[n].level); + SPtr<BCProcessor> bcProc = bcProcessor->clone(block->getKernel()); + SPtr<BCArray3D> bcArr(new BCArray3D()); + bcArr->bcindexmatrix = bcim; + bcArr->bcvector = bcVector; + bcArr->indexContainer = indexContainerV; + bcProc->setBCArray(bcArr); + + block->getKernel()->setBCProcessor(bcProc); + } + + delete nullBouCond; + delete[] bcArray; + delete[] bcAddArray; + delete[] intArray1; + delete[] intArray2; + + if (comm->isRoot()) { + UBLOG(logINFO, "MPIIORestartCoProcessor::readBoundaryConds end of restore of data, rank = " << rank); + UBLOG(logINFO, "Physical Memory currently used by current process: " + << Utilities::getPhysMemUsedByMe() / 1073741824.0 << " GB"); + } } ////////////////////////////////////////////////////////////////////////// -void MPIIORestartCoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) -{ - this->lbmKernel = kernel; -} +void MPIIORestartCoProcessor::setLBMKernel(SPtr<LBMKernel> kernel) { this->lbmKernel = kernel; } ////////////////////////////////////////////////////////////////////////// -void MPIIORestartCoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) -{ - this->bcProcessor = bcProcessor; -} - +void MPIIORestartCoProcessor::setBCProcessor(SPtr<BCProcessor> bcProcessor) { this->bcProcessor = bcProcessor; } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.h index fa4cf2619..a5d65c206 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MPIIORestartCoProcessor.h @@ -5,8 +5,8 @@ //#include <PointerDefinitions.h> #include <string> -#include "MPIIODataStructures.h" #include "MPIIOCoProcessor.h" +#include "MPIIODataStructures.h" class Grid3D; class UbScheduler; @@ -14,63 +14,61 @@ class Communicator; class BCProcessor; class LBMKernel; - - -//! \class MPIIORestartCoProcessor -//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating +//! \class MPIIORestartCoProcessor +//! \brief Writes the grid each timestep into the files and reads the grip from the files before regenerating class MPIIORestartCoProcessor : public MPIIOCoProcessor { public: - MPIIORestartCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm); - ~MPIIORestartCoProcessor() override; - //! Each timestep writes the grid into the files - void process(double step) override; - //! Reads the grid from the files before grid reconstruction - void restart(int step); - //! Writes the blocks of the grid into the file cpBlocks.bin - void writeBlocks(int step); - //! Writes the datasets of the blocks into the file cpDataSet.bin - void writeDataSet(int step); - void writeAverageDensityArray(int step); - void writeAverageVelocityArray(int step); - void writeAverageFluktuationsArray(int step); - void writeAverageTripleArray(int step); - void writeShearStressValArray(int step); - void writeRelaxationFactor(int step); - //! Writes the boundary conditions of the blocks into the file cpBC.bin - void writeBoundaryConds(int step); + MPIIORestartCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, SPtr<Communicator> comm); + ~MPIIORestartCoProcessor() override; + //! Each timestep writes the grid into the files + void process(double step) override; + //! Reads the grid from the files before grid reconstruction + void restart(int step); + //! Writes the blocks of the grid into the file cpBlocks.bin + void writeBlocks(int step); + //! Writes the datasets of the blocks into the file cpDataSet.bin + void writeDataSet(int step); + void writeAverageDensityArray(int step); + void writeAverageVelocityArray(int step); + void writeAverageFluktuationsArray(int step); + void writeAverageTripleArray(int step); + void writeShearStressValArray(int step); + void writeRelaxationFactor(int step); + //! Writes the boundary conditions of the blocks into the file cpBC.bin + void writeBoundaryConds(int step); - //! Reads the blocks of the grid from the file cpBlocks.bin - void readBlocks(int step); - //! Reads the datasets of the blocks from the file cpDataSet.bin - void readDataSet(int step); - void readAverageDensityArray(int step); - void readAverageVelocityArray(int step); - void readAverageFluktuationsArray(int step); - void readAverageTripleArray(int step); - void readShearStressValArray(int step); - void readRelaxationFactor(int step); - //! Reads the boundary conditions of the blocks from the file cpBC.bin - void readBoundaryConds(int step); - //! The function sets LBMKernel - void setLBMKernel(SPtr<LBMKernel> kernel); - //!The function sets BCProcessor - void setBCProcessor(SPtr<BCProcessor> bcProcessor); - //!The function truncates the data files - void clearAllFiles(int step); + //! Reads the blocks of the grid from the file cpBlocks.bin + void readBlocks(int step); + //! Reads the datasets of the blocks from the file cpDataSet.bin + void readDataSet(int step); + void readAverageDensityArray(int step); + void readAverageVelocityArray(int step); + void readAverageFluktuationsArray(int step); + void readAverageTripleArray(int step); + void readShearStressValArray(int step); + void readRelaxationFactor(int step); + //! Reads the boundary conditions of the blocks from the file cpBC.bin + void readBoundaryConds(int step); + //! The function sets LBMKernel + void setLBMKernel(SPtr<LBMKernel> kernel); + //! The function sets BCProcessor + void setBCProcessor(SPtr<BCProcessor> bcProcessor); + //! The function truncates the data files + void clearAllFiles(int step); protected: - //std::string path; - //SPtr<Communicator> comm; + // std::string path; + // SPtr<Communicator> comm; private: - //MPI_Datatype gridParamType, block3dType; - MPI_Datatype dataSetType, dataSetSmallType, dataSetDoubleType; - MPI_Datatype boundCondParamType, boundCondType1000, boundCondTypeAdd, bcindexmatrixType; + // MPI_Datatype gridParamType, block3dType; + MPI_Datatype dataSetType, dataSetSmallType, dataSetDoubleType; + MPI_Datatype boundCondParamType, boundCondType1000, boundCondTypeAdd, bcindexmatrixType; - MPIIODataStructures::boundCondParam boundCondParamStr; - SPtr<LBMKernel> lbmKernel; - SPtr<BCProcessor> bcProcessor; + MPIIODataStructures::boundCondParam boundCondParamStr; + SPtr<LBMKernel> lbmKernel; + SPtr<BCProcessor> bcProcessor; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.cpp index 8ea0e64d5..1a5edc27b 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.cpp @@ -1,125 +1,125 @@ #include "MicrophoneArrayCoProcessor.h" -#include "Vector3D.h" -#include "Grid3D.h" -#include "ILBMKernel.h" -#include "Communicator.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "Block3D.h" -#include "DistributionArray3D.h" -#include "DataSet3D.h" +#include "Communicator.h" #include "D3Q27System.h" +#include "DataSet3D.h" +#include "DistributionArray3D.h" +#include "Grid3D.h" +#include "ILBMKernel.h" #include "UbScheduler.h" -#include "BCProcessor.h" -#include "BCArray3D.h" +#include "Vector3D.h" #include <sstream> -MicrophoneArrayCoProcessor::MicrophoneArrayCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string & path, SPtr<Communicator> comm) : CoProcessor(grid, s), path(path), comm(comm) +MicrophoneArrayCoProcessor::MicrophoneArrayCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), comm(comm) { - count = 0; - micID = 0; + count = 0; + micID = 0; } -MicrophoneArrayCoProcessor::~MicrophoneArrayCoProcessor() -= default; +MicrophoneArrayCoProcessor::~MicrophoneArrayCoProcessor() = default; void MicrophoneArrayCoProcessor::process(double step) { - if (microphones.size() > 0) - { - collectData(step); + if (microphones.size() > 0) { + collectData(step); - if (scheduler->isDue(step)) - writeFile(step); - } + if (scheduler->isDue(step)) + writeFile(step); + } - UBLOG(logDEBUG3, "MicrophoneArrayCoProcessor::process:" << step); + UBLOG(logDEBUG3, "MicrophoneArrayCoProcessor::process:" << step); } bool MicrophoneArrayCoProcessor::addMicrophone(Vector3D coords) { - micID++; -// UbTupleInt3 blockIndexes = grid->getBlockIndexes(coords[0], coords[1], coords[2]); + micID++; + // UbTupleInt3 blockIndexes = grid->getBlockIndexes(coords[0], coords[1], coords[2]); - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level<=maxInitLevel; level++) - { - UbTupleInt3 blockIndexes = grid->getBlockIndexes(coords[0], coords[1], coords[2], level); - SPtr<Block3D> block = grid->getBlock(val<1>(blockIndexes), val<2>(blockIndexes), val<3>(blockIndexes), level); - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - if (kernel) - { - SPtr<BCArray3D> bcarray = kernel->getBCProcessor()->getBCArray(); - UbTupleInt3 nodes = grid->getNodeIndexes(block, coords[0], coords[1], coords[2]); - if (!bcarray->isUndefined(val<1>(nodes), val<2>(nodes), val<3>(nodes))) - { + for (int level = minInitLevel; level <= maxInitLevel; level++) { + UbTupleInt3 blockIndexes = grid->getBlockIndexes(coords[0], coords[1], coords[2], level); + SPtr<Block3D> block = grid->getBlock(val<1>(blockIndexes), val<2>(blockIndexes), val<3>(blockIndexes), level); + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + if (kernel) { + SPtr<BCArray3D> bcarray = kernel->getBCProcessor()->getBCArray(); + UbTupleInt3 nodes = grid->getNodeIndexes(block, coords[0], coords[1], coords[2]); + if (!bcarray->isUndefined(val<1>(nodes), val<2>(nodes), val<3>(nodes))) { - if (kernel->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } - SPtr<Mic> mic(new Mic); - mic->id = micID; - mic->distridution = kernel->getDataSet()->getFdistributions(); - mic->nodeIndexes = grid->getNodeIndexes(block, coords[0], coords[1], coords[2]); - microphones.push_back(mic); + if (kernel->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + SPtr<Mic> mic(new Mic); + mic->id = micID; + mic->distridution = kernel->getDataSet()->getFdistributions(); + mic->nodeIndexes = grid->getNodeIndexes(block, coords[0], coords[1], coords[2]); + microphones.push_back(mic); - strVector.push_back(SPtr<std::stringstream>(new std::stringstream)); + strVector.push_back(SPtr<std::stringstream>(new std::stringstream)); - std::string fname = path+"/mic/mic_"+UbSystem::toString(micID)+".csv"; - std::ofstream ostr; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size()>0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file "+fname); - } - ostr << "#microphone position: " << coords[0] << "; " << coords[1] << "; " << coords[2] << "; " << "\n"; - ostr.close(); - return true; + std::string fname = path + "/mic/mic_" + UbSystem::toString(micID) + ".csv"; + std::ofstream ostr; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr << "#microphone position: " << coords[0] << "; " << coords[1] << "; " << coords[2] << "; " + << "\n"; + ostr.close(); + return true; + } } - } - } - } - return false; + } + } + return false; } void MicrophoneArrayCoProcessor::collectData(double step) { - for (int i = 0; i < microphones.size(); i++ ) - { - LBMReal f[D3Q27System::ENDF+1]; - microphones[i]->distridution->getDistribution(f, val<1>(microphones[i]->nodeIndexes), val<2>(microphones[i]->nodeIndexes), val<3>(microphones[i]->nodeIndexes)); - LBMReal vx1, vx2, vx3, rho; - calcMacros(f, rho, vx1, vx2, vx3); - *strVector[i] << step << ';' << rho << '\n'; - } + for (int i = 0; i < microphones.size(); i++) { + LBMReal f[D3Q27System::ENDF + 1]; + microphones[i]->distridution->getDistribution(f, val<1>(microphones[i]->nodeIndexes), + val<2>(microphones[i]->nodeIndexes), + val<3>(microphones[i]->nodeIndexes)); + LBMReal vx1, vx2, vx3, rho; + calcMacros(f, rho, vx1, vx2, vx3); + *strVector[i] << step << ';' << rho << '\n'; + } } -void MicrophoneArrayCoProcessor::writeFile(double /*step*/) +void MicrophoneArrayCoProcessor::writeFile(double /*step*/) { - for (int i = 0; i < microphones.size(); i++) - { - std::string fname = path+"/mic/mic_"+UbSystem::toString(microphones[i]->id)+".csv"; - std::ofstream ostr; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size()>0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file "+fname); - } - ostr << strVector[i]->str(); - ostr.close(); - strVector[i] = SPtr<std::stringstream>(new std::stringstream); - } + for (int i = 0; i < microphones.size(); i++) { + std::string fname = path + "/mic/mic_" + UbSystem::toString(microphones[i]->id) + ".csv"; + std::ofstream ostr; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr << strVector[i]->str(); + ostr.close(); + strVector[i] = SPtr<std::stringstream>(new std::stringstream); + } } \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.h index 73821538b..d6185df6b 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/MicrophoneArrayCoProcessor.h @@ -2,11 +2,11 @@ #define MicrophoneArrayCoProcessor_h__ #include "CoProcessor.h" +#include "LBMSystem.h" +#include "UbTuple.h" +#include <array> #include <string> #include <vector> -#include <array> -#include "UbTuple.h" -#include "LBMSystem.h" class Communicator; class Grid3D; @@ -22,36 +22,38 @@ class DistributionArray3D; class MicrophoneArrayCoProcessor : public CoProcessor { public: - MicrophoneArrayCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, SPtr<Communicator> comm); - ~MicrophoneArrayCoProcessor() override; + MicrophoneArrayCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<Communicator> comm); + ~MicrophoneArrayCoProcessor() override; - //! calls collectData. - void process(double step) override; + //! calls collectData. + void process(double step) override; + + //! add microphone + bool addMicrophone(Vector3D coords); - //! add microphone - bool addMicrophone(Vector3D coords); protected: - void collectData(double step); - void writeFile(double step); + void collectData(double step); + void writeFile(double step); + private: - std::string path; - SPtr<Communicator> comm; + std::string path; + SPtr<Communicator> comm; - struct Mic - { - unsigned int id; - SPtr<DistributionArray3D> distridution; - UbTupleInt3 nodeIndexes; - }; - std::vector< SPtr<Mic> > microphones; + struct Mic { + unsigned int id; + SPtr<DistributionArray3D> distridution; + UbTupleInt3 nodeIndexes; + }; + std::vector<SPtr<Mic>> microphones; - std::vector< SPtr<std::stringstream> > strVector; + std::vector<SPtr<std::stringstream>> strVector; - int count; - int micID; + int count; + int micID; - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; }; #endif // MicrophoneArrayCoProcessor_h__ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.cpp index 43652ec72..46cbba0df 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,60 +34,52 @@ #include "NUPSCounterCoProcessor.h" #include "Communicator.h" -#include "UbScheduler.h" #include "Grid3D.h" +#include "UbScheduler.h" -NUPSCounterCoProcessor::NUPSCounterCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, int numOfThreads, SPtr<Communicator> comm) - : CoProcessor(grid, s), - numOfThreads(numOfThreads), - nup(0), - nup_t(0), - nupsStep(0.0), - comm(comm) +NUPSCounterCoProcessor::NUPSCounterCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, int numOfThreads, + SPtr<Communicator> comm) + : CoProcessor(grid, s), numOfThreads(numOfThreads), nup(0), nup_t(0), nupsStep(0.0), comm(comm) { - if (comm->getProcessID() == comm->getRoot()) - { - timer.resetAndStart(); + if (comm->getProcessID() == comm->getRoot()) { + timer.resetAndStart(); - double nop = comm->getNumberOfProcesses(); - int minInitLevel = grid->getCoarsestInitializedLevel(); - int maxInitLevel = grid->getFinestInitializedLevel(); - UbTupleInt3 blocknx = grid->getBlockNX(); - double nod = (double)(val<1>(blocknx)) * (double)(val<2>(blocknx)) * (double)(val<3>(blocknx)); - nup = 0; + double nop = comm->getNumberOfProcesses(); + int minInitLevel = grid->getCoarsestInitializedLevel(); + int maxInitLevel = grid->getFinestInitializedLevel(); + UbTupleInt3 blocknx = grid->getBlockNX(); + double nod = (double)(val<1>(blocknx)) * (double)(val<2>(blocknx)) * (double)(val<3>(blocknx)); + nup = 0; - for(int level = minInitLevel; level<=maxInitLevel; level++) - { - int nob = grid->getNumberOfBlocks(level); - nup_t += (double)(1<<level) * nob * nod; - } - nup = nup_t / nop; - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + int nob = grid->getNumberOfBlocks(level); + nup_t += (double)(1 << level) * nob * nod; + } + nup = nup_t / nop; + } } ////////////////////////////////////////////////////////////////////////// -NUPSCounterCoProcessor::~NUPSCounterCoProcessor() -= default; +NUPSCounterCoProcessor::~NUPSCounterCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void NUPSCounterCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// void NUPSCounterCoProcessor::collectData(double step) { - if (comm->getProcessID() == comm->getRoot()) - { - double time = timer.stop(); - double nups_t = nup_t*(step-nupsStep)/time; - double nups = nup*(step-nupsStep)/time; - double tnups = nups/(double)numOfThreads; - UBLOG(logINFO, "Calculation step = "<<step); - UBLOG(logINFO, "Total performance = "<<nups_t<<" NUPS"); - UBLOG(logINFO, "Performance per process = "<<nups<<" NUPS"); - UBLOG(logINFO, "Performance per thread = "<<tnups<<" NUPS"); - UBLOG(logINFO, "Time for " << step-nupsStep <<" steps = "<< time <<" s"); - nupsStep = step; - timer.resetAndStart(); - } + if (comm->getProcessID() == comm->getRoot()) { + double time = timer.stop(); + double nups_t = nup_t * (step - nupsStep) / time; + double nups = nup * (step - nupsStep) / time; + double tnups = nups / (double)numOfThreads; + UBLOG(logINFO, "Calculation step = " << step); + UBLOG(logINFO, "Total performance = " << nups_t << " NUPS"); + UBLOG(logINFO, "Performance per process = " << nups << " NUPS"); + UBLOG(logINFO, "Performance per thread = " << tnups << " NUPS"); + UBLOG(logINFO, "Time for " << step - nupsStep << " steps = " << time << " s"); + nupsStep = step; + timer.resetAndStart(); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.h index f111a4b8c..61d2ba0b6 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/NUPSCounterCoProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -45,33 +45,32 @@ class UbScheduler; //! \class NUPSCounterCoProcessor //! \brief A class calculates Nodal Updates Per Second (NUPS) -class NUPSCounterCoProcessor: public CoProcessor +class NUPSCounterCoProcessor : public CoProcessor { public: - //! \brief Construct NUPSCounterCoProcessor object for grid object and scheduler object. - //! \pre The Grid3D and UbScheduler objects must exist. - //! \param grid is observable Grid3D object - //! \param s is UbScheduler object for scheduling of observer - //! \param numOfThreads is number of threads - //! \param comm is Communicator object - NUPSCounterCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, int numOfThreads, SPtr<Communicator> comm); - ~NUPSCounterCoProcessor() override; + //! \brief Construct NUPSCounterCoProcessor object for grid object and scheduler object. + //! \pre The Grid3D and UbScheduler objects must exist. + //! \param grid is observable Grid3D object + //! \param s is UbScheduler object for scheduling of observer + //! \param numOfThreads is number of threads + //! \param comm is Communicator object + NUPSCounterCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, int numOfThreads, SPtr<Communicator> comm); + ~NUPSCounterCoProcessor() override; - void process(double step)override; + void process(double step) override; protected: - //! Collect data for calculation of NUPS - //! \param step is a time step - void collectData(double step); - UbTimer timer; - int numOfThreads; - double numberOfNodes; - double numberOfBlocks; - double nup; - double nup_t; - double nupsStep; - SPtr<Communicator> comm; + //! Collect data for calculation of NUPS + //! \param step is a time step + void collectData(double step); + UbTimer timer; + int numOfThreads; + double numberOfNodes; + double numberOfBlocks; + double nup; + double nup_t; + double nupsStep; + SPtr<Communicator> comm; }; - -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.cpp index 417f713a7..b350f441b 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.cpp @@ -1,221 +1,209 @@ #include "PressureCoefficientCoProcessor.h" #include <WbWriterVtkXmlASCII.h> -#include "LBMKernel.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "DataSet3D.h" #include "Block3D.h" -#include "UbScheduler.h" -#include "Grid3D.h" #include "Communicator.h" -#include "GbCuboid3D.h" #include "D3Q27Interactor.h" -#include "BCArray3D.h" +#include "DataSet3D.h" +#include "GbCuboid3D.h" +#include "Grid3D.h" +#include "LBMKernel.h" +#include "UbScheduler.h" PressureCoefficientCoProcessor::PressureCoefficientCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - GbCuboid3DPtr plane, - const std::string& path, SPtr<Communicator> comm) - : CoProcessor(grid, s), - plane(plane), - path(path), - comm(comm) + GbCuboid3DPtr plane, const std::string &path, + SPtr<Communicator> comm) + : CoProcessor(grid, s), plane(plane), path(path), comm(comm) { - maxStep = scheduler->getMaxEnd(); - numberOfSteps = int(maxStep - scheduler->getMinBegin()); + maxStep = scheduler->getMaxEnd(); + numberOfSteps = int(maxStep - scheduler->getMinBegin()); } ////////////////////////////////////////////////////////////////////////// -PressureCoefficientCoProcessor::~PressureCoefficientCoProcessor() -= default; +PressureCoefficientCoProcessor::~PressureCoefficientCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void PressureCoefficientCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "D3Q27ForcesCoProcessor::update:" << step); + UBLOG(logDEBUG3, "D3Q27ForcesCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void PressureCoefficientCoProcessor::collectData(double step) { - calculateRho(); + calculateRho(); - if (step == maxStep) - { - writeValues((int)step); - } + if (step == maxStep) { + writeValues((int)step); + } } ////////////////////////////////////////////////////////////////////////// void PressureCoefficientCoProcessor::calculateRho() { - double f[D3Q27System::ENDF+1]; - double vx1, vx2, vx3, rho; - std::vector<double> values; - std::vector<double> rvalues; - - for(SPtr<D3Q27Interactor> interactor : interactors) - { - typedef std::map<SPtr<Block3D>, std::set< std::vector<int> > > TransNodeIndicesMap; - for(TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& bcNodeIndicesSet = t.second; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - if (kernel->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } - - int ghostLayerWidth = kernel->getGhostLayerWidth(); - int minX1 = ghostLayerWidth; - int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayerWidth; - int minX2 = ghostLayerWidth; - int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayerWidth; - int minX3 = ghostLayerWidth; - int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayerWidth; - - for(std::vector<int> node : bcNodeIndicesSet) - { - int x1 = node[0]; - int x2 = node[1]; - int x3 = node[2]; - - //without ghost nodes - if (x1 < minX1 || x1 > maxX1 || x2 < minX2 || x2 > maxX2 ||x3 < minX3 || x3 > maxX3) continue; - - if (bcArray->isFluid(x1, x2, x3)) //es kann sein, dass der node von einem anderen interactor z.B. als solid gemarkt wurde!!! - { - double cx1 = val<1>(org) - val<1>(nodeOffset) + x1*dx; - double cx2 = val<2>(org) - val<2>(nodeOffset) + x2*dx; - double cx3 = val<3>(org) - val<3>(nodeOffset) + x3*dx; - if (plane->isPointInGbObject3D(cx1, cx2, cx3)) - { - distributions->getDistribution(f, x1, x2, x3); - calcMacros(f, rho, vx1, vx2, vx3); - values.push_back(cx1); - values.push_back(cx2); - values.push_back(cx3); - values.push_back(rho); - } + double f[D3Q27System::ENDF + 1]; + double vx1, vx2, vx3, rho; + std::vector<double> values; + std::vector<double> rvalues; + + for (SPtr<D3Q27Interactor> interactor : interactors) { + typedef std::map<SPtr<Block3D>, std::set<std::vector<int>>> TransNodeIndicesMap; + for (TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &bcNodeIndicesSet = t.second; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + if (kernel->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; } - } - - } - } - - comm->allGather(values, rvalues); - if (comm->getProcessID() == comm->getRoot()) - { - if (outValues.size() == 0) - { - outValues.resize(rvalues.size()); - } - int size = (int)rvalues.size(); - for (int i = 0; i < size; i+=4) - { - outValues[i] = rvalues[i]; - outValues[i+1] = rvalues[i+1]; - outValues[i+2] = rvalues[i+2]; - outValues[i+3] += rvalues[i+3]; - } - } + int ghostLayerWidth = kernel->getGhostLayerWidth(); + int minX1 = ghostLayerWidth; + int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayerWidth; + int minX2 = ghostLayerWidth; + int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayerWidth; + int minX3 = ghostLayerWidth; + int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayerWidth; + + for (std::vector<int> node : bcNodeIndicesSet) { + int x1 = node[0]; + int x2 = node[1]; + int x3 = node[2]; + + // without ghost nodes + if (x1 < minX1 || x1 > maxX1 || x2 < minX2 || x2 > maxX2 || x3 < minX3 || x3 > maxX3) + continue; + + if (bcArray->isFluid( + x1, x2, + x3)) // es kann sein, dass der node von einem anderen interactor z.B. als solid gemarkt wurde!!! + { + double cx1 = val<1>(org) - val<1>(nodeOffset) + x1 * dx; + double cx2 = val<2>(org) - val<2>(nodeOffset) + x2 * dx; + double cx3 = val<3>(org) - val<3>(nodeOffset) + x3 * dx; + if (plane->isPointInGbObject3D(cx1, cx2, cx3)) { + distributions->getDistribution(f, x1, x2, x3); + calcMacros(f, rho, vx1, vx2, vx3); + values.push_back(cx1); + values.push_back(cx2); + values.push_back(cx3); + values.push_back(rho); + } + } + } + } + } + + comm->allGather(values, rvalues); + if (comm->getProcessID() == comm->getRoot()) { + if (outValues.size() == 0) { + outValues.resize(rvalues.size()); + } + int size = (int)rvalues.size(); + for (int i = 0; i < size; i += 4) { + outValues[i] = rvalues[i]; + outValues[i + 1] = rvalues[i + 1]; + outValues[i + 2] = rvalues[i + 2]; + outValues[i + 3] += rvalues[i + 3]; + } + } } ////////////////////////////////////////////////////////////////////////// void PressureCoefficientCoProcessor::writeValues(int step) { - if (comm->getProcessID() == comm->getRoot()) - { - datanames.resize(0); - datanames.emplace_back("rho"); - data.resize(datanames.size()); - - std::ofstream ostr; - std::string fname = path+UbSystem::toString(step)+".csv"; - ostr.open(fname.c_str(), std::ios_base::out); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size()>0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file "+fname); - } - - ostr << "x1;x2;x3;rho\n"; - - int size = (int)outValues.size(); - for (int i = 0; i < size; i+=4) - { - ostr << outValues[i] << ";" << outValues[i+1] <<";" << outValues[i+2] << ";" << outValues[i+3]/numberOfSteps << std::endl; - - int index = 0; - nodes.push_back(makeUbTuple(float(outValues[i]), - float(outValues[i+1]), - float(outValues[i+2]))); - - data[index++].push_back(outValues[i+3]/numberOfSteps); - } - - ostr.close(); - - WbWriterVtkXmlASCII::getInstance()->writeNodesWithNodeData(path+UbSystem::toString(step), nodes, datanames, data); - - fname = path+UbSystem::toString(step)+".bin"; - std::ofstream out(fname.c_str(), std::ios::out | std::ios::binary); - if (!out) - { - out.clear(); //flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! - std::string path = UbSystem::getPathFromString(fname); - if (path.size()>0) { UbSystem::makeDirectory(path); out.open(fname.c_str(), std::ios::out | std::ios::binary); } - if (!out) throw UbException(UB_EXARGS, "couldn't open file "+fname); - } - - out.write((char*)&outValues[0], outValues.size()*sizeof(double)); - - out.close(); - - UBLOG(logINFO, "PressureCoefficientCoProcessor::writeValues() step: " << (int)step); - } + if (comm->getProcessID() == comm->getRoot()) { + datanames.resize(0); + datanames.emplace_back("rho"); + data.resize(datanames.size()); + + std::ofstream ostr; + std::string fname = path + UbSystem::toString(step) + ".csv"; + ostr.open(fname.c_str(), std::ios_base::out); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + + ostr << "x1;x2;x3;rho\n"; + + int size = (int)outValues.size(); + for (int i = 0; i < size; i += 4) { + ostr << outValues[i] << ";" << outValues[i + 1] << ";" << outValues[i + 2] << ";" + << outValues[i + 3] / numberOfSteps << std::endl; + + int index = 0; + nodes.push_back(makeUbTuple(float(outValues[i]), float(outValues[i + 1]), float(outValues[i + 2]))); + + data[index++].push_back(outValues[i + 3] / numberOfSteps); + } + + ostr.close(); + + WbWriterVtkXmlASCII::getInstance()->writeNodesWithNodeData(path + UbSystem::toString(step), nodes, datanames, + data); + + fname = path + UbSystem::toString(step) + ".bin"; + std::ofstream out(fname.c_str(), std::ios::out | std::ios::binary); + if (!out) { + out.clear(); // flags ruecksetzen (ansonsten liefert utern if(!out) weiterhin true!!! + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + out.open(fname.c_str(), std::ios::out | std::ios::binary); + } + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + + out.write((char *)&outValues[0], outValues.size() * sizeof(double)); + + out.close(); + + UBLOG(logINFO, "PressureCoefficientCoProcessor::writeValues() step: " << (int)step); + } } void PressureCoefficientCoProcessor::readValues(int step) { - if (comm->isRoot()) - { - std::string fname = path+UbSystem::toString(step)+".bin"; - std::ifstream in(fname.c_str(), std::ios::in | std::ios::binary); - if (!in) - { - throw UbException(UB_EXARGS, "couldn't open file "+fname); - } + if (comm->isRoot()) { + std::string fname = path + UbSystem::toString(step) + ".bin"; + std::ifstream in(fname.c_str(), std::ios::in | std::ios::binary); + if (!in) { + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } - // get length of file: - in.seekg(0, in.end); - int length = (int)in.tellg(); - in.seekg(0, in.beg); + // get length of file: + in.seekg(0, in.end); + int length = (int)in.tellg(); + in.seekg(0, in.beg); - outValues.resize(length/sizeof(double)); + outValues.resize(length / sizeof(double)); - in.read((char*)&outValues[0], length); + in.read((char *)&outValues[0], length); - in.close(); + in.close(); - UBLOG(logINFO, "PressureCoefficientCoProcessor::readValues() step: " << (int)step); - } + UBLOG(logINFO, "PressureCoefficientCoProcessor::readValues() step: " << (int)step); + } } ////////////////////////////////////////////////////////////////////////// void PressureCoefficientCoProcessor::addInteractor(SPtr<D3Q27Interactor> interactor) { - interactors.push_back(interactor); + interactors.push_back(interactor); } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.h index 441e6ca8e..f8f1d80d9 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/PressureCoefficientCoProcessor.h @@ -9,48 +9,45 @@ #include "LBMSystem.h" #include "UbTuple.h" - class GbCuboid3D; class D3Q27Interactor; class Communicator; class Grid3D; class UbScheduler; -class PressureCoefficientCoProcessor: public CoProcessor +class PressureCoefficientCoProcessor : public CoProcessor { public: - PressureCoefficientCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - SPtr<GbCuboid3D> plane, const std::string& path, SPtr<Communicator> comm); - ~PressureCoefficientCoProcessor() override; + PressureCoefficientCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<GbCuboid3D> plane, + const std::string &path, SPtr<Communicator> comm); + ~PressureCoefficientCoProcessor() override; - void process(double step) override; + void process(double step) override; - void addInteractor(SPtr<D3Q27Interactor> interactor); - void readValues(int step); + void addInteractor(SPtr<D3Q27Interactor> interactor); + void readValues(int step); protected: - void collectData(double step); - void calculateRho(); - void writeValues(int step); + void collectData(double step); + void calculateRho(); + void writeValues(int step); private: SPtr<GbCuboid3D> plane; - std::string path; - SPtr<Communicator> comm; - std::vector<SPtr<D3Q27Interactor> > interactors; - int numberOfSteps; - double maxStep; + std::string path; + SPtr<Communicator> comm; + std::vector<SPtr<D3Q27Interactor>> interactors; + int numberOfSteps; + double maxStep; - std::vector<UbTupleFloat3> nodes; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; + std::vector<UbTupleFloat3> nodes; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; - std::vector<double> outValues; + std::vector<double> outValues; - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; }; #endif // PressureDistributionCoProcessor_h__ - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.cpp index 46399e0bd..e9b94dc6a 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.cpp @@ -9,93 +9,113 @@ #include <fstream> +#include "Communicator.h" +#include "Grid3D.h" #include "IntegrateValuesHelper.h" #include "LBMUnitConverter.h" -#include "Communicator.h" #include "UbScheduler.h" -#include "Grid3D.h" - -PressureDifferenceCoProcessor::PressureDifferenceCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, - SPtr<IntegrateValuesHelper> h1, SPtr<IntegrateValuesHelper> h2, - LBMReal rhoReal, LBMReal uReal, LBMReal uLB, - SPtr<Communicator> comm) +PressureDifferenceCoProcessor::PressureDifferenceCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, + const std::string &path, SPtr<IntegrateValuesHelper> h1, + SPtr<IntegrateValuesHelper> h2, LBMReal rhoReal, + LBMReal uReal, LBMReal uLB, SPtr<Communicator> comm) - : CoProcessor(grid, s) - , path(path) - , h1(h1) - , h2(h2) - ,comm(comm) + : CoProcessor(grid, s), path(path), h1(h1), h2(h2), comm(comm) { - if (comm->getProcessID() == comm->getRoot()) - { - std::ofstream ostr; - std::string fname = path; - ostr.open(fname.c_str(), std::ios_base::out); - if(!ostr) - { - ostr.clear(); - std::string file_path = UbSystem::getPathFromString(fname); - if(file_path.size()>0){ UbSystem::makeDirectory(file_path); ostr.open(fname.c_str(), std::ios_base::out);} - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } - ostr << "step" << "\t" << "nodes1" << "\t" << "nodes2" << "\t"; - ostr << "sRho1" << "\t" << "p1_1" << "\t" << "sRho2" << "\t" << "p1_2" << "\t" << "deltaP1"<< "\t"; - ostr << "sPress1" << "\t" << "p2_1" << "\t" << "sPress2" << "\t" << "p2_2" << "\t" << "deltaP2"; - ostr << std::endl; - ostr.close(); + if (comm->getProcessID() == comm->getRoot()) { + std::ofstream ostr; + std::string fname = path; + ostr.open(fname.c_str(), std::ios_base::out); + if (!ostr) { + ostr.clear(); + std::string file_path = UbSystem::getPathFromString(fname); + if (file_path.size() > 0) { + UbSystem::makeDirectory(file_path); + ostr.open(fname.c_str(), std::ios_base::out); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr << "step" + << "\t" + << "nodes1" + << "\t" + << "nodes2" + << "\t"; + ostr << "sRho1" + << "\t" + << "p1_1" + << "\t" + << "sRho2" + << "\t" + << "p1_2" + << "\t" + << "deltaP1" + << "\t"; + ostr << "sPress1" + << "\t" + << "p2_1" + << "\t" + << "sPress2" + << "\t" + << "p2_2" + << "\t" + << "deltaP2"; + ostr << std::endl; + ostr.close(); - factor1 = (1.0/3.0)*rhoReal*(uReal/uLB)*(uReal/uLB); - factor2 = rhoReal*(uReal/uLB)*(uReal/uLB); - } + factor1 = (1.0 / 3.0) * rhoReal * (uReal / uLB) * (uReal / uLB); + factor2 = rhoReal * (uReal / uLB) * (uReal / uLB); + } } ////////////////////////////////////////////////////////////////////////// -PressureDifferenceCoProcessor::~PressureDifferenceCoProcessor() -= default; +PressureDifferenceCoProcessor::~PressureDifferenceCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void PressureDifferenceCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// void PressureDifferenceCoProcessor::collectData(double step) { - h1->calculateMQ(); - h2->calculateMQ(); - - if (comm->getProcessID() == comm->getRoot()) - { - int istep = static_cast<int>(step); - std::ofstream ostr; - double nn1 = h1->getNumberOfFluidsNodes(); - double nn2 = h2->getNumberOfFluidsNodes(); - double rho1 = h1->getRho(); - double rho2 = h2->getRho(); - double p1_1 = (rho1/nn1) * factor1; - double p1_2 = (rho2/nn2) * factor1; - double dp1 = p1_1 - p1_2; + h1->calculateMQ(); + h2->calculateMQ(); + + if (comm->getProcessID() == comm->getRoot()) { + int istep = static_cast<int>(step); + std::ofstream ostr; + double nn1 = h1->getNumberOfFluidsNodes(); + double nn2 = h2->getNumberOfFluidsNodes(); + double rho1 = h1->getRho(); + double rho2 = h2->getRho(); + double p1_1 = (rho1 / nn1) * factor1; + double p1_2 = (rho2 / nn2) * factor1; + double dp1 = p1_1 - p1_2; - //double press1 = h1->getPress(); - //double press2 = h2->getPress(); - //double p2_1 = (press1/nn1) * factor2; - //double p2_2 = (press2/nn2) * factor2; - //double dp2 = p2_1 - p2_2; + // double press1 = h1->getPress(); + // double press2 = h2->getPress(); + // double p2_1 = (press1/nn1) * factor2; + // double p2_2 = (press2/nn2) * factor2; + // double dp2 = p2_1 - p2_2; - std::string fname = path; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if(!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app);} - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } + std::string fname = path; + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } - ostr << istep << "\t" << nn1 << "\t" << nn2 << "\t"; - ostr << rho1 << "\t" << p1_1 << "\t" << rho2 << "\t" << p1_2 << "\t" << dp1 << "\t"; - //ostr << press1 << "\t" << p2_1 << "\t" << press2 << "\t" << p2_2 << "\t" << dp2; - ostr << std::endl; - ostr.close(); - } + ostr << istep << "\t" << nn1 << "\t" << nn2 << "\t"; + ostr << rho1 << "\t" << p1_1 << "\t" << rho2 << "\t" << p1_2 << "\t" << dp1 << "\t"; + // ostr << press1 << "\t" << p2_1 << "\t" << press2 << "\t" << p2_2 << "\t" << dp2; + ostr << std::endl; + ostr.close(); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.h index c3903443d..e805c250b 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/PressureDifferenceCoProcessor.h @@ -20,25 +20,27 @@ class UbScheduler; class LBMUnitConverter; class IntegrateValuesHelper; -class PressureDifferenceCoProcessor: public CoProcessor { +class PressureDifferenceCoProcessor : public CoProcessor +{ public: - PressureDifferenceCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, - SPtr<IntegrateValuesHelper> h1, SPtr<IntegrateValuesHelper> h2, - LBMReal rhoReal, LBMReal uReal, LBMReal uLB, - /*const SPtr<LBMUnitConverter> conv,*/ SPtr<Communicator> comm); - ~PressureDifferenceCoProcessor() override; + PressureDifferenceCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + SPtr<IntegrateValuesHelper> h1, SPtr<IntegrateValuesHelper> h2, LBMReal rhoReal, + LBMReal uReal, LBMReal uLB, + /*const SPtr<LBMUnitConverter> conv,*/ SPtr<Communicator> comm); + ~PressureDifferenceCoProcessor() override; - void process(double step) override; + void process(double step) override; protected: SPtr<IntegrateValuesHelper> h1, h2; - std::string path; - SPtr<LBMUnitConverter> conv; - void collectData(double step); + std::string path; + SPtr<LBMUnitConverter> conv; + void collectData(double step); SPtr<Communicator> comm; - LBMReal factor1; //= (1/3)*rhoReal*(uReal/uLB)^2 for calculation pReal = rhoLB * (1/3)*rhoReal*(uReal/uLB)^2, rhoReal and uReal in SI - LBMReal factor2; //= rhoReal*(uReal/uLB)^2 for calculation pReal = press * rhoReal*(uReal/uLB)^2, rhoReal and uReal in SI + LBMReal factor1; //= (1/3)*rhoReal*(uReal/uLB)^2 for calculation pReal = rhoLB * (1/3)*rhoReal*(uReal/uLB)^2, + //rhoReal and uReal in SI + LBMReal factor2; //= rhoReal*(uReal/uLB)^2 for calculation pReal = press * rhoReal*(uReal/uLB)^2, rhoReal and + //uReal in SI }; - #endif /* D3Q27RHODIFFERENCECoProcessor_H_ */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.cpp index 75801803c..1aaa4bf11 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.cpp @@ -1,392 +1,357 @@ #include "QCriterionCoProcessor.h" -#include "LBMKernel.h" #include "BCProcessor.h" -#include "basics/writer/WbWriterVtkXmlASCII.h" +#include "Block3D.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "Block3D.h" +#include "LBMKernel.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" +#include "BCArray3D.h" #include "Communicator.h" #include "UbScheduler.h" -#include "BCArray3D.h" - -QCriterionCoProcessor::QCriterionCoProcessor(SPtr<Grid3D> grid, const std::string& path, - WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm) - : CoProcessor(grid, s), - path(path), - comm(comm), - writer(writer) +QCriterionCoProcessor::QCriterionCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), comm(comm), writer(writer) { - init(); + init(); } ////////////////////////////////////////////////////////////////////////// void QCriterionCoProcessor::init() { - gridRank = comm->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = comm->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - blockVector.resize(maxInitLevel+1); + blockVector.resize(maxInitLevel + 1); - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); //grid: private variable in CoProcessor. Initialized by filling with blocks - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks( + level, gridRank, true, + blockVector[level]); // grid: private variable in CoProcessor. Initialized by filling with blocks + } } ////////////////////////////////////////////////////////////////////////// void QCriterionCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "QCriterionCoProcessor::update:" << step); + UBLOG(logDEBUG3, "QCriterionCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void QCriterionCoProcessor::collectData(double step) { - int istep = static_cast<int>(step); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); - - } - } - } - - std::string partName = writer->writeOctsWithNodeData(path+ UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep),nodes,cells,datanames,data); - size_t found=partName.find_last_of("//"); - std::string piece = partName.substr(found+1); - - std::vector<std::string> cellDataNames; - - //distributed writing as in MacroscopicValuesCoProcessor.cpp - std::vector<std::string> pieces = comm->gather(piece); //comm: MPI-Wrapper - if (comm->getProcessID() == comm->getRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(path+"_"+UbSystem::toString(istep),pieces,datanames,cellDataNames); - - std::vector<std::string> filenames; - filenames.push_back(pname); - if (step == CoProcessor::scheduler->getMinBegin()) //first time in timeseries - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"_collection",filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path+"_collection",filenames,istep,false); - } - UBLOG(logINFO,"QCriterionCoProcessor step: " << istep); - } - - clearData(); - - + int istep = static_cast<int>(step); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } + } + } + + std::string partName = writer->writeOctsWithNodeData( + path + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep), nodes, cells, datanames, data); + size_t found = partName.find_last_of("//"); + std::string piece = partName.substr(found + 1); + + std::vector<std::string> cellDataNames; + + // distributed writing as in MacroscopicValuesCoProcessor.cpp + std::vector<std::string> pieces = comm->gather(piece); // comm: MPI-Wrapper + if (comm->getProcessID() == comm->getRoot()) { + std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile( + path + "_" + UbSystem::toString(istep), pieces, datanames, cellDataNames); + + std::vector<std::string> filenames; + filenames.push_back(pname); + if (step == CoProcessor::scheduler->getMinBegin()) // first time in timeseries + { + WbWriterVtkXmlASCII::getInstance()->writeCollection(path + "_collection", filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "_collection", filenames, istep, false); + } + UBLOG(logINFO, "QCriterionCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void QCriterionCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void QCriterionCoProcessor::addData(const SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("q"); - datanames.emplace_back("scaleFactor"); - data.resize(datanames.size()); - - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - - unsigned int SWB,SEB,NEB,NWB,SWT,SET,NET,NWT; - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - - int currentLevel = block->getLevel(); - //nummern vergeben und node std::vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - maxX1 -= 2; //-2 wegen ghost layer: - maxX2 -= 2; //0-maxXi-1 ist arraygroesse. - maxX3 -= 2; //ueberlapp 1 in +,- Richtung. zum schreiben werden statt feldern von 1 bis (max-2) felder von 0 bis max-3 verwendet! - - - int nr = (int)nodes.size(); - - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - //nodeNumbers-vektor wird mit koordinaten befuellt - int index = 0; - nodeNumbers(ix1,ix2,ix3) = nr++; - nodes.push_back( makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1*dx), - float(val<2>(org) - val<2>(nodeOffset) + ix2*dx), - float(val<3>(org) - val<3>(nodeOffset) + ix3*dx)) ); - - ///////////////////////////// - // Geschwindigkeitsvektoren - LBMReal vE[3]; - LBMReal vW[3]; - LBMReal vN[3]; - LBMReal vS[3]; - LBMReal vT[3]; - LBMReal vB[3]; - //hole geschwindigkeiten an nachbarknoten - getNeighborVelocities(1,0,0, ix1, ix2, ix3, block, vE, vW); - getNeighborVelocities(0,1,0, ix1, ix2, ix3, block, vN, vS); - getNeighborVelocities(0,0,1, ix1, ix2, ix3, block, vT, vB); - ////////////////////////////////// - //derivatives - LBMReal duxdy=(vN[xdir]-vS[xdir])*0.5; - LBMReal duydx=(vE[ydir]-vW[ydir])*0.5; - LBMReal duxdz=(vT[xdir]-vB[xdir])*0.5; - LBMReal duzdx=(vE[zdir]-vW[zdir])*0.5; - LBMReal duydz=(vT[ydir]-vB[ydir])*0.5; - LBMReal duzdy=(vN[zdir]-vS[zdir])*0.5; - - LBMReal duxdx=(vE[xdir]-vW[xdir])*0.5; - LBMReal duydy=(vN[ydir]-vS[ydir])*0.5; - LBMReal duzdz=(vT[zdir]-vB[zdir])*0.5; - - LBMReal scaleFactor=(double)(1<<(currentLevel-minInitLevel));//pow(2.0,(double)(currentLevel-minInitLevel));//finer grid -> current level higher. coarsest grid: currentLevel=minInitLevel=0 - // Q=-0.5*(S_ij S_ij - Omega_ij Omega_ij) => regions where vorticity is larger than strain rate - LBMReal q=-(duxdy*duydx+duxdz*duzdx+duydz*duzdy+duxdx*duxdx+duydy*duydy+duzdz*duzdz)*scaleFactor; - - data[index++].push_back( q ); - data[index++].push_back( scaleFactor ); - - } - } - } - } - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - //cell vector erstellen - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if( (SWB=nodeNumbers( ix1 , ix2, ix3 )) >= 0 - && (SEB=nodeNumbers( ix1+1, ix2, ix3 )) >= 0 - && (NEB=nodeNumbers( ix1+1, ix2+1, ix3 )) >= 0 - && (NWB=nodeNumbers( ix1 , ix2+1, ix3 )) >= 0 - && (SWT=nodeNumbers( ix1 , ix2, ix3+1 )) >= 0 - && (SET=nodeNumbers( ix1+1, ix2, ix3+1 )) >= 0 - && (NET=nodeNumbers( ix1+1, ix2+1, ix3+1 )) >= 0 - && (NWT=nodeNumbers( ix1 , ix2+1, ix3+1 )) >= 0 ) - { - // for valid points: neighbors are added to cells-vector - cells.push_back( makeUbTuple(SWB,SEB,NEB,NWB,SWT,SET,NET,NWT) ); - } - } - } - } - + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("q"); + datanames.emplace_back("scaleFactor"); + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + + int currentLevel = block->getLevel(); + // nummern vergeben und node std::vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; //-2 wegen ghost layer: + maxX2 -= 2; // 0-maxXi-1 ist arraygroesse. + maxX3 -= 2; // ueberlapp 1 in +,- Richtung. zum schreiben werden statt feldern von 1 bis (max-2) felder von 0 bis + // max-3 verwendet! + + int nr = (int)nodes.size(); + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + // nodeNumbers-vektor wird mit koordinaten befuellt + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + ///////////////////////////// + // Geschwindigkeitsvektoren + LBMReal vE[3]; + LBMReal vW[3]; + LBMReal vN[3]; + LBMReal vS[3]; + LBMReal vT[3]; + LBMReal vB[3]; + // hole geschwindigkeiten an nachbarknoten + getNeighborVelocities(1, 0, 0, ix1, ix2, ix3, block, vE, vW); + getNeighborVelocities(0, 1, 0, ix1, ix2, ix3, block, vN, vS); + getNeighborVelocities(0, 0, 1, ix1, ix2, ix3, block, vT, vB); + ////////////////////////////////// + // derivatives + LBMReal duxdy = (vN[xdir] - vS[xdir]) * 0.5; + LBMReal duydx = (vE[ydir] - vW[ydir]) * 0.5; + LBMReal duxdz = (vT[xdir] - vB[xdir]) * 0.5; + LBMReal duzdx = (vE[zdir] - vW[zdir]) * 0.5; + LBMReal duydz = (vT[ydir] - vB[ydir]) * 0.5; + LBMReal duzdy = (vN[zdir] - vS[zdir]) * 0.5; + + LBMReal duxdx = (vE[xdir] - vW[xdir]) * 0.5; + LBMReal duydy = (vN[ydir] - vS[ydir]) * 0.5; + LBMReal duzdz = (vT[zdir] - vB[zdir]) * 0.5; + + LBMReal scaleFactor = + (double)(1 + << (currentLevel - + minInitLevel)); // pow(2.0,(double)(currentLevel-minInitLevel));//finer grid -> + // current level higher. coarsest grid: currentLevel=minInitLevel=0 + // Q=-0.5*(S_ij S_ij - Omega_ij Omega_ij) => regions where vorticity is larger than strain rate + LBMReal q = -(duxdy * duydx + duxdz * duzdx + duydz * duzdy + duxdx * duxdx + duydy * duydy + + duzdz * duzdz) * + scaleFactor; + + data[index++].push_back(q); + data[index++].push_back(scaleFactor); + } + } + } + } + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + // for valid points: neighbors are added to cells-vector + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } + } + } + } } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void QCriterionCoProcessor::getNeighborVelocities(int offx, int offy, int offz, int ix1, int ix2, int ix3, const SPtr<Block3D> block, LBMReal* vE, LBMReal* vW) +void QCriterionCoProcessor::getNeighborVelocities(int offx, int offy, int offz, int ix1, int ix2, int ix3, + const SPtr<Block3D> block, LBMReal *vE, LBMReal *vW) { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - - bool compressible = block->getKernel()->getCompressible(); - -// int minX1 = 0; -// int minX2 = 0; -// int minX3 = 0; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - if (maxX1<3) throw UbException(UB_EXARGS,"QCriterionCoProcessor: NX1 too small for FD stencils!"); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - bool checkInterpolation=true; - bool neighNodeIsBC=false; - SPtr<BoundaryConditions> bcPtr; - - int rankSelf= block->getRank(); - - if (!(offx+offy+offz)==1) // FIXME: logical not is only applied to the left hand side of this comparison - throw UbException(UB_EXARGS,"getNeighborVelocities called for diagonal directions!"); - - //////get neighbor nodes, if existent - if ((ix1==0 && offx==1) || (ix2==0 && offy==1) || (ix3==0 && offz==1)) - { - int RankNeighborW; - Vector3D orgNodeRW = grid->getNodeCoordinates(block, ix1, ix2, ix3); - double xp000= orgNodeRW[0]; - double yp000= orgNodeRW[1]; - double zp000= orgNodeRW[2]; - - int currentLevel = block->getLevel(); - UbTupleInt3 blockIndexes = grid->getBlockIndexes(xp000,yp000, zp000,currentLevel); - SPtr<Block3D> blockNeighW; - - if ((val<1>(blockIndexes)!=0 && offx==1) || (val<2>(blockIndexes)!=0 && offy==1) || (val<3>(blockIndexes)!=0 && offz==1)) - { - - blockNeighW = grid->getBlock(val<1>(blockIndexes)-offx, val<2>(blockIndexes)-offy, val<3>(blockIndexes)-offz, currentLevel); - - } - else if (offx==1 && grid->isPeriodicX1()) - { - blockNeighW = grid->getBlock((grid->getNX1()-1), val<2>(blockIndexes), val<3>(blockIndexes), currentLevel); - } - else if (offy==1 && grid->isPeriodicX1()) - { - blockNeighW = grid->getBlock(val<1>(blockIndexes),(grid->getNX2()-1), val<3>(blockIndexes), currentLevel); - } - else if (offz==1 && grid->isPeriodicX1()) - { - blockNeighW = grid->getBlock( val<1>(blockIndexes), val<2>(blockIndexes),(grid->getNX3()-1), currentLevel); - } - else neighNodeIsBC; // FIXME??? - - if(blockNeighW && blockNeighW->isActive()) - { - RankNeighborW= blockNeighW->getRank(); - } - else - { - - blockNeighW = block; - RankNeighborW= blockNeighW->getRank(); - checkInterpolation=false; - } - if (RankNeighborW!=rankSelf) - { - - blockNeighW = block; - RankNeighborW= blockNeighW->getRank(); - checkInterpolation=false; - } - - /////////////////////////////////////// - ////compute distribution at neighboring nodes from neighboring blocks - - if (!checkInterpolation || neighNodeIsBC) - { - SPtr<ILBMKernel> kernelW = blockNeighW->getKernel(); - SPtr<BCArray3D> bcArrayW = kernelW->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributionsW = kernelW->getDataSet()->getFdistributions(); - LBMReal fW2[27]; - LBMReal fW[27]; - LBMReal f0[27]; - LBMReal fE[27]; - LBMReal v0[3]; - LBMReal vW2[3]; - //distributionsW->getDistribution(fW2, std::max(ix1+2*offx,1), std::max(ix2+2*offy,1), std::max(ix3+2*offz,1)); - //distributionsW->getDistribution(fW, std::max(ix1+offx,1), std::max(ix2+offy,1), std::max(ix3+offz,1)); - //distributionsW->getDistribution(f0, std::max(ix1 ,1), std::max(ix2 ,1), std::max(ix3 ,1)); - //distributions->getDistribution(fE, std::max(ix1+offx ,1), std::max(ix2+offy ,1), std::max(ix3+offz ,1)); //E:= plus 1 - distributionsW->getDistribution(fW2, std::max(ix1+2*offx,0), std::max(ix2+2*offy,0), std::max(ix3+2*offz,0)); - distributionsW->getDistribution(fW, std::max(ix1+offx,0), std::max(ix2+offy,0), std::max(ix3+offz,0)); - distributionsW->getDistribution(f0, std::max(ix1 ,0), std::max(ix2 ,0), std::max(ix3 ,0)); - distributions->getDistribution(fE, std::max(ix1+offx ,0), std::max(ix2+offy ,0), std::max(ix3+offz ,0)); //E:= plus 1 - - computeVelocity(fE,vE,compressible); - computeVelocity(fW,vW,compressible); - computeVelocity(fW2,vW2,compressible); - computeVelocity(f0,v0,compressible); - //second order non-symetric interpolation - vW[0]=v0[0]*1.5-vW[0]+0.5*vW2[0]; - vW[1]=v0[1]*1.5-vW[1]+0.5*vW2[1]; - vW[2]=v0[2]*1.5-vW[2]+0.5*vW2[2]; - //throw UbException(UB_EXARGS,"Parallel or Non-Uniform Simulation -- not yet implemented"); - } - else - { - SPtr<ILBMKernel> kernelW = blockNeighW->getKernel(); - SPtr<BCArray3D> bcArrayW = kernelW->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributionsW = kernelW->getDataSet()->getFdistributions(); - LBMReal fW[27]; - - if (offx==1) - { - distributionsW->getDistribution(fW, (distributions->getNX1())-1, ix2, ix3); //moved one block backward, now get last entry - } - else if (offy==1) - { - distributionsW->getDistribution(fW, ix1,(distributions->getNX2())-1, ix3); - - } - else if (offz==1) - { - distributionsW->getDistribution(fW, ix1,ix2,distributions->getNX3()-1); - } - computeVelocity(fW,vW,compressible); - } - - - } - else - { - //data available in current block: - LBMReal fW[27]; - distributions->getDistribution(fW, ix1-offx, ix2-offy, ix3-offz); - computeVelocity(fW,vW,compressible); - - } - if (checkInterpolation) - { - //in plus-direction data is available in current block because of ghost layers - LBMReal fE[27]; - distributions->getDistribution(fE, ix1+offx, ix2+offy, ix3+offz); //E:= plus 1 - computeVelocity(fE,vE,compressible); - } + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + + bool compressible = block->getKernel()->getCompressible(); + + // int minX1 = 0; + // int minX2 = 0; + // int minX3 = 0; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + if (maxX1 < 3) + throw UbException(UB_EXARGS, "QCriterionCoProcessor: NX1 too small for FD stencils!"); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + bool checkInterpolation = true; + bool neighNodeIsBC = false; + SPtr<BoundaryConditions> bcPtr; + + int rankSelf = block->getRank(); + + if (!(offx + offy + offz) == 1) // FIXME: logical not is only applied to the left hand side of this comparison + throw UbException(UB_EXARGS, "getNeighborVelocities called for diagonal directions!"); + + //////get neighbor nodes, if existent + if ((ix1 == 0 && offx == 1) || (ix2 == 0 && offy == 1) || (ix3 == 0 && offz == 1)) { + int RankNeighborW; + Vector3D orgNodeRW = grid->getNodeCoordinates(block, ix1, ix2, ix3); + double xp000 = orgNodeRW[0]; + double yp000 = orgNodeRW[1]; + double zp000 = orgNodeRW[2]; + + int currentLevel = block->getLevel(); + UbTupleInt3 blockIndexes = grid->getBlockIndexes(xp000, yp000, zp000, currentLevel); + SPtr<Block3D> blockNeighW; + + if ((val<1>(blockIndexes) != 0 && offx == 1) || (val<2>(blockIndexes) != 0 && offy == 1) || + (val<3>(blockIndexes) != 0 && offz == 1)) { + + blockNeighW = grid->getBlock(val<1>(blockIndexes) - offx, val<2>(blockIndexes) - offy, + val<3>(blockIndexes) - offz, currentLevel); + + } else if (offx == 1 && grid->isPeriodicX1()) { + blockNeighW = + grid->getBlock((grid->getNX1() - 1), val<2>(blockIndexes), val<3>(blockIndexes), currentLevel); + } else if (offy == 1 && grid->isPeriodicX1()) { + blockNeighW = + grid->getBlock(val<1>(blockIndexes), (grid->getNX2() - 1), val<3>(blockIndexes), currentLevel); + } else if (offz == 1 && grid->isPeriodicX1()) { + blockNeighW = + grid->getBlock(val<1>(blockIndexes), val<2>(blockIndexes), (grid->getNX3() - 1), currentLevel); + } else + neighNodeIsBC; // FIXME??? + + if (blockNeighW && blockNeighW->isActive()) { + RankNeighborW = blockNeighW->getRank(); + } else { + + blockNeighW = block; + RankNeighborW = blockNeighW->getRank(); + checkInterpolation = false; + } + if (RankNeighborW != rankSelf) { + + blockNeighW = block; + RankNeighborW = blockNeighW->getRank(); + checkInterpolation = false; + } + + /////////////////////////////////////// + ////compute distribution at neighboring nodes from neighboring blocks + + if (!checkInterpolation || neighNodeIsBC) { + SPtr<ILBMKernel> kernelW = blockNeighW->getKernel(); + SPtr<BCArray3D> bcArrayW = kernelW->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributionsW = kernelW->getDataSet()->getFdistributions(); + LBMReal fW2[27]; + LBMReal fW[27]; + LBMReal f0[27]; + LBMReal fE[27]; + LBMReal v0[3]; + LBMReal vW2[3]; + // distributionsW->getDistribution(fW2, std::max(ix1+2*offx,1), std::max(ix2+2*offy,1), + // std::max(ix3+2*offz,1)); distributionsW->getDistribution(fW, std::max(ix1+offx,1), std::max(ix2+offy,1), + // std::max(ix3+offz,1)); distributionsW->getDistribution(f0, std::max(ix1 ,1), std::max(ix2 ,1), + // std::max(ix3 ,1)); distributions->getDistribution(fE, std::max(ix1+offx ,1), std::max(ix2+offy ,1), + // std::max(ix3+offz ,1)); //E:= plus 1 + distributionsW->getDistribution(fW2, std::max(ix1 + 2 * offx, 0), std::max(ix2 + 2 * offy, 0), + std::max(ix3 + 2 * offz, 0)); + distributionsW->getDistribution(fW, std::max(ix1 + offx, 0), std::max(ix2 + offy, 0), + std::max(ix3 + offz, 0)); + distributionsW->getDistribution(f0, std::max(ix1, 0), std::max(ix2, 0), std::max(ix3, 0)); + distributions->getDistribution(fE, std::max(ix1 + offx, 0), std::max(ix2 + offy, 0), + std::max(ix3 + offz, 0)); // E:= plus 1 + + computeVelocity(fE, vE, compressible); + computeVelocity(fW, vW, compressible); + computeVelocity(fW2, vW2, compressible); + computeVelocity(f0, v0, compressible); + // second order non-symetric interpolation + vW[0] = v0[0] * 1.5 - vW[0] + 0.5 * vW2[0]; + vW[1] = v0[1] * 1.5 - vW[1] + 0.5 * vW2[1]; + vW[2] = v0[2] * 1.5 - vW[2] + 0.5 * vW2[2]; + // throw UbException(UB_EXARGS,"Parallel or Non-Uniform Simulation -- not yet implemented"); + } else { + SPtr<ILBMKernel> kernelW = blockNeighW->getKernel(); + SPtr<BCArray3D> bcArrayW = kernelW->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributionsW = kernelW->getDataSet()->getFdistributions(); + LBMReal fW[27]; + + if (offx == 1) { + distributionsW->getDistribution(fW, (distributions->getNX1()) - 1, ix2, + ix3); // moved one block backward, now get last entry + } else if (offy == 1) { + distributionsW->getDistribution(fW, ix1, (distributions->getNX2()) - 1, ix3); + + } else if (offz == 1) { + distributionsW->getDistribution(fW, ix1, ix2, distributions->getNX3() - 1); + } + computeVelocity(fW, vW, compressible); + } + + } else { + // data available in current block: + LBMReal fW[27]; + distributions->getDistribution(fW, ix1 - offx, ix2 - offy, ix3 - offz); + computeVelocity(fW, vW, compressible); + } + if (checkInterpolation) { + // in plus-direction data is available in current block because of ghost layers + LBMReal fE[27]; + distributions->getDistribution(fE, ix1 + offx, ix2 + offy, ix3 + offz); // E:= plus 1 + computeVelocity(fE, vE, compressible); + } } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -void QCriterionCoProcessor::computeVelocity(LBMReal* f, LBMReal* v, bool compressible) +void QCriterionCoProcessor::computeVelocity(LBMReal *f, LBMReal *v, bool compressible) { - ////////////////////////////////////////////////////////////////////////// - //compute x,y,z-velocity components from distribution - ////////////////////////////////////////////////////////////////////////// - if (compressible) - { - v[xdir] = D3Q27System::getCompVelocityX1(f); - v[ydir] = D3Q27System::getCompVelocityX2(f); - v[zdir] = D3Q27System::getCompVelocityX3(f); - } - else - { - v[xdir] = D3Q27System::getIncompVelocityX1(f); - v[ydir] = D3Q27System::getIncompVelocityX2(f); - v[zdir] = D3Q27System::getIncompVelocityX3(f); - } + ////////////////////////////////////////////////////////////////////////// + // compute x,y,z-velocity components from distribution + ////////////////////////////////////////////////////////////////////////// + if (compressible) { + v[xdir] = D3Q27System::getCompVelocityX1(f); + v[ydir] = D3Q27System::getCompVelocityX2(f); + v[zdir] = D3Q27System::getCompVelocityX3(f); + } else { + v[xdir] = D3Q27System::getIncompVelocityX1(f); + v[ydir] = D3Q27System::getIncompVelocityX2(f); + v[zdir] = D3Q27System::getIncompVelocityX3(f); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.h index 506922db8..022768752 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/QCriterionCoProcessor.h @@ -2,7 +2,6 @@ //! \brief Created on: 25.08.2013 //! \author: Sonja Uphoff - #ifndef QCriterionCoProcessor_H #define QCriterionCoProcessor_H @@ -20,48 +19,47 @@ class UbScheduler; class WbWriter; class Block3D; -//! \brief Computes the value Q with which vortices can be visualized as isocontours to Q=0, writes to .vtk, For uniform, serial setups only! -//! \details writes at given time intervals specified in scheduler (s) -//! Processing: paraview, take isolines of entry for Q-criterion vortex detection +//! \brief Computes the value Q with which vortices can be visualized as isocontours to Q=0, writes to .vtk, For +//! uniform, serial setups only! \details writes at given time intervals specified in scheduler (s) +//! Processing: paraview, take isolines of entry for Q-criterion vortex detection //! Q-Criterion: Visualize Vorteces as regions where Vorticity is larger than strain rate (Hunt, 1988) -//! \author Sonja Uphoff +//! \author Sonja Uphoff class QCriterionCoProcessor : public CoProcessor { public: - QCriterionCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm); - //! Make update if timestep is write-timestep specified in SPtr<UbScheduler> s - void process(double step) override; + QCriterionCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<Communicator> comm); + //! Make update if timestep is write-timestep specified in SPtr<UbScheduler> s + void process(double step) override; protected: - //! Prepare data and write in .vtk file - void collectData(double step); - //! Q is computed for all points in a block. Data for writing is added to data and cell vectors. - void addData(const SPtr<Block3D> block); - //! After writing to .vtk-file, all vectors are reset - void clearData(); - //! Computes macroscopic velocities - void computeVelocity(LBMReal* f, LBMReal* v, bool compressible); - //! Computes average and RMS values of macroscopic quantities - void getNeighborVelocities(int offx, int offy, int offz, int ix1, int ix2, int ix3,const SPtr<Block3D> block, LBMReal* vE,LBMReal* vW); + //! Prepare data and write in .vtk file + void collectData(double step); + //! Q is computed for all points in a block. Data for writing is added to data and cell vectors. + void addData(const SPtr<Block3D> block); + //! After writing to .vtk-file, all vectors are reset + void clearData(); + //! Computes macroscopic velocities + void computeVelocity(LBMReal *f, LBMReal *v, bool compressible); + //! Computes average and RMS values of macroscopic quantities + void getNeighborVelocities(int offx, int offy, int offz, int ix1, int ix2, int ix3, const SPtr<Block3D> block, + LBMReal *vE, LBMReal *vW); private: - void init(); - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; //only one entry for QKrit-CoProcessor: Q - std::vector<std::vector<double> > data; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - int minInitLevel; //go through all levels for block vector of current process from minInitLevel to maxInitLevel - int maxInitLevel; - int gridRank; //comm-Rank des aktuellen prozesses - std::string path; - WbWriter* writer; + void init(); + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; // only one entry for QKrit-CoProcessor: Q + std::vector<std::vector<double>> data; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; // go through all levels for block vector of current process from minInitLevel to maxInitLevel + int maxInitLevel; + int gridRank; // comm-Rank des aktuellen prozesses + std::string path; + WbWriter *writer; SPtr<Communicator> comm; - enum Values{xdir = 0, ydir = 1, zdir = 2}; //labels for the different components + enum Values { xdir = 0, ydir = 1, zdir = 2 }; // labels for the different components }; #endif - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.cpp index 5487936b5..3b546a702 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.cpp @@ -2,699 +2,940 @@ #include "BCProcessor.h" #include "WbWriterVtkXmlASCII.h" +#include "BCArray3D.h" #include "Block3D.h" -#include "DataSet3D.h" -#include "LBMKernel.h" #include "Communicator.h" #include "D3Q27Interactor.h" -#include "UbScheduler.h" -#include "BCArray3D.h" -#include "InterpolationProcessor.h" +#include "DataSet3D.h" #include "Grid3D.h" +#include "InterpolationProcessor.h" +#include "LBMKernel.h" +#include "UbScheduler.h" -ShearStressCoProcessor::ShearStressCoProcessor(SPtr<Grid3D> grid, const std::string& path, - WbWriter* const writer, - SPtr<UbScheduler> s,SPtr<UbScheduler> rs) - : CoProcessor(grid, s), - Resetscheduler(rs), - path(path), - writer(writer) +ShearStressCoProcessor::ShearStressCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<UbScheduler> rs) + : CoProcessor(grid, s), Resetscheduler(rs), path(path), writer(writer) { - SPtr<Communicator> comm = Communicator::getInstance(); - normals.push_back(0); - normals.push_back(0); - normals.push_back(1); - gridRank = grid->getRank(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); - - blockVector.resize(maxInitLevel+1); - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - for(SPtr<Block3D> block : blockVector[level]) - { - UbTupleInt3 nx = grid->getBlockNX(); - SPtr<ShearStressValuesArray3D> shearStressValues = SPtr<ShearStressValuesArray3D>(new ShearStressValuesArray3D(14, val<1>(nx)+1, val<2>(nx)+1, val<3>(nx)+1, 0.0)); - block->getKernel()->getDataSet()->setShearStressValues(shearStressValues); - } - } + SPtr<Communicator> comm = Communicator::getInstance(); + normals.push_back(0); + normals.push_back(0); + normals.push_back(1); + gridRank = grid->getRank(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); + + blockVector.resize(maxInitLevel + 1); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + for (SPtr<Block3D> block : blockVector[level]) { + UbTupleInt3 nx = grid->getBlockNX(); + SPtr<ShearStressValuesArray3D> shearStressValues = SPtr<ShearStressValuesArray3D>( + new ShearStressValuesArray3D(14, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setShearStressValues(shearStressValues); + } + } } ////////////////////////////////////////////////////////////////////////// -ShearStressCoProcessor::~ShearStressCoProcessor() -= default; +ShearStressCoProcessor::~ShearStressCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// -void ShearStressCoProcessor::process( double step ) +void ShearStressCoProcessor::process(double step) { - if (step==0) - { - initDistance(); - } - calculateShearStress(step); - if(scheduler->isDue(step) ) - collectData(step); - UBLOG(logDEBUG3, "D3Q27ShearStressCoProcessor::update:" << step); + if (step == 0) { + initDistance(); + } + calculateShearStress(step); + if (scheduler->isDue(step)) + collectData(step); + UBLOG(logDEBUG3, "D3Q27ShearStressCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::collectData(double step) { - using namespace std; - - int istep = int(step); - addData(); - - //string partName = writer->writeNodesWithNodeData(path+ UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep),nodes,datanames,data); - //size_t found=partName.find_last_of("//"); - //string piece = partName.substr(found+1); - - //vector<string> cellDataNames; - - //SPtr<Communicator> comm = Communicator::getInstance(); - //vector<string> pieces = comm->gatherStrings(piece); - //if (comm->getProcessID() == comm->getRoot()) - //{ - // string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(path+"_"+UbSystem::toString(istep),pieces,datanames,cellDataNames); - - // vector<string> filenames; - // filenames.push_back(pname); - // if (step == CoProcessor::scheduler->getMinBegin()) - // { - // WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"__Shear_collection",filenames,istep,false); - // } - // else - // { - // WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path+"__Shear_collection",filenames,istep,false); - // } - // UBLOG(logINFO,"D3Q27ShearStressCoProcessor step: " << istep); - //} - - string pfilePath, partPath, subfolder, cfilePath; - subfolder = "shs"+UbSystem::toString(istep); - pfilePath = path+"/shs/"+subfolder; - cfilePath = path+"/shs/shs_collection"; - partPath = pfilePath+"/shs"+UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep); - - string partName = writer->writeNodesWithNodeData(partPath,nodes,datanames,data); - size_t found=partName.find_last_of("/"); - string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; - - vector<string> cellDataNames; - SPtr<Communicator> comm = Communicator::getInstance(); - vector<string> pieces = comm->gather(piece); - if (comm->getProcessID() == comm->getRoot()) - { - string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath,pieces,datanames,cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); - - vector<string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath,filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath,filenames,istep,false); - } - UBLOG(logINFO,"D3Q27ShearStressCoProcessor step: " << istep); - } - - clearData(); + using namespace std; + + int istep = int(step); + addData(); + + // string partName = writer->writeNodesWithNodeData(path+ UbSystem::toString(gridRank)+ "_" + + // UbSystem::toString(istep),nodes,datanames,data); size_t found=partName.find_last_of("//"); string piece = + // partName.substr(found+1); + + // vector<string> cellDataNames; + + // SPtr<Communicator> comm = Communicator::getInstance(); + // vector<string> pieces = comm->gatherStrings(piece); + // if (comm->getProcessID() == comm->getRoot()) + //{ + // string pname = + // WbWriterVtkXmlASCII::getInstance()->writeParallelFile(path+"_"+UbSystem::toString(istep),pieces,datanames,cellDataNames); + + // vector<string> filenames; + // filenames.push_back(pname); + // if (step == CoProcessor::scheduler->getMinBegin()) + // { + // WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"__Shear_collection",filenames,istep,false); + // } + // else + // { + // WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path+"__Shear_collection",filenames,istep,false); + // } + // UBLOG(logINFO,"D3Q27ShearStressCoProcessor step: " << istep); + //} + + string pfilePath, partPath, subfolder, cfilePath; + subfolder = "shs" + UbSystem::toString(istep); + pfilePath = path + "/shs/" + subfolder; + cfilePath = path + "/shs/shs_collection"; + partPath = pfilePath + "/shs" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); + + string partName = writer->writeNodesWithNodeData(partPath, nodes, datanames, data); + size_t found = partName.find_last_of("/"); + string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + vector<string> cellDataNames; + SPtr<Communicator> comm = Communicator::getInstance(); + vector<string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); + + vector<string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "D3Q27ShearStressCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::clearData() { - nodes.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::calculateShearStress(double timeStep) { - using namespace D3Q27System; - - LBMReal f[27]; - LBMReal vx, vy, vz, sxx, syy, szz, sxy, syz, sxz; - - for(SPtr<D3Q27Interactor> interactor : interactors) - { - typedef std::map<SPtr<Block3D>, std::set< std::vector<int> > > TransNodeIndicesMap; - for(TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& transNodeIndicesSet = t.second; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); - - int ghostLayer = kernel->getGhostLayerWidth(); - LBMReal collFactor = kernel->getCollisionFactor(); - - int minX1 = ghostLayer; - int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; - int minX2 = ghostLayer; - int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; - int minX3 = ghostLayer; - int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; - - for(std::vector<int> node : transNodeIndicesSet) - { - int ix1 = node[0]; - int ix2 = node[1]; - int ix3 = node[2]; - - //without ghost nodes - if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 ||ix3 < minX3 || ix3 > maxX3 ) continue; - - if(bcArray->isFluid(ix1,ix2,ix3)) - { - double q=(*ssv)(normalq,ix1,ix2,ix3) ; - double numPoint=(*ssv)(numberOfPoint,ix1,ix2,ix3) ; - if (q==0||numPoint!=3)continue; - // if (q==0)continue; - ////////////////////////////////////////////////////////////////////////// - //read distribution - //////////////////////////////////////////////////////////////////////////// - distributions->getDistribution(f, ix1, ix2, ix3); - ////////////////////////////////////////////////////////////////////////// - //compute velocity - ////////////////////////////////////////////////////////////////////////// - vx = ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[BSE]-f[TNW]) + (f[BNE]-f[TSW]))) + - (((f[BE]-f[TW]) + (f[TE]-f[BW])) + ((f[SE]-f[NW]) + (f[NE]-f[SW]))) + - (f[E]-f[W])); - - vy = ((((f[TNE]-f[BSW]) + (f[BNW]-f[TSE])) + ((f[TNW]-f[BSE]) + (f[BNE]-f[TSW]))) + - (((f[BN]-f[TS]) + (f[TN]-f[BS])) + ((f[NW]-f[SE]) + (f[NE]-f[SW]))) + - (f[N]-f[S])); - - vz = ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[TNW]-f[BSE]) + (f[TSW]-f[BNE]))) + - (((f[TS]-f[BN]) + (f[TN]-f[BS])) + ((f[TW]-f[BE]) + (f[TE]-f[BW]))) + - (f[T]-f[B])); - - - sxy = 3.0 * collFactor/(collFactor - 1.0)* ( ((f[TNE] + f[BSW])-(f[TSE]+f[BNW]))+(-(f[BSE]+f[TNW])+ (f[TSW]+f[BNE])) - +(((f[NE] + f[SW]) - (f[SE] + f[NW]))) -vx*vy); - - sxz = 3.0 * collFactor/(collFactor-1.0)*(((f[TNE] + f[BSW])+(f[TSE]+f[BNW]))+(-(f[BSE]+f[TNW])- (f[TSW]+f[BNE])) - +((f[TE] + f[BW])-(f[BE]+ f[TW])) -vx*vz); - - syz = 3.0 * collFactor/(collFactor-1.0)*(((f[TNE] + f[BSW])-(f[TSE]+f[BNW]))+((f[BSE]+f[TNW])- (f[TSW]+f[BNE])) - +(-(f[BN] + f[TS]) + (f[TN] + f[BS])) -vy*vz); - - LBMReal dxxMyy =3.0/2.0 * collFactor/(collFactor-1.0)* (((f[TE] + f[BW])+(f[BE]+ f[TW])) - -((f[BN] + f[TS]) + (f[TN] + f[BS]))+((f[E] + f[W])-(f[N] + f[S]))-vx*vx+vy*vy); - - LBMReal dxxMzz =3.0/2.0 * collFactor/(collFactor-1.0)*((((f[NE] + f[SW]) + (f[SE] + f[NW])) - -((f[BN] + f[TS]) + (f[TN] + f[BS])))+((f[E] + f[W])-(f[T] + f[B])) -vx*vx +vz*vz); - - // LBMReal dyyMzz =3.0/2.0 *collFactor/(collFactor-1.0)*((((f[NE] + f[SW]) + (f[SE] + f[NW]))-((f[TE] + f[BW])+(f[BE]+ f[TW]))) - // +((f[N] + f[S])-(f[T] + f[B])) -vy*vy +vz*vz); - - sxx=(dxxMyy+dxxMzz)/3.0; // weil dxxPyyPzz=0 - - syy=(dxxMzz-2*dxxMyy)/3.0; - - szz=(dxxMyy-2*dxxMzz)/3.0; - - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - (*ssv)(AvVx,ix1,ix2,ix3) = ((*ssv)(AvVx,ix1,ix2,ix3)*timeStep + vx)/(timeStep+1.0); - (*ssv)(AvVy,ix1,ix2,ix3) = ((*ssv)(AvVy,ix1,ix2,ix3)*timeStep + vy)/(timeStep+1.0); - (*ssv)(AvVz,ix1,ix2,ix3) = ((*ssv)(AvVz,ix1,ix2,ix3)*timeStep + vz)/(timeStep+1.0); - - (*ssv)(AvSxx,ix1,ix2,ix3) = ((*ssv)(AvSxx,ix1,ix2,ix3)*timeStep + sxx)/(timeStep+1.0); - (*ssv)(AvSyy,ix1,ix2,ix3) = ((*ssv)(AvSyy,ix1,ix2,ix3)*timeStep + syy)/(timeStep+1.0); - (*ssv)(AvSzz,ix1,ix2,ix3) = ((*ssv)(AvSzz,ix1,ix2,ix3)*timeStep + szz)/(timeStep+1.0); - (*ssv)(AvSxy,ix1,ix2,ix3) = ((*ssv)(AvSxy,ix1,ix2,ix3)*timeStep + sxy)/(timeStep+1.0); - (*ssv)(AvSyz,ix1,ix2,ix3) = ((*ssv)(AvSyz,ix1,ix2,ix3)*timeStep + syz)/(timeStep+1.0); - (*ssv)(AvSxz,ix1,ix2,ix3) = ((*ssv)(AvSxz,ix1,ix2,ix3)*timeStep + sxz)/(timeStep+1.0); + using namespace D3Q27System; + + LBMReal f[27]; + LBMReal vx, vy, vz, sxx, syy, szz, sxy, syz, sxz; + + for (SPtr<D3Q27Interactor> interactor : interactors) { + typedef std::map<SPtr<Block3D>, std::set<std::vector<int>>> TransNodeIndicesMap; + for (TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &transNodeIndicesSet = t.second; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); + + int ghostLayer = kernel->getGhostLayerWidth(); + LBMReal collFactor = kernel->getCollisionFactor(); + + int minX1 = ghostLayer; + int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; + int minX2 = ghostLayer; + int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; + int minX3 = ghostLayer; + int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; + + for (std::vector<int> node : transNodeIndicesSet) { + int ix1 = node[0]; + int ix2 = node[1]; + int ix3 = node[2]; + + // without ghost nodes + if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 || ix3 < minX3 || ix3 > maxX3) + continue; + + if (bcArray->isFluid(ix1, ix2, ix3)) { + double q = (*ssv)(normalq, ix1, ix2, ix3); + double numPoint = (*ssv)(numberOfPoint, ix1, ix2, ix3); + if (q == 0 || numPoint != 3) + continue; + // if (q==0)continue; + ////////////////////////////////////////////////////////////////////////// + // read distribution + //////////////////////////////////////////////////////////////////////////// + distributions->getDistribution(f, ix1, ix2, ix3); + ////////////////////////////////////////////////////////////////////////// + // compute velocity + ////////////////////////////////////////////////////////////////////////// + vx = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])); + + vy = ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])); + + vz = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])); + + sxy = 3.0 * collFactor / (collFactor - 1.0) * + (((f[TNE] + f[BSW]) - (f[TSE] + f[BNW])) + (-(f[BSE] + f[TNW]) + (f[TSW] + f[BNE])) + + (((f[NE] + f[SW]) - (f[SE] + f[NW]))) - vx * vy); + + sxz = 3.0 * collFactor / (collFactor - 1.0) * + (((f[TNE] + f[BSW]) + (f[TSE] + f[BNW])) + (-(f[BSE] + f[TNW]) - (f[TSW] + f[BNE])) + + ((f[TE] + f[BW]) - (f[BE] + f[TW])) - vx * vz); + + syz = 3.0 * collFactor / (collFactor - 1.0) * + (((f[TNE] + f[BSW]) - (f[TSE] + f[BNW])) + ((f[BSE] + f[TNW]) - (f[TSW] + f[BNE])) + + (-(f[BN] + f[TS]) + (f[TN] + f[BS])) - vy * vz); + + LBMReal dxxMyy = 3.0 / 2.0 * collFactor / (collFactor - 1.0) * + (((f[TE] + f[BW]) + (f[BE] + f[TW])) - ((f[BN] + f[TS]) + (f[TN] + f[BS])) + + ((f[E] + f[W]) - (f[N] + f[S])) - vx * vx + vy * vy); + + LBMReal dxxMzz = 3.0 / 2.0 * collFactor / (collFactor - 1.0) * + ((((f[NE] + f[SW]) + (f[SE] + f[NW])) - ((f[BN] + f[TS]) + (f[TN] + f[BS]))) + + ((f[E] + f[W]) - (f[T] + f[B])) - vx * vx + vz * vz); + + // LBMReal dyyMzz =3.0/2.0 *collFactor/(collFactor-1.0)*((((f[NE] + f[SW]) + (f[SE] + + // f[NW]))-((f[TE] + f[BW])+(f[BE]+ f[TW]))) + // +((f[N] + f[S])-(f[T] + f[B])) -vy*vy +vz*vz); + + sxx = (dxxMyy + dxxMzz) / 3.0; // weil dxxPyyPzz=0 + + syy = (dxxMzz - 2 * dxxMyy) / 3.0; + + szz = (dxxMyy - 2 * dxxMzz) / 3.0; + + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + (*ssv)(AvVx, ix1, ix2, ix3) = ((*ssv)(AvVx, ix1, ix2, ix3) * timeStep + vx) / (timeStep + 1.0); + (*ssv)(AvVy, ix1, ix2, ix3) = ((*ssv)(AvVy, ix1, ix2, ix3) * timeStep + vy) / (timeStep + 1.0); + (*ssv)(AvVz, ix1, ix2, ix3) = ((*ssv)(AvVz, ix1, ix2, ix3) * timeStep + vz) / (timeStep + 1.0); + + (*ssv)(AvSxx, ix1, ix2, ix3) = ((*ssv)(AvSxx, ix1, ix2, ix3) * timeStep + sxx) / (timeStep + 1.0); + (*ssv)(AvSyy, ix1, ix2, ix3) = ((*ssv)(AvSyy, ix1, ix2, ix3) * timeStep + syy) / (timeStep + 1.0); + (*ssv)(AvSzz, ix1, ix2, ix3) = ((*ssv)(AvSzz, ix1, ix2, ix3) * timeStep + szz) / (timeStep + 1.0); + (*ssv)(AvSxy, ix1, ix2, ix3) = ((*ssv)(AvSxy, ix1, ix2, ix3) * timeStep + sxy) / (timeStep + 1.0); + (*ssv)(AvSyz, ix1, ix2, ix3) = ((*ssv)(AvSyz, ix1, ix2, ix3) * timeStep + syz) / (timeStep + 1.0); + (*ssv)(AvSxz, ix1, ix2, ix3) = ((*ssv)(AvSxz, ix1, ix2, ix3) * timeStep + sxz) / (timeStep + 1.0); + } } - } - - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::addData() { - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("y^plus"); - datanames.emplace_back("u_tau"); - //datanames.push_back("yPlusFD"); - - data.resize(datanames.size()); - - for(const auto& interactor : interactors) - { - using TransNodeIndicesMap = std::map<SPtr<Block3D>, std::set<std::vector<int> > >; - for(TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& transNodeIndicesSet = t.second; - - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); - - int ghostLayer = kernel->getGhostLayerWidth(); - LBMReal collFactor = kernel->getCollisionFactor(); - - int minX1 = ghostLayer; - int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; - int minX2 = ghostLayer; - int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; - int minX3 = ghostLayer; - int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; - -// int level=block->getLevel(); -// if(level==1) -// { -// int le=0; -// } - for(std::vector<int> node : transNodeIndicesSet) - { - int ix1 = node[0]; - int ix2 = node[1]; - int ix3 = node[2]; - - //without ghost nodes - if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 ||ix3 < minX3 || ix3 > maxX3 ) continue; - - if(bcArray->isFluid(ix1,ix2,ix3)) - { - double q=(*ssv)(normalq,ix1,ix2,ix3) ; - double numPoint=(*ssv)(numberOfPoint,ix1,ix2,ix3) ; - if (q==0||numPoint!=3)continue; - // if (q==0)continue; - - int index = 0; - nodes.push_back( makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1*dx), - float(val<2>(org) - val<2>(nodeOffset) + ix2*dx), - float(val<3>(org) - val<3>(nodeOffset) + ix3*dx)) ); - - //////get normal and distance////// - double A,B,C; - A= (*ssv)(normalX1,ix1,ix2,ix3) ; - B= (*ssv)(normalX2,ix1,ix2,ix3) ; - C= (*ssv)(normalX3,ix1,ix2,ix3) ; - - /////////// - //compute y plus - //double vtxSonja, vtySonja, vtzSonja; //tangent velocity - // double temp = (*av)(ix1,ix2,ix3,AvVx)*A+(*av)(ix1,ix2,ix3,AvVy)*B+(*av)(ix1,ix2,ix3,AvVz)*C; - // vtxSonja = (*av)(ix1,ix2,ix3,AvVx)-normals[0]*temp; - // vtySonja = (*av)(ix1,ix2,ix3,AvVy)-normals[1]*temp; - // vtzSonja = (*av)(ix1,ix2,ix3,AvVz)-normals[2]*temp; - - double vtx= (B*B*(*ssv)(AvVx,ix1,ix2,ix3) + C*C*(*ssv)(AvVx,ix1,ix2,ix3) - A*B*(*ssv)(AvVy,ix1,ix2,ix3) - A*C*(*ssv)(AvVy,ix1,ix2,ix3))/(A*A+B*B+C*C); - double vty=(-(A*B*(*ssv)(AvVx,ix1,ix2,ix3)) + A*A*(*ssv)(AvVy,ix1,ix2,ix3) + C*C*(*ssv)(AvVy,ix1,ix2,ix3) - B*C*(*ssv)(AvVz,ix1,ix2,ix3))/(A*A+B*B+C*C); - double vtz=(-(A*C*(*ssv)(AvVx,ix1,ix2,ix3)) - B*C*(*ssv)(AvVy,ix1,ix2,ix3) + A*A*(*ssv)(AvVz,ix1,ix2,ix3) + B*B*(*ssv)(AvVz,ix1,ix2,ix3))/(A*A+B*B+C*C); - - double normVt = sqrt(vtx*vtx+vty*vty+vtz*vtz)+1e-100; - double nvtx = vtx / normVt; - double nvty = vty / normVt; - double nvtz = vtz / normVt; - - double sx=0.5*((*ssv)(AvSxx,ix1,ix2,ix3)*nvtx+(*ssv)(AvSxy,ix1,ix2,ix3)*nvty+(*ssv)(AvSxz,ix1,ix2,ix3)*nvtz); - double sy=0.5*((*ssv)(AvSxy,ix1,ix2,ix3)*nvtx+(*ssv)(AvSyy,ix1,ix2,ix3)*nvty+(*ssv)(AvSyz,ix1,ix2,ix3)*nvtz); - double sz=0.5*((*ssv)(AvSxz,ix1,ix2,ix3)*nvtx+(*ssv)(AvSyz,ix1,ix2,ix3)*nvty+(*ssv)(AvSzz,ix1,ix2,ix3)*nvtz); - double sabs=sqrt(sx*sx+sy*sy+sz*sz); - - double viscosity = (1.0/3.0)*(1.0/collFactor-0.5); - double rho = 1.0; - double utau=sqrt(viscosity/rho*sabs); - - // double q=(*av)(ix1,ix2,ix3,normalq) ; - double yPlus = (utau*q)/viscosity; - - data[index++].push_back(yPlus); - data[index++].push_back(utau); + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("y^plus"); + datanames.emplace_back("u_tau"); + // datanames.push_back("yPlusFD"); + + data.resize(datanames.size()); + + for (const auto &interactor : interactors) { + using TransNodeIndicesMap = std::map<SPtr<Block3D>, std::set<std::vector<int>>>; + for (TransNodeIndicesMap::value_type t : interactor->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &transNodeIndicesSet = t.second; + + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); + + int ghostLayer = kernel->getGhostLayerWidth(); + LBMReal collFactor = kernel->getCollisionFactor(); + + int minX1 = ghostLayer; + int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; + int minX2 = ghostLayer; + int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; + int minX3 = ghostLayer; + int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; + + // int level=block->getLevel(); + // if(level==1) + // { + // int le=0; + // } + for (std::vector<int> node : transNodeIndicesSet) { + int ix1 = node[0]; + int ix2 = node[1]; + int ix3 = node[2]; + + // without ghost nodes + if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 || ix3 < minX3 || ix3 > maxX3) + continue; + + if (bcArray->isFluid(ix1, ix2, ix3)) { + double q = (*ssv)(normalq, ix1, ix2, ix3); + double numPoint = (*ssv)(numberOfPoint, ix1, ix2, ix3); + if (q == 0 || numPoint != 3) + continue; + // if (q==0)continue; + + int index = 0; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + //////get normal and distance////// + double A, B, C; + A = (*ssv)(normalX1, ix1, ix2, ix3); + B = (*ssv)(normalX2, ix1, ix2, ix3); + C = (*ssv)(normalX3, ix1, ix2, ix3); + + /////////// + // compute y plus + // double vtxSonja, vtySonja, vtzSonja; //tangent velocity + // double temp = (*av)(ix1,ix2,ix3,AvVx)*A+(*av)(ix1,ix2,ix3,AvVy)*B+(*av)(ix1,ix2,ix3,AvVz)*C; + // vtxSonja = (*av)(ix1,ix2,ix3,AvVx)-normals[0]*temp; + // vtySonja = (*av)(ix1,ix2,ix3,AvVy)-normals[1]*temp; + // vtzSonja = (*av)(ix1,ix2,ix3,AvVz)-normals[2]*temp; + + double vtx = (B * B * (*ssv)(AvVx, ix1, ix2, ix3) + C * C * (*ssv)(AvVx, ix1, ix2, ix3) - + A * B * (*ssv)(AvVy, ix1, ix2, ix3) - A * C * (*ssv)(AvVy, ix1, ix2, ix3)) / + (A * A + B * B + C * C); + double vty = (-(A * B * (*ssv)(AvVx, ix1, ix2, ix3)) + A * A * (*ssv)(AvVy, ix1, ix2, ix3) + + C * C * (*ssv)(AvVy, ix1, ix2, ix3) - B * C * (*ssv)(AvVz, ix1, ix2, ix3)) / + (A * A + B * B + C * C); + double vtz = (-(A * C * (*ssv)(AvVx, ix1, ix2, ix3)) - B * C * (*ssv)(AvVy, ix1, ix2, ix3) + + A * A * (*ssv)(AvVz, ix1, ix2, ix3) + B * B * (*ssv)(AvVz, ix1, ix2, ix3)) / + (A * A + B * B + C * C); + + double normVt = sqrt(vtx * vtx + vty * vty + vtz * vtz) + 1e-100; + double nvtx = vtx / normVt; + double nvty = vty / normVt; + double nvtz = vtz / normVt; + + double sx = 0.5 * ((*ssv)(AvSxx, ix1, ix2, ix3) * nvtx + (*ssv)(AvSxy, ix1, ix2, ix3) * nvty + + (*ssv)(AvSxz, ix1, ix2, ix3) * nvtz); + double sy = 0.5 * ((*ssv)(AvSxy, ix1, ix2, ix3) * nvtx + (*ssv)(AvSyy, ix1, ix2, ix3) * nvty + + (*ssv)(AvSyz, ix1, ix2, ix3) * nvtz); + double sz = 0.5 * ((*ssv)(AvSxz, ix1, ix2, ix3) * nvtx + (*ssv)(AvSyz, ix1, ix2, ix3) * nvty + + (*ssv)(AvSzz, ix1, ix2, ix3) * nvtz); + double sabs = sqrt(sx * sx + sy * sy + sz * sz); + + double viscosity = (1.0 / 3.0) * (1.0 / collFactor - 0.5); + double rho = 1.0; + double utau = sqrt(viscosity / rho * sabs); + + // double q=(*av)(ix1,ix2,ix3,normalq) ; + double yPlus = (utau * q) / viscosity; + + data[index++].push_back(yPlus); + data[index++].push_back(utau); + } } - } - } - } - + } + } } ////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::reset(double step) { - if(Resetscheduler->isDue(step) ) - resetData(step); + if (Resetscheduler->isDue(step)) + resetData(step); - UBLOG(logDEBUG3, "resetCoProcessor::update:" << step); + UBLOG(logDEBUG3, "resetCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// -void ShearStressCoProcessor::resetData(double /*step*/) +void ShearStressCoProcessor::resetData(double /*step*/) { - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(const auto& block : blockVector[level]) - { - if (block) - { -// UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); -// UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); -// double dx = grid->getDeltaX(block); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - (*ssv)(AvVx,ix1,ix2,ix3) = 0.0; - (*ssv)(AvVy,ix1,ix2,ix3) = 0.0; - (*ssv)(AvVz,ix1,ix2,ix3) = 0.0; - - (*ssv)(AvSxx,ix1,ix2,ix3) = 0.0; - (*ssv)(AvSyy,ix1,ix2,ix3) = 0.0; - (*ssv)(AvSzz,ix1,ix2,ix3) = 0.0; - (*ssv)(AvSxy,ix1,ix2,ix3) = 0.0; - (*ssv)(AvSyz,ix1,ix2,ix3) = 0.0; - (*ssv)(AvSxz,ix1,ix2,ix3) = 0.0; - ////////////////////////////////////////////////////////////////////////// - } - } - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (const auto &block : blockVector[level]) { + if (block) { + // UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + // UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + // double dx = grid->getDeltaX(block); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + (*ssv)(AvVx, ix1, ix2, ix3) = 0.0; + (*ssv)(AvVy, ix1, ix2, ix3) = 0.0; + (*ssv)(AvVz, ix1, ix2, ix3) = 0.0; + + (*ssv)(AvSxx, ix1, ix2, ix3) = 0.0; + (*ssv)(AvSyy, ix1, ix2, ix3) = 0.0; + (*ssv)(AvSzz, ix1, ix2, ix3) = 0.0; + (*ssv)(AvSxy, ix1, ix2, ix3) = 0.0; + (*ssv)(AvSyz, ix1, ix2, ix3) = 0.0; + (*ssv)(AvSxz, ix1, ix2, ix3) = 0.0; + ////////////////////////////////////////////////////////////////////////// + } + } + } + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -void ShearStressCoProcessor::addInteractor( SPtr<D3Q27Interactor> interactor ) -{ - interactors.push_back(interactor); -} +void ShearStressCoProcessor::addInteractor(SPtr<D3Q27Interactor> interactor) { interactors.push_back(interactor); } ////////////////////////////////////////////////////////////////////////// -void ShearStressCoProcessor::findPlane(int ix1,int ix2,int ix3,SPtr<Grid3D> grid,SPtr<Block3D> block,double &A,double &B,double &C,double &D,double &ii) +void ShearStressCoProcessor::findPlane(int ix1, int ix2, int ix3, SPtr<Grid3D> grid, SPtr<Block3D> block, double &A, + double &B, double &C, double &D, double &ii) { - double x1plane=0.0,y1plane=0.0,z1plane=0.0; - double x2plane=0.0,y2plane=0.0,z2plane=0.0; - double x3plane=0.0,y3plane=0.0,z3plane=0.0; - SPtr<BoundaryConditions> bcPtr; - double dx = grid->getDeltaX(block); - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - bcPtr=bcArray->getBC(ix1,ix2,ix3); - int x,y,z; - - - if(InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2, ix3)) { x = ix1;y = ix2;z = ix3;} - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2-1, ix3 )) { x = ix1+0; y = ix2-1; z = ix3+0;}//S - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2 , ix3-1)) { x = ix1+0; y = ix2+0; z = ix3-1;}//B - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2 , ix3 )) { x = ix1-1; y = ix2+0; z = ix3+0;}//w - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2-1, ix3-1)) { x = ix1+0; y = ix2-1; z = ix3-1;}//BS - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2 , ix3-1)) { x = ix1-1; y = ix2+0; z = ix3-1;}//BW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2-1, ix3 )) { x = ix1-1; y = ix2-1; z = ix3+0;}//SW - - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2-1, ix3-1)) { x = ix1-1; y = ix2-1; z = ix3-1;}//BSW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2 , ix3 )) { x = ix1+1; y = ix2+0; z = ix3+0;}//E - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2+1, ix3 )) { x = ix1+0; y = ix2+1; z = ix3+0;}//N - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2 , ix3+1)) { x = ix1+0; y = ix2+0; z = ix3+1;}//T - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2+1, ix3 )) { x = ix1+1; y = ix2+1; z = ix3+0;}//NE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2 , ix3+1)) { x = ix1+1; y = ix2+0; z = ix3+1;}//TE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1 , ix2+1, ix3+1)) { x = ix1+0; y = ix2+1; z = ix3+1;}//TN - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2+1, ix3+1)) { x = ix1+1; y = ix2+1; z = ix3+1;}//TNE - - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2-1, ix3 )) { x = ix1+1; y = ix2-1; z = ix3+0;}//SE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2+1, ix3 )) { x = ix1-1; y = ix2+1; z = ix3+0;}//NW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2 , ix3-1)) { x = ix1+1; y = ix2+0; z = ix3-1;}//BE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2 , ix3+1)) { x = ix1-1; y = ix2+0; z = ix3+1;}//TW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+0, ix2+1, ix3-1)) { x = ix1+0; y = ix2+1; z = ix3-1;}//BN - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+0, ix2-1, ix3+1)) { x = ix1+0; y = ix2-1; z = ix3+1;}//TS - - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2+1, ix3+1)) { x = ix1-1; y = ix2+1; z = ix3+1;}//TNW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2-1, ix3+1)) { x = ix1+1; y = ix2-1; z = ix3+1;}//TSE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2-1, ix3+1)) { x = ix1-1; y = ix2-1; z = ix3+1;}//TSW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2+1, ix3-1)) { x = ix1+1; y = ix2+1; z = ix3-1;}//BNE - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1-1, ix2+1, ix3-1)) { x = ix1-1; y = ix2+1; z = ix3-1;}//BNW - else if(InterpolationProcessor::iCellHasSolid(bcArray, ix1+1, ix2-1, ix3-1)) { x = ix1+1; y = ix2-1; z = ix3-1;}//BSE - - - else {{UB_THROW( UbException(UB_EXARGS,"there is no cell ix1="+UbSystem::toString(ix1)+"ix2="+UbSystem::toString(ix2)+"ix3="+UbSystem::toString(ix3)+"GlobalID="+UbSystem::toString(block->getGlobalID())+"dx="+UbSystem::toString(dx) - +"T="+UbSystem::toString(bcPtr->getQ(D3Q27System::T))+"B="+UbSystem::toString(bcPtr->getQ(D3Q27System::B)) - +"E="+UbSystem::toString(bcPtr->getQ(D3Q27System::E))+"W="+UbSystem::toString(bcPtr->getQ(D3Q27System::W))+"N="+UbSystem::toString(bcPtr->getQ(D3Q27System::N)) - +"S="+UbSystem::toString(bcPtr->getQ(D3Q27System::S))+"NE="+UbSystem::toString(bcPtr->getQ(D3Q27System::NE))+"SW="+UbSystem::toString(bcPtr->getQ(D3Q27System::SW)) - +"SE="+UbSystem::toString(bcPtr->getQ(D3Q27System::SE))+"NW="+UbSystem::toString(bcPtr->getQ(D3Q27System::NW)) - +"TE="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TE))+"BW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BW))+"BE="+UbSystem::toString(bcPtr->getQ(D3Q27System::BE))+"TW="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TW))+"TN="+UbSystem::toString(bcPtr->getQ(D3Q27System::TN))+"BS="+UbSystem::toString(bcPtr->getQ(D3Q27System::BS))+"BN="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::BN))+"TS="+UbSystem::toString(bcPtr->getQ(D3Q27System::TS))+"TNE="+UbSystem::toString(bcPtr->getQ(D3Q27System::TNE))+"TNW="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TNW))+"TSE="+UbSystem::toString(bcPtr->getQ(D3Q27System::TSE))+"TSW="+UbSystem::toString(bcPtr->getQ(D3Q27System::TSW))+"BNE="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::BNE))+"BNW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BNW))+"BSE="+UbSystem::toString(bcPtr->getQ(D3Q27System::BSE))+"BSW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BSW)*dx) - ) ) ;}} - - - if(InterpolationProcessor::iCellHasSolid(bcArray, x, y, z)) - { - for(int i = x; i <= x + 1; i++){ - for(int j = y; j <= y + 1; j++){ - for (int k = z; k <= z + 1; k++) - { - Vector3D pointplane1 = grid->getNodeCoordinates(block, i, j, k); - - double iph=pointplane1[0]; - double jph=pointplane1[1]; - double kph=pointplane1[2]; - - if(!bcArray->isSolid(i, j, k)) - { - SPtr<BoundaryConditions> bcPtrIn=bcArray->getBC(i,j,k); - if(bcPtrIn) - { - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if( ii<=2) - { - LBMReal q = bcPtrIn->getQ(fdir); - if (q!=999.00000) - { - if ( fdir==D3Q27System::E ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if (i+q<=x+1) - { - if (ii==0) { x1plane=iph+q*dx; y1plane=jph; z1plane=kph; ii++; } - else if (ii==1) { x2plane=iph+q*dx; y2plane=jph; z2plane=kph; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if(ii==2) { x3plane=iph+q*dx; y3plane=jph; z3plane=kph; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - if ( fdir==D3Q27System::W ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if (i-q>=x) - { - if (ii==0) { x1plane=iph-q*dx; y1plane=jph; z1plane=kph; ii++; } - else if (ii==1) { x2plane=iph-q*dx; y2plane=jph; z2plane=kph; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if(ii==2) { x3plane=iph-q*dx; y3plane=jph; z3plane=kph; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - if ( fdir==D3Q27System::N ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if(j+q<=y+1) - { - if (ii==0) { x1plane=iph; y1plane=jph+q*dx; z1plane=kph; ii++; } - else if (ii==1) { x2plane=iph; y2plane=jph+q*dx; z2plane=kph; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if (ii==2) { x3plane=iph; y3plane=jph+q*dx; z3plane=kph; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - if ( fdir==D3Q27System::S ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if (j-q>=y) - { - if (ii==0) { x1plane=iph; y1plane=jph-q*dx; z1plane=kph; ii++; } - else if (ii==1) { x2plane=iph; y2plane=jph-q*dx; z2plane=kph; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if (ii==2) { x3plane=iph; y3plane=jph-q*dx; z3plane=kph; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - - if ( fdir==D3Q27System::T ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if(k+q<=z+1) - { - if (ii==0) { x1plane=iph; y1plane=jph; z1plane=kph+q*dx; ii++; } - else if (ii==1) { x2plane=iph; y2plane=jph; z2plane=kph+q*dx; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if (ii==2) { x3plane=iph; y3plane=jph; z3plane=kph+q*dx; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - if ( fdir==D3Q27System::B ) - { - //if(!bcArray->isSolid(i, j, k))continue; - if (k-q>=z) - { - if (ii==0) { x1plane=iph; y1plane=jph; z1plane=kph-q*dx; ii++; } - else if (ii==1) { x2plane=iph; y2plane=jph; z2plane=kph-q*dx; if (x1plane!=x2plane||y1plane!=y2plane||z1plane!=z2plane) ii++; } - else if (ii==2) { x3plane=iph; y3plane=jph; z3plane=kph-q*dx; if ((x3plane!=x1plane||y3plane!=y1plane||z3plane!=z1plane)&&(x2plane!=x3plane||y2plane!=y3plane||z2plane!=z3plane)) ii++;} - } - } - - } + double x1plane = 0.0, y1plane = 0.0, z1plane = 0.0; + double x2plane = 0.0, y2plane = 0.0, z2plane = 0.0; + double x3plane = 0.0, y3plane = 0.0, z3plane = 0.0; + SPtr<BoundaryConditions> bcPtr; + double dx = grid->getDeltaX(block); + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + bcPtr = bcArray->getBC(ix1, ix2, ix3); + int x, y, z; + + if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2, ix3)) { + x = ix1; + y = ix2; + z = ix3; + } else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2 - 1, ix3)) { + x = ix1 + 0; + y = ix2 - 1; + z = ix3 + 0; + } // S + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2, ix3 - 1)) { + x = ix1 + 0; + y = ix2 + 0; + z = ix3 - 1; + } // B + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2, ix3)) { + x = ix1 - 1; + y = ix2 + 0; + z = ix3 + 0; + } // w + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2 - 1, ix3 - 1)) { + x = ix1 + 0; + y = ix2 - 1; + z = ix3 - 1; + } // BS + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2, ix3 - 1)) { + x = ix1 - 1; + y = ix2 + 0; + z = ix3 - 1; + } // BW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 - 1, ix3)) { + x = ix1 - 1; + y = ix2 - 1; + z = ix3 + 0; + } // SW + + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 - 1, ix3 - 1)) { + x = ix1 - 1; + y = ix2 - 1; + z = ix3 - 1; + } // BSW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2, ix3)) { + x = ix1 + 1; + y = ix2 + 0; + z = ix3 + 0; + } // E + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2 + 1, ix3)) { + x = ix1 + 0; + y = ix2 + 1; + z = ix3 + 0; + } // N + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2, ix3 + 1)) { + x = ix1 + 0; + y = ix2 + 0; + z = ix3 + 1; + } // T + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 + 1, ix3)) { + x = ix1 + 1; + y = ix2 + 1; + z = ix3 + 0; + } // NE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2, ix3 + 1)) { + x = ix1 + 1; + y = ix2 + 0; + z = ix3 + 1; + } // TE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1, ix2 + 1, ix3 + 1)) { + x = ix1 + 0; + y = ix2 + 1; + z = ix3 + 1; + } // TN + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 + 1, ix3 + 1)) { + x = ix1 + 1; + y = ix2 + 1; + z = ix3 + 1; + } // TNE + + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 - 1, ix3)) { + x = ix1 + 1; + y = ix2 - 1; + z = ix3 + 0; + } // SE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 + 1, ix3)) { + x = ix1 - 1; + y = ix2 + 1; + z = ix3 + 0; + } // NW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2, ix3 - 1)) { + x = ix1 + 1; + y = ix2 + 0; + z = ix3 - 1; + } // BE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2, ix3 + 1)) { + x = ix1 - 1; + y = ix2 + 0; + z = ix3 + 1; + } // TW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 0, ix2 + 1, ix3 - 1)) { + x = ix1 + 0; + y = ix2 + 1; + z = ix3 - 1; + } // BN + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 0, ix2 - 1, ix3 + 1)) { + x = ix1 + 0; + y = ix2 - 1; + z = ix3 + 1; + } // TS + + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 + 1, ix3 + 1)) { + x = ix1 - 1; + y = ix2 + 1; + z = ix3 + 1; + } // TNW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 - 1, ix3 + 1)) { + x = ix1 + 1; + y = ix2 - 1; + z = ix3 + 1; + } // TSE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 - 1, ix3 + 1)) { + x = ix1 - 1; + y = ix2 - 1; + z = ix3 + 1; + } // TSW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 + 1, ix3 - 1)) { + x = ix1 + 1; + y = ix2 + 1; + z = ix3 - 1; + } // BNE + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 - 1, ix2 + 1, ix3 - 1)) { + x = ix1 - 1; + y = ix2 + 1; + z = ix3 - 1; + } // BNW + else if (InterpolationProcessor::iCellHasSolid(bcArray, ix1 + 1, ix2 - 1, ix3 - 1)) { + x = ix1 + 1; + y = ix2 - 1; + z = ix3 - 1; + } // BSE + + else { + { + UB_THROW(UbException(UB_EXARGS, "there is no cell ix1=" + UbSystem::toString(ix1) + + "ix2=" + UbSystem::toString(ix2) + "ix3=" + UbSystem::toString(ix3) + + "GlobalID=" + UbSystem::toString(block->getGlobalID()) + + "dx=" + UbSystem::toString(dx) + + "T=" + UbSystem::toString(bcPtr->getQ(D3Q27System::T)) + + "B=" + UbSystem::toString(bcPtr->getQ(D3Q27System::B)) + + "E=" + UbSystem::toString(bcPtr->getQ(D3Q27System::E)) + + "W=" + UbSystem::toString(bcPtr->getQ(D3Q27System::W)) + + "N=" + UbSystem::toString(bcPtr->getQ(D3Q27System::N)) + + "S=" + UbSystem::toString(bcPtr->getQ(D3Q27System::S)) + + "NE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::NE)) + + "SW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::SW)) + + "SE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::SE)) + + "NW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::NW)) + + "TE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TE)) + + "BW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BW)) + + "BE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BE)) + + "TW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TW)) + + "TN=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TN)) + + "BS=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BS)) + + "BN=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BN)) + + "TS=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TS)) + + "TNE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TNE)) + + "TNW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TNW)) + + "TSE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TSE)) + + "TSW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TSW)) + + "BNE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BNE)) + + "BNW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BNW)) + + "BSE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BSE)) + + "BSW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BSW) * dx))); + } + } + + if (InterpolationProcessor::iCellHasSolid(bcArray, x, y, z)) { + for (int i = x; i <= x + 1; i++) { + for (int j = y; j <= y + 1; j++) { + for (int k = z; k <= z + 1; k++) { + Vector3D pointplane1 = grid->getNodeCoordinates(block, i, j, k); + + double iph = pointplane1[0]; + double jph = pointplane1[1]; + double kph = pointplane1[2]; + + if (!bcArray->isSolid(i, j, k)) { + SPtr<BoundaryConditions> bcPtrIn = bcArray->getBC(i, j, k); + if (bcPtrIn) { + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (ii <= 2) { + LBMReal q = bcPtrIn->getQ(fdir); + if (q != 999.00000) { + if (fdir == D3Q27System::E) { + // if(!bcArray->isSolid(i, j, k))continue; + if (i + q <= x + 1) { + if (ii == 0) { + x1plane = iph + q * dx; + y1plane = jph; + z1plane = kph; + ii++; + } else if (ii == 1) { + x2plane = iph + q * dx; + y2plane = jph; + z2plane = kph; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph + q * dx; + y3plane = jph; + z3plane = kph; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + if (fdir == D3Q27System::W) { + // if(!bcArray->isSolid(i, j, k))continue; + if (i - q >= x) { + if (ii == 0) { + x1plane = iph - q * dx; + y1plane = jph; + z1plane = kph; + ii++; + } else if (ii == 1) { + x2plane = iph - q * dx; + y2plane = jph; + z2plane = kph; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph - q * dx; + y3plane = jph; + z3plane = kph; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + if (fdir == D3Q27System::N) { + // if(!bcArray->isSolid(i, j, k))continue; + if (j + q <= y + 1) { + if (ii == 0) { + x1plane = iph; + y1plane = jph + q * dx; + z1plane = kph; + ii++; + } else if (ii == 1) { + x2plane = iph; + y2plane = jph + q * dx; + z2plane = kph; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph; + y3plane = jph + q * dx; + z3plane = kph; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + if (fdir == D3Q27System::S) { + // if(!bcArray->isSolid(i, j, k))continue; + if (j - q >= y) { + if (ii == 0) { + x1plane = iph; + y1plane = jph - q * dx; + z1plane = kph; + ii++; + } else if (ii == 1) { + x2plane = iph; + y2plane = jph - q * dx; + z2plane = kph; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph; + y3plane = jph - q * dx; + z3plane = kph; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + + if (fdir == D3Q27System::T) { + // if(!bcArray->isSolid(i, j, k))continue; + if (k + q <= z + 1) { + if (ii == 0) { + x1plane = iph; + y1plane = jph; + z1plane = kph + q * dx; + ii++; + } else if (ii == 1) { + x2plane = iph; + y2plane = jph; + z2plane = kph + q * dx; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph; + y3plane = jph; + z3plane = kph + q * dx; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + if (fdir == D3Q27System::B) { + // if(!bcArray->isSolid(i, j, k))continue; + if (k - q >= z) { + if (ii == 0) { + x1plane = iph; + y1plane = jph; + z1plane = kph - q * dx; + ii++; + } else if (ii == 1) { + x2plane = iph; + y2plane = jph; + z2plane = kph - q * dx; + if (x1plane != x2plane || y1plane != y2plane || z1plane != z2plane) + ii++; + } else if (ii == 2) { + x3plane = iph; + y3plane = jph; + z3plane = kph - q * dx; + if ((x3plane != x1plane || y3plane != y1plane || + z3plane != z1plane) && + (x2plane != x3plane || y2plane != y3plane || + z2plane != z3plane)) + ii++; + } + } + } + } + } + } } - } - } - } + } + } } - } - } - - A = y1plane* (z2plane - z3plane) + y2plane*(z3plane - z1plane) + y3plane* (z1plane - z2plane); - B = z1plane* (x2plane - x3plane) + z2plane*(x3plane - x1plane) + z3plane* (x1plane - x2plane) ; - C = x1plane* (y2plane - y3plane) + x2plane*(y3plane - y1plane) + x3plane* (y1plane - y2plane) ; - D =-( x1plane*(y2plane*z3plane - y3plane*z2plane)+x2plane*(y3plane*z1plane - y1plane*z3plane) + x3plane* (y1plane* z2plane - y2plane* z1plane)); - } - if(ii!=3){ - - {{UB_THROW( UbException(UB_EXARGS,"ii is="+UbSystem::toString(ii)+" ix1="+UbSystem::toString(ix1)+" ix2="+UbSystem::toString(ix2)+" ix3="+UbSystem::toString(ix3)+" Block3D::GlobalID="+UbSystem::toString(block->getGlobalID())+" dx="+UbSystem::toString(dx) - +" T="+UbSystem::toString(bcPtr->getQ(D3Q27System::T))+" B="+UbSystem::toString(bcPtr->getQ(D3Q27System::B)) - +" E="+UbSystem::toString(bcPtr->getQ(D3Q27System::E))+" W="+UbSystem::toString(bcPtr->getQ(D3Q27System::W))+" N="+UbSystem::toString(bcPtr->getQ(D3Q27System::N)) - +" S="+UbSystem::toString(bcPtr->getQ(D3Q27System::S))+" NE="+UbSystem::toString(bcPtr->getQ(D3Q27System::NE))+" SW="+UbSystem::toString(bcPtr->getQ(D3Q27System::SW)) - +" SE="+UbSystem::toString(bcPtr->getQ(D3Q27System::SE))+" NW="+UbSystem::toString(bcPtr->getQ(D3Q27System::NW)) - +" TE="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TE))+" BW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BW))+" BE="+UbSystem::toString(bcPtr->getQ(D3Q27System::BE))+" TW="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TW))+" TN="+UbSystem::toString(bcPtr->getQ(D3Q27System::TN))+" BS="+UbSystem::toString(bcPtr->getQ(D3Q27System::BS))+" BN="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::BN))+" TS="+UbSystem::toString(bcPtr->getQ(D3Q27System::TS))+" TNE="+UbSystem::toString(bcPtr->getQ(D3Q27System::TNE))+" TNW="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::TNW))+" TSE="+UbSystem::toString(bcPtr->getQ(D3Q27System::TSE))+" TSW="+UbSystem::toString(bcPtr->getQ(D3Q27System::TSW))+" BNE="+ - UbSystem::toString(bcPtr->getQ(D3Q27System::BNE))+" BNW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BNW))+" BSE="+UbSystem::toString(bcPtr->getQ(D3Q27System::BSE))+" BSW="+UbSystem::toString(bcPtr->getQ(D3Q27System::BSW)) - ) ) ;}} - - } + } + + A = y1plane * (z2plane - z3plane) + y2plane * (z3plane - z1plane) + y3plane * (z1plane - z2plane); + B = z1plane * (x2plane - x3plane) + z2plane * (x3plane - x1plane) + z3plane * (x1plane - x2plane); + C = x1plane * (y2plane - y3plane) + x2plane * (y3plane - y1plane) + x3plane * (y1plane - y2plane); + D = -(x1plane * (y2plane * z3plane - y3plane * z2plane) + x2plane * (y3plane * z1plane - y1plane * z3plane) + + x3plane * (y1plane * z2plane - y2plane * z1plane)); + } + if (ii != 3) { + + { + { + UB_THROW(UbException( + UB_EXARGS, "ii is=" + UbSystem::toString(ii) + " ix1=" + UbSystem::toString(ix1) + + " ix2=" + UbSystem::toString(ix2) + " ix3=" + UbSystem::toString(ix3) + + " Block3D::GlobalID=" + UbSystem::toString(block->getGlobalID()) + " dx=" + + UbSystem::toString(dx) + " T=" + UbSystem::toString(bcPtr->getQ(D3Q27System::T)) + + " B=" + UbSystem::toString(bcPtr->getQ(D3Q27System::B)) + + " E=" + UbSystem::toString(bcPtr->getQ(D3Q27System::E)) + + " W=" + UbSystem::toString(bcPtr->getQ(D3Q27System::W)) + + " N=" + UbSystem::toString(bcPtr->getQ(D3Q27System::N)) + + " S=" + UbSystem::toString(bcPtr->getQ(D3Q27System::S)) + + " NE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::NE)) + + " SW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::SW)) + + " SE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::SE)) + + " NW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::NW)) + + " TE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TE)) + + " BW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BW)) + + " BE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BE)) + + " TW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TW)) + + " TN=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TN)) + + " BS=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BS)) + + " BN=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BN)) + + " TS=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TS)) + + " TNE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TNE)) + + " TNW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TNW)) + + " TSE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TSE)) + + " TSW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::TSW)) + + " BNE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BNE)) + + " BNW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BNW)) + + " BSE=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BSE)) + + " BSW=" + UbSystem::toString(bcPtr->getQ(D3Q27System::BSW)))); + } + } + } } //////////////////////////////////////////////////////////////////////////////////////////////////////// -bool ShearStressCoProcessor::checkUndefindedNodes( SPtr<BCArray3D> bcArray,int ix1,int ix2,int ix3) +bool ShearStressCoProcessor::checkUndefindedNodes(SPtr<BCArray3D> bcArray, int ix1, int ix2, int ix3) { - for(int i = ix1; i <= ix1 + 1; i++){ - for(int j = ix2; j <= ix2 + 1; j++){ - for (int k = ix3; k <= ix3 + 1; k++) - { - if(bcArray->isUndefined(i, j, k)) return true; - } - } - } - return false; + for (int i = ix1; i <= ix1 + 1; i++) { + for (int j = ix2; j <= ix2 + 1; j++) { + for (int k = ix3; k <= ix3 + 1; k++) { + if (bcArray->isUndefined(i, j, k)) + return true; + } + } + } + return false; } ////////////////////////////////////////////////////////////////////////////////////// void ShearStressCoProcessor::initDistance() { - for(const auto& interactor : interactors) - { -// typedef std::map<SPtr<Block3D>, std::set< std::vector<int> > > TransNodeIndicesMap; - for (const auto& t : interactor->getBcNodeIndicesMap()) - { - SPtr<Block3D> block = t.first; - const std::set< std::vector<int> >& transNodeIndicesSet = t.second; - -// UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); -// UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); -// double dx = grid->getDeltaX(block); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); - - int ghostLayer = kernel->getGhostLayerWidth(); -// LBMReal collFactor = kernel->getCollisionFactor(); - - int minX1 = ghostLayer; - int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; - int minX2 = ghostLayer; - int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; - int minX3 = ghostLayer; - int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; - - for(std::vector<int> node : transNodeIndicesSet) - { - int ix1 = node[0]; - int ix2 = node[1]; - int ix3 = node[2]; - - //without ghost nodes - if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 ||ix3 < minX3 || ix3 > maxX3 ) continue; - - if(bcArray->isFluid(ix1,ix2,ix3) ) - { - SPtr<BoundaryConditions> bc = bcArray->getBC(ix1,ix2,ix3); - if((bc->hasDensityBoundary()||bc->hasVelocityBoundary()))continue; - int numberOfCorner=0; - - if(bc->getQ(D3Q27System::T) !=999.000){ numberOfCorner++;} - if(bc->getQ(D3Q27System::B) !=999.000){ numberOfCorner++;} - if(bc->getQ(D3Q27System::E) !=999.000){ numberOfCorner++;} - if(bc->getQ(D3Q27System::W) !=999.000){ numberOfCorner++;} - if(bc->getQ(D3Q27System::N) !=999.000){ numberOfCorner++;} - if(bc->getQ(D3Q27System::S) !=999.000){ numberOfCorner++;} - // if(bc->hasVelocityBoundary()||bc->hasDensityBoundary())continue; - if(numberOfCorner>1)continue; - if(checkUndefindedNodes( bcArray, ix1,ix2,ix3))continue; - - - //////get normal and distance////// - double A,B,C,D,ii=0.0; - findPlane(ix1,ix2,ix3,grid,block,A,B,C,D,ii); - Vector3D pointplane1 = grid->getNodeCoordinates(block, ix1,ix2,ix3); - double ix1ph= pointplane1[0]; - double ix2ph= pointplane1[1]; - double ix3ph= pointplane1[2]; - double normalDis; - if(ii!=3) - { - UB_THROW( UbException(UB_EXARGS,"not enough points to create plane"+UbSystem::toString(ii))); - } - else - { - double s = A*ix1ph + B*ix2ph + C*ix3ph + D;//The sign of s = Ax + By + Cz + D determines which side the point (x,y,z) lies with respect to the plane. If s > 0 then the point lies on the same side as the normal (A,B,C). If s < 0 then it lies on the opposite side, if s = 0 then the point (x,y,z) lies on the plane. - if (s>0){s=1;} else if (s<0){s=-1;}else {s=0;} - - normalDis=((A*ix1ph + B*ix2ph + C*ix3ph + D)/sqrt(A*A+B*B+C*C));///distance point to plane xp-Xw=distance - normalDis*=s; - - (*ssv)(normalX1,ix1,ix2,ix3) = A; - (*ssv)(normalX2,ix1,ix2,ix3) = B; - (*ssv)(normalX3,ix1,ix2,ix3) = C; - (*ssv)(normalq,ix1,ix2,ix3) = normalDis; - (*ssv)(numberOfPoint,ix1,ix2,ix3) = ii; - - } + for (const auto &interactor : interactors) { + // typedef std::map<SPtr<Block3D>, std::set< std::vector<int> > > TransNodeIndicesMap; + for (const auto &t : interactor->getBcNodeIndicesMap()) { + SPtr<Block3D> block = t.first; + const std::set<std::vector<int>> &transNodeIndicesSet = t.second; + + // UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + // UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + // double dx = grid->getDeltaX(block); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<ShearStressValuesArray3D> ssv = kernel->getDataSet()->getShearStressValues(); + + int ghostLayer = kernel->getGhostLayerWidth(); + // LBMReal collFactor = kernel->getCollisionFactor(); + + int minX1 = ghostLayer; + int maxX1 = (int)bcArray->getNX1() - 1 - ghostLayer; + int minX2 = ghostLayer; + int maxX2 = (int)bcArray->getNX2() - 1 - ghostLayer; + int minX3 = ghostLayer; + int maxX3 = (int)bcArray->getNX3() - 1 - ghostLayer; + + for (std::vector<int> node : transNodeIndicesSet) { + int ix1 = node[0]; + int ix2 = node[1]; + int ix3 = node[2]; + + // without ghost nodes + if (ix1 < minX1 || ix1 > maxX1 || ix2 < minX2 || ix2 > maxX2 || ix3 < minX3 || ix3 > maxX3) + continue; + + if (bcArray->isFluid(ix1, ix2, ix3)) { + SPtr<BoundaryConditions> bc = bcArray->getBC(ix1, ix2, ix3); + if ((bc->hasDensityBoundary() || bc->hasVelocityBoundary())) + continue; + int numberOfCorner = 0; + + if (bc->getQ(D3Q27System::T) != 999.000) { + numberOfCorner++; + } + if (bc->getQ(D3Q27System::B) != 999.000) { + numberOfCorner++; + } + if (bc->getQ(D3Q27System::E) != 999.000) { + numberOfCorner++; + } + if (bc->getQ(D3Q27System::W) != 999.000) { + numberOfCorner++; + } + if (bc->getQ(D3Q27System::N) != 999.000) { + numberOfCorner++; + } + if (bc->getQ(D3Q27System::S) != 999.000) { + numberOfCorner++; + } + // if(bc->hasVelocityBoundary()||bc->hasDensityBoundary())continue; + if (numberOfCorner > 1) + continue; + if (checkUndefindedNodes(bcArray, ix1, ix2, ix3)) + continue; + + //////get normal and distance////// + double A, B, C, D, ii = 0.0; + findPlane(ix1, ix2, ix3, grid, block, A, B, C, D, ii); + Vector3D pointplane1 = grid->getNodeCoordinates(block, ix1, ix2, ix3); + double ix1ph = pointplane1[0]; + double ix2ph = pointplane1[1]; + double ix3ph = pointplane1[2]; + double normalDis; + if (ii != 3) { + UB_THROW(UbException(UB_EXARGS, "not enough points to create plane" + UbSystem::toString(ii))); + } else { + double s = A * ix1ph + B * ix2ph + C * ix3ph + + D; // The sign of s = Ax + By + Cz + D determines which side the point (x,y,z) lies + // with respect to the plane. If s > 0 then the point lies on the same side as the + // normal (A,B,C). If s < 0 then it lies on the opposite side, if s = 0 then the + // point (x,y,z) lies on the plane. + if (s > 0) { + s = 1; + } else if (s < 0) { + s = -1; + } else { + s = 0; + } + + normalDis = ((A * ix1ph + B * ix2ph + C * ix3ph + D) / + sqrt(A * A + B * B + C * C)); /// distance point to plane xp-Xw=distance + normalDis *= s; + + (*ssv)(normalX1, ix1, ix2, ix3) = A; + (*ssv)(normalX2, ix1, ix2, ix3) = B; + (*ssv)(normalX3, ix1, ix2, ix3) = C; + (*ssv)(normalq, ix1, ix2, ix3) = normalDis; + (*ssv)(numberOfPoint, ix1, ix2, ix3) = ii; + } + } } - } - } - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.h index a054fa36e..995589b9e 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/ShearStressCoProcessor.h @@ -2,8 +2,8 @@ #define D3Q27ShearStressCoProcessor_H #include <PointerDefinitions.h> -#include <vector> #include <string> +#include <vector> #include <basics/utilities/UbTuple.h> @@ -17,53 +17,69 @@ class BCArray3D; class WbWriter; //! \brief Computes the shear stress and y plus values and writes to parallel .vtk -//! \details writes at given time intervals specified in scheduler (s) and resets according to scheduler (rs). -//! Take root to obtain during post processing (paraview). -//! \author K. Kucher, S. Uphoff, M. Geier, E. Goraki Fard +//! \details writes at given time intervals specified in scheduler (s) and resets according to scheduler (rs). +//! Take root to obtain during post processing (paraview). +//! \author K. Kucher, S. Uphoff, M. Geier, E. Goraki Fard -class ShearStressCoProcessor: public CoProcessor +class ShearStressCoProcessor : public CoProcessor { public: - //! Default constructor - ShearStressCoProcessor()= default; - //! Constructor - ShearStressCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<UbScheduler> rs); - ~ShearStressCoProcessor() override; - - void process(double step) override; + //! Default constructor + ShearStressCoProcessor() = default; + //! Constructor + ShearStressCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<UbScheduler> rs); + ~ShearStressCoProcessor() override; + + void process(double step) override; + + void addInteractor(SPtr<D3Q27Interactor> interactor); - void addInteractor(SPtr<D3Q27Interactor> interactor); protected: - //! Computes average and shear stress values of macroscopic quantities - void calculateShearStress(double timeStep); - //! Prepare data and write in .vtk file - void collectData(double step); - //! Reset data - void resetData(double step); - //! prepare data - void addData(); - void clearData(); - void reset(double step); - void findPlane(int ix1,int ix2,int ix3, SPtr<Grid3D> grid, SPtr<Block3D> block,double &A,double &B,double &C,double &D,double &ii); - bool checkUndefindedNodes(SPtr<BCArray3D> bcArray,int ix1,int ix2,int ix3); - void initDistance(); + //! Computes average and shear stress values of macroscopic quantities + void calculateShearStress(double timeStep); + //! Prepare data and write in .vtk file + void collectData(double step); + //! Reset data + void resetData(double step); + //! prepare data + void addData(); + void clearData(); + void reset(double step); + void findPlane(int ix1, int ix2, int ix3, SPtr<Grid3D> grid, SPtr<Block3D> block, double &A, double &B, double &C, + double &D, double &ii); + bool checkUndefindedNodes(SPtr<BCArray3D> bcArray, int ix1, int ix2, int ix3); + void initDistance(); private: - std::vector<UbTupleFloat3> nodes; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::string path; - std::vector<SPtr<D3Q27Interactor> > interactors; - std::vector<double> normals; - int gridRank; - WbWriter* writer; - SPtr<UbScheduler> Resetscheduler; //additional scheduler to restart averaging after a given interval - int minInitLevel; //min init level - int maxInitLevel; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - enum Values{AvVx = 0, AvVy = 1, AvVz = 2, AvSxx = 3, AvSyy = 4, AvSzz = 5, AvSxy = 6, AvSyz = 7, AvSxz = 8, normalX1 = 9, normalX2 = 10, normalX3 = 11, normalq = 12,numberOfPoint=13}; + std::vector<UbTupleFloat3> nodes; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::string path; + std::vector<SPtr<D3Q27Interactor>> interactors; + std::vector<double> normals; + int gridRank; + WbWriter *writer; + SPtr<UbScheduler> Resetscheduler; // additional scheduler to restart averaging after a given interval + int minInitLevel; // min init level + int maxInitLevel; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + enum Values { + AvVx = 0, + AvVy = 1, + AvVz = 2, + AvSxx = 3, + AvSyy = 4, + AvSzz = 5, + AvSxy = 6, + AvSyz = 7, + AvSxz = 8, + normalX1 = 9, + normalX2 = 10, + normalX3 = 11, + normalq = 12, + numberOfPoint = 13 + }; }; - #endif /* D3Q27ShearStressCoProcessor_H */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.cpp index b3a92e95f..eb702a548 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.cpp @@ -1,999 +1,907 @@ #include "TimeAveragedValuesCoProcessor.h" - -#include "LBMKernel.h" #include "BCProcessor.h" +#include "LBMKernel.h" -#include "basics/writer/WbWriterVtkXmlASCII.h" -#include "DataSet3D.h" -#include "Grid3D.h" #include "Block3D.h" #include "Communicator.h" +#include "DataSet3D.h" +#include "Grid3D.h" #include "UbScheduler.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" #include "BCArray3D.h" - -TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor() -= default; +TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// -TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm, int options) - : CoProcessor(grid, s), - path(path), - writer(writer), - comm(comm), - options(options) +TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, + WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<Communicator> comm, int options) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm), options(options) { - init(); - planarAveraging = false; - timeAveraging = true; + init(); + planarAveraging = false; + timeAveraging = true; } ////////////////////////////////////////////////////////////////////////// -TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm, int options, - std::vector<int> levels, std::vector<double>& levelCoords, std::vector<double>& bounds, bool timeAveraging) - : CoProcessor(grid, s), - path(path), - writer(writer), - comm(comm), - options(options), - levels(levels), - levelCoords(levelCoords), - bounds(bounds), - timeAveraging(timeAveraging) +TimeAveragedValuesCoProcessor::TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, + WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<Communicator> comm, int options, + std::vector<int> levels, std::vector<double> &levelCoords, + std::vector<double> &bounds, bool timeAveraging) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm), options(options), levels(levels), + levelCoords(levelCoords), bounds(bounds), timeAveraging(timeAveraging) { - init(); - planarAveraging = true; + init(); + planarAveraging = true; } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::init() { - root = comm->isRoot(); - gridRank = grid->getRank(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); - - withGhostLayer = false; - iMinC = 1; - - minStep = scheduler->getMinBegin(); - maxStep = scheduler->getMaxEnd(); - numberOfSteps = (maxStep - minStep); - - //function pointer - using namespace D3Q27System; - calcMacros = NULL; - if (compressible) - { - calcMacros = &calcCompMacroscopicValues; - } - else - { - calcMacros = &calcIncompMacroscopicValues; - } - - double begin = scheduler->getMinBegin(); - double gridTimeStep = grid->getTimeStep(); - - if (gridTimeStep == begin || gridTimeStep == 0) - { - initData(); - } - else - { - blockVector.clear(); - blockVector.resize(maxInitLevel + 1); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - if (blockVector[level].size() > 0) compressible = blockVector[level][0]->getKernel()->getCompressible(); - } - } + root = comm->isRoot(); + gridRank = grid->getRank(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); + + withGhostLayer = false; + iMinC = 1; + + minStep = scheduler->getMinBegin(); + maxStep = scheduler->getMaxEnd(); + numberOfSteps = (maxStep - minStep); + + // function pointer + using namespace D3Q27System; + calcMacros = NULL; + if (compressible) { + calcMacros = &calcCompMacroscopicValues; + } else { + calcMacros = &calcIncompMacroscopicValues; + } + + double begin = scheduler->getMinBegin(); + double gridTimeStep = grid->getTimeStep(); + + if (gridTimeStep == begin || gridTimeStep == 0) { + initData(); + } else { + blockVector.clear(); + blockVector.resize(maxInitLevel + 1); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + if (blockVector[level].size() > 0) + compressible = blockVector[level][0]->getKernel()->getCompressible(); + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::initData() { - blockVector.clear(); - blockVector.resize(maxInitLevel + 1); - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - - if (blockVector[level].size() > 0) - compressible = blockVector[level][0]->getKernel()->getCompressible(); - - for (SPtr<Block3D> block : blockVector[level]) - { - UbTupleInt3 nx = grid->getBlockNX(); - - if ((options&Density) == Density) - { - SPtr<AverageValuesArray3D> ar = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(2, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); - block->getKernel()->getDataSet()->setAverageDensity(ar); - } - - if ((options&Velocity) == Velocity) - { - SPtr<AverageValuesArray3D> av = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(3, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); - block->getKernel()->getDataSet()->setAverageVelocity(av); - } - - if ((options&Fluctuations) == Fluctuations) - { - SPtr<AverageValuesArray3D> af = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(6, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); - block->getKernel()->getDataSet()->setAverageFluctuations(af); - } - - if ((options&Triplecorrelations) == Triplecorrelations) - { - SPtr<AverageValuesArray3D> at = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(10, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); - block->getKernel()->getDataSet()->setAverageTriplecorrelations(at); - } - } - } + blockVector.clear(); + blockVector.resize(maxInitLevel + 1); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + + if (blockVector[level].size() > 0) + compressible = blockVector[level][0]->getKernel()->getCompressible(); + + for (SPtr<Block3D> block : blockVector[level]) { + UbTupleInt3 nx = grid->getBlockNX(); + + if ((options & Density) == Density) { + SPtr<AverageValuesArray3D> ar = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(2, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setAverageDensity(ar); + } + + if ((options & Velocity) == Velocity) { + SPtr<AverageValuesArray3D> av = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(3, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setAverageVelocity(av); + } + + if ((options & Fluctuations) == Fluctuations) { + SPtr<AverageValuesArray3D> af = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(6, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setAverageFluctuations(af); + } + + if ((options & Triplecorrelations) == Triplecorrelations) { + SPtr<AverageValuesArray3D> at = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(10, val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 0.0)); + block->getKernel()->getDataSet()->setAverageTriplecorrelations(at); + } + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::process(double step) { - if (step == minStep) - { - initData(); - numberOfSteps = (maxStep - minStep)+1; - //DEBUG///////////////////// - //UBLOG(logINFO, "process::step = " << step << ", minStep = " << minStep << ", maxStep = " << maxStep << ", numberOfSteps = " << numberOfSteps << " init()"); - //////////////////////////// - } - calculateSubtotal(step); - - if (step == maxStep) - { - //DEBUG///////////////////// - //UBLOG(logINFO, "process::step = " << step << ", minStep = " << minStep << ", maxStep = " << maxStep << ", numberOfSteps = " << numberOfSteps); - //////////////////////////// - - //calculateAverageValues((double)numberOfFineSteps); - calculateAverageValues(numberOfSteps); - - if (timeAveraging) - { - collectData(step); - } - - if (planarAveraging) - { - planarAverage(step); - } - } - - UBLOG(logDEBUG3, "AverageValuesCoProcessor::update:" << step); + if (step == minStep) { + initData(); + numberOfSteps = (maxStep - minStep) + 1; + // DEBUG///////////////////// + // UBLOG(logINFO, "process::step = " << step << ", minStep = " << minStep << ", maxStep = " << maxStep << ", + // numberOfSteps = " << numberOfSteps << " init()"); + //////////////////////////// + } + calculateSubtotal(step); + + if (step == maxStep) { + // DEBUG///////////////////// + // UBLOG(logINFO, "process::step = " << step << ", minStep = " << minStep << ", maxStep = " << maxStep << ", + // numberOfSteps = " << numberOfSteps); + //////////////////////////// + + // calculateAverageValues((double)numberOfFineSteps); + calculateAverageValues(numberOfSteps); + + if (timeAveraging) { + collectData(step); + } + + if (planarAveraging) { + planarAverage(step); + } + } + + UBLOG(logDEBUG3, "AverageValuesCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::collectData(double step) { - int istep = int(step); - - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); - } - } - } - - std::string pfilePath, partPath, subfolder, cfilePath; - subfolder = "tav" + UbSystem::toString(istep); - pfilePath = path + "/tav/" + subfolder; - partPath = pfilePath + "/tav" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); - - std::string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); - size_t found = partName.find_last_of("/"); - std::string piece = partName.substr(found + 1); - piece = subfolder + "/" + piece; - - std::vector<std::string> cellDataNames; - std::vector<std::string> pieces = comm->gather(piece); - if (root) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); - UBLOG(logINFO, "TimeAveragedValuesCoProcessor::collectData() step: " << istep); - } - - clearData(); + int istep = int(step); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } + } + } + + std::string pfilePath, partPath, subfolder, cfilePath; + subfolder = "tav" + UbSystem::toString(istep); + pfilePath = path + "/tav/" + subfolder; + partPath = pfilePath + "/tav" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); + + std::string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); + size_t found = partName.find_last_of("/"); + std::string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + std::vector<std::string> cellDataNames; + std::vector<std::string> pieces = comm->gather(piece); + if (root) { + std::string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + UBLOG(logINFO, "TimeAveragedValuesCoProcessor::collectData() step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::addData(const SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - int level = block->getLevel(); - - //Diese Daten werden geschrieben: - datanames.resize(0); - - datanames.emplace_back("level"); - datanames.emplace_back("Rho"); - - if ((options&Density) == Density) - { - datanames.emplace_back("taRho"); - datanames.emplace_back("taRhoF"); - } - - if ((options&Velocity) == Velocity) - { - datanames.emplace_back("taVx"); - datanames.emplace_back("taVy"); - datanames.emplace_back("taVz"); - } - - if ((options&Fluctuations) == Fluctuations) - { - datanames.emplace_back("taVxx"); - datanames.emplace_back("taVyy"); - datanames.emplace_back("taVzz"); - datanames.emplace_back("taVxy"); - datanames.emplace_back("taVxz"); - datanames.emplace_back("taVyz"); - datanames.emplace_back("taVyz"); - } - - if ((options&Triplecorrelations) == Triplecorrelations) - { - datanames.emplace_back("taVxxx"); - datanames.emplace_back("taVxxy"); - datanames.emplace_back("taVxxz"); - datanames.emplace_back("taVyyy"); - datanames.emplace_back("taVyyx"); - datanames.emplace_back("taVyyz"); - datanames.emplace_back("taVzzz"); - datanames.emplace_back("taVzzx"); - datanames.emplace_back("taVzzy"); - datanames.emplace_back("taVxyz"); - } - - - //datanames.push_back("AvP"); - //datanames.push_back("AvPrms"); - - - data.resize(datanames.size()); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); - SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); - SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); - //int ghostLayerWidth = kernel->getGhostLayerWidth(); - - //knotennummerierung faengt immer bei 0 an! - unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; - - int minX1 = iMinC; - int minX2 = iMinC; - int minX3 = iMinC; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); - - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - LBMReal f[D3Q27System::ENDF + 1]; - LBMReal vx1, vx2, vx3, rho; - - //D3Q27BoundaryConditionPtr bcPtr; - - int nr = (int)nodes.size(); - - for (int ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (int ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (int ix1 = minX1; ix1 <= maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) - { - int index = 0; - nodeNumbers(ix1, ix2, ix3) = nr++; - nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1*dx), - float(val<2>(org) - val<2>(nodeOffset) + ix2*dx), - float(val<3>(org) - val<3>(nodeOffset) + ix3*dx))); - - data[index++].push_back(level); - - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f, rho, vx1, vx2, vx3); - - data[index++].push_back(rho); - - - - if ((options&Density) == Density) - { - data[index++].push_back((*ar)(Rho, ix1, ix2, ix3)); - data[index++].push_back((*ar)(RhoF, ix1, ix2, ix3)); - } - - if ((options&Velocity) == Velocity) - { - data[index++].push_back((*av)(Vx, ix1, ix2, ix3)); - data[index++].push_back((*av)(Vy, ix1, ix2, ix3)); - data[index++].push_back((*av)(Vz, ix1, ix2, ix3)); - } - - if ((options&Fluctuations) == Fluctuations) - { - data[index++].push_back((*af)(Vxx, ix1, ix2, ix3)); - data[index++].push_back((*af)(Vyy, ix1, ix2, ix3)); - data[index++].push_back((*af)(Vzz, ix1, ix2, ix3)); - data[index++].push_back((*af)(Vxy, ix1, ix2, ix3)); - data[index++].push_back((*af)(Vxz, ix1, ix2, ix3)); - data[index++].push_back((*af)(Vyz, ix1, ix2, ix3)); - } - - if ((options&Triplecorrelations) == Triplecorrelations) - { - data[index++].push_back((*at)(Vxxx, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vxxy, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vxxz, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vyyy, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vyyx, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vyyz, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vzzz, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vzzx, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vzzy, ix1, ix2, ix3)); - data[index++].push_back((*at)(Vxyz, ix1, ix2, ix3)); - } + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + int level = block->getLevel(); + + // Diese Daten werden geschrieben: + datanames.resize(0); + + datanames.emplace_back("level"); + datanames.emplace_back("Rho"); + + if ((options & Density) == Density) { + datanames.emplace_back("taRho"); + datanames.emplace_back("taRhoF"); + } + + if ((options & Velocity) == Velocity) { + datanames.emplace_back("taVx"); + datanames.emplace_back("taVy"); + datanames.emplace_back("taVz"); + } + + if ((options & Fluctuations) == Fluctuations) { + datanames.emplace_back("taVxx"); + datanames.emplace_back("taVyy"); + datanames.emplace_back("taVzz"); + datanames.emplace_back("taVxy"); + datanames.emplace_back("taVxz"); + datanames.emplace_back("taVyz"); + datanames.emplace_back("taVyz"); + } + + if ((options & Triplecorrelations) == Triplecorrelations) { + datanames.emplace_back("taVxxx"); + datanames.emplace_back("taVxxy"); + datanames.emplace_back("taVxxz"); + datanames.emplace_back("taVyyy"); + datanames.emplace_back("taVyyx"); + datanames.emplace_back("taVyyz"); + datanames.emplace_back("taVzzz"); + datanames.emplace_back("taVzzx"); + datanames.emplace_back("taVzzy"); + datanames.emplace_back("taVxyz"); + } + + // datanames.push_back("AvP"); + // datanames.push_back("AvPrms"); + + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); + SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); + SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); + // int ghostLayerWidth = kernel->getGhostLayerWidth(); + + // knotennummerierung faengt immer bei 0 an! + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + int minX1 = iMinC; + int minX2 = iMinC; + int minX3 = iMinC; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + + // D3Q27BoundaryConditionPtr bcPtr; + + int nr = (int)nodes.size(); + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + data[index++].push_back(level); + + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + + data[index++].push_back(rho); + + if ((options & Density) == Density) { + data[index++].push_back((*ar)(Rho, ix1, ix2, ix3)); + data[index++].push_back((*ar)(RhoF, ix1, ix2, ix3)); + } + + if ((options & Velocity) == Velocity) { + data[index++].push_back((*av)(Vx, ix1, ix2, ix3)); + data[index++].push_back((*av)(Vy, ix1, ix2, ix3)); + data[index++].push_back((*av)(Vz, ix1, ix2, ix3)); + } + + if ((options & Fluctuations) == Fluctuations) { + data[index++].push_back((*af)(Vxx, ix1, ix2, ix3)); + data[index++].push_back((*af)(Vyy, ix1, ix2, ix3)); + data[index++].push_back((*af)(Vzz, ix1, ix2, ix3)); + data[index++].push_back((*af)(Vxy, ix1, ix2, ix3)); + data[index++].push_back((*af)(Vxz, ix1, ix2, ix3)); + data[index++].push_back((*af)(Vyz, ix1, ix2, ix3)); + } + + if ((options & Triplecorrelations) == Triplecorrelations) { + data[index++].push_back((*at)(Vxxx, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vxxy, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vxxz, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vyyy, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vyyx, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vyyz, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vzzz, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vzzx, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vzzy, ix1, ix2, ix3)); + data[index++].push_back((*at)(Vxyz, ix1, ix2, ix3)); + } + } } - } - } - } - - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - //cell vector erstellen - for (int ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (int ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (int ix1 = minX1; ix1 <= maxX1; ix1++) - { - if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 - && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 - && (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 - && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 - && (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 - && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 - && (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 - && (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) - { - cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } + } + + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::calculateAverageValues(double timeSteps) { - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - int i; - //#ifdef _OPENMP - // #pragma omp parallel for - //#endif - //for(SPtr<Block3D> block : blockVector[level]) - for (i = 0; i < blockVector[level].size(); i++) - { - SPtr<Block3D> block = blockVector[level][i]; - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); - SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); - SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); - - int minX1 = iMinC; - int minX2 = iMinC; - int minX3 = iMinC; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - LBMReal rho, ux, uy, uz, uxx, uzz, uyy, uxy, uxz, uyz, rhof; - - for (int ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (int ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (int ix1 = minX1; ix1 <= maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - - //mean density - if ((options&Density) == Density) - { - rho = (*ar)(Rho, ix1, ix2, ix3) / timeSteps; - rhof = (*ar)(RhoF, ix1, ix2, ix3) / timeSteps; - (*ar)(Rho, ix1, ix2, ix3) = rho; - (*ar)(RhoF, ix1, ix2, ix3) = rhof - rho*rho; - } - - //mean velocity - if ((options&Velocity) == Velocity) - { - ux = (*av)(Vx, ix1, ix2, ix3) / timeSteps; - uy = (*av)(Vy, ix1, ix2, ix3) / timeSteps; - uz = (*av)(Vz, ix1, ix2, ix3) / timeSteps; - - (*av)(Vx, ix1, ix2, ix3) = ux; - (*av)(Vy, ix1, ix2, ix3) = uy; - (*av)(Vz, ix1, ix2, ix3) = uz; - } - - //fluctuations - if ((options&Fluctuations) == Fluctuations) - { - uxx = (*af)(Vxx, ix1, ix2, ix3) / timeSteps; - uyy = (*af)(Vyy, ix1, ix2, ix3) / timeSteps; - uzz = (*af)(Vzz, ix1, ix2, ix3) / timeSteps; - uxy = (*af)(Vxy, ix1, ix2, ix3) / timeSteps; - uxz = (*af)(Vxz, ix1, ix2, ix3) / timeSteps; - uyz = (*af)(Vyz, ix1, ix2, ix3) / timeSteps; - - (*af)(Vxx, ix1, ix2, ix3) = uxx - ux*ux; - (*af)(Vyy, ix1, ix2, ix3) = uyy - uy*uy; - (*af)(Vzz, ix1, ix2, ix3) = uzz - uz*uz; - (*af)(Vxy, ix1, ix2, ix3) = uxy - ux*uy; - (*af)(Vxz, ix1, ix2, ix3) = uxz - ux*uz; - (*af)(Vyz, ix1, ix2, ix3) = uyz - uy*uz; - } - - if ((options&Triplecorrelations) == Triplecorrelations) - { - //triple-correlations - (*at)(Vxxx, ix1, ix2, ix3) = (*at)(Vxxx, ix1, ix2, ix3) / timeSteps - 3.0 * uxx*ux + 2.0 * ux*ux*ux; - (*at)(Vxxy, ix1, ix2, ix3) = (*at)(Vxxy, ix1, ix2, ix3) / timeSteps - 2.0 * uxy*ux - uxx*uy + 2.0 * ux*ux*uy; - (*at)(Vxxz, ix1, ix2, ix3) = (*at)(Vxxz, ix1, ix2, ix3) / timeSteps - 2.0 * uxz*ux - uxx*uz + 2.0 * ux*ux*uz; - (*at)(Vyyy, ix1, ix2, ix3) = (*at)(Vyyy, ix1, ix2, ix3) / timeSteps - 3.0 * uyy*uy + 2.0 * uy*uy*uy; - (*at)(Vyyx, ix1, ix2, ix3) = (*at)(Vyyx, ix1, ix2, ix3) / timeSteps - 2.0 * uxy*uy - uyy*ux + 2.0 * uy*uy*ux; - (*at)(Vyyz, ix1, ix2, ix3) = (*at)(Vyyz, ix1, ix2, ix3) / timeSteps - 2.0 * uyz*uy - uyy*uz + 2.0 * uy*uy*uz; - (*at)(Vzzz, ix1, ix2, ix3) = (*at)(Vzzz, ix1, ix2, ix3) / timeSteps - 3.0 * uzz*uz + 2.0 * uz*uz*uz; - (*at)(Vzzx, ix1, ix2, ix3) = (*at)(Vzzx, ix1, ix2, ix3) / timeSteps - 2.0 * uxz*uz - uzz*ux + 2.0 * uz*uz*ux; - (*at)(Vzzy, ix1, ix2, ix3) = (*at)(Vzzy, ix1, ix2, ix3) / timeSteps - 2.0 * uyz*uz - uzz*uy + 2.0 * uz*uz*uy; - (*at)(Vxyz, ix1, ix2, ix3) = (*at)(Vxyz, ix1, ix2, ix3) / timeSteps - uxy*uz - uxz*uy - uyz*ux + 2.0 * ux*uy*uz; + for (int level = minInitLevel; level <= maxInitLevel; level++) { + int i; + //#ifdef _OPENMP + // #pragma omp parallel for + //#endif + // for(SPtr<Block3D> block : blockVector[level]) + for (i = 0; i < blockVector[level].size(); i++) { + SPtr<Block3D> block = blockVector[level][i]; + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); + SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); + SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); + + int minX1 = iMinC; + int minX2 = iMinC; + int minX3 = iMinC; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + LBMReal rho, ux, uy, uz, uxx, uzz, uyy, uxy, uxz, uyz, rhof; + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + + // mean density + if ((options & Density) == Density) { + rho = (*ar)(Rho, ix1, ix2, ix3) / timeSteps; + rhof = (*ar)(RhoF, ix1, ix2, ix3) / timeSteps; + (*ar)(Rho, ix1, ix2, ix3) = rho; + (*ar)(RhoF, ix1, ix2, ix3) = rhof - rho * rho; + } + + // mean velocity + if ((options & Velocity) == Velocity) { + ux = (*av)(Vx, ix1, ix2, ix3) / timeSteps; + uy = (*av)(Vy, ix1, ix2, ix3) / timeSteps; + uz = (*av)(Vz, ix1, ix2, ix3) / timeSteps; + + (*av)(Vx, ix1, ix2, ix3) = ux; + (*av)(Vy, ix1, ix2, ix3) = uy; + (*av)(Vz, ix1, ix2, ix3) = uz; + } + + // fluctuations + if ((options & Fluctuations) == Fluctuations) { + uxx = (*af)(Vxx, ix1, ix2, ix3) / timeSteps; + uyy = (*af)(Vyy, ix1, ix2, ix3) / timeSteps; + uzz = (*af)(Vzz, ix1, ix2, ix3) / timeSteps; + uxy = (*af)(Vxy, ix1, ix2, ix3) / timeSteps; + uxz = (*af)(Vxz, ix1, ix2, ix3) / timeSteps; + uyz = (*af)(Vyz, ix1, ix2, ix3) / timeSteps; + + (*af)(Vxx, ix1, ix2, ix3) = uxx - ux * ux; + (*af)(Vyy, ix1, ix2, ix3) = uyy - uy * uy; + (*af)(Vzz, ix1, ix2, ix3) = uzz - uz * uz; + (*af)(Vxy, ix1, ix2, ix3) = uxy - ux * uy; + (*af)(Vxz, ix1, ix2, ix3) = uxz - ux * uz; + (*af)(Vyz, ix1, ix2, ix3) = uyz - uy * uz; + } + + if ((options & Triplecorrelations) == Triplecorrelations) { + // triple-correlations + (*at)(Vxxx, ix1, ix2, ix3) = + (*at)(Vxxx, ix1, ix2, ix3) / timeSteps - 3.0 * uxx * ux + 2.0 * ux * ux * ux; + (*at)(Vxxy, ix1, ix2, ix3) = (*at)(Vxxy, ix1, ix2, ix3) / timeSteps - + 2.0 * uxy * ux - uxx * uy + 2.0 * ux * ux * uy; + (*at)(Vxxz, ix1, ix2, ix3) = (*at)(Vxxz, ix1, ix2, ix3) / timeSteps - + 2.0 * uxz * ux - uxx * uz + 2.0 * ux * ux * uz; + (*at)(Vyyy, ix1, ix2, ix3) = + (*at)(Vyyy, ix1, ix2, ix3) / timeSteps - 3.0 * uyy * uy + 2.0 * uy * uy * uy; + (*at)(Vyyx, ix1, ix2, ix3) = (*at)(Vyyx, ix1, ix2, ix3) / timeSteps - + 2.0 * uxy * uy - uyy * ux + 2.0 * uy * uy * ux; + (*at)(Vyyz, ix1, ix2, ix3) = (*at)(Vyyz, ix1, ix2, ix3) / timeSteps - + 2.0 * uyz * uy - uyy * uz + 2.0 * uy * uy * uz; + (*at)(Vzzz, ix1, ix2, ix3) = + (*at)(Vzzz, ix1, ix2, ix3) / timeSteps - 3.0 * uzz * uz + 2.0 * uz * uz * uz; + (*at)(Vzzx, ix1, ix2, ix3) = (*at)(Vzzx, ix1, ix2, ix3) / timeSteps - + 2.0 * uxz * uz - uzz * ux + 2.0 * uz * uz * ux; + (*at)(Vzzy, ix1, ix2, ix3) = (*at)(Vzzy, ix1, ix2, ix3) / timeSteps - + 2.0 * uyz * uz - uzz * uy + 2.0 * uz * uz * uy; + (*at)(Vxyz, ix1, ix2, ix3) = (*at)(Vxyz, ix1, ix2, ix3) / timeSteps - uxy * uz - + uxz * uy - uyz * ux + 2.0 * ux * uy * uz; + } + ////////////////////////////////////////////////////////////////////////// + } } - ////////////////////////////////////////////////////////////////////////// - } - } - } + } + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::calculateSubtotal(double step) { - if (scheduler->isDue(step)) - { - - //DEBUG///////////////////// - //UBLOG(logINFO, "calculateSubtotal::step = " << step); - //////////////////////////// - LBMReal f[27]; - - -//#ifdef _OPENMP -//#pragma omp parallel private (f) -//#endif - { - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - int i; -//#ifdef _OPENMP -//#pragma omp for schedule(dynamic) -//#endif - //for(SPtr<Block3D> block : blockVector[level]) - for (i = 0; i < blockVector[level].size(); i++) - { - SPtr<Block3D> block = blockVector[level][i]; - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); - SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); - SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); - - int minX1 = iMinC; - int minX2 = iMinC; - int minX3 = iMinC; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - for (int ix3 = minX3; ix3 <= maxX3; ix3++) - { - for (int ix2 = minX2; ix2 <= maxX2; ix2++) - { - for (int ix1 = minX1; ix1 <= maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //read distribution - //////////////////////////////////////////////////////////////////////////// - - distributions->getDistribution(f, ix1, ix2, ix3); - ////////////////////////////////////////////////////////////////////////// - //compute velocity - ////////////////////////////////////////////////////////////////////////// - LBMReal vx, vy, vz, rho; - calcMacros(f, rho, vx, vy, vz); - //double press = D3Q27System::calcPress(f, rho, vx, vy, vz); - - ////////////////////////////////////////////////////////////////////////// - //compute subtotals - ////////////////////////////////////////////////////////////////////////// - - //mean density - if ((options&Density) == Density) - { - (*ar)(0, ix1, ix2, ix3) = (*ar)(Rho, ix1, ix2, ix3) + rho; - (*ar)(RhoF, ix1, ix2, ix3) = (*ar)(RhoF, ix1, ix2, ix3) + rho*rho; - } - - //mean velocity - if ((options&Velocity) == Velocity) - { - (*av)(Vx, ix1, ix2, ix3) = (*av)(Vx, ix1, ix2, ix3) + vx; - (*av)(Vy, ix1, ix2, ix3) = (*av)(Vy, ix1, ix2, ix3) + vy; - (*av)(Vz, ix1, ix2, ix3) = (*av)(Vz, ix1, ix2, ix3) + vz; - } - - //fluctuations - if ((options&Fluctuations) == Fluctuations) - { - (*af)(Vxx, ix1, ix2, ix3) = (*af)(Vxx, ix1, ix2, ix3) + vx*vx; - (*af)(Vyy, ix1, ix2, ix3) = (*af)(Vyy, ix1, ix2, ix3) + vy*vy; - (*af)(Vzz, ix1, ix2, ix3) = (*af)(Vzz, ix1, ix2, ix3) + vz*vz; - (*af)(Vxy, ix1, ix2, ix3) = (*af)(Vxy, ix1, ix2, ix3) + vx*vy; - (*af)(Vxz, ix1, ix2, ix3) = (*af)(Vxz, ix1, ix2, ix3) + vx*vz; - (*af)(Vyz, ix1, ix2, ix3) = (*af)(Vyz, ix1, ix2, ix3) + vy*vz; - } - - //triple-correlations - if ((options&Triplecorrelations) == Triplecorrelations) - { - (*at)(Vxxx, ix1, ix2, ix3) = (*at)(Vxxx, ix1, ix2, ix3) + vx*vx*vx; - (*at)(Vxxy, ix1, ix2, ix3) = (*at)(Vxxy, ix1, ix2, ix3) + vx*vx*vy; - (*at)(Vxxz, ix1, ix2, ix3) = (*at)(Vxxz, ix1, ix2, ix3) + vx*vx*vz; - (*at)(Vyyy, ix1, ix2, ix3) = (*at)(Vyyy, ix1, ix2, ix3) + vy*vy*vy; - (*at)(Vyyx, ix1, ix2, ix3) = (*at)(Vyyx, ix1, ix2, ix3) + vy*vy*vx; - (*at)(Vyyz, ix1, ix2, ix3) = (*at)(Vyyz, ix1, ix2, ix3) + vy*vy*vz; - (*at)(Vzzz, ix1, ix2, ix3) = (*at)(Vzzz, ix1, ix2, ix3) + vz*vz*vz; - (*at)(Vzzx, ix1, ix2, ix3) = (*at)(Vzzx, ix1, ix2, ix3) + vz*vz*vx; - (*at)(Vzzy, ix1, ix2, ix3) = (*at)(Vzzy, ix1, ix2, ix3) + vz*vz*vy; - (*at)(Vxyz, ix1, ix2, ix3) = (*at)(Vxyz, ix1, ix2, ix3) + vx*vy*vz; - } - ////////////////////////////////////////////////////////////////////////// - } + if (scheduler->isDue(step)) { + + // DEBUG///////////////////// + // UBLOG(logINFO, "calculateSubtotal::step = " << step); + //////////////////////////// + LBMReal f[27]; + + //#ifdef _OPENMP + //#pragma omp parallel private (f) + //#endif + { + for (int level = minInitLevel; level <= maxInitLevel; level++) { + int i; + //#ifdef _OPENMP + //#pragma omp for schedule(dynamic) + //#endif + // for(SPtr<Block3D> block : blockVector[level]) + for (i = 0; i < blockVector[level].size(); i++) { + SPtr<Block3D> block = blockVector[level][i]; + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> ar = kernel->getDataSet()->getAverageDensity(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageVelocity(); + SPtr<AverageValuesArray3D> af = kernel->getDataSet()->getAverageFluctuations(); + SPtr<AverageValuesArray3D> at = kernel->getDataSet()->getAverageTriplecorrelations(); + + int minX1 = iMinC; + int minX2 = iMinC; + int minX3 = iMinC; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // read distribution + //////////////////////////////////////////////////////////////////////////// + + distributions->getDistribution(f, ix1, ix2, ix3); + ////////////////////////////////////////////////////////////////////////// + // compute velocity + ////////////////////////////////////////////////////////////////////////// + LBMReal vx, vy, vz, rho; + calcMacros(f, rho, vx, vy, vz); + // double press = D3Q27System::calcPress(f, rho, vx, vy, vz); + + ////////////////////////////////////////////////////////////////////////// + // compute subtotals + ////////////////////////////////////////////////////////////////////////// + + // mean density + if ((options & Density) == Density) { + (*ar)(0, ix1, ix2, ix3) = (*ar)(Rho, ix1, ix2, ix3) + rho; + (*ar)(RhoF, ix1, ix2, ix3) = (*ar)(RhoF, ix1, ix2, ix3) + rho * rho; + } + + // mean velocity + if ((options & Velocity) == Velocity) { + (*av)(Vx, ix1, ix2, ix3) = (*av)(Vx, ix1, ix2, ix3) + vx; + (*av)(Vy, ix1, ix2, ix3) = (*av)(Vy, ix1, ix2, ix3) + vy; + (*av)(Vz, ix1, ix2, ix3) = (*av)(Vz, ix1, ix2, ix3) + vz; + } + + // fluctuations + if ((options & Fluctuations) == Fluctuations) { + (*af)(Vxx, ix1, ix2, ix3) = (*af)(Vxx, ix1, ix2, ix3) + vx * vx; + (*af)(Vyy, ix1, ix2, ix3) = (*af)(Vyy, ix1, ix2, ix3) + vy * vy; + (*af)(Vzz, ix1, ix2, ix3) = (*af)(Vzz, ix1, ix2, ix3) + vz * vz; + (*af)(Vxy, ix1, ix2, ix3) = (*af)(Vxy, ix1, ix2, ix3) + vx * vy; + (*af)(Vxz, ix1, ix2, ix3) = (*af)(Vxz, ix1, ix2, ix3) + vx * vz; + (*af)(Vyz, ix1, ix2, ix3) = (*af)(Vyz, ix1, ix2, ix3) + vy * vz; + } + + // triple-correlations + if ((options & Triplecorrelations) == Triplecorrelations) { + (*at)(Vxxx, ix1, ix2, ix3) = (*at)(Vxxx, ix1, ix2, ix3) + vx * vx * vx; + (*at)(Vxxy, ix1, ix2, ix3) = (*at)(Vxxy, ix1, ix2, ix3) + vx * vx * vy; + (*at)(Vxxz, ix1, ix2, ix3) = (*at)(Vxxz, ix1, ix2, ix3) + vx * vx * vz; + (*at)(Vyyy, ix1, ix2, ix3) = (*at)(Vyyy, ix1, ix2, ix3) + vy * vy * vy; + (*at)(Vyyx, ix1, ix2, ix3) = (*at)(Vyyx, ix1, ix2, ix3) + vy * vy * vx; + (*at)(Vyyz, ix1, ix2, ix3) = (*at)(Vyyz, ix1, ix2, ix3) + vy * vy * vz; + (*at)(Vzzz, ix1, ix2, ix3) = (*at)(Vzzz, ix1, ix2, ix3) + vz * vz * vz; + (*at)(Vzzx, ix1, ix2, ix3) = (*at)(Vzzx, ix1, ix2, ix3) + vz * vz * vx; + (*at)(Vzzy, ix1, ix2, ix3) = (*at)(Vzzy, ix1, ix2, ix3) + vz * vz * vy; + (*at)(Vxyz, ix1, ix2, ix3) = (*at)(Vxyz, ix1, ix2, ix3) + vx * vy * vz; + } + ////////////////////////////////////////////////////////////////////////// + } + } + } } - } - } - } + } + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::planarAverage(double step) { - std::ofstream ostr; - - if (root) - { - int istep = int(step); - std::string fname = path + "/tav/" + "tav" + UbSystem::toString(istep) + ".csv"; - - - ostr.open(fname.c_str(), std::ios_base::out); - if (!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if (path.size() > 0) { UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out); } - if (!ostr) throw UbException(UB_EXARGS, "couldn't open file " + fname); - } - - ostr << "z"; - - if ((options&Density) == Density) - { - ostr << ";Rho;RhoF"; - } - //mean velocity - if ((options&Velocity) == Velocity) - { - ostr << ";Vx;Vy;Vz"; - } - //fluctuations - if ((options&Fluctuations) == Fluctuations) - { - ostr << ";Vxx;Vyy;Vzz;Vxy;Vxz;Vyz"; - } - //triple-correlations - if ((options&Triplecorrelations) == Triplecorrelations) - { - ostr << ";Vxxx;Vxxy;Vxxz;Vyyy;Vyyx;Vyyz;Vzzz;Vzzx;Vzzy;Vxyz"; - } - ostr << "\n"; - } - - int size = (int)levels.size(); - int sizeOfLevelCoords = (int)levelCoords.size(); - - if (2 * size != sizeOfLevelCoords) - { - UB_THROW(UbException(UB_EXARGS, "Number of levels coordinates don't match number of levels!")); - } - - int k = 0; - - for (int i = 0; i < size; i++) - { - int level = levels[i]; - double dx = grid->getDeltaX(level); - double start = levelCoords[k]; - double stop = levelCoords[k + 1]; - - for (double j = start; j <stop; j += dx) - { - IntegrateValuesHelper intValHelp(grid, comm, - bounds[0], bounds[1], j, - bounds[3], bounds[4], j + dx, level); - - std::vector<IntegrateValuesHelper::CalcNodes> cnodes = intValHelp.getCNodes(); - //if (cnodes.size() == 0) - //{ - // continue; - //} - calculateAverageValuesForPlane(cnodes); - - if (root) - { - double numberOfFluidsNodes = intValHelp.getNumberOfFluidsNodes(); - if (numberOfFluidsNodes > 0) - { - ostr << j + 0.5*dx << std::setprecision(15); - - //mean density - if ((options&Density) == Density) - { - double rho = saRho / numberOfFluidsNodes; - double rhoF = saRhoF / numberOfFluidsNodes; - ostr << ";" << rho << ";" << rhoF; - } - - //mean velocity - if ((options&Velocity) == Velocity) - { - double Vx = saVx / numberOfFluidsNodes; - double Vy = saVy / numberOfFluidsNodes; - double Vz = saVz / numberOfFluidsNodes; - ostr << ";" << Vx << ";" << Vy << ";" << Vz; - } - //fluctuations - if ((options&Fluctuations) == Fluctuations) - { - double Vxx = saVxx / numberOfFluidsNodes; - double Vyy = saVyy / numberOfFluidsNodes; - double Vzz = saVzz / numberOfFluidsNodes; - double Vxy = saVxy / numberOfFluidsNodes; - double Vxz = saVxz / numberOfFluidsNodes; - double Vyz = saVyz / numberOfFluidsNodes; - ostr << ";" << Vxx << ";" << Vyy << ";" << Vzz << ";" << Vxy << ";" << Vxz << ";" << Vyz; - } - //triple-correlations - if ((options&Triplecorrelations) == Triplecorrelations) - { - double Vxxx = saVxxx / numberOfFluidsNodes; - double Vxxy = saVxxy / numberOfFluidsNodes; - double Vxxz = saVxxz / numberOfFluidsNodes; - double Vyyy = saVyyy / numberOfFluidsNodes; - double Vyyx = saVyyx / numberOfFluidsNodes; - double Vyyz = saVyyz / numberOfFluidsNodes; - double Vzzz = saVzzz / numberOfFluidsNodes; - double Vzzx = saVzzx / numberOfFluidsNodes; - double Vzzy = saVzzy / numberOfFluidsNodes; - double Vxyz = saVxyz / numberOfFluidsNodes; - ostr << ";" << Vxxx << ";" << Vxxy << ";" << Vxxz << ";" << Vyyy << ";" << Vyyx << ";" << Vyyz << ";" << Vzzz << ";" << Vzzx << ";" << Vzzy << ";" << Vxyz; - } - ostr << "\n"; + std::ofstream ostr; + + if (root) { + int istep = int(step); + std::string fname = path + "/tav/" + "tav" + UbSystem::toString(istep) + ".csv"; + + ostr.open(fname.c_str(), std::ios_base::out); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out); } - } - } - k += 2; - } - - if (root) - { - ostr.close(); - UBLOG(logINFO, "TimeAveragedValuesCoProcessor::planarAverage() step: " << (int)step); - } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + + ostr << "z"; + + if ((options & Density) == Density) { + ostr << ";Rho;RhoF"; + } + // mean velocity + if ((options & Velocity) == Velocity) { + ostr << ";Vx;Vy;Vz"; + } + // fluctuations + if ((options & Fluctuations) == Fluctuations) { + ostr << ";Vxx;Vyy;Vzz;Vxy;Vxz;Vyz"; + } + // triple-correlations + if ((options & Triplecorrelations) == Triplecorrelations) { + ostr << ";Vxxx;Vxxy;Vxxz;Vyyy;Vyyx;Vyyz;Vzzz;Vzzx;Vzzy;Vxyz"; + } + ostr << "\n"; + } + + int size = (int)levels.size(); + int sizeOfLevelCoords = (int)levelCoords.size(); + + if (2 * size != sizeOfLevelCoords) { + UB_THROW(UbException(UB_EXARGS, "Number of levels coordinates don't match number of levels!")); + } + + int k = 0; + + for (int i = 0; i < size; i++) { + int level = levels[i]; + double dx = grid->getDeltaX(level); + double start = levelCoords[k]; + double stop = levelCoords[k + 1]; + + for (double j = start; j < stop; j += dx) { + IntegrateValuesHelper intValHelp(grid, comm, bounds[0], bounds[1], j, bounds[3], bounds[4], j + dx, level); + + std::vector<IntegrateValuesHelper::CalcNodes> cnodes = intValHelp.getCNodes(); + // if (cnodes.size() == 0) + //{ + // continue; + //} + calculateAverageValuesForPlane(cnodes); + + if (root) { + double numberOfFluidsNodes = intValHelp.getNumberOfFluidsNodes(); + if (numberOfFluidsNodes > 0) { + ostr << j + 0.5 * dx << std::setprecision(15); + + // mean density + if ((options & Density) == Density) { + double rho = saRho / numberOfFluidsNodes; + double rhoF = saRhoF / numberOfFluidsNodes; + ostr << ";" << rho << ";" << rhoF; + } + + // mean velocity + if ((options & Velocity) == Velocity) { + double Vx = saVx / numberOfFluidsNodes; + double Vy = saVy / numberOfFluidsNodes; + double Vz = saVz / numberOfFluidsNodes; + ostr << ";" << Vx << ";" << Vy << ";" << Vz; + } + // fluctuations + if ((options & Fluctuations) == Fluctuations) { + double Vxx = saVxx / numberOfFluidsNodes; + double Vyy = saVyy / numberOfFluidsNodes; + double Vzz = saVzz / numberOfFluidsNodes; + double Vxy = saVxy / numberOfFluidsNodes; + double Vxz = saVxz / numberOfFluidsNodes; + double Vyz = saVyz / numberOfFluidsNodes; + ostr << ";" << Vxx << ";" << Vyy << ";" << Vzz << ";" << Vxy << ";" << Vxz << ";" << Vyz; + } + // triple-correlations + if ((options & Triplecorrelations) == Triplecorrelations) { + double Vxxx = saVxxx / numberOfFluidsNodes; + double Vxxy = saVxxy / numberOfFluidsNodes; + double Vxxz = saVxxz / numberOfFluidsNodes; + double Vyyy = saVyyy / numberOfFluidsNodes; + double Vyyx = saVyyx / numberOfFluidsNodes; + double Vyyz = saVyyz / numberOfFluidsNodes; + double Vzzz = saVzzz / numberOfFluidsNodes; + double Vzzx = saVzzx / numberOfFluidsNodes; + double Vzzy = saVzzy / numberOfFluidsNodes; + double Vxyz = saVxyz / numberOfFluidsNodes; + ostr << ";" << Vxxx << ";" << Vxxy << ";" << Vxxz << ";" << Vyyy << ";" << Vyyx << ";" << Vyyz + << ";" << Vzzz << ";" << Vzzx << ";" << Vzzy << ";" << Vxyz; + } + ostr << "\n"; + } + } + } + k += 2; + } + + if (root) { + ostr.close(); + UBLOG(logINFO, "TimeAveragedValuesCoProcessor::planarAverage() step: " << (int)step); + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::reset() { - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - for (SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - SPtr<AverageValuesArray3D> arho = block->getKernel()->getDataSet()->getAverageDensity(); - if (arho) - { - arho->reset(0.0); - } - - SPtr<AverageValuesArray3D> avel = block->getKernel()->getDataSet()->getAverageVelocity(); - if (avel) - { - avel->reset(0.0); - } - - SPtr<AverageValuesArray3D> afl = block->getKernel()->getDataSet()->getAverageFluctuations(); - if (afl) - { - afl->reset(0.0); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + SPtr<AverageValuesArray3D> arho = block->getKernel()->getDataSet()->getAverageDensity(); + if (arho) { + arho->reset(0.0); + } + + SPtr<AverageValuesArray3D> avel = block->getKernel()->getDataSet()->getAverageVelocity(); + if (avel) { + avel->reset(0.0); + } + + SPtr<AverageValuesArray3D> afl = block->getKernel()->getDataSet()->getAverageFluctuations(); + if (afl) { + afl->reset(0.0); + } + + SPtr<AverageValuesArray3D> atrp = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); + if (atrp) { + atrp->reset(0.0); + } } - - SPtr<AverageValuesArray3D> atrp = block->getKernel()->getDataSet()->getAverageTriplecorrelations(); - if (atrp) - { - atrp->reset(0.0); - } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void TimeAveragedValuesCoProcessor::setWithGhostLayer(bool val) { - withGhostLayer = val; - - if (withGhostLayer) - { - iMinC = 0; - } - else - { - iMinC = 1; - } + withGhostLayer = val; + + if (withGhostLayer) { + iMinC = 0; + } else { + iMinC = 1; + } } ////////////////////////////////////////////////////////////////////////// -bool TimeAveragedValuesCoProcessor::getWithGhostLayer() -{ - return withGhostLayer; -} +bool TimeAveragedValuesCoProcessor::getWithGhostLayer() { return withGhostLayer; } ////////////////////////////////////////////////////////////////////////// -void TimeAveragedValuesCoProcessor::calculateAverageValuesForPlane(std::vector<IntegrateValuesHelper::CalcNodes>& cnodes) +void TimeAveragedValuesCoProcessor::calculateAverageValuesForPlane( + std::vector<IntegrateValuesHelper::CalcNodes> &cnodes) { - saVx = 0; - saVy = 0; - saVz = 0; - - saVxx = 0; - saVyy = 0; - saVzz = 0; - saVxy = 0; - saVxz = 0; - saVyz = 0; - - saVxxx = 0; - saVxxy = 0; - saVxxz = 0; - saVyyy = 0; - saVyyx = 0; - saVyyz = 0; - saVzzz = 0; - saVzzx = 0; - saVzzy = 0; - saVxyz = 0; - - saRho = 0; - saRhoF = 0; - - double lsaVx = 0; - double lsaVy = 0; - double lsaVz = 0; - - double lsaVxx = 0; - double lsaVyy = 0; - double lsaVzz = 0; - double lsaVxy = 0; - double lsaVxz = 0; - double lsaVyz = 0; - - double lsaVxxx = 0; - double lsaVxxy = 0; - double lsaVxxz = 0; - double lsaVyyy = 0; - double lsaVyyx = 0; - double lsaVyyz = 0; - double lsaVzzz = 0; - double lsaVzzx = 0; - double lsaVzzy = 0; - double lsaVxyz = 0; - - double lsaRho = 0; - double lsaRhoF = 0; - - for (IntegrateValuesHelper::CalcNodes cn : cnodes) - { - SPtr<ILBMKernel> kernel = cn.block->getKernel(); - SPtr<AverageValuesArray3D> averagedDensity = kernel->getDataSet()->getAverageDensity(); - SPtr<AverageValuesArray3D> averagedVelocity = kernel->getDataSet()->getAverageVelocity(); - SPtr<AverageValuesArray3D> averagedFluctuations = kernel->getDataSet()->getAverageFluctuations(); - SPtr<AverageValuesArray3D> averagedTriplecorrelations = kernel->getDataSet()->getAverageTriplecorrelations(); - - for (UbTupleInt3 node : cn.nodes) - { - double aRho = (*averagedDensity)(Rho, val<1>(node), val<2>(node), val<3>(node)); - double aRhoF = (*averagedDensity)(RhoF, val<1>(node), val<2>(node), val<3>(node)); - - double aVx = (*averagedVelocity)(Vx, val<1>(node), val<2>(node), val<3>(node)); - double aVy = (*averagedVelocity)(Vy, val<1>(node), val<2>(node), val<3>(node)); - double aVz = (*averagedVelocity)(Vz, val<1>(node), val<2>(node), val<3>(node)); - - double aVxx = (*averagedFluctuations)(Vxx, val<1>(node), val<2>(node), val<3>(node)); - double aVyy = (*averagedFluctuations)(Vyy, val<1>(node), val<2>(node), val<3>(node)); - double aVzz = (*averagedFluctuations)(Vzz, val<1>(node), val<2>(node), val<3>(node)); - double aVxy = (*averagedFluctuations)(Vxy, val<1>(node), val<2>(node), val<3>(node)); - double aVxz = (*averagedFluctuations)(Vxz, val<1>(node), val<2>(node), val<3>(node)); - double aVyz = (*averagedFluctuations)(Vyz, val<1>(node), val<2>(node), val<3>(node)); - - - double aVxxx = (*averagedTriplecorrelations)(Vxxx, val<1>(node), val<2>(node), val<3>(node)); - double aVxxy = (*averagedTriplecorrelations)(Vxxy, val<1>(node), val<2>(node), val<3>(node)); - double aVxxz = (*averagedTriplecorrelations)(Vxxz, val<1>(node), val<2>(node), val<3>(node)); - double aVyyy = (*averagedTriplecorrelations)(Vyyy, val<1>(node), val<2>(node), val<3>(node)); - double aVyyx = (*averagedTriplecorrelations)(Vyyx, val<1>(node), val<2>(node), val<3>(node)); - double aVyyz = (*averagedTriplecorrelations)(Vyyz, val<1>(node), val<2>(node), val<3>(node)); - double aVzzz = (*averagedTriplecorrelations)(Vzzz, val<1>(node), val<2>(node), val<3>(node)); - double aVzzx = (*averagedTriplecorrelations)(Vzzx, val<1>(node), val<2>(node), val<3>(node)); - double aVzzy = (*averagedTriplecorrelations)(Vzzy, val<1>(node), val<2>(node), val<3>(node)); - double aVxyz = (*averagedTriplecorrelations)(Vxyz, val<1>(node), val<2>(node), val<3>(node)); - - lsaRho += aRho; - lsaRhoF += aRhoF; - - lsaVx += aVx; - lsaVy += aVy; - lsaVz += aVz; - - lsaVxx += aVxx; - lsaVyy += aVyy; - lsaVzz += aVzz; - lsaVxy += aVxy; - lsaVxz += aVxz; - lsaVyz += aVyz; - - lsaVxxx += aVxxx; - lsaVxxy += aVxxy; - lsaVxxz += aVxxz; - lsaVyyy += aVyyy; - lsaVyyx += aVyyx; - lsaVyyz += aVyyz; - lsaVzzz += aVzzz; - lsaVzzx += aVzzx; - lsaVzzy += aVzzy; - lsaVxyz += aVxyz; - } - } - std::vector<double> values; - std::vector<double> rvalues; - - values.push_back(lsaRho); - values.push_back(lsaRhoF); - - values.push_back(lsaVx); - values.push_back(lsaVy); - values.push_back(lsaVz); - - values.push_back(lsaVxx); - values.push_back(lsaVyy); - values.push_back(lsaVzz); - values.push_back(lsaVxy); - values.push_back(lsaVxz); - values.push_back(lsaVyz); - - values.push_back(lsaVxxx); - values.push_back(lsaVxxy); - values.push_back(lsaVxxz); - values.push_back(lsaVyyy); - values.push_back(lsaVyyx); - values.push_back(lsaVyyz); - values.push_back(lsaVzzz); - values.push_back(lsaVzzx); - values.push_back(lsaVzzy); - values.push_back(lsaVxyz); - - rvalues = comm->gather(values); - if (root) - { - for (int i = 0; i < (int)rvalues.size(); i += 21) - { - saRho += rvalues[i]; - saRhoF += rvalues[i + 1]; - - saVx += rvalues[i + 2]; - saVy += rvalues[i + 3]; - saVz += rvalues[i + 4]; - - saVxx += rvalues[i + 5]; - saVyy += rvalues[i + 6]; - saVzz += rvalues[i + 7]; - saVxy += rvalues[i + 8]; - saVxz += rvalues[i + 9]; - saVyz += rvalues[i + 10]; - - saVxxx += rvalues[i + 11]; - saVxxy += rvalues[i + 12]; - saVxxz += rvalues[i + 13]; - saVyyy += rvalues[i + 14]; - saVyyx += rvalues[i + 15]; - saVyyz += rvalues[i + 16]; - saVzzz += rvalues[i + 17]; - saVzzx += rvalues[i + 18]; - saVzzy += rvalues[i + 19]; - saVxyz += rvalues[i + 20]; - } - } + saVx = 0; + saVy = 0; + saVz = 0; + + saVxx = 0; + saVyy = 0; + saVzz = 0; + saVxy = 0; + saVxz = 0; + saVyz = 0; + + saVxxx = 0; + saVxxy = 0; + saVxxz = 0; + saVyyy = 0; + saVyyx = 0; + saVyyz = 0; + saVzzz = 0; + saVzzx = 0; + saVzzy = 0; + saVxyz = 0; + + saRho = 0; + saRhoF = 0; + + double lsaVx = 0; + double lsaVy = 0; + double lsaVz = 0; + + double lsaVxx = 0; + double lsaVyy = 0; + double lsaVzz = 0; + double lsaVxy = 0; + double lsaVxz = 0; + double lsaVyz = 0; + + double lsaVxxx = 0; + double lsaVxxy = 0; + double lsaVxxz = 0; + double lsaVyyy = 0; + double lsaVyyx = 0; + double lsaVyyz = 0; + double lsaVzzz = 0; + double lsaVzzx = 0; + double lsaVzzy = 0; + double lsaVxyz = 0; + + double lsaRho = 0; + double lsaRhoF = 0; + + for (IntegrateValuesHelper::CalcNodes cn : cnodes) { + SPtr<ILBMKernel> kernel = cn.block->getKernel(); + SPtr<AverageValuesArray3D> averagedDensity = kernel->getDataSet()->getAverageDensity(); + SPtr<AverageValuesArray3D> averagedVelocity = kernel->getDataSet()->getAverageVelocity(); + SPtr<AverageValuesArray3D> averagedFluctuations = kernel->getDataSet()->getAverageFluctuations(); + SPtr<AverageValuesArray3D> averagedTriplecorrelations = kernel->getDataSet()->getAverageTriplecorrelations(); + + for (UbTupleInt3 node : cn.nodes) { + double aRho = (*averagedDensity)(Rho, val<1>(node), val<2>(node), val<3>(node)); + double aRhoF = (*averagedDensity)(RhoF, val<1>(node), val<2>(node), val<3>(node)); + + double aVx = (*averagedVelocity)(Vx, val<1>(node), val<2>(node), val<3>(node)); + double aVy = (*averagedVelocity)(Vy, val<1>(node), val<2>(node), val<3>(node)); + double aVz = (*averagedVelocity)(Vz, val<1>(node), val<2>(node), val<3>(node)); + + double aVxx = (*averagedFluctuations)(Vxx, val<1>(node), val<2>(node), val<3>(node)); + double aVyy = (*averagedFluctuations)(Vyy, val<1>(node), val<2>(node), val<3>(node)); + double aVzz = (*averagedFluctuations)(Vzz, val<1>(node), val<2>(node), val<3>(node)); + double aVxy = (*averagedFluctuations)(Vxy, val<1>(node), val<2>(node), val<3>(node)); + double aVxz = (*averagedFluctuations)(Vxz, val<1>(node), val<2>(node), val<3>(node)); + double aVyz = (*averagedFluctuations)(Vyz, val<1>(node), val<2>(node), val<3>(node)); + + double aVxxx = (*averagedTriplecorrelations)(Vxxx, val<1>(node), val<2>(node), val<3>(node)); + double aVxxy = (*averagedTriplecorrelations)(Vxxy, val<1>(node), val<2>(node), val<3>(node)); + double aVxxz = (*averagedTriplecorrelations)(Vxxz, val<1>(node), val<2>(node), val<3>(node)); + double aVyyy = (*averagedTriplecorrelations)(Vyyy, val<1>(node), val<2>(node), val<3>(node)); + double aVyyx = (*averagedTriplecorrelations)(Vyyx, val<1>(node), val<2>(node), val<3>(node)); + double aVyyz = (*averagedTriplecorrelations)(Vyyz, val<1>(node), val<2>(node), val<3>(node)); + double aVzzz = (*averagedTriplecorrelations)(Vzzz, val<1>(node), val<2>(node), val<3>(node)); + double aVzzx = (*averagedTriplecorrelations)(Vzzx, val<1>(node), val<2>(node), val<3>(node)); + double aVzzy = (*averagedTriplecorrelations)(Vzzy, val<1>(node), val<2>(node), val<3>(node)); + double aVxyz = (*averagedTriplecorrelations)(Vxyz, val<1>(node), val<2>(node), val<3>(node)); + + lsaRho += aRho; + lsaRhoF += aRhoF; + + lsaVx += aVx; + lsaVy += aVy; + lsaVz += aVz; + + lsaVxx += aVxx; + lsaVyy += aVyy; + lsaVzz += aVzz; + lsaVxy += aVxy; + lsaVxz += aVxz; + lsaVyz += aVyz; + + lsaVxxx += aVxxx; + lsaVxxy += aVxxy; + lsaVxxz += aVxxz; + lsaVyyy += aVyyy; + lsaVyyx += aVyyx; + lsaVyyz += aVyyz; + lsaVzzz += aVzzz; + lsaVzzx += aVzzx; + lsaVzzy += aVzzy; + lsaVxyz += aVxyz; + } + } + std::vector<double> values; + std::vector<double> rvalues; + + values.push_back(lsaRho); + values.push_back(lsaRhoF); + + values.push_back(lsaVx); + values.push_back(lsaVy); + values.push_back(lsaVz); + + values.push_back(lsaVxx); + values.push_back(lsaVyy); + values.push_back(lsaVzz); + values.push_back(lsaVxy); + values.push_back(lsaVxz); + values.push_back(lsaVyz); + + values.push_back(lsaVxxx); + values.push_back(lsaVxxy); + values.push_back(lsaVxxz); + values.push_back(lsaVyyy); + values.push_back(lsaVyyx); + values.push_back(lsaVyyz); + values.push_back(lsaVzzz); + values.push_back(lsaVzzx); + values.push_back(lsaVzzy); + values.push_back(lsaVxyz); + + rvalues = comm->gather(values); + if (root) { + for (int i = 0; i < (int)rvalues.size(); i += 21) { + saRho += rvalues[i]; + saRhoF += rvalues[i + 1]; + + saVx += rvalues[i + 2]; + saVy += rvalues[i + 3]; + saVz += rvalues[i + 4]; + + saVxx += rvalues[i + 5]; + saVyy += rvalues[i + 6]; + saVzz += rvalues[i + 7]; + saVxy += rvalues[i + 8]; + saVxz += rvalues[i + 9]; + saVyz += rvalues[i + 10]; + + saVxxx += rvalues[i + 11]; + saVxxy += rvalues[i + 12]; + saVxxz += rvalues[i + 13]; + saVyyy += rvalues[i + 14]; + saVyyx += rvalues[i + 15]; + saVyyz += rvalues[i + 16]; + saVzzz += rvalues[i + 17]; + saVzzx += rvalues[i + 18]; + saVzzy += rvalues[i + 19]; + saVxyz += rvalues[i + 20]; + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.h index e88a859a9..70dd79f06 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeAveragedValuesCoProcessor.h @@ -6,8 +6,8 @@ #include <vector> #include "CoProcessor.h" -#include "LBMSystem.h" #include "IntegrateValuesHelper.h" +#include "LBMSystem.h" class Communicator; class Grid3D; @@ -16,108 +16,110 @@ class WbWriter; class Block3D; //! \brief Computes the time averaged mean velocity and RMS values and writes to parallel .vtk -//! \details writes at given time intervals specified in scheduler (s), does averaging according to scheduler (Avs) and resets according to scheduler (rs). <br> -//! Computes the time averaged mean velocity \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ and RMS of fluctuations. You need to calculate a square root before plotting RMS. <br> -// -//! \author Konstantin Kutscher +//! \details writes at given time intervals specified in scheduler (s), does averaging according to scheduler (Avs) and +//! resets according to scheduler (rs). <br> +//! Computes the time averaged mean velocity \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ and RMS of +//! fluctuations. You need to calculate a square root before plotting RMS. <br> +// +//! \author Konstantin Kutscher // \f$ u_{mean}=\frac{1}{N}\sum\limits_{i=1}^n u_{i} \f$ - class TimeAveragedValuesCoProcessor : public CoProcessor { public: - enum Options - { - Density = 1, - Velocity = 2, - Fluctuations = 4, - Triplecorrelations = 8, - - //Velocity = 1, - //Fluctuations = 2, - //Triplecorrelations = 4, - }; + enum Options { + Density = 1, + Velocity = 2, + Fluctuations = 4, + Triplecorrelations = 8, + + // Velocity = 1, + // Fluctuations = 2, + // Triplecorrelations = 4, + }; + public: - TimeAveragedValuesCoProcessor(); - TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm, int options); - TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm, int options, std::vector<int> levels, std::vector<double>& levelCoords, std::vector<double>& bounds, bool timeAveraging = true); - //! Make update - void process(double step) override; - //! Computes subtotal of velocity , fluctuations and triple correlations - void calculateSubtotal(double step); - void addLevelCoordinate(double c); - void reset(); - void setWithGhostLayer(bool val); - bool getWithGhostLayer(); + TimeAveragedValuesCoProcessor(); + TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<Communicator> comm, int options); + TimeAveragedValuesCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<Communicator> comm, int options, std::vector<int> levels, + std::vector<double> &levelCoords, std::vector<double> &bounds, + bool timeAveraging = true); + //! Make update + void process(double step) override; + //! Computes subtotal of velocity , fluctuations and triple correlations + void calculateSubtotal(double step); + void addLevelCoordinate(double c); + void reset(); + void setWithGhostLayer(bool val); + bool getWithGhostLayer(); protected: - //! Prepare data and write in .vtk file - void collectData(double step); - //! prepare data - void addData(const SPtr<Block3D> block); - void clearData(); - //! Computes average values of velocity , fluctuations and triple correlations - void calculateAverageValues(double timeStep); - - void init(); - void initData(); - void planarAverage(double step); - void calculateAverageValuesForPlane(std::vector<IntegrateValuesHelper::CalcNodes>& cnodes); + //! Prepare data and write in .vtk file + void collectData(double step); + //! prepare data + void addData(const SPtr<Block3D> block); + void clearData(); + //! Computes average values of velocity , fluctuations and triple correlations + void calculateAverageValues(double timeStep); + + void init(); + void initData(); + void planarAverage(double step); + void calculateAverageValuesForPlane(std::vector<IntegrateValuesHelper::CalcNodes> &cnodes); private: SPtr<Communicator> comm; - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - bool root; - int minInitLevel; //min init level - int maxInitLevel; - int gridRank; - int resetStepRMS; - int resetStepMeans; - double averageInterval; - std::string path; - WbWriter* writer; - bool restart, compressible; - SPtr<UbScheduler> averageScheduler; //additional scheduler to averaging after a given interval - SPtr<UbScheduler> resetSchedulerRMS; //additional scheduler to restart averaging after a given interval - SPtr<UbScheduler> resetSchedulerMeans; //additional scheduler to restart averaging after a given interval - //labels for the different components, e.g. AvVxx for time averaged RMS: 1/n SUM((U-Umean)^2) - //you need to calculate a square root before plotting RMS - enum Density { Rho, RhoF }; - enum Velocity { Vx, Vy, Vz }; - enum Fluctuations { Vxx, Vyy, Vzz, Vxy, Vxz, Vyz }; - enum Triplecorrelations { Vxxx, Vxxy, Vxxz, Vyyy, Vyyx, Vyyz, Vzzz, Vzzx, Vzzy, Vxyz }; - - double saRho, saRhoF; - double saVx, saVy, saVz; - double saVxx, saVyy, saVzz, saVxy, saVxz, saVyz; - double saVxxx, saVxxy, saVxxz, saVyyy, saVyyx, saVyyz, saVzzz, saVzzx, saVzzy, saVxyz; - - int options; - double numberOfSteps; - double minStep; - double maxStep; - - int iMinX1, iMinX2, iMinX3; - //int iMaxX1, iMaxX2, iMaxX3; - int iMinC; - int iMaxC; - - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; - - bool planarAveraging; - bool timeAveraging; - std::vector<double> levelCoords; - std::vector<int> levels; - std::vector<double> bounds; - - bool withGhostLayer; - + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + bool root; + int minInitLevel; // min init level + int maxInitLevel; + int gridRank; + int resetStepRMS; + int resetStepMeans; + double averageInterval; + std::string path; + WbWriter *writer; + bool restart, compressible; + SPtr<UbScheduler> averageScheduler; // additional scheduler to averaging after a given interval + SPtr<UbScheduler> resetSchedulerRMS; // additional scheduler to restart averaging after a given interval + SPtr<UbScheduler> resetSchedulerMeans; // additional scheduler to restart averaging after a given interval + // labels for the different components, e.g. AvVxx for time averaged RMS: 1/n SUM((U-Umean)^2) + // you need to calculate a square root before plotting RMS + enum Density { Rho, RhoF }; + enum Velocity { Vx, Vy, Vz }; + enum Fluctuations { Vxx, Vyy, Vzz, Vxy, Vxz, Vyz }; + enum Triplecorrelations { Vxxx, Vxxy, Vxxz, Vyyy, Vyyx, Vyyz, Vzzz, Vzzx, Vzzy, Vxyz }; + + double saRho, saRhoF; + double saVx, saVy, saVz; + double saVxx, saVyy, saVzz, saVxy, saVxz, saVyz; + double saVxxx, saVxxy, saVxxz, saVyyy, saVyyx, saVyyz, saVzzz, saVzzx, saVzzy, saVxyz; + + int options; + double numberOfSteps; + double minStep; + double maxStep; + + int iMinX1, iMinX2, iMinX3; + // int iMaxX1, iMaxX2, iMaxX3; + int iMinC; + int iMaxC; + + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; + + bool planarAveraging; + bool timeAveraging; + std::vector<double> levelCoords; + std::vector<int> levels; + std::vector<double> bounds; + + bool withGhostLayer; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.cpp index d1308a110..1540ef953 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.cpp @@ -1,32 +1,22 @@ #include "TimeDependentBCCoProcessor.h" +#include "Grid3D.h" #include "Interactor3D.h" #include "UbScheduler.h" -#include "Grid3D.h" -TimeDependentBCCoProcessor::TimeDependentBCCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s) : CoProcessor(grid, s) -{ - -} +TimeDependentBCCoProcessor::TimeDependentBCCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s) : CoProcessor(grid, s) {} ////////////////////////////////////////////////////////////////////////// -TimeDependentBCCoProcessor::~TimeDependentBCCoProcessor() -= default; +TimeDependentBCCoProcessor::~TimeDependentBCCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void TimeDependentBCCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - { - for (SPtr<Interactor3D> inter : interactors) - inter->updateInteractor(step); - UBLOG(logDEBUG3, "TimeDependentBCCoProcessor::update:" << step); - } + if (scheduler->isDue(step)) { + for (SPtr<Interactor3D> inter : interactors) + inter->updateInteractor(step); + UBLOG(logDEBUG3, "TimeDependentBCCoProcessor::update:" << step); + } } ////////////////////////////////////////////////////////////////////////// -void TimeDependentBCCoProcessor::addInteractor( SPtr<Interactor3D> interactor ) -{ - interactors.push_back(interactor); -} +void TimeDependentBCCoProcessor::addInteractor(SPtr<Interactor3D> interactor) { interactors.push_back(interactor); } ////////////////////////////////////////////////////////////////////////// - - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.h index e316a1d19..0483c9f82 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeDependentBCCoProcessor.h @@ -1,31 +1,30 @@ #ifndef TimeDependentBCCoProcessor_H #define TimeDependentBCCoProcessor_H -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "CoProcessor.h" class Interactor3D; class Grid3D; -//! \brief The class update interactors depend of time step. +//! \brief The class update interactors depend of time step. //! \details TimeDependentBCCoProcessor update every time step information in BCAdapters throw Interactors //! \author Sonja Uphoff, Kostyantyn Kucher class TimeDependentBCCoProcessor : public CoProcessor { public: - TimeDependentBCCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s); - ~TimeDependentBCCoProcessor() override; + TimeDependentBCCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s); + ~TimeDependentBCCoProcessor() override; - void process(double step) override; + void process(double step) override; - //! add interactors to CoProcessor - void addInteractor(SPtr<Interactor3D> interactor); + //! add interactors to CoProcessor + void addInteractor(SPtr<Interactor3D> interactor); private: - std::vector<SPtr<Interactor3D> > interactors; + std::vector<SPtr<Interactor3D>> interactors; }; - #endif /* TimeDependentBCCoProcessor_H */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.cpp index 8f0ff8c99..8103d6466 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.cpp @@ -1,86 +1,84 @@ /* -* TimeseriesWriterCoProcessor.h -* -* Created on: 08.05.2013 -* Author: uphoff -*/ + * TimeseriesWriterCoProcessor.h + * + * Created on: 08.05.2013 + * Author: uphoff + */ #include "TimeseriesCoProcessor.h" #include <fstream> +#include "Communicator.h" +#include "Grid3D.h" #include "IntegrateValuesHelper.h" #include "LBMUnitConverter.h" -#include "Communicator.h" #include "UbScheduler.h" -#include "Grid3D.h" - -TimeseriesCoProcessor::TimeseriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - SPtr<IntegrateValuesHelper> h1, - const std::string& path, SPtr<Communicator> comm) - : CoProcessor(grid, s), - h1(h1), - path(path), - comm(comm) +TimeseriesCoProcessor::TimeseriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<IntegrateValuesHelper> h1, + const std::string &path, SPtr<Communicator> comm) + : CoProcessor(grid, s), h1(h1), path(path), comm(comm) { - if (comm->getProcessID() == comm->getRoot()) - { - std::ofstream ostr; - //fname = path+"/timeseries/timeseries"+UbSystem::toString(grid->getTimeStep())+".csv"; - fname = path+".csv"; - UBLOG(logINFO, "TimeseriesWriterCoProcessor::fname:" << fname); - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if(!ostr) - { - ostr.clear(); - std::string file_path = UbSystem::getPathFromString(fname); - if (file_path.size()>0) { UbSystem::makeDirectory(file_path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); } - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } - ostr << "step;rho;vx;vy;vz;volume\n"; - ostr.close(); - UBLOG(logINFO, "TimeseriesWriterCoProcessor::Constructor:end"); - } + if (comm->getProcessID() == comm->getRoot()) { + std::ofstream ostr; + // fname = path+"/timeseries/timeseries"+UbSystem::toString(grid->getTimeStep())+".csv"; + fname = path + ".csv"; + UBLOG(logINFO, "TimeseriesWriterCoProcessor::fname:" << fname); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string file_path = UbSystem::getPathFromString(fname); + if (file_path.size() > 0) { + UbSystem::makeDirectory(file_path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } + ostr << "step;rho;vx;vy;vz;volume\n"; + ostr.close(); + UBLOG(logINFO, "TimeseriesWriterCoProcessor::Constructor:end"); + } } ////////////////////////////////////////////////////////////////////////// -TimeseriesCoProcessor::~TimeseriesCoProcessor() -= default; +TimeseriesCoProcessor::~TimeseriesCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void TimeseriesCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// void TimeseriesCoProcessor::collectData(double step) { - h1->calculateMQ(); + h1->calculateMQ(); - UBLOG(logDEBUG3, "TimeseriesWriterCoProcessor::update:" << step); + UBLOG(logDEBUG3, "TimeseriesWriterCoProcessor::update:" << step); - if (comm->getProcessID() == comm->getRoot()) - { - int istep = static_cast<int>(step); - std::ofstream ostr; - double cellsVolume = h1->getCellsVolume(); + if (comm->getProcessID() == comm->getRoot()) { + int istep = static_cast<int>(step); + std::ofstream ostr; + double cellsVolume = h1->getCellsVolume(); - double rho=(h1->getRho())/cellsVolume; - double vx= (h1->getVx1())/cellsVolume; - double vy= (h1->getVx2())/cellsVolume; - double vz= (h1->getVx3())/cellsVolume; - double volume = cellsVolume; + double rho = (h1->getRho()) / cellsVolume; + double vx = (h1->getVx1()) / cellsVolume; + double vy = (h1->getVx2()) / cellsVolume; + double vz = (h1->getVx3()) / cellsVolume; + double volume = cellsVolume; - ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); - if(!ostr) - { - ostr.clear(); - std::string path = UbSystem::getPathFromString(fname); - if(path.size()>0){ UbSystem::makeDirectory(path); ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app);} - if(!ostr) throw UbException(UB_EXARGS,"couldn't open file "+fname); - } + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + if (!ostr) { + ostr.clear(); + std::string path = UbSystem::getPathFromString(fname); + if (path.size() > 0) { + UbSystem::makeDirectory(path); + ostr.open(fname.c_str(), std::ios_base::out | std::ios_base::app); + } + if (!ostr) + throw UbException(UB_EXARGS, "couldn't open file " + fname); + } - ostr << istep << ";" << rho <<";" << vx << ";" << vy << ";" << vz << ";" << volume << "\n"; - ostr.close(); - } + ostr << istep << ";" << rho << ";" << vx << ";" << vy << ";" << vz << ";" << volume << "\n"; + ostr.close(); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.h index 981344167..b59a68b66 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TimeseriesCoProcessor.h @@ -26,7 +26,8 @@ class IntegrateValuesHelper; class TimeseriesCoProcessor : public CoProcessor { public: - TimeseriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<IntegrateValuesHelper> h1, const std::string& path, SPtr<Communicator> comm); + TimeseriesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<IntegrateValuesHelper> h1, + const std::string &path, SPtr<Communicator> comm); ~TimeseriesCoProcessor() override; //! calls collectData. @@ -44,5 +45,4 @@ private: std::string fname; }; - #endif /* TimeseriesCoProcessor_H */ diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.cpp index 9f1a383c2..864918f03 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.cpp @@ -1,268 +1,248 @@ #include "TurbulenceIntensityCoProcessor.h" -#include "LBMKernel.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "basics/writer/WbWriterVtkXmlASCII.h" -#include "basics/utilities/UbMath.h" +#include "Block3D.h" +#include "Communicator.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "Block3D.h" +#include "LBMKernel.h" #include "LBMUnitConverter.h" -#include "Communicator.h" #include "UbScheduler.h" -#include "BCArray3D.h" +#include "basics/utilities/UbMath.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" -TurbulenceIntensityCoProcessor::TurbulenceIntensityCoProcessor(SPtr<Grid3D> grid, const std::string& path, - WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm) - : CoProcessor(grid, s), - path(path), - comm(comm), - writer(writer) +TurbulenceIntensityCoProcessor::TurbulenceIntensityCoProcessor(SPtr<Grid3D> grid, const std::string &path, + WbWriter *const writer, SPtr<UbScheduler> s, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), comm(comm), writer(writer) { - init(); + init(); } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::init() { - gridRank = grid->getRank(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); - - blockVector.resize(maxInitLevel+1); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - - for(SPtr<Block3D> block : blockVector[level]) - { - UbTupleInt3 nx = grid->getBlockNX(); - SPtr<AverageValuesArray3D> averageValues = SPtr<AverageValuesArray3D>(new AverageValuesArray3D(val<1>(nx)+1, val<2>(nx)+1, val<3>(nx)+1, 4, 0.0)); - block->getKernel()->getDataSet()->setAverageValues(averageValues); - } - } + gridRank = grid->getRank(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); + + blockVector.resize(maxInitLevel + 1); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + + for (SPtr<Block3D> block : blockVector[level]) { + UbTupleInt3 nx = grid->getBlockNX(); + SPtr<AverageValuesArray3D> averageValues = SPtr<AverageValuesArray3D>( + new AverageValuesArray3D(val<1>(nx) + 1, val<2>(nx) + 1, val<3>(nx) + 1, 4, 0.0)); + block->getKernel()->getDataSet()->setAverageValues(averageValues); + } + } } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::process(double step) { - calculateAverageValues(int(step)); + calculateAverageValues(int(step)); - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "TurbulenceIntensityCoProcessor::update:" << step); + UBLOG(logDEBUG3, "TurbulenceIntensityCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::collectData(double step) { - int istep = int(step); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addData(block); - } - } - } - - std::string partName = writer->writeOctsWithNodeData(path+ UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep),nodes,cells,datanames,data); - size_t found=partName.find_last_of("//"); - std::string piece = partName.substr(found+1); - - std::vector<std::string> cellDataNames; - - std::vector<std::string> pieces = comm->gather(piece); - if (comm->getProcessID() == comm->getRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(path+"_"+UbSystem::toString(istep),pieces,datanames,cellDataNames); - - std::vector<std::string> filenames; - filenames.push_back(pname); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"_collection",filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path+"_collection",filenames,istep,false); - } - UBLOG(logINFO,"TurbulenceIntensityCoProcessor step: " << istep); - } - - clearData(); + int istep = int(step); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addData(block); + } + } + } + + std::string partName = writer->writeOctsWithNodeData( + path + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep), nodes, cells, datanames, data); + size_t found = partName.find_last_of("//"); + std::string piece = partName.substr(found + 1); + + std::vector<std::string> cellDataNames; + + std::vector<std::string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile( + path + "_" + UbSystem::toString(istep), pieces, datanames, cellDataNames); + + std::vector<std::string> filenames; + filenames.push_back(pname); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(path + "_collection", filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "_collection", filenames, istep, false); + } + UBLOG(logINFO, "TurbulenceIntensityCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::addData(const SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("TI"); - - data.resize(datanames.size()); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - //int ghostLayerWidth = kernel->getGhostLayerWidth(); - - //knotennummerierung faengt immer bei 0 an! - unsigned int SWB,SEB,NEB,NWB,SWT,SET,NET,NWT; - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - //nummern vergeben und node std::vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - //D3Q27BoundaryConditionPtr bcPtr; - int nr = (int)nodes.size(); - - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - int index = 0; - nodeNumbers(ix1,ix2,ix3) = nr++; - nodes.push_back( makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1*dx), - float(val<2>(org) - val<2>(nodeOffset) + ix2*dx), - float(val<3>(org) - val<3>(nodeOffset) + ix3*dx)) ); - - //compute turbulence intensity - double temp = (*av)(ix1,ix2,ix3,AvVxxyyzz)/ - ((*av)(ix1,ix2,ix3,AvVx)*(*av)(ix1,ix2,ix3,AvVx)+ - (*av)(ix1,ix2,ix3,AvVy)*(*av)(ix1,ix2,ix3,AvVy)+ - (*av)(ix1,ix2,ix3,AvVz)*(*av)(ix1,ix2,ix3,AvVz)); - - LBMReal ti = sqrt(temp); - - if (UbMath::isNaN(ti)) UB_THROW( UbException(UB_EXARGS,"TI is not a number (nan or -1.#IND), sqrt(temp), where temp = "+UbSystem::toString(temp)+", AvVx = "+UbSystem::toString((*av)(ix1,ix2,ix3,AvVx))+" AvVy = "+UbSystem::toString((*av)(ix1,ix2,ix3,AvVy))+" AvVz = "+UbSystem::toString((*av)(ix1,ix2,ix3,AvVz)))); - - data[index++].push_back(ti); + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("TI"); + + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + // int ghostLayerWidth = kernel->getGhostLayerWidth(); + + // knotennummerierung faengt immer bei 0 an! + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + // nummern vergeben und node std::vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + // D3Q27BoundaryConditionPtr bcPtr; + int nr = (int)nodes.size(); + + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + // compute turbulence intensity + double temp = + (*av)(ix1, ix2, ix3, AvVxxyyzz) / ((*av)(ix1, ix2, ix3, AvVx) * (*av)(ix1, ix2, ix3, AvVx) + + (*av)(ix1, ix2, ix3, AvVy) * (*av)(ix1, ix2, ix3, AvVy) + + (*av)(ix1, ix2, ix3, AvVz) * (*av)(ix1, ix2, ix3, AvVz)); + + LBMReal ti = sqrt(temp); + + if (UbMath::isNaN(ti)) + UB_THROW( + UbException(UB_EXARGS, "TI is not a number (nan or -1.#IND), sqrt(temp), where temp = " + + UbSystem::toString(temp) + + ", AvVx = " + UbSystem::toString((*av)(ix1, ix2, ix3, AvVx)) + + " AvVy = " + UbSystem::toString((*av)(ix1, ix2, ix3, AvVy)) + + " AvVz = " + UbSystem::toString((*av)(ix1, ix2, ix3, AvVz)))); + + data[index++].push_back(ti); + } } - } - } - } - //cell std::vector erstellen - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if( (SWB=nodeNumbers( ix1 , ix2, ix3 )) >= 0 - && (SEB=nodeNumbers( ix1+1, ix2, ix3 )) >= 0 - && (NEB=nodeNumbers( ix1+1, ix2+1, ix3 )) >= 0 - && (NWB=nodeNumbers( ix1 , ix2+1, ix3 )) >= 0 - && (SWT=nodeNumbers( ix1 , ix2, ix3+1 )) >= 0 - && (SET=nodeNumbers( ix1+1, ix2, ix3+1 )) >= 0 - && (NET=nodeNumbers( ix1+1, ix2+1, ix3+1 )) >= 0 - && (NWT=nodeNumbers( ix1 , ix2+1, ix3+1 )) >= 0 ) - { - cells.push_back( makeUbTuple(SWB,SEB,NEB,NWB,SWT,SET,NET,NWT) ); + } + } + // cell std::vector erstellen + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void TurbulenceIntensityCoProcessor::calculateAverageValues(double timeStep) { - using namespace D3Q27System; - - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - LBMReal f[27]; - LBMReal vx, vy, vz; - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = int(distributions->getNX1()); - int maxX2 = int(distributions->getNX2()); - int maxX3 = int(distributions->getNX3()); - - for(int ix3=minX3; ix3<maxX3-1; ix3++) - { - for(int ix2=minX2; ix2<maxX2-1; ix2++) - { - for(int ix1=minX1; ix1<maxX1-1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - ////////////////////////////////////////////////////////////////////////// - //read distribution - //////////////////////////////////////////////////////////////////////////// - distributions->getDistribution(f, ix1, ix2, ix3); - ////////////////////////////////////////////////////////////////////////// - //compute velocity - ////////////////////////////////////////////////////////////////////////// - vx = f[E] - f[W] + f[NE] - f[SW] + f[SE] - f[NW] + f[TE] - f[BW] - + f[BE] - f[TW] + f[TNE] - f[TSW] + f[TSE] - f[TNW] + f[BNE] - f[BSW] - + f[BSE] - f[BNW]; - - vy = f[N] - f[S] + f[NE] - f[SW] - f[SE] + f[NW] + f[TN] - f[BS] + f[BN] - - f[TS] + f[TNE] - f[TSW] - f[TSE] + f[TNW] + f[BNE] - f[BSW] - f[BSE] - + f[BNW]; - - vz = f[T] - f[B] + f[TE] - f[BW] - f[BE] + f[TW] + f[TN] - f[BS] - f[BN] - + f[TS] + f[TNE] + f[TSW] + f[TSE] + f[TNW] - f[BNE] - f[BSW] - f[BSE] - - f[BNW]; - ////////////////////////////////////////////////////////////////////////// - //compute average values - ////////////////////////////////////////////////////////////////////////// - (*av)(ix1,ix2,ix3,AvVx) = ((*av)(ix1,ix2,ix3,AvVx)*timeStep + vx)/(timeStep+1.0); - (*av)(ix1,ix2,ix3,AvVy) = ((*av)(ix1,ix2,ix3,AvVy)*timeStep + vy)/(timeStep+1.0); - (*av)(ix1,ix2,ix3,AvVz) = ((*av)(ix1,ix2,ix3,AvVz)*timeStep + vz)/(timeStep+1.0); - - (*av)(ix1,ix2,ix3,AvVxxyyzz) = ((vx-(*av)(ix1,ix2,ix3,AvVx))*(vx-(*av)(ix1,ix2,ix3,AvVx)) + - (vy-(*av)(ix1,ix2,ix3,AvVy))*(vy-(*av)(ix1,ix2,ix3,AvVy)) + - (vz-(*av)(ix1,ix2,ix3,AvVz))*(vz-(*av)(ix1,ix2,ix3,AvVz)) + - (*av)(ix1,ix2,ix3,AvVxxyyzz)*timeStep)/(timeStep+1.0); - ////////////////////////////////////////////////////////////////////////// - } - } - } + using namespace D3Q27System; + + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + LBMReal f[27]; + LBMReal vx, vy, vz; + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<AverageValuesArray3D> av = kernel->getDataSet()->getAverageValues(); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = int(distributions->getNX1()); + int maxX2 = int(distributions->getNX2()); + int maxX3 = int(distributions->getNX3()); + + for (int ix3 = minX3; ix3 < maxX3 - 1; ix3++) { + for (int ix2 = minX2; ix2 < maxX2 - 1; ix2++) { + for (int ix1 = minX1; ix1 < maxX1 - 1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + ////////////////////////////////////////////////////////////////////////// + // read distribution + //////////////////////////////////////////////////////////////////////////// + distributions->getDistribution(f, ix1, ix2, ix3); + ////////////////////////////////////////////////////////////////////////// + // compute velocity + ////////////////////////////////////////////////////////////////////////// + vx = f[E] - f[W] + f[NE] - f[SW] + f[SE] - f[NW] + f[TE] - f[BW] + f[BE] - f[TW] + + f[TNE] - f[TSW] + f[TSE] - f[TNW] + f[BNE] - f[BSW] + f[BSE] - f[BNW]; + + vy = f[N] - f[S] + f[NE] - f[SW] - f[SE] + f[NW] + f[TN] - f[BS] + f[BN] - f[TS] + + f[TNE] - f[TSW] - f[TSE] + f[TNW] + f[BNE] - f[BSW] - f[BSE] + f[BNW]; + + vz = f[T] - f[B] + f[TE] - f[BW] - f[BE] + f[TW] + f[TN] - f[BS] - f[BN] + f[TS] + + f[TNE] + f[TSW] + f[TSE] + f[TNW] - f[BNE] - f[BSW] - f[BSE] - f[BNW]; + ////////////////////////////////////////////////////////////////////////// + // compute average values + ////////////////////////////////////////////////////////////////////////// + (*av)(ix1, ix2, ix3, AvVx) = + ((*av)(ix1, ix2, ix3, AvVx) * timeStep + vx) / (timeStep + 1.0); + (*av)(ix1, ix2, ix3, AvVy) = + ((*av)(ix1, ix2, ix3, AvVy) * timeStep + vy) / (timeStep + 1.0); + (*av)(ix1, ix2, ix3, AvVz) = + ((*av)(ix1, ix2, ix3, AvVz) * timeStep + vz) / (timeStep + 1.0); + + (*av)(ix1, ix2, ix3, AvVxxyyzz) = + ((vx - (*av)(ix1, ix2, ix3, AvVx)) * (vx - (*av)(ix1, ix2, ix3, AvVx)) + + (vy - (*av)(ix1, ix2, ix3, AvVy)) * (vy - (*av)(ix1, ix2, ix3, AvVy)) + + (vz - (*av)(ix1, ix2, ix3, AvVz)) * (vz - (*av)(ix1, ix2, ix3, AvVz)) + + (*av)(ix1, ix2, ix3, AvVxxyyzz) * timeStep) / + (timeStep + 1.0); + ////////////////////////////////////////////////////////////////////////// + } + } + } + } } - } - } - } + } + } } - diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.h index fe14a4922..5c389eed8 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/TurbulenceIntensityCoProcessor.h @@ -17,27 +17,29 @@ class Block3D; class TurbulenceIntensityCoProcessor : public CoProcessor { public: - TurbulenceIntensityCoProcessor(SPtr<Grid3D> grid, const std::string& path, WbWriter* const writer, - SPtr<UbScheduler> s, SPtr<Communicator> comm); - void process(double step) override; + TurbulenceIntensityCoProcessor(SPtr<Grid3D> grid, const std::string &path, WbWriter *const writer, + SPtr<UbScheduler> s, SPtr<Communicator> comm); + void process(double step) override; + protected: - void collectData(double step); - void addData(const SPtr<Block3D> block); - void clearData(); - void calculateAverageValues(double timeStep); + void collectData(double step); + void addData(const SPtr<Block3D> block); + void clearData(); + void calculateAverageValues(double timeStep); + private: - void init(); - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - std::string path; - WbWriter* writer; - SPtr<Communicator> comm; - enum Values{AvVx = 0, AvVy = 1, AvVz = 2, AvVxxyyzz = 3}; + void init(); + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + std::string path; + WbWriter *writer; + SPtr<Communicator> comm; + enum Values { AvVx = 0, AvVy = 1, AvVz = 2, AvVxxyyzz = 3 }; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp index 077c10e32..bac7c9c34 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,152 +34,152 @@ #include "WriteBlocksCoProcessor.h" #include "basics/writer/WbWriterVtkXmlASCII.h" -#include "D3Q27System.h" #include "Block3D.h" -#include "UbScheduler.h" #include "Communicator.h" +#include "D3Q27System.h" #include "Grid3D.h" +#include "UbScheduler.h" -WriteBlocksCoProcessor::WriteBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, WbWriter* const writer, - SPtr<Communicator> comm) : - CoProcessor(grid, s), - path(path), - writer(writer), - comm(comm) +WriteBlocksCoProcessor::WriteBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm) { - } ////////////////////////////////////////////////////////////////////////// -WriteBlocksCoProcessor::~WriteBlocksCoProcessor() -= default; +WriteBlocksCoProcessor::~WriteBlocksCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void WriteBlocksCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// void WriteBlocksCoProcessor::collectData(double step) { - if (comm->getProcessID() == comm->getRoot()) - { - int istep = int(step); - std::vector<std::string> filenames; - std::vector< UbTupleFloat3 > nodes; - std::vector< UbTupleInt8 > cells; - std::vector<std::string> celldatanames; - - celldatanames.emplace_back("isActive"); - celldatanames.emplace_back("rank"); - celldatanames.emplace_back("interface"); - celldatanames.emplace_back("ID"); - celldatanames.emplace_back("part"); - celldatanames.emplace_back("level"); - //celldatanames.push_back("connectorCF"); - //celldatanames.push_back("connectorFC"); + if (comm->getProcessID() == comm->getRoot()) { + int istep = int(step); + std::vector<std::string> filenames; + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt8> cells; + std::vector<std::string> celldatanames; + + celldatanames.emplace_back("isActive"); + celldatanames.emplace_back("rank"); + celldatanames.emplace_back("interface"); + celldatanames.emplace_back("ID"); + celldatanames.emplace_back("part"); + celldatanames.emplace_back("level"); + // celldatanames.push_back("connectorCF"); + // celldatanames.push_back("connectorFC"); #if defined VF_FETOL - celldatanames.push_back("bundle"); + celldatanames.push_back("bundle"); #endif - std::vector< std::vector< double > > celldata(celldatanames.size()); - - int nr=0; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - int maxInitLevel = this->grid->getFinestInitializedLevel(); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, blockVector); - for(SPtr<Block3D> block : blockVector) - { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLength = grid->getBlockLengths(block); - - nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)), (float)(val<3>(org)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)+val<1>(blockLength)), (float)(val<2>(org)), (float)(val<3>(org)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)+val<1>(blockLength)), (float)(val<2>(org)+val<2>(blockLength)), (float)(val<3>(org)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)+val<2>(blockLength)), (float)(val<3>(org)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)), (float)(val<3>(org)+val<3>(blockLength)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)+val<1>(blockLength)), (float)(val<2>(org)), (float)(val<3>(org)+val<3>(blockLength)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)+val<1>(blockLength)), (float)(val<2>(org)+val<2>(blockLength)), (float)(val<3>(org)+val<3>(blockLength)))); - nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)+val<2>(blockLength)), (float)(val<3>(org)+val<3>(blockLength)))); - cells.push_back(makeUbTuple(nr, nr+1, nr+2, nr+3, nr+4, nr+5, nr+6, nr+7)); - nr += 8; - - //data - celldata[0].push_back((double)block->isActive()); - celldata[1].push_back((double)block->getRank()); - celldata[2].push_back((double)block->hasInterpolationFlag()); - celldata[3].push_back((double)block->getGlobalID()); - celldata[4].push_back((double)block->getPart()); - celldata[5].push_back((double)block->getLevel()); - - //bool flag = false; - //std::vector<SPtr<Block3DConnector>> connectors; - - //block->pushBackLocalInterpolationConnectorsCF(connectors); - //for (std::size_t i = 0; i<connectors.size(); i++) - // if (connectors[i]) - // { - // if (connectors[i]->getSendDir() == D3Q27System::BS) - // { - - // flag = true; - // } - // } - - //if (flag) - //{ - // celldata[6].push_back(1); - // UBLOG(logINFO, "CF: "+block->toString()); - //} - //else - //{ - // celldata[6].push_back(0); - //} - - //flag = false; - //connectors.resize(0); - //block->pushBackLocalInterpolationConnectorsFC(connectors); - //for (std::size_t i = 0; i<connectors.size(); i++) - // if (connectors[i]) - // { - // if (connectors[i]->getSendDir() == D3Q27System::BS) - // { - - // flag = true; - // } - // } - - //if (flag) - //{ - // celldata[7].push_back(1); - // UBLOG(logINFO, "FC: "+block->toString()); - //} - //else - //{ - // celldata[7].push_back(0); - //} - -#ifdef VF_FETOL - celldata[6].push_back( (double)block->getBundle()); + std::vector<std::vector<double>> celldata(celldatanames.size()); + + int nr = 0; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + int maxInitLevel = this->grid->getFinestInitializedLevel(); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, blockVector); + for (SPtr<Block3D> block : blockVector) { + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLength = grid->getBlockLengths(block); + + nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)), (float)(val<3>(org)))); + nodes.push_back(makeUbTuple((float)(val<1>(org) + val<1>(blockLength)), (float)(val<2>(org)), + (float)(val<3>(org)))); + nodes.push_back(makeUbTuple((float)(val<1>(org) + val<1>(blockLength)), + (float)(val<2>(org) + val<2>(blockLength)), (float)(val<3>(org)))); + nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org) + val<2>(blockLength)), + (float)(val<3>(org)))); + nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org)), + (float)(val<3>(org) + val<3>(blockLength)))); + nodes.push_back(makeUbTuple((float)(val<1>(org) + val<1>(blockLength)), (float)(val<2>(org)), + (float)(val<3>(org) + val<3>(blockLength)))); + nodes.push_back(makeUbTuple((float)(val<1>(org) + val<1>(blockLength)), + (float)(val<2>(org) + val<2>(blockLength)), + (float)(val<3>(org) + val<3>(blockLength)))); + nodes.push_back(makeUbTuple((float)(val<1>(org)), (float)(val<2>(org) + val<2>(blockLength)), + (float)(val<3>(org) + val<3>(blockLength)))); + cells.push_back(makeUbTuple(nr, nr + 1, nr + 2, nr + 3, nr + 4, nr + 5, nr + 6, nr + 7)); + nr += 8; + + // data + celldata[0].push_back((double)block->isActive()); + celldata[1].push_back((double)block->getRank()); + celldata[2].push_back((double)block->hasInterpolationFlag()); + celldata[3].push_back((double)block->getGlobalID()); + celldata[4].push_back((double)block->getPart()); + celldata[5].push_back((double)block->getLevel()); + + // bool flag = false; + // std::vector<SPtr<Block3DConnector>> connectors; + + // block->pushBackLocalInterpolationConnectorsCF(connectors); + // for (std::size_t i = 0; i<connectors.size(); i++) + // if (connectors[i]) + // { + // if (connectors[i]->getSendDir() == D3Q27System::BS) + // { + + // flag = true; + // } + // } + + // if (flag) + //{ + // celldata[6].push_back(1); + // UBLOG(logINFO, "CF: "+block->toString()); + //} + // else + //{ + // celldata[6].push_back(0); + //} + + // flag = false; + // connectors.resize(0); + // block->pushBackLocalInterpolationConnectorsFC(connectors); + // for (std::size_t i = 0; i<connectors.size(); i++) + // if (connectors[i]) + // { + // if (connectors[i]->getSendDir() == D3Q27System::BS) + // { + + // flag = true; + // } + // } + + // if (flag) + //{ + // celldata[7].push_back(1); + // UBLOG(logINFO, "FC: "+block->toString()); + //} + // else + //{ + // celldata[7].push_back(0); + //} + +#ifdef VF_FETOL + celldata[6].push_back((double)block->getBundle()); #endif - } - } - - filenames.push_back(writer->writeOctsWithCellData(path+"/blocks/blocks_" + UbSystem::toString(grid->getRank()) + "_" + UbSystem::toString(istep),nodes,cells,celldatanames,celldata)); - - if (istep == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(path+"/blocks/blocks_collection",filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "/blocks/blocks_collection", filenames, istep, false); - } - - UBLOG(logINFO,"WriteBlocksCoProcessor step: " << istep); - } + } + } + + filenames.push_back(writer->writeOctsWithCellData( + path + "/blocks/blocks_" + UbSystem::toString(grid->getRank()) + "_" + UbSystem::toString(istep), nodes, + cells, celldatanames, celldata)); + + if (istep == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(path + "/blocks/blocks_collection", filenames, istep, + false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(path + "/blocks/blocks_collection", filenames, + istep, false); + } + + UBLOG(logINFO, "WriteBlocksCoProcessor step: " << istep); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.h index 30beca567..b26cdeebb 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBlocksCoProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -46,30 +46,30 @@ class WbWriter; //! \class WriteBlocksCoProcessor //! \brief A class writes a block grid to a VTK-file -class WriteBlocksCoProcessor: public CoProcessor +class WriteBlocksCoProcessor : public CoProcessor { public: - //! \brief Construct WriteBlocksCoProcessor object. - //! \pre The Grid3D and UbScheduler objects must exist. - //! \param grid is observable Grid3D object - //! \param s is UbScheduler object for scheduling of observer - //! \param path is path of folder for output - //! \param writer is WbWriter object - //! \param comm is Communicator object - WriteBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm); - ~WriteBlocksCoProcessor() override; + //! \brief Construct WriteBlocksCoProcessor object. + //! \pre The Grid3D and UbScheduler objects must exist. + //! \param grid is observable Grid3D object + //! \param s is UbScheduler object for scheduling of observer + //! \param path is path of folder for output + //! \param writer is WbWriter object + //! \param comm is Communicator object + WriteBlocksCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, WbWriter *const writer, + SPtr<Communicator> comm); + ~WriteBlocksCoProcessor() override; - void process(double step) override; + void process(double step) override; protected: - //! Collect data for VTK-file - //! \param step is a time step - void collectData(double step); + //! Collect data for VTK-file + //! \param step is a time step + void collectData(double step); - std::string path; - WbWriter* writer; - SPtr<Communicator> comm; + std::string path; + WbWriter *writer; + SPtr<Communicator> comm; }; - -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp index 4902ea845..bae45335e 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,234 +32,202 @@ //======================================================================================= #include "WriteBoundaryConditionsCoProcessor.h" -#include "LBMKernel.h" #include "BCProcessor.h" -#include <vector> +#include "LBMKernel.h" #include <string> +#include <vector> -#include "basics/writer/WbWriterVtkXmlASCII.h" -#include "Grid3D.h" +#include "BCArray3D.h" #include "Block3D.h" -#include "LBMUnitConverter.h" +#include "CbArray3D.h" #include "Communicator.h" -#include "WbWriter.h" +#include "Grid3D.h" +#include "LBMUnitConverter.h" #include "UbScheduler.h" -#include "CbArray3D.h" -#include "BCArray3D.h" +#include "WbWriter.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" using namespace std; -WriteBoundaryConditionsCoProcessor::WriteBoundaryConditionsCoProcessor() -= default; +WriteBoundaryConditionsCoProcessor::WriteBoundaryConditionsCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// WriteBoundaryConditionsCoProcessor::WriteBoundaryConditionsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, WbWriter* const writer, SPtr<Communicator> comm) - : CoProcessor(grid, s), - path(path), - writer(writer), - comm(comm) + const std::string &path, WbWriter *const writer, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm) { - gridRank = comm->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = comm->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - blockVector.resize(maxInitLevel+1); + blockVector.resize(maxInitLevel + 1); - for (int level = minInitLevel; level<=maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + } } ////////////////////////////////////////////////////////////////////////// void WriteBoundaryConditionsCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "WriteBoundaryConditionsCoProcessor::update:"<<step); + UBLOG(logDEBUG3, "WriteBoundaryConditionsCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void WriteBoundaryConditionsCoProcessor::collectData(double step) { - int istep = static_cast<int>(step); - - for (int level = minInitLevel; level<=maxInitLevel; level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addDataGeo(block); - } - } - } - - string pfilePath, partPath, subfolder, cfilePath; - - subfolder = "bc"+UbSystem::toString(istep); - pfilePath = path+"/bc/"+subfolder; - cfilePath = path+"/bc/bc_collection"; - partPath = pfilePath+"/bc"+UbSystem::toString(gridRank)+"_"+UbSystem::toString(istep); - - - string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); - size_t found = partName.find_last_of("/"); - string piece = partName.substr(found+1); - piece = subfolder+"/"+piece; + int istep = static_cast<int>(step); - vector<string> cellDataNames; - vector<string> pieces = comm->gather(piece); - if (comm->getProcessID()==comm->getRoot()) - { - string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); - found = pname.find_last_of("/"); - piece = pname.substr(found+1); - - vector<string> filenames; - filenames.push_back(piece); - if (step==CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); - } - UBLOG(logINFO, "WriteBoundaryConditionsCoProcessor step: "<<istep); - } - - clearData(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addDataGeo(block); + } + } + } + + string pfilePath, partPath, subfolder, cfilePath; + + subfolder = "bc" + UbSystem::toString(istep); + pfilePath = path + "/bc/" + subfolder; + cfilePath = path + "/bc/bc_collection"; + partPath = pfilePath + "/bc" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); + + string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); + size_t found = partName.find_last_of("/"); + string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + vector<string> cellDataNames; + vector<string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); + + vector<string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "WriteBoundaryConditionsCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void WriteBoundaryConditionsCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void WriteBoundaryConditionsCoProcessor::addDataGeo(SPtr<Block3D> block) { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - double level = (double)block->getLevel(); - - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("Boundary Conditions"); - datanames.emplace_back("Geometry"); - datanames.emplace_back("Level"); - //datanames.emplace_back("Interface CF"); - - data.resize(datanames.size()); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - - //knotennummerierung faengt immer bei 0 an! - unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)bcArray->getNX1(); - int maxX2 = (int)bcArray->getNX2(); - int maxX3 = (int)bcArray->getNX3(); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); - //D3Q27BoundaryConditionPtr bcPtr; - int nr = (int)nodes.size(); - - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - for (size_t ix3 = minX3; ix3<=maxX3; ix3++) - { - for (size_t ix2 = minX2; ix2<=maxX2; ix2++) - { - for (size_t ix1 = minX1; ix1<=maxX1; ix1++) - { - if (!bcArray->isUndefined(ix1, ix2, ix3)) - { - //int index = 0; - nodeNumbers(ix1, ix2, ix3) = nr++; - nodes.push_back(makeUbTuple(float(val<1>(org)-val<1>(nodeOffset)+ix1*dx), - float(val<2>(org)-val<2>(nodeOffset)+ix2*dx), - float(val<3>(org)-val<3>(nodeOffset)+ix3*dx))); - - - - if (!bcArray->hasBC(ix1, ix2, ix3)) - { - data[0].push_back(0.0); - } - else if (bcArray->getBC(ix1, ix2, ix3)->hasNoSlipBoundary()) - data[0].push_back(1.0); - else if (bcArray->getBC(ix1, ix2, ix3)->hasVelocityBoundary()) - data[0].push_back(2.0); - else if (bcArray->getBC(ix1, ix2, ix3)->hasDensityBoundary()) - data[0].push_back(3.0); - else if (bcArray->getBC(ix1, ix2, ix3)->hasSlipBoundary()) - data[0].push_back(4.0); - //else - // data[0].push_back(5.0); - - - if (bcArray->isSolid(ix1, ix2, ix3)) - { - data[1].push_back(1.0); - } - else - { - data[1].push_back(0.0); - } - - - data[2].push_back(level); - - //if (bcArray->isInterfaceCF(ix1, ix2, ix3)) - //{ - // data[3].push_back(1.0); - //} - //else - //{ - // data[3].push_back(0.0); - //} - + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + double level = (double)block->getLevel(); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("Boundary Conditions"); + datanames.emplace_back("Geometry"); + datanames.emplace_back("Level"); + // datanames.emplace_back("Interface CF"); + + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + + // knotennummerierung faengt immer bei 0 an! + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)bcArray->getNX1(); + int maxX2 = (int)bcArray->getNX2(); + int maxX3 = (int)bcArray->getNX3(); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + // D3Q27BoundaryConditionPtr bcPtr; + int nr = (int)nodes.size(); + + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + for (size_t ix3 = minX3; ix3 <= maxX3; ix3++) { + for (size_t ix2 = minX2; ix2 <= maxX2; ix2++) { + for (size_t ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3)) { + // int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + nodes.push_back(makeUbTuple(float(val<1>(org) - val<1>(nodeOffset) + ix1 * dx), + float(val<2>(org) - val<2>(nodeOffset) + ix2 * dx), + float(val<3>(org) - val<3>(nodeOffset) + ix3 * dx))); + + if (!bcArray->hasBC(ix1, ix2, ix3)) { + data[0].push_back(0.0); + } else if (bcArray->getBC(ix1, ix2, ix3)->hasNoSlipBoundary()) + data[0].push_back(1.0); + else if (bcArray->getBC(ix1, ix2, ix3)->hasVelocityBoundary()) + data[0].push_back(2.0); + else if (bcArray->getBC(ix1, ix2, ix3)->hasDensityBoundary()) + data[0].push_back(3.0); + else if (bcArray->getBC(ix1, ix2, ix3)->hasSlipBoundary()) + data[0].push_back(4.0); + // else + // data[0].push_back(5.0); + + if (bcArray->isSolid(ix1, ix2, ix3)) { + data[1].push_back(1.0); + } else { + data[1].push_back(0.0); + } + + data[2].push_back(level); + + // if (bcArray->isInterfaceCF(ix1, ix2, ix3)) + //{ + // data[3].push_back(1.0); + //} + // else + //{ + // data[3].push_back(0.0); + //} + } } - } - } - } - - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - - //cell vector erstellen - for (int ix3 = minX3; ix3<=maxX3; ix3++) - { - for (int ix2 = minX2; ix2<=maxX2; ix2++) - { - for (int ix1 = minX1; ix1<=maxX1; ix1++) - { - if ((SWB = nodeNumbers(ix1, ix2, ix3))>=0 - &&(SEB = nodeNumbers(ix1+1, ix2, ix3))>=0 - &&(NEB = nodeNumbers(ix1+1, ix2+1, ix3))>=0 - &&(NWB = nodeNumbers(ix1, ix2+1, ix3))>=0 - &&(SWT = nodeNumbers(ix1, ix2, ix3+1))>=0 - &&(SET = nodeNumbers(ix1+1, ix2, ix3+1))>=0 - &&(NET = nodeNumbers(ix1+1, ix2+1, ix3+1))>=0 - &&(NWT = nodeNumbers(ix1, ix2+1, ix3+1))>=0) - { - cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } + } + + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } } - } - } - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.h index b89db187d..ad29abca5 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteBoundaryConditionsCoProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -49,40 +49,41 @@ class Block3D; class LBMUnitConverter; //! \brief A class writes boundary conditions information to a VTK-file -class WriteBoundaryConditionsCoProcessor : public CoProcessor +class WriteBoundaryConditionsCoProcessor : public CoProcessor { public: - WriteBoundaryConditionsCoProcessor(); - //! \brief Construct WriteBoundaryConditionsCoProcessor object - //! \pre The Grid3D and UbScheduler objects must exist - //! \param grid is observable Grid3D object - //! \param s is UbScheduler object for scheduling of observer - //! \param path is path of folder for output - //! \param writer is WbWriter object - //! \param comm is Communicator object - WriteBoundaryConditionsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm); - ~WriteBoundaryConditionsCoProcessor() override = default; + WriteBoundaryConditionsCoProcessor(); + //! \brief Construct WriteBoundaryConditionsCoProcessor object + //! \pre The Grid3D and UbScheduler objects must exist + //! \param grid is observable Grid3D object + //! \param s is UbScheduler object for scheduling of observer + //! \param path is path of folder for output + //! \param writer is WbWriter object + //! \param comm is Communicator object + WriteBoundaryConditionsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<Communicator> comm); + ~WriteBoundaryConditionsCoProcessor() override = default; - void process(double step) override; + void process(double step) override; protected: - //! Collect data for VTK-file - //! \param step is a time step - void collectData(double step); - void addDataGeo(SPtr<Block3D> block); - void clearData(); + //! Collect data for VTK-file + //! \param step is a time step + void collectData(double step); + void addDataGeo(SPtr<Block3D> block); + void clearData(); private: - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::string path; - WbWriter* writer; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - SPtr<Communicator> comm; + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::string path; + WbWriter *writer; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + SPtr<Communicator> comm; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.cpp index 0b66c1287..3c1c36a11 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.cpp @@ -1,80 +1,73 @@ #include "WriteGbObjectsCoProcessor.h" -#include "UbScheduler.h" -#include "WbWriterVtkXmlBinary.h" -#include "WbWriterVtkXmlASCII.h" #include "Communicator.h" #include "GbObject3D.h" +#include "UbScheduler.h" +#include "WbWriterVtkXmlASCII.h" +#include "WbWriterVtkXmlBinary.h" #include <vector> -WriteGbObjectsCoProcessor::WriteGbObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm) : CoProcessor(grid, s), path(path), writer(writer), comm(comm) +WriteGbObjectsCoProcessor::WriteGbObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), writer(writer), comm(comm) { } ////////////////////////////////////////////////////////////////////////// -WriteGbObjectsCoProcessor::~WriteGbObjectsCoProcessor() -= default; +WriteGbObjectsCoProcessor::~WriteGbObjectsCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// void WriteGbObjectsCoProcessor::process(double step) { - if (scheduler->isDue(step)) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); } ////////////////////////////////////////////////////////////////////////// -void WriteGbObjectsCoProcessor::addGbObject(SPtr<GbObject3D> object) -{ - objects.push_back(object); -} +void WriteGbObjectsCoProcessor::addGbObject(SPtr<GbObject3D> object) { objects.push_back(object); } ////////////////////////////////////////////////////////////////////////// void WriteGbObjectsCoProcessor::collectData(double step) { - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleInt3> triangles; - - int numObjcts = 0; + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleInt3> triangles; - for (SPtr<GbObject3D>object : objects) - { - object->addSurfaceTriangleSet(nodes, triangles); - numObjcts++; - } + int numObjcts = 0; - int istep = static_cast<int>(step); + for (SPtr<GbObject3D> object : objects) { + object->addSurfaceTriangleSet(nodes, triangles); + numObjcts++; + } - std::string pfilePath, partPath, subfolder, cfilePath; + int istep = static_cast<int>(step); - subfolder = "gob"+UbSystem::toString(istep); - pfilePath = path+"/gob/"+subfolder; - cfilePath = path+"/gob/gob_collection"; - partPath = pfilePath+"/gob"+UbSystem::toString(comm->getProcessID())+ "_" + UbSystem::toString(istep); + std::string pfilePath, partPath, subfolder, cfilePath; + subfolder = "gob" + UbSystem::toString(istep); + pfilePath = path + "/gob/" + subfolder; + cfilePath = path + "/gob/gob_collection"; + partPath = pfilePath + "/gob" + UbSystem::toString(comm->getProcessID()) + "_" + UbSystem::toString(istep); - std::string partName = writer->writeTriangles(partPath, nodes, triangles); + std::string partName = writer->writeTriangles(partPath, nodes, triangles); - size_t found=partName.find_last_of("/"); - std::string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; + size_t found = partName.find_last_of("/"); + std::string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; - std::vector<std::string> datanames; - std::vector<std::string> cellDataNames; - //std::vector<std::string> pieces = comm->gather(piece); - std::vector<std::string> pieces; - pieces.push_back(piece); - if (comm->isRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); + std::vector<std::string> datanames; + std::vector<std::string> cellDataNames; + // std::vector<std::string> pieces = comm->gather(piece); + std::vector<std::string> pieces; + pieces.push_back(piece); + if (comm->isRoot()) { + std::string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); - std::vector<std::string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); - } - UBLOG(logINFO, "WriteGbObjectsCoProcessor number of objects: " << numObjcts); - UBLOG(logINFO, "WriteGbObjectsCoProcessor step: " << istep); - } + std::vector<std::string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "WriteGbObjectsCoProcessor number of objects: " << numObjcts); + UBLOG(logINFO, "WriteGbObjectsCoProcessor step: " << istep); + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.h index 6b1c9f24a..d1e9925b5 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteGbObjectsCoProcessor.h @@ -17,22 +17,25 @@ class WbWriter; //! \author Konstantin Kutscher //! \date December 2018 -class WriteGbObjectsCoProcessor :public CoProcessor +class WriteGbObjectsCoProcessor : public CoProcessor { public: - WriteGbObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string& path, WbWriter* const writer, SPtr<Communicator> comm); - ~WriteGbObjectsCoProcessor() override; - //! calls collectData. - void process(double step) override; - //! adds geometry object - void addGbObject(SPtr<GbObject3D> object); + WriteGbObjectsCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, WbWriter *const writer, + SPtr<Communicator> comm); + ~WriteGbObjectsCoProcessor() override; + //! calls collectData. + void process(double step) override; + //! adds geometry object + void addGbObject(SPtr<GbObject3D> object); + protected: - void collectData(double step); + void collectData(double step); + private: - std::vector< SPtr<GbObject3D> > objects; - std::string path; - WbWriter* writer; - SPtr<Communicator> comm; + std::vector<SPtr<GbObject3D>> objects; + std::string path; + WbWriter *writer; + SPtr<Communicator> comm; }; #endif // WriteGbObjectsCoProcessor_h__ \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.cpp index 0f53b97a4..3d892d561 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.cpp @@ -1,235 +1,213 @@ #include "WriteMQFromSelectionCoProcessor.h" -#include "LBMKernel.h" #include "BCProcessor.h" -#include <vector> +#include "LBMKernel.h" #include <string> +#include <vector> -#include "basics/writer/WbWriterVtkXmlASCII.h" +#include "BCArray3D.h" +#include "Block3D.h" +#include "Communicator.h" #include "DataSet3D.h" -#include "UbScheduler.h" +#include "GbObject3D.h" #include "Grid3D.h" -#include "Communicator.h" #include "LBMUnitConverter.h" -#include "Block3D.h" -#include "BCArray3D.h" -#include "GbObject3D.h" +#include "UbScheduler.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" -WriteMQFromSelectionCoProcessor::WriteMQFromSelectionCoProcessor() -= default; +WriteMQFromSelectionCoProcessor::WriteMQFromSelectionCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// WriteMQFromSelectionCoProcessor::WriteMQFromSelectionCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - SPtr<GbObject3D> gbObject, - const std::string& path, WbWriter* const writer, - SPtr<LBMUnitConverter> conv, - SPtr<Communicator> comm) - : CoProcessor(grid, s), - gbObject(gbObject), - path(path), - writer(writer), - conv(conv), - comm(comm) + SPtr<GbObject3D> gbObject, const std::string &path, + WbWriter *const writer, SPtr<LBMUnitConverter> conv, + SPtr<Communicator> comm) + : CoProcessor(grid, s), gbObject(gbObject), path(path), writer(writer), conv(conv), comm(comm) { - gridRank = comm->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = comm->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - blockVector.resize(maxInitLevel+1); + blockVector.resize(maxInitLevel + 1); - for (int level = minInitLevel; level<=maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + } } ////////////////////////////////////////////////////////////////////////// -void WriteMQFromSelectionCoProcessor::init() -{ - -} +void WriteMQFromSelectionCoProcessor::init() {} ////////////////////////////////////////////////////////////////////////// void WriteMQFromSelectionCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "WriteMQFromSelectionCoProcessor::update:" << step); + UBLOG(logDEBUG3, "WriteMQFromSelectionCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void WriteMQFromSelectionCoProcessor::collectData(double step) { - int istep = static_cast<int>(step); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - - double minX1 = val<1>(org); - double minX2 = val<2>(org); - double minX3 = val<3>(org); - double maxX1 = val<1>(org)+val<1>(blockLengths); - double maxX2 = val<2>(org)+val<2>(blockLengths); - double maxX3 = val<3>(org)+val<3>(blockLengths); - - if (gbObject->isCellInsideOrCuttingGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)) - { - addDataMQ(block); + int istep = static_cast<int>(step); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + + double minX1 = val<1>(org); + double minX2 = val<2>(org); + double minX3 = val<3>(org); + double maxX1 = val<1>(org) + val<1>(blockLengths); + double maxX2 = val<2>(org) + val<2>(blockLengths); + double maxX3 = val<3>(org) + val<3>(blockLengths); + + if (gbObject->isCellInsideOrCuttingGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)) { + addDataMQ(block); + } } - } - } - } - - std::string pfilePath, partPath, subfolder, cfilePath; - - subfolder = "mqSelect"+UbSystem::toString(istep); - pfilePath = path+"/mqSelect/"+subfolder; - cfilePath = path+"/mqSelect/mq_collection"; - partPath = pfilePath+"/mqSelect"+UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep); - - - std::string partName = writer->writeNodesWithNodeData(partPath,nodes,datanames,data); - size_t found=partName.find_last_of("/"); - std::string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; - - std::vector<std::string> cellDataNames; - SPtr<Communicator> comm = Communicator::getInstance(); - std::vector<std::string> pieces = comm->gather(piece); - if (comm->getProcessID() == comm->getRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath,pieces,datanames,cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); - - std::vector<std::string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath,filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath,filenames,istep,false); - } - UBLOG(logINFO,"WriteMQFromSelectionCoProcessor step: " << istep); - } - - clearData(); + } + } + + std::string pfilePath, partPath, subfolder, cfilePath; + + subfolder = "mqSelect" + UbSystem::toString(istep); + pfilePath = path + "/mqSelect/" + subfolder; + cfilePath = path + "/mqSelect/mq_collection"; + partPath = pfilePath + "/mqSelect" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); + + std::string partName = writer->writeNodesWithNodeData(partPath, nodes, datanames, data); + size_t found = partName.find_last_of("/"); + std::string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; + + std::vector<std::string> cellDataNames; + SPtr<Communicator> comm = Communicator::getInstance(); + std::vector<std::string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + std::string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); + + std::vector<std::string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "WriteMQFromSelectionCoProcessor step: " << istep); + } + + clearData(); } ////////////////////////////////////////////////////////////////////////// void WriteMQFromSelectionCoProcessor::clearData() { - nodes.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void WriteMQFromSelectionCoProcessor::addDataMQ(SPtr<Block3D> block) { - double level = (double)block->getLevel(); -// double blockID = (double)block->getGlobalID(); - - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("Rho"); - datanames.emplace_back("Vx"); - datanames.emplace_back("Vy"); - datanames.emplace_back("Vz"); - //datanames.push_back("Press"); - datanames.emplace_back("Level"); - //datanames.push_back("BlockID"); - - - - data.resize(datanames.size()); - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - LBMReal f[D3Q27System::ENDF+1]; - LBMReal vx1,vx2,vx3,rho; - - if(block->getKernel()->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } - - int minX1 = 1; - int minX2 = 1; - int minX3 = 1; - - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); - - //int minX1 = 1; - //int minX2 = 1; - //int minX3 = 1; - - //int maxX1 = (int)(distributions->getNX1()); - //int maxX2 = (int)(distributions->getNX2()); - //int maxX3 = (int)(distributions->getNX3()); - - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; - - //D3Q27BoundaryConditionPtr bcPtr; - int nr = (int)nodes.size(); - - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - Vector3D worldCoordinates = grid->getNodeCoordinates(block, ix1, ix2, ix3); - if (gbObject->isPointInGbObject3D(worldCoordinates[0], worldCoordinates[1], worldCoordinates[2])) - { - int index = 0; - nodeNumbers(ix1, ix2, ix3) = nr++; - - nodes.emplace_back(float(worldCoordinates[0]), - float(worldCoordinates[1]), - float(worldCoordinates[2])); - - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f, rho, vx1, vx2, vx3); - - if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) - UB_THROW(UbException(UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) - UB_THROW(UbException(UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx1=999.0; - if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) - UB_THROW(UbException(UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx2=999.0; - if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) - UB_THROW(UbException(UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - - data[index++].push_back(rho); - data[index++].push_back(vx1); - data[index++].push_back(vx2); - data[index++].push_back(vx3); - data[index++].push_back(level); - } + double level = (double)block->getLevel(); + // double blockID = (double)block->getGlobalID(); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("Rho"); + datanames.emplace_back("Vx"); + datanames.emplace_back("Vy"); + datanames.emplace_back("Vz"); + // datanames.push_back("Press"); + datanames.emplace_back("Level"); + // datanames.push_back("BlockID"); + + data.resize(datanames.size()); + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; + + if (block->getKernel()->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } + + int minX1 = 1; + int minX2 = 1; + int minX3 = 1; + + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); + + // int minX1 = 1; + // int minX2 = 1; + // int minX3 = 1; + + // int maxX1 = (int)(distributions->getNX1()); + // int maxX2 = (int)(distributions->getNX2()); + // int maxX3 = (int)(distributions->getNX3()); + + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; + + // D3Q27BoundaryConditionPtr bcPtr; + int nr = (int)nodes.size(); + + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + Vector3D worldCoordinates = grid->getNodeCoordinates(block, ix1, ix2, ix3); + if (gbObject->isPointInGbObject3D(worldCoordinates[0], worldCoordinates[1], worldCoordinates[2])) { + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + + nodes.emplace_back(float(worldCoordinates[0]), float(worldCoordinates[1]), + float(worldCoordinates[2])); + + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + + if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) + UB_THROW(UbException( + UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) + UB_THROW(UbException( + UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx1=999.0; + if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) + UB_THROW(UbException( + UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx2=999.0; + if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) + UB_THROW(UbException( + UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + + data[index++].push_back(rho); + data[index++].push_back(vx1); + data[index++].push_back(vx2); + data[index++].push_back(vx3); + data[index++].push_back(level); + } + } } - } - } - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.h index a10ab7f27..0e52856cb 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMQFromSelectionCoProcessor.h @@ -10,7 +10,6 @@ #include "LBMSystem.h" #include "UbTuple.h" - class Communicator; class Grid3D; class UbScheduler; @@ -19,41 +18,40 @@ class WbWriter; class Block3D; class GbObject3D; -class WriteMQFromSelectionCoProcessor : public CoProcessor +class WriteMQFromSelectionCoProcessor : public CoProcessor { public: - WriteMQFromSelectionCoProcessor(); - WriteMQFromSelectionCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - SPtr<GbObject3D> gbObject, - const std::string& path, WbWriter* const writer, - SPtr<LBMUnitConverter> conv, SPtr<Communicator> comm); - ~WriteMQFromSelectionCoProcessor() override= default; + WriteMQFromSelectionCoProcessor(); + WriteMQFromSelectionCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, SPtr<GbObject3D> gbObject, + const std::string &path, WbWriter *const writer, SPtr<LBMUnitConverter> conv, + SPtr<Communicator> comm); + ~WriteMQFromSelectionCoProcessor() override = default; - void process(double step) override; + void process(double step) override; protected: - void collectData(double step); - void addDataMQ(SPtr<Block3D> block); - void clearData(); + void collectData(double step); + void addDataMQ(SPtr<Block3D> block); + void clearData(); private: - void init(); - std::vector<UbTupleFloat3> nodes; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::string path; - WbWriter* writer; - SPtr<LBMUnitConverter> conv; -// bool bcInformation; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - SPtr<Communicator> comm; - SPtr<GbObject3D> gbObject; - - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; + void init(); + std::vector<UbTupleFloat3> nodes; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::string path; + WbWriter *writer; + SPtr<LBMUnitConverter> conv; + // bool bcInformation; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + SPtr<Communicator> comm; + SPtr<GbObject3D> gbObject; + + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; }; #endif diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.cpp b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.cpp index d621d5515..c34dccf9f 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,257 +32,234 @@ //======================================================================================= #include "WriteMacroscopicQuantitiesCoProcessor.h" -#include "LBMKernel.h" #include "BCProcessor.h" -#include <vector> +#include "LBMKernel.h" #include <string> +#include <vector> -#include "basics/writer/WbWriterVtkXmlASCII.h" +#include "BCArray3D.h" +#include "Block3D.h" +#include "Communicator.h" #include "DataSet3D.h" -#include "UbScheduler.h" #include "Grid3D.h" -#include "Communicator.h" #include "LBMUnitConverter.h" -#include "Block3D.h" -#include "BCArray3D.h" +#include "UbScheduler.h" +#include "basics/writer/WbWriterVtkXmlASCII.h" -WriteMacroscopicQuantitiesCoProcessor::WriteMacroscopicQuantitiesCoProcessor() -= default; +WriteMacroscopicQuantitiesCoProcessor::WriteMacroscopicQuantitiesCoProcessor() = default; ////////////////////////////////////////////////////////////////////////// WriteMacroscopicQuantitiesCoProcessor::WriteMacroscopicQuantitiesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, WbWriter* const writer, - SPtr<LBMUnitConverter> conv, - SPtr<Communicator> comm) - : CoProcessor(grid, s), - path(path), - writer(writer), - conv(conv), - comm(comm) + const std::string &path, + WbWriter *const writer, + SPtr<LBMUnitConverter> conv, + SPtr<Communicator> comm) + : CoProcessor(grid, s), path(path), writer(writer), conv(conv), comm(comm) { - gridRank = comm->getProcessID(); - minInitLevel = this->grid->getCoarsestInitializedLevel(); - maxInitLevel = this->grid->getFinestInitializedLevel(); + gridRank = comm->getProcessID(); + minInitLevel = this->grid->getCoarsestInitializedLevel(); + maxInitLevel = this->grid->getFinestInitializedLevel(); - blockVector.resize(maxInitLevel+1); + blockVector.resize(maxInitLevel + 1); - for (int level = minInitLevel; level<=maxInitLevel; level++) - { - grid->getBlocks(level, gridRank, true, blockVector[level]); - } + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, gridRank, true, blockVector[level]); + } } ////////////////////////////////////////////////////////////////////////// -void WriteMacroscopicQuantitiesCoProcessor::init() -{ - -} +void WriteMacroscopicQuantitiesCoProcessor::init() {} ////////////////////////////////////////////////////////////////////////// void WriteMacroscopicQuantitiesCoProcessor::process(double step) { - if(scheduler->isDue(step) ) - collectData(step); + if (scheduler->isDue(step)) + collectData(step); - UBLOG(logDEBUG3, "WriteMacroscopicQuantitiesCoProcessor::update:" << step); + UBLOG(logDEBUG3, "WriteMacroscopicQuantitiesCoProcessor::update:" << step); } ////////////////////////////////////////////////////////////////////////// void WriteMacroscopicQuantitiesCoProcessor::collectData(double step) { - int istep = static_cast<int>(step); - - for(int level = minInitLevel; level<=maxInitLevel;level++) - { - for(SPtr<Block3D> block : blockVector[level]) - { - if (block) - { - addDataMQ(block); - } - } - } + int istep = static_cast<int>(step); - std::string pfilePath, partPath, subfolder, cfilePath; + for (int level = minInitLevel; level <= maxInitLevel; level++) { + for (SPtr<Block3D> block : blockVector[level]) { + if (block) { + addDataMQ(block); + } + } + } - subfolder = "mq"+UbSystem::toString(istep); - pfilePath = path+"/mq/"+subfolder; - cfilePath = path+"/mq/mq_collection"; - partPath = pfilePath+"/mq"+UbSystem::toString(gridRank)+ "_" + UbSystem::toString(istep); + std::string pfilePath, partPath, subfolder, cfilePath; + subfolder = "mq" + UbSystem::toString(istep); + pfilePath = path + "/mq/" + subfolder; + cfilePath = path + "/mq/mq_collection"; + partPath = pfilePath + "/mq" + UbSystem::toString(gridRank) + "_" + UbSystem::toString(istep); - std::string partName = writer->writeOctsWithNodeData(partPath,nodes,cells,datanames,data); - size_t found=partName.find_last_of("/"); - std::string piece = partName.substr(found+1); - piece = subfolder + "/" + piece; + std::string partName = writer->writeOctsWithNodeData(partPath, nodes, cells, datanames, data); + size_t found = partName.find_last_of("/"); + std::string piece = partName.substr(found + 1); + piece = subfolder + "/" + piece; - std::vector<std::string> cellDataNames; - std::vector<std::string> pieces = comm->gather(piece); - if (comm->getProcessID() == comm->getRoot()) - { - std::string pname = WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath,pieces,datanames,cellDataNames); - found=pname.find_last_of("/"); - piece = pname.substr(found+1); + std::vector<std::string> cellDataNames; + std::vector<std::string> pieces = comm->gather(piece); + if (comm->getProcessID() == comm->getRoot()) { + std::string pname = + WbWriterVtkXmlASCII::getInstance()->writeParallelFile(pfilePath, pieces, datanames, cellDataNames); + found = pname.find_last_of("/"); + piece = pname.substr(found + 1); - std::vector<std::string> filenames; - filenames.push_back(piece); - if (step == CoProcessor::scheduler->getMinBegin()) - { - WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath,filenames,istep,false); - } - else - { - WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath,filenames,istep,false); - } - UBLOG(logINFO,"WriteMacroscopicQuantitiesCoProcessor step: " << istep); - } + std::vector<std::string> filenames; + filenames.push_back(piece); + if (step == CoProcessor::scheduler->getMinBegin()) { + WbWriterVtkXmlASCII::getInstance()->writeCollection(cfilePath, filenames, istep, false); + } else { + WbWriterVtkXmlASCII::getInstance()->addFilesToCollection(cfilePath, filenames, istep, false); + } + UBLOG(logINFO, "WriteMacroscopicQuantitiesCoProcessor step: " << istep); + } - clearData(); + clearData(); } ////////////////////////////////////////////////////////////////////////// void WriteMacroscopicQuantitiesCoProcessor::clearData() { - nodes.clear(); - cells.clear(); - datanames.clear(); - data.clear(); + nodes.clear(); + cells.clear(); + datanames.clear(); + data.clear(); } ////////////////////////////////////////////////////////////////////////// void WriteMacroscopicQuantitiesCoProcessor::addDataMQ(SPtr<Block3D> block) { - double level = (double)block->getLevel(); -// double blockID = (double)block->getGlobalID(); + double level = (double)block->getLevel(); + // double blockID = (double)block->getGlobalID(); + + // Diese Daten werden geschrieben: + datanames.resize(0); + datanames.emplace_back("Rho"); + datanames.emplace_back("Vx"); + datanames.emplace_back("Vy"); + datanames.emplace_back("Vz"); + // datanames.emplace_back("Press"); + datanames.emplace_back("Level"); + // datanames.emplace_back("BlockID"); - //Diese Daten werden geschrieben: - datanames.resize(0); - datanames.emplace_back("Rho"); - datanames.emplace_back("Vx"); - datanames.emplace_back("Vy"); - datanames.emplace_back("Vz"); - //datanames.emplace_back("Press"); - datanames.emplace_back("Level"); - //datanames.emplace_back("BlockID"); + data.resize(datanames.size()); - + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal vx1, vx2, vx3, rho; - data.resize(datanames.size()); + // knotennummerierung faengt immer bei 0 an! + unsigned int SWB, SEB, NEB, NWB, SWT, SET, NET, NWT; - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - LBMReal f[D3Q27System::ENDF+1]; - LBMReal vx1,vx2,vx3,rho; + if (block->getKernel()->getCompressible()) { + calcMacros = &D3Q27System::calcCompMacroscopicValues; + } else { + calcMacros = &D3Q27System::calcIncompMacroscopicValues; + } - //knotennummerierung faengt immer bei 0 an! - unsigned int SWB,SEB,NEB,NWB,SWT,SET,NET,NWT; + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; - if(block->getKernel()->getCompressible()) - { - calcMacros = &D3Q27System::calcCompMacroscopicValues; - } - else - { - calcMacros = &D3Q27System::calcIncompMacroscopicValues; - } + int maxX1 = (int)(distributions->getNX1()); + int maxX2 = (int)(distributions->getNX2()); + int maxX3 = (int)(distributions->getNX3()); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; + // int minX1 = 1; + // int minX2 = 1; + // int minX3 = 1; - int maxX1 = (int)(distributions->getNX1()); - int maxX2 = (int)(distributions->getNX2()); - int maxX3 = (int)(distributions->getNX3()); + // int maxX1 = (int)(distributions->getNX1()); + // int maxX2 = (int)(distributions->getNX2()); + // int maxX3 = (int)(distributions->getNX3()); - //int minX1 = 1; - //int minX2 = 1; - //int minX3 = 1; + // nummern vergeben und node vector erstellen + daten sammeln + CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3, -1); + maxX1 -= 2; + maxX2 -= 2; + maxX3 -= 2; - //int maxX1 = (int)(distributions->getNX1()); - //int maxX2 = (int)(distributions->getNX2()); - //int maxX3 = (int)(distributions->getNX3()); + // D3Q27BoundaryConditionPtr bcPtr; + int nr = (int)nodes.size(); - //nummern vergeben und node vector erstellen + daten sammeln - CbArray3D<int> nodeNumbers((int)maxX1, (int)maxX2, (int)maxX3,-1); - maxX1 -= 2; - maxX2 -= 2; - maxX3 -= 2; + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (!bcArray->isUndefined(ix1, ix2, ix3) && !bcArray->isSolid(ix1, ix2, ix3)) { + int index = 0; + nodeNumbers(ix1, ix2, ix3) = nr++; + Vector3D worldCoordinates = grid->getNodeCoordinates(block, ix1, ix2, ix3); + nodes.emplace_back(float(worldCoordinates[0]), float(worldCoordinates[1]), + float(worldCoordinates[2])); - //D3Q27BoundaryConditionPtr bcPtr; - int nr = (int)nodes.size(); - - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if(!bcArray->isUndefined(ix1,ix2,ix3) && !bcArray->isSolid(ix1,ix2,ix3)) - { - int index = 0; - nodeNumbers(ix1,ix2,ix3) = nr++; - Vector3D worldCoordinates = grid->getNodeCoordinates(block, ix1, ix2, ix3); - nodes.emplace_back(float(worldCoordinates[0]), - float(worldCoordinates[1]), - float(worldCoordinates[2]) ); + distributions->getDistribution(f, ix1, ix2, ix3); + calcMacros(f, rho, vx1, vx2, vx3); + // double press = D3Q27System::calcPress(f,rho,vx1,vx2,vx3); - distributions->getDistribution(f, ix1, ix2, ix3); - calcMacros(f,rho,vx1,vx2,vx3); - //double press = D3Q27System::calcPress(f,rho,vx1,vx2,vx3); + if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) + UB_THROW(UbException( + UB_EXARGS, "rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // rho=999.0; + // if (UbMath::isNaN(press) || UbMath::isInfinity(press)) + // UB_THROW( UbException(UB_EXARGS,"press is not a number (nan or -1.#IND) or infinity number + // -1.#INF in block="+block->toString()+ + // ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); + // press=999.0; + if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) + UB_THROW(UbException( + UB_EXARGS, "vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx1=999.0; + if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) + UB_THROW(UbException( + UB_EXARGS, "vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); + // vx2=999.0; + if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) + UB_THROW(UbException( + UB_EXARGS, "vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block=" + + block->toString() + ", node=" + UbSystem::toString(ix1) + "," + + UbSystem::toString(ix2) + "," + UbSystem::toString(ix3))); - if (UbMath::isNaN(rho) || UbMath::isInfinity(rho)) - UB_THROW( UbException(UB_EXARGS,"rho is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //rho=999.0; - //if (UbMath::isNaN(press) || UbMath::isInfinity(press)) - // UB_THROW( UbException(UB_EXARGS,"press is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - // ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //press=999.0; - if (UbMath::isNaN(vx1) || UbMath::isInfinity(vx1)) - UB_THROW( UbException(UB_EXARGS,"vx1 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx1=999.0; - if (UbMath::isNaN(vx2) || UbMath::isInfinity(vx2)) - UB_THROW( UbException(UB_EXARGS,"vx2 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); - //vx2=999.0; - if (UbMath::isNaN(vx3) || UbMath::isInfinity(vx3)) - UB_THROW( UbException(UB_EXARGS,"vx3 is not a number (nan or -1.#IND) or infinity number -1.#INF in block="+block->toString()+ - ", node="+UbSystem::toString(ix1)+","+UbSystem::toString(ix2)+","+UbSystem::toString(ix3))); + data[index++].push_back(rho); + data[index++].push_back(vx1); + data[index++].push_back(vx2); + data[index++].push_back(vx3); - data[index++].push_back(rho); - data[index++].push_back(vx1); - data[index++].push_back(vx2); - data[index++].push_back(vx3); - - //data[index++].push_back(rho * conv->getFactorDensityLbToW2() ); - //data[index++].push_back(vx1 * conv->getFactorVelocityLbToW2()); - //data[index++].push_back(vx2 * conv->getFactorVelocityLbToW2()); - //data[index++].push_back(vx3 * conv->getFactorVelocityLbToW2()); - //data[index++].push_back(press * conv->getFactorPressureLbToW2()); - data[index++].push_back(level); - //data[index++].push_back(blockID); + // data[index++].push_back(rho * conv->getFactorDensityLbToW2() ); + // data[index++].push_back(vx1 * conv->getFactorVelocityLbToW2()); + // data[index++].push_back(vx2 * conv->getFactorVelocityLbToW2()); + // data[index++].push_back(vx3 * conv->getFactorVelocityLbToW2()); + // data[index++].push_back(press * conv->getFactorPressureLbToW2()); + data[index++].push_back(level); + // data[index++].push_back(blockID); + } } - } - } - } - maxX1 -= 1; - maxX2 -= 1; - maxX3 -= 1; - //cell vector erstellen - for(int ix3=minX3; ix3<=maxX3; ix3++) - { - for(int ix2=minX2; ix2<=maxX2; ix2++) - { - for(int ix1=minX1; ix1<=maxX1; ix1++) - { - if( (SWB=nodeNumbers( ix1 , ix2, ix3 )) >= 0 - && (SEB=nodeNumbers( ix1+1, ix2, ix3 )) >= 0 - && (NEB=nodeNumbers( ix1+1, ix2+1, ix3 )) >= 0 - && (NWB=nodeNumbers( ix1 , ix2+1, ix3 )) >= 0 - && (SWT=nodeNumbers( ix1 , ix2, ix3+1 )) >= 0 - && (SET=nodeNumbers( ix1+1, ix2, ix3+1 )) >= 0 - && (NET=nodeNumbers( ix1+1, ix2+1, ix3+1 )) >= 0 - && (NWT=nodeNumbers( ix1 , ix2+1, ix3+1 )) >= 0 ) - { - cells.push_back( makeUbTuple(SWB,SEB,NEB,NWB,SWT,SET,NET,NWT) ); + } + } + maxX1 -= 1; + maxX2 -= 1; + maxX3 -= 1; + // cell vector erstellen + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if ((SWB = nodeNumbers(ix1, ix2, ix3)) >= 0 && (SEB = nodeNumbers(ix1 + 1, ix2, ix3)) >= 0 && + (NEB = nodeNumbers(ix1 + 1, ix2 + 1, ix3)) >= 0 && (NWB = nodeNumbers(ix1, ix2 + 1, ix3)) >= 0 && + (SWT = nodeNumbers(ix1, ix2, ix3 + 1)) >= 0 && (SET = nodeNumbers(ix1 + 1, ix2, ix3 + 1)) >= 0 && + (NET = nodeNumbers(ix1 + 1, ix2 + 1, ix3 + 1)) >= 0 && + (NWT = nodeNumbers(ix1, ix2 + 1, ix3 + 1)) >= 0) { + cells.push_back(makeUbTuple(SWB, SEB, NEB, NWB, SWT, SET, NET, NWT)); + } } - } - } - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h index 816999a71..91df3acf3 100644 --- a/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h +++ b/src/cpu/VirtualFluidsCore/CoProcessors/WriteMacroscopicQuantitiesCoProcessor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -39,8 +39,8 @@ #include <vector> #include "CoProcessor.h" -#include "UbTuple.h" #include "LBMSystem.h" +#include "UbTuple.h" class Communicator; class Grid3D; @@ -49,53 +49,51 @@ class LBMUnitConverter; class WbWriter; class Block3D; - //! \brief A class writes macroscopic quantities information to a VTK-file -class WriteMacroscopicQuantitiesCoProcessor : public CoProcessor +class WriteMacroscopicQuantitiesCoProcessor : public CoProcessor { public: - WriteMacroscopicQuantitiesCoProcessor(); - //! \brief Construct WriteMacroscopicQuantitiesCoProcessor object - //! \pre The Grid3D and UbScheduler objects must exist - //! \param grid is observable Grid3D object - //! \param s is UbScheduler object for scheduling of observer - //! \param path is path of folder for output - //! \param writer is WbWriter object - //! \param conv is LBMUnitConverter object - //! \param comm is Communicator object - WriteMacroscopicQuantitiesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, - const std::string& path, WbWriter* const writer, - SPtr<LBMUnitConverter> conv, SPtr<Communicator> comm); - ~WriteMacroscopicQuantitiesCoProcessor() override= default; + WriteMacroscopicQuantitiesCoProcessor(); + //! \brief Construct WriteMacroscopicQuantitiesCoProcessor object + //! \pre The Grid3D and UbScheduler objects must exist + //! \param grid is observable Grid3D object + //! \param s is UbScheduler object for scheduling of observer + //! \param path is path of folder for output + //! \param writer is WbWriter object + //! \param conv is LBMUnitConverter object + //! \param comm is Communicator object + WriteMacroscopicQuantitiesCoProcessor(SPtr<Grid3D> grid, SPtr<UbScheduler> s, const std::string &path, + WbWriter *const writer, SPtr<LBMUnitConverter> conv, SPtr<Communicator> comm); + ~WriteMacroscopicQuantitiesCoProcessor() override = default; - void process(double step) override; + void process(double step) override; protected: - //! Collect data for VTK-file - //! \param step is a time step - void collectData(double step); - //! Collect data for VTK-file - //! \param block is a time step - void addDataMQ(SPtr<Block3D> block); - void clearData(); + //! Collect data for VTK-file + //! \param step is a time step + void collectData(double step); + //! Collect data for VTK-file + //! \param block is a time step + void addDataMQ(SPtr<Block3D> block); + void clearData(); private: - void init(); - std::vector<UbTupleFloat3> nodes; - std::vector<UbTupleUInt8> cells; - std::vector<std::string> datanames; - std::vector<std::vector<double> > data; - std::string path; - WbWriter* writer; - SPtr<LBMUnitConverter> conv; - std::vector<std::vector<SPtr<Block3D> > > blockVector; - int minInitLevel; - int maxInitLevel; - int gridRank; - SPtr<Communicator> comm; + void init(); + std::vector<UbTupleFloat3> nodes; + std::vector<UbTupleUInt8> cells; + std::vector<std::string> datanames; + std::vector<std::vector<double>> data; + std::string path; + WbWriter *writer; + SPtr<LBMUnitConverter> conv; + std::vector<std::vector<SPtr<Block3D>>> blockVector; + int minInitLevel; + int maxInitLevel; + int gridRank; + SPtr<Communicator> comm; - using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); - CalcMacrosFct calcMacros; + using CalcMacrosFct = void (*)(const LBMReal *const &, LBMReal &, LBMReal &, LBMReal &, LBMReal &); + CalcMacrosFct calcMacros; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnector.h index 1bef67374..1b737141a 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnector.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,67 +34,67 @@ #ifndef BLOCK2DCONNECTOR_H #define BLOCK2DCONNECTOR_H -#include <vector> #include <string> +#include <vector> #include <basics/utilities/UbTuple.h> #include <PointerDefinitions.h> -//! \brief Abstract class of connectors +//! \brief Abstract class of connectors //! \details Connector send and receive full distributions between two blocks in shared memory. class Block3DConnector { public: - Block3DConnector() = default; - Block3DConnector(const int& sendDir) : sendDir(sendDir) {} - virtual ~Block3DConnector() = default; - //!Iniitializes connector - virtual void init()=0; - //!Synchronizes the send-buffer length - virtual void sendTransmitterDataSize()=0; - //!Synchronizes the receive-buffer length - virtual void receiveTransmitterDataSize()=0; - - //Send (should be called in given order!!!) - virtual void prepareForSend()=0; - virtual void fillSendVectors()=0; - virtual void sendVectors()=0; - - //Receive (should be called in given order!!!) - virtual void prepareForReceive()=0; - virtual void receiveVectors()=0; - virtual void distributeReceiveVectors()=0; - - //info section - virtual bool isLocalConnector() = 0; - virtual bool isRemoteConnector() = 0; - virtual bool isInterpolationConnectorCF() = 0; - virtual bool isInterpolationConnectorFC() = 0; - - //grid refinement - virtual int getSendDir() const { return sendDir; } - - //virtual double getSendRecieveTime() = 0; - - virtual void prepareForSendX1() = 0; - virtual void prepareForSendX2() = 0; - virtual void prepareForSendX3() = 0; - - virtual void sendVectorsX1() = 0; - virtual void sendVectorsX2() = 0; - virtual void sendVectorsX3() = 0; - - virtual void prepareForReceiveX1() = 0; - virtual void prepareForReceiveX2() = 0; - virtual void prepareForReceiveX3() = 0; - - virtual void receiveVectorsX1() = 0; - virtual void receiveVectorsX2() = 0; - virtual void receiveVectorsX3() = 0; + Block3DConnector() = default; + Block3DConnector(const int &sendDir) : sendDir(sendDir) {} + virtual ~Block3DConnector() = default; + //! Iniitializes connector + virtual void init() = 0; + //! Synchronizes the send-buffer length + virtual void sendTransmitterDataSize() = 0; + //! Synchronizes the receive-buffer length + virtual void receiveTransmitterDataSize() = 0; + + // Send (should be called in given order!!!) + virtual void prepareForSend() = 0; + virtual void fillSendVectors() = 0; + virtual void sendVectors() = 0; + + // Receive (should be called in given order!!!) + virtual void prepareForReceive() = 0; + virtual void receiveVectors() = 0; + virtual void distributeReceiveVectors() = 0; + + // info section + virtual bool isLocalConnector() = 0; + virtual bool isRemoteConnector() = 0; + virtual bool isInterpolationConnectorCF() = 0; + virtual bool isInterpolationConnectorFC() = 0; + + // grid refinement + virtual int getSendDir() const { return sendDir; } + + // virtual double getSendRecieveTime() = 0; + + virtual void prepareForSendX1() = 0; + virtual void prepareForSendX2() = 0; + virtual void prepareForSendX3() = 0; + + virtual void sendVectorsX1() = 0; + virtual void sendVectorsX2() = 0; + virtual void sendVectorsX3() = 0; + + virtual void prepareForReceiveX1() = 0; + virtual void prepareForReceiveX2() = 0; + virtual void prepareForReceiveX3() = 0; + + virtual void receiveVectorsX1() = 0; + virtual void receiveVectorsX2() = 0; + virtual void receiveVectorsX3() = 0; protected: - int sendDir{-1}; + int sendDir{ -1 }; }; -#endif //BLOCK3DCONNECTOR_H +#endif // BLOCK3DCONNECTOR_H diff --git a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.cpp b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.cpp index af4cefa67..e30da27cd 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.cpp @@ -1,48 +1,41 @@ #include "Block3DConnectorFactory.h" +#include "CoarseToFineNodeSetBlock3DConnector.h" #include "D3Q27ETFullDirectConnector.h" #include "D3Q27ETFullVectorConnector.h" -#include "CoarseToFineNodeSetBlock3DConnector.h" #include "FineToCoarseNodeSetBlock3DConnector.h" -Block3DConnectorFactory::Block3DConnectorFactory() -= default; +Block3DConnectorFactory::Block3DConnectorFactory() = default; ////////////////////////////////////////////////////////////////////////// -Block3DConnectorFactory::~Block3DConnectorFactory() -= default; +Block3DConnectorFactory::~Block3DConnectorFactory() = default; ////////////////////////////////////////////////////////////////////////// -SPtr<Block3DConnector> Block3DConnectorFactory::createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) +SPtr<Block3DConnector> Block3DConnectorFactory::createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, + int sendDir) { - return SPtr<Block3DConnector>(new D3Q27ETFullDirectConnector(from, to, sendDir)); + return SPtr<Block3DConnector>(new D3Q27ETFullDirectConnector(from, to, sendDir)); } ////////////////////////////////////////////////////////////////////////// SPtr<Block3DConnector> Block3DConnectorFactory::createSameLevelVectorConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir) + VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, + int sendDir) { - return SPtr<Block3DConnector>(new D3Q27ETFullVectorConnector(block, sender, receiver, sendDir)); + return SPtr<Block3DConnector>(new D3Q27ETFullVectorConnector(block, sender, receiver, sendDir)); } ////////////////////////////////////////////////////////////////////////// -SPtr<Block3DConnector> Block3DConnectorFactory::createCoarseToFineConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor) +SPtr<Block3DConnector> Block3DConnectorFactory::createCoarseToFineConnector( + SPtr<Block3D> block, VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, VectorTransmitterPtr sender01, + VectorTransmitterPtr receiver01, VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, + VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, int sendDir, InterpolationProcessorPtr iprocessor) { - return SPtr<Block3DConnector> (new CoarseToFineNodeSetBlock3DConnector(block, - sender00, receiver00, sender01, receiver01, - sender10, receiver10, sender11, receiver11, - sendDir, iprocessor)); + return SPtr<Block3DConnector>(new CoarseToFineNodeSetBlock3DConnector(block, sender00, receiver00, sender01, + receiver01, sender10, receiver10, sender11, + receiver11, sendDir, iprocessor)); } ////////////////////////////////////////////////////////////////////////// -SPtr<Block3DConnector> Block3DConnectorFactory::createFineToCoarseConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir, - InterpolationProcessorPtr iprocessor, - FineToCoarseBlock3DConnector::CFconnectorType connType) +SPtr<Block3DConnector> Block3DConnectorFactory::createFineToCoarseConnector( + SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, int sendDir, + InterpolationProcessorPtr iprocessor, FineToCoarseBlock3DConnector::CFconnectorType connType) { - return SPtr<Block3DConnector>(new FineToCoarseNodeSetBlock3DConnector(block, - sender, receiver, sendDir, iprocessor, connType)); + return SPtr<Block3DConnector>( + new FineToCoarseNodeSetBlock3DConnector(block, sender, receiver, sendDir, iprocessor, connType)); } diff --git a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.h b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.h index 4e2ae44a0..687f787cd 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.h +++ b/src/cpu/VirtualFluidsCore/Connectors/Block3DConnectorFactory.h @@ -8,32 +8,26 @@ class Block3DConnectorFactory : public ConnectorFactory { public: - Block3DConnectorFactory(); - ~Block3DConnectorFactory() override; - - SPtr<Block3DConnector> createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) override; - - SPtr<Block3DConnector> createSameLevelVectorConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir) override; - - SPtr<Block3DConnector> createCoarseToFineConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor) override; - - SPtr<Block3DConnector> createFineToCoarseConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir, - InterpolationProcessorPtr iprocessor, - FineToCoarseBlock3DConnector::CFconnectorType connType) override; + Block3DConnectorFactory(); + ~Block3DConnectorFactory() override; -private: + SPtr<Block3DConnector> createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) override; + + SPtr<Block3DConnector> createSameLevelVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir) override; + + SPtr<Block3DConnector> createCoarseToFineConnector(SPtr<Block3D> block, VectorTransmitterPtr sender00, + VectorTransmitterPtr receiver00, VectorTransmitterPtr sender01, + VectorTransmitterPtr receiver01, VectorTransmitterPtr sender10, + VectorTransmitterPtr receiver10, VectorTransmitterPtr sender11, + VectorTransmitterPtr receiver11, int sendDir, + InterpolationProcessorPtr iprocessor) override; + SPtr<Block3DConnector> createFineToCoarseConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir, + InterpolationProcessorPtr iprocessor, + FineToCoarseBlock3DConnector::CFconnectorType connType) override; + +private: }; #endif // Block3DConnectorFactory_h__ - diff --git a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.cpp index dadbd0c96..d9c493e5d 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.cpp @@ -1,135 +1,138 @@ #include "CoarseToFineBlock3DConnector.h" - - //////////////////////////////////////////////////////////////////////////// -CoarseToFineBlock3DConnector::CoarseToFineBlock3DConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor) : Block3DConnector(sendDir) - , block(block) - , sender00(sender00) - , sender01(sender01) - , sender10(sender10) - , sender11(sender11) - , receiver00(receiver00) - , receiver01(receiver01) - , receiver10(receiver10) - , receiver11(receiver11) - , iprocessor(iprocessor) +CoarseToFineBlock3DConnector::CoarseToFineBlock3DConnector( + SPtr<Block3D> block, VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, VectorTransmitterPtr sender01, + VectorTransmitterPtr receiver01, VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, + VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, int sendDir, InterpolationProcessorPtr iprocessor) + : Block3DConnector(sendDir), block(block), sender00(sender00), sender01(sender01), sender10(sender10), + sender11(sender11), receiver00(receiver00), receiver01(receiver01), receiver10(receiver10), + receiver11(receiver11), iprocessor(iprocessor) { - if (!(sendDir==D3Q27System::E || sendDir==D3Q27System::W || sendDir==D3Q27System::N || sendDir==D3Q27System::S || sendDir==D3Q27System::T || sendDir==D3Q27System::B - || sendDir==D3Q27System::NE || sendDir==D3Q27System::SW || sendDir==D3Q27System::SE || sendDir==D3Q27System::NW - || sendDir==D3Q27System::TE || sendDir==D3Q27System::BW || sendDir==D3Q27System::BE || sendDir==D3Q27System::TW - || sendDir==D3Q27System::TN || sendDir==D3Q27System::BS || sendDir==D3Q27System::BN || sendDir==D3Q27System::TS - || sendDir==D3Q27System::TNE || sendDir==D3Q27System::TNW || sendDir==D3Q27System::TSE || sendDir==D3Q27System::TSW - || sendDir==D3Q27System::BNE || sendDir==D3Q27System::BNW || sendDir==D3Q27System::BSE || sendDir==D3Q27System::BSW - )) - { - throw UbException(UB_EXARGS, "invalid constructor for this direction"); - } + if (!(sendDir == D3Q27System::E || sendDir == D3Q27System::W || sendDir == D3Q27System::N || + sendDir == D3Q27System::S || sendDir == D3Q27System::T || sendDir == D3Q27System::B || + sendDir == D3Q27System::NE || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE || + sendDir == D3Q27System::NW || sendDir == D3Q27System::TE || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE || sendDir == D3Q27System::TW || sendDir == D3Q27System::TN || + sendDir == D3Q27System::BS || sendDir == D3Q27System::BN || sendDir == D3Q27System::TS || + sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSE || + sendDir == D3Q27System::TSW || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSE || sendDir == D3Q27System::BSW)) { + throw UbException(UB_EXARGS, "invalid constructor for this direction"); + } } ////////////////////////////////////////////////////////////////////////// -bool CoarseToFineBlock3DConnector::isLocalConnector() -{ - return !this->isRemoteConnector(); -} +bool CoarseToFineBlock3DConnector::isLocalConnector() { return !this->isRemoteConnector(); } ////////////////////////////////////////////////////////////////////////// bool CoarseToFineBlock3DConnector::isRemoteConnector() { - return ((sender11 && sender11->isRemoteTransmitter()) || (receiver11 && receiver11->isRemoteTransmitter()) - || (sender00 && sender00->isRemoteTransmitter()) || (receiver00 && receiver00->isRemoteTransmitter()) - || (sender01 && sender01->isRemoteTransmitter()) || (receiver01 && receiver01->isRemoteTransmitter()) - || (sender10 && sender10->isRemoteTransmitter()) || (receiver10 && receiver10->isRemoteTransmitter())); + return ((sender11 && sender11->isRemoteTransmitter()) || (receiver11 && receiver11->isRemoteTransmitter()) || + (sender00 && sender00->isRemoteTransmitter()) || (receiver00 && receiver00->isRemoteTransmitter()) || + (sender01 && sender01->isRemoteTransmitter()) || (receiver01 && receiver01->isRemoteTransmitter()) || + (sender10 && sender10->isRemoteTransmitter()) || (receiver10 && receiver10->isRemoteTransmitter())); } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::sendTransmitterDataSize() { - if (sender00) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender00 "<<block.lock()->toString()<<" sendDir="<<sendDir); - sender00->sendDataSize(); - } - if (sender01) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender01 "<<block.lock()->toString()<<"sendDir="<<sendDir); - sender01->sendDataSize(); - } - if (sender10) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender10 "<<block.lock()->toString()+"sendDir="<<sendDir); - sender10->sendDataSize(); - } - if (sender11) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender11 "<<block.lock()->toString()<<"sendDir="<<sendDir); - sender11->sendDataSize(); - } + if (sender00) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender00 " + << block.lock()->toString() << " sendDir=" << sendDir); + sender00->sendDataSize(); + } + if (sender01) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender01 " + << block.lock()->toString() << "sendDir=" << sendDir); + sender01->sendDataSize(); + } + if (sender10) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender10 " + << block.lock()->toString() + "sendDir=" << sendDir); + sender10->sendDataSize(); + } + if (sender11) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()-sender11 " + << block.lock()->toString() << "sendDir=" << sendDir); + sender11->sendDataSize(); + } } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::receiveTransmitterDataSize() { - if (receiver00) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver00 "<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver00->receiveDataSize(); - } - if (receiver01) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver01 "<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver01->receiveDataSize(); - } - if (receiver10) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver10 "<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver10->receiveDataSize(); - } - if (receiver11) - { - UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver11 "<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver11->receiveDataSize(); - } + if (receiver00) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver00 " + << block.lock()->toString() << "sendDir=" << sendDir); + receiver00->receiveDataSize(); + } + if (receiver01) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver01 " + << block.lock()->toString() << "sendDir=" << sendDir); + receiver01->receiveDataSize(); + } + if (receiver10) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver10 " + << block.lock()->toString() << "sendDir=" << sendDir); + receiver10->receiveDataSize(); + } + if (receiver11) { + UBLOG(logDEBUG5, "CoarseToFineBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiver11 " + << block.lock()->toString() << "sendDir=" << sendDir); + receiver11->receiveDataSize(); + } } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::prepareForSend() { - if (sender00) sender00->prepareForSend(); - if (sender01) sender01->prepareForSend(); - if (sender10) sender10->prepareForSend(); - if (sender11) sender11->prepareForSend(); + if (sender00) + sender00->prepareForSend(); + if (sender01) + sender01->prepareForSend(); + if (sender10) + sender10->prepareForSend(); + if (sender11) + sender11->prepareForSend(); } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::sendVectors() { - if (sender00) sender00->sendData(); - if (sender01) sender01->sendData(); - if (sender10) sender10->sendData(); - if (sender11) sender11->sendData(); + if (sender00) + sender00->sendData(); + if (sender01) + sender01->sendData(); + if (sender10) + sender10->sendData(); + if (sender11) + sender11->sendData(); } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::prepareForReceive() { - if (receiver00) receiver00->prepareForReceive(); - if (receiver01) receiver01->prepareForReceive(); - if (receiver10) receiver10->prepareForReceive(); - if (receiver11) receiver11->prepareForReceive(); + if (receiver00) + receiver00->prepareForReceive(); + if (receiver01) + receiver01->prepareForReceive(); + if (receiver10) + receiver10->prepareForReceive(); + if (receiver11) + receiver11->prepareForReceive(); } ////////////////////////////////////////////////////////////////////////// void CoarseToFineBlock3DConnector::receiveVectors() { - if (receiver00) receiver00->receiveData(); - if (receiver01) receiver01->receiveData(); - if (receiver10) receiver10->receiveData(); - if (receiver11) receiver11->receiveData(); + if (receiver00) + receiver00->receiveData(); + if (receiver01) + receiver01->receiveData(); + if (receiver10) + receiver10->receiveData(); + if (receiver11) + receiver11->receiveData(); } diff --git a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.h index 54798eaf8..6ca7c40bf 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineBlock3DConnector.h @@ -1,36 +1,35 @@ //! \file CoarseToFineBlock3DConnector.h -//! \brief Base class for connectors that interpolates and sends data from coarse level to fine. +//! \brief Base class for connectors that interpolates and sends data from coarse level to fine. //! \author Konstantin Kutscher //! \date 18.05.2015 #ifndef CoarseToFineBlock3DConnector_H #define CoarseToFineBlock3DConnector_H -#include "TransmitterType.h" +#include "Block3D.h" #include "Block3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" #include "InterpolationProcessor.h" +#include "TransmitterType.h" #include <PointerDefinitions.h> - class Block3D; //! \class CoarseToFineBlock3DConnector -//! \brief Base class for connectors that interpolates and sends data from coarse level to fine. -//! \details The data is copied in a vector (this is located in the transmitter). -//! The vector is transmitted via transmitter. -//! The transmitter can be a local, MPI, RCG, CTL or whatever +//! \brief Base class for connectors that interpolates and sends data from coarse level to fine. +//! \details The data is copied in a vector (this is located in the transmitter). +//! The vector is transmitted via transmitter. +//! The transmitter can be a local, MPI, RCG, CTL or whatever //! which a transmitter that is derived from transmitter base class. //! //! four fine blocks inside a coarse block: //! //! | | | -//! |:--:|:---| -//! | 01 | 11 | -//! | 00 | 10 | +//! |:--:|:---| +//! | 01 | 11 | +//! | 00 | 10 | //! -//! send direction: +//! send direction: //! //! |E<->W | N<->S | T<->B | //! |--------|---------|--------| @@ -38,68 +37,58 @@ class Block3D; //! | ^ | ^ | ^ | //! | +->x2 | +->x1 | +->x1| - class CoarseToFineBlock3DConnector : public Block3DConnector { public: - CoarseToFineBlock3DConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor); + CoarseToFineBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, + VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, + VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, + VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, int sendDir, + InterpolationProcessorPtr iprocessor); - ~CoarseToFineBlock3DConnector() override = default; + ~CoarseToFineBlock3DConnector() override = default; - bool isLocalConnector() override; - bool isRemoteConnector() override; + bool isLocalConnector() override; + bool isRemoteConnector() override; - void init() override =0; + void init() override = 0; - void sendTransmitterDataSize() override; - void receiveTransmitterDataSize() override; + void sendTransmitterDataSize() override; + void receiveTransmitterDataSize() override; - void prepareForSend() override; - void sendVectors() override; + void prepareForSend() override; + void sendVectors() override; - void prepareForReceive() override; - void receiveVectors() override; + void prepareForReceive() override; + void receiveVectors() override; - void fillSendVectors() override =0; - void distributeReceiveVectors() override = 0; + void fillSendVectors() override = 0; + void distributeReceiveVectors() override = 0; - bool isInterpolationConnectorCF() override { return true; } - bool isInterpolationConnectorFC() override { return false; } + bool isInterpolationConnectorCF() override { return true; } + bool isInterpolationConnectorFC() override { return false; } - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override {} - void sendVectorsX2() override {} - void sendVectorsX3() override {} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> block; //dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet - VectorTransmitterPtr sender00, receiver00, - sender01, receiver01, - sender10, receiver10, - sender11, receiver11; - - InterpolationProcessorPtr iprocessor; + WPtr<Block3D> block; // dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet + VectorTransmitterPtr sender00, receiver00, sender01, receiver01, sender10, receiver10, sender11, receiver11; + InterpolationProcessorPtr iprocessor; }; - - - -#endif - +#endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.cpp index e39ad4127..36553307d 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.cpp @@ -1,1384 +1,1293 @@ #include "CoarseToFineNodeSetBlock3DConnector.h" #include "DataSet3D.h" - //////////////////////////////////////////////////////////////////////////// -CoarseToFineNodeSetBlock3DConnector::CoarseToFineNodeSetBlock3DConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor) : CoarseToFineBlock3DConnector(block, sender00, receiver00, - sender01, receiver01, - sender10, receiver10, - sender11, receiver11, - sendDir, iprocessor) +CoarseToFineNodeSetBlock3DConnector::CoarseToFineNodeSetBlock3DConnector( + SPtr<Block3D> block, VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, VectorTransmitterPtr sender01, + VectorTransmitterPtr receiver01, VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, + VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, int sendDir, InterpolationProcessorPtr iprocessor) + : CoarseToFineBlock3DConnector(block, sender00, receiver00, sender01, receiver01, sender10, receiver10, sender11, + receiver11, sendDir, iprocessor) { } ////////////////////////////////////////////////////////////////////////// void CoarseToFineNodeSetBlock3DConnector::init() { - bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); - bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); - bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); - - minX1 = 0; - minX2 = 0; - minX3 = 0; - maxX1 = bMaxX1 - 1; - maxX2 = bMaxX2 - 1; - maxX3 = bMaxX3 - 1; - - minHalfX1 = 0; - minHalfX2 = 0; - minHalfX3 = 0; - - maxHalfX1 = 0; - maxHalfX2 = 0; - maxHalfX3 = 0; - - if (Utilities::isEven(bMaxX1)) - { - minHalfX1 = bMaxX1 / 2 - 1; - maxHalfX1 = bMaxX1 / 2 - 1; - } - else if (Utilities::isOdd(bMaxX1)) - { - minHalfX1 = bMaxX1 / 2; - maxHalfX1 = bMaxX1 / 2 - 1; - } - - if (Utilities::isEven(bMaxX2)) - { - minHalfX2 = bMaxX2 / 2 - 1; - maxHalfX2 = bMaxX2 / 2 - 1; - } - else if (Utilities::isOdd(bMaxX2)) - { - minHalfX2 = bMaxX2 / 2; - maxHalfX2 = bMaxX2 / 2 - 1; - } - - if (Utilities::isEven(bMaxX3)) - { - minHalfX3 = bMaxX3 / 2 - 1; - maxHalfX3 = bMaxX3 / 2 - 1; - } - else if (Utilities::isOdd(bMaxX3)) - { - minHalfX3 = bMaxX3 / 2; - maxHalfX3 = bMaxX3 / 2 - 1; - } - - //int sendSize = 0; - LBMReal initValue = -999.0; - - int sendDataPerNode = 27/*f*/; - int iCellSize = 8; //size of interpolation cell - - findCFCells(); - findFCCells(); - - ////////////////////////////////////////////////////// - //Debug - ////////////////////////////////////////////////////// -// if (block.lock()->getGlobalID() == 2234) -// { -// int test = 0; -// } - - if (sender00) sender00->getData().resize(iNodeSetSender00.size()*iCellSize*sendDataPerNode, initValue); - else sender00 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (sender01) sender01->getData().resize(iNodeSetSender01.size()*iCellSize*sendDataPerNode, initValue); - else sender01 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (sender10) sender10->getData().resize(iNodeSetSender10.size()*iCellSize*sendDataPerNode, initValue); - else sender10 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (sender11) sender11->getData().resize(iNodeSetSender11.size()*iCellSize*sendDataPerNode, initValue); - else sender11 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - - if (!receiver00) receiver00 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiver01) receiver01 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiver10) receiver10 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiver11) receiver11 = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); + bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); + bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); + bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); + + minX1 = 0; + minX2 = 0; + minX3 = 0; + maxX1 = bMaxX1 - 1; + maxX2 = bMaxX2 - 1; + maxX3 = bMaxX3 - 1; + + minHalfX1 = 0; + minHalfX2 = 0; + minHalfX3 = 0; + + maxHalfX1 = 0; + maxHalfX2 = 0; + maxHalfX3 = 0; + + if (Utilities::isEven(bMaxX1)) { + minHalfX1 = bMaxX1 / 2 - 1; + maxHalfX1 = bMaxX1 / 2 - 1; + } else if (Utilities::isOdd(bMaxX1)) { + minHalfX1 = bMaxX1 / 2; + maxHalfX1 = bMaxX1 / 2 - 1; + } + + if (Utilities::isEven(bMaxX2)) { + minHalfX2 = bMaxX2 / 2 - 1; + maxHalfX2 = bMaxX2 / 2 - 1; + } else if (Utilities::isOdd(bMaxX2)) { + minHalfX2 = bMaxX2 / 2; + maxHalfX2 = bMaxX2 / 2 - 1; + } + + if (Utilities::isEven(bMaxX3)) { + minHalfX3 = bMaxX3 / 2 - 1; + maxHalfX3 = bMaxX3 / 2 - 1; + } else if (Utilities::isOdd(bMaxX3)) { + minHalfX3 = bMaxX3 / 2; + maxHalfX3 = bMaxX3 / 2 - 1; + } + + // int sendSize = 0; + LBMReal initValue = -999.0; + + int sendDataPerNode = 27 /*f*/; + int iCellSize = 8; // size of interpolation cell + + findCFCells(); + findFCCells(); + + ////////////////////////////////////////////////////// + // Debug + ////////////////////////////////////////////////////// + // if (block.lock()->getGlobalID() == 2234) + // { + // int test = 0; + // } + + if (sender00) + sender00->getData().resize(iNodeSetSender00.size() * iCellSize * sendDataPerNode, initValue); + else + sender00 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (sender01) + sender01->getData().resize(iNodeSetSender01.size() * iCellSize * sendDataPerNode, initValue); + else + sender01 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (sender10) + sender10->getData().resize(iNodeSetSender10.size() * iCellSize * sendDataPerNode, initValue); + else + sender10 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (sender11) + sender11->getData().resize(iNodeSetSender11.size() * iCellSize * sendDataPerNode, initValue); + else + sender11 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + + if (!receiver00) + receiver00 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiver01) + receiver01 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiver10) + receiver10 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiver11) + receiver11 = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes) +void CoarseToFineNodeSetBlock3DConnector::findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, + int lMaxX3, INodeSet &inodes) { - int ix1, ix2, ix3; - LBMReal x1off, x2off, x3off; - - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); - - for (ix3 = lMinX3; ix3<=lMaxX3; ix3++) - { - for (ix2 = lMinX2; ix2<=lMaxX2; ix2++) - { - for (ix1 = lMinX1; ix1<=lMaxX1; ix1++) - { - D3Q27ICell icellC; - - int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); - - if (howManySolids == 0 || howManySolids == 8) - { - x1off = 0.0; - x2off = 0.0; - x3off = 0.0; - } - else - { - if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, x1off, x2off, x3off)) - { - std::string err = "For "+block.lock()->toString()+" x1="+UbSystem::toString(ix1)+", x2=" + UbSystem::toString(ix2)+", x3=" + UbSystem::toString(ix3)+ - " interpolation is not implemented for other direction"+ - " by using in: "+(std::string)typeid(*this).name()+ - " or maybe you have a solid on the block boundary"; - UB_THROW(UbException(UB_EXARGS, err)); - } + int ix1, ix2, ix3; + LBMReal x1off, x2off, x3off; + + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); + + for (ix3 = lMinX3; ix3 <= lMaxX3; ix3++) { + for (ix2 = lMinX2; ix2 <= lMaxX2; ix2++) { + for (ix1 = lMinX1; ix1 <= lMaxX1; ix1++) { + D3Q27ICell icellC; + + int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + + if (howManySolids == 0 || howManySolids == 8) { + x1off = 0.0; + x2off = 0.0; + x3off = 0.0; + } else { + if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, + x1off, x2off, x3off)) { + std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + + " interpolation is not implemented for other direction" + + " by using in: " + (std::string) typeid(*this).name() + + " or maybe you have a solid on the block boundary"; + UB_THROW(UbException(UB_EXARGS, err)); + } + } + + INodeVector inv; + inv.push_back(ix1 + (int)x1off); + inv.push_back(ix2 + (int)x2off); + inv.push_back(ix3 + (int)x3off); + inv.push_back((int)x1off); + inv.push_back((int)x2off); + inv.push_back((int)x3off); + // inodes.insert(inv); + inodes.push_back(inv); } - - INodeVector inv; - inv.push_back(ix1 + (int)x1off); - inv.push_back(ix2 + (int)x2off); - inv.push_back(ix3 + (int)x3off); - inv.push_back((int)x1off); - inv.push_back((int)x2off); - inv.push_back((int)x3off); - //inodes.insert(inv); - inodes.push_back(inv); - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -//template< typename VectorTransmitter > +// template< typename VectorTransmitter > void CoarseToFineNodeSetBlock3DConnector::findCFCells() { - using namespace D3Q27System; - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - - switch (sendDir) - { - //faces - case E: case W: - if (sendDir == E) - { - lMinX1 = maxX1 - 2; - lMaxX1 = lMinX1; - } - else if (sendDir == W) - { - lMinX1 = 1; - lMaxX1 = lMinX1; - } - - if (sender00) - { - lMinX2 = minX2; - lMaxX2 = maxHalfX2; - lMinX3 = minX3; - lMaxX3 = maxHalfX3; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX2 = minHalfX2; - lMaxX2 = maxX2 - 1; - lMinX3 = minX3; - lMaxX3 = maxHalfX3; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - if (sender01) - { - lMinX2 = minX2; - lMaxX2 = maxHalfX2; - lMinX3 = minHalfX3; - lMaxX3 = maxX3 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); - } - if (sender11) - { - lMinX2 = minHalfX2; - lMaxX2 = maxX2 - 1; - lMinX3 = minHalfX3; - lMaxX3 = maxX3 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); - } - break; - case N: case S: - if (sendDir == N) - { - lMinX2 = maxX2 - 2; - lMaxX2 = lMinX2; - } - else if (sendDir == S) - { - lMinX2 = 1; - lMaxX2 = lMinX2; - } - - if (sender00) - { - lMinX1 = minX1; - lMaxX1 = maxHalfX1; - lMinX3 = minX3; - lMaxX3 = maxHalfX3; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX1 = minHalfX1; - lMaxX1 = maxX1 - 1; - lMinX3 = minX3; - lMaxX3 = maxHalfX3; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - if (sender01) - { - lMinX1 = minX1; - lMaxX1 = maxHalfX1; - lMinX3 = minHalfX3; - lMaxX3 = maxX3 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); - } - if (sender11) - { - lMinX1 = minHalfX1; - lMaxX1 = maxX1 - 1; - lMinX3 = minHalfX3; - lMaxX3 = maxX3 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); - } - break; - case T: case B: - if (sendDir == T) - { - lMinX3 = maxX3 - 2; - lMaxX3 = lMinX3; - } - else if (sendDir == B) - { - lMinX3 = 1; - lMaxX3 = lMinX3; - } - - if (sender00) - { - lMinX1 = minX1; - lMaxX1 = maxHalfX1; - lMinX2 = minX2; - lMaxX2 = maxHalfX2; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX1 = minHalfX1; - lMaxX1 = maxX1 - 1; - lMinX2 = minX2; - lMaxX2 = maxHalfX2; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - if (sender01) - { - lMinX1 = minX1; - lMaxX1 = maxHalfX1; - lMinX2 = minHalfX2; - lMaxX2 = maxX2 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); - } - if (sender11) - { - lMinX1 = minHalfX1; - lMaxX1 = maxX1 - 1; - lMinX2 = minHalfX2; - lMaxX2 = maxX2 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); - } - break; - //edges - //N-S-E-W - case NE: case SW: case SE: case NW: - if (sendDir == NE) - { - lMinX1 = maxX1 - 2; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2 - 2; - lMaxX2 = lMinX2 + 1; - } - else if (sendDir == SW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 1; - lMinX2 = 0; - lMaxX2 = lMinX2 + 1; - } - else if (sendDir == SE) - { - lMinX1 = maxX1 - 2; - lMaxX1 = lMinX1 + 1; - lMinX2 = 0; - lMaxX2 = lMinX2 + 1; - } - else if (sendDir == NW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2 - 2; - lMaxX2 = lMinX2 + 1; - } - - if (sender00) - { - lMinX3 = minX3; - lMaxX3 = maxHalfX3; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX3 = minHalfX3; - lMaxX3 = maxX3 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - break; - //T-B-E-W - case TE: case BW: case BE: case TW: - if (sendDir == TE) - { - lMinX1 = maxX1 - 2; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3 - 2; - lMaxX3 = lMinX3 + 1; - } - else if (sendDir == BW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == BE) - { - lMinX1 = maxX1 - 2; - lMaxX1 = lMinX1 + 1; - lMinX3 = 0; - lMaxX3 = lMinX3 + 1; - } - else if (sendDir == TW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3 - 2; - lMaxX3 = lMinX3 + 1; - } - - if (sender00) - { - lMinX2 = minX2; - lMaxX2 = maxHalfX2; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX2 = minHalfX2; - lMaxX2 = maxX2 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - break; - //T-B-N-S - case TN: case BS: case BN: case TS: - if (sendDir == TN) - { - lMinX2 = maxX2 - 2; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 1; - } - else if (sendDir == BS) - { - lMinX2 = 0; - lMaxX2 = lMinX2 + 1; - lMinX3 = 0; - lMaxX3 = lMinX3 + 1; - } - else if (sendDir == BN) - { - lMinX2 = maxX2 - 2; - lMaxX2 = lMinX2 + 1; - lMinX3 = 0; - lMaxX3 = lMinX3 + 1; - } - else if (sendDir == TS) - { - lMinX2 = 0; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3 - 2; - lMaxX3 = lMinX3 + 1; - } - - if (sender00) - { - lMinX1 = minX1; - lMaxX1 = maxHalfX1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - if (sender10) - { - lMinX1 = minHalfX1; - lMaxX1 = maxX1 - 1; - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); - } - break; - //corners - case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: - if (sendDir == TNE) - { - lMinX1 = maxX1-2; - lMaxX1 = maxX1-1; - lMinX2 = maxX2-2; - lMaxX2 = maxX2-1; - lMinX3 = maxX3-2; - lMaxX3 = maxX3-1; - } - else if (sendDir == TNW) - { - lMinX1 = 0; - lMaxX1 = 1; - lMinX2 = maxX2-2; - lMaxX2 = maxX2-1; - lMinX3 = maxX3-2; - lMaxX3 = maxX3-1; - } - else if (sendDir == TSE) - { - lMinX1 = maxX1-2; - lMaxX1 = maxX1-1; - lMinX2 = 0; - lMaxX2 = 1; - lMinX3 = maxX3-2; - lMaxX3 = maxX3-1; - } - else if (sendDir == TSW) - { - lMinX1 = 0; - lMaxX1 = 1; - lMinX2 = 0; - lMaxX2 = 1; - lMinX3 = maxX3-2; - lMaxX3 = maxX3-1; - } - else if (sendDir == BNE) - { - lMinX1 = maxX1-2; - lMaxX1 = maxX1-1; - lMinX2 = maxX2-2; - lMaxX2 = maxX2-1; - lMinX3 = 0; - lMaxX3 = 1; - } - else if (sendDir == BNW) - { - lMinX1 = 0; - lMaxX1 = 1; - lMinX2 = maxX2-2; - lMaxX2 = maxX2-1; - lMinX3 = 0; - lMaxX3 = 1; - } - else if (sendDir == BSE) - { - lMinX1 = maxX1-2; - lMaxX1 = maxX1-1; - lMinX2 = 0; - lMaxX2 = 1; - lMinX3 = 0; - lMaxX3 = 1; - } - else if (sendDir == BSW) - { - lMinX1 = 0; - lMaxX1 = 1; - lMinX2 = 0; - lMaxX2 = 1; - lMinX3 = 0; - lMaxX3 = 1; - } - if (sender00) - { - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); - } - break; - } + using namespace D3Q27System; + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + + switch (sendDir) { + // faces + case E: + case W: + if (sendDir == E) { + lMinX1 = maxX1 - 2; + lMaxX1 = lMinX1; + } else if (sendDir == W) { + lMinX1 = 1; + lMaxX1 = lMinX1; + } + + if (sender00) { + lMinX2 = minX2; + lMaxX2 = maxHalfX2; + lMinX3 = minX3; + lMaxX3 = maxHalfX3; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX2 = minHalfX2; + lMaxX2 = maxX2 - 1; + lMinX3 = minX3; + lMaxX3 = maxHalfX3; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + if (sender01) { + lMinX2 = minX2; + lMaxX2 = maxHalfX2; + lMinX3 = minHalfX3; + lMaxX3 = maxX3 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); + } + if (sender11) { + lMinX2 = minHalfX2; + lMaxX2 = maxX2 - 1; + lMinX3 = minHalfX3; + lMaxX3 = maxX3 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); + } + break; + case N: + case S: + if (sendDir == N) { + lMinX2 = maxX2 - 2; + lMaxX2 = lMinX2; + } else if (sendDir == S) { + lMinX2 = 1; + lMaxX2 = lMinX2; + } + + if (sender00) { + lMinX1 = minX1; + lMaxX1 = maxHalfX1; + lMinX3 = minX3; + lMaxX3 = maxHalfX3; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX1 = minHalfX1; + lMaxX1 = maxX1 - 1; + lMinX3 = minX3; + lMaxX3 = maxHalfX3; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + if (sender01) { + lMinX1 = minX1; + lMaxX1 = maxHalfX1; + lMinX3 = minHalfX3; + lMaxX3 = maxX3 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); + } + if (sender11) { + lMinX1 = minHalfX1; + lMaxX1 = maxX1 - 1; + lMinX3 = minHalfX3; + lMaxX3 = maxX3 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); + } + break; + case T: + case B: + if (sendDir == T) { + lMinX3 = maxX3 - 2; + lMaxX3 = lMinX3; + } else if (sendDir == B) { + lMinX3 = 1; + lMaxX3 = lMinX3; + } + + if (sender00) { + lMinX1 = minX1; + lMaxX1 = maxHalfX1; + lMinX2 = minX2; + lMaxX2 = maxHalfX2; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX1 = minHalfX1; + lMaxX1 = maxX1 - 1; + lMinX2 = minX2; + lMaxX2 = maxHalfX2; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + if (sender01) { + lMinX1 = minX1; + lMaxX1 = maxHalfX1; + lMinX2 = minHalfX2; + lMaxX2 = maxX2 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender01); + } + if (sender11) { + lMinX1 = minHalfX1; + lMaxX1 = maxX1 - 1; + lMinX2 = minHalfX2; + lMaxX2 = maxX2 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender11); + } + break; + // edges + // N-S-E-W + case NE: + case SW: + case SE: + case NW: + if (sendDir == NE) { + lMinX1 = maxX1 - 2; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 2; + lMaxX2 = lMinX2 + 1; + } else if (sendDir == SW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 1; + lMinX2 = 0; + lMaxX2 = lMinX2 + 1; + } else if (sendDir == SE) { + lMinX1 = maxX1 - 2; + lMaxX1 = lMinX1 + 1; + lMinX2 = 0; + lMaxX2 = lMinX2 + 1; + } else if (sendDir == NW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 2; + lMaxX2 = lMinX2 + 1; + } + + if (sender00) { + lMinX3 = minX3; + lMaxX3 = maxHalfX3; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX3 = minHalfX3; + lMaxX3 = maxX3 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + break; + // T-B-E-W + case TE: + case BW: + case BE: + case TW: + if (sendDir == TE) { + lMinX1 = maxX1 - 2; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 2; + lMaxX3 = lMinX3 + 1; + } else if (sendDir == BW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == BE) { + lMinX1 = maxX1 - 2; + lMaxX1 = lMinX1 + 1; + lMinX3 = 0; + lMaxX3 = lMinX3 + 1; + } else if (sendDir == TW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 2; + lMaxX3 = lMinX3 + 1; + } + + if (sender00) { + lMinX2 = minX2; + lMaxX2 = maxHalfX2; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX2 = minHalfX2; + lMaxX2 = maxX2 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + break; + // T-B-N-S + case TN: + case BS: + case BN: + case TS: + if (sendDir == TN) { + lMinX2 = maxX2 - 2; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 1; + } else if (sendDir == BS) { + lMinX2 = 0; + lMaxX2 = lMinX2 + 1; + lMinX3 = 0; + lMaxX3 = lMinX3 + 1; + } else if (sendDir == BN) { + lMinX2 = maxX2 - 2; + lMaxX2 = lMinX2 + 1; + lMinX3 = 0; + lMaxX3 = lMinX3 + 1; + } else if (sendDir == TS) { + lMinX2 = 0; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 2; + lMaxX3 = lMinX3 + 1; + } + + if (sender00) { + lMinX1 = minX1; + lMaxX1 = maxHalfX1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + if (sender10) { + lMinX1 = minHalfX1; + lMaxX1 = maxX1 - 1; + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender10); + } + break; + // corners + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + if (sendDir == TNE) { + lMinX1 = maxX1 - 2; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 2; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 2; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TNW) { + lMinX1 = 0; + lMaxX1 = 1; + lMinX2 = maxX2 - 2; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 2; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TSE) { + lMinX1 = maxX1 - 2; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 1; + lMinX3 = maxX3 - 2; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TSW) { + lMinX1 = 0; + lMaxX1 = 1; + lMinX2 = 0; + lMaxX2 = 1; + lMinX3 = maxX3 - 2; + lMaxX3 = maxX3 - 1; + } else if (sendDir == BNE) { + lMinX1 = maxX1 - 2; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 2; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 1; + } else if (sendDir == BNW) { + lMinX1 = 0; + lMaxX1 = 1; + lMinX2 = maxX2 - 2; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 1; + } else if (sendDir == BSE) { + lMinX1 = maxX1 - 2; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 1; + lMinX3 = 0; + lMaxX3 = 1; + } else if (sendDir == BSW) { + lMinX1 = 0; + lMaxX1 = 1; + lMinX2 = 0; + lMaxX2 = 1; + lMinX3 = 0; + lMaxX3 = 1; + } + if (sender00) { + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetSender00); + } + break; + } } ////////////////////////////////////////////////////////////////////////// -//template< typename VectorTransmitter > +// template< typename VectorTransmitter > void CoarseToFineNodeSetBlock3DConnector::fillSendVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - - int index00 = 0; - int index01 = 0; - int index10 = 0; - int index11 = 0; - - vector_type& data00 = this->sender00->getData(); - vector_type& data01 = this->sender01->getData(); - vector_type& data10 = this->sender10->getData(); - vector_type& data11 = this->sender11->getData(); - - for(INodeVector inode : iNodeSetSender00) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); - iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); - writeICellFtoData(data00, index00, icellF); - } - for(INodeVector inode : iNodeSetSender01) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); - iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); - writeICellFtoData(data01, index01, icellF); - } - for(INodeVector inode : iNodeSetSender10) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); - iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); - writeICellFtoData(data10, index10, icellF); - } - for(INodeVector inode : iNodeSetSender11) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); - iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); - writeICellFtoData(data11, index11, icellF); - } + using namespace D3Q27System; + + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + + int index00 = 0; + int index01 = 0; + int index10 = 0; + int index11 = 0; + + vector_type &data00 = this->sender00->getData(); + vector_type &data01 = this->sender01->getData(); + vector_type &data10 = this->sender10->getData(); + vector_type &data11 = this->sender11->getData(); + + for (INodeVector inode : iNodeSetSender00) { + D3Q27ICell icellC; + D3Q27ICell icellF; + iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); + iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); + writeICellFtoData(data00, index00, icellF); + } + for (INodeVector inode : iNodeSetSender01) { + D3Q27ICell icellC; + D3Q27ICell icellF; + iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); + iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); + writeICellFtoData(data01, index01, icellF); + } + for (INodeVector inode : iNodeSetSender10) { + D3Q27ICell icellC; + D3Q27ICell icellF; + iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); + iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); + writeICellFtoData(data10, index10, icellF); + } + for (INodeVector inode : iNodeSetSender11) { + D3Q27ICell icellC; + D3Q27ICell icellF; + iprocessor->readICell(fFrom, icellC, inode[0], inode[1], inode[2]); + iprocessor->interpolateCoarseToFine(icellC, icellF, inode[3], inode[4], inode[5]); + writeICellFtoData(data11, index11, icellF); + } } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::writeICellFtoData(vector_type& data, int& index, D3Q27ICell& icellF) +void CoarseToFineNodeSetBlock3DConnector::writeICellFtoData(vector_type &data, int &index, D3Q27ICell &icellF) { - writeNodeToVector(data, index, icellF.BSW); - writeNodeToVector(data, index, icellF.BSE); - writeNodeToVector(data, index, icellF.BNW); - writeNodeToVector(data, index, icellF.BNE); - writeNodeToVector(data, index, icellF.TSW); - writeNodeToVector(data, index, icellF.TSE); - writeNodeToVector(data, index, icellF.TNW); - writeNodeToVector(data, index, icellF.TNE); + writeNodeToVector(data, index, icellF.BSW); + writeNodeToVector(data, index, icellF.BSE); + writeNodeToVector(data, index, icellF.BNW); + writeNodeToVector(data, index, icellF.BNE); + writeNodeToVector(data, index, icellF.TSW); + writeNodeToVector(data, index, icellF.TSE); + writeNodeToVector(data, index, icellF.TNW); + writeNodeToVector(data, index, icellF.TNE); } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::writeNodeToVector(vector_type& data, int& index, LBMReal* inode) +void CoarseToFineNodeSetBlock3DConnector::writeNodeToVector(vector_type &data, int &index, LBMReal *inode) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - data[index++] = inode[i]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + data[index++] = inode[i]; + } } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes) +void CoarseToFineNodeSetBlock3DConnector::findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, + int lMaxX3, INodeSet &inodes) { - int ix1, ix2, ix3; - - for (ix3 = lMinX3; ix3<=lMaxX3; ix3++) - { - for (ix2 = lMinX2; ix2<=lMaxX2; ix2++) - { - for (ix1 = lMinX1; ix1<=lMaxX1; ix1++) - { - INodeVector inv; - inv.push_back(ix1); - inv.push_back(ix2); - inv.push_back(ix3); - //inodes.insert(inv); - inodes.push_back(inv); - } - } - } + int ix1, ix2, ix3; + + for (ix3 = lMinX3; ix3 <= lMaxX3; ix3++) { + for (ix2 = lMinX2; ix2 <= lMaxX2; ix2++) { + for (ix1 = lMinX1; ix1 <= lMaxX1; ix1++) { + INodeVector inv; + inv.push_back(ix1); + inv.push_back(ix2); + inv.push_back(ix3); + // inodes.insert(inv); + inodes.push_back(inv); + } + } + } } ////////////////////////////////////////////////////////////////////////// -//template< typename VectorTransmitter > +// template< typename VectorTransmitter > void CoarseToFineNodeSetBlock3DConnector::findFCCells() { - using namespace D3Q27System; - - int lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3; - int lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3; - int lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3; - int dummy; - - switch (sendDir) - { - - ////////////////////////////////////////////////////// - //Debug - ////////////////////////////////////////////////////// - // if (block.lock()->getGlobalID() == 2234) - // { - // int test = 0; - // } - - //faces - case E: case W: - if (sendDir == E) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = lMin1X1; - } - else if (sendDir == W) - { - lMin1X1 = 3; - lMax1X1 = lMin1X1; - } - - //int TminX1 = lMinX1; int TminX2 = lMinX2; int TminX3 = lMinX3; int TmaxX1 = lMaxX1; int TmaxX2 = lMaxX2; int TmaxX3 = lMaxX3; - - //if (block.lock()->hasInterpolationFlagCF(E)) - //{ - // if (maxX1==TmaxX1) maxX1 -= 2; - //} - //if (block.lock()->hasInterpolationFlagCF(W)) - //{ - // if (minX1==TminX1) minX1 += 2; - //} - //if (block.lock()->hasInterpolationFlagCF(N)) - //{ - // if (maxX2==TmaxX2) maxX2 -= 2; - //} - //if (block.lock()->hasInterpolationFlagCF(S)) - //{ - // if (minX2==TminX2) minX2 += 2; - //} - //if (block.lock()->hasInterpolationFlagCF(T)) - //{ - // if (maxX3==TmaxX3) maxX3 -= 2; - //} - //if (block.lock()->hasInterpolationFlagCF(B)) - //{ - // if (minX3==TminX3) minX3 += 2; - //} - if (receiver00) - { - lMin1X2 = minX2; - lMax1X2 = maxHalfX2; - lMin1X3 = minX3; - lMax1X3 = maxHalfX3; - getLocalMinMax(dummy, lMin1X2, lMin1X3, dummy, dummy, dummy); - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X2 = minHalfX2; - lMax1X2 = maxX2 - 1; - lMin1X3 = minX3; - lMax1X3 = maxHalfX3; - getLocalMinMax(dummy, dummy, lMin1X3, dummy, lMax1X2, dummy); - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - if (receiver01) - { - lMin1X2 = minX2; - lMax1X2 = maxHalfX2; - lMin1X3 = minHalfX3; - lMax1X3 = maxX3 - 1; - getLocalMinMax(dummy, lMin1X2, dummy, dummy, dummy, lMax1X3); - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); - } - if (receiver11) - { - lMin1X2 = minHalfX2; - lMax1X2 = maxX2 - 1; - lMin1X3 = minHalfX3; - lMax1X3 = maxX3 - 1; - getLocalMinMax(dummy, dummy, dummy, dummy, lMax1X2, lMax1X3); - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); - } - break; - case N: case S: - if (sendDir == N) - { - lMin1X2 = maxX2 - 3; - lMax1X2 = lMin1X2; - } - else if (sendDir == S) - { - lMin1X2 = 3; - lMax1X2 = lMin1X2; - } - - if (receiver00) - { - lMin1X1 = minX1; - lMax1X1 = maxHalfX1; - lMin1X3 = minX3; - lMax1X3 = maxHalfX3; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X1 = minHalfX1; - lMax1X1 = maxX1 - 1; - lMin1X3 = minX3; - lMax1X3 = maxHalfX3; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - if (receiver01) - { - lMin1X1 = minX1; - lMax1X1 = maxHalfX1; - lMin1X3 = minHalfX3; - lMax1X3 = maxX3 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); - } - if (receiver11) - { - lMin1X1 = minHalfX1; - lMax1X1 = maxX1 - 1; - lMin1X3 = minHalfX3; - lMax1X3 = maxX3 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); - } - break; - case T: case B: - if (sendDir == T) - { - lMin1X3 = maxX3 - 3; - lMax1X3 = lMin1X3; - } - else if (sendDir == B) - { - lMin1X3 = 3; - lMax1X3 = lMin1X3; - } - - if (receiver00) - { - lMin1X1 = minX1; - lMax1X1 = maxHalfX1; - lMin1X2 = minX2; - lMax1X2 = maxHalfX2; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X1 = minHalfX1; - lMax1X1 = maxX1 - 1; - lMin1X2 = minX2; - lMax1X2 = maxHalfX2; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - if (receiver01) - { - lMin1X1 = minX1; - lMax1X1 = maxHalfX1; - lMin1X2 = minHalfX2; - lMax1X2 = maxX2 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); - } - if (receiver11) - { - lMin1X1 = minHalfX1; - lMax1X1 = maxX1 - 1; - lMin1X2 = minHalfX2; - lMax1X2 = maxX2 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); - } - break; - //edges - //N-S-E-W - case NE: case SW: case SE: case NW: - if (sendDir == NE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = lMin1X1 + 2; - lMin1X2 = maxX2 - 3; - lMax1X2 = lMin1X2; - - lMin2X1 = maxX1 - 3; - lMax2X1 = lMin2X1; - lMin2X2 = maxX2 - 3; - lMax2X2 = lMin2X2 + 2; - } - else if (sendDir == SW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 2; - lMin1X2 = 3; - lMax1X2 = lMin1X2; - - lMin2X1 = 3; - lMax2X1 = lMin2X1; - lMin2X2 = 1; - lMax2X2 = lMin2X2 + 2; - } - else if (sendDir == SE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = lMin1X1 + 2; - lMin1X2 = 3; - lMax1X2 = lMin1X2; - - lMin2X1 = maxX1 - 3; - lMax2X1 = lMin2X1; - lMin2X2 = 1; - lMax2X2 = lMin2X2 + 2; - } - else if (sendDir == NW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 2; - lMin1X2 = maxX2 - 3; - lMax1X2 = lMin1X2; - - lMin2X1 = 3; - lMax2X1 = lMin2X1; - lMin2X2 = maxX2 - 3; - lMax2X2 = lMin2X2 + 2; - } - - if (receiver00) - { - lMin1X3 = minX3; - lMax1X3 = maxHalfX3; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X3 = minHalfX3; - lMax1X3 = maxX3 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - - if (receiver00) - { - lMin2X3 = minX3; - lMax2X3 = maxHalfX3; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin2X3 = minHalfX3; - lMax2X3 = maxX3 - 1; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); - } - break; - //T-B-E-W - case TE: case BW: case BE: case TW: - if (sendDir == TE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = lMin1X1 + 2; - lMin1X3 = maxX3 - 3; - lMax1X3 = lMin1X3; - - lMin2X1 = maxX1 - 3; - lMax2X1 = lMin2X1; - lMin2X3 = maxX3 - 3; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == BW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 2; - lMin1X3 = 3; - lMax1X3 = lMin1X3; - - lMin2X1 = 3; - lMax2X1 = lMin2X1; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == BE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = lMin1X1 + 2; - lMin1X3 = 3; - lMax1X3 = lMin1X3; - - - lMin2X1 = maxX1 - 3; - lMax2X1 = lMin2X1; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == TW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 2; - lMin1X3 = maxX3 - 3; - lMax1X3 = lMin1X3; - - lMin2X1 = 3; - lMax2X1 = lMin2X1; - lMin2X3 = maxX3 - 3; - lMax2X3 = lMin2X3 + 2; - } - - if (receiver00) - { - lMin1X2 = minX2; - lMax1X2 = maxHalfX2; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X2 = minHalfX2; - lMax1X2 = maxX2 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - - if (receiver00) - { - lMin2X2 = minX2; - lMax2X2 = maxHalfX2; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin2X2 = minHalfX2; - lMax2X2 = maxX2 - 1; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); - } - break; - //T-B-N-S - case TN: case BS: case BN: case TS: - if (sendDir == TN) - { - lMin1X2 = maxX2 - 3; - lMax1X2 = lMin1X2 + 2; - lMin1X3 = maxX3 - 3; - lMax1X3 = lMin1X3; - - lMin2X2 = maxX2 - 3; - lMax2X2 = lMin2X2; - lMin2X3 = maxX3 - 3; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == BS) - { - lMin1X2 = 1; - lMax1X2 = lMin1X2 + 2; - lMin1X3 = 3; - lMax1X3 = lMin1X3; - - lMin2X2 = 3; - lMax2X2 = lMin2X2; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == BN) - { - lMin1X2 = maxX2 - 3; - lMax1X2 = lMin1X2 + 2; - lMin1X3 = 3; - lMax1X3 = lMin1X3; - - lMin2X2 = maxX2 - 3; - lMax2X2 = lMin2X2; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 2; - } - else if (sendDir == TS) - { - lMin1X2 = 1; - lMax1X2 = lMin1X2 + 2; - lMin1X3 = maxX3 - 3; - lMax1X3 = lMin1X3; - - lMin2X2 = 3; - lMax2X2 = lMin2X2; - lMin2X3 = maxX3 - 3; - lMax2X3 = lMin2X3 + 2; - } - - if (receiver00) - { - lMin1X1 = minX1; - lMax1X1 = maxHalfX1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin1X1 = minHalfX1; - lMax1X1 = maxX1 - 1; - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); - } - - if (receiver00) - { - lMin2X1 = minX1; - lMax2X1 = maxHalfX1; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); - } - if (receiver10) - { - lMin2X1 = minHalfX1; - lMax2X1 = maxX1 - 1; - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); - } - break; - //corners - case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: - if (sendDir == TNE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = maxX1 - 2; - lMin1X2 = maxX2 - 3; - lMax1X2 = maxX2 - 1; - lMin1X3 = maxX3 - 3; - lMax1X3 = maxX3 - 1; - - lMin2X1 = maxX1 - 3; - lMax2X1 = maxX1 - 1; - lMin2X2 = maxX2 - 3; - lMax2X2 = maxX2 - 2; - lMin2X3 = maxX3 - 3; - lMax2X3 = maxX3 - 1; - - lMin3X1 = maxX1 - 3; - lMax3X1 = maxX1 - 1; - lMin3X2 = maxX2 - 3; - lMax3X2 = maxX2 - 1; - lMin3X3 = maxX3 - 3; - lMax3X3 = maxX3 - 2; - } - else if (sendDir == TNW) - { - lMin1X1 = 3; - lMax1X1 = 3; - lMin1X2 = maxX2 - 3; - lMax1X2 = maxX2 - 1; - lMin1X3 = maxX3 - 3; - lMax1X3 = maxX3 - 1; - - lMin2X1 = 1; - lMax2X1 = 3; - lMin2X2 = maxX2 - 3; - lMax2X2 = maxX2 - 2; - lMin2X3 = maxX3 - 3; - lMax2X3 = maxX3; - - lMin3X1 = 1; - lMax3X1 = 3; - lMin3X2 = maxX2 - 3; - lMax3X2 = maxX2 - 1; - lMin3X3 = maxX3 - 3; - lMax3X3 = maxX3 - 2; - } - else if (sendDir == TSE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = maxX1 - 2; - lMin1X2 = 1; - lMax1X2 = 3; - lMin1X3 = maxX3 - 3; - lMax1X3 = maxX3; - - lMin2X1 = maxX1 - 3; - lMax2X1 = maxX1 - 1; - lMin2X2 = 3; - lMax2X2 = 3; - lMin2X3 = maxX3 - 3; - lMax2X3 = maxX3; - - lMin3X1 = maxX1 - 3; - lMax3X1 = maxX1 - 1; - lMin3X2 = 1; - lMax3X2 = 3; - lMin3X3 = maxX3 - 3; - lMax3X3 = maxX3 - 2; - } - else if (sendDir == TSW) - { - lMin1X1 = 3; - lMax1X1 = 3; - lMin1X2 = 1; - lMax1X2 = 3; - lMin1X3 = maxX3 - 3; - lMax1X3 = maxX3 - 1; - - lMin2X1 = 1; - lMax2X1 = 3; - lMin2X2 = 3; - lMax2X2 = 3; - lMin2X3 = maxX3 - 3; - lMax2X3 = maxX3 - 1; - - lMin3X1 = 1; - lMax3X1 = 3; - lMin3X2 = 1; - lMax3X2 = 3; - lMin3X3 = maxX3 - 3; - lMax3X3 = maxX3 - 2; - } - else if (sendDir == BNE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = maxX1 - 2; - lMin1X2 = maxX2 - 3; - lMax1X2 = maxX2 - 1; - lMin1X3 = 1; - lMax1X3 = 3; - - lMin2X1 = maxX1 - 3; - lMax2X1 = maxX1 - 1; - lMin2X2 = maxX2 - 3; - lMax2X2 = maxX2 - 2; - lMin2X3 = 1; - lMax2X3 = 3; - - lMin3X1 = maxX1 - 3; - lMax3X1 = maxX1 - 1; - lMin3X2 = maxX2 - 3; - lMax3X2 = maxX2 - 1; - lMin3X3 = 3; - lMax3X3 = 3; - } - else if (sendDir == BNW) - { - lMin1X1 = 3; - lMax1X1 = 3; - lMin1X2 = maxX2 - 3; - lMax1X2 = maxX2 - 1; - lMin1X3 = 1; - lMax1X3 = 3; - - lMin2X1 = 1; - lMax2X1 = 3; - lMin2X2 = maxX2 - 3; - lMax2X2 = maxX2 - 2; - lMin2X3 = 1; - lMax2X3 = 3; - - lMin3X1 = 1; - lMax3X1 = 3; - lMin3X2 = maxX2 - 3; - lMax3X2 = maxX2 - 1; - lMin3X3 = 3; - lMax3X3 = 3; - } - else if (sendDir == BSE) - { - lMin1X1 = maxX1 - 3; - lMax1X1 = maxX1 - 2; - lMin1X2 = 1; - lMax1X2 = 3; - lMin1X3 = 1; - lMax1X3 = 3; - - lMin2X1 = maxX1 - 3; - lMax2X1 = maxX1 - 1; - lMin2X2 = 3; - lMax2X2 = 3; - lMin2X3 = 1; - lMax2X3 = 3; - - lMin3X1 = maxX1 - 3; - lMax3X1 = maxX1 - 1; - lMin3X2 = 1; - lMax3X2 = 3; - lMin3X3 = 3; - lMax3X3 = 3; - } - else if (sendDir == BSW) - { - lMin1X1 = 3; - lMax1X1 = 3; - lMin1X2 = 1; - lMax1X2 = 3; - lMin1X3 = 1; - lMax1X3 = 3; - - lMin2X1 = 1; - lMax2X1 = 3; - lMin2X2 = 3; - lMax2X2 = 3; - lMin2X3 = 1; - lMax2X3 = 3; - - lMin3X1 = 1; - lMax3X1 = 3; - lMin3X2 = 1; - lMax3X2 = 3; - lMin3X3 = 3; - lMax3X3 = 3; - } - if (receiver00) - { - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); - } - if (receiver00) - { - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); - } - if (receiver00) - { - findFCCells(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3, iNodeSetReceiver00); - } - break; - } + using namespace D3Q27System; + + int lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3; + int lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3; + int lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3; + int dummy; + + switch (sendDir) { + + ////////////////////////////////////////////////////// + // Debug + ////////////////////////////////////////////////////// + // if (block.lock()->getGlobalID() == 2234) + // { + // int test = 0; + // } + + // faces + case E: + case W: + if (sendDir == E) { + lMin1X1 = maxX1 - 3; + lMax1X1 = lMin1X1; + } else if (sendDir == W) { + lMin1X1 = 3; + lMax1X1 = lMin1X1; + } + + // int TminX1 = lMinX1; int TminX2 = lMinX2; int TminX3 = lMinX3; int TmaxX1 = lMaxX1; int TmaxX2 = lMaxX2; + // int TmaxX3 = lMaxX3; + + // if (block.lock()->hasInterpolationFlagCF(E)) + //{ + // if (maxX1==TmaxX1) maxX1 -= 2; + //} + // if (block.lock()->hasInterpolationFlagCF(W)) + //{ + // if (minX1==TminX1) minX1 += 2; + //} + // if (block.lock()->hasInterpolationFlagCF(N)) + //{ + // if (maxX2==TmaxX2) maxX2 -= 2; + //} + // if (block.lock()->hasInterpolationFlagCF(S)) + //{ + // if (minX2==TminX2) minX2 += 2; + //} + // if (block.lock()->hasInterpolationFlagCF(T)) + //{ + // if (maxX3==TmaxX3) maxX3 -= 2; + //} + // if (block.lock()->hasInterpolationFlagCF(B)) + //{ + // if (minX3==TminX3) minX3 += 2; + //} + if (receiver00) { + lMin1X2 = minX2; + lMax1X2 = maxHalfX2; + lMin1X3 = minX3; + lMax1X3 = maxHalfX3; + getLocalMinMax(dummy, lMin1X2, lMin1X3, dummy, dummy, dummy); + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X2 = minHalfX2; + lMax1X2 = maxX2 - 1; + lMin1X3 = minX3; + lMax1X3 = maxHalfX3; + getLocalMinMax(dummy, dummy, lMin1X3, dummy, lMax1X2, dummy); + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + if (receiver01) { + lMin1X2 = minX2; + lMax1X2 = maxHalfX2; + lMin1X3 = minHalfX3; + lMax1X3 = maxX3 - 1; + getLocalMinMax(dummy, lMin1X2, dummy, dummy, dummy, lMax1X3); + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); + } + if (receiver11) { + lMin1X2 = minHalfX2; + lMax1X2 = maxX2 - 1; + lMin1X3 = minHalfX3; + lMax1X3 = maxX3 - 1; + getLocalMinMax(dummy, dummy, dummy, dummy, lMax1X2, lMax1X3); + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); + } + break; + case N: + case S: + if (sendDir == N) { + lMin1X2 = maxX2 - 3; + lMax1X2 = lMin1X2; + } else if (sendDir == S) { + lMin1X2 = 3; + lMax1X2 = lMin1X2; + } + + if (receiver00) { + lMin1X1 = minX1; + lMax1X1 = maxHalfX1; + lMin1X3 = minX3; + lMax1X3 = maxHalfX3; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X1 = minHalfX1; + lMax1X1 = maxX1 - 1; + lMin1X3 = minX3; + lMax1X3 = maxHalfX3; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + if (receiver01) { + lMin1X1 = minX1; + lMax1X1 = maxHalfX1; + lMin1X3 = minHalfX3; + lMax1X3 = maxX3 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); + } + if (receiver11) { + lMin1X1 = minHalfX1; + lMax1X1 = maxX1 - 1; + lMin1X3 = minHalfX3; + lMax1X3 = maxX3 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); + } + break; + case T: + case B: + if (sendDir == T) { + lMin1X3 = maxX3 - 3; + lMax1X3 = lMin1X3; + } else if (sendDir == B) { + lMin1X3 = 3; + lMax1X3 = lMin1X3; + } + + if (receiver00) { + lMin1X1 = minX1; + lMax1X1 = maxHalfX1; + lMin1X2 = minX2; + lMax1X2 = maxHalfX2; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X1 = minHalfX1; + lMax1X1 = maxX1 - 1; + lMin1X2 = minX2; + lMax1X2 = maxHalfX2; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + if (receiver01) { + lMin1X1 = minX1; + lMax1X1 = maxHalfX1; + lMin1X2 = minHalfX2; + lMax1X2 = maxX2 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver01); + } + if (receiver11) { + lMin1X1 = minHalfX1; + lMax1X1 = maxX1 - 1; + lMin1X2 = minHalfX2; + lMax1X2 = maxX2 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver11); + } + break; + // edges + // N-S-E-W + case NE: + case SW: + case SE: + case NW: + if (sendDir == NE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = lMin1X1 + 2; + lMin1X2 = maxX2 - 3; + lMax1X2 = lMin1X2; + + lMin2X1 = maxX1 - 3; + lMax2X1 = lMin2X1; + lMin2X2 = maxX2 - 3; + lMax2X2 = lMin2X2 + 2; + } else if (sendDir == SW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 2; + lMin1X2 = 3; + lMax1X2 = lMin1X2; + + lMin2X1 = 3; + lMax2X1 = lMin2X1; + lMin2X2 = 1; + lMax2X2 = lMin2X2 + 2; + } else if (sendDir == SE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = lMin1X1 + 2; + lMin1X2 = 3; + lMax1X2 = lMin1X2; + + lMin2X1 = maxX1 - 3; + lMax2X1 = lMin2X1; + lMin2X2 = 1; + lMax2X2 = lMin2X2 + 2; + } else if (sendDir == NW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 2; + lMin1X2 = maxX2 - 3; + lMax1X2 = lMin1X2; + + lMin2X1 = 3; + lMax2X1 = lMin2X1; + lMin2X2 = maxX2 - 3; + lMax2X2 = lMin2X2 + 2; + } + + if (receiver00) { + lMin1X3 = minX3; + lMax1X3 = maxHalfX3; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X3 = minHalfX3; + lMax1X3 = maxX3 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + + if (receiver00) { + lMin2X3 = minX3; + lMax2X3 = maxHalfX3; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin2X3 = minHalfX3; + lMax2X3 = maxX3 - 1; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); + } + break; + // T-B-E-W + case TE: + case BW: + case BE: + case TW: + if (sendDir == TE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = lMin1X1 + 2; + lMin1X3 = maxX3 - 3; + lMax1X3 = lMin1X3; + + lMin2X1 = maxX1 - 3; + lMax2X1 = lMin2X1; + lMin2X3 = maxX3 - 3; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == BW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 2; + lMin1X3 = 3; + lMax1X3 = lMin1X3; + + lMin2X1 = 3; + lMax2X1 = lMin2X1; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == BE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = lMin1X1 + 2; + lMin1X3 = 3; + lMax1X3 = lMin1X3; + + lMin2X1 = maxX1 - 3; + lMax2X1 = lMin2X1; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == TW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 2; + lMin1X3 = maxX3 - 3; + lMax1X3 = lMin1X3; + + lMin2X1 = 3; + lMax2X1 = lMin2X1; + lMin2X3 = maxX3 - 3; + lMax2X3 = lMin2X3 + 2; + } + + if (receiver00) { + lMin1X2 = minX2; + lMax1X2 = maxHalfX2; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X2 = minHalfX2; + lMax1X2 = maxX2 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + + if (receiver00) { + lMin2X2 = minX2; + lMax2X2 = maxHalfX2; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin2X2 = minHalfX2; + lMax2X2 = maxX2 - 1; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); + } + break; + // T-B-N-S + case TN: + case BS: + case BN: + case TS: + if (sendDir == TN) { + lMin1X2 = maxX2 - 3; + lMax1X2 = lMin1X2 + 2; + lMin1X3 = maxX3 - 3; + lMax1X3 = lMin1X3; + + lMin2X2 = maxX2 - 3; + lMax2X2 = lMin2X2; + lMin2X3 = maxX3 - 3; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == BS) { + lMin1X2 = 1; + lMax1X2 = lMin1X2 + 2; + lMin1X3 = 3; + lMax1X3 = lMin1X3; + + lMin2X2 = 3; + lMax2X2 = lMin2X2; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == BN) { + lMin1X2 = maxX2 - 3; + lMax1X2 = lMin1X2 + 2; + lMin1X3 = 3; + lMax1X3 = lMin1X3; + + lMin2X2 = maxX2 - 3; + lMax2X2 = lMin2X2; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 2; + } else if (sendDir == TS) { + lMin1X2 = 1; + lMax1X2 = lMin1X2 + 2; + lMin1X3 = maxX3 - 3; + lMax1X3 = lMin1X3; + + lMin2X2 = 3; + lMax2X2 = lMin2X2; + lMin2X3 = maxX3 - 3; + lMax2X3 = lMin2X3 + 2; + } + + if (receiver00) { + lMin1X1 = minX1; + lMax1X1 = maxHalfX1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin1X1 = minHalfX1; + lMax1X1 = maxX1 - 1; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver10); + } + + if (receiver00) { + lMin2X1 = minX1; + lMax2X1 = maxHalfX1; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); + } + if (receiver10) { + lMin2X1 = minHalfX1; + lMax2X1 = maxX1 - 1; + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver10); + } + break; + // corners + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + if (sendDir == TNE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = maxX1 - 2; + lMin1X2 = maxX2 - 3; + lMax1X2 = maxX2 - 1; + lMin1X3 = maxX3 - 3; + lMax1X3 = maxX3 - 1; + + lMin2X1 = maxX1 - 3; + lMax2X1 = maxX1 - 1; + lMin2X2 = maxX2 - 3; + lMax2X2 = maxX2 - 2; + lMin2X3 = maxX3 - 3; + lMax2X3 = maxX3 - 1; + + lMin3X1 = maxX1 - 3; + lMax3X1 = maxX1 - 1; + lMin3X2 = maxX2 - 3; + lMax3X2 = maxX2 - 1; + lMin3X3 = maxX3 - 3; + lMax3X3 = maxX3 - 2; + } else if (sendDir == TNW) { + lMin1X1 = 3; + lMax1X1 = 3; + lMin1X2 = maxX2 - 3; + lMax1X2 = maxX2 - 1; + lMin1X3 = maxX3 - 3; + lMax1X3 = maxX3 - 1; + + lMin2X1 = 1; + lMax2X1 = 3; + lMin2X2 = maxX2 - 3; + lMax2X2 = maxX2 - 2; + lMin2X3 = maxX3 - 3; + lMax2X3 = maxX3; + + lMin3X1 = 1; + lMax3X1 = 3; + lMin3X2 = maxX2 - 3; + lMax3X2 = maxX2 - 1; + lMin3X3 = maxX3 - 3; + lMax3X3 = maxX3 - 2; + } else if (sendDir == TSE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = maxX1 - 2; + lMin1X2 = 1; + lMax1X2 = 3; + lMin1X3 = maxX3 - 3; + lMax1X3 = maxX3; + + lMin2X1 = maxX1 - 3; + lMax2X1 = maxX1 - 1; + lMin2X2 = 3; + lMax2X2 = 3; + lMin2X3 = maxX3 - 3; + lMax2X3 = maxX3; + + lMin3X1 = maxX1 - 3; + lMax3X1 = maxX1 - 1; + lMin3X2 = 1; + lMax3X2 = 3; + lMin3X3 = maxX3 - 3; + lMax3X3 = maxX3 - 2; + } else if (sendDir == TSW) { + lMin1X1 = 3; + lMax1X1 = 3; + lMin1X2 = 1; + lMax1X2 = 3; + lMin1X3 = maxX3 - 3; + lMax1X3 = maxX3 - 1; + + lMin2X1 = 1; + lMax2X1 = 3; + lMin2X2 = 3; + lMax2X2 = 3; + lMin2X3 = maxX3 - 3; + lMax2X3 = maxX3 - 1; + + lMin3X1 = 1; + lMax3X1 = 3; + lMin3X2 = 1; + lMax3X2 = 3; + lMin3X3 = maxX3 - 3; + lMax3X3 = maxX3 - 2; + } else if (sendDir == BNE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = maxX1 - 2; + lMin1X2 = maxX2 - 3; + lMax1X2 = maxX2 - 1; + lMin1X3 = 1; + lMax1X3 = 3; + + lMin2X1 = maxX1 - 3; + lMax2X1 = maxX1 - 1; + lMin2X2 = maxX2 - 3; + lMax2X2 = maxX2 - 2; + lMin2X3 = 1; + lMax2X3 = 3; + + lMin3X1 = maxX1 - 3; + lMax3X1 = maxX1 - 1; + lMin3X2 = maxX2 - 3; + lMax3X2 = maxX2 - 1; + lMin3X3 = 3; + lMax3X3 = 3; + } else if (sendDir == BNW) { + lMin1X1 = 3; + lMax1X1 = 3; + lMin1X2 = maxX2 - 3; + lMax1X2 = maxX2 - 1; + lMin1X3 = 1; + lMax1X3 = 3; + + lMin2X1 = 1; + lMax2X1 = 3; + lMin2X2 = maxX2 - 3; + lMax2X2 = maxX2 - 2; + lMin2X3 = 1; + lMax2X3 = 3; + + lMin3X1 = 1; + lMax3X1 = 3; + lMin3X2 = maxX2 - 3; + lMax3X2 = maxX2 - 1; + lMin3X3 = 3; + lMax3X3 = 3; + } else if (sendDir == BSE) { + lMin1X1 = maxX1 - 3; + lMax1X1 = maxX1 - 2; + lMin1X2 = 1; + lMax1X2 = 3; + lMin1X3 = 1; + lMax1X3 = 3; + + lMin2X1 = maxX1 - 3; + lMax2X1 = maxX1 - 1; + lMin2X2 = 3; + lMax2X2 = 3; + lMin2X3 = 1; + lMax2X3 = 3; + + lMin3X1 = maxX1 - 3; + lMax3X1 = maxX1 - 1; + lMin3X2 = 1; + lMax3X2 = 3; + lMin3X3 = 3; + lMax3X3 = 3; + } else if (sendDir == BSW) { + lMin1X1 = 3; + lMax1X1 = 3; + lMin1X2 = 1; + lMax1X2 = 3; + lMin1X3 = 1; + lMax1X3 = 3; + + lMin2X1 = 1; + lMax2X1 = 3; + lMin2X2 = 3; + lMax2X2 = 3; + lMin2X3 = 1; + lMax2X3 = 3; + + lMin3X1 = 1; + lMax3X1 = 3; + lMin3X2 = 1; + lMax3X2 = 3; + lMin3X3 = 3; + lMax3X3 = 3; + } + if (receiver00) { + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetReceiver00); + } + if (receiver00) { + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetReceiver00); + } + if (receiver00) { + findFCCells(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3, iNodeSetReceiver00); + } + break; + } } ////////////////////////////////////////////////////////////////////////// -//template< typename VectorTransmitter > +// template< typename VectorTransmitter > void CoarseToFineNodeSetBlock3DConnector::distributeReceiveVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); - - int index00 = 0; - int index01 = 0; - int index10 = 0; - int index11 = 0; - - vector_type& data00 = this->receiver00->getData(); - vector_type& data01 = this->receiver01->getData(); - vector_type& data10 = this->receiver10->getData(); - vector_type& data11 = this->receiver11->getData(); - - for(INodeVector inode : iNodeSetReceiver00) - { - LBMReal icellC[27]; - this->readICellCfromData(data00, index00, icellC); - iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); - } - for(INodeVector inode : iNodeSetReceiver01) - { - LBMReal icellC[27]; - this->readICellCfromData(data01, index01, icellC); - iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); - } - for(INodeVector inode : iNodeSetReceiver10) - { - LBMReal icellC[27]; - this->readICellCfromData(data10, index10, icellC); - iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); - } - for(INodeVector inode : iNodeSetReceiver11) - { - LBMReal icellC[27]; - this->readICellCfromData(data11, index11, icellC); - iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); - } + using namespace D3Q27System; + + SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); + + int index00 = 0; + int index01 = 0; + int index10 = 0; + int index11 = 0; + + vector_type &data00 = this->receiver00->getData(); + vector_type &data01 = this->receiver01->getData(); + vector_type &data10 = this->receiver10->getData(); + vector_type &data11 = this->receiver11->getData(); + + for (INodeVector inode : iNodeSetReceiver00) { + LBMReal icellC[27]; + this->readICellCfromData(data00, index00, icellC); + iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); + } + for (INodeVector inode : iNodeSetReceiver01) { + LBMReal icellC[27]; + this->readICellCfromData(data01, index01, icellC); + iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); + } + for (INodeVector inode : iNodeSetReceiver10) { + LBMReal icellC[27]; + this->readICellCfromData(data10, index10, icellC); + iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); + } + for (INodeVector inode : iNodeSetReceiver11) { + LBMReal icellC[27]; + this->readICellCfromData(data11, index11, icellC); + iprocessor->writeINodeInv(fTo, icellC, inode[0], inode[1], inode[2]); + } } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::readICellCfromData(vector_type& data, int& index, LBMReal* icellC) +void CoarseToFineNodeSetBlock3DConnector::readICellCfromData(vector_type &data, int &index, LBMReal *icellC) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - icellC[i] = data[index++]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + icellC[i] = data[index++]; + } } ////////////////////////////////////////////////////////////////////////// -void CoarseToFineNodeSetBlock3DConnector::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3) +void CoarseToFineNodeSetBlock3DConnector::getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, + int &maxX3) { - using namespace D3Q27System; - int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = maxX3; - - if (block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1==TmaxX1) maxX1 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1==TminX1) minX1 += 2; - } - if (block.lock()->hasInterpolationFlagCF(N)) - { - if (maxX2==TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(S)) - { - if (minX2==TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX3==TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(B)) - { - if (minX3==TminX3) minX3 += 2; - } - - //E-W-N-S - if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1==TmaxX1) maxX1 -= 2; - if (maxX2==TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (minX1==TminX1) minX1 += 2; - if (minX2==TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (maxX1==TmaxX1) maxX1 -= 2; - if (minX2==TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1==TminX1) minX1 += 2; - if (maxX2==TmaxX2) maxX2 -= 2; - } - - // ////T-B-E-W - if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX1==TmaxX1) maxX1 -= 2; - if (maxX3==TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX1==TminX1) minX1 += 2; - if (minX3==TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX1==TmaxX1) maxX1 -= 2; - if (minX3==TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX1==TminX1) minX1 += 2; - if (maxX3==TmaxX3) maxX3 -= 2; - } - - - ////T-B-N-S - if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX2==TmaxX2) maxX2 -= 2; - if (maxX3==TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX2==TminX2) minX2 += 2; - if (minX3==TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX2==TmaxX2) maxX2 -= 2; - if (minX3==TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX2==TminX2) minX2 += 2; - if (maxX3==TmaxX3) maxX3 -= 2; - } + using namespace D3Q27System; + int TminX1 = minX1; + int TminX2 = minX2; + int TminX3 = minX3; + int TmaxX1 = maxX1; + int TmaxX2 = maxX2; + int TmaxX3 = maxX3; + + if (block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + } + if (block.lock()->hasInterpolationFlagCF(N)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(S)) { + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(T)) { + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(B)) { + if (minX3 == TminX3) + minX3 += 2; + } + + // E-W-N-S + if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + + // ////T-B-E-W + if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + + ////T-B-N-S + if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX2 == TminX2) + minX2 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX2 == TminX2) + minX2 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } } - - diff --git a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.h index ae8f09b16..4e71916d4 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/CoarseToFineNodeSetBlock3DConnector.h @@ -1,103 +1,98 @@ //! \file CoarseToFineNodeSetBlock3DConnector.h //! \class CoarseToFineNodeSetBlock3DConnector -//! \brief Connector interpolates and sends data from coarse level to fine. +//! \brief Connector interpolates and sends data from coarse level to fine. //! \author Konstantin Kutscher //! \date 18.05.2015 #ifndef CoarseToFineNodeSetBlock3DConnector_H #define CoarseToFineNodeSetBlock3DConnector_H -#include <vector> #include <set> +#include <vector> //#include "basics/transmitter/TbTransmitter.h" //#include "basics/transmitter/TbTransmitterLocal.h" //#include "basics/container/CbVector.h" +#include "BCProcessor.h" +#include "Block3D.h" #include "CoarseToFineBlock3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" -#include "LBMKernel.h" -#include "BCProcessor.h" +#include "Grid3D.h" #include "InterpolationProcessor.h" +#include "LBMKernel.h" #include "MathUtil.hpp" -#include "Grid3D.h" #include <PointerDefinitions.h> - class Block3D; -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) - - -// send direction: E<->W N<->S T<->B -// --------- x3 x3 x2 -// | 01 | 11 | ^ ^ ^ -// |----+----| +-> x2 +->x1 +->x1 -// | 00 | 10 | -// --------- +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) +// send direction: E<->W N<->S T<->B +// --------- x3 x3 x2 +// | 01 | 11 | ^ ^ ^ +// |----+----| +-> x2 +->x1 +->x1 +// | 00 | 10 | +// --------- class CoarseToFineNodeSetBlock3DConnector : public CoarseToFineBlock3DConnector { public: - CoarseToFineNodeSetBlock3DConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor); + CoarseToFineNodeSetBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender00, + VectorTransmitterPtr receiver00, VectorTransmitterPtr sender01, + VectorTransmitterPtr receiver01, VectorTransmitterPtr sender10, + VectorTransmitterPtr receiver10, VectorTransmitterPtr sender11, + VectorTransmitterPtr receiver11, int sendDir, + InterpolationProcessorPtr iprocessor); - void init() override; + void init() override; - void fillSendVectors() override; - void distributeReceiveVectors() override; + void fillSendVectors() override; + void distributeReceiveVectors() override; protected: - typedef std::vector< int > INodeVector; - using INodeSet = std::vector<INodeVector>; - INodeSet iNodeSetSender00; - INodeSet iNodeSetSender01; - INodeSet iNodeSetSender10; - INodeSet iNodeSetSender11; - INodeSet iNodeSetReceiver00; - INodeSet iNodeSetReceiver01; - INodeSet iNodeSetReceiver10; - INodeSet iNodeSetReceiver11; - - void writeICellFtoData(vector_type& data, int& index, D3Q27ICell& icellF); - void writeNodeToVector(vector_type& data, int& index, LBMReal* inode); - void readICellCfromData(vector_type& data, int& index, LBMReal* icellC); - - void findCFCells(); - void findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); - - void findFCCells(); - void findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); - - void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3); - - int bMaxX1, bMaxX2, bMaxX3; - - int minX1; - int minX2; - int minX3; - - int maxX1; - int maxX2; - int maxX3; - - int minHalfX1; - int minHalfX2; - int minHalfX3; - - int maxHalfX1; - int maxHalfX2; - int maxHalfX3; + typedef std::vector<int> INodeVector; + using INodeSet = std::vector<INodeVector>; + INodeSet iNodeSetSender00; + INodeSet iNodeSetSender01; + INodeSet iNodeSetSender10; + INodeSet iNodeSetSender11; + INodeSet iNodeSetReceiver00; + INodeSet iNodeSetReceiver01; + INodeSet iNodeSetReceiver10; + INodeSet iNodeSetReceiver11; + + void writeICellFtoData(vector_type &data, int &index, D3Q27ICell &icellF); + void writeNodeToVector(vector_type &data, int &index, LBMReal *inode); + void readICellCfromData(vector_type &data, int &index, LBMReal *icellC); + + void findCFCells(); + void findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); + + void findFCCells(); + void findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); + + void getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, int &maxX3); + + int bMaxX1, bMaxX2, bMaxX3; + + int minX1; + int minX2; + int minX3; + + int maxX1; + int maxX2; + int maxX3; + + int minHalfX1; + int minHalfX2; + int minHalfX3; + + int maxHalfX1; + int maxHalfX2; + int maxHalfX3; }; - - -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/ConnectorFactory.h b/src/cpu/VirtualFluidsCore/Connectors/ConnectorFactory.h index 323d0349f..65307fe3a 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/ConnectorFactory.h +++ b/src/cpu/VirtualFluidsCore/Connectors/ConnectorFactory.h @@ -2,35 +2,34 @@ #define ConnectorFactory_h__ #include "Block3DConnector.h" -#include "TransmitterType.h" -#include "InterpolationProcessor.h" #include "FineToCoarseBlock3DConnector.h" +#include "InterpolationProcessor.h" +#include "TransmitterType.h" #include <PointerDefinitions.h> class ConnectorFactory { public: - ConnectorFactory() = default;; - virtual ~ConnectorFactory() = default;; + ConnectorFactory() = default; + ; + virtual ~ConnectorFactory() = default; + ; - virtual SPtr<Block3DConnector> createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) = 0; - virtual SPtr<Block3DConnector> createSameLevelVectorConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir) = 0; - virtual SPtr<Block3DConnector> createCoarseToFineConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, - VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, - VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, - VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, - int sendDir, InterpolationProcessorPtr iprocessor) = 0; - virtual SPtr<Block3DConnector> createFineToCoarseConnector(SPtr<Block3D> block, - VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, - int sendDir, - InterpolationProcessorPtr iprocessor, - FineToCoarseBlock3DConnector::CFconnectorType connType) = 0; + virtual SPtr<Block3DConnector> createSameLevelDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, + int sendDir) = 0; + virtual SPtr<Block3DConnector> createSameLevelVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir) = 0; + virtual SPtr<Block3DConnector> + createCoarseToFineConnector(SPtr<Block3D> block, VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, + VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, + VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, + VectorTransmitterPtr sender11, VectorTransmitterPtr receiver11, int sendDir, + InterpolationProcessorPtr iprocessor) = 0; + virtual SPtr<Block3DConnector> + createFineToCoarseConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir, InterpolationProcessorPtr iprocessor, + FineToCoarseBlock3DConnector::CFconnectorType connType) = 0; protected: private: diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETCFOffVectorConnector.h b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETCFOffVectorConnector.h index 96c8627fe..66a03d63c 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETCFOffVectorConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETCFOffVectorConnector.h @@ -1,1939 +1,2060 @@ /** -* @file D3Q27ETCFOffVectorConnector.h -* @class D3Q27ETCFOffVectorConnector -* @brief Interpolation from coarse level to fine. -* @author Kostyantyn Kucher and Ehsan Fard -* @date 08.06.2011 -*/ + * @file D3Q27ETCFOffVectorConnector.h + * @class D3Q27ETCFOffVectorConnector + * @brief Interpolation from coarse level to fine. + * @author Kostyantyn Kucher and Ehsan Fard + * @date 08.06.2011 + */ #ifndef D3Q27ETCFOffVectorConnector_H #define D3Q27ETCFOffVectorConnector_H #include <vector> -#include "basics/transmitter/TbTransmitter.h" -#include "basics/transmitter/TbTransmitterLocal.h" -#include "basics/container/CbVector.h" +#include "Block3D.h" #include "Block3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" -#include "LBMKernel.h" +#include "Grid3D.h" #include "InterpolationProcessor.h" +#include "LBMKernel.h" #include "MathUtil.hpp" -#include "Grid3D.h" +#include "basics/container/CbVector.h" +#include "basics/transmitter/TbTransmitter.h" +#include "basics/transmitter/TbTransmitterLocal.h" #include <PointerDefinitions.h> -#include "D3Q27ETFCOffVectorConnector.h" #include "BCProcessor.h" +#include "D3Q27ETFCOffVectorConnector.h" class Block3D; -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) -//sendrichtung: E<->W N<->S T<->B +// sendrichtung: E<->W N<->S T<->B // --------- x3 x3 x2 // | NW | NE | ^ ^ ^ // |----+----| +-> x2 +->x1 +->x1 -// | SW | SE | +// | SW | SE | // --------- // NW==even-odd, SW==even-even, SE==odd-even, NE==odd-odd -template< typename VectorTransmitter > +template <typename VectorTransmitter> class D3Q27ETCFOffVectorConnector : public Block3DConnector { public: - using vector_type = typename VectorTransmitter::value_type; - using VectorTransmitterPtr = SPtr<VectorTransmitter>; + using vector_type = typename VectorTransmitter::value_type; + using VectorTransmitterPtr = SPtr<VectorTransmitter>; + public: - D3Q27ETCFOffVectorConnector(SPtr<Block3D> block, - VectorTransmitterPtr senderEvenEvenSW, VectorTransmitterPtr receiverEvenEvenSW, - VectorTransmitterPtr senderEvenOddNW, VectorTransmitterPtr receiverEvenOddNW, - VectorTransmitterPtr senderOddEvenSE, VectorTransmitterPtr receiverOddEvenSE, - VectorTransmitterPtr senderOddOddNE, VectorTransmitterPtr receiverOddOddNE, - int sendDir, InterpolationProcessorPtr iprocessor); + D3Q27ETCFOffVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr senderEvenEvenSW, + VectorTransmitterPtr receiverEvenEvenSW, VectorTransmitterPtr senderEvenOddNW, + VectorTransmitterPtr receiverEvenOddNW, VectorTransmitterPtr senderOddEvenSE, + VectorTransmitterPtr receiverOddEvenSE, VectorTransmitterPtr senderOddOddNE, + VectorTransmitterPtr receiverOddOddNE, int sendDir, + InterpolationProcessorPtr iprocessor); - bool isLocalConnector() override; - bool isRemoteConnector() override; - void init() override; + bool isLocalConnector() override; + bool isRemoteConnector() override; + void init() override; - void sendTransmitterDataSize() override; - void receiveTransmitterDataSize() override; + void sendTransmitterDataSize() override; + void receiveTransmitterDataSize() override; - void prepareForSend() override; - void sendVectors() override; + void prepareForSend() override; + void sendVectors() override; - void prepareForReceive() override; - void receiveVectors() override; + void prepareForReceive() override; + void receiveVectors() override; - void fillSendVectors() override; - void distributeReceiveVectors() override; + void fillSendVectors() override; + void distributeReceiveVectors() override; - bool isInterpolationConnectorCF() override { return true; } - bool isInterpolationConnectorFC() override { return false; } + bool isInterpolationConnectorCF() override { return true; } + bool isInterpolationConnectorFC() override { return false; } - double getSendRecieveTime(); + double getSendRecieveTime(); - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override {} - void sendVectorsX2() override {} - void sendVectorsX3() override {} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> block; //dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet - VectorTransmitterPtr senderEvenEvenSW, receiverEvenEvenSW, - senderEvenOddNW, receiverEvenOddNW, - senderOddEvenSE, receiverOddEvenSE, - senderOddOddNE, receiverOddOddNE; - - InterpolationProcessorPtr iprocessor; - - void writeICellFtoData(vector_type& data, int& index, D3Q27ICell& icellF); - void writeNodeToVector(vector_type& data, int& index, LBMReal* inode); - void getLocalMinMax(const int& gMin, const int& gMax, const bool& even, int& lMin, int& lMax, const bool& dataDistribution); - void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3); - void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3, CFconnectorType connType); - void fillSendVectorExt(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index); - - void distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index); - void readICellCfromData(vector_type& data, int& index, LBMReal* icellC); - - void findCFnodes(); - void findCFnodes(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index); - - int bMaxX1, bMaxX2, bMaxX3; + WPtr<Block3D> block; // dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet + VectorTransmitterPtr senderEvenEvenSW, receiverEvenEvenSW, senderEvenOddNW, receiverEvenOddNW, senderOddEvenSE, + receiverOddEvenSE, senderOddOddNE, receiverOddOddNE; + + InterpolationProcessorPtr iprocessor; + + void writeICellFtoData(vector_type &data, int &index, D3Q27ICell &icellF); + void writeNodeToVector(vector_type &data, int &index, LBMReal *inode); + void getLocalMinMax(const int &gMin, const int &gMax, const bool &even, int &lMin, int &lMax, + const bool &dataDistribution); + void getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, int &maxX3); + void getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, int &maxX3, + CFconnectorType connType); + void fillSendVectorExt(SPtr<DistributionArray3D> fFrom, const int &lMinX1, const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, const int &lMaxX3, vector_type &data, int &index); + + void distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int &lMinX1, const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, const int &lMaxX3, vector_type &data, + int &index); + void readICellCfromData(vector_type &data, int &index, LBMReal *icellC); + + void findCFnodes(); + void findCFnodes(SPtr<DistributionArray3D> fFrom, const int &lMinX1, const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, const int &lMaxX3, vector_type &data, int &index); + + int bMaxX1, bMaxX2, bMaxX3; }; //////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -D3Q27ETCFOffVectorConnector<VectorTransmitter>::D3Q27ETCFOffVectorConnector(SPtr<Block3D> block, - VectorTransmitterPtr senderEvenEvenSW, VectorTransmitterPtr receiverEvenEvenSW, - VectorTransmitterPtr senderEvenOddNW, VectorTransmitterPtr receiverEvenOddNW, - VectorTransmitterPtr senderOddEvenSE, VectorTransmitterPtr receiverOddEvenSE, - VectorTransmitterPtr senderOddOddNE, VectorTransmitterPtr receiverOddOddNE, - int sendDir, InterpolationProcessorPtr iprocessor) : Block3DConnector(sendDir) - , block(block) - , senderEvenEvenSW(senderEvenEvenSW) - , senderEvenOddNW(senderEvenOddNW) - , senderOddEvenSE(senderOddEvenSE) - , senderOddOddNE(senderOddOddNE) - , receiverEvenEvenSW(receiverEvenEvenSW) - , receiverEvenOddNW(receiverEvenOddNW) - , receiverOddEvenSE(receiverOddEvenSE) - , receiverOddOddNE(receiverOddOddNE) - , iprocessor(iprocessor) +template <typename VectorTransmitter> +D3Q27ETCFOffVectorConnector<VectorTransmitter>::D3Q27ETCFOffVectorConnector( + SPtr<Block3D> block, VectorTransmitterPtr senderEvenEvenSW, VectorTransmitterPtr receiverEvenEvenSW, + VectorTransmitterPtr senderEvenOddNW, VectorTransmitterPtr receiverEvenOddNW, VectorTransmitterPtr senderOddEvenSE, + VectorTransmitterPtr receiverOddEvenSE, VectorTransmitterPtr senderOddOddNE, VectorTransmitterPtr receiverOddOddNE, + int sendDir, InterpolationProcessorPtr iprocessor) + : Block3DConnector(sendDir), block(block), senderEvenEvenSW(senderEvenEvenSW), senderEvenOddNW(senderEvenOddNW), + senderOddEvenSE(senderOddEvenSE), senderOddOddNE(senderOddOddNE), receiverEvenEvenSW(receiverEvenEvenSW), + receiverEvenOddNW(receiverEvenOddNW), receiverOddEvenSE(receiverOddEvenSE), receiverOddOddNE(receiverOddOddNE), + iprocessor(iprocessor) { - if (!(sendDir == D3Q27System::E || sendDir == D3Q27System::W || sendDir == D3Q27System::N || sendDir == D3Q27System::S || sendDir == D3Q27System::T || sendDir == D3Q27System::B - || sendDir == D3Q27System::NE || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE || sendDir == D3Q27System::NW - || sendDir == D3Q27System::TE || sendDir == D3Q27System::BW || sendDir == D3Q27System::BE || sendDir == D3Q27System::TW - || sendDir == D3Q27System::TN || sendDir == D3Q27System::BS || sendDir == D3Q27System::BN || sendDir == D3Q27System::TS - || sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSE || sendDir == D3Q27System::TSW - || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || sendDir == D3Q27System::BSE || sendDir == D3Q27System::BSW - )) - { - throw UbException(UB_EXARGS, "invalid constructor for this direction"); - } + if (!(sendDir == D3Q27System::E || sendDir == D3Q27System::W || sendDir == D3Q27System::N || + sendDir == D3Q27System::S || sendDir == D3Q27System::T || sendDir == D3Q27System::B || + sendDir == D3Q27System::NE || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE || + sendDir == D3Q27System::NW || sendDir == D3Q27System::TE || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE || sendDir == D3Q27System::TW || sendDir == D3Q27System::TN || + sendDir == D3Q27System::BS || sendDir == D3Q27System::BN || sendDir == D3Q27System::TS || + sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSE || + sendDir == D3Q27System::TSW || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSE || sendDir == D3Q27System::BSW)) { + throw UbException(UB_EXARGS, "invalid constructor for this direction"); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> bool D3Q27ETCFOffVectorConnector<VectorTransmitter>::isLocalConnector() { - return !this->isRemoteConnector(); + return !this->isRemoteConnector(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> bool D3Q27ETCFOffVectorConnector<VectorTransmitter>::isRemoteConnector() { - return ((senderOddOddNE && senderOddOddNE->isRemoteTransmitter()) || (receiverOddOddNE && receiverOddOddNE->isRemoteTransmitter()) - || (senderEvenEvenSW && senderEvenEvenSW->isRemoteTransmitter()) || (receiverEvenEvenSW && receiverEvenEvenSW->isRemoteTransmitter()) - || (senderEvenOddNW && senderEvenOddNW->isRemoteTransmitter()) || (receiverEvenOddNW && receiverEvenOddNW->isRemoteTransmitter()) - || (senderOddEvenSE && senderOddEvenSE->isRemoteTransmitter()) || (receiverOddEvenSE && receiverOddEvenSE->isRemoteTransmitter())); + return ((senderOddOddNE && senderOddOddNE->isRemoteTransmitter()) || + (receiverOddOddNE && receiverOddOddNE->isRemoteTransmitter()) || + (senderEvenEvenSW && senderEvenEvenSW->isRemoteTransmitter()) || + (receiverEvenEvenSW && receiverEvenEvenSW->isRemoteTransmitter()) || + (senderEvenOddNW && senderEvenOddNW->isRemoteTransmitter()) || + (receiverEvenOddNW && receiverEvenOddNW->isRemoteTransmitter()) || + (senderOddEvenSE && senderOddEvenSE->isRemoteTransmitter()) || + (receiverOddEvenSE && receiverOddEvenSE->isRemoteTransmitter())); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize() { - if (senderEvenEvenSW) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderEvenEvenSW " << block.lock()->toString() << " sendDir=" << sendDir); - senderEvenEvenSW->sendDataSize(); - } - if (senderEvenOddNW) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderEvenOddNW " << block.lock()->toString() << "sendDir=" << sendDir); - senderEvenOddNW->sendDataSize(); - } - if (senderOddEvenSE) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderOddEvenSE " << block.lock()->toString() + "sendDir=" << sendDir); - senderOddEvenSE->sendDataSize(); - } - if (senderOddOddNE) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderOddOddNE " << block.lock()->toString() << "sendDir=" << sendDir); - senderOddOddNE->sendDataSize(); - } + if (senderEvenEvenSW) { + UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderEvenEvenSW " + << block.lock()->toString() << " sendDir=" << sendDir); + senderEvenEvenSW->sendDataSize(); + } + if (senderEvenOddNW) { + UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderEvenOddNW " + << block.lock()->toString() << "sendDir=" << sendDir); + senderEvenOddNW->sendDataSize(); + } + if (senderOddEvenSE) { + UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderOddEvenSE " + << block.lock()->toString() + "sendDir=" << sendDir); + senderOddEvenSE->sendDataSize(); + } + if (senderOddOddNE) { + UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()-senderOddOddNE " + << block.lock()->toString() << "sendDir=" << sendDir); + senderOddOddNE->sendDataSize(); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize() { - if (receiverEvenEvenSW) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverEvenEvenSW " << block.lock()->toString() << "sendDir=" << sendDir); - receiverEvenEvenSW->receiveDataSize(); - } - if (receiverEvenOddNW) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverEvenOddNW " << block.lock()->toString() << "sendDir=" << sendDir); - receiverEvenOddNW->receiveDataSize(); - } - if (receiverOddEvenSE) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverOddEvenSE " << block.lock()->toString() << "sendDir=" << sendDir); - receiverOddEvenSE->receiveDataSize(); - } - if (receiverOddOddNE) - { - UBLOG(logDEBUG5, "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverOddOddNE " << block.lock()->toString() << "sendDir=" << sendDir); - receiverOddOddNE->receiveDataSize(); - } + if (receiverEvenEvenSW) { + UBLOG(logDEBUG5, + "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverEvenEvenSW " + << block.lock()->toString() << "sendDir=" << sendDir); + receiverEvenEvenSW->receiveDataSize(); + } + if (receiverEvenOddNW) { + UBLOG(logDEBUG5, + "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverEvenOddNW " + << block.lock()->toString() << "sendDir=" << sendDir); + receiverEvenOddNW->receiveDataSize(); + } + if (receiverOddEvenSE) { + UBLOG(logDEBUG5, + "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverOddEvenSE " + << block.lock()->toString() << "sendDir=" << sendDir); + receiverOddEvenSE->receiveDataSize(); + } + if (receiverOddOddNE) { + UBLOG(logDEBUG5, + "D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()-receiverOddOddNE " + << block.lock()->toString() << "sendDir=" << sendDir); + receiverOddOddNE->receiveDataSize(); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::prepareForSend() { - if (senderEvenEvenSW) senderEvenEvenSW->prepareForSend(); - if (senderEvenOddNW) senderEvenOddNW->prepareForSend(); - if (senderOddEvenSE) senderOddEvenSE->prepareForSend(); - if (senderOddOddNE) senderOddOddNE->prepareForSend(); + if (senderEvenEvenSW) + senderEvenEvenSW->prepareForSend(); + if (senderEvenOddNW) + senderEvenOddNW->prepareForSend(); + if (senderOddEvenSE) + senderOddEvenSE->prepareForSend(); + if (senderOddOddNE) + senderOddOddNE->prepareForSend(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::sendVectors() { - if (senderEvenEvenSW) senderEvenEvenSW->sendData(); - if (senderEvenOddNW) senderEvenOddNW->sendData(); - if (senderOddEvenSE) senderOddEvenSE->sendData(); - if (senderOddOddNE) senderOddOddNE->sendData(); + if (senderEvenEvenSW) + senderEvenEvenSW->sendData(); + if (senderEvenOddNW) + senderEvenOddNW->sendData(); + if (senderOddEvenSE) + senderOddEvenSE->sendData(); + if (senderOddOddNE) + senderOddOddNE->sendData(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::prepareForReceive() { - if (receiverEvenEvenSW) receiverEvenEvenSW->prepareForReceive(); - if (receiverEvenOddNW) receiverEvenOddNW->prepareForReceive(); - if (receiverOddEvenSE) receiverOddEvenSE->prepareForReceive(); - if (receiverOddOddNE) receiverOddOddNE->prepareForReceive(); + if (receiverEvenEvenSW) + receiverEvenEvenSW->prepareForReceive(); + if (receiverEvenOddNW) + receiverEvenOddNW->prepareForReceive(); + if (receiverOddEvenSE) + receiverOddEvenSE->prepareForReceive(); + if (receiverOddOddNE) + receiverOddOddNE->prepareForReceive(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::receiveVectors() { - if (receiverEvenEvenSW) receiverEvenEvenSW->receiveData(); - if (receiverEvenOddNW) receiverEvenOddNW->receiveData(); - if (receiverOddEvenSE) receiverOddEvenSE->receiveData(); - if (receiverOddOddNE) receiverOddOddNE->receiveData(); + if (receiverEvenEvenSW) + receiverEvenEvenSW->receiveData(); + if (receiverEvenOddNW) + receiverEvenOddNW->receiveData(); + if (receiverOddEvenSE) + receiverOddEvenSE->receiveData(); + if (receiverOddOddNE) + receiverOddOddNE->receiveData(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETCFOffVectorConnector<VectorTransmitter>::init() { - using namespace D3Q27System; - - bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); - bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); - bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); - - int sendSize = 0; - LBMReal initValue = -999.0; - - int sendDataPerNode = 27/*f*/; - int iCellSize = 8; //size of interpolation cell - - switch (this->sendDir) - { - case E: case W: sendSize = bMaxX2*bMaxX3*sendDataPerNode*iCellSize; break; - case N: case S: sendSize = bMaxX1*bMaxX3*sendDataPerNode*iCellSize; break; - case T: case B: sendSize = bMaxX1*bMaxX2*sendDataPerNode*iCellSize; break; - case NE: case SW:case SE: case NW: sendSize = 2 * bMaxX3*sendDataPerNode*iCellSize; break; - case TE: case BW:case BE: case TW: sendSize = 2 * bMaxX2*sendDataPerNode*iCellSize; break; - case TN: case BS:case BN: case TS: sendSize = 2 * bMaxX1*sendDataPerNode*iCellSize; break; - case TNE: case TNW:case TSE: case TSW:case BNE: case BNW:case BSE: case BSW: sendSize = 6 * bMaxX1*sendDataPerNode*iCellSize; break; - default: throw UbException(UB_EXARGS, "direction not allowed in this constructor"); - } - if (senderEvenEvenSW) senderEvenEvenSW->getData().resize(sendSize, initValue); - else senderEvenEvenSW = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (senderEvenOddNW) senderEvenOddNW->getData().resize(sendSize, initValue); - else senderEvenOddNW = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (senderOddEvenSE) senderOddEvenSE->getData().resize(sendSize, initValue); - else senderOddEvenSE = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (senderOddOddNE) senderOddOddNE->getData().resize(sendSize, initValue); - else senderOddOddNE = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - - if (!receiverEvenEvenSW) receiverEvenEvenSW = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiverEvenOddNW) receiverEvenOddNW = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiverOddEvenSE) receiverOddEvenSE = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - if (!receiverOddOddNE) receiverOddOddNE = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - - //findCFnodes(); + using namespace D3Q27System; + + bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); + bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); + bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); + + int sendSize = 0; + LBMReal initValue = -999.0; + + int sendDataPerNode = 27 /*f*/; + int iCellSize = 8; // size of interpolation cell + + switch (this->sendDir) { + case E: + case W: + sendSize = bMaxX2 * bMaxX3 * sendDataPerNode * iCellSize; + break; + case N: + case S: + sendSize = bMaxX1 * bMaxX3 * sendDataPerNode * iCellSize; + break; + case T: + case B: + sendSize = bMaxX1 * bMaxX2 * sendDataPerNode * iCellSize; + break; + case NE: + case SW: + case SE: + case NW: + sendSize = 2 * bMaxX3 * sendDataPerNode * iCellSize; + break; + case TE: + case BW: + case BE: + case TW: + sendSize = 2 * bMaxX2 * sendDataPerNode * iCellSize; + break; + case TN: + case BS: + case BN: + case TS: + sendSize = 2 * bMaxX1 * sendDataPerNode * iCellSize; + break; + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + sendSize = 6 * bMaxX1 * sendDataPerNode * iCellSize; + break; + default: + throw UbException(UB_EXARGS, "direction not allowed in this constructor"); + } + if (senderEvenEvenSW) + senderEvenEvenSW->getData().resize(sendSize, initValue); + else + senderEvenEvenSW = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (senderEvenOddNW) + senderEvenOddNW->getData().resize(sendSize, initValue); + else + senderEvenOddNW = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (senderOddEvenSE) + senderOddEvenSE->getData().resize(sendSize, initValue); + else + senderOddEvenSE = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (senderOddOddNE) + senderOddOddNE->getData().resize(sendSize, initValue); + else + senderOddOddNE = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + + if (!receiverEvenEvenSW) + receiverEvenEvenSW = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiverEvenOddNW) + receiverEvenOddNW = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiverOddEvenSE) + receiverOddEvenSE = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + if (!receiverOddOddNE) + receiverOddOddNE = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + + // findCFnodes(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::fillSendVectors() +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::fillSendVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - int maxX1 = (int)fFrom->getNX1(); - int maxX2 = (int)fFrom->getNX2(); - int maxX3 = (int)fFrom->getNX3(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int indexEvEv = 0; - int indexEvOd = 0; - int indexOdEv = 0; - int indexOdOd = 0; - - vector_type& dataEvEv = this->senderEvenEvenSW->getData(); - vector_type& dataEvOd = this->senderEvenOddNW->getData(); - vector_type& dataOdEv = this->senderOddEvenSE->getData(); - vector_type& dataOdOd = this->senderOddOddNE->getData(); - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - //int lMinX1_2, lMinX2_2, lMinX3_2, lMaxX1_2, lMaxX2_2, lMaxX3_2; - - //for coners -// int lMinX1W = 1; -// int lMaxX1W = 2; -// -// int lMinX1E = maxX1 - 3; -// int lMaxX1E = maxX1 - 2; -// -// int lMinX2S = 1; -// int lMaxX2S = 2; -// -// int lMinX2N = maxX2 - 3; -// int lMaxX2N = maxX2 - 2; -// -// int lMinX3B = 1; -// int lMaxX3B = 2; -// -// int lMinX3T = maxX3 - 3; -// int lMaxX3T = maxX3 - 2; - - - switch (sendDir) - { - case E: - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 1; - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case W: - /////////////////////////////////////// - ///DEBUG - //if (block.lock()->getGlobalID() == 5780) - //{ - // int test = 0; - //} - ////////////// - lMinX1 = 1; - lMaxX1 = lMinX1 + 1; - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case N: - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 1; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case S: - lMinX2 = 1; - lMaxX2 = lMinX2 + 1; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case T: - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 1; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case B: - lMinX3 = 1; - lMaxX3 = lMinX3 + 1; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - ///N-S-E-W - case NE: - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case SW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case SE: - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case NW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + using namespace D3Q27System; + + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + int maxX1 = (int)fFrom->getNX1(); + int maxX2 = (int)fFrom->getNX2(); + int maxX3 = (int)fFrom->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int indexEvEv = 0; + int indexEvOd = 0; + int indexOdEv = 0; + int indexOdOd = 0; + + vector_type &dataEvEv = this->senderEvenEvenSW->getData(); + vector_type &dataEvOd = this->senderEvenOddNW->getData(); + vector_type &dataOdEv = this->senderOddEvenSE->getData(); + vector_type &dataOdOd = this->senderOddOddNE->getData(); + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + // int lMinX1_2, lMinX2_2, lMinX3_2, lMaxX1_2, lMaxX2_2, lMaxX3_2; + + // for coners + // int lMinX1W = 1; + // int lMaxX1W = 2; + // + // int lMinX1E = maxX1 - 3; + // int lMaxX1E = maxX1 - 2; + // + // int lMinX2S = 1; + // int lMaxX2S = 2; + // + // int lMinX2N = maxX2 - 3; + // int lMaxX2N = maxX2 - 2; + // + // int lMinX3B = 1; + // int lMaxX3B = 2; + // + // int lMinX3T = maxX3 - 3; + // int lMaxX3T = maxX3 - 2; + + switch (sendDir) { + case E: + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 1; + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case W: + /////////////////////////////////////// + /// DEBUG + // if (block.lock()->getGlobalID() == 5780) + //{ + // int test = 0; + //} + ////////////// + lMinX1 = 1; + lMaxX1 = lMinX1 + 1; + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case N: + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 1; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case S: + lMinX2 = 1; + lMaxX2 = lMinX2 + 1; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case T: + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 1; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case B: + lMinX3 = 1; + lMaxX3 = lMinX3 + 1; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + /// N-S-E-W + case NE: + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case SW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case SE: + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; - break; - /////T-B-E-W - case TE: - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; + case NW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + break; + /////T-B-E-W + case TE: + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; - break; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - case BW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + case BW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; - break; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - case BE: - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case TW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; + case BE: + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - //// - /////T-B-N-S - case TN: - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case BS: - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case BN: - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case TS: - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - - //TNE - case TNE: - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // TNW - case TNW: - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // TSE - case TSE: - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // TSW - case TSW: - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BNE - case BNE: - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = 0; - lMaxX3 = 2; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BNW - case BNW: - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = 0; - lMaxX3 = 2; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BSE - case BSE: - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = 0; - lMaxX3 = 2; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BSW - case BSW: - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = 0; - lMaxX3 = 2; - - fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - } + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case TW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + //// + /////T-B-N-S + case TN: + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BS: + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BN: + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case TS: + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, false); + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + // TNE + case TNE: + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // TNW + case TNW: + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // TSE + case TSE: + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // TSW + case TSW: + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BNE + case BNE: + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 2; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BNW + case BNW: + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 2; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BSE + case BSE: + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = 0; + lMaxX3 = 2; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BSW + case BSW: + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = 0; + lMaxX3 = 2; + + fillSendVectorExt(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::getLocalMinMax(const int& gMin, const int& gMax, const bool& even, int& lMin, int& lMax, const bool& dataDistribution) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::getLocalMinMax(const int &gMin, const int &gMax, const bool &even, + int &lMin, int &lMax, const bool &dataDistribution) { - int halfEven = 0; - int halfOdd = 0; - int dCoef = 0; - - if (dataDistribution) - dCoef = 1; - - if (Utilities::isOdd(gMax)) - { - halfEven = gMax / 2; - halfOdd = gMax / 2; - } - if (Utilities::isEven(gMax)) - { - halfEven = gMax / 2; - halfOdd = gMax / 2 - 1 + dCoef; - } - - if(even) - { - lMin = gMin + dCoef; - lMax = lMin + halfEven - dCoef; - } - else - { - lMin = gMin + halfOdd; - lMax = gMax - 1; - } + int halfEven = 0; + int halfOdd = 0; + int dCoef = 0; + + if (dataDistribution) + dCoef = 1; + + if (Utilities::isOdd(gMax)) { + halfEven = gMax / 2; + halfOdd = gMax / 2; + } + if (Utilities::isEven(gMax)) { + halfEven = gMax / 2; + halfOdd = gMax / 2 - 1 + dCoef; + } + + if (even) { + lMin = gMin + dCoef; + lMax = lMin + halfEven - dCoef; + } else { + lMin = gMin + halfOdd; + lMax = gMax - 1; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::fillSendVectorExt(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::fillSendVectorExt(SPtr<DistributionArray3D> fFrom, + const int &lMinX1, const int &lMinX2, + const int &lMinX3, const int &lMaxX1, + const int &lMaxX2, const int &lMaxX3, + vector_type &data, int &index) { - if (data.size() == 0) return; - int ix1, ix2, ix3; - LBMReal xoff, yoff, zoff; - SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); - - for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) - { - for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) - { - for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - - int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); - - if (howManySolids == 0 || howManySolids == 8) - { - iprocessor->readICell(fFrom, icellC, ix1, ix2, ix3); - xoff = 0.0; - yoff = 0.0; - zoff = 0.0; + if (data.size() == 0) + return; + int ix1, ix2, ix3; + LBMReal xoff, yoff, zoff; + SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); + + for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) { + for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) { + for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) { + D3Q27ICell icellC; + D3Q27ICell icellF; + + int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + + if (howManySolids == 0 || howManySolids == 8) { + iprocessor->readICell(fFrom, icellC, ix1, ix2, ix3); + xoff = 0.0; + yoff = 0.0; + zoff = 0.0; + } else { + if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, + xoff, yoff, zoff)) { + std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + + " interpolation is not implemented for other direction" + + " by using in: " + (std::string) typeid(*this).name() + + " or maybe you have a solid on the block boundary"; + UB_THROW(UbException(UB_EXARGS, err)); + } + } + + iprocessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); + this->writeICellFtoData(data, index, icellF); } - else - { - if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, xoff, yoff, zoff)) - { - std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + - " interpolation is not implemented for other direction" + - " by using in: " + (std::string)typeid(*this).name() + - " or maybe you have a solid on the block boundary"; - UB_THROW(UbException(UB_EXARGS, err)); - } - } - - iprocessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); - this->writeICellFtoData(data, index, icellF); - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::writeICellFtoData(vector_type& data, int& index, D3Q27ICell& icellF) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::writeICellFtoData(vector_type &data, int &index, + D3Q27ICell &icellF) { - writeNodeToVector(data, index, icellF.BSW); - writeNodeToVector(data, index, icellF.BSE); - writeNodeToVector(data, index, icellF.BNW); - writeNodeToVector(data, index, icellF.BNE); - writeNodeToVector(data, index, icellF.TSW); - writeNodeToVector(data, index, icellF.TSE); - writeNodeToVector(data, index, icellF.TNW); - writeNodeToVector(data, index, icellF.TNE); + writeNodeToVector(data, index, icellF.BSW); + writeNodeToVector(data, index, icellF.BSE); + writeNodeToVector(data, index, icellF.BNW); + writeNodeToVector(data, index, icellF.BNE); + writeNodeToVector(data, index, icellF.TSW); + writeNodeToVector(data, index, icellF.TSE); + writeNodeToVector(data, index, icellF.TNW); + writeNodeToVector(data, index, icellF.TNE); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::writeNodeToVector(vector_type& data, int& index, LBMReal* inode) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::writeNodeToVector(vector_type &data, int &index, LBMReal *inode) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) - { - data[index++] = inode[i]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + data[index++] = inode[i]; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::distributeReceiveVectors() +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::distributeReceiveVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); - int maxX1 = (int)fTo->getNX1(); - int maxX2 = (int)fTo->getNX2(); - int maxX3 = (int)fTo->getNX3(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int indexEvEv = 0; - int indexEvOd = 0; - int indexOdEv = 0; - int indexOdOd = 0; - - vector_type& dataEvEv = this->receiverEvenEvenSW->getData(); - vector_type& dataEvOd = this->receiverEvenOddNW->getData(); - vector_type& dataOdEv = this->receiverOddEvenSE->getData(); - vector_type& dataOdOd = this->receiverOddOddNE->getData(); - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - int dummy; - - //for coners -// int lMinX1W = 3; -// int lMaxX1W = 3; -// -// int lMinX1E = maxX1 - 3; -// int lMaxX1E = maxX1 - 2; -// -// int lMinX2S = 1; -// int lMaxX2S = 3; -// -// int lMinX2N = maxX2 - 3; -// int lMaxX2N = maxX2 - 2; -// -// int lMinX3B = 1; -// int lMaxX3B = 3; -// -// int lMinX3T = maxX3 - 3; -// int lMaxX3T = maxX3 - 2; - - /////////////////////////////////////// - ///DEBUG - //if (block.lock()->getGlobalID() == 5780) - //{ - // int test = 0; - //} - ////////////// - - switch (sendDir) - { - case E: - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, lMinX2, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case W: - /////////////////////////////////////// - ///DEBUG - //if (block.lock()->getGlobalID() == 5780) - //{ - // int test = 0; - //} - ////////////// - lMinX1 = 3; - lMaxX1 = lMinX1 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, lMinX2, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case N: - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(lMinX1, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case S: - lMinX2 = 3; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(lMinX1, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case T: - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(lMinX1, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - case B: - lMinX3 = 3; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(lMinX1, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - break; - - // /////E-W-N-S - case NE: - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 3; - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 3; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case SW: - lMinX1 = 1; - lMaxX1 = lMinX1 + 3; - lMinX2 = 3; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = 3; - lMaxX1 = lMinX1 + 1; - lMinX2 = 1; - lMaxX2 = lMinX2 + 3; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case SE: - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 3; - lMinX2 = 3; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 1; - lMinX2 = 1; - lMaxX2 = lMinX2 + 3; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case NW: - lMinX1 = 1; - lMaxX1 = lMinX1 + 3; - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 1; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = 3; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 3; - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); - getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - // /////T-B-E-W - case TE: - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 3; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case BW: - lMinX1 = 1; - lMaxX1 = lMinX1 + 3; - lMinX3 = 3; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = 3; - lMaxX1 = lMinX1 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case BE: - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 3; - lMinX3 = 3; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = lMinX1 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case TW: - lMinX1 = 1; - lMaxX1 = lMinX1 + 3; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX1 = 3; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); - getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - /////////////////////////T-N-B-S - case TN: - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 3; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case BS: - lMinX2 = 1; - lMaxX2 = lMinX2 + 3; - lMinX3 = 3; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX2 = 3; - lMaxX2 = lMinX2 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - - case BN: - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 3; - lMinX3 = 3; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX2 = maxX2 - 4; - lMaxX2 = lMinX2 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - case TS: - lMinX2 = 1; - lMaxX2 = lMinX2 + 3; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 1; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - lMinX2 = 3; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3 - 4; - lMaxX3 = lMinX3 + 3; - getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); - getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); - getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - break; - - //TNE - case TNE: - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 3; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 3; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - break; - // TNW - case TNW: - lMinX1 = 3; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 3; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - break; - // TSE - case TSE: - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 3; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = 3; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // TSW - case TSW: - lMinX1 = 3; - lMaxX1 = 4; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = 3; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = maxX3 - 4; - lMaxX3 = maxX3 - 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BNE - case BNE: - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 3; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 3; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = 3; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - break; - // BNW - case BNW: - lMinX1 = 3; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 3; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = maxX2 - 4; - lMaxX2 = maxX2 - 1; - lMinX3 = 3; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BSE - case BSE: - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 3; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = 3; - lMaxX2 = 4; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = maxX1 - 4; - lMaxX1 = maxX1 - 1; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = 3; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - break; - // BSW - case BSW: - lMinX1 = 3; - lMaxX1 = 4; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = 3; - lMaxX2 = 4; - lMinX3 = 1; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - lMinX1 = 1; - lMaxX1 = 4; - lMinX2 = 1; - lMaxX2 = 4; - lMinX3 = 3; - lMaxX3 = 4; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - break; - } + using namespace D3Q27System; + + SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); + int maxX1 = (int)fTo->getNX1(); + int maxX2 = (int)fTo->getNX2(); + int maxX3 = (int)fTo->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int indexEvEv = 0; + int indexEvOd = 0; + int indexOdEv = 0; + int indexOdOd = 0; + + vector_type &dataEvEv = this->receiverEvenEvenSW->getData(); + vector_type &dataEvOd = this->receiverEvenOddNW->getData(); + vector_type &dataOdEv = this->receiverOddEvenSE->getData(); + vector_type &dataOdOd = this->receiverOddOddNE->getData(); + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + int dummy; + + // for coners + // int lMinX1W = 3; + // int lMaxX1W = 3; + // + // int lMinX1E = maxX1 - 3; + // int lMaxX1E = maxX1 - 2; + // + // int lMinX2S = 1; + // int lMaxX2S = 3; + // + // int lMinX2N = maxX2 - 3; + // int lMaxX2N = maxX2 - 2; + // + // int lMinX3B = 1; + // int lMaxX3B = 3; + // + // int lMinX3T = maxX3 - 3; + // int lMaxX3T = maxX3 - 2; + + /////////////////////////////////////// + /// DEBUG + // if (block.lock()->getGlobalID() == 5780) + //{ + // int test = 0; + //} + ////////////// + + switch (sendDir) { + case E: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, lMinX2, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case W: + /////////////////////////////////////// + /// DEBUG + // if (block.lock()->getGlobalID() == 5780) + //{ + // int test = 0; + //} + ////////////// + lMinX1 = 3; + lMaxX1 = lMinX1 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, lMinX2, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case N: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(lMinX1, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case S: + lMinX2 = 3; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(lMinX1, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case T: + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(lMinX1, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + case B: + lMinX3 = 3; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(lMinX1, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + break; + + // /////E-W-N-S + case NE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case SW: + lMinX1 = 1; + lMaxX1 = lMinX1 + 3; + lMinX2 = 3; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = 3; + lMaxX1 = lMinX1 + 1; + lMinX2 = 1; + lMaxX2 = lMinX2 + 3; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case SE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX2 = 3; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + lMinX2 = 1; + lMaxX2 = lMinX2 + 3; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case NW: + lMinX1 = 1; + lMaxX1 = lMinX1 + 3; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = 3; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, lMinX3, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, true); + getLocalMinMax(dummy, dummy, dummy, dummy, dummy, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + // /////T-B-E-W + case TE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BW: + lMinX1 = 1; + lMaxX1 = lMinX1 + 3; + lMinX3 = 3; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = 3; + lMaxX1 = lMinX1 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX3 = 3; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case TW: + lMinX1 = 1; + lMaxX1 = lMinX1 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX1 = 3; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, lMinX2, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, true); + getLocalMinMax(dummy, dummy, dummy, dummy, lMaxX2, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + /////////////////////////T-N-B-S + case TN: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BS: + lMinX2 = 1; + lMaxX2 = lMinX2 + 3; + lMinX3 = 3; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX2 = 3; + lMaxX2 = lMinX2 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case BN: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + lMinX3 = 3; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + case TS: + lMinX2 = 1; + lMaxX2 = lMinX2 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + lMinX2 = 3; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMax(minX1, maxX1, true, lMinX1, lMaxX1, true); + getLocalMinMax(lMinX1, dummy, dummy, dummy, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1, maxX1, false, lMinX1, lMaxX1, true); + getLocalMinMax(dummy, dummy, dummy, lMaxX1, dummy, dummy); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + break; + + // TNE + case TNE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 3; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 3; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + break; + // TNW + case TNW: + lMinX1 = 3; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 3; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + break; + // TSE + case TSE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 3; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 3; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // TSW + case TSW: + lMinX1 = 3; + lMaxX1 = 4; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = 3; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BNE + case BNE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 3; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 3; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 3; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + break; + // BNW + case BNW: + lMinX1 = 3; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 3; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 3; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BSE + case BSE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 3; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 3; + lMaxX2 = 4; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = 3; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + break; + // BSW + case BSW: + lMinX1 = 3; + lMaxX1 = 4; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = 3; + lMaxX2 = 4; + lMinX3 = 1; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + lMinX1 = 1; + lMaxX1 = 4; + lMinX2 = 1; + lMaxX2 = 4; + lMinX3 = 3; + lMaxX3 = 4; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + break; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::distributeReceiveVector(SPtr<DistributionArray3D> fTo, + const int &lMinX1, const int &lMinX2, + const int &lMinX3, const int &lMaxX1, + const int &lMaxX2, const int &lMaxX3, + vector_type &data, int &index) { - if (data.size() == 0) return; - - int ix1, ix2, ix3; - for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) - { - for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) - { - for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) - { - LBMReal icellC[27]; - this->readICellCfromData(data, index, icellC); - iprocessor->writeINodeInv(fTo, icellC, ix1, ix2, ix3); - } - } - } + if (data.size() == 0) + return; + + int ix1, ix2, ix3; + for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) { + for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) { + for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) { + LBMReal icellC[27]; + this->readICellCfromData(data, index, icellC); + iprocessor->writeINodeInv(fTo, icellC, ix1, ix2, ix3); + } + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::readICellCfromData(vector_type& data, int& index, LBMReal* icellC) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::readICellCfromData(vector_type &data, int &index, LBMReal *icellC) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) - { - icellC[i] = data[index++]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + icellC[i] = data[index++]; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, + int &maxX2, int &maxX3) { - using namespace D3Q27System; - int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = maxX3; - - if (block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1 == TminX1) minX1 += 2; - } - if (block.lock()->hasInterpolationFlagCF(N)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(S)) - { - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(B)) - { - if (minX3 == TminX3) minX3 += 2; - } - - //E-W-N-S - if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (maxX2 == TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (minX1 == TminX1) minX1 += 2; - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1 == TminX1) minX1 += 2; - if (maxX2 == TmaxX2) maxX2 -= 2; - } - - // ////T-B-E-W - if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX1 == TminX1) minX1 += 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX1 == TminX1) minX1 += 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - - - ////T-B-N-S - if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX2 == TminX2) minX2 += 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX2 == TminX2) minX2 += 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - - //if (block.lock()->hasInterpolationFlagCF(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::N) && !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) - //if (!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&& !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) - //{ - // if (maxX1==TmaxX1) maxX1 -= 2; - // if (maxX2==TmaxX2) maxX2 -= 2; - // if (maxX3==TmaxX3) maxX3 -= 2; - //} + using namespace D3Q27System; + int TminX1 = minX1; + int TminX2 = minX2; + int TminX3 = minX3; + int TmaxX1 = maxX1; + int TmaxX2 = maxX2; + int TmaxX3 = maxX3; + + if (block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + } + if (block.lock()->hasInterpolationFlagCF(N)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(S)) { + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(T)) { + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(B)) { + if (minX3 == TminX3) + minX3 += 2; + } + + // E-W-N-S + if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + + // ////T-B-E-W + if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + + ////T-B-N-S + if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX2 == TminX2) + minX2 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX2 == TminX2) + minX2 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + + // if + // (block.lock()->hasInterpolationFlagCF(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::N) + // && !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) if + // (!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&& + // !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) + //{ + // if (maxX1==TmaxX1) maxX1 -= 2; + // if (maxX2==TmaxX2) maxX2 -= 2; + // if (maxX3==TmaxX3) maxX3 -= 2; + //} } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3, CFconnectorType /*connType*/) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, + int &maxX2, int &maxX3, + CFconnectorType /*connType*/) { - using namespace D3Q27System; - int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = maxX3; - - if (block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1 == TminX1) minX1 += 2; - } - if (block.lock()->hasInterpolationFlagCF(N)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(S)) - { - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(B)) - { - if (minX3 == TminX3) minX3 += 2; - } - - //E-W-N-S - if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(E)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (maxX2 == TmaxX2) maxX2 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (minX1 == TminX1) minX1 += 2; - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(S)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (minX2 == TminX2) minX2 += 2; - } - if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(W)) - { - if (minX1 == TminX1) minX1 += 2; - if (maxX2 == TmaxX2) maxX2 -= 2; - } - - // ////T-B-E-W - if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX1 == TminX1) minX1 += 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX1 == TmaxX1) maxX1 -= 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX1 == TminX1) minX1 += 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - - - ////T-B-N-S - if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (minX2 == TminX2) minX2 += 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(B)) - { - if (maxX2 == TmaxX2) maxX2 -= 2; - if (minX3 == TminX3) minX3 += 2; - } - if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && !block.lock()->hasInterpolationFlagCF(T)) - { - if (minX2 == TminX2) minX2 += 2; - if (maxX3 == TmaxX3) maxX3 -= 2; - } - - //if (block.lock()->hasInterpolationFlagCF(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::N) && !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) - //{ - // if (maxX1==TmaxX1) maxX1 -= 2; - // if (maxX2==TmaxX2) maxX2 -= 2; - // if (maxX3==TmaxX3) maxX3 -= 2; - //} + using namespace D3Q27System; + int TminX1 = minX1; + int TminX2 = minX2; + int TminX3 = minX3; + int TmaxX1 = maxX1; + int TmaxX2 = maxX2; + int TmaxX3 = maxX3; + + if (block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + } + if (block.lock()->hasInterpolationFlagCF(N)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(S)) { + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(T)) { + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(B)) { + if (minX3 == TminX3) + minX3 += 2; + } + + // E-W-N-S + if (block.lock()->hasInterpolationFlagCF(NE) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(SW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(SE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(S)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX2 == TminX2) + minX2 += 2; + } + if (block.lock()->hasInterpolationFlagCF(NW) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(W)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX2 == TmaxX2) + maxX2 -= 2; + } + + // ////T-B-E-W + if (block.lock()->hasInterpolationFlagCF(TE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX1 == TminX1) + minX1 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BE) && !block.lock()->hasInterpolationFlagCF(E) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX1 == TmaxX1) + maxX1 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TW) && !block.lock()->hasInterpolationFlagCF(W) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX1 == TminX1) + minX1 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + + ////T-B-N-S + if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + if (block.lock()->hasInterpolationFlagCF(BS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (minX2 == TminX2) + minX2 += 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(BN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(B)) { + if (maxX2 == TmaxX2) + maxX2 -= 2; + if (minX3 == TminX3) + minX3 += 2; + } + if (block.lock()->hasInterpolationFlagCF(TS) && !block.lock()->hasInterpolationFlagCF(S) && + !block.lock()->hasInterpolationFlagCF(T)) { + if (minX2 == TminX2) + minX2 += 2; + if (maxX3 == TmaxX3) + maxX3 -= 2; + } + + // if + // (block.lock()->hasInterpolationFlagCF(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::T)&&!block.lock()->hasInterpolationFlagCF(D3Q27System::N) + // && !block.lock()->hasInterpolationFlagCF(D3Q27System::E)) + //{ + // if (maxX1==TmaxX1) maxX1 -= 2; + // if (maxX2==TmaxX2) maxX2 -= 2; + // if (maxX3==TmaxX3) maxX3 -= 2; + //} } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::findCFnodes() +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::findCFnodes() { - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - int maxX1 = (int)fFrom->getNX1(); - int maxX2 = (int)fFrom->getNX2(); - int maxX3 = (int)fFrom->getNX3(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int indexEvEv = 0; - int indexEvOd = 0; - int indexOdEv = 0; - int indexOdOd = 0; - - vector_type& dataEvEv = this->senderEvenEvenSW->getData(); - vector_type& dataEvOd = this->senderEvenOddNW->getData(); - vector_type& dataOdEv = this->senderOddEvenSE->getData(); - vector_type& dataOdOd = this->senderOddOddNE->getData(); - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - - using namespace D3Q27System; - if (block.lock()->hasInterpolationFlagCF(W)) - { - lMinX1 = 1; - lMaxX1 = lMinX1 + 1; - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - - getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); - getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); - } - if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && !block.lock()->hasInterpolationFlagCF(T)) - { - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 1; - - getLocalMinMax(minX1 + 1, maxX1, true, lMinX1, lMaxX1, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); - - getLocalMinMax(minX1 + 1, maxX1, false, lMinX1, lMaxX1, false); - findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); - } + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + int maxX1 = (int)fFrom->getNX1(); + int maxX2 = (int)fFrom->getNX2(); + int maxX3 = (int)fFrom->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int indexEvEv = 0; + int indexEvOd = 0; + int indexOdEv = 0; + int indexOdOd = 0; + + vector_type &dataEvEv = this->senderEvenEvenSW->getData(); + vector_type &dataEvOd = this->senderEvenOddNW->getData(); + vector_type &dataOdEv = this->senderOddEvenSE->getData(); + vector_type &dataOdOd = this->senderOddOddNE->getData(); + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + + using namespace D3Q27System; + if (block.lock()->hasInterpolationFlagCF(W)) { + lMinX1 = 1; + lMaxX1 = lMinX1 + 1; + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX2, maxX2, true, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvOd, indexEvOd); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, true, lMinX3, lMaxX3, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + + getLocalMinMax(minX2, maxX2, false, lMinX2, lMaxX2, false); + getLocalMinMax(minX3, maxX3, false, lMinX3, lMaxX3, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdOd, indexOdOd); + } + if (block.lock()->hasInterpolationFlagCF(TN) && !block.lock()->hasInterpolationFlagCF(N) && + !block.lock()->hasInterpolationFlagCF(T)) { + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 1; + + getLocalMinMax(minX1 + 1, maxX1, true, lMinX1, lMaxX1, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataEvEv, indexEvEv); + + getLocalMinMax(minX1 + 1, maxX1, false, lMinX1, lMaxX1, false); + findCFnodes(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, dataOdEv, indexOdEv); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETCFOffVectorConnector< VectorTransmitter>::findCFnodes(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index) +template <typename VectorTransmitter> +void D3Q27ETCFOffVectorConnector<VectorTransmitter>::findCFnodes(SPtr<DistributionArray3D> fFrom, const int &lMinX1, + const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, + const int &lMaxX3, vector_type &data, int &index) { - if (data.size() == 0) return; - int ix1, ix2, ix3; - LBMReal xoff, yoff, zoff; - SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); - - for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) - { - for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) - { - for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - - int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); - - if (howManySolids == 0 || howManySolids == 8) - { - iprocessor->readICell(fFrom, icellC, ix1, ix2, ix3); - xoff = 0.0; - yoff = 0.0; - zoff = 0.0; - } - else - { - if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, xoff, yoff, zoff)) - { - std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + - " interpolation is not implemented for other direction" + - " by using in: " + (std::string)typeid(*this).name() + - " or maybe you have a solid on the block boundary"; - //UBLOG(logINFO, err); - UB_THROW(UbException(UB_EXARGS, err)); - } + if (data.size() == 0) + return; + int ix1, ix2, ix3; + LBMReal xoff, yoff, zoff; + SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); + + for (ix3 = lMinX3; ix3 < lMaxX3; ix3++) { + for (ix2 = lMinX2; ix2 < lMaxX2; ix2++) { + for (ix1 = lMinX1; ix1 < lMaxX1; ix1++) { + D3Q27ICell icellC; + D3Q27ICell icellF; + + int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + + if (howManySolids == 0 || howManySolids == 8) { + iprocessor->readICell(fFrom, icellC, ix1, ix2, ix3); + xoff = 0.0; + yoff = 0.0; + zoff = 0.0; + } else { + if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, + xoff, yoff, zoff)) { + std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + + " interpolation is not implemented for other direction" + + " by using in: " + (std::string) typeid(*this).name() + + " or maybe you have a solid on the block boundary"; + // UBLOG(logINFO, err); + UB_THROW(UbException(UB_EXARGS, err)); + } + } + + iprocessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); + this->writeICellFtoData(data, index, icellF); + // for (int iix3 = ix3; iix3<=ix3+1; iix3++) + //{ + // for (int iix2 = ix2; iix2<=ix2+1; iix2++) + // { + // for (int iix1 = ix1; iix1<=ix1+1; iix1++) + // { + // bcArray->setInterfaceCF(iix1, iix2, iix3); + // } + // } + //} } - - iprocessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); - this->writeICellFtoData(data, index, icellF); - //for (int iix3 = ix3; iix3<=ix3+1; iix3++) - //{ - // for (int iix2 = ix2; iix2<=ix2+1; iix2++) - // { - // for (int iix1 = ix1; iix1<=ix1+1; iix1++) - // { - // bcArray->setInterfaceCF(iix1, iix2, iix3); - // } - // } - //} - - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> double D3Q27ETCFOffVectorConnector<VectorTransmitter>::getSendRecieveTime() { - return 0; + return 0; } -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.cpp index f745d7597..128c7819f 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.cpp @@ -1,3 +1 @@ #include "D3Q27ETFCOffVectorConnector.h" - - diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.h b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.h index 14acb11e5..63084e6a3 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFCOffVectorConnector.h @@ -1,23 +1,23 @@ /** -* @file D3Q27ETFCOffVectorConnector.h -* @class D3Q27ETFCVectorConnector -* @brief Interpolation from fine level to coarse. -* @author Kostyantyn Kucher and Ehsan Fard -* @date 08.06.2011 -*/ + * @file D3Q27ETFCOffVectorConnector.h + * @class D3Q27ETFCVectorConnector + * @brief Interpolation from fine level to coarse. + * @author Kostyantyn Kucher and Ehsan Fard + * @date 08.06.2011 + */ #ifndef D3Q27ETFCOffVectorConnector_H #define D3Q27ETFCOffVectorConnector_H #include <vector> -#include "basics/transmitter/TbTransmitter.h" +#include "Block3D.h" #include "Block3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" #include "Grid3D.h" -#include "LBMKernel.h" #include "InterpolationProcessor.h" +#include "LBMKernel.h" #include "MathUtil.hpp" +#include "basics/transmitter/TbTransmitter.h" #include <PointerDefinitions.h> #include "BCProcessor.h" @@ -25,1413 +25,1521 @@ class Block3D; -enum CFconnectorType {EvenOddNW, EvenEvenSW, OddEvenSE, OddOddNE}; +enum CFconnectorType { EvenOddNW, EvenEvenSW, OddEvenSE, OddOddNE }; -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) -template< typename VectorTransmitter > +template <typename VectorTransmitter> class D3Q27ETFCOffVectorConnector : public Block3DConnector { public: - protected: - using vector_type = typename VectorTransmitter::value_type; - using VectorTransmitterPtr = SPtr<VectorTransmitter>; + using vector_type = typename VectorTransmitter::value_type; + using VectorTransmitterPtr = SPtr<VectorTransmitter>; + public: - D3Q27ETFCOffVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, int sendDir, - InterpolationProcessorPtr iprocessor, CFconnectorType connType); + D3Q27ETFCOffVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType); - bool isLocalConnector() override; - bool isRemoteConnector() override; - void init() override; + bool isLocalConnector() override; + bool isRemoteConnector() override; + void init() override; - void sendTransmitterDataSize() override; - void receiveTransmitterDataSize() override; + void sendTransmitterDataSize() override; + void receiveTransmitterDataSize() override; - void prepareForSend() override; - void sendVectors() override; + void prepareForSend() override; + void sendVectors() override; - void prepareForReceive() override; - void receiveVectors() override; + void prepareForReceive() override; + void receiveVectors() override; - void fillSendVectors() override; - void distributeReceiveVectors() override; + void fillSendVectors() override; + void distributeReceiveVectors() override; - bool isInterpolationConnectorCF() override { return false; } - bool isInterpolationConnectorFC() override { return true; } + bool isInterpolationConnectorCF() override { return false; } + bool isInterpolationConnectorFC() override { return true; } - double getSendRecieveTime(); + double getSendRecieveTime(); - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override{} - void sendVectorsX2() override{} - void sendVectorsX3() override{} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> block; //dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet - //gegenstelle muss "inversen" connector besitzen - VectorTransmitterPtr sender, receiver; - - InterpolationProcessorPtr iprocessor; - - CFconnectorType connType; - - void writeICellCtoData(vector_type& data, int& index, LBMReal* icellC); - void writeNodeToVector(vector_type& data, int& index, LBMReal* inode); - void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3); - void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3, CFconnectorType connType); - void getLocalMinMaxCF(int gMax, int& lMin, int& lMax); - void fillSendVector(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index); - - void distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index); - void readICellFfromData(vector_type& data, int& index, D3Q27ICell& icellF); - void readNodeFromVector(vector_type& data, int& index, LBMReal* inode); - void getLocalOffsets(const int& gMax, int& oMin); - void getLocalMins(int& minX1, int& minX2, int& minX3, const int& oMinX1, const int& oMinX2, const int& oMinX3); - - int bMaxX1, bMaxX2, bMaxX3; + WPtr<Block3D> block; // dieser nvd sendet daten und die empfangenen werden diesem nvd zugeordnet + // gegenstelle muss "inversen" connector besitzen + VectorTransmitterPtr sender, receiver; + + InterpolationProcessorPtr iprocessor; + + CFconnectorType connType; + + void writeICellCtoData(vector_type &data, int &index, LBMReal *icellC); + void writeNodeToVector(vector_type &data, int &index, LBMReal *inode); + void getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, int &maxX3); + void getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, int &maxX2, int &maxX3, + CFconnectorType connType); + void getLocalMinMaxCF(int gMax, int &lMin, int &lMax); + void fillSendVector(SPtr<DistributionArray3D> fFrom, const int &lMinX1, const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, const int &lMaxX3, vector_type &data, int &index); + + void distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int &lMinX1, const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, const int &lMaxX3, vector_type &data, + int &index); + void readICellFfromData(vector_type &data, int &index, D3Q27ICell &icellF); + void readNodeFromVector(vector_type &data, int &index, LBMReal *inode); + void getLocalOffsets(const int &gMax, int &oMin); + void getLocalMins(int &minX1, int &minX2, int &minX3, const int &oMinX1, const int &oMinX2, const int &oMinX3); + + int bMaxX1, bMaxX2, bMaxX3; }; //////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -D3Q27ETFCOffVectorConnector<VectorTransmitter>::D3Q27ETFCOffVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, int sendDir, - InterpolationProcessorPtr iprocessor, - CFconnectorType connType) - : Block3DConnector(sendDir) - , block(block) - , sender(sender) - , receiver(receiver) - , iprocessor(iprocessor) - , connType(connType) +template <typename VectorTransmitter> +D3Q27ETFCOffVectorConnector<VectorTransmitter>::D3Q27ETFCOffVectorConnector(SPtr<Block3D> block, + VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir, + InterpolationProcessorPtr iprocessor, + CFconnectorType connType) + : Block3DConnector(sendDir), block(block), sender(sender), receiver(receiver), iprocessor(iprocessor), + connType(connType) { - if( !( sendDir==D3Q27System::E || sendDir==D3Q27System::W || sendDir==D3Q27System::N || sendDir==D3Q27System::S || sendDir==D3Q27System::T || sendDir==D3Q27System::B - || sendDir==D3Q27System::NE || sendDir==D3Q27System::SW || sendDir==D3Q27System::SE || sendDir==D3Q27System::NW - || sendDir==D3Q27System::TE || sendDir==D3Q27System::BW || sendDir==D3Q27System::BE || sendDir==D3Q27System::TW - || sendDir==D3Q27System::TN || sendDir==D3Q27System::BS || sendDir==D3Q27System::BN || sendDir==D3Q27System::TS - - || sendDir==D3Q27System::TNE || sendDir==D3Q27System::TNW || sendDir==D3Q27System::TSE || sendDir==D3Q27System::TSW - || sendDir==D3Q27System::BNE || sendDir==D3Q27System::BNW || sendDir==D3Q27System::BSE || sendDir==D3Q27System::BSW - - ) ) - { - throw UbException(UB_EXARGS,"invalid constructor for this direction"); - } + if (!(sendDir == D3Q27System::E || sendDir == D3Q27System::W || sendDir == D3Q27System::N || + sendDir == D3Q27System::S || sendDir == D3Q27System::T || sendDir == D3Q27System::B || + sendDir == D3Q27System::NE || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE || + sendDir == D3Q27System::NW || sendDir == D3Q27System::TE || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE || sendDir == D3Q27System::TW || sendDir == D3Q27System::TN || + sendDir == D3Q27System::BS || sendDir == D3Q27System::BN || sendDir == D3Q27System::TS + + || sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSE || + sendDir == D3Q27System::TSW || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSE || sendDir == D3Q27System::BSW + + )) { + throw UbException(UB_EXARGS, "invalid constructor for this direction"); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> bool D3Q27ETFCOffVectorConnector<VectorTransmitter>::isLocalConnector() -{ - return !this->isRemoteConnector(); +{ + return !this->isRemoteConnector(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -bool D3Q27ETFCOffVectorConnector<VectorTransmitter>::isRemoteConnector() -{ - return sender->isRemoteTransmitter() || receiver->isRemoteTransmitter(); +template <typename VectorTransmitter> +bool D3Q27ETFCOffVectorConnector<VectorTransmitter>::isRemoteConnector() +{ + return sender->isRemoteTransmitter() || receiver->isRemoteTransmitter(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize() -{ - if(sender) - { - UBLOG(logDEBUG5, "D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()"<<block.lock()->toString()+"sendDir="<<sendDir); - sender->sendDataSize(); - } +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize() +{ + if (sender) { + UBLOG(logDEBUG5, "D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendTransmitterDataSize()" + << block.lock()->toString() + "sendDir=" << sendDir); + sender->sendDataSize(); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETFCOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize() -{ - if(receiver) - { - UBLOG(logDEBUG5, "D3Q27ETFCOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()"<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver->receiveDataSize(); - } +{ + if (receiver) { + UBLOG(logDEBUG5, "D3Q27ETFCOffVectorConnector<VectorTransmitter>::receiveTransmitterDataSize()" + << block.lock()->toString() << "sendDir=" << sendDir); + receiver->receiveDataSize(); + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETFCOffVectorConnector<VectorTransmitter>::prepareForSend() -{ - if(sender) sender->prepareForSend(); +{ + if (sender) + sender->prepareForSend(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendVectors() -{ - if(sender) sender->sendData(); +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::sendVectors() +{ + if (sender) + sender->sendData(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector<VectorTransmitter>::prepareForReceive() -{ - if(receiver) receiver->prepareForReceive(); +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::prepareForReceive() +{ + if (receiver) + receiver->prepareForReceive(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector<VectorTransmitter>::receiveVectors() -{ - if(receiver) receiver->receiveData(); +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::receiveVectors() +{ + if (receiver) + receiver->receiveData(); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> void D3Q27ETFCOffVectorConnector<VectorTransmitter>::init() { - using namespace D3Q27System; - - bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); - bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); - bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); - - int sendSize = 0; - LBMReal initValue = -999.0; - - int sendDataPerNode = 27/*f*/; - int iCellSize = 1; //size of interpolation cell - - switch(this->sendDir) - { - case E : case W : sendSize = (bMaxX2-1)/2*(bMaxX3-1)/2*sendDataPerNode*iCellSize; break; - case N : case S : sendSize = (bMaxX1-1)/2*(bMaxX3-1)/2*sendDataPerNode*iCellSize; break; - case T : case B : sendSize = (bMaxX1-1)/2*(bMaxX2-1)/2*sendDataPerNode*iCellSize; break; - case NE : case SW :case SE : case NW : sendSize = (3*bMaxX3-3)*sendDataPerNode*iCellSize; break; // buffer overhead, should be (3*bMaxX3-6) for even bMax3 - case TE : case BW :case BE : case TW : sendSize = (3*bMaxX2-3)*sendDataPerNode*iCellSize; break; - case TN : case BS :case BN : case TS : sendSize = (3*bMaxX1-3)*sendDataPerNode*iCellSize; break; - case TNE: case TNW:case TSE: case TSW:case BNE: case BNW:case BSE: case BSW: sendSize = 3*(3*bMaxX1-3)*sendDataPerNode*iCellSize; break; - default: throw UbException(UB_EXARGS,"direction not allowed in this constructor"); - } - sender->getData().resize(sendSize, initValue); + using namespace D3Q27System; + + bMaxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); + bMaxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); + bMaxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); + + int sendSize = 0; + LBMReal initValue = -999.0; + + int sendDataPerNode = 27 /*f*/; + int iCellSize = 1; // size of interpolation cell + + switch (this->sendDir) { + case E: + case W: + sendSize = (bMaxX2 - 1) / 2 * (bMaxX3 - 1) / 2 * sendDataPerNode * iCellSize; + break; + case N: + case S: + sendSize = (bMaxX1 - 1) / 2 * (bMaxX3 - 1) / 2 * sendDataPerNode * iCellSize; + break; + case T: + case B: + sendSize = (bMaxX1 - 1) / 2 * (bMaxX2 - 1) / 2 * sendDataPerNode * iCellSize; + break; + case NE: + case SW: + case SE: + case NW: + sendSize = (3 * bMaxX3 - 3) * sendDataPerNode * iCellSize; + break; // buffer overhead, should be (3*bMaxX3-6) for even bMax3 + case TE: + case BW: + case BE: + case TW: + sendSize = (3 * bMaxX2 - 3) * sendDataPerNode * iCellSize; + break; + case TN: + case BS: + case BN: + case TS: + sendSize = (3 * bMaxX1 - 3) * sendDataPerNode * iCellSize; + break; + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + sendSize = 3 * (3 * bMaxX1 - 3) * sendDataPerNode * iCellSize; + break; + default: + throw UbException(UB_EXARGS, "direction not allowed in this constructor"); + } + sender->getData().resize(sendSize, initValue); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::fillSendVectors() -{ - using namespace D3Q27System; - - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - int maxX1 = (int)fFrom->getNX1(); - int maxX2 = (int)fFrom->getNX2(); - int maxX3 = (int)fFrom->getNX3(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int oMinX1, oMinX2, oMinX3; - getLocalOffsets(maxX1, oMinX1); - getLocalOffsets(maxX2, oMinX2); - getLocalOffsets(maxX3, oMinX3); - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - int index = 0; - vector_type& data = sender->getData(); - - lMinX1 = minX1+1; lMinX2 = minX2+1; lMinX3 = minX3+1; - lMaxX1 = maxX1-2; lMaxX2 = maxX2-2; lMaxX3 = maxX3-2; - - /////////////////////////////////////// - ///DEBUG +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::fillSendVectors() +{ + using namespace D3Q27System; + + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + int maxX1 = (int)fFrom->getNX1(); + int maxX2 = (int)fFrom->getNX2(); + int maxX3 = (int)fFrom->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int oMinX1, oMinX2, oMinX3; + getLocalOffsets(maxX1, oMinX1); + getLocalOffsets(maxX2, oMinX2); + getLocalOffsets(maxX3, oMinX3); + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + int index = 0; + vector_type &data = sender->getData(); + + lMinX1 = minX1 + 1; + lMinX2 = minX2 + 1; + lMinX3 = minX3 + 1; + lMaxX1 = maxX1 - 2; + lMaxX2 = maxX2 - 2; + lMaxX3 = maxX3 - 2; + + /////////////////////////////////////// + /// DEBUG #ifdef _DEBUG - //if (block.lock()->getGlobalID() == 2558) - //{ - // int test = 0; - //} + // if (block.lock()->getGlobalID() == 2558) + //{ + // int test = 0; + //} #endif - ////////////// - - switch(sendDir) - { - case E: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case W: - /////////////////////////////////////// - ///DEBUG + ////////////// + + switch (sendDir) { + case E: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case W: + /////////////////////////////////////// + /// DEBUG #ifdef _DEBUG - //if (block.lock()->getGlobalID() == 2516) - //{ - // int test = 0; - //} + // if (block.lock()->getGlobalID() == 2516) + //{ + // int test = 0; + //} #endif - ////////////// - //getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, none); - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = 5; - lMaxX1 = lMinX1 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case N: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case S: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = 5; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case T: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case B: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX3 = 5; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - // ////N-S-E-W - case NE: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 +5; - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case SW: - - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = 1; - lMaxX1 = lMinX1 + 5; - lMinX2 = 5; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 5; - lMaxX1 = lMinX1 + 1; - lMinX2 = 1; - lMaxX2 = lMinX2 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case SE: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 +5; - lMinX2 = 5; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 + 1; - lMinX2 = 1; - lMaxX2 = lMinX2 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - - case NW: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = 1; - lMaxX1 = lMinX1 + 5; - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 5; - lMaxX1 = lMinX1 + 1; - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; -//////T-B-E-W - case TE: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 +5; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BW: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = 1; - lMaxX1 = lMinX1 + 5; - lMinX3 = 5; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 5; - lMaxX1 = lMinX1 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BE: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 +5; - lMinX3 = 5; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = lMinX1 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case TW: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX1 = 1; - lMaxX1 = lMinX1 + 5; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 5; - lMaxX1 = lMinX1 + 1; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; -///////////////T-B-N-S -// - case TN: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 5; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BS: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = 1; - lMaxX2 = lMinX2 + 5; - lMinX3 = 5; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX2 = 5; - lMaxX2 = lMinX2 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BN: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 5; - lMinX3 = 5; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX2 = maxX2-7; - lMaxX2 = lMinX2 + 1; - lMinX3 = 1; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case TS: - getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); - getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); - lMinX2 = 1; - lMaxX2 = lMinX2 + 5; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 1; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX2 = 5; - lMaxX2 = lMinX2 + 1; - lMinX3 = maxX3-7; - lMaxX3 = lMinX3 + 5; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - //TNE - case TNE: - lMinX1 = maxX1-7; - lMaxX1 = maxX1-6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - - //TNW - case TNW: - lMinX1 = 5; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - break; - - // TSE - case TSE: - lMinX1 = maxX1-7; - lMaxX1 = maxX1-6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = 5; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - // TSW - case TSW: - lMinX1 = 5; - lMaxX1 = 6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = 5; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-2; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = maxX3-7; - lMaxX3 = maxX3-6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - // BNE - case BNE: - lMinX1 = maxX1-7; - lMaxX1 = maxX1-6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = 5; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - // BNW - case BNW: - lMinX1 = 5; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = maxX2-7; - lMaxX2 = maxX2-2; - lMinX3 = 5; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - - - // BSE - case BSE: - lMinX1 = maxX1-7; - lMaxX1 = maxX1-6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = 5; - lMaxX2 = 6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = maxX1-7; - lMaxX1 = maxX1-2; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = 5; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - - //BSW - case BSW: - lMinX1 = 5; - lMaxX1 = 6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = 5; - lMaxX2 = 6; - lMinX3 = 1; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - lMinX1 = 1; - lMaxX1 = 6; - lMinX2 = 1; - lMaxX2 = 6; - lMinX3 = 5; - lMaxX3 = 6; - fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - - break; - } + ////////////// + // getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, none); + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = 5; + lMaxX1 = lMinX1 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case N: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case S: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = 5; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case T: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case B: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX3 = 5; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + // ////N-S-E-W + case NE: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 5; + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case SW: + + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = 1; + lMaxX1 = lMinX1 + 5; + lMinX2 = 5; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 5; + lMaxX1 = lMinX1 + 1; + lMinX2 = 1; + lMaxX2 = lMinX2 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case SE: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 5; + lMinX2 = 5; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 1; + lMinX2 = 1; + lMaxX2 = lMinX2 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + + case NW: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = 1; + lMaxX1 = lMinX1 + 5; + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 5; + lMaxX1 = lMinX1 + 1; + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + //////T-B-E-W + case TE: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 5; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BW: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = 1; + lMaxX1 = lMinX1 + 5; + lMinX3 = 5; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 5; + lMaxX1 = lMinX1 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BE: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 5; + lMinX3 = 5; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = lMinX1 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case TW: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX1 = 1; + lMaxX1 = lMinX1 + 5; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 5; + lMaxX1 = lMinX1 + 1; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + ///////////////T-B-N-S + // + case TN: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 5; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BS: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = 1; + lMaxX2 = lMinX2 + 5; + lMinX3 = 5; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX2 = 5; + lMaxX2 = lMinX2 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BN: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 5; + lMinX3 = 5; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX2 = maxX2 - 7; + lMaxX2 = lMinX2 + 1; + lMinX3 = 1; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case TS: + getLocalMinMax(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3); + getLocalMins(lMinX1, lMinX2, lMinX3, oMinX1, oMinX2, oMinX3); + lMinX2 = 1; + lMaxX2 = lMinX2 + 5; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 1; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX2 = 5; + lMaxX2 = lMinX2 + 1; + lMinX3 = maxX3 - 7; + lMaxX3 = lMinX3 + 5; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + // TNE + case TNE: + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + // TNW + case TNW: + lMinX1 = 5; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + break; + + // TSE + case TSE: + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = 5; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + // TSW + case TSW: + lMinX1 = 5; + lMaxX1 = 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = 5; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 2; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = maxX3 - 7; + lMaxX3 = maxX3 - 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + // BNE + case BNE: + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = 5; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + // BNW + case BNW: + lMinX1 = 5; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = maxX2 - 7; + lMaxX2 = maxX2 - 2; + lMinX3 = 5; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + + // BSE + case BSE: + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = 5; + lMaxX2 = 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = maxX1 - 7; + lMaxX1 = maxX1 - 2; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = 5; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + + // BSW + case BSW: + lMinX1 = 5; + lMaxX1 = 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = 5; + lMaxX2 = 6; + lMinX3 = 1; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + lMinX1 = 1; + lMaxX1 = 6; + lMinX2 = 1; + lMaxX2 = 6; + lMinX3 = 5; + lMaxX3 = 6; + fillSendVector(fFrom, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + + break; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::fillSendVector(SPtr<DistributionArray3D> fFrom, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::fillSendVector(SPtr<DistributionArray3D> fFrom, const int &lMinX1, + const int &lMinX2, const int &lMinX3, + const int &lMaxX1, const int &lMaxX2, + const int &lMaxX3, vector_type &data, int &index) { - int ix1, ix2, ix3; - LBMReal xoff, yoff, zoff; - SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); - - for (ix3=lMinX3; ix3<lMaxX3; ix3+=2) - { - for (ix2=lMinX2; ix2<lMaxX2; ix2+=2) - { - for (ix1=lMinX1; ix1<lMaxX1; ix1+=2) - { - LBMReal icellC[27]; - D3Q27ICell icellF; - - int howManySolids= iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); - - if(howManySolids == 0 || howManySolids == 8) - { - iprocessor->readICell(fFrom, icellF, ix1, ix2, ix3); - xoff=0.0; - yoff=0.0; - zoff=0.0; - } - else - { - if(!iprocessor->findNeighborICell(bcArray, fFrom, icellF, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, xoff, yoff, zoff)) - { - std::string err = "For "+block.lock()->toString()+" x1="+UbSystem::toString(ix1)+", x2=" + UbSystem::toString(ix2)+", x3=" + UbSystem::toString(ix3)+ - " interpolation is not implemented for other direction"+ - " by using in: "+(std::string)typeid(*this).name()+ - " or maybe you have a solid on the block boundary"; - //UBLOG(logINFO, err); - UB_THROW(UbException(UB_EXARGS, err)); - } - } - - iprocessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); - this->writeICellCtoData(data, index, icellC); - } - } - } + int ix1, ix2, ix3; + LBMReal xoff, yoff, zoff; + SPtr<BCArray3D> bcArray = block.lock()->getKernel()->getBCProcessor()->getBCArray(); + + for (ix3 = lMinX3; ix3 < lMaxX3; ix3 += 2) { + for (ix2 = lMinX2; ix2 < lMaxX2; ix2 += 2) { + for (ix1 = lMinX1; ix1 < lMaxX1; ix1 += 2) { + LBMReal icellC[27]; + D3Q27ICell icellF; + + int howManySolids = iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + + if (howManySolids == 0 || howManySolids == 8) { + iprocessor->readICell(fFrom, icellF, ix1, ix2, ix3); + xoff = 0.0; + yoff = 0.0; + zoff = 0.0; + } else { + if (!iprocessor->findNeighborICell(bcArray, fFrom, icellF, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, + xoff, yoff, zoff)) { + std::string err = "For " + block.lock()->toString() + " x1=" + UbSystem::toString(ix1) + + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + + " interpolation is not implemented for other direction" + + " by using in: " + (std::string) typeid(*this).name() + + " or maybe you have a solid on the block boundary"; + // UBLOG(logINFO, err); + UB_THROW(UbException(UB_EXARGS, err)); + } + } + + iprocessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); + this->writeICellCtoData(data, index, icellC); + } + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::writeICellCtoData(vector_type& data, int& index, LBMReal* icellC) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::writeICellCtoData(vector_type &data, int &index, LBMReal *icellC) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - data[index++] = icellC[i]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + data[index++] = icellC[i]; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::getLocalMinMaxCF(int gMax, int& lMin, int& lMax) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::getLocalMinMaxCF(int gMax, int &lMin, int &lMax) { - if (Utilities::isOdd(gMax)) - { - if(connType == OddEvenSE || connType == OddOddNE) - { - lMin = 1; - lMax = gMax; - } - } + if (Utilities::isOdd(gMax)) { + if (connType == OddEvenSE || connType == OddOddNE) { + lMin = 1; + lMax = gMax; + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::distributeReceiveVectors() +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::distributeReceiveVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); - int maxX1 = (int)fTo->getNX1(); - int maxX2 = (int)fTo->getNX2(); - int maxX3 = (int)fTo->getNX3(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; - int index = 0; - vector_type& data = receiver->getData(); - - lMinX1 = minX1; lMinX2 = minX2; lMinX3 = minX3; - lMaxX1 = maxX1-1; lMaxX2 = maxX2-1; lMaxX3 = maxX3-1; - - switch(sendDir) - { - case E: - lMinX1 = maxX1-4; - lMaxX1 = lMinX1 + 1; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case W: - /////////////////////////////////////// - ///DEBUG - //if (block.lock()->getGlobalID() == 2554) - //{ - // int test = 0; - //} - ////////////// - lMinX1 = 2; - lMaxX1 = lMinX1 + 1; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case N: - lMinX2 = maxX2-4; - lMaxX2 = lMinX2 + 1; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case S: - lMinX2 = 2; - lMaxX2 = lMinX2 + 1; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case T: - lMinX3 = maxX3-4; - lMaxX3 = lMinX3 + 1; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - case B: - lMinX3 = 2; - lMaxX3 = lMinX3 + 1; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - /////E-W-N-S - case NE: - lMinX1 = maxX1-4; - lMaxX1 = lMinX1 + 3; - lMinX2 = maxX2-4; - lMaxX2 = lMinX2 + 3; - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case SW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 3; - lMinX2 = 0; - lMaxX2 = lMinX2 + 3; - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case SE: - lMinX1 = maxX1-4; - lMaxX1 = lMinX1 + 3; - lMinX2 = 0; - lMaxX2 = lMinX2 + 3; - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case NW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 3; - lMinX2 = maxX2-4; - lMaxX2 = lMinX2 + 3; - getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // - // /////T-B-E-W - case TE: - lMinX1 = maxX1-4; - lMaxX1 = lMinX1 + 3; - lMinX3 = maxX3-4; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 3; - lMinX3 = 0; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BE: - lMinX1 = maxX1-4; - lMaxX1 = lMinX1 + 3; - lMinX3 = 0; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case TW: - lMinX1 = 0; - lMaxX1 = lMinX1 + 3; - lMinX3 = maxX3-4; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - // ////////////////T-B-N-S - // - case TN: - lMinX2 = maxX2-4; - lMaxX2 = lMinX2 + 3; - lMinX3 = maxX3-4; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BS: - lMinX2 = 0; - lMaxX2 = lMinX2 + 3; - lMinX3 = 0; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case BN: - lMinX2 = maxX2-4; - lMaxX2 = lMinX2 + 3; - lMinX3 = 0; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - case TS: - lMinX2 = 0; - lMaxX2 = lMinX2 + 3; - lMinX3 = maxX3-4; - lMaxX3 = lMinX3 + 3; - getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - - // //TNE - case TNE: - lMinX1 = maxX1-4; - lMaxX1 = maxX1-1; - lMinX2 = maxX2-4; - lMaxX2 = maxX2-1; - lMinX3 = maxX3-4; - lMaxX3 = maxX3-1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // TNW - case TNW: - lMinX1 = 0; - lMaxX1 = 3; - lMinX2 = maxX2-4; - lMaxX2 = maxX2-1; - lMinX3 = maxX3-4; - lMaxX3 = maxX3-1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // TSE - case TSE: - lMinX1 = maxX1-4; - lMaxX1 = maxX1-1; - lMinX2 = 0; - lMaxX2 = 3; - lMinX3 = maxX3-4; - lMaxX3 = maxX3-1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // TSW - case TSW: - lMinX1 = 0; - lMaxX1 = 3; - lMinX2 = 0; - lMaxX2 = 3; - lMinX3 = maxX3-4; - lMaxX3 = maxX3-1; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // BNE - case BNE: - lMinX1 = maxX1-4; - lMaxX1 = maxX1-1; - lMinX2 = maxX2-4; - lMaxX2 = maxX2-1; - lMinX3 = 0; - lMaxX3 = 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // BNW - case BNW: - lMinX1 = 0; - lMaxX1 = 3; - lMinX2 = maxX2-4; - lMaxX2 = maxX2-1; - lMinX3 = 0; - lMaxX3 = 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - // BSE - case BSE: - lMinX1 = maxX1-4; - lMaxX1 = maxX1-1; - lMinX2 = 0; - lMaxX2 = 3; - lMinX3 = 0; - lMaxX3 = 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - //BSW - case BSW: - lMinX1 = 0; - lMaxX1 = 3; - lMinX2 = 0; - lMaxX2 = 3; - lMinX3 = 0; - lMaxX3 = 3; - distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); - break; - } + using namespace D3Q27System; + + SPtr<DistributionArray3D> fTo = block.lock()->getKernel()->getDataSet()->getFdistributions(); + int maxX1 = (int)fTo->getNX1(); + int maxX2 = (int)fTo->getNX2(); + int maxX3 = (int)fTo->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + int index = 0; + vector_type &data = receiver->getData(); + + lMinX1 = minX1; + lMinX2 = minX2; + lMinX3 = minX3; + lMaxX1 = maxX1 - 1; + lMaxX2 = maxX2 - 1; + lMaxX3 = maxX3 - 1; + + switch (sendDir) { + case E: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 1; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case W: + /////////////////////////////////////// + /// DEBUG + // if (block.lock()->getGlobalID() == 2554) + //{ + // int test = 0; + //} + ////////////// + lMinX1 = 2; + lMaxX1 = lMinX1 + 1; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case N: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 1; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case S: + lMinX2 = 2; + lMaxX2 = lMinX2 + 1; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case T: + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 1; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + case B: + lMinX3 = 2; + lMaxX3 = lMinX3 + 1; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + /////E-W-N-S + case NE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case SW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 3; + lMinX2 = 0; + lMaxX2 = lMinX2 + 3; + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case SE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX2 = 0; + lMaxX2 = lMinX2 + 3; + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case NW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 3; + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + getLocalMinMaxCF(maxX3, lMinX3, lMaxX3); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // + // /////T-B-E-W + case TE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 3; + lMinX3 = 0; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BE: + lMinX1 = maxX1 - 4; + lMaxX1 = lMinX1 + 3; + lMinX3 = 0; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case TW: + lMinX1 = 0; + lMaxX1 = lMinX1 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX2, lMinX2, lMaxX2); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + // ////////////////T-B-N-S + // + case TN: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BS: + lMinX2 = 0; + lMaxX2 = lMinX2 + 3; + lMinX3 = 0; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case BN: + lMinX2 = maxX2 - 4; + lMaxX2 = lMinX2 + 3; + lMinX3 = 0; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + case TS: + lMinX2 = 0; + lMaxX2 = lMinX2 + 3; + lMinX3 = maxX3 - 4; + lMaxX3 = lMinX3 + 3; + getLocalMinMaxCF(maxX1, lMinX1, lMaxX1); + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + + // //TNE + case TNE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // TNW + case TNW: + lMinX1 = 0; + lMaxX1 = 3; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // TSE + case TSE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 3; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // TSW + case TSW: + lMinX1 = 0; + lMaxX1 = 3; + lMinX2 = 0; + lMaxX2 = 3; + lMinX3 = maxX3 - 4; + lMaxX3 = maxX3 - 1; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // BNE + case BNE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // BNW + case BNW: + lMinX1 = 0; + lMaxX1 = 3; + lMinX2 = maxX2 - 4; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // BSE + case BSE: + lMinX1 = maxX1 - 4; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 3; + lMinX3 = 0; + lMaxX3 = 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + // BSW + case BSW: + lMinX1 = 0; + lMaxX1 = 3; + lMinX2 = 0; + lMaxX2 = 3; + lMinX3 = 0; + lMaxX3 = 3; + distributeReceiveVector(fTo, lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, data, index); + break; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::distributeReceiveVector(SPtr<DistributionArray3D> fTo, const int& lMinX1, const int& lMinX2, const int& lMinX3, const int& lMaxX1, const int& lMaxX2, const int& lMaxX3, vector_type& data, int& index) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::distributeReceiveVector(SPtr<DistributionArray3D> fTo, + const int &lMinX1, const int &lMinX2, + const int &lMinX3, const int &lMaxX1, + const int &lMaxX2, const int &lMaxX3, + vector_type &data, int &index) { - if(data.size() == 0) return; - - int ix1, ix2, ix3; - for (ix3=lMinX3; ix3<lMaxX3; ix3+=2) - { - for (ix2=lMinX2; ix2<lMaxX2; ix2+=2) - { - for (ix1=lMinX1; ix1<lMaxX1; ix1+=2) - { - D3Q27ICell icellF; - this->readICellFfromData(data, index, icellF); - iprocessor->writeICellInv(fTo, icellF, ix1, ix2, ix3); - } - } - } + if (data.size() == 0) + return; + + int ix1, ix2, ix3; + for (ix3 = lMinX3; ix3 < lMaxX3; ix3 += 2) { + for (ix2 = lMinX2; ix2 < lMaxX2; ix2 += 2) { + for (ix1 = lMinX1; ix1 < lMaxX1; ix1 += 2) { + D3Q27ICell icellF; + this->readICellFfromData(data, index, icellF); + iprocessor->writeICellInv(fTo, icellF, ix1, ix2, ix3); + } + } + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::readICellFfromData(vector_type& data, int& index, D3Q27ICell& icellF) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::readICellFfromData(vector_type &data, int &index, + D3Q27ICell &icellF) { - readNodeFromVector(data, index, icellF.BSW); - readNodeFromVector(data, index, icellF.BSE); - readNodeFromVector(data, index, icellF.BNW); - readNodeFromVector(data, index, icellF.BNE); - readNodeFromVector(data, index, icellF.TSW); - readNodeFromVector(data, index, icellF.TSE); - readNodeFromVector(data, index, icellF.TNW); - readNodeFromVector(data, index, icellF.TNE); + readNodeFromVector(data, index, icellF.BSW); + readNodeFromVector(data, index, icellF.BSE); + readNodeFromVector(data, index, icellF.BNW); + readNodeFromVector(data, index, icellF.BNE); + readNodeFromVector(data, index, icellF.TSW); + readNodeFromVector(data, index, icellF.TSE); + readNodeFromVector(data, index, icellF.TNW); + readNodeFromVector(data, index, icellF.TNE); } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::readNodeFromVector(vector_type& data, int& index, LBMReal* inode) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::readNodeFromVector(vector_type &data, int &index, LBMReal *inode) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - inode[i] = data[index++]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + inode[i] = data[index++]; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, + int &maxX2, int &maxX3) { - using namespace D3Q27System; - int TminX1=minX1; int TminX2=minX2; int TminX3=minX3; int TmaxX1=maxX1; int TmaxX2=maxX2; int TmaxX3=maxX3; - - if(block.lock()->hasInterpolationFlagFC(E)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(W)) - { - if (minX1==TminX1) minX1 += 4; - } - if(block.lock()->hasInterpolationFlagFC(N)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(S)) - { - if (minX2==TminX2) minX2 += 4; - } - if(block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX3==TmaxX3) maxX3 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(B)) - { - if (minX3==TminX3) minX3 += 4; - } - - //////////// - /////E-W-N-S - if(block.lock()->hasInterpolationFlagFC(NE)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(E)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (maxX2==TmaxX2) maxX2 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(SW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(S)) - { - if (minX1==TminX1) minX1 += 4; - if (minX2==TminX2) minX2 += 4; - } - if(block.lock()->hasInterpolationFlagFC(SE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(S)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (minX2==TminX2) minX2 += 4; - } - if(block.lock()->hasInterpolationFlagFC(NW)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(W)) - { - if (minX1==TminX1) minX1 += 4; - if (maxX2==TmaxX2) maxX2 -= 3; - } - - //////T-B-E-W - if(block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (maxX3==TmaxX3) maxX3 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(BW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (minX1==TminX1) minX1 += 4; - if (minX3==TminX3) minX3 += 4; - } - if(block.lock()->hasInterpolationFlagFC(BE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (minX3==TminX3) minX3 += 4; - } - if(block.lock()->hasInterpolationFlagFC(TW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (minX1==TminX1) minX1 += 4; - if (maxX3==TmaxX3) maxX3 -= 3; - } - - - ////T-B-N-S - if(block.lock()->hasInterpolationFlagFC(TN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - if (maxX3==TmaxX3) maxX3 -= 3; - } - if(block.lock()->hasInterpolationFlagFC(BS)&& !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (minX2==TminX2) minX2 += 4; - if (minX3==TminX3) minX3 += 4; - } - if(block.lock()->hasInterpolationFlagFC(BN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - if (minX3==TminX3) minX3 += 4; - } - if(block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (minX2==TminX2) minX2 += 4; - if (maxX3==TmaxX3) maxX3 -= 3; - } - - //if (block.lock()->hasInterpolationFlagFC(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::N) && !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) - //if (!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T) && !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) - //{ - // if (maxX1==TmaxX1) maxX1 -= 3; - // if (maxX2==TmaxX2) maxX2 -= 3; - // if (maxX3==TmaxX3) maxX3 -= 3; - //} + using namespace D3Q27System; + int TminX1 = minX1; + int TminX2 = minX2; + int TminX3 = minX3; + int TmaxX1 = maxX1; + int TmaxX2 = maxX2; + int TmaxX3 = maxX3; + + if (block.lock()->hasInterpolationFlagFC(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(W)) { + if (minX1 == TminX1) + minX1 += 4; + } + if (block.lock()->hasInterpolationFlagFC(N)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(S)) { + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(T)) { + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(B)) { + if (minX3 == TminX3) + minX3 += 4; + } + + //////////// + /////E-W-N-S + if (block.lock()->hasInterpolationFlagFC(NE) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(SW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(S)) { + if (minX1 == TminX1) + minX1 += 4; + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(SE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(S)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(NW) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(W)) { + if (minX1 == TminX1) + minX1 += 4; + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + + //////T-B-E-W + if (block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(BW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (minX1 == TminX1) + minX1 += 4; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(BE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(TW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (minX1 == TminX1) + minX1 += 4; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + + ////T-B-N-S + if (block.lock()->hasInterpolationFlagFC(TN) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(BS) && !block.lock()->hasInterpolationFlagFC(S) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (minX2 == TminX2) + minX2 += 4; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(BN) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (minX2 == TminX2) + minX2 += 4; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + + // if + // (block.lock()->hasInterpolationFlagFC(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::N) + // && !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) if + // (!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T) && + // !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) + //{ + // if (maxX1==TmaxX1) maxX1 -= 3; + // if (maxX2==TmaxX2) maxX2 -= 3; + // if (maxX3==TmaxX3) maxX3 -= 3; + //} } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3, CFconnectorType /*connType*/) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::getLocalMinMax(int &minX1, int &minX2, int &minX3, int &maxX1, + int &maxX2, int &maxX3, + CFconnectorType /*connType*/) { - using namespace D3Q27System; - int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = maxX3; - - if (block.lock()->hasInterpolationFlagFC(E)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(W)) - { - if (minX1==TminX1) minX1 += 4; - } - if (block.lock()->hasInterpolationFlagFC(N)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(S)) - { - if (minX2==TminX2) minX2 += 4; - } - if (block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX3==TmaxX3) maxX3 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(B)) - { - if (minX3==TminX3) minX3 += 4; - } - - //////////// - /////E-W-N-S - if (block.lock()->hasInterpolationFlagFC(NE)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(E)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (maxX2==TmaxX2) maxX2 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(SW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(S)) - { - if (minX1==TminX1) minX1 += 4; - if (minX2==TminX2) minX2 += 4; - } - if (block.lock()->hasInterpolationFlagFC(SE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(S)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (minX2==TminX2) minX2 += 4; - } - if (block.lock()->hasInterpolationFlagFC(NW)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(W)) - { - if (minX1==TminX1) minX1 += 4; - if (maxX2==TmaxX2) maxX2 -= 3; - } - - //////T-B-E-W - if (block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (maxX3==TmaxX3) maxX3 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(BW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (minX1==TminX1) minX1 += 4; - if (minX3==TminX3) minX3 += 4; - } - if (block.lock()->hasInterpolationFlagFC(BE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (maxX1==TmaxX1) maxX1 -= 3; - if (minX3==TminX3) minX3 += 4; - } - if (block.lock()->hasInterpolationFlagFC(TW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (minX1==TminX1) minX1 += 4; - if (maxX3==TmaxX3) maxX3 -= 3; - } - - - ////T-B-N-S - if (block.lock()->hasInterpolationFlagFC(TN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - if (maxX3==TmaxX3) maxX3 -= 3; - } - if (block.lock()->hasInterpolationFlagFC(BS)&& !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (minX2==TminX2) minX2 += 4; - if (minX3==TminX3) minX3 += 4; - } - if (block.lock()->hasInterpolationFlagFC(BN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(B)) - { - if (maxX2==TmaxX2) maxX2 -= 3; - if (minX3==TminX3) minX3 += 4; - } - if (block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(T)) - { - if (minX2==TminX2) minX2 += 4; - if (maxX3==TmaxX3) maxX3 -= 3; - } - - //if (block.lock()->hasInterpolationFlagFC(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::N) && !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) - //{ - // if (maxX1==TmaxX1) maxX1 -= 3; - // if (maxX2==TmaxX2) maxX2 -= 3; - // if (maxX3==TmaxX3) maxX3 -= 3; - //} + using namespace D3Q27System; + int TminX1 = minX1; + int TminX2 = minX2; + int TminX3 = minX3; + int TmaxX1 = maxX1; + int TmaxX2 = maxX2; + int TmaxX3 = maxX3; + + if (block.lock()->hasInterpolationFlagFC(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(W)) { + if (minX1 == TminX1) + minX1 += 4; + } + if (block.lock()->hasInterpolationFlagFC(N)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(S)) { + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(T)) { + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(B)) { + if (minX3 == TminX3) + minX3 += 4; + } + + //////////// + /////E-W-N-S + if (block.lock()->hasInterpolationFlagFC(NE) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(E)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(SW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(S)) { + if (minX1 == TminX1) + minX1 += 4; + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(SE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(S)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (minX2 == TminX2) + minX2 += 4; + } + if (block.lock()->hasInterpolationFlagFC(NW) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(W)) { + if (minX1 == TminX1) + minX1 += 4; + if (maxX2 == TmaxX2) + maxX2 -= 3; + } + + //////T-B-E-W + if (block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(BW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (minX1 == TminX1) + minX1 += 4; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(BE) && !block.lock()->hasInterpolationFlagFC(E) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (maxX1 == TmaxX1) + maxX1 -= 3; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(TW) && !block.lock()->hasInterpolationFlagFC(W) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (minX1 == TminX1) + minX1 += 4; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + + ////T-B-N-S + if (block.lock()->hasInterpolationFlagFC(TN) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + if (block.lock()->hasInterpolationFlagFC(BS) && !block.lock()->hasInterpolationFlagFC(S) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (minX2 == TminX2) + minX2 += 4; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(BN) && !block.lock()->hasInterpolationFlagFC(N) && + !block.lock()->hasInterpolationFlagFC(B)) { + if (maxX2 == TmaxX2) + maxX2 -= 3; + if (minX3 == TminX3) + minX3 += 4; + } + if (block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && + !block.lock()->hasInterpolationFlagFC(T)) { + if (minX2 == TminX2) + minX2 += 4; + if (maxX3 == TmaxX3) + maxX3 -= 3; + } + + // if + // (block.lock()->hasInterpolationFlagFC(D3Q27System::TNE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::TN)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::NE)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::T)&&!block.lock()->hasInterpolationFlagFC(D3Q27System::N) + // && !block.lock()->hasInterpolationFlagFC(D3Q27System::E)) + //{ + // if (maxX1==TmaxX1) maxX1 -= 3; + // if (maxX2==TmaxX2) maxX2 -= 3; + // if (maxX3==TmaxX3) maxX3 -= 3; + //} } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::getLocalOffsets(const int& gMax, int& oMin) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::getLocalOffsets(const int &gMax, int &oMin) { - if (Utilities::isEven(gMax)) - { - oMin = 0; - } - if (Utilities::isOdd(gMax)) - { - oMin = -1; - } - + if (Utilities::isEven(gMax)) { + oMin = 0; + } + if (Utilities::isOdd(gMax)) { + oMin = -1; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > -void D3Q27ETFCOffVectorConnector< VectorTransmitter>::getLocalMins(int& minX1, int& minX2, int& minX3, const int& oMinX1, const int& oMinX2, const int& oMinX3) +template <typename VectorTransmitter> +void D3Q27ETFCOffVectorConnector<VectorTransmitter>::getLocalMins(int &minX1, int &minX2, int &minX3, const int &oMinX1, + const int &oMinX2, const int &oMinX3) { - using namespace D3Q27System; - - switch(sendDir) - { - case E: case W: - if(connType == OddEvenSE) - minX2 += oMinX2; - if(connType == OddOddNE) - { - minX2 += oMinX2; - minX3 += oMinX3; - } - if(connType == EvenOddNW) - minX3 += oMinX3; - break; - case N: case S: - if(connType == OddEvenSE) - minX1 += oMinX1; - if(connType == OddOddNE) - { - minX1 += oMinX1; - minX3 += oMinX3; - } - if(connType == EvenOddNW) - minX3 += oMinX3; - break; - case T: case B: - if(connType == OddEvenSE) - minX1 += oMinX1; - if(connType == OddOddNE) - { - minX1 += oMinX1; - minX2 += oMinX2; - } - if(connType == EvenOddNW) - minX2 += oMinX2; - break; - - ///// - case NE: case SW: case SE: case NW: - //case SW: - if(connType == OddEvenSE) - //minX2 += oMinX2; - if(connType == OddOddNE) - { - //minX2 += oMinX2; - minX3 += oMinX3; - } - if(connType == EvenOddNW) - minX3 += oMinX3; - break; - - ////// - case TE: case BW: case BE: case TW: - if(connType == OddEvenSE) - // minX1 += oMinX1; - if(connType == OddOddNE) - { - // minX1 += oMinX1; - minX2 += oMinX2; - } - if(connType == EvenOddNW) - minX2 += oMinX2; - break; - - // ////// - case TN: case BS: case BN: case TS: - if(connType == OddEvenSE) - minX1 += oMinX1; - if(connType == OddOddNE) - { - minX1 += oMinX1; - //minX3 += oMinX3; - } - if(connType == EvenOddNW) - //minX3 += oMinX3; - break; - - // ///// - // case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: - // if(connType == OddEvenSE) - // // minX1 += oMinX1; - // if(connType == OddOddNE) - // { - // //minX1 += oMinX1; - // //minX3 += oMinX3; - // } - // if(connType == EvenOddNW) - // //minX3 += oMinX3; - // break; - } + using namespace D3Q27System; + + switch (sendDir) { + case E: + case W: + if (connType == OddEvenSE) + minX2 += oMinX2; + if (connType == OddOddNE) { + minX2 += oMinX2; + minX3 += oMinX3; + } + if (connType == EvenOddNW) + minX3 += oMinX3; + break; + case N: + case S: + if (connType == OddEvenSE) + minX1 += oMinX1; + if (connType == OddOddNE) { + minX1 += oMinX1; + minX3 += oMinX3; + } + if (connType == EvenOddNW) + minX3 += oMinX3; + break; + case T: + case B: + if (connType == OddEvenSE) + minX1 += oMinX1; + if (connType == OddOddNE) { + minX1 += oMinX1; + minX2 += oMinX2; + } + if (connType == EvenOddNW) + minX2 += oMinX2; + break; + + ///// + case NE: + case SW: + case SE: + case NW: + // case SW: + if (connType == OddEvenSE) + // minX2 += oMinX2; + if (connType == OddOddNE) { + // minX2 += oMinX2; + minX3 += oMinX3; + } + if (connType == EvenOddNW) + minX3 += oMinX3; + break; + + ////// + case TE: + case BW: + case BE: + case TW: + if (connType == OddEvenSE) + // minX1 += oMinX1; + if (connType == OddOddNE) { + // minX1 += oMinX1; + minX2 += oMinX2; + } + if (connType == EvenOddNW) + minX2 += oMinX2; + break; + + // ////// + case TN: + case BS: + case BN: + case TS: + if (connType == OddEvenSE) + minX1 += oMinX1; + if (connType == OddOddNE) { + minX1 += oMinX1; + // minX3 += oMinX3; + } + if (connType == EvenOddNW) + // minX3 += oMinX3; + break; + + // ///// + // case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: + // if(connType == OddEvenSE) + // // minX1 += oMinX1; + // if(connType == OddOddNE) + // { + // //minX1 += oMinX1; + // //minX3 += oMinX3; + // } + // if(connType == EvenOddNW) + // //minX3 += oMinX3; + // break; + } } ////////////////////////////////////////////////////////////////////////// -template< typename VectorTransmitter > +template <typename VectorTransmitter> double D3Q27ETFCOffVectorConnector<VectorTransmitter>::getSendRecieveTime() { - return 0; + return 0; } #endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.cpp index 8519b39d0..1e7e49f63 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,212 +32,162 @@ //======================================================================================= #include "D3Q27ETFullDirectConnector.h" -#include "LBMKernel.h" #include "D3Q27EsoTwist3DSplittedVector.h" #include "DataSet3D.h" +#include "LBMKernel.h" using namespace std; D3Q27ETFullDirectConnector::D3Q27ETFullDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) - : LocalBlock3DConnector(from, to, sendDir) + : LocalBlock3DConnector(from, to, sendDir) { - } ////////////////////////////////////////////////////////////////////////// void D3Q27ETFullDirectConnector::init() { - maxX1 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1() - 1; - maxX2 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2() - 1; - maxX3 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3() - 1; + maxX1 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1() - 1; + maxX2 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2() - 1; + maxX3 = (int)this->from.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3() - 1; - fFrom = dynamic_pointer_cast<EsoTwist3D>(from.lock()->getKernel()->getDataSet()->getFdistributions()); - fTo = dynamic_pointer_cast<EsoTwist3D>(to.lock()->getKernel()->getDataSet()->getFdistributions()); + fFrom = dynamic_pointer_cast<EsoTwist3D>(from.lock()->getKernel()->getDataSet()->getFdistributions()); + fTo = dynamic_pointer_cast<EsoTwist3D>(to.lock()->getKernel()->getDataSet()->getFdistributions()); } ////////////////////////////////////////////////////////////////////////// void D3Q27ETFullDirectConnector::sendVectors() { - localDistributionsFrom = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getLocalDistributions(); - nonLocalDistributionsFrom = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getNonLocalDistributions(); - zeroDistributionsFrom = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getZeroDistributions(); + localDistributionsFrom = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getLocalDistributions(); + nonLocalDistributionsFrom = + dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getNonLocalDistributions(); + zeroDistributionsFrom = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fFrom)->getZeroDistributions(); - localDistributionsTo = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getLocalDistributions(); - nonLocalDistributionsTo = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getNonLocalDistributions(); - zeroDistributionsTo = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getZeroDistributions(); + localDistributionsTo = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getLocalDistributions(); + nonLocalDistributionsTo = + dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getNonLocalDistributions(); + zeroDistributionsTo = dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(this->fTo)->getZeroDistributions(); - //EAST - if (sendDir == D3Q27System::E) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(maxX1 - 1, x2, x3, 0, x2, x3); - } - } - } - //WEST - else if (sendDir == D3Q27System::W) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(1, x2, x3, maxX1, x2, x3); - } - } - } - //NORTH - else if (sendDir == D3Q27System::N) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, maxX2 - 1, x3, x1, 0, x3); - } - } - } - //SOUTH - else if (sendDir == D3Q27System::S) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, 1, x3, x1, maxX2, x3); - } - } - } + // EAST + if (sendDir == D3Q27System::E) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(maxX1 - 1, x2, x3, 0, x2, x3); + } + } + } + // WEST + else if (sendDir == D3Q27System::W) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(1, x2, x3, maxX1, x2, x3); + } + } + } + // NORTH + else if (sendDir == D3Q27System::N) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, maxX2 - 1, x3, x1, 0, x3); + } + } + } + // SOUTH + else if (sendDir == D3Q27System::S) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, 1, x3, x1, maxX2, x3); + } + } + } - //TOP - else if (sendDir == D3Q27System::T) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, x2, maxX3 - 1, x1, x2, 0); - } - } - } - //BOTTOM - else if (sendDir == D3Q27System::B) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, x2, 1, x1, x2, maxX3); - } - } - } - //NORTHEAST - else if (sendDir == D3Q27System::NE) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - exchangeData(maxX1 - 1, maxX2 - 1, x3, 0, 0, x3); - } - } - //NORTHWEST - else if (sendDir == D3Q27System::NW) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - exchangeData(1, maxX2 - 1, x3, maxX1, 0, x3); - } - } - //SOUTHWEST - else if (sendDir == D3Q27System::SW) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - exchangeData(1, 1, x3, maxX1, maxX2, x3); - } - } - //SOUTHEAST - else if (sendDir == D3Q27System::SE) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - exchangeData(maxX1 - 1, 1, x3, 0, maxX2, x3); - } - } - else if (sendDir == D3Q27System::TE) - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(maxX1 - 1, x2, maxX3 - 1, 0, x2, 0); - } - else if (sendDir == D3Q27System::BW) - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(1, x2, 1, maxX1, x2, maxX3); - } - else if (sendDir == D3Q27System::BE) - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(maxX1 - 1, x2, 1, 0, x2, maxX3); - } - else if (sendDir == D3Q27System::TW) - for (int x2 = 1; x2 < maxX2; x2++) - { - exchangeData(1, x2, maxX3 - 1, maxX1, x2, 0); - } - else if (sendDir == D3Q27System::TN) - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, maxX2 - 1, maxX3 - 1, x1, 0, 0); - } - else if (sendDir == D3Q27System::BS) - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, 1, 1, x1, maxX2, maxX3); - } - else if (sendDir == D3Q27System::BN) - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, maxX2 - 1, 1, x1, 0, maxX3); - } + // TOP + else if (sendDir == D3Q27System::T) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, x2, maxX3 - 1, x1, x2, 0); + } + } + } + // BOTTOM + else if (sendDir == D3Q27System::B) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, x2, 1, x1, x2, maxX3); + } + } + } + // NORTHEAST + else if (sendDir == D3Q27System::NE) { + for (int x3 = 1; x3 < maxX3; x3++) { + exchangeData(maxX1 - 1, maxX2 - 1, x3, 0, 0, x3); + } + } + // NORTHWEST + else if (sendDir == D3Q27System::NW) { + for (int x3 = 1; x3 < maxX3; x3++) { + exchangeData(1, maxX2 - 1, x3, maxX1, 0, x3); + } + } + // SOUTHWEST + else if (sendDir == D3Q27System::SW) { + for (int x3 = 1; x3 < maxX3; x3++) { + exchangeData(1, 1, x3, maxX1, maxX2, x3); + } + } + // SOUTHEAST + else if (sendDir == D3Q27System::SE) { + for (int x3 = 1; x3 < maxX3; x3++) { + exchangeData(maxX1 - 1, 1, x3, 0, maxX2, x3); + } + } else if (sendDir == D3Q27System::TE) + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(maxX1 - 1, x2, maxX3 - 1, 0, x2, 0); + } + else if (sendDir == D3Q27System::BW) + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(1, x2, 1, maxX1, x2, maxX3); + } + else if (sendDir == D3Q27System::BE) + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(maxX1 - 1, x2, 1, 0, x2, maxX3); + } + else if (sendDir == D3Q27System::TW) + for (int x2 = 1; x2 < maxX2; x2++) { + exchangeData(1, x2, maxX3 - 1, maxX1, x2, 0); + } + else if (sendDir == D3Q27System::TN) + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, maxX2 - 1, maxX3 - 1, x1, 0, 0); + } + else if (sendDir == D3Q27System::BS) + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, 1, 1, x1, maxX2, maxX3); + } + else if (sendDir == D3Q27System::BN) + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, maxX2 - 1, 1, x1, 0, maxX3); + } - else if (sendDir == D3Q27System::TS) - for (int x1 = 1; x1 < maxX1; x1++) - { - exchangeData(x1, 1, maxX3 - 1, x1, maxX2, 0); - } + else if (sendDir == D3Q27System::TS) + for (int x1 = 1; x1 < maxX1; x1++) { + exchangeData(x1, 1, maxX3 - 1, x1, maxX2, 0); + } - else if (sendDir == D3Q27System::TSW) - { - exchangeData(1, 1, maxX3 - 1, maxX1, maxX2, 0); - } - else if (sendDir == D3Q27System::TSE) - { - exchangeData(maxX1 - 1, 1, maxX3 - 1, 0, maxX2, 0); - } - else if (sendDir == D3Q27System::TNW) - { - exchangeData(1, maxX2 - 1, maxX3 - 1, maxX1, 0, 0); - } - else if (sendDir == D3Q27System::TNE) - { - exchangeData(maxX1 - 1, maxX2 - 1, maxX3 - 1, 0, 0, 0); - } - else if (sendDir == D3Q27System::BSW) - { - exchangeData(1, 1, 1, maxX1, maxX2, maxX3); - } - else if (sendDir == D3Q27System::BSE) - { - exchangeData(maxX1 - 1, 1, 1, 0, maxX2, maxX3); - } - else if (sendDir == D3Q27System::BNW) - { - exchangeData(1, maxX2 - 1, 1, maxX1, 0, maxX3); - } - else if (sendDir == D3Q27System::BNE) - { - exchangeData(maxX1 - 1, maxX2 - 1, 1, 0, 0, maxX3); - } - else UB_THROW(UbException(UB_EXARGS, "unknown dir")); + else if (sendDir == D3Q27System::TSW) { + exchangeData(1, 1, maxX3 - 1, maxX1, maxX2, 0); + } else if (sendDir == D3Q27System::TSE) { + exchangeData(maxX1 - 1, 1, maxX3 - 1, 0, maxX2, 0); + } else if (sendDir == D3Q27System::TNW) { + exchangeData(1, maxX2 - 1, maxX3 - 1, maxX1, 0, 0); + } else if (sendDir == D3Q27System::TNE) { + exchangeData(maxX1 - 1, maxX2 - 1, maxX3 - 1, 0, 0, 0); + } else if (sendDir == D3Q27System::BSW) { + exchangeData(1, 1, 1, maxX1, maxX2, maxX3); + } else if (sendDir == D3Q27System::BSE) { + exchangeData(maxX1 - 1, 1, 1, 0, maxX2, maxX3); + } else if (sendDir == D3Q27System::BNW) { + exchangeData(1, maxX2 - 1, 1, maxX1, 0, maxX3); + } else if (sendDir == D3Q27System::BNE) { + exchangeData(maxX1 - 1, maxX2 - 1, 1, 0, 0, maxX3); + } else + UB_THROW(UbException(UB_EXARGS, "unknown dir")); } - diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.h b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.h index ffce993cc..101bc96af 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullDirectConnector.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,74 +34,99 @@ #ifndef D3Q27ETFULLDIRECTCONNECTOR_H #define D3Q27ETFULLDIRECTCONNECTOR_H -#include "LocalBlock3DConnector.h" #include "Block3D.h" #include "D3Q27System.h" +#include "EsoTwist3D.h" +#include "LocalBlock3DConnector.h" #include "basics/container/CbArray3D.h" #include "basics/container/CbArray4D.h" -#include "EsoTwist3D.h" -//! \brief Exchange data between blocks. +//! \brief Exchange data between blocks. //! \details Connector send and receive full distributions between two blocks in shared memory. class D3Q27ETFullDirectConnector : public LocalBlock3DConnector { public: - D3Q27ETFullDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir); - void init() override; - void sendVectors() override; + D3Q27ETFullDirectConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir); + void init() override; + void sendVectors() override; protected: - inline void exchangeData(int x1From, int x2From, int x3From, int x1To, int x2To, int x3To); + inline void exchangeData(int x1From, int x2From, int x3From, int x1To, int x2To, int x3To); + private: - int maxX1; - int maxX2; - int maxX3; + int maxX1; + int maxX2; + int maxX3; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributionsFrom; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributionsFrom; - CbArray3D <LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributionsFrom; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributionsFrom; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributionsFrom; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributionsFrom; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributionsTo; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributionsTo; - CbArray3D <LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributionsTo; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributionsTo; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributionsTo; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributionsTo; - SPtr<EsoTwist3D> fFrom; - SPtr<EsoTwist3D> fTo; + SPtr<EsoTwist3D> fFrom; + SPtr<EsoTwist3D> fTo; }; - ////////////////////////////////////////////////////////////////////////// inline void D3Q27ETFullDirectConnector::exchangeData(int x1From, int x2From, int x3From, int x1To, int x2To, int x3To) { - (*this->localDistributionsTo)(D3Q27System::ET_E, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_E, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_N, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_N, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_T, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_T, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_NE, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_NE, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_NW, x1To + 1, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_NW, x1From + 1, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TE, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TE, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TW, x1To + 1, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TW, x1From + 1, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TN, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TN, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TS, x1To, x2To + 1, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TS, x1From, x2From + 1, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TNE, x1To, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TNE, x1From, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TNW, x1To + 1, x2To, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TNW, x1From + 1, x2From, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TSE, x1To, x2To + 1, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TSE, x1From, x2From + 1, x3From); - (*this->localDistributionsTo)(D3Q27System::ET_TSW, x1To + 1, x2To + 1, x3To) = (*this->localDistributionsFrom)(D3Q27System::ET_TSW, x1From + 1, x2From + 1, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_E, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_E, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_N, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_N, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_T, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_T, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_NE, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_NE, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_NW, x1To + 1, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_NW, x1From + 1, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TE, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TE, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TW, x1To + 1, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TW, x1From + 1, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TN, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TN, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TS, x1To, x2To + 1, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TS, x1From, x2From + 1, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TNE, x1To, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TNE, x1From, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TNW, x1To + 1, x2To, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TNW, x1From + 1, x2From, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TSE, x1To, x2To + 1, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TSE, x1From, x2From + 1, x3From); + (*this->localDistributionsTo)(D3Q27System::ET_TSW, x1To + 1, x2To + 1, x3To) = + (*this->localDistributionsFrom)(D3Q27System::ET_TSW, x1From + 1, x2From + 1, x3From); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_W, x1To + 1, x2To, x3To) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_W, x1From + 1, x2From, x3From); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_S, x1To, x2To + 1, x3To) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_S, x1From, x2From + 1, x3From); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_B, x1To, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_B, x1From, x2From, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_SW, x1To + 1, x2To + 1, x3To) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_SW, x1From + 1, x2From + 1, x3From); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_SE, x1To, x2To + 1, x3To) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_SE, x1From, x2From + 1, x3From); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BW, x1To + 1, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BW, x1From + 1, x2From, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BE, x1To, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BE, x1From, x2From, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BS, x1To, x2To + 1, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BS, x1From, x2From + 1, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BN, x1To, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BN, x1From, x2From, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BSW, x1To + 1, x2To + 1, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BSW, x1From + 1, x2From + 1, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BSE, x1To, x2To + 1, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BSE, x1From, x2From + 1, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BNW, x1To + 1, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BNW, x1From + 1, x2From, x3From + 1); - (*this->nonLocalDistributionsTo)(D3Q27System::ET_BNE, x1To, x2To, x3To + 1) = (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BNE, x1From, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_W, x1To + 1, x2To, x3To) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_W, x1From + 1, x2From, x3From); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_S, x1To, x2To + 1, x3To) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_S, x1From, x2From + 1, x3From); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_B, x1To, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_B, x1From, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_SW, x1To + 1, x2To + 1, x3To) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_SW, x1From + 1, x2From + 1, x3From); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_SE, x1To, x2To + 1, x3To) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_SE, x1From, x2From + 1, x3From); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BW, x1To + 1, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BW, x1From + 1, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BE, x1To, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BE, x1From, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BS, x1To, x2To + 1, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BS, x1From, x2From + 1, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BN, x1To, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BN, x1From, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BSW, x1To + 1, x2To + 1, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BSW, x1From + 1, x2From + 1, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BSE, x1To, x2To + 1, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BSE, x1From, x2From + 1, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BNW, x1To + 1, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BNW, x1From + 1, x2From, x3From + 1); + (*this->nonLocalDistributionsTo)(D3Q27System::ET_BNE, x1To, x2To, x3To + 1) = + (*this->nonLocalDistributionsFrom)(D3Q27System::ET_BNE, x1From, x2From, x3From + 1); - (*this->zeroDistributionsTo)(x1To, x2To, x3To) = (*this->zeroDistributionsFrom)(x1From, x2From, x3From); + (*this->zeroDistributionsTo)(x1To, x2To, x3To) = (*this->zeroDistributionsFrom)(x1From, x2From, x3From); } -#endif - +#endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.cpp index e85d14098..70d7c438e 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.cpp @@ -1,468 +1,458 @@ #include "D3Q27ETFullVectorConnector.h" #include "D3Q27EsoTwist3DSplittedVector.h" -#include "LBMKernel.h" #include "DataSet3D.h" +#include "LBMKernel.h" ////////////////////////////////////////////////////////////////////////// -D3Q27ETFullVectorConnector::D3Q27ETFullVectorConnector(SPtr<Block3D> block - , VectorTransmitterPtr sender - , VectorTransmitterPtr receiver - , int sendDir) - : RemoteBlock3DConnector(block, sender, receiver, sendDir) +D3Q27ETFullVectorConnector::D3Q27ETFullVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir) + : RemoteBlock3DConnector(block, sender, receiver, sendDir) { - if (!block || !sender || !receiver) - UB_THROW(UbException(UB_EXARGS, "sender or receiver == NULL!!")); - + if (!block || !sender || !receiver) + UB_THROW(UbException(UB_EXARGS, "sender or receiver == NULL!!")); } ////////////////////////////////////////////////////////////////////////// void D3Q27ETFullVectorConnector::init() { - maxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1() - 1; - maxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2() - 1; - maxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3() - 1; + maxX1 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1() - 1; + maxX2 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2() - 1; + maxX3 = (int)block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3() - 1; - fDis = dynamicPointerCast<EsoTwist3D>(block.lock()->getKernel()->getDataSet()->getFdistributions()); + fDis = dynamicPointerCast<EsoTwist3D>(block.lock()->getKernel()->getDataSet()->getFdistributions()); - int anz = 27; - switch (sendDir) - { - case D3Q27System::ZERO: UB_THROW(UbException(UB_EXARGS, "ZERO not allowed")); break; - case D3Q27System::E: - case D3Q27System::W: sender->getData().resize(maxX2*maxX3*anz, 0.0); break; - case D3Q27System::N: - case D3Q27System::S: sender->getData().resize(maxX1*maxX3*anz, 0.0); break; - case D3Q27System::T: - case D3Q27System::B: sender->getData().resize(maxX1*maxX2*anz, 0.0); break; + int anz = 27; + switch (sendDir) { + case D3Q27System::ZERO: + UB_THROW(UbException(UB_EXARGS, "ZERO not allowed")); + break; + case D3Q27System::E: + case D3Q27System::W: + sender->getData().resize(maxX2 * maxX3 * anz, 0.0); + break; + case D3Q27System::N: + case D3Q27System::S: + sender->getData().resize(maxX1 * maxX3 * anz, 0.0); + break; + case D3Q27System::T: + case D3Q27System::B: + sender->getData().resize(maxX1 * maxX2 * anz, 0.0); + break; - case D3Q27System::NE: - case D3Q27System::SW: - case D3Q27System::SE: - case D3Q27System::NW: sender->getData().resize(maxX3*anz, 0.0); break; + case D3Q27System::NE: + case D3Q27System::SW: + case D3Q27System::SE: + case D3Q27System::NW: + sender->getData().resize(maxX3 * anz, 0.0); + break; - case D3Q27System::TE: - case D3Q27System::BW: - case D3Q27System::BE: - case D3Q27System::TW: sender->getData().resize(maxX2*anz, 0.0); break; + case D3Q27System::TE: + case D3Q27System::BW: + case D3Q27System::BE: + case D3Q27System::TW: + sender->getData().resize(maxX2 * anz, 0.0); + break; - case D3Q27System::TN: - case D3Q27System::BS: - case D3Q27System::BN: - case D3Q27System::TS: sender->getData().resize(maxX1*anz, 0.0); break; + case D3Q27System::TN: + case D3Q27System::BS: + case D3Q27System::BN: + case D3Q27System::TS: + sender->getData().resize(maxX1 * anz, 0.0); + break; - case D3Q27System::TNE: - case D3Q27System::BSW: - case D3Q27System::BNE: - case D3Q27System::TSW: - case D3Q27System::TSE: - case D3Q27System::BNW: - case D3Q27System::BSE: - case D3Q27System::TNW: sender->getData().resize(anz, 0.0); break; + case D3Q27System::TNE: + case D3Q27System::BSW: + case D3Q27System::BNE: + case D3Q27System::TSW: + case D3Q27System::TSE: + case D3Q27System::BNW: + case D3Q27System::BSE: + case D3Q27System::TNW: + sender->getData().resize(anz, 0.0); + break; - default: UB_THROW(UbException(UB_EXARGS, "unknown sendDir")); - } + default: + UB_THROW(UbException(UB_EXARGS, "unknown sendDir")); + } } ////////////////////////////////////////////////////////////////////////// void D3Q27ETFullVectorConnector::fillSendVectors() { - localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getLocalDistributions(); - nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getNonLocalDistributions(); - zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getZeroDistributions(); + localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getLocalDistributions(); + nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getNonLocalDistributions(); + zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getZeroDistributions(); - vector_type& sdata = sender->getData(); + vector_type &sdata = sender->getData(); - int index = 0; - //EAST - if (sendDir == D3Q27System::E) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - fillData(sdata, index, maxX1 - 1, x2, x3); - } - } - } - //WEST - else if (sendDir == D3Q27System::W) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - fillData(sdata, index, 1, x2, x3); - } - } - } - //NORTH - else if (sendDir == D3Q27System::N) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - fillData(sdata, index, x1, maxX2 - 1, x3); - } - } - } - //SOUTH - else if (sendDir == D3Q27System::S) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - fillData(sdata, index, x1, 1, x3); - } - } - } - //TOP - else if (sendDir == D3Q27System::T) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - fillData(sdata, index, x1, x2, maxX3 - 1); - } - } - } - //BOTTOM - else if (sendDir == D3Q27System::B) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - fillData(sdata, index, x1, x2, 1); - } - } - } - //NE NW SW SE - else if (sendDir == D3Q27System::NE || sendDir == D3Q27System::NW || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE) - { - int x1 = 0; - int x2 = 0; - switch (sendDir) - { - case D3Q27System::NE: - x1 = maxX1 - 1; - x2 = maxX2 - 1; - break; - case D3Q27System::NW: - x1 = 1; - x2 = maxX2 - 1; - break; - case D3Q27System::SW: - x1 = 1; - x2 = 1; - break; - case D3Q27System::SE: - x1 = maxX1 - 1; - x2 = 1; - break; - } - for (int x3 = 1; x3 < maxX3; x3++) - { - fillData(sdata, index, x1, x2, x3); - } - } - //TE TW BW BE - else if (sendDir == D3Q27System::TE || sendDir == D3Q27System::TW || sendDir == D3Q27System::BW || sendDir == D3Q27System::BE) - { - int x1 = 0; - int x3 = 0; - switch (sendDir) - { - case D3Q27System::TE: - x1 = maxX1 - 1; - x3 = maxX3 - 1; - break; - case D3Q27System::TW: - x1 = 1; - x3 = maxX3 - 1; - break; - case D3Q27System::BW: - x1 = 1; - x3 = 1; - break; - case D3Q27System::BE: - x1 = maxX1 - 1; - x3 = 1; - break; - } - for (int x2 = 1; x2 < maxX2; x2++) - { - fillData(sdata, index, x1, x2, x3); - } - } - //TN BN BS TS - else if (sendDir == D3Q27System::TN || sendDir == D3Q27System::BN || sendDir == D3Q27System::BS || sendDir == D3Q27System::TS) - { - int x2 = 0; - int x3 = 0; - switch (sendDir) - { - case D3Q27System::TN: - x3 = maxX3 - 1; - x2 = maxX2 - 1; - break; - case D3Q27System::BN: - x3 = 1; - x2 = maxX2 - 1; - break; - case D3Q27System::BS: - x3 = 1; - x2 = 1; - break; - case D3Q27System::TS: - x3 = maxX3 - 1; - x2 = 1; - break; - } - for (int x1 = 1; x1 < maxX1; x1++) - { - fillData(sdata, index, x1, x2, x3); - } - } - //TNE TNW TSW TSE BNE BNW BSW BSE - else if (sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSW || sendDir == D3Q27System::TSE - || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || sendDir == D3Q27System::BSW || sendDir == D3Q27System::BSE) - { - int x1 = 0; - int x2 = 0; - int x3 = 0; - switch (sendDir) - { - case D3Q27System::TNE: x1 = maxX1 - 1; x2 = maxX2 - 1; x3 = maxX3 - 1; break; - case D3Q27System::TNW: x1 = 1; x2 = maxX2 - 1; x3 = maxX3 - 1; break; - case D3Q27System::TSW: x1 = 1; x2 = 1; x3 = maxX3 - 1; break; - case D3Q27System::TSE: x1 = maxX1 - 1; x2 = 1; x3 = maxX3 - 1; break; - case D3Q27System::BNE: x1 = maxX1 - 1; x2 = maxX2 - 1; x3 = 1; break; - case D3Q27System::BNW: x1 = 1; x2 = maxX2 - 1; x3 = 1; break; - case D3Q27System::BSW: x1 = 1; x2 = 1; x3 = 1; break; - case D3Q27System::BSE: x1 = maxX1 - 1; x2 = 1; x3 = 1; break; - } - fillData(sdata, index, x1, x2, x3); - } - else UB_THROW(UbException(UB_EXARGS, "unknown dir")); + int index = 0; + // EAST + if (sendDir == D3Q27System::E) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + fillData(sdata, index, maxX1 - 1, x2, x3); + } + } + } + // WEST + else if (sendDir == D3Q27System::W) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + fillData(sdata, index, 1, x2, x3); + } + } + } + // NORTH + else if (sendDir == D3Q27System::N) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + fillData(sdata, index, x1, maxX2 - 1, x3); + } + } + } + // SOUTH + else if (sendDir == D3Q27System::S) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + fillData(sdata, index, x1, 1, x3); + } + } + } + // TOP + else if (sendDir == D3Q27System::T) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + fillData(sdata, index, x1, x2, maxX3 - 1); + } + } + } + // BOTTOM + else if (sendDir == D3Q27System::B) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + fillData(sdata, index, x1, x2, 1); + } + } + } + // NE NW SW SE + else if (sendDir == D3Q27System::NE || sendDir == D3Q27System::NW || sendDir == D3Q27System::SW || + sendDir == D3Q27System::SE) { + int x1 = 0; + int x2 = 0; + switch (sendDir) { + case D3Q27System::NE: + x1 = maxX1 - 1; + x2 = maxX2 - 1; + break; + case D3Q27System::NW: + x1 = 1; + x2 = maxX2 - 1; + break; + case D3Q27System::SW: + x1 = 1; + x2 = 1; + break; + case D3Q27System::SE: + x1 = maxX1 - 1; + x2 = 1; + break; + } + for (int x3 = 1; x3 < maxX3; x3++) { + fillData(sdata, index, x1, x2, x3); + } + } + // TE TW BW BE + else if (sendDir == D3Q27System::TE || sendDir == D3Q27System::TW || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE) { + int x1 = 0; + int x3 = 0; + switch (sendDir) { + case D3Q27System::TE: + x1 = maxX1 - 1; + x3 = maxX3 - 1; + break; + case D3Q27System::TW: + x1 = 1; + x3 = maxX3 - 1; + break; + case D3Q27System::BW: + x1 = 1; + x3 = 1; + break; + case D3Q27System::BE: + x1 = maxX1 - 1; + x3 = 1; + break; + } + for (int x2 = 1; x2 < maxX2; x2++) { + fillData(sdata, index, x1, x2, x3); + } + } + // TN BN BS TS + else if (sendDir == D3Q27System::TN || sendDir == D3Q27System::BN || sendDir == D3Q27System::BS || + sendDir == D3Q27System::TS) { + int x2 = 0; + int x3 = 0; + switch (sendDir) { + case D3Q27System::TN: + x3 = maxX3 - 1; + x2 = maxX2 - 1; + break; + case D3Q27System::BN: + x3 = 1; + x2 = maxX2 - 1; + break; + case D3Q27System::BS: + x3 = 1; + x2 = 1; + break; + case D3Q27System::TS: + x3 = maxX3 - 1; + x2 = 1; + break; + } + for (int x1 = 1; x1 < maxX1; x1++) { + fillData(sdata, index, x1, x2, x3); + } + } + // TNE TNW TSW TSE BNE BNW BSW BSE + else if (sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSW || + sendDir == D3Q27System::TSE || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSW || sendDir == D3Q27System::BSE) { + int x1 = 0; + int x2 = 0; + int x3 = 0; + switch (sendDir) { + case D3Q27System::TNE: + x1 = maxX1 - 1; + x2 = maxX2 - 1; + x3 = maxX3 - 1; + break; + case D3Q27System::TNW: + x1 = 1; + x2 = maxX2 - 1; + x3 = maxX3 - 1; + break; + case D3Q27System::TSW: + x1 = 1; + x2 = 1; + x3 = maxX3 - 1; + break; + case D3Q27System::TSE: + x1 = maxX1 - 1; + x2 = 1; + x3 = maxX3 - 1; + break; + case D3Q27System::BNE: + x1 = maxX1 - 1; + x2 = maxX2 - 1; + x3 = 1; + break; + case D3Q27System::BNW: + x1 = 1; + x2 = maxX2 - 1; + x3 = 1; + break; + case D3Q27System::BSW: + x1 = 1; + x2 = 1; + x3 = 1; + break; + case D3Q27System::BSE: + x1 = maxX1 - 1; + x2 = 1; + x3 = 1; + break; + } + fillData(sdata, index, x1, x2, x3); + } else + UB_THROW(UbException(UB_EXARGS, "unknown dir")); } //////////////////////////////////////////////////////////////////////// void D3Q27ETFullVectorConnector::distributeReceiveVectors() { - /*e.g. connector sendet nach EAST --> empfaengt daten aus WEST ;-)*/ + /*e.g. connector sendet nach EAST --> empfaengt daten aus WEST ;-)*/ - localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getLocalDistributions(); - nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getNonLocalDistributions(); - zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getZeroDistributions(); + localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getLocalDistributions(); + nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getNonLocalDistributions(); + zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(this->fDis)->getZeroDistributions(); - vector_type& rdata = receiver->getData(); + vector_type &rdata = receiver->getData(); - int index = 0; + int index = 0; - if (sendDir == D3Q27System::W) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - distributeData(rdata, index, 0, x2, x3); - } - } - } - else if (sendDir == D3Q27System::E) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - distributeData(rdata, index, maxX1, x2, x3); - } - } - } - else if (sendDir == D3Q27System::S) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - distributeData(rdata, index, x1, 0, x3); - } - } - } - else if (sendDir == D3Q27System::N) - { - for (int x3 = 1; x3 < maxX3; x3++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - distributeData(rdata, index, x1, maxX2, x3); - } - } - } - else if (sendDir == D3Q27System::B) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - distributeData(rdata, index, x1, x2, 0); - } - } - } - else if (sendDir == D3Q27System::T) - { - for (int x2 = 1; x2 < maxX2; x2++) - { - for (int x1 = 1; x1 < maxX1; x1++) - { - distributeData(rdata, index, x1, x2, maxX3); - } - } - } - //NE NW SW SE - else if (sendDir == D3Q27System::NE || sendDir == D3Q27System::NW || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE) - { - int x1 = 0; - int x2 = 0; - switch (sendDir) //wenn sendir NE dann kommen werte von SW - { - case D3Q27System::NE: - x1 = maxX1; - x2 = maxX2; - break; - case D3Q27System::NW: - x1 = 0; - x2 = maxX2; - break; - case D3Q27System::SW: - x1 = 0; - x2 = 0; - break; - case D3Q27System::SE: - x1 = maxX1; - x2 = 0; - break; - } - for (int x3 = 1; x3 < maxX3; x3++) - { - distributeData(rdata, index, x1, x2, x3); - } + if (sendDir == D3Q27System::W) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + distributeData(rdata, index, 0, x2, x3); + } + } + } else if (sendDir == D3Q27System::E) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x2 = 1; x2 < maxX2; x2++) { + distributeData(rdata, index, maxX1, x2, x3); + } + } + } else if (sendDir == D3Q27System::S) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + distributeData(rdata, index, x1, 0, x3); + } + } + } else if (sendDir == D3Q27System::N) { + for (int x3 = 1; x3 < maxX3; x3++) { + for (int x1 = 1; x1 < maxX1; x1++) { + distributeData(rdata, index, x1, maxX2, x3); + } + } + } else if (sendDir == D3Q27System::B) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + distributeData(rdata, index, x1, x2, 0); + } + } + } else if (sendDir == D3Q27System::T) { + for (int x2 = 1; x2 < maxX2; x2++) { + for (int x1 = 1; x1 < maxX1; x1++) { + distributeData(rdata, index, x1, x2, maxX3); + } + } + } + // NE NW SW SE + else if (sendDir == D3Q27System::NE || sendDir == D3Q27System::NW || sendDir == D3Q27System::SW || + sendDir == D3Q27System::SE) { + int x1 = 0; + int x2 = 0; + switch (sendDir) // wenn sendir NE dann kommen werte von SW + { + case D3Q27System::NE: + x1 = maxX1; + x2 = maxX2; + break; + case D3Q27System::NW: + x1 = 0; + x2 = maxX2; + break; + case D3Q27System::SW: + x1 = 0; + x2 = 0; + break; + case D3Q27System::SE: + x1 = maxX1; + x2 = 0; + break; + } + for (int x3 = 1; x3 < maxX3; x3++) { + distributeData(rdata, index, x1, x2, x3); + } - } - //TE TW BW BE - else if (sendDir == D3Q27System::TE || sendDir == D3Q27System::TW || sendDir == D3Q27System::BW || sendDir == D3Q27System::BE) + } + // TE TW BW BE + else if (sendDir == D3Q27System::TE || sendDir == D3Q27System::TW || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE) - { - int x1 = 0; - int x3 = 0; - switch (sendDir) //wenn sendir NE dann kommen werte von SW - { - case D3Q27System::TE: - x1 = maxX1; - x3 = maxX3; - break; - case D3Q27System::TW: - x1 = 0; - x3 = maxX3; - break; - case D3Q27System::BW: - x1 = 0; - x3 = 0; - break; - case D3Q27System::BE: - x1 = maxX1; - x3 = 0; - break; - } - for (int x2 = 1; x2 < maxX2; x2++) - { - distributeData(rdata, index, x1, x2, x3); - } - } - //TN BN BS TS - else if (sendDir == D3Q27System::TN || sendDir == D3Q27System::BN || sendDir == D3Q27System::BS || sendDir == D3Q27System::TS) - { - int x2 = 0; - int x3 = 0; - switch (sendDir) - { - case D3Q27System::TN: - x3 = maxX3; - x2 = maxX2; - break; - case D3Q27System::BN: - x3 = 0; - x2 = maxX2; - break; - case D3Q27System::BS: - x3 = 0; - x2 = 0; - break; - case D3Q27System::TS: - x3 = maxX3; - x2 = 0; - break; + { + int x1 = 0; + int x3 = 0; + switch (sendDir) // wenn sendir NE dann kommen werte von SW + { + case D3Q27System::TE: + x1 = maxX1; + x3 = maxX3; + break; + case D3Q27System::TW: + x1 = 0; + x3 = maxX3; + break; + case D3Q27System::BW: + x1 = 0; + x3 = 0; + break; + case D3Q27System::BE: + x1 = maxX1; + x3 = 0; + break; + } + for (int x2 = 1; x2 < maxX2; x2++) { + distributeData(rdata, index, x1, x2, x3); + } + } + // TN BN BS TS + else if (sendDir == D3Q27System::TN || sendDir == D3Q27System::BN || sendDir == D3Q27System::BS || + sendDir == D3Q27System::TS) { + int x2 = 0; + int x3 = 0; + switch (sendDir) { + case D3Q27System::TN: + x3 = maxX3; + x2 = maxX2; + break; + case D3Q27System::BN: + x3 = 0; + x2 = maxX2; + break; + case D3Q27System::BS: + x3 = 0; + x2 = 0; + break; + case D3Q27System::TS: + x3 = maxX3; + x2 = 0; + break; + } + for (int x1 = 1; x1 < maxX1; x1++) { + distributeData(rdata, index, x1, x2, x3); + } + } + // TNE TNW TSW TSE BNE BNW BSW BSE + else if (sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSW || + sendDir == D3Q27System::TSE || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSW || sendDir == D3Q27System::BSE) { + int x1 = 0; + int x2 = 0; + int x3 = 0; - } - for (int x1 = 1; x1 < maxX1; x1++) - { - distributeData(rdata, index, x1, x2, x3); - } - } - //TNE TNW TSW TSE BNE BNW BSW BSE - else if (sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSW || sendDir == D3Q27System::TSE - || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || sendDir == D3Q27System::BSW || sendDir == D3Q27System::BSE) - { - int x1 = 0; - int x2 = 0; - int x3 = 0; - - switch (sendDir) - { - case D3Q27System::TNE: - x1 = maxX1; - x2 = maxX2; - x3 = maxX3; - break; - case D3Q27System::TNW: - x1 = 0; - x2 = maxX2; - x3 = maxX3; - break; - case D3Q27System::TSW: - x1 = 0; - x2 = 0; - x3 = maxX3; - break; - case D3Q27System::TSE: - x1 = maxX1; - x2 = 0; - x3 = maxX3; - break; - case D3Q27System::BNE: - x1 = maxX1; - x2 = maxX2; - x3 = 0; - break; - case D3Q27System::BNW: - x1 = 0; - x2 = maxX2; - x3 = 0; - break; - case D3Q27System::BSW: - x1 = 0; - x2 = 0; - x3 = 0; - break; - case D3Q27System::BSE: - x1 = maxX1; - x2 = 0; - x3 = 0; - break; - } - distributeData(rdata, index, x1, x2, x3); - } - else UB_THROW(UbException(UB_EXARGS, "unknown dir")); + switch (sendDir) { + case D3Q27System::TNE: + x1 = maxX1; + x2 = maxX2; + x3 = maxX3; + break; + case D3Q27System::TNW: + x1 = 0; + x2 = maxX2; + x3 = maxX3; + break; + case D3Q27System::TSW: + x1 = 0; + x2 = 0; + x3 = maxX3; + break; + case D3Q27System::TSE: + x1 = maxX1; + x2 = 0; + x3 = maxX3; + break; + case D3Q27System::BNE: + x1 = maxX1; + x2 = maxX2; + x3 = 0; + break; + case D3Q27System::BNW: + x1 = 0; + x2 = maxX2; + x3 = 0; + break; + case D3Q27System::BSW: + x1 = 0; + x2 = 0; + x3 = 0; + break; + case D3Q27System::BSE: + x1 = maxX1; + x2 = 0; + x3 = 0; + break; + } + distributeData(rdata, index, x1, x2, x3); + } else + UB_THROW(UbException(UB_EXARGS, "unknown dir")); } ////////////////////////////////////////////////////////////////////////// - - diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.h b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.h index b1c3a8e82..6842293af 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETFullVectorConnector.h @@ -3,116 +3,111 @@ #include <vector> -#include "RemoteBlock3DConnector.h" -#include "D3Q27System.h" #include "Block3D.h" -#include "LBMKernel.h" +#include "D3Q27System.h" +#include "EsoTwist3D.h" #include "EsoTwistD3Q27System.h" +#include "LBMKernel.h" +#include "RemoteBlock3DConnector.h" #include "basics/container/CbArray3D.h" #include "basics/container/CbArray4D.h" -#include "EsoTwist3D.h" - -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) class D3Q27ETFullVectorConnector : public RemoteBlock3DConnector { public: - D3Q27ETFullVectorConnector(SPtr<Block3D> block - , VectorTransmitterPtr sender - , VectorTransmitterPtr receiver - , int sendDir); + D3Q27ETFullVectorConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir); - void init() override; + void init() override; - void fillSendVectors() override; - void distributeReceiveVectors() override; + void fillSendVectors() override; + void distributeReceiveVectors() override; protected: - inline void fillData(vector_type& sdata, int& index, int x1, int x2, int x3); - inline void distributeData(vector_type& rdata, int& index, int x1, int x2, int x3); -private: - int maxX1; - int maxX2; - int maxX3; + inline void fillData(vector_type &sdata, int &index, int x1, int x2, int x3); + inline void distributeData(vector_type &rdata, int &index, int x1, int x2, int x3); - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D <LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D <LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; +private: + int maxX1; + int maxX2; + int maxX3; - SPtr<EsoTwist3D> fDis; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + SPtr<EsoTwist3D> fDis; }; ////////////////////////////////////////////////////////////////////////// -inline void D3Q27ETFullVectorConnector::fillData(vector_type& sdata, int& index, int x1, int x2, int x3) +inline void D3Q27ETFullVectorConnector::fillData(vector_type &sdata, int &index, int x1, int x2, int x3) { - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); - sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); - - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); - sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); - - sdata[index++] = (*this->zeroDistributions)(x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); + sdata[index++] = (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); + + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); + sdata[index++] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); + + sdata[index++] = (*this->zeroDistributions)(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -inline void D3Q27ETFullVectorConnector::distributeData(vector_type& rdata, int& index, int x1, int x2, int x3) +inline void D3Q27ETFullVectorConnector::distributeData(vector_type &rdata, int &index, int x1, int x2, int x3) { - (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = rdata[index++]; - (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = rdata[index++]; - - (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = rdata[index++]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = rdata[index++]; - - (*this->zeroDistributions)(x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = rdata[index++]; + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = rdata[index++]; + + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = rdata[index++]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = rdata[index++]; + + (*this->zeroDistributions)(x1, x2, x3) = rdata[index++]; } - -#endif //D3Q27VECTORCONNECTOR_H - +#endif // D3Q27VECTORCONNECTOR_H diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.cpp b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.cpp index 4d01e21e5..fdeb0e556 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.cpp @@ -5,15 +5,15 @@ //#include "D3Q27ETFCVectorConnector.h" //#include "FineToCoarseBlock3DConnector.h" // -//D3Q27ETOffConnectorFactory::D3Q27ETOffConnectorFactory() +// D3Q27ETOffConnectorFactory::D3Q27ETOffConnectorFactory() //{ //} //////////////////////////////////////////////////////////////////////////// -//D3Q27ETOffConnectorFactory::~D3Q27ETOffConnectorFactory() +// D3Q27ETOffConnectorFactory::~D3Q27ETOffConnectorFactory() //{ //} //////////////////////////////////////////////////////////////////////////// -//SPtr<Block3DConnector> D3Q27ETOffConnectorFactory::createCoarseToFineConnector(SPtr<Block3D> block, +// SPtr<Block3DConnector> D3Q27ETOffConnectorFactory::createCoarseToFineConnector(SPtr<Block3D> block, // VectorTransmitterPtr sender00, VectorTransmitterPtr receiver00, // VectorTransmitterPtr sender01, VectorTransmitterPtr receiver01, // VectorTransmitterPtr sender10, VectorTransmitterPtr receiver10, @@ -26,7 +26,7 @@ // sendDir, iprocessor)); //} //////////////////////////////////////////////////////////////////////////// -//SPtr<Block3DConnector> D3Q27ETOffConnectorFactory::createFineToCoarseConnector(SPtr<Block3D> block, +// SPtr<Block3DConnector> D3Q27ETOffConnectorFactory::createFineToCoarseConnector(SPtr<Block3D> block, // VectorTransmitterPtr sender, // VectorTransmitterPtr receiver, // int sendDir, diff --git a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.h b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.h index 4879a1930..8ed08c80a 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.h +++ b/src/cpu/VirtualFluidsCore/Connectors/D3Q27ETOffConnectorFactory.h @@ -4,12 +4,12 @@ //#include "Block3DConnectorFactory.h" // //#include <PointerDefinitions.h> -//class D3Q27ETOffConnectorFactory; -//typedef SPtr<D3Q27ETOffConnectorFactory> D3Q27ETOffSPtr<ConnectorFactory>; +// class D3Q27ETOffConnectorFactory; +// typedef SPtr<D3Q27ETOffConnectorFactory> D3Q27ETOffSPtr<ConnectorFactory>; // -//class D3Q27ETOffConnectorFactory : public Block3DConnectorFactory +// class D3Q27ETOffConnectorFactory : public Block3DConnectorFactory //{ -//public: +// public: // D3Q27ETOffConnectorFactory(); // virtual ~D3Q27ETOffConnectorFactory(); // @@ -27,8 +27,7 @@ // D3Q27InterpolationProcessorPtr iprocessor, // FineToCoarseBlock3DConnector::CFconnectorType connType); // -//private: +// private: // //}; //#endif // D3Q27ETOffConnectorFactory_h__ - diff --git a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.cpp index faaaca492..ca6d017a5 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.cpp @@ -2,76 +2,73 @@ //////////////////////////////////////////////////////////////////////////// FineToCoarseBlock3DConnector::FineToCoarseBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, - VectorTransmitterPtr receiver, int sendDir, - InterpolationProcessorPtr iprocessor, - CFconnectorType connType) - : Block3DConnector(sendDir) - , block(block) - , sender(sender) - , receiver(receiver) - , iprocessor(iprocessor) - , connType(connType) + VectorTransmitterPtr receiver, int sendDir, + InterpolationProcessorPtr iprocessor, + CFconnectorType connType) + : Block3DConnector(sendDir), block(block), sender(sender), receiver(receiver), iprocessor(iprocessor), + connType(connType) { - if (!(sendDir==D3Q27System::E || sendDir==D3Q27System::W || sendDir==D3Q27System::N || sendDir==D3Q27System::S || sendDir==D3Q27System::T || sendDir==D3Q27System::B - || sendDir==D3Q27System::NE || sendDir==D3Q27System::SW || sendDir==D3Q27System::SE || sendDir==D3Q27System::NW - || sendDir==D3Q27System::TE || sendDir==D3Q27System::BW || sendDir==D3Q27System::BE || sendDir==D3Q27System::TW - || sendDir==D3Q27System::TN || sendDir==D3Q27System::BS || sendDir==D3Q27System::BN || sendDir==D3Q27System::TS + if (!(sendDir == D3Q27System::E || sendDir == D3Q27System::W || sendDir == D3Q27System::N || + sendDir == D3Q27System::S || sendDir == D3Q27System::T || sendDir == D3Q27System::B || + sendDir == D3Q27System::NE || sendDir == D3Q27System::SW || sendDir == D3Q27System::SE || + sendDir == D3Q27System::NW || sendDir == D3Q27System::TE || sendDir == D3Q27System::BW || + sendDir == D3Q27System::BE || sendDir == D3Q27System::TW || sendDir == D3Q27System::TN || + sendDir == D3Q27System::BS || sendDir == D3Q27System::BN || sendDir == D3Q27System::TS - || sendDir==D3Q27System::TNE || sendDir==D3Q27System::TNW || sendDir==D3Q27System::TSE || sendDir==D3Q27System::TSW - || sendDir==D3Q27System::BNE || sendDir==D3Q27System::BNW || sendDir==D3Q27System::BSE || sendDir==D3Q27System::BSW + || sendDir == D3Q27System::TNE || sendDir == D3Q27System::TNW || sendDir == D3Q27System::TSE || + sendDir == D3Q27System::TSW || sendDir == D3Q27System::BNE || sendDir == D3Q27System::BNW || + sendDir == D3Q27System::BSE || sendDir == D3Q27System::BSW - )) - { - throw UbException(UB_EXARGS, "invalid constructor for this direction"); - } + )) { + throw UbException(UB_EXARGS, "invalid constructor for this direction"); + } } ////////////////////////////////////////////////////////////////////////// -bool FineToCoarseBlock3DConnector::isLocalConnector() -{ - return !this->isRemoteConnector(); -} +bool FineToCoarseBlock3DConnector::isLocalConnector() { return !this->isRemoteConnector(); } ////////////////////////////////////////////////////////////////////////// bool FineToCoarseBlock3DConnector::isRemoteConnector() { - return sender->isRemoteTransmitter() || receiver->isRemoteTransmitter(); + return sender->isRemoteTransmitter() || receiver->isRemoteTransmitter(); } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::sendTransmitterDataSize() { - if (sender) - { - UBLOG(logDEBUG5, "FineToCoarseBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()"<<block.lock()->toString()+"sendDir="<<sendDir); - sender->sendDataSize(); - } + if (sender) { + UBLOG(logDEBUG5, "FineToCoarseBlock3DConnector<VectorTransmitter>::sendTransmitterDataSize()" + << block.lock()->toString() + "sendDir=" << sendDir); + sender->sendDataSize(); + } } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::receiveTransmitterDataSize() { - if (receiver) - { - UBLOG(logDEBUG5, "FineToCoarseBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()"<<block.lock()->toString()<<"sendDir="<<sendDir); - receiver->receiveDataSize(); - } + if (receiver) { + UBLOG(logDEBUG5, "FineToCoarseBlock3DConnector<VectorTransmitter>::receiveTransmitterDataSize()" + << block.lock()->toString() << "sendDir=" << sendDir); + receiver->receiveDataSize(); + } } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::prepareForSend() { - if (sender) sender->prepareForSend(); + if (sender) + sender->prepareForSend(); } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::sendVectors() { - if (sender) sender->sendData(); + if (sender) + sender->sendData(); } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::prepareForReceive() { - if (receiver) receiver->prepareForReceive(); + if (receiver) + receiver->prepareForReceive(); } ////////////////////////////////////////////////////////////////////////// void FineToCoarseBlock3DConnector::receiveVectors() { - if (receiver) receiver->receiveData(); + if (receiver) + receiver->receiveData(); } - - diff --git a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.h index c4bbc182f..5e988887c 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseBlock3DConnector.h @@ -1,38 +1,37 @@ //! \file FineToCoarseBlock3DConnector.h -//! \brief Base class for connectors that interpolates and sends data from fine level to coarse. +//! \brief Base class for connectors that interpolates and sends data from fine level to coarse. //! \author Konstantin Kutscher //! \date 21.05.2015 #ifndef FineToCoarseBlock3DConnector_H #define FineToCoarseBlock3DConnector_H -#include "TransmitterType.h" +#include "Block3D.h" #include "Block3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" -#include "LBMKernel.h" #include "InterpolationProcessor.h" +#include "LBMKernel.h" +#include "TransmitterType.h" #include <PointerDefinitions.h> - class Block3D; //! \class FineToCoarseBlock3DConnector -//! \brief Base class for connectors that interpolates and sends data from fine level to coarse. -//! \details The data is copied in a vector (this is located in the transmitter). -//! The vector is transmitted via transmitter. -//! The transmitter can be a local, MPI, RCG, CTL or whatever +//! \brief Base class for connectors that interpolates and sends data from fine level to coarse. +//! \details The data is copied in a vector (this is located in the transmitter). +//! The vector is transmitted via transmitter. +//! The transmitter can be a local, MPI, RCG, CTL or whatever //! which a transmitter that is derived from transmitter base class. //! //! four fine blocks inside a coarse block: //! //! | | | -//! |:--:|:---| -//! | 01 | 11 | -//! | 00 | 10 | +//! |:--:|:---| +//! | 01 | 11 | +//! | 00 | 10 | //! -//! send direction: +//! send direction: //! //! |E<->W | N<->S | T<->B | //! |--------|---------|--------| @@ -43,53 +42,52 @@ class Block3D; class FineToCoarseBlock3DConnector : public Block3DConnector { public: - enum CFconnectorType { Type00, Type10, Type01, Type11 }; + enum CFconnectorType { Type00, Type10, Type01, Type11 }; + public: - FineToCoarseBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType); + FineToCoarseBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType); + + bool isLocalConnector() override; + bool isRemoteConnector() override; - bool isLocalConnector() override; - bool isRemoteConnector() override; - - void sendTransmitterDataSize() override; - void receiveTransmitterDataSize() override; + void sendTransmitterDataSize() override; + void receiveTransmitterDataSize() override; - void prepareForSend() override; - void sendVectors() override; + void prepareForSend() override; + void sendVectors() override; - void prepareForReceive() override; - void receiveVectors() override; + void prepareForReceive() override; + void receiveVectors() override; - void init() override =0; - void fillSendVectors() override =0; - void distributeReceiveVectors() override =0; + void init() override = 0; + void fillSendVectors() override = 0; + void distributeReceiveVectors() override = 0; - bool isInterpolationConnectorCF() override { return false; } - bool isInterpolationConnectorFC() override { return true; } + bool isInterpolationConnectorCF() override { return false; } + bool isInterpolationConnectorFC() override { return true; } - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override {} - void sendVectorsX2() override {} - void sendVectorsX3() override {} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> block; - VectorTransmitterPtr sender, receiver; - InterpolationProcessorPtr iprocessor; - CFconnectorType connType; + WPtr<Block3D> block; + VectorTransmitterPtr sender, receiver; + InterpolationProcessorPtr iprocessor; + CFconnectorType connType; }; - - -#endif - +#endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.cpp index 591fc727c..06bb95328 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.cpp @@ -2,1141 +2,1016 @@ #include "BCProcessor.h" #include "DataSet3D.h" - ////////////////////////////////////////////////////////////////////////// -FineToCoarseNodeSetBlock3DConnector::FineToCoarseNodeSetBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, - int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType) : FineToCoarseBlock3DConnector(block, sender, receiver, sendDir, iprocessor, connType) +FineToCoarseNodeSetBlock3DConnector::FineToCoarseNodeSetBlock3DConnector(SPtr<Block3D> block, + VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir, + InterpolationProcessorPtr iprocessor, + CFconnectorType connType) + : FineToCoarseBlock3DConnector(block, sender, receiver, sendDir, iprocessor, connType) { - } ////////////////////////////////////////////////////////////////////////// void FineToCoarseNodeSetBlock3DConnector::init() { - bMaxX1 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); - bMaxX2 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); - bMaxX3 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); - - minX1 = 0; - minX2 = 0; - minX3 = 0; - maxX1 = bMaxX1 - 1; - maxX2 = bMaxX2 - 1; - maxX3 = bMaxX3 - 1; - - minOffX1 = 0; - minOffX2 = 0; - minOffX3 = 0; - - maxOffX1 = 0; - maxOffX2 = 0; - maxOffX3 = 0; - - if (Utilities::isEven(bMaxX1)) - { - minOffX1 = 0; - maxOffX1 = 0; - } - else if (Utilities::isOdd(bMaxX1)) - { - minOffX1 = 1; - maxOffX1 = -1; - } - - if (Utilities::isEven(bMaxX2)) - { - minOffX2 = 0; - maxOffX2 = 0; - } - else if (Utilities::isOdd(bMaxX2)) - { - minOffX2 = 1; - maxOffX2 = -1; - } - - if (Utilities::isEven(bMaxX3)) - { - minOffX3 = 0; - maxOffX3 = 0; - } - else if (Utilities::isOdd(bMaxX3)) - { - minOffX3 = 1; - maxOffX3 = -1; - } - - //int sendSize = 0; - LBMReal initValue = -999.0; - - int sendDataPerNode = 27/*f*/; - int iCellSize = 1; //size of interpolation cell - - findFCCells(); - findCFCells(); - - ////////////////////////////////////////////////////// - //Debug - ////////////////////////////////////////////////////// -// if (FineToCoarseBlock3DConnector::block.lock()->getGlobalID() == 2183) -// { -// int test = 0; -// } - - - if (FineToCoarseBlock3DConnector::sender) FineToCoarseBlock3DConnector::sender->getData().resize(iNodeSetSender.size()*iCellSize*sendDataPerNode, initValue); - else FineToCoarseBlock3DConnector::sender = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - - if (!FineToCoarseBlock3DConnector::receiver) FineToCoarseBlock3DConnector::receiver = VectorTransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); + bMaxX1 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX1(); + bMaxX2 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX2(); + bMaxX3 = (int)FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions()->getNX3(); + + minX1 = 0; + minX2 = 0; + minX3 = 0; + maxX1 = bMaxX1 - 1; + maxX2 = bMaxX2 - 1; + maxX3 = bMaxX3 - 1; + + minOffX1 = 0; + minOffX2 = 0; + minOffX3 = 0; + + maxOffX1 = 0; + maxOffX2 = 0; + maxOffX3 = 0; + + if (Utilities::isEven(bMaxX1)) { + minOffX1 = 0; + maxOffX1 = 0; + } else if (Utilities::isOdd(bMaxX1)) { + minOffX1 = 1; + maxOffX1 = -1; + } + + if (Utilities::isEven(bMaxX2)) { + minOffX2 = 0; + maxOffX2 = 0; + } else if (Utilities::isOdd(bMaxX2)) { + minOffX2 = 1; + maxOffX2 = -1; + } + + if (Utilities::isEven(bMaxX3)) { + minOffX3 = 0; + maxOffX3 = 0; + } else if (Utilities::isOdd(bMaxX3)) { + minOffX3 = 1; + maxOffX3 = -1; + } + + // int sendSize = 0; + LBMReal initValue = -999.0; + + int sendDataPerNode = 27 /*f*/; + int iCellSize = 1; // size of interpolation cell + + findFCCells(); + findCFCells(); + + ////////////////////////////////////////////////////// + // Debug + ////////////////////////////////////////////////////// + // if (FineToCoarseBlock3DConnector::block.lock()->getGlobalID() == 2183) + // { + // int test = 0; + // } + + if (FineToCoarseBlock3DConnector::sender) + FineToCoarseBlock3DConnector::sender->getData().resize(iNodeSetSender.size() * iCellSize * sendDataPerNode, + initValue); + else + FineToCoarseBlock3DConnector::sender = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + + if (!FineToCoarseBlock3DConnector::receiver) + FineToCoarseBlock3DConnector::receiver = VectorTransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); } ////////////////////////////////////////////////////////////////////////// -void FineToCoarseNodeSetBlock3DConnector::findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes) +void FineToCoarseNodeSetBlock3DConnector::findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, + int lMaxX3, INodeSet &inodes) { - ////////////////////////////////////////////////////// - //Debug - ////////////////////////////////////////////////////// -// if (FineToCoarseBlock3DConnector::block.lock()->getGlobalID() == 2183) -// { -// int test = 0; -// } + ////////////////////////////////////////////////////// + // Debug + ////////////////////////////////////////////////////// + // if (FineToCoarseBlock3DConnector::block.lock()->getGlobalID() == 2183) + // { + // int test = 0; + // } + + int ix1, ix2, ix3; + LBMReal x1off, x2off, x3off; + + SPtr<DistributionArray3D> fFrom = + FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions(); + SPtr<BCArray3D> bcArray = FineToCoarseBlock3DConnector::block.lock()->getKernel()->getBCProcessor()->getBCArray(); + + for (ix3 = lMinX3; ix3 <= lMaxX3; ix3 += 2) { + for (ix2 = lMinX2; ix2 <= lMaxX2; ix2 += 2) { + for (ix1 = lMinX1; ix1 <= lMaxX1; ix1 += 2) { + D3Q27ICell icellC; + + int howManySolids = + FineToCoarseBlock3DConnector::iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + + if (howManySolids == 0 || howManySolids == 8) { + x1off = 0.0; + x2off = 0.0; + x3off = 0.0; + } else { + if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, + x1off, x2off, x3off)) { + std::string err = "For " + FineToCoarseBlock3DConnector::block.lock()->toString() + + " x1=" + UbSystem::toString(ix1) + ", x2=" + UbSystem::toString(ix2) + + ", x3=" + UbSystem::toString(ix3) + + " interpolation is not implemented for other direction" + + " by using in: " + (std::string) typeid(*this).name() + + " or maybe you have a solid on the block boundary"; + UB_THROW(UbException(UB_EXARGS, err)); + } + } + + INodeVector inv; + inv.push_back(ix1 + (int)x1off); + inv.push_back(ix2 + (int)x2off); + inv.push_back(ix3 + (int)x3off); + inv.push_back((int)x1off); + inv.push_back((int)x2off); + inv.push_back((int)x3off); + // inodes.insert(inv); + inodes.push_back(inv); + } + } + } +} +////////////////////////////////////////////////////////////////////////// +void FineToCoarseNodeSetBlock3DConnector::findFCCells() +{ + using namespace D3Q27System; + + int lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3; + int lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3; + int lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3; + + // lMin1X1 = minX1+1; lMin1X2 = minX2+1; lMin1X3 = minX3+1; + // lMax1X1 = maxX1-1; lMax1X2 = maxX2-1; lMax1X3 = maxX3-1; + // getLocalMinMax(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3); + + // lMin2X1 = minX1+1; lMin2X2 = minX2+1; lMin2X3 = minX3+1; + // lMax2X1 = maxX1-1; lMax2X2 = maxX2-1; lMax2X3 = maxX3-1; + // getLocalMinMax(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3); + + // lMin3X1 = minX1+1; lMin3X2 = minX2+1; lMin3X3 = minX3+1; + // lMax3X1 = maxX1-1; lMax3X2 = maxX2-1; lMax3X3 = maxX3-1; + // getLocalMinMax(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3); + + switch (sendDir) { + // faces + case E: + case W: + if (sendDir == E) { + lMin1X1 = maxX1 - 6; + lMax1X1 = lMin1X1; + } else if (sendDir == W) { + lMin1X1 = 5; + lMax1X1 = lMin1X1; + } - int ix1, ix2, ix3; - LBMReal x1off, x2off, x3off; + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X2 = minX2; + lMax1X2 = maxX2 + maxOffX2 - 1; + lMin1X3 = minX3; + lMax1X3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X2 = minX2 + minOffX2; + lMax1X2 = maxX2 - 1; + lMin1X3 = minX3; + lMax1X3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMin1X2 = minX2; + lMax1X2 = maxX2 + maxOffX2 - 1; + lMin1X3 = minX3 + minOffX3; + lMax1X3 = maxX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMin1X2 = minX2 + minOffX2; + lMax1X2 = maxX2 - 1; + lMin1X3 = minX3 + minOffX3; + lMax1X3 = maxX3 - 1; + } + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + break; + case N: + case S: + if (sendDir == N) { + lMin1X2 = maxX2 - 6; + lMax1X2 = lMin1X2; + } else if (sendDir == S) { + lMin1X2 = 5; + lMax1X2 = lMin1X2; + } - SPtr<DistributionArray3D> fFrom = FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions(); - SPtr<BCArray3D> bcArray = FineToCoarseBlock3DConnector::block.lock()->getKernel()->getBCProcessor()->getBCArray(); + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X1 = minX1; + lMax1X1 = maxX1 + maxOffX1 - 1; + lMin1X3 = minX3; + lMax1X3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X1 = minX1 + minOffX1; + lMax1X1 = maxX1 - 1; + lMin1X3 = minX3; + lMax1X3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMin1X1 = minX1; + lMax1X1 = maxX1 + maxOffX1 - 1; + lMin1X3 = minX3 + minOffX3; + lMax1X3 = maxX3; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMin1X1 = minX1 + minOffX1; + lMax1X1 = maxX1 - 1; + lMin1X3 = minX3 + minOffX3; + lMax1X3 = maxX3 - 1; + } + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + break; + case T: + case B: + if (sendDir == T) { + lMin1X3 = maxX3 - 6; + lMax1X3 = lMin1X3; + } else if (sendDir == B) { + lMin1X3 = 5; + lMax1X3 = lMin1X3; + } - for (ix3 = lMinX3; ix3<=lMaxX3; ix3 += 2) - { - for (ix2 = lMinX2; ix2<=lMaxX2; ix2 += 2) - { - for (ix1 = lMinX1; ix1<=lMaxX1; ix1 += 2) - { - D3Q27ICell icellC; + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X1 = minX1; + lMax1X1 = maxX1 + maxOffX1 - 1; + lMin1X2 = minX2; + lMax1X2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X1 = minX1 + minOffX1; + lMax1X1 = maxX1 - 1; + lMin1X2 = minX2; + lMax1X2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMin1X1 = minX1; + lMax1X1 = maxX1 + maxOffX1 - 1; + lMin1X2 = minX2 + minOffX2; + lMax1X2 = maxX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMin1X1 = minX1 + minOffX1; + lMax1X1 = maxX1 - 1; + lMin1X2 = minX2 + minOffX2; + lMax1X2 = maxX2 - 1; + } + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + break; + // edges + // N-S-E-W + case NE: + case SW: + case SE: + case NW: + if (sendDir == NE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = lMin1X1 + 4; + lMin1X2 = maxX2 - 6; + lMax1X2 = lMin1X2; + + lMin2X1 = maxX1 - 6; + lMax2X1 = lMin2X1; + lMin2X2 = maxX2 - 6; + lMax2X2 = lMin2X2 + 4; + } else if (sendDir == SW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 4; + lMin1X2 = 5; + lMax1X2 = lMin1X2; + + lMin2X1 = 5; + lMax2X1 = lMin2X1; + lMin2X2 = 1; + lMax2X2 = lMin2X2 + 4; + } else if (sendDir == SE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = lMin1X1 + 4; + lMin1X2 = 5; + lMax1X2 = lMin1X2; + + lMin2X1 = maxX1 - 6; + lMax2X1 = lMin2X1; + lMin2X2 = 1; + lMax2X2 = lMin2X2 + 4; + } else if (sendDir == NW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 4; + lMin1X2 = maxX2 - 6; + lMax1X2 = lMin1X2; + + lMin2X1 = 5; + lMax2X1 = lMin2X1; + lMin2X2 = maxX2 - 6; + lMax2X2 = lMin2X2 + 4; + } - int howManySolids = FineToCoarseBlock3DConnector::iprocessor->iCellHowManySolids(bcArray, ix1, ix2, ix3); + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X3 = minX3; + lMax1X3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X3 = minX3 + minOffX3; + lMax1X3 = maxX3 - 1; + } - if (howManySolids == 0 || howManySolids == 8) - { - x1off = 0.0; - x2off = 0.0; - x3off = 0.0; + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + findFCCells(lMin2X1, lMin2X2, lMin1X3, lMax2X1, lMax2X2, lMax1X3, iNodeSetSender); + + break; + // T-B-E-W + case TE: + case BW: + case BE: + case TW: + if (sendDir == TE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = lMin1X1 + 4; + lMin1X3 = maxX3 - 6; + lMax1X3 = lMin1X3; + + lMin2X1 = maxX1 - 6; + lMax2X1 = lMin2X1; + lMin2X3 = maxX3 - 6; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == BW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 4; + lMin1X3 = 5; + lMax1X3 = lMin1X3; + + lMin2X1 = 5; + lMax2X1 = lMin2X1; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == BE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = lMin1X1 + 4; + lMin1X3 = 5; + lMax1X3 = lMin1X3; + + lMin2X1 = maxX1 - 6; + lMax2X1 = lMin2X1; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == TW) { + lMin1X1 = 1; + lMax1X1 = lMin1X1 + 5; + lMin1X3 = maxX3 - 6; + lMax1X3 = lMin1X3; + + lMin2X1 = 5; + lMax2X1 = lMin2X1; + lMin2X3 = maxX3 - 6; + lMax2X3 = lMin2X3 + 4; } - else - { - if (!iprocessor->findNeighborICell(bcArray, fFrom, icellC, bMaxX1, bMaxX2, bMaxX3, ix1, ix2, ix3, x1off, x2off, x3off)) - { - std::string err = "For "+FineToCoarseBlock3DConnector::block.lock()->toString()+" x1="+UbSystem::toString(ix1)+", x2=" + UbSystem::toString(ix2)+", x3=" + UbSystem::toString(ix3)+ - " interpolation is not implemented for other direction"+ - " by using in: "+(std::string)typeid(*this).name()+ - " or maybe you have a solid on the block boundary"; - UB_THROW(UbException(UB_EXARGS, err)); - } + + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X2 = minX2; + lMax1X2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X2 = minX2 + minOffX2; + lMax1X2 = maxX2 - 1; } - INodeVector inv; - inv.push_back(ix1 + (int)x1off); - inv.push_back(ix2 + (int)x2off); - inv.push_back(ix3 + (int)x3off); - inv.push_back((int)x1off); - inv.push_back((int)x2off); - inv.push_back((int)x3off); - //inodes.insert(inv); - inodes.push_back(inv); - } - } - } -} -////////////////////////////////////////////////////////////////////////// + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + findFCCells(lMin2X1, lMin1X2, lMin2X3, lMax2X1, lMax1X2, lMax2X3, iNodeSetSender); + break; + // T-B-N-S + case TN: + case BS: + case BN: + case TS: + if (sendDir == TN) { + lMin1X2 = maxX2 - 6; + lMax1X2 = lMin1X2 + 4; + lMin1X3 = maxX3 - 6; + lMax1X3 = lMin1X3; + + lMin2X2 = maxX2 - 6; + lMax2X2 = lMin2X2; + lMin2X3 = maxX3 - 6; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == BS) { + lMin1X2 = 1; + lMax1X2 = lMin1X2 + 4; + lMin1X3 = 5; + lMax1X3 = lMin1X3; + + lMin2X2 = 5; + lMax2X2 = lMin2X2; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == BN) { + lMin1X2 = maxX2 - 6; + lMax1X2 = lMin1X2 + 4; + lMin1X3 = 5; + lMax1X3 = lMin1X3; + + lMin2X2 = maxX2 - 6; + lMax2X2 = lMin2X2; + lMin2X3 = 1; + lMax2X3 = lMin2X3 + 4; + } else if (sendDir == TS) { + lMin1X2 = 1; + lMax1X2 = lMin1X2 + 4; + lMin1X3 = maxX3 - 6; + lMax1X3 = lMin1X3; + + lMin2X2 = 5; + lMax2X2 = lMin2X2; + lMin2X3 = maxX3 - 6; + lMax2X3 = lMin2X3 + 4; + } -void FineToCoarseNodeSetBlock3DConnector::findFCCells() -{ - using namespace D3Q27System; - - int lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3; - int lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3; - int lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3; - - //lMin1X1 = minX1+1; lMin1X2 = minX2+1; lMin1X3 = minX3+1; - //lMax1X1 = maxX1-1; lMax1X2 = maxX2-1; lMax1X3 = maxX3-1; - //getLocalMinMax(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3); - - //lMin2X1 = minX1+1; lMin2X2 = minX2+1; lMin2X3 = minX3+1; - //lMax2X1 = maxX1-1; lMax2X2 = maxX2-1; lMax2X3 = maxX3-1; - //getLocalMinMax(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3); - - //lMin3X1 = minX1+1; lMin3X2 = minX2+1; lMin3X3 = minX3+1; - //lMax3X1 = maxX1-1; lMax3X2 = maxX2-1; lMax3X3 = maxX3-1; - //getLocalMinMax(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3); - - switch (sendDir) - { - //faces - case E: case W: - if (sendDir == E) - { - lMin1X1 = maxX1 - 6; - lMax1X1 = lMin1X1; - } - else if (sendDir == W) - { - lMin1X1 = 5; - lMax1X1 = lMin1X1; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X2 = minX2; - lMax1X2 = maxX2 + maxOffX2 - 1; - lMin1X3 = minX3; - lMax1X3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X2 = minX2 + minOffX2; - lMax1X2 = maxX2 - 1; - lMin1X3 = minX3; - lMax1X3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMin1X2 = minX2; - lMax1X2 = maxX2 + maxOffX2 - 1; - lMin1X3 = minX3 + minOffX3; - lMax1X3 = maxX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMin1X2 = minX2 + minOffX2; - lMax1X2 = maxX2 - 1; - lMin1X3 = minX3 + minOffX3; - lMax1X3 = maxX3 - 1; - } - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - break; - case N: case S: - if (sendDir == N) - { - lMin1X2 = maxX2 - 6; - lMax1X2 = lMin1X2; - } - else if (sendDir == S) - { - lMin1X2 = 5; - lMax1X2 = lMin1X2; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X1 = minX1; - lMax1X1 = maxX1 + maxOffX1 - 1; - lMin1X3 = minX3; - lMax1X3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X1 = minX1 + minOffX1; - lMax1X1 = maxX1 - 1; - lMin1X3 = minX3; - lMax1X3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMin1X1 = minX1; - lMax1X1 = maxX1 + maxOffX1 - 1; - lMin1X3 = minX3 + minOffX3; - lMax1X3 = maxX3; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMin1X1 = minX1 + minOffX1; - lMax1X1 = maxX1 - 1; - lMin1X3 = minX3 + minOffX3; - lMax1X3 = maxX3 - 1; - } - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - break; - case T: case B: - if (sendDir == T) - { - lMin1X3 = maxX3 - 6; - lMax1X3 = lMin1X3; - } - else if (sendDir == B) - { - lMin1X3 = 5; - lMax1X3 = lMin1X3; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X1 = minX1; - lMax1X1 = maxX1 + maxOffX1 - 1; - lMin1X2 = minX2; - lMax1X2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X1 = minX1 + minOffX1; - lMax1X1 = maxX1 - 1; - lMin1X2 = minX2; - lMax1X2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMin1X1 = minX1; - lMax1X1 = maxX1 + maxOffX1 - 1; - lMin1X2 = minX2 + minOffX2; - lMax1X2 = maxX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMin1X1 = minX1 + minOffX1; - lMax1X1 = maxX1 - 1; - lMin1X2 = minX2 + minOffX2; - lMax1X2 = maxX2 - 1; - } - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - break; - //edges - //N-S-E-W - case NE: case SW: case SE: case NW: - if (sendDir == NE) - { - lMin1X1 = maxX1 - 6; - lMax1X1 = lMin1X1 + 4; - lMin1X2 = maxX2 - 6; - lMax1X2 = lMin1X2; - - lMin2X1 = maxX1 - 6; - lMax2X1 = lMin2X1; - lMin2X2 = maxX2 - 6; - lMax2X2 = lMin2X2 + 4; - } - else if (sendDir == SW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 4; - lMin1X2 = 5; - lMax1X2 = lMin1X2; - - lMin2X1 = 5; - lMax2X1 = lMin2X1; - lMin2X2 = 1; - lMax2X2 = lMin2X2 + 4; - } - else if (sendDir == SE) - { - lMin1X1 = maxX1 - 6; - lMax1X1 = lMin1X1 + 4; - lMin1X2 = 5; - lMax1X2 = lMin1X2; - - lMin2X1 = maxX1 - 6; - lMax2X1 = lMin2X1; - lMin2X2 = 1; - lMax2X2 = lMin2X2 + 4; - } - else if (sendDir == NW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 4; - lMin1X2 = maxX2 - 6; - lMax1X2 = lMin1X2; - - lMin2X1 = 5; - lMax2X1 = lMin2X1; - lMin2X2 = maxX2 - 6; - lMax2X2 = lMin2X2 + 4; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X3 = minX3; - lMax1X3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X3 = minX3 + minOffX3; - lMax1X3 = maxX3 - 1; - } - - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - findFCCells(lMin2X1, lMin2X2, lMin1X3, lMax2X1, lMax2X2, lMax1X3, iNodeSetSender); - - break; - //T-B-E-W - case TE: case BW: case BE: case TW: - if (sendDir == TE) - { - lMin1X1 = maxX1 - 6; - lMax1X1 = lMin1X1 + 4; - lMin1X3 = maxX3 - 6; - lMax1X3 = lMin1X3; - - lMin2X1 = maxX1 - 6; - lMax2X1 = lMin2X1; - lMin2X3 = maxX3 - 6; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == BW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 4; - lMin1X3 = 5; - lMax1X3 = lMin1X3; - - lMin2X1 = 5; - lMax2X1 = lMin2X1; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == BE) - { - lMin1X1 = maxX1 - 6; - lMax1X1 = lMin1X1 + 4; - lMin1X3 = 5; - lMax1X3 = lMin1X3; - - - lMin2X1 = maxX1 - 6; - lMax2X1 = lMin2X1; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == TW) - { - lMin1X1 = 1; - lMax1X1 = lMin1X1 + 5; - lMin1X3 = maxX3 - 6; - lMax1X3 = lMin1X3; - - lMin2X1 = 5; - lMax2X1 = lMin2X1; - lMin2X3 = maxX3 - 6; - lMax2X3 = lMin2X3 + 4; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X2 = minX2; - lMax1X2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X2 = minX2 + minOffX2; - lMax1X2 = maxX2 - 1; - } - - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - findFCCells(lMin2X1, lMin1X2, lMin2X3, lMax2X1, lMax1X2, lMax2X3, iNodeSetSender); - break; - //T-B-N-S - case TN: case BS: case BN: case TS: - if (sendDir == TN) - { - lMin1X2 = maxX2 - 6; - lMax1X2 = lMin1X2 + 4; - lMin1X3 = maxX3 - 6; - lMax1X3 = lMin1X3; - - lMin2X2 = maxX2 - 6; - lMax2X2 = lMin2X2; - lMin2X3 = maxX3 - 6; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == BS) - { - lMin1X2 = 1; - lMax1X2 = lMin1X2 + 4; - lMin1X3 = 5; - lMax1X3 = lMin1X3; - - lMin2X2 = 5; - lMax2X2 = lMin2X2; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == BN) - { - lMin1X2 = maxX2 - 6; - lMax1X2 = lMin1X2 + 4; - lMin1X3 = 5; - lMax1X3 = lMin1X3; - - lMin2X2 = maxX2 - 6; - lMax2X2 = lMin2X2; - lMin2X3 = 1; - lMax2X3 = lMin2X3 + 4; - } - else if (sendDir == TS) - { - lMin1X2 = 1; - lMax1X2 = lMin1X2 + 4; - lMin1X3 = maxX3 - 6; - lMax1X3 = lMin1X3; - - lMin2X2 = 5; - lMax2X2 = lMin2X2; - lMin2X3 = maxX3 - 6; - lMax2X3 = lMin2X3 + 4; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMin1X1 = minX1; - lMax1X1 = maxX1 + maxOffX1 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMin1X1 = minX1 + minOffX1; - lMax1X1 = maxX1 - 1; - } - - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - findFCCells(lMin1X1, lMin2X2, lMin2X3, lMax1X1, lMax2X2, lMax2X3, iNodeSetSender); - break; - //corners - case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: - if (sendDir == TNE) - { - lMin1X1 = maxX1-6; - lMax1X1 = maxX1-6; - lMin1X2 = maxX2-6; - lMax1X2 = maxX2-2; - lMin1X3 = maxX3-6; - lMax1X3 = maxX3-2; - - lMin2X1 = maxX1-6; - lMax2X1 = maxX1-2; - lMin2X2 = maxX2-6; - lMax2X2 = maxX2-6; - lMin2X3 = maxX3-6; - lMax2X3 = maxX3-1; - - lMin3X1 = maxX1-6; - lMax3X1 = maxX1-2; - lMin3X2 = maxX2-6; - lMax3X2 = maxX2-2; - lMin3X3 = maxX3-6; - lMax3X3 = maxX3-5; - } - else if (sendDir == TNW) - { - lMin1X1 = 5; - lMax1X1 = 5; - lMin1X2 = maxX2-6; - lMax1X2 = maxX2-2; - lMin1X3 = maxX3-6; - lMax1X3 = maxX3-2; - - lMin2X1 = 1; - lMax2X1 = 5; - lMin2X2 = maxX2-6; - lMax2X2 = maxX2-6; - lMin2X3 = maxX3-6; - lMax2X3 = maxX3-2; - - lMin3X1 = 1; - lMax3X1 = 5; - lMin3X2 = maxX2-6; - lMax3X2 = maxX2-2; - lMin3X3 = maxX3-6; - lMax3X3 = maxX3-6; - } - else if (sendDir == TSE) - { - lMin1X1 = maxX1-6; - lMax1X1 = maxX1-6; - lMin1X2 = 1; - lMax1X2 = 5; - lMin1X3 = maxX3-6; - lMax1X3 = maxX3-2; - - lMin2X1 = maxX1-6; - lMax2X1 = maxX1-2; - lMin2X2 = 5; - lMax2X2 = 5; - lMin2X3 = maxX3-6; - lMax2X3 = maxX3-2; - - lMin3X1 = maxX1-6; - lMax3X1 = maxX1-2; - lMin3X2 = 1; - lMax3X2 = 5; - lMin3X3 = maxX3-6; - lMax3X3 = maxX3-6; - } - else if (sendDir == TSW) - { - lMin1X1 = 5; - lMax1X1 = 5; - lMin1X2 = 1; - lMax1X2 = 5; - lMin1X3 = maxX3-6; - lMax1X3 = maxX3-2; - - lMin2X1 = 1; - lMax2X1 = 5; - lMin2X2 = 5; - lMax2X2 = 5; - lMin2X3 = maxX3-6; - lMax2X3 = maxX3-2; - - lMin3X1 = 1; - lMax3X1 = 5; - lMin3X2 = 1; - lMax3X2 = 5; - lMin3X3 = maxX3-6; - lMax3X3 = maxX3-6; - } - else if (sendDir == BNE) - { - lMin1X1 = maxX1-6; - lMax1X1 = maxX1-6; - lMin1X2 = maxX2-6; - lMax1X2 = maxX2-2; - lMin1X3 = 1; - lMax1X3 = 5; - - lMin2X1 = maxX1-6; - lMax2X1 = maxX1-2; - lMin2X2 = maxX2-6; - lMax2X2 = maxX2-6; - lMin2X3 = 1; - lMax2X3 = 5; - - lMin3X1 = maxX1-6; - lMax3X1 = maxX1-2; - lMin3X2 = maxX2-6; - lMax3X2 = maxX2-2; - lMin3X3 = 5; - lMax3X3 = 5; - } - else if (sendDir == BNW) - { - lMin1X1 = 5; - lMax1X1 = 5; - lMin1X2 = maxX2-6; - lMax1X2 = maxX2-2; - lMin1X3 = 1; - lMax1X3 = 5; - - lMin2X1 = 1; - lMax2X1 = 5; - lMin2X2 = maxX2-6; - lMax2X2 = maxX2-6; - lMin2X3 = 1; - lMax2X3 = 5; - - lMin3X1 = 1; - lMax3X1 = 5; - lMin3X2 = maxX2-6; - lMax3X2 = maxX2-2; - lMin3X3 = 5; - lMax3X3 = 5; - } - else if (sendDir == BSE) - { - lMin1X1 = maxX1-6; - lMax1X1 = maxX1-6; - lMin1X2 = 1; - lMax1X2 = 5; - lMin1X3 = 1; - lMax1X3 = 5; - - lMin2X1 = maxX1-6; - lMax2X1 = maxX1-2; - lMin2X2 = 5; - lMax2X2 = 5; - lMin2X3 = 1; - lMax2X3 = 5; - - lMin3X1 = maxX1-5; - lMax3X1 = maxX1-2; - lMin3X2 = 1; - lMax3X2 = 5; - lMin3X3 = 5; - lMax3X3 = 5; - } - else if (sendDir == BSW) - { - lMin1X1 = 5; - lMax1X1 = 5; - lMin1X2 = 1; - lMax1X2 = 5; - lMin1X3 = 1; - lMax1X3 = 5; - - lMin2X1 = 1; - lMax2X1 = 5; - lMin2X2 = 5; - lMax2X2 = 5; - lMin2X3 = 1; - lMax2X3 = 5; - - lMin3X1 = 1; - lMax3X1 = 5; - lMin3X2 = 1; - lMax3X2 = 5; - lMin3X3 = 5; - lMax3X3 = 5; - } - findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); - findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetSender); - findFCCells(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3, iNodeSetSender); - break; - } + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMin1X1 = minX1; + lMax1X1 = maxX1 + maxOffX1 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMin1X1 = minX1 + minOffX1; + lMax1X1 = maxX1 - 1; + } + + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + findFCCells(lMin1X1, lMin2X2, lMin2X3, lMax1X1, lMax2X2, lMax2X3, iNodeSetSender); + break; + // corners + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + if (sendDir == TNE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = maxX1 - 6; + lMin1X2 = maxX2 - 6; + lMax1X2 = maxX2 - 2; + lMin1X3 = maxX3 - 6; + lMax1X3 = maxX3 - 2; + + lMin2X1 = maxX1 - 6; + lMax2X1 = maxX1 - 2; + lMin2X2 = maxX2 - 6; + lMax2X2 = maxX2 - 6; + lMin2X3 = maxX3 - 6; + lMax2X3 = maxX3 - 1; + + lMin3X1 = maxX1 - 6; + lMax3X1 = maxX1 - 2; + lMin3X2 = maxX2 - 6; + lMax3X2 = maxX2 - 2; + lMin3X3 = maxX3 - 6; + lMax3X3 = maxX3 - 5; + } else if (sendDir == TNW) { + lMin1X1 = 5; + lMax1X1 = 5; + lMin1X2 = maxX2 - 6; + lMax1X2 = maxX2 - 2; + lMin1X3 = maxX3 - 6; + lMax1X3 = maxX3 - 2; + + lMin2X1 = 1; + lMax2X1 = 5; + lMin2X2 = maxX2 - 6; + lMax2X2 = maxX2 - 6; + lMin2X3 = maxX3 - 6; + lMax2X3 = maxX3 - 2; + + lMin3X1 = 1; + lMax3X1 = 5; + lMin3X2 = maxX2 - 6; + lMax3X2 = maxX2 - 2; + lMin3X3 = maxX3 - 6; + lMax3X3 = maxX3 - 6; + } else if (sendDir == TSE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = maxX1 - 6; + lMin1X2 = 1; + lMax1X2 = 5; + lMin1X3 = maxX3 - 6; + lMax1X3 = maxX3 - 2; + + lMin2X1 = maxX1 - 6; + lMax2X1 = maxX1 - 2; + lMin2X2 = 5; + lMax2X2 = 5; + lMin2X3 = maxX3 - 6; + lMax2X3 = maxX3 - 2; + + lMin3X1 = maxX1 - 6; + lMax3X1 = maxX1 - 2; + lMin3X2 = 1; + lMax3X2 = 5; + lMin3X3 = maxX3 - 6; + lMax3X3 = maxX3 - 6; + } else if (sendDir == TSW) { + lMin1X1 = 5; + lMax1X1 = 5; + lMin1X2 = 1; + lMax1X2 = 5; + lMin1X3 = maxX3 - 6; + lMax1X3 = maxX3 - 2; + + lMin2X1 = 1; + lMax2X1 = 5; + lMin2X2 = 5; + lMax2X2 = 5; + lMin2X3 = maxX3 - 6; + lMax2X3 = maxX3 - 2; + + lMin3X1 = 1; + lMax3X1 = 5; + lMin3X2 = 1; + lMax3X2 = 5; + lMin3X3 = maxX3 - 6; + lMax3X3 = maxX3 - 6; + } else if (sendDir == BNE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = maxX1 - 6; + lMin1X2 = maxX2 - 6; + lMax1X2 = maxX2 - 2; + lMin1X3 = 1; + lMax1X3 = 5; + + lMin2X1 = maxX1 - 6; + lMax2X1 = maxX1 - 2; + lMin2X2 = maxX2 - 6; + lMax2X2 = maxX2 - 6; + lMin2X3 = 1; + lMax2X3 = 5; + + lMin3X1 = maxX1 - 6; + lMax3X1 = maxX1 - 2; + lMin3X2 = maxX2 - 6; + lMax3X2 = maxX2 - 2; + lMin3X3 = 5; + lMax3X3 = 5; + } else if (sendDir == BNW) { + lMin1X1 = 5; + lMax1X1 = 5; + lMin1X2 = maxX2 - 6; + lMax1X2 = maxX2 - 2; + lMin1X3 = 1; + lMax1X3 = 5; + + lMin2X1 = 1; + lMax2X1 = 5; + lMin2X2 = maxX2 - 6; + lMax2X2 = maxX2 - 6; + lMin2X3 = 1; + lMax2X3 = 5; + + lMin3X1 = 1; + lMax3X1 = 5; + lMin3X2 = maxX2 - 6; + lMax3X2 = maxX2 - 2; + lMin3X3 = 5; + lMax3X3 = 5; + } else if (sendDir == BSE) { + lMin1X1 = maxX1 - 6; + lMax1X1 = maxX1 - 6; + lMin1X2 = 1; + lMax1X2 = 5; + lMin1X3 = 1; + lMax1X3 = 5; + + lMin2X1 = maxX1 - 6; + lMax2X1 = maxX1 - 2; + lMin2X2 = 5; + lMax2X2 = 5; + lMin2X3 = 1; + lMax2X3 = 5; + + lMin3X1 = maxX1 - 5; + lMax3X1 = maxX1 - 2; + lMin3X2 = 1; + lMax3X2 = 5; + lMin3X3 = 5; + lMax3X3 = 5; + } else if (sendDir == BSW) { + lMin1X1 = 5; + lMax1X1 = 5; + lMin1X2 = 1; + lMax1X2 = 5; + lMin1X3 = 1; + lMax1X3 = 5; + + lMin2X1 = 1; + lMax2X1 = 5; + lMin2X2 = 5; + lMax2X2 = 5; + lMin2X3 = 1; + lMax2X3 = 5; + + lMin3X1 = 1; + lMax3X1 = 5; + lMin3X2 = 1; + lMax3X2 = 5; + lMin3X3 = 5; + lMax3X3 = 5; + } + findFCCells(lMin1X1, lMin1X2, lMin1X3, lMax1X1, lMax1X2, lMax1X3, iNodeSetSender); + findFCCells(lMin2X1, lMin2X2, lMin2X3, lMax2X1, lMax2X2, lMax2X3, iNodeSetSender); + findFCCells(lMin3X1, lMin3X2, lMin3X3, lMax3X1, lMax3X2, lMax3X3, iNodeSetSender); + break; + } } ////////////////////////////////////////////////////////////////////////// void FineToCoarseNodeSetBlock3DConnector::fillSendVectors() { - using namespace D3Q27System; - - SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); + using namespace D3Q27System; - int index = 0; + SPtr<DistributionArray3D> fFrom = block.lock()->getKernel()->getDataSet()->getFdistributions(); - vector_type& data = this->sender->getData(); + int index = 0; - for(INodeVector inode : iNodeSetSender) - { - LBMReal icellC[27]; - D3Q27ICell icellF; - iprocessor->readICell(fFrom, icellF, inode[0], inode[1], inode[2]); - iprocessor->interpolateFineToCoarse(icellF, icellC, inode[3], inode[4], inode[5]); - writeICellCtoData(data, index, icellC); - } + vector_type &data = this->sender->getData(); + for (INodeVector inode : iNodeSetSender) { + LBMReal icellC[27]; + D3Q27ICell icellF; + iprocessor->readICell(fFrom, icellF, inode[0], inode[1], inode[2]); + iprocessor->interpolateFineToCoarse(icellF, icellC, inode[3], inode[4], inode[5]); + writeICellCtoData(data, index, icellC); + } } ////////////////////////////////////////////////////////////////////////// -void FineToCoarseNodeSetBlock3DConnector::readICellFfromData(vector_type& data, int& index, D3Q27ICell& icellF) +void FineToCoarseNodeSetBlock3DConnector::readICellFfromData(vector_type &data, int &index, D3Q27ICell &icellF) { - readNodeFromVector(data, index, icellF.BSW); - readNodeFromVector(data, index, icellF.BSE); - readNodeFromVector(data, index, icellF.BNW); - readNodeFromVector(data, index, icellF.BNE); - readNodeFromVector(data, index, icellF.TSW); - readNodeFromVector(data, index, icellF.TSE); - readNodeFromVector(data, index, icellF.TNW); - readNodeFromVector(data, index, icellF.TNE); + readNodeFromVector(data, index, icellF.BSW); + readNodeFromVector(data, index, icellF.BSE); + readNodeFromVector(data, index, icellF.BNW); + readNodeFromVector(data, index, icellF.BNE); + readNodeFromVector(data, index, icellF.TSW); + readNodeFromVector(data, index, icellF.TSE); + readNodeFromVector(data, index, icellF.TNW); + readNodeFromVector(data, index, icellF.TNE); } ////////////////////////////////////////////////////////////////////////// -void FineToCoarseNodeSetBlock3DConnector::readNodeFromVector(vector_type& data, int& index, LBMReal* inode) +void FineToCoarseNodeSetBlock3DConnector::readNodeFromVector(vector_type &data, int &index, LBMReal *inode) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - inode[i] = data[index++]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + inode[i] = data[index++]; + } } ////////////////////////////////////////////////////////////////////////// -void FineToCoarseNodeSetBlock3DConnector::writeICellCtoData(vector_type& data, int& index, LBMReal* icellC) +void FineToCoarseNodeSetBlock3DConnector::writeICellCtoData(vector_type &data, int &index, LBMReal *icellC) { - for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF+1; i++) - { - data[index++] = icellC[i]; - } + for (int i = D3Q27System::STARTF; i < D3Q27System::ENDF + 1; i++) { + data[index++] = icellC[i]; + } } ////////////////////////////////////////////////////////////////////////// -void FineToCoarseNodeSetBlock3DConnector::findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes) +void FineToCoarseNodeSetBlock3DConnector::findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, + int lMaxX3, INodeSet &inodes) { - int ix1, ix2, ix3; - - for (ix3 = lMinX3; ix3<=lMaxX3; ix3 += 2) - { - for (ix2 = lMinX2; ix2<=lMaxX2; ix2 += 2) - { - for (ix1 = lMinX1; ix1<=lMaxX1; ix1 += 2) - { - INodeVector inv; - inv.push_back(ix1); - inv.push_back(ix2); - inv.push_back(ix3); - //inodes.insert(inv); - inodes.push_back(inv); - } - } - } + int ix1, ix2, ix3; + + for (ix3 = lMinX3; ix3 <= lMaxX3; ix3 += 2) { + for (ix2 = lMinX2; ix2 <= lMaxX2; ix2 += 2) { + for (ix1 = lMinX1; ix1 <= lMaxX1; ix1 += 2) { + INodeVector inv; + inv.push_back(ix1); + inv.push_back(ix2); + inv.push_back(ix3); + // inodes.insert(inv); + inodes.push_back(inv); + } + } + } } ////////////////////////////////////////////////////////////////////////// void FineToCoarseNodeSetBlock3DConnector::findCFCells() { - using namespace D3Q27System; + using namespace D3Q27System; + + int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + + ////////////////////////////////////////////////////// + // Debug + ////////////////////////////////////////////////////// + // if (block.lock()->getGlobalID() == 2183) + // { + // int test = 0; + // } + + switch (sendDir) { + // faces + case E: + case W: + if (sendDir == E) { + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1; + } else if (sendDir == W) { + lMinX1 = 2; + lMaxX1 = lMinX1; + } - int lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3; + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX2 = minX2; + lMaxX2 = maxX2 + maxOffX2 - 1; + lMinX3 = minX3; + lMaxX3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX2 = minX2 + minOffX2; + lMaxX2 = maxX2 - 1; + lMinX3 = minX3; + lMaxX3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMinX2 = minX2; + lMaxX2 = maxX2 + maxOffX2 - 1; + lMinX3 = minX3 + minOffX3; + lMaxX3 = maxX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMinX2 = minX2 + minOffX2; + lMaxX2 = maxX2 - 1; + lMinX3 = minX3 + minOffX3; + lMaxX3 = maxX3 - 1; + } + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + case N: + case S: + if (sendDir == N) { + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2; + } else if (sendDir == S) { + lMinX2 = 2; + lMaxX2 = lMinX2; + } - ////////////////////////////////////////////////////// - //Debug - ////////////////////////////////////////////////////// -// if (block.lock()->getGlobalID() == 2183) -// { -// int test = 0; -// } + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX1 = minX1; + lMaxX1 = maxX1 + maxOffX1 - 1; + lMinX3 = minX3; + lMaxX3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX1 = minX1 + minOffX1; + lMaxX1 = maxX1; + lMinX3 = minX3; + lMaxX3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMinX1 = minX1; + lMaxX1 = maxX1 + maxOffX1 - 1; + lMinX3 = minX3 + minOffX3; + lMaxX3 = maxX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMinX1 = minX1 + minOffX1; + lMaxX1 = maxX1 - 1; + lMinX3 = minX3 + minOffX3; + lMaxX3 = maxX3 - 1; + } + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + case T: + case B: + if (sendDir == T) { + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3; + } else if (sendDir == B) { + lMinX3 = 2; + lMaxX3 = lMinX3; + } - switch (sendDir) - { - //faces - case E: case W: - if (sendDir == E) - { - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1; - } - else if (sendDir == W) - { - lMinX1 = 2; - lMaxX1 = lMinX1; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX2 = minX2; - lMaxX2 = maxX2 + maxOffX2 - 1; - lMinX3 = minX3; - lMaxX3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX2 = minX2 + minOffX2; - lMaxX2 = maxX2 - 1; - lMinX3 = minX3; - lMaxX3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMinX2 = minX2; - lMaxX2 = maxX2 + maxOffX2 - 1; - lMinX3 = minX3 + minOffX3; - lMaxX3 = maxX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMinX2 = minX2 + minOffX2; - lMaxX2 = maxX2 - 1; - lMinX3 = minX3 + minOffX3; - lMaxX3 = maxX3 - 1; - } - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - case N: case S: - if (sendDir == N) - { - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2; - } - else if (sendDir == S) - { - lMinX2 = 2; - lMaxX2 = lMinX2; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX1 = minX1; - lMaxX1 = maxX1 + maxOffX1 - 1; - lMinX3 = minX3; - lMaxX3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX1 = minX1 + minOffX1; - lMaxX1 = maxX1; - lMinX3 = minX3; - lMaxX3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMinX1 = minX1; - lMaxX1 = maxX1 + maxOffX1 - 1; - lMinX3 = minX3 + minOffX3; - lMaxX3 = maxX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMinX1 = minX1 + minOffX1; - lMaxX1 = maxX1 - 1; - lMinX3 = minX3 + minOffX3; - lMaxX3 = maxX3 - 1; - } - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - case T: case B: - if (sendDir == T) - { - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3; - } - else if (sendDir == B) - { - lMinX3 = 2; - lMaxX3 = lMinX3; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX1 = minX1; - lMaxX1 = maxX1 + maxOffX1 - 1; - lMinX2 = minX2; - lMaxX2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX1 = minX1 + minOffX1; - lMaxX1 = maxX1 - 1; - lMinX2 = minX2; - lMaxX2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type01) - { - lMinX1 = minX1; - lMaxX1 = maxX1 + maxOffX1 - 1; - lMinX2 = minX2 + minOffX2; - lMaxX2 = maxX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type11) - { - lMinX1 = minX1 + minOffX1; - lMaxX1 = maxX1 - 1; - lMinX2 = minX2 + minOffX2; - lMaxX2 = maxX2 - 1; - } - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - - //edges - //N-S-E-W - case NE: case SW: case SE: case NW: - if (sendDir == NE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - } - else if (sendDir == SW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 3; - lMinX2 = 0; - lMaxX2 = lMinX2 + 3; - } - else if (sendDir == SE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - } - else if (sendDir == NW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX3 = minX3; - lMaxX3 = maxX3 + maxOffX3 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX3 = minX3 + minOffX3; - lMaxX3 = maxX3 - 1; - } - - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - //T-B-E-W - case TE: case BW: case BE: case TW: - if (sendDir == TE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == BW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == BE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = lMinX1 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == TW) - { - lMinX1 = 0; - lMaxX1 = lMinX1 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX2 = minX2; - lMaxX2 = maxX2 + maxOffX2 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX2 = minX2 + minOffX2; - lMaxX2 = maxX2 - 1; - } - - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - //T-B-N-S - case TN: case BS: case BN: case TS: - if (sendDir == TN) - { - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == BS) - { - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == BN) - { - lMinX2 = maxX2 - 3; - lMaxX2 = lMinX2 + 2; - lMinX3 = 0; - lMaxX3 = lMinX3 + 2; - } - else if (sendDir == TS) - { - lMinX2 = 0; - lMaxX2 = lMinX2 + 2; - lMinX3 = maxX3 - 3; - lMaxX3 = lMinX3 + 2; - } - - if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type00) - { - lMinX1 = minX1; - lMaxX1 = maxX1 + maxOffX1 - 1; - } - else if (FineToCoarseBlock3DConnector::connType ==FineToCoarseBlock3DConnector::Type10) - { - lMinX1 = minX1 + minOffX1; - lMaxX1 = maxX1 - 1; - } - - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - //corners - case TNE: case TNW: case TSE: case TSW: case BNE: case BNW: case BSE: case BSW: - if (sendDir == TNE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - } - else if (sendDir == TNW) - { - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - } - else if (sendDir == TSE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - } - else if (sendDir == TSW) - { - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = maxX3 - 3; - lMaxX3 = maxX3 - 1; - } - else if (sendDir == BNE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = 0; - lMaxX3 = 2; - } - else if (sendDir == BNW) - { - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = maxX2 - 3; - lMaxX2 = maxX2 - 1; - lMinX3 = 0; - lMaxX3 = 2; - } - else if (sendDir == BSE) - { - lMinX1 = maxX1 - 3; - lMaxX1 = maxX1 - 1; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = 0; - lMaxX3 = 2; - } - else if (sendDir == BSW) - { - lMinX1 = 0; - lMaxX1 = 2; - lMinX2 = 0; - lMaxX2 = 2; - lMinX3 = 0; - lMaxX3 = 2; - } - findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); - break; - } + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX1 = minX1; + lMaxX1 = maxX1 + maxOffX1 - 1; + lMinX2 = minX2; + lMaxX2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX1 = minX1 + minOffX1; + lMaxX1 = maxX1 - 1; + lMinX2 = minX2; + lMaxX2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type01) { + lMinX1 = minX1; + lMaxX1 = maxX1 + maxOffX1 - 1; + lMinX2 = minX2 + minOffX2; + lMaxX2 = maxX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type11) { + lMinX1 = minX1 + minOffX1; + lMaxX1 = maxX1 - 1; + lMinX2 = minX2 + minOffX2; + lMaxX2 = maxX2 - 1; + } + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + + // edges + // N-S-E-W + case NE: + case SW: + case SE: + case NW: + if (sendDir == NE) { + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + } else if (sendDir == SW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 3; + lMinX2 = 0; + lMaxX2 = lMinX2 + 3; + } else if (sendDir == SE) { + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + } else if (sendDir == NW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + } + + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX3 = minX3; + lMaxX3 = maxX3 + maxOffX3 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX3 = minX3 + minOffX3; + lMaxX3 = maxX3 - 1; + } + + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + // T-B-E-W + case TE: + case BW: + case BE: + case TW: + if (sendDir == TE) { + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == BW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == BE) { + lMinX1 = maxX1 - 3; + lMaxX1 = lMinX1 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == TW) { + lMinX1 = 0; + lMaxX1 = lMinX1 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + } + + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX2 = minX2; + lMaxX2 = maxX2 + maxOffX2 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX2 = minX2 + minOffX2; + lMaxX2 = maxX2 - 1; + } + + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + // T-B-N-S + case TN: + case BS: + case BN: + case TS: + if (sendDir == TN) { + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == BS) { + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == BN) { + lMinX2 = maxX2 - 3; + lMaxX2 = lMinX2 + 2; + lMinX3 = 0; + lMaxX3 = lMinX3 + 2; + } else if (sendDir == TS) { + lMinX2 = 0; + lMaxX2 = lMinX2 + 2; + lMinX3 = maxX3 - 3; + lMaxX3 = lMinX3 + 2; + } + + if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type00) { + lMinX1 = minX1; + lMaxX1 = maxX1 + maxOffX1 - 1; + } else if (FineToCoarseBlock3DConnector::connType == FineToCoarseBlock3DConnector::Type10) { + lMinX1 = minX1 + minOffX1; + lMaxX1 = maxX1 - 1; + } + + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + // corners + case TNE: + case TNW: + case TSE: + case TSW: + case BNE: + case BNW: + case BSE: + case BSW: + if (sendDir == TNE) { + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TNW) { + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TSE) { + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + } else if (sendDir == TSW) { + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = maxX3 - 3; + lMaxX3 = maxX3 - 1; + } else if (sendDir == BNE) { + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 2; + } else if (sendDir == BNW) { + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = maxX2 - 3; + lMaxX2 = maxX2 - 1; + lMinX3 = 0; + lMaxX3 = 2; + } else if (sendDir == BSE) { + lMinX1 = maxX1 - 3; + lMaxX1 = maxX1 - 1; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = 0; + lMaxX3 = 2; + } else if (sendDir == BSW) { + lMinX1 = 0; + lMaxX1 = 2; + lMinX2 = 0; + lMaxX2 = 2; + lMinX3 = 0; + lMaxX3 = 2; + } + findCFCells(lMinX1, lMinX2, lMinX3, lMaxX1, lMaxX2, lMaxX3, iNodeSetReceiver); + break; + } } ////////////////////////////////////////////////////////////////////////// void FineToCoarseNodeSetBlock3DConnector::distributeReceiveVectors() { - using namespace D3Q27System; + using namespace D3Q27System; - SPtr<DistributionArray3D> fTo = FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions(); + SPtr<DistributionArray3D> fTo = + FineToCoarseBlock3DConnector::block.lock()->getKernel()->getDataSet()->getFdistributions(); - int index = 0; + int index = 0; - vector_type& data = this->receiver->getData(); + vector_type &data = this->receiver->getData(); - for(INodeVector inode : iNodeSetReceiver) - { - D3Q27ICell icellF; - this->readICellFfromData(data, index, icellF); - iprocessor->writeICellInv(fTo, icellF, inode[0], inode[1], inode[2]); - } + for (INodeVector inode : iNodeSetReceiver) { + D3Q27ICell icellF; + this->readICellFfromData(data, index, icellF); + iprocessor->writeICellInv(fTo, icellF, inode[0], inode[1], inode[2]); + } } ////////////////////////////////////////////////////////////////////////// // -//void FineToCoarseNodeSetBlock3DConnector::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3) +// void FineToCoarseNodeSetBlock3DConnector::getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, +// int& maxX3) //{ // using namespace D3Q27System; -// int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = maxX3; +// int TminX1 = minX1; int TminX2 = minX2; int TminX3 = minX3; int TmaxX1 = maxX1; int TmaxX2 = maxX2; int TmaxX3 = +// maxX3; // // if (block.lock()->hasInterpolationFlagFC(E)) // { @@ -1165,44 +1040,52 @@ void FineToCoarseNodeSetBlock3DConnector::distributeReceiveVectors() // // //////////// // /////E-W-N-S -// if (block.lock()->hasInterpolationFlagFC(NE)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(E)) +// if (block.lock()->hasInterpolationFlagFC(NE)&& !block.lock()->hasInterpolationFlagFC(N) && +// !block.lock()->hasInterpolationFlagFC(E)) // { // if (maxX1==TmaxX1) maxX1 -= 2; // if (maxX2==TmaxX2) maxX2 -= 2; // } -// if (block.lock()->hasInterpolationFlagFC(SW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(S)) +// if (block.lock()->hasInterpolationFlagFC(SW)&& !block.lock()->hasInterpolationFlagFC(W) && +// !block.lock()->hasInterpolationFlagFC(S)) // { // if (minX1==TminX1) minX1 += 4; // if (minX2==TminX2) minX2 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(SE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(S)) +// if (block.lock()->hasInterpolationFlagFC(SE)&& !block.lock()->hasInterpolationFlagFC(E) && +// !block.lock()->hasInterpolationFlagFC(S)) // { // if (maxX1==TmaxX1) maxX1 -= 2; // if (minX2==TminX2) minX2 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(NW)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(W)) +// if (block.lock()->hasInterpolationFlagFC(NW)&& !block.lock()->hasInterpolationFlagFC(N) && +// !block.lock()->hasInterpolationFlagFC(W)) // { // if (minX1==TminX1) minX1 += 4; // if (maxX2==TmaxX2) maxX2 -= 2; // } // // //////T-B-E-W -// if (block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(T)) +// if (block.lock()->hasInterpolationFlagFC(TE) && !block.lock()->hasInterpolationFlagFC(E) && +// !block.lock()->hasInterpolationFlagFC(T)) // { // if (maxX1==TmaxX1) maxX1 -= 2; // if (maxX3==TmaxX3) maxX3 -= 2; // } -// if (block.lock()->hasInterpolationFlagFC(BW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(B)) +// if (block.lock()->hasInterpolationFlagFC(BW)&& !block.lock()->hasInterpolationFlagFC(W) && +// !block.lock()->hasInterpolationFlagFC(B)) // { // if (minX1==TminX1) minX1 += 4; // if (minX3==TminX3) minX3 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(BE)&& !block.lock()->hasInterpolationFlagFC(E) && !block.lock()->hasInterpolationFlagFC(B)) +// if (block.lock()->hasInterpolationFlagFC(BE)&& !block.lock()->hasInterpolationFlagFC(E) && +// !block.lock()->hasInterpolationFlagFC(B)) // { // if (maxX1==TmaxX1) maxX1 -= 2; // if (minX3==TminX3) minX3 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(TW)&& !block.lock()->hasInterpolationFlagFC(W) && !block.lock()->hasInterpolationFlagFC(T)) +// if (block.lock()->hasInterpolationFlagFC(TW)&& !block.lock()->hasInterpolationFlagFC(W) && +// !block.lock()->hasInterpolationFlagFC(T)) // { // if (minX1==TminX1) minX1 += 4; // if (maxX3==TmaxX3) maxX3 -= 2; @@ -1210,26 +1093,29 @@ void FineToCoarseNodeSetBlock3DConnector::distributeReceiveVectors() // // // ////T-B-N-S -// if (block.lock()->hasInterpolationFlagFC(TN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(T)) +// if (block.lock()->hasInterpolationFlagFC(TN)&& !block.lock()->hasInterpolationFlagFC(N) && +// !block.lock()->hasInterpolationFlagFC(T)) // { // if (maxX2==TmaxX2) maxX2 -= 2; // if (maxX3==TmaxX3) maxX3 -= 2; // } -// if (block.lock()->hasInterpolationFlagFC(BS)&& !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(B)) +// if (block.lock()->hasInterpolationFlagFC(BS)&& !block.lock()->hasInterpolationFlagFC(S) && +// !block.lock()->hasInterpolationFlagFC(B)) // { // if (minX2==TminX2) minX2 += 4; // if (minX3==TminX3) minX3 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(BN)&& !block.lock()->hasInterpolationFlagFC(N) && !block.lock()->hasInterpolationFlagFC(B)) +// if (block.lock()->hasInterpolationFlagFC(BN)&& !block.lock()->hasInterpolationFlagFC(N) && +// !block.lock()->hasInterpolationFlagFC(B)) // { // if (maxX2==TmaxX2) maxX2 -= 2; // if (minX3==TminX3) minX3 += 4; // } -// if (block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && !block.lock()->hasInterpolationFlagFC(T)) +// if (block.lock()->hasInterpolationFlagFC(TS) && !block.lock()->hasInterpolationFlagFC(S) && +// !block.lock()->hasInterpolationFlagFC(T)) // { // if (minX2==TminX2) minX2 += 4; // if (maxX3==TmaxX3) maxX3 -= 2; // } //} ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.h index 0c10e7778..bcf29041e 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/FineToCoarseNodeSetBlock3DConnector.h @@ -1,78 +1,74 @@ /// \file CoarseToFineNodeSetBlock3DConnector.h /// \class CoarseToFineNodeSetBlock3DConnector -/// \brief Connector interpolates and sends data from coarse level to fine. +/// \brief Connector interpolates and sends data from coarse level to fine. /// \author Konstantin Kutscher /// \date 21.05.2015 #ifndef FineToCoarseNodeSetBlock3DConnector_H #define FineToCoarseNodeSetBlock3DConnector_H -#include <vector> -#include "FineToCoarseBlock3DConnector.h" -#include "D3Q27System.h" #include "Block3D.h" +#include "D3Q27System.h" +#include "FineToCoarseBlock3DConnector.h" #include "Grid3D.h" -#include "LBMKernel.h" #include "InterpolationProcessor.h" +#include "LBMKernel.h" #include "MathUtil.hpp" #include <PointerDefinitions.h> - +#include <vector> class Block3D; -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) class FineToCoarseNodeSetBlock3DConnector : public FineToCoarseBlock3DConnector { public: - FineToCoarseNodeSetBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType); - void init() override; - void fillSendVectors() override; - void distributeReceiveVectors() override; + FineToCoarseNodeSetBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir, InterpolationProcessorPtr iprocessor, CFconnectorType connType); + void init() override; + void fillSendVectors() override; + void distributeReceiveVectors() override; + protected: - using INodeVector = std::vector<int>; - using INodeSet = std::vector<INodeVector>; - INodeSet iNodeSetSender; - INodeSet iNodeSetReceiver; + using INodeVector = std::vector<int>; + using INodeSet = std::vector<INodeVector>; + INodeSet iNodeSetSender; + INodeSet iNodeSetReceiver; - void readICellFfromData(vector_type& data, int& index, D3Q27ICell& icellF); - void readNodeFromVector(vector_type& data, int& index, LBMReal* inode); + void readICellFfromData(vector_type &data, int &index, D3Q27ICell &icellF); + void readNodeFromVector(vector_type &data, int &index, LBMReal *inode); - void writeICellCtoData(vector_type& data, int& index, LBMReal* icellC); + void writeICellCtoData(vector_type &data, int &index, LBMReal *icellC); - void findFCCells(); - void findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); + void findFCCells(); + void findFCCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); - void findCFCells(); - void findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); + void findCFCells(); + void findCFCells(int lMinX1, int lMinX2, int lMinX3, int lMaxX1, int lMaxX2, int lMaxX3, INodeSet &inodes); - //void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3); + // void getLocalMinMax(int& minX1, int& minX2, int& minX3, int& maxX1, int& maxX2, int& maxX3); + int bMaxX1, bMaxX2, bMaxX3; - int bMaxX1, bMaxX2, bMaxX3; - - int minX1; - int minX2; - int minX3; + int minX1; + int minX2; + int minX3; - int maxX1; - int maxX2; - int maxX3; + int maxX1; + int maxX2; + int maxX3; - int minOffX1; - int minOffX2; - int minOffX3; + int minOffX1; + int minOffX2; + int minOffX3; - int maxOffX1; - int maxOffX2; - int maxOffX3; + int maxOffX1; + int maxOffX2; + int maxOffX3; }; - - - - #endif diff --git a/src/cpu/VirtualFluidsCore/Connectors/LocalBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/LocalBlock3DConnector.h index 90790ce7d..9e8819ebd 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/LocalBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/LocalBlock3DConnector.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,59 +34,56 @@ #ifndef LocalBlock3DConnector_H #define LocalBlock3DConnector_H -#include "Block3DConnector.h" #include "Block3D.h" +#include "Block3DConnector.h" #include "PointerDefinitions.h" //! A class provides an interface for connectors in shared memory class LocalBlock3DConnector : public Block3DConnector { public: - LocalBlock3DConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) - : Block3DConnector(sendDir) - , from(from) - , to(to) - { - - } - ~LocalBlock3DConnector() override = default; - void sendTransmitterDataSize() override {} - void receiveTransmitterDataSize() override {} - void init() override = 0; - void prepareForReceive() override {} - void prepareForSend() override {} - void fillSendVectors() override {} - void sendVectors() override =0; - void receiveVectors() override {} + LocalBlock3DConnector(SPtr<Block3D> from, SPtr<Block3D> to, int sendDir) + : Block3DConnector(sendDir), from(from), to(to) + { + } + ~LocalBlock3DConnector() override = default; + void sendTransmitterDataSize() override {} + void receiveTransmitterDataSize() override {} + void init() override = 0; + void prepareForReceive() override {} + void prepareForSend() override {} + void fillSendVectors() override {} + void sendVectors() override = 0; + void receiveVectors() override {} - void distributeReceiveVectors() override {} + void distributeReceiveVectors() override {} - bool isLocalConnector() override { return true; } - bool isRemoteConnector() override { return false; } - bool isInterpolationConnectorCF() override { return false; } - bool isInterpolationConnectorFC() override { return false; } + bool isLocalConnector() override { return true; } + bool isRemoteConnector() override { return false; } + bool isInterpolationConnectorCF() override { return false; } + bool isInterpolationConnectorFC() override { return false; } - double getSendRecieveTime(); + double getSendRecieveTime(); - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override {} - void sendVectorsX2() override {} - void sendVectorsX3() override {} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> from; - WPtr<Block3D> to; + WPtr<Block3D> from; + WPtr<Block3D> to; }; -#endif //LocalBlock3DConnector_H +#endif // LocalBlock3DConnector_H diff --git a/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.cpp b/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.cpp index e7adf6a63..cc5927465 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.cpp +++ b/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.cpp @@ -1,64 +1,61 @@ #include "RemoteBlock3DConnector.h" ////////////////////////////////////////////////////////////////////////// -RemoteBlock3DConnector::RemoteBlock3DConnector(SPtr<Block3D> block - , VectorTransmitterPtr sender - , VectorTransmitterPtr receiver - , int sendDir) - : Block3DConnector(sendDir) - , block(block) - , sender(sender) - , receiver(receiver) +RemoteBlock3DConnector::RemoteBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, + VectorTransmitterPtr receiver, int sendDir) + : Block3DConnector(sendDir), block(block), sender(sender), receiver(receiver) { - if (!block || !sender || !receiver) - UB_THROW(UbException(UB_EXARGS, "sender or receiver == NULL!!")); + if (!block || !sender || !receiver) + UB_THROW(UbException(UB_EXARGS, "sender or receiver == NULL!!")); } ////////////////////////////////////////////////////////////////////////// -bool RemoteBlock3DConnector::isLocalConnector() -{ - return !this->isRemoteConnector(); -} +bool RemoteBlock3DConnector::isLocalConnector() { return !this->isRemoteConnector(); } ////////////////////////////////////////////////////////////////////////// bool RemoteBlock3DConnector::isRemoteConnector() { - return ((sender && sender->isRemoteTransmitter()) - || (receiver && receiver->isRemoteTransmitter())); + return ((sender && sender->isRemoteTransmitter()) || (receiver && receiver->isRemoteTransmitter())); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::sendTransmitterDataSize() { - assert(sender !=NULL); sender->sendDataSize(); + assert(sender != NULL); + sender->sendDataSize(); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::receiveTransmitterDataSize() { - assert(receiver!=NULL); receiver->receiveDataSize(); + assert(receiver != NULL); + receiver->receiveDataSize(); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::prepareForSend() { - assert(sender !=NULL); sender->prepareForSend(); + assert(sender != NULL); + sender->prepareForSend(); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::sendVectors() { - assert(sender !=NULL); sender->sendData(); + assert(sender != NULL); + sender->sendData(); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::prepareForReceive() { - assert(receiver!=NULL); receiver->prepareForReceive(); + assert(receiver != NULL); + receiver->prepareForReceive(); } ////////////////////////////////////////////////////////////////////////// void RemoteBlock3DConnector::receiveVectors() { - assert(receiver!=NULL); receiver->receiveData(); + assert(receiver != NULL); + receiver->receiveData(); } diff --git a/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.h b/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.h index 95d34f91f..00276a5b2 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.h +++ b/src/cpu/VirtualFluidsCore/Connectors/RemoteBlock3DConnector.h @@ -3,70 +3,65 @@ #include <vector> -#include "TransmitterType.h" +#include "Block3D.h" #include "Block3DConnector.h" #include "D3Q27System.h" -#include "Block3D.h" -#include "LBMKernel.h" #include "EsoTwistD3Q27System.h" +#include "LBMKernel.h" +#include "TransmitterType.h" - -//daten werden in einen vector (dieser befindet sich im transmitter) kopiert -//der vector wird via transmitter uebertragen -//transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein -//transmitter sein, der von Transmitter abgeleitet ist ;-) +// daten werden in einen vector (dieser befindet sich im transmitter) kopiert +// der vector wird via transmitter uebertragen +// transmitter kann ein lokal, MPI, RCG, CTL oder was auch immer fuer ein +// transmitter sein, der von Transmitter abgeleitet ist ;-) class RemoteBlock3DConnector : public Block3DConnector { public: - RemoteBlock3DConnector(SPtr<Block3D> block - , VectorTransmitterPtr sender - , VectorTransmitterPtr receiver - , int sendDir); + RemoteBlock3DConnector(SPtr<Block3D> block, VectorTransmitterPtr sender, VectorTransmitterPtr receiver, + int sendDir); - bool isLocalConnector() override; - bool isRemoteConnector() override; + bool isLocalConnector() override; + bool isRemoteConnector() override; - void init() override = 0; + void init() override = 0; - void sendTransmitterDataSize() override; - void receiveTransmitterDataSize() override; + void sendTransmitterDataSize() override; + void receiveTransmitterDataSize() override; - void prepareForSend() override; - void sendVectors() override; + void prepareForSend() override; + void sendVectors() override; - void prepareForReceive() override; - void receiveVectors() override; + void prepareForReceive() override; + void receiveVectors() override; - void fillSendVectors() override = 0; - void distributeReceiveVectors() override = 0; + void fillSendVectors() override = 0; + void distributeReceiveVectors() override = 0; - bool isInterpolationConnectorCF() override { return false; } - bool isInterpolationConnectorFC() override { return false; } + bool isInterpolationConnectorCF() override { return false; } + bool isInterpolationConnectorFC() override { return false; } - double getSendRecieveTime() { return 0; } + double getSendRecieveTime() { return 0; } - void prepareForSendX1() override {} - void prepareForSendX2() override {} - void prepareForSendX3() override {} + void prepareForSendX1() override {} + void prepareForSendX2() override {} + void prepareForSendX3() override {} - void sendVectorsX1() override {} - void sendVectorsX2() override {} - void sendVectorsX3() override {} + void sendVectorsX1() override {} + void sendVectorsX2() override {} + void sendVectorsX3() override {} - void prepareForReceiveX1() override {} - void prepareForReceiveX2() override {} - void prepareForReceiveX3() override {} + void prepareForReceiveX1() override {} + void prepareForReceiveX2() override {} + void prepareForReceiveX3() override {} - void receiveVectorsX1() override {} - void receiveVectorsX2() override {} - void receiveVectorsX3() override {} + void receiveVectorsX1() override {} + void receiveVectorsX2() override {} + void receiveVectorsX3() override {} protected: - WPtr<Block3D> block; - VectorTransmitterPtr sender; - VectorTransmitterPtr receiver; + WPtr<Block3D> block; + VectorTransmitterPtr sender; + VectorTransmitterPtr receiver; }; - -#endif //RemoteBlock3DConnector_H - +#endif // RemoteBlock3DConnector_H diff --git a/src/cpu/VirtualFluidsCore/Connectors/TransmitterType.h b/src/cpu/VirtualFluidsCore/Connectors/TransmitterType.h index 27300328c..3690bb917 100644 --- a/src/cpu/VirtualFluidsCore/Connectors/TransmitterType.h +++ b/src/cpu/VirtualFluidsCore/Connectors/TransmitterType.h @@ -1,16 +1,14 @@ #ifndef TransmitterType_h__ #define TransmitterType_h__ +#include "D3Q27System.h" +#include "basics/container/CbVector.h" #include "basics/transmitter/TbTransmitter.h" #include "basics/transmitter/TbTransmitterLocal.h" -#include "basics/container/CbVector.h" -#include "D3Q27System.h" #include <PointerDefinitions.h> - -using VectorTransmitter = TbTransmitter<CbVector<LBMReal> >; -using vector_type = VectorTransmitter::value_type; -using VectorTransmitterPtr = SPtr<TbTransmitter<CbVector<LBMReal> > >; +using VectorTransmitter = TbTransmitter<CbVector<LBMReal>>; +using vector_type = VectorTransmitter::value_type; +using VectorTransmitterPtr = SPtr<TbTransmitter<CbVector<LBMReal>>>; #endif // TransmitterType_h__ - diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.cpp b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.cpp index 77da3c462..d75c90c9d 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.cpp +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.cpp @@ -1,591 +1,610 @@ #include "D3Q27EsoTwist3DSoA.h" -#include <D3Q27System.h> #include "EsoTwistD3Q27System.h" +#include <D3Q27System.h> -D3Q27EsoTwist3DSoA::D3Q27EsoTwist3DSoA() -= default; +D3Q27EsoTwist3DSoA::D3Q27EsoTwist3DSoA() = default; ////////////////////////////////////////////////////////////////////////// -D3Q27EsoTwist3DSoA::D3Q27EsoTwist3DSoA( const size_t& nx1, const size_t& nx2, const size_t& nx3, LBMReal value ) +D3Q27EsoTwist3DSoA::D3Q27EsoTwist3DSoA(const size_t &nx1, const size_t &nx2, const size_t &nx3, LBMReal value) { - this->NX1 = nx1; - this->NX2 = nx2; - this->NX3 = nx3; + this->NX1 = nx1; + this->NX2 = nx2; + this->NX3 = nx3; - d.E = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.W = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.N = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.S = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.T = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.B = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.NE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.SW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.SE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.NW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TN = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BS = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BN = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TS = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TNE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TNW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TSE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.TSW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BNE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BNW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BSE = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.BSW = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1+1, nx2+1, nx3+1, value)); - d.ZERO= CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1, nx2, nx3, value)); + d.E = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.W = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.N = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.S = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.T = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.B = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.NE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.SW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.SE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.NW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TN = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BS = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BN = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TS = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TNE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TNW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TSE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.TSW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BNE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BNW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BSE = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.BSW = CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr( + new CbArray3D<LBMReal, IndexerX3X2X1>(nx1 + 1, nx2 + 1, nx3 + 1, value)); + d.ZERO = + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(nx1, nx2, nx3, value)); } ////////////////////////////////////////////////////////////////////////// -D3Q27EsoTwist3DSoA::~D3Q27EsoTwist3DSoA() -= default; +D3Q27EsoTwist3DSoA::~D3Q27EsoTwist3DSoA() = default; ////////////////////////////////////////////////////////////////////////// void D3Q27EsoTwist3DSoA::swap() { - std::swap(d.E , d.W ); - std::swap(d.N , d.S ); - std::swap(d.T , d.B ); - std::swap(d.NE , d.SW ); - std::swap(d.NW , d.SE ); - std::swap(d.TE , d.BW ); - std::swap(d.TW , d.BE ); - std::swap(d.TN , d.BS ); - std::swap(d.TS , d.BN ); - std::swap(d.TNE, d.BSW); - std::swap(d.TNW, d.BSE); - std::swap(d.TSE, d.BNW); - std::swap(d.TSW, d.BNE); + std::swap(d.E, d.W); + std::swap(d.N, d.S); + std::swap(d.T, d.B); + std::swap(d.NE, d.SW); + std::swap(d.NW, d.SE); + std::swap(d.TE, d.BW); + std::swap(d.TW, d.BE); + std::swap(d.TN, d.BS); + std::swap(d.TS, d.BN); + std::swap(d.TNE, d.BSW); + std::swap(d.TNW, d.BSE); + std::swap(d.TSE, d.BNW); + std::swap(d.TSW, d.BNE); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::getDistribution(LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSoA::getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) { - size_t x1p = x1 + 1; - size_t x2p = x2 + 1; - size_t x3p = x3 + 1; + size_t x1p = x1 + 1; + size_t x2p = x2 + 1; + size_t x3p = x3 + 1; - f[D3Q27System::E] = (*d.E)(x1,x2,x3); - f[D3Q27System::N] = (*d.N)(x1,x2,x3); - f[D3Q27System::T] = (*d.T)(x1,x2,x3); - f[D3Q27System::NE] = (*d.NE)(x1,x2,x3); - f[D3Q27System::NW] = (*d.NW)(x1p,x2,x3); - f[D3Q27System::TE] = (*d.TE)(x1,x2,x3); - f[D3Q27System::TW] = (*d.TW)(x1p,x2,x3); - f[D3Q27System::TN] = (*d.TN)(x1,x2,x3); - f[D3Q27System::TS] = (*d.TS)(x1,x2p,x3); - f[D3Q27System::TNE] = (*d.TNE)(x1,x2,x3); - f[D3Q27System::TNW] = (*d.TNW)(x1p,x2,x3); - f[D3Q27System::TSE] = (*d.TSE)(x1,x2p,x3); - f[D3Q27System::TSW] = (*d.TSW)(x1p,x2p,x3); + f[D3Q27System::E] = (*d.E)(x1, x2, x3); + f[D3Q27System::N] = (*d.N)(x1, x2, x3); + f[D3Q27System::T] = (*d.T)(x1, x2, x3); + f[D3Q27System::NE] = (*d.NE)(x1, x2, x3); + f[D3Q27System::NW] = (*d.NW)(x1p, x2, x3); + f[D3Q27System::TE] = (*d.TE)(x1, x2, x3); + f[D3Q27System::TW] = (*d.TW)(x1p, x2, x3); + f[D3Q27System::TN] = (*d.TN)(x1, x2, x3); + f[D3Q27System::TS] = (*d.TS)(x1, x2p, x3); + f[D3Q27System::TNE] = (*d.TNE)(x1, x2, x3); + f[D3Q27System::TNW] = (*d.TNW)(x1p, x2, x3); + f[D3Q27System::TSE] = (*d.TSE)(x1, x2p, x3); + f[D3Q27System::TSW] = (*d.TSW)(x1p, x2p, x3); - f[D3Q27System::W ] = (*d.W)(x1p,x2,x3); - f[D3Q27System::S ] = (*d.S)(x1,x2p,x3); - f[D3Q27System::B ] = (*d.B)(x1,x2,x3p); - f[D3Q27System::SW] = (*d.SW)(x1p,x2p,x3); - f[D3Q27System::SE] = (*d.SE)(x1,x2p,x3); - f[D3Q27System::BW] = (*d.BW)(x1p,x2,x3p); - f[D3Q27System::BE] = (*d.BE)(x1,x2,x3p); - f[D3Q27System::BS] = (*d.BS)(x1,x2p,x3p); - f[D3Q27System::BN] = (*d.BN)(x1,x2,x3p); - f[D3Q27System::BSW] = (*d.BSW)(x1p,x2p,x3p); - f[D3Q27System::BSE] = (*d.BSE)(x1,x2p,x3p); - f[D3Q27System::BNW] = (*d.BNW)(x1p,x2,x3p); - f[D3Q27System::BNE] = (*d.BNE)(x1,x2,x3p); + f[D3Q27System::W] = (*d.W)(x1p, x2, x3); + f[D3Q27System::S] = (*d.S)(x1, x2p, x3); + f[D3Q27System::B] = (*d.B)(x1, x2, x3p); + f[D3Q27System::SW] = (*d.SW)(x1p, x2p, x3); + f[D3Q27System::SE] = (*d.SE)(x1, x2p, x3); + f[D3Q27System::BW] = (*d.BW)(x1p, x2, x3p); + f[D3Q27System::BE] = (*d.BE)(x1, x2, x3p); + f[D3Q27System::BS] = (*d.BS)(x1, x2p, x3p); + f[D3Q27System::BN] = (*d.BN)(x1, x2, x3p); + f[D3Q27System::BSW] = (*d.BSW)(x1p, x2p, x3p); + f[D3Q27System::BSE] = (*d.BSE)(x1, x2p, x3p); + f[D3Q27System::BNW] = (*d.BNW)(x1p, x2, x3p); + f[D3Q27System::BNE] = (*d.BNE)(x1, x2, x3p); - f[D3Q27System::ZERO] = (*d.ZERO)(x1,x2,x3); + f[D3Q27System::ZERO] = (*d.ZERO)(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSoA::setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) { - size_t x1p = x1 + 1; - size_t x2p = x2 + 1; - size_t x3p = x3 + 1; + size_t x1p = x1 + 1; + size_t x2p = x2 + 1; + size_t x3p = x3 + 1; - (*d.E)(x1,x2,x3) = f[D3Q27System::INV_E]; - (*d.N)(x1,x2,x3) = f[D3Q27System::INV_N]; - (*d.T)(x1,x2,x3) = f[D3Q27System::INV_T]; - (*d.NE)(x1,x2,x3) = f[D3Q27System::INV_NE]; - (*d.NW)(x1p,x2,x3) = f[D3Q27System::INV_NW]; - (*d.TE)(x1,x2,x3) = f[D3Q27System::INV_TE]; - (*d.TW)(x1p,x2,x3) = f[D3Q27System::INV_TW]; - (*d.TN)(x1,x2,x3) = f[D3Q27System::INV_TN]; - (*d.TS)(x1,x2p,x3) = f[D3Q27System::INV_TS]; - (*d.TNE)(x1,x2,x3) = f[D3Q27System::INV_TNE]; - (*d.TNW)(x1p,x2,x3) = f[D3Q27System::INV_TNW]; - (*d.TSE)(x1,x2p,x3) = f[D3Q27System::INV_TSE]; - (*d.TSW)(x1p,x2p,x3) = f[D3Q27System::INV_TSW]; + (*d.E)(x1, x2, x3) = f[D3Q27System::INV_E]; + (*d.N)(x1, x2, x3) = f[D3Q27System::INV_N]; + (*d.T)(x1, x2, x3) = f[D3Q27System::INV_T]; + (*d.NE)(x1, x2, x3) = f[D3Q27System::INV_NE]; + (*d.NW)(x1p, x2, x3) = f[D3Q27System::INV_NW]; + (*d.TE)(x1, x2, x3) = f[D3Q27System::INV_TE]; + (*d.TW)(x1p, x2, x3) = f[D3Q27System::INV_TW]; + (*d.TN)(x1, x2, x3) = f[D3Q27System::INV_TN]; + (*d.TS)(x1, x2p, x3) = f[D3Q27System::INV_TS]; + (*d.TNE)(x1, x2, x3) = f[D3Q27System::INV_TNE]; + (*d.TNW)(x1p, x2, x3) = f[D3Q27System::INV_TNW]; + (*d.TSE)(x1, x2p, x3) = f[D3Q27System::INV_TSE]; + (*d.TSW)(x1p, x2p, x3) = f[D3Q27System::INV_TSW]; - (*d.W)(x1p,x2,x3) = f[D3Q27System::INV_W ]; - (*d.S)(x1,x2p,x3) = f[D3Q27System::INV_S ]; - (*d.B)(x1,x2,x3p) = f[D3Q27System::INV_B ]; - (*d.SW)(x1p,x2p,x3) = f[D3Q27System::INV_SW]; - (*d.SE)(x1,x2p,x3) = f[D3Q27System::INV_SE]; - (*d.BW)(x1p,x2,x3p) = f[D3Q27System::INV_BW]; - (*d.BE)(x1,x2,x3p) = f[D3Q27System::INV_BE]; - (*d.BS)(x1,x2p,x3p) = f[D3Q27System::INV_BS]; - (*d.BN)(x1,x2,x3p) = f[D3Q27System::INV_BN]; - (*d.BSW)(x1p,x2p,x3p) = f[D3Q27System::INV_BSW]; - (*d.BSE)(x1,x2p,x3p) = f[D3Q27System::INV_BSE]; - (*d.BNW)(x1p,x2,x3p) = f[D3Q27System::INV_BNW]; - (*d.BNE)(x1,x2,x3p) = f[D3Q27System::INV_BNE]; + (*d.W)(x1p, x2, x3) = f[D3Q27System::INV_W]; + (*d.S)(x1, x2p, x3) = f[D3Q27System::INV_S]; + (*d.B)(x1, x2, x3p) = f[D3Q27System::INV_B]; + (*d.SW)(x1p, x2p, x3) = f[D3Q27System::INV_SW]; + (*d.SE)(x1, x2p, x3) = f[D3Q27System::INV_SE]; + (*d.BW)(x1p, x2, x3p) = f[D3Q27System::INV_BW]; + (*d.BE)(x1, x2, x3p) = f[D3Q27System::INV_BE]; + (*d.BS)(x1, x2p, x3p) = f[D3Q27System::INV_BS]; + (*d.BN)(x1, x2, x3p) = f[D3Q27System::INV_BN]; + (*d.BSW)(x1p, x2p, x3p) = f[D3Q27System::INV_BSW]; + (*d.BSE)(x1, x2p, x3p) = f[D3Q27System::INV_BSE]; + (*d.BNW)(x1p, x2, x3p) = f[D3Q27System::INV_BNW]; + (*d.BNE)(x1, x2, x3p) = f[D3Q27System::INV_BNE]; - (*d.ZERO)(x1,x2,x3) = f[D3Q27System::ZERO]; + (*d.ZERO)(x1, x2, x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::getDistributionInv(LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSoA::getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) { - f[D3Q27System::INV_E] = (*d.E)(x1,x2,x3); - f[D3Q27System::INV_N] = (*d.N)(x1,x2,x3); - f[D3Q27System::INV_T] = (*d.T)(x1,x2,x3); - f[D3Q27System::INV_NE] = (*d.NE)(x1,x2,x3); - f[D3Q27System::INV_NW] = (*d.NW)(x1+1,x2,x3); - f[D3Q27System::INV_TE] = (*d.TE)(x1,x2,x3); - f[D3Q27System::INV_TW] = (*d.TW)(x1+1,x2,x3); - f[D3Q27System::INV_TN] = (*d.TN)(x1,x2,x3); - f[D3Q27System::INV_TS] = (*d.TS)(x1,x2+1,x3); - f[D3Q27System::INV_TNE] = (*d.TNE)(x1,x2,x3); - f[D3Q27System::INV_TNW] = (*d.TNW)(x1+1,x2,x3); - f[D3Q27System::INV_TSE] = (*d.TSE)(x1,x2+1,x3); - f[D3Q27System::INV_TSW] = (*d.TSW)(x1+1,x2+1,x3); + f[D3Q27System::INV_E] = (*d.E)(x1, x2, x3); + f[D3Q27System::INV_N] = (*d.N)(x1, x2, x3); + f[D3Q27System::INV_T] = (*d.T)(x1, x2, x3); + f[D3Q27System::INV_NE] = (*d.NE)(x1, x2, x3); + f[D3Q27System::INV_NW] = (*d.NW)(x1 + 1, x2, x3); + f[D3Q27System::INV_TE] = (*d.TE)(x1, x2, x3); + f[D3Q27System::INV_TW] = (*d.TW)(x1 + 1, x2, x3); + f[D3Q27System::INV_TN] = (*d.TN)(x1, x2, x3); + f[D3Q27System::INV_TS] = (*d.TS)(x1, x2 + 1, x3); + f[D3Q27System::INV_TNE] = (*d.TNE)(x1, x2, x3); + f[D3Q27System::INV_TNW] = (*d.TNW)(x1 + 1, x2, x3); + f[D3Q27System::INV_TSE] = (*d.TSE)(x1, x2 + 1, x3); + f[D3Q27System::INV_TSW] = (*d.TSW)(x1 + 1, x2 + 1, x3); - f[D3Q27System::INV_W ] = (*d.W)(x1+1,x2,x3 ); - f[D3Q27System::INV_S ] = (*d.S)(x1,x2+1,x3 ); - f[D3Q27System::INV_B ] = (*d.B)(x1,x2,x3+1 ); - f[D3Q27System::INV_SW] = (*d.SW)(x1+1,x2+1,x3 ); - f[D3Q27System::INV_SE] = (*d.SE)(x1,x2+1,x3 ); - f[D3Q27System::INV_BW] = (*d.BW)(x1+1,x2,x3+1 ); - f[D3Q27System::INV_BE] = (*d.BE)(x1,x2,x3+1 ); - f[D3Q27System::INV_BS] = (*d.BS)(x1,x2+1,x3+1 ); - f[D3Q27System::INV_BN] = (*d.BN)(x1,x2,x3+1 ); - f[D3Q27System::INV_BSW] = (*d.BSW)(x1+1,x2+1,x3+1); - f[D3Q27System::INV_BSE] = (*d.BSE)(x1,x2+1,x3+1); - f[D3Q27System::INV_BNW] = (*d.BNW)(x1+1,x2,x3+1); - f[D3Q27System::INV_BNE] = (*d.BNE)(x1,x2,x3+1); + f[D3Q27System::INV_W] = (*d.W)(x1 + 1, x2, x3); + f[D3Q27System::INV_S] = (*d.S)(x1, x2 + 1, x3); + f[D3Q27System::INV_B] = (*d.B)(x1, x2, x3 + 1); + f[D3Q27System::INV_SW] = (*d.SW)(x1 + 1, x2 + 1, x3); + f[D3Q27System::INV_SE] = (*d.SE)(x1, x2 + 1, x3); + f[D3Q27System::INV_BW] = (*d.BW)(x1 + 1, x2, x3 + 1); + f[D3Q27System::INV_BE] = (*d.BE)(x1, x2, x3 + 1); + f[D3Q27System::INV_BS] = (*d.BS)(x1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BN] = (*d.BN)(x1, x2, x3 + 1); + f[D3Q27System::INV_BSW] = (*d.BSW)(x1 + 1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BSE] = (*d.BSE)(x1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BNW] = (*d.BNW)(x1 + 1, x2, x3 + 1); + f[D3Q27System::INV_BNE] = (*d.BNE)(x1, x2, x3 + 1); - f[D3Q27System::ZERO] = (*d.ZERO)(x1,x2,x3); + f[D3Q27System::ZERO] = (*d.ZERO)(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSoA::setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) { - //(*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; - //(*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; - //(*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; - //(*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; - //(*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; - //(*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; - //(*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; - //(*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; - //(*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; - //(*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; - //(*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; - //(*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; - //(*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; + //(*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; + //(*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; + //(*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; + //(*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; + //(*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; + //(*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; + //(*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; + //(*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; + //(*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; + //(*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; + //(*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; + //(*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; + //(*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; - //(*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W ]; - //(*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S ]; - //(*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B ]; - //(*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; - //(*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; - //(*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::BNE]; + //(*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W ]; + //(*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S ]; + //(*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B ]; + //(*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; + //(*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; + //(*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::BNE]; - //(*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; + //(*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSoA::setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) { - //bool directionFlag = false; - //if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) - // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::E]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) - // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::W]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) - // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::S]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) - // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::N]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) - // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::B]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) - // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::T]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) - // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::SW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) - // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::NE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) - // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::NW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) - // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::SE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) - // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::BW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) - // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::TE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) - // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::TW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) - // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::BE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) - // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::BS]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) - // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::TN]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) - // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::TS]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) - // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::BN]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) - // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::BSW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) - // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::TNE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) - // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::BSE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) - // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::TNW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) - // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::BNW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) - // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::TSE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) - // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::BNE]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) - // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::TSW]; directionFlag=true; - //if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) - // (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; directionFlag=true; -//#ifdef _DEBUG -// if(!directionFlag)UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); -//#endif //DEBUG + // bool directionFlag = false; + // if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) + // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::E]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) + // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::W]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) + // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::S]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) + // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::N]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) + // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::B]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) + // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::T]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) + // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::SW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) + // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::NE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) + // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::NW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) + // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::SE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) + // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::BW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::TE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::TW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) + // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::BE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) + // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::BS]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) + // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::TN]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) + // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::TS]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) + // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::BN]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) + // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::BSW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::TNE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) + // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::BSE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::TNW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) + // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::BNW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::TSE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) + // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::BNE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::TSW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) + // (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; directionFlag=true; + //#ifdef _DEBUG + // if(!directionFlag)UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); + //#endif //DEBUG } ////////////////////////////////////////////////////////////////////////// void D3Q27EsoTwist3DSoA::setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) { - //switch (direction) - //{ - //case D3Q27System::E : - // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; - // break; - //case D3Q27System::W : - // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; - // break; - //case D3Q27System::S : - // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; - // break; - //case D3Q27System::N : - // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; - // break; - //case D3Q27System::B : - // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; - // break; - //case D3Q27System::T : - // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::SW : - // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; - // break; - //case D3Q27System::NE : - // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; - // break; - //case D3Q27System::NW : - // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; - // break; - //case D3Q27System::SE : - // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::BW : - // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; - // break; - //case D3Q27System::TE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; - // break; - //case D3Q27System::TW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::BE : - // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::BS : - // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; - // break; - //case D3Q27System::TN : - // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; - // break; - //case D3Q27System::TS : - // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::BN : - // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; - // break; - //case D3Q27System::BSW : - // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; - // break; - //case D3Q27System::TNE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; - // break; - //case D3Q27System::BSE : - // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::TNW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; - // break; - //case D3Q27System::BNW : - // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; - // break; - //case D3Q27System::TSE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; - // break; - //case D3Q27System::BNE : - // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; - // break; - //case D3Q27System::TSW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; - // break; - //case D3Q27System::ZERO : - // (*this->zeroDistributions)(x1,x2,x3) = f; - // break; - //default: - // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - //} + // switch (direction) + //{ + // case D3Q27System::E : + // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; + // break; + // case D3Q27System::W : + // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; + // break; + // case D3Q27System::S : + // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; + // break; + // case D3Q27System::N : + // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; + // break; + // case D3Q27System::B : + // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; + // break; + // case D3Q27System::T : + // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::SW : + // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; + // break; + // case D3Q27System::NE : + // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; + // break; + // case D3Q27System::NW : + // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; + // break; + // case D3Q27System::SE : + // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::BW : + // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; + // break; + // case D3Q27System::TE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; + // break; + // case D3Q27System::TW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::BE : + // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::BS : + // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; + // break; + // case D3Q27System::TN : + // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; + // break; + // case D3Q27System::TS : + // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::BN : + // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; + // break; + // case D3Q27System::BSW : + // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; + // break; + // case D3Q27System::TNE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; + // break; + // case D3Q27System::BSE : + // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::TNW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; + // break; + // case D3Q27System::BNW : + // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; + // break; + // case D3Q27System::TSE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; + // break; + // case D3Q27System::BNE : + // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; + // break; + // case D3Q27System::TSW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; + // break; + // case D3Q27System::ZERO : + // (*this->zeroDistributions)(x1,x2,x3) = f; + // break; + // default: + // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); + //} } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSoA::setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) { -// bool directionFlag = false; -// if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) -// (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) -// (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) -// (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) -// (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) -// (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) -// (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) -// (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) -// (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) -// (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) -// (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) -// (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) -// (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) -// (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) -// (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) -// (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) -// (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) -// (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) -// (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) -// (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) -// (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) -// (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) -// (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) -// (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) -// (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) -// (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1)= f[D3Q27System::BNE]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) -// (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; directionFlag=true; -// if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) -// (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; directionFlag=true; -//#ifdef _DEBUG -// if(!directionFlag)UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); -//#endif //DEBUG + // bool directionFlag = false; + // if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) + // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) + // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) + // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) + // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) + // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) + // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) + // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) + // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) + // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) + // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) + // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) + // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) + // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) + // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) + // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) + // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; + // directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) + // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; + // directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) + // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) + // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; + // directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) + // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) + // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1)= f[D3Q27System::BNE]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) + // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; directionFlag=true; + // if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) + // (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; directionFlag=true; + //#ifdef _DEBUG + // if(!directionFlag)UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); + //#endif //DEBUG } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSoA::setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSoA::setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) { - //switch (direction) - //{ - //case D3Q27System::E : - // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; - // break; - //case D3Q27System::W : - // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; - // break; - //case D3Q27System::S : - // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; - // break; - //case D3Q27System::N : - // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; - // break; - //case D3Q27System::B : - // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::T : - // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; - // break; - //case D3Q27System::SW : - // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; - // break; - //case D3Q27System::NE : - // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; - // break; - //case D3Q27System::NW : - // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::SE : - // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; - // break; - //case D3Q27System::BW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; - // break; - //case D3Q27System::TE : - // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; - // break; - //case D3Q27System::TW : - // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::BE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::BS : - // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; - // break; - //case D3Q27System::TN : - // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; - // break; - //case D3Q27System::TS : - // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; - // break; - //case D3Q27System::BN : - // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; - // break; - //case D3Q27System::BSW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; - // break; - //case D3Q27System::TNE : - // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; - // break; - //case D3Q27System::BSE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; - // break; - //case D3Q27System::TNW : - // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; - // break; - //case D3Q27System::BNW : - // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; - // break; - //case D3Q27System::TSE : - // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; - // break; - //case D3Q27System::BNE : - // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; - // break; - //case D3Q27System::TSW : - // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; - // break; - //case D3Q27System::ZERO : - // (*this->zeroDistributions)(x1,x2,x3) = f; - // break; - //default: - // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - //} + // switch (direction) + //{ + // case D3Q27System::E : + // (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; + // break; + // case D3Q27System::W : + // (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; + // break; + // case D3Q27System::S : + // (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; + // break; + // case D3Q27System::N : + // (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; + // break; + // case D3Q27System::B : + // (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::T : + // (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; + // break; + // case D3Q27System::SW : + // (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; + // break; + // case D3Q27System::NE : + // (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; + // break; + // case D3Q27System::NW : + // (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::SE : + // (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; + // break; + // case D3Q27System::BW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; + // break; + // case D3Q27System::TE : + // (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; + // break; + // case D3Q27System::TW : + // (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::BE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::BS : + // (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; + // break; + // case D3Q27System::TN : + // (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; + // break; + // case D3Q27System::TS : + // (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; + // break; + // case D3Q27System::BN : + // (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; + // break; + // case D3Q27System::BSW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; + // break; + // case D3Q27System::TNE : + // (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; + // break; + // case D3Q27System::BSE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; + // break; + // case D3Q27System::TNW : + // (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; + // break; + // case D3Q27System::BNW : + // (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; + // break; + // case D3Q27System::TSE : + // (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; + // break; + // case D3Q27System::BNE : + // (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; + // break; + // case D3Q27System::TSW : + // (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; + // break; + // case D3Q27System::ZERO : + // (*this->zeroDistributions)(x1,x2,x3) = f; + // break; + // default: + // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); + //} } ////////////////////////////////////////////////////////////////////////// -LBMReal D3Q27EsoTwist3DSoA::getDistributionInvForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, int /*direction*/) +LBMReal D3Q27EsoTwist3DSoA::getDistributionInvForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, + int /*direction*/) { - //switch (direction) - //{ - //case D3Q27System::E : - // return (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ); - //case D3Q27System::W : - // return (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3); - //case D3Q27System::S : - // return (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3); - //case D3Q27System::N : - // return (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ); - //case D3Q27System::B : - // return (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3); - //case D3Q27System::T : - // return (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ); - //case D3Q27System::SW : - // return (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3); - //case D3Q27System::NE : - // return (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); - //case D3Q27System::NW : - // return (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ); - //case D3Q27System::SE : - // return (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3); - //case D3Q27System::BW : - // return (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3); - //case D3Q27System::TE : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ); - //case D3Q27System::TW : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ); - //case D3Q27System::BE : - // return (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3); - //case D3Q27System::BS : - // return (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3); - //case D3Q27System::TN : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ); - //case D3Q27System::TS : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ); - //case D3Q27System::BN : - // return (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3); - //case D3Q27System::BSW : - // return (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3); - //case D3Q27System::TNE : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); - //case D3Q27System::BSE : - // return (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3); - //case D3Q27System::TNW : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1); - //case D3Q27System::BNW : - // return (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3); - //case D3Q27System::TSE : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1); - //case D3Q27System::BNE : - // return (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); - //case D3Q27System::TSW : - // return (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1); - //case D3Q27System::ZERO : - // return (*this->zeroDistributions)(x1,x2,x3); - //default: - // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - //} - return 0; + // switch (direction) + //{ + // case D3Q27System::E : + // return (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ); + // case D3Q27System::W : + // return (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3); + // case D3Q27System::S : + // return (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3); + // case D3Q27System::N : + // return (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ); + // case D3Q27System::B : + // return (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3); + // case D3Q27System::T : + // return (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ); + // case D3Q27System::SW : + // return (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3); + // case D3Q27System::NE : + // return (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); + // case D3Q27System::NW : + // return (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ); + // case D3Q27System::SE : + // return (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3); + // case D3Q27System::BW : + // return (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3); + // case D3Q27System::TE : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ); + // case D3Q27System::TW : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ); + // case D3Q27System::BE : + // return (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3); + // case D3Q27System::BS : + // return (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3); + // case D3Q27System::TN : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ); + // case D3Q27System::TS : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ); + // case D3Q27System::BN : + // return (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3); + // case D3Q27System::BSW : + // return (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3); + // case D3Q27System::TNE : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); + // case D3Q27System::BSE : + // return (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3); + // case D3Q27System::TNW : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1); + // case D3Q27System::BNW : + // return (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3); + // case D3Q27System::TSE : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1); + // case D3Q27System::BNE : + // return (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); + // case D3Q27System::TSW : + // return (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1); + // case D3Q27System::ZERO : + // return (*this->zeroDistributions)(x1,x2,x3); + // default: + // UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); + //} + return 0; } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSoA::getNX1() const -{ - return NX1; -} +size_t D3Q27EsoTwist3DSoA::getNX1() const { return NX1; } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSoA::getNX2() const -{ - return NX2; -} +size_t D3Q27EsoTwist3DSoA::getNX2() const { return NX2; } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSoA::getNX3() const -{ - return NX3; -} +size_t D3Q27EsoTwist3DSoA::getNX3() const { return NX3; } ////////////////////////////////////////////////////////////////////////// -Distributions D3Q27EsoTwist3DSoA::getDistributions() -{ - return d; -} +Distributions D3Q27EsoTwist3DSoA::getDistributions() { return d; } ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.h b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.h index c409b03a6..72951922a 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.h +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSoA.h @@ -8,84 +8,82 @@ //#include <boost/serialization/serialization.hpp> //#include <boost/serialization/base_object.hpp> - -struct Distributions -{ - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr E; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr W; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr N; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr S; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr T; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr B; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr NE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr SW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr SE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr NW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TN; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BS; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BN; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TS; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TNE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TNW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TSE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr TSW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BNE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BNW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BSE; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr BSW; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr ZERO; +struct Distributions { + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr E; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr W; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr N; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr S; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr T; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr B; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr NE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr SW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr SE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr NW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TN; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BS; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BN; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TS; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TNE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TNW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TSE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr TSW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BNE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BNW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BSE; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr BSW; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr ZERO; }; - class D3Q27EsoTwist3DSoA : public EsoTwist3D { public: - D3Q27EsoTwist3DSoA(); - D3Q27EsoTwist3DSoA(const size_t& nx1, const size_t& nx2, const size_t& nx3, LBMReal value); - ////////////////////////////////////////////////////////////////////////// - ~D3Q27EsoTwist3DSoA() override; - ////////////////////////////////////////////////////////////////////////// - void swap() override; - ////////////////////////////////////////////////////////////////////////// - void getDistribution( LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - //////////////////////////////////////////////////////////////////////// - void getDistributionInv( LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX1() const override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX2() const override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX3() const override; - ////////////////////////////////////////////////////////////////////////// - Distributions getDistributions(); - ////////////////////////////////////////////////////////////////////////// - void getDistributionAfterLastStep(LBMReal* const f, size_t x1, size_t x2, size_t x3); + D3Q27EsoTwist3DSoA(); + D3Q27EsoTwist3DSoA(const size_t &nx1, const size_t &nx2, const size_t &nx3, LBMReal value); + ////////////////////////////////////////////////////////////////////////// + ~D3Q27EsoTwist3DSoA() override; + ////////////////////////////////////////////////////////////////////////// + void swap() override; + ////////////////////////////////////////////////////////////////////////// + void getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + //////////////////////////////////////////////////////////////////////// + void getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX1() const override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX2() const override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX3() const override; + ////////////////////////////////////////////////////////////////////////// + Distributions getDistributions(); + ////////////////////////////////////////////////////////////////////////// + void getDistributionAfterLastStep(LBMReal *const f, size_t x1, size_t x2, size_t x3); protected: - Distributions d; - size_t NX1, NX2, NX3; - + Distributions d; + size_t NX1, NX2, NX3; }; #endif - diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.cpp b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.cpp index 113fd04ce..6f8a6e746 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.cpp +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,642 +34,620 @@ #include "D3Q27EsoTwist3DSplittedVector.h" #include "EsoTwistD3Q27System.h" -D3Q27EsoTwist3DSplittedVector::D3Q27EsoTwist3DSplittedVector() -= default; +D3Q27EsoTwist3DSplittedVector::D3Q27EsoTwist3DSplittedVector() = default; ////////////////////////////////////////////////////////////////////////// -D3Q27EsoTwist3DSplittedVector::D3Q27EsoTwist3DSplittedVector( size_t nx1, size_t nx2, size_t nx3, LBMReal value ) +D3Q27EsoTwist3DSplittedVector::D3Q27EsoTwist3DSplittedVector(size_t nx1, size_t nx2, size_t nx3, LBMReal value) { - this->NX1 = nx1; - this->NX2 = nx2; - this->NX3 = nx3; + this->NX1 = nx1; + this->NX2 = nx2; + this->NX3 = nx3; - this->localDistributions = std::make_shared<CbArray4D<LBMReal, IndexerX4X3X2X1> >(13, nx1+1, nx2+1, nx3+1, value); - this->nonLocalDistributions = std::make_shared<CbArray4D<LBMReal, IndexerX4X3X2X1> >(13, nx1+1, nx2+1, nx3+1, value); + this->localDistributions = + std::make_shared<CbArray4D<LBMReal, IndexerX4X3X2X1>>(13, nx1 + 1, nx2 + 1, nx3 + 1, value); + this->nonLocalDistributions = + std::make_shared<CbArray4D<LBMReal, IndexerX4X3X2X1>>(13, nx1 + 1, nx2 + 1, nx3 + 1, value); - this->zeroDistributions = std::make_shared<CbArray3D<LBMReal, IndexerX3X2X1> >(nx1, nx2, nx3, value); + this->zeroDistributions = std::make_shared<CbArray3D<LBMReal, IndexerX3X2X1>>(nx1, nx2, nx3, value); } ////////////////////////////////////////////////////////////////////////// -D3Q27EsoTwist3DSplittedVector::~D3Q27EsoTwist3DSplittedVector() -= default; +D3Q27EsoTwist3DSplittedVector::~D3Q27EsoTwist3DSplittedVector() = default; ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::swap() -{ - std::swap( this->localDistributions, this->nonLocalDistributions ); -} +void D3Q27EsoTwist3DSplittedVector::swap() { std::swap(this->localDistributions, this->nonLocalDistributions); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::getDistribution(LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSplittedVector::getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) { - f[D3Q27System::E] = (*this->localDistributions)(D3Q27System::ET_E, x1,x2,x3); - f[D3Q27System::N] = (*this->localDistributions)(D3Q27System::ET_N,x1,x2,x3); - f[D3Q27System::T] = (*this->localDistributions)(D3Q27System::ET_T,x1,x2,x3); - f[D3Q27System::NE] = (*this->localDistributions)(D3Q27System::ET_NE,x1,x2,x3); - f[D3Q27System::NW] = (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2,x3); - f[D3Q27System::TE] = (*this->localDistributions)(D3Q27System::ET_TE,x1,x2,x3); - f[D3Q27System::TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1+1,x2,x3); - f[D3Q27System::TN] = (*this->localDistributions)(D3Q27System::ET_TN,x1,x2,x3); - f[D3Q27System::TS] = (*this->localDistributions)(D3Q27System::ET_TS,x1,x2+1,x3); - f[D3Q27System::TNE] = (*this->localDistributions)(D3Q27System::ET_TNE,x1,x2,x3); - f[D3Q27System::TNW] = (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2,x3); - f[D3Q27System::TSE] = (*this->localDistributions)(D3Q27System::ET_TSE,x1,x2+1,x3); - f[D3Q27System::TSW] = (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); + f[D3Q27System::E] = (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + f[D3Q27System::N] = (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + f[D3Q27System::T] = (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + f[D3Q27System::NE] = (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + f[D3Q27System::NW] = (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); + f[D3Q27System::TE] = (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + f[D3Q27System::TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); + f[D3Q27System::TN] = (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + f[D3Q27System::TS] = (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); + f[D3Q27System::TNE] = (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + f[D3Q27System::TNW] = (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); + f[D3Q27System::TSE] = (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); + f[D3Q27System::TSW] = (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); - f[D3Q27System::W ] = (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2,x3 ); - f[D3Q27System::S ] = (*this->nonLocalDistributions)(D3Q27System::ET_S,x1,x2+1,x3 ); - f[D3Q27System::B ] = (*this->nonLocalDistributions)(D3Q27System::ET_B,x1,x2,x3+1 ); - f[D3Q27System::SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); - f[D3Q27System::SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1,x2+1,x3 ); - f[D3Q27System::BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2,x3+1 ); - f[D3Q27System::BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1,x2,x3+1 ); - f[D3Q27System::BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1,x2+1,x3+1 ); - f[D3Q27System::BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1,x2,x3+1 ); - f[D3Q27System::BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); - f[D3Q27System::BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1,x2+1,x3+1); - f[D3Q27System::BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2,x3+1); - f[D3Q27System::BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1,x2,x3+1); + f[D3Q27System::W] = (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); + f[D3Q27System::S] = (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); + f[D3Q27System::B] = (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); + f[D3Q27System::SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); + f[D3Q27System::SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); + f[D3Q27System::BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); + f[D3Q27System::BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); + f[D3Q27System::BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); + f[D3Q27System::BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); + f[D3Q27System::BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); + f[D3Q27System::BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); + f[D3Q27System::BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); + f[D3Q27System::BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); - f[D3Q27System::ZERO] = (*this->zeroDistributions)(x1,x2,x3); + f[D3Q27System::ZERO] = (*this->zeroDistributions)(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSplittedVector::setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) { - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::INV_E]; - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::INV_N]; - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::INV_T]; - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::INV_NE]; - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::INV_NW]; - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::INV_TE]; - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::INV_TW]; - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::INV_TN]; - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::INV_TS]; - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::INV_TNE]; - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::INV_TNW]; - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::INV_TSE]; - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::INV_TSW]; + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f[D3Q27System::INV_E]; + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f[D3Q27System::INV_N]; + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f[D3Q27System::INV_T]; + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f[D3Q27System::INV_NE]; + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f[D3Q27System::INV_NW]; + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f[D3Q27System::INV_TE]; + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f[D3Q27System::INV_TW]; + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f[D3Q27System::INV_TN]; + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f[D3Q27System::INV_TS]; + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f[D3Q27System::INV_TNE]; + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f[D3Q27System::INV_TNW]; + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f[D3Q27System::INV_TSE]; + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f[D3Q27System::INV_TSW]; - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::INV_W ]; - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::INV_S ]; - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::INV_B ]; - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::INV_SW]; - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::INV_SE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::INV_BW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::INV_BE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::INV_BS]; - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::INV_BN]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::INV_BSW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::INV_BSE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::INV_BNW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::INV_BNE]; + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f[D3Q27System::INV_W]; + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f[D3Q27System::INV_S]; + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f[D3Q27System::INV_B]; + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f[D3Q27System::INV_SW]; + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f[D3Q27System::INV_SE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f[D3Q27System::INV_BW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f[D3Q27System::INV_BE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f[D3Q27System::INV_BS]; + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f[D3Q27System::INV_BN]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f[D3Q27System::INV_BSW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f[D3Q27System::INV_BSE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f[D3Q27System::INV_BNW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f[D3Q27System::INV_BNE]; - (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; + (*this->zeroDistributions)(x1, x2, x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::getDistributionInv(LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSplittedVector::getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) { - f[D3Q27System::INV_E] = (*this->localDistributions)(D3Q27System::ET_E, x1,x2,x3); - f[D3Q27System::INV_N] = (*this->localDistributions)(D3Q27System::ET_N,x1,x2,x3); - f[D3Q27System::INV_T] = (*this->localDistributions)(D3Q27System::ET_T,x1,x2,x3); - f[D3Q27System::INV_NE] = (*this->localDistributions)(D3Q27System::ET_NE,x1,x2,x3); - f[D3Q27System::INV_NW] = (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2,x3); - f[D3Q27System::INV_TE] = (*this->localDistributions)(D3Q27System::ET_TE,x1,x2,x3); - f[D3Q27System::INV_TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1+1,x2,x3); - f[D3Q27System::INV_TN] = (*this->localDistributions)(D3Q27System::ET_TN,x1,x2,x3); - f[D3Q27System::INV_TS] = (*this->localDistributions)(D3Q27System::ET_TS,x1,x2+1,x3); - f[D3Q27System::INV_TNE] = (*this->localDistributions)(D3Q27System::ET_TNE,x1,x2,x3); - f[D3Q27System::INV_TNW] = (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2,x3); - f[D3Q27System::INV_TSE] = (*this->localDistributions)(D3Q27System::ET_TSE,x1,x2+1,x3); - f[D3Q27System::INV_TSW] = (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); + f[D3Q27System::INV_E] = (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + f[D3Q27System::INV_N] = (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + f[D3Q27System::INV_T] = (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + f[D3Q27System::INV_NE] = (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + f[D3Q27System::INV_NW] = (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); + f[D3Q27System::INV_TE] = (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + f[D3Q27System::INV_TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); + f[D3Q27System::INV_TN] = (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + f[D3Q27System::INV_TS] = (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); + f[D3Q27System::INV_TNE] = (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + f[D3Q27System::INV_TNW] = (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); + f[D3Q27System::INV_TSE] = (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); + f[D3Q27System::INV_TSW] = (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); - f[D3Q27System::INV_W ] = (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2,x3 ); - f[D3Q27System::INV_S ] = (*this->nonLocalDistributions)(D3Q27System::ET_S,x1,x2+1,x3 ); - f[D3Q27System::INV_B ] = (*this->nonLocalDistributions)(D3Q27System::ET_B,x1,x2,x3+1 ); - f[D3Q27System::INV_SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); - f[D3Q27System::INV_SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1,x2+1,x3 ); - f[D3Q27System::INV_BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2,x3+1 ); - f[D3Q27System::INV_BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1,x2,x3+1 ); - f[D3Q27System::INV_BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1,x2+1,x3+1 ); - f[D3Q27System::INV_BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1,x2,x3+1 ); - f[D3Q27System::INV_BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); - f[D3Q27System::INV_BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1,x2+1,x3+1); - f[D3Q27System::INV_BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2,x3+1); - f[D3Q27System::INV_BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1,x2,x3+1); + f[D3Q27System::INV_W] = (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); + f[D3Q27System::INV_S] = (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); + f[D3Q27System::INV_B] = (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); + f[D3Q27System::INV_SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); + f[D3Q27System::INV_SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); + f[D3Q27System::INV_BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); + f[D3Q27System::INV_BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); + f[D3Q27System::INV_BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); + f[D3Q27System::INV_BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); + f[D3Q27System::INV_BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); + f[D3Q27System::INV_BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); - f[D3Q27System::ZERO] = (*this->zeroDistributions)(x1,x2,x3); + f[D3Q27System::ZERO] = (*this->zeroDistributions)(x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) +void D3Q27EsoTwist3DSplittedVector::setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) { - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f[D3Q27System::E]; + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f[D3Q27System::N]; + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f[D3Q27System::T]; + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f[D3Q27System::NE]; + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f[D3Q27System::NW]; + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f[D3Q27System::TE]; + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f[D3Q27System::TW]; + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f[D3Q27System::TN]; + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f[D3Q27System::TS]; + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f[D3Q27System::TNE]; + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f[D3Q27System::TNW]; + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f[D3Q27System::TSE]; + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f[D3Q27System::TSW]; - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W ]; - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S ]; - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B ]; - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::BNE]; + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f[D3Q27System::W]; + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f[D3Q27System::S]; + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f[D3Q27System::B]; + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f[D3Q27System::SW]; + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f[D3Q27System::SE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f[D3Q27System::BW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f[D3Q27System::BE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f[D3Q27System::BS]; + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f[D3Q27System::BN]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f[D3Q27System::BSW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f[D3Q27System::BSE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f[D3Q27System::BNW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f[D3Q27System::BNE]; - (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; + (*this->zeroDistributions)(x1, x2, x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSplittedVector::setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) { - if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::E]; - if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::W]; - if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::S]; - if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::N]; - if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::B]; - if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::T]; - if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::SW]; - if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::NE]; - if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::NW]; - if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::SE]; - if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::BW]; - if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::TE]; - if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::TW]; - if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::BE]; - if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::BS]; - if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::TN]; - if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::TS]; - if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::BN]; - if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::BSW]; - if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::TNE]; - if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::BSE]; - if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::TNW]; - if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::BNW]; - if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::TSE]; - if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::BNE]; - if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f[D3Q27System::TSW]; - if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) - (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; + if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f[D3Q27System::E]; + if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f[D3Q27System::W]; + if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f[D3Q27System::S]; + if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f[D3Q27System::N]; + if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f[D3Q27System::B]; + if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f[D3Q27System::T]; + if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f[D3Q27System::SW]; + if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f[D3Q27System::NE]; + if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f[D3Q27System::NW]; + if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f[D3Q27System::SE]; + if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f[D3Q27System::BW]; + if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f[D3Q27System::TE]; + if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f[D3Q27System::TW]; + if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f[D3Q27System::BE]; + if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f[D3Q27System::BS]; + if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f[D3Q27System::TN]; + if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f[D3Q27System::TS]; + if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f[D3Q27System::BN]; + if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f[D3Q27System::BSW]; + if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f[D3Q27System::TNE]; + if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f[D3Q27System::BSE]; + if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f[D3Q27System::TNW]; + if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f[D3Q27System::BNW]; + if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f[D3Q27System::TSE]; + if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f[D3Q27System::BNE]; + if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f[D3Q27System::TSW]; + if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) + (*this->zeroDistributions)(x1, x2, x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) +void D3Q27EsoTwist3DSplittedVector::setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + int direction) { - switch (direction) - { - case D3Q27System::E : - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; - break; - case D3Q27System::W : - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; - break; - case D3Q27System::S : - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; - break; - case D3Q27System::N : - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; - break; - case D3Q27System::B : - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; - break; - case D3Q27System::T : - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; - break; - case D3Q27System::SW : - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; - break; - case D3Q27System::NE : - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; - break; - case D3Q27System::NW : - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; - break; - case D3Q27System::SE : - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; - break; - case D3Q27System::BW : - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; - break; - case D3Q27System::TE : - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; - break; - case D3Q27System::TW : - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; - break; - case D3Q27System::BE : - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; - break; - case D3Q27System::BS : - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; - break; - case D3Q27System::TN : - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; - break; - case D3Q27System::TS : - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; - break; - case D3Q27System::BN : - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; - break; - case D3Q27System::BSW : - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; - break; - case D3Q27System::TNE : - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; - break; - case D3Q27System::BSE : - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; - break; - case D3Q27System::TNW : - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; - break; - case D3Q27System::BNW : - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; - break; - case D3Q27System::TSE : - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; - break; - case D3Q27System::BNE : - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; - break; - case D3Q27System::TSW : - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; - break; - case D3Q27System::ZERO : - (*this->zeroDistributions)(x1,x2,x3) = f; - break; - default: - UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - } + switch (direction) { + case D3Q27System::E: + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f; + break; + case D3Q27System::W: + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f; + break; + case D3Q27System::S: + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f; + break; + case D3Q27System::N: + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f; + break; + case D3Q27System::B: + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f; + break; + case D3Q27System::T: + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f; + break; + case D3Q27System::SW: + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f; + break; + case D3Q27System::NE: + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f; + break; + case D3Q27System::NW: + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f; + break; + case D3Q27System::SE: + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::BW: + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f; + break; + case D3Q27System::TE: + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f; + break; + case D3Q27System::TW: + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f; + break; + case D3Q27System::BE: + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::BS: + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f; + break; + case D3Q27System::TN: + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::TS: + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f; + break; + case D3Q27System::BN: + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f; + break; + case D3Q27System::BSW: + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f; + break; + case D3Q27System::TNE: + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::BSE: + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::TNW: + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::BNW: + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f; + break; + case D3Q27System::TSE: + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f; + break; + case D3Q27System::BNE: + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f; + break; + case D3Q27System::TSW: + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f; + break; + case D3Q27System::ZERO: + (*this->zeroDistributions)(x1, x2, x3) = f; + break; + default: + UB_THROW(UbException(UB_EXARGS, "Direction didn't find")); + } } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSplittedVector::setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, + size_t x3, unsigned long int direction) { - if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::E]; - if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f[D3Q27System::W]; - if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f[D3Q27System::S]; - if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::N]; - if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f[D3Q27System::B]; - if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::T]; - if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f[D3Q27System::SW]; - if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::NE]; - if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f[D3Q27System::NW]; - if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f[D3Q27System::SE]; - if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f[D3Q27System::BW]; - if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::TE]; - if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f[D3Q27System::TW]; - if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f[D3Q27System::BE]; - if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f[D3Q27System::BS]; - if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::TN]; - if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f[D3Q27System::TS]; - if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f[D3Q27System::BN]; - if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f[D3Q27System::BSW]; - if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::TNE]; - if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f[D3Q27System::BSE]; - if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f[D3Q27System::TNW]; - if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f[D3Q27System::BNW]; - if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f[D3Q27System::TSE]; - if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1)= f[D3Q27System::BNE]; - if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f[D3Q27System::TSW]; - if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) - (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; + if ((direction & EsoTwistD3Q27System::etE) == EsoTwistD3Q27System::etE) + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f[D3Q27System::E]; + if ((direction & EsoTwistD3Q27System::etW) == EsoTwistD3Q27System::etW) + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f[D3Q27System::W]; + if ((direction & EsoTwistD3Q27System::etS) == EsoTwistD3Q27System::etS) + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f[D3Q27System::S]; + if ((direction & EsoTwistD3Q27System::etN) == EsoTwistD3Q27System::etN) + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f[D3Q27System::N]; + if ((direction & EsoTwistD3Q27System::etB) == EsoTwistD3Q27System::etB) + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f[D3Q27System::B]; + if ((direction & EsoTwistD3Q27System::etT) == EsoTwistD3Q27System::etT) + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f[D3Q27System::T]; + if ((direction & EsoTwistD3Q27System::etSW) == EsoTwistD3Q27System::etSW) + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f[D3Q27System::SW]; + if ((direction & EsoTwistD3Q27System::etNE) == EsoTwistD3Q27System::etNE) + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f[D3Q27System::NE]; + if ((direction & EsoTwistD3Q27System::etNW) == EsoTwistD3Q27System::etNW) + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f[D3Q27System::NW]; + if ((direction & EsoTwistD3Q27System::etSE) == EsoTwistD3Q27System::etSE) + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f[D3Q27System::SE]; + if ((direction & EsoTwistD3Q27System::etBW) == EsoTwistD3Q27System::etBW) + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f[D3Q27System::BW]; + if ((direction & EsoTwistD3Q27System::etTE) == EsoTwistD3Q27System::etTE) + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f[D3Q27System::TE]; + if ((direction & EsoTwistD3Q27System::etTW) == EsoTwistD3Q27System::etTW) + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f[D3Q27System::TW]; + if ((direction & EsoTwistD3Q27System::etBE) == EsoTwistD3Q27System::etBE) + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f[D3Q27System::BE]; + if ((direction & EsoTwistD3Q27System::etBS) == EsoTwistD3Q27System::etBS) + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f[D3Q27System::BS]; + if ((direction & EsoTwistD3Q27System::etTN) == EsoTwistD3Q27System::etTN) + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f[D3Q27System::TN]; + if ((direction & EsoTwistD3Q27System::etTS) == EsoTwistD3Q27System::etTS) + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f[D3Q27System::TS]; + if ((direction & EsoTwistD3Q27System::etBN) == EsoTwistD3Q27System::etBN) + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f[D3Q27System::BN]; + if ((direction & EsoTwistD3Q27System::etBSW) == EsoTwistD3Q27System::etBSW) + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f[D3Q27System::BSW]; + if ((direction & EsoTwistD3Q27System::etTNE) == EsoTwistD3Q27System::etTNE) + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f[D3Q27System::TNE]; + if ((direction & EsoTwistD3Q27System::etBSE) == EsoTwistD3Q27System::etBSE) + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f[D3Q27System::BSE]; + if ((direction & EsoTwistD3Q27System::etTNW) == EsoTwistD3Q27System::etTNW) + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f[D3Q27System::TNW]; + if ((direction & EsoTwistD3Q27System::etBNW) == EsoTwistD3Q27System::etBNW) + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f[D3Q27System::BNW]; + if ((direction & EsoTwistD3Q27System::etTSE) == EsoTwistD3Q27System::etTSE) + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f[D3Q27System::TSE]; + if ((direction & EsoTwistD3Q27System::etBNE) == EsoTwistD3Q27System::etBNE) + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f[D3Q27System::BNE]; + if ((direction & EsoTwistD3Q27System::etTSW) == EsoTwistD3Q27System::etTSW) + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f[D3Q27System::TSW]; + if ((direction & EsoTwistD3Q27System::ZERO) == EsoTwistD3Q27System::ZERO) + (*this->zeroDistributions)(x1, x2, x3) = f[D3Q27System::ZERO]; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) +void D3Q27EsoTwist3DSplittedVector::setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) { - switch (direction) - { - case D3Q27System::E : - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f; - break; - case D3Q27System::W : - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ) = f; - break; - case D3Q27System::S : - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ) = f; - break; - case D3Q27System::N : - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f; - break; - case D3Q27System::B : - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ) = f; - break; - case D3Q27System::T : - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f; - break; - case D3Q27System::SW : - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ) = f; - break; - case D3Q27System::NE : - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f; - break; - case D3Q27System::NW : - (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3) = f; - break; - case D3Q27System::SE : - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ) = f; - break; - case D3Q27System::BW : - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ) = f; - break; - case D3Q27System::TE : - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f; - break; - case D3Q27System::TW : - (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3) = f; - break; - case D3Q27System::BE : - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ) = f; - break; - case D3Q27System::BS : - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ) = f; - break; - case D3Q27System::TN : - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f; - break; - case D3Q27System::TS : - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3) = f; - break; - case D3Q27System::BN : - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ) = f; - break; - case D3Q27System::BSW : - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1) = f; - break; - case D3Q27System::TNE : - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f; - break; - case D3Q27System::BSE : - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1) = f; - break; - case D3Q27System::TNW : - (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3) = f; - break; - case D3Q27System::BNW : - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1) = f; - break; - case D3Q27System::TSE : - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3) = f; - break; - case D3Q27System::BNE : - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1) = f; - break; - case D3Q27System::TSW : - (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3) = f; - break; - case D3Q27System::ZERO : - (*this->zeroDistributions)(x1,x2,x3) = f; - break; - default: - UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - } + switch (direction) { + case D3Q27System::E: + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f; + break; + case D3Q27System::W: + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3) = f; + break; + case D3Q27System::S: + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3) = f; + break; + case D3Q27System::N: + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f; + break; + case D3Q27System::B: + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1) = f; + break; + case D3Q27System::T: + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f; + break; + case D3Q27System::SW: + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3) = f; + break; + case D3Q27System::NE: + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f; + break; + case D3Q27System::NW: + (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::SE: + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3) = f; + break; + case D3Q27System::BW: + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1) = f; + break; + case D3Q27System::TE: + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f; + break; + case D3Q27System::TW: + (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::BE: + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1) = f; + break; + case D3Q27System::BS: + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::TN: + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f; + break; + case D3Q27System::TS: + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3) = f; + break; + case D3Q27System::BN: + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1) = f; + break; + case D3Q27System::BSW: + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::TNE: + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f; + break; + case D3Q27System::BSE: + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1) = f; + break; + case D3Q27System::TNW: + (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3) = f; + break; + case D3Q27System::BNW: + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1) = f; + break; + case D3Q27System::TSE: + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3) = f; + break; + case D3Q27System::BNE: + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1) = f; + break; + case D3Q27System::TSW: + (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3) = f; + break; + case D3Q27System::ZERO: + (*this->zeroDistributions)(x1, x2, x3) = f; + break; + default: + UB_THROW(UbException(UB_EXARGS, "Direction didn't find")); + } } ////////////////////////////////////////////////////////////////////////// LBMReal D3Q27EsoTwist3DSplittedVector::getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) { - switch (direction) - { - case D3Q27System::W : - return (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ); - case D3Q27System::E : - return (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3); - case D3Q27System::N : - return (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3); - case D3Q27System::S : - return (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ); - case D3Q27System::T : - return (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3); - case D3Q27System::B : - return (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ); - case D3Q27System::NE : - return (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3); - case D3Q27System::SW : - return (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); - case D3Q27System::SE : - return (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ); - case D3Q27System::NW : - return (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3); - case D3Q27System::TE : - return (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3); - case D3Q27System::BW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ); - case D3Q27System::BE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ); - case D3Q27System::TW : - return (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3); - case D3Q27System::TN : - return (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3); - case D3Q27System::BS : - return (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ); - case D3Q27System::BN : - return (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ); - case D3Q27System::TS : - return (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3); - case D3Q27System::TNE : - return (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3); - case D3Q27System::BSW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); - case D3Q27System::TNW : - return (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3); - case D3Q27System::BSE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1); - case D3Q27System::TSE : - return (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3); - case D3Q27System::BNW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1); - case D3Q27System::TSW : - return (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); - case D3Q27System::BNE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1); - case D3Q27System::ZERO : - return (*this->zeroDistributions)(x1,x2,x3); - default: - UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - } + switch (direction) { + case D3Q27System::W: + return (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); + case D3Q27System::E: + return (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + case D3Q27System::N: + return (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + case D3Q27System::S: + return (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); + case D3Q27System::T: + return (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + case D3Q27System::B: + return (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); + case D3Q27System::NE: + return (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + case D3Q27System::SW: + return (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); + case D3Q27System::SE: + return (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); + case D3Q27System::NW: + return (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); + case D3Q27System::TE: + return (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + case D3Q27System::BW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); + case D3Q27System::BE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); + case D3Q27System::TW: + return (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); + case D3Q27System::TN: + return (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + case D3Q27System::BS: + return (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); + case D3Q27System::BN: + return (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); + case D3Q27System::TS: + return (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); + case D3Q27System::TNE: + return (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + case D3Q27System::BSW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); + case D3Q27System::TNW: + return (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); + case D3Q27System::BSE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); + case D3Q27System::TSE: + return (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); + case D3Q27System::BNW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); + case D3Q27System::TSW: + return (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); + case D3Q27System::BNE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); + case D3Q27System::ZERO: + return (*this->zeroDistributions)(x1, x2, x3); + default: + UB_THROW(UbException(UB_EXARGS, "Direction didn't find")); + } } ////////////////////////////////////////////////////////////////////////// LBMReal D3Q27EsoTwist3DSplittedVector::getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) { - switch (direction) - { - case D3Q27System::E : - return (*this->nonLocalDistributions)(D3Q27System::ET_W,x1+1,x2, x3 ); - case D3Q27System::W : - return (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3); - case D3Q27System::S : - return (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3); - case D3Q27System::N : - return (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2+1,x3 ); - case D3Q27System::B : - return (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3); - case D3Q27System::T : - return (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3+1 ); - case D3Q27System::SW : - return (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3); - case D3Q27System::NE : - return (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1+1,x2+1,x3 ); - case D3Q27System::NW : - return (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2+1,x3 ); - case D3Q27System::SE : - return (*this->localDistributions)(D3Q27System::ET_NW,x1+1,x2, x3); - case D3Q27System::BW : - return (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3); - case D3Q27System::TE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1+1,x2, x3+1 ); - case D3Q27System::TW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3+1 ); - case D3Q27System::BE : - return (*this->localDistributions)(D3Q27System::ET_TW,x1+1,x2, x3); - case D3Q27System::BS : - return (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3); - case D3Q27System::TN : - return (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2+1,x3+1 ); - case D3Q27System::TS : - return (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3+1 ); - case D3Q27System::BN : - return (*this->localDistributions)(D3Q27System::ET_TS,x1, x2+1,x3); - case D3Q27System::BSW : - return (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3); - case D3Q27System::TNE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1+1,x2+1,x3+1); - case D3Q27System::BSE : - return (*this->localDistributions)(D3Q27System::ET_TNW,x1+1,x2, x3); - case D3Q27System::TNW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2+1,x3+1); - case D3Q27System::BNW : - return (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2+1,x3); - case D3Q27System::TSE : - return (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1+1,x2, x3+1); - case D3Q27System::BNE : - return (*this->localDistributions)(D3Q27System::ET_TSW,x1+1,x2+1,x3); - case D3Q27System::TSW : - return (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3+1); - case D3Q27System::ZERO : - return (*this->zeroDistributions)(x1,x2,x3); - default: - UB_THROW( UbException(UB_EXARGS, "Direction didn't find") ); - } + switch (direction) { + case D3Q27System::E: + return (*this->nonLocalDistributions)(D3Q27System::ET_W, x1 + 1, x2, x3); + case D3Q27System::W: + return (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + case D3Q27System::S: + return (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + case D3Q27System::N: + return (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2 + 1, x3); + case D3Q27System::B: + return (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + case D3Q27System::T: + return (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3 + 1); + case D3Q27System::SW: + return (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + case D3Q27System::NE: + return (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1 + 1, x2 + 1, x3); + case D3Q27System::NW: + return (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2 + 1, x3); + case D3Q27System::SE: + return (*this->localDistributions)(D3Q27System::ET_NW, x1 + 1, x2, x3); + case D3Q27System::BW: + return (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + case D3Q27System::TE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1 + 1, x2, x3 + 1); + case D3Q27System::TW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3 + 1); + case D3Q27System::BE: + return (*this->localDistributions)(D3Q27System::ET_TW, x1 + 1, x2, x3); + case D3Q27System::BS: + return (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + case D3Q27System::TN: + return (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2 + 1, x3 + 1); + case D3Q27System::TS: + return (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3 + 1); + case D3Q27System::BN: + return (*this->localDistributions)(D3Q27System::ET_TS, x1, x2 + 1, x3); + case D3Q27System::BSW: + return (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + case D3Q27System::TNE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1 + 1, x2 + 1, x3 + 1); + case D3Q27System::BSE: + return (*this->localDistributions)(D3Q27System::ET_TNW, x1 + 1, x2, x3); + case D3Q27System::TNW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2 + 1, x3 + 1); + case D3Q27System::BNW: + return (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2 + 1, x3); + case D3Q27System::TSE: + return (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1 + 1, x2, x3 + 1); + case D3Q27System::BNE: + return (*this->localDistributions)(D3Q27System::ET_TSW, x1 + 1, x2 + 1, x3); + case D3Q27System::TSW: + return (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3 + 1); + case D3Q27System::ZERO: + return (*this->zeroDistributions)(x1, x2, x3); + default: + UB_THROW(UbException(UB_EXARGS, "Direction didn't find")); + } } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSplittedVector::getNX1() const -{ - return NX1; -} +size_t D3Q27EsoTwist3DSplittedVector::getNX1() const { return NX1; } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSplittedVector::getNX2() const -{ - return NX2; -} +size_t D3Q27EsoTwist3DSplittedVector::getNX2() const { return NX2; } ////////////////////////////////////////////////////////////////////////// -size_t D3Q27EsoTwist3DSplittedVector::getNX3() const -{ - return NX3; -} +size_t D3Q27EsoTwist3DSplittedVector::getNX3() const { return NX3; } ////////////////////////////////////////////////////////////////////////// -CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr D3Q27EsoTwist3DSplittedVector::getLocalDistributions() +CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr D3Q27EsoTwist3DSplittedVector::getLocalDistributions() { - return this->localDistributions; + return this->localDistributions; } ////////////////////////////////////////////////////////////////////////// -CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr D3Q27EsoTwist3DSplittedVector::getNonLocalDistributions() +CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr D3Q27EsoTwist3DSplittedVector::getNonLocalDistributions() { - return this->nonLocalDistributions; + return this->nonLocalDistributions; } ////////////////////////////////////////////////////////////////////////// -CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr D3Q27EsoTwist3DSplittedVector::getZeroDistributions() +CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr D3Q27EsoTwist3DSplittedVector::getZeroDistributions() { - return this->zeroDistributions; + return this->zeroDistributions; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setNX1(size_t newNX1) -{ - NX1 = newNX1; -} +void D3Q27EsoTwist3DSplittedVector::setNX1(size_t newNX1) { NX1 = newNX1; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setNX2(size_t newNX2) -{ - NX2 = newNX2; -} +void D3Q27EsoTwist3DSplittedVector::setNX2(size_t newNX2) { NX2 = newNX2; } ////////////////////////////////////////////////////////////////////////// -void D3Q27EsoTwist3DSplittedVector::setNX3(size_t newNX3) -{ - NX3 = newNX3; -} +void D3Q27EsoTwist3DSplittedVector::setNX3(size_t newNX3) { NX3 = newNX3; } ////////////////////////////////////////////////////////////////////////// void D3Q27EsoTwist3DSplittedVector::setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array) { - localDistributions = array; + localDistributions = array; } ////////////////////////////////////////////////////////////////////////// void D3Q27EsoTwist3DSplittedVector::setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array) { - nonLocalDistributions = array; + nonLocalDistributions = array; } ////////////////////////////////////////////////////////////////////////// void D3Q27EsoTwist3DSplittedVector::setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr array) { - zeroDistributions = array; + zeroDistributions = array; } ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.h b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.h index 1e92809c0..1c0d7d05f 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.h +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVector.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,75 +34,77 @@ #ifndef D3Q27EsoTwist3DSplittedVector_h #define D3Q27EsoTwist3DSplittedVector_h -#include "EsoTwist3D.h" #include "D3Q27System.h" -#include "basics/container/CbArray4D.h" +#include "EsoTwist3D.h" #include "basics/container/CbArray3D.h" +#include "basics/container/CbArray4D.h" //! \brief Class implements EsoTwist3D //! \details D3Q27EsoTwist3DSplittedVector uses three vectors to implement Esoteric Twist method class D3Q27EsoTwist3DSplittedVector : public EsoTwist3D { public: - D3Q27EsoTwist3DSplittedVector(); - //! \param nx1 number of nodes in x1 direction - //! \param nx2 number of nodes in x2 direction - //! \param nx3 number of nodes in x3 direction - //! \param value initialisation value - D3Q27EsoTwist3DSplittedVector(size_t nx1, size_t nx2, size_t nx3, LBMReal value); - ////////////////////////////////////////////////////////////////////////// - ~D3Q27EsoTwist3DSplittedVector() override; - ////////////////////////////////////////////////////////////////////////// - void swap() override; - ////////////////////////////////////////////////////////////////////////// - void getDistribution( LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - //////////////////////////////////////////////////////////////////////// - void getDistributionInv( LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX1() const override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX2() const override; - ////////////////////////////////////////////////////////////////////////// - size_t getNX3() const override; - ////////////////////////////////////////////////////////////////////////// - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr getLocalDistributions(); - ////////////////////////////////////////////////////////////////////////// - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr getNonLocalDistributions(); - ////////////////////////////////////////////////////////////////////////// - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr getZeroDistributions(); - ////////////////////////////////////////////////////////////////////////// - void setNX1(size_t newNX1); - void setNX2(size_t newNX2); - void setNX3(size_t newNX3); - void setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array); - void setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array); - void setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr array); - -protected: - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr zeroDistributions; - size_t NX1, NX2, NX3; + D3Q27EsoTwist3DSplittedVector(); + //! \param nx1 number of nodes in x1 direction + //! \param nx2 number of nodes in x2 direction + //! \param nx3 number of nodes in x3 direction + //! \param value initialisation value + D3Q27EsoTwist3DSplittedVector(size_t nx1, size_t nx2, size_t nx3, LBMReal value); + ////////////////////////////////////////////////////////////////////////// + ~D3Q27EsoTwist3DSplittedVector() override; + ////////////////////////////////////////////////////////////////////////// + void swap() override; + ////////////////////////////////////////////////////////////////////////// + void getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + //////////////////////////////////////////////////////////////////////// + void getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX1() const override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX2() const override; + ////////////////////////////////////////////////////////////////////////// + size_t getNX3() const override; + ////////////////////////////////////////////////////////////////////////// + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr getLocalDistributions(); + ////////////////////////////////////////////////////////////////////////// + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr getNonLocalDistributions(); + ////////////////////////////////////////////////////////////////////////// + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr getZeroDistributions(); + ////////////////////////////////////////////////////////////////////////// + void setNX1(size_t newNX1); + void setNX2(size_t newNX2); + void setNX3(size_t newNX3); + void setLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array); + void setNonLocalDistributions(CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr array); + void setZeroDistributions(CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr array); - friend class MPIIORestartCoProcessor; - friend class MPIIOMigrationCoProcessor; +protected: + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + size_t NX1, NX2, NX3; + friend class MPIIORestartCoProcessor; + friend class MPIIOMigrationCoProcessor; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.cpp b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.cpp index 6a8ccc149..d67341e1a 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.cpp +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.cpp @@ -1,13 +1,16 @@ #include "D3Q27EsoTwist3DSplittedVectorEx.h" -D3Q27EsoTwist3DSplittedVectorEx::D3Q27EsoTwist3DSplittedVectorEx( int nx1, int nx2, int nx3, LBMReal value ) +D3Q27EsoTwist3DSplittedVectorEx::D3Q27EsoTwist3DSplittedVectorEx(int nx1, int nx2, int nx3, LBMReal value) { - this->NX1 = nx1; - this->NX2 = nx2; - this->NX3 = nx3; + this->NX1 = nx1; + this->NX2 = nx2; + this->NX3 = nx3; - this->localDistributions = CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal,IndexerX4X3X2X1>(13, nx1, nx2, nx3, value)); - this->nonLocalDistributions = CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr(new CbArray4D<LBMReal,IndexerX4X3X2X1>(13, nx1, nx2, nx3, value)); + this->localDistributions = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(13, nx1, nx2, nx3, value)); + this->nonLocalDistributions = CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr( + new CbArray4D<LBMReal, IndexerX4X3X2X1>(13, nx1, nx2, nx3, value)); - this->zeroDistributions = CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal,IndexerX3X2X1>(nx1, nx2, nx3, value)); + this->zeroDistributions = + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr(new CbArray3D<LBMReal, IndexerX3X2X1>(nx1, nx2, nx3, value)); } diff --git a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.h b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.h index 9e41d877b..54f9d55e5 100644 --- a/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.h +++ b/src/cpu/VirtualFluidsCore/Data/D3Q27EsoTwist3DSplittedVectorEx.h @@ -6,10 +6,10 @@ class D3Q27EsoTwist3DSplittedVectorEx : public D3Q27EsoTwist3DSplittedVector { public: - D3Q27EsoTwist3DSplittedVectorEx(int nx1, int nx2, int nx3, LBMReal value); + D3Q27EsoTwist3DSplittedVectorEx(int nx1, int nx2, int nx3, LBMReal value); + protected: private: }; #endif - diff --git a/src/cpu/VirtualFluidsCore/Data/DataSet3D.h b/src/cpu/VirtualFluidsCore/Data/DataSet3D.h index 66fefb15a..c0171588b 100644 --- a/src/cpu/VirtualFluidsCore/Data/DataSet3D.h +++ b/src/cpu/VirtualFluidsCore/Data/DataSet3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,134 +36,89 @@ #include <PointerDefinitions.h> -#include "basics/container/CbArray4D.h" -#include "basics/container/CbArray3D.h" #include "DistributionArray3D.h" +#include "basics/container/CbArray3D.h" +#include "basics/container/CbArray4D.h" -using AverageValuesArray3D = CbArray4D<LBMReal, IndexerX4X3X2X1>; +using AverageValuesArray3D = CbArray4D<LBMReal, IndexerX4X3X2X1>; using ShearStressValuesArray3D = CbArray4D<LBMReal, IndexerX4X3X2X1>; -using RelaxationFactorArray3D = CbArray3D<LBMReal, IndexerX3X2X1>; +using RelaxationFactorArray3D = CbArray3D<LBMReal, IndexerX3X2X1>; //! A class provides an interface for data structures in the kernel. class DataSet3D { public: - SPtr<DistributionArray3D> getFdistributions() const; - void setFdistributions(SPtr<DistributionArray3D> distributions); + SPtr<DistributionArray3D> getFdistributions() const; + void setFdistributions(SPtr<DistributionArray3D> distributions); + + SPtr<AverageValuesArray3D> getAverageDensity() const; + void setAverageDensity(SPtr<AverageValuesArray3D> values); + + SPtr<AverageValuesArray3D> getAverageVelocity() const; + void setAverageVelocity(SPtr<AverageValuesArray3D> values); + + SPtr<AverageValuesArray3D> getAverageFluctuations() const; + void setAverageFluctuations(SPtr<AverageValuesArray3D> values); - SPtr<AverageValuesArray3D> getAverageDensity() const; - void setAverageDensity(SPtr<AverageValuesArray3D> values); + SPtr<AverageValuesArray3D> getAverageTriplecorrelations() const; + void setAverageTriplecorrelations(SPtr<AverageValuesArray3D> values); - SPtr<AverageValuesArray3D> getAverageVelocity() const; - void setAverageVelocity(SPtr<AverageValuesArray3D> values); + SPtr<AverageValuesArray3D> getAverageValues() const; + void setAverageValues(SPtr<AverageValuesArray3D> values); - SPtr<AverageValuesArray3D> getAverageFluctuations() const; - void setAverageFluctuations(SPtr<AverageValuesArray3D> values); + SPtr<ShearStressValuesArray3D> getShearStressValues() const; + void setShearStressValues(SPtr<ShearStressValuesArray3D> values); - SPtr<AverageValuesArray3D> getAverageTriplecorrelations() const; - void setAverageTriplecorrelations(SPtr<AverageValuesArray3D> values); - - SPtr<AverageValuesArray3D> getAverageValues() const; - void setAverageValues(SPtr<AverageValuesArray3D> values); - - SPtr<ShearStressValuesArray3D> getShearStressValues() const; - void setShearStressValues(SPtr<ShearStressValuesArray3D> values); + SPtr<RelaxationFactorArray3D> getRelaxationFactor() const; + void setRelaxationFactor(SPtr<RelaxationFactorArray3D> values); - SPtr<RelaxationFactorArray3D> getRelaxationFactor() const; - void setRelaxationFactor(SPtr<RelaxationFactorArray3D> values); protected: private: - SPtr<DistributionArray3D> fdistributions; - SPtr<AverageValuesArray3D> averageValues; + SPtr<DistributionArray3D> fdistributions; + SPtr<AverageValuesArray3D> averageValues; - SPtr<AverageValuesArray3D> averageDensity; - SPtr<AverageValuesArray3D> averageVelocity; - SPtr<AverageValuesArray3D> averageFluktuations; - SPtr<AverageValuesArray3D> averageTriplecorrelations; + SPtr<AverageValuesArray3D> averageDensity; + SPtr<AverageValuesArray3D> averageVelocity; + SPtr<AverageValuesArray3D> averageFluktuations; + SPtr<AverageValuesArray3D> averageTriplecorrelations; - SPtr<ShearStressValuesArray3D> shearStressValues; - - SPtr<RelaxationFactorArray3D> relaxationFactor; + SPtr<ShearStressValuesArray3D> shearStressValues; + SPtr<RelaxationFactorArray3D> relaxationFactor; }; -inline SPtr<DistributionArray3D> DataSet3D::getFdistributions() const -{ - return fdistributions; -} +inline SPtr<DistributionArray3D> DataSet3D::getFdistributions() const { return fdistributions; } -inline void DataSet3D::setFdistributions(SPtr<DistributionArray3D> distributions) -{ - fdistributions = distributions; -} +inline void DataSet3D::setFdistributions(SPtr<DistributionArray3D> distributions) { fdistributions = distributions; } -inline SPtr<AverageValuesArray3D> DataSet3D::getAverageValues() const -{ - return averageValues; -} +inline SPtr<AverageValuesArray3D> DataSet3D::getAverageValues() const { return averageValues; } -inline void DataSet3D::setAverageValues(SPtr<AverageValuesArray3D> values) -{ - averageValues = values; -} +inline void DataSet3D::setAverageValues(SPtr<AverageValuesArray3D> values) { averageValues = values; } -inline SPtr<AverageValuesArray3D> DataSet3D::getAverageDensity() const -{ - return averageDensity; -} +inline SPtr<AverageValuesArray3D> DataSet3D::getAverageDensity() const { return averageDensity; } -inline void DataSet3D::setAverageDensity(SPtr<AverageValuesArray3D> values) -{ - averageDensity = values; -} +inline void DataSet3D::setAverageDensity(SPtr<AverageValuesArray3D> values) { averageDensity = values; } -inline SPtr<AverageValuesArray3D> DataSet3D::getAverageVelocity() const -{ - return averageVelocity; -} +inline SPtr<AverageValuesArray3D> DataSet3D::getAverageVelocity() const { return averageVelocity; } -inline void DataSet3D::setAverageVelocity(SPtr<AverageValuesArray3D> values) -{ - averageVelocity = values; -} +inline void DataSet3D::setAverageVelocity(SPtr<AverageValuesArray3D> values) { averageVelocity = values; } -inline SPtr<AverageValuesArray3D> DataSet3D::getAverageFluctuations() const -{ - return averageFluktuations; -} +inline SPtr<AverageValuesArray3D> DataSet3D::getAverageFluctuations() const { return averageFluktuations; } -inline void DataSet3D::setAverageFluctuations(SPtr<AverageValuesArray3D> values) -{ - averageFluktuations = values; -} +inline void DataSet3D::setAverageFluctuations(SPtr<AverageValuesArray3D> values) { averageFluktuations = values; } -inline SPtr<AverageValuesArray3D> DataSet3D::getAverageTriplecorrelations() const -{ - return averageTriplecorrelations; -} +inline SPtr<AverageValuesArray3D> DataSet3D::getAverageTriplecorrelations() const { return averageTriplecorrelations; } inline void DataSet3D::setAverageTriplecorrelations(SPtr<AverageValuesArray3D> values) { - averageTriplecorrelations = values; + averageTriplecorrelations = values; } -inline SPtr<ShearStressValuesArray3D> DataSet3D::getShearStressValues() const -{ - return shearStressValues; -} +inline SPtr<ShearStressValuesArray3D> DataSet3D::getShearStressValues() const { return shearStressValues; } -inline void DataSet3D::setShearStressValues(SPtr<ShearStressValuesArray3D> values) -{ - shearStressValues = values; -} +inline void DataSet3D::setShearStressValues(SPtr<ShearStressValuesArray3D> values) { shearStressValues = values; } -inline SPtr<RelaxationFactorArray3D> DataSet3D::getRelaxationFactor() const -{ - return relaxationFactor; -} +inline SPtr<RelaxationFactorArray3D> DataSet3D::getRelaxationFactor() const { return relaxationFactor; } -inline void DataSet3D::setRelaxationFactor(SPtr<RelaxationFactorArray3D> values) -{ - relaxationFactor = values; -} +inline void DataSet3D::setRelaxationFactor(SPtr<RelaxationFactorArray3D> values) { relaxationFactor = values; } #endif diff --git a/src/cpu/VirtualFluidsCore/Data/DistributionArray3D.h b/src/cpu/VirtualFluidsCore/Data/DistributionArray3D.h index 89da1577f..593778cd0 100644 --- a/src/cpu/VirtualFluidsCore/Data/DistributionArray3D.h +++ b/src/cpu/VirtualFluidsCore/Data/DistributionArray3D.h @@ -6,26 +6,31 @@ class DistributionArray3D { public: - DistributionArray3D() = default;; - virtual ~DistributionArray3D()= default;; + DistributionArray3D() = default; + ; + virtual ~DistributionArray3D() = default; + ; + + virtual size_t getNX1() const = 0; + virtual size_t getNX2() const = 0; + virtual size_t getNX3() const = 0; + virtual void getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) = 0; + virtual void setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) = 0; + virtual void getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) = 0; + virtual void setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) = 0; + virtual void setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) = 0; + virtual void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) = 0; + virtual LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) = 0; + virtual void setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) = 0; + virtual void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) = 0; + virtual LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) = 0; + virtual void swap() = 0; - virtual size_t getNX1() const = 0; - virtual size_t getNX2() const = 0; - virtual size_t getNX3() const = 0; - virtual void getDistribution(LBMReal* const f, size_t x1, size_t x2, size_t x3) = 0; - virtual void setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) = 0; - virtual void getDistributionInv( LBMReal* const f, size_t x1, size_t x2, size_t x3) = 0; - virtual void setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) = 0; - virtual void setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) = 0; - virtual void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) = 0; - virtual LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) = 0; - virtual void setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) = 0; - virtual void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) = 0; - virtual LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) = 0; - virtual void swap() = 0; protected: private: - }; #endif diff --git a/src/cpu/VirtualFluidsCore/Data/EsoTwist3D.h b/src/cpu/VirtualFluidsCore/Data/EsoTwist3D.h index 2e0475f1d..e7d9b90de 100644 --- a/src/cpu/VirtualFluidsCore/Data/EsoTwist3D.h +++ b/src/cpu/VirtualFluidsCore/Data/EsoTwist3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,52 +38,63 @@ #include <LBMSystem.h> //! \brief Abstract class for implementation of Esoteric Twist method -//! \details EsoTwist3D provide an interface for different implementations of Esoteric Twist method -//! <a href="https://doi.org/10.3390/computation5020019"><b>[ Geier et al., (2017), 10.3390/computation5020019]</b></a> -// Geier, M., & Schönherr, M. (2017). Esoteric twist: an efficient in-place streaming algorithmus for the lattice Boltzmann method on massively parallel hardware. Computation, 5(2), 19. - +//! \details EsoTwist3D provide an interface for different implementations of Esoteric Twist method +//! <a href="https://doi.org/10.3390/computation5020019"><b>[ Geier et al., (2017), 10.3390/computation5020019]</b></a> +// Geier, M., & Schönherr, M. (2017). Esoteric twist: an efficient in-place streaming algorithmus for the lattice +// Boltzmann method on massively parallel hardware. Computation, 5(2), 19. -class EsoTwistD3Q27UnrollArray{}; -class EsoTwistPlusD3Q27UnrollArray{}; -class EsoTwistPlusD3Q19UnrollArray{}; +class EsoTwistD3Q27UnrollArray +{ +}; +class EsoTwistPlusD3Q27UnrollArray +{ +}; +class EsoTwistPlusD3Q19UnrollArray +{ +}; class EsoTwist3D : public DistributionArray3D { public: - EsoTwist3D()= default;; - ~EsoTwist3D() override= default;; - ////////////////////////////////////////////////////////////////////////// - void swap() override = 0; - ////////////////////////////////////////////////////////////////////////// - void getDistribution(LBMReal* const f, size_t x1, size_t x2, size_t x3) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override = 0; - //////////////////////////////////////////////////////////////////////// - void getDistributionInv( LBMReal* const f, size_t x1, size_t x2, size_t x3) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - //virtual void getDistributionInvForDirection(LBMReal* const& f, const size_t& x1, const size_t& x2, const size_t& x3, const unsigned long int& direction) = 0; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override = 0; - ////////////////////////////////////////////////////////////////////////// - size_t getNX1() const override = 0; - ////////////////////////////////////////////////////////////////////////// - size_t getNX2() const override = 0; - ////////////////////////////////////////////////////////////////////////// - size_t getNX3() const override = 0; - ////////////////////////////////////////////////////////////////////////// - + EsoTwist3D() = default; + ; + ~EsoTwist3D() override = default; + ; + ////////////////////////////////////////////////////////////////////////// + void swap() override = 0; + ////////////////////////////////////////////////////////////////////////// + void getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override = 0; + //////////////////////////////////////////////////////////////////////// + void getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + // virtual void getDistributionInvForDirection(LBMReal* const& f, const size_t& x1, const size_t& x2, const size_t& + // x3, const unsigned long int& direction) = 0; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionInvForDirection(size_t x1, size_t x2, size_t x3, int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + LBMReal getDistributionForDirection(size_t x1, size_t x2, size_t x3, int direction) override = 0; + ////////////////////////////////////////////////////////////////////////// + size_t getNX1() const override = 0; + ////////////////////////////////////////////////////////////////////////// + size_t getNX2() const override = 0; + ////////////////////////////////////////////////////////////////////////// + size_t getNX3() const override = 0; + ////////////////////////////////////////////////////////////////////////// }; #endif diff --git a/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.cpp b/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.cpp index 64fa72bd0..1a13aa008 100644 --- a/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.cpp +++ b/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,93 +33,54 @@ #include "EsoTwistD3Q27System.h" -//index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 -//f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW ZERO -const int EsoTwistD3Q27System::ETX1[EsoTwistD3Q27System::ENDF+1] = { 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; -const int EsoTwistD3Q27System::ETX2[EsoTwistD3Q27System::ENDF+1] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1, 0, 1, 0, -1, 0, 1, 0 }; -const int EsoTwistD3Q27System::ETX3[EsoTwistD3Q27System::ENDF+1] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, 0, 1, 1, 0, 0, -1, 0, -1, 0, 1, 0, 1, 0 }; - -const int EsoTwistD3Q27System::etINVDIR[EsoTwistD3Q27System::ENDF+1] = { D3Q27System::INV_E, - D3Q27System::INV_W, - D3Q27System::INV_N, - D3Q27System::INV_S, - D3Q27System::INV_T, - D3Q27System::INV_B, - D3Q27System::INV_NE, - D3Q27System::INV_SW, - D3Q27System::INV_SE, - D3Q27System::INV_NW, - D3Q27System::INV_TE, - D3Q27System::INV_BW, - D3Q27System::INV_BE, - D3Q27System::INV_TW, - D3Q27System::INV_TN, - D3Q27System::INV_BS, - D3Q27System::INV_BN, - D3Q27System::INV_TS, - D3Q27System::INV_TNE, - D3Q27System::INV_TNW, - D3Q27System::INV_TSE, - D3Q27System::INV_TSW, - D3Q27System::INV_BNE, - D3Q27System::INV_BNW, - D3Q27System::INV_BSE, - D3Q27System::INV_BSW, - D3Q27System::ZERO}; +// index 0 1 2 3 4 5 6 7 8 9 10 11 12 +// 13 14 15 16 17 18 19 20 21 22 23 24 25 26 f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, +// BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW ZERO +const int EsoTwistD3Q27System::ETX1[EsoTwistD3Q27System::ENDF + 1] = { 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, + 0, 0, 0, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0 }; +const int EsoTwistD3Q27System::ETX2[EsoTwistD3Q27System::ENDF + 1] = { 0, 0, 0, 1, 0, 0, 0, 1, 0, -1, 0, 0, 0, 0, + 0, 1, -1, 0, 0, -1, 0, 1, 0, -1, 0, 1, 0 }; +const int EsoTwistD3Q27System::ETX3[EsoTwistD3Q27System::ENDF + 1] = { 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 1, 0, -1, + 0, 1, 1, 0, 0, -1, 0, -1, 0, 1, 0, 1, 0 }; -const unsigned long int EsoTwistD3Q27System::etDIR[EsoTwistD3Q27System::ENDF+1] = { etE, - etW, - etN, - etS, - etT, - etB, - etNE, - etSW, - etSE, - etNW, - etTE, - etBW, - etBE, - etTW, - etTN, - etBS, - etBN, - etTS, - etTNE, - etTNW, - etTSE, - etTSW, - etBNE, - etBNW, - etBSE, - etBSW, - etZERO}; +const int EsoTwistD3Q27System::etINVDIR[EsoTwistD3Q27System::ENDF + 1] = { + D3Q27System::INV_E, D3Q27System::INV_W, D3Q27System::INV_N, D3Q27System::INV_S, D3Q27System::INV_T, + D3Q27System::INV_B, D3Q27System::INV_NE, D3Q27System::INV_SW, D3Q27System::INV_SE, D3Q27System::INV_NW, + D3Q27System::INV_TE, D3Q27System::INV_BW, D3Q27System::INV_BE, D3Q27System::INV_TW, D3Q27System::INV_TN, + D3Q27System::INV_BS, D3Q27System::INV_BN, D3Q27System::INV_TS, D3Q27System::INV_TNE, D3Q27System::INV_TNW, + D3Q27System::INV_TSE, D3Q27System::INV_TSW, D3Q27System::INV_BNE, D3Q27System::INV_BNW, D3Q27System::INV_BSE, + D3Q27System::INV_BSW, D3Q27System::ZERO +}; - const unsigned long int EsoTwistD3Q27System::etZERO = 1;/*f0 */ - const unsigned long int EsoTwistD3Q27System::etE = 2; /*f1 */ - const unsigned long int EsoTwistD3Q27System::etW = 4; /*f2 */ - const unsigned long int EsoTwistD3Q27System::etN = 8; /*f3 */ - const unsigned long int EsoTwistD3Q27System::etS = 16; /*f4 */ - const unsigned long int EsoTwistD3Q27System::etT = 32; /*f5 */ - const unsigned long int EsoTwistD3Q27System::etB = 64; /*f6 */ - const unsigned long int EsoTwistD3Q27System::etNE = 128; /*f7 */ - const unsigned long int EsoTwistD3Q27System::etSW = 256; /*f8 */ - const unsigned long int EsoTwistD3Q27System::etSE = 512; /*f9 */ - const unsigned long int EsoTwistD3Q27System::etNW = 1024; /*f10*/ - const unsigned long int EsoTwistD3Q27System::etTE = 2048; /*f11*/ - const unsigned long int EsoTwistD3Q27System::etBW = 4096; /*f12*/ - const unsigned long int EsoTwistD3Q27System::etBE = 8192; /*f13*/ - const unsigned long int EsoTwistD3Q27System::etTW = 16384; /*f14*/ - const unsigned long int EsoTwistD3Q27System::etTN = 32768; /*f15*/ - const unsigned long int EsoTwistD3Q27System::etBS = 65536; /*f16*/ - const unsigned long int EsoTwistD3Q27System::etBN = 131072; /*f17*/ - const unsigned long int EsoTwistD3Q27System::etTS = 262144; /*f18*/ - const unsigned long int EsoTwistD3Q27System::etTNE = 524288; - const unsigned long int EsoTwistD3Q27System::etTNW = 1048576; - const unsigned long int EsoTwistD3Q27System::etTSE = 2097152; - const unsigned long int EsoTwistD3Q27System::etTSW = 4194304; - const unsigned long int EsoTwistD3Q27System::etBNE = 8388608; - const unsigned long int EsoTwistD3Q27System::etBNW = 16777216; - const unsigned long int EsoTwistD3Q27System::etBSE = 33554432; -const unsigned long int EsoTwistD3Q27System::etBSW = 67108864; +const unsigned long int EsoTwistD3Q27System::etDIR[EsoTwistD3Q27System::ENDF + 1] = { + etE, etW, etN, etS, etT, etB, etNE, etSW, etSE, etNW, etTE, etBW, etBE, etTW, + etTN, etBS, etBN, etTS, etTNE, etTNW, etTSE, etTSW, etBNE, etBNW, etBSE, etBSW, etZERO +}; +const unsigned long int EsoTwistD3Q27System::etZERO = 1; /*f0 */ +const unsigned long int EsoTwistD3Q27System::etE = 2; /*f1 */ +const unsigned long int EsoTwistD3Q27System::etW = 4; /*f2 */ +const unsigned long int EsoTwistD3Q27System::etN = 8; /*f3 */ +const unsigned long int EsoTwistD3Q27System::etS = 16; /*f4 */ +const unsigned long int EsoTwistD3Q27System::etT = 32; /*f5 */ +const unsigned long int EsoTwistD3Q27System::etB = 64; /*f6 */ +const unsigned long int EsoTwistD3Q27System::etNE = 128; /*f7 */ +const unsigned long int EsoTwistD3Q27System::etSW = 256; /*f8 */ +const unsigned long int EsoTwistD3Q27System::etSE = 512; /*f9 */ +const unsigned long int EsoTwistD3Q27System::etNW = 1024; /*f10*/ +const unsigned long int EsoTwistD3Q27System::etTE = 2048; /*f11*/ +const unsigned long int EsoTwistD3Q27System::etBW = 4096; /*f12*/ +const unsigned long int EsoTwistD3Q27System::etBE = 8192; /*f13*/ +const unsigned long int EsoTwistD3Q27System::etTW = 16384; /*f14*/ +const unsigned long int EsoTwistD3Q27System::etTN = 32768; /*f15*/ +const unsigned long int EsoTwistD3Q27System::etBS = 65536; /*f16*/ +const unsigned long int EsoTwistD3Q27System::etBN = 131072; /*f17*/ +const unsigned long int EsoTwistD3Q27System::etTS = 262144; /*f18*/ +const unsigned long int EsoTwistD3Q27System::etTNE = 524288; +const unsigned long int EsoTwistD3Q27System::etTNW = 1048576; +const unsigned long int EsoTwistD3Q27System::etTSE = 2097152; +const unsigned long int EsoTwistD3Q27System::etTSW = 4194304; +const unsigned long int EsoTwistD3Q27System::etBNE = 8388608; +const unsigned long int EsoTwistD3Q27System::etBNW = 16777216; +const unsigned long int EsoTwistD3Q27System::etBSE = 33554432; +const unsigned long int EsoTwistD3Q27System::etBSW = 67108864; diff --git a/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.h b/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.h index 2c21e65ac..a9214673e 100644 --- a/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.h +++ b/src/cpu/VirtualFluidsCore/Data/EsoTwistD3Q27System.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,107 +36,105 @@ #include "D3Q27System.h" -//! -struct EsoTwistD3Q27System -{ - const static int FSTARTDIR = D3Q27System::FSTARTDIR; - const static int FENDDIR = D3Q27System::FENDDIR; //gellerstyle: meint alle frichtungen OHNE f0 +//! +struct EsoTwistD3Q27System { + const static int FSTARTDIR = D3Q27System::FSTARTDIR; + const static int FENDDIR = D3Q27System::FENDDIR; // gellerstyle: meint alle frichtungen OHNE f0 - const static int STARTF = D3Q27System::STARTF; - const static int ENDF = D3Q27System::ENDF; + const static int STARTF = D3Q27System::STARTF; + const static int ENDF = D3Q27System::ENDF; - const static int STARTDIR = D3Q27System::STARTDIR; - const static int ENDDIR = D3Q27System::ENDDIR; + const static int STARTDIR = D3Q27System::STARTDIR; + const static int ENDDIR = D3Q27System::ENDDIR; - static const int ZERO = D3Q27System::ZERO;/*f0 */ - static const int E = D3Q27System::E; /*f1 */ - static const int W = D3Q27System::W; /*f2 */ - static const int N = D3Q27System::N; /*f3 */ - static const int S = D3Q27System::S; /*f4 */ - static const int T = D3Q27System::T; /*f5 */ - static const int B = D3Q27System::B; /*f6 */ - static const int NE = D3Q27System::NE; /*f7 */ - static const int SW = D3Q27System::SW; /*f8 */ - static const int SE = D3Q27System::SE; /*f9 */ - static const int NW = D3Q27System::NW; /*f10*/ - static const int TE = D3Q27System::TE; /*f11*/ - static const int BW = D3Q27System::BW; /*f12*/ - static const int BE = D3Q27System::BE; /*f13*/ - static const int TW = D3Q27System::TW; /*f14*/ - static const int TN = D3Q27System::TN; /*f15*/ - static const int BS = D3Q27System::BS; /*f16*/ - static const int BN = D3Q27System::BN; /*f17*/ - static const int TS = D3Q27System::TS; /*f18*/ - static const int TNE = D3Q27System::TNE; - static const int TNW = D3Q27System::TNW; - static const int TSE = D3Q27System::TSE; - static const int TSW = D3Q27System::TSW; - static const int BNE = D3Q27System::BNE; - static const int BNW = D3Q27System::BNW; - static const int BSE = D3Q27System::BSE; - static const int BSW = D3Q27System::BSW; - + static const int ZERO = D3Q27System::ZERO; /*f0 */ + static const int E = D3Q27System::E; /*f1 */ + static const int W = D3Q27System::W; /*f2 */ + static const int N = D3Q27System::N; /*f3 */ + static const int S = D3Q27System::S; /*f4 */ + static const int T = D3Q27System::T; /*f5 */ + static const int B = D3Q27System::B; /*f6 */ + static const int NE = D3Q27System::NE; /*f7 */ + static const int SW = D3Q27System::SW; /*f8 */ + static const int SE = D3Q27System::SE; /*f9 */ + static const int NW = D3Q27System::NW; /*f10*/ + static const int TE = D3Q27System::TE; /*f11*/ + static const int BW = D3Q27System::BW; /*f12*/ + static const int BE = D3Q27System::BE; /*f13*/ + static const int TW = D3Q27System::TW; /*f14*/ + static const int TN = D3Q27System::TN; /*f15*/ + static const int BS = D3Q27System::BS; /*f16*/ + static const int BN = D3Q27System::BN; /*f17*/ + static const int TS = D3Q27System::TS; /*f18*/ + static const int TNE = D3Q27System::TNE; + static const int TNW = D3Q27System::TNW; + static const int TSE = D3Q27System::TSE; + static const int TSW = D3Q27System::TSW; + static const int BNE = D3Q27System::BNE; + static const int BNW = D3Q27System::BNW; + static const int BSE = D3Q27System::BSE; + static const int BSW = D3Q27System::BSW; - static const int INV_E = D3Q27System::W; - static const int INV_W = D3Q27System::E; - static const int INV_N = D3Q27System::S; - static const int INV_S = D3Q27System::N; - static const int INV_T = D3Q27System::B; - static const int INV_B = D3Q27System::T; - static const int INV_NE = D3Q27System::SW; - static const int INV_SW = D3Q27System::NE; - static const int INV_SE = D3Q27System::NW; - static const int INV_NW = D3Q27System::SE; - static const int INV_TE = D3Q27System::BW; - static const int INV_BW = D3Q27System::TE; - static const int INV_BE = D3Q27System::TW; - static const int INV_TW = D3Q27System::BE; - static const int INV_TN = D3Q27System::BS; - static const int INV_BS = D3Q27System::TN; - static const int INV_BN = D3Q27System::TS; - static const int INV_TS = D3Q27System::BN; - static const int INV_TNE = D3Q27System::BSW; - static const int INV_TNW = D3Q27System::BSE; - static const int INV_TSE = D3Q27System::BNW; - static const int INV_TSW = D3Q27System::BNE; - static const int INV_BNE = D3Q27System::TSW; - static const int INV_BNW = D3Q27System::TSE; - static const int INV_BSE = D3Q27System::TNW; - static const int INV_BSW = D3Q27System::TNE; + static const int INV_E = D3Q27System::W; + static const int INV_W = D3Q27System::E; + static const int INV_N = D3Q27System::S; + static const int INV_S = D3Q27System::N; + static const int INV_T = D3Q27System::B; + static const int INV_B = D3Q27System::T; + static const int INV_NE = D3Q27System::SW; + static const int INV_SW = D3Q27System::NE; + static const int INV_SE = D3Q27System::NW; + static const int INV_NW = D3Q27System::SE; + static const int INV_TE = D3Q27System::BW; + static const int INV_BW = D3Q27System::TE; + static const int INV_BE = D3Q27System::TW; + static const int INV_TW = D3Q27System::BE; + static const int INV_TN = D3Q27System::BS; + static const int INV_BS = D3Q27System::TN; + static const int INV_BN = D3Q27System::TS; + static const int INV_TS = D3Q27System::BN; + static const int INV_TNE = D3Q27System::BSW; + static const int INV_TNW = D3Q27System::BSE; + static const int INV_TSE = D3Q27System::BNW; + static const int INV_TSW = D3Q27System::BNE; + static const int INV_BNE = D3Q27System::TSW; + static const int INV_BNW = D3Q27System::TSE; + static const int INV_BSE = D3Q27System::TNW; + static const int INV_BSW = D3Q27System::TNE; - static const unsigned long int etZERO;// 1;/*f0 */ - static const unsigned long int etE;// 2; /*f1 */ - static const unsigned long int etW;// 4; /*f2 */ - static const unsigned long int etN;// 8; /*f3 */ - static const unsigned long int etS;// 16; /*f4 */ - static const unsigned long int etT;// 32; /*f5 */ - static const unsigned long int etB;// 64; /*f6 */ - static const unsigned long int etNE;// 128; /*f7 */ - static const unsigned long int etSW;// 256; /*f8 */ - static const unsigned long int etSE;// 512; /*f9 */ - static const unsigned long int etNW;// 1024; /*f10*/ - static const unsigned long int etTE;// 2048; /*f11*/ - static const unsigned long int etBW;// 4096; /*f12*/ - static const unsigned long int etBE;// 8192; /*f13*/ - static const unsigned long int etTW;// 16384; /*f14*/ - static const unsigned long int etTN;// 32768; /*f15*/ - static const unsigned long int etBS;// 65536; /*f16*/ - static const unsigned long int etBN;// 131072; /*f17*/ - static const unsigned long int etTS;// 262144; /*f18*/ - static const unsigned long int etTNE;// 524288; - static const unsigned long int etTNW;// 1048576; - static const unsigned long int etTSE;// 2097152; - static const unsigned long int etTSW;// 4194304; - static const unsigned long int etBNE;// 8388608; - static const unsigned long int etBNW;// 16777216; - static const unsigned long int etBSE;// 33554432; - static const unsigned long int etBSW;// = 67108864; + static const unsigned long int etZERO; // 1;/*f0 */ + static const unsigned long int etE; // 2; /*f1 */ + static const unsigned long int etW; // 4; /*f2 */ + static const unsigned long int etN; // 8; /*f3 */ + static const unsigned long int etS; // 16; /*f4 */ + static const unsigned long int etT; // 32; /*f5 */ + static const unsigned long int etB; // 64; /*f6 */ + static const unsigned long int etNE; // 128; /*f7 */ + static const unsigned long int etSW; // 256; /*f8 */ + static const unsigned long int etSE; // 512; /*f9 */ + static const unsigned long int etNW; // 1024; /*f10*/ + static const unsigned long int etTE; // 2048; /*f11*/ + static const unsigned long int etBW; // 4096; /*f12*/ + static const unsigned long int etBE; // 8192; /*f13*/ + static const unsigned long int etTW; // 16384; /*f14*/ + static const unsigned long int etTN; // 32768; /*f15*/ + static const unsigned long int etBS; // 65536; /*f16*/ + static const unsigned long int etBN; // 131072; /*f17*/ + static const unsigned long int etTS; // 262144; /*f18*/ + static const unsigned long int etTNE; // 524288; + static const unsigned long int etTNW; // 1048576; + static const unsigned long int etTSE; // 2097152; + static const unsigned long int etTSW; // 4194304; + static const unsigned long int etBNE; // 8388608; + static const unsigned long int etBNW; // 16777216; + static const unsigned long int etBSE; // 33554432; + static const unsigned long int etBSW; // = 67108864; - const static int ETX1[ENDF+1]; - const static int ETX2[ENDF+1]; - const static int ETX3[ENDF+1]; - const static int etINVDIR[ENDF+1]; - const static unsigned long int etDIR[ENDF+1]; + const static int ETX1[ENDF + 1]; + const static int ETX2[ENDF + 1]; + const static int ETX3[ENDF + 1]; + const static int etINVDIR[ENDF + 1]; + const static unsigned long int etDIR[ENDF + 1]; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Data/VoidData3D.h b/src/cpu/VirtualFluidsCore/Data/VoidData3D.h index b4a9b2ff6..bab8eca0d 100644 --- a/src/cpu/VirtualFluidsCore/Data/VoidData3D.h +++ b/src/cpu/VirtualFluidsCore/Data/VoidData3D.h @@ -3,35 +3,52 @@ #include "EsoTwist3D.h" - class VoidData3D : public EsoTwist3D { public: - VoidData3D() = default;; - VoidData3D (size_t nx1, size_t nx2, size_t nx3, LBMReal /*value*/) - { - this->NX1 = nx1; - this->NX2 = nx2; - this->NX3 = nx3; - } - ~VoidData3D() override = default;; - size_t getNX1() const override { return NX1;} - size_t getNX2() const override { return NX2;} - size_t getNX3() const override { return NX3;} - void getDistribution(LBMReal* const f, size_t x1, size_t x2, size_t x3) override {} - void setDistribution(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override{} - void getDistributionInv(LBMReal* const f, size_t x1, size_t x2, size_t x3) override {} - void setDistributionInv(const LBMReal* const f, size_t x1, size_t x2, size_t x3) override {} - void setDistributionForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override {} + VoidData3D() = default; + ; + VoidData3D(size_t nx1, size_t nx2, size_t nx3, LBMReal /*value*/) + { + this->NX1 = nx1; + this->NX2 = nx2; + this->NX3 = nx3; + } + ~VoidData3D() override = default; + ; + size_t getNX1() const override { return NX1; } + size_t getNX2() const override { return NX2; } + size_t getNX3() const override { return NX3; } + void getDistribution(LBMReal *const f, size_t x1, size_t x2, size_t x3) override {} + void setDistribution(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override {} + void getDistributionInv(LBMReal *const f, size_t x1, size_t x2, size_t x3) override {} + void setDistributionInv(const LBMReal *const f, size_t x1, size_t x2, size_t x3) override {} + void setDistributionForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override + { + } void setDistributionForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, int direction) override {} - LBMReal getDistributionInvForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, int /*direction*/) override {return 0.0;} - void setDistributionInvForDirection(const LBMReal* const f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override {} - void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, unsigned long int direction) override {} - LBMReal getDistributionForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, int /*direction*/) override {return 0.0;} + LBMReal getDistributionInvForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, int /*direction*/) override + { + return 0.0; + } + void setDistributionInvForDirection(const LBMReal *const f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override + { + } + void setDistributionInvForDirection(LBMReal f, size_t x1, size_t x2, size_t x3, + unsigned long int direction) override + { + } + LBMReal getDistributionForDirection(size_t /*x1*/, size_t /*x2*/, size_t /*x3*/, int /*direction*/) override + { + return 0.0; + } void swap() override {} + protected: private: - size_t NX1, NX2, NX3; + size_t NX1, NX2, NX3; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.cpp b/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.cpp index 55c35a9cd..362225638 100644 --- a/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.cpp +++ b/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,12 +33,12 @@ #include "BasicCalculator.h" -#include "Block3D.h" #include "BCProcessor.h" -#include "LBMKernel.h" +#include "Block3D.h" #include "Block3DConnector.h" -#include "UbScheduler.h" +#include "LBMKernel.h" #include "UbLogger.h" +#include "UbScheduler.h" #ifdef _OPENMP #include <omp.h> @@ -48,136 +48,126 @@ //#define TIMING //#include "UbTiming.h" -BasicCalculator::BasicCalculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps) : - Calculator(grid, additionalGhostLayerUpdateScheduler, numberOfTimeSteps) +BasicCalculator::BasicCalculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, + int numberOfTimeSteps) + : Calculator(grid, additionalGhostLayerUpdateScheduler, numberOfTimeSteps) { - } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::calculate() { - UBLOG(logDEBUG1, "OMPCalculator::calculate() - started"); - int calcStep = 0; - try - { - int minInitLevel = minLevel; - int maxInitLevel = maxLevel - minLevel; - int straightStartLevel = minInitLevel; - int internalIterations = 1 << (maxInitLevel - minInitLevel); -// int forwardStartLevel; - int threshold; + UBLOG(logDEBUG1, "OMPCalculator::calculate() - started"); + int calcStep = 0; + try { + int minInitLevel = minLevel; + int maxInitLevel = maxLevel - minLevel; + int straightStartLevel = minInitLevel; + int internalIterations = 1 << (maxInitLevel - minInitLevel); + // int forwardStartLevel; + int threshold; #ifdef TIMING - UbTimer timer; - double time[6]; + UbTimer timer; + double time[6]; #endif - for (calcStep = startTimeStep; calcStep <= numberOfTimeSteps; calcStep++) - { - ////////////////////////////////////////////////////////////////////////// + for (calcStep = startTimeStep; calcStep <= numberOfTimeSteps; calcStep++) { + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - UBLOG(logINFO, "calcStep = " << calcStep); + UBLOG(logINFO, "calcStep = " << calcStep); #endif - ////////////////////////////////////////////////////////////////////////// - - for (int staggeredStep = 1; staggeredStep <= internalIterations; staggeredStep++) - { -// forwardStartLevel = straightStartLevel; - if (staggeredStep == internalIterations) straightStartLevel = minInitLevel; - else - { - for (straightStartLevel = maxInitLevel, threshold = 1; - (staggeredStep & threshold) != threshold; straightStartLevel--, threshold <<= 1); - } ////////////////////////////////////////////////////////////////////////// + + for (int staggeredStep = 1; staggeredStep <= internalIterations; staggeredStep++) { + // forwardStartLevel = straightStartLevel; + if (staggeredStep == internalIterations) + straightStartLevel = minInitLevel; + else { + for (straightStartLevel = maxInitLevel, threshold = 1; (staggeredStep & threshold) != threshold; + straightStartLevel--, threshold <<= 1) + ; + } + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - timer.resetAndStart(); + timer.resetAndStart(); #endif - ////////////////////////////////////////////////////////////////////////// - applyPreCollisionBC(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// + applyPreCollisionBC(straightStartLevel, maxInitLevel); - //do collision for all blocks - calculateBlocks(straightStartLevel, maxInitLevel, calcStep); - ////////////////////////////////////////////////////////////////////////// + // do collision for all blocks + calculateBlocks(straightStartLevel, maxInitLevel, calcStep); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[0] = timer.stop(); - UBLOG(logINFO, "calculateBlocks time = " << time[0]); + time[0] = timer.stop(); + UBLOG(logINFO, "calculateBlocks time = " << time[0]); #endif - ////////////////////////////////////////////////////////////////////////// - ////////////////////////////////////////////////////////////////////////// - //exchange data between blocks - exchangeBlockData(straightStartLevel, maxInitLevel); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // exchange data between blocks + exchangeBlockData(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[1] = timer.stop(); - UBLOG(logINFO, "exchangeBlockData time = " << time[1]); + time[1] = timer.stop(); + UBLOG(logINFO, "exchangeBlockData time = " << time[1]); #endif - ////////////////////////////////////////////////////////////////////////// - applyPostCollisionBC(straightStartLevel, maxInitLevel); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + applyPostCollisionBC(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[2] = timer.stop(); - UBLOG(logINFO, "applyBCs time = " << time[2]); + time[2] = timer.stop(); + UBLOG(logINFO, "applyBCs time = " << time[2]); #endif - ////////////////////////////////////////////////////////////////////////// - //swap distributions in kernel - swapDistributions(straightStartLevel, maxInitLevel); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // swap distributions in kernel + swapDistributions(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[3] = timer.stop(); - UBLOG(logINFO, "swapDistributions time = " << time[3]); + time[3] = timer.stop(); + UBLOG(logINFO, "swapDistributions time = " << time[3]); #endif - ////////////////////////////////////////////////////////////////////////// - if (refinement) - { - if (straightStartLevel < maxInitLevel) - exchangeBlockData(straightStartLevel, maxInitLevel); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + if (refinement) { + if (straightStartLevel < maxInitLevel) + exchangeBlockData(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[4] = timer.stop(); - UBLOG(logINFO, "refinement exchangeBlockData time = " << time[4]); + time[4] = timer.stop(); + UBLOG(logINFO, "refinement exchangeBlockData time = " << time[4]); #endif - ////////////////////////////////////////////////////////////////////////// - //now ghost nodes have actual values - //interpolation of interface nodes between grid levels - interpolation(straightStartLevel, maxInitLevel); - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // now ghost nodes have actual values + // interpolation of interface nodes between grid levels + interpolation(straightStartLevel, maxInitLevel); + ////////////////////////////////////////////////////////////////////////// #ifdef TIMING - time[5] = timer.stop(); - UBLOG(logINFO, "refinement interpolation time = " << time[5]); + time[5] = timer.stop(); + UBLOG(logINFO, "refinement interpolation time = " << time[5]); #endif - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + } } - } - //exchange data between blocks for visualization - if (additionalGhostLayerUpdateScheduler->isDue(calcStep)) - { - exchangeBlockData(straightStartLevel, maxInitLevel); - } - coProcess((double)(calcStep)); - //now ghost nodes have actual values - } - UBLOG(logDEBUG1, "OMPCalculator::calculate() - stoped"); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - UBLOG(logERROR, " step = " << calcStep); - //throw e; - //exit(EXIT_FAILURE); - } - catch (std::string & s) - { - UBLOG(logERROR, s); - //exit(EXIT_FAILURE); - //throw s; - } - catch (...) - { - UBLOG(logERROR, "unknown exception"); - //exit(EXIT_FAILURE); - //throw; - } + // exchange data between blocks for visualization + if (additionalGhostLayerUpdateScheduler->isDue(calcStep)) { + exchangeBlockData(straightStartLevel, maxInitLevel); + } + coProcess((double)(calcStep)); + // now ghost nodes have actual values + } + UBLOG(logDEBUG1, "OMPCalculator::calculate() - stoped"); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + UBLOG(logERROR, " step = " << calcStep); + // throw e; + // exit(EXIT_FAILURE); + } catch (std::string &s) { + UBLOG(logERROR, s); + // exit(EXIT_FAILURE); + // throw s; + } catch (...) { + UBLOG(logERROR, "unknown exception"); + // exit(EXIT_FAILURE); + // throw; + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::calculateBlocks(int startLevel, int maxInitLevel, int calcStep) @@ -185,50 +175,45 @@ void BasicCalculator::calculateBlocks(int startLevel, int maxInitLevel, int calc #ifdef _OPENMP #pragma omp parallel #endif - { - SPtr<Block3D> blockTemp; - //startLevel bis maxInitLevel - for (int level = startLevel; level <= maxInitLevel; level++) - { - //timer.resetAndStart(); - //call LBM kernel - int size = (int)blocks[level].size(); + { + SPtr<Block3D> blockTemp; + // startLevel bis maxInitLevel + for (int level = startLevel; level <= maxInitLevel; level++) { + // timer.resetAndStart(); + // call LBM kernel + int size = (int)blocks[level].size(); #ifdef _OPENMP #pragma omp for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - try - { - blockTemp = blocks[level][i]; - blockTemp->getKernel()->calculate(calcStep); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - UBLOG(logERROR, blockTemp->toString() << " step = " << calcStep); - std::exit(EXIT_FAILURE); + for (int i = 0; i < size; i++) { + try { + blockTemp = blocks[level][i]; + blockTemp->getKernel()->calculate(calcStep); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + UBLOG(logERROR, blockTemp->toString() << " step = " << calcStep); + std::exit(EXIT_FAILURE); + } } - } - //timer.stop(); - //UBLOG(logINFO, "level = " << level << " blocks = " << blocks[level].size() << " collision time = " << timer.getTotalTime()); - } - } + // timer.stop(); + // UBLOG(logINFO, "level = " << level << " blocks = " << blocks[level].size() << " collision time = " << + // timer.getTotalTime()); + } + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::exchangeBlockData(int startLevel, int maxInitLevel) { - //startLevel bis maxInitLevel - for (int level = startLevel; level <= maxInitLevel; level++) - { - //connectorsPrepareLocal(localConns[level]); - connectorsSendLocal(localConns[level]); - //connectorsReceiveLocal(localConns[level]); + // startLevel bis maxInitLevel + for (int level = startLevel; level <= maxInitLevel; level++) { + // connectorsPrepareLocal(localConns[level]); + connectorsSendLocal(localConns[level]); + // connectorsReceiveLocal(localConns[level]); - connectorsPrepareRemote(remoteConns[level]); - connectorsSendRemote(remoteConns[level]); - connectorsReceiveRemote(remoteConns[level]); - } + connectorsPrepareRemote(remoteConns[level]); + connectorsSendRemote(remoteConns[level]); + connectorsReceiveRemote(remoteConns[level]); + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::swapDistributions(int startLevel, int maxInitLevel) @@ -236,192 +221,156 @@ void BasicCalculator::swapDistributions(int startLevel, int maxInitLevel) #ifdef _OPENMP #pragma omp parallel #endif - { - //startLevel bis maxInitLevel - for (int level = startLevel; level <= maxInitLevel; level++) - { - int size = (int)blocks[level].size(); + { + // startLevel bis maxInitLevel + for (int level = startLevel; level <= maxInitLevel; level++) { + int size = (int)blocks[level].size(); #ifdef _OPENMP #pragma omp for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - blocks[level][i]->getKernel()->swapDistributions(); - } - } - } + for (int i = 0; i < size; i++) { + blocks[level][i]->getKernel()->swapDistributions(); + } + } + } } ////////////////////////////////////////////////////////////////////////// -void BasicCalculator::connectorsPrepareLocal(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsPrepareLocal(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); + int size = (int)connectors.size(); #ifdef _OPENMP #pragma omp parallel for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - try - { - connectors[i]->prepareForReceive(); - connectors[i]->prepareForSend(); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - std::exit(EXIT_FAILURE); - } - } + for (int i = 0; i < size; i++) { + try { + connectors[i]->prepareForReceive(); + connectors[i]->prepareForSend(); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + std::exit(EXIT_FAILURE); + } + } } ////////////////////////////////////////////////////////////////////////// -void BasicCalculator::connectorsSendLocal(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsSendLocal(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); + int size = (int)connectors.size(); #ifdef _OPENMP #pragma omp parallel for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - try - { - connectors[i]->fillSendVectors(); - connectors[i]->sendVectors(); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - std::exit(EXIT_FAILURE); - } - } + for (int i = 0; i < size; i++) { + try { + connectors[i]->fillSendVectors(); + connectors[i]->sendVectors(); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + std::exit(EXIT_FAILURE); + } + } } ////////////////////////////////////////////////////////////////////////// -void BasicCalculator::connectorsReceiveLocal(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsReceiveLocal(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); + int size = (int)connectors.size(); #ifdef _OPENMP #pragma omp parallel for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - connectors[i]->receiveVectors(); - connectors[i]->distributeReceiveVectors(); - } + for (int i = 0; i < size; i++) { + connectors[i]->receiveVectors(); + connectors[i]->distributeReceiveVectors(); + } } -void BasicCalculator::connectorsPrepareRemote(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsPrepareRemote(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); - for (int i = 0; i < size; i++) - { - connectors[i]->prepareForReceive(); - connectors[i]->prepareForSend(); - } + int size = (int)connectors.size(); + for (int i = 0; i < size; i++) { + connectors[i]->prepareForReceive(); + connectors[i]->prepareForSend(); + } } ////////////////////////////////////////////////////////////////////////// -void BasicCalculator::connectorsSendRemote(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsSendRemote(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); - for (int i = 0; i < size; i++) - { - connectors[i]->fillSendVectors(); - connectors[i]->sendVectors(); - } + int size = (int)connectors.size(); + for (int i = 0; i < size; i++) { + connectors[i]->fillSendVectors(); + connectors[i]->sendVectors(); + } } ////////////////////////////////////////////////////////////////////////// -void BasicCalculator::connectorsReceiveRemote(std::vector< SPtr<Block3DConnector> >& connectors) +void BasicCalculator::connectorsReceiveRemote(std::vector<SPtr<Block3DConnector>> &connectors) { - int size = (int)connectors.size(); - for (int i = 0; i < size; i++) - { - connectors[i]->receiveVectors(); - connectors[i]->distributeReceiveVectors(); - } + int size = (int)connectors.size(); + for (int i = 0; i < size; i++) { + connectors[i]->receiveVectors(); + connectors[i]->distributeReceiveVectors(); + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::interpolation(int startLevel, int maxInitLevel) { - for (int level = startLevel; level < maxInitLevel; level++) - { - connectorsPrepareLocal(localInterConns[level]); - connectorsPrepareRemote(remoteInterConns[level]); - } + for (int level = startLevel; level < maxInitLevel; level++) { + connectorsPrepareLocal(localInterConns[level]); + connectorsPrepareRemote(remoteInterConns[level]); + } - for (int level = startLevel; level < maxInitLevel; level++) - { - connectorsSendLocal(localInterConns[level]); - connectorsSendRemote(remoteInterConns[level]); - } + for (int level = startLevel; level < maxInitLevel; level++) { + connectorsSendLocal(localInterConns[level]); + connectorsSendRemote(remoteInterConns[level]); + } - for (int level = startLevel; level < maxInitLevel; level++) - { - connectorsReceiveLocal(localInterConns[level]); - connectorsReceiveRemote(remoteInterConns[level]); - } + for (int level = startLevel; level < maxInitLevel; level++) { + connectorsReceiveLocal(localInterConns[level]); + connectorsReceiveRemote(remoteInterConns[level]); + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::applyPreCollisionBC(int startLevel, int maxInitLevel) { - //startLevel bis maxInitLevel - for (int level = startLevel; level <= maxInitLevel; level++) - { - int size = (int)blocks[level].size(); + // startLevel bis maxInitLevel + for (int level = startLevel; level <= maxInitLevel; level++) { + int size = (int)blocks[level].size(); #ifdef _OPENMP #pragma omp parallel for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - try - { - blocks[level][i]->getKernel()->getBCProcessor()->applyPreCollisionBC(); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - exit(EXIT_FAILURE); - } - catch (std::string & s) - { - UBLOG(logERROR, s); - exit(EXIT_FAILURE); - } - catch (...) - { - UBLOG(logERROR, "unknown exception"); - exit(EXIT_FAILURE); - } - } - } + for (int i = 0; i < size; i++) { + try { + blocks[level][i]->getKernel()->getBCProcessor()->applyPreCollisionBC(); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + exit(EXIT_FAILURE); + } catch (std::string &s) { + UBLOG(logERROR, s); + exit(EXIT_FAILURE); + } catch (...) { + UBLOG(logERROR, "unknown exception"); + exit(EXIT_FAILURE); + } + } + } } ////////////////////////////////////////////////////////////////////////// void BasicCalculator::applyPostCollisionBC(int startLevel, int maxInitLevel) { - //startLevel bis maxInitLevel - for (int level = startLevel; level <= maxInitLevel; level++) - { - int size = (int)blocks[level].size(); + // startLevel bis maxInitLevel + for (int level = startLevel; level <= maxInitLevel; level++) { + int size = (int)blocks[level].size(); #ifdef _OPENMP #pragma omp parallel for schedule(OMP_SCHEDULE) #endif - for (int i = 0; i < size; i++) - { - try - { - blocks[level][i]->getKernel()->getBCProcessor()->applyPostCollisionBC(); - } - catch (std::exception & e) - { - UBLOG(logERROR, e.what()); - exit(EXIT_FAILURE); - } - catch (std::string & s) - { - UBLOG(logERROR, s); - exit(EXIT_FAILURE); - } - catch (...) - { - UBLOG(logERROR, "unknown exception"); - exit(EXIT_FAILURE); - } - } - } + for (int i = 0; i < size; i++) { + try { + blocks[level][i]->getKernel()->getBCProcessor()->applyPostCollisionBC(); + } catch (std::exception &e) { + UBLOG(logERROR, e.what()); + exit(EXIT_FAILURE); + } catch (std::string &s) { + UBLOG(logERROR, s); + exit(EXIT_FAILURE); + } catch (...) { + UBLOG(logERROR, "unknown exception"); + exit(EXIT_FAILURE); + } + } + } } - diff --git a/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.h b/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.h index 7585f53ce..3ef1f4c71 100644 --- a/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.h +++ b/src/cpu/VirtualFluidsCore/Grid/BasicCalculator.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,34 +38,32 @@ class Block3DConnector; -//! \class BasicCalculator -//! \brief Class implements basic functionality with MPI + OpenMP parallelization for main calculation loop -//! \author Konstantin Kutscher +//! \class BasicCalculator +//! \brief Class implements basic functionality with MPI + OpenMP parallelization for main calculation loop +//! \author Konstantin Kutscher class BasicCalculator : public Calculator { public: - BasicCalculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps); - ~BasicCalculator() override = default; - void calculate() override; + BasicCalculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps); + ~BasicCalculator() override = default; + void calculate() override; protected: - void calculateBlocks(int startLevel, int maxInitLevel, int calcStep); - void swapDistributions(int startLevel, int maxInitLevel); - void exchangeBlockData(int startLevel, int maxInitLevel); - void connectorsPrepareLocal(std::vector< SPtr<Block3DConnector> >& connectors); - void connectorsSendLocal(std::vector< SPtr<Block3DConnector> >& connectors); - void connectorsReceiveLocal(std::vector< SPtr<Block3DConnector> >& connectors); - void connectorsPrepareRemote(std::vector< SPtr<Block3DConnector> >& connectors); - void connectorsSendRemote(std::vector< SPtr<Block3DConnector> >& connectors); - void connectorsReceiveRemote(std::vector< SPtr<Block3DConnector> >& connectors); - void interpolation(int startLevel, int maxInitLevel); - void applyPreCollisionBC(int startLevel, int maxInitLevel); - void applyPostCollisionBC(int startLevel, int maxInitLevel); + void calculateBlocks(int startLevel, int maxInitLevel, int calcStep); + void swapDistributions(int startLevel, int maxInitLevel); + void exchangeBlockData(int startLevel, int maxInitLevel); + void connectorsPrepareLocal(std::vector<SPtr<Block3DConnector>> &connectors); + void connectorsSendLocal(std::vector<SPtr<Block3DConnector>> &connectors); + void connectorsReceiveLocal(std::vector<SPtr<Block3DConnector>> &connectors); + void connectorsPrepareRemote(std::vector<SPtr<Block3DConnector>> &connectors); + void connectorsSendRemote(std::vector<SPtr<Block3DConnector>> &connectors); + void connectorsReceiveRemote(std::vector<SPtr<Block3DConnector>> &connectors); + void interpolation(int startLevel, int maxInitLevel); + void applyPreCollisionBC(int startLevel, int maxInitLevel); + void applyPostCollisionBC(int startLevel, int maxInitLevel); + private: }; #endif // BasicCalculator_h__ - - - diff --git a/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp b/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp index 23fc3903b..79753c144 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp +++ b/src/cpu/VirtualFluidsCore/Grid/Block3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,488 +33,352 @@ #include "Block3D.h" -#include "Grid3DSystem.h" #include "Block3DConnector.h" +#include "Grid3DSystem.h" #include "LBMKernel.h" - int Block3D::counter = 0; ////////////////////////////////////////////////////////////////////////// -Block3D::Block3D(int x1, int x2, int x3, int level) - : x1(x1), x2(x2), x3(x3), - rank(0),part(0), - level(level), bundle(0) - +Block3D::Block3D(int x1, int x2, int x3, int level) : x1(x1), x2(x2), x3(x3), rank(0), part(0), level(level), bundle(0) + { - globalID = counter++; + globalID = counter++; } ////////////////////////////////////////////////////////////////////////// -Block3D::~Block3D() -= default; +Block3D::~Block3D() = default; ////////////////////////////////////////////////////////////////////////// -bool Block3D::operator==(const Block3D& src) const -{ - return (x1==src.x1 && x2==src.x2 && x3==src.x3); -} +bool Block3D::operator==(const Block3D &src) const { return (x1 == src.x1 && x2 == src.x2 && x3 == src.x3); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::operator!=(const Block3D& src) const -{ - return !(*this==src); -} +bool Block3D::operator!=(const Block3D &src) const { return !(*this == src); } ////////////////////////////////////////////////////////////////////////// -int Block3D::getX1() const -{ - return this->x1; -} +int Block3D::getX1() const { return this->x1; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getX2() const -{ - return this->x2; -} +int Block3D::getX2() const { return this->x2; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getX3() const -{ - return this->x3; -} +int Block3D::getX3() const { return this->x3; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setActive(bool active) -{ - this->active = active; -} +void Block3D::setActive(bool active) { this->active = active; } ////////////////////////////////////////////////////////////////////////// -bool Block3D::isActive() const -{ - return this->active; -} +bool Block3D::isActive() const { return this->active; } ////////////////////////////////////////////////////////////////////////// -bool Block3D::isNotActive() const -{ - return(!this->active); -} +bool Block3D::isNotActive() const { return (!this->active); } ////////////////////////////////////////////////////////////////////////// -void Block3D::setKernel(SPtr<LBMKernel> kernel) -{ - this->kernel = kernel; -} +void Block3D::setKernel(SPtr<LBMKernel> kernel) { this->kernel = kernel; } ////////////////////////////////////////////////////////////////////////// -SPtr<ILBMKernel> Block3D::getKernel() const -{ - return this->kernel; -} +SPtr<ILBMKernel> Block3D::getKernel() const { return this->kernel; } ////////////////////////////////////////////////////////////////////////// -void Block3D::deleteKernel() -{ - this->kernel = SPtr<LBMKernel>(); -} +void Block3D::deleteKernel() { this->kernel = SPtr<LBMKernel>(); } ////////////////////////////////////////////////////////////////////////// -int Block3D::getBundle() const -{ - return bundle; -} +int Block3D::getBundle() const { return bundle; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setBundle(int bundle) -{ - this->bundle = bundle; -} +void Block3D::setBundle(int bundle) { this->bundle = bundle; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setRank(int rank) -{ - this->rank = rank; -} +void Block3D::setRank(int rank) { this->rank = rank; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getRank() const -{ - return this->rank; -} +int Block3D::getRank() const { return this->rank; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setLocalRank(int rank) -{ - this->lrank = rank; -} +void Block3D::setLocalRank(int rank) { this->lrank = rank; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getLocalRank() const -{ - return this->lrank; -} +int Block3D::getLocalRank() const { return this->lrank; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getGlobalID() const -{ - return this->globalID; -} +int Block3D::getGlobalID() const { return this->globalID; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setGlobalID(int id) -{ - this->globalID = id; -} +void Block3D::setGlobalID(int id) { this->globalID = id; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getLocalID() const -{ - return this->localID; -} +int Block3D::getLocalID() const { return this->localID; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setLocalID(int id) -{ - this->localID = id; -} +void Block3D::setLocalID(int id) { this->localID = id; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getPart() const -{ - return this->part; -} +int Block3D::getPart() const { return this->part; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setPart(int part) -{ - this->part = part; -} +void Block3D::setPart(int part) { this->part = part; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getLevel() const -{ - return this->level; -} +int Block3D::getLevel() const { return this->level; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setLevel(int level) -{ - this->level = level; -} +void Block3D::setLevel(int level) { this->level = level; } ////////////////////////////////////////////////////////////////////////// SPtr<Block3DConnector> Block3D::getConnector(int dir) const -{ - for(SPtr<Block3DConnector> c : connectors) - { - if( c ) - { - if(c->getSendDir() == dir) return c; - } - } - return SPtr<Block3DConnector>(); -} -////////////////////////////////////////////////////////////////////////// -void Block3D::setConnector(SPtr<Block3DConnector> connector) { - connectors.push_back(connector); + for (SPtr<Block3DConnector> c : connectors) { + if (c) { + if (c->getSendDir() == dir) + return c; + } + } + return SPtr<Block3DConnector>(); } ////////////////////////////////////////////////////////////////////////// -void Block3D::deleteConnectors() -{ - connectors.clear(); -} +void Block3D::setConnector(SPtr<Block3DConnector> connector) { connectors.push_back(connector); } +////////////////////////////////////////////////////////////////////////// +void Block3D::deleteConnectors() { connectors.clear(); } ////////////////////////////////////////////////////////////////////////// bool Block3D::hasConnectors() { - for(SPtr<Block3DConnector> c : connectors) - if( c ) return true; - - return false; + for (SPtr<Block3DConnector> c : connectors) + if (c) + return true; + + return false; } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackSameLevelConnectors( std::vector<SPtr<Block3DConnector>>& localSameLevelConnectors - , std::vector<SPtr<Block3DConnector>>& remoteSameLevelConnectors ) +void Block3D::pushBackSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors, + std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && !connector->isInterpolationConnectorFC() ) - localSameLevelConnectors.push_back(this->connectors[i]); - else - remoteSameLevelConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && + !connector->isInterpolationConnectorFC()) + localSameLevelConnectors.push_back(this->connectors[i]); + else + remoteSameLevelConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackLocalSameLevelConnectors( std::vector<SPtr<Block3DConnector>>& localSameLevelConnectors ) +void Block3D::pushBackLocalSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && !connector->isInterpolationConnectorFC() ) - localSameLevelConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && + !connector->isInterpolationConnectorFC()) + localSameLevelConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackLocalSameLevelConnectors( std::vector<SPtr<Block3DConnector>>& localSameLevelConnectors, const int& dir) +void Block3D::pushBackLocalSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors, + const int &dir) { - SPtr<Block3DConnector> connector = this->connectors[dir]; - if( this->connectors[dir] ) - { - if( connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && !connector->isInterpolationConnectorFC() ) - localSameLevelConnectors.push_back(this->connectors[dir]); - } + SPtr<Block3DConnector> connector = this->connectors[dir]; + if (this->connectors[dir]) { + if (connector->isLocalConnector() && !connector->isInterpolationConnectorCF() && + !connector->isInterpolationConnectorFC()) + localSameLevelConnectors.push_back(this->connectors[dir]); + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackRemoteSameLevelConnectors( std::vector<SPtr<Block3DConnector>>& remoteSameLevelConnectors ) +void Block3D::pushBackRemoteSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isRemoteConnector() && !connector->isInterpolationConnectorCF() && !connector->isInterpolationConnectorFC() ) - remoteSameLevelConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isRemoteConnector() && !connector->isInterpolationConnectorCF() && + !connector->isInterpolationConnectorFC()) + remoteSameLevelConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackRemoteSameLevelConnectors( std::vector<SPtr<Block3DConnector>>& remoteSameLevelConnectors, const int& dir ) +void Block3D::pushBackRemoteSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors, + const int &dir) { - SPtr<Block3DConnector> connector = this->connectors[dir]; - if( this->connectors[dir] ) - { - if( connector->isRemoteConnector() && !connector->isInterpolationConnectorCF() && !connector->isInterpolationConnectorFC() ) - remoteSameLevelConnectors.push_back(this->connectors[dir]); - } + SPtr<Block3DConnector> connector = this->connectors[dir]; + if (this->connectors[dir]) { + if (connector->isRemoteConnector() && !connector->isInterpolationConnectorCF() && + !connector->isInterpolationConnectorFC()) + remoteSameLevelConnectors.push_back(this->connectors[dir]); + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackLocalInterpolationConnectorsCF( std::vector<SPtr<Block3DConnector>>& localInterpolationConnectors ) +void Block3D::pushBackLocalInterpolationConnectorsCF(std::vector<SPtr<Block3DConnector>> &localInterpolationConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isLocalConnector() && connector->isInterpolationConnectorCF() ) - localInterpolationConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isLocalConnector() && connector->isInterpolationConnectorCF()) + localInterpolationConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackRemoteInterpolationConnectorsCF( std::vector<SPtr<Block3DConnector>>& remoteInterpolationConnectors ) +void Block3D::pushBackRemoteInterpolationConnectorsCF( + std::vector<SPtr<Block3DConnector>> &remoteInterpolationConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isRemoteConnector() && connector->isInterpolationConnectorCF() ) - remoteInterpolationConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isRemoteConnector() && connector->isInterpolationConnectorCF()) + remoteInterpolationConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackLocalInterpolationConnectorsFC( std::vector<SPtr<Block3DConnector>>& localInterpolationConnectors ) +void Block3D::pushBackLocalInterpolationConnectorsFC(std::vector<SPtr<Block3DConnector>> &localInterpolationConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isLocalConnector() && connector->isInterpolationConnectorFC() ) - localInterpolationConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isLocalConnector() && connector->isInterpolationConnectorFC()) + localInterpolationConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::pushBackRemoteInterpolationConnectorsFC( std::vector<SPtr<Block3DConnector>>& remoteInterpolationConnectors ) +void Block3D::pushBackRemoteInterpolationConnectorsFC( + std::vector<SPtr<Block3DConnector>> &remoteInterpolationConnectors) { - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isRemoteConnector() && connector->isInterpolationConnectorFC() ) - remoteInterpolationConnectors.push_back(this->connectors[i]); - } - } + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isRemoteConnector() && connector->isInterpolationConnectorFC()) + remoteInterpolationConnectors.push_back(this->connectors[i]); + } + } } ////////////////////////////////////////////////////////////////////////// int Block3D::getNumberOfLocalConnectors() { - int count = 0; - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isLocalConnector() ) count++; - } - } - return count; + int count = 0; + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isLocalConnector()) + count++; + } + } + return count; } ////////////////////////////////////////////////////////////////////////// int Block3D::getNumberOfRemoteConnectors() { - int count = 0; - for(int i=0; i<(int)connectors.size(); i++) - { - SPtr<Block3DConnector> connector = this->connectors[i]; - if( this->connectors[i] ) - { - if( connector->isRemoteConnector() ) count++; - } - } - return count; + int count = 0; + for (int i = 0; i < (int)connectors.size(); i++) { + SPtr<Block3DConnector> connector = this->connectors[i]; + if (this->connectors[i]) { + if (connector->isRemoteConnector()) + count++; + } + } + return count; } ////////////////////////////////////////////////////////////////////////// int Block3D::getNumberOfLocalConnectorsForSurfaces() { - int count = 0; - - if(connectors.size() < 6) - return count; + int count = 0; + + if (connectors.size() < 6) + return count; - for(int dir=0; dir<=5; dir++) //Hard coding. It works if you have 0...5 for E, N ... B - { - SPtr<Block3DConnector> connector = this->connectors[dir]; - if( this->connectors[dir] ) - { - if( connector->isLocalConnector() ) count++; - } - } - return count; + for (int dir = 0; dir <= 5; dir++) // Hard coding. It works if you have 0...5 for E, N ... B + { + SPtr<Block3DConnector> connector = this->connectors[dir]; + if (this->connectors[dir]) { + if (connector->isLocalConnector()) + count++; + } + } + return count; } ////////////////////////////////////////////////////////////////////////// int Block3D::getNumberOfRemoteConnectorsForSurfaces() { - int count = 0; - for(int dir=0; dir<=5; dir++) //Hard coding. It works if you have 0...5 for E, N ... B - { - SPtr<Block3DConnector> connector = this->connectors[dir]; - if( this->connectors[dir] ) - { - if( connector->isRemoteConnector() ) count++; - } - } - return count; -} -void Block3D::setCollectionOfInterpolationFlagCF(int flags) -{ - interpolationFlagCF = flags; + int count = 0; + for (int dir = 0; dir <= 5; dir++) // Hard coding. It works if you have 0...5 for E, N ... B + { + SPtr<Block3DConnector> connector = this->connectors[dir]; + if (this->connectors[dir]) { + if (connector->isRemoteConnector()) + count++; + } + } + return count; } +void Block3D::setCollectionOfInterpolationFlagCF(int flags) { interpolationFlagCF = flags; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setInterpolationFlagCF(int dir) -{ - UbSystem::setBit(interpolationFlagCF, 1<<dir); -} -////////////////////////////////////////////////////////////////////////// -int Block3D::getCollectionOfInterpolationFlagCF() -{ - return interpolationFlagCF; -} +void Block3D::setInterpolationFlagCF(int dir) { UbSystem::setBit(interpolationFlagCF, 1 << dir); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlagCF(int dir) -{ - return UbSystem::bitCheck( interpolationFlagCF, 1<<dir ); -} -void Block3D::setCollectionOfInterpolationFlagFC(int flags) -{ - interpolationFlagFC = flags; -} +int Block3D::getCollectionOfInterpolationFlagCF() { return interpolationFlagCF; } ////////////////////////////////////////////////////////////////////////// -void Block3D::setInterpolationFlagFC(int dir) -{ - UbSystem::setBit(interpolationFlagFC, 1<<dir); -} +bool Block3D::hasInterpolationFlagCF(int dir) { return UbSystem::bitCheck(interpolationFlagCF, 1 << dir); } +void Block3D::setCollectionOfInterpolationFlagFC(int flags) { interpolationFlagFC = flags; } ////////////////////////////////////////////////////////////////////////// -int Block3D::getCollectionOfInterpolationFlagFC() -{ - return interpolationFlagFC; -} +void Block3D::setInterpolationFlagFC(int dir) { UbSystem::setBit(interpolationFlagFC, 1 << dir); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlagFC(int dir) -{ - return UbSystem::bitCheck( interpolationFlagFC, 1<<dir ); -} +int Block3D::getCollectionOfInterpolationFlagFC() { return interpolationFlagFC; } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlag() -{ - return(interpolationFlagCF!=0 || interpolationFlagFC!=0); -} +bool Block3D::hasInterpolationFlagFC(int dir) { return UbSystem::bitCheck(interpolationFlagFC, 1 << dir); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlag(int direction) -{ - return(hasInterpolationFlagCF(direction) || hasInterpolationFlagFC(direction)); -} +bool Block3D::hasInterpolationFlag() { return (interpolationFlagCF != 0 || interpolationFlagFC != 0); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlagCF() +bool Block3D::hasInterpolationFlag(int direction) { - return(interpolationFlagCF!=0); + return (hasInterpolationFlagCF(direction) || hasInterpolationFlagFC(direction)); } ////////////////////////////////////////////////////////////////////////// -bool Block3D::hasInterpolationFlagFC() -{ - return(interpolationFlagFC!=0); -} +bool Block3D::hasInterpolationFlagCF() { return (interpolationFlagCF != 0); } +////////////////////////////////////////////////////////////////////////// +bool Block3D::hasInterpolationFlagFC() { return (interpolationFlagFC != 0); } ////////////////////////////////////////////////////////////////////////// void Block3D::deleteInterpolationFlag() { - interpolationFlagFC = 0; - interpolationFlagCF = 0; + interpolationFlagFC = 0; + interpolationFlagCF = 0; } ////////////////////////////////////////////////////////////////////////// double Block3D::getWorkLoad() { - double l = kernel->getCalculationTime(); - l *= static_cast<double>(1<<level); - return l; + double l = kernel->getCalculationTime(); + l *= static_cast<double>(1 << level); + return l; } ////////////////////////////////////////////////////////////////////////// -std::string Block3D::toString() +std::string Block3D::toString() { - std::stringstream ss; - ss<<"Block3D[(x1,x2,x3,level),"; - ss<<" ("<<this->x1<<", "<<this->x2<<", "<<this->x3<<", "<<this->level<<"), id=" << globalID; - ss<< ", active="<<this->active<< ", bundle="<<this->bundle<< ", rank="<<this->rank<<"]"; - ss<<" connectors:"; - for(std::size_t i=0; i<connectors.size(); i++) - if( connectors[i] ) - { - if(connectors[i]->isLocalConnector()) - ss <<"l."<< Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; - if(connectors[i]->isRemoteConnector()) - ss <<"r."<< Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; - if(connectors[i]->isInterpolationConnectorCF()) - ss <<"cf."<< Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; - if(connectors[i]->isInterpolationConnectorFC()) - ss <<"fc."<< Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; - } - return ss.str(); + std::stringstream ss; + ss << "Block3D[(x1,x2,x3,level),"; + ss << " (" << this->x1 << ", " << this->x2 << ", " << this->x3 << ", " << this->level << "), id=" << globalID; + ss << ", active=" << this->active << ", bundle=" << this->bundle << ", rank=" << this->rank << "]"; + ss << " connectors:"; + for (std::size_t i = 0; i < connectors.size(); i++) + if (connectors[i]) { + if (connectors[i]->isLocalConnector()) + ss << "l." << Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; + if (connectors[i]->isRemoteConnector()) + ss << "r." << Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; + if (connectors[i]->isInterpolationConnectorCF()) + ss << "cf." << Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; + if (connectors[i]->isInterpolationConnectorFC()) + ss << "fc." << Grid3DSystem::getDirectionString(connectors[i]->getSendDir()) << ", "; + } + return ss.str(); } ////////////////////////////////////////////////////////////////////////// -void Block3D::setWeight( int rank, int weight ) +void Block3D::setWeight(int rank, int weight) { - std::map<int, int>::iterator it; - if((it = this->weight.find(rank)) != this->weight.end()) - it->second = weight; - else - this->weight.insert(std::make_pair(rank, weight)); + std::map<int, int>::iterator it; + if ((it = this->weight.find(rank)) != this->weight.end()) + it->second = weight; + else + this->weight.insert(std::make_pair(rank, weight)); } ////////////////////////////////////////////////////////////////////////// -int Block3D::getWeight( int rank ) +int Block3D::getWeight(int rank) { - std::map<int, int>::iterator it; - if((it = this->weight.find(rank)) != this->weight.end()) - return it->second; - else - return 0; + std::map<int, int>::iterator it; + if ((it = this->weight.find(rank)) != this->weight.end()) + return it->second; + else + return 0; } ////////////////////////////////////////////////////////////////////////// -void Block3D::addWeight( int rank, int weight ) +void Block3D::addWeight(int rank, int weight) { - int weight_old = getWeight(rank); - weight += weight_old; - setWeight(rank, weight); + int weight_old = getWeight(rank); + weight += weight_old; + setWeight(rank, weight); } ////////////////////////////////////////////////////////////////////////// -void Block3D::addWeightForAll( int weight ) +void Block3D::addWeightForAll(int weight) { - using wMap = std::map<int, int>; - for (wMap::value_type &w : this->weight) - { - w.second += weight; - } + using wMap = std::map<int, int>; + for (wMap::value_type &w : this->weight) { + w.second += weight; + } } ////////////////////////////////////////////////////////////////////////// -void Block3D::clearWeight() -{ - this->weight.clear(); -} +void Block3D::clearWeight() { this->weight.clear(); } ////////////////////////////////////////////////////////////////////////// -int Block3D::getWeightSize() -{ - return static_cast<int>(this->weight.size()); -} +int Block3D::getWeightSize() { return static_cast<int>(this->weight.size()); } diff --git a/src/cpu/VirtualFluidsCore/Grid/Block3D.h b/src/cpu/VirtualFluidsCore/Grid/Block3D.h index 0912f82ac..b2279b069 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Block3D.h +++ b/src/cpu/VirtualFluidsCore/Grid/Block3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,9 +35,9 @@ #define BLOCK3D_H #include <PointerDefinitions.h> -#include <vector> #include <map> #include <string> +#include <vector> class Block3DConnector; class LBMKernel; @@ -47,121 +47,122 @@ class ILBMKernel; class Block3D { public: - Block3D() = default; - Block3D(int x1, int x2, int x3, int level); - virtual ~Block3D(); - bool operator==(const Block3D& src) const; - bool operator!=(const Block3D& src) const; - - int getX1() const; - int getX2() const; - int getX3() const; - - void setActive(bool active); - bool isActive() const; - bool isNotActive() const; - - void setKernel(SPtr<LBMKernel> kernel); - SPtr<ILBMKernel> getKernel() const; - void deleteKernel(); - - void setBundle(int bundle); - int getBundle() const; - - void setRank(int rank); - int getRank() const; - - void setLocalRank(int rank); - int getLocalRank() const; - - int getGlobalID() const; - void setGlobalID(int id); - - int getLocalID() const; - void setLocalID(int id); - - int getPart() const; - void setPart(int part); - - int getLevel() const; - void setLevel(int level); - - //Connector-Section - void setConnector(SPtr<Block3DConnector> connector); - SPtr<Block3DConnector> getConnector(int dir) const; - bool hasConnectors(); - void deleteConnectors(); - void pushBackSameLevelConnectors( std::vector<SPtr<Block3DConnector> >& localSameLevelConnectors - , std::vector<SPtr<Block3DConnector> >& remoteSameLevelConnectors ); - void pushBackLocalSameLevelConnectors( std::vector<SPtr<Block3DConnector> >& localSameLevelConnectors ); - void pushBackRemoteSameLevelConnectors( std::vector<SPtr<Block3DConnector> >& remoteSameLevelConnectors ); - void pushBackLocalInterpolationConnectorsCF( std::vector<SPtr<Block3DConnector> >& localInterpolationConnectors ); - void pushBackRemoteInterpolationConnectorsCF( std::vector<SPtr<Block3DConnector> >& remoteInterpolationConnectors ); - void pushBackLocalInterpolationConnectorsFC( std::vector<SPtr<Block3DConnector> >& localInterpolationConnectors ); - void pushBackRemoteInterpolationConnectorsFC( std::vector<SPtr<Block3DConnector> >& remoteInterpolationConnectors ); - void pushBackLocalSameLevelConnectors( std::vector<SPtr<Block3DConnector> >& localSameLevelConnectors, const int& dir); - void pushBackRemoteSameLevelConnectors( std::vector<SPtr<Block3DConnector> >& remoteSameLevelConnectors, const int& dir ); - int getNumberOfLocalConnectors(); - int getNumberOfRemoteConnectors(); - int getNumberOfLocalConnectorsForSurfaces(); - int getNumberOfRemoteConnectorsForSurfaces(); - - void setWeight(int rank, int weight); - int getWeight(int rank); - void addWeightForAll(int weight); - void addWeight(int rank, int weight); - void clearWeight(); - int getWeightSize(); - - //interpolation - bool hasInterpolationFlag(); - bool hasInterpolationFlag(int dir); - void deleteInterpolationFlag(); - - int getCollectionOfInterpolationFlagCF(); - void setCollectionOfInterpolationFlagCF(int flags); - - void setInterpolationFlagCF(int dir); - bool hasInterpolationFlagCF(int dir); - bool hasInterpolationFlagCF(); - - int getCollectionOfInterpolationFlagFC(); - void setCollectionOfInterpolationFlagFC(int flags); - - void setInterpolationFlagFC(int dir); - bool hasInterpolationFlagFC(int dir); - bool hasInterpolationFlagFC(); - - double getWorkLoad(); - - std::string toString() ; - - static int getMaxGlobalID() { return counter; } - static void setMaxGlobalID(int /*c*/) { counter = 0; } // FIXME ??? + Block3D() = default; + Block3D(int x1, int x2, int x3, int level); + virtual ~Block3D(); + bool operator==(const Block3D &src) const; + bool operator!=(const Block3D &src) const; + + int getX1() const; + int getX2() const; + int getX3() const; + + void setActive(bool active); + bool isActive() const; + bool isNotActive() const; + + void setKernel(SPtr<LBMKernel> kernel); + SPtr<ILBMKernel> getKernel() const; + void deleteKernel(); + + void setBundle(int bundle); + int getBundle() const; + + void setRank(int rank); + int getRank() const; + + void setLocalRank(int rank); + int getLocalRank() const; + + int getGlobalID() const; + void setGlobalID(int id); + + int getLocalID() const; + void setLocalID(int id); + + int getPart() const; + void setPart(int part); + + int getLevel() const; + void setLevel(int level); + + // Connector-Section + void setConnector(SPtr<Block3DConnector> connector); + SPtr<Block3DConnector> getConnector(int dir) const; + bool hasConnectors(); + void deleteConnectors(); + void pushBackSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors, + std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors); + void pushBackLocalSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors); + void pushBackRemoteSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors); + void pushBackLocalInterpolationConnectorsCF(std::vector<SPtr<Block3DConnector>> &localInterpolationConnectors); + void pushBackRemoteInterpolationConnectorsCF(std::vector<SPtr<Block3DConnector>> &remoteInterpolationConnectors); + void pushBackLocalInterpolationConnectorsFC(std::vector<SPtr<Block3DConnector>> &localInterpolationConnectors); + void pushBackRemoteInterpolationConnectorsFC(std::vector<SPtr<Block3DConnector>> &remoteInterpolationConnectors); + void pushBackLocalSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &localSameLevelConnectors, + const int &dir); + void pushBackRemoteSameLevelConnectors(std::vector<SPtr<Block3DConnector>> &remoteSameLevelConnectors, + const int &dir); + int getNumberOfLocalConnectors(); + int getNumberOfRemoteConnectors(); + int getNumberOfLocalConnectorsForSurfaces(); + int getNumberOfRemoteConnectorsForSurfaces(); + + void setWeight(int rank, int weight); + int getWeight(int rank); + void addWeightForAll(int weight); + void addWeight(int rank, int weight); + void clearWeight(); + int getWeightSize(); + + // interpolation + bool hasInterpolationFlag(); + bool hasInterpolationFlag(int dir); + void deleteInterpolationFlag(); + + int getCollectionOfInterpolationFlagCF(); + void setCollectionOfInterpolationFlagCF(int flags); + + void setInterpolationFlagCF(int dir); + bool hasInterpolationFlagCF(int dir); + bool hasInterpolationFlagCF(); + + int getCollectionOfInterpolationFlagFC(); + void setCollectionOfInterpolationFlagFC(int flags); + + void setInterpolationFlagFC(int dir); + bool hasInterpolationFlagFC(int dir); + bool hasInterpolationFlagFC(); + + double getWorkLoad(); + + std::string toString(); + + static int getMaxGlobalID() { return counter; } + static void setMaxGlobalID(int /*c*/) { counter = 0; } // FIXME ??? private: - int x1{0}; - int x2{0}; - int x3{0}; - - bool active{true}; - - int interpolationFlagCF{0}; - int interpolationFlagFC{0}; - - SPtr<LBMKernel> kernel; - std::vector<SPtr<Block3DConnector> > connectors; - std::map<int, int> weight; - - int bundle{-1}; - int rank{-1}; - int lrank{-1}; - int globalID{-1}; - int localID{-1}; - int part{-1}; - int level{-1}; - static int counter; - + int x1{ 0 }; + int x2{ 0 }; + int x3{ 0 }; + + bool active{ true }; + + int interpolationFlagCF{ 0 }; + int interpolationFlagFC{ 0 }; + + SPtr<LBMKernel> kernel; + std::vector<SPtr<Block3DConnector>> connectors; + std::map<int, int> weight; + + int bundle{ -1 }; + int rank{ -1 }; + int lrank{ -1 }; + int globalID{ -1 }; + int localID{ -1 }; + int part{ -1 }; + int level{ -1 }; + static int counter; }; -#endif //BLOCK3D_H +#endif // BLOCK3D_H diff --git a/src/cpu/VirtualFluidsCore/Grid/Calculator.cpp b/src/cpu/VirtualFluidsCore/Grid/Calculator.cpp index 5fc3f8d42..fbeb2de97 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Calculator.cpp +++ b/src/cpu/VirtualFluidsCore/Grid/Calculator.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,214 +33,199 @@ #include "Calculator.h" -#include "Grid3D.h" -#include "Block3DConnector.h" #include "Block3D.h" -#include "UbScheduler.h" +#include "Block3DConnector.h" #include "CoProcessor.h" +#include "Grid3D.h" +#include "UbScheduler.h" #include <basics/utilities/UbException.h> -Calculator::Calculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps) : - grid(grid), - additionalGhostLayerUpdateScheduler(additionalGhostLayerUpdateScheduler), - numberOfTimeSteps(numberOfTimeSteps) +Calculator::Calculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps) + : grid(grid), additionalGhostLayerUpdateScheduler(additionalGhostLayerUpdateScheduler), + numberOfTimeSteps(numberOfTimeSteps) { - this->grid = grid; - startTimeStep = int(grid->getTimeStep())+1; - minLevel = grid->getCoarsestInitializedLevel(); - maxLevel = grid->getFinestInitializedLevel(); - if (maxLevel > 0) - refinement = true; - else - refinement = false; - blocks.resize(maxLevel+1); - localConns.resize(maxLevel+1); - remoteConns.resize(maxLevel+1); - localInterConns.resize(maxLevel); - remoteInterConns.resize(maxLevel); - - int gridRank = grid->getRank(); - - for (int level = minLevel; level <= maxLevel; level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, gridRank, true, blockVector); - for (const auto& block : blockVector) - if (block) - blocks[block->getLevel()].push_back(block); - } - - initLocalConnectors(); - initRemoteConnectors(); + this->grid = grid; + startTimeStep = int(grid->getTimeStep()) + 1; + minLevel = grid->getCoarsestInitializedLevel(); + maxLevel = grid->getFinestInitializedLevel(); + if (maxLevel > 0) + refinement = true; + else + refinement = false; + blocks.resize(maxLevel + 1); + localConns.resize(maxLevel + 1); + remoteConns.resize(maxLevel + 1); + localInterConns.resize(maxLevel); + remoteInterConns.resize(maxLevel); + + int gridRank = grid->getRank(); + + for (int level = minLevel; level <= maxLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, gridRank, true, blockVector); + for (const auto &block : blockVector) + if (block) + blocks[block->getLevel()].push_back(block); + } + + initLocalConnectors(); + initRemoteConnectors(); } ////////////////////////////////////////////////////////////////////////// -Calculator::~Calculator() -= default; +Calculator::~Calculator() = default; ////////////////////////////////////////////////////////////////////////// -void Calculator::addCoProcessor(SPtr<CoProcessor> coProcessor) -{ - coProcessors.push_back(coProcessor); -} +void Calculator::addCoProcessor(SPtr<CoProcessor> coProcessor) { coProcessors.push_back(coProcessor); } ////////////////////////////////////////////////////////////////////////// void Calculator::coProcess(double step) { - for (SPtr<CoProcessor> cp : coProcessors) - { - cp->process(step); - } + for (SPtr<CoProcessor> cp : coProcessors) { + cp->process(step); + } } ////////////////////////////////////////////////////////////////////////// void Calculator::initLocalConnectors() { - UBLOG(logDEBUG1, "Calculator::initLocalConnectors() - start"); - - for (int l = minLevel; l <= maxLevel; l++) - { - for(SPtr<Block3D> block : blocks[l]) - { - block->pushBackLocalSameLevelConnectors(localConns[l]); - - if (l != maxLevel) - block->pushBackLocalInterpolationConnectorsCF(localInterConns[l]); - } - if (l != maxLevel) - { - for(SPtr<Block3D> block : blocks[l+1]) - { - block->pushBackLocalInterpolationConnectorsFC(localInterConns[l]); - } - } - UBLOG(logDEBUG5, "Calculator::initConnectors()-initConnectors(localConns["<<l<<"])"); - initConnectors(localConns[l]); - - if (l != maxLevel) - { - UBLOG(logDEBUG5, "Calculator::initConnectors()-initConnectors(localInterConns["<<l<<"])"); - initConnectors(localInterConns[l]); - } - } - - UBLOG(logDEBUG1, "Calculator::initLocalConnectors() - end"); + UBLOG(logDEBUG1, "Calculator::initLocalConnectors() - start"); + + for (int l = minLevel; l <= maxLevel; l++) { + for (SPtr<Block3D> block : blocks[l]) { + block->pushBackLocalSameLevelConnectors(localConns[l]); + + if (l != maxLevel) + block->pushBackLocalInterpolationConnectorsCF(localInterConns[l]); + } + if (l != maxLevel) { + for (SPtr<Block3D> block : blocks[l + 1]) { + block->pushBackLocalInterpolationConnectorsFC(localInterConns[l]); + } + } + UBLOG(logDEBUG5, "Calculator::initConnectors()-initConnectors(localConns[" << l << "])"); + initConnectors(localConns[l]); + + if (l != maxLevel) { + UBLOG(logDEBUG5, "Calculator::initConnectors()-initConnectors(localInterConns[" << l << "])"); + initConnectors(localInterConns[l]); + } + } + + UBLOG(logDEBUG1, "Calculator::initLocalConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// void Calculator::initRemoteConnectors() { - std::vector< std::vector< SPtr<Block3DConnector> > > remoteInterConnsCF; - std::vector< std::vector< SPtr<Block3DConnector> > > remoteInterConnsFC; - remoteInterConnsCF.resize(maxLevel+1); - remoteInterConnsFC.resize(maxLevel+1); - - for(int l = minLevel; l<=maxLevel;l++) - { - std::vector<SPtr<Block3D>> blockVector; - //grid->getBlocks(level, gridRank, true, blockVector); - grid->getBlocks(l, blockVector); - for(SPtr<Block3D> block : blockVector) - { - int block_level = block->getLevel(); - block->pushBackRemoteSameLevelConnectors(remoteConns[block_level]); - - block->pushBackRemoteInterpolationConnectorsCF(remoteInterConnsCF[block_level]); - block->pushBackRemoteInterpolationConnectorsFC(remoteInterConnsFC[block_level]); - } - } - - for (int l = minLevel; l <= maxLevel; l++) - { - UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-initConnectors(remoteConns["<<l<<"])"); - initConnectors(remoteConns[l]); - if (l != maxLevel) - { - for(size_t i = 0; i < remoteInterConnsCF[l].size(); i++) - remoteInterConns[l].push_back(remoteInterConnsCF[l][i]); - for(size_t i = 0; i < remoteInterConnsFC[l+1].size(); i++) - remoteInterConns[l].push_back(remoteInterConnsFC[l+1][i]); - } - } - ////////////////////////////////////////////////////////////////////////// - //UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - start"); - for (int l = minLevel; l <= maxLevel; l++) - { - if (l != maxLevel) - { - UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-initConnectors(remoteInterConns["<<l<<"])"); - for(SPtr<Block3DConnector> c : remoteInterConns[l] ) c->init(); - } - } - //UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - end"); - ////////////////////////////////////////////////////////////////////////// - //sendTransmitterDataSize - //UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - start"); - for (int l = minLevel; l <= maxLevel; l++) - { - if (l != maxLevel) - { - UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-sendTransmitterDataSize(remoteInterConns["<<l<<"])"); - for(SPtr<Block3DConnector> c : remoteInterConns[l] ) c->sendTransmitterDataSize(); - } - } - //UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - end"); - ////////////////////////////////////////////////////////////////////////// - //receiveTransmitterDataSize - //wenn er hier bei verteilten berechnungen stopped, dann ist vermutlich auf einer seite ein nicht aktiver block!!! - //UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - start"); - for (int l = minLevel; l <= maxLevel; l++) - { - if (l != maxLevel) - { - UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-receiveTransmitterDataSize(remoteInterConns["<<l<<"])"); - for(SPtr<Block3DConnector> c : remoteInterConns[l] ) c->receiveTransmitterDataSize(); - } - } - //UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - end"); - ////////////////////////////////////////////////////////////////////////// + std::vector<std::vector<SPtr<Block3DConnector>>> remoteInterConnsCF; + std::vector<std::vector<SPtr<Block3DConnector>>> remoteInterConnsFC; + remoteInterConnsCF.resize(maxLevel + 1); + remoteInterConnsFC.resize(maxLevel + 1); + + for (int l = minLevel; l <= maxLevel; l++) { + std::vector<SPtr<Block3D>> blockVector; + // grid->getBlocks(level, gridRank, true, blockVector); + grid->getBlocks(l, blockVector); + for (SPtr<Block3D> block : blockVector) { + int block_level = block->getLevel(); + block->pushBackRemoteSameLevelConnectors(remoteConns[block_level]); + + block->pushBackRemoteInterpolationConnectorsCF(remoteInterConnsCF[block_level]); + block->pushBackRemoteInterpolationConnectorsFC(remoteInterConnsFC[block_level]); + } + } + + for (int l = minLevel; l <= maxLevel; l++) { + UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-initConnectors(remoteConns[" << l << "])"); + initConnectors(remoteConns[l]); + if (l != maxLevel) { + for (size_t i = 0; i < remoteInterConnsCF[l].size(); i++) + remoteInterConns[l].push_back(remoteInterConnsCF[l][i]); + for (size_t i = 0; i < remoteInterConnsFC[l + 1].size(); i++) + remoteInterConns[l].push_back(remoteInterConnsFC[l + 1][i]); + } + } + ////////////////////////////////////////////////////////////////////////// + // UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - start"); + for (int l = minLevel; l <= maxLevel; l++) { + if (l != maxLevel) { + UBLOG(logDEBUG5, "Calculator::initRemoteConnectors()-initConnectors(remoteInterConns[" << l << "])"); + for (SPtr<Block3DConnector> c : remoteInterConns[l]) + c->init(); + } + } + // UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - end"); + ////////////////////////////////////////////////////////////////////////// + // sendTransmitterDataSize + // UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - start"); + for (int l = minLevel; l <= maxLevel; l++) { + if (l != maxLevel) { + UBLOG(logDEBUG5, + "Calculator::initRemoteConnectors()-sendTransmitterDataSize(remoteInterConns[" << l << "])"); + for (SPtr<Block3DConnector> c : remoteInterConns[l]) + c->sendTransmitterDataSize(); + } + } + // UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - end"); + ////////////////////////////////////////////////////////////////////////// + // receiveTransmitterDataSize + // wenn er hier bei verteilten berechnungen stopped, dann ist vermutlich auf einer seite ein nicht aktiver block!!! + // UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - start"); + for (int l = minLevel; l <= maxLevel; l++) { + if (l != maxLevel) { + UBLOG(logDEBUG5, + "Calculator::initRemoteConnectors()-receiveTransmitterDataSize(remoteInterConns[" << l << "])"); + for (SPtr<Block3DConnector> c : remoteInterConns[l]) + c->receiveTransmitterDataSize(); + } + } + // UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - end"); + ////////////////////////////////////////////////////////////////////////// } ////////////////////////////////////////////////////////////////////////// -void Calculator::initConnectors(std::vector<SPtr<Block3DConnector>>& connectors) +void Calculator::initConnectors(std::vector<SPtr<Block3DConnector>> &connectors) { - UBLOG(logDEBUG1, "Calculator::initConnectors() - start"); - - //initialization - ////////////////////////////////////////////////////////////////////////// - //initialize connectors - UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - start"); - for(SPtr<Block3DConnector> c : connectors ) c->init(); - UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - end"); - ////////////////////////////////////////////////////////////////////////// - //sendTransmitterDataSize - UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - start"); - for(SPtr<Block3DConnector> c : connectors ) c->sendTransmitterDataSize(); - UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - end"); - ////////////////////////////////////////////////////////////////////////// - //receiveTransmitterDataSize - //wenn er hier bei verteilten berechnungen stopped, dann ist vermutlich auf einer seite ein nicht aktiver block!!! - UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - start"); - for(SPtr<Block3DConnector> c : connectors ) c->receiveTransmitterDataSize(); - UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - end"); - - UBLOG(logDEBUG1, "Calculator::initConnectors() - end"); + UBLOG(logDEBUG1, "Calculator::initConnectors() - start"); + + // initialization + ////////////////////////////////////////////////////////////////////////// + // initialize connectors + UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - start"); + for (SPtr<Block3DConnector> c : connectors) + c->init(); + UBLOG(logDEBUG5, "Calculator::initConnectors() - connectoren initialisieren - end"); + ////////////////////////////////////////////////////////////////////////// + // sendTransmitterDataSize + UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - start"); + for (SPtr<Block3DConnector> c : connectors) + c->sendTransmitterDataSize(); + UBLOG(logDEBUG5, "Calculator::initConnectors() - sendTransmitterDataSize - end"); + ////////////////////////////////////////////////////////////////////////// + // receiveTransmitterDataSize + // wenn er hier bei verteilten berechnungen stopped, dann ist vermutlich auf einer seite ein nicht aktiver block!!! + UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - start"); + for (SPtr<Block3DConnector> c : connectors) + c->receiveTransmitterDataSize(); + UBLOG(logDEBUG5, "Calculator::initConnectors() - receiveTransmitterDataSize - end"); + + UBLOG(logDEBUG1, "Calculator::initConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// void Calculator::deleteBlocks() { - for(std::vector< SPtr<Block3D> > &bs : blocks) - bs.resize(0); + for (std::vector<SPtr<Block3D>> &bs : blocks) + bs.resize(0); } ////////////////////////////////////////////////////////////////////////// void Calculator::deleteConnectors() { - deleteConnectors(localConns); - deleteConnectors(remoteConns); + deleteConnectors(localConns); + deleteConnectors(remoteConns); - deleteConnectors(localInterConns); - deleteConnectors(remoteInterConns); + deleteConnectors(localInterConns); + deleteConnectors(remoteInterConns); } ////////////////////////////////////////////////////////////////////////// -void Calculator::deleteConnectors(std::vector< std::vector< SPtr<Block3DConnector> > >& conns) +void Calculator::deleteConnectors(std::vector<std::vector<SPtr<Block3DConnector>>> &conns) { - for(std::vector< SPtr<Block3DConnector> > &c : conns) - c.resize(0); + for (std::vector<SPtr<Block3DConnector>> &c : conns) + c.resize(0); } ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/Grid/Calculator.h b/src/cpu/VirtualFluidsCore/Grid/Calculator.h index dfa1fabae..377e6eee7 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Calculator.h +++ b/src/cpu/VirtualFluidsCore/Grid/Calculator.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -43,48 +43,49 @@ class Block3D; class Block3DConnector; class CoProcessor; -//! \class Calculator -//! \brief A base class for main calculation loop +//! \class Calculator +//! \brief A base class for main calculation loop -class Calculator +class Calculator { public: - Calculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps); - virtual ~Calculator(); - //! control of coProcessors - void addCoProcessor(SPtr<CoProcessor> coProcessor); - void coProcess(double step); + Calculator(SPtr<Grid3D> grid, SPtr<UbScheduler> additionalGhostLayerUpdateScheduler, int numberOfTimeSteps); + virtual ~Calculator(); + //! control of coProcessors + void addCoProcessor(SPtr<CoProcessor> coProcessor); + void coProcess(double step); + + virtual void calculate() = 0; - virtual void calculate()=0; protected: - virtual void initLocalConnectors(); - virtual void initRemoteConnectors(); - void initConnectors(std::vector<SPtr<Block3DConnector> >& connectors); - void deleteBlocks(); - void deleteConnectors(); - void deleteConnectors(std::vector< std::vector< SPtr<Block3DConnector> > >& conns); + virtual void initLocalConnectors(); + virtual void initRemoteConnectors(); + void initConnectors(std::vector<SPtr<Block3DConnector>> &connectors); + void deleteBlocks(); + void deleteConnectors(); + void deleteConnectors(std::vector<std::vector<SPtr<Block3DConnector>>> &conns); - int minLevel, maxLevel; - int startTimeStep; - int numberOfTimeSteps; - std::vector< std::vector< SPtr<Block3DConnector> > > localConns; - std::vector< std::vector< SPtr<Block3DConnector> > > remoteConns; + int minLevel, maxLevel; + int startTimeStep; + int numberOfTimeSteps; + std::vector<std::vector<SPtr<Block3DConnector>>> localConns; + std::vector<std::vector<SPtr<Block3DConnector>>> remoteConns; - bool refinement; - SPtr<Grid3D> grid; - SPtr<UbScheduler> additionalGhostLayerUpdateScheduler; - std::vector< std::vector<SPtr<Block3D> > > blocks; + bool refinement; + SPtr<Grid3D> grid; + SPtr<UbScheduler> additionalGhostLayerUpdateScheduler; + std::vector<std::vector<SPtr<Block3D>>> blocks; - //localInterConns and remoteInterConns save interpolation connectors - //every element save CF connectors for current level and FC connectors for next level - //e.g. - //localInterConns[0] = CF(0), FC(1) - //localInterConns[1] = CF(1), FC(2) - //localInterConns[2] - std::vector< std::vector< SPtr<Block3DConnector> > > localInterConns; - std::vector< std::vector< SPtr<Block3DConnector> > > remoteInterConns; + // localInterConns and remoteInterConns save interpolation connectors + // every element save CF connectors for current level and FC connectors for next level + // e.g. + // localInterConns[0] = CF(0), FC(1) + // localInterConns[1] = CF(1), FC(2) + // localInterConns[2] + std::vector<std::vector<SPtr<Block3DConnector>>> localInterConns; + std::vector<std::vector<SPtr<Block3DConnector>>> remoteInterConns; - std::vector< SPtr<CoProcessor> > coProcessors; + std::vector<SPtr<CoProcessor>> coProcessors; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Grid/Grid3D.cpp b/src/cpu/VirtualFluidsCore/Grid/Grid3D.cpp index 3cb76a8b2..520da83f6 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Grid3D.cpp +++ b/src/cpu/VirtualFluidsCore/Grid/Grid3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,1934 +35,2217 @@ #include <set> -#include <geometry3d/CoordinateTransformation3D.h> #include <basics/writer/WbWriterVtkXmlASCII.h> +#include <geometry3d/CoordinateTransformation3D.h> -#include "Grid3DVisitor.h" #include "Block3DVisitor.h" -#include "Interactor3D.h" #include "Grid3DSystem.h" +#include "Grid3DVisitor.h" +#include "Interactor3D.h" #include "LBMSystem.h" #include <Block3D.h> #include <Communicator.h> - using namespace std; -Grid3D::Grid3D() - -{ - levelSet.resize(Grid3DSystem::MAXLEVEL + 1); -} +Grid3D::Grid3D() { levelSet.resize(Grid3DSystem::MAXLEVEL + 1); } ////////////////////////////////////////////////////////////////////////// -Grid3D::Grid3D(SPtr<Communicator> comm) - +Grid3D::Grid3D(SPtr<Communicator> comm) + { - levelSet.resize(Grid3DSystem::MAXLEVEL + 1); - bundle = comm->getBundleID(); - rank = comm->getProcessID(); + levelSet.resize(Grid3DSystem::MAXLEVEL + 1); + bundle = comm->getBundleID(); + rank = comm->getProcessID(); } ////////////////////////////////////////////////////////////////////////// -Grid3D::Grid3D(SPtr<Communicator> comm, int blockNx1, int blockNx2, int blockNx3, int gridNx1, int gridNx2, int gridNx3) : - - blockNx1(blockNx1), - blockNx2(blockNx2), - blockNx3(blockNx2), - nx1(gridNx1), - nx2(gridNx2), - nx3(gridNx3) +Grid3D::Grid3D(SPtr<Communicator> comm, int blockNx1, int blockNx2, int blockNx3, int gridNx1, int gridNx2, int gridNx3) + : + + blockNx1(blockNx1), blockNx2(blockNx2), blockNx3(blockNx2), nx1(gridNx1), nx2(gridNx2), nx3(gridNx3) { - levelSet.resize(Grid3DSystem::MAXLEVEL + 1); - bundle = comm->getBundleID(); - rank = comm->getProcessID(); - trafo = std::make_shared<CoordinateTransformation3D>(0.0, 0.0, 0.0, (double)blockNx1, (double)blockNx2, (double)blockNx3); - UbTupleInt3 minInd(0, 0, 0); - UbTupleInt3 maxInd(gridNx1, gridNx2, gridNx3); - this->fillExtentWithBlocks(minInd, maxInd); + levelSet.resize(Grid3DSystem::MAXLEVEL + 1); + bundle = comm->getBundleID(); + rank = comm->getProcessID(); + trafo = std::make_shared<CoordinateTransformation3D>(0.0, 0.0, 0.0, (double)blockNx1, (double)blockNx2, + (double)blockNx3); + UbTupleInt3 minInd(0, 0, 0); + UbTupleInt3 maxInd(gridNx1, gridNx2, gridNx3); + this->fillExtentWithBlocks(minInd, maxInd); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::addInteractor(SPtr<Interactor3D> interactor) -{ - interactors.push_back(interactor); -} +void Grid3D::addInteractor(SPtr<Interactor3D> interactor) { interactors.push_back(interactor); } ////////////////////////////////////////////////////////////////////////// void Grid3D::addAndInitInteractor(SPtr<Interactor3D> interactor, double timestep) { - interactors.push_back(interactor); - interactor->initInteractor(timestep); -} -////////////////////////////////////////////////////////////////////////// -Grid3D::Interactor3DSet Grid3D::getInteractors() -{ - return interactors; -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::accept(Block3DVisitor& blockVisitor) -{ - int startLevel = blockVisitor.getStartLevel(); - int stopLevel = blockVisitor.getStopLevel(); - - if (startLevel < 0 || stopLevel < 0 || startLevel > Grid3DSystem::MAXLEVEL || stopLevel > Grid3DSystem::MAXLEVEL) - throw UbException(UB_EXARGS, "not valid level!"); - - bool dir = startLevel < stopLevel; - if (dir) stopLevel += 1; - else stopLevel -= 1; - - //#pragma omp parallel - // { - // for (int l = startLevel; l!=stopLevel;) - // { - // std::vector<SPtr<Block3D>> blockVector; - // getBlocks(l, blockVector); - // int sizeb = (int)blockVector.size(); - // - //#pragma omp for - // for (int i = 0; i < sizeb; i++) - // { - // blockVisitor.visit(shared_from_this(), blockVector[i]); - // } - // if (dir) l++; - // else l--; - // } - // } - for (int l = startLevel; l != stopLevel;) - { - std::vector<SPtr<Block3D>> blockVector; - getBlocks(l, blockVector); - for (SPtr<Block3D> b : blockVector) - { - blockVisitor.visit(shared_from_this(), b); - } - if (dir) l++; - else l--; - } -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::accept(Grid3DVisitor& gridVisitor) -{ - gridVisitor.visit(shared_from_this()); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::accept(SPtr<Grid3DVisitor> gridVisitor) -{ - gridVisitor->visit(shared_from_this()); -} + interactors.push_back(interactor); + interactor->initInteractor(timestep); +} +////////////////////////////////////////////////////////////////////////// +Grid3D::Interactor3DSet Grid3D::getInteractors() { return interactors; } +////////////////////////////////////////////////////////////////////////// +void Grid3D::accept(Block3DVisitor &blockVisitor) +{ + int startLevel = blockVisitor.getStartLevel(); + int stopLevel = blockVisitor.getStopLevel(); + + if (startLevel < 0 || stopLevel < 0 || startLevel > Grid3DSystem::MAXLEVEL || stopLevel > Grid3DSystem::MAXLEVEL) + throw UbException(UB_EXARGS, "not valid level!"); + + bool dir = startLevel < stopLevel; + if (dir) + stopLevel += 1; + else + stopLevel -= 1; + + //#pragma omp parallel + // { + // for (int l = startLevel; l!=stopLevel;) + // { + // std::vector<SPtr<Block3D>> blockVector; + // getBlocks(l, blockVector); + // int sizeb = (int)blockVector.size(); + // + //#pragma omp for + // for (int i = 0; i < sizeb; i++) + // { + // blockVisitor.visit(shared_from_this(), blockVector[i]); + // } + // if (dir) l++; + // else l--; + // } + // } + for (int l = startLevel; l != stopLevel;) { + std::vector<SPtr<Block3D>> blockVector; + getBlocks(l, blockVector); + for (SPtr<Block3D> b : blockVector) { + blockVisitor.visit(shared_from_this(), b); + } + if (dir) + l++; + else + l--; + } +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::accept(Grid3DVisitor &gridVisitor) { gridVisitor.visit(shared_from_this()); } +////////////////////////////////////////////////////////////////////////// +void Grid3D::accept(SPtr<Grid3DVisitor> gridVisitor) { gridVisitor->visit(shared_from_this()); } ////////////////////////////////////////////////////////////////////////// void Grid3D::addBlock(SPtr<Block3D> block) { - if (block) - { - this->blockIdMap.insert(std::make_pair(block->getGlobalID(), block)); - int level = block->getLevel(); - this->levelSet[level].insert(std::make_pair(Block3DKey(block->getX1(), block->getX2(), block->getX3()), block)); - } + if (block) { + this->blockIdMap.insert(std::make_pair(block->getGlobalID(), block)); + int level = block->getLevel(); + this->levelSet[level].insert(std::make_pair(Block3DKey(block->getX1(), block->getX2(), block->getX3()), block)); + } } ////////////////////////////////////////////////////////////////////////// bool Grid3D::deleteBlock(SPtr<Block3D> block) { - return this->deleteBlock(block->getX1(), block->getX2(), block->getX3(), block->getLevel()); + return this->deleteBlock(block->getX1(), block->getX2(), block->getX3(), block->getLevel()); } ////////////////////////////////////////////////////////////////////////// bool Grid3D::deleteBlock(int ix1, int ix2, int ix3, int level) { - SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); - if (block) - { - this->blockIdMap.erase(block->getGlobalID()); - return this->levelSet[level].erase(Block3DKey(ix1, ix2, ix3)) > 0; - } - else - { - return false; - } + SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); + if (block) { + this->blockIdMap.erase(block->getGlobalID()); + return this->levelSet[level].erase(Block3DKey(ix1, ix2, ix3)) > 0; + } else { + return false; + } } void Grid3D::deleteBlocks() { - std::vector < std::vector<SPtr<Block3D> > > blocksVector(25); - int minInitLevel = Grid3DSystem::MINLEVEL; - int maxInitLevel = Grid3DSystem::MAXLEVEL; - for (int level = minInitLevel; level < maxInitLevel; level++) - { - getBlocks(level, blocksVector[level]); - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - deleteBlock(block); - } + std::vector<std::vector<SPtr<Block3D>>> blocksVector(25); + int minInitLevel = Grid3DSystem::MINLEVEL; + int maxInitLevel = Grid3DSystem::MAXLEVEL; + for (int level = minInitLevel; level < maxInitLevel; level++) { + getBlocks(level, blocksVector[level]); + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + deleteBlock(block); + } } ////////////////////////////////////////////////////////////////////////// void Grid3D::replaceBlock(SPtr<Block3D> block) { - if (block) - { - this->deleteBlock(block); - this->addBlock(block); - } + if (block) { + this->deleteBlock(block); + this->addBlock(block); + } } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getBlock(int ix1, int ix2, int ix3, int level) const { - if (!this->hasLevel(level)) return SPtr<Block3D>(); - - int N1 = (nx1 << level); - int N2 = (nx2 << level); - int N3 = (nx3 << level); - - if (!this->isPeriodicX1() && (ix1 > N1 - 1 || ix1 < 0)) return SPtr<Block3D>(); - else if (this->isPeriodicX1() && (ix1 >= N1 - 1 || ix1 < 0)) { ix1 = ((ix1 % N1) + N1) % N1; } - if (!this->isPeriodicX2() && (ix2 > N2 - 1 || ix2 < 0)) return SPtr<Block3D>(); - else if (this->isPeriodicX2() && (ix2 >= N2 - 1 || ix2 < 0)) { ix2 = ((ix2 % N2) + N2) % N2; } - if (!this->isPeriodicX3() && (ix3 > N3 - 1 || ix3 < 0)) return SPtr<Block3D>(); - else if (this->isPeriodicX3() && (ix3 >= N3 - 1 || ix3 < 0)) { ix3 = ((ix3 % N3) + N3) % N3; } - - Block3DMap::const_iterator it; - it = levelSet[level].find(Block3DKey(ix1, ix2, ix3)); - if (it == levelSet[level].end()) - return SPtr<Block3D>(); - else - return it->second; + if (!this->hasLevel(level)) + return SPtr<Block3D>(); + + int N1 = (nx1 << level); + int N2 = (nx2 << level); + int N3 = (nx3 << level); + + if (!this->isPeriodicX1() && (ix1 > N1 - 1 || ix1 < 0)) + return SPtr<Block3D>(); + else if (this->isPeriodicX1() && (ix1 >= N1 - 1 || ix1 < 0)) { + ix1 = ((ix1 % N1) + N1) % N1; + } + if (!this->isPeriodicX2() && (ix2 > N2 - 1 || ix2 < 0)) + return SPtr<Block3D>(); + else if (this->isPeriodicX2() && (ix2 >= N2 - 1 || ix2 < 0)) { + ix2 = ((ix2 % N2) + N2) % N2; + } + if (!this->isPeriodicX3() && (ix3 > N3 - 1 || ix3 < 0)) + return SPtr<Block3D>(); + else if (this->isPeriodicX3() && (ix3 >= N3 - 1 || ix3 < 0)) { + ix3 = ((ix3 % N3) + N3) % N3; + } + + Block3DMap::const_iterator it; + it = levelSet[level].find(Block3DKey(ix1, ix2, ix3)); + if (it == levelSet[level].end()) + return SPtr<Block3D>(); + else + return it->second; } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getBlock(int id) const { - BlockIDMap::const_iterator it; - if ((it = blockIdMap.find(id)) == blockIdMap.end()) - { - return SPtr<Block3D>(); - } + BlockIDMap::const_iterator it; + if ((it = blockIdMap.find(id)) == blockIdMap.end()) { + return SPtr<Block3D>(); + } - return it->second; + return it->second; } ////////////////////////////////////////////////////////////////////////// -//const Grid3D::Block3DMap& Grid3D::getBlocks(int level) -//{ +// const Grid3D::Block3DMap& Grid3D::getBlocks(int level) +//{ // return levelSet[level]; //} ////////////////////////////////////////////////////////////////////////// -Grid3D::BlockIDMap& Grid3D::getBlockIDs() -{ - return blockIdMap; -} +Grid3D::BlockIDMap &Grid3D::getBlockIDs() { return blockIdMap; } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getSuperBlock(SPtr<Block3D> block) { - int ix1 = block->getX1(); - int ix2 = block->getX2(); - int ix3 = block->getX3(); - int level = block->getLevel(); - return getSuperBlock(ix1, ix2, ix3, level); + int ix1 = block->getX1(); + int ix2 = block->getX2(); + int ix3 = block->getX3(); + int level = block->getLevel(); + return getSuperBlock(ix1, ix2, ix3, level); } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getSuperBlock(int ix1, int ix2, int ix3, int level) { - if (!this->hasLevel(level)) return SPtr<Block3D>(); - if (level < 1) throw UbException(UB_EXARGS, "level <1"); - - //from Lower Level to higher: >> 1 in x1,x2,x3 - SPtr<Block3D> block; - for (int l = level - 1; l >= 0; l--) - { - ix1 = ix1 >> 1; - ix2 = ix2 >> 1; - ix3 = ix3 >> 1; - - block = this->getBlock(ix1, ix2, ix3, l); - if (block) return block; - } - return SPtr<Block3D>(); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocks(SPtr<Block3D> block, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - int ix1 = block->getX1(); - int ix2 = block->getX2(); - int ix3 = block->getX3(); - int level = block->getLevel(); - getSubBlocks(ix1, ix2, ix3, level, levelDepth, blocks); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocks(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - if (!this->getBlock(ix1, ix2, ix3, level)) return; - if (level > 0 && !this->getSuperBlock(ix1, ix2, ix3, level)) return; - if (level >= Grid3DSystem::MAXLEVEL) throw UbException(UB_EXARGS, "Level bigger then MAXLEVEL"); - - int x1[] = { ix1 << 1, (ix1 << 1) + 1 }; - int x2[] = { ix2 << 1, (ix2 << 1) + 1 }; - int x3[] = { ix3 << 1, (ix3 << 1) + 1 }; - int l = level + 1; - - for (int i = 0; i < 2; i++) - for (int j = 0; j < 2; j++) - for (int k = 0; k < 2; k++) - { - SPtr<Block3D> block = this->getBlock(x1[i], x2[j], x3[k], l); - if (block) blocks.push_back(block); - else if (l < levelDepth) this->getSubBlocks(x1[i], x2[j], x3[k], l, levelDepth, blocks); - } + if (!this->hasLevel(level)) + return SPtr<Block3D>(); + if (level < 1) + throw UbException(UB_EXARGS, "level <1"); + + // from Lower Level to higher: >> 1 in x1,x2,x3 + SPtr<Block3D> block; + for (int l = level - 1; l >= 0; l--) { + ix1 = ix1 >> 1; + ix2 = ix2 >> 1; + ix3 = ix3 >> 1; + + block = this->getBlock(ix1, ix2, ix3, l); + if (block) + return block; + } + return SPtr<Block3D>(); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocks(SPtr<Block3D> block, int levelDepth, std::vector<SPtr<Block3D>> &blocks) +{ + int ix1 = block->getX1(); + int ix2 = block->getX2(); + int ix3 = block->getX3(); + int level = block->getLevel(); + getSubBlocks(ix1, ix2, ix3, level, levelDepth, blocks); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocks(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) +{ + if (!this->getBlock(ix1, ix2, ix3, level)) + return; + if (level > 0 && !this->getSuperBlock(ix1, ix2, ix3, level)) + return; + if (level >= Grid3DSystem::MAXLEVEL) + throw UbException(UB_EXARGS, "Level bigger then MAXLEVEL"); + + int x1[] = { ix1 << 1, (ix1 << 1) + 1 }; + int x2[] = { ix2 << 1, (ix2 << 1) + 1 }; + int x3[] = { ix3 << 1, (ix3 << 1) + 1 }; + int l = level + 1; + + for (int i = 0; i < 2; i++) + for (int j = 0; j < 2; j++) + for (int k = 0; k < 2; k++) { + SPtr<Block3D> block = this->getBlock(x1[i], x2[j], x3[k], l); + if (block) + blocks.push_back(block); + else if (l < levelDepth) + this->getSubBlocks(x1[i], x2[j], x3[k], l, levelDepth, blocks); + } } ////////////////////////////////////////////////////////////////////////// bool Grid3D::expandBlock(int ix1, int ix2, int ix3, int level) { - this->checkLevel(level); - - SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); - if (!block) throw UbException(UB_EXARGS, "block(x1=" + UbSystem::toString(ix1) + ", x2=" + UbSystem::toString(ix2) + ", x3=" + UbSystem::toString(ix3) + ", l=" + UbSystem::toString(level) + ") is not exist"); - //if(!block->isActive()) throw UbException(UB_EXARGS,"block(x1="+UbSystem::toString(ix1)+", x2="+UbSystem::toString(ix2)+", x3="+UbSystem::toString(ix3)+", l="+UbSystem::toString(level)+") is not active"); - - //da bei periodic der eigentliche block andere indizes hat: - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - - int l = level + 1; - if (l > Grid3DSystem::MAXLEVEL) throw UbException(UB_EXARGS, "level > Grid3D::MAXLEVEL"); - - int west = ix1 << 1; - int east = west + 1; - int south = ix2 << 1; - int north = south + 1; - int bottom = ix3 << 1; - int top = bottom + 1; - - auto blockBSW = std::make_shared<Block3D>(west, south, bottom, l); - auto blockBSE = std::make_shared<Block3D>(east, south, bottom, l); - auto blockBNW = std::make_shared<Block3D>(west, north, bottom, l); - auto blockBNE = std::make_shared<Block3D>(east, north, bottom, l); - auto blockTSW = std::make_shared<Block3D>(west, south, top, l); - auto blockTSE = std::make_shared<Block3D>(east, south, top, l); - auto blockTNW = std::make_shared<Block3D>(west, north, top, l); - auto blockTNE = std::make_shared<Block3D>(east, north, top, l); - - if (!this->deleteBlock(ix1, ix2, ix3, level)) - throw UbException(UB_EXARGS, "could not delete block"); - - this->addBlock(blockBSW); - this->addBlock(blockBSE); - this->addBlock(blockBNW); - this->addBlock(blockBNE); - this->addBlock(blockTSW); - this->addBlock(blockTSE); - this->addBlock(blockTNW); - this->addBlock(blockTNE); - - return true; + this->checkLevel(level); + + SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); + if (!block) + throw UbException(UB_EXARGS, "block(x1=" + UbSystem::toString(ix1) + ", x2=" + UbSystem::toString(ix2) + + ", x3=" + UbSystem::toString(ix3) + ", l=" + UbSystem::toString(level) + + ") is not exist"); + // if(!block->isActive()) throw UbException(UB_EXARGS,"block(x1="+UbSystem::toString(ix1)+", + // x2="+UbSystem::toString(ix2)+", x3="+UbSystem::toString(ix3)+", l="+UbSystem::toString(level)+") is not active"); + + // da bei periodic der eigentliche block andere indizes hat: + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + + int l = level + 1; + if (l > Grid3DSystem::MAXLEVEL) + throw UbException(UB_EXARGS, "level > Grid3D::MAXLEVEL"); + + int west = ix1 << 1; + int east = west + 1; + int south = ix2 << 1; + int north = south + 1; + int bottom = ix3 << 1; + int top = bottom + 1; + + auto blockBSW = std::make_shared<Block3D>(west, south, bottom, l); + auto blockBSE = std::make_shared<Block3D>(east, south, bottom, l); + auto blockBNW = std::make_shared<Block3D>(west, north, bottom, l); + auto blockBNE = std::make_shared<Block3D>(east, north, bottom, l); + auto blockTSW = std::make_shared<Block3D>(west, south, top, l); + auto blockTSE = std::make_shared<Block3D>(east, south, top, l); + auto blockTNW = std::make_shared<Block3D>(west, north, top, l); + auto blockTNE = std::make_shared<Block3D>(east, north, top, l); + + if (!this->deleteBlock(ix1, ix2, ix3, level)) + throw UbException(UB_EXARGS, "could not delete block"); + + this->addBlock(blockBSW); + this->addBlock(blockBSE); + this->addBlock(blockBNW); + this->addBlock(blockBNE); + this->addBlock(blockTSW); + this->addBlock(blockTSE); + this->addBlock(blockTNW); + this->addBlock(blockTNE); + + return true; } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::collapseBlock(int fix1, int fix2, int fix3, int flevel, int levelDepth) { - using UbSystem::toString; - - SPtr<Block3D> fblock = this->getBlock(fix1, fix2, fix3, flevel); - if (flevel < 1) throw UbException(UB_EXARGS, "level of block (" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + "," + toString(flevel) + ") is < 1"); - if (!fblock) - { - throw UbException(UB_EXARGS, "specific block(" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + "," + toString(flevel) + ") doesn't exists"); - } - if (!fblock->isActive()) throw UbException(UB_EXARGS, "block(" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + "," + toString(flevel) + ") is not active"); - - //da bei periodic der eigentliche block andere indizes hat: - fix1 = fblock->getX1(); - fix2 = fblock->getX2(); - fix3 = fblock->getX3(); - - int cix1 = fblock->getX1() >> 1; - int cix2 = fblock->getX2() >> 1; - int cix3 = fblock->getX3() >> 1; - - int fx1[2] = { cix1 << 1, (cix1 << 1) + 1 }; - int fx2[2] = { cix2 << 1, (cix2 << 1) + 1 }; - int fx3[2] = { cix3 << 1, (cix3 << 1) + 1 }; - int clevel = flevel - 1; - - vector<SPtr<Block3D>> blocks; - for (int i = 0; i < 2; i++) - for (int k = 0; k < 2; k++) - for (int l = 0; l < 2; l++) - { - this->getSubBlocks(fx1[k], fx2[i], fx3[l], flevel, levelDepth, blocks); - while (!blocks.empty()) - { - //man muss nur eine von den moeglichen acht "collapsen", die anderen werden - //dann (rekursiv) collapsed, da die schleife oben alle vier abfragt - this->collapseBlock(blocks[0]->getX1(), blocks[0]->getX2(), blocks[0]->getX3(), blocks[0]->getLevel(), levelDepth); - this->getSubBlocks(fx1[k], fx2[i], fx3[l], flevel, levelDepth, blocks); + using UbSystem::toString; + + SPtr<Block3D> fblock = this->getBlock(fix1, fix2, fix3, flevel); + if (flevel < 1) + throw UbException(UB_EXARGS, "level of block (" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + + "," + toString(flevel) + ") is < 1"); + if (!fblock) { + throw UbException(UB_EXARGS, "specific block(" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + + "," + toString(flevel) + ") doesn't exists"); + } + if (!fblock->isActive()) + throw UbException(UB_EXARGS, "block(" + toString(fix1) + "," + toString(fix2) + "," + toString(fix3) + "," + + toString(flevel) + ") is not active"); + + // da bei periodic der eigentliche block andere indizes hat: + fix1 = fblock->getX1(); + fix2 = fblock->getX2(); + fix3 = fblock->getX3(); + + int cix1 = fblock->getX1() >> 1; + int cix2 = fblock->getX2() >> 1; + int cix3 = fblock->getX3() >> 1; + + int fx1[2] = { cix1 << 1, (cix1 << 1) + 1 }; + int fx2[2] = { cix2 << 1, (cix2 << 1) + 1 }; + int fx3[2] = { cix3 << 1, (cix3 << 1) + 1 }; + int clevel = flevel - 1; + + vector<SPtr<Block3D>> blocks; + for (int i = 0; i < 2; i++) + for (int k = 0; k < 2; k++) + for (int l = 0; l < 2; l++) { + this->getSubBlocks(fx1[k], fx2[i], fx3[l], flevel, levelDepth, blocks); + while (!blocks.empty()) { + // man muss nur eine von den moeglichen acht "collapsen", die anderen werden + // dann (rekursiv) collapsed, da die schleife oben alle vier abfragt + this->collapseBlock(blocks[0]->getX1(), blocks[0]->getX2(), blocks[0]->getX3(), + blocks[0]->getLevel(), levelDepth); + this->getSubBlocks(fx1[k], fx2[i], fx3[l], flevel, levelDepth, blocks); + } } - } - vector<SPtr<Block3D>> fineBlocks(8); - /*BSW*/fineBlocks[0] = this->getBlock(fx1[0], fx2[0], fx3[0], flevel); - /*BSE*/fineBlocks[1] = this->getBlock(fx1[1], fx2[0], fx3[0], flevel); - /*BNE*/fineBlocks[2] = this->getBlock(fx1[1], fx2[1], fx3[0], flevel); - /*BNW*/fineBlocks[3] = this->getBlock(fx1[0], fx2[1], fx3[0], flevel); - /*TSW*/fineBlocks[4] = this->getBlock(fx1[0], fx2[0], fx3[1], flevel); - /*TSE*/fineBlocks[5] = this->getBlock(fx1[1], fx2[0], fx3[1], flevel); - /*TNE*/fineBlocks[6] = this->getBlock(fx1[1], fx2[1], fx3[1], flevel); - /*TNW*/fineBlocks[7] = this->getBlock(fx1[0], fx2[1], fx3[1], flevel); + vector<SPtr<Block3D>> fineBlocks(8); + /*BSW*/ fineBlocks[0] = this->getBlock(fx1[0], fx2[0], fx3[0], flevel); + /*BSE*/ fineBlocks[1] = this->getBlock(fx1[1], fx2[0], fx3[0], flevel); + /*BNE*/ fineBlocks[2] = this->getBlock(fx1[1], fx2[1], fx3[0], flevel); + /*BNW*/ fineBlocks[3] = this->getBlock(fx1[0], fx2[1], fx3[0], flevel); + /*TSW*/ fineBlocks[4] = this->getBlock(fx1[0], fx2[0], fx3[1], flevel); + /*TSE*/ fineBlocks[5] = this->getBlock(fx1[1], fx2[0], fx3[1], flevel); + /*TNE*/ fineBlocks[6] = this->getBlock(fx1[1], fx2[1], fx3[1], flevel); + /*TNW*/ fineBlocks[7] = this->getBlock(fx1[0], fx2[1], fx3[1], flevel); - auto cblock = std::make_shared<Block3D>(cix1, cix2, cix3, clevel); + auto cblock = std::make_shared<Block3D>(cix1, cix2, cix3, clevel); - for (int i = 0; i < 2; i++) - for (int k = 0; k < 2; k++) - for (int l = 0; l < 2; l++) - if (!this->deleteBlock(fx1[k], fx2[i], fx3[l], flevel)) - throw UbException(UB_EXARGS, "could not delete block"); + for (int i = 0; i < 2; i++) + for (int k = 0; k < 2; k++) + for (int l = 0; l < 2; l++) + if (!this->deleteBlock(fx1[k], fx2[i], fx3[l], flevel)) + throw UbException(UB_EXARGS, "could not delete block"); - this->addBlock(cblock); + this->addBlock(cblock); - return cblock; + return cblock; } ////////////////////////////////////////////////////////////////////////// // TODO: make visitor for this void Grid3D::deleteConnectors() { - for (Block3DMap blockMap : levelSet) - { - for (Block3DMap::value_type b : blockMap) - { - SPtr<Block3D> block = b.second; - block->deleteConnectors(); - //block->deleteInterpolationConnectors(); - } - } + for (Block3DMap blockMap : levelSet) { + for (Block3DMap::value_type b : blockMap) { + SPtr<Block3D> block = b.second; + block->deleteConnectors(); + // block->deleteInterpolationConnectors(); + } + } } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setRank(int rank) -{ - this->rank = rank; -} +void Grid3D::setRank(int rank) { this->rank = rank; } ////////////////////////////////////////////////////////////////////////// -int Grid3D::getRank() const -{ - return rank; -} +int Grid3D::getRank() const { return rank; } ////////////////////////////////////////////////////////////////////////// -int Grid3D::getBundle() const -{ - return bundle; -} +int Grid3D::getBundle() const { return bundle; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setBundle(int bundle) -{ - this->bundle = bundle; -} +void Grid3D::setBundle(int bundle) { this->bundle = bundle; } ////////////////////////////////////////////////////////////////////////// -bool Grid3D::isPeriodicX1() const -{ - return this->periodicX1; -} +bool Grid3D::isPeriodicX1() const { return this->periodicX1; } ////////////////////////////////////////////////////////////////////////// -bool Grid3D::isPeriodicX2() const -{ - return this->periodicX2; -} +bool Grid3D::isPeriodicX2() const { return this->periodicX2; } ////////////////////////////////////////////////////////////////////////// -bool Grid3D::isPeriodicX3() const -{ - return this->periodicX3; -} +bool Grid3D::isPeriodicX3() const { return this->periodicX3; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setPeriodicX1(bool value) -{ - this->periodicX1 = value; -} +void Grid3D::setPeriodicX1(bool value) { this->periodicX1 = value; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setPeriodicX2(bool value) -{ - this->periodicX2 = value; -} +void Grid3D::setPeriodicX2(bool value) { this->periodicX2 = value; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setPeriodicX3(bool value) -{ - this->periodicX3 = value; -} +void Grid3D::setPeriodicX3(bool value) { this->periodicX3 = value; } ////////////////////////////////////////////////////////////////////////// -UbTupleInt3 Grid3D::getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord) const +UbTupleInt3 Grid3D::getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord) const { - if (!trafo) - { - return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); - } - - return makeUbTuple((int)trafo->transformForwardToX1Coordinate(blockX1Coord, blockX2Coord, blockX3Coord) - , (int)trafo->transformForwardToX2Coordinate(blockX1Coord, blockX2Coord, blockX3Coord) - , (int)trafo->transformForwardToX3Coordinate(blockX1Coord, blockX2Coord, blockX3Coord)); + if (!trafo) { + return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); + } + return makeUbTuple((int)trafo->transformForwardToX1Coordinate(blockX1Coord, blockX2Coord, blockX3Coord), + (int)trafo->transformForwardToX2Coordinate(blockX1Coord, blockX2Coord, blockX3Coord), + (int)trafo->transformForwardToX3Coordinate(blockX1Coord, blockX2Coord, blockX3Coord)); } ////////////////////////////////////////////////////////////////////////// -UbTupleInt3 Grid3D::getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord, int level) const +UbTupleInt3 Grid3D::getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord, int level) const { - if (!trafo) - { - return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); - } - - double dx = getDeltaX(level); - double blockLentghX1, blockLentghX2, blockLentghX3; - blockLentghX1 = blockNx1 * dx; - blockLentghX2 = blockNx2 * dx; - blockLentghX3 = blockNx3 * dx; - UbTupleDouble3 org = getBlockWorldCoordinates(0, 0, 0, 0); + if (!trafo) { + return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); + } - SPtr<CoordinateTransformation3D> trafo_temp(new CoordinateTransformation3D(val<1>(org), val<2>(org), val<3>(org), blockLentghX1, blockLentghX2, blockLentghX3)); + double dx = getDeltaX(level); + double blockLentghX1, blockLentghX2, blockLentghX3; + blockLentghX1 = blockNx1 * dx; + blockLentghX2 = blockNx2 * dx; + blockLentghX3 = blockNx3 * dx; + UbTupleDouble3 org = getBlockWorldCoordinates(0, 0, 0, 0); - if (!trafo_temp) - { - return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); - } + SPtr<CoordinateTransformation3D> trafo_temp(new CoordinateTransformation3D( + val<1>(org), val<2>(org), val<3>(org), blockLentghX1, blockLentghX2, blockLentghX3)); - return makeUbTuple((int)trafo_temp->transformForwardToX1Coordinate(blockX1Coord, blockX2Coord, blockX3Coord) - , (int)trafo_temp->transformForwardToX2Coordinate(blockX1Coord, blockX2Coord, blockX3Coord) - , (int)trafo_temp->transformForwardToX3Coordinate(blockX1Coord, blockX2Coord, blockX3Coord)); + if (!trafo_temp) { + return makeUbTuple((int)blockX1Coord, (int)blockX2Coord, (int)blockX3Coord); + } + return makeUbTuple((int)trafo_temp->transformForwardToX1Coordinate(blockX1Coord, blockX2Coord, blockX3Coord), + (int)trafo_temp->transformForwardToX2Coordinate(blockX1Coord, blockX2Coord, blockX3Coord), + (int)trafo_temp->transformForwardToX3Coordinate(blockX1Coord, blockX2Coord, blockX3Coord)); } ////////////////////////////////////////////////////////////////////////// -UbTupleDouble3 Grid3D::getBlockLengths(const SPtr<Block3D> block) const +UbTupleDouble3 Grid3D::getBlockLengths(const SPtr<Block3D> block) const { - int level = block->getLevel(); - double delta = 1.0 / (double)(1 << level); + int level = block->getLevel(); + double delta = 1.0 / (double)(1 << level); - if (!trafo) makeUbTuple<double, double, double>(delta, delta, delta); + if (!trafo) + makeUbTuple<double, double, double>(delta, delta, delta); - return makeUbTuple(trafo->getX1CoordinateScaling() * delta, - trafo->getX2CoordinateScaling() * delta, - trafo->getX3CoordinateScaling() * delta); + return makeUbTuple(trafo->getX1CoordinateScaling() * delta, trafo->getX2CoordinateScaling() * delta, + trafo->getX3CoordinateScaling() * delta); } ////////////////////////////////////////////////////////////////////////// -UbTupleDouble6 Grid3D::getBlockOversize() const -{ - return makeUbTuple(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); -} +UbTupleDouble6 Grid3D::getBlockOversize() const { return makeUbTuple(0.0, 0.0, 0.0, 0.0, 0.0, 0.0); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setCoordinateTransformator(SPtr<CoordinateTransformation3D> trafo) -{ - this->trafo = trafo; -} +void Grid3D::setCoordinateTransformator(SPtr<CoordinateTransformation3D> trafo) { this->trafo = trafo; } ////////////////////////////////////////////////////////////////////////// -const SPtr<CoordinateTransformation3D> Grid3D::getCoordinateTransformator() const -{ - return this->trafo; -} +const SPtr<CoordinateTransformation3D> Grid3D::getCoordinateTransformator() const { return this->trafo; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setDeltaX(double dx) -{ - this->orgDeltaX = dx; -} +void Grid3D::setDeltaX(double dx) { this->orgDeltaX = dx; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setDeltaX(double worldUnit, double gridUnit) -{ - this->orgDeltaX = worldUnit / gridUnit; -} +void Grid3D::setDeltaX(double worldUnit, double gridUnit) { this->orgDeltaX = worldUnit / gridUnit; } ////////////////////////////////////////////////////////////////////////// double Grid3D::getDeltaX(int level) const { - double delta = this->orgDeltaX / (double)(1 << level); - return delta; + double delta = this->orgDeltaX / (double)(1 << level); + return delta; } ////////////////////////////////////////////////////////////////////////// -double Grid3D::getDeltaX(SPtr<Block3D> block) const -{ - return getDeltaX(block->getLevel()); -} +double Grid3D::getDeltaX(SPtr<Block3D> block) const { return getDeltaX(block->getLevel()); } ////////////////////////////////////////////////////////////////////////// -UbTupleDouble3 Grid3D::getNodeOffset(SPtr<Block3D> block) const +UbTupleDouble3 Grid3D::getNodeOffset(SPtr<Block3D> block) const { - double delta = this->getDeltaX(block); - return makeUbTuple(OFFSET * delta, OFFSET * delta, OFFSET * delta); + double delta = this->getDeltaX(block); + return makeUbTuple(OFFSET * delta, OFFSET * delta, OFFSET * delta); } //////////////////////////////////////////////////////////////////////////// Vector3D Grid3D::getNodeCoordinates(SPtr<Block3D> block, int ix1, int ix2, int ix3) const { - UbTupleDouble3 org = this->getBlockWorldCoordinates(block); - UbTupleDouble3 nodeOffset = this->getNodeOffset(block); - double deltaX = getDeltaX(block); + UbTupleDouble3 org = this->getBlockWorldCoordinates(block); + UbTupleDouble3 nodeOffset = this->getNodeOffset(block); + double deltaX = getDeltaX(block); - double x1 = val<1>(org) - val<1>(nodeOffset) + (double)ix1 * deltaX; - double x2 = val<2>(org) - val<2>(nodeOffset) + (double)ix2 * deltaX; - double x3 = val<3>(org) - val<3>(nodeOffset) + (double)ix3 * deltaX; + double x1 = val<1>(org) - val<1>(nodeOffset) + (double)ix1 * deltaX; + double x2 = val<2>(org) - val<2>(nodeOffset) + (double)ix2 * deltaX; + double x3 = val<3>(org) - val<3>(nodeOffset) + (double)ix3 * deltaX; - return Vector3D(x1, x2, x3); + return Vector3D(x1, x2, x3); } //////////////////////////////////////////////////////////////////////////// -UbTupleInt3 Grid3D::getNodeIndexes(SPtr<Block3D> block, double nodeX1Coord, double nodeX2Coord, double nodeX3Coord) const -{ - UbTupleDouble3 org = this->getBlockWorldCoordinates(block); - UbTupleDouble3 nodeOffset = this->getNodeOffset(block); - double deltaX = getDeltaX(block); - - int ix1, ix2, ix3; - double ixx1 = (abs(nodeX1Coord - val<1>(org) + val<1>(nodeOffset)) / deltaX); - double ixx2 = (abs(nodeX2Coord - val<2>(org) + val<2>(nodeOffset)) / deltaX); - double ixx3 = (abs(nodeX3Coord - val<3>(org) + val<3>(nodeOffset)) / deltaX); - if (ixx1 - (int)ixx1 > .9999999999) ix1 = (int)ixx1 + 1; else ix1 = (int)ixx1; - if (ixx2 - (int)ixx2 > .9999999999) ix2 = (int)ixx2 + 1; else ix2 = (int)ixx2; - if (ixx3 - (int)ixx3 > .9999999999) ix3 = (int)ixx3 + 1; else ix3 = (int)ixx3; - - return makeUbTuple(ix1, ix2, ix3); -} -////////////////////////////////////////////////////////////////////////// -//returns tuple with origin of block in world-coordinates +UbTupleInt3 Grid3D::getNodeIndexes(SPtr<Block3D> block, double nodeX1Coord, double nodeX2Coord, + double nodeX3Coord) const +{ + UbTupleDouble3 org = this->getBlockWorldCoordinates(block); + UbTupleDouble3 nodeOffset = this->getNodeOffset(block); + double deltaX = getDeltaX(block); + + int ix1, ix2, ix3; + double ixx1 = (abs(nodeX1Coord - val<1>(org) + val<1>(nodeOffset)) / deltaX); + double ixx2 = (abs(nodeX2Coord - val<2>(org) + val<2>(nodeOffset)) / deltaX); + double ixx3 = (abs(nodeX3Coord - val<3>(org) + val<3>(nodeOffset)) / deltaX); + if (ixx1 - (int)ixx1 > .9999999999) + ix1 = (int)ixx1 + 1; + else + ix1 = (int)ixx1; + if (ixx2 - (int)ixx2 > .9999999999) + ix2 = (int)ixx2 + 1; + else + ix2 = (int)ixx2; + if (ixx3 - (int)ixx3 > .9999999999) + ix3 = (int)ixx3 + 1; + else + ix3 = (int)ixx3; + + return makeUbTuple(ix1, ix2, ix3); +} +////////////////////////////////////////////////////////////////////////// +// returns tuple with origin of block in world-coordinates UbTupleDouble3 Grid3D::getBlockWorldCoordinates(SPtr<Block3D> block) const { - if (!block) - throw UbException(UB_EXARGS, "block " + block->toString() + "is not exist"); + if (!block) + throw UbException(UB_EXARGS, "block " + block->toString() + "is not exist"); - int blockX1Index = block->getX1(); - int blockX2Index = block->getX2(); - int blockX3Index = block->getX3(); - int level = block->getLevel(); + int blockX1Index = block->getX1(); + int blockX2Index = block->getX2(); + int blockX3Index = block->getX3(); + int level = block->getLevel(); - return this->getBlockWorldCoordinates(blockX1Index, blockX2Index, blockX3Index, level); + return this->getBlockWorldCoordinates(blockX1Index, blockX2Index, blockX3Index, level); } ////////////////////////////////////////////////////////////////////////// UbTupleDouble3 Grid3D::getBlockWorldCoordinates(int blockX1Index, int blockX2Index, int blockX3Index, int level) const { - double c1oShiftedLevel = 1.0 / (double)(1 << level); - double x1 = (double)blockX1Index * c1oShiftedLevel; - double x2 = (double)blockX2Index * c1oShiftedLevel; - double x3 = (double)blockX3Index * c1oShiftedLevel; + double c1oShiftedLevel = 1.0 / (double)(1 << level); + double x1 = (double)blockX1Index * c1oShiftedLevel; + double x2 = (double)blockX2Index * c1oShiftedLevel; + double x3 = (double)blockX3Index * c1oShiftedLevel; - if (!trafo) - return { x1, x2, x3 }; + if (!trafo) + return { x1, x2, x3 }; - return {trafo->transformBackwardToX1Coordinate(x1, x2, x3) - , trafo->transformBackwardToX2Coordinate(x1, x2, x3) - , trafo->transformBackwardToX3Coordinate(x1, x2, x3) }; + return { trafo->transformBackwardToX1Coordinate(x1, x2, x3), trafo->transformBackwardToX2Coordinate(x1, x2, x3), + trafo->transformBackwardToX3Coordinate(x1, x2, x3) }; } ////////////////////////////////////////////////////////////////////////// -//double Grid3D::getDeltaT(SPtr<Block3D> block) const -//{ +// double Grid3D::getDeltaT(SPtr<Block3D> block) const +//{ // int level = block->getLevel(); // double delta = 1.0/(double)(1<<level); -// return delta; +// return delta; //} ////////////////////////////////////////////////////////////////////////// void Grid3D::checkLevel(int level) { - if (level < 0) - { - throw UbException(UB_EXARGS, "l(" + UbSystem::toString(level) + (string)")<0"); - } - if (level > Grid3DSystem::MAXLEVEL) - { - throw UbException(UB_EXARGS, "l(" + UbSystem::toString(level) + (string)")>MAXLEVEL"); - } - if (this->levelSet[level].size() == 0) - { - throw UbException(UB_EXARGS, "levelMap for level(" + UbSystem::toString(level) + (string)")==NULL"); - } + if (level < 0) { + throw UbException(UB_EXARGS, "l(" + UbSystem::toString(level) + (string) ")<0"); + } + if (level > Grid3DSystem::MAXLEVEL) { + throw UbException(UB_EXARGS, "l(" + UbSystem::toString(level) + (string) ")>MAXLEVEL"); + } + if (this->levelSet[level].size() == 0) { + throw UbException(UB_EXARGS, "levelMap for level(" + UbSystem::toString(level) + (string) ")==NULL"); + } } ////////////////////////////////////////////////////////////////////////// bool Grid3D::hasLevel(int level) const { - if (level < 0) return false; - if (level > Grid3DSystem::MAXLEVEL) return false; - if (this->levelSet[level].size() == 0) return false; + if (level < 0) + return false; + if (level > Grid3DSystem::MAXLEVEL) + return false; + if (this->levelSet[level].size() == 0) + return false; - return true; + return true; } ////////////////////////////////////////////////////////////////////////// void Grid3D::setBlockNX(int nx1, int nx2, int nx3) { - blockNx1 = nx1; - blockNx2 = nx2; - blockNx3 = nx3; + blockNx1 = nx1; + blockNx2 = nx2; + blockNx3 = nx3; } ////////////////////////////////////////////////////////////////////////// -UbTupleInt3 Grid3D::getBlockNX() const -{ - return makeUbTuple(blockNx1, blockNx2, blockNx3); -} +UbTupleInt3 Grid3D::getBlockNX() const { return makeUbTuple(blockNx1, blockNx2, blockNx3); } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getNeighborBlock(int dir, int ix1, int ix2, int ix3, int level) const { - return this->getBlock(ix1 + Grid3DSystem::EX1[dir], ix2 + Grid3DSystem::EX2[dir], ix3 + Grid3DSystem::EX3[dir], level); + return this->getBlock(ix1 + Grid3DSystem::EX1[dir], ix2 + Grid3DSystem::EX2[dir], ix3 + Grid3DSystem::EX3[dir], + level); } ////////////////////////////////////////////////////////////////////////// SPtr<Block3D> Grid3D::getNeighborBlock(int dir, SPtr<Block3D> block) const { - int x1 = block->getX1(); - int x2 = block->getX2(); - int x3 = block->getX3(); - int level = block->getLevel(); - return this->getNeighborBlock(dir, x1, x2, x3, level); + int x1 = block->getX1(); + int x2 = block->getX2(); + int x3 = block->getX3(); + int level = block->getLevel(); + return this->getNeighborBlock(dir, x1, x2, x3, level); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getAllNeighbors(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +void Grid3D::getAllNeighbors(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - for (int dir = Grid3DSystem::STARTDIR; dir <= Grid3DSystem::ENDDIR; dir++) - //for (int dir = Grid3DSystem::STARTDIR; dir<=Grid3DSystem::TS; dir++) - { - this->getNeighborBlocksForDirection(dir, ix1, ix2, ix3, level, levelDepth, blocks); - } + for (int dir = Grid3DSystem::STARTDIR; dir <= Grid3DSystem::ENDDIR; dir++) + // for (int dir = Grid3DSystem::STARTDIR; dir<=Grid3DSystem::TS; dir++) + { + this->getNeighborBlocksForDirection(dir, ix1, ix2, ix3, level, levelDepth, blocks); + } } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getAllNeighbors(SPtr<Block3D> block, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +void Grid3D::getAllNeighbors(SPtr<Block3D> block, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - int x1 = block->getX1(); - int x2 = block->getX2(); - int x3 = block->getX3(); - getAllNeighbors(x1, x2, x3, level, levelDepth, blocks); + int x1 = block->getX1(); + int x2 = block->getX2(); + int x3 = block->getX3(); + getAllNeighbors(x1, x2, x3, level, levelDepth, blocks); } ////////////////////////////////////////////////////////////////////////// - /** - * Returns all direct northern neighbor cells of the specified grid cell (may be NULL!). - * @param ix1 index in x1 direction - * @param ix2 index in x2 direction - * @param ix3 index in x3 direction - * @param level the level - */ -void Grid3D::getNeighborsNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +/** + * Returns all direct northern neighbor cells of the specified grid cell (may be NULL!). + * @param ix1 index in x1 direction + * @param ix2 index in x2 direction + * @param ix3 index in x3 direction + * @param level the level + */ +void Grid3D::getNeighborsNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } + SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksSouth(ix1, ix2 + 1, ix3, level, blocks, levelDepth); + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksSouth(ix1, ix2 + 1, ix3, level, blocks, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTop(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +void Grid3D::getNeighborsTop(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } + SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottom(ix1, ix2, ix3 + 1, level, blocks, levelDepth); + if (level > 0) { + block = this->getSuperBlock(ix1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottom(ix1, ix2, ix3 + 1, level, blocks, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottom(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +void Grid3D::getNeighborsBottom(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) { - SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } + SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } - } - this->getSubBlocksTop(ix1, ix2, ix3 - 1, level, blocks, levelDepth); -} + if (level > 0) { + block = this->getSuperBlock(ix1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTop(ix1, ix2, ix3 - 1, level, blocks, levelDepth); +} ////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) +void Grid3D::getNeighborsSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } + SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } - } - this->getSubBlocksNorth(ix1, ix2 - 1, ix3, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksNorth(ix1, ix2 - 1, ix3, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) { - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksWest(ix1 + 1, ix2, ix3, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3, level); - if (block) { blocks.push_back(block); } + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksWest(ix1 + 1, ix2, ix3, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksEast(ix1 - 1, ix2, ix3, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +// diagonals +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksEast(ix1 - 1, ix2, ix3, level, blocks, levelDepth); + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksSouthWest(ix1 + 1, ix2 + 1, ix3, level, blocks, levelDepth); } -////////////////////////////////////////////////////////////////////////// -// diagonals -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksSouthWest(ix1 + 1, ix2 + 1, ix3, level, blocks, levelDepth); +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksSouthEast(ix1 - 1, ix2 + 1, ix3, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksNorthWest(ix1 + 1, ix2 - 1, ix3, level, blocks, levelDepth); } -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksNorthEast(ix1 - 1, ix2 - 1, ix3, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +// diagonals top +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksSouthEast(ix1 - 1, ix2 + 1, ix3, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksNorthWest(ix1 + 1, ix2 - 1, ix3, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksNorthEast(ix1 - 1, ix2 - 1, ix3, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -// diagonals top -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomWest(ix1 + 1, ix2, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomEast(ix1 - 1, ix2, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomSouth(ix1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomNorth(ix1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -// diagonals bottom -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopWest(ix1 + 1, ix2, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopEast(ix1 - 1, ix2, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomWest(ix1 + 1, ix2, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopSouth(ix1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopNorth(ix1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomSouthWest(ix1 + 1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomSouthEast(ix1 - 1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomNorthWest(ix1 + 1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsTopSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3 + 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksBottomNorthEast(ix1 - 1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopSouthWest(ix1 + 1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopSouthEast(ix1 - 1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopNorthWest(ix1 + 1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsBottomSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3 - 1, level); - if (block) { blocks.push_back(block); } - } - this->getSubBlocksTopNorthEast(ix1 - 1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborBlocksForDirection(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - switch (dir) - { - case Grid3DSystem::E: this->getNeighborsEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::W: this->getNeighborsWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::N: this->getNeighborsNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::S: this->getNeighborsSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::T: this->getNeighborsTop(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::B: this->getNeighborsBottom(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::NE: this->getNeighborsNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::SW: this->getNeighborsSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::SE: this->getNeighborsSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::NW: this->getNeighborsNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TE: this->getNeighborsTopEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BW: this->getNeighborsBottomWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BE: this->getNeighborsBottomEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TW: this->getNeighborsTopWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TN: this->getNeighborsTopNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BS: this->getNeighborsBottomSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BN: this->getNeighborsBottomNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TS: this->getNeighborsTopSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TNE: this->getNeighborsTopNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TNW: this->getNeighborsTopNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TSE: this->getNeighborsTopSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TSW: this->getNeighborsTopSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BNE: this->getNeighborsBottomNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BNW: this->getNeighborsBottomNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BSE: this->getNeighborsBottomSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BSW: this->getNeighborsBottomSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - default:throw UbException(UB_EXARGS, "direction " + UbSystem::toString(dir) + " is not exist"); - } -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborsZero(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); - if (block) { blocks.push_back(block); } - - if (level > 0) - { - block = this->getSuperBlock(ix1, ix2, ix3, level); - if (block) { blocks.push_back(block); } - } - // this->getSubBlocksNull(ix1, ix2, ix3, level, blocks, levelDepth); - this->getSubBlocks(ix1, ix2, ix3, level, levelDepth, blocks); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksZero(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1E = (ix1 << 1) + 1; - int x1W = (ix1 << 1); - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3B = ix3 << 1; - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1E, x2S, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1E, x2S, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2N, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1E, x2N, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2S, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1E, x2S, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2N, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1E, x2N, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2S, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1W, x2S, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2N, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1W, x2N, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2S, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1W, x2S, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2N, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1W, x2N, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getNeighborBlocksForDirectionWithDirZero(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks) -{ - switch (dir) - { - case Grid3DSystem::E: this->getNeighborsEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::W: this->getNeighborsWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::N: this->getNeighborsNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::S: this->getNeighborsSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::T: this->getNeighborsTop(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::B: this->getNeighborsBottom(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::NE: this->getNeighborsNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::SW: this->getNeighborsSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::SE: this->getNeighborsSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::NW: this->getNeighborsNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TE: this->getNeighborsTopEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BW: this->getNeighborsBottomWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BE: this->getNeighborsBottomEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TW: this->getNeighborsTopWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TN: this->getNeighborsTopNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BS: this->getNeighborsBottomSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BN: this->getNeighborsBottomNorth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TS: this->getNeighborsTopSouth(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TNE: this->getNeighborsTopNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TNW: this->getNeighborsTopNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TSE: this->getNeighborsTopSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::TSW: this->getNeighborsTopSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BNE: this->getNeighborsBottomNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BNW: this->getNeighborsBottomNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BSE: this->getNeighborsBottomSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::BSW: this->getNeighborsBottomSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); break; - case Grid3DSystem::ZERO: this->getNeighborsZero(ix1, ix2, ix3, level, levelDepth, blocks); break; - default:throw UbException(UB_EXARGS, "direction " + UbSystem::toString(dir) + " is not exist"); - } -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = (ix1 << 1) + 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3B = ix3 << 1; - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1, x2S, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1, x2S, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2N, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1, x2N, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2S, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1, x2S, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2N, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksEast(x1, x2N, x3T, l, blockVector, levelDepth); -} - -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = ix1 << 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3B = ix3 << 1; - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1, x2S, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksWest(x1, x2S, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2N, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksWest(x1, x2N, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2S, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksWest(x1, x2S, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1, x2N, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksWest(x1, x2N, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1W = ix1 << 1; - int x1E = x1W + 1; - int x2 = (ix2 << 1) + 1; - int x3B = ix3 << 1; - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1W, x2, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksNorth(x1W, x2, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksNorth(x1E, x2, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksNorth(x1W, x2, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksNorth(x1E, x2, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1W = ix1 << 1; - int x1E = x1W + 1; - int x2 = ix2 << 1; - int x3B = ix3 << 1; - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1W, x2, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksSouth(x1W, x2, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2, x3B, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksSouth(x1E, x2, x3B, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksSouth(x1W, x2, x3T, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2, x3T, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksSouth(x1E, x2, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTop(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1W = ix1 << 1; - int x1E = x1W + 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1W, x2N, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksTop(x1W, x2N, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2N, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksTop(x1E, x2N, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2S, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksTop(x1W, x2S, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2S, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksTop(x1E, x2S, x3, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottom(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1W = ix1 << 1; - int x1E = x1W + 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3 = ix3 << 1; - int l = level + 1; - - SPtr<Block3D> block = this->getBlock(x1W, x2N, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksBottom(x1W, x2N, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2N, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksBottom(x1E, x2N, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1W, x2S, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksBottom(x1W, x2S, x3, l, blockVector, levelDepth); - - block = this->getBlock(x1E, x2S, x3, l); - if (block != NULL) blockVector.push_back(block); - else if (l < levelDepth) this->getSubBlocksBottom(x1E, x2S, x3, l, blockVector, levelDepth); + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomEast(ix1 - 1, ix2, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopNorth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomSouth(ix1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopSouth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomNorth(ix1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +// diagonals bottom +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopWest(ix1 + 1, ix2, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopEast(ix1 - 1, ix2, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomNorth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopSouth(ix1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomSouth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopNorth(ix1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomSouthWest(ix1 + 1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomSouthEast(ix1 - 1, ix2 + 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomNorthWest(ix1 + 1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsTopSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3 + 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksBottomNorthEast(ix1 - 1, ix2 - 1, ix3 + 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopSouthWest(ix1 + 1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 + 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopSouthEast(ix1 - 1, ix2 + 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 + 1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 + 1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopNorthWest(ix1 + 1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsBottomSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1 - 1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1 - 1, ix2 - 1, ix3 - 1, level); + if (block) { + blocks.push_back(block); + } + } + this->getSubBlocksTopNorthEast(ix1 - 1, ix2 - 1, ix3 - 1, level, blocks, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborBlocksForDirection(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + switch (dir) { + case Grid3DSystem::E: + this->getNeighborsEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::W: + this->getNeighborsWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::N: + this->getNeighborsNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::S: + this->getNeighborsSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::T: + this->getNeighborsTop(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::B: + this->getNeighborsBottom(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::NE: + this->getNeighborsNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::SW: + this->getNeighborsSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::SE: + this->getNeighborsSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::NW: + this->getNeighborsNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TE: + this->getNeighborsTopEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BW: + this->getNeighborsBottomWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BE: + this->getNeighborsBottomEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TW: + this->getNeighborsTopWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TN: + this->getNeighborsTopNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BS: + this->getNeighborsBottomSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BN: + this->getNeighborsBottomNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TS: + this->getNeighborsTopSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TNE: + this->getNeighborsTopNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TNW: + this->getNeighborsTopNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TSE: + this->getNeighborsTopSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TSW: + this->getNeighborsTopSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BNE: + this->getNeighborsBottomNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BNW: + this->getNeighborsBottomNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BSE: + this->getNeighborsBottomSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BSW: + this->getNeighborsBottomSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + default: + throw UbException(UB_EXARGS, "direction " + UbSystem::toString(dir) + " is not exist"); + } +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborsZero(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks) +{ + SPtr<Block3D> block = this->getBlock(ix1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + + if (level > 0) { + block = this->getSuperBlock(ix1, ix2, ix3, level); + if (block) { + blocks.push_back(block); + } + } + // this->getSubBlocksNull(ix1, ix2, ix3, level, blocks, levelDepth); + this->getSubBlocks(ix1, ix2, ix3, level, levelDepth, blocks); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksZero(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1E = (ix1 << 1) + 1; + int x1W = (ix1 << 1); + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3B = ix3 << 1; + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1E, x2S, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1E, x2S, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2N, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1E, x2N, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2S, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1E, x2S, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2N, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1E, x2N, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2S, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1W, x2S, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2N, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1W, x2N, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2S, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1W, x2S, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2N, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1W, x2N, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getNeighborBlocksForDirectionWithDirZero(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks) +{ + switch (dir) { + case Grid3DSystem::E: + this->getNeighborsEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::W: + this->getNeighborsWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::N: + this->getNeighborsNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::S: + this->getNeighborsSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::T: + this->getNeighborsTop(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::B: + this->getNeighborsBottom(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::NE: + this->getNeighborsNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::SW: + this->getNeighborsSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::SE: + this->getNeighborsSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::NW: + this->getNeighborsNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TE: + this->getNeighborsTopEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BW: + this->getNeighborsBottomWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BE: + this->getNeighborsBottomEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TW: + this->getNeighborsTopWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TN: + this->getNeighborsTopNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BS: + this->getNeighborsBottomSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BN: + this->getNeighborsBottomNorth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TS: + this->getNeighborsTopSouth(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TNE: + this->getNeighborsTopNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TNW: + this->getNeighborsTopNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TSE: + this->getNeighborsTopSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::TSW: + this->getNeighborsTopSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BNE: + this->getNeighborsBottomNorthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BNW: + this->getNeighborsBottomNorthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BSE: + this->getNeighborsBottomSouthEast(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::BSW: + this->getNeighborsBottomSouthWest(ix1, ix2, ix3, level, levelDepth, blocks); + break; + case Grid3DSystem::ZERO: + this->getNeighborsZero(ix1, ix2, ix3, level, levelDepth, blocks); + break; + default: + throw UbException(UB_EXARGS, "direction " + UbSystem::toString(dir) + " is not exist"); + } +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1 = (ix1 << 1) + 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3B = ix3 << 1; + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1, x2S, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1, x2S, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2N, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1, x2N, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2S, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1, x2S, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2N, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksEast(x1, x2N, x3T, l, blockVector, levelDepth); +} + +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1 = ix1 << 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3B = ix3 << 1; + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1, x2S, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksWest(x1, x2S, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2N, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksWest(x1, x2N, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2S, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksWest(x1, x2S, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1, x2N, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksWest(x1, x2N, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1W = ix1 << 1; + int x1E = x1W + 1; + int x2 = (ix2 << 1) + 1; + int x3B = ix3 << 1; + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1W, x2, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksNorth(x1W, x2, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksNorth(x1E, x2, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksNorth(x1W, x2, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksNorth(x1E, x2, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1W = ix1 << 1; + int x1E = x1W + 1; + int x2 = ix2 << 1; + int x3B = ix3 << 1; + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1W, x2, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksSouth(x1W, x2, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2, x3B, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksSouth(x1E, x2, x3B, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksSouth(x1W, x2, x3T, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2, x3T, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksSouth(x1E, x2, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksTop(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, int levelDepth) +{ + int x1W = ix1 << 1; + int x1E = x1W + 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1W, x2N, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksTop(x1W, x2N, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2N, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksTop(x1E, x2N, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2S, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksTop(x1W, x2S, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2S, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksTop(x1E, x2S, x3, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksBottom(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1W = ix1 << 1; + int x1E = x1W + 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3 = ix3 << 1; + int l = level + 1; + + SPtr<Block3D> block = this->getBlock(x1W, x2N, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksBottom(x1W, x2N, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2N, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksBottom(x1E, x2N, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1W, x2S, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksBottom(x1W, x2S, x3, l, blockVector, levelDepth); + + block = this->getBlock(x1E, x2S, x3, l); + if (block != NULL) + blockVector.push_back(block); + else if (l < levelDepth) + this->getSubBlocksBottom(x1E, x2S, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// // diagonals ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksNorthEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = (ix1 << 1) + 1; - int x2 = (ix2 << 1) + 1; - int x3B = (ix3 << 1); - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); - if (blockB) blockVector.push_back(blockB); - else if (l < levelDepth) this->getSubBlocksNorthEast(x1, x2, x3B, l, blockVector, levelDepth); - - SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); - if (blockT) blockVector.push_back(blockT); - else if (l < levelDepth) this->getSubBlocksNorthEast(x1, x2, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksNorthWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = (ix1 << 1); - int x2 = (ix2 << 1) + 1; - int x3B = (ix3 << 1); - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); - if (blockB) blockVector.push_back(blockB); - else if (l < levelDepth) this->getSubBlocksNorthWest(x1, x2, x3B, l, blockVector, levelDepth); - - SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); - if (blockT) blockVector.push_back(blockT); - else if (l < levelDepth) this->getSubBlocksNorthWest(x1, x2, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksSouthWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = ix1 << 1; - int x2 = ix2 << 1; - int x3B = (ix3 << 1); - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); - if (blockB) blockVector.push_back(blockB); - else if (l < levelDepth) this->getSubBlocksSouthWest(x1, x2, x3B, l, blockVector, levelDepth); - - SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); - if (blockT) blockVector.push_back(blockT); - else if (l < levelDepth) this->getSubBlocksSouthWest(x1, x2, x3T, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksSouthEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1 = (ix1 << 1) + 1; - int x2 = ix2 << 1; - int x3B = (ix3 << 1); - int x3T = x3B + 1; - int l = level + 1; - - SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); - if (blockB) blockVector.push_back(blockB); - else if (l < levelDepth) this->getSubBlocksSouthEast(x1, x2, x3B, l, blockVector, levelDepth); - - SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); - if (blockT) blockVector.push_back(blockT); - else if (l < levelDepth) this->getSubBlocksSouthEast(x1, x2, x3T, l, blockVector, levelDepth); +void Grid3D::getSubBlocksNorthEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1 = (ix1 << 1) + 1; + int x2 = (ix2 << 1) + 1; + int x3B = (ix3 << 1); + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); + if (blockB) + blockVector.push_back(blockB); + else if (l < levelDepth) + this->getSubBlocksNorthEast(x1, x2, x3B, l, blockVector, levelDepth); + + SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); + if (blockT) + blockVector.push_back(blockT); + else if (l < levelDepth) + this->getSubBlocksNorthEast(x1, x2, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksNorthWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1 = (ix1 << 1); + int x2 = (ix2 << 1) + 1; + int x3B = (ix3 << 1); + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); + if (blockB) + blockVector.push_back(blockB); + else if (l < levelDepth) + this->getSubBlocksNorthWest(x1, x2, x3B, l, blockVector, levelDepth); + + SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); + if (blockT) + blockVector.push_back(blockT); + else if (l < levelDepth) + this->getSubBlocksNorthWest(x1, x2, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksSouthWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1 = ix1 << 1; + int x2 = ix2 << 1; + int x3B = (ix3 << 1); + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); + if (blockB) + blockVector.push_back(blockB); + else if (l < levelDepth) + this->getSubBlocksSouthWest(x1, x2, x3B, l, blockVector, levelDepth); + + SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); + if (blockT) + blockVector.push_back(blockT); + else if (l < levelDepth) + this->getSubBlocksSouthWest(x1, x2, x3T, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksSouthEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1 = (ix1 << 1) + 1; + int x2 = ix2 << 1; + int x3B = (ix3 << 1); + int x3T = x3B + 1; + int l = level + 1; + + SPtr<Block3D> blockB = this->getBlock(x1, x2, x3B, l); + if (blockB) + blockVector.push_back(blockB); + else if (l < levelDepth) + this->getSubBlocksSouthEast(x1, x2, x3B, l, blockVector, levelDepth); + + SPtr<Block3D> blockT = this->getBlock(x1, x2, x3T, l); + if (blockT) + blockVector.push_back(blockT); + else if (l < levelDepth) + this->getSubBlocksSouthEast(x1, x2, x3T, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// // diagonals ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2S = (ix2 << 1); - int x2N = x2S + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2S = (ix2 << 1); + int x2N = x2S + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); - if (blockN) blockVector.push_back(blockN); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); + if (blockN) + blockVector.push_back(blockN); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); - SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); - if (blockS) blockVector.push_back(blockS); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); + if (blockS) + blockVector.push_back(blockS); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = ix1 << 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = ix1 << 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); - if (blockN) blockVector.push_back(blockN); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); + if (blockN) + blockVector.push_back(blockN); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); - SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); - if (blockS) blockVector.push_back(blockS); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); + if (blockS) + blockVector.push_back(blockS); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomEast(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2S = ix2 << 1; - int x2N = x2S + 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2S = ix2 << 1; + int x2N = x2S + 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); - if (blockN) blockVector.push_back(blockN); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); + if (blockN) + blockVector.push_back(blockN); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); - SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); - if (blockS) blockVector.push_back(blockS); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); + if (blockS) + blockVector.push_back(blockS); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomWest(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1); - int x2S = (ix2 << 1); - int x2N = x2S + 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = (ix1 << 1); + int x2S = (ix2 << 1); + int x2N = x2S + 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); - if (blockN) blockVector.push_back(blockN); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockN = this->getBlock(x1, x2N, x3, l); + if (blockN) + blockVector.push_back(blockN); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2N, x3, l, blockVector, levelDepth); - SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); - if (blockS) blockVector.push_back(blockS); - else if (l < levelDepth) this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockS = this->getBlock(x1, x2S, x3, l); + if (blockS) + blockVector.push_back(blockS); + else if (l < levelDepth) + this->getSubBlocksTopEast(x1, x2S, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// // edge-diagonals ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1E = (ix1 << 1); - int x1W = x1E + 1; - int x2 = (ix2 << 1) + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; - - SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); - if (blockE) blockVector.push_back(blockE); - else if (l < levelDepth) this->getSubBlocksTopNorth(x1E, x2, x3, l, blockVector, levelDepth); - - SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); - if (blockW) blockVector.push_back(blockW); - else if (l < levelDepth) this->getSubBlocksTopNorth(x1W, x2, x3, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1E = (ix1 << 1); - int x1W = x1E + 1; - int x2 = (ix2 << 1); - int x3 = (ix3 << 1) + 1; - int l = level + 1; - - SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); - if (blockE) blockVector.push_back(blockE); - else if (l < levelDepth) this->getSubBlocksTopSouth(x1E, x2, x3, l, blockVector, levelDepth); - - SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); - if (blockW) blockVector.push_back(blockW); - else if (l < levelDepth) this->getSubBlocksTopSouth(x1W, x2, x3, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1E = ix1 << 1; - int x1W = x1E + 1; - int x2 = (ix2 << 1) + 1; - int x3 = ix3 << 1; - int l = level + 1; - - SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); - if (blockE) blockVector.push_back(blockE); - else if (l < levelDepth) this->getSubBlocksBottomNorth(x1E, x2, x3, l, blockVector, levelDepth); - - SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); - if (blockW) blockVector.push_back(blockW); - else if (l < levelDepth) this->getSubBlocksBottomNorth(x1W, x2, x3, l, blockVector, levelDepth); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>>& blockVector, int levelDepth) -{ - int x1E = (ix1 << 1); - int x1W = x1E + 1; - int x2 = ix2 << 1; - int x3 = ix3 << 1; - int l = level + 1; - - SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); - if (blockE) blockVector.push_back(blockE); - else if (l < levelDepth) this->getSubBlocksBottomSouth(x1E, x2, x3, l, blockVector, levelDepth); - - SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); - if (blockW) blockVector.push_back(blockW); - else if (l < levelDepth) this->getSubBlocksBottomSouth(x1W, x2, x3, l, blockVector, levelDepth); +void Grid3D::getSubBlocksTopNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1E = (ix1 << 1); + int x1W = x1E + 1; + int x2 = (ix2 << 1) + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; + + SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); + if (blockE) + blockVector.push_back(blockE); + else if (l < levelDepth) + this->getSubBlocksTopNorth(x1E, x2, x3, l, blockVector, levelDepth); + + SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); + if (blockW) + blockVector.push_back(blockW); + else if (l < levelDepth) + this->getSubBlocksTopNorth(x1W, x2, x3, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksTopSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1E = (ix1 << 1); + int x1W = x1E + 1; + int x2 = (ix2 << 1); + int x3 = (ix3 << 1) + 1; + int l = level + 1; + + SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); + if (blockE) + blockVector.push_back(blockE); + else if (l < levelDepth) + this->getSubBlocksTopSouth(x1E, x2, x3, l, blockVector, levelDepth); + + SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); + if (blockW) + blockVector.push_back(blockW); + else if (l < levelDepth) + this->getSubBlocksTopSouth(x1W, x2, x3, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksBottomNorth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1E = ix1 << 1; + int x1W = x1E + 1; + int x2 = (ix2 << 1) + 1; + int x3 = ix3 << 1; + int l = level + 1; + + SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); + if (blockE) + blockVector.push_back(blockE); + else if (l < levelDepth) + this->getSubBlocksBottomNorth(x1E, x2, x3, l, blockVector, levelDepth); + + SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); + if (blockW) + blockVector.push_back(blockW); + else if (l < levelDepth) + this->getSubBlocksBottomNorth(x1W, x2, x3, l, blockVector, levelDepth); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getSubBlocksBottomSouth(int ix1, int ix2, int ix3, int level, vector<SPtr<Block3D>> &blockVector, + int levelDepth) +{ + int x1E = (ix1 << 1); + int x1W = x1E + 1; + int x2 = ix2 << 1; + int x3 = ix3 << 1; + int l = level + 1; + + SPtr<Block3D> blockE = this->getBlock(x1E, x2, x3, l); + if (blockE) + blockVector.push_back(blockE); + else if (l < levelDepth) + this->getSubBlocksBottomSouth(x1E, x2, x3, l, blockVector, levelDepth); + + SPtr<Block3D> blockW = this->getBlock(x1W, x2, x3, l); + if (blockW) + blockVector.push_back(blockW); + else if (l < levelDepth) + this->getSubBlocksBottomSouth(x1W, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// // space-diagonals ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2 = (ix2 << 1) + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2 = (ix2 << 1) + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockTNE = this->getBlock(x1, x2, x3, l); - if (blockTNE) blockVector.push_back(blockTNE); - else if (l < levelDepth) this->getSubBlocksTopNorthEast(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockTNE = this->getBlock(x1, x2, x3, l); + if (blockTNE) + blockVector.push_back(blockTNE); + else if (l < levelDepth) + this->getSubBlocksTopNorthEast(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = ix1 << 1; - int x2 = (ix2 << 1) + 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = ix1 << 1; + int x2 = (ix2 << 1) + 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockTNW = this->getBlock(x1, x2, x3, l); - if (blockTNW) blockVector.push_back(blockTNW); - else if (l < levelDepth) this->getSubBlocksTopNorthWest(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockTNW = this->getBlock(x1, x2, x3, l); + if (blockTNW) + blockVector.push_back(blockTNW); + else if (l < levelDepth) + this->getSubBlocksTopNorthWest(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2 = ix2 << 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2 = ix2 << 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockTNW = this->getBlock(x1, x2, x3, l); - if (blockTNW) blockVector.push_back(blockTNW); - else if (l < levelDepth) this->getSubBlocksTopSouthEast(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockTNW = this->getBlock(x1, x2, x3, l); + if (blockTNW) + blockVector.push_back(blockTNW); + else if (l < levelDepth) + this->getSubBlocksTopSouthEast(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksTopSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksTopSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = ix1 << 1; - int x2 = ix2 << 1; - int x3 = (ix3 << 1) + 1; - int l = level + 1; + int x1 = ix1 << 1; + int x2 = ix2 << 1; + int x3 = (ix3 << 1) + 1; + int l = level + 1; - SPtr<Block3D> blockTSW = this->getBlock(x1, x2, x3, l); - if (blockTSW) blockVector.push_back(blockTSW); - else if (l < levelDepth) this->getSubBlocksTopSouthWest(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockTSW = this->getBlock(x1, x2, x3, l); + if (blockTSW) + blockVector.push_back(blockTSW); + else if (l < levelDepth) + this->getSubBlocksTopSouthWest(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2 = (ix2 << 1) + 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2 = (ix2 << 1) + 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockBNE = this->getBlock(x1, x2, x3, l); - if (blockBNE) blockVector.push_back(blockBNE); - else if (l < levelDepth) this->getSubBlocksBottomNorthEast(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockBNE = this->getBlock(x1, x2, x3, l); + if (blockBNE) + blockVector.push_back(blockBNE); + else if (l < levelDepth) + this->getSubBlocksBottomNorthEast(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = ix1 << 1; - int x2 = (ix2 << 1) + 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = ix1 << 1; + int x2 = (ix2 << 1) + 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockBNW = this->getBlock(x1, x2, x3, l); - if (blockBNW) blockVector.push_back(blockBNW); - else if (l < levelDepth) this->getSubBlocksBottomNorthWest(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockBNW = this->getBlock(x1, x2, x3, l); + if (blockBNW) + blockVector.push_back(blockBNW); + else if (l < levelDepth) + this->getSubBlocksBottomNorthWest(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = (ix1 << 1) + 1; - int x2 = ix2 << 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = (ix1 << 1) + 1; + int x2 = ix2 << 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockBSE = this->getBlock(x1, x2, x3, l); - if (blockBSE) blockVector.push_back(blockBSE); - else if (l < levelDepth) this->getSubBlocksBottomSouthEast(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockBSE = this->getBlock(x1, x2, x3, l); + if (blockBSE) + blockVector.push_back(blockBSE); + else if (l < levelDepth) + this->getSubBlocksBottomSouthEast(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getSubBlocksBottomSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth) +void Grid3D::getSubBlocksBottomSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth) { - int x1 = ix1 << 1; - int x2 = ix2 << 1; - int x3 = ix3 << 1; - int l = level + 1; + int x1 = ix1 << 1; + int x2 = ix2 << 1; + int x3 = ix3 << 1; + int l = level + 1; - SPtr<Block3D> blockBSW = this->getBlock(x1, x2, x3, l); - if (blockBSW) blockVector.push_back(blockBSW); - else if (l < levelDepth) this->getSubBlocksBottomSouthWest(x1, x2, x3, l, blockVector, levelDepth); + SPtr<Block3D> blockBSW = this->getBlock(x1, x2, x3, l); + if (blockBSW) + blockVector.push_back(blockBSW); + else if (l < levelDepth) + this->getSubBlocksBottomSouthWest(x1, x2, x3, l, blockVector, levelDepth); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getBlocks(int level, std::vector<SPtr<Block3D>>& blockVector) +void Grid3D::getBlocks(int level, std::vector<SPtr<Block3D>> &blockVector) { - for (Block3DMap::value_type b : levelSet[level]) - { - blockVector.push_back(b.second); - } - + for (Block3DMap::value_type b : levelSet[level]) { + blockVector.push_back(b.second); + } } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getBlocks(int level, int rank, std::vector<SPtr<Block3D>>& blockVector) +void Grid3D::getBlocks(int level, int rank, std::vector<SPtr<Block3D>> &blockVector) { - for (Block3DMap::value_type b : levelSet[level]) - { - SPtr<Block3D> block = b.second; - int blockRank = block->getRank(); - if (blockRank == rank) - { - blockVector.push_back(b.second); - } - } + for (Block3DMap::value_type b : levelSet[level]) { + SPtr<Block3D> block = b.second; + int blockRank = block->getRank(); + if (blockRank == rank) { + blockVector.push_back(b.second); + } + } } ////////////////////////////////////////////////////////////////////////// -void Grid3D::getBlocks(int level, int rank, bool active, std::vector<SPtr<Block3D>>& blockVector) +void Grid3D::getBlocks(int level, int rank, bool active, std::vector<SPtr<Block3D>> &blockVector) { - for (Block3DMap::value_type b : levelSet[level]) - { - SPtr<Block3D> block = b.second; - int blockRank = block->getRank(); + for (Block3DMap::value_type b : levelSet[level]) { + SPtr<Block3D> block = b.second; + int blockRank = block->getRank(); - if (blockRank == rank && active ? block->isActive() : block->isNotActive()) - { - blockVector.push_back(b.second); - } - } + if (blockRank == rank && active ? block->isActive() : block->isNotActive()) { + blockVector.push_back(b.second); + } + } } ////////////////////////////////////////////////////////////////////////// int Grid3D::getFinestInitializedLevel() { - for (int i = Grid3DSystem::MAXLEVEL; i >= 0; i--) if (this->levelSet[i].size() > 0) return(i); - return(-1); + for (int i = Grid3DSystem::MAXLEVEL; i >= 0; i--) + if (this->levelSet[i].size() > 0) + return (i); + return (-1); } ////////////////////////////////////////////////////////////////////////// int Grid3D::getCoarsestInitializedLevel() { - for (int i = 0; i <= Grid3DSystem::MAXLEVEL; i++) if (this->levelSet[i].size() > 0) return(i); - return(-1); + for (int i = 0; i <= Grid3DSystem::MAXLEVEL; i++) + if (this->levelSet[i].size() > 0) + return (i); + return (-1); } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setNX1(int nx1) -{ - this->nx1 = nx1; -} +void Grid3D::setNX1(int nx1) { this->nx1 = nx1; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setNX2(int nx2) -{ - this->nx2 = nx2; -} +void Grid3D::setNX2(int nx2) { this->nx2 = nx2; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::setNX3(int nx3) -{ - this->nx3 = nx3; -} +void Grid3D::setNX3(int nx3) { this->nx3 = nx3; } ////////////////////////////////////////////////////////////////////////// -int Grid3D::getNX1() const -{ - return this->nx1; -} +int Grid3D::getNX1() const { return this->nx1; } ////////////////////////////////////////////////////////////////////////// -int Grid3D::getNX2() const -{ - return this->nx2; -} +int Grid3D::getNX2() const { return this->nx2; } ////////////////////////////////////////////////////////////////////////// -int Grid3D::getNX3() const -{ - return this->nx3; -} +int Grid3D::getNX3() const { return this->nx3; } ////////////////////////////////////////////////////////////////////////// -void Grid3D::deleteBlocks(const std::vector<int>& ids) +void Grid3D::deleteBlocks(const std::vector<int> &ids) { - for (int i : ids) - { - SPtr<Block3D> block = getBlock(i); - if (block) this->deleteBlock(block); - } + for (int i : ids) { + SPtr<Block3D> block = getBlock(i); + if (block) + this->deleteBlock(block); + } } ////////////////////////////////////////////////////////////////////////// int Grid3D::getNumberOfBlocks() { - int c = 0; - for (Block3DMap l : levelSet) - { - c += (int)l.size(); - } - return c; -} -////////////////////////////////////////////////////////////////////////// -int Grid3D::getNumberOfBlocks(int level) -{ - return (int)levelSet[level].size(); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks) -{ - int coarsestLevel = this->getCoarsestInitializedLevel(); - int finestLevel = this->getFinestInitializedLevel(); - - ////////////////////////////////////////////////////////////////////////// - //MINIMALE BLOCK-INDIZES BESTIMMEN - // - //min: - double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - - //Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden, - //da beim Transformieren der "groessere" Index rauskommt - int iMinX1 = (int)dMinX1; if (UbMath::zero(dMinX1 - iMinX1)) iMinX1 -= 1; - int iMinX2 = (int)dMinX2; if (UbMath::zero(dMinX2 - iMinX2)) iMinX2 -= 1; - int iMinX3 = (int)dMinX3; if (UbMath::zero(dMinX3 - iMinX3)) iMinX3 -= 1; - - //max (hier kann die Zusatzabfrage vernachlaessigt werden): - int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - - SPtr<Block3D> block; - - //set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen - std::set<SPtr<Block3D>> blockset; - for (int level = coarsestLevel; level <= finestLevel; level++) - { - //damit bei negativen werten auch der "kleinere" genommen wird -> floor! - int minx1 = (int)std::floor((double)iMinX1 / (1 << (finestLevel - level))); - int minx2 = (int)std::floor((double)iMinX2 / (1 << (finestLevel - level))); - int minx3 = (int)std::floor((double)iMinX3 / (1 << (finestLevel - level))); - - int maxx1 = iMaxX1 / (1 << (finestLevel - level)); - int maxx2 = iMaxX2 / (1 << (finestLevel - level)); - int maxx3 = iMaxX3 / (1 << (finestLevel - level)); - - for (int ix1 = minx1; ix1 <= maxx1; ix1++) - for (int ix2 = minx2; ix2 <= maxx2; ix2++) - for (int ix3 = minx3; ix3 <= maxx3; ix3++) - if ((block = this->getBlock(ix1, ix2, ix3, level))) - { - if (block->getRank() == rank) - { - blockset.insert(block); - } - } - } - - blocks.resize(blockset.size()); - std::copy(blockset.begin(), blockset.end(), blocks.begin()); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getBlocksByCuboid(int level, double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks) -{ - ////////////////////////////////////////////////////////////////////////// - //MINIMALE BLOCK-INDIZES BESTIMMEN - // - //min: - double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << level); - double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << level); - double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << level); - - //Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden: - int iMinX1 = (int)dMinX1; if (UbMath::zero(dMinX1 - iMinX1)) iMinX1 -= 1; - int iMinX2 = (int)dMinX2; if (UbMath::zero(dMinX2 - iMinX2)) iMinX2 -= 1; - int iMinX3 = (int)dMinX3; if (UbMath::zero(dMinX3 - iMinX3)) iMinX3 -= 1; - - //max: - int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << level)); - int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << level)); - int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << level)); - - - //set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen - std::set<SPtr<Block3D>> blockset; - SPtr<Block3D> block; - - for (int ix1 = iMinX1; ix1 <= iMaxX1; ix1++) - for (int ix2 = iMinX2; ix2 <= iMaxX2; ix2++) - for (int ix3 = iMinX3; ix3 <= iMaxX3; ix3++) - if ((block = this->getBlock(ix1, ix2, ix3, level))) - { - if (block->getRank() == rank) - { - blockset.insert(block); - } - } - - blocks.resize(blockset.size()); - std::copy(blockset.begin(), blockset.end(), blocks.begin()); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::getAllBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks) -{ - int coarsestLevel = this->getCoarsestInitializedLevel(); - int finestLevel = this->getFinestInitializedLevel(); - - ////////////////////////////////////////////////////////////////////////// - //MINIMALE BLOCK-INDIZES BESTIMMEN - // - //min: - double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << finestLevel); - - //Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden, - //da beim Transformieren der "groessere" Index rauskommt - int iMinX1 = (int)dMinX1; if (UbMath::zero(dMinX1 - iMinX1)) iMinX1 -= 1; - int iMinX2 = (int)dMinX2; if (UbMath::zero(dMinX2 - iMinX2)) iMinX2 -= 1; - int iMinX3 = (int)dMinX3; if (UbMath::zero(dMinX3 - iMinX3)) iMinX3 -= 1; - - //max (hier kann die Zusatzabfrage vernachlaessigt werden): - int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); - - SPtr<Block3D> block; - - //set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen - std::set<SPtr<Block3D>> blockset; - for (int level = coarsestLevel; level <= finestLevel; level++) - { - //damit bei negativen werten auch der "kleinere" genommen wird -> floor! - int minx1 = (int)std::floor((double)iMinX1 / (1 << (finestLevel - level))); - int minx2 = (int)std::floor((double)iMinX2 / (1 << (finestLevel - level))); - int minx3 = (int)std::floor((double)iMinX3 / (1 << (finestLevel - level))); - - int maxx1 = iMaxX1 / (1 << (finestLevel - level)); - int maxx2 = iMaxX2 / (1 << (finestLevel - level)); - int maxx3 = iMaxX3 / (1 << (finestLevel - level)); - - for (int ix1 = minx1; ix1 <= maxx1; ix1++) - for (int ix2 = minx2; ix2 <= maxx2; ix2++) - for (int ix3 = minx3; ix3 <= maxx3; ix3++) - if ((block = this->getBlock(ix1, ix2, ix3, level))) - { - if (block) - { - blockset.insert(block); - } - } - } - - blocks.resize(blockset.size()); - std::copy(blockset.begin(), blockset.end(), blocks.begin()); -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::calcStartCoordinatesAndDelta(SPtr<Block3D> block, double& worldX1, double& worldX2, double& worldX3, double& deltaX) -{ - int blocklevel = block->getLevel(); - worldX1 = block->getX1() / (float)(1 << blocklevel); - worldX2 = block->getX2() / (float)(1 << blocklevel); - worldX3 = block->getX3() / (float)(1 << blocklevel); - deltaX = (double)1.0 / (double)(this->blockNx1 * (double)(1 << blocklevel)); - - if (this->trafo) - { - double x1tmp = worldX1, x2tmp = worldX2, x3tmp = worldX3; - worldX1 = this->trafo->transformBackwardToX1Coordinate(x1tmp, x2tmp, x3tmp); - worldX2 = this->trafo->transformBackwardToX2Coordinate(x1tmp, x2tmp, x3tmp); - worldX3 = this->trafo->transformBackwardToX3Coordinate(x1tmp, x2tmp, x3tmp); - deltaX = this->trafo->getX1CoordinateScaling() / (double)(this->blockNx1 * (double)(1 << blocklevel)); - } -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::calcStartCoordinatesWithOutOverlap(SPtr<Block3D> block, double& worldX1, double& worldX2, double& worldX3) -{ - int blocklevel = block->getLevel(); - worldX1 = block->getX1() / (float)(1 << blocklevel); - worldX2 = block->getX2() / (float)(1 << blocklevel); - worldX3 = block->getX3() / (float)(1 << blocklevel); - - if (this->trafo) - { - double x1tmp = worldX1, x2tmp = worldX2, x3tmp = worldX3; - worldX1 = this->trafo->transformBackwardToX1Coordinate(x1tmp, x2tmp, x3tmp); - worldX2 = this->trafo->transformBackwardToX2Coordinate(x1tmp, x2tmp, x3tmp); - worldX3 = this->trafo->transformBackwardToX3Coordinate(x1tmp, x2tmp, x3tmp); - } -} -////////////////////////////////////////////////////////////////////////// -void Grid3D::setTimeStep(double step) -{ - timeStep = step; -} -////////////////////////////////////////////////////////////////////////// -double Grid3D::getTimeStep() const -{ - return timeStep; -} + int c = 0; + for (Block3DMap l : levelSet) { + c += (int)l.size(); + } + return c; +} +////////////////////////////////////////////////////////////////////////// +int Grid3D::getNumberOfBlocks(int level) { return (int)levelSet[level].size(); } +////////////////////////////////////////////////////////////////////////// +void Grid3D::getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + std::vector<SPtr<Block3D>> &blocks) +{ + int coarsestLevel = this->getCoarsestInitializedLevel(); + int finestLevel = this->getFinestInitializedLevel(); + + ////////////////////////////////////////////////////////////////////////// + // MINIMALE BLOCK-INDIZES BESTIMMEN + // + // min: + double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + + // Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden, + // da beim Transformieren der "groessere" Index rauskommt + int iMinX1 = (int)dMinX1; + if (UbMath::zero(dMinX1 - iMinX1)) + iMinX1 -= 1; + int iMinX2 = (int)dMinX2; + if (UbMath::zero(dMinX2 - iMinX2)) + iMinX2 -= 1; + int iMinX3 = (int)dMinX3; + if (UbMath::zero(dMinX3 - iMinX3)) + iMinX3 -= 1; + + // max (hier kann die Zusatzabfrage vernachlaessigt werden): + int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + + SPtr<Block3D> block; + + // set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen + std::set<SPtr<Block3D>> blockset; + for (int level = coarsestLevel; level <= finestLevel; level++) { + // damit bei negativen werten auch der "kleinere" genommen wird -> floor! + int minx1 = (int)std::floor((double)iMinX1 / (1 << (finestLevel - level))); + int minx2 = (int)std::floor((double)iMinX2 / (1 << (finestLevel - level))); + int minx3 = (int)std::floor((double)iMinX3 / (1 << (finestLevel - level))); + + int maxx1 = iMaxX1 / (1 << (finestLevel - level)); + int maxx2 = iMaxX2 / (1 << (finestLevel - level)); + int maxx3 = iMaxX3 / (1 << (finestLevel - level)); + + for (int ix1 = minx1; ix1 <= maxx1; ix1++) + for (int ix2 = minx2; ix2 <= maxx2; ix2++) + for (int ix3 = minx3; ix3 <= maxx3; ix3++) + if ((block = this->getBlock(ix1, ix2, ix3, level))) { + if (block->getRank() == rank) { + blockset.insert(block); + } + } + } + + blocks.resize(blockset.size()); + std::copy(blockset.begin(), blockset.end(), blocks.begin()); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getBlocksByCuboid(int level, double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, std::vector<SPtr<Block3D>> &blocks) +{ + ////////////////////////////////////////////////////////////////////////// + // MINIMALE BLOCK-INDIZES BESTIMMEN + // + // min: + double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << level); + double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << level); + double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << level); + + // Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden: + int iMinX1 = (int)dMinX1; + if (UbMath::zero(dMinX1 - iMinX1)) + iMinX1 -= 1; + int iMinX2 = (int)dMinX2; + if (UbMath::zero(dMinX2 - iMinX2)) + iMinX2 -= 1; + int iMinX3 = (int)dMinX3; + if (UbMath::zero(dMinX3 - iMinX3)) + iMinX3 -= 1; + + // max: + int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << level)); + int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << level)); + int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << level)); + + // set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen + std::set<SPtr<Block3D>> blockset; + SPtr<Block3D> block; + + for (int ix1 = iMinX1; ix1 <= iMaxX1; ix1++) + for (int ix2 = iMinX2; ix2 <= iMaxX2; ix2++) + for (int ix3 = iMinX3; ix3 <= iMaxX3; ix3++) + if ((block = this->getBlock(ix1, ix2, ix3, level))) { + if (block->getRank() == rank) { + blockset.insert(block); + } + } + + blocks.resize(blockset.size()); + std::copy(blockset.begin(), blockset.end(), blocks.begin()); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::getAllBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + std::vector<SPtr<Block3D>> &blocks) +{ + int coarsestLevel = this->getCoarsestInitializedLevel(); + int finestLevel = this->getFinestInitializedLevel(); + + ////////////////////////////////////////////////////////////////////////// + // MINIMALE BLOCK-INDIZES BESTIMMEN + // + // min: + double dMinX1 = trafo->transformForwardToX1Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + double dMinX2 = trafo->transformForwardToX2Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + double dMinX3 = trafo->transformForwardToX3Coordinate(minX1, minX2, minX3) * (1 << finestLevel); + + // Achtung, wenn minX1 genau auf grenze zwischen zwei bloecken -> der "kleinere" muss genommen werden, + // da beim Transformieren der "groessere" Index rauskommt + int iMinX1 = (int)dMinX1; + if (UbMath::zero(dMinX1 - iMinX1)) + iMinX1 -= 1; + int iMinX2 = (int)dMinX2; + if (UbMath::zero(dMinX2 - iMinX2)) + iMinX2 -= 1; + int iMinX3 = (int)dMinX3; + if (UbMath::zero(dMinX3 - iMinX3)) + iMinX3 -= 1; + + // max (hier kann die Zusatzabfrage vernachlaessigt werden): + int iMaxX1 = (int)(trafo->transformForwardToX1Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + int iMaxX2 = (int)(trafo->transformForwardToX2Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + int iMaxX3 = (int)(trafo->transformForwardToX3Coordinate(maxX1, maxX2, maxX3) * (1 << finestLevel)); + + SPtr<Block3D> block; + + // set, um doppelte bloecke zu vermeiden, die u.U. bei periodic auftreten koennen + std::set<SPtr<Block3D>> blockset; + for (int level = coarsestLevel; level <= finestLevel; level++) { + // damit bei negativen werten auch der "kleinere" genommen wird -> floor! + int minx1 = (int)std::floor((double)iMinX1 / (1 << (finestLevel - level))); + int minx2 = (int)std::floor((double)iMinX2 / (1 << (finestLevel - level))); + int minx3 = (int)std::floor((double)iMinX3 / (1 << (finestLevel - level))); + + int maxx1 = iMaxX1 / (1 << (finestLevel - level)); + int maxx2 = iMaxX2 / (1 << (finestLevel - level)); + int maxx3 = iMaxX3 / (1 << (finestLevel - level)); + + for (int ix1 = minx1; ix1 <= maxx1; ix1++) + for (int ix2 = minx2; ix2 <= maxx2; ix2++) + for (int ix3 = minx3; ix3 <= maxx3; ix3++) + if ((block = this->getBlock(ix1, ix2, ix3, level))) { + if (block) { + blockset.insert(block); + } + } + } + + blocks.resize(blockset.size()); + std::copy(blockset.begin(), blockset.end(), blocks.begin()); +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::calcStartCoordinatesAndDelta(SPtr<Block3D> block, double &worldX1, double &worldX2, double &worldX3, + double &deltaX) +{ + int blocklevel = block->getLevel(); + worldX1 = block->getX1() / (float)(1 << blocklevel); + worldX2 = block->getX2() / (float)(1 << blocklevel); + worldX3 = block->getX3() / (float)(1 << blocklevel); + deltaX = (double)1.0 / (double)(this->blockNx1 * (double)(1 << blocklevel)); + + if (this->trafo) { + double x1tmp = worldX1, x2tmp = worldX2, x3tmp = worldX3; + worldX1 = this->trafo->transformBackwardToX1Coordinate(x1tmp, x2tmp, x3tmp); + worldX2 = this->trafo->transformBackwardToX2Coordinate(x1tmp, x2tmp, x3tmp); + worldX3 = this->trafo->transformBackwardToX3Coordinate(x1tmp, x2tmp, x3tmp); + deltaX = this->trafo->getX1CoordinateScaling() / (double)(this->blockNx1 * (double)(1 << blocklevel)); + } +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::calcStartCoordinatesWithOutOverlap(SPtr<Block3D> block, double &worldX1, double &worldX2, double &worldX3) +{ + int blocklevel = block->getLevel(); + worldX1 = block->getX1() / (float)(1 << blocklevel); + worldX2 = block->getX2() / (float)(1 << blocklevel); + worldX3 = block->getX3() / (float)(1 << blocklevel); + + if (this->trafo) { + double x1tmp = worldX1, x2tmp = worldX2, x3tmp = worldX3; + worldX1 = this->trafo->transformBackwardToX1Coordinate(x1tmp, x2tmp, x3tmp); + worldX2 = this->trafo->transformBackwardToX2Coordinate(x1tmp, x2tmp, x3tmp); + worldX3 = this->trafo->transformBackwardToX3Coordinate(x1tmp, x2tmp, x3tmp); + } +} +////////////////////////////////////////////////////////////////////////// +void Grid3D::setTimeStep(double step) { timeStep = step; } +////////////////////////////////////////////////////////////////////////// +double Grid3D::getTimeStep() const { return timeStep; } ////////////////////////////////////////////////////////////////////////// void Grid3D::fillExtentWithBlocks(UbTupleInt3 minInd, UbTupleInt3 maxInd) { - for (int x3 = val<3>(minInd); x3 < val<3>(maxInd); x3++) - { - for (int x2 = val<2>(minInd); x2 < val<2>(maxInd); x2++) - { - for (int x1 = val<1>(minInd); x1 < val<1>(maxInd); x1++) - { - SPtr<Block3D> block(new Block3D(x1, x2, x3, 0)); - this->addBlock(block); - } - } - } + for (int x3 = val<3>(minInd); x3 < val<3>(maxInd); x3++) { + for (int x2 = val<2>(minInd); x2 < val<2>(maxInd); x2++) { + for (int x1 = val<1>(minInd); x1 < val<1>(maxInd); x1++) { + SPtr<Block3D> block(new Block3D(x1, x2, x3, 0)); + this->addBlock(block); + } + } + } } ////////////////////////////////////////////////////////////////////////// -//void Grid3D::notifyObservers( double step ) +// void Grid3D::notifyObservers( double step ) //{ // for(ObserverPtr o, observers) // { @@ -1988,98 +2271,84 @@ void Grid3D::fillExtentWithBlocks(UbTupleInt3 minInd, UbTupleInt3 maxInd) // //} ////////////////////////////////////////////////////////////////////////// -//void Grid3D::addObserver( ObserverPtr observer ) +// void Grid3D::addObserver( ObserverPtr observer ) //{ // observers.insert(observer); // //observers.push_back(observer); //} //////////////////////////////////////////////////////////////////////////// -//void Grid3D::removeObserver( ObserverPtr observer ) +// void Grid3D::removeObserver( ObserverPtr observer ) //{ // observers.erase(observer); // //observers.remove(observer); //} ////////////////////////////////////////////////////////////////////////// -void Grid3D::deleteBlockIDs() -{ - this->blockIdMap.clear(); -} +void Grid3D::deleteBlockIDs() { this->blockIdMap.clear(); } ////////////////////////////////////////////////////////////////////////// void Grid3D::renumberBlockIDs() { - deleteBlockIDs(); + deleteBlockIDs(); - int startLevel = getCoarsestInitializedLevel(); - int stopLevel = getFinestInitializedLevel(); - int counter = 0; + int startLevel = getCoarsestInitializedLevel(); + int stopLevel = getFinestInitializedLevel(); + int counter = 0; - for (int l = startLevel; l <= stopLevel; l++) - { - std::vector<SPtr<Block3D>> blockVector; - getBlocks(l, blockVector); - for (SPtr<Block3D> block : blockVector) - { - block->setGlobalID(counter); - blockIdMap.insert(std::make_pair(counter, block)); - //Block3D::setMaxGlobalID(counter); - counter++; - } - } + for (int l = startLevel; l <= stopLevel; l++) { + std::vector<SPtr<Block3D>> blockVector; + getBlocks(l, blockVector); + for (SPtr<Block3D> block : blockVector) { + block->setGlobalID(counter); + blockIdMap.insert(std::make_pair(counter, block)); + // Block3D::setMaxGlobalID(counter); + counter++; + } + } } - ////////////////////////////////////////////////////////////////////////// void Grid3D::updateDistributedBlocks(SPtr<Communicator> comm) { - std::vector<int> blocks; - - if (comm->isRoot()) - { - int startLevel = getCoarsestInitializedLevel(); - int stopLevel = getFinestInitializedLevel(); - - for (int l = startLevel; l <= stopLevel; l++) - { - std::vector<SPtr<Block3D>> blockVector; - getBlocks(l, blockVector); - for (SPtr<Block3D> block : blockVector) - { - blocks.push_back(block->getX1()); - blocks.push_back(block->getX2()); - blocks.push_back(block->getX3()); - blocks.push_back(l); - blocks.push_back(block->getGlobalID()); - } - } - } - - comm->broadcast(blocks); - - if (!comm->isRoot()) - { - int startLevel = getCoarsestInitializedLevel(); - int stopLevel = getFinestInitializedLevel(); - - blockIdMap.clear(); - - for (int l = startLevel; l <= stopLevel; l++) - { - levelSet[l].clear(); - } - this->levelSet.clear(); - levelSet.resize(Grid3DSystem::MAXLEVEL + 1); - - int rsize = (int)blocks.size(); - for (int i = 0; i < rsize; i += 5) - { - SPtr<Block3D> block(new Block3D(blocks[i], blocks[i + 1], blocks[i + 2], blocks[i + 3])); - block->setGlobalID(blocks[i + 4]); - this->addBlock(block); - } - - } + std::vector<int> blocks; + + if (comm->isRoot()) { + int startLevel = getCoarsestInitializedLevel(); + int stopLevel = getFinestInitializedLevel(); + + for (int l = startLevel; l <= stopLevel; l++) { + std::vector<SPtr<Block3D>> blockVector; + getBlocks(l, blockVector); + for (SPtr<Block3D> block : blockVector) { + blocks.push_back(block->getX1()); + blocks.push_back(block->getX2()); + blocks.push_back(block->getX3()); + blocks.push_back(l); + blocks.push_back(block->getGlobalID()); + } + } + } + + comm->broadcast(blocks); + if (!comm->isRoot()) { + int startLevel = getCoarsestInitializedLevel(); + int stopLevel = getFinestInitializedLevel(); + + blockIdMap.clear(); + + for (int l = startLevel; l <= stopLevel; l++) { + levelSet[l].clear(); + } + this->levelSet.clear(); + levelSet.resize(Grid3DSystem::MAXLEVEL + 1); + + int rsize = (int)blocks.size(); + for (int i = 0; i < rsize; i += 5) { + SPtr<Block3D> block(new Block3D(blocks[i], blocks[i + 1], blocks[i + 2], blocks[i + 3])); + block->setGlobalID(blocks[i + 4]); + this->addBlock(block); + } + } } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Grid/Grid3D.h b/src/cpu/VirtualFluidsCore/Grid/Grid3D.h index c91dca4a0..b954a4361 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Grid3D.h +++ b/src/cpu/VirtualFluidsCore/Grid/Grid3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,14 +34,13 @@ #ifndef GRID3D_H #define GRID3D_H - -#include <vector> -#include <map> #include <PointerDefinitions.h> +#include <map> +#include <vector> -#include <basics/utilities/Vector3D.h> -#include <basics/utilities/UbTuple.h> #include <basics/utilities/UbKeys.h> +#include <basics/utilities/UbTuple.h> +#include <basics/utilities/Vector3D.h> class CoordinateTransformation3D; @@ -51,7 +50,7 @@ class CoordinateTransformation3D; class Communicator; class Block3D; class Interactor3D; -//class Grid3DVisitor; +// class Grid3DVisitor; #define OFFSET 0.5 @@ -59,219 +58,262 @@ class Interactor3D; class Grid3D : public enableSharedFromThis<Grid3D> { public: - using Block3DKey = UbKeys::Key3<int>; - using Block3DMap = std::map<Block3DKey, SPtr<Block3D> >; - using BlockIDMap = std::map<int, SPtr<Block3D> >; - using LevelSet = std::vector<Block3DMap>; - using Interactor3DSet = std::vector<SPtr<Interactor3D> >; + using Block3DKey = UbKeys::Key3<int>; + using Block3DMap = std::map<Block3DKey, SPtr<Block3D>>; + using BlockIDMap = std::map<int, SPtr<Block3D>>; + using LevelSet = std::vector<Block3DMap>; + using Interactor3DSet = std::vector<SPtr<Interactor3D>>; public: - Grid3D(); - Grid3D(SPtr<Communicator> comm); - Grid3D(SPtr<Communicator> comm, int blockNx1, int blockNx2, int blockNx3, int gridNx1, int gridNx2, int gridNx3); - virtual ~Grid3D() = default; - ////////////////////////////////////////////////////////////////////////// - //blocks control - void addBlock(SPtr<Block3D> block); - bool deleteBlock(SPtr<Block3D> block); - bool deleteBlock(int ix1, int ix2, int ix3, int level); - void deleteBlocks(); - void deleteBlocks(const std::vector<int>& ids); - void replaceBlock(SPtr<Block3D> block); - SPtr<Block3D> getBlock(int ix1, int ix2, int ix3, int level) const; - SPtr<Block3D> getBlock(int id) const; - void getBlocksByCuboid(double minX1, double minX2, double minX3, - double maxX1, double maxX2, double maxX3, - std::vector<SPtr<Block3D>>& blocks); - void getBlocksByCuboid(int level, double minX1, double minX2, double minX3, - double maxX1, double maxX2, double maxX3, - std::vector<SPtr<Block3D>>& blocks); - void getAllBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, std::vector<SPtr<Block3D>>& blocks); - //!get blocks for level - void getBlocks(int level, std::vector<SPtr<Block3D>>& blockVector); - //!get blocks for level with current rank - void getBlocks(int level, int rank, std::vector<SPtr<Block3D>>& blockVector); - //!get only active or not active blocks - void getBlocks(int level, int rank, bool active, std::vector<SPtr<Block3D>>& blockVector); - int getNumberOfBlocks(); - int getNumberOfBlocks(int level); - //const Block3DMap& getBlocks(int level); - BlockIDMap& getBlockIDs(); - void deleteBlockIDs(); - void renumberBlockIDs(); - void updateDistributedBlocks(SPtr<Communicator> comm); - SPtr<Block3D> getSuperBlock(SPtr<Block3D> block); - SPtr<Block3D> getSuperBlock(int ix1, int ix2, int ix3, int level); - void getSubBlocks(SPtr<Block3D> block, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getSubBlocks(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blockVector); - SPtr<Block3D> getNeighborBlock(int dir, int ix1, int ix2, int ix3, int level) const; - SPtr<Block3D> getNeighborBlock(int dir, SPtr<Block3D> block) const; - bool expandBlock(int ix1, int ix2, int ix3, int level); - SPtr<Block3D> collapseBlock(int fix1, int fix2, int fix3, int flevel, int levelDepth); - void getAllNeighbors(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getAllNeighbors(SPtr<Block3D> block, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborBlocksForDirection(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborBlocksForDirectionWithDirZero(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); + Grid3D(); + Grid3D(SPtr<Communicator> comm); + Grid3D(SPtr<Communicator> comm, int blockNx1, int blockNx2, int blockNx3, int gridNx1, int gridNx2, int gridNx3); + virtual ~Grid3D() = default; + ////////////////////////////////////////////////////////////////////////// + // blocks control + void addBlock(SPtr<Block3D> block); + bool deleteBlock(SPtr<Block3D> block); + bool deleteBlock(int ix1, int ix2, int ix3, int level); + void deleteBlocks(); + void deleteBlocks(const std::vector<int> &ids); + void replaceBlock(SPtr<Block3D> block); + SPtr<Block3D> getBlock(int ix1, int ix2, int ix3, int level) const; + SPtr<Block3D> getBlock(int id) const; + void getBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + std::vector<SPtr<Block3D>> &blocks); + void getBlocksByCuboid(int level, double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, std::vector<SPtr<Block3D>> &blocks); + void getAllBlocksByCuboid(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + std::vector<SPtr<Block3D>> &blocks); + //! get blocks for level + void getBlocks(int level, std::vector<SPtr<Block3D>> &blockVector); + //! get blocks for level with current rank + void getBlocks(int level, int rank, std::vector<SPtr<Block3D>> &blockVector); + //! get only active or not active blocks + void getBlocks(int level, int rank, bool active, std::vector<SPtr<Block3D>> &blockVector); + int getNumberOfBlocks(); + int getNumberOfBlocks(int level); + // const Block3DMap& getBlocks(int level); + BlockIDMap &getBlockIDs(); + void deleteBlockIDs(); + void renumberBlockIDs(); + void updateDistributedBlocks(SPtr<Communicator> comm); + SPtr<Block3D> getSuperBlock(SPtr<Block3D> block); + SPtr<Block3D> getSuperBlock(int ix1, int ix2, int ix3, int level); + void getSubBlocks(SPtr<Block3D> block, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getSubBlocks(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blockVector); + SPtr<Block3D> getNeighborBlock(int dir, int ix1, int ix2, int ix3, int level) const; + SPtr<Block3D> getNeighborBlock(int dir, SPtr<Block3D> block) const; + bool expandBlock(int ix1, int ix2, int ix3, int level); + SPtr<Block3D> collapseBlock(int fix1, int fix2, int fix3, int flevel, int levelDepth); + void getAllNeighbors(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getAllNeighbors(SPtr<Block3D> block, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborBlocksForDirection(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborBlocksForDirectionWithDirZero(int dir, int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); - void getNeighborsZero(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTop(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottom(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); + void getNeighborsZero(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTop(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottom(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); - void getNeighborsNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); + void getNeighborsNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); - void getNeighborsTopNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); + void getNeighborsTopNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>> &blocks); - void getNeighborsBottomNorth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomSouth(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); + void getNeighborsBottomNorth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomSouth(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); - void getNeighborsTopNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsTopSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - void getNeighborsBottomSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, std::vector<SPtr<Block3D>>& blocks); - ////////////////////////////////////////////////////////////////////////// - //level control - int getFinestInitializedLevel(); - int getCoarsestInitializedLevel(); - ////////////////////////////////////////////////////////////////////////// - void deleteConnectors(); - ////////////////////////////////////////////////////////////////////////// - //interactors control - void addInteractor(SPtr<Interactor3D> interactor); - void addAndInitInteractor(SPtr<Interactor3D> interactor, double timestep=0); - Interactor3DSet getInteractors(); - ////////////////////////////////////////////////////////////////////////// - //visitors - void accept(Block3DVisitor& blockVisitor); - void accept(Grid3DVisitor& gridVisitor); - void accept(SPtr<Grid3DVisitor> gridVisitor); - ////////////////////////////////////////////////////////////////////////// - //bundle and rank for distributed memory - void setBundle(int bundle); - int getBundle() const; - int getRank() const; - void setRank(int rank); - ////////////////////////////////////////////////////////////////////////// - //periodic boundary - bool isPeriodicX1() const; - bool isPeriodicX2() const; - bool isPeriodicX3() const; - void setPeriodicX1(bool value); - void setPeriodicX2(bool value); - void setPeriodicX3(bool value); - ////////////////////////////////////////////////////////////////////////// - //Topology - UbTupleInt3 getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord) const; - UbTupleInt3 getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord, int level) const; - UbTupleDouble3 getBlockLengths(SPtr<Block3D> block) const; - UbTupleDouble6 getBlockOversize() const ; - void setCoordinateTransformator(SPtr<CoordinateTransformation3D> trafo); - const SPtr<CoordinateTransformation3D> getCoordinateTransformator() const ; - void setDeltaX(double dx); - void setDeltaX(double worldUnit, double gridUnit); - double getDeltaX(int level) const; - double getDeltaX(SPtr<Block3D> block) const; - UbTupleDouble3 getNodeOffset(SPtr<Block3D> block) const ; - Vector3D getNodeCoordinates(SPtr<Block3D> block, int ix1, int ix2, int ix3) const; - UbTupleInt3 getNodeIndexes(SPtr<Block3D> block, double nodeX1Coord, double nodeX2Coord, double nodeX3Coord) const; - void setBlockNX(int nx1, int nx2, int nx3); - UbTupleInt3 getBlockNX() const; - UbTupleDouble3 getBlockWorldCoordinates(SPtr<Block3D> block) const; - UbTupleDouble3 getBlockWorldCoordinates(int blockX1Index, int blockX2Index, int blockX3Index, int level) const; - void setNX1(int nx1); - void setNX2(int nx2); - void setNX3(int nx3); - int getNX1() const; - int getNX2() const; - int getNX3() const; - void calcStartCoordinatesAndDelta(SPtr<Block3D> block, double& worldX1, double& worldX2, double& worldX3, double& deltaX); - void calcStartCoordinatesWithOutOverlap(SPtr<Block3D> block, double& worldX1, double& worldX2, double& worldX3); - ////////////////////////////////////////////////////////////////////////// - //LBM - //double getDeltaT(SPtr<Block3D>) const; - ////////////////////////////////////////////////////////////////////////// - void setTimeStep(double step); - double getTimeStep() const; + void getNeighborsTopNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsTopSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomNorthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomNorthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomSouthEast(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + void getNeighborsBottomSouthWest(int ix1, int ix2, int ix3, int level, int levelDepth, + std::vector<SPtr<Block3D>> &blocks); + ////////////////////////////////////////////////////////////////////////// + // level control + int getFinestInitializedLevel(); + int getCoarsestInitializedLevel(); + ////////////////////////////////////////////////////////////////////////// + void deleteConnectors(); + ////////////////////////////////////////////////////////////////////////// + // interactors control + void addInteractor(SPtr<Interactor3D> interactor); + void addAndInitInteractor(SPtr<Interactor3D> interactor, double timestep = 0); + Interactor3DSet getInteractors(); + ////////////////////////////////////////////////////////////////////////// + // visitors + void accept(Block3DVisitor &blockVisitor); + void accept(Grid3DVisitor &gridVisitor); + void accept(SPtr<Grid3DVisitor> gridVisitor); + ////////////////////////////////////////////////////////////////////////// + // bundle and rank for distributed memory + void setBundle(int bundle); + int getBundle() const; + int getRank() const; + void setRank(int rank); + ////////////////////////////////////////////////////////////////////////// + // periodic boundary + bool isPeriodicX1() const; + bool isPeriodicX2() const; + bool isPeriodicX3() const; + void setPeriodicX1(bool value); + void setPeriodicX2(bool value); + void setPeriodicX3(bool value); + ////////////////////////////////////////////////////////////////////////// + // Topology + UbTupleInt3 getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord) const; + UbTupleInt3 getBlockIndexes(double blockX1Coord, double blockX2Coord, double blockX3Coord, int level) const; + UbTupleDouble3 getBlockLengths(SPtr<Block3D> block) const; + UbTupleDouble6 getBlockOversize() const; + void setCoordinateTransformator(SPtr<CoordinateTransformation3D> trafo); + const SPtr<CoordinateTransformation3D> getCoordinateTransformator() const; + void setDeltaX(double dx); + void setDeltaX(double worldUnit, double gridUnit); + double getDeltaX(int level) const; + double getDeltaX(SPtr<Block3D> block) const; + UbTupleDouble3 getNodeOffset(SPtr<Block3D> block) const; + Vector3D getNodeCoordinates(SPtr<Block3D> block, int ix1, int ix2, int ix3) const; + UbTupleInt3 getNodeIndexes(SPtr<Block3D> block, double nodeX1Coord, double nodeX2Coord, double nodeX3Coord) const; + void setBlockNX(int nx1, int nx2, int nx3); + UbTupleInt3 getBlockNX() const; + UbTupleDouble3 getBlockWorldCoordinates(SPtr<Block3D> block) const; + UbTupleDouble3 getBlockWorldCoordinates(int blockX1Index, int blockX2Index, int blockX3Index, int level) const; + void setNX1(int nx1); + void setNX2(int nx2); + void setNX3(int nx3); + int getNX1() const; + int getNX2() const; + int getNX3() const; + void calcStartCoordinatesAndDelta(SPtr<Block3D> block, double &worldX1, double &worldX2, double &worldX3, + double &deltaX); + void calcStartCoordinatesWithOutOverlap(SPtr<Block3D> block, double &worldX1, double &worldX2, double &worldX3); + ////////////////////////////////////////////////////////////////////////// + // LBM + // double getDeltaT(SPtr<Block3D>) const; + ////////////////////////////////////////////////////////////////////////// + void setTimeStep(double step); + double getTimeStep() const; protected: - void checkLevel(int level); - bool hasLevel(int level) const; + void checkLevel(int level); + bool hasLevel(int level) const; - void fillExtentWithBlocks( UbTupleInt3 minInd, UbTupleInt3 maxInd ); + void fillExtentWithBlocks(UbTupleInt3 minInd, UbTupleInt3 maxInd); - void getSubBlocksZero(int ix1, int ix2, int ix3, int level,std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksZero(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); - void getSubBlocksEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTop(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottom(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTop(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, int levelDepth); + void getSubBlocksBottom(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); - void getSubBlocksSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); - void getSubBlocksTopEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksTopEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); - void getSubBlocksBottomEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksBottomEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomNorth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomSouth(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); - void getSubBlocksTopNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksTopSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); - void getSubBlocksBottomSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>>& blockVector, int levelDepth); + void getSubBlocksTopNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksTopSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomNorthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomNorthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomSouthEast(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); + void getSubBlocksBottomSouthWest(int ix1, int ix2, int ix3, int level, std::vector<SPtr<Block3D>> &blockVector, + int levelDepth); private: - LevelSet levelSet; - BlockIDMap blockIdMap; - Interactor3DSet interactors; + LevelSet levelSet; + BlockIDMap blockIdMap; + Interactor3DSet interactors; + + int rank{ 0 }; + int bundle{ 0 }; - int rank{0}; - int bundle{0}; - - bool periodicX1{false}; - bool periodicX2{false}; - bool periodicX3{false}; + bool periodicX1{ false }; + bool periodicX2{ false }; + bool periodicX3{ false }; - int blockNx1{0}; - int blockNx2{0}; - int blockNx3{0}; + int blockNx1{ 0 }; + int blockNx2{ 0 }; + int blockNx3{ 0 }; - int nx1{0}; - int nx2{0}; - int nx3{0}; + int nx1{ 0 }; + int nx2{ 0 }; + int nx3{ 0 }; - SPtr<CoordinateTransformation3D> trafo; - double orgDeltaX{1.0}; + SPtr<CoordinateTransformation3D> trafo; + double orgDeltaX{ 1.0 }; - double timeStep{0.0}; - + double timeStep{ 0.0 }; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.cpp b/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.cpp index b3c711a73..33db1b0cf 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.cpp +++ b/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,47 +35,24 @@ namespace Grid3DSystem { - const int INVDIR[] = { INV_E , - INV_W , - INV_N , - INV_S , - INV_T , - INV_B , - INV_NE , - INV_NW , - INV_SE , - INV_SW , - INV_TE , - INV_TW , - INV_BE , - INV_BW , - INV_TN , - INV_TS , - INV_BN , - INV_BS , - INV_TNE, - INV_TNW, - INV_TSE, - INV_TSW, - INV_BNE, - INV_BNW, - INV_BSE, - INV_BSW }; +const int INVDIR[] = { INV_E, INV_W, INV_N, INV_S, INV_T, INV_B, INV_NE, INV_NW, INV_SE, + INV_SW, INV_TE, INV_TW, INV_BE, INV_BW, INV_TN, INV_TS, INV_BN, INV_BS, + INV_TNE, INV_TNW, INV_TSE, INV_TSW, INV_BNE, INV_BNW, INV_BSE, INV_BSW }; - //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 - //direction: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW - const int EX1[] = { 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 }; - const int EX2[] = { 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1 }; - const int EX3[] = { 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1 }; -} +// index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 +// direction: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE +// BSW +const int EX1[] = { 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 }; +const int EX2[] = { 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1 }; +const int EX3[] = { 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1 }; +} // namespace Grid3DSystem ////////////////////////////////////////////////////////////////////////// -const int& Grid3DSystem::getInvertDirection(const int& direction) -{ +const int &Grid3DSystem::getInvertDirection(const int &direction) +{ #ifdef _DEBUG - if(direction<STARTDIR || direction>ENDDIR) - throw UbException(UB_EXARGS,"unknown direction"); + if (direction < STARTDIR || direction > ENDDIR) + throw UbException(UB_EXARGS, "unknown direction"); #endif - return INVDIR[direction]; + return INVDIR[direction]; } - diff --git a/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.h b/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.h index 49fb973f5..ee61b8f73 100644 --- a/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.h +++ b/src/cpu/VirtualFluidsCore/Grid/Grid3DSystem.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,149 +38,254 @@ #include <iostream> #include <string> -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbException.h> - +#include <basics/utilities/UbMath.h> namespace Grid3DSystem { - static const int STARTDIR = 0; +static const int STARTDIR = 0; - static const int E /*f1 */ = 0; - static const int W /*f2 */ = 1; - static const int N /*f3 */ = 2; - static const int S /*f4 */ = 3; - static const int T /*f5 */ = 4; - static const int B /*f6 */ = 5; - static const int NE /*f7 */ = 6; - static const int SW /*f8 */ = 7; - static const int SE /*f9 */ = 8; - static const int NW /*f10*/ = 9; - static const int TE /*f11*/ = 10; - static const int BW /*f12*/ = 11; - static const int BE /*f13*/ = 12; - static const int TW /*f14*/ = 13; - static const int TN /*f15*/ = 14; - static const int BS /*f16*/ = 15; - static const int BN /*f17*/ = 16; - static const int TS /*f18*/ = 17; - static const int TNE = 18; - static const int TNW = 19; - static const int TSE = 20; - static const int TSW = 21; - static const int BNE = 22; - static const int BNW = 23; - static const int BSE = 24; - static const int BSW = 25; - static const int ZERO /*f0 */ = 26; +static const int E /*f1 */ = 0; +static const int W /*f2 */ = 1; +static const int N /*f3 */ = 2; +static const int S /*f4 */ = 3; +static const int T /*f5 */ = 4; +static const int B /*f6 */ = 5; +static const int NE /*f7 */ = 6; +static const int SW /*f8 */ = 7; +static const int SE /*f9 */ = 8; +static const int NW /*f10*/ = 9; +static const int TE /*f11*/ = 10; +static const int BW /*f12*/ = 11; +static const int BE /*f13*/ = 12; +static const int TW /*f14*/ = 13; +static const int TN /*f15*/ = 14; +static const int BS /*f16*/ = 15; +static const int BN /*f17*/ = 16; +static const int TS /*f18*/ = 17; +static const int TNE = 18; +static const int TNW = 19; +static const int TSE = 20; +static const int TSW = 21; +static const int BNE = 22; +static const int BNW = 23; +static const int BSE = 24; +static const int BSW = 25; +static const int ZERO /*f0 */ = 26; - static const int ENDDIR = 25; +static const int ENDDIR = 25; - static const int INV_E = W; - static const int INV_W = E; - static const int INV_N = S; - static const int INV_S = N; - static const int INV_T = B; - static const int INV_B = T; - static const int INV_NE = SW; - static const int INV_NW = SE; - static const int INV_SE = NW; - static const int INV_SW = NE; - static const int INV_TE = BW; - static const int INV_TW = BE; - static const int INV_BE = TW; - static const int INV_BW = TE; - static const int INV_TN = BS; - static const int INV_TS = BN; - static const int INV_BN = TS; - static const int INV_BS = TN; - static const int INV_TNE = BSW; - static const int INV_TNW = BSE; - static const int INV_TSE = BNW; - static const int INV_TSW = BNE; - static const int INV_BNE = TSW; - static const int INV_BNW = TSE; - static const int INV_BSE = TNW; - static const int INV_BSW = TNE; +static const int INV_E = W; +static const int INV_W = E; +static const int INV_N = S; +static const int INV_S = N; +static const int INV_T = B; +static const int INV_B = T; +static const int INV_NE = SW; +static const int INV_NW = SE; +static const int INV_SE = NW; +static const int INV_SW = NE; +static const int INV_TE = BW; +static const int INV_TW = BE; +static const int INV_BE = TW; +static const int INV_BW = TE; +static const int INV_TN = BS; +static const int INV_TS = BN; +static const int INV_BN = TS; +static const int INV_BS = TN; +static const int INV_TNE = BSW; +static const int INV_TNW = BSE; +static const int INV_TSE = BNW; +static const int INV_TSW = BNE; +static const int INV_BNE = TSW; +static const int INV_BNW = TSE; +static const int INV_BSE = TNW; +static const int INV_BSW = TNE; - extern const int INVDIR[ENDDIR+1]; +extern const int INVDIR[ENDDIR + 1]; - static const int MINLEVEL = 0; - static const int MAXLEVEL = 25; +static const int MINLEVEL = 0; +static const int MAXLEVEL = 25; - extern const int EX1[ENDDIR+1]; - extern const int EX2[ENDDIR+1]; - extern const int EX3[ENDDIR+1]; +extern const int EX1[ENDDIR + 1]; +extern const int EX2[ENDDIR + 1]; +extern const int EX3[ENDDIR + 1]; - inline std::string getDirectionString(int direction) - { - switch(direction) - { - case E : return "E"; - case W : return "W"; - case N : return "N"; - case S : return "S"; - case T : return "T"; - case B : return "B"; - case NE : return "NE"; - case NW : return "NW"; - case SE : return "SE"; - case SW : return "SW"; - case TE : return "TE"; - case TW : return "TW"; - case BE : return "BE"; - case BW : return "BW"; - case TN : return "TN"; - case TS : return "TS"; - case BN : return "BN"; - case BS : return "BS"; - case TNE : return "TNE"; - case TNW : return "TNW"; - case TSE : return "TSE"; - case TSW : return "TSW"; - case BNE : return "BNE"; - case BNW : return "BNW"; - case BSE : return "BSE"; - case BSW : return "BSW"; - default : return "Cell3DSystem::getDrectionString(...) - unknown dir"; - } - } - static const int& getInvertDirection(const int& direction); +inline std::string getDirectionString(int direction) +{ + switch (direction) { + case E: + return "E"; + case W: + return "W"; + case N: + return "N"; + case S: + return "S"; + case T: + return "T"; + case B: + return "B"; + case NE: + return "NE"; + case NW: + return "NW"; + case SE: + return "SE"; + case SW: + return "SW"; + case TE: + return "TE"; + case TW: + return "TW"; + case BE: + return "BE"; + case BW: + return "BW"; + case TN: + return "TN"; + case TS: + return "TS"; + case BN: + return "BN"; + case BS: + return "BS"; + case TNE: + return "TNE"; + case TNW: + return "TNW"; + case TSE: + return "TSE"; + case TSW: + return "TSW"; + case BNE: + return "BNE"; + case BNW: + return "BNW"; + case BSE: + return "BSE"; + case BSW: + return "BSW"; + default: + return "Cell3DSystem::getDrectionString(...) - unknown dir"; + } +} +static const int &getInvertDirection(const int &direction); ////////////////////////////////////////////////////////////////////////// - static inline void setNeighborCoordinatesForDirection(int &x1, int &x2,int &x3, const int& direction) - { - switch(direction) - { - case Grid3DSystem::E : x1++; break; - case Grid3DSystem::N : x2++; break; - case Grid3DSystem::T : x3++; break; - case Grid3DSystem::W : x1--; break; - case Grid3DSystem::S : x2--; break; - case Grid3DSystem::B : x3--; break; - case Grid3DSystem::NE : x1++; x2++; break; - case Grid3DSystem::NW : x1--; x2++; break; - case Grid3DSystem::SW : x1--; x2--; break; - case Grid3DSystem::SE : x1++; x2--; break; - case Grid3DSystem::TE : x1++; x3++; break; - case Grid3DSystem::BW : x1--; x3--; break; - case Grid3DSystem::BE : x1++; x3--; break; - case Grid3DSystem::TW : x1--; x3++; break; - case Grid3DSystem::TN : x2++; x3++; break; - case Grid3DSystem::BS : x2--; x3--; break; - case Grid3DSystem::BN : x2++; x3--; break; - case Grid3DSystem::TS : x2--; x3++; break; - case Grid3DSystem::TNE: x1++; x2++; x3++; break; - case Grid3DSystem::TNW: x1--; x2++; x3++; break; - case Grid3DSystem::TSE: x1++; x2--; x3++; break; - case Grid3DSystem::TSW: x1--; x2--; x3++; break; - case Grid3DSystem::BNE: x1++; x2++; x3--; break; - case Grid3DSystem::BNW: x1--; x2++; x3--; break; - case Grid3DSystem::BSE: x1++; x2--; x3--; break; - case Grid3DSystem::BSW: x1--; x2--; x3--; break; - default: throw UbException(UB_EXARGS,"no direction ..."); - } - } +static inline void setNeighborCoordinatesForDirection(int &x1, int &x2, int &x3, const int &direction) +{ + switch (direction) { + case Grid3DSystem::E: + x1++; + break; + case Grid3DSystem::N: + x2++; + break; + case Grid3DSystem::T: + x3++; + break; + case Grid3DSystem::W: + x1--; + break; + case Grid3DSystem::S: + x2--; + break; + case Grid3DSystem::B: + x3--; + break; + case Grid3DSystem::NE: + x1++; + x2++; + break; + case Grid3DSystem::NW: + x1--; + x2++; + break; + case Grid3DSystem::SW: + x1--; + x2--; + break; + case Grid3DSystem::SE: + x1++; + x2--; + break; + case Grid3DSystem::TE: + x1++; + x3++; + break; + case Grid3DSystem::BW: + x1--; + x3--; + break; + case Grid3DSystem::BE: + x1++; + x3--; + break; + case Grid3DSystem::TW: + x1--; + x3++; + break; + case Grid3DSystem::TN: + x2++; + x3++; + break; + case Grid3DSystem::BS: + x2--; + x3--; + break; + case Grid3DSystem::BN: + x2++; + x3--; + break; + case Grid3DSystem::TS: + x2--; + x3++; + break; + case Grid3DSystem::TNE: + x1++; + x2++; + x3++; + break; + case Grid3DSystem::TNW: + x1--; + x2++; + x3++; + break; + case Grid3DSystem::TSE: + x1++; + x2--; + x3++; + break; + case Grid3DSystem::TSW: + x1--; + x2--; + x3++; + break; + case Grid3DSystem::BNE: + x1++; + x2++; + x3--; + break; + case Grid3DSystem::BNW: + x1--; + x2++; + x3--; + break; + case Grid3DSystem::BSE: + x1++; + x2--; + x3--; + break; + case Grid3DSystem::BSW: + x1--; + x2--; + x3--; + break; + default: + throw UbException(UB_EXARGS, "no direction ..."); + } } +} // namespace Grid3DSystem -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.cpp b/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.cpp index bc77cedde..55ce8d1dd 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.cpp +++ b/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,21 +34,20 @@ //======================================================================================= #include "D3Q27Interactor.h" -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbLogger.h> +#include <basics/utilities/UbMath.h> #include <basics/writer/WbWriterVtkXmlBinary.h> -#include <GbCuboid3D.h> -#include <GbLine3D.h> -#include "Block3D.h" -#include "Grid3D.h" +#include "BCAdapter.h" #include "BCArray3D.h" +#include "BCProcessor.h" +#include "Block3D.h" #include "BoundaryConditions.h" +#include "Grid3D.h" #include "LBMKernel.h" -#include "BCProcessor.h" -#include "BCAdapter.h" - +#include <GbCuboid3D.h> +#include <GbLine3D.h> using namespace std; @@ -56,139 +55,225 @@ using namespace std; ////////////////////////////////////////////////////////////////////////// D3Q27Interactor::D3Q27Interactor() : Interactor3D() { - this->reinitWithStoredQsFlag = false; - this->initRayVectors(); + this->reinitWithStoredQsFlag = false; + this->initRayVectors(); } ////////////////////////////////////////////////////////////////////////// D3Q27Interactor::D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type) -: Interactor3D(geoObject3D, grid, type), relevantForForces(false) + : Interactor3D(geoObject3D, grid, type), relevantForForces(false) { - this->reinitWithStoredQsFlag = false; - this->initRayVectors(); + this->reinitWithStoredQsFlag = false; + this->initRayVectors(); } ////////////////////////////////////////////////////////////////////////// -D3Q27Interactor::D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type) - : Interactor3D(geoObject3D, grid, type), relevantForForces(false) +D3Q27Interactor::D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type) + : Interactor3D(geoObject3D, grid, type), relevantForForces(false) { - this->reinitWithStoredQsFlag = false; - this->addBCAdapter(bcAdapter); - this->initRayVectors(); + this->reinitWithStoredQsFlag = false; + this->addBCAdapter(bcAdapter); + this->initRayVectors(); } ////////////////////////////////////////////////////////////////////////// -D3Q27Interactor::D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, Interactor3D::Accuracy a) - : Interactor3D(geoObject3D, grid, type, a), relevantForForces(false) +D3Q27Interactor::D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, + Interactor3D::Accuracy a) + : Interactor3D(geoObject3D, grid, type, a), relevantForForces(false) { - this->reinitWithStoredQsFlag = false; - this->addBCAdapter(bcAdapter); - this->initRayVectors(); + this->reinitWithStoredQsFlag = false; + this->addBCAdapter(bcAdapter); + this->initRayVectors(); } ////////////////////////////////////////////////////////////////////////// -D3Q27Interactor::~D3Q27Interactor() -= default; +D3Q27Interactor::~D3Q27Interactor() = default; ////////////////////////////////////////////////////////////////////////// void D3Q27Interactor::initRayVectors() { - int fdir; - double c1oS2 = UbMath::one_over_sqrt2; - double c1oS3 = UbMath::one_over_sqrt3; - fdir = D3Q27System::E; rayX1[fdir] = 1.0; rayX2[fdir] = 0.0; rayX3[fdir] = 0.0; - fdir = D3Q27System::W; rayX1[fdir] = -1.0; rayX2[fdir] = 0.0; rayX3[fdir] = 0.0; - fdir = D3Q27System::N; rayX1[fdir] = 0.0; rayX2[fdir] = 1.0; rayX3[fdir] = 0.0; - fdir = D3Q27System::S; rayX1[fdir] = 0.0; rayX2[fdir] = -1.0; rayX3[fdir] = 0.0; - fdir = D3Q27System::T; rayX1[fdir] = 0.0; rayX2[fdir] = 0.0; rayX3[fdir] = 1.0; - fdir = D3Q27System::B; rayX1[fdir] = 0.0; rayX2[fdir] = 0.0; rayX3[fdir] = -1.0; - fdir = D3Q27System::NE; rayX1[fdir] = c1oS2; rayX2[fdir] = c1oS2; rayX3[fdir] = 0.0; - fdir = D3Q27System::SW; rayX1[fdir] = -c1oS2; rayX2[fdir] = -c1oS2; rayX3[fdir] = 0.0; - fdir = D3Q27System::SE; rayX1[fdir] = c1oS2; rayX2[fdir] = -c1oS2; rayX3[fdir] = 0.0; - fdir = D3Q27System::NW; rayX1[fdir] = -c1oS2; rayX2[fdir] = c1oS2; rayX3[fdir] = 0.0; - fdir = D3Q27System::TE; rayX1[fdir] = c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = c1oS2; - fdir = D3Q27System::BW; rayX1[fdir] = -c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = -c1oS2; - fdir = D3Q27System::BE; rayX1[fdir] = c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = -c1oS2; - fdir = D3Q27System::TW; rayX1[fdir] = -c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = c1oS2; - fdir = D3Q27System::TN; rayX1[fdir] = 0.0; rayX2[fdir] = c1oS2; rayX3[fdir] = c1oS2; - fdir = D3Q27System::BS; rayX1[fdir] = 0.0; rayX2[fdir] =-c1oS2; rayX3[fdir] = -c1oS2; - fdir = D3Q27System::BN; rayX1[fdir] = 0.0; rayX2[fdir] = c1oS2; rayX3[fdir] = -c1oS2; - fdir = D3Q27System::TS; rayX1[fdir] = 0.0; rayX2[fdir] =-c1oS2; rayX3[fdir] = c1oS2; - - fdir = D3Q27System::TNW; rayX1[fdir] = -c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = c1oS3; - fdir = D3Q27System::TNE; rayX1[fdir] = c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = c1oS3; - fdir = D3Q27System::TSW; rayX1[fdir] = -c1oS3; rayX2[fdir] =-c1oS3; rayX3[fdir] = c1oS3; - fdir = D3Q27System::TSE; rayX1[fdir] = c1oS3; rayX2[fdir] =-c1oS3; rayX3[fdir] = c1oS3; - fdir = D3Q27System::BNW; rayX1[fdir] = -c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = -c1oS3; - fdir = D3Q27System::BNE; rayX1[fdir] = c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = -c1oS3; - fdir = D3Q27System::BSW; rayX1[fdir] = -c1oS3; rayX2[fdir] =-c1oS3; rayX3[fdir] = -c1oS3; - fdir = D3Q27System::BSE; rayX1[fdir] = c1oS3; rayX2[fdir] =-c1oS3; rayX3[fdir] = -c1oS3; + int fdir; + double c1oS2 = UbMath::one_over_sqrt2; + double c1oS3 = UbMath::one_over_sqrt3; + fdir = D3Q27System::E; + rayX1[fdir] = 1.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 0.0; + fdir = D3Q27System::W; + rayX1[fdir] = -1.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 0.0; + fdir = D3Q27System::N; + rayX1[fdir] = 0.0; + rayX2[fdir] = 1.0; + rayX3[fdir] = 0.0; + fdir = D3Q27System::S; + rayX1[fdir] = 0.0; + rayX2[fdir] = -1.0; + rayX3[fdir] = 0.0; + fdir = D3Q27System::T; + rayX1[fdir] = 0.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 1.0; + fdir = D3Q27System::B; + rayX1[fdir] = 0.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = -1.0; + fdir = D3Q27System::NE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = c1oS2; + rayX3[fdir] = 0.0; + fdir = D3Q27System::SW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = 0.0; + fdir = D3Q27System::SE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = 0.0; + fdir = D3Q27System::NW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = c1oS2; + rayX3[fdir] = 0.0; + fdir = D3Q27System::TE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = c1oS2; + fdir = D3Q27System::BW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = -c1oS2; + fdir = D3Q27System::BE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = -c1oS2; + fdir = D3Q27System::TW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = c1oS2; + fdir = D3Q27System::TN; + rayX1[fdir] = 0.0; + rayX2[fdir] = c1oS2; + rayX3[fdir] = c1oS2; + fdir = D3Q27System::BS; + rayX1[fdir] = 0.0; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = -c1oS2; + fdir = D3Q27System::BN; + rayX1[fdir] = 0.0; + rayX2[fdir] = c1oS2; + rayX3[fdir] = -c1oS2; + fdir = D3Q27System::TS; + rayX1[fdir] = 0.0; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = c1oS2; + + fdir = D3Q27System::TNW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = c1oS3; + fdir = D3Q27System::TNE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = c1oS3; + fdir = D3Q27System::TSW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = c1oS3; + fdir = D3Q27System::TSE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = c1oS3; + fdir = D3Q27System::BNW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = -c1oS3; + fdir = D3Q27System::BNE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = -c1oS3; + fdir = D3Q27System::BSW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = -c1oS3; + fdir = D3Q27System::BSE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = -c1oS3; } ////////////////////////////////////////////////////////////////////////// -void D3Q27Interactor::initInteractor(const double& timeStep) +void D3Q27Interactor::initInteractor(const double &timeStep) { - UBLOG(logDEBUG5,"D3Q27Interactor::initInteractor - "<<" for timestep = "<<timeStep); - - ////////////////////////////////////////////////////////////////////////// - //init bcs - int nofAdapter = (int)bcAdapters.size(); - if(nofAdapter==0) { UBLOG(logWARNING,"WARNING - D3Q27Interactor::initInteractor Warning - no nodeAdapter available"); } - bool needTimeDependence = false; - for(int pos=0; pos<nofAdapter; ++pos) - { - bcAdapters[pos]->init(this,timeStep); - if(bcAdapters[pos]->isTimeDependent()) needTimeDependence = true; - } - if(needTimeDependence) this->setTimeDependent(); - else this->unsetTimeDependent(); - - Interactor3D::initInteractor(timeStep); + UBLOG(logDEBUG5, "D3Q27Interactor::initInteractor - " + << " for timestep = " << timeStep); + + ////////////////////////////////////////////////////////////////////////// + // init bcs + int nofAdapter = (int)bcAdapters.size(); + if (nofAdapter == 0) { + UBLOG(logWARNING, "WARNING - D3Q27Interactor::initInteractor Warning - no nodeAdapter available"); + } + bool needTimeDependence = false; + for (int pos = 0; pos < nofAdapter; ++pos) { + bcAdapters[pos]->init(this, timeStep); + if (bcAdapters[pos]->isTimeDependent()) + needTimeDependence = true; + } + if (needTimeDependence) + this->setTimeDependent(); + else + this->unsetTimeDependent(); + + Interactor3D::initInteractor(timeStep); } ////////////////////////////////////////////////////////////////////////// -void D3Q27Interactor::updateInteractor(const double& timestep) +void D3Q27Interactor::updateInteractor(const double ×tep) { - UBLOG(logDEBUG5,"D3Q27Interactor::updateInteractor - for timestep = "<<timestep); - - ////////////////////////////////////////////////////////////////////////// - //update bcs - int nofAdapter = (int)bcAdapters.size(); - if(nofAdapter==0) { UBLOG(logERROR,"WARNING - D3Q27Interactor::updateInteractor Warning - no nodeAdapter available for "); } - - bool needTimeDependence = false; - - for(int pos=0; pos<nofAdapter; ++pos) - { - bcAdapters[pos]->update(this,timestep); - if(bcAdapters[pos]->isTimeDependent()) needTimeDependence = true; - } - if(needTimeDependence) this->setTimeDependent(); - else this->unsetTimeDependent(); - - for(BcNodeIndicesMap::value_type t : bcNodeIndicesMap) - { - SPtr<Block3D> block = t.first; - std::set< std::vector<int> >& transNodeIndicesSet = t.second; - - if(block->isNotActive() || !block) continue; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - - set< std::vector<int> >::iterator setPos; - - for(setPos=transNodeIndicesSet.begin(); setPos!=transNodeIndicesSet.end(); ++setPos) - { - int x1 = (*setPos)[0]; - int x2 = (*setPos)[1]; - int x3 = (*setPos)[2]; - Vector3D coords = grid.lock()->getNodeCoordinates(block, x1, x2, x3); - double worldX1 = coords[0]; - double worldX2 = coords[1]; - double worldX3 = coords[2]; - - SPtr<BoundaryConditions> bc = bcArray->getBC(x1,x2,x3); - if(bc) //may be that the BC has been deleted by the solid setting of another interactor - { - for(size_t i=0; i<bcAdapters.size(); i++) - bcAdapters[i]->adaptBC(*this,bc,worldX1,worldX2,worldX3,timestep); - } - } - } + UBLOG(logDEBUG5, "D3Q27Interactor::updateInteractor - for timestep = " << timestep); + + ////////////////////////////////////////////////////////////////////////// + // update bcs + int nofAdapter = (int)bcAdapters.size(); + if (nofAdapter == 0) { + UBLOG(logERROR, "WARNING - D3Q27Interactor::updateInteractor Warning - no nodeAdapter available for "); + } + + bool needTimeDependence = false; + + for (int pos = 0; pos < nofAdapter; ++pos) { + bcAdapters[pos]->update(this, timestep); + if (bcAdapters[pos]->isTimeDependent()) + needTimeDependence = true; + } + if (needTimeDependence) + this->setTimeDependent(); + else + this->unsetTimeDependent(); + + for (BcNodeIndicesMap::value_type t : bcNodeIndicesMap) { + SPtr<Block3D> block = t.first; + std::set<std::vector<int>> &transNodeIndicesSet = t.second; + + if (block->isNotActive() || !block) + continue; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + + set<std::vector<int>>::iterator setPos; + + for (setPos = transNodeIndicesSet.begin(); setPos != transNodeIndicesSet.end(); ++setPos) { + int x1 = (*setPos)[0]; + int x2 = (*setPos)[1]; + int x3 = (*setPos)[2]; + Vector3D coords = grid.lock()->getNodeCoordinates(block, x1, x2, x3); + double worldX1 = coords[0]; + double worldX2 = coords[1]; + double worldX3 = coords[2]; + + SPtr<BoundaryConditions> bc = bcArray->getBC(x1, x2, x3); + if (bc) // may be that the BC has been deleted by the solid setting of another interactor + { + for (size_t i = 0; i < bcAdapters.size(); i++) + bcAdapters[i]->adaptBC(*this, bc, worldX1, worldX2, worldX3, timestep); + } + } + } } ////////////////////////////////////////////////////////////////////////// // calculation takes place in the real coordinate system !!! @@ -197,542 +282,730 @@ void D3Q27Interactor::updateInteractor(const double& timestep) // extendedBoundingGeoOfGeoObject MUST already have been magnified by delta_x_level in each direction for SOLID bool D3Q27Interactor::setDifferencesToGbObject3D(const SPtr<Block3D> block) { - if(!block) return false; - - if(block->isNotActive()) return false;//continue; - - bcNodeIndicesMap[block] = set< std::vector<int> >(); - set< std::vector<int> >& transNodeIndices = bcNodeIndicesMap[block]; - solidNodeIndicesMap[block] = set< UbTupleInt3 >(); - set< UbTupleInt3 >& solidNodeIndices = solidNodeIndicesMap[block]; - - - double timestep = 0; - bool oneEntryGotBC = false; - bool gotQs = false; - SPtr<BoundaryConditions> bc; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - - double internX1,internX2,internX3; - - - int startIX1 = 0; - int startIX2 = 0; - int startIX3 = 0; - int stopIX1 = (int)bcArray->getNX1(); - int stopIX2 = (int)bcArray->getNX2(); - int stopIX3 = (int)bcArray->getNX3(); - - double dx = grid.lock()->getDeltaX(block); - - //other boundingRect than in init, because here the boundrect has to be increased by one dx - GbCuboid3D extendedBoundingGeoOfGeoObject( geoObject3D->getX1Minimum()-1.02*dx - , geoObject3D->getX2Minimum()-1.02*dx - , geoObject3D->getX3Minimum()-1.02*dx - , geoObject3D->getX1Maximum()+1.02*dx - , geoObject3D->getX2Maximum()+1.02*dx - , geoObject3D->getX3Maximum()+1.02*dx ); - - double deltaX1=dx, deltaX2 =dx, deltaX3=dx; - - if( geoObject3D->hasRaytracing() - || (this->isInverseSolid() && geoObject3D->raytracingSupportsPointsInside() ) ) - { - //if deltaX1==deltaX2==deltaX3 (must for LB!!) - if(!UbMath::zero( deltaX1-deltaX2 + deltaX1-deltaX3 + deltaX2-deltaX3 ) ) - throw UbException(UB_EXARGS,"fuer den bei LB nicht vorkommenden Fall deltaX1!=deltaX2!=deltaX3 nicht implementiert "); - - vector<double> distNeigh(D3Q27System::FENDDIR+1, UbMath::sqrt2*deltaX1); - distNeigh[D3Q27System::E] = distNeigh[D3Q27System::W] = distNeigh[D3Q27System::N] = deltaX1; - distNeigh[D3Q27System::S] = distNeigh[D3Q27System::T] = distNeigh[D3Q27System::B] = deltaX1; - distNeigh[D3Q27System::NE] = distNeigh[D3Q27System::NW] = distNeigh[D3Q27System::SW] = distNeigh[D3Q27System::SE] = UbMath::sqrt2*deltaX1; - distNeigh[D3Q27System::TE] = distNeigh[D3Q27System::TN] = distNeigh[D3Q27System::TW] = distNeigh[D3Q27System::TS] = UbMath::sqrt2*deltaX1; - distNeigh[D3Q27System::BE] = distNeigh[D3Q27System::BN] = distNeigh[D3Q27System::BW] = distNeigh[D3Q27System::BS] = UbMath::sqrt2*deltaX1; - distNeigh[D3Q27System::TNE] = distNeigh[D3Q27System::TNW] = distNeigh[D3Q27System::TSE] = distNeigh[D3Q27System::TSW] = UbMath::sqrt3*deltaX1; - distNeigh[D3Q27System::BNE] = distNeigh[D3Q27System::BNW] = distNeigh[D3Q27System::BSE] = distNeigh[D3Q27System::BSW] = UbMath::sqrt3*deltaX1; - double q; - bool pointOnBoundary = false; - -//#ifdef _OPENMP -// #pragma omp parallel for private(internX1,internX2,internX3,gotQs,bc,q ) -//#endif - for(int ix3=startIX3; ix3<stopIX3; ix3++) - { - for(int ix2=startIX2; ix2<stopIX2; ix2++) - { - for(int ix1=startIX1; ix1<stopIX1; ix1++) - { - //TODO: further, investigate if this is not a mistake - if(bcArray->isUndefined(ix1, ix2, ix3)) continue; - - Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); - internX1 = coords[0]; - internX2 = coords[1]; - internX3 = coords[2]; - - // Point in the object test is superfluous, since the start and stop indices already exist - // are determined -> only point-in-cube indexes are considered - if(extendedBoundingGeoOfGeoObject.isPointInGbObject3D(internX1,internX2,internX3)) - { - if(this->isSolid() ) - { - if(this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) - { - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); - } + if (!block) + return false; + + if (block->isNotActive()) + return false; // continue; + + bcNodeIndicesMap[block] = set<std::vector<int>>(); + set<std::vector<int>> &transNodeIndices = bcNodeIndicesMap[block]; + solidNodeIndicesMap[block] = set<UbTupleInt3>(); + set<UbTupleInt3> &solidNodeIndices = solidNodeIndicesMap[block]; + + double timestep = 0; + bool oneEntryGotBC = false; + bool gotQs = false; + SPtr<BoundaryConditions> bc; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + + double internX1, internX2, internX3; + + int startIX1 = 0; + int startIX2 = 0; + int startIX3 = 0; + int stopIX1 = (int)bcArray->getNX1(); + int stopIX2 = (int)bcArray->getNX2(); + int stopIX3 = (int)bcArray->getNX3(); + + double dx = grid.lock()->getDeltaX(block); + + // other boundingRect than in init, because here the boundrect has to be increased by one dx + GbCuboid3D extendedBoundingGeoOfGeoObject( + geoObject3D->getX1Minimum() - 1.02 * dx, geoObject3D->getX2Minimum() - 1.02 * dx, + geoObject3D->getX3Minimum() - 1.02 * dx, geoObject3D->getX1Maximum() + 1.02 * dx, + geoObject3D->getX2Maximum() + 1.02 * dx, geoObject3D->getX3Maximum() + 1.02 * dx); + + double deltaX1 = dx, deltaX2 = dx, deltaX3 = dx; + + if (geoObject3D->hasRaytracing() || (this->isInverseSolid() && geoObject3D->raytracingSupportsPointsInside())) { + // if deltaX1==deltaX2==deltaX3 (must for LB!!) + if (!UbMath::zero(deltaX1 - deltaX2 + deltaX1 - deltaX3 + deltaX2 - deltaX3)) + throw UbException( + UB_EXARGS, "fuer den bei LB nicht vorkommenden Fall deltaX1!=deltaX2!=deltaX3 nicht implementiert "); + + vector<double> distNeigh(D3Q27System::FENDDIR + 1, UbMath::sqrt2 * deltaX1); + distNeigh[D3Q27System::E] = distNeigh[D3Q27System::W] = distNeigh[D3Q27System::N] = deltaX1; + distNeigh[D3Q27System::S] = distNeigh[D3Q27System::T] = distNeigh[D3Q27System::B] = deltaX1; + distNeigh[D3Q27System::NE] = distNeigh[D3Q27System::NW] = distNeigh[D3Q27System::SW] = + distNeigh[D3Q27System::SE] = UbMath::sqrt2 * deltaX1; + distNeigh[D3Q27System::TE] = distNeigh[D3Q27System::TN] = distNeigh[D3Q27System::TW] = + distNeigh[D3Q27System::TS] = UbMath::sqrt2 * deltaX1; + distNeigh[D3Q27System::BE] = distNeigh[D3Q27System::BN] = distNeigh[D3Q27System::BW] = + distNeigh[D3Q27System::BS] = UbMath::sqrt2 * deltaX1; + distNeigh[D3Q27System::TNE] = distNeigh[D3Q27System::TNW] = distNeigh[D3Q27System::TSE] = + distNeigh[D3Q27System::TSW] = UbMath::sqrt3 * deltaX1; + distNeigh[D3Q27System::BNE] = distNeigh[D3Q27System::BNW] = distNeigh[D3Q27System::BSE] = + distNeigh[D3Q27System::BSW] = UbMath::sqrt3 * deltaX1; + double q; + bool pointOnBoundary = false; + + //#ifdef _OPENMP + // #pragma omp parallel for private(internX1,internX2,internX3,gotQs,bc,q ) + //#endif + for (int ix3 = startIX3; ix3 < stopIX3; ix3++) { + for (int ix2 = startIX2; ix2 < stopIX2; ix2++) { + for (int ix1 = startIX1; ix1 < stopIX1; ix1++) { + // TODO: further, investigate if this is not a mistake + if (bcArray->isUndefined(ix1, ix2, ix3)) continue; - } - } - else if( this->isInverseSolid() ) - { - //in inverse solid all nodes are OUTSIDE and on the boundary SOLID - if( !this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) - || pointOnBoundary == true ) - { - - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); + + Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); + internX1 = coords[0]; + internX2 = coords[1]; + internX3 = coords[2]; + + // Point in the object test is superfluous, since the start and stop indices already exist + // are determined -> only point-in-cube indexes are considered + if (extendedBoundingGeoOfGeoObject.isPointInGbObject3D(internX1, internX2, internX3)) { + if (this->isSolid()) { + if (this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) { + { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + continue; + } + } else if (this->isInverseSolid()) { + // in inverse solid all nodes are OUTSIDE and on the boundary SOLID + if (!this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, + pointOnBoundary) || + pointOnBoundary == true) { + + { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + continue; + } } - continue; - } - } - - if(bcArray->isSolid(ix1,ix2,ix3)) - continue; - - gotQs = false; - - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - q = geoObject3D->getIntersectionRaytraceFactor(internX1,internX2,internX3,rayX1[fdir],rayX2[fdir],rayX3[fdir]); - q /= distNeigh[fdir]; - - //assert(UbMath::lessEqual(q, 1.0)); - - if( UbMath::inClosedInterval(q, 1.0, 1.0) ) q = 1.0; - if( UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0) ) - { - //#pragma omp critical (BC_CHANGE) - { - bc = bcArray->getBC(ix1,ix2,ix3); - if(!bc) - { - bc = std::make_shared<BoundaryConditions>(); - bcArray->setBC(ix1,ix2,ix3,bc); - } - - if(bc->hasNoSlipBoundary()) - { - bc->setBoundaryVelocityX1(0.0); - bc->setBoundaryVelocityX2(0.0); - bc->setBoundaryVelocityX3(0.0); - } - - for(int index=(int)bcAdapters.size()-1; index>=0; --index) - bcAdapters[index]->adaptBCForDirection(*this,bc,internX1,internX2,internX3,q,fdir, timestep); + + if (bcArray->isSolid(ix1, ix2, ix3)) + continue; + + gotQs = false; + + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + q = geoObject3D->getIntersectionRaytraceFactor(internX1, internX2, internX3, rayX1[fdir], + rayX2[fdir], rayX3[fdir]); + q /= distNeigh[fdir]; + + // assert(UbMath::lessEqual(q, 1.0)); + + if (UbMath::inClosedInterval(q, 1.0, 1.0)) + q = 1.0; + if (UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0)) { + //#pragma omp critical (BC_CHANGE) + { + bc = bcArray->getBC(ix1, ix2, ix3); + if (!bc) { + bc = std::make_shared<BoundaryConditions>(); + bcArray->setBC(ix1, ix2, ix3, bc); + } + + if (bc->hasNoSlipBoundary()) { + bc->setBoundaryVelocityX1(0.0); + bc->setBoundaryVelocityX2(0.0); + bc->setBoundaryVelocityX3(0.0); + } + + for (int index = (int)bcAdapters.size() - 1; index >= 0; --index) + bcAdapters[index]->adaptBCForDirection(*this, bc, internX1, internX2, internX3, + q, fdir, timestep); + } + + gotQs = true; + } } - gotQs=true; - } - } - - if(gotQs) - { - { - oneEntryGotBC = true; - - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - transNodeIndices.insert(p); - - for(int index=(int)bcAdapters.size()-1; index>=0; --index) - bcAdapters[index]->adaptBC(*this,bc,internX1,internX2,internX3, timestep); - } - } - } - else if( this->isInverseSolid() ) - { - //bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID - if( !this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) - || pointOnBoundary == true ) - { - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); - } - continue; - } - } - } - } - } - } - else //clipping -> slower (currently also used for all inverse Solid objects whose raytracing does not work for nodes INSIDE the geo) - { - bool pointOnBoundary = false; - for(int ix1=startIX1; ix1<stopIX1; ix1++) - { - for(int ix2=startIX2; ix2<stopIX2; ix2++) - { - for(int ix3=startIX3; ix3<stopIX3; ix3++) - { - if(bcArray->isSolid(ix1,ix2,ix3) || bcArray->isUndefined(ix1, ix2, ix3)) continue; - - Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); - internX1 = coords[0]; - internX2 = coords[1]; - internX3 = coords[2]; - - if(extendedBoundingGeoOfGeoObject.isPointInGbObject3D(internX1,internX2,internX3)) - { - if( this->isSolid() && this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3) ) - { - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); - } - continue; - } - else if( this->isInverseSolid() ) - { - //bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID - if( !this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) - || pointOnBoundary == true ) - { - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); + if (gotQs) { + { + oneEntryGotBC = true; + + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + transNodeIndices.insert(p); + + for (int index = (int)bcAdapters.size() - 1; index >= 0; --index) + bcAdapters[index]->adaptBC(*this, bc, internX1, internX2, internX3, timestep); + } } - continue; - } - } - - gotQs = false; - - GbPoint3D pointA(internX1,internX2,internX3); - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - double x1B = internX1+D3Q27System::DX1[fdir]*deltaX1; - double x2B = internX2+D3Q27System::DX2[fdir]*deltaX2; - double x3B = internX3+D3Q27System::DX3[fdir]*deltaX3; - - GbPoint3D pointB(x1B,x2B,x3B); - GbLine3D* clippedLine = this->geoObject3D->createClippedLine3D(pointA, pointB); - - if(clippedLine) - { - double q=0.0; - if( !this->isInverseSolid() ) //A is outside - { - double distanceAB = pointA.getDistance(&pointB); //pointA to B - double distanceAP = UbMath::min(pointA.getDistance(clippedLine->getPoint1()), - pointA.getDistance(clippedLine->getPoint2()) ); - q = distanceAP/distanceAB; + } else if (this->isInverseSolid()) { + // bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID + if (!this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) || + pointOnBoundary == true) { + { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + continue; } - else - { - bool pointIsOnBoundary = false; - if( !clippedLine->getPoint1()->equals(&pointB) - && !clippedLine->getPoint2()->equals(&pointB) ) - { - //A is inside, a clipped line must not contain B - double distanceAB = pointA.getDistance(&pointB); //pointA to B - double distanceAP = clippedLine->getLength(); - q = distanceAP/distanceAB; - } - else if( this->geoObject3D->isPointInGbObject3D( pointB.getX1Coordinate() - ,pointB.getX2Coordinate() - ,pointB.getX3Coordinate() - ,pointIsOnBoundary ) - && pointIsOnBoundary ) - { - //A is definitely inside, B is exactly on ObjectBoundary => q = 1.0 - q=1.0; - } - else - { - q = 0.0; - } + } + } + } + } + } else // clipping -> slower (currently also used for all inverse Solid objects whose raytracing does not work for + // nodes INSIDE the geo) + { + bool pointOnBoundary = false; + for (int ix1 = startIX1; ix1 < stopIX1; ix1++) { + for (int ix2 = startIX2; ix2 < stopIX2; ix2++) { + for (int ix3 = startIX3; ix3 < stopIX3; ix3++) { + if (bcArray->isSolid(ix1, ix2, ix3) || bcArray->isUndefined(ix1, ix2, ix3)) + continue; + + Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); + internX1 = coords[0]; + internX2 = coords[1]; + internX3 = coords[2]; + + if (extendedBoundingGeoOfGeoObject.isPointInGbObject3D(internX1, internX2, internX3)) { + if (this->isSolid() && this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) { + { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + continue; + } else if (this->isInverseSolid()) { + // bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID + if (!this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, + pointOnBoundary) || + pointOnBoundary == true) { + { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + continue; + } } - if(UbMath::inClosedInterval(q, 1.0, 1.0)) q = 1.0; - if(UbMath::lessEqual(q, 1.0) && UbMath::greater(q, 0.0)) - { - { - bc = bcArray->getBC(ix1,ix2,ix3); - if(!bc) - { - bc = std::make_shared<BoundaryConditions>(); - bcArray->setBC(ix1,ix2,ix3,bc); - } - for(int index=(int)bcAdapters.size()-1; index>=0; --index) - bcAdapters[index]->adaptBCForDirection(*this,bc,internX1,internX2,internX3,q,fdir,timestep); - } - - gotQs=true; + gotQs = false; + + GbPoint3D pointA(internX1, internX2, internX3); + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + double x1B = internX1 + D3Q27System::DX1[fdir] * deltaX1; + double x2B = internX2 + D3Q27System::DX2[fdir] * deltaX2; + double x3B = internX3 + D3Q27System::DX3[fdir] * deltaX3; + + GbPoint3D pointB(x1B, x2B, x3B); + GbLine3D *clippedLine = this->geoObject3D->createClippedLine3D(pointA, pointB); + + if (clippedLine) { + double q = 0.0; + if (!this->isInverseSolid()) // A is outside + { + double distanceAB = pointA.getDistance(&pointB); // pointA to B + double distanceAP = UbMath::min(pointA.getDistance(clippedLine->getPoint1()), + pointA.getDistance(clippedLine->getPoint2())); + q = distanceAP / distanceAB; + } else { + bool pointIsOnBoundary = false; + if (!clippedLine->getPoint1()->equals(&pointB) && + !clippedLine->getPoint2()->equals(&pointB)) { + // A is inside, a clipped line must not contain B + double distanceAB = pointA.getDistance(&pointB); // pointA to B + double distanceAP = clippedLine->getLength(); + q = distanceAP / distanceAB; + } else if (this->geoObject3D->isPointInGbObject3D( + pointB.getX1Coordinate(), pointB.getX2Coordinate(), + pointB.getX3Coordinate(), pointIsOnBoundary) && + pointIsOnBoundary) { + // A is definitely inside, B is exactly on ObjectBoundary => q = 1.0 + q = 1.0; + } else { + q = 0.0; + } + } + + if (UbMath::inClosedInterval(q, 1.0, 1.0)) + q = 1.0; + if (UbMath::lessEqual(q, 1.0) && UbMath::greater(q, 0.0)) { + { + bc = bcArray->getBC(ix1, ix2, ix3); + if (!bc) { + bc = std::make_shared<BoundaryConditions>(); + bcArray->setBC(ix1, ix2, ix3, bc); + } + for (int index = (int)bcAdapters.size() - 1; index >= 0; --index) + bcAdapters[index]->adaptBCForDirection(*this, bc, internX1, internX2, + internX3, q, fdir, timestep); + } + + gotQs = true; + } + + clippedLine->deletePoint1(); + clippedLine->deletePoint2(); + delete clippedLine; + } } - clippedLine->deletePoint1(); - clippedLine->deletePoint2(); - delete clippedLine; - } - } - - if(gotQs) - { - { - oneEntryGotBC = true; - - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - transNodeIndices.insert(p); - - for(int index=(int)bcAdapters.size()-1; index>=0; --index) - bcAdapters[index]->adaptBC(*this,bc,internX1,internX2,internX3,timestep); - } - } - } + if (gotQs) { + { + oneEntryGotBC = true; + + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + transNodeIndices.insert(p); + + for (int index = (int)bcAdapters.size() - 1; index >= 0; --index) + bcAdapters[index]->adaptBC(*this, bc, internX1, internX2, internX3, timestep); + } + } + } + } } - } - } - } + } + } - return oneEntryGotBC; + return oneEntryGotBC; } ////////////////////////////////////////////////////////////////////////// -void D3Q27Interactor::addQsLineSet(std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines) +void D3Q27Interactor::addQsLineSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt2> &lines) { - for(SPtr<Block3D> block : bcBlocks) - { - if(!block) continue; + for (SPtr<Block3D> block : bcBlocks) { + if (!block) + continue; - double dx = grid.lock()->getDeltaX(block); - UbTupleDouble3 orgDelta = grid.lock()->getNodeOffset(block); + double dx = grid.lock()->getDeltaX(block); + UbTupleDouble3 orgDelta = grid.lock()->getNodeOffset(block); - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - map<SPtr<Block3D>, set< std::vector<int> > >::iterator pos = bcNodeIndicesMap.find(block); - if(pos==bcNodeIndicesMap.end()) - { - UB_THROW( UbException(UB_EXARGS,"block nicht in indizes map!!!") ); - } - set< std::vector<int> >& transNodeIndicesSet = pos->second; - set< std::vector<int> >::iterator setPos; + map<SPtr<Block3D>, set<std::vector<int>>>::iterator pos = bcNodeIndicesMap.find(block); + if (pos == bcNodeIndicesMap.end()) { + UB_THROW(UbException(UB_EXARGS, "block nicht in indizes map!!!")); + } + set<std::vector<int>> &transNodeIndicesSet = pos->second; + set<std::vector<int>>::iterator setPos; - std::size_t node1Index, node2Index; + std::size_t node1Index, node2Index; - UbTupleDouble3 blockOrg = grid.lock()->getBlockWorldCoordinates(block); + UbTupleDouble3 blockOrg = grid.lock()->getBlockWorldCoordinates(block); - for(setPos=transNodeIndicesSet.begin(); setPos!=transNodeIndicesSet.end(); ++setPos) - { + for (setPos = transNodeIndicesSet.begin(); setPos != transNodeIndicesSet.end(); ++setPos) { int ix1 = (*setPos)[0]; int ix2 = (*setPos)[1]; int ix3 = (*setPos)[2]; - if(bcArray->isFluid(ix1,ix2,ix3)) //it may be that the node is replaced by another interactor e.g. was marked as solid !!! + if (bcArray->isFluid( + ix1, ix2, + ix3)) // it may be that the node is replaced by another interactor e.g. was marked as solid !!! { - if( !bcArray->hasBC(ix1,ix2,ix3) ) continue; - SPtr<BoundaryConditions> bc = bcArray->getBC(ix1,ix2,ix3); - - double x1a = val<1>(blockOrg) - val<1>(orgDelta) + ix1 * dx; - double x2a = val<2>(blockOrg) - val<2>(orgDelta) + ix2 * dx; - double x3a = val<3>(blockOrg) - val<3>(orgDelta) + ix3 * dx; - nodes.push_back( makeUbTuple( (float)x1a, (float)x2a, (float)x3a ) ); - node1Index = nodes.size()-1; - - for(int dir = D3Q27System::FSTARTDIR; dir<=D3Q27System::FENDDIR; dir++) - { - if (bc->hasBoundaryConditionFlag(D3Q27System::INVDIR[dir])) - { - double x1b, x2b, x3b, q = bc->getQ(dir); - switch(dir) - { - case D3Q27System::E : x1b = x1a+q*dx; x2b = x2a ; x3b = x3a ; break; - case D3Q27System::N : x1b = x1a ; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::W : x1b = x1a-q*dx; x2b = x2a ; x3b = x3a ; break; - case D3Q27System::S : x1b = x1a ; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::NE: x1b = x1a+q*dx; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::NW: x1b = x1a-q*dx; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::SW: x1b = x1a-q*dx; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::SE: x1b = x1a+q*dx; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::T : x1b = x1a ; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TE: x1b = x1a+q*dx; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TN: x1b = x1a ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - case D3Q27System::TW: x1b = x1a-q*dx; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TS: x1b = x1a ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::B : x1b = x1a ; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BE: x1b = x1a+q*dx; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BN: x1b = x1a ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BW: x1b = x1a-q*dx; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BS: x1b = x1a ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TNE : x1b = x1a+q*dx ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - case D3Q27System::BSW : x1b = x1a-q*dx ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BNE : x1b = x1a+q*dx ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TSW : x1b = x1a-q*dx ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::TSE : x1b = x1a+q*dx ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::BNW : x1b = x1a-q*dx ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BSE : x1b = x1a+q*dx ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TNW : x1b = x1a-q*dx ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - default: throw UbException(UB_EXARGS,"unknown direction"); - } - - nodes.push_back( makeUbTuple( (float)x1b, (float)x2b, (float)x3b ) ); - node2Index = nodes.size()-1; - - lines.push_back( makeUbTuple( (int)node1Index, (int)node2Index) ); - } - } + if (!bcArray->hasBC(ix1, ix2, ix3)) + continue; + SPtr<BoundaryConditions> bc = bcArray->getBC(ix1, ix2, ix3); + + double x1a = val<1>(blockOrg) - val<1>(orgDelta) + ix1 * dx; + double x2a = val<2>(blockOrg) - val<2>(orgDelta) + ix2 * dx; + double x3a = val<3>(blockOrg) - val<3>(orgDelta) + ix3 * dx; + nodes.push_back(makeUbTuple((float)x1a, (float)x2a, (float)x3a)); + node1Index = nodes.size() - 1; + + for (int dir = D3Q27System::FSTARTDIR; dir <= D3Q27System::FENDDIR; dir++) { + if (bc->hasBoundaryConditionFlag(D3Q27System::INVDIR[dir])) { + double x1b, x2b, x3b, q = bc->getQ(dir); + switch (dir) { + case D3Q27System::E: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a; + break; + case D3Q27System::N: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::W: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a; + break; + case D3Q27System::S: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::NE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::NW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::SW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::SE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::T: + x1b = x1a; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TE: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TN: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::TW: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TS: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::B: + x1b = x1a; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BE: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BN: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BW: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BS: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TNE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::BSW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BNE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TSW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::TSE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::BNW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BSE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TNW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + default: + throw UbException(UB_EXARGS, "unknown direction"); + } + + nodes.push_back(makeUbTuple((float)x1b, (float)x2b, (float)x3b)); + node2Index = nodes.size() - 1; + + lines.push_back(makeUbTuple((int)node1Index, (int)node2Index)); + } + } } - } - } + } + } } //////////////////////////////////////////////////////////////////////////// -vector< pair<GbPoint3D,GbPoint3D> > D3Q27Interactor::getQsLineSet() +vector<pair<GbPoint3D, GbPoint3D>> D3Q27Interactor::getQsLineSet() { - vector< pair<GbPoint3D,GbPoint3D> > QsLineSet; - pair<GbPoint3D,GbPoint3D> pointpair; - - UbTupleInt3 blocknx = grid.lock()->getBlockNX(); - - int blocknx1 = val<1>(blocknx); - int blocknx2 = val<2>(blocknx); - int blocknx3 = val<3>(blocknx); - - for(SPtr<Block3D> block : bcBlocks) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); - - //Check whether top row is double in the system or not - bool include_N_Face = false; //x1=[0..blocknx1[ && x3=[0..blocknx3[ - bool include_E_Face = false; //x2=[0..blocknx2[ && x3=[0..blocknx3[ - bool include_T_Face = false; //x1=[0..blocknx1[ && x2=[0..blocknx2[ - bool include_NE_Edge = false; //(x1/x2/x3)=(blocknx1/blocknx2/[0..blocknx3[) - bool include_TN_Edge = false; //(x1/x2/x3)=([0..blocknx1[/blocknx2/blocknx1) - bool include_TE_Edge = false; //(x1/x2/x3)=(blocknx1/[0..blocknx2[/blocknx2) - if(block) - { - if( !block->getConnector(D3Q27System::N ) ) include_N_Face = true; - if( !block->getConnector(D3Q27System::E ) ) include_E_Face = true; - if( !block->getConnector(D3Q27System::T ) ) include_T_Face = true; - if( !block->getConnector(D3Q27System::NE) && include_N_Face && include_E_Face ) include_NE_Edge = true; - if( !block->getConnector(D3Q27System::TN) && include_T_Face && include_N_Face ) include_TN_Edge = true; - if( !block->getConnector(D3Q27System::TE) && include_T_Face && include_E_Face ) include_TE_Edge = true; - } - - map<SPtr<Block3D>, set< std::vector<int> > >::iterator pos = bcNodeIndicesMap.find(block); - if(pos==bcNodeIndicesMap.end()) throw UbException(UB_EXARGS,"block nicht in indizes map!!!"+block->toString()); - set< std::vector<int> >& transNodeIndicesSet = pos->second; - set< std::vector<int> >::iterator setPos; - - double x1,x2,x3,dx; - grid.lock()->calcStartCoordinatesAndDelta(block,x1,x2,x3,dx); - - for(setPos=transNodeIndicesSet.begin(); setPos!=transNodeIndicesSet.end(); ++setPos) - { - int ix1 = (*setPos)[0]; - int ix2 = (*setPos)[1]; - int ix3 = (*setPos)[2]; - - if( ( ix1<blocknx1 && ix2<blocknx2 && ix3<blocknx3 ) - || ( include_E_Face && ix1==blocknx1 && ix2<blocknx2 && ix3<blocknx3 ) - || ( include_N_Face && ix2==blocknx2 && ix1<blocknx1 && ix3<blocknx3 ) - || ( include_T_Face && ix3==blocknx3 && ix1<blocknx1 && ix2<blocknx2 ) - || ( include_NE_Edge && ix1==blocknx1 && ix2==blocknx2 ) - || ( include_TN_Edge && ix2==blocknx2 && ix3==blocknx3 ) - || ( include_TE_Edge && ix1==blocknx1 && ix3==blocknx3 ) ) - { - if(bcMatrix->isFluid(ix1,ix2,ix3)) //it may be that the node is replaced by another interactor e.g. was marked as solid !!! - { - if( !bcMatrix->hasBC(ix1,ix2,ix3) ) continue; - SPtr<BoundaryConditions> bc = bcMatrix->getBC(ix1,ix2,ix3); - double x1a = x1-val<1>(nodeOffset)+dx * ix1; - double x2a = x2-val<2>(nodeOffset)+dx * ix2; - double x3a = x3-val<3>(nodeOffset)+dx * ix3; - pointpair.first.setX1(x1a); - pointpair.first.setX2(x2a); - pointpair.first.setX3(x3a); - for(int dir = D3Q27System::FSTARTDIR; dir<=D3Q27System::FENDDIR; dir++) - { - if (bc->hasBoundaryConditionFlag(D3Q27System::INVDIR[dir])) - { - double x1b, x2b, x3b, q = bc->getQ(dir); - switch(dir) - { - case D3Q27System::E : x1b = x1a+q*dx; x2b = x2a ; x3b = x3a ; break; - case D3Q27System::N : x1b = x1a ; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::W : x1b = x1a-q*dx; x2b = x2a ; x3b = x3a ; break; - case D3Q27System::S : x1b = x1a ; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::NE: x1b = x1a+q*dx; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::NW: x1b = x1a-q*dx; x2b = x2a+q*dx; x3b = x3a ; break; - case D3Q27System::SW: x1b = x1a-q*dx; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::SE: x1b = x1a+q*dx; x2b = x2a-q*dx; x3b = x3a ; break; - case D3Q27System::T : x1b = x1a ; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TE: x1b = x1a+q*dx; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TN: x1b = x1a ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - case D3Q27System::TW: x1b = x1a-q*dx; x2b = x2a ; x3b = x3a+q*dx; break; - case D3Q27System::TS: x1b = x1a ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::B : x1b = x1a ; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BE: x1b = x1a+q*dx; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BN: x1b = x1a ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BW: x1b = x1a-q*dx; x2b = x2a ; x3b = x3a-q*dx; break; - case D3Q27System::BS: x1b = x1a ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TNE : x1b = x1a+q*dx ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - case D3Q27System::BSW : x1b = x1a-q*dx ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BNE : x1b = x1a+q*dx ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TSW : x1b = x1a-q*dx ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::TSE : x1b = x1a+q*dx ; x2b = x2a-q*dx; x3b = x3a+q*dx; break; - case D3Q27System::BNW : x1b = x1a-q*dx ; x2b = x2a+q*dx; x3b = x3a-q*dx; break; - case D3Q27System::BSE : x1b = x1a+q*dx ; x2b = x2a-q*dx; x3b = x3a-q*dx; break; - case D3Q27System::TNW : x1b = x1a-q*dx ; x2b = x2a+q*dx; x3b = x3a+q*dx; break; - default: throw UbException(UB_EXARGS,"unknown direction"); - } - pointpair.second.setX1(x1b); - pointpair.second.setX2(x2b); - pointpair.second.setX3(x3b); - QsLineSet.push_back(pointpair); - } - } + vector<pair<GbPoint3D, GbPoint3D>> QsLineSet; + pair<GbPoint3D, GbPoint3D> pointpair; + + UbTupleInt3 blocknx = grid.lock()->getBlockNX(); + + int blocknx1 = val<1>(blocknx); + int blocknx2 = val<2>(blocknx); + int blocknx3 = val<3>(blocknx); + + for (SPtr<Block3D> block : bcBlocks) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); + + // Check whether top row is double in the system or not + bool include_N_Face = false; // x1=[0..blocknx1[ && x3=[0..blocknx3[ + bool include_E_Face = false; // x2=[0..blocknx2[ && x3=[0..blocknx3[ + bool include_T_Face = false; // x1=[0..blocknx1[ && x2=[0..blocknx2[ + bool include_NE_Edge = false; //(x1/x2/x3)=(blocknx1/blocknx2/[0..blocknx3[) + bool include_TN_Edge = false; //(x1/x2/x3)=([0..blocknx1[/blocknx2/blocknx1) + bool include_TE_Edge = false; //(x1/x2/x3)=(blocknx1/[0..blocknx2[/blocknx2) + if (block) { + if (!block->getConnector(D3Q27System::N)) + include_N_Face = true; + if (!block->getConnector(D3Q27System::E)) + include_E_Face = true; + if (!block->getConnector(D3Q27System::T)) + include_T_Face = true; + if (!block->getConnector(D3Q27System::NE) && include_N_Face && include_E_Face) + include_NE_Edge = true; + if (!block->getConnector(D3Q27System::TN) && include_T_Face && include_N_Face) + include_TN_Edge = true; + if (!block->getConnector(D3Q27System::TE) && include_T_Face && include_E_Face) + include_TE_Edge = true; + } + + map<SPtr<Block3D>, set<std::vector<int>>>::iterator pos = bcNodeIndicesMap.find(block); + if (pos == bcNodeIndicesMap.end()) + throw UbException(UB_EXARGS, "block nicht in indizes map!!!" + block->toString()); + set<std::vector<int>> &transNodeIndicesSet = pos->second; + set<std::vector<int>>::iterator setPos; + + double x1, x2, x3, dx; + grid.lock()->calcStartCoordinatesAndDelta(block, x1, x2, x3, dx); + + for (setPos = transNodeIndicesSet.begin(); setPos != transNodeIndicesSet.end(); ++setPos) { + int ix1 = (*setPos)[0]; + int ix2 = (*setPos)[1]; + int ix3 = (*setPos)[2]; + if ((ix1 < blocknx1 && ix2 < blocknx2 && ix3 < blocknx3) || + (include_E_Face && ix1 == blocknx1 && ix2 < blocknx2 && ix3 < blocknx3) || + (include_N_Face && ix2 == blocknx2 && ix1 < blocknx1 && ix3 < blocknx3) || + (include_T_Face && ix3 == blocknx3 && ix1 < blocknx1 && ix2 < blocknx2) || + (include_NE_Edge && ix1 == blocknx1 && ix2 == blocknx2) || + (include_TN_Edge && ix2 == blocknx2 && ix3 == blocknx3) || + (include_TE_Edge && ix1 == blocknx1 && ix3 == blocknx3)) { + if (bcMatrix->isFluid( + ix1, ix2, + ix3)) // it may be that the node is replaced by another interactor e.g. was marked as solid !!! + { + if (!bcMatrix->hasBC(ix1, ix2, ix3)) + continue; + SPtr<BoundaryConditions> bc = bcMatrix->getBC(ix1, ix2, ix3); + double x1a = x1 - val<1>(nodeOffset) + dx * ix1; + double x2a = x2 - val<2>(nodeOffset) + dx * ix2; + double x3a = x3 - val<3>(nodeOffset) + dx * ix3; + pointpair.first.setX1(x1a); + pointpair.first.setX2(x2a); + pointpair.first.setX3(x3a); + for (int dir = D3Q27System::FSTARTDIR; dir <= D3Q27System::FENDDIR; dir++) { + if (bc->hasBoundaryConditionFlag(D3Q27System::INVDIR[dir])) { + double x1b, x2b, x3b, q = bc->getQ(dir); + switch (dir) { + case D3Q27System::E: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a; + break; + case D3Q27System::N: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::W: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a; + break; + case D3Q27System::S: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::NE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::NW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a; + break; + case D3Q27System::SW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::SE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a; + break; + case D3Q27System::T: + x1b = x1a; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TE: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TN: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::TW: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a + q * dx; + break; + case D3Q27System::TS: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::B: + x1b = x1a; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BE: + x1b = x1a + q * dx; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BN: + x1b = x1a; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BW: + x1b = x1a - q * dx; + x2b = x2a; + x3b = x3a - q * dx; + break; + case D3Q27System::BS: + x1b = x1a; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TNE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::BSW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BNE: + x1b = x1a + q * dx; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TSW: + x1b = x1a - q * dx; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::TSE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a + q * dx; + break; + case D3Q27System::BNW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::BSE: + x1b = x1a + q * dx; + x2b = x2a - q * dx; + x3b = x3a - q * dx; + break; + case D3Q27System::TNW: + x1b = x1a - q * dx; + x2b = x2a + q * dx; + x3b = x3a + q * dx; + break; + default: + throw UbException(UB_EXARGS, "unknown direction"); + } + pointpair.second.setX1(x1b); + pointpair.second.setX2(x2b); + pointpair.second.setX3(x3b); + QsLineSet.push_back(pointpair); + } + } + } } - } - } - } - return QsLineSet; + } + } + return QsLineSet; } void D3Q27Interactor::writeValidationAVSFile(string filename) { - UBLOG(logINFO,"D3Q27Interactor::writeValidationAVSFile("<<filename<<") - start "); - ofstream out(filename.c_str(),ios::out); - if(!out) throw UbException(UB_EXARGS,"couldn't open file "+filename); - - int numpoints, numlines; - vector< pair<GbPoint3D,GbPoint3D> > qsLineSet = this->getQsLineSet(); - numlines = (unsigned)qsLineSet.size(); - numpoints = numlines*2; - - out<<"# UCD-File created by D3Q27Interactor\n"; - out<<numpoints<<" "<<numlines<<" 0 0 0 "<<endl; - int nr=1; - for (int i=0; i<numlines; i++) - { - out<<nr++<<" "<<qsLineSet[i].first.getX1Coordinate() <<" " <<qsLineSet[i].first.getX2Coordinate() <<" " <<qsLineSet[i].first.getX3Coordinate() <<" \n"; - out<<nr++<<" "<<qsLineSet[i].second.getX1Coordinate()<<" " <<qsLineSet[i].second.getX2Coordinate()<<" " <<qsLineSet[i].second.getX3Coordinate() <<" \n"; - } - nr = 1; - for (int i=0; i<numlines; i++) - { - int el = nr+1; - out<<i+1<<" "<<2<<" line "<<nr<<" "<<el<<" "<<endl; - nr=el+1; - } - UBLOG(logINFO,"D3Q27Interactor::writeValidationAVSFile("<<filename<<") - end"); + UBLOG(logINFO, "D3Q27Interactor::writeValidationAVSFile(" << filename << ") - start "); + ofstream out(filename.c_str(), ios::out); + if (!out) + throw UbException(UB_EXARGS, "couldn't open file " + filename); + + int numpoints, numlines; + vector<pair<GbPoint3D, GbPoint3D>> qsLineSet = this->getQsLineSet(); + numlines = (unsigned)qsLineSet.size(); + numpoints = numlines * 2; + + out << "# UCD-File created by D3Q27Interactor\n"; + out << numpoints << " " << numlines << " 0 0 0 " << endl; + int nr = 1; + for (int i = 0; i < numlines; i++) { + out << nr++ << " " << qsLineSet[i].first.getX1Coordinate() << " " << qsLineSet[i].first.getX2Coordinate() << " " + << qsLineSet[i].first.getX3Coordinate() << " \n"; + out << nr++ << " " << qsLineSet[i].second.getX1Coordinate() << " " << qsLineSet[i].second.getX2Coordinate() + << " " << qsLineSet[i].second.getX3Coordinate() << " \n"; + } + nr = 1; + for (int i = 0; i < numlines; i++) { + int el = nr + 1; + out << i + 1 << " " << 2 << " line " << nr << " " << el << " " << endl; + nr = el + 1; + } + UBLOG(logINFO, "D3Q27Interactor::writeValidationAVSFile(" << filename << ") - end"); } diff --git a/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.h b/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.h index d0c16b2a5..4e588e96a 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.h +++ b/src/cpu/VirtualFluidsCore/Interactors/D3Q27Interactor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,79 +36,85 @@ #ifndef D3Q27INTERACTOR_H #define D3Q27INTERACTOR_H -#include <string> -#include <vector> +#include <PointerDefinitions.h> #include <map> #include <set> -#include <PointerDefinitions.h> +#include <string> +#include <vector> -#include "UbException.h" -#include "UbTuple.h" +#include "D3Q27System.h" #include "GbPoint3D.h" #include "Interactor3D.h" -#include "D3Q27System.h" +#include "UbException.h" +#include "UbTuple.h" class BCAdapter; class Block3D; class Grid3D; class GbObject3D; -using BcNodeIndicesMap = std::map<SPtr<Block3D>, std::set< std::vector<int> > >; -using SolidNodeIndicesMap = std::map<SPtr<Block3D>, std::set<UbTupleInt3> >; +using BcNodeIndicesMap = std::map<SPtr<Block3D>, std::set<std::vector<int>>>; +using SolidNodeIndicesMap = std::map<SPtr<Block3D>, std::set<UbTupleInt3>>; //! \brief A specialized class for grid generation. //! \details Support standard geometric primitives. -class D3Q27Interactor : public Interactor3D +class D3Q27Interactor : public Interactor3D { public: - D3Q27Interactor(); - D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); - D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type); - D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, Interactor3D::Accuracy a); + D3Q27Interactor(); + D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); + D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type); + D3Q27Interactor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, + Interactor3D::Accuracy a); - ~D3Q27Interactor() override; + ~D3Q27Interactor() override; - void setRelevantForForces(const bool& value) { this->relevantForForces = value; } - bool isRelevantForForces() { return this->relevantForForces; } + void setRelevantForForces(const bool &value) { this->relevantForForces = value; } + bool isRelevantForForces() { return this->relevantForForces; } - virtual void addBCAdapter(const SPtr<BCAdapter> bcAdapter) { bcAdapters.push_back(bcAdapter); } - void deleteBCAdapter() { bcAdapters.clear(); } + virtual void addBCAdapter(const SPtr<BCAdapter> bcAdapter) { bcAdapters.push_back(bcAdapter); } + void deleteBCAdapter() { bcAdapters.clear(); } - - void initInteractor(const double& timeStep=0) override; - void updateInteractor(const double& timestep=0) override; + void initInteractor(const double &timeStep = 0) override; + void updateInteractor(const double ×tep = 0) override; - void setReinitWithStoredQs(bool reinitWithStoredQsFlag) { this->reinitWithStoredQsFlag = reinitWithStoredQsFlag; } - - void removeSolidBlocks() override { Interactor3D::removeSolidBlocks(); solidNodeIndicesMap.clear(); } - void removeBcBlocks() override { Interactor3D::removeBcBlocks(); bcNodeIndicesMap.clear(); } + void setReinitWithStoredQs(bool reinitWithStoredQsFlag) { this->reinitWithStoredQsFlag = reinitWithStoredQsFlag; } - bool setDifferencesToGbObject3D(const SPtr<Block3D> block) override; + void removeSolidBlocks() override + { + Interactor3D::removeSolidBlocks(); + solidNodeIndicesMap.clear(); + } + void removeBcBlocks() override + { + Interactor3D::removeBcBlocks(); + bcNodeIndicesMap.clear(); + } - ObObject* clone() { throw UbException(UB_EXARGS,"not implemented"); } + bool setDifferencesToGbObject3D(const SPtr<Block3D> block) override; - void writeValidationAVSFile(std::string filename); - virtual std::vector< std::pair<GbPoint3D,GbPoint3D> > getQsLineSet(); + ObObject *clone() { throw UbException(UB_EXARGS, "not implemented"); } - void addQsLineSet(std::vector<UbTupleFloat3 >& nodes, std::vector<UbTupleInt2 >& lines); + void writeValidationAVSFile(std::string filename); + virtual std::vector<std::pair<GbPoint3D, GbPoint3D>> getQsLineSet(); - const BcNodeIndicesMap& getBcNodeIndicesMap() const { return bcNodeIndicesMap; } + void addQsLineSet(std::vector<UbTupleFloat3> &nodes, std::vector<UbTupleInt2> &lines); + + const BcNodeIndicesMap &getBcNodeIndicesMap() const { return bcNodeIndicesMap; } protected: - bool relevantForForces; - bool reinitWithStoredQsFlag; + bool relevantForForces; + bool reinitWithStoredQsFlag; - std::vector<SPtr<BCAdapter> > bcAdapters; + std::vector<SPtr<BCAdapter>> bcAdapters; - SolidNodeIndicesMap solidNodeIndicesMap; - BcNodeIndicesMap bcNodeIndicesMap; - - void initRayVectors(); - double rayX1[D3Q27System::FENDDIR+1]; - double rayX2[D3Q27System::FENDDIR+1]; - double rayX3[D3Q27System::FENDDIR+1]; + SolidNodeIndicesMap solidNodeIndicesMap; + BcNodeIndicesMap bcNodeIndicesMap; + void initRayVectors(); + double rayX1[D3Q27System::FENDDIR + 1]; + double rayX2[D3Q27System::FENDDIR + 1]; + double rayX3[D3Q27System::FENDDIR + 1]; }; - #endif diff --git a/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.cpp b/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.cpp index 9bdf07cce..fba352908 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.cpp +++ b/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.cpp @@ -1,562 +1,583 @@ #include "D3Q27TriFaceMeshInteractor.h" -#include <basics/utilities/UbMath.h> #include <basics/utilities/UbLogger.h> +#include <basics/utilities/UbMath.h> +#include "basics/writer/WbWriterVtkXmlASCII.h" +#include <basics/writer/WbWriterVtkASCII.h> #include <basics/writer/WbWriterVtkBinary.h> #include <basics/writer/WbWriterVtkXmlBinary.h> -#include <basics/writer/WbWriterVtkASCII.h> -#include "basics/writer/WbWriterVtkXmlASCII.h" -#include <geometry3d/GbSystem3D.h> -#include <geometry3d/GbCuboid3D.h> -#include <geometry3d/GbHalfSpace3D.h> -#include <geometry3d/GbMeshTools3D.h> -#include "Block3D.h" -#include "Grid3D.h" #include "BCArray3D.h" +#include "BCProcessor.h" +#include "Block3D.h" #include "BoundaryConditions.h" -#include "VelocityBCAdapter.h" +#include "Grid3D.h" #include "LBMKernel.h" -#include "BCProcessor.h" +#include "VelocityBCAdapter.h" #include "basics/utilities/UbTiming.h" +#include <geometry3d/GbCuboid3D.h> +#include <geometry3d/GbHalfSpace3D.h> +#include <geometry3d/GbMeshTools3D.h> +#include <geometry3d/GbSystem3D.h> #include <geometry3d/GbTriFaceMesh3D.h> //#include <omp.h> -#include <stack> #include "CoordinateTransformation3D.h" +#include <stack> using namespace std; -D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor() -: D3Q27Interactor() -{ - this->stressMode = STRESSNORMAL; -} +D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor() : D3Q27Interactor() { this->stressMode = STRESSNORMAL; } ////////////////////////////////////////////////////////////////////////// -D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<Grid3D> /*grid*/, std::string /*name*/) +D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<Grid3D> /*grid*/, std::string /*name*/) { - this->stressMode = STRESSNORMAL; + this->stressMode = STRESSNORMAL; } ////////////////////////////////////////////////////////////////////////// -D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type) -: D3Q27Interactor(triFaceMesh, grid, bcAdapter, type) +D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, + SPtr<BCAdapter> bcAdapter, int type) + : D3Q27Interactor(triFaceMesh, grid, bcAdapter, type) { - this->stressMode = STRESSNORMAL; + this->stressMode = STRESSNORMAL; } ////////////////////////////////////////////////////////////////////////// -D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, Interactor3D::Accuracy a) - : D3Q27Interactor(triFaceMesh, grid, bcAdapter, type, a) +D3Q27TriFaceMeshInteractor::D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, + SPtr<BCAdapter> bcAdapter, int type, Interactor3D::Accuracy a) + : D3Q27Interactor(triFaceMesh, grid, bcAdapter, type, a) { - this->stressMode = STRESSNORMAL; + this->stressMode = STRESSNORMAL; } ////////////////////////////////////////////////////////////////////////// -D3Q27TriFaceMeshInteractor::~D3Q27TriFaceMeshInteractor() -= default; +D3Q27TriFaceMeshInteractor::~D3Q27TriFaceMeshInteractor() = default; ////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::initInteractor(const double& timeStep) +void D3Q27TriFaceMeshInteractor::initInteractor(const double &timeStep) { - Interactor3D::initInteractor(timeStep); // FIXME: refers to a member overridden in subclass - setQs(timeStep); + Interactor3D::initInteractor(timeStep); // FIXME: refers to a member overridden in subclass + setQs(timeStep); } ////////////////////////////////////////////////////////////////////////// bool D3Q27TriFaceMeshInteractor::setDifferencesToGbObject3D(const SPtr<Block3D> block/*,const double& orgX1,const double& orgX2,const double& orgX3,const double& blockLengthX1,const double& blockLengthX2,const double& blockLengthX3, const double& timestep*/) { - if(!block) return false; - - //UBLOG(logINFO, "D3Q27TriFaceMeshInteractor::setDifferencesToGbObject3D()"); - - bcNodeIndicesMap[block] = set< std::vector<int> >(); -// set< std::vector<int> >& transNodeIndices = bcNodeIndicesMap[block]; - solidNodeIndicesMap[block] = set< UbTupleInt3 >(); - set< UbTupleInt3 >& solidNodeIndices = solidNodeIndicesMap[block]; - - - bool oneEntryGotBC = false; //ob ueberhaupt ein eintrag ein BC zugewiesen wurde -// bool gotQs = false; //true, wenn "difference" gesetzt wurde - SPtr<BoundaryConditions> bc; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - - double internX1,internX2,internX3; - - int startIX1 = 0, startIX2 = 0, startIX3 = 0; - int stopIX1 = (int)bcArray->getNX1(), stopIX2 = (int)bcArray->getNX2(), stopIX3 = (int)bcArray->getNX3(); - -// double dx = grid.lock()->getDeltaX(block); -// UbTupleDouble3 orgDelta = grid.lock()->getNodeOffset(block); - - bool pointOnBoundary = false; - - for(int ix3=startIX3; ix3<stopIX3; ix3++) - { - for(int ix2=startIX2; ix2<stopIX2; ix2++) - { - for(int ix1=startIX1; ix1<stopIX1; ix1++) - { - Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); - internX1 = coords[0]; - internX2 = coords[1]; - internX3 = coords[2]; - - if(this->isSolid() ) - { - if(this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) - { - if(bcArray->isFluid(ix1,ix2,ix3)) - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); - } - } - } - else if( this->isInverseSolid() ) - { - //bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID - if( !this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) || pointOnBoundary == true ) - { - if(bcArray->isFluid(ix1,ix2,ix3)) - { - solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); - bcArray->setSolid(ix1,ix2,ix3); - } - } - } - } - } - } + if (!block) + return false; - return oneEntryGotBC; -} -////////////////////////////////////////////////////////////////////////// -//E.F. /4/16/2013 -void D3Q27TriFaceMeshInteractor::setQs(const double& timeStep) -{ - UBLOGML(logDEBUG1,"\nLBMTriFaceMeshInteractor - setQs start "); - if( !this->grid.lock() ) throw UbException(UB_EXARGS,"ups, no grid.lock()!!"); - - if( this->reinitWithStoredQsFlag && !bcNodeIndicesAndQsMap.empty() ) - { - this->reinitWithStoredQs(timeStep); - return; - } - - GbTriFaceMesh3D* mesh = dynamic_cast<GbTriFaceMesh3D*>(this->geoObject3D.get()); - - ////////////////////////////////////////////////////////////////////////// - //init bcs - ////////////////////////////////////////////////////////////////////////// - int nofAdapter = (int)this->bcAdapters.size(); - if(nofAdapter==0) std::cout<<"WARNING - D3Q27TriFaceMeshInteractor::initInteractor Warning - no nodeAdapter available for "/*<<this->getName()*/<<std::endl; - bool needTimeDependence = false; - for(int pos=0; pos<nofAdapter; ++pos) - { - this->bcAdapters[pos]->init(this,timeStep); - if(this->bcAdapters[pos]->isTimeDependent()) needTimeDependence = true; - } - if(needTimeDependence) this->setTimeDependent(); - else this->unsetTimeDependent(); - - ////////////////////////////////////////////////////////////////////////// - //grid.lock() info - ////////////////////////////////////////////////////////////////////////// - int coarsestInitLevel = grid.lock()->getCoarsestInitializedLevel(); - int finestInitLevel = grid.lock()->getFinestInitializedLevel(); - - UbTupleInt3 blocknx = grid.lock()->getBlockNX(); - int blocknx1 = val<1>(blocknx); //gilt fuer alle Level - int blocknx2 = val<2>(blocknx); //gilt fuer alle Level - int blocknx3 = val<3>(blocknx); //gilt fuer alle Level - - //grobe Blocklaengen - SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); - double cblockDeltaX1,cblockDeltaX2,cblockDeltaX3, delta ; - cblockDeltaX1 = cblockDeltaX2 = cblockDeltaX3 = delta = 1.0/(double)(1<<coarsestInitLevel); - if(trafo) - { - cblockDeltaX1 = trafo->getX1CoordinateScaling()*delta; - cblockDeltaX2 = trafo->getX2CoordinateScaling()*delta; - cblockDeltaX3 = trafo->getX3CoordinateScaling()*delta; - } - //levelspezifische blocklaengen und knotenabstaende - std::vector< std::vector<double> > nodeDeltaToNeigh(finestInitLevel+1); - std::vector<float> deltaMinX1(finestInitLevel+1),deltaMinX2(finestInitLevel+1),deltaMinX3(finestInitLevel+1); - std::vector<float> deltaMaxX1(finestInitLevel+1),deltaMaxX2(finestInitLevel+1),deltaMaxX3(finestInitLevel+1); - - //Im Boltzmankontext muss dx1==dx2==dx3 sein!! - assert( UbMath::equal(cblockDeltaX1/(double)blocknx1, cblockDeltaX2/(double)blocknx2 ) ); - assert( UbMath::equal(cblockDeltaX1/(double)blocknx1, cblockDeltaX3/(double)blocknx3 ) ); - - for(int level = coarsestInitLevel; level<=finestInitLevel; level++) - { - double nodeDeltaX1 = cblockDeltaX1/(double)(blocknx1*(1<<(level-coarsestInitLevel))); - double nodeDeltaX2 = cblockDeltaX2/(double)(blocknx2*(1<<(level-coarsestInitLevel))); - double nodeDeltaX3 = cblockDeltaX3/(double)(blocknx3*(1<<(level-coarsestInitLevel))); - - std::vector<double> distNeigh(D3Q27System::FENDDIR+1, 0.0); - D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDeltaX1,nodeDeltaX2,nodeDeltaX3); - //D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDeltaX1); - - - nodeDeltaToNeigh[level].resize(D3Q27System::ENDDIR+1,0.0); - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - nodeDeltaToNeigh[level][fdir] = distNeigh[fdir]; - } - - //im gegensatz zum allg. Cell3DInteractor kann man hier auf max(0.02*blockDeltaX1[level],fabs(...)) verzichten - //da dies nur für blockDeltaCalculator->getMinX1Delta(level)==0.0 benötigt wird. ist im D3Q19... aber nie so - //Geller: kann man nicht diesen befuckten DeltaCalculator weglassen und hier einfach die Formel zum Delta rechnen reinpacken - //SirAnn: klar, mann kann auch weißwuerste am Alex verkaufen... aber zum einen ist das Ding dazu da - // und zum anderen sollt eman mal überlegen: "Formel zum Delta rechnen"->man muss rechnen - // blockDeltaCalculator->getMinX1Delta(level) -> ein geinlinter wert wird geholt - - //TODO: set 5.0 as variable parameter in constructor, default 2.0 - deltaMinX1[level] = (float)( 5.0*nodeDeltaX1); //kein minus da unten -deltaMin - deltaMinX2[level] = (float)( 5.0*nodeDeltaX2); - deltaMinX3[level] = (float)( 5.0*nodeDeltaX3); - deltaMaxX1[level] = (float)( 5.0*nodeDeltaX1); - deltaMaxX2[level] = (float)( 5.0*nodeDeltaX2); - deltaMaxX3[level] = (float)( 5.0*nodeDeltaX3); - } - - ////////////////////////////////////////////////////////////////////////// - //bounding cubes des TriFaceMesh ermitteln (pro level) - ////////////////////////////////////////////////////////////////////////// - //min/max Werte des Dreiecksnetzes holen -// double geoMinX1(0.0), geoMinX2(0.0), geoMinX3(0.0), geoMaxX1(0.0), geoMaxX2(0.0), geoMaxX3(0.0); - -// geoMinX1 = this->geoObject3D->getX1Minimum(); geoMaxX1 = this->geoObject3D->getX1Maximum(); -// geoMinX2 = this->geoObject3D->getX2Minimum(); geoMaxX2 = this->geoObject3D->getX2Maximum(); -// geoMinX3 = this->geoObject3D->getX3Minimum(); geoMaxX3 = this->geoObject3D->getX3Maximum(); - - - ////////////////////////////////////////////////////////////////////////// - //DREIECKE: q-Bestimmung - ////////////////////////////////////////////////////////////////////////// - - //notwendige variablen initialisieren (u.a. blockDeltas des groben levels) - float triPoints[3][3]; - float vx1=0.0, vx2=0.0, vx3=0.0; - unsigned counterTriBoxOverlap=0, counterAABBTriFace=0, counterHalfspace=0, counterBilligOBB=0; - std::vector<GbTriFaceMesh3D::TriFace>& triangles = *mesh->getTriangles(); - std::vector<GbTriFaceMesh3D::Vertex>& nodes = *mesh->getNodes(); - std::map< SPtr<Block3D>, std::set< UbTupleInt3 > > tmpSolidNodesFromOtherInteractors; - - int onePercent = UbMath::integerRounding(triangles.size()*0.01); - if(onePercent==0) onePercent=1; - UbTimer setQTimer; setQTimer.start(); - UBLOG(logDEBUG3, " - setQs for "<<(int)triangles.size()<<" triangles"); - -// bool solidFromOtherInteractor = false; - float blockMinX[3],blockMaxX[3],boxCenter[3],halfBoxSize[3]; - - for(size_t t=0; t<triangles.size(); t++) - { - ////////////////////////////////////////////////////////////////////////// - // Halfspace zum Dreieck generieren und min/max des Dreiecks ermitteln - ////////////////////////////////////////////////////////////////////////// - GbTriFaceMesh3D::TriFace& triangle = triangles[t]; - - GbTriFaceMesh3D::Vertex& v1 = nodes[triangle.v1]; - GbTriFaceMesh3D::Vertex& v2 = nodes[triangle.v2]; - GbTriFaceMesh3D::Vertex& v3 = nodes[triangle.v3]; - - if(this->isInverseSolid() ) - { - triangle.nx*=(-1); - triangle.ny*=(-1); - triangle.nz*=(-1); - } - GbHalfSpace3D halfSpace( v1.x,v1.y,v1.z,triangle.nx,triangle.ny,triangle.nz ); - - ////////////////////////////////////////////////////////////////////////// - //fuer GbMeshTools3D::triBoxOverlap - ////////////////////////////////////////////////////////////////////////// - triPoints[0][0] = v1.x; triPoints[0][1] = v1.y; triPoints[0][2] = v1.z; - triPoints[1][0] = v2.x; triPoints[1][1] = v2.y; triPoints[1][2] = v2.z; - triPoints[2][0] = v3.x; triPoints[2][1] = v3.y; triPoints[2][2] = v3.z; - - double minX1 = triangle.getMinX(nodes); double maxX1 = triangle.getMaxX(nodes); - double minX2 = triangle.getMinY(nodes); double maxX2 = triangle.getMaxY(nodes); - double minX3 = triangle.getMinZ(nodes); double maxX3 = triangle.getMaxZ(nodes); - - ////////////////////////////////////////////////////////////////////////// - // Schleife ueber alle Level - ////////////////////////////////////////////////////////////////////////// - double e1x1,e1x2,e1x3,e2x1,e2x2,e2x3,px1,px2,px3,a,f,sx1,sx2,sx3,u,qx1,qx2,qx3,v; - bool gotQs = false; - SPtr<BoundaryConditions> bc; - - for(int level=coarsestInitLevel; level<=finestInitLevel; level++) - { - ////////////////////////////////////////////////////////////////////////// - // levelspezifisches BoundCube des Dreicks ermitteln und zugehörige Bloecke beziehen - ////////////////////////////////////////////////////////////////////////// - double boundCubeTriangleMinX1 = minX1-deltaMinX1[level]; double boundCubeTriangleMaxX1 = maxX1+deltaMaxX1[level]; - double boundCubeTriangleMinX2 = minX2-deltaMinX2[level]; double boundCubeTriangleMaxX2 = maxX2+deltaMaxX2[level]; - double boundCubeTriangleMinX3 = minX3-deltaMinX3[level]; double boundCubeTriangleMaxX3 = maxX3+deltaMaxX3[level]; - - GbCuboid3D boundingCubeTriangle( boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3 - , boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3 ); - - std::vector<SPtr<Block3D>> triBlocks; - grid.lock()->getBlocksByCuboid(level, boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3 - , boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3, triBlocks ); - - ////////////////////////////////////////////////////////////////////////// - // Schleife ueber bloecke des level, die das dreieck beinhalten - ////////////////////////////////////////////////////////////////////////// - for(std::size_t b=0; b<triBlocks.size(); b++) - { - SPtr<Block3D> block = triBlocks[b]; - - //////////////////////////////////////////////////////////////////////////// - //// Block Dreieck-/test - //////////////////////////////////////////////////////////////////////////// - UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); - UbTupleDouble3 deltas = grid.lock()->getBlockLengths(block); + // UBLOG(logINFO, "D3Q27TriFaceMeshInteractor::setDifferencesToGbObject3D()"); + + bcNodeIndicesMap[block] = set<std::vector<int>>(); + // set< std::vector<int> >& transNodeIndices = bcNodeIndicesMap[block]; + solidNodeIndicesMap[block] = set<UbTupleInt3>(); + set<UbTupleInt3> &solidNodeIndices = solidNodeIndicesMap[block]; + + bool oneEntryGotBC = false; // ob ueberhaupt ein eintrag ein BC zugewiesen wurde + // bool gotQs = false; //true, wenn "difference" gesetzt wurde + SPtr<BoundaryConditions> bc; - blockMinX[0] = (float)(val<1>(coords)-deltaMinX1[level]); - blockMinX[1] = (float)(val<2>(coords)-deltaMinX2[level]); - blockMinX[2] = (float)(val<3>(coords)-deltaMinX3[level]); + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - blockMaxX[0] = (float)(val<1>(coords)+val<1>(deltas)+deltaMaxX1[level]); - blockMaxX[1] = (float)(val<2>(coords)+val<2>(deltas)+deltaMaxX2[level]); - blockMaxX[2] = (float)(val<3>(coords)+val<3>(deltas)+deltaMaxX3[level]); + double internX1, internX2, internX3; - boxCenter[0] = (float)(0.5*(blockMaxX[0]+blockMinX[0])); - boxCenter[1] = (float)(0.5*(blockMaxX[1]+blockMinX[1])); - boxCenter[2] = (float)(0.5*(blockMaxX[2]+blockMinX[2])); + int startIX1 = 0, startIX2 = 0, startIX3 = 0; + int stopIX1 = (int)bcArray->getNX1(), stopIX2 = (int)bcArray->getNX2(), stopIX3 = (int)bcArray->getNX3(); - halfBoxSize[0] = (float)(0.5*(blockMaxX[0]-blockMinX[0])); - halfBoxSize[1] = (float)(0.5*(blockMaxX[1]-blockMinX[1])); - halfBoxSize[2] = (float)(0.5*(blockMaxX[2]-blockMinX[2])); + // double dx = grid.lock()->getDeltaX(block); + // UbTupleDouble3 orgDelta = grid.lock()->getNodeOffset(block); - //wenn dreieck "vergroesserten cube" nicht schneidet/beruehrt -> keine BC moeglich -> continue - if( !GbMeshTools3D::triBoxOverlap(boxCenter,halfBoxSize,triPoints) ) - { - counterTriBoxOverlap++; - continue; + bool pointOnBoundary = false; + + for (int ix3 = startIX3; ix3 < stopIX3; ix3++) { + for (int ix2 = startIX2; ix2 < stopIX2; ix2++) { + for (int ix1 = startIX1; ix1 < stopIX1; ix1++) { + Vector3D coords = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); + internX1 = coords[0]; + internX2 = coords[1]; + internX3 = coords[2]; + + if (this->isSolid()) { + if (this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3)) { + if (bcArray->isFluid(ix1, ix2, ix3)) { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + } + } else if (this->isInverseSolid()) { + // bei inverse solid sind alle Knoten AUSSERHALB und auf der boundary SOLID + if (!this->geoObject3D->isPointInGbObject3D(internX1, internX2, internX3, pointOnBoundary) || + pointOnBoundary == true) { + if (bcArray->isFluid(ix1, ix2, ix3)) { + solidNodeIndices.insert(UbTupleInt3(ix1, ix2, ix3)); + bcArray->setSolid(ix1, ix2, ix3); + } + } + } } + } + } + return oneEntryGotBC; +} +////////////////////////////////////////////////////////////////////////// +// E.F. /4/16/2013 +void D3Q27TriFaceMeshInteractor::setQs(const double &timeStep) +{ + UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - setQs start "); + if (!this->grid.lock()) + throw UbException(UB_EXARGS, "ups, no grid.lock()!!"); + + if (this->reinitWithStoredQsFlag && !bcNodeIndicesAndQsMap.empty()) { + this->reinitWithStoredQs(timeStep); + return; + } + + GbTriFaceMesh3D *mesh = dynamic_cast<GbTriFaceMesh3D *>(this->geoObject3D.get()); + + ////////////////////////////////////////////////////////////////////////// + // init bcs + ////////////////////////////////////////////////////////////////////////// + int nofAdapter = (int)this->bcAdapters.size(); + if (nofAdapter == 0) + std::cout + << "WARNING - D3Q27TriFaceMeshInteractor::initInteractor Warning - no nodeAdapter available for " /*<<this->getName()*/ + << std::endl; + bool needTimeDependence = false; + for (int pos = 0; pos < nofAdapter; ++pos) { + this->bcAdapters[pos]->init(this, timeStep); + if (this->bcAdapters[pos]->isTimeDependent()) + needTimeDependence = true; + } + if (needTimeDependence) + this->setTimeDependent(); + else + this->unsetTimeDependent(); + + ////////////////////////////////////////////////////////////////////////// + // grid.lock() info + ////////////////////////////////////////////////////////////////////////// + int coarsestInitLevel = grid.lock()->getCoarsestInitializedLevel(); + int finestInitLevel = grid.lock()->getFinestInitializedLevel(); + + UbTupleInt3 blocknx = grid.lock()->getBlockNX(); + int blocknx1 = val<1>(blocknx); // gilt fuer alle Level + int blocknx2 = val<2>(blocknx); // gilt fuer alle Level + int blocknx3 = val<3>(blocknx); // gilt fuer alle Level + + // grobe Blocklaengen + SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); + double cblockDeltaX1, cblockDeltaX2, cblockDeltaX3, delta; + cblockDeltaX1 = cblockDeltaX2 = cblockDeltaX3 = delta = 1.0 / (double)(1 << coarsestInitLevel); + if (trafo) { + cblockDeltaX1 = trafo->getX1CoordinateScaling() * delta; + cblockDeltaX2 = trafo->getX2CoordinateScaling() * delta; + cblockDeltaX3 = trafo->getX3CoordinateScaling() * delta; + } + // levelspezifische blocklaengen und knotenabstaende + std::vector<std::vector<double>> nodeDeltaToNeigh(finestInitLevel + 1); + std::vector<float> deltaMinX1(finestInitLevel + 1), deltaMinX2(finestInitLevel + 1), + deltaMinX3(finestInitLevel + 1); + std::vector<float> deltaMaxX1(finestInitLevel + 1), deltaMaxX2(finestInitLevel + 1), + deltaMaxX3(finestInitLevel + 1); + + // Im Boltzmankontext muss dx1==dx2==dx3 sein!! + assert(UbMath::equal(cblockDeltaX1 / (double)blocknx1, cblockDeltaX2 / (double)blocknx2)); + assert(UbMath::equal(cblockDeltaX1 / (double)blocknx1, cblockDeltaX3 / (double)blocknx3)); + + for (int level = coarsestInitLevel; level <= finestInitLevel; level++) { + double nodeDeltaX1 = cblockDeltaX1 / (double)(blocknx1 * (1 << (level - coarsestInitLevel))); + double nodeDeltaX2 = cblockDeltaX2 / (double)(blocknx2 * (1 << (level - coarsestInitLevel))); + double nodeDeltaX3 = cblockDeltaX3 / (double)(blocknx3 * (1 << (level - coarsestInitLevel))); + + std::vector<double> distNeigh(D3Q27System::FENDDIR + 1, 0.0); + D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDeltaX1, nodeDeltaX2, nodeDeltaX3); + // D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDeltaX1); + + nodeDeltaToNeigh[level].resize(D3Q27System::ENDDIR + 1, 0.0); + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + nodeDeltaToNeigh[level][fdir] = distNeigh[fdir]; + } + + // im gegensatz zum allg. Cell3DInteractor kann man hier auf max(0.02*blockDeltaX1[level],fabs(...)) verzichten + // da dies nur für blockDeltaCalculator->getMinX1Delta(level)==0.0 benötigt wird. ist im D3Q19... aber nie so + // Geller: kann man nicht diesen befuckten DeltaCalculator weglassen und hier einfach die Formel zum Delta + // rechnen reinpacken SirAnn: klar, mann kann auch weißwuerste am Alex verkaufen... aber zum einen ist das Ding + // dazu da + // und zum anderen sollt eman mal überlegen: "Formel zum Delta rechnen"->man muss rechnen + // blockDeltaCalculator->getMinX1Delta(level) -> ein geinlinter wert wird geholt + + // TODO: set 5.0 as variable parameter in constructor, default 2.0 + deltaMinX1[level] = (float)(5.0 * nodeDeltaX1); // kein minus da unten -deltaMin + deltaMinX2[level] = (float)(5.0 * nodeDeltaX2); + deltaMinX3[level] = (float)(5.0 * nodeDeltaX3); + deltaMaxX1[level] = (float)(5.0 * nodeDeltaX1); + deltaMaxX2[level] = (float)(5.0 * nodeDeltaX2); + deltaMaxX3[level] = (float)(5.0 * nodeDeltaX3); + } + + ////////////////////////////////////////////////////////////////////////// + // bounding cubes des TriFaceMesh ermitteln (pro level) + ////////////////////////////////////////////////////////////////////////// + // min/max Werte des Dreiecksnetzes holen + // double geoMinX1(0.0), geoMinX2(0.0), geoMinX3(0.0), geoMaxX1(0.0), geoMaxX2(0.0), geoMaxX3(0.0); + + // geoMinX1 = this->geoObject3D->getX1Minimum(); geoMaxX1 = this->geoObject3D->getX1Maximum(); + // geoMinX2 = this->geoObject3D->getX2Minimum(); geoMaxX2 = this->geoObject3D->getX2Maximum(); + // geoMinX3 = this->geoObject3D->getX3Minimum(); geoMaxX3 = this->geoObject3D->getX3Maximum(); + + ////////////////////////////////////////////////////////////////////////// + // DREIECKE: q-Bestimmung + ////////////////////////////////////////////////////////////////////////// + + // notwendige variablen initialisieren (u.a. blockDeltas des groben levels) + float triPoints[3][3]; + float vx1 = 0.0, vx2 = 0.0, vx3 = 0.0; + unsigned counterTriBoxOverlap = 0, counterAABBTriFace = 0, counterHalfspace = 0, counterBilligOBB = 0; + std::vector<GbTriFaceMesh3D::TriFace> &triangles = *mesh->getTriangles(); + std::vector<GbTriFaceMesh3D::Vertex> &nodes = *mesh->getNodes(); + std::map<SPtr<Block3D>, std::set<UbTupleInt3>> tmpSolidNodesFromOtherInteractors; + + int onePercent = UbMath::integerRounding(triangles.size() * 0.01); + if (onePercent == 0) + onePercent = 1; + UbTimer setQTimer; + setQTimer.start(); + UBLOG(logDEBUG3, " - setQs for " << (int)triangles.size() << " triangles"); + + // bool solidFromOtherInteractor = false; + float blockMinX[3], blockMaxX[3], boxCenter[3], halfBoxSize[3]; + + for (size_t t = 0; t < triangles.size(); t++) { + ////////////////////////////////////////////////////////////////////////// + // Halfspace zum Dreieck generieren und min/max des Dreiecks ermitteln + ////////////////////////////////////////////////////////////////////////// + GbTriFaceMesh3D::TriFace &triangle = triangles[t]; + + GbTriFaceMesh3D::Vertex &v1 = nodes[triangle.v1]; + GbTriFaceMesh3D::Vertex &v2 = nodes[triangle.v2]; + GbTriFaceMesh3D::Vertex &v3 = nodes[triangle.v3]; + + if (this->isInverseSolid()) { + triangle.nx *= (-1); + triangle.ny *= (-1); + triangle.nz *= (-1); + } + GbHalfSpace3D halfSpace(v1.x, v1.y, v1.z, triangle.nx, triangle.ny, triangle.nz); + + ////////////////////////////////////////////////////////////////////////// + // fuer GbMeshTools3D::triBoxOverlap + ////////////////////////////////////////////////////////////////////////// + triPoints[0][0] = v1.x; + triPoints[0][1] = v1.y; + triPoints[0][2] = v1.z; + triPoints[1][0] = v2.x; + triPoints[1][1] = v2.y; + triPoints[1][2] = v2.z; + triPoints[2][0] = v3.x; + triPoints[2][1] = v3.y; + triPoints[2][2] = v3.z; + + double minX1 = triangle.getMinX(nodes); + double maxX1 = triangle.getMaxX(nodes); + double minX2 = triangle.getMinY(nodes); + double maxX2 = triangle.getMaxY(nodes); + double minX3 = triangle.getMinZ(nodes); + double maxX3 = triangle.getMaxZ(nodes); + + ////////////////////////////////////////////////////////////////////////// + // Schleife ueber alle Level + ////////////////////////////////////////////////////////////////////////// + double e1x1, e1x2, e1x3, e2x1, e2x2, e2x3, px1, px2, px3, a, f, sx1, sx2, sx3, u, qx1, qx2, qx3, v; + bool gotQs = false; + SPtr<BoundaryConditions> bc; + + for (int level = coarsestInitLevel; level <= finestInitLevel; level++) { ////////////////////////////////////////////////////////////////////////// - //Untersuchung der einzelnen nodes + // levelspezifisches BoundCube des Dreicks ermitteln und zugehörige Bloecke beziehen ////////////////////////////////////////////////////////////////////////// - bool blockGotBCs = false; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - - int indexMinX1 = 0; - int indexMinX2 = 0; - int indexMinX3 = 0; - - int indexMaxX1 = (int)bcMatrix->getNX1(); - int indexMaxX2 = (int)bcMatrix->getNX2(); - int indexMaxX3 = (int)bcMatrix->getNX3(); - - std::set< std::vector<int> >& bcNodeIndices = this->bcNodeIndicesMap[block]; -// std::set< UbTupleInt3 >& solidsFromOtherInteractors = tmpSolidNodesFromOtherInteractors[block]; - double q, distance; - - double& nodeDx1 = nodeDeltaToNeigh[level][D3Q27System::E]; - double& nodeDx2 = nodeDeltaToNeigh[level][D3Q27System::N]; - double& nodeDx3 = nodeDeltaToNeigh[level][D3Q27System::T]; - - //fuer OBB-Test - double qEinflussDelta = 1.1 * sqrt( nodeDx1*nodeDx1 + nodeDx2*nodeDx2 + nodeDx3*nodeDx3); - - for(int ix3=indexMinX3; ix3<indexMaxX3; ix3++) - { - for(int ix2=indexMinX2; ix2<indexMaxX2; ix2++) - { - for(int ix1=indexMinX1; ix1<indexMaxX1; ix1++) - { - Vector3D pointplane1 = grid.lock()->getNodeCoordinates(block, ix1,ix2,ix3); - double internX1 = pointplane1[0]; - double internX2 = pointplane1[1]; - double internX3 = pointplane1[2]; - -// int blx1 = block->getX1(); -// int blx2 = block->getX2(); -// int blx3 = block->getX3(); - - if(bcMatrix->isSolid(ix1,ix2,ix3) || bcMatrix->isUndefined(ix1,ix2,ix3)) - { - continue; - } - - ////////////////////////////////////////////////////////////////////////// - //Punkt in AABB von Dreieck? - ////////////////////////////////////////////////////////////////////////// - //ehsan changed - bool pointIsOnBoundary = true; - if( !boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3,pointIsOnBoundary) ) - { - counterAABBTriFace++; - continue; - } - //std::cout<<"internX3 "<<internX3<<" internX2"<<internX2<<" internX1 "<<internX1<<"\n"; - ////////////////////////////////////////////////////////////////////////// - // Halbebenentests - ////////////////////////////////////////////////////////////////////////// - distance = halfSpace.getDistance( internX1, internX2, internX3 ); - //Punkt in Halbebene? (nein, wenn distance<0) - if(useHalfSpace && UbMath::less(distance, 0.0) )//== !halfSpace.ptInside(internX1,internX2,internX3) ) - { - counterHalfspace++; - continue; - } - - //BilligOBB-Test: wenn distance > qEinflussDelta -> kein q - if( UbMath::greater( fabs(distance), qEinflussDelta ) ) - { - counterBilligOBB++; - continue; - } - - ///////////////////////////////////////////////////////////////////////////// - //Raytracingfür diskrete Boltzmannrichtungen - ///////////////////////////////////////////////////////////////////////////// - gotQs = false; - bc = SPtr<BoundaryConditions>(); - - //RAYTRACING - diskrete LB-dir zu Dreick - //e1 = v1 - v0 - e1x1 = v2.x-v1.x; - e1x2 = v2.y-v1.y; - e1x3 = v2.z-v1.z; - - //e2 = v2 - v0 - e2x1 = v3.x-v1.x; - e2x2 = v3.y-v1.y; - e2x3 = v3.z-v1.z; - - //s = o - v0 - sx1 = internX1 - v1.x; - sx2 = internX2 - v1.y; - sx3 = internX3 - v1.z; - - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - //p = d x e2 - px1 = this->rayX2[fdir]*e2x3 - this->rayX3[fdir]*e2x2; - px2 = this->rayX3[fdir]*e2x1 - this->rayX1[fdir]*e2x3; - px3 = this->rayX1[fdir]*e2x2 - this->rayX2[fdir]*e2x1; - - //a = e1 dot p - a = e1x1*px1 + e1x2*px2 + e1x3*px3; - if(fabs(a)<1.E-10) continue; - f = 1.0/a; - - //u = f * ( s dot p) - u = f * ( sx1*px1 + sx2*px2 + sx3*px3 ); - if(u<-1.E-10 || u>1.0+1.E-10) continue; - - //q = s x e1 - qx1 = sx2*e1x3 - sx3*e1x2; - qx2 = sx3*e1x1 - sx1*e1x3; - qx3 = sx1*e1x2 - sx2*e1x1; - - //v = f*(e2 dot q) - v = f * (this->rayX1[fdir]*qx1 + this->rayX2[fdir]*qx2 + this->rayX3[fdir]*qx3); - if(v<-1.E-10 || (u+v)>1.0+1.E-10) continue; - - //t = f * (e2 dot q) - q = f * (e2x1*qx1 + e2x2*qx2 + e2x3*qx3); - q /= nodeDeltaToNeigh[level][fdir]; - /////ehsan q///////////////////////////////////////////////////////////////////// - double det=triangle.nx * this->rayX1[fdir]+ triangle.ny * this->rayX2[fdir]+ triangle.nz * this->rayX3[fdir]; - - if(det>-1.E-10) continue; - double d=triangle.nx*v1.x+triangle.ny*v1.y+triangle.nz*v1.z; - double x1= -((-d* this->rayX1[fdir] - triangle.ny *this->rayX2[fdir]* internX1 - triangle.nz *this->rayX3[fdir]* internX1 + triangle.ny *this->rayX1[fdir]* internX2 + triangle.nz* this->rayX1[fdir]* internX3))/det; - double y1= -((-d* this->rayX2[fdir] + triangle.nx* this->rayX2[fdir]* internX1 - triangle.nx* this->rayX1[fdir]* internX2 - triangle.nz* this->rayX3[fdir] *internX2 + triangle.nz* this->rayX2[fdir]* internX3))/det; - double z1= -((-d* this->rayX3[fdir] + triangle.nx* this->rayX3[fdir]* internX1 + triangle.ny* this->rayX3[fdir]* internX2 - triangle.nx* this->rayX1[fdir]* internX3 - triangle.ny* this->rayX2[fdir]* internX3))/det; - double q_ehsan=sqrt((x1-internX1)*(x1-internX1)+(y1-internX2)*(y1-internX2)+(z1-internX3)*(z1-internX3)); - q_ehsan /= nodeDeltaToNeigh[level][fdir]; - q=q_ehsan; - if( UbMath::greater(q, 1.0) || UbMath::lessEqual(q, 0.0) )continue; - - //gefundenes q auf gueltigkeit pruefen - if( UbMath::zero(q) ) - { - //neu (18.05.2010) - //es kann vorkommen, dass bei dünnwandigen geos punkte, die auf einem dreieck liegen, qs bekommen, die durch die geo - //durchgehen. diese punkte werden später jedoch nicht mehr auf solid getestet, da sie ja ne BC bekommen haben - //--> da mind ein q==0.0 für eines der dreiecke -> dort solid setzen - this->solidNodeIndicesMap[block].insert( UbTupleInt3(ix1,ix2,ix3) ); - bcMatrix->setSolid( ix1, ix2, ix3 ); - continue; - } + double boundCubeTriangleMinX1 = minX1 - deltaMinX1[level]; + double boundCubeTriangleMaxX1 = maxX1 + deltaMaxX1[level]; + double boundCubeTriangleMinX2 = minX2 - deltaMinX2[level]; + double boundCubeTriangleMaxX2 = maxX2 + deltaMaxX2[level]; + double boundCubeTriangleMinX3 = minX3 - deltaMinX3[level]; + double boundCubeTriangleMaxX3 = maxX3 + deltaMaxX3[level]; + + GbCuboid3D boundingCubeTriangle(boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3, + boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3); - if( UbMath::inClosedInterval(q, 1.0, 1.0) ) q = 1.0; - if( UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0) ) - { - gotQs=blockGotBCs=true; - - bc = bcMatrix->getBC(ix1,ix2,ix3); - - //SG 26.08.2010 if(!bc && !bcMatrix->isSolid()) - if(!bc) - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions);; - bcMatrix->setBC(ix1,ix2,ix3,bc); - } - else if( UbMath::less( bc->getQ(fdir), q ) ) //schon ein kuerzeres q voehanden? - { - //neu:: 18.05.2010 - //um falsche qs die evtl durch die "wand" gehen zu vermeiden - //q nur dann neu setzen, wenn neues q kleiner als vorhandenes! - //Zudem: insbesondere an ecken mit zwei BC geos ist nur das - //naehere gueltig - continue; - } - - bc->setBoundaryVelocityX1(vx1); - bc->setBoundaryVelocityX2(vx2); - bc->setBoundaryVelocityX3(vx3); - - for(int index=(int)this->bcAdapters.size()-1; index>=0; --index) - this->bcAdapters[index]->adaptBCForDirection(*this,bc,internX1,internX2,internX3,q,fdir); - - //fuer beschleunigtes wiedereinlesen - if(this->reinitWithStoredQsFlag) - { - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ].resize(D3Q27System::FENDDIR+1+3, -1.0f); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][fdir ] = float(q); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+0] = float(internX1); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+1] = float(internX2); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+2] = float(internX3); - } + std::vector<SPtr<Block3D>> triBlocks; + grid.lock()->getBlocksByCuboid(level, boundCubeTriangleMinX1, boundCubeTriangleMinX2, + boundCubeTriangleMinX3, boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, + boundCubeTriangleMaxX3, triBlocks); + + ////////////////////////////////////////////////////////////////////////// + // Schleife ueber bloecke des level, die das dreieck beinhalten + ////////////////////////////////////////////////////////////////////////// + for (std::size_t b = 0; b < triBlocks.size(); b++) { + SPtr<Block3D> block = triBlocks[b]; + + //////////////////////////////////////////////////////////////////////////// + //// Block Dreieck-/test + //////////////////////////////////////////////////////////////////////////// + UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); + UbTupleDouble3 deltas = grid.lock()->getBlockLengths(block); + + blockMinX[0] = (float)(val<1>(coords) - deltaMinX1[level]); + blockMinX[1] = (float)(val<2>(coords) - deltaMinX2[level]); + blockMinX[2] = (float)(val<3>(coords) - deltaMinX3[level]); + + blockMaxX[0] = (float)(val<1>(coords) + val<1>(deltas) + deltaMaxX1[level]); + blockMaxX[1] = (float)(val<2>(coords) + val<2>(deltas) + deltaMaxX2[level]); + blockMaxX[2] = (float)(val<3>(coords) + val<3>(deltas) + deltaMaxX3[level]); + + boxCenter[0] = (float)(0.5 * (blockMaxX[0] + blockMinX[0])); + boxCenter[1] = (float)(0.5 * (blockMaxX[1] + blockMinX[1])); + boxCenter[2] = (float)(0.5 * (blockMaxX[2] + blockMinX[2])); + + halfBoxSize[0] = (float)(0.5 * (blockMaxX[0] - blockMinX[0])); + halfBoxSize[1] = (float)(0.5 * (blockMaxX[1] - blockMinX[1])); + halfBoxSize[2] = (float)(0.5 * (blockMaxX[2] - blockMinX[2])); + + // wenn dreieck "vergroesserten cube" nicht schneidet/beruehrt -> keine BC moeglich -> continue + if (!GbMeshTools3D::triBoxOverlap(boxCenter, halfBoxSize, triPoints)) { + counterTriBoxOverlap++; + continue; + } + + ////////////////////////////////////////////////////////////////////////// + // Untersuchung der einzelnen nodes + ////////////////////////////////////////////////////////////////////////// + bool blockGotBCs = false; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + + int indexMinX1 = 0; + int indexMinX2 = 0; + int indexMinX3 = 0; + + int indexMaxX1 = (int)bcMatrix->getNX1(); + int indexMaxX2 = (int)bcMatrix->getNX2(); + int indexMaxX3 = (int)bcMatrix->getNX3(); + + std::set<std::vector<int>> &bcNodeIndices = this->bcNodeIndicesMap[block]; + // std::set< UbTupleInt3 >& solidsFromOtherInteractors = + // tmpSolidNodesFromOtherInteractors[block]; + double q, distance; + + double &nodeDx1 = nodeDeltaToNeigh[level][D3Q27System::E]; + double &nodeDx2 = nodeDeltaToNeigh[level][D3Q27System::N]; + double &nodeDx3 = nodeDeltaToNeigh[level][D3Q27System::T]; + + // fuer OBB-Test + double qEinflussDelta = 1.1 * sqrt(nodeDx1 * nodeDx1 + nodeDx2 * nodeDx2 + nodeDx3 * nodeDx3); + + for (int ix3 = indexMinX3; ix3 < indexMaxX3; ix3++) { + for (int ix2 = indexMinX2; ix2 < indexMaxX2; ix2++) { + for (int ix1 = indexMinX1; ix1 < indexMaxX1; ix1++) { + Vector3D pointplane1 = grid.lock()->getNodeCoordinates(block, ix1, ix2, ix3); + double internX1 = pointplane1[0]; + double internX2 = pointplane1[1]; + double internX3 = pointplane1[2]; + + // int blx1 = block->getX1(); + // int blx2 = block->getX2(); + // int blx3 = block->getX3(); + + if (bcMatrix->isSolid(ix1, ix2, ix3) || bcMatrix->isUndefined(ix1, ix2, ix3)) { + continue; + } + + ////////////////////////////////////////////////////////////////////////// + // Punkt in AABB von Dreieck? + ////////////////////////////////////////////////////////////////////////// + // ehsan changed + bool pointIsOnBoundary = true; + if (!boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3, + pointIsOnBoundary)) { + counterAABBTriFace++; + continue; + } + // std::cout<<"internX3 "<<internX3<<" internX2"<<internX2<<" internX1 "<<internX1<<"\n"; + ////////////////////////////////////////////////////////////////////////// + // Halbebenentests + ////////////////////////////////////////////////////////////////////////// + distance = halfSpace.getDistance(internX1, internX2, internX3); + // Punkt in Halbebene? (nein, wenn distance<0) + if (useHalfSpace && + UbMath::less(distance, 0.0)) //== !halfSpace.ptInside(internX1,internX2,internX3) ) + { + counterHalfspace++; + continue; + } + + // BilligOBB-Test: wenn distance > qEinflussDelta -> kein q + if (UbMath::greater(fabs(distance), qEinflussDelta)) { + counterBilligOBB++; + continue; + } + + ///////////////////////////////////////////////////////////////////////////// + // Raytracingfür diskrete Boltzmannrichtungen + ///////////////////////////////////////////////////////////////////////////// + gotQs = false; + bc = SPtr<BoundaryConditions>(); + + // RAYTRACING - diskrete LB-dir zu Dreick + // e1 = v1 - v0 + e1x1 = v2.x - v1.x; + e1x2 = v2.y - v1.y; + e1x3 = v2.z - v1.z; + + // e2 = v2 - v0 + e2x1 = v3.x - v1.x; + e2x2 = v3.y - v1.y; + e2x3 = v3.z - v1.z; + + // s = o - v0 + sx1 = internX1 - v1.x; + sx2 = internX2 - v1.y; + sx3 = internX3 - v1.z; + + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + // p = d x e2 + px1 = this->rayX2[fdir] * e2x3 - this->rayX3[fdir] * e2x2; + px2 = this->rayX3[fdir] * e2x1 - this->rayX1[fdir] * e2x3; + px3 = this->rayX1[fdir] * e2x2 - this->rayX2[fdir] * e2x1; + + // a = e1 dot p + a = e1x1 * px1 + e1x2 * px2 + e1x3 * px3; + if (fabs(a) < 1.E-10) + continue; + f = 1.0 / a; + + // u = f * ( s dot p) + u = f * (sx1 * px1 + sx2 * px2 + sx3 * px3); + if (u < -1.E-10 || u > 1.0 + 1.E-10) + continue; + + // q = s x e1 + qx1 = sx2 * e1x3 - sx3 * e1x2; + qx2 = sx3 * e1x1 - sx1 * e1x3; + qx3 = sx1 * e1x2 - sx2 * e1x1; + + // v = f*(e2 dot q) + v = f * (this->rayX1[fdir] * qx1 + this->rayX2[fdir] * qx2 + this->rayX3[fdir] * qx3); + if (v < -1.E-10 || (u + v) > 1.0 + 1.E-10) + continue; + + // t = f * (e2 dot q) + q = f * (e2x1 * qx1 + e2x2 * qx2 + e2x3 * qx3); + q /= nodeDeltaToNeigh[level][fdir]; + /////ehsan q///////////////////////////////////////////////////////////////////// + double det = triangle.nx * this->rayX1[fdir] + triangle.ny * this->rayX2[fdir] + + triangle.nz * this->rayX3[fdir]; + + if (det > -1.E-10) + continue; + double d = triangle.nx * v1.x + triangle.ny * v1.y + triangle.nz * v1.z; + double x1 = -((-d * this->rayX1[fdir] - triangle.ny * this->rayX2[fdir] * internX1 - + triangle.nz * this->rayX3[fdir] * internX1 + + triangle.ny * this->rayX1[fdir] * internX2 + + triangle.nz * this->rayX1[fdir] * internX3)) / + det; + double y1 = -((-d * this->rayX2[fdir] + triangle.nx * this->rayX2[fdir] * internX1 - + triangle.nx * this->rayX1[fdir] * internX2 - + triangle.nz * this->rayX3[fdir] * internX2 + + triangle.nz * this->rayX2[fdir] * internX3)) / + det; + double z1 = -((-d * this->rayX3[fdir] + triangle.nx * this->rayX3[fdir] * internX1 + + triangle.ny * this->rayX3[fdir] * internX2 - + triangle.nx * this->rayX1[fdir] * internX3 - + triangle.ny * this->rayX2[fdir] * internX3)) / + det; + double q_ehsan = + sqrt((x1 - internX1) * (x1 - internX1) + (y1 - internX2) * (y1 - internX2) + + (z1 - internX3) * (z1 - internX3)); + q_ehsan /= nodeDeltaToNeigh[level][fdir]; + q = q_ehsan; + if (UbMath::greater(q, 1.0) || UbMath::lessEqual(q, 0.0)) + continue; + + // gefundenes q auf gueltigkeit pruefen + if (UbMath::zero(q)) { + // neu (18.05.2010) + // es kann vorkommen, dass bei dünnwandigen geos punkte, die auf einem dreieck + // liegen, qs bekommen, die durch die geo durchgehen. diese punkte werden später + // jedoch nicht mehr auf solid getestet, da sie ja ne BC bekommen haben + //--> da mind ein q==0.0 für eines der dreiecke -> dort solid setzen + this->solidNodeIndicesMap[block].insert(UbTupleInt3(ix1, ix2, ix3)); + bcMatrix->setSolid(ix1, ix2, ix3); + continue; + } + + if (UbMath::inClosedInterval(q, 1.0, 1.0)) + q = 1.0; + if (UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0)) { + gotQs = blockGotBCs = true; + + bc = bcMatrix->getBC(ix1, ix2, ix3); + + // SG 26.08.2010 if(!bc && !bcMatrix->isSolid()) + if (!bc) { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + ; + bcMatrix->setBC(ix1, ix2, ix3, bc); + } else if (UbMath::less(bc->getQ(fdir), q)) // schon ein kuerzeres q voehanden? + { + // neu:: 18.05.2010 + // um falsche qs die evtl durch die "wand" gehen zu vermeiden + // q nur dann neu setzen, wenn neues q kleiner als vorhandenes! + // Zudem: insbesondere an ecken mit zwei BC geos ist nur das + // naehere gueltig + continue; + } + + bc->setBoundaryVelocityX1(vx1); + bc->setBoundaryVelocityX2(vx2); + bc->setBoundaryVelocityX3(vx3); + + for (int index = (int)this->bcAdapters.size() - 1; index >= 0; --index) + this->bcAdapters[index]->adaptBCForDirection(*this, bc, internX1, internX2, + internX3, q, fdir); + + // fuer beschleunigtes wiedereinlesen + if (this->reinitWithStoredQsFlag) { + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)].resize( + D3Q27System::FENDDIR + 1 + 3, -1.0f); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)][fdir] = float(q); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 0] = float(internX1); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 1] = float(internX2); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 2] = float(internX3); + } + } + } + + if (gotQs) { + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + bcNodeIndices.insert(p); + + for (int index = (int)this->bcAdapters.size() - 1; index >= 0; --index) + this->bcAdapters[index]->adaptBC(*this, bc, internX1, internX2, internX3); + } } - } - - if(gotQs) - { - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - bcNodeIndices.insert(p); - - for(int index=(int)this->bcAdapters.size()-1; index>=0; --index) - this->bcAdapters[index]->adaptBC(*this,bc,internX1,internX2,internX3); - } - } - } + } + } } - } - //dynamische Punkte des GbCuboids muessen leider per "Hand" geloescht werden :-( - boundingCubeTriangle.finalize(); - } - } - UBLOGML(logDEBUG1,"\nLBMTriFaceMeshInteractor - setQs end "); + // dynamische Punkte des GbCuboids muessen leider per "Hand" geloescht werden :-( + boundingCubeTriangle.finalize(); + } + } + UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - setQs end "); } ////////////////////////////////////////////////////////////////////////// -//Vorgehesnweise -//A – Bestimmung der q's +// Vorgehesnweise +// A – Bestimmung der q's // 1. fuer jeden Bounding cube eines Dreiecks des netzes werden die Bloecke des Blockgitter ermittelt // 2. mittels eines Dreieck/Block Verschneidungstest werden weitere nicht relevante Bloecke aussortiert // (fuer lange „schief“ im Raum stehende Dreicke, bei denen das Bounding Cube suboptimal ist) @@ -564,1272 +585,1323 @@ void D3Q27TriFaceMeshInteractor::setQs(const double& timeStep) // 4. Knoten die innerhalb des Cubes aber „innerhalb“ des Netzes liegen werden mittels Halbebenentest aussoriert // 5. fuer die restliche Knoten erfolgt die q bestimmung mittels effizienter raytracing algorithmen // fuer die diskreten Boltzmannrichtungen -//B – Setzen der nicht aktiven Bloecke und Solid Nodes +// B – Setzen der nicht aktiven Bloecke und Solid Nodes // alle Bloecke des Bounding Cube des Netzes, die mind eine BC erhielten, wurden in A markiert -// 1. fuer nicht markierte Bloecke genuegt EIN pointInObject(Dreicksnetz)-Test um den gesamten Block bei Erfolg als „not active“ zu markieren +// 1. fuer nicht markierte Bloecke genuegt EIN pointInObject(Dreicksnetz)-Test um den gesamten Block bei Erfolg als +// „not active“ zu markieren // 2. fuer markiertre Bloecke wird ein rekursiver Fuellalgorithmus durchgefuehrt -void D3Q27TriFaceMeshInteractor::initInteractor2(const double& timeStep) +void D3Q27TriFaceMeshInteractor::initInteractor2(const double &timeStep) { - UBLOGML(logDEBUG1,"\nLBMTriFaceMeshInteractor - initInteractor start "); - if( !this->grid.lock() ) throw UbException(UB_EXARGS,"ups, no grid.lock()!!"); - - if( this->reinitWithStoredQsFlag && !bcNodeIndicesAndQsMap.empty() ) - { - this->reinitWithStoredQs(timeStep); - return; - } - - GbTriFaceMesh3D* mesh = dynamic_cast<GbTriFaceMesh3D*>(this->geoObject3D.get()); - - UBLOGML(logDEBUG1,"\nLBMTriFaceMeshInteractor - initInteractor for \""<<mesh->getName()<<" \" t="<<timeStep); - //cout<<" - init basics ..."; - - this->removeBcBlocks(); //hier wird auch die nodeIndicesMap geloescht! - this->removeSolidBlocks(); - - ////////////////////////////////////////////////////////////////////////// - //init bcs - ////////////////////////////////////////////////////////////////////////// - int nofAdapter = (int)this->bcAdapters.size(); - if(nofAdapter==0) std::cout<<"WARNING - D3Q27TriFaceMeshInteractor::initInteractor Warning - no nodeAdapter available for "/*<<this->getName()*/<<std::endl; - bool needTimeDependence = false; - for(int pos=0; pos<nofAdapter; ++pos) - { - this->bcAdapters[pos]->init(this,timeStep); - if(this->bcAdapters[pos]->isTimeDependent()) needTimeDependence = true; - } - if(needTimeDependence) this->setTimeDependent(); - else this->unsetTimeDependent(); - - ////////////////////////////////////////////////////////////////////////// - //grid.lock() info - ////////////////////////////////////////////////////////////////////////// - int coarsestInitLevel = grid.lock()->getCoarsestInitializedLevel(); - int finestInitLevel = grid.lock()->getFinestInitializedLevel(); - - UbTupleInt3 blocknx = grid.lock()->getBlockNX(); - int blocknx1 = val<1>(blocknx); //gilt fuer alle Level - int blocknx2 = val<2>(blocknx); //gilt fuer alle Level - int blocknx3 = val<3>(blocknx); //gilt fuer alle Level - - //grobe Blocklaengen - SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); - double cblockDeltaX1,cblockDeltaX2,cblockDeltaX3, delta ; - cblockDeltaX1 = cblockDeltaX2 = cblockDeltaX3 = delta = 1.0/(double)(1<<coarsestInitLevel); - if(trafo) - { - cblockDeltaX1 = trafo->getX1CoordinateScaling()*delta; - cblockDeltaX2 = trafo->getX2CoordinateScaling()*delta; - cblockDeltaX3 = trafo->getX3CoordinateScaling()*delta; - } - //levelspezifische blocklaengen und knotenabstaende - std::vector< std::vector<double> > nodeDeltaToNeigh(finestInitLevel+1); - //vector<double> blockDeltaX1(finestInitLevel+1), blockDeltaX2(finestInitLevel+1), blockDeltaX3(finestInitLevel+1); - std::vector<float> deltaMinX1(finestInitLevel+1),deltaMinX2(finestInitLevel+1),deltaMinX3(finestInitLevel+1); - std::vector<float> deltaMaxX1(finestInitLevel+1),deltaMaxX2(finestInitLevel+1),deltaMaxX3(finestInitLevel+1); - - //Im Boltzmankontext muss dx1==dx2==dx3 sein!! - assert( UbMath::equal(cblockDeltaX1/(double)blocknx1, cblockDeltaX2/(double)blocknx2 ) ); - assert( UbMath::equal(cblockDeltaX1/(double)blocknx1, cblockDeltaX3/(double)blocknx3 ) ); - - for(int level = coarsestInitLevel; level<=finestInitLevel; level++) - { - double nodeDelta = cblockDeltaX1/(double)(blocknx1*(1<<(level-coarsestInitLevel))); - - std::vector<double> distNeigh(D3Q27System::FENDDIR+1, 0.0); - D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDelta); - - nodeDeltaToNeigh[level].resize(D3Q27System::ENDDIR+1,0.0); - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - nodeDeltaToNeigh[level][fdir] = distNeigh[fdir]; - } - - //im gegensatz zum allg. Cell3DInteractor kann man hier auf max(0.02*blockDeltaX1[level],fabs(...)) verzichten - //da dies nur für blockDeltaCalculator->getMinX1Delta(level)==0.0 benötigt wird. ist im D3Q19... aber nie so - //Geller: kann man nicht diesen befuckten DeltaCalculator weglassen und hier einfach die Formel zum Delta rechnen reinpacken - //SirAnn: klar, mann kann auch weißwuerste am Alex verkaufen... aber zum einen ist das Ding dazu da - // und zum anderen sollt eman mal überlegen: "Formel zum Delta rechnen"->man muss rechnen - // blockDeltaCalculator->getMinX1Delta(level) -> ein geinlinter wert wird geholt - - deltaMinX1[level] = (float)( 1.2*nodeDelta); //kein minus da unten -deltaMin - deltaMinX2[level] = (float)( 1.2*nodeDelta); - deltaMinX3[level] = (float)( 1.2*nodeDelta); - deltaMaxX1[level] = (float)( 1.2*nodeDelta); - deltaMaxX2[level] = (float)( 1.2*nodeDelta); - deltaMaxX3[level] = (float)( 1.2*nodeDelta); - } - - ////////////////////////////////////////////////////////////////////////// - //bounding cubes des TriFaceMesh ermitteln (pro level) - ////////////////////////////////////////////////////////////////////////// - //min/max Werte des Dreiecksnetzes holen - double geoMinX1(0.0), geoMinX2(0.0), geoMinX3(0.0), geoMaxX1(0.0), geoMaxX2(0.0), geoMaxX3(0.0); - if(this->isSolid() || this->isMoveable()) - { - geoMinX1 = this->geoObject3D->getX1Minimum(); geoMaxX1 = this->geoObject3D->getX1Maximum(); - geoMinX2 = this->geoObject3D->getX2Minimum(); geoMaxX2 = this->geoObject3D->getX2Maximum(); - geoMinX3 = this->geoObject3D->getX3Minimum(); geoMaxX3 = this->geoObject3D->getX3Maximum(); - } - else throw UbException(UB_EXARGS,"only TYPE==SOLID is implemented" ); - - std::map<SPtr<Block3D>,SolidCheckMethod> blocksForSolidCheck; - - for(int level = coarsestInitLevel; level<=finestInitLevel; level++) - { - if(this->isSolid() || this->isMoveable()) - { - //bloecke fuer "bounding cube gesamt" - std::vector<SPtr<Block3D>> tmpblocks; - grid.lock()->getBlocksByCuboid(level,geoMinX1-deltaMinX1[level], geoMinX2-deltaMinX2[level], geoMinX3-deltaMinX3[level], - geoMaxX1+deltaMaxX1[level], geoMaxX2+deltaMaxX2[level], geoMaxX3+deltaMaxX3[level],tmpblocks ); - - for( size_t i=0; i<tmpblocks.size(); i++ ) - blocksForSolidCheck[tmpblocks[i]] = PointInObject; - } - } - - ////////////////////////////////////////////////////////////////////////// - //FE-specific - ////////////////////////////////////////////////////////////////////////// - //bool calcVelocities = false; - //FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(mesh); - //std::vector<FeTriFaceMesh3D::VertexAttributes>* attributes = NULL; - //if(feMesh) - //{ - // calcVelocities = true; - // attributes = feMesh->getAttributes(); - //} - - ////////////////////////////////////////////////////////////////////////// - //DREIECKE: q-Bestimmung - ////////////////////////////////////////////////////////////////////////// - - //notwendige variablen initialisieren (u.a. blockDeltas des groben levels) - float triPoints[3][3]; - float vx1=0.0, vx2=0.0, vx3=0.0; - unsigned counterTriBoxOverlap=0, counterAABBTriFace=0, counterHalfspace=0, counterBilligOBB=0; - std::vector<GbTriFaceMesh3D::TriFace>& triangles = *mesh->getTriangles(); - std::vector<GbTriFaceMesh3D::Vertex>& nodes = *mesh->getNodes(); - std::map< SPtr<Block3D>, std::set< std::vector<int> > > tmpSolidNodesFromOtherInteractors; - - int onePercent = UbMath::integerRounding(triangles.size()*0.01); - if(onePercent==0) onePercent=1; - UbTimer setQTimer; setQTimer.start(); - UBLOG(logDEBUG3, " - setQs for "<<(int)triangles.size()<<" triangles"); - -// bool solidFromOtherInteractor = false; - float blockMinX[3],blockMaxX[3],boxCenter[3],halfBoxSize[3]; - - for(size_t t=0; t<triangles.size(); t++) - { - //if (t==10577) - //{ - // int ehsan=0; - //} - ////////////////////////////////////////////////////////////////////////// - // Halfspace zum Dreieck generieren und min/max des Dreiecks ermitteln - ////////////////////////////////////////////////////////////////////////// - GbTriFaceMesh3D::TriFace& triangle = triangles[t]; - - GbTriFaceMesh3D::Vertex& v1 = nodes[triangle.v1]; - GbTriFaceMesh3D::Vertex& v2 = nodes[triangle.v2]; - GbTriFaceMesh3D::Vertex& v3 = nodes[triangle.v3]; - - GbHalfSpace3D halfSpace( v1.x,v1.y,v1.z,v2.x,v2.y,v2.z,v3.x,v3.y,v3.z ); - - //if(calcVelocities) - //{ - // FeTriFaceMesh3D::VertexAttributes& vAttribut1 = (*attributes)[triangle.v1]; - // FeTriFaceMesh3D::VertexAttributes& vAttribut2 = (*attributes)[triangle.v2]; - // FeTriFaceMesh3D::VertexAttributes& vAttribut3 = (*attributes)[triangle.v3]; - // vx1 = (float)(UbMath::c1o3*(vAttribut1.getVelocityX()+vAttribut2.getVelocityX()+vAttribut3.getVelocityX())); - // vx2 = (float)(UbMath::c1o3*(vAttribut1.getVelocityY()+vAttribut2.getVelocityY()+vAttribut3.getVelocityY())); - // vx3 = (float)(UbMath::c1o3*(vAttribut1.getVelocityZ()+vAttribut2.getVelocityZ()+vAttribut3.getVelocityZ())); - //} - - ////////////////////////////////////////////////////////////////////////// - //fuer GbMeshTools3D::triBoxOverlap - ////////////////////////////////////////////////////////////////////////// - triPoints[0][0] = v1.x; triPoints[0][1] = v1.y; triPoints[0][2] = v1.z; - triPoints[1][0] = v2.x; triPoints[1][1] = v2.y; triPoints[1][2] = v2.z; - triPoints[2][0] = v3.x; triPoints[2][1] = v3.y; triPoints[2][2] = v3.z; - - double minX1 = triangle.getMinX(nodes); double maxX1 = triangle.getMaxX(nodes); - double minX2 = triangle.getMinY(nodes); double maxX2 = triangle.getMaxY(nodes); - double minX3 = triangle.getMinZ(nodes); double maxX3 = triangle.getMaxZ(nodes); - - ////////////////////////////////////////////////////////////////////////// - // Schleife ueber alle Level - ////////////////////////////////////////////////////////////////////////// - double e1x1,e1x2,e1x3,e2x1,e2x2,e2x3,px1,px2,px3,a,f,sx1,sx2,sx3,u,qx1,qx2,qx3,v; - bool gotQs = false; - SPtr<BoundaryConditions> bc; - - for(int level=coarsestInitLevel; level<=finestInitLevel; level++) - { - ////////////////////////////////////////////////////////////////////////// - // levelspezifisches BoundCube des Dreicks ermitteln und zugehörige Bloecke beziehen - ////////////////////////////////////////////////////////////////////////// - double boundCubeTriangleMinX1 = minX1-deltaMinX1[level]; double boundCubeTriangleMaxX1 = maxX1+deltaMaxX1[level]; - double boundCubeTriangleMinX2 = minX2-deltaMinX2[level]; double boundCubeTriangleMaxX2 = maxX2+deltaMaxX2[level]; - double boundCubeTriangleMinX3 = minX3-deltaMinX3[level]; double boundCubeTriangleMaxX3 = maxX3+deltaMaxX3[level]; - - GbCuboid3D boundingCubeTriangle( boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3 - , boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3 ); - - std::vector<SPtr<Block3D>> triBlocks; - grid.lock()->getBlocksByCuboid(level, boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3 - , boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3, triBlocks ); - - ////////////////////////////////////////////////////////////////////////// - // Schleife ueber bloecke des level, die das dreieck beinhalten - ////////////////////////////////////////////////////////////////////////// - for(std::size_t b=0; b<triBlocks.size(); b++) - { - SPtr<Block3D> block = triBlocks[b]; - - //////////////////////////////////////////////////////////////////////////// - //// Block Dreieck-/test - //////////////////////////////////////////////////////////////////////////// - UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); - UbTupleDouble3 deltas = grid.lock()->getBlockLengths(block); - - blockMinX[0] = (float)(val<1>(coords)-deltaMinX1[level]); - blockMinX[1] = (float)(val<2>(coords)-deltaMinX2[level]); - blockMinX[2] = (float)(val<3>(coords)-deltaMinX3[level]); - - blockMaxX[0] = (float)(val<1>(coords)+val<1>(deltas)+deltaMaxX1[level]); - blockMaxX[1] = (float)(val<2>(coords)+val<2>(deltas)+deltaMaxX2[level]); - blockMaxX[2] = (float)(val<3>(coords)+val<3>(deltas)+deltaMaxX3[level]); - - boxCenter[0] = (float)(0.5*(blockMaxX[0]+blockMinX[0])); - boxCenter[1] = (float)(0.5*(blockMaxX[1]+blockMinX[1])); - boxCenter[2] = (float)(0.5*(blockMaxX[2]+blockMinX[2])); + UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - initInteractor start "); + if (!this->grid.lock()) + throw UbException(UB_EXARGS, "ups, no grid.lock()!!"); + + if (this->reinitWithStoredQsFlag && !bcNodeIndicesAndQsMap.empty()) { + this->reinitWithStoredQs(timeStep); + return; + } + + GbTriFaceMesh3D *mesh = dynamic_cast<GbTriFaceMesh3D *>(this->geoObject3D.get()); + + UBLOGML(logDEBUG1, "\nLBMTriFaceMeshInteractor - initInteractor for \"" << mesh->getName() << " \" t=" << timeStep); + // cout<<" - init basics ..."; + + this->removeBcBlocks(); // hier wird auch die nodeIndicesMap geloescht! + this->removeSolidBlocks(); + + ////////////////////////////////////////////////////////////////////////// + // init bcs + ////////////////////////////////////////////////////////////////////////// + int nofAdapter = (int)this->bcAdapters.size(); + if (nofAdapter == 0) + std::cout + << "WARNING - D3Q27TriFaceMeshInteractor::initInteractor Warning - no nodeAdapter available for " /*<<this->getName()*/ + << std::endl; + bool needTimeDependence = false; + for (int pos = 0; pos < nofAdapter; ++pos) { + this->bcAdapters[pos]->init(this, timeStep); + if (this->bcAdapters[pos]->isTimeDependent()) + needTimeDependence = true; + } + if (needTimeDependence) + this->setTimeDependent(); + else + this->unsetTimeDependent(); + + ////////////////////////////////////////////////////////////////////////// + // grid.lock() info + ////////////////////////////////////////////////////////////////////////// + int coarsestInitLevel = grid.lock()->getCoarsestInitializedLevel(); + int finestInitLevel = grid.lock()->getFinestInitializedLevel(); + + UbTupleInt3 blocknx = grid.lock()->getBlockNX(); + int blocknx1 = val<1>(blocknx); // gilt fuer alle Level + int blocknx2 = val<2>(blocknx); // gilt fuer alle Level + int blocknx3 = val<3>(blocknx); // gilt fuer alle Level + + // grobe Blocklaengen + SPtr<CoordinateTransformation3D> trafo = grid.lock()->getCoordinateTransformator(); + double cblockDeltaX1, cblockDeltaX2, cblockDeltaX3, delta; + cblockDeltaX1 = cblockDeltaX2 = cblockDeltaX3 = delta = 1.0 / (double)(1 << coarsestInitLevel); + if (trafo) { + cblockDeltaX1 = trafo->getX1CoordinateScaling() * delta; + cblockDeltaX2 = trafo->getX2CoordinateScaling() * delta; + cblockDeltaX3 = trafo->getX3CoordinateScaling() * delta; + } + // levelspezifische blocklaengen und knotenabstaende + std::vector<std::vector<double>> nodeDeltaToNeigh(finestInitLevel + 1); + // vector<double> blockDeltaX1(finestInitLevel+1), blockDeltaX2(finestInitLevel+1), blockDeltaX3(finestInitLevel+1); + std::vector<float> deltaMinX1(finestInitLevel + 1), deltaMinX2(finestInitLevel + 1), + deltaMinX3(finestInitLevel + 1); + std::vector<float> deltaMaxX1(finestInitLevel + 1), deltaMaxX2(finestInitLevel + 1), + deltaMaxX3(finestInitLevel + 1); + + // Im Boltzmankontext muss dx1==dx2==dx3 sein!! + assert(UbMath::equal(cblockDeltaX1 / (double)blocknx1, cblockDeltaX2 / (double)blocknx2)); + assert(UbMath::equal(cblockDeltaX1 / (double)blocknx1, cblockDeltaX3 / (double)blocknx3)); + + for (int level = coarsestInitLevel; level <= finestInitLevel; level++) { + double nodeDelta = cblockDeltaX1 / (double)(blocknx1 * (1 << (level - coarsestInitLevel))); + + std::vector<double> distNeigh(D3Q27System::FENDDIR + 1, 0.0); + D3Q27System::calcDistanceToNeighbors(distNeigh, nodeDelta); + + nodeDeltaToNeigh[level].resize(D3Q27System::ENDDIR + 1, 0.0); + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + nodeDeltaToNeigh[level][fdir] = distNeigh[fdir]; + } + + // im gegensatz zum allg. Cell3DInteractor kann man hier auf max(0.02*blockDeltaX1[level],fabs(...)) verzichten + // da dies nur für blockDeltaCalculator->getMinX1Delta(level)==0.0 benötigt wird. ist im D3Q19... aber nie so + // Geller: kann man nicht diesen befuckten DeltaCalculator weglassen und hier einfach die Formel zum Delta + // rechnen reinpacken SirAnn: klar, mann kann auch weißwuerste am Alex verkaufen... aber zum einen ist das Ding + // dazu da + // und zum anderen sollt eman mal überlegen: "Formel zum Delta rechnen"->man muss rechnen + // blockDeltaCalculator->getMinX1Delta(level) -> ein geinlinter wert wird geholt + + deltaMinX1[level] = (float)(1.2 * nodeDelta); // kein minus da unten -deltaMin + deltaMinX2[level] = (float)(1.2 * nodeDelta); + deltaMinX3[level] = (float)(1.2 * nodeDelta); + deltaMaxX1[level] = (float)(1.2 * nodeDelta); + deltaMaxX2[level] = (float)(1.2 * nodeDelta); + deltaMaxX3[level] = (float)(1.2 * nodeDelta); + } + + ////////////////////////////////////////////////////////////////////////// + // bounding cubes des TriFaceMesh ermitteln (pro level) + ////////////////////////////////////////////////////////////////////////// + // min/max Werte des Dreiecksnetzes holen + double geoMinX1(0.0), geoMinX2(0.0), geoMinX3(0.0), geoMaxX1(0.0), geoMaxX2(0.0), geoMaxX3(0.0); + if (this->isSolid() || this->isMoveable()) { + geoMinX1 = this->geoObject3D->getX1Minimum(); + geoMaxX1 = this->geoObject3D->getX1Maximum(); + geoMinX2 = this->geoObject3D->getX2Minimum(); + geoMaxX2 = this->geoObject3D->getX2Maximum(); + geoMinX3 = this->geoObject3D->getX3Minimum(); + geoMaxX3 = this->geoObject3D->getX3Maximum(); + } else + throw UbException(UB_EXARGS, "only TYPE==SOLID is implemented"); + + std::map<SPtr<Block3D>, SolidCheckMethod> blocksForSolidCheck; + + for (int level = coarsestInitLevel; level <= finestInitLevel; level++) { + if (this->isSolid() || this->isMoveable()) { + // bloecke fuer "bounding cube gesamt" + std::vector<SPtr<Block3D>> tmpblocks; + grid.lock()->getBlocksByCuboid(level, geoMinX1 - deltaMinX1[level], geoMinX2 - deltaMinX2[level], + geoMinX3 - deltaMinX3[level], geoMaxX1 + deltaMaxX1[level], + geoMaxX2 + deltaMaxX2[level], geoMaxX3 + deltaMaxX3[level], tmpblocks); + + for (size_t i = 0; i < tmpblocks.size(); i++) + blocksForSolidCheck[tmpblocks[i]] = PointInObject; + } + } + + ////////////////////////////////////////////////////////////////////////// + // FE-specific + ////////////////////////////////////////////////////////////////////////// + // bool calcVelocities = false; + // FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(mesh); + // std::vector<FeTriFaceMesh3D::VertexAttributes>* attributes = NULL; + // if(feMesh) + //{ + // calcVelocities = true; + // attributes = feMesh->getAttributes(); + //} + + ////////////////////////////////////////////////////////////////////////// + // DREIECKE: q-Bestimmung + ////////////////////////////////////////////////////////////////////////// + + // notwendige variablen initialisieren (u.a. blockDeltas des groben levels) + float triPoints[3][3]; + float vx1 = 0.0, vx2 = 0.0, vx3 = 0.0; + unsigned counterTriBoxOverlap = 0, counterAABBTriFace = 0, counterHalfspace = 0, counterBilligOBB = 0; + std::vector<GbTriFaceMesh3D::TriFace> &triangles = *mesh->getTriangles(); + std::vector<GbTriFaceMesh3D::Vertex> &nodes = *mesh->getNodes(); + std::map<SPtr<Block3D>, std::set<std::vector<int>>> tmpSolidNodesFromOtherInteractors; + + int onePercent = UbMath::integerRounding(triangles.size() * 0.01); + if (onePercent == 0) + onePercent = 1; + UbTimer setQTimer; + setQTimer.start(); + UBLOG(logDEBUG3, " - setQs for " << (int)triangles.size() << " triangles"); + + // bool solidFromOtherInteractor = false; + float blockMinX[3], blockMaxX[3], boxCenter[3], halfBoxSize[3]; + + for (size_t t = 0; t < triangles.size(); t++) { + // if (t==10577) + //{ + // int ehsan=0; + //} + ////////////////////////////////////////////////////////////////////////// + // Halfspace zum Dreieck generieren und min/max des Dreiecks ermitteln + ////////////////////////////////////////////////////////////////////////// + GbTriFaceMesh3D::TriFace &triangle = triangles[t]; + + GbTriFaceMesh3D::Vertex &v1 = nodes[triangle.v1]; + GbTriFaceMesh3D::Vertex &v2 = nodes[triangle.v2]; + GbTriFaceMesh3D::Vertex &v3 = nodes[triangle.v3]; + + GbHalfSpace3D halfSpace(v1.x, v1.y, v1.z, v2.x, v2.y, v2.z, v3.x, v3.y, v3.z); + + // if(calcVelocities) + //{ + // FeTriFaceMesh3D::VertexAttributes& vAttribut1 = (*attributes)[triangle.v1]; + // FeTriFaceMesh3D::VertexAttributes& vAttribut2 = (*attributes)[triangle.v2]; + // FeTriFaceMesh3D::VertexAttributes& vAttribut3 = (*attributes)[triangle.v3]; + // vx1 = + // (float)(UbMath::c1o3*(vAttribut1.getVelocityX()+vAttribut2.getVelocityX()+vAttribut3.getVelocityX())); vx2 + // = (float)(UbMath::c1o3*(vAttribut1.getVelocityY()+vAttribut2.getVelocityY()+vAttribut3.getVelocityY())); + // vx3 = + // (float)(UbMath::c1o3*(vAttribut1.getVelocityZ()+vAttribut2.getVelocityZ()+vAttribut3.getVelocityZ())); + //} + + ////////////////////////////////////////////////////////////////////////// + // fuer GbMeshTools3D::triBoxOverlap + ////////////////////////////////////////////////////////////////////////// + triPoints[0][0] = v1.x; + triPoints[0][1] = v1.y; + triPoints[0][2] = v1.z; + triPoints[1][0] = v2.x; + triPoints[1][1] = v2.y; + triPoints[1][2] = v2.z; + triPoints[2][0] = v3.x; + triPoints[2][1] = v3.y; + triPoints[2][2] = v3.z; + + double minX1 = triangle.getMinX(nodes); + double maxX1 = triangle.getMaxX(nodes); + double minX2 = triangle.getMinY(nodes); + double maxX2 = triangle.getMaxY(nodes); + double minX3 = triangle.getMinZ(nodes); + double maxX3 = triangle.getMaxZ(nodes); + + ////////////////////////////////////////////////////////////////////////// + // Schleife ueber alle Level + ////////////////////////////////////////////////////////////////////////// + double e1x1, e1x2, e1x3, e2x1, e2x2, e2x3, px1, px2, px3, a, f, sx1, sx2, sx3, u, qx1, qx2, qx3, v; + bool gotQs = false; + SPtr<BoundaryConditions> bc; + + for (int level = coarsestInitLevel; level <= finestInitLevel; level++) { + ////////////////////////////////////////////////////////////////////////// + // levelspezifisches BoundCube des Dreicks ermitteln und zugehörige Bloecke beziehen + ////////////////////////////////////////////////////////////////////////// + double boundCubeTriangleMinX1 = minX1 - deltaMinX1[level]; + double boundCubeTriangleMaxX1 = maxX1 + deltaMaxX1[level]; + double boundCubeTriangleMinX2 = minX2 - deltaMinX2[level]; + double boundCubeTriangleMaxX2 = maxX2 + deltaMaxX2[level]; + double boundCubeTriangleMinX3 = minX3 - deltaMinX3[level]; + double boundCubeTriangleMaxX3 = maxX3 + deltaMaxX3[level]; - halfBoxSize[0] = (float)(0.5*(blockMaxX[0]-blockMinX[0])); - halfBoxSize[1] = (float)(0.5*(blockMaxX[1]-blockMinX[1])); - halfBoxSize[2] = (float)(0.5*(blockMaxX[2]-blockMinX[2])); + GbCuboid3D boundingCubeTriangle(boundCubeTriangleMinX1, boundCubeTriangleMinX2, boundCubeTriangleMinX3, + boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, boundCubeTriangleMaxX3); - //wenn dreieck "vergroesserten cube" nicht schneidet/beruehrt -> keine BC moeglich -> continue - if( !GbMeshTools3D::triBoxOverlap(boxCenter,halfBoxSize,triPoints) ) - { - counterTriBoxOverlap++; - continue; - } + std::vector<SPtr<Block3D>> triBlocks; + grid.lock()->getBlocksByCuboid(level, boundCubeTriangleMinX1, boundCubeTriangleMinX2, + boundCubeTriangleMinX3, boundCubeTriangleMaxX1, boundCubeTriangleMaxX2, + boundCubeTriangleMaxX3, triBlocks); ////////////////////////////////////////////////////////////////////////// - //Untersuchung der einzelnen nodes + // Schleife ueber bloecke des level, die das dreieck beinhalten ////////////////////////////////////////////////////////////////////////// - bool blockGotBCs = false; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - - int indexMinX1 = 0; - int indexMinX2 = 0; - int indexMinX3 = 0; - - int indexMaxX1 = (int)bcMatrix->getNX1(); - int indexMaxX2 = (int)bcMatrix->getNX2(); - int indexMaxX3 = (int)bcMatrix->getNX3(); - - std::set< std::vector<int> >& bcNodeIndices = this->bcNodeIndicesMap[block]; - std::set< std::vector<int> >& solidsFromOtherInteractors = tmpSolidNodesFromOtherInteractors[block]; - double q, internX1, internX2, internX3,distance; - - double& nodeDx1 = nodeDeltaToNeigh[level][D3Q27System::E]; - double& nodeDx2 = nodeDeltaToNeigh[level][D3Q27System::N]; - double& nodeDx3 = nodeDeltaToNeigh[level][D3Q27System::T]; - - //fuer OBB-Test - double qEinflussDelta = 1.1 * sqrt( nodeDx1*nodeDx1 + nodeDx2*nodeDx2 + nodeDx3*nodeDx3); - - for(int ix3=indexMinX3; ix3<indexMaxX3; ix3++) - { - internX3 = val<3>(coords)+nodeDx3*ix3-0.5*nodeDx3; - for(int ix2=indexMinX2; ix2<indexMaxX2; ix2++) - { - internX2 = val<2>(coords)+nodeDx2*ix2-0.5*nodeDx2; - for(int ix1=indexMinX1; ix1<indexMaxX1; ix1++) - { - -// int blx1 =block->getX1(); -// int blx2 = block->getX2(); -// int blx3 = block->getX3(); - -// if (blx1==0&&blx2==1&&blx3==0) -// { -// //if (ix2==39&&ix3==4) -// if (ix2==39&&ix3==4) -// { -// int seb=0; -// } -// } - //Problem: wenn voher der punkt durch eine andere geo not active gesetzt wird und - //dieser nun uebersprungen wird, dann hat man spaeter beim fuellalgorithmus luecken - //in der front und der block wird u.U. faelschlicher weise komplett solid markiert - //Lsg: positionen merken und erst Nach dem fuellarlgo wieder auf not active setzen :-) -// solidFromOtherInteractor = false; - if(bcMatrix->isSolid(ix1,ix2,ix3)) - { - if(this->reinitWithStoredQsFlag) - { - //solidFromOtherInteractor = true; //hier muss man weitermachen - //SG //oje - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - solidsFromOtherInteractors.insert( p ); - } - else - { - //SG //oje - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - solidsFromOtherInteractors.insert(p); - //SG continue; - //solidFromOtherInteractor = true; - } - } - - internX1 = val<1>(coords)+nodeDx1*ix1-0.5*nodeDx1; - - ////////////////////////////////////////////////////////////////////////// - //Punkt in AABB von Dreieck? - ////////////////////////////////////////////////////////////////////////// - //ehsan changedâ—˜ - bool pointIsOnBoundary = false; - if( !boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3,pointIsOnBoundary) ) - // if( !boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3) ) - { - counterAABBTriFace++; - continue; - } - - ////////////////////////////////////////////////////////////////////////// - // Halbebenentests - ////////////////////////////////////////////////////////////////////////// - distance = halfSpace.getDistance( internX1, internX2, internX3 ); - - //Punkt in Halbebene? (nein, wenn distance<0) - if(useHalfSpace && UbMath::less(distance, 0.0) )//== !halfSpace.ptInside(internX1,internX2,internX3) ) - { - counterHalfspace++; - continue; - } - - //BilligOBB-Test: wenn distance > qEinflussDelta -> kein q - if( UbMath::greater( fabs(distance), qEinflussDelta ) ) - { - counterBilligOBB++; - continue; - } - - ///////////////////////////////////////////////////////////////////////////// - //Raytracingfür diskrete Boltzmannrichtungen - ///////////////////////////////////////////////////////////////////////////// - gotQs = false; - bc = SPtr<BoundaryConditions>(); - - //RAYTRACING - diskrete LB-dir zu Dreick - //e1 = v1 - v0 - e1x1 = v2.x-v1.x; - e1x2 = v2.y-v1.y; - e1x3 = v2.z-v1.z; - - //e2 = v2 - v0 - e2x1 = v3.x-v1.x; - e2x2 = v3.y-v1.y; - e2x3 = v3.z-v1.z; - - //s = o - v0 - sx1 = internX1 - v1.x; - sx2 = internX2 - v1.y; - sx3 = internX3 - v1.z; - - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - //p = d x e2 - px1 = this->rayX2[fdir]*e2x3 - this->rayX3[fdir]*e2x2; - px2 = this->rayX3[fdir]*e2x1 - this->rayX1[fdir]*e2x3; - px3 = this->rayX1[fdir]*e2x2 - this->rayX2[fdir]*e2x1; - - //a = e1 dot p - a = e1x1*px1 + e1x2*px2 + e1x3*px3; - if(fabs(a)<1.E-10) continue; - f = 1.0/a; - - //u = f * ( s dot p) - u = f * ( sx1*px1 + sx2*px2 + sx3*px3 ); - if(u<-1.E-10 || u>1.0+1.E-10) continue; - - //q = s x e1 - qx1 = sx2*e1x3 - sx3*e1x2; - qx2 = sx3*e1x1 - sx1*e1x3; - qx3 = sx1*e1x2 - sx2*e1x1; - - //v = f*(e2 dot q) - v = f * (this->rayX1[fdir]*qx1 + this->rayX2[fdir]*qx2 + this->rayX3[fdir]*qx3); - if(v<-1.E-10 || (u+v)>1.0+1.E-10) continue; - - //t = f * (e2 dot q) - q = f * (e2x1*qx1 + e2x2*qx2 + e2x3*qx3); - q /= nodeDeltaToNeigh[level][fdir]; - - //gefundenes q auf gueltigkeit pruefen - if( UbMath::zero(q) ) - { - //neu (18.05.2010) - //es kann vorkommen, dass bei dünnwandigen geos punkte, die auf einem dreieck liegen, qs bekommen, die durch die geo - //durchgehen. diese punkte werden später jedoch nicht mehr auf solid getestet, da sie ja ne BC bekommen haben - //--> da mind ein q==0.0 für eines der dreiecke -> dort solid setzen - this->solidNodeIndicesMap[block].insert( UbTupleInt3(ix1,ix2,ix3) ); - bcMatrix->setSolid( ix1, ix2, ix3 ); - continue; - } - - if( UbMath::inClosedInterval(q, 1.0, 1.0) ) q = 1.0; - if( UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0) ) - { - //if( !solidFromOtherInteractor ) //--> Knoten schon solid-->BC setzen ueberfluessig - //SG changed to - //if( solidFromOtherInteractor ) //--> Knoten schon solid-->BC setzen ueberfluessig - { - //SG 26.08.2010 muss bereits hierhin, da das continue sonst den Knoten nicht als transNode fürs - //markiert - gotQs=blockGotBCs=true; - - bc = bcMatrix->getBC(ix1,ix2,ix3); - - //SG 26.08.2010 if(!bc && !bcMatrix->isSolid()) - if(!bc) - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions);; - bcMatrix->setBC(ix1,ix2,ix3,bc); - } - else if( UbMath::less( bc->getQ(fdir), q ) ) //schon ein kuerzeres q voehanden? - { - //neu:: 18.05.2010 - //um falsche qs die evtl durch die "wand" gehen zu vermeiden - //q nur dann neu setzen, wenn neues q kleiner als vorhandenes! - //Zudem: insbesondere an ecken mit zwei BC geos ist nur das - //naehere gueltig - continue; - } - - bc->setBoundaryVelocityX1(vx1); - bc->setBoundaryVelocityX2(vx2); - bc->setBoundaryVelocityX3(vx3); - - for(int index=(int)this->bcAdapters.size()-1; index>=0; --index) - this->bcAdapters[index]->adaptBCForDirection(*this,bc,internX1,internX2,internX3,q,fdir); - - //SG 26.08.2010 gotQs=blockGotBCs=true; - } - //fuer beschleunigtes wiedereinlesen - if(this->reinitWithStoredQsFlag) - { - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ].resize(D3Q27System::FENDDIR+1+3, -1.0f); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][fdir ] = float(q); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+0] = float(internX1); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+1] = float(internX2); - bcNodeIndicesAndQsMap[block][ UbTupleInt3(ix1, ix2, ix3) ][D3Q27System::FENDDIR+1+2] = float(internX3); - } + for (std::size_t b = 0; b < triBlocks.size(); b++) { + SPtr<Block3D> block = triBlocks[b]; + + //////////////////////////////////////////////////////////////////////////// + //// Block Dreieck-/test + //////////////////////////////////////////////////////////////////////////// + UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); + UbTupleDouble3 deltas = grid.lock()->getBlockLengths(block); + + blockMinX[0] = (float)(val<1>(coords) - deltaMinX1[level]); + blockMinX[1] = (float)(val<2>(coords) - deltaMinX2[level]); + blockMinX[2] = (float)(val<3>(coords) - deltaMinX3[level]); + + blockMaxX[0] = (float)(val<1>(coords) + val<1>(deltas) + deltaMaxX1[level]); + blockMaxX[1] = (float)(val<2>(coords) + val<2>(deltas) + deltaMaxX2[level]); + blockMaxX[2] = (float)(val<3>(coords) + val<3>(deltas) + deltaMaxX3[level]); + + boxCenter[0] = (float)(0.5 * (blockMaxX[0] + blockMinX[0])); + boxCenter[1] = (float)(0.5 * (blockMaxX[1] + blockMinX[1])); + boxCenter[2] = (float)(0.5 * (blockMaxX[2] + blockMinX[2])); + + halfBoxSize[0] = (float)(0.5 * (blockMaxX[0] - blockMinX[0])); + halfBoxSize[1] = (float)(0.5 * (blockMaxX[1] - blockMinX[1])); + halfBoxSize[2] = (float)(0.5 * (blockMaxX[2] - blockMinX[2])); + + // wenn dreieck "vergroesserten cube" nicht schneidet/beruehrt -> keine BC moeglich -> continue + if (!GbMeshTools3D::triBoxOverlap(boxCenter, halfBoxSize, triPoints)) { + counterTriBoxOverlap++; + continue; + } + + ////////////////////////////////////////////////////////////////////////// + // Untersuchung der einzelnen nodes + ////////////////////////////////////////////////////////////////////////// + bool blockGotBCs = false; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + + int indexMinX1 = 0; + int indexMinX2 = 0; + int indexMinX3 = 0; + + int indexMaxX1 = (int)bcMatrix->getNX1(); + int indexMaxX2 = (int)bcMatrix->getNX2(); + int indexMaxX3 = (int)bcMatrix->getNX3(); + + std::set<std::vector<int>> &bcNodeIndices = this->bcNodeIndicesMap[block]; + std::set<std::vector<int>> &solidsFromOtherInteractors = tmpSolidNodesFromOtherInteractors[block]; + double q, internX1, internX2, internX3, distance; + + double &nodeDx1 = nodeDeltaToNeigh[level][D3Q27System::E]; + double &nodeDx2 = nodeDeltaToNeigh[level][D3Q27System::N]; + double &nodeDx3 = nodeDeltaToNeigh[level][D3Q27System::T]; + + // fuer OBB-Test + double qEinflussDelta = 1.1 * sqrt(nodeDx1 * nodeDx1 + nodeDx2 * nodeDx2 + nodeDx3 * nodeDx3); + + for (int ix3 = indexMinX3; ix3 < indexMaxX3; ix3++) { + internX3 = val<3>(coords) + nodeDx3 * ix3 - 0.5 * nodeDx3; + for (int ix2 = indexMinX2; ix2 < indexMaxX2; ix2++) { + internX2 = val<2>(coords) + nodeDx2 * ix2 - 0.5 * nodeDx2; + for (int ix1 = indexMinX1; ix1 < indexMaxX1; ix1++) { + + // int blx1 =block->getX1(); + // int blx2 = block->getX2(); + // int blx3 = block->getX3(); + + // if (blx1==0&&blx2==1&&blx3==0) + // { + // //if (ix2==39&&ix3==4) + // if (ix2==39&&ix3==4) + // { + // int seb=0; + // } + // } + // Problem: wenn voher der punkt durch eine andere geo not active gesetzt wird und + // dieser nun uebersprungen wird, dann hat man spaeter beim fuellalgorithmus luecken + // in der front und der block wird u.U. faelschlicher weise komplett solid markiert + // Lsg: positionen merken und erst Nach dem fuellarlgo wieder auf not active setzen :-) + // solidFromOtherInteractor = false; + if (bcMatrix->isSolid(ix1, ix2, ix3)) { + if (this->reinitWithStoredQsFlag) { + // solidFromOtherInteractor = true; //hier muss man weitermachen + // SG //oje + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + solidsFromOtherInteractors.insert(p); + } else { + // SG //oje + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + solidsFromOtherInteractors.insert(p); + // SG continue; + // solidFromOtherInteractor = true; + } + } + + internX1 = val<1>(coords) + nodeDx1 * ix1 - 0.5 * nodeDx1; + + ////////////////////////////////////////////////////////////////////////// + // Punkt in AABB von Dreieck? + ////////////////////////////////////////////////////////////////////////// + // ehsan changedâ—˜ + bool pointIsOnBoundary = false; + if (!boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3, + pointIsOnBoundary)) + // if( !boundingCubeTriangle.isPointInGbObject3D(internX1, internX2, internX3) ) + { + counterAABBTriFace++; + continue; + } + + ////////////////////////////////////////////////////////////////////////// + // Halbebenentests + ////////////////////////////////////////////////////////////////////////// + distance = halfSpace.getDistance(internX1, internX2, internX3); + + // Punkt in Halbebene? (nein, wenn distance<0) + if (useHalfSpace && + UbMath::less(distance, 0.0)) //== !halfSpace.ptInside(internX1,internX2,internX3) ) + { + counterHalfspace++; + continue; + } + + // BilligOBB-Test: wenn distance > qEinflussDelta -> kein q + if (UbMath::greater(fabs(distance), qEinflussDelta)) { + counterBilligOBB++; + continue; + } + + ///////////////////////////////////////////////////////////////////////////// + // Raytracingfür diskrete Boltzmannrichtungen + ///////////////////////////////////////////////////////////////////////////// + gotQs = false; + bc = SPtr<BoundaryConditions>(); + + // RAYTRACING - diskrete LB-dir zu Dreick + // e1 = v1 - v0 + e1x1 = v2.x - v1.x; + e1x2 = v2.y - v1.y; + e1x3 = v2.z - v1.z; + + // e2 = v2 - v0 + e2x1 = v3.x - v1.x; + e2x2 = v3.y - v1.y; + e2x3 = v3.z - v1.z; + + // s = o - v0 + sx1 = internX1 - v1.x; + sx2 = internX2 - v1.y; + sx3 = internX3 - v1.z; + + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + // p = d x e2 + px1 = this->rayX2[fdir] * e2x3 - this->rayX3[fdir] * e2x2; + px2 = this->rayX3[fdir] * e2x1 - this->rayX1[fdir] * e2x3; + px3 = this->rayX1[fdir] * e2x2 - this->rayX2[fdir] * e2x1; + + // a = e1 dot p + a = e1x1 * px1 + e1x2 * px2 + e1x3 * px3; + if (fabs(a) < 1.E-10) + continue; + f = 1.0 / a; + + // u = f * ( s dot p) + u = f * (sx1 * px1 + sx2 * px2 + sx3 * px3); + if (u < -1.E-10 || u > 1.0 + 1.E-10) + continue; + + // q = s x e1 + qx1 = sx2 * e1x3 - sx3 * e1x2; + qx2 = sx3 * e1x1 - sx1 * e1x3; + qx3 = sx1 * e1x2 - sx2 * e1x1; + + // v = f*(e2 dot q) + v = f * (this->rayX1[fdir] * qx1 + this->rayX2[fdir] * qx2 + this->rayX3[fdir] * qx3); + if (v < -1.E-10 || (u + v) > 1.0 + 1.E-10) + continue; + + // t = f * (e2 dot q) + q = f * (e2x1 * qx1 + e2x2 * qx2 + e2x3 * qx3); + q /= nodeDeltaToNeigh[level][fdir]; + + // gefundenes q auf gueltigkeit pruefen + if (UbMath::zero(q)) { + // neu (18.05.2010) + // es kann vorkommen, dass bei dünnwandigen geos punkte, die auf einem dreieck + // liegen, qs bekommen, die durch die geo durchgehen. diese punkte werden später + // jedoch nicht mehr auf solid getestet, da sie ja ne BC bekommen haben + //--> da mind ein q==0.0 für eines der dreiecke -> dort solid setzen + this->solidNodeIndicesMap[block].insert(UbTupleInt3(ix1, ix2, ix3)); + bcMatrix->setSolid(ix1, ix2, ix3); + continue; + } + + if (UbMath::inClosedInterval(q, 1.0, 1.0)) + q = 1.0; + if (UbMath::greater(q, 0.0) && UbMath::lessEqual(q, 1.0)) { + // if( !solidFromOtherInteractor ) //--> Knoten schon solid-->BC setzen + // ueberfluessig SG changed to if( solidFromOtherInteractor ) //--> Knoten schon + // solid-->BC setzen ueberfluessig + { + // SG 26.08.2010 muss bereits hierhin, da das continue sonst den Knoten nicht + // als transNode fürs markiert + gotQs = blockGotBCs = true; + + bc = bcMatrix->getBC(ix1, ix2, ix3); + + // SG 26.08.2010 if(!bc && !bcMatrix->isSolid()) + if (!bc) { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + ; + bcMatrix->setBC(ix1, ix2, ix3, bc); + } else if (UbMath::less(bc->getQ(fdir), q)) // schon ein kuerzeres q voehanden? + { + // neu:: 18.05.2010 + // um falsche qs die evtl durch die "wand" gehen zu vermeiden + // q nur dann neu setzen, wenn neues q kleiner als vorhandenes! + // Zudem: insbesondere an ecken mit zwei BC geos ist nur das + // naehere gueltig + continue; + } + + bc->setBoundaryVelocityX1(vx1); + bc->setBoundaryVelocityX2(vx2); + bc->setBoundaryVelocityX3(vx3); + + for (int index = (int)this->bcAdapters.size() - 1; index >= 0; --index) + this->bcAdapters[index]->adaptBCForDirection(*this, bc, internX1, internX2, + internX3, q, fdir); + + // SG 26.08.2010 gotQs=blockGotBCs=true; + } + // fuer beschleunigtes wiedereinlesen + if (this->reinitWithStoredQsFlag) { + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)].resize( + D3Q27System::FENDDIR + 1 + 3, -1.0f); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)][fdir] = float(q); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 0] = float(internX1); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 1] = float(internX2); + bcNodeIndicesAndQsMap[block][UbTupleInt3(ix1, ix2, ix3)] + [D3Q27System::FENDDIR + 1 + 2] = float(internX3); + } + } + } + + if (gotQs) { + std::vector<int> p(3); + p[0] = ix1; + p[1] = ix2; + p[2] = ix3; + bcNodeIndices.insert(p); + + for (int index = (int)this->bcAdapters.size() - 1; index >= 0; --index) + this->bcAdapters[index]->adaptBC(*this, bc, internX1, internX2, internX3); + } } - } - - if(gotQs) - { - std::vector<int> p(3); - p[0]=ix1; p[1]=ix2; p[2]=ix3; - bcNodeIndices.insert(p); - - for(int index=(int)this->bcAdapters.size()-1; index>=0; --index) - this->bcAdapters[index]->adaptBC(*this,bc,internX1,internX2,internX3); - } - } - } + } + } + // Block wird für scanline-check "anmelden", dieser wird dann spaeter zu "transBlocks" hinzugefuegt + if (blockGotBCs) { + blocksForSolidCheck[block] = ScanLine; + } + // bvd->getTimer().stop(); } - //Block wird für scanline-check "anmelden", dieser wird dann spaeter zu "transBlocks" hinzugefuegt - if(blockGotBCs) - { - blocksForSolidCheck[block] = ScanLine; - } - // bvd->getTimer().stop(); - } - //dynamische Punkte des GbCuboids muessen leider per "Hand" geloescht werden :-( - boundingCubeTriangle.finalize(); - } - } - setQTimer.stop(); - - UBLOG(logDEBUG1," - setQs for "/*<< this->getName()*/ << " - " <<(int)triangles.size()<<" triangles: 100% done in "<<setQTimer.getTotalTime()<<"sec"); - UBLOG(logDEBUG1," * rejected blocks with tribox overlap test : " << counterTriBoxOverlap); - UBLOG(logDEBUG1," * rejected nodes with AABB test : " << counterAABBTriFace); - UBLOG(logDEBUG1," * rejected nodes with halfspace test : " << counterHalfspace); - UBLOG(logDEBUG1," * rejected nodes with OBB test : " << counterBilligOBB); - - typedef std::map<SPtr<Block3D>,SolidCheckMethod>::iterator BlockSolidCheckMethodIterator; - - ////////////////////////////////////////////////////////////////////////// - // SOLID checks - ////////////////////////////////////////////////////////////////////////// - if( regardPIOTest ) - { - int pointInObjectCounter = 0; - int scanlineCounter = 0; -// int counter = 0; - - //sollte die matrix groesse zu gross sein und der rekursive floodFill mehr speicher - //benoetigen als der Stack hergibt -> keinen floodFill verwenden! - void (D3Q27TriFaceMeshInteractor::*gridFill)(CbArray3D<FLAGS>&, const short&, const short&, const short&, const FLAGS&) = NULL; - /*if(blocknx1*blocknx2*blocknx3 < 200000 ) gridFill = &D3Q27TriFaceMeshInteractor::recursiveGridFill;*/ - /*else */ gridFill = &D3Q27TriFaceMeshInteractor::iterativeGridFill; - - UBLOG(logDEBUG1," - setSolids for "<< blocksForSolidCheck.size() << " blocks"); - - UbTimer scanLineTimer; - UbTimer solidTimer; - solidTimer.start(); - - for(BlockSolidCheckMethodIterator pos=blocksForSolidCheck.begin(); pos!=blocksForSolidCheck.end(); ++pos) - { - SPtr<Block3D> const& block = pos->first; - int level = block->getLevel(); - - UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); - - //Bloecke, die keinerlei Verschneidung mit Dreicken bzw. deren BoundCubes hatten - //hier: durch inside/outside Tests EINES knotens gilt fuer ALLE Knoten des blockes - if( pos->second == PointInObject ) - { - pointInObjectCounter++; - if(mesh->isPointInGbObject3D(val<1>(coords),val<2>(coords),val<3>(coords)) ) - { - //block->setActive(false); - //this->solidBlocks.push_back(block); + // dynamische Punkte des GbCuboids muessen leider per "Hand" geloescht werden :-( + boundingCubeTriangle.finalize(); + } + } + setQTimer.stop(); + + UBLOG(logDEBUG1, " - setQs for " /*<< this->getName()*/ << " - " << (int)triangles.size() + << " triangles: 100% done in " << setQTimer.getTotalTime() + << "sec"); + UBLOG(logDEBUG1, " * rejected blocks with tribox overlap test : " << counterTriBoxOverlap); + UBLOG(logDEBUG1, " * rejected nodes with AABB test : " << counterAABBTriFace); + UBLOG(logDEBUG1, " * rejected nodes with halfspace test : " << counterHalfspace); + UBLOG(logDEBUG1, " * rejected nodes with OBB test : " << counterBilligOBB); + + typedef std::map<SPtr<Block3D>, SolidCheckMethod>::iterator BlockSolidCheckMethodIterator; + + ////////////////////////////////////////////////////////////////////////// + // SOLID checks + ////////////////////////////////////////////////////////////////////////// + if (regardPIOTest) { + int pointInObjectCounter = 0; + int scanlineCounter = 0; + // int counter = 0; + + // sollte die matrix groesse zu gross sein und der rekursive floodFill mehr speicher + // benoetigen als der Stack hergibt -> keinen floodFill verwenden! + void (D3Q27TriFaceMeshInteractor::*gridFill)(CbArray3D<FLAGS> &, const short &, const short &, const short &, + const FLAGS &) = NULL; + /*if(blocknx1*blocknx2*blocknx3 < 200000 ) gridFill = &D3Q27TriFaceMeshInteractor::recursiveGridFill;*/ + /*else */ gridFill = &D3Q27TriFaceMeshInteractor::iterativeGridFill; + + UBLOG(logDEBUG1, " - setSolids for " << blocksForSolidCheck.size() << " blocks"); + + UbTimer scanLineTimer; + UbTimer solidTimer; + solidTimer.start(); + + for (BlockSolidCheckMethodIterator pos = blocksForSolidCheck.begin(); pos != blocksForSolidCheck.end(); ++pos) { + SPtr<Block3D> const &block = pos->first; + int level = block->getLevel(); + + UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates(block); + + // Bloecke, die keinerlei Verschneidung mit Dreicken bzw. deren BoundCubes hatten + // hier: durch inside/outside Tests EINES knotens gilt fuer ALLE Knoten des blockes + if (pos->second == PointInObject) { + pointInObjectCounter++; + if (mesh->isPointInGbObject3D(val<1>(coords), val<2>(coords), val<3>(coords))) { + // block->setActive(false); + // this->solidBlocks.push_back(block); + } } - } - //Bloecke, die Verschneidung mit Dreicken bzw. deren BoundCubes hatten - //scanline algortihmus. dieser berücksichtigt durch weitere tests, dass innerhalb evtl schon andere - //geos bcs gesetzt haben. es werden ausschließelich solids gesetzt (also keine FLUIDS oder neuen BCs) - else if( pos->second == ScanLine ) - { - scanlineCounter++; - scanLineTimer.start(); - - SPtr<ILBMKernel> kernel = block->getKernel(); - if(!kernel) throw UbException(UB_EXARGS,"na sowas kein kernel bzw. kernel=NULL (2)"); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - - // bvd->getTimer().start(); -// int indexMinX1 = 0; -// int indexMinX2 = 0; -// int indexMinX3 = 0; - int indexMaxX1 = (int)bcMatrix->getNX1(); - int indexMaxX2 = (int)bcMatrix->getNX2(); - int indexMaxX3 = (int)bcMatrix->getNX3(); - - //quick and dirty - blocknx1 = indexMaxX1; - blocknx2 = indexMaxX2; - blocknx3 = indexMaxX3; - - std::set< UbTupleInt3 >& solidNodeIndices = this->solidNodeIndicesMap[block]; - - float nodeDeltaX1 = (float)nodeDeltaToNeigh[level][D3Q27System::E]; - float nodeDeltaX2 = (float)nodeDeltaToNeigh[level][D3Q27System::N]; - float nodeDeltaX3 = (float)nodeDeltaToNeigh[level][D3Q27System::T]; - - //flagfield matrix initialisieren - CbArray3D<FLAGS> flagField(blocknx1,blocknx2,blocknx3,UNDEF_FLAG); - - //hier gesetzte bcs markieren - std::set< std::vector<int> >& transNodeIndices = this->bcNodeIndicesMap[block]; - std::set< std::vector<int> >::iterator setPos; - for(setPos=transNodeIndices.begin(); setPos!=transNodeIndices.end(); ++setPos) - flagField( (*setPos)[0], (*setPos)[1], (*setPos)[2] ) = BC_FLAG; - - //solids die bereits durch andere interaktoren gesetzt wurden (wurden oben gespeichert) - //ist EMPTY bei reinitWithStoredQsFlag == true - //SG 28.08.2010 std::set< UbTupleInt3 >& tmpSolidNodeIndices = tmpSolidNodesFromOtherInteractors[block]; - //SG 28.08.2010 if(reinitWithStoredQsFlag && !tmpSolidNodeIndices.empty() ) throw UbException(UB_EXARGS, "tmpSolidNodeIndices darf bei reinitWithStoredQsFlag==true keine Knoten enthalten"); - //SG 28.08.2010 for(setPos=tmpSolidNodeIndices.begin(); setPos!=tmpSolidNodeIndices.end(); ++setPos) - //SG 28.08.2010 flagField( val<1>(*setPos), val<2>(*setPos), val<3>(*setPos) ) = OLDSOLID_FLAG; - - //flagfield matrix belegen - for(int bx3=0; bx3<blocknx3; ++bx3) - { - for(int bx2=0; bx2<blocknx2; ++bx2) - { - for(int bx1=0; bx1<blocknx1; ++bx1) - { - -// if (bx2==9&&bx3==29) -// { -// int ride=0; -// } - if( flagField(bx1,bx2,bx3)==UNDEF_FLAG ) - { - if( mesh->isPointInGbObject3D( val<1>(coords) + bx1*nodeDeltaX1 - 0.5*nodeDeltaX1 - , val<2>(coords) + bx2*nodeDeltaX2 - 0.5*nodeDeltaX2 - , val<3>(coords) + bx3*nodeDeltaX3 - 0.5*nodeDeltaX3) ) - { - (this->*gridFill)(flagField,bx1,bx2,bx3,SOLID_FLAG); - } - else - { - (this->*gridFill)(flagField,bx1,bx2,bx3,FLUID_FLAG); + // Bloecke, die Verschneidung mit Dreicken bzw. deren BoundCubes hatten + // scanline algortihmus. dieser berücksichtigt durch weitere tests, dass innerhalb evtl schon andere + // geos bcs gesetzt haben. es werden ausschließelich solids gesetzt (also keine FLUIDS oder neuen BCs) + else if (pos->second == ScanLine) { + scanlineCounter++; + scanLineTimer.start(); + + SPtr<ILBMKernel> kernel = block->getKernel(); + if (!kernel) + throw UbException(UB_EXARGS, "na sowas kein kernel bzw. kernel=NULL (2)"); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + + // bvd->getTimer().start(); + // int indexMinX1 = 0; + // int indexMinX2 = 0; + // int indexMinX3 = 0; + int indexMaxX1 = (int)bcMatrix->getNX1(); + int indexMaxX2 = (int)bcMatrix->getNX2(); + int indexMaxX3 = (int)bcMatrix->getNX3(); + + // quick and dirty + blocknx1 = indexMaxX1; + blocknx2 = indexMaxX2; + blocknx3 = indexMaxX3; + + std::set<UbTupleInt3> &solidNodeIndices = this->solidNodeIndicesMap[block]; + + float nodeDeltaX1 = (float)nodeDeltaToNeigh[level][D3Q27System::E]; + float nodeDeltaX2 = (float)nodeDeltaToNeigh[level][D3Q27System::N]; + float nodeDeltaX3 = (float)nodeDeltaToNeigh[level][D3Q27System::T]; + + // flagfield matrix initialisieren + CbArray3D<FLAGS> flagField(blocknx1, blocknx2, blocknx3, UNDEF_FLAG); + + // hier gesetzte bcs markieren + std::set<std::vector<int>> &transNodeIndices = this->bcNodeIndicesMap[block]; + std::set<std::vector<int>>::iterator setPos; + for (setPos = transNodeIndices.begin(); setPos != transNodeIndices.end(); ++setPos) + flagField((*setPos)[0], (*setPos)[1], (*setPos)[2]) = BC_FLAG; + + // solids die bereits durch andere interaktoren gesetzt wurden (wurden oben gespeichert) + // ist EMPTY bei reinitWithStoredQsFlag == true + // SG 28.08.2010 std::set< UbTupleInt3 >& tmpSolidNodeIndices = + // tmpSolidNodesFromOtherInteractors[block]; SG 28.08.2010 if(reinitWithStoredQsFlag && + // !tmpSolidNodeIndices.empty() ) throw UbException(UB_EXARGS, "tmpSolidNodeIndices darf bei + // reinitWithStoredQsFlag==true keine Knoten enthalten"); SG 28.08.2010 + // for(setPos=tmpSolidNodeIndices.begin(); setPos!=tmpSolidNodeIndices.end(); ++setPos) SG 28.08.2010 + // flagField( val<1>(*setPos), val<2>(*setPos), val<3>(*setPos) ) = OLDSOLID_FLAG; + + // flagfield matrix belegen + for (int bx3 = 0; bx3 < blocknx3; ++bx3) { + for (int bx2 = 0; bx2 < blocknx2; ++bx2) { + for (int bx1 = 0; bx1 < blocknx1; ++bx1) { + + // if (bx2==9&&bx3==29) + // { + // int ride=0; + // } + if (flagField(bx1, bx2, bx3) == UNDEF_FLAG) { + if (mesh->isPointInGbObject3D(val<1>(coords) + bx1 * nodeDeltaX1 - 0.5 * nodeDeltaX1, + val<2>(coords) + bx2 * nodeDeltaX2 - 0.5 * nodeDeltaX2, + val<3>(coords) + bx3 * nodeDeltaX3 - 0.5 * nodeDeltaX3)) { + (this->*gridFill)(flagField, bx1, bx2, bx3, SOLID_FLAG); + } else { + (this->*gridFill)(flagField, bx1, bx2, bx3, FLUID_FLAG); + } + } + + if (flagField(bx1, bx2, bx3) == SOLID_FLAG) { + // hier ist noch das Problem, das "alle" solid in die solidNodeIndices kommen + // evtl. Abhilfe durch einführen eines anderen Flags bei tmpSolidNodeIndices .. + solidNodeIndices.insert(UbTupleInt3(bx1, bx2, bx3)); + bcMatrix->setSolid(bx1, bx2, bx3); + } + // SG 28.08.2010 else if( flagField(bx1,bx2,bx3)==OLDSOLID_FLAG ) + // SG 28.08.2010 { + // SG 28.08.2010 bcMatrix->setSolid(bx1,bx2,bx3); + // SG 28.08.2010 } } - } - - if( flagField(bx1,bx2,bx3)==SOLID_FLAG ) - { - //hier ist noch das Problem, das "alle" solid in die solidNodeIndices kommen - //evtl. Abhilfe durch einführen eines anderen Flags bei tmpSolidNodeIndices .. - solidNodeIndices.insert(UbTupleInt3(bx1,bx2,bx3)); - bcMatrix->setSolid(bx1,bx2,bx3); - } - //SG 28.08.2010 else if( flagField(bx1,bx2,bx3)==OLDSOLID_FLAG ) - //SG 28.08.2010 { - //SG 28.08.2010 bcMatrix->setSolid(bx1,bx2,bx3); - //SG 28.08.2010 } - } - } - } - - //SG 28.08.2010 halt danach setzen, damit die BCs die fälschlicherweise gesetzt wurden korrigiert werden - std::set< std::vector<int> >& tmpSolidNodeIndices = tmpSolidNodesFromOtherInteractors[block]; - for(setPos=tmpSolidNodeIndices.begin(); setPos!=tmpSolidNodeIndices.end(); ++setPos) - bcMatrix->setSolid((*setPos)[0], (*setPos)[1], (*setPos)[2] ); - - //block hat in initInteractor mind eine BC erhalten -> transBlock - this->bcBlocks.push_back(block); - scanLineTimer.stop(); - - // bvd->getTimer().stop(); - } - else throw UbException(UB_EXARGS,"unknown option for in object test"); - } - - solidTimer.stop(); - - UBLOG(logDEBUG1, " - setSolids for "<<blocksForSolidCheck.size()<<" blocks: 100% done in "<<solidTimer.getTotalTime()<<"s"); - UBLOG(logDEBUG1, " * pointInObject for "<<pointInObjectCounter<<" blocks in "<<solidTimer.getTotalTime()-scanLineTimer.getTotalTime()<<"s"); - UBLOG(logDEBUG1, " * flood fill for "<<scanlineCounter <<" blocks in "<<scanLineTimer.getTotalTime()<<" secs"); - UBLOG(logDEBUG1, "LBMTriFaceMeshInteractor::initInteractor for \""<<mesh->getName()<<"\" done in "<<setQTimer.getTotalTime()+solidTimer.getTotalTime()<<"s"); - } - - //calcForces arbeitet nicht korrekt, wenn Geo mit Bloecken - //unterschiedlicher Leveltiefe diskretisiert -> exception - //abfrage steht hier, weil es theoretisch sein kann, dass bei parallelen rechnungen - //genau der block mit dem anderen level auf einem anderen prozess liegt... - //Update: es kann u.U. passieren, dass Blöcke in der Liste nicht aktiv sin - //(falls diese z.B. duch andere Interactoren solid gesetzt wurden) - //diese werden nicht berücksichtigt (auch nicht beid er kraftauswertung später) - //if( this->isRelevantForForces() ) - //{ - // int level = -1; - // for( std::vector<SPtr<Block3D>>::const_iterator pos = this->transBlocks.begin(); pos!=this->transBlocks.end(); ++pos) - // if( (*pos)->isActive() ) - // { - // level = (*pos)->getLevel(); - // break; - // } - - // bool check = false; - // for( std::vector<SPtr<Block3D>>::const_iterator pos = this->transBlocks.begin(); pos!=this->transBlocks.end(); ++pos) - // if( (*pos)->isActive() && (*pos)->getLevel()!=level) - // { - // (*pos)->setRank(1000); - // check = true; - // UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates((*pos)); - // std::cout<<(*pos)->getLevel()<<","<<(*pos)->getX1()<<","<<(*pos)->getX2()<<","<<(*pos)->getX3()<<std::endl; - // std::cout<<std::setprecision(15)<<val<1>(coords)<<","<<val<2>(coords)<<","<<val<3>(coords)<<std::endl<<std::endl; - - // } - // if(check) - // { - // //this->grid.lock()->writeBlocks(UbStaticPathMap::getPath(UbStaticPathMap::GLOBAL)+"/error_grid",0, WbWriterVtkXmlASCII::getInstance(), false); - - // throw UbException(UB_EXARGS,"interactor is relevant for forces," - // +(std::string)" but has transblocks with different levels (wrote error_grid)" - // +(std::string)" -> not supportet by LBMInteractor::getForces()" - // +(std::string)" -> increase refineWidth"); - - // } - //} + } + } + + // SG 28.08.2010 halt danach setzen, damit die BCs die fälschlicherweise gesetzt wurden korrigiert + // werden + std::set<std::vector<int>> &tmpSolidNodeIndices = tmpSolidNodesFromOtherInteractors[block]; + for (setPos = tmpSolidNodeIndices.begin(); setPos != tmpSolidNodeIndices.end(); ++setPos) + bcMatrix->setSolid((*setPos)[0], (*setPos)[1], (*setPos)[2]); + + // block hat in initInteractor mind eine BC erhalten -> transBlock + this->bcBlocks.push_back(block); + scanLineTimer.stop(); + + // bvd->getTimer().stop(); + } else + throw UbException(UB_EXARGS, "unknown option for in object test"); + } + + solidTimer.stop(); + + UBLOG(logDEBUG1, " - setSolids for " << blocksForSolidCheck.size() << " blocks: 100% done in " + << solidTimer.getTotalTime() << "s"); + UBLOG(logDEBUG1, " * pointInObject for " << pointInObjectCounter << " blocks in " + << solidTimer.getTotalTime() - scanLineTimer.getTotalTime() + << "s"); + UBLOG(logDEBUG1, " * flood fill for " << scanlineCounter << " blocks in " + << scanLineTimer.getTotalTime() << " secs"); + UBLOG(logDEBUG1, "LBMTriFaceMeshInteractor::initInteractor for \"" + << mesh->getName() << "\" done in " << setQTimer.getTotalTime() + solidTimer.getTotalTime() + << "s"); + } + + // calcForces arbeitet nicht korrekt, wenn Geo mit Bloecken + // unterschiedlicher Leveltiefe diskretisiert -> exception + // abfrage steht hier, weil es theoretisch sein kann, dass bei parallelen rechnungen + // genau der block mit dem anderen level auf einem anderen prozess liegt... + // Update: es kann u.U. passieren, dass Blöcke in der Liste nicht aktiv sin + //(falls diese z.B. duch andere Interactoren solid gesetzt wurden) + // diese werden nicht berücksichtigt (auch nicht beid er kraftauswertung später) + // if( this->isRelevantForForces() ) + //{ + // int level = -1; + // for( std::vector<SPtr<Block3D>>::const_iterator pos = this->transBlocks.begin(); pos!=this->transBlocks.end(); + // ++pos) + // if( (*pos)->isActive() ) + // { + // level = (*pos)->getLevel(); + // break; + // } + + // bool check = false; + // for( std::vector<SPtr<Block3D>>::const_iterator pos = this->transBlocks.begin(); + // pos!=this->transBlocks.end(); ++pos) + // if( (*pos)->isActive() && (*pos)->getLevel()!=level) + // { + // (*pos)->setRank(1000); + // check = true; + // UbTupleDouble3 coords = grid.lock()->getBlockWorldCoordinates((*pos)); + // std::cout<<(*pos)->getLevel()<<","<<(*pos)->getX1()<<","<<(*pos)->getX2()<<","<<(*pos)->getX3()<<std::endl; + // std::cout<<std::setprecision(15)<<val<1>(coords)<<","<<val<2>(coords)<<","<<val<3>(coords)<<std::endl<<std::endl; + + // } + // if(check) + // { + // //this->grid.lock()->writeBlocks(UbStaticPathMap::getPath(UbStaticPathMap::GLOBAL)+"/error_grid",0, + // WbWriterVtkXmlASCII::getInstance(), false); + + // throw UbException(UB_EXARGS,"interactor is relevant for forces," + // +(std::string)" but has transblocks with different levels (wrote error_grid)" + // +(std::string)" -> not supportet by LBMInteractor::getForces()" + // +(std::string)" -> increase refineWidth"); + + // } + //} } ////////////////////////////////////////////////////////////////////////// void D3Q27TriFaceMeshInteractor::refineBlockGridToLevel(int level, double startDistance, double stopDistance) { - UBLOG(logDEBUG1, "D3Q27TriFaceMeshInteractor::refineBlockGridToLevel - start"); - - //ToDo: evtl checken, ob man noch einen HalbraumCheck für StopDistance einbaut - // oder ob man schneller ist, wenn man gar keinen halbraum test macht... - if(!grid.lock()) - throw UbException(UB_EXARGS,"Grid isn't exist!"); - if( UbMath::greater(startDistance,0.0) ) - throw UbException(UB_EXARGS,"startDistance>0.0 not supported by this interactor"); - if( UbMath::less(stopDistance,0.0) ) - throw UbException(UB_EXARGS,"stopDistance<0.0 not supported by this interactor"); - - SPtr<Grid3D> bgrid = this->grid.lock(); - GbTriFaceMesh3D& mesh = dynamic_cast<GbTriFaceMesh3D&>(*this->geoObject3D.get()); - - int coarsestLevel = bgrid->getCoarsestInitializedLevel(); - - std::vector<GbTriFaceMesh3D::TriFace>& triangles = *mesh.getTriangles(); - std::vector<GbTriFaceMesh3D::Vertex>& nodes = *mesh.getNodes(); - - double minX1,minX2,minX3,maxX1,maxX2,maxX3; - float blockMinX[3],blockMaxX[3],boxCenter[3],halfBoxSize[3]; - float triPoints[3][3]; - - size_t nofTriangles = (int)triangles.size(); - -//#pragma omp parallel -//#pragma omp for - for(size_t i=0; i<nofTriangles; i++) - //for(int i=0; i<nofTriangles; i++) - { -//#pragma omp master - //{ - // printf_s("num_threads=%d\n", omp_get_num_threads( )); - //} - - - GbTriFaceMesh3D::TriFace& triangle = triangles[i]; - - GbTriFaceMesh3D::Vertex& v1 = nodes[triangle.v1]; - GbTriFaceMesh3D::Vertex& v2 = nodes[triangle.v2]; - GbTriFaceMesh3D::Vertex& v3 = nodes[triangle.v3]; - - //dreick muss normal besitzen! - assert( !UbMath::zero(triangle.nx) || !UbMath::zero(triangle.ny) || !UbMath::zero(triangle.nz) ); - //Normale muss normiert sein! - assert( (fabs(std::sqrt( triangle.nx*triangle.nx + triangle.ny*triangle.ny + triangle.nz*triangle.nz ))-1.0f)<1.0E-6); - - //Halfspace um startDistance entgegen normale verscheiebn, ansonsten werden spaeter - //zu testende bloecke auf der dreicksrueckseite nicht getestet!!! - GbHalfSpace3D halfSpace( v1.x+startDistance*triangle.nx, v1.y+startDistance*triangle.ny, v1.z+startDistance*triangle.nz - , v2.x+startDistance*triangle.nx, v2.y+startDistance*triangle.ny, v2.z+startDistance*triangle.nz - , v3.x+startDistance*triangle.nx, v3.y+startDistance*triangle.ny, v3.z+startDistance*triangle.nz ); - - //Boundingbox um massgebliches dx erweitern -> zur Bestimmung der zu testenden Bloecke - if( triangle.nx>1.0E-8 ) { minX1 = triangle.getMinX(nodes)+1.05*triangle.nx*startDistance; - maxX1 = triangle.getMaxX(nodes)+1.05*triangle.nx*stopDistance; } - else { minX1 = triangle.getMinX(nodes)+1.05*triangle.nx*stopDistance; - maxX1 = triangle.getMaxX(nodes)+1.05*triangle.nx*startDistance; } - - if( triangle.ny>1.0E-8 ) { minX2 = triangle.getMinY(nodes)+1.05*triangle.ny*startDistance; - maxX2 = triangle.getMaxY(nodes)+1.05*triangle.ny*stopDistance; } - else { minX2 = triangle.getMinY(nodes)+1.05*triangle.ny*stopDistance; - maxX2 = triangle.getMaxY(nodes)+1.05*triangle.ny*startDistance; } - - if( triangle.nz>1.0E-8 ) { minX3 = triangle.getMinZ(nodes)+1.05*triangle.nz*startDistance; - maxX3 = triangle.getMaxZ(nodes)+1.05*triangle.nz*stopDistance; } - else { minX3 = triangle.getMinZ(nodes)+1.05*triangle.nz*stopDistance; - maxX3 = triangle.getMaxZ(nodes)+1.05*triangle.nz*startDistance; } - - - int flag = 0; - //Levelweise alle Bloecke holen, die erweiterte BB schneiden - //und bearbeiten - for(int l=coarsestLevel; l<level; l++) - { - std::vector<SPtr<Block3D>> consideredBlocks; - bgrid->getBlocksByCuboid(l,minX1, minX2, minX3, maxX1, maxX2, maxX3, consideredBlocks); - double x1a,x2a,x3a,x1b,x2b,x3b; - - for(size_t b=0; b<consideredBlocks.size(); b++) - { - SPtr<Block3D> block = consideredBlocks[b]; - if(block->getLevel()>=level) continue; - - //start coordinaten des blocks ermitteln - UbTupleDouble3 coords = bgrid->getBlockWorldCoordinates(block); - UbTupleDouble3 deltas = bgrid->getBlockLengths(block); - - //Check, ob block komplett im Halbraum - x1a = val<1>(coords); x1b = val<1>(coords)+val<1>(deltas); - x2a = val<2>(coords); x2b = val<2>(coords)+val<2>(deltas); - x3a = val<3>(coords); x3b = val<3>(coords)+val<3>(deltas); - - flag = 0; - if( !halfSpace.ptInside(x1a,x2a,x3a) ) flag |= (1<<0); //1 - if( !halfSpace.ptInside(x1b,x2a,x3a) ) flag |= (1<<1); //2 - if( !halfSpace.ptInside(x1b,x2b,x3a) ) flag |= (1<<2); //4 - if( !halfSpace.ptInside(x1a,x2b,x3a) ) flag |= (1<<3); //8 - if( !halfSpace.ptInside(x1a,x2a,x3b) ) flag |= (1<<4); //16 - if( !halfSpace.ptInside(x1b,x2a,x3b) ) flag |= (1<<5); //32 - if( !halfSpace.ptInside(x1b,x2b,x3b) ) flag |= (1<<6); //64 - if( !halfSpace.ptInside(x1a,x2b,x3b) ) flag |= (1<<7); //128 - - - if( true && flag!=255 ) - { - //blockseite ermitteln (skalarprodukt dreiecks-normale, vector (midTri->midCub) ) - //je nachdem muss für den massgeblichen block start oder stopdistance verwendet werden - //liegt block auf pos seite -> stopdistance ansonsten startdistance - double skalarprod = triangle.nx * ( 0.5*(x1a+x1b)-triangle.getX1Centroid(nodes) ) - + triangle.ny * ( 0.5*(x2a+x2b)-triangle.getX2Centroid(nodes) ) - + triangle.nz * ( 0.5*(x3a+x3b)-triangle.getX3Centroid(nodes) ); - - double blockdelta = 1.05*stopDistance; - if (skalarprod<1.E-8 ) blockdelta = -1.05*startDistance; //startDistance<0!! - else if( fabs(skalarprod)<1.E-8) blockdelta = 1.05*UbMath::max(-startDistance,stopDistance); - - //block anpassen - blockMinX[0] = (float)(val<1>(coords)-blockdelta ); - blockMinX[1] = (float)(val<2>(coords)-blockdelta ); - blockMinX[2] = (float)(val<3>(coords)-blockdelta ); - - blockMaxX[0] = (float)(val<1>(coords)+val<1>(deltas)+blockdelta ); - blockMaxX[1] = (float)(val<2>(coords)+val<2>(deltas)+blockdelta ); - blockMaxX[2] = (float)(val<3>(coords)+val<3>(deltas)+blockdelta ); - - boxCenter[0] = (float)(0.5*(blockMaxX[0]+blockMinX[0])); - boxCenter[1] = (float)(0.5*(blockMaxX[1]+blockMinX[1])); - boxCenter[2] = (float)(0.5*(blockMaxX[2]+blockMinX[2])); - - halfBoxSize[0] = (float)(0.5*(blockMaxX[0]-blockMinX[0])); - halfBoxSize[1] = (float)(0.5*(blockMaxX[1]-blockMinX[1])); - halfBoxSize[2] = (float)(0.5*(blockMaxX[2]-blockMinX[2])); - - GbTriFaceMesh3D::Vertex& v1_ = nodes[triangle.v1]; - GbTriFaceMesh3D::Vertex& v2_ = nodes[triangle.v2]; - GbTriFaceMesh3D::Vertex& v3_ = nodes[triangle.v3]; - - triPoints[0][0] = v1_.x; triPoints[0][1] = v1_.y; triPoints[0][2] = v1_.z; - triPoints[1][0] = v2_.x; triPoints[1][1] = v2_.y; triPoints[1][2] = v2_.z; - triPoints[2][0] = v3_.x; triPoints[2][1] = v3_.y; triPoints[2][2] = v3_.z; - - //wenn block dreick schneidet, dann muss er verfeinert werden - if( GbMeshTools3D::triBoxOverlap(boxCenter,halfBoxSize,triPoints) ) - { - bgrid->expandBlock(block->getX1(), block->getX2(),block->getX3(),block->getLevel()); - } + UBLOG(logDEBUG1, "D3Q27TriFaceMeshInteractor::refineBlockGridToLevel - start"); + + // ToDo: evtl checken, ob man noch einen HalbraumCheck für StopDistance einbaut + // oder ob man schneller ist, wenn man gar keinen halbraum test macht... + if (!grid.lock()) + throw UbException(UB_EXARGS, "Grid isn't exist!"); + if (UbMath::greater(startDistance, 0.0)) + throw UbException(UB_EXARGS, "startDistance>0.0 not supported by this interactor"); + if (UbMath::less(stopDistance, 0.0)) + throw UbException(UB_EXARGS, "stopDistance<0.0 not supported by this interactor"); + + SPtr<Grid3D> bgrid = this->grid.lock(); + GbTriFaceMesh3D &mesh = dynamic_cast<GbTriFaceMesh3D &>(*this->geoObject3D.get()); + + int coarsestLevel = bgrid->getCoarsestInitializedLevel(); + + std::vector<GbTriFaceMesh3D::TriFace> &triangles = *mesh.getTriangles(); + std::vector<GbTriFaceMesh3D::Vertex> &nodes = *mesh.getNodes(); + + double minX1, minX2, minX3, maxX1, maxX2, maxX3; + float blockMinX[3], blockMaxX[3], boxCenter[3], halfBoxSize[3]; + float triPoints[3][3]; + + size_t nofTriangles = (int)triangles.size(); + + //#pragma omp parallel + //#pragma omp for + for (size_t i = 0; i < nofTriangles; i++) + // for(int i=0; i<nofTriangles; i++) + { + //#pragma omp master + //{ + // printf_s("num_threads=%d\n", omp_get_num_threads( )); + //} + + GbTriFaceMesh3D::TriFace &triangle = triangles[i]; + + GbTriFaceMesh3D::Vertex &v1 = nodes[triangle.v1]; + GbTriFaceMesh3D::Vertex &v2 = nodes[triangle.v2]; + GbTriFaceMesh3D::Vertex &v3 = nodes[triangle.v3]; + + // dreick muss normal besitzen! + assert(!UbMath::zero(triangle.nx) || !UbMath::zero(triangle.ny) || !UbMath::zero(triangle.nz)); + // Normale muss normiert sein! + assert((fabs(std::sqrt(triangle.nx * triangle.nx + triangle.ny * triangle.ny + triangle.nz * triangle.nz)) - + 1.0f) < 1.0E-6); + + // Halfspace um startDistance entgegen normale verscheiebn, ansonsten werden spaeter + // zu testende bloecke auf der dreicksrueckseite nicht getestet!!! + GbHalfSpace3D halfSpace( + v1.x + startDistance * triangle.nx, v1.y + startDistance * triangle.ny, v1.z + startDistance * triangle.nz, + v2.x + startDistance * triangle.nx, v2.y + startDistance * triangle.ny, v2.z + startDistance * triangle.nz, + v3.x + startDistance * triangle.nx, v3.y + startDistance * triangle.ny, v3.z + startDistance * triangle.nz); + + // Boundingbox um massgebliches dx erweitern -> zur Bestimmung der zu testenden Bloecke + if (triangle.nx > 1.0E-8) { + minX1 = triangle.getMinX(nodes) + 1.05 * triangle.nx * startDistance; + maxX1 = triangle.getMaxX(nodes) + 1.05 * triangle.nx * stopDistance; + } else { + minX1 = triangle.getMinX(nodes) + 1.05 * triangle.nx * stopDistance; + maxX1 = triangle.getMaxX(nodes) + 1.05 * triangle.nx * startDistance; + } + + if (triangle.ny > 1.0E-8) { + minX2 = triangle.getMinY(nodes) + 1.05 * triangle.ny * startDistance; + maxX2 = triangle.getMaxY(nodes) + 1.05 * triangle.ny * stopDistance; + } else { + minX2 = triangle.getMinY(nodes) + 1.05 * triangle.ny * stopDistance; + maxX2 = triangle.getMaxY(nodes) + 1.05 * triangle.ny * startDistance; + } + + if (triangle.nz > 1.0E-8) { + minX3 = triangle.getMinZ(nodes) + 1.05 * triangle.nz * startDistance; + maxX3 = triangle.getMaxZ(nodes) + 1.05 * triangle.nz * stopDistance; + } else { + minX3 = triangle.getMinZ(nodes) + 1.05 * triangle.nz * stopDistance; + maxX3 = triangle.getMaxZ(nodes) + 1.05 * triangle.nz * startDistance; + } + + int flag = 0; + // Levelweise alle Bloecke holen, die erweiterte BB schneiden + // und bearbeiten + for (int l = coarsestLevel; l < level; l++) { + std::vector<SPtr<Block3D>> consideredBlocks; + bgrid->getBlocksByCuboid(l, minX1, minX2, minX3, maxX1, maxX2, maxX3, consideredBlocks); + double x1a, x2a, x3a, x1b, x2b, x3b; + + for (size_t b = 0; b < consideredBlocks.size(); b++) { + SPtr<Block3D> block = consideredBlocks[b]; + if (block->getLevel() >= level) + continue; + + // start coordinaten des blocks ermitteln + UbTupleDouble3 coords = bgrid->getBlockWorldCoordinates(block); + UbTupleDouble3 deltas = bgrid->getBlockLengths(block); + + // Check, ob block komplett im Halbraum + x1a = val<1>(coords); + x1b = val<1>(coords) + val<1>(deltas); + x2a = val<2>(coords); + x2b = val<2>(coords) + val<2>(deltas); + x3a = val<3>(coords); + x3b = val<3>(coords) + val<3>(deltas); + + flag = 0; + if (!halfSpace.ptInside(x1a, x2a, x3a)) + flag |= (1 << 0); // 1 + if (!halfSpace.ptInside(x1b, x2a, x3a)) + flag |= (1 << 1); // 2 + if (!halfSpace.ptInside(x1b, x2b, x3a)) + flag |= (1 << 2); // 4 + if (!halfSpace.ptInside(x1a, x2b, x3a)) + flag |= (1 << 3); // 8 + if (!halfSpace.ptInside(x1a, x2a, x3b)) + flag |= (1 << 4); // 16 + if (!halfSpace.ptInside(x1b, x2a, x3b)) + flag |= (1 << 5); // 32 + if (!halfSpace.ptInside(x1b, x2b, x3b)) + flag |= (1 << 6); // 64 + if (!halfSpace.ptInside(x1a, x2b, x3b)) + flag |= (1 << 7); // 128 + + if (true && flag != 255) { + // blockseite ermitteln (skalarprodukt dreiecks-normale, vector (midTri->midCub) ) + // je nachdem muss für den massgeblichen block start oder stopdistance verwendet werden + // liegt block auf pos seite -> stopdistance ansonsten startdistance + double skalarprod = triangle.nx * (0.5 * (x1a + x1b) - triangle.getX1Centroid(nodes)) + + triangle.ny * (0.5 * (x2a + x2b) - triangle.getX2Centroid(nodes)) + + triangle.nz * (0.5 * (x3a + x3b) - triangle.getX3Centroid(nodes)); + + double blockdelta = 1.05 * stopDistance; + if (skalarprod < 1.E-8) + blockdelta = -1.05 * startDistance; // startDistance<0!! + else if (fabs(skalarprod) < 1.E-8) + blockdelta = 1.05 * UbMath::max(-startDistance, stopDistance); + + // block anpassen + blockMinX[0] = (float)(val<1>(coords) - blockdelta); + blockMinX[1] = (float)(val<2>(coords) - blockdelta); + blockMinX[2] = (float)(val<3>(coords) - blockdelta); + + blockMaxX[0] = (float)(val<1>(coords) + val<1>(deltas) + blockdelta); + blockMaxX[1] = (float)(val<2>(coords) + val<2>(deltas) + blockdelta); + blockMaxX[2] = (float)(val<3>(coords) + val<3>(deltas) + blockdelta); + + boxCenter[0] = (float)(0.5 * (blockMaxX[0] + blockMinX[0])); + boxCenter[1] = (float)(0.5 * (blockMaxX[1] + blockMinX[1])); + boxCenter[2] = (float)(0.5 * (blockMaxX[2] + blockMinX[2])); + + halfBoxSize[0] = (float)(0.5 * (blockMaxX[0] - blockMinX[0])); + halfBoxSize[1] = (float)(0.5 * (blockMaxX[1] - blockMinX[1])); + halfBoxSize[2] = (float)(0.5 * (blockMaxX[2] - blockMinX[2])); + + GbTriFaceMesh3D::Vertex &v1_ = nodes[triangle.v1]; + GbTriFaceMesh3D::Vertex &v2_ = nodes[triangle.v2]; + GbTriFaceMesh3D::Vertex &v3_ = nodes[triangle.v3]; + + triPoints[0][0] = v1_.x; + triPoints[0][1] = v1_.y; + triPoints[0][2] = v1_.z; + triPoints[1][0] = v2_.x; + triPoints[1][1] = v2_.y; + triPoints[1][2] = v2_.z; + triPoints[2][0] = v3_.x; + triPoints[2][1] = v3_.y; + triPoints[2][2] = v3_.z; + + // wenn block dreick schneidet, dann muss er verfeinert werden + if (GbMeshTools3D::triBoxOverlap(boxCenter, halfBoxSize, triPoints)) { + bgrid->expandBlock(block->getX1(), block->getX2(), block->getX3(), block->getLevel()); + } + } } - } - } - } - UBLOG(logDEBUG1, " - refine done"); + } + } + UBLOG(logDEBUG1, " - refine done"); } ////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::updateMovedGeometry(const double& timeStep) -{ - -} +void D3Q27TriFaceMeshInteractor::updateMovedGeometry(const double &timeStep) {} //////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::recursiveGridFill(CbArray3D<FLAGS>& flagfield, const short& xs, const short& ys, const short& zs, const FLAGS& type) +void D3Q27TriFaceMeshInteractor::recursiveGridFill(CbArray3D<FLAGS> &flagfield, const short &xs, const short &ys, + const short &zs, const FLAGS &type) { - // Algorithmus zum Füllen eines Polyeders, ausgehend vom Saatpunkt xs,ys,zs - - //Saatknoten einfärben - if( flagfield(xs,ys,zs)==UNDEF_FLAG ) - { - flagfield(xs,ys,zs) = type; - - if ( flagfield.indicesInRange( xs+1, ys , zs ) ) this->recursiveGridFill(flagfield,xs+1, ys , zs ,type); - if ( flagfield.indicesInRange( xs , ys+1, zs ) ) this->recursiveGridFill(flagfield,xs , ys+1, zs ,type); - if ( flagfield.indicesInRange( xs , ys , zs+1 ) ) this->recursiveGridFill(flagfield,xs , ys , zs+1,type); - if ( flagfield.indicesInRange( xs-1, ys , zs ) ) this->recursiveGridFill(flagfield,xs-1, ys , zs ,type); - if ( flagfield.indicesInRange( xs , ys-1, zs ) ) this->recursiveGridFill(flagfield,xs , ys-1, zs ,type); - if ( flagfield.indicesInRange( xs , ys , zs-1 ) ) this->recursiveGridFill(flagfield,xs , ys , zs-1,type); - } + // Algorithmus zum Füllen eines Polyeders, ausgehend vom Saatpunkt xs,ys,zs + + // Saatknoten einfärben + if (flagfield(xs, ys, zs) == UNDEF_FLAG) { + flagfield(xs, ys, zs) = type; + + if (flagfield.indicesInRange(xs + 1, ys, zs)) + this->recursiveGridFill(flagfield, xs + 1, ys, zs, type); + if (flagfield.indicesInRange(xs, ys + 1, zs)) + this->recursiveGridFill(flagfield, xs, ys + 1, zs, type); + if (flagfield.indicesInRange(xs, ys, zs + 1)) + this->recursiveGridFill(flagfield, xs, ys, zs + 1, type); + if (flagfield.indicesInRange(xs - 1, ys, zs)) + this->recursiveGridFill(flagfield, xs - 1, ys, zs, type); + if (flagfield.indicesInRange(xs, ys - 1, zs)) + this->recursiveGridFill(flagfield, xs, ys - 1, zs, type); + if (flagfield.indicesInRange(xs, ys, zs - 1)) + this->recursiveGridFill(flagfield, xs, ys, zs - 1, type); + } } ////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::iterativeGridFill(CbArray3D<FLAGS>& flagfield, const short& xs, const short& ys, const short& zs, const FLAGS& type) +void D3Q27TriFaceMeshInteractor::iterativeGridFill(CbArray3D<FLAGS> &flagfield, const short &xs, const short &ys, + const short &zs, const FLAGS &type) { - std::stack< UbTupleInt3 > stck; - stck.push( UbTupleInt3(xs,ys,zs) ); - - int x,y,z; - - while( !stck.empty() ) - { - x = val<1>( stck.top() ); - y = val<2>( stck.top() ); - z = val<3>( stck.top() ); - stck.pop(); - - FLAGS& flagType = flagfield( x, y, z ); - - if( flagType == UNDEF_FLAG ) - { - flagType = type; - - if ( flagfield.indicesInRange( x+1, y , z ) ) stck.push( UbTupleInt3( x+1, y , z ) ); - if ( flagfield.indicesInRange( x , y+1, z ) ) stck.push( UbTupleInt3( x , y+1, z ) ); - if ( flagfield.indicesInRange( x , y , z+1 ) ) stck.push( UbTupleInt3( x , y , z+1 ) ); - if ( flagfield.indicesInRange( x-1, y , z ) ) stck.push( UbTupleInt3( x-1, y , z ) ); - if ( flagfield.indicesInRange( x , y-1, z ) ) stck.push( UbTupleInt3( x , y-1, z ) ); - if ( flagfield.indicesInRange( x , y , z-1 ) ) stck.push( UbTupleInt3( x , y , z-1 ) ); - } - } - return; + std::stack<UbTupleInt3> stck; + stck.push(UbTupleInt3(xs, ys, zs)); + + int x, y, z; + + while (!stck.empty()) { + x = val<1>(stck.top()); + y = val<2>(stck.top()); + z = val<3>(stck.top()); + stck.pop(); + + FLAGS &flagType = flagfield(x, y, z); + + if (flagType == UNDEF_FLAG) { + flagType = type; + + if (flagfield.indicesInRange(x + 1, y, z)) + stck.push(UbTupleInt3(x + 1, y, z)); + if (flagfield.indicesInRange(x, y + 1, z)) + stck.push(UbTupleInt3(x, y + 1, z)); + if (flagfield.indicesInRange(x, y, z + 1)) + stck.push(UbTupleInt3(x, y, z + 1)); + if (flagfield.indicesInRange(x - 1, y, z)) + stck.push(UbTupleInt3(x - 1, y, z)); + if (flagfield.indicesInRange(x, y - 1, z)) + stck.push(UbTupleInt3(x, y - 1, z)); + if (flagfield.indicesInRange(x, y, z - 1)) + stck.push(UbTupleInt3(x, y, z - 1)); + } + } + return; } ////////////////////////////////////////////////////////////////////////// UbTupleDouble3 D3Q27TriFaceMeshInteractor::getForces() { - //FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(this->geoObject3D.get()); - //if(!feMesh) - //{ - // return D3Q19AMRInteractor::getForces(); - //} - ////return getForcesTriangle(); - //this->calculateForces(); - - double forceX1=0.0; - double forceX2=0.0; - double forceX3=0.0; - - //double area = 0.0; - - //vector<FeTriFaceMesh3D::VertexAttributes>* attributes = feMesh->getAttributes(); - - //for(size_t i=0; i<attributes->size(); i++) - //{ - // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; - // area = attribut.getArea(); - // forceX1 += attribut.getFX()*area; - // forceX2 += attribut.getFY()*area; - // forceX3 += attribut.getFZ()*area; - //} - return {forceX1,forceX2,forceX3}; + // FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(this->geoObject3D.get()); + // if(!feMesh) + //{ + // return D3Q19AMRInteractor::getForces(); + //} + ////return getForcesTriangle(); + // this->calculateForces(); + + double forceX1 = 0.0; + double forceX2 = 0.0; + double forceX3 = 0.0; + + // double area = 0.0; + + // vector<FeTriFaceMesh3D::VertexAttributes>* attributes = feMesh->getAttributes(); + + // for(size_t i=0; i<attributes->size(); i++) + //{ + // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; + // area = attribut.getArea(); + // forceX1 += attribut.getFX()*area; + // forceX2 += attribut.getFY()*area; + // forceX3 += attribut.getFZ()*area; + //} + return { forceX1, forceX2, forceX3 }; } ////////////////////////////////////////////////////////////////////////// UbTupleDouble3 D3Q27TriFaceMeshInteractor::getForcesTriangle() { - double forceX1=0.0; - double forceX2=0.0; - double forceX3=0.0; - - //D3Q19BlockGrid& grid.lock() = dynamic_cast<D3Q19BlockGrid&>(*this->grid.lock()); - //// CoordinateTransformation3D *trafo = this->grid.lock()->getTransformation(); - //// int minLevel = this->grid.lock()->getFinestInitializedLevel(); - //// double scaleX = trafo->getX1CoordinateScaling()/(1<<minLevel); - //// double scaleY = trafo->getX2CoordinateScaling()/(1<<minLevel); - //// double scaleZ = trafo->getX3CoordinateScaling()/(1<<minLevel); - //// int blocknx1 = grid.lock()->getBlockNX1(); - //// int blocknx2 = grid.lock()->getBlockNX2(); - //// int blocknx3 = grid.lock()->getBlockNX3(); - //// double xOffset = trafo->getX1CoordinateOffset(); - //// double yOffset = trafo->getX2CoordinateOffset(); - //// double zOffset = trafo->getX3CoordinateOffset(); - //vector<D3Q19Real> collFactors = ((D3Q19Calculator*)grid.lock()->getCalculator())->getCollisionsFactors(); - - ////for (int i=0;i<(int)gbTriangle3DInteractors.size(); i++) - ////{ - //// GbTriangle3D* tri = (GbTriangle3D*)gbTriangle3DInteractors[i]->getGbObject3D(); - - //// double px0 = tri->getX1Centroid(); - //// double py0 = tri->getX2Centroid(); - //// double pz0 = tri->getX3Centroid(); - //// double px = px0-xOffset; - //// double py = py0-yOffset; - //// double pz = pz0-zOffset; - //// px = px/scaleX; - //// py = py/scaleY; - //// pz = pz/scaleZ; - //// int x1 = (int)px; - //// int y1 = (int)py; - //// int z1 = (int)pz; - //// AMR3DBlock* block = this->grid.lock()->getBlock(x1,y1,z1,minLevel); - //// if(!block) block = this->grid.lock()->getSuperBlock(x1,y1,z1,minLevel); - //// if(!block) throw UbException(__FILE__,__LINE__,"kein Block ..."); - - //// double collFactor = collFactors[block->getLevel()]; - //// double nodeDistance = grid.lock()->getNodeDeltaX(block->getLevel()); - //// double bertX1 = ((px0-xOffset)/(1000.*nodeDistance)); - //// double bertX2 = ((py0-yOffset)/(1000.*nodeDistance)); - //// double bertX3 = ((pz0-zOffset)/(1000.*nodeDistance)); - //// int abstaendeX1 = (int)(bertX1*1000.); - //// int abstaendeX2 = (int)(bertX2*1000.); - //// int abstaendeX3 = (int)(bertX3*1000.); - //// int posW = abstaendeX1 - block->getX1Index()*blocknx1; - //// int posS = abstaendeX2 - block->getX2Index()*blocknx2; - //// int posB = abstaendeX3 - block->getX3Index()*blocknx3; - //// int posE=posW+1; - //// int posN=posS+1; - //// int posT=posB+1; - - //// D3Q19BlockDescriptor *bvd = dynamic_cast<D3Q19BlockDescriptor*>(block->getBlockDescriptor()); - //// if(!bvd) throw UbException(__FILE__,__LINE__,"kein Bvd ..."); - - //// CbUniformMatrix4D<double,IndexerX1X2X3X4>* tempdistributions = bvd->getTempDistributionMatrix(); - //// D3Q19BCMatrix<D3Q19BoundaryCondition> *bcMatrix = bvd->getBcMatrix(); - - //// UbTupleDouble6 stresses; - //// double dX = px0-this->geoObject3D->getX1Centroid(); - //// double dY = py0-this->geoObject3D->getX2Centroid(); - //// double dZ = pz0-this->geoObject3D->getX3Centroid(); - //// if(dX<=0.0 && dY<=0.0 && dZ<=0.0) - //// { - //// double *fWSB = tempdistributions->getStartAdressOfSortedArray(posW,posS,posB,0); - //// if(bcMatrix->isFluid(posW,posS,posB)) stresses = D3Q19System::getIncompStresses(fWSB, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX<=0.0 && dY>0.0 && dZ<=0.0) - //// { - //// double *fWNB = tempdistributions->getStartAdressOfSortedArray(posW,posN,posB,0); - //// if(bcMatrix->isFluid(posW,posN,posB)) stresses = D3Q19System::getIncompStresses(fWNB, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX<=0.0 && dY<=0.0 && dZ>0.0) - //// { - //// double *fWST = tempdistributions->getStartAdressOfSortedArray(posW,posS,posT,0); - //// if(bcMatrix->isFluid(posW,posS,posT)) stresses = D3Q19System::getIncompStresses(fWST, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX<=0.0 && dY>0.0 && dZ>0.0) - //// { - //// double *fWNT = tempdistributions->getStartAdressOfSortedArray(posW,posN,posT,0); - //// if(bcMatrix->isFluid(posW,posN,posT)) stresses = D3Q19System::getIncompStresses(fWNT, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX>0.0 && dY<=0.0 && dZ<=0.0) - //// { - //// double *fESB = tempdistributions->getStartAdressOfSortedArray(posE,posS,posB,0); - //// if(bcMatrix->isFluid(posE,posS,posB)) stresses = D3Q19System::getIncompStresses(fESB, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX>0.0 && dY>0.0 && dZ<=0.0) - //// { - //// double *fENB = tempdistributions->getStartAdressOfSortedArray(posE,posN,posB,0); - //// if(bcMatrix->isFluid(posE,posN,posB)) stresses = D3Q19System::getIncompStresses(fENB, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX>0.0 && dY<=0.0 && dZ>0.0) - //// { - //// double *fEST = tempdistributions->getStartAdressOfSortedArray(posE,posS,posT,0); - //// if(bcMatrix->isFluid(posE,posS,posT)) stresses = D3Q19System::getIncompStresses(fEST, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else if(dX>0.0 && dY>0.0 && dZ>0.0) - //// { - //// double *fENT = tempdistributions->getStartAdressOfSortedArray(posE,posN,posT,0); - //// if(bcMatrix->isFluid(posE,posN,posT)) stresses = D3Q19System::getIncompStresses(fENT, collFactor ); - //// else cout<<__LINE__<<" nicht fluid ..."; - //// } - //// else cout<<"punkt mit:"<<dX<<" "<<dY<<" "<<dZ<<" ist nicht bei \n"; - - //// double S11 = val<1>(stresses); - //// double S22 = val<2>(stresses); - //// double S33 = val<3>(stresses); - //// double S12 = val<4>(stresses); - //// double S13 = val<5>(stresses); - //// double S23 = val<6>(stresses); - - //// GbVector3D normal = tri->getNormal(); - //// double nx = normal.X1(); - //// double ny = normal.X2(); - //// double nz = normal.X3(); - //// double area = tri->getArea(); - - //// double Fx1 = area*(S11*nx+S12*ny+S13*nz); - //// double Fy1 = area*(S12*nx+S22*ny+S23*nz); - //// double Fz1 = area*(S13*nx+S23*ny+S33*nz); - //// forceX1 += Fx1; - //// forceX2 += Fy1; - //// forceX3 += Fz1; - ////} - return {forceX1,forceX2,forceX3}; + double forceX1 = 0.0; + double forceX2 = 0.0; + double forceX3 = 0.0; + + // D3Q19BlockGrid& grid.lock() = dynamic_cast<D3Q19BlockGrid&>(*this->grid.lock()); + //// CoordinateTransformation3D *trafo = this->grid.lock()->getTransformation(); + //// int minLevel = this->grid.lock()->getFinestInitializedLevel(); + //// double scaleX = trafo->getX1CoordinateScaling()/(1<<minLevel); + //// double scaleY = trafo->getX2CoordinateScaling()/(1<<minLevel); + //// double scaleZ = trafo->getX3CoordinateScaling()/(1<<minLevel); + //// int blocknx1 = grid.lock()->getBlockNX1(); + //// int blocknx2 = grid.lock()->getBlockNX2(); + //// int blocknx3 = grid.lock()->getBlockNX3(); + //// double xOffset = trafo->getX1CoordinateOffset(); + //// double yOffset = trafo->getX2CoordinateOffset(); + //// double zOffset = trafo->getX3CoordinateOffset(); + // vector<D3Q19Real> collFactors = ((D3Q19Calculator*)grid.lock()->getCalculator())->getCollisionsFactors(); + + ////for (int i=0;i<(int)gbTriangle3DInteractors.size(); i++) + ////{ + //// GbTriangle3D* tri = (GbTriangle3D*)gbTriangle3DInteractors[i]->getGbObject3D(); + + //// double px0 = tri->getX1Centroid(); + //// double py0 = tri->getX2Centroid(); + //// double pz0 = tri->getX3Centroid(); + //// double px = px0-xOffset; + //// double py = py0-yOffset; + //// double pz = pz0-zOffset; + //// px = px/scaleX; + //// py = py/scaleY; + //// pz = pz/scaleZ; + //// int x1 = (int)px; + //// int y1 = (int)py; + //// int z1 = (int)pz; + //// AMR3DBlock* block = this->grid.lock()->getBlock(x1,y1,z1,minLevel); + //// if(!block) block = this->grid.lock()->getSuperBlock(x1,y1,z1,minLevel); + //// if(!block) throw UbException(__FILE__,__LINE__,"kein Block ..."); + + //// double collFactor = collFactors[block->getLevel()]; + //// double nodeDistance = grid.lock()->getNodeDeltaX(block->getLevel()); + //// double bertX1 = ((px0-xOffset)/(1000.*nodeDistance)); + //// double bertX2 = ((py0-yOffset)/(1000.*nodeDistance)); + //// double bertX3 = ((pz0-zOffset)/(1000.*nodeDistance)); + //// int abstaendeX1 = (int)(bertX1*1000.); + //// int abstaendeX2 = (int)(bertX2*1000.); + //// int abstaendeX3 = (int)(bertX3*1000.); + //// int posW = abstaendeX1 - block->getX1Index()*blocknx1; + //// int posS = abstaendeX2 - block->getX2Index()*blocknx2; + //// int posB = abstaendeX3 - block->getX3Index()*blocknx3; + //// int posE=posW+1; + //// int posN=posS+1; + //// int posT=posB+1; + + //// D3Q19BlockDescriptor *bvd = dynamic_cast<D3Q19BlockDescriptor*>(block->getBlockDescriptor()); + //// if(!bvd) throw UbException(__FILE__,__LINE__,"kein Bvd ..."); + + //// CbUniformMatrix4D<double,IndexerX1X2X3X4>* tempdistributions = bvd->getTempDistributionMatrix(); + //// D3Q19BCMatrix<D3Q19BoundaryCondition> *bcMatrix = bvd->getBcMatrix(); + + //// UbTupleDouble6 stresses; + //// double dX = px0-this->geoObject3D->getX1Centroid(); + //// double dY = py0-this->geoObject3D->getX2Centroid(); + //// double dZ = pz0-this->geoObject3D->getX3Centroid(); + //// if(dX<=0.0 && dY<=0.0 && dZ<=0.0) + //// { + //// double *fWSB = tempdistributions->getStartAdressOfSortedArray(posW,posS,posB,0); + //// if(bcMatrix->isFluid(posW,posS,posB)) stresses = D3Q19System::getIncompStresses(fWSB, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX<=0.0 && dY>0.0 && dZ<=0.0) + //// { + //// double *fWNB = tempdistributions->getStartAdressOfSortedArray(posW,posN,posB,0); + //// if(bcMatrix->isFluid(posW,posN,posB)) stresses = D3Q19System::getIncompStresses(fWNB, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX<=0.0 && dY<=0.0 && dZ>0.0) + //// { + //// double *fWST = tempdistributions->getStartAdressOfSortedArray(posW,posS,posT,0); + //// if(bcMatrix->isFluid(posW,posS,posT)) stresses = D3Q19System::getIncompStresses(fWST, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX<=0.0 && dY>0.0 && dZ>0.0) + //// { + //// double *fWNT = tempdistributions->getStartAdressOfSortedArray(posW,posN,posT,0); + //// if(bcMatrix->isFluid(posW,posN,posT)) stresses = D3Q19System::getIncompStresses(fWNT, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX>0.0 && dY<=0.0 && dZ<=0.0) + //// { + //// double *fESB = tempdistributions->getStartAdressOfSortedArray(posE,posS,posB,0); + //// if(bcMatrix->isFluid(posE,posS,posB)) stresses = D3Q19System::getIncompStresses(fESB, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX>0.0 && dY>0.0 && dZ<=0.0) + //// { + //// double *fENB = tempdistributions->getStartAdressOfSortedArray(posE,posN,posB,0); + //// if(bcMatrix->isFluid(posE,posN,posB)) stresses = D3Q19System::getIncompStresses(fENB, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX>0.0 && dY<=0.0 && dZ>0.0) + //// { + //// double *fEST = tempdistributions->getStartAdressOfSortedArray(posE,posS,posT,0); + //// if(bcMatrix->isFluid(posE,posS,posT)) stresses = D3Q19System::getIncompStresses(fEST, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else if(dX>0.0 && dY>0.0 && dZ>0.0) + //// { + //// double *fENT = tempdistributions->getStartAdressOfSortedArray(posE,posN,posT,0); + //// if(bcMatrix->isFluid(posE,posN,posT)) stresses = D3Q19System::getIncompStresses(fENT, collFactor ); + //// else cout<<__LINE__<<" nicht fluid ..."; + //// } + //// else cout<<"punkt mit:"<<dX<<" "<<dY<<" "<<dZ<<" ist nicht bei \n"; + + //// double S11 = val<1>(stresses); + //// double S22 = val<2>(stresses); + //// double S33 = val<3>(stresses); + //// double S12 = val<4>(stresses); + //// double S13 = val<5>(stresses); + //// double S23 = val<6>(stresses); + + //// GbVector3D normal = tri->getNormal(); + //// double nx = normal.X1(); + //// double ny = normal.X2(); + //// double nz = normal.X3(); + //// double area = tri->getArea(); + + //// double Fx1 = area*(S11*nx+S12*ny+S13*nz); + //// double Fy1 = area*(S12*nx+S22*ny+S23*nz); + //// double Fz1 = area*(S13*nx+S23*ny+S33*nz); + //// forceX1 += Fx1; + //// forceX2 += Fy1; + //// forceX3 += Fz1; + ////} + return { forceX1, forceX2, forceX3 }; } ////////////////////////////////////////////////////////////////////////// void D3Q27TriFaceMeshInteractor::calculateForces() { - //FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(this->geoObject3D.get()); - //if(!feMesh) throw UbException(UB_EXARGS,"geoObject is not a FeTriFaceMesh3D!"); - - //if(this->stressMode == STRESSNORMAL) this->calculateStresses(); - //else if(this->stressMode == STRESSALTERNATIV) this->calculateStressesAlternativ(); - - //vector<FeTriFaceMesh3D::VertexAttributes>* attributes = feMesh->getAttributes(); - - //for (int i=0;i<(int)attributes->size() ;i++) - //{ - // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; - // attribut.setFX(0.0); - // attribut.setFY(0.0); - // attribut.setFZ(0.0); - // attribut.setArea(0.0); - //} - //vector<GbTriFaceMesh3D::TriFace>& triangles = *feMesh->getTriangles(); - //vector<GbTriFaceMesh3D::Vertex>& nodes = *feMesh->getNodes(); - //for (size_t i=0; i<triangles.size(); i++) - //{ - // GbTriFaceMesh3D::TriFace& triangle = triangles[i]; - // FeTriFaceMesh3D::VertexAttributes& vAttribut1 = (*attributes)[triangle.v1]; - // FeTriFaceMesh3D::VertexAttributes& vAttribut2 = (*attributes)[triangle.v2]; - // FeTriFaceMesh3D::VertexAttributes& vAttribut3 = (*attributes)[triangle.v3]; - // UbTupleDouble6& stressesP1 = vAttribut1.getStresses(); - // UbTupleDouble6& stressesP2 = vAttribut2.getStresses(); - // UbTupleDouble6& stressesP3 = vAttribut3.getStresses(); - // double p1S11 = val<1>(stressesP1); double p2S11 = val<1>(stressesP2); double p3S11 = val<1>(stressesP3); - // double p1S22 = val<2>(stressesP1); double p2S22 = val<2>(stressesP2); double p3S22 = val<2>(stressesP3); - // double p1S33 = val<3>(stressesP1); double p2S33 = val<3>(stressesP2); double p3S33 = val<3>(stressesP3); - // double p1S12 = val<4>(stressesP1); double p2S12 = val<4>(stressesP2); double p3S12 = val<4>(stressesP3); - // double p1S13 = val<5>(stressesP1); double p2S13 = val<5>(stressesP2); double p3S13 = val<5>(stressesP3); - // double p1S23 = val<6>(stressesP1); double p2S23 = val<6>(stressesP2); double p3S23 = val<6>(stressesP3); - - // triangle.calculateNormal(nodes); - // double nx = triangle.nx; - // double ny = triangle.ny; - // double nz = triangle.nz; - // double area = 0.3333*triangle.getArea(nodes); - - // if(UbMath::lessEqual(area,0.0)) cout<<__FILE__<<" "<<__LINE__<<" area <= 0 "<<endl; - - // double Fx1 = area*(0.333*(p1S11*nx+p1S12*ny+p1S13*nz)+0.333*(p2S11*nx+p2S12*ny+p2S13*nz)+0.333*(p3S11*nx+p3S12*ny+p3S13*nz)); - // double Fx2 = Fx1; - // double Fx3 = Fx1; - - // double Fy1 = area*(0.333*(p1S12*nx+p1S22*ny+p1S23*nz)+0.333*(p2S12*nx+p2S22*ny+p2S23*nz)+0.333*(p3S12*nx+p3S22*ny+p3S23*nz)); - // double Fy2 = Fy1; - // double Fy3 = Fy1; - - // double Fz1 = area*(0.333*(p1S13*nx+p1S23*ny+p1S33*nz)+0.333*(p2S13*nx+p2S23*ny+p2S33*nz)+0.333*(p3S13*nx+p3S23*ny+p3S33*nz)); - // double Fz2 = Fz1; - // double Fz3 = Fz1; - // // cout<<Fx1<<" "<<Fy1<<" "<<Fz1<<endl; - // vAttribut1.addFX(Fx1); vAttribut2.addFX(Fx2); vAttribut3.addFX(Fx3); - // vAttribut1.addFY(Fy1); vAttribut2.addFY(Fy2); vAttribut3.addFY(Fy3); - // vAttribut1.addFZ(Fz1); vAttribut2.addFZ(Fz2); vAttribut3.addFZ(Fz3); - // vAttribut1.addArea(area); vAttribut2.addArea(area); vAttribut3.addArea(area); - //} - //for (size_t i=0; i<attributes->size(); i++) - //{ - // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; - - // double newFX = attribut.getFX()/attribut.getArea(); - // double newFY = attribut.getFY()/attribut.getArea(); - // double newFZ = attribut.getFZ()/attribut.getArea(); - // //if(i==100) cout<<"F:"<<newFX<<" "<<newFY<<" "<<newFZ<<endl; - // //double oldFX = p->getOldFX(); - // //double oldFY = p->getOldFY(); - // //int alphaSteps = p->getFilteringSteps(); - // //double alpha = 1.0; - // //if(alphaSteps != 0) - // //{ - // // alpha = (1.0-alphaSteps*0.1); - // // // cout<<p->toString()<<" alpha:"<<alpha<<" steps:"<<alphaSteps<<endl; - // // p->reduceFilteringSteps(); - // //} - // //newFX = (1.-alpha)*oldFX+alpha*newFX; - // //newFY = (1.-alpha)*oldFY+alpha*newFY; - - // attribut.setFX(newFX); - // attribut.setFY(newFY); - // attribut.setFZ(newFZ); - // //cout<<i<<" "<<newFX<<" "<<newFY<<" "<<newFZ<<endl; - // //cout<<i<<" "<<p->toString()<<endl; - - //} + // FeTriFaceMesh3D* feMesh = dynamic_cast<FeTriFaceMesh3D*>(this->geoObject3D.get()); + // if(!feMesh) throw UbException(UB_EXARGS,"geoObject is not a FeTriFaceMesh3D!"); + + // if(this->stressMode == STRESSNORMAL) this->calculateStresses(); + // else if(this->stressMode == STRESSALTERNATIV) this->calculateStressesAlternativ(); + + // vector<FeTriFaceMesh3D::VertexAttributes>* attributes = feMesh->getAttributes(); + + // for (int i=0;i<(int)attributes->size() ;i++) + //{ + // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; + // attribut.setFX(0.0); + // attribut.setFY(0.0); + // attribut.setFZ(0.0); + // attribut.setArea(0.0); + //} + // vector<GbTriFaceMesh3D::TriFace>& triangles = *feMesh->getTriangles(); + // vector<GbTriFaceMesh3D::Vertex>& nodes = *feMesh->getNodes(); + // for (size_t i=0; i<triangles.size(); i++) + //{ + // GbTriFaceMesh3D::TriFace& triangle = triangles[i]; + // FeTriFaceMesh3D::VertexAttributes& vAttribut1 = (*attributes)[triangle.v1]; + // FeTriFaceMesh3D::VertexAttributes& vAttribut2 = (*attributes)[triangle.v2]; + // FeTriFaceMesh3D::VertexAttributes& vAttribut3 = (*attributes)[triangle.v3]; + // UbTupleDouble6& stressesP1 = vAttribut1.getStresses(); + // UbTupleDouble6& stressesP2 = vAttribut2.getStresses(); + // UbTupleDouble6& stressesP3 = vAttribut3.getStresses(); + // double p1S11 = val<1>(stressesP1); double p2S11 = val<1>(stressesP2); double p3S11 = val<1>(stressesP3); + // double p1S22 = val<2>(stressesP1); double p2S22 = val<2>(stressesP2); double p3S22 = val<2>(stressesP3); + // double p1S33 = val<3>(stressesP1); double p2S33 = val<3>(stressesP2); double p3S33 = val<3>(stressesP3); + // double p1S12 = val<4>(stressesP1); double p2S12 = val<4>(stressesP2); double p3S12 = val<4>(stressesP3); + // double p1S13 = val<5>(stressesP1); double p2S13 = val<5>(stressesP2); double p3S13 = val<5>(stressesP3); + // double p1S23 = val<6>(stressesP1); double p2S23 = val<6>(stressesP2); double p3S23 = val<6>(stressesP3); + + // triangle.calculateNormal(nodes); + // double nx = triangle.nx; + // double ny = triangle.ny; + // double nz = triangle.nz; + // double area = 0.3333*triangle.getArea(nodes); + + // if(UbMath::lessEqual(area,0.0)) cout<<__FILE__<<" "<<__LINE__<<" area <= 0 "<<endl; + + // double Fx1 = + // area*(0.333*(p1S11*nx+p1S12*ny+p1S13*nz)+0.333*(p2S11*nx+p2S12*ny+p2S13*nz)+0.333*(p3S11*nx+p3S12*ny+p3S13*nz)); + // double Fx2 = Fx1; + // double Fx3 = Fx1; + + // double Fy1 = + // area*(0.333*(p1S12*nx+p1S22*ny+p1S23*nz)+0.333*(p2S12*nx+p2S22*ny+p2S23*nz)+0.333*(p3S12*nx+p3S22*ny+p3S23*nz)); + // double Fy2 = Fy1; + // double Fy3 = Fy1; + + // double Fz1 = + // area*(0.333*(p1S13*nx+p1S23*ny+p1S33*nz)+0.333*(p2S13*nx+p2S23*ny+p2S33*nz)+0.333*(p3S13*nx+p3S23*ny+p3S33*nz)); + // double Fz2 = Fz1; + // double Fz3 = Fz1; + // // cout<<Fx1<<" "<<Fy1<<" "<<Fz1<<endl; + // vAttribut1.addFX(Fx1); vAttribut2.addFX(Fx2); vAttribut3.addFX(Fx3); + // vAttribut1.addFY(Fy1); vAttribut2.addFY(Fy2); vAttribut3.addFY(Fy3); + // vAttribut1.addFZ(Fz1); vAttribut2.addFZ(Fz2); vAttribut3.addFZ(Fz3); + // vAttribut1.addArea(area); vAttribut2.addArea(area); vAttribut3.addArea(area); + //} + // for (size_t i=0; i<attributes->size(); i++) + //{ + // FeTriFaceMesh3D::VertexAttributes& attribut = (*attributes)[i]; + + // double newFX = attribut.getFX()/attribut.getArea(); + // double newFY = attribut.getFY()/attribut.getArea(); + // double newFZ = attribut.getFZ()/attribut.getArea(); + // //if(i==100) cout<<"F:"<<newFX<<" "<<newFY<<" "<<newFZ<<endl; + // //double oldFX = p->getOldFX(); + // //double oldFY = p->getOldFY(); + // //int alphaSteps = p->getFilteringSteps(); + // //double alpha = 1.0; + // //if(alphaSteps != 0) + // //{ + // // alpha = (1.0-alphaSteps*0.1); + // // // cout<<p->toString()<<" alpha:"<<alpha<<" steps:"<<alphaSteps<<endl; + // // p->reduceFilteringSteps(); + // //} + // //newFX = (1.-alpha)*oldFX+alpha*newFX; + // //newFY = (1.-alpha)*oldFY+alpha*newFY; + + // attribut.setFX(newFX); + // attribut.setFY(newFY); + // attribut.setFZ(newFZ); + // //cout<<i<<" "<<newFX<<" "<<newFY<<" "<<newFZ<<endl; + // //cout<<i<<" "<<p->toString()<<endl; + + //} } ////////////////////////////////////////////////////////////////////////// string D3Q27TriFaceMeshInteractor::toString() { - stringstream ss; - ss<< "D3Q27TriFaceMeshInteractor[label=D3Q27TriFaceMeshInteractor"; - if(this->isSolid()) ss<<", solid"; - if(this->isInverseSolid()) ss<<", inversesolid"; - if(this->isTimeDependent()) ss<<", timedependent"; - if(geoObject3D!=NULL) ss<<", AMR3DInteractor: "<<geoObject3D->toString(); - ss<<"]"; - - return ss.str(); + stringstream ss; + ss << "D3Q27TriFaceMeshInteractor[label=D3Q27TriFaceMeshInteractor"; + if (this->isSolid()) + ss << ", solid"; + if (this->isInverseSolid()) + ss << ", inversesolid"; + if (this->isTimeDependent()) + ss << ", timedependent"; + if (geoObject3D != NULL) + ss << ", AMR3DInteractor: " << geoObject3D->toString(); + ss << "]"; + + return ss.str(); } ////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::reinitWithStoredQs( const double& /*timeStep*/ ) +void D3Q27TriFaceMeshInteractor::reinitWithStoredQs(const double & /*timeStep*/) { - //alle solid Bloecke wieder solid setzen - std::vector<SPtr<Block3D>>& solidBlocks = this->getSolidBlockSet(); - for(size_t i=0; i<solidBlocks.size(); i++) - { - solidBlocks[i]->setActive(false); //<- quick n dirty - } - - //alle solid-nodes wieder solid setzen (solids die quasi in den TransBloecken liegen) - std::map<SPtr<Block3D>, std::set< UbTupleInt3 > >::iterator it1; - for( it1=this->solidNodeIndicesMap.begin(); it1!=this->solidNodeIndicesMap.end(); ++it1 ) - { - SPtr<Block3D> block = it1->first; - - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - std::set< UbTupleInt3 >& indicesSet = it1->second; - - for( std::set< UbTupleInt3 >::iterator setIt=indicesSet.begin(); setIt!=indicesSet.end(); ++setIt ) - { - bcMatrix->setSolid( val<1>(*setIt), val<2>(*setIt), val<3>(*setIt) ); - } - } - - //BCS WIEDERHERSTELLEN - std::map<SPtr<Block3D>, std::map< UbTupleInt3, std::vector<float> > >::iterator it; - for( it=bcNodeIndicesAndQsMap.begin(); it!=bcNodeIndicesAndQsMap.end(); ++it ) - { - SPtr<Block3D> block = it->first; - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - - std::map< UbTupleInt3, std::vector<float> >::iterator it2; - for( it2=it->second.begin(); it2!=it->second.end(); ++it2 ) - { - const UbTupleInt3& pos = it2->first; - std::vector< float > qs = it2->second; - - //SG_27.08.2010 - if(bcMatrix->isSolid(val<1>(pos), val<2>(pos), val<3>(pos))) continue; - - SPtr<BoundaryConditions> bc = bcMatrix->getBC( val<1>(pos), val<2>(pos), val<3>(pos) ); - if(!bc) - { - bc = SPtr<BoundaryConditions>(new BoundaryConditions); - bcMatrix->setBC( val<1>(pos), val<2>(pos), val<3>(pos), bc ); - } - - double x1w = qs[D3Q27System::FENDDIR+1+0]; - double x2w = qs[D3Q27System::FENDDIR+1+1]; - double x3w = qs[D3Q27System::FENDDIR+1+2]; - - - //TODO: HACK GEHOERT NICHT HIERHIER!!! - start - //es handelt sich un ein statisches Objekt und beim Propeller gibt - // es Schwierigkeiten an den Flügelspitzen, dass kann daher kommen, - //dass dort zuviel bc-flaggs sind und mit Geschwindigkeit ergibt dies ziemlich grosse Werte - bc->setBoundaryVelocityX1(0.0); - bc->setBoundaryVelocityX2(0.0); - bc->setBoundaryVelocityX3(0.0); - //TODO: HACK GEHOERT NICHT HIERHIER!!! - end - - bool gotQs = false; - for(int fdir=D3Q27System::FSTARTDIR; fdir<=D3Q27System::FENDDIR; fdir++) - { - if( UbMath::greater(qs[fdir], -1.0) && UbMath::less( qs[fdir], bc->getQ(fdir) ) ) - { - gotQs = true; - for(size_t index=0; index<this->bcAdapters.size(); index++) - this->bcAdapters[index]->adaptBCForDirection( *this, bc, x1w, x2w, x3w, qs[fdir], fdir); + // alle solid Bloecke wieder solid setzen + std::vector<SPtr<Block3D>> &solidBlocks = this->getSolidBlockSet(); + for (size_t i = 0; i < solidBlocks.size(); i++) { + solidBlocks[i]->setActive(false); //<- quick n dirty + } + + // alle solid-nodes wieder solid setzen (solids die quasi in den TransBloecken liegen) + std::map<SPtr<Block3D>, std::set<UbTupleInt3>>::iterator it1; + for (it1 = this->solidNodeIndicesMap.begin(); it1 != this->solidNodeIndicesMap.end(); ++it1) { + SPtr<Block3D> block = it1->first; + + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + std::set<UbTupleInt3> &indicesSet = it1->second; + + for (std::set<UbTupleInt3>::iterator setIt = indicesSet.begin(); setIt != indicesSet.end(); ++setIt) { + bcMatrix->setSolid(val<1>(*setIt), val<2>(*setIt), val<3>(*setIt)); + } + } + + // BCS WIEDERHERSTELLEN + std::map<SPtr<Block3D>, std::map<UbTupleInt3, std::vector<float>>>::iterator it; + for (it = bcNodeIndicesAndQsMap.begin(); it != bcNodeIndicesAndQsMap.end(); ++it) { + SPtr<Block3D> block = it->first; + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + + std::map<UbTupleInt3, std::vector<float>>::iterator it2; + for (it2 = it->second.begin(); it2 != it->second.end(); ++it2) { + const UbTupleInt3 &pos = it2->first; + std::vector<float> qs = it2->second; + + // SG_27.08.2010 + if (bcMatrix->isSolid(val<1>(pos), val<2>(pos), val<3>(pos))) + continue; + + SPtr<BoundaryConditions> bc = bcMatrix->getBC(val<1>(pos), val<2>(pos), val<3>(pos)); + if (!bc) { + bc = SPtr<BoundaryConditions>(new BoundaryConditions); + bcMatrix->setBC(val<1>(pos), val<2>(pos), val<3>(pos), bc); + } + + double x1w = qs[D3Q27System::FENDDIR + 1 + 0]; + double x2w = qs[D3Q27System::FENDDIR + 1 + 1]; + double x3w = qs[D3Q27System::FENDDIR + 1 + 2]; + + // TODO: HACK GEHOERT NICHT HIERHIER!!! - start + // es handelt sich un ein statisches Objekt und beim Propeller gibt + // es Schwierigkeiten an den Flügelspitzen, dass kann daher kommen, + // dass dort zuviel bc-flaggs sind und mit Geschwindigkeit ergibt dies ziemlich grosse Werte + bc->setBoundaryVelocityX1(0.0); + bc->setBoundaryVelocityX2(0.0); + bc->setBoundaryVelocityX3(0.0); + // TODO: HACK GEHOERT NICHT HIERHIER!!! - end + + bool gotQs = false; + for (int fdir = D3Q27System::FSTARTDIR; fdir <= D3Q27System::FENDDIR; fdir++) { + if (UbMath::greater(qs[fdir], -1.0) && UbMath::less(qs[fdir], bc->getQ(fdir))) { + gotQs = true; + for (size_t index = 0; index < this->bcAdapters.size(); index++) + this->bcAdapters[index]->adaptBCForDirection(*this, bc, x1w, x2w, x3w, qs[fdir], fdir); + } } - } - if(gotQs) - for(size_t index=0; index<this->bcAdapters.size(); index++) - this->bcAdapters[index]->adaptBC( *this, bc, x1w, x2w, x3w); - } - } + if (gotQs) + for (size_t index = 0; index < this->bcAdapters.size(); index++) + this->bcAdapters[index]->adaptBC(*this, bc, x1w, x2w, x3w); + } + } } ////////////////////////////////////////////////////////////////////////// -void D3Q27TriFaceMeshInteractor::updateInteractor( const double& /*timestep*//*=0*/ ) +void D3Q27TriFaceMeshInteractor::updateInteractor(const double & /*timestep*/ /*=0*/) { - UB_THROW( UbException("D3Q27TriFaceMeshInteractor::updateInteractor - toDo") ); + UB_THROW(UbException("D3Q27TriFaceMeshInteractor::updateInteractor - toDo")); } - - - - - - diff --git a/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.h b/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.h index 70e1b2d25..ebd707a41 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.h +++ b/src/cpu/VirtualFluidsCore/Interactors/D3Q27TriFaceMeshInteractor.h @@ -1,13 +1,13 @@ #ifndef D3Q19AMRTRIFACEMESHINTERACTOR_H #define D3Q19AMRTRIFACEMESHINTERACTOR_H +#include <PointerDefinitions.h> +#include <map> #include <string> #include <vector> -#include <map> -#include <PointerDefinitions.h> -#include "D3Q27Interactor.h" #include "CbArray3D.h" +#include "D3Q27Interactor.h" class GbObject3D; class Grid3D; @@ -15,91 +15,113 @@ class BCAdapter; class GbTriFaceMesh3D; class Block3D; -class D3Q27TriFaceMeshInteractor : public D3Q27Interactor +class D3Q27TriFaceMeshInteractor : public D3Q27Interactor { public: - static const int STRESSNORMAL=0; - static const int STRESSALTERNATIV=1; - - D3Q27TriFaceMeshInteractor(); - D3Q27TriFaceMeshInteractor(SPtr<Grid3D> grid, std::string name="D3Q27TriFaceMeshInteractor"); - D3Q27TriFaceMeshInteractor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); - D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type); - D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, int type, Interactor3D::Accuracy a); - //D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, D3Q27BoundaryConditionAdapterPtr bcAdapter, int type, std::string name="D3Q27TriFaceMeshInteractor"); - - ~D3Q27TriFaceMeshInteractor() override; - - void initInteractor(const double& timeStep=0) override; - virtual void initInteractor2(const double& timeStep=0); - - void updateInteractor(const double& timestep=0) override; - - void updateMovedGeometry(const double& timeStep=0); - void setQs(const double& timeStep); - void refineBlockGridToLevel(int level, double startDistance, double stopDistance); - - bool setDifferencesToGbObject3D(const SPtr<Block3D> block/*,const double& orgX1,const double& orgX2,const double& orgX3,const double& blockLengthX1,const double& blockLengthX2,const double& blockLengthX3, const double& timestep=0*/) override; - - void setRegardPointInObjectTest( bool opt ) { this->regardPIOTest = opt; } - - ObObject* clone() { throw UbException(UB_EXARGS,"not implemented"); } - - UbTupleDouble3 getForces() override; - UbTupleDouble3 getForcesTriangle(); - - void setStressMode(int stressMode) { this->stressMode = stressMode; } - void setUseHalfSpaceCheck(bool useHalfSpace ) { this->useHalfSpace = useHalfSpace; } - //void setReinitWithStoredQs(bool reinitWithStoredQsFlag) { this->reinitWithStoredQsFlag = reinitWithStoredQsFlag; } - - void calculateForces(); - void calculateStresses(); - void calculateStressesAlternativ(); - - void calcStressesLine(UbTupleDouble6& stresses, const double& weight, const UbTupleDouble6& stvW, const UbTupleDouble6& stvE ); - void calcStressesFace(UbTupleDouble6& stresses, const double& weightX, const double& weightY, const UbTupleDouble6& stvSW, const UbTupleDouble6& stvSE, const UbTupleDouble6& stvNE, const UbTupleDouble6& stvNW ); - void calcStressesCube(UbTupleDouble6& stresses, const double& weightX, const double& weightY, const double& weightZ, const UbTupleDouble6& stvBSW, const UbTupleDouble6& stvBSE, const UbTupleDouble6& stvBNE, const UbTupleDouble6& stvBNW, const UbTupleDouble6& stvTSW, const UbTupleDouble6& stvTSE, const UbTupleDouble6& stvTNE, const UbTupleDouble6& stvTNW ); - - void calculatePressure(); - void calcPressureLine(double &p, const double& weight, const double& pW, const double& pE ); - void calcPressureFace(double &p, const double& weightX, const double& weightY, const double& pSW, const double& pSE, const double& pNE, const double& pNW ); - void calcPressureCube(double &p, const double& weightX, const double& weightY, const double& weightZ, const double& pBSW, const double& pBSE, const double& pBNE, const double& pBNW, const double& pTSW, const double& pTSE, const double& pTNE, const double& pTNW ); - - void setForceShift(double forceshift) { this->forceshift = forceshift; this->forceshiftpolicy = true; } - void setVelocityShift(double velocityshift) { this->velocityshift = velocityshift; this->velocityshiftpolicy = true; } - double getForceShift() { return this->forceshift; } - double getVelocityShift() { return this->velocityshift; } - bool getForceShiftPolicy() { return forceshiftpolicy;} - bool getVelocityShiftPolicy() { return velocityshiftpolicy;} - - void clearBcNodeIndicesAndQsMap() { this->bcNodeIndicesAndQsMap.clear();} - - virtual std::string toString(); - + static const int STRESSNORMAL = 0; + static const int STRESSALTERNATIV = 1; + + D3Q27TriFaceMeshInteractor(); + D3Q27TriFaceMeshInteractor(SPtr<Grid3D> grid, std::string name = "D3Q27TriFaceMeshInteractor"); + D3Q27TriFaceMeshInteractor(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); + D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, + int type); + D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, SPtr<Grid3D> grid, SPtr<BCAdapter> bcAdapter, + int type, Interactor3D::Accuracy a); + // D3Q27TriFaceMeshInteractor(SPtr<GbTriFaceMesh3D> triFaceMesh, D3Q27BoundaryConditionAdapterPtr bcAdapter, int + // type, std::string name="D3Q27TriFaceMeshInteractor"); + + ~D3Q27TriFaceMeshInteractor() override; + + void initInteractor(const double &timeStep = 0) override; + virtual void initInteractor2(const double &timeStep = 0); + + void updateInteractor(const double ×tep = 0) override; + + void updateMovedGeometry(const double &timeStep = 0); + void setQs(const double &timeStep); + void refineBlockGridToLevel(int level, double startDistance, double stopDistance); + + bool setDifferencesToGbObject3D(const SPtr<Block3D> block/*,const double& orgX1,const double& orgX2,const double& orgX3,const double& blockLengthX1,const double& blockLengthX2,const double& blockLengthX3, const double& timestep=0*/) override; + + void setRegardPointInObjectTest(bool opt) { this->regardPIOTest = opt; } + + ObObject *clone() { throw UbException(UB_EXARGS, "not implemented"); } + + UbTupleDouble3 getForces() override; + UbTupleDouble3 getForcesTriangle(); + + void setStressMode(int stressMode) { this->stressMode = stressMode; } + void setUseHalfSpaceCheck(bool useHalfSpace) { this->useHalfSpace = useHalfSpace; } + // void setReinitWithStoredQs(bool reinitWithStoredQsFlag) { this->reinitWithStoredQsFlag = reinitWithStoredQsFlag; + // } + + void calculateForces(); + void calculateStresses(); + void calculateStressesAlternativ(); + + void calcStressesLine(UbTupleDouble6 &stresses, const double &weight, const UbTupleDouble6 &stvW, + const UbTupleDouble6 &stvE); + void calcStressesFace(UbTupleDouble6 &stresses, const double &weightX, const double &weightY, + const UbTupleDouble6 &stvSW, const UbTupleDouble6 &stvSE, const UbTupleDouble6 &stvNE, + const UbTupleDouble6 &stvNW); + void calcStressesCube(UbTupleDouble6 &stresses, const double &weightX, const double &weightY, const double &weightZ, + const UbTupleDouble6 &stvBSW, const UbTupleDouble6 &stvBSE, const UbTupleDouble6 &stvBNE, + const UbTupleDouble6 &stvBNW, const UbTupleDouble6 &stvTSW, const UbTupleDouble6 &stvTSE, + const UbTupleDouble6 &stvTNE, const UbTupleDouble6 &stvTNW); + + void calculatePressure(); + void calcPressureLine(double &p, const double &weight, const double &pW, const double &pE); + void calcPressureFace(double &p, const double &weightX, const double &weightY, const double &pSW, const double &pSE, + const double &pNE, const double &pNW); + void calcPressureCube(double &p, const double &weightX, const double &weightY, const double &weightZ, + const double &pBSW, const double &pBSE, const double &pBNE, const double &pBNW, + const double &pTSW, const double &pTSE, const double &pTNE, const double &pTNW); + + void setForceShift(double forceshift) + { + this->forceshift = forceshift; + this->forceshiftpolicy = true; + } + void setVelocityShift(double velocityshift) + { + this->velocityshift = velocityshift; + this->velocityshiftpolicy = true; + } + double getForceShift() { return this->forceshift; } + double getVelocityShift() { return this->velocityshift; } + bool getForceShiftPolicy() { return forceshiftpolicy; } + bool getVelocityShiftPolicy() { return velocityshiftpolicy; } + + void clearBcNodeIndicesAndQsMap() { this->bcNodeIndicesAndQsMap.clear(); } + + virtual std::string toString(); protected: - int stressMode; - - double forceshift{0.0}; - double velocityshift{0.0}; - bool forceshiftpolicy{false}; - bool velocityshiftpolicy{false}; - bool useHalfSpace{true}; - bool regardPIOTest{true}; - - void reinitWithStoredQs(const double& timeStep); - // bool reinitWithStoredQsFlag; - std::map< SPtr<Block3D>, std::map < UbTupleInt3, std::vector< float > > > bcNodeIndicesAndQsMap; //!!! es kann sein, dass in diesem interactor - //an eine rpos eine BC gesetzt wurde, aber derselbe node in - //in einem anderen in einen anderen Typ (z.B. Solid) geaendert - //wurde --> es ist keine BC mehr an der stelle! - - enum SolidCheckMethod { ScanLine, PointInObject }; - - enum FLAGS { BC_FLAG, UNDEF_FLAG, FLUID_FLAG, SOLID_FLAG, OLDSOLID_FLAG }; - void recursiveGridFill(CbArray3D<FLAGS>& flagfield, const short& xs, const short& ys, const short& zs, const FLAGS& type); - void iterativeGridFill(CbArray3D<FLAGS>& flagfield, const short& xs, const short& ys, const short& zs, const FLAGS& type); + int stressMode; + + double forceshift{ 0.0 }; + double velocityshift{ 0.0 }; + bool forceshiftpolicy{ false }; + bool velocityshiftpolicy{ false }; + bool useHalfSpace{ true }; + bool regardPIOTest{ true }; + + void reinitWithStoredQs(const double &timeStep); + // bool reinitWithStoredQsFlag; + std::map<SPtr<Block3D>, std::map<UbTupleInt3, std::vector<float>>> + bcNodeIndicesAndQsMap; //!!! es kann sein, dass in diesem interactor + // an eine rpos eine BC gesetzt wurde, aber derselbe node in + // in einem anderen in einen anderen Typ (z.B. Solid) geaendert + // wurde --> es ist keine BC mehr an der stelle! + + enum SolidCheckMethod { ScanLine, PointInObject }; + + enum FLAGS { BC_FLAG, UNDEF_FLAG, FLUID_FLAG, SOLID_FLAG, OLDSOLID_FLAG }; + void recursiveGridFill(CbArray3D<FLAGS> &flagfield, const short &xs, const short &ys, const short &zs, + const FLAGS &type); + void iterativeGridFill(CbArray3D<FLAGS> &flagfield, const short &xs, const short &ys, const short &zs, + const FLAGS &type); }; - -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.cpp b/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.cpp index 0899c8634..0127c9c88 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.cpp +++ b/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,312 +33,274 @@ #include "Interactor3D.h" +#include "UbException.h" +#include <basics/utilities/UbMath.h> #include <fstream> #include <geometry3d/GbCuboid3D.h> -#include <basics/utilities/UbMath.h> -#include "UbException.h" -#include "Grid3D.h" #include "Block3D.h" #include "GbObject3D.h" - +#include "Grid3D.h" using namespace std; -const int Interactor3D::SOLID = (1<<0); //1 -const int Interactor3D::INVERSESOLID = (1<<1); //2 -const int Interactor3D::TIMEDEPENDENT = (1<<2); //4 //zeitlich -const int Interactor3D::FLUID = (1<<3); //8 -const int Interactor3D::MOVEABLE = (1<<4); //16 // geometrisch -const int Interactor3D::CHANGENOTNECESSARY = (1<<5); //32 - - +const int Interactor3D::SOLID = (1 << 0); // 1 +const int Interactor3D::INVERSESOLID = (1 << 1); // 2 +const int Interactor3D::TIMEDEPENDENT = (1 << 2); // 4 //zeitlich +const int Interactor3D::FLUID = (1 << 3); // 8 +const int Interactor3D::MOVEABLE = (1 << 4); // 16 // geometrisch +const int Interactor3D::CHANGENOTNECESSARY = (1 << 5); // 32 ////////////////////////////////////////////////////////////////////////// -Interactor3D::Interactor3D() - : type(SOLID) -{ - -} +Interactor3D::Interactor3D() : type(SOLID) {} ////////////////////////////////////////////////////////////////////////// -Interactor3D::Interactor3D(SPtr<Grid3D> grid, int type) - : grid(grid), type(type) -{ - -} +Interactor3D::Interactor3D(SPtr<Grid3D> grid, int type) : grid(grid), type(type) {} ////////////////////////////////////////////////////////////////////////// Interactor3D::Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type) - : geoObject3D(geoObject3D) - , grid(grid) - , type(type) - , accuracy(SIMPLE) + : geoObject3D(geoObject3D), grid(grid), type(type), accuracy(SIMPLE) { - } ////////////////////////////////////////////////////////////////////////// Interactor3D::Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type, Interactor3D::Accuracy a) - : geoObject3D(geoObject3D) - , grid(grid) - , type(type) - , accuracy(a) + : geoObject3D(geoObject3D), grid(grid), type(type), accuracy(a) { - } ////////////////////////////////////////////////////////////////////////// -Interactor3D::~Interactor3D() -= default; +Interactor3D::~Interactor3D() = default; ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::arePointsInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::arePointsInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - bool result = true; - for (double ix3=minX3; ix3<=maxX3; ix3+=delta) - for (double ix2=minX2; ix2<=maxX2; ix2+=delta) - for (double ix1=minX1; ix1<=maxX1; ix1+=delta) - result = result && this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3); + bool result = true; + for (double ix3 = minX3; ix3 <= maxX3; ix3 += delta) + for (double ix2 = minX2; ix2 <= maxX2; ix2 += delta) + for (double ix1 = minX1; ix1 <= maxX1; ix1 += delta) + result = result && this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3); - return result; + return result; } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::arePointsOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::arePointsOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - bool result = true; - for (double ix3=minX3; ix3<=maxX3; ix3+=delta) - for (double ix2=minX2; ix2<=maxX2; ix2+=delta) - for (double ix1=minX1; ix1<=maxX1; ix1+=delta) - result = result && (!this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3)); + bool result = true; + for (double ix3 = minX3; ix3 <= maxX3; ix3 += delta) + for (double ix2 = minX2; ix2 <= maxX2; ix2 += delta) + for (double ix1 = minX1; ix1 <= maxX1; ix1 += delta) + result = result && (!this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3)); - return result; + return result; } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::arePointsCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::arePointsCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - bool result = true; - for (double ix3=minX3; ix3<=maxX3; ix3+=delta) - for (double ix2=minX2; ix2<=maxX2; ix2+=delta) - for (double ix1=minX1; ix1<=maxX1; ix1+=delta) - result = result || this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3); + bool result = true; + for (double ix3 = minX3; ix3 <= maxX3; ix3 += delta) + for (double ix2 = minX2; ix2 <= maxX2; ix2 += delta) + for (double ix1 = minX1; ix1 <= maxX1; ix1 += delta) + result = result || this->geoObject3D->isPointInGbObject3D(ix1, ix2, ix3); - return result; + return result; } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::isBlockOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::isBlockOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - switch (accuracy) - { - //simple duff - case SIMPLE: - return !this->geoObject3D->isCellInsideOrCuttingGbObject3D(minX1,minX2,minX3,maxX1,maxX2,maxX3); - //test only edges - case EDGES: - return arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) && - arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && - arePointsOutsideGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) && - - arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) && - arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && - arePointsOutsideGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) && - - arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && - arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) && - arePointsOutsideGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); - //test only faces - case FACES: - return arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && - arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) && - arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); - //test all points - case POINTS: - return arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); - default: - UB_THROW( UbException(UB_EXARGS, "Accuracy isn't correct") ); - break; - } + switch (accuracy) { + // simple duff + case SIMPLE: + return !this->geoObject3D->isCellInsideOrCuttingGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3); + // test only edges + case EDGES: + return arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) && + arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && + arePointsOutsideGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) && + + arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) && + arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && + arePointsOutsideGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) && + + arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && + arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) && + arePointsOutsideGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); + // test only faces + case FACES: + return arePointsOutsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && + arePointsOutsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) && + arePointsOutsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsOutsideGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); + // test all points + case POINTS: + return arePointsOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); + default: + UB_THROW(UbException(UB_EXARGS, "Accuracy isn't correct")); + break; + } } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::isBlockInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::isBlockInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - switch (accuracy) - { - //simple duff - case SIMPLE: - return this->geoObject3D->isCellInsideGbObject3D(minX1,minX2,minX3,maxX1,maxX2,maxX3); - //test only edges - case EDGES: - return arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) && - arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && - arePointsInsideGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) && - - arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) && - arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && - arePointsInsideGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) && - - arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && - arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) && - arePointsInsideGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); - //test only faces - case FACES: - return arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && - arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) && - arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) && - arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) && - arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); - //test all points - case POINTS: - return arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); - default: - UB_THROW( UbException(UB_EXARGS, "Accuracy isn't correct") ); - break; - } + switch (accuracy) { + // simple duff + case SIMPLE: + return this->geoObject3D->isCellInsideGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3); + // test only edges + case EDGES: + return arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) && + arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && + arePointsInsideGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) && + + arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) && + arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) && + arePointsInsideGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) && + + arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && + arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) && + arePointsInsideGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); + // test only faces + case FACES: + return arePointsInsideGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) && + arePointsInsideGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) && + arePointsInsideGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) && + arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) && + arePointsInsideGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); + // test all points + case POINTS: + return arePointsInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); + default: + UB_THROW(UbException(UB_EXARGS, "Accuracy isn't correct")); + break; + } } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::isBlockCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta) +bool Interactor3D::isBlockCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, + double maxX3, double delta) { - switch (accuracy) - { - //simple duff - case SIMPLE: - return this->geoObject3D->isCellCuttingGbObject3D(minX1,minX2,minX3,maxX1,maxX2,maxX3); - //test only edges - case EDGES: - return arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) || - arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) || - arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) || - arePointsCuttingGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) || - - arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) || - arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) || - arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) || - arePointsCuttingGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) || - - arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) || - arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) || - arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) || - arePointsCuttingGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); - //test only faceCutting - case FACES: - return arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) || - arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) || - arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) || - arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) || - arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) || - arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); - //test all pointCutting - case POINTS: - return arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); - default: - UB_THROW( UbException(UB_EXARGS, "Accuracy isn't correct") ); - break; - } + switch (accuracy) { + // simple duff + case SIMPLE: + return this->geoObject3D->isCellCuttingGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3); + // test only edges + case EDGES: + return arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, minX2, minX3, delta) || + arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, maxX2, minX3, delta) || + arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) || + arePointsCuttingGeoObject(minX1, maxX2, maxX3, maxX1, maxX2, maxX3, delta) || + + arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, minX3, delta) || + arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, minX3, delta) || + arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, minX2, maxX3, delta) || + arePointsCuttingGeoObject(maxX1, minX2, maxX3, maxX1, maxX2, maxX3, delta) || + + arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) || + arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) || + arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, minX2, maxX3, delta) || + arePointsCuttingGeoObject(maxX1, maxX2, minX3, maxX1, maxX2, maxX3, delta); + // test only faceCutting + case FACES: + return arePointsCuttingGeoObject(minX1, minX2, minX3, minX1, maxX2, maxX3, delta) || + arePointsCuttingGeoObject(maxX1, minX2, minX3, maxX1, maxX2, maxX3, delta) || + arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, minX2, maxX3, delta) || + arePointsCuttingGeoObject(minX1, maxX2, minX3, maxX1, maxX2, maxX3, delta) || + arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, minX3, delta) || + arePointsCuttingGeoObject(minX1, minX2, maxX3, maxX1, maxX2, maxX3, delta); + // test all pointCutting + case POINTS: + return arePointsCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, delta); + default: + UB_THROW(UbException(UB_EXARGS, "Accuracy isn't correct")); + break; + } } ////////////////////////////////////////////////////////////////////////// void Interactor3D::setSolidBlock(SPtr<Block3D> block) { - double minX1,minX2,minX3,maxX1,maxX2,maxX3; + double minX1, minX2, minX3, maxX1, maxX2, maxX3; - double deltaX = grid.lock()->getDeltaX(block); - UbTupleDouble3 blockLengths = grid.lock()->getBlockLengths(block); - UbTupleDouble3 org = grid.lock()->getBlockWorldCoordinates(block); - UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); + double deltaX = grid.lock()->getDeltaX(block); + UbTupleDouble3 blockLengths = grid.lock()->getBlockLengths(block); + UbTupleDouble3 org = grid.lock()->getBlockWorldCoordinates(block); + UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); - //coordinates of block without ghost layer - minX1 = val<1>(org) + val<1>(nodeOffset); - minX2 = val<2>(org) + val<2>(nodeOffset); - minX3 = val<3>(org) + val<3>(nodeOffset); - maxX1 = val<1>(org) + val<1>(blockLengths) - val<1>(nodeOffset); - maxX2 = val<2>(org) + val<2>(blockLengths) - val<2>(nodeOffset); - maxX3 = val<3>(org) + val<3>(blockLengths) - val<3>(nodeOffset); + // coordinates of block without ghost layer + minX1 = val<1>(org) + val<1>(nodeOffset); + minX2 = val<2>(org) + val<2>(nodeOffset); + minX3 = val<3>(org) + val<3>(nodeOffset); + maxX1 = val<1>(org) + val<1>(blockLengths) - val<1>(nodeOffset); + maxX2 = val<2>(org) + val<2>(blockLengths) - val<2>(nodeOffset); + maxX3 = val<3>(org) + val<3>(blockLengths) - val<3>(nodeOffset); - if(this->isInverseSolid()) - { - if(isBlockOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) - { - block->setActive(false); - this->solidBlocks.push_back(block); - } - } - else //solid - { - if(isBlockInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) - { - block->setActive(false); - this->solidBlocks.push_back(block); - } - } + if (this->isInverseSolid()) { + if (isBlockOutsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) { + block->setActive(false); + this->solidBlocks.push_back(block); + } + } else // solid + { + if (isBlockInsideGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) { + block->setActive(false); + this->solidBlocks.push_back(block); + } + } } ////////////////////////////////////////////////////////////////////////// void Interactor3D::setBCBlock(SPtr<Block3D> block) { - double minX1,minX2,minX3,maxX1,maxX2,maxX3; + double minX1, minX2, minX3, maxX1, maxX2, maxX3; - double deltaX = grid.lock()->getDeltaX(block); - UbTupleDouble3 blockLengths = grid.lock()->getBlockLengths(block); - UbTupleDouble3 org = grid.lock()->getBlockWorldCoordinates(block); - UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); + double deltaX = grid.lock()->getDeltaX(block); + UbTupleDouble3 blockLengths = grid.lock()->getBlockLengths(block); + UbTupleDouble3 org = grid.lock()->getBlockWorldCoordinates(block); + UbTupleDouble3 nodeOffset = grid.lock()->getNodeOffset(block); - //coordinates of block with ghost layer - minX1 = val<1>(org) - val<1>(nodeOffset); - minX2 = val<2>(org) - val<2>(nodeOffset); - minX3 = val<3>(org) - val<3>(nodeOffset); - maxX1 = val<1>(org) + val<1>(blockLengths) + val<1>(nodeOffset); - maxX2 = val<2>(org) + val<2>(blockLengths) + val<2>(nodeOffset); - maxX3 = val<3>(org) + val<3>(blockLengths) + val<3>(nodeOffset); + // coordinates of block with ghost layer + minX1 = val<1>(org) - val<1>(nodeOffset); + minX2 = val<2>(org) - val<2>(nodeOffset); + minX3 = val<3>(org) - val<3>(nodeOffset); + maxX1 = val<1>(org) + val<1>(blockLengths) + val<1>(nodeOffset); + maxX2 = val<2>(org) + val<2>(blockLengths) + val<2>(nodeOffset); + maxX3 = val<3>(org) + val<3>(blockLengths) + val<3>(nodeOffset); - if(isBlockCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) - this->bcBlocks.push_back(block); + if (isBlockCuttingGeoObject(minX1, minX2, minX3, maxX1, maxX2, maxX3, deltaX)) + this->bcBlocks.push_back(block); } UbTupleDouble3 Interactor3D::getForces() { - UB_THROW( UbException("UbTupleDouble3 getForces() - gehoert in die abgeleitete klasse") ); -} -void Interactor3D::setID(int id) -{ - this->id = id; + UB_THROW(UbException("UbTupleDouble3 getForces() - gehoert in die abgeleitete klasse")); } +void Interactor3D::setID(int id) { this->id = id; } ////////////////////////////////////////////////////////////////////////// -int Interactor3D::getID() -{ - return id; -} +int Interactor3D::getID() { return id; } ////////////////////////////////////////////////////////////////////////// -void Interactor3D::setActive() -{ - active = true; -} +void Interactor3D::setActive() { active = true; } ////////////////////////////////////////////////////////////////////////// -void Interactor3D::setInactive() -{ - active = false; -} +void Interactor3D::setInactive() { active = false; } ////////////////////////////////////////////////////////////////////////// -bool Interactor3D::isActive() -{ - return active; -} +bool Interactor3D::isActive() { return active; } ////////////////////////////////////////////////////////////////////////// -void Interactor3D::initInteractor(const double& /*timeStep*/) +void Interactor3D::initInteractor(const double & /*timeStep*/) { - //UBLOG(logINFO, "transBlocks.size = "<<transBlocks.size()); + // UBLOG(logINFO, "transBlocks.size = "<<transBlocks.size()); - for(SPtr<Block3D> block : bcBlocks) - { - this->setDifferencesToGbObject3D(block); - } + for (SPtr<Block3D> block : bcBlocks) { + this->setDifferencesToGbObject3D(block); + } } ////////////////////////////////////////////////////////////////////////// -void Interactor3D::updateInteractor(const double& /*timeStep*/) +void Interactor3D::updateInteractor(const double & /*timeStep*/) { - UB_THROW( UbException("Interactor3D::updateInteractor - toDo") ); + UB_THROW(UbException("Interactor3D::updateInteractor - toDo")); } ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.h b/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.h index ef7ac33db..9bf3a03ba 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.h +++ b/src/cpu/VirtualFluidsCore/Interactors/Interactor3D.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,8 +34,8 @@ #ifndef INTERACTOR3D_H #define INTERACTOR3D_H -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "UbSystem.h" #include "UbTuple.h" @@ -48,99 +48,101 @@ class GbObject3D; class Interactor3D : public enableSharedFromThis<Interactor3D> { public: - enum Accuracy{SIMPLE, EDGES, FACES, POINTS}; - Interactor3D(); - Interactor3D(SPtr<Grid3D> grid, int type=Interactor3D::SOLID); - Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); - //! constructor - //! \param a set accuracy for arePointsInObject() and arePointsNotInObject() - Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type, Interactor3D::Accuracy a); - - virtual ~Interactor3D(); - virtual void initInteractor(const double& timestep=0); - virtual void updateInteractor(const double& timestep=0)=0; - - void setSolidBlock(SPtr<Block3D> block); - void setBCBlock(SPtr<Block3D> block); + enum Accuracy { SIMPLE, EDGES, FACES, POINTS }; + Interactor3D(); + Interactor3D(SPtr<Grid3D> grid, int type = Interactor3D::SOLID); + Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type); + //! constructor + //! \param a set accuracy for arePointsInObject() and arePointsNotInObject() + Interactor3D(SPtr<GbObject3D> geoObject3D, SPtr<Grid3D> grid, int type, Interactor3D::Accuracy a); + + virtual ~Interactor3D(); + virtual void initInteractor(const double ×tep = 0); + virtual void updateInteractor(const double ×tep = 0) = 0; + + void setSolidBlock(SPtr<Block3D> block); + void setBCBlock(SPtr<Block3D> block); virtual UbTupleDouble3 getForces(); - void setSolid() { UbSystem::setBit(this->type, SOLID ); } - void setMoveable() { UbSystem::setBit(this->type, MOVEABLE); } - - bool isSolid() { return UbSystem::bitCheck(this->type, SOLID ); } - bool isInverseSolid() { return UbSystem::bitCheck(this->type, INVERSESOLID ); } - bool isTimeDependent() { return UbSystem::bitCheck(this->type, TIMEDEPENDENT); } - bool isMoveable() { return UbSystem::bitCheck(this->type, MOVEABLE ); } - - SPtr<Grid3D> getGrid3D() const { return grid.lock(); } - void setGrid3D(SPtr<Grid3D> grid) { this->grid = grid; } - virtual SPtr<GbObject3D> getGbObject3D() const { return geoObject3D; } - virtual bool setDifferencesToGbObject3D(const SPtr<Block3D> /*block*//*, const double& x1, const double& x2, const double& x3, const double& blockLengthX1, const double& blockLengthX2, const double& blockLengthX3, const double& timestep=0*/) - { - //UBLOG(logINFO, "Interactor3D::setDifferencesToGbObject3D()"); - return false; - } - - virtual std::vector<SPtr<Block3D> >& getBcBlocks() { return this->bcBlocks; } - virtual void removeBcBlocks() { this->bcBlocks.clear(); } - virtual std::vector<SPtr<Block3D> >& getSolidBlockSet() { return this->solidBlocks; } - virtual void removeSolidBlocks() { this->solidBlocks.clear(); } - - void setID(int id); - int getID(); - - void setActive(); - void setInactive(); - bool isActive(); + void setSolid() { UbSystem::setBit(this->type, SOLID); } + void setMoveable() { UbSystem::setBit(this->type, MOVEABLE); } + + bool isSolid() { return UbSystem::bitCheck(this->type, SOLID); } + bool isInverseSolid() { return UbSystem::bitCheck(this->type, INVERSESOLID); } + bool isTimeDependent() { return UbSystem::bitCheck(this->type, TIMEDEPENDENT); } + bool isMoveable() { return UbSystem::bitCheck(this->type, MOVEABLE); } + + SPtr<Grid3D> getGrid3D() const { return grid.lock(); } + void setGrid3D(SPtr<Grid3D> grid) { this->grid = grid; } + virtual SPtr<GbObject3D> getGbObject3D() const { return geoObject3D; } + virtual bool setDifferencesToGbObject3D(const SPtr<Block3D> /*block*//*, const double& x1, const double& x2, const double& x3, const double& blockLengthX1, const double& blockLengthX2, const double& blockLengthX3, const double& timestep=0*/) + { + // UBLOG(logINFO, "Interactor3D::setDifferencesToGbObject3D()"); + return false; + } + + virtual std::vector<SPtr<Block3D>> &getBcBlocks() { return this->bcBlocks; } + virtual void removeBcBlocks() { this->bcBlocks.clear(); } + virtual std::vector<SPtr<Block3D>> &getSolidBlockSet() { return this->solidBlocks; } + virtual void removeSolidBlocks() { this->solidBlocks.clear(); } + + void setID(int id); + int getID(); + + void setActive(); + void setInactive(); + bool isActive(); protected: - void setTimeDependent() { UbSystem::setBit(this->type , TIMEDEPENDENT); } - void unsetTimeDependent() { UbSystem::unsetBit(this->type, TIMEDEPENDENT); } - - //! detect that points are inside object - //! \param min/max coordinates of bounding box - //! \param delta is delta x - bool arePointsInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - - //! detect that points aren't inside object - //! \param min/max coordinates of bounding box - //! \param delta is delta x - bool arePointsOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - - //! detect that points are cutting object - //! \param min/max coordinates of bounding box - //! \param delta is delta x - bool arePointsCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - - bool isBlockOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - bool isBlockInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - bool isBlockCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, double delta); - - - SPtr<GbObject3D> geoObject3D; + void setTimeDependent() { UbSystem::setBit(this->type, TIMEDEPENDENT); } + void unsetTimeDependent() { UbSystem::unsetBit(this->type, TIMEDEPENDENT); } + + //! detect that points are inside object + //! \param min/max coordinates of bounding box + //! \param delta is delta x + bool arePointsInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + + //! detect that points aren't inside object + //! \param min/max coordinates of bounding box + //! \param delta is delta x + bool arePointsOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + + //! detect that points are cutting object + //! \param min/max coordinates of bounding box + //! \param delta is delta x + bool arePointsCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + + bool isBlockOutsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + bool isBlockInsideGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + bool isBlockCuttingGeoObject(double minX1, double minX2, double minX3, double maxX1, double maxX2, double maxX3, + double delta); + + SPtr<GbObject3D> geoObject3D; WPtr<Grid3D> grid; int type; - std::vector<SPtr<Block3D> > bcBlocks; - std::vector<SPtr<Block3D> > solidBlocks; - int accuracy; - - bool active; - int id; + std::vector<SPtr<Block3D>> bcBlocks; + std::vector<SPtr<Block3D>> solidBlocks; + int accuracy; + + bool active; + int id; public: - static const int SOLID ;//= (1<<0); //1 - static const int INVERSESOLID ;//= (1<<1); //2 - static const int TIMEDEPENDENT ;//= (1<<2); //4 //zeitlich - static const int FLUID ;//= (1<<3); //8 - static const int MOVEABLE ;//= (1<<4); //16 // geometrisch - static const int CHANGENOTNECESSARY ;//= (1<<5); //32 + static const int SOLID; //= (1<<0); //1 + static const int INVERSESOLID; //= (1<<1); //2 + static const int TIMEDEPENDENT; //= (1<<2); //4 //zeitlich + static const int FLUID; //= (1<<3); //8 + static const int MOVEABLE; //= (1<<4); //16 // geometrisch + static const int CHANGENOTNECESSARY; //= (1<<5); //32 private: - }; - - #endif diff --git a/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.cpp b/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.cpp index 29ccab6ba..d8ee65934 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.cpp +++ b/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,73 +33,62 @@ #include "InteractorsHelper.h" -#include <Grid3DVisitor.h> -#include <Grid3D.h> -#include <Interactor3D.h> #include "Block3D.h" #include "Communicator.h" -#include "SetSolidBlocksBlockVisitor.h" #include "SetBcBlocksBlockVisitor.h" +#include "SetSolidBlocksBlockVisitor.h" +#include <Grid3D.h> +#include <Grid3DVisitor.h> +#include <Interactor3D.h> - -InteractorsHelper::InteractorsHelper(SPtr<Grid3D> grid, SPtr<Grid3DVisitor> visitor, bool deleteBlocks) : - grid(grid), visitor(visitor), deleteBlocks(deleteBlocks) +InteractorsHelper::InteractorsHelper(SPtr<Grid3D> grid, SPtr<Grid3DVisitor> visitor, bool deleteBlocks) + : grid(grid), visitor(visitor), deleteBlocks(deleteBlocks) { - } ////////////////////////////////////////////////////////////////////////// -InteractorsHelper::~InteractorsHelper() -= default; +InteractorsHelper::~InteractorsHelper() = default; ////////////////////////////////////////////////////////////////////////// -void InteractorsHelper::addInteractor( SPtr<Interactor3D> interactor ) -{ - interactors.push_back(interactor); -} +void InteractorsHelper::addInteractor(SPtr<Interactor3D> interactor) { interactors.push_back(interactor); } ////////////////////////////////////////////////////////////////////////// void InteractorsHelper::setBC() { - for(SPtr<Interactor3D> i : interactors) + for (SPtr<Interactor3D> i : interactors) i->initInteractor(); } -void InteractorsHelper::sendDomainDecompositionVisitor() const -{ - grid->accept( visitor ); -} +void InteractorsHelper::sendDomainDecompositionVisitor() const { grid->accept(visitor); } ////////////////////////////////////////////////////////////////////////// void InteractorsHelper::selectBlocks() { - sendDomainDecompositionVisitor(); - deleteSolidBlocks(); + sendDomainDecompositionVisitor(); + deleteSolidBlocks(); - sendDomainDecompositionVisitor(); - setBcBlocks(); + sendDomainDecompositionVisitor(); + setBcBlocks(); } ////////////////////////////////////////////////////////////////////////// void InteractorsHelper::deleteSolidBlocks() { - for(SPtr<Interactor3D> interactor : interactors) - { + for (SPtr<Interactor3D> interactor : interactors) { SetSolidBlocksBlockVisitor v(interactor); grid->accept(v); - if (deleteBlocks) - { - std::vector<SPtr<Block3D>>& sb = interactor->getSolidBlockSet(); - solidBlocks.insert(solidBlocks.end(), sb.begin(), sb.end()); - interactor->removeSolidBlocks(); + if (deleteBlocks) { + std::vector<SPtr<Block3D>> &sb = interactor->getSolidBlockSet(); + solidBlocks.insert(solidBlocks.end(), sb.begin(), sb.end()); + interactor->removeSolidBlocks(); } } - if (deleteBlocks) updateGrid(); + if (deleteBlocks) + updateGrid(); } ////////////////////////////////////////////////////////////////////////// void InteractorsHelper::setBcBlocks() { - for(const auto& interactor : interactors) - { - SetBcBlocksBlockVisitor v(interactor); - grid->accept(v); + for (const auto &interactor : interactors) { + SetBcBlocksBlockVisitor v(interactor); + grid->accept(v); } } ////////////////////////////////////////////////////////////////////////// @@ -107,11 +96,10 @@ void InteractorsHelper::updateGrid() { std::vector<int> ids; - for(const auto& block : solidBlocks) + for (const auto &block : solidBlocks) ids.push_back(block->getGlobalID()); std::vector<int> rids; Communicator::getInstance()->allGather(ids, rids); grid->deleteBlocks(rids); } - diff --git a/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.h b/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.h index 3d6d30f0c..2eb554905 100644 --- a/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.h +++ b/src/cpu/VirtualFluidsCore/Interactors/InteractorsHelper.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -31,12 +31,11 @@ //! \author Konstantin Kutscher //======================================================================================= -#ifndef InteractorsHelper_h +#ifndef InteractorsHelper_h #define InteractorsHelper_h -#include <vector> #include <PointerDefinitions.h> - +#include <vector> class Interactor3D; class Block3D; @@ -47,26 +46,26 @@ class Grid3DVisitor; class InteractorsHelper { public: - InteractorsHelper(SPtr<Grid3D> grid, SPtr<Grid3DVisitor> visitor, bool deleteBlocks=true); - ~InteractorsHelper(); + InteractorsHelper(SPtr<Grid3D> grid, SPtr<Grid3DVisitor> visitor, bool deleteBlocks = true); + ~InteractorsHelper(); - void addInteractor(SPtr<Interactor3D> interactor); - void selectBlocks(); - void setBC(); - void sendDomainDecompositionVisitor() const; + void addInteractor(SPtr<Interactor3D> interactor); + void selectBlocks(); + void setBC(); + void sendDomainDecompositionVisitor() const; protected: - void deleteSolidBlocks(); - void setBcBlocks(); + void deleteSolidBlocks(); + void setBcBlocks(); private: - void updateGrid(); + void updateGrid(); - std::vector<SPtr<Interactor3D> > interactors; - SPtr<Grid3D> grid; - std::vector<SPtr<Block3D> > solidBlocks; - SPtr<Grid3DVisitor> visitor; - bool deleteBlocks; + std::vector<SPtr<Interactor3D>> interactors; + SPtr<Grid3D> grid; + std::vector<SPtr<Block3D>> solidBlocks; + SPtr<Grid3DVisitor> visitor; + bool deleteBlocks; }; #endif diff --git a/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.cpp b/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.cpp index b2f5cd60f..365373c09 100644 --- a/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.cpp @@ -1,298 +1,295 @@ #include "BGKLBMKernel.h" -#include "D3Q27System.h" -#include "D3Q27EsoTwist3DSplittedVector.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "D3Q27EsoTwist3DSoA.h" +#include "D3Q27EsoTwist3DSplittedVector.h" +#include "D3Q27System.h" #include "DataSet3D.h" -#include "BCProcessor.h" -#include "BCArray3D.h" //#define PROOF_CORRECTNESS ////////////////////////////////////////////////////////////////////////// -BGKLBMKernel::BGKLBMKernel() -{ - this->compressible = false; -} +BGKLBMKernel::BGKLBMKernel() { this->compressible = false; } ////////////////////////////////////////////////////////////////////////// -BGKLBMKernel::~BGKLBMKernel(void) -= default; +BGKLBMKernel::~BGKLBMKernel(void) = default; ////////////////////////////////////////////////////////////////////////// void BGKLBMKernel::initDataSet() { - SPtr<DistributionArray3D> d(new D3Q27EsoTwist3DSplittedVector(nx[0]+2, nx[1]+2, nx[2]+2, -999.9)); - dataSet->setFdistributions(d); + SPtr<DistributionArray3D> d(new D3Q27EsoTwist3DSplittedVector(nx[0] + 2, nx[1] + 2, nx[2] + 2, -999.9)); + dataSet->setFdistributions(d); } ////////////////////////////////////////////////////////////////////////// SPtr<LBMKernel> BGKLBMKernel::clone() { - SPtr<LBMKernel> kernel(new BGKLBMKernel()); - std::dynamic_pointer_cast<BGKLBMKernel>(kernel)->initDataSet(); - kernel->setCollisionFactor(this->collFactor); - kernel->setBCProcessor(bcProcessor->clone(kernel)); - kernel->setWithForcing(withForcing); - kernel->setForcingX1(muForcingX1); - kernel->setForcingX2(muForcingX2); - kernel->setForcingX3(muForcingX3); - kernel->setIndex(ix1, ix2, ix3); - return kernel; + SPtr<LBMKernel> kernel(new BGKLBMKernel()); + std::dynamic_pointer_cast<BGKLBMKernel>(kernel)->initDataSet(); + kernel->setCollisionFactor(this->collFactor); + kernel->setBCProcessor(bcProcessor->clone(kernel)); + kernel->setWithForcing(withForcing); + kernel->setForcingX1(muForcingX1); + kernel->setForcingX2(muForcingX2); + kernel->setForcingX3(muForcingX3); + kernel->setIndex(ix1, ix2, ix3); + return kernel; } ////////////////////////////////////////////////////////////////////////// -void BGKLBMKernel::calculate(int /*step*/) +void BGKLBMKernel::calculate(int /*step*/) { - using namespace D3Q27System; - using namespace UbMath; + using namespace D3Q27System; + using namespace UbMath; - //initializing of forcing stuff - if (withForcing) - { - muForcingX1.DefineVar("x1",&muX1); muForcingX1.DefineVar("x2",&muX2); muForcingX1.DefineVar("x3",&muX3); - muForcingX2.DefineVar("x1",&muX1); muForcingX2.DefineVar("x2",&muX2); muForcingX2.DefineVar("x3",&muX3); - muForcingX3.DefineVar("x1",&muX1); muForcingX3.DefineVar("x2",&muX2); muForcingX3.DefineVar("x3",&muX3); - forcingX1 = 0; - forcingX2 = 0; - forcingX3 = 0; - } - ///////////////////////////////////// + // initializing of forcing stuff + if (withForcing) { + muForcingX1.DefineVar("x1", &muX1); + muForcingX1.DefineVar("x2", &muX2); + muForcingX1.DefineVar("x3", &muX3); + muForcingX2.DefineVar("x1", &muX1); + muForcingX2.DefineVar("x2", &muX2); + muForcingX2.DefineVar("x3", &muX3); + muForcingX3.DefineVar("x1", &muX1); + muForcingX3.DefineVar("x2", &muX2); + muForcingX3.DefineVar("x3", &muX3); + forcingX1 = 0; + forcingX2 = 0; + forcingX3 = 0; + } + ///////////////////////////////////// - localDistributions = std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions())->getLocalDistributions(); - nonLocalDistributions = std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions())->getNonLocalDistributions(); - zeroDistributions = std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions())->getZeroDistributions(); + localDistributions = + std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions())->getLocalDistributions(); + nonLocalDistributions = std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions()) + ->getNonLocalDistributions(); + zeroDistributions = + std::dynamic_pointer_cast<D3Q27EsoTwist3DSplittedVector>(dataSet->getFdistributions())->getZeroDistributions(); - SPtr<BCArray3D> bcArray = this->getBCProcessor()->getBCArray(); - LBMReal f[D3Q27System::ENDF+1]; - LBMReal feq[D3Q27System::ENDF+1]; - LBMReal drho,vx1,vx2,vx3; - const int bcArrayMaxX1 = (int)bcArray->getNX1(); - const int bcArrayMaxX2 = (int)bcArray->getNX2(); - const int bcArrayMaxX3 = (int)bcArray->getNX3(); + SPtr<BCArray3D> bcArray = this->getBCProcessor()->getBCArray(); + LBMReal f[D3Q27System::ENDF + 1]; + LBMReal feq[D3Q27System::ENDF + 1]; + LBMReal drho, vx1, vx2, vx3; + const int bcArrayMaxX1 = (int)bcArray->getNX1(); + const int bcArrayMaxX2 = (int)bcArray->getNX2(); + const int bcArrayMaxX3 = (int)bcArray->getNX3(); - int minX1 = ghostLayerWidth; - int minX2 = ghostLayerWidth; - int minX3 = ghostLayerWidth; - int maxX1 = bcArrayMaxX1-ghostLayerWidth; - int maxX2 = bcArrayMaxX2-ghostLayerWidth; - int maxX3 = bcArrayMaxX3-ghostLayerWidth; + int minX1 = ghostLayerWidth; + int minX2 = ghostLayerWidth; + int minX3 = ghostLayerWidth; + int maxX1 = bcArrayMaxX1 - ghostLayerWidth; + int maxX2 = bcArrayMaxX2 - ghostLayerWidth; + int maxX3 = bcArrayMaxX3 - ghostLayerWidth; - for(int x3 = minX3; x3 < maxX3; x3++) - { - for(int x2 = minX2; x2 < maxX2; x2++) - { - for(int x1 = minX1; x1 < maxX1; x1++) - { - if(!bcArray->isSolid(x1,x2,x3) && !bcArray->isUndefined(x1,x2,x3)) - { - int x1p = x1 + 1; - int x2p = x2 + 1; - int x3p = x3 + 1; - ////////////////////////////////////////////////////////////////////////// - //read distribution - //////////////////////////////////////////////////////////////////////////// - f[ZERO] = (*this->zeroDistributions)(x1,x2,x3); + for (int x3 = minX3; x3 < maxX3; x3++) { + for (int x2 = minX2; x2 < maxX2; x2++) { + for (int x1 = minX1; x1 < maxX1; x1++) { + if (!bcArray->isSolid(x1, x2, x3) && !bcArray->isUndefined(x1, x2, x3)) { + int x1p = x1 + 1; + int x2p = x2 + 1; + int x3p = x3 + 1; + ////////////////////////////////////////////////////////////////////////// + // read distribution + //////////////////////////////////////////////////////////////////////////// + f[ZERO] = (*this->zeroDistributions)(x1, x2, x3); - f[E] = (*this->localDistributions)(D3Q27System::ET_E, x1,x2,x3); - f[N] = (*this->localDistributions)(D3Q27System::ET_N,x1,x2,x3); - f[T] = (*this->localDistributions)(D3Q27System::ET_T,x1,x2,x3); - f[NE] = (*this->localDistributions)(D3Q27System::ET_NE,x1,x2,x3); - f[NW] = (*this->localDistributions)(D3Q27System::ET_NW,x1p,x2,x3); - f[TE] = (*this->localDistributions)(D3Q27System::ET_TE,x1,x2,x3); - f[TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1p,x2,x3); - f[TN] = (*this->localDistributions)(D3Q27System::ET_TN,x1,x2,x3); - f[TS] = (*this->localDistributions)(D3Q27System::ET_TS,x1,x2p,x3); - f[TNE] = (*this->localDistributions)(D3Q27System::ET_TNE,x1,x2,x3); - f[TNW] = (*this->localDistributions)(D3Q27System::ET_TNW,x1p,x2,x3); - f[TSE] = (*this->localDistributions)(D3Q27System::ET_TSE,x1,x2p,x3); - f[TSW] = (*this->localDistributions)(D3Q27System::ET_TSW,x1p,x2p,x3); + f[E] = (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3); + f[N] = (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3); + f[T] = (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3); + f[NE] = (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3); + f[NW] = (*this->localDistributions)(D3Q27System::ET_NW, x1p, x2, x3); + f[TE] = (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3); + f[TW] = (*this->localDistributions)(D3Q27System::ET_TW, x1p, x2, x3); + f[TN] = (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3); + f[TS] = (*this->localDistributions)(D3Q27System::ET_TS, x1, x2p, x3); + f[TNE] = (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3); + f[TNW] = (*this->localDistributions)(D3Q27System::ET_TNW, x1p, x2, x3); + f[TSE] = (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2p, x3); + f[TSW] = (*this->localDistributions)(D3Q27System::ET_TSW, x1p, x2p, x3); - f[W ] = (*this->nonLocalDistributions)(D3Q27System::ET_W,x1p,x2,x3 ); - f[S ] = (*this->nonLocalDistributions)(D3Q27System::ET_S,x1,x2p,x3 ); - f[B ] = (*this->nonLocalDistributions)(D3Q27System::ET_B,x1,x2,x3p ); - f[SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1p,x2p,x3 ); - f[SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1,x2p,x3 ); - f[BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1p,x2,x3p ); - f[BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1,x2,x3p ); - f[BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1,x2p,x3p ); - f[BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1,x2,x3p ); - f[BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1p,x2p,x3p); - f[BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1,x2p,x3p); - f[BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1p,x2,x3p); - f[BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1,x2,x3p); - ////////////////////////////////////////////////////////////////////////// + f[W] = (*this->nonLocalDistributions)(D3Q27System::ET_W, x1p, x2, x3); + f[S] = (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2p, x3); + f[B] = (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3p); + f[SW] = (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1p, x2p, x3); + f[SE] = (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2p, x3); + f[BW] = (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1p, x2, x3p); + f[BE] = (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3p); + f[BS] = (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2p, x3p); + f[BN] = (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3p); + f[BSW] = (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1p, x2p, x3p); + f[BSE] = (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2p, x3p); + f[BNW] = (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1p, x2, x3p); + f[BNE] = (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3p); + ////////////////////////////////////////////////////////////////////////// - drho = f[ZERO] + f[E] + f[W] + f[N] + f[S] + f[T] + f[B] - + f[NE] + f[SW] + f[SE] + f[NW] + f[TE] + f[BW] + f[BE] - + f[TW] + f[TN] + f[BS] + f[BN] + f[TS] + f[TNE] + f[TSW] - + f[TSE] + f[TNW] + f[BNE] + f[BSW] + f[BSE] + f[BNW]; + drho = f[ZERO] + f[E] + f[W] + f[N] + f[S] + f[T] + f[B] + f[NE] + f[SW] + f[SE] + f[NW] + f[TE] + + f[BW] + f[BE] + f[TW] + f[TN] + f[BS] + f[BN] + f[TS] + f[TNE] + f[TSW] + f[TSE] + f[TNW] + + f[BNE] + f[BSW] + f[BSE] + f[BNW]; - vx1 = f[E] - f[W] + f[NE] - f[SW] + f[SE] - f[NW] + f[TE] - f[BW] - + f[BE] - f[TW] + f[TNE] - f[TSW] + f[TSE] - f[TNW] + f[BNE] - f[BSW] - + f[BSE] - f[BNW]; + vx1 = f[E] - f[W] + f[NE] - f[SW] + f[SE] - f[NW] + f[TE] - f[BW] + f[BE] - f[TW] + f[TNE] - + f[TSW] + f[TSE] - f[TNW] + f[BNE] - f[BSW] + f[BSE] - f[BNW]; - vx2 = f[N] - f[S] + f[NE] - f[SW] - f[SE] + f[NW] + f[TN] - f[BS] + f[BN] - - f[TS] + f[TNE] - f[TSW] - f[TSE] + f[TNW] + f[BNE] - f[BSW] - f[BSE] - + f[BNW]; + vx2 = f[N] - f[S] + f[NE] - f[SW] - f[SE] + f[NW] + f[TN] - f[BS] + f[BN] - f[TS] + f[TNE] - + f[TSW] - f[TSE] + f[TNW] + f[BNE] - f[BSW] - f[BSE] + f[BNW]; - vx3 = f[T] - f[B] + f[TE] - f[BW] - f[BE] + f[TW] + f[TN] - f[BS] - f[BN] - + f[TS] + f[TNE] + f[TSW] + f[TSE] + f[TNW] - f[BNE] - f[BSW] - f[BSE] - - f[BNW]; + vx3 = f[T] - f[B] + f[TE] - f[BW] - f[BE] + f[TW] + f[TN] - f[BS] - f[BN] + f[TS] + f[TNE] + + f[TSW] + f[TSE] + f[TNW] - f[BNE] - f[BSW] - f[BSE] - f[BNW]; - LBMReal cu_sq=1.5*(vx1*vx1+vx2*vx2+vx3*vx3); + LBMReal cu_sq = 1.5 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); - feq[ZERO] = c8o27*(drho-cu_sq); - feq[E] = c2o27*(drho+3.0*( vx1 )+c9o2*( vx1 )*( vx1 )-cu_sq); - feq[W] = c2o27*(drho+3.0*(-vx1 )+c9o2*(-vx1 )*(-vx1 )-cu_sq); - feq[N] = c2o27*(drho+3.0*( vx2)+c9o2*( vx2)*( vx2)-cu_sq); - feq[S] = c2o27*(drho+3.0*( -vx2)+c9o2*( -vx2)*( -vx2)-cu_sq); - feq[T] = c2o27*(drho+3.0*( vx3 )+c9o2*( vx3)*( vx3)-cu_sq); - feq[B] = c2o27*(drho+3.0*( -vx3)+c9o2*( -vx3)*( -vx3)-cu_sq); - feq[NE] = c1o54*(drho+3.0*( vx1+vx2)+c9o2*( vx1+vx2)*( vx1+vx2)-cu_sq); - feq[SW] = c1o54*(drho+3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq); - feq[SE] = c1o54*(drho+3.0*( vx1-vx2)+c9o2*( vx1-vx2)*( vx1-vx2)-cu_sq); - feq[NW] = c1o54*(drho+3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq); - feq[TE] = c1o54*(drho+3.0*( vx1+vx3)+c9o2*( vx1+vx3)*( vx1+vx3)-cu_sq); - feq[BW] = c1o54*(drho+3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq); - feq[BE] = c1o54*(drho+3.0*( vx1-vx3)+c9o2*( vx1-vx3)*( vx1-vx3)-cu_sq); - feq[TW] = c1o54*(drho+3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq); - feq[TN] = c1o54*(drho+3.0*( vx2+vx3)+c9o2*( vx2+vx3)*( vx2+vx3)-cu_sq); - feq[BS] = c1o54*(drho+3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq); - feq[BN] = c1o54*(drho+3.0*( vx2-vx3)+c9o2*( vx2-vx3)*( vx2-vx3)-cu_sq); - feq[TS] = c1o54*(drho+3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq); - feq[TNE]= c1o216*(drho+3.0*( vx1+vx2+vx3)+c9o2*( vx1+vx2+vx3)*( vx1+vx2+vx3)-cu_sq); - feq[BSW]= c1o216*(drho+3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq); - feq[BNE]= c1o216*(drho+3.0*( vx1+vx2-vx3)+c9o2*( vx1+vx2-vx3)*( vx1+vx2-vx3)-cu_sq); - feq[TSW]= c1o216*(drho+3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq); - feq[TSE]= c1o216*(drho+3.0*( vx1-vx2+vx3)+c9o2*( vx1-vx2+vx3)*( vx1-vx2+vx3)-cu_sq); - feq[BNW]= c1o216*(drho+3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq); - feq[BSE]= c1o216*(drho+3.0*( vx1-vx2-vx3)+c9o2*( vx1-vx2-vx3)*( vx1-vx2-vx3)-cu_sq); - feq[TNW]= c1o216*(drho+3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq); + feq[ZERO] = c8o27 * (drho - cu_sq); + feq[E] = c2o27 * (drho + 3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq); + feq[W] = c2o27 * (drho + 3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq); + feq[N] = c2o27 * (drho + 3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq); + feq[S] = c2o27 * (drho + 3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq); + feq[T] = c2o27 * (drho + 3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq); + feq[B] = c2o27 * (drho + 3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq); + feq[NE] = c1o54 * (drho + 3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq); + feq[SW] = c1o54 * (drho + 3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq); + feq[SE] = c1o54 * (drho + 3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq); + feq[NW] = c1o54 * (drho + 3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq); + feq[TE] = c1o54 * (drho + 3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq); + feq[BW] = c1o54 * (drho + 3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq); + feq[BE] = c1o54 * (drho + 3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq); + feq[TW] = c1o54 * (drho + 3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq); + feq[TN] = c1o54 * (drho + 3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq); + feq[BS] = c1o54 * (drho + 3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq); + feq[BN] = c1o54 * (drho + 3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq); + feq[TS] = c1o54 * (drho + 3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq); + feq[TNE] = c1o216 * + (drho + 3.0 * (vx1 + vx2 + vx3) + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq); + feq[BSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 - vx3) + + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq); + feq[BNE] = c1o216 * + (drho + 3.0 * (vx1 + vx2 - vx3) + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq); + feq[TSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 + vx3) + + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq); + feq[TSE] = c1o216 * + (drho + 3.0 * (vx1 - vx2 + vx3) + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq); + feq[BNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 - vx3) + + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq); + feq[BSE] = c1o216 * + (drho + 3.0 * (vx1 - vx2 - vx3) + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq); + feq[TNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 + vx3) + + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq); - //Relaxation - f[ZERO] += (feq[ZERO]-f[ZERO])*collFactor; - f[E] += (feq[E]-f[E])*collFactor; - f[W] += (feq[W]-f[W])*collFactor; - f[N] += (feq[N]-f[N])*collFactor; - f[S] += (feq[S]-f[S])*collFactor; - f[T] += (feq[T]-f[T])*collFactor; - f[B] += (feq[B]-f[B])*collFactor; - f[NE] += (feq[NE]-f[NE])*collFactor; - f[SW] += (feq[SW]-f[SW])*collFactor; - f[SE] += (feq[SE]-f[SE])*collFactor; - f[NW] += (feq[NW]-f[NW])*collFactor; - f[TE] += (feq[TE]-f[TE])*collFactor; - f[BW] += (feq[BW]-f[BW])*collFactor; - f[BE] += (feq[BE]-f[BE])*collFactor; - f[TW] += (feq[TW]-f[TW])*collFactor; - f[TN] += (feq[TN]-f[TN])*collFactor; - f[BS] += (feq[BS]-f[BS])*collFactor; - f[BN] += (feq[BN]-f[BN])*collFactor; - f[TS] += (feq[TS]-f[TS])*collFactor; + // Relaxation + f[ZERO] += (feq[ZERO] - f[ZERO]) * collFactor; + f[E] += (feq[E] - f[E]) * collFactor; + f[W] += (feq[W] - f[W]) * collFactor; + f[N] += (feq[N] - f[N]) * collFactor; + f[S] += (feq[S] - f[S]) * collFactor; + f[T] += (feq[T] - f[T]) * collFactor; + f[B] += (feq[B] - f[B]) * collFactor; + f[NE] += (feq[NE] - f[NE]) * collFactor; + f[SW] += (feq[SW] - f[SW]) * collFactor; + f[SE] += (feq[SE] - f[SE]) * collFactor; + f[NW] += (feq[NW] - f[NW]) * collFactor; + f[TE] += (feq[TE] - f[TE]) * collFactor; + f[BW] += (feq[BW] - f[BW]) * collFactor; + f[BE] += (feq[BE] - f[BE]) * collFactor; + f[TW] += (feq[TW] - f[TW]) * collFactor; + f[TN] += (feq[TN] - f[TN]) * collFactor; + f[BS] += (feq[BS] - f[BS]) * collFactor; + f[BN] += (feq[BN] - f[BN]) * collFactor; + f[TS] += (feq[TS] - f[TS]) * collFactor; - f[TNE] += (feq[TNE]-f[TNE])*collFactor; - f[BSW] += (feq[BSW]-f[BSW])*collFactor; - f[BNE] += (feq[BNE]-f[BNE])*collFactor; - f[TSW] += (feq[TSW]-f[TSW])*collFactor; - f[TSE] += (feq[TSE]-f[TSE])*collFactor; - f[BNW] += (feq[BNW]-f[BNW])*collFactor; - f[BSE] += (feq[BSE]-f[BSE])*collFactor; - f[TNW] += (feq[TNW]-f[TNW])*collFactor; + f[TNE] += (feq[TNE] - f[TNE]) * collFactor; + f[BSW] += (feq[BSW] - f[BSW]) * collFactor; + f[BNE] += (feq[BNE] - f[BNE]) * collFactor; + f[TSW] += (feq[TSW] - f[TSW]) * collFactor; + f[TSE] += (feq[TSE] - f[TSE]) * collFactor; + f[BNW] += (feq[BNW] - f[BNW]) * collFactor; + f[BSE] += (feq[BSE] - f[BSE]) * collFactor; + f[TNW] += (feq[TNW] - f[TNW]) * collFactor; - ////////////////////////////////////////////////////////////////////////// - //forcing - if (withForcing) - { - muX1 = x1+ix1*bcArrayMaxX1; - muX2 = x2+ix2*bcArrayMaxX2; - muX3 = x3+ix3*bcArrayMaxX3; + ////////////////////////////////////////////////////////////////////////// + // forcing + if (withForcing) { + muX1 = x1 + ix1 * bcArrayMaxX1; + muX2 = x2 + ix2 * bcArrayMaxX2; + muX3 = x3 + ix3 * bcArrayMaxX3; - forcingX1 = muForcingX1.Eval(); - forcingX2 = muForcingX2.Eval(); - forcingX3 = muForcingX3.Eval(); + forcingX1 = muForcingX1.Eval(); + forcingX2 = muForcingX2.Eval(); + forcingX3 = muForcingX3.Eval(); - f[ZERO] += 0.0 ; - f[E ] += 3.0*c2o27 * (forcingX1) ; - f[W ] += 3.0*c2o27 * (-forcingX1) ; - f[N ] += 3.0*c2o27 * (forcingX2) ; - f[S ] += 3.0*c2o27 * (-forcingX2) ; - f[T ] += 3.0*c2o27 * (forcingX3) ; - f[B ] += 3.0*c2o27 * (-forcingX3); - f[NE ] += 3.0*c1o54 * ( forcingX1+forcingX2 ) ; - f[SW ] += 3.0*c1o54 * (-forcingX1-forcingX2 ) ; - f[SE ] += 3.0*c1o54 * ( forcingX1-forcingX2 ) ; - f[NW ] += 3.0*c1o54 * (-forcingX1+forcingX2 ) ; - f[TE ] += 3.0*c1o54 * ( forcingX1 +forcingX3) ; - f[BW ] += 3.0*c1o54 * (-forcingX1 -forcingX3) ; - f[BE ] += 3.0*c1o54 * ( forcingX1 -forcingX3) ; - f[TW ] += 3.0*c1o54 * (-forcingX1 +forcingX3) ; - f[TN ] += 3.0*c1o54 * ( forcingX2+forcingX3) ; - f[BS ] += 3.0*c1o54 * ( -forcingX2-forcingX3) ; - f[BN ] += 3.0*c1o54 * ( forcingX2-forcingX3) ; - f[TS ] += 3.0*c1o54 * ( -forcingX2+forcingX3) ; - f[TNE] += 3.0*c1o216* ( forcingX1+forcingX2+forcingX3) ; - f[BSW] += 3.0*c1o216* (-forcingX1-forcingX2-forcingX3) ; - f[BNE] += 3.0*c1o216* ( forcingX1+forcingX2-forcingX3) ; - f[TSW] += 3.0*c1o216* (-forcingX1-forcingX2+forcingX3) ; - f[TSE] += 3.0*c1o216* ( forcingX1-forcingX2+forcingX3) ; - f[BNW] += 3.0*c1o216* (-forcingX1+forcingX2-forcingX3) ; - f[BSE] += 3.0*c1o216* ( forcingX1-forcingX2-forcingX3) ; - f[TNW] += 3.0*c1o216* (-forcingX1+forcingX2+forcingX3) ; - } - ////////////////////////////////////////////////////////////////////////// -#ifdef PROOF_CORRECTNESS - LBMReal rho_post = f[ZERO] + f[E] + f[W] + f[N] + f[S] + f[T] + f[B] - + f[NE] + f[SW] + f[SE] + f[NW] + f[TE] + f[BW] + f[BE] - + f[TW] + f[TN] + f[BS] + f[BN] + f[TS] + f[TNE] + f[TSW] - + f[TSE] + f[TNW] + f[BNE] + f[BSW] + f[BSE] + f[BNW]; - LBMReal dif = drho - rho_post; + f[ZERO] += 0.0; + f[E] += 3.0 * c2o27 * (forcingX1); + f[W] += 3.0 * c2o27 * (-forcingX1); + f[N] += 3.0 * c2o27 * (forcingX2); + f[S] += 3.0 * c2o27 * (-forcingX2); + f[T] += 3.0 * c2o27 * (forcingX3); + f[B] += 3.0 * c2o27 * (-forcingX3); + f[NE] += 3.0 * c1o54 * (forcingX1 + forcingX2); + f[SW] += 3.0 * c1o54 * (-forcingX1 - forcingX2); + f[SE] += 3.0 * c1o54 * (forcingX1 - forcingX2); + f[NW] += 3.0 * c1o54 * (-forcingX1 + forcingX2); + f[TE] += 3.0 * c1o54 * (forcingX1 + forcingX3); + f[BW] += 3.0 * c1o54 * (-forcingX1 - forcingX3); + f[BE] += 3.0 * c1o54 * (forcingX1 - forcingX3); + f[TW] += 3.0 * c1o54 * (-forcingX1 + forcingX3); + f[TN] += 3.0 * c1o54 * (forcingX2 + forcingX3); + f[BS] += 3.0 * c1o54 * (-forcingX2 - forcingX3); + f[BN] += 3.0 * c1o54 * (forcingX2 - forcingX3); + f[TS] += 3.0 * c1o54 * (-forcingX2 + forcingX3); + f[TNE] += 3.0 * c1o216 * (forcingX1 + forcingX2 + forcingX3); + f[BSW] += 3.0 * c1o216 * (-forcingX1 - forcingX2 - forcingX3); + f[BNE] += 3.0 * c1o216 * (forcingX1 + forcingX2 - forcingX3); + f[TSW] += 3.0 * c1o216 * (-forcingX1 - forcingX2 + forcingX3); + f[TSE] += 3.0 * c1o216 * (forcingX1 - forcingX2 + forcingX3); + f[BNW] += 3.0 * c1o216 * (-forcingX1 + forcingX2 - forcingX3); + f[BSE] += 3.0 * c1o216 * (forcingX1 - forcingX2 - forcingX3); + f[TNW] += 3.0 * c1o216 * (-forcingX1 + forcingX2 + forcingX3); + } + ////////////////////////////////////////////////////////////////////////// +#ifdef PROOF_CORRECTNESS + LBMReal rho_post = f[ZERO] + f[E] + f[W] + f[N] + f[S] + f[T] + f[B] + f[NE] + f[SW] + f[SE] + + f[NW] + f[TE] + f[BW] + f[BE] + f[TW] + f[TN] + f[BS] + f[BN] + f[TS] + f[TNE] + + f[TSW] + f[TSE] + f[TNW] + f[BNE] + f[BSW] + f[BSE] + f[BNW]; + LBMReal dif = drho - rho_post; #ifdef SINGLEPRECISION - if(dif > 10.0E-7 || dif < -10.0E-7) + if (dif > 10.0E-7 || dif < -10.0E-7) #else - if(dif > 10.0E-15 || dif < -10.0E-15) + if (dif > 10.0E-15 || dif < -10.0E-15) #endif - { - UB_THROW(UbException(UB_EXARGS,"rho is not correct")); - } + { + UB_THROW(UbException(UB_EXARGS, "rho is not correct")); + } #endif - ////////////////////////////////////////////////////////////////////////// - //write distribution - ////////////////////////////////////////////////////////////////////////// - (*this->localDistributions)(D3Q27System::ET_E,x1, x2, x3) = f[D3Q27System::INV_E]; - (*this->localDistributions)(D3Q27System::ET_N,x1, x2, x3) = f[D3Q27System::INV_N]; - (*this->localDistributions)(D3Q27System::ET_T,x1, x2, x3) = f[D3Q27System::INV_T]; - (*this->localDistributions)(D3Q27System::ET_NE,x1, x2, x3) = f[D3Q27System::INV_NE]; - (*this->localDistributions)(D3Q27System::ET_NW,x1p,x2, x3) = f[D3Q27System::INV_NW]; - (*this->localDistributions)(D3Q27System::ET_TE,x1, x2, x3) = f[D3Q27System::INV_TE]; - (*this->localDistributions)(D3Q27System::ET_TW,x1p,x2, x3) = f[D3Q27System::INV_TW]; - (*this->localDistributions)(D3Q27System::ET_TN,x1, x2, x3) = f[D3Q27System::INV_TN]; - (*this->localDistributions)(D3Q27System::ET_TS,x1, x2p,x3) = f[D3Q27System::INV_TS]; - (*this->localDistributions)(D3Q27System::ET_TNE,x1, x2, x3) = f[D3Q27System::INV_TNE]; - (*this->localDistributions)(D3Q27System::ET_TNW,x1p,x2, x3) = f[D3Q27System::INV_TNW]; - (*this->localDistributions)(D3Q27System::ET_TSE,x1, x2p,x3) = f[D3Q27System::INV_TSE]; - (*this->localDistributions)(D3Q27System::ET_TSW,x1p,x2p,x3) = f[D3Q27System::INV_TSW]; - - (*this->nonLocalDistributions)(D3Q27System::ET_W,x1p,x2, x3 ) = f[D3Q27System::INV_W ]; - (*this->nonLocalDistributions)(D3Q27System::ET_S,x1, x2p,x3 ) = f[D3Q27System::INV_S ]; - (*this->nonLocalDistributions)(D3Q27System::ET_B,x1, x2, x3p ) = f[D3Q27System::INV_B ]; - (*this->nonLocalDistributions)(D3Q27System::ET_SW,x1p,x2p,x3 ) = f[D3Q27System::INV_SW]; - (*this->nonLocalDistributions)(D3Q27System::ET_SE,x1, x2p,x3 ) = f[D3Q27System::INV_SE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BW,x1p,x2, x3p ) = f[D3Q27System::INV_BW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BE,x1, x2, x3p ) = f[D3Q27System::INV_BE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BS,x1, x2p,x3p ) = f[D3Q27System::INV_BS]; - (*this->nonLocalDistributions)(D3Q27System::ET_BN,x1, x2, x3p ) = f[D3Q27System::INV_BN]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSW,x1p,x2p,x3p) = f[D3Q27System::INV_BSW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BSE,x1, x2p,x3p) = f[D3Q27System::INV_BSE]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNW,x1p,x2, x3p) = f[D3Q27System::INV_BNW]; - (*this->nonLocalDistributions)(D3Q27System::ET_BNE,x1, x2, x3p) = f[D3Q27System::INV_BNE]; - - (*this->zeroDistributions)(x1,x2,x3) = f[D3Q27System::ZERO]; - ////////////////////////////////////////////////////////////////////////// + ////////////////////////////////////////////////////////////////////////// + // write distribution + ////////////////////////////////////////////////////////////////////////// + (*this->localDistributions)(D3Q27System::ET_E, x1, x2, x3) = f[D3Q27System::INV_E]; + (*this->localDistributions)(D3Q27System::ET_N, x1, x2, x3) = f[D3Q27System::INV_N]; + (*this->localDistributions)(D3Q27System::ET_T, x1, x2, x3) = f[D3Q27System::INV_T]; + (*this->localDistributions)(D3Q27System::ET_NE, x1, x2, x3) = f[D3Q27System::INV_NE]; + (*this->localDistributions)(D3Q27System::ET_NW, x1p, x2, x3) = f[D3Q27System::INV_NW]; + (*this->localDistributions)(D3Q27System::ET_TE, x1, x2, x3) = f[D3Q27System::INV_TE]; + (*this->localDistributions)(D3Q27System::ET_TW, x1p, x2, x3) = f[D3Q27System::INV_TW]; + (*this->localDistributions)(D3Q27System::ET_TN, x1, x2, x3) = f[D3Q27System::INV_TN]; + (*this->localDistributions)(D3Q27System::ET_TS, x1, x2p, x3) = f[D3Q27System::INV_TS]; + (*this->localDistributions)(D3Q27System::ET_TNE, x1, x2, x3) = f[D3Q27System::INV_TNE]; + (*this->localDistributions)(D3Q27System::ET_TNW, x1p, x2, x3) = f[D3Q27System::INV_TNW]; + (*this->localDistributions)(D3Q27System::ET_TSE, x1, x2p, x3) = f[D3Q27System::INV_TSE]; + (*this->localDistributions)(D3Q27System::ET_TSW, x1p, x2p, x3) = f[D3Q27System::INV_TSW]; + (*this->nonLocalDistributions)(D3Q27System::ET_W, x1p, x2, x3) = f[D3Q27System::INV_W]; + (*this->nonLocalDistributions)(D3Q27System::ET_S, x1, x2p, x3) = f[D3Q27System::INV_S]; + (*this->nonLocalDistributions)(D3Q27System::ET_B, x1, x2, x3p) = f[D3Q27System::INV_B]; + (*this->nonLocalDistributions)(D3Q27System::ET_SW, x1p, x2p, x3) = f[D3Q27System::INV_SW]; + (*this->nonLocalDistributions)(D3Q27System::ET_SE, x1, x2p, x3) = f[D3Q27System::INV_SE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BW, x1p, x2, x3p) = f[D3Q27System::INV_BW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BE, x1, x2, x3p) = f[D3Q27System::INV_BE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BS, x1, x2p, x3p) = f[D3Q27System::INV_BS]; + (*this->nonLocalDistributions)(D3Q27System::ET_BN, x1, x2, x3p) = f[D3Q27System::INV_BN]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSW, x1p, x2p, x3p) = f[D3Q27System::INV_BSW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BSE, x1, x2p, x3p) = f[D3Q27System::INV_BSE]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNW, x1p, x2, x3p) = f[D3Q27System::INV_BNW]; + (*this->nonLocalDistributions)(D3Q27System::ET_BNE, x1, x2, x3p) = f[D3Q27System::INV_BNE]; + (*this->zeroDistributions)(x1, x2, x3) = f[D3Q27System::ZERO]; + ////////////////////////////////////////////////////////////////////////// + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// -double BGKLBMKernel::getCalculationTime() -{ - return 0.0; -} +double BGKLBMKernel::getCalculationTime() { return 0.0; } diff --git a/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.h index 0118352ba..e998267c0 100644 --- a/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/BGKLBMKernel.h @@ -2,35 +2,31 @@ #define LBMKERNELETD3Q27BGK_H #include "LBMKernel.h" -#include "basics/container/CbArray4D.h" #include "basics/container/CbArray3D.h" +#include "basics/container/CbArray4D.h" - - -class BGKLBMKernel : public LBMKernel +class BGKLBMKernel : public LBMKernel { public: - BGKLBMKernel(); - ~BGKLBMKernel() override; - void calculate(int step)override; - SPtr<LBMKernel> clone()override; - double getCalculationTime() override; + BGKLBMKernel(); + ~BGKLBMKernel() override; + void calculate(int step) override; + SPtr<LBMKernel> clone() override; + double getCalculationTime() override; private: - void initDataSet(); - //void collideAllCompressible(); - //void collideAllIncompressible(); - - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr localDistributions; - CbArray4D<LBMReal,IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; - CbArray3D<LBMReal,IndexerX3X2X1>::CbArray3DPtr zeroDistributions; - - mu::value_type muX1,muX2,muX3; - LBMReal forcingX1; - LBMReal forcingX2; - LBMReal forcingX3; - - + void initDataSet(); + // void collideAllCompressible(); + // void collideAllIncompressible(); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions; + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions; + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions; + + mu::value_type muX1, muX2, muX3; + LBMReal forcingX1; + LBMReal forcingX2; + LBMReal forcingX3; }; #endif diff --git a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp index ec791cbb3..6c2f84f06 100644 --- a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.cpp @@ -1,197 +1,208 @@ #include "D3Q27System.h" namespace D3Q27System { - using namespace UbMath; - - //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18//falsch - //f: ZERO, E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW - //const int EX1[] = { 0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 }; - //const int EX2[] = { 0, 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1 }; - //const int EX3[] = { 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1 }; - - //index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 - //f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW - const int DX1[] = { 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 }; - const int DX2[] = { 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1 }; - const int DX3[] = { 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1 }; - - ////index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 - ////f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE BSW - const double WEIGTH[] = { c2o27, c2o27, c2o27, c2o27, c2o27, c2o27, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o216, c1o216, c1o216, c1o216, c1o216, c1o216, c1o216, c1o216 , c8o27 }; - - - const int INVDIR[] = { - INV_E, - INV_W, - INV_N, - INV_S, - INV_T, - INV_B, - INV_NE, - INV_SW, - INV_SE, - INV_NW, - INV_TE, - INV_BW, - INV_BE, - INV_TW, - INV_TN, - INV_BS, - INV_BN, - INV_TS, - INV_TNE, - INV_TNW, - INV_TSE, - INV_TSW, - INV_BNE, - INV_BNW, - INV_BSE, - INV_BSW }; - - - // The x,y,z component for each normalized direction - const double cNorm[3][ENDDIR] = { - { - double(DX1[0]), double(DX1[1]), - double(DX1[2]), double(DX1[3]), - double(DX1[4]), double(DX1[5]), - double(DX1[6]) / std::sqrt(double(2)), double(DX1[7]) / std::sqrt(double(2)), - double(DX1[8]) / std::sqrt(double(2)), double(DX1[9]) / std::sqrt(double(2)), - double(DX1[10]) / std::sqrt(double(2)), double(DX1[11]) / std::sqrt(double(2)), - double(DX1[12]) / std::sqrt(double(2)), double(DX1[13]) / std::sqrt(double(2)), - double(DX1[14]), double(DX1[15]), - double(DX1[16]), double(DX1[17]), - double(DX1[18]) / std::sqrt(double(3)), double(DX1[19]) / std::sqrt(double(3)), - double(DX1[20]) / std::sqrt(double(3)), double(DX1[21]) / std::sqrt(double(3)), - double(DX1[22]) / std::sqrt(double(3)), double(DX1[23]) / std::sqrt(double(3)), - double(DX1[24]) / std::sqrt(double(3)), double(DX1[25]) / std::sqrt(double(3)) - },{ - double(DX2[0]), double(DX2[1]), - double(DX2[2]), double(DX2[3]), - double(DX2[4]), double(DX2[5]), - double(DX2[6]) / std::sqrt(double(2)), double(DX2[7]) / std::sqrt(double(2)), - double(DX2[8]) / std::sqrt(double(2)), double(DX2[9]) / std::sqrt(double(2)), - double(DX2[10]), double(DX2[11]), - double(DX2[12]), double(DX2[13]), - double(DX2[14]) / std::sqrt(double(2)), double(DX2[15]) / std::sqrt(double(2)), - double(DX2[16]) / std::sqrt(double(2)), double(DX2[17]) / std::sqrt(double(2)), - double(DX2[18]) / std::sqrt(double(3)), double(DX2[19]) / std::sqrt(double(3)), - double(DX2[20]) / std::sqrt(double(3)), double(DX2[21]) / std::sqrt(double(3)), - double(DX2[22]) / std::sqrt(double(3)), double(DX2[23]) / std::sqrt(double(3)), - double(DX2[24]) / std::sqrt(double(3)), double(DX2[25]) / std::sqrt(double(3)) - },{ - double(DX3[0]), double(DX3[1]), - double(DX3[2]), double(DX3[3]), - double(DX3[4]), double(DX3[5]), - double(DX3[6]), double(DX3[7]), - double(DX3[8]), double(DX3[9]), - double(DX3[10]) / std::sqrt(double(2)), double(DX3[11]) / std::sqrt(double(2)), - double(DX3[12]) / std::sqrt(double(2)), double(DX3[13]) / std::sqrt(double(2)), - double(DX3[14]) / std::sqrt(double(2)), double(DX3[15]) / std::sqrt(double(2)), - double(DX3[16]) / std::sqrt(double(2)), double(DX3[17]) / std::sqrt(double(2)), - double(DX3[18]) / std::sqrt(double(3)), double(DX3[19]) / std::sqrt(double(3)), - double(DX3[20]) / std::sqrt(double(3)), double(DX3[21]) / std::sqrt(double(3)), - double(DX3[22]) / std::sqrt(double(3)), double(DX3[23]) / std::sqrt(double(3)), - double(DX3[24]) / std::sqrt(double(3)), double(DX3[25]) / std::sqrt(double(3)) - } - }; - -} - -//const int FSTARTDIR = 0; -//const int FENDDIR = 25; //D3Q27 - -//const int STARTF = 0; -//const int ENDF = 26; //D3Q27 - -//const int EX1[ENDF+1]; -//const int EX2[ENDF+1]; -//const int EX3[ENDF+1]; - -//const int STARTDIR = 0; -//const int ENDDIR = 26; //alle geometrischen richtungen - -//const int DX1[ENDDIR+1]; -//const int DX2[ENDDIR+1]; -//const int DX3[ENDDIR+1]; - - -//const int E /*f1 */ = 0; -//const int W /*f2 */ = 1; -//const int N /*f3 */ = 2; -//const int S /*f4 */ = 3; -//const int T /*f5 */ = 4; -//const int B /*f6 */ = 5; -//const int NE /*f7 */ = 6; -//const int SW /*f8 */ = 7; -//const int SE /*f9 */ = 8; -//const int NW /*f10*/ = 9; -//const int TE /*f11*/ = 10; -//const int BW /*f12*/ = 11; -//const int BE /*f13*/ = 12; -//const int TW /*f14*/ = 13; -//const int TN /*f15*/ = 14; -//const int BS /*f16*/ = 15; -//const int BN /*f17*/ = 16; -//const int TS /*f18*/ = 17; -//const int TNE = 18; -//const int TNW = 19; -//const int TSE = 20; -//const int TSW = 21; -//const int BNE = 22; -//const int BNW = 23; -//const int BSE = 24; -//const int BSW = 25; -//const int ZERO /*f0 */ = 26; - -//const int INV_E = W; -//const int INV_W = E; -//const int INV_N = S; -//const int INV_S = N; -//const int INV_T = B; -//const int INV_B = T; -//const int INV_NE = SW; -//const int INV_SW = NE; -//const int INV_SE = NW; -//const int INV_NW = SE; -//const int INV_TE = BW; -//const int INV_BW = TE; -//const int INV_BE = TW; -//const int INV_TW = BE; -//const int INV_TN = BS; -//const int INV_BS = TN; -//const int INV_BN = TS; -//const int INV_TS = BN; -//const int INV_TNE = BSW; -//const int INV_TNW = BSE; -//const int INV_TSE = BNW; -//const int INV_TSW = BNE; -//const int INV_BNE = TSW; -//const int INV_BNW = TSE; -//const int INV_BSE = TNW; -//const int INV_BSW = TNE; - -//const int INVDIR[ENDDIR+1]; - -//const int M_RHO = 0; -//const int M_EN = 1; -//const int M_EPS = 2; -//const int M_JX1 = 3; -//const int M_QX1 = 4; -//const int M_JX2 = 5; -//const int M_QX2 = 6; -//const int M_JX3 = 7; -//const int M_QX3 = 8; -//const int M_3PX1X1 = 9; -//const int M_3PIX1X1 = 10; -//const int M_PWW = 11; -//const int M_PIWW = 12; -//const int M_PX1X2 = 13; -//const int M_PX2X3 = 14; -//const int M_PX1X3 = 15; -//const int M_MX1 = 16; -//const int M_MX2 = 17; -//const int M_MX3 = 18; - -//const int STARTM = 0; -//const int ENDM = 18; //D3Q27 +using namespace UbMath; + +// index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18//falsch +// f: ZERO, E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW +// BSE BSW const int EX1[] = { 0, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, +// 1, -1, 1, -1 }; const int EX2[] = { 0, 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, +// -1, -1, 1, 1, -1, -1 }; const int EX3[] = { 0, 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, +// 1, 1, 1, 1, 1, -1, -1, -1, -1 }; + +// index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 +// f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW BSE +// BSW +const int DX1[] = { 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1, 0, 0, 0, 0, 1, -1, 1, -1, 1, -1, 1, -1 }; +const int DX2[] = { 0, 0, 1, -1, 0, 0, 1, -1, -1, 1, 0, 0, 0, 0, 1, -1, 1, -1, 1, 1, -1, -1, 1, 1, -1, -1 }; +const int DX3[] = { 0, 0, 0, 0, 1, -1, 0, 0, 0, 0, 1, -1, -1, 1, 1, -1, -1, 1, 1, 1, 1, 1, -1, -1, -1, -1 }; + +////index 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 +////f: E, W, N, S, T, B, NE, SW, SE, NW, TE, BW, BE, TW, TN, BS, BN, TS, TNE TNW TSE TSW BNE BNW +///BSE BSW +const double WEIGTH[] = { c2o27, c2o27, c2o27, c2o27, c2o27, c2o27, c1o54, c1o54, c1o54, + c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, c1o54, + c1o216, c1o216, c1o216, c1o216, c1o216, c1o216, c1o216, c1o216, c8o27 }; + +const int INVDIR[] = { INV_E, INV_W, INV_N, INV_S, INV_T, INV_B, INV_NE, INV_SW, INV_SE, + INV_NW, INV_TE, INV_BW, INV_BE, INV_TW, INV_TN, INV_BS, INV_BN, INV_TS, + INV_TNE, INV_TNW, INV_TSE, INV_TSW, INV_BNE, INV_BNW, INV_BSE, INV_BSW }; + +// The x,y,z component for each normalized direction +const double cNorm[3][ENDDIR] = { { double(DX1[0]), + double(DX1[1]), + double(DX1[2]), + double(DX1[3]), + double(DX1[4]), + double(DX1[5]), + double(DX1[6]) / std::sqrt(double(2)), + double(DX1[7]) / std::sqrt(double(2)), + double(DX1[8]) / std::sqrt(double(2)), + double(DX1[9]) / std::sqrt(double(2)), + double(DX1[10]) / std::sqrt(double(2)), + double(DX1[11]) / std::sqrt(double(2)), + double(DX1[12]) / std::sqrt(double(2)), + double(DX1[13]) / std::sqrt(double(2)), + double(DX1[14]), + double(DX1[15]), + double(DX1[16]), + double(DX1[17]), + double(DX1[18]) / std::sqrt(double(3)), + double(DX1[19]) / std::sqrt(double(3)), + double(DX1[20]) / std::sqrt(double(3)), + double(DX1[21]) / std::sqrt(double(3)), + double(DX1[22]) / std::sqrt(double(3)), + double(DX1[23]) / std::sqrt(double(3)), + double(DX1[24]) / std::sqrt(double(3)), + double(DX1[25]) / std::sqrt(double(3)) }, + { double(DX2[0]), + double(DX2[1]), + double(DX2[2]), + double(DX2[3]), + double(DX2[4]), + double(DX2[5]), + double(DX2[6]) / std::sqrt(double(2)), + double(DX2[7]) / std::sqrt(double(2)), + double(DX2[8]) / std::sqrt(double(2)), + double(DX2[9]) / std::sqrt(double(2)), + double(DX2[10]), + double(DX2[11]), + double(DX2[12]), + double(DX2[13]), + double(DX2[14]) / std::sqrt(double(2)), + double(DX2[15]) / std::sqrt(double(2)), + double(DX2[16]) / std::sqrt(double(2)), + double(DX2[17]) / std::sqrt(double(2)), + double(DX2[18]) / std::sqrt(double(3)), + double(DX2[19]) / std::sqrt(double(3)), + double(DX2[20]) / std::sqrt(double(3)), + double(DX2[21]) / std::sqrt(double(3)), + double(DX2[22]) / std::sqrt(double(3)), + double(DX2[23]) / std::sqrt(double(3)), + double(DX2[24]) / std::sqrt(double(3)), + double(DX2[25]) / std::sqrt(double(3)) }, + { double(DX3[0]), + double(DX3[1]), + double(DX3[2]), + double(DX3[3]), + double(DX3[4]), + double(DX3[5]), + double(DX3[6]), + double(DX3[7]), + double(DX3[8]), + double(DX3[9]), + double(DX3[10]) / std::sqrt(double(2)), + double(DX3[11]) / std::sqrt(double(2)), + double(DX3[12]) / std::sqrt(double(2)), + double(DX3[13]) / std::sqrt(double(2)), + double(DX3[14]) / std::sqrt(double(2)), + double(DX3[15]) / std::sqrt(double(2)), + double(DX3[16]) / std::sqrt(double(2)), + double(DX3[17]) / std::sqrt(double(2)), + double(DX3[18]) / std::sqrt(double(3)), + double(DX3[19]) / std::sqrt(double(3)), + double(DX3[20]) / std::sqrt(double(3)), + double(DX3[21]) / std::sqrt(double(3)), + double(DX3[22]) / std::sqrt(double(3)), + double(DX3[23]) / std::sqrt(double(3)), + double(DX3[24]) / std::sqrt(double(3)), + double(DX3[25]) / std::sqrt(double(3)) } }; + +} // namespace D3Q27System + +// const int FSTARTDIR = 0; +// const int FENDDIR = 25; //D3Q27 + +// const int STARTF = 0; +// const int ENDF = 26; //D3Q27 + +// const int EX1[ENDF+1]; +// const int EX2[ENDF+1]; +// const int EX3[ENDF+1]; + +// const int STARTDIR = 0; +// const int ENDDIR = 26; //alle geometrischen richtungen + +// const int DX1[ENDDIR+1]; +// const int DX2[ENDDIR+1]; +// const int DX3[ENDDIR+1]; + +// const int E /*f1 */ = 0; +// const int W /*f2 */ = 1; +// const int N /*f3 */ = 2; +// const int S /*f4 */ = 3; +// const int T /*f5 */ = 4; +// const int B /*f6 */ = 5; +// const int NE /*f7 */ = 6; +// const int SW /*f8 */ = 7; +// const int SE /*f9 */ = 8; +// const int NW /*f10*/ = 9; +// const int TE /*f11*/ = 10; +// const int BW /*f12*/ = 11; +// const int BE /*f13*/ = 12; +// const int TW /*f14*/ = 13; +// const int TN /*f15*/ = 14; +// const int BS /*f16*/ = 15; +// const int BN /*f17*/ = 16; +// const int TS /*f18*/ = 17; +// const int TNE = 18; +// const int TNW = 19; +// const int TSE = 20; +// const int TSW = 21; +// const int BNE = 22; +// const int BNW = 23; +// const int BSE = 24; +// const int BSW = 25; +// const int ZERO /*f0 */ = 26; + +// const int INV_E = W; +// const int INV_W = E; +// const int INV_N = S; +// const int INV_S = N; +// const int INV_T = B; +// const int INV_B = T; +// const int INV_NE = SW; +// const int INV_SW = NE; +// const int INV_SE = NW; +// const int INV_NW = SE; +// const int INV_TE = BW; +// const int INV_BW = TE; +// const int INV_BE = TW; +// const int INV_TW = BE; +// const int INV_TN = BS; +// const int INV_BS = TN; +// const int INV_BN = TS; +// const int INV_TS = BN; +// const int INV_TNE = BSW; +// const int INV_TNW = BSE; +// const int INV_TSE = BNW; +// const int INV_TSW = BNE; +// const int INV_BNE = TSW; +// const int INV_BNW = TSE; +// const int INV_BSE = TNW; +// const int INV_BSW = TNE; + +// const int INVDIR[ENDDIR+1]; + +// const int M_RHO = 0; +// const int M_EN = 1; +// const int M_EPS = 2; +// const int M_JX1 = 3; +// const int M_QX1 = 4; +// const int M_JX2 = 5; +// const int M_QX2 = 6; +// const int M_JX3 = 7; +// const int M_QX3 = 8; +// const int M_3PX1X1 = 9; +// const int M_3PIX1X1 = 10; +// const int M_PWW = 11; +// const int M_PIWW = 12; +// const int M_PX1X2 = 13; +// const int M_PX2X3 = 14; +// const int M_PX1X3 = 15; +// const int M_MX1 = 16; +// const int M_MX2 = 17; +// const int M_MX3 = 18; + +// const int STARTM = 0; +// const int ENDM = 18; //D3Q27 diff --git a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h index e5b93f54b..1376e0da6 100644 --- a/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h +++ b/src/cpu/VirtualFluidsCore/LBM/D3Q27System.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,609 +35,784 @@ #define D3Q27SYSTEM_H #include <cmath> -#include <string> #include <iostream> +#include <string> +#include "LBMSystem.h" #include "UbException.h" #include "UbMath.h" -#include "LBMSystem.h" //! \brief namespace for global system-functions namespace D3Q27System { - ////////////////////////////////////////////////////////////////////////// - //DIRECTION STUFF - static const int FSTARTDIR = 0; - static const int FENDDIR = 25; //D3Q27 +////////////////////////////////////////////////////////////////////////// +// DIRECTION STUFF +static const int FSTARTDIR = 0; +static const int FENDDIR = 25; // D3Q27 - static const int STARTF = 0; - static const int ENDF = 26; //D3Q27 +static const int STARTF = 0; +static const int ENDF = 26; // D3Q27 - static const int STARTDIR = 0; - static const int ENDDIR = 26; +static const int STARTDIR = 0; +static const int ENDDIR = 26; - extern const int DX1[ENDDIR+1]; - extern const int DX2[ENDDIR+1]; - extern const int DX3[ENDDIR+1]; - extern const double WEIGTH[ENDDIR+1]; +extern const int DX1[ENDDIR + 1]; +extern const int DX2[ENDDIR + 1]; +extern const int DX3[ENDDIR + 1]; +extern const double WEIGTH[ENDDIR + 1]; - extern const double cNorm[3][ENDDIR]; - - //static const int ZERO /*f0 */ = 0; - //static const int E /*f1 */ = 1; - //static const int W /*f2 */ = 2; - //static const int N /*f3 */ = 3; - //static const int S /*f4 */ = 4; - //static const int T /*f5 */ = 5; - //static const int B /*f6 */ = 6; - //static const int NE /*f7 */ = 7; - //static const int SW /*f8 */ = 8; - //static const int SE /*f9 */ = 9; - //static const int NW /*f10*/ = 10; - //static const int TE /*f11*/ = 11; - //static const int BW /*f12*/ = 12; - //static const int BE /*f13*/ = 13; - //static const int TW /*f14*/ = 14; - //static const int TN /*f15*/ = 15; - //static const int BS /*f16*/ = 16; - //static const int BN /*f17*/ = 17; - //static const int TS /*f18*/ = 18; - //static const int TNE = 19; - //static const int TNW = 20; - //static const int TSE = 21; - //static const int TSW = 22; - //static const int BNE = 23; - //static const int BNW = 24; - //static const int BSE = 25; - //static const int BSW = 26; +extern const double cNorm[3][ENDDIR]; - static const int E /*f1 */ = 0; - static const int W /*f2 */ = 1; - static const int N /*f3 */ = 2; - static const int S /*f4 */ = 3; - static const int T /*f5 */ = 4; - static const int B /*f6 */ = 5; - static const int NE /*f7 */ = 6; - static const int SW /*f8 */ = 7; - static const int SE /*f9 */ = 8; - static const int NW /*f10*/ = 9; - static const int TE /*f11*/ = 10; - static const int BW /*f12*/ = 11; - static const int BE /*f13*/ = 12; - static const int TW /*f14*/ = 13; - static const int TN /*f15*/ = 14; - static const int BS /*f16*/ = 15; - static const int BN /*f17*/ = 16; - static const int TS /*f18*/ = 17; - static const int TNE = 18; - static const int TNW = 19; - static const int TSE = 20; - static const int TSW = 21; - static const int BNE = 22; - static const int BNW = 23; - static const int BSE = 24; - static const int BSW = 25; - static const int ZERO /*f0 */ = 26; +// static const int ZERO /*f0 */ = 0; +// static const int E /*f1 */ = 1; +// static const int W /*f2 */ = 2; +// static const int N /*f3 */ = 3; +// static const int S /*f4 */ = 4; +// static const int T /*f5 */ = 5; +// static const int B /*f6 */ = 6; +// static const int NE /*f7 */ = 7; +// static const int SW /*f8 */ = 8; +// static const int SE /*f9 */ = 9; +// static const int NW /*f10*/ = 10; +// static const int TE /*f11*/ = 11; +// static const int BW /*f12*/ = 12; +// static const int BE /*f13*/ = 13; +// static const int TW /*f14*/ = 14; +// static const int TN /*f15*/ = 15; +// static const int BS /*f16*/ = 16; +// static const int BN /*f17*/ = 17; +// static const int TS /*f18*/ = 18; +// static const int TNE = 19; +// static const int TNW = 20; +// static const int TSE = 21; +// static const int TSW = 22; +// static const int BNE = 23; +// static const int BNW = 24; +// static const int BSE = 25; +// static const int BSW = 26; - static const int INV_E = W; - static const int INV_W = E; - static const int INV_N = S; - static const int INV_S = N; - static const int INV_T = B; - static const int INV_B = T; - static const int INV_NE = SW; - static const int INV_SW = NE; - static const int INV_SE = NW; - static const int INV_NW = SE; - static const int INV_TE = BW; - static const int INV_BW = TE; - static const int INV_BE = TW; - static const int INV_TW = BE; - static const int INV_TN = BS; - static const int INV_BS = TN; - static const int INV_BN = TS; - static const int INV_TS = BN; - static const int INV_TNE = BSW; - static const int INV_TNW = BSE; - static const int INV_TSE = BNW; - static const int INV_TSW = BNE; - static const int INV_BNE = TSW; - static const int INV_BNW = TSE; - static const int INV_BSE = TNW; - static const int INV_BSW = TNE; - - extern const int INVDIR[ENDDIR+1]; +static const int E /*f1 */ = 0; +static const int W /*f2 */ = 1; +static const int N /*f3 */ = 2; +static const int S /*f4 */ = 3; +static const int T /*f5 */ = 4; +static const int B /*f6 */ = 5; +static const int NE /*f7 */ = 6; +static const int SW /*f8 */ = 7; +static const int SE /*f9 */ = 8; +static const int NW /*f10*/ = 9; +static const int TE /*f11*/ = 10; +static const int BW /*f12*/ = 11; +static const int BE /*f13*/ = 12; +static const int TW /*f14*/ = 13; +static const int TN /*f15*/ = 14; +static const int BS /*f16*/ = 15; +static const int BN /*f17*/ = 16; +static const int TS /*f18*/ = 17; +static const int TNE = 18; +static const int TNW = 19; +static const int TSE = 20; +static const int TSW = 21; +static const int BNE = 22; +static const int BNW = 23; +static const int BSE = 24; +static const int BSW = 25; +static const int ZERO /*f0 */ = 26; - static const int ET_E = 0; - static const int ET_W = 0; - static const int ET_N = 1; - static const int ET_S = 1; - static const int ET_T = 2; - static const int ET_B = 2; - static const int ET_NE = 3; - static const int ET_SW = 3; - static const int ET_SE = 4; - static const int ET_NW = 4; - static const int ET_TE = 5; - static const int ET_BW = 5; - static const int ET_BE = 6; - static const int ET_TW = 6; - static const int ET_TN = 7; - static const int ET_BS = 7; - static const int ET_BN = 8; - static const int ET_TS = 8; - static const int ET_TNE = 9; - static const int ET_BSW = 9; - static const int ET_TNW = 10; - static const int ET_BSE = 10; - static const int ET_TSE = 11; - static const int ET_BNW = 11; - static const int ET_TSW = 12; - static const int ET_BNE = 12; +static const int INV_E = W; +static const int INV_W = E; +static const int INV_N = S; +static const int INV_S = N; +static const int INV_T = B; +static const int INV_B = T; +static const int INV_NE = SW; +static const int INV_SW = NE; +static const int INV_SE = NW; +static const int INV_NW = SE; +static const int INV_TE = BW; +static const int INV_BW = TE; +static const int INV_BE = TW; +static const int INV_TW = BE; +static const int INV_TN = BS; +static const int INV_BS = TN; +static const int INV_BN = TS; +static const int INV_TS = BN; +static const int INV_TNE = BSW; +static const int INV_TNW = BSE; +static const int INV_TSE = BNW; +static const int INV_TSW = BNE; +static const int INV_BNE = TSW; +static const int INV_BNW = TSE; +static const int INV_BSE = TNW; +static const int INV_BSW = TNE; - static const int M_RHO = 0; - static const int M_EN = 1; - static const int M_EPS = 2; - static const int M_JX1 = 3; - static const int M_QX1 = 4; - static const int M_JX2 = 5; - static const int M_QX2 = 6; - static const int M_JX3 = 7; - static const int M_QX3 = 8; - static const int M_3PX1X1 = 9; - static const int M_3PIX1X1 = 10; - static const int M_PWW = 11; - static const int M_PIWW = 12; - static const int M_PX1X2 = 13; - static const int M_PX2X3 = 14; - static const int M_PX1X3 = 15; - static const int M_MX1 = 16; - static const int M_MX2 = 17; - static const int M_MX3 = 18; - - static const int STARTM = 0; - static const int ENDM = 18; //D3Q27 +extern const int INVDIR[ENDDIR + 1]; +static const int ET_E = 0; +static const int ET_W = 0; +static const int ET_N = 1; +static const int ET_S = 1; +static const int ET_T = 2; +static const int ET_B = 2; +static const int ET_NE = 3; +static const int ET_SW = 3; +static const int ET_SE = 4; +static const int ET_NW = 4; +static const int ET_TE = 5; +static const int ET_BW = 5; +static const int ET_BE = 6; +static const int ET_TW = 6; +static const int ET_TN = 7; +static const int ET_BS = 7; +static const int ET_BN = 8; +static const int ET_TS = 8; +static const int ET_TNE = 9; +static const int ET_BSW = 9; +static const int ET_TNW = 10; +static const int ET_BSE = 10; +static const int ET_TSE = 11; +static const int ET_BNW = 11; +static const int ET_TSW = 12; +static const int ET_BNE = 12; - - ////////////////////////////////////////////////////////////////////////// - //MACROSCOPIC VALUES - /*=====================================================================*/ - static LBMReal getDensity(const LBMReal* const& f/*[27]*/) - { - return ((f[TNE] + f[BSW])+(f[TSE]+f[BNW]))+((f[BSE]+f[TNW])+ (f[TSW]+f[BNE])) - +(((f[NE] + f[SW]) + (f[SE] + f[NW]))+((f[TE] + f[BW])+(f[BE]+ f[TW])) - +((f[BN] + f[TS]) + (f[TN] + f[BS])))+((f[E] + f[W])+(f[N] + f[S]) - +(f[T] + f[B]))+f[ZERO]; - } - /*=====================================================================*/ - //ATTENTION: does not apply to all models -> use certificate instead of static! to do - static LBMReal getPressure(const LBMReal* const& f/*[27]*/) - { - return REAL_CAST( UbMath::c1o3 )*getDensity(f); - } - /*=====================================================================*/ - static LBMReal getIncompVelocityX1(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[BSE]-f[TNW]) + (f[BNE]-f[TSW]))) + - (((f[BE]-f[TW]) + (f[TE]-f[BW])) + ((f[SE]-f[NW]) + (f[NE]-f[SW]))) + - (f[E]-f[W])); - } - /*=====================================================================*/ - static LBMReal getIncompVelocityX2(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE]-f[BSW]) + (f[BNW]-f[TSE])) + ((f[TNW]-f[BSE]) + (f[BNE]-f[TSW]))) + - (((f[BN]-f[TS]) + (f[TN]-f[BS])) + ((f[NW]-f[SE]) + (f[NE]-f[SW]))) + - (f[N]-f[S])); - } - /*=====================================================================*/ - static LBMReal getIncompVelocityX3(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + - (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + - (f[T] - f[B])); - } - /*=====================================================================*/ - static void calcDensity(const LBMReal* const& f/*[27]*/, LBMReal& rho) - { - rho = ((f[TNE] + f[BSW])+(f[TSE]+f[BNW]))+((f[BSE]+f[TNW])+ (f[TSW]+f[BNE])) - +(((f[NE] + f[SW]) + (f[SE] + f[NW]))+((f[TE] + f[BW])+(f[BE]+ f[TW])) - +((f[BN] + f[TS]) + (f[TN] + f[BS])))+((f[E] + f[W])+(f[N] + f[S]) - +(f[T] + f[B]))+f[ZERO]; - - } - /*=====================================================================*/ - static void calcIncompVelocityX1(const LBMReal* const& f/*[27]*/, LBMReal& vx1) - { - vx1 = ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[BSE]-f[TNW]) + (f[BNE]-f[TSW]))) + - (((f[BE]-f[TW]) + (f[TE]-f[BW])) + ((f[SE]-f[NW]) + (f[NE]-f[SW]))) + - (f[E]-f[W])); - } - /*=====================================================================*/ - static void calcIncompVelocityX2(const LBMReal* const& f/*[27]*/, LBMReal& vx2) - { - vx2 = ((((f[TNE]-f[BSW]) + (f[BNW]-f[TSE])) + ((f[TNW]-f[BSE]) + (f[BNE]-f[TSW]))) + - (((f[BN]-f[TS]) + (f[TN]-f[BS])) + ((f[NW]-f[SE]) + (f[NE]-f[SW]))) + - (f[N]-f[S])); - } - /*=====================================================================*/ - static void calcIncompVelocityX3(const LBMReal* const& f/*[27]*/, LBMReal& vx3) - { - vx3 =((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[TNW]-f[BSE]) + (f[TSW]-f[BNE]))) + - (((f[TS]-f[BN]) + (f[TN]-f[BS])) + ((f[TW]-f[BE]) + (f[TE]-f[BW]))) + - (f[T]-f[B])); - } - /*=====================================================================*/ - static LBMReal getCompVelocityX1(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[BSE]-f[TNW]) + (f[BNE]-f[TSW]))) + - (((f[BE]-f[TW]) + (f[TE]-f[BW])) + ((f[SE]-f[NW]) + (f[NE]-f[SW]))) + - (f[E]-f[W]))/getDensity(f); - } - /*=====================================================================*/ - static LBMReal getCompVelocityX2(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE]-f[BSW]) + (f[BNW]-f[TSE])) + ((f[TNW]-f[BSE]) + (f[BNE]-f[TSW]))) + - (((f[BN]-f[TS]) + (f[TN]-f[BS])) + ((f[NW]-f[SE]) + (f[NE]-f[SW]))) + - (f[N]-f[S]))/getDensity(f); - } - /*=====================================================================*/ - static LBMReal getCompVelocityX3(const LBMReal* const& f/*[27]*/) - { - return ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[TNW]-f[BSE]) + (f[TSW]-f[BNE]))) + - (((f[TS]-f[BN]) + (f[TN]-f[BS])) + ((f[TW]-f[BE]) + (f[TE]-f[BW]))) + - (f[T]-f[B]))/getDensity(f); - } - /*=====================================================================*/ - static void calcCompVelocityX1(const LBMReal* const& f/*[27]*/, LBMReal& vx1) - { - vx1 = ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[BSE]-f[TNW]) + (f[BNE]-f[TSW]))) + - (((f[BE]-f[TW]) + (f[TE]-f[BW])) + ((f[SE]-f[NW]) + (f[NE]-f[SW]))) + - (f[E]-f[W]))/getDensity(f); - } - /*=====================================================================*/ - static void calcCompVelocityX2(const LBMReal* const& f/*[27]*/, LBMReal& vx2) - { - vx2 = ((((f[TNE]-f[BSW]) + (f[BNW]-f[TSE])) + ((f[TNW]-f[BSE]) + (f[BNE]-f[TSW]))) + - (((f[BN]-f[TS]) + (f[TN]-f[BS])) + ((f[NW]-f[SE]) + (f[NE]-f[SW]))) + - (f[N]-f[S]))/getDensity(f); - } - /*=====================================================================*/ - static void calcCompVelocityX3(const LBMReal* const& f/*[27]*/, LBMReal& vx3) - { - vx3 = ((((f[TNE]-f[BSW]) + (f[TSE]-f[BNW])) + ((f[TNW]-f[BSE]) + (f[TSW]-f[BNE]))) + - (((f[TS]-f[BN]) + (f[TN]-f[BS])) + ((f[TW]-f[BE]) + (f[TE]-f[BW]))) + - (f[T]-f[B]))/getDensity(f); - } - /*=====================================================================*/ - static void calcIncompMacroscopicValues(const LBMReal* const& f/*[27]*/, LBMReal& rho, LBMReal& vx1, LBMReal& vx2, LBMReal& vx3) - { - D3Q27System::calcDensity(f, rho); - D3Q27System::calcIncompVelocityX1(f, vx1); - D3Q27System::calcIncompVelocityX2(f, vx2); - D3Q27System::calcIncompVelocityX3(f, vx3); - } +static const int M_RHO = 0; +static const int M_EN = 1; +static const int M_EPS = 2; +static const int M_JX1 = 3; +static const int M_QX1 = 4; +static const int M_JX2 = 5; +static const int M_QX2 = 6; +static const int M_JX3 = 7; +static const int M_QX3 = 8; +static const int M_3PX1X1 = 9; +static const int M_3PIX1X1 = 10; +static const int M_PWW = 11; +static const int M_PIWW = 12; +static const int M_PX1X2 = 13; +static const int M_PX2X3 = 14; +static const int M_PX1X3 = 15; +static const int M_MX1 = 16; +static const int M_MX2 = 17; +static const int M_MX3 = 18; - /*=====================================================================*/ - static void calcCompMacroscopicValues(const LBMReal* const& f/*[27]*/, LBMReal& drho, LBMReal& vx1, LBMReal& vx2, LBMReal& vx3) - { - D3Q27System::calcDensity(f, drho); - D3Q27System::calcIncompVelocityX1(f, vx1); - D3Q27System::calcIncompVelocityX2(f, vx2); - D3Q27System::calcIncompVelocityX3(f, vx3); - LBMReal rho = drho+UbMath::c1; - vx1/=rho; - vx2/=rho; - vx3/=rho; - } - ////////////////////////////////////////////////////////////////////////// - static LBMReal getCompFeqForDirection(const int& direction, const LBMReal& drho,const LBMReal& vx1,const LBMReal& vx2,const LBMReal& vx3) - { - using namespace UbMath; - LBMReal cu_sq=1.5*(vx1*vx1+vx2*vx2+vx3*vx3); +static const int STARTM = 0; +static const int ENDM = 18; // D3Q27 - ////----- - LBMReal rho = drho+c1; - switch (direction) - { - case ZERO: return REAL_CAST(c8o27*(drho+rho*(-cu_sq))); - case E: return REAL_CAST(c2o27*(drho+rho*(3.0*(vx1)+c9o2*(vx1)*(vx1)-cu_sq))); - case W: return REAL_CAST(c2o27*(drho+rho*(3.0*(-vx1)+c9o2*(-vx1)*(-vx1)-cu_sq))); - case N: return REAL_CAST(c2o27*(drho+rho*(3.0*(vx2)+c9o2*(vx2)*(vx2)-cu_sq))); - case S: return REAL_CAST(c2o27*(drho+rho*(3.0*(-vx2)+c9o2*(-vx2)*(-vx2)-cu_sq))); - case T: return REAL_CAST(c2o27*(drho+rho*(3.0*(vx3)+c9o2*(vx3)*(vx3)-cu_sq))); - case B: return REAL_CAST(c2o27*(drho+rho*(3.0*(-vx3)+c9o2*(-vx3)*(-vx3)-cu_sq))); - case NE: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx1+vx2)+c9o2*(vx1+vx2)*(vx1+vx2)-cu_sq))); - case SW: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq))); - case SE: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx1-vx2)+c9o2*(vx1-vx2)*(vx1-vx2)-cu_sq))); - case NW: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq))); - case TE: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx1+vx3)+c9o2*(vx1+vx3)*(vx1+vx3)-cu_sq))); - case BW: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq))); - case BE: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx1-vx3)+c9o2*(vx1-vx3)*(vx1-vx3)-cu_sq))); - case TW: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq))); - case TN: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx2+vx3)+c9o2*(vx2+vx3)*(vx2+vx3)-cu_sq))); - case BS: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq))); - case BN: return REAL_CAST(c1o54*(drho+rho*(3.0*(vx2-vx3)+c9o2*(vx2-vx3)*(vx2-vx3)-cu_sq))); - case TS: return REAL_CAST(c1o54*(drho+rho*(3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq))); - case TNE: return REAL_CAST(c1o216*(drho+rho*(3.0*(vx1+vx2+vx3)+c9o2*(vx1+vx2+vx3)*(vx1+vx2+vx3)-cu_sq))); - case BSW: return REAL_CAST(c1o216*(drho+rho*(3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq))); - case BNE: return REAL_CAST(c1o216*(drho+rho*(3.0*(vx1+vx2-vx3)+c9o2*(vx1+vx2-vx3)*(vx1+vx2-vx3)-cu_sq))); - case TSW: return REAL_CAST(c1o216*(drho+rho*(3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq))); - case TSE: return REAL_CAST(c1o216*(drho+rho*(3.0*(vx1-vx2+vx3)+c9o2*(vx1-vx2+vx3)*(vx1-vx2+vx3)-cu_sq))); - case BNW: return REAL_CAST(c1o216*(drho+rho*(3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq))); - case BSE: return REAL_CAST(c1o216*(drho+rho*(3.0*(vx1-vx2-vx3)+c9o2*(vx1-vx2-vx3)*(vx1-vx2-vx3)-cu_sq))); - case TNW: return REAL_CAST(c1o216*(drho+rho*(3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq))); - default: throw UbException(UB_EXARGS, "unknown dir"); - } +////////////////////////////////////////////////////////////////////////// +// MACROSCOPIC VALUES +/*=====================================================================*/ +static LBMReal getDensity(const LBMReal *const &f /*[27]*/) +{ + return ((f[TNE] + f[BSW]) + (f[TSE] + f[BNW])) + ((f[BSE] + f[TNW]) + (f[TSW] + f[BNE])) + + (((f[NE] + f[SW]) + (f[SE] + f[NW])) + ((f[TE] + f[BW]) + (f[BE] + f[TW])) + + ((f[BN] + f[TS]) + (f[TN] + f[BS]))) + + ((f[E] + f[W]) + (f[N] + f[S]) + (f[T] + f[B])) + f[ZERO]; +} +/*=====================================================================*/ +// ATTENTION: does not apply to all models -> use certificate instead of static! to do +static LBMReal getPressure(const LBMReal *const &f /*[27]*/) { return REAL_CAST(UbMath::c1o3) * getDensity(f); } +/*=====================================================================*/ +static LBMReal getIncompVelocityX1(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])); +} +/*=====================================================================*/ +static LBMReal getIncompVelocityX2(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])); +} +/*=====================================================================*/ +static LBMReal getIncompVelocityX3(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])); +} +/*=====================================================================*/ +static void calcDensity(const LBMReal *const &f /*[27]*/, LBMReal &rho) +{ + rho = ((f[TNE] + f[BSW]) + (f[TSE] + f[BNW])) + ((f[BSE] + f[TNW]) + (f[TSW] + f[BNE])) + + (((f[NE] + f[SW]) + (f[SE] + f[NW])) + ((f[TE] + f[BW]) + (f[BE] + f[TW])) + + ((f[BN] + f[TS]) + (f[TN] + f[BS]))) + + ((f[E] + f[W]) + (f[N] + f[S]) + (f[T] + f[B])) + f[ZERO]; +} +/*=====================================================================*/ +static void calcIncompVelocityX1(const LBMReal *const &f /*[27]*/, LBMReal &vx1) +{ + vx1 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])); +} +/*=====================================================================*/ +static void calcIncompVelocityX2(const LBMReal *const &f /*[27]*/, LBMReal &vx2) +{ + vx2 = ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])); +} +/*=====================================================================*/ +static void calcIncompVelocityX3(const LBMReal *const &f /*[27]*/, LBMReal &vx3) +{ + vx3 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])); +} +/*=====================================================================*/ +static LBMReal getCompVelocityX1(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])) / + getDensity(f); +} +/*=====================================================================*/ +static LBMReal getCompVelocityX2(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])) / + getDensity(f); +} +/*=====================================================================*/ +static LBMReal getCompVelocityX3(const LBMReal *const &f /*[27]*/) +{ + return ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])) / + getDensity(f); +} +/*=====================================================================*/ +static void calcCompVelocityX1(const LBMReal *const &f /*[27]*/, LBMReal &vx1) +{ + vx1 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[BSE] - f[TNW]) + (f[BNE] - f[TSW]))) + + (((f[BE] - f[TW]) + (f[TE] - f[BW])) + ((f[SE] - f[NW]) + (f[NE] - f[SW]))) + (f[E] - f[W])) / + getDensity(f); +} +/*=====================================================================*/ +static void calcCompVelocityX2(const LBMReal *const &f /*[27]*/, LBMReal &vx2) +{ + vx2 = ((((f[TNE] - f[BSW]) + (f[BNW] - f[TSE])) + ((f[TNW] - f[BSE]) + (f[BNE] - f[TSW]))) + + (((f[BN] - f[TS]) + (f[TN] - f[BS])) + ((f[NW] - f[SE]) + (f[NE] - f[SW]))) + (f[N] - f[S])) / + getDensity(f); +} +/*=====================================================================*/ +static void calcCompVelocityX3(const LBMReal *const &f /*[27]*/, LBMReal &vx3) +{ + vx3 = ((((f[TNE] - f[BSW]) + (f[TSE] - f[BNW])) + ((f[TNW] - f[BSE]) + (f[TSW] - f[BNE]))) + + (((f[TS] - f[BN]) + (f[TN] - f[BS])) + ((f[TW] - f[BE]) + (f[TE] - f[BW]))) + (f[T] - f[B])) / + getDensity(f); +} +/*=====================================================================*/ +static void calcIncompMacroscopicValues(const LBMReal *const &f /*[27]*/, LBMReal &rho, LBMReal &vx1, LBMReal &vx2, + LBMReal &vx3) +{ + D3Q27System::calcDensity(f, rho); + D3Q27System::calcIncompVelocityX1(f, vx1); + D3Q27System::calcIncompVelocityX2(f, vx2); + D3Q27System::calcIncompVelocityX3(f, vx3); +} - } - ////////////////////////////////////////////////////////////////////////// - static void calcCompFeq(LBMReal* const& feq/*[27]*/,const LBMReal& drho,const LBMReal& vx1,const LBMReal& vx2,const LBMReal& vx3) - { - using namespace UbMath; +/*=====================================================================*/ +static void calcCompMacroscopicValues(const LBMReal *const &f /*[27]*/, LBMReal &drho, LBMReal &vx1, LBMReal &vx2, + LBMReal &vx3) +{ + D3Q27System::calcDensity(f, drho); + D3Q27System::calcIncompVelocityX1(f, vx1); + D3Q27System::calcIncompVelocityX2(f, vx2); + D3Q27System::calcIncompVelocityX3(f, vx3); + LBMReal rho = drho + UbMath::c1; + vx1 /= rho; + vx2 /= rho; + vx3 /= rho; +} +////////////////////////////////////////////////////////////////////////// +static LBMReal getCompFeqForDirection(const int &direction, const LBMReal &drho, const LBMReal &vx1, const LBMReal &vx2, + const LBMReal &vx3) +{ + using namespace UbMath; + LBMReal cu_sq = 1.5 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); + + ////----- + LBMReal rho = drho + c1; + switch (direction) { + case ZERO: + return REAL_CAST(c8o27 * (drho + rho * (-cu_sq))); + case E: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq))); + case W: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq))); + case N: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq))); + case S: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq))); + case T: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq))); + case B: + return REAL_CAST(c2o27 * (drho + rho * (3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq))); + case NE: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq))); + case SW: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq))); + case SE: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq))); + case NW: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq))); + case TE: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq))); + case BW: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq))); + case BE: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq))); + case TW: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq))); + case TN: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq))); + case BS: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq))); + case BN: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq))); + case TS: + return REAL_CAST(c1o54 * (drho + rho * (3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq))); + case TNE: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (vx1 + vx2 + vx3) + + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq))); + case BSW: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (-vx1 - vx2 - vx3) + + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq))); + case BNE: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (vx1 + vx2 - vx3) + + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq))); + case TSW: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (-vx1 - vx2 + vx3) + + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq))); + case TSE: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (vx1 - vx2 + vx3) + + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq))); + case BNW: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (-vx1 + vx2 - vx3) + + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq))); + case BSE: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (vx1 - vx2 - vx3) + + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq))); + case TNW: + return REAL_CAST(c1o216 * (drho + rho * (3.0 * (-vx1 + vx2 + vx3) + + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq))); + default: + throw UbException(UB_EXARGS, "unknown dir"); + } +} +////////////////////////////////////////////////////////////////////////// +static void calcCompFeq(LBMReal *const &feq /*[27]*/, const LBMReal &drho, const LBMReal &vx1, const LBMReal &vx2, + const LBMReal &vx3) +{ + using namespace UbMath; - LBMReal cu_sq = 1.5*(vx1*vx1+vx2*vx2+vx3*vx3); - LBMReal rho = drho+c1; + LBMReal cu_sq = 1.5 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); + LBMReal rho = drho + c1; - feq[ZERO] = c8o27*(drho+rho*(-cu_sq)); - feq[E] = c2o27*(drho+rho*(3.0*(vx1)+c9o2*(vx1)*(vx1)-cu_sq)); - feq[W] = c2o27*(drho+rho*(3.0*(-vx1)+c9o2*(-vx1)*(-vx1)-cu_sq)); - feq[N] = c2o27*(drho+rho*(3.0*(vx2)+c9o2*(vx2)*(vx2)-cu_sq)); - feq[S] = c2o27*(drho+rho*(3.0*(-vx2)+c9o2*(-vx2)*(-vx2)-cu_sq)); - feq[T] = c2o27*(drho+rho*(3.0*(vx3)+c9o2*(vx3)*(vx3)-cu_sq)); - feq[B] = c2o27*(drho+rho*(3.0*(-vx3)+c9o2*(-vx3)*(-vx3)-cu_sq)); - feq[NE] = c1o54*(drho+rho*(3.0*(vx1+vx2)+c9o2*(vx1+vx2)*(vx1+vx2)-cu_sq)); - feq[SW] = c1o54*(drho+rho*(3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq)); - feq[SE] = c1o54*(drho+rho*(3.0*(vx1-vx2)+c9o2*(vx1-vx2)*(vx1-vx2)-cu_sq)); - feq[NW] = c1o54*(drho+rho*(3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq)); - feq[TE] = c1o54*(drho+rho*(3.0*(vx1+vx3)+c9o2*(vx1+vx3)*(vx1+vx3)-cu_sq)); - feq[BW] = c1o54*(drho+rho*(3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq)); - feq[BE] = c1o54*(drho+rho*(3.0*(vx1-vx3)+c9o2*(vx1-vx3)*(vx1-vx3)-cu_sq)); - feq[TW] = c1o54*(drho+rho*(3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq)); - feq[TN] = c1o54*(drho+rho*(3.0*(vx2+vx3)+c9o2*(vx2+vx3)*(vx2+vx3)-cu_sq)); - feq[BS] = c1o54*(drho+rho*(3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq)); - feq[BN] = c1o54*(drho+rho*(3.0*(vx2-vx3)+c9o2*(vx2-vx3)*(vx2-vx3)-cu_sq)); - feq[TS] = c1o54*(drho+rho*(3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq)); - feq[TNE] = c1o216*(drho+rho*(3.0*(vx1+vx2+vx3)+c9o2*(vx1+vx2+vx3)*(vx1+vx2+vx3)-cu_sq)); - feq[BSW] = c1o216*(drho+rho*(3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq)); - feq[BNE] = c1o216*(drho+rho*(3.0*(vx1+vx2-vx3)+c9o2*(vx1+vx2-vx3)*(vx1+vx2-vx3)-cu_sq)); - feq[TSW] = c1o216*(drho+rho*(3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq)); - feq[TSE] = c1o216*(drho+rho*(3.0*(vx1-vx2+vx3)+c9o2*(vx1-vx2+vx3)*(vx1-vx2+vx3)-cu_sq)); - feq[BNW] = c1o216*(drho+rho*(3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq)); - feq[BSE] = c1o216*(drho+rho*(3.0*(vx1-vx2-vx3)+c9o2*(vx1-vx2-vx3)*(vx1-vx2-vx3)-cu_sq)); - feq[TNW] = c1o216*(drho+rho*(3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq)); - } - ////////////////////////////////////////////////////////////////////////// - static LBMReal getIncompFeqForDirection(const int& direction,const LBMReal& drho, const LBMReal& vx1,const LBMReal& vx2,const LBMReal& vx3) - { - using namespace UbMath; + feq[ZERO] = c8o27 * (drho + rho * (-cu_sq)); + feq[E] = c2o27 * (drho + rho * (3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq)); + feq[W] = c2o27 * (drho + rho * (3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq)); + feq[N] = c2o27 * (drho + rho * (3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq)); + feq[S] = c2o27 * (drho + rho * (3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq)); + feq[T] = c2o27 * (drho + rho * (3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq)); + feq[B] = c2o27 * (drho + rho * (3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq)); + feq[NE] = c1o54 * (drho + rho * (3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq)); + feq[SW] = c1o54 * (drho + rho * (3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq)); + feq[SE] = c1o54 * (drho + rho * (3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq)); + feq[NW] = c1o54 * (drho + rho * (3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq)); + feq[TE] = c1o54 * (drho + rho * (3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq)); + feq[BW] = c1o54 * (drho + rho * (3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq)); + feq[BE] = c1o54 * (drho + rho * (3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq)); + feq[TW] = c1o54 * (drho + rho * (3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq)); + feq[TN] = c1o54 * (drho + rho * (3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq)); + feq[BS] = c1o54 * (drho + rho * (3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq)); + feq[BN] = c1o54 * (drho + rho * (3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq)); + feq[TS] = c1o54 * (drho + rho * (3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq)); + feq[TNE] = c1o216 * (drho + rho * (3.0 * (vx1 + vx2 + vx3) + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq)); + feq[BSW] = + c1o216 * (drho + rho * (3.0 * (-vx1 - vx2 - vx3) + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq)); + feq[BNE] = c1o216 * (drho + rho * (3.0 * (vx1 + vx2 - vx3) + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq)); + feq[TSW] = + c1o216 * (drho + rho * (3.0 * (-vx1 - vx2 + vx3) + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq)); + feq[TSE] = c1o216 * (drho + rho * (3.0 * (vx1 - vx2 + vx3) + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq)); + feq[BNW] = + c1o216 * (drho + rho * (3.0 * (-vx1 + vx2 - vx3) + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq)); + feq[BSE] = c1o216 * (drho + rho * (3.0 * (vx1 - vx2 - vx3) + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq)); + feq[TNW] = + c1o216 * (drho + rho * (3.0 * (-vx1 + vx2 + vx3) + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq)); +} +////////////////////////////////////////////////////////////////////////// +static LBMReal getIncompFeqForDirection(const int &direction, const LBMReal &drho, const LBMReal &vx1, + const LBMReal &vx2, const LBMReal &vx3) +{ + using namespace UbMath; - LBMReal cu_sq=1.5f*(vx1*vx1+vx2*vx2+vx3*vx3); + LBMReal cu_sq = 1.5f * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); - switch(direction) - { - case ZERO : return REAL_CAST( c8o27*(drho-cu_sq)); - case E : return REAL_CAST( c2o27*(drho+3.0*( vx1 )+c9o2*( vx1 )*( vx1 )-cu_sq)); - case W : return REAL_CAST( c2o27*(drho+3.0*(-vx1 )+c9o2*(-vx1 )*(-vx1 )-cu_sq)); - case N : return REAL_CAST( c2o27*(drho+3.0*( vx2)+c9o2*( vx2)*( vx2)-cu_sq)); - case S : return REAL_CAST( c2o27*(drho+3.0*( -vx2)+c9o2*( -vx2)*( -vx2)-cu_sq)); - case T : return REAL_CAST( c2o27*(drho+3.0*( vx3 )+c9o2*( vx3)*( vx3)-cu_sq)); - case B : return REAL_CAST( c2o27*(drho+3.0*( -vx3)+c9o2*( -vx3)*( -vx3)-cu_sq)); - case NE : return REAL_CAST( c1o54*(drho+3.0*( vx1+vx2)+c9o2*( vx1+vx2)*( vx1+vx2)-cu_sq)); - case SW : return REAL_CAST( c1o54*(drho+3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq)); - case SE : return REAL_CAST( c1o54*(drho+3.0*( vx1-vx2)+c9o2*( vx1-vx2)*( vx1-vx2)-cu_sq)); - case NW : return REAL_CAST( c1o54*(drho+3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq)); - case TE : return REAL_CAST( c1o54*(drho+3.0*( vx1+vx3)+c9o2*( vx1+vx3)*( vx1+vx3)-cu_sq)); - case BW : return REAL_CAST( c1o54*(drho+3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq)); - case BE : return REAL_CAST( c1o54*(drho+3.0*( vx1-vx3)+c9o2*( vx1-vx3)*( vx1-vx3)-cu_sq)); - case TW : return REAL_CAST( c1o54*(drho+3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq)); - case TN : return REAL_CAST( c1o54*(drho+3.0*( vx2+vx3)+c9o2*( vx2+vx3)*( vx2+vx3)-cu_sq)); - case BS : return REAL_CAST( c1o54*(drho+3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq)); - case BN : return REAL_CAST( c1o54*(drho+3.0*( vx2-vx3)+c9o2*( vx2-vx3)*( vx2-vx3)-cu_sq)); - case TS : return REAL_CAST( c1o54*(drho+3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq)); - case TNE : return REAL_CAST(c1o216*(drho+3.0*( vx1+vx2+vx3)+c9o2*( vx1+vx2+vx3)*( vx1+vx2+vx3)-cu_sq)); - case BSW : return REAL_CAST(c1o216*(drho+3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq)); - case BNE : return REAL_CAST(c1o216*(drho+3.0*( vx1+vx2-vx3)+c9o2*( vx1+vx2-vx3)*( vx1+vx2-vx3)-cu_sq)); - case TSW : return REAL_CAST(c1o216*(drho+3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq)); - case TSE : return REAL_CAST(c1o216*(drho+3.0*( vx1-vx2+vx3)+c9o2*( vx1-vx2+vx3)*( vx1-vx2+vx3)-cu_sq)); - case BNW : return REAL_CAST(c1o216*(drho+3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq)); - case BSE : return REAL_CAST(c1o216*(drho+3.0*( vx1-vx2-vx3)+c9o2*( vx1-vx2-vx3)*( vx1-vx2-vx3)-cu_sq)); - case TNW : return REAL_CAST(c1o216*(drho+3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq)); - default: throw UbException(UB_EXARGS,"unknown dir"); - } - } - ////////////////////////////////////////////////////////////////////////// - static void calcIncompFeq(LBMReal* const& feq/*[27]*/,const LBMReal& drho,const LBMReal& vx1,const LBMReal& vx2,const LBMReal& vx3) - { - using namespace UbMath; + switch (direction) { + case ZERO: + return REAL_CAST(c8o27 * (drho - cu_sq)); + case E: + return REAL_CAST(c2o27 * (drho + 3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq)); + case W: + return REAL_CAST(c2o27 * (drho + 3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq)); + case N: + return REAL_CAST(c2o27 * (drho + 3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq)); + case S: + return REAL_CAST(c2o27 * (drho + 3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq)); + case T: + return REAL_CAST(c2o27 * (drho + 3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq)); + case B: + return REAL_CAST(c2o27 * (drho + 3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq)); + case NE: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq)); + case SW: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq)); + case SE: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq)); + case NW: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq)); + case TE: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq)); + case BW: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq)); + case BE: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq)); + case TW: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq)); + case TN: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq)); + case BS: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq)); + case BN: + return REAL_CAST(c1o54 * (drho + 3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq)); + case TS: + return REAL_CAST(c1o54 * (drho + 3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq)); + case TNE: + return REAL_CAST(c1o216 * + (drho + 3.0 * (vx1 + vx2 + vx3) + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq)); + case BSW: + return REAL_CAST( + c1o216 * (drho + 3.0 * (-vx1 - vx2 - vx3) + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq)); + case BNE: + return REAL_CAST(c1o216 * + (drho + 3.0 * (vx1 + vx2 - vx3) + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq)); + case TSW: + return REAL_CAST( + c1o216 * (drho + 3.0 * (-vx1 - vx2 + vx3) + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq)); + case TSE: + return REAL_CAST(c1o216 * + (drho + 3.0 * (vx1 - vx2 + vx3) + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq)); + case BNW: + return REAL_CAST( + c1o216 * (drho + 3.0 * (-vx1 + vx2 - vx3) + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq)); + case BSE: + return REAL_CAST(c1o216 * + (drho + 3.0 * (vx1 - vx2 - vx3) + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq)); + case TNW: + return REAL_CAST( + c1o216 * (drho + 3.0 * (-vx1 + vx2 + vx3) + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq)); + default: + throw UbException(UB_EXARGS, "unknown dir"); + } +} +////////////////////////////////////////////////////////////////////////// +static void calcIncompFeq(LBMReal *const &feq /*[27]*/, const LBMReal &drho, const LBMReal &vx1, const LBMReal &vx2, + const LBMReal &vx3) +{ + using namespace UbMath; - LBMReal cu_sq=1.5*(vx1*vx1+vx2*vx2+vx3*vx3); + LBMReal cu_sq = 1.5 * (vx1 * vx1 + vx2 * vx2 + vx3 * vx3); - feq[ZERO] = c8o27*(drho-cu_sq); - feq[E] = c2o27*(drho+3.0*( vx1 )+c9o2*( vx1 )*( vx1 )-cu_sq); - feq[W] = c2o27*(drho+3.0*(-vx1 )+c9o2*(-vx1 )*(-vx1 )-cu_sq); - feq[N] = c2o27*(drho+3.0*( vx2)+c9o2*( vx2)*( vx2)-cu_sq); - feq[S] = c2o27*(drho+3.0*( -vx2)+c9o2*( -vx2)*( -vx2)-cu_sq); - feq[T] = c2o27*(drho+3.0*( vx3 )+c9o2*( vx3)*( vx3)-cu_sq); - feq[B] = c2o27*(drho+3.0*( -vx3)+c9o2*( -vx3)*( -vx3)-cu_sq); - feq[NE] = c1o54*(drho+3.0*( vx1+vx2)+c9o2*( vx1+vx2)*( vx1+vx2)-cu_sq); - feq[SW] = c1o54*(drho+3.0*(-vx1-vx2)+c9o2*(-vx1-vx2)*(-vx1-vx2)-cu_sq); - feq[SE] = c1o54*(drho+3.0*( vx1-vx2)+c9o2*( vx1-vx2)*( vx1-vx2)-cu_sq); - feq[NW] = c1o54*(drho+3.0*(-vx1+vx2)+c9o2*(-vx1+vx2)*(-vx1+vx2)-cu_sq); - feq[TE] = c1o54*(drho+3.0*( vx1+vx3)+c9o2*( vx1+vx3)*( vx1+vx3)-cu_sq); - feq[BW] = c1o54*(drho+3.0*(-vx1-vx3)+c9o2*(-vx1-vx3)*(-vx1-vx3)-cu_sq); - feq[BE] = c1o54*(drho+3.0*( vx1-vx3)+c9o2*( vx1-vx3)*( vx1-vx3)-cu_sq); - feq[TW] = c1o54*(drho+3.0*(-vx1+vx3)+c9o2*(-vx1+vx3)*(-vx1+vx3)-cu_sq); - feq[TN] = c1o54*(drho+3.0*( vx2+vx3)+c9o2*( vx2+vx3)*( vx2+vx3)-cu_sq); - feq[BS] = c1o54*(drho+3.0*(-vx2-vx3)+c9o2*(-vx2-vx3)*(-vx2-vx3)-cu_sq); - feq[BN] = c1o54*(drho+3.0*( vx2-vx3)+c9o2*( vx2-vx3)*( vx2-vx3)-cu_sq); - feq[TS] = c1o54*(drho+3.0*(-vx2+vx3)+c9o2*(-vx2+vx3)*(-vx2+vx3)-cu_sq); - feq[TNE] = c1o216*(drho+3.0*( vx1+vx2+vx3)+c9o2*( vx1+vx2+vx3)*( vx1+vx2+vx3)-cu_sq); - feq[BSW] = c1o216*(drho+3.0*(-vx1-vx2-vx3)+c9o2*(-vx1-vx2-vx3)*(-vx1-vx2-vx3)-cu_sq); - feq[BNE] = c1o216*(drho+3.0*( vx1+vx2-vx3)+c9o2*( vx1+vx2-vx3)*( vx1+vx2-vx3)-cu_sq); - feq[TSW] = c1o216*(drho+3.0*(-vx1-vx2+vx3)+c9o2*(-vx1-vx2+vx3)*(-vx1-vx2+vx3)-cu_sq); - feq[TSE] = c1o216*(drho+3.0*( vx1-vx2+vx3)+c9o2*( vx1-vx2+vx3)*( vx1-vx2+vx3)-cu_sq); - feq[BNW] = c1o216*(drho+3.0*(-vx1+vx2-vx3)+c9o2*(-vx1+vx2-vx3)*(-vx1+vx2-vx3)-cu_sq); - feq[BSE] = c1o216*(drho+3.0*( vx1-vx2-vx3)+c9o2*( vx1-vx2-vx3)*( vx1-vx2-vx3)-cu_sq); - feq[TNW] = c1o216*(drho+3.0*(-vx1+vx2+vx3)+c9o2*(-vx1+vx2+vx3)*(-vx1+vx2+vx3)-cu_sq); - } - ////////////////////////////////////////////////////////////////////////// - static inline float getBoundaryVelocityForDirection(const int& direction, const float& bcVelocityX1,const float& bcVelocityX2,const float& bcVelocityX3) - { - using namespace UbMath; + feq[ZERO] = c8o27 * (drho - cu_sq); + feq[E] = c2o27 * (drho + 3.0 * (vx1) + c9o2 * (vx1) * (vx1)-cu_sq); + feq[W] = c2o27 * (drho + 3.0 * (-vx1) + c9o2 * (-vx1) * (-vx1) - cu_sq); + feq[N] = c2o27 * (drho + 3.0 * (vx2) + c9o2 * (vx2) * (vx2)-cu_sq); + feq[S] = c2o27 * (drho + 3.0 * (-vx2) + c9o2 * (-vx2) * (-vx2) - cu_sq); + feq[T] = c2o27 * (drho + 3.0 * (vx3) + c9o2 * (vx3) * (vx3)-cu_sq); + feq[B] = c2o27 * (drho + 3.0 * (-vx3) + c9o2 * (-vx3) * (-vx3) - cu_sq); + feq[NE] = c1o54 * (drho + 3.0 * (vx1 + vx2) + c9o2 * (vx1 + vx2) * (vx1 + vx2) - cu_sq); + feq[SW] = c1o54 * (drho + 3.0 * (-vx1 - vx2) + c9o2 * (-vx1 - vx2) * (-vx1 - vx2) - cu_sq); + feq[SE] = c1o54 * (drho + 3.0 * (vx1 - vx2) + c9o2 * (vx1 - vx2) * (vx1 - vx2) - cu_sq); + feq[NW] = c1o54 * (drho + 3.0 * (-vx1 + vx2) + c9o2 * (-vx1 + vx2) * (-vx1 + vx2) - cu_sq); + feq[TE] = c1o54 * (drho + 3.0 * (vx1 + vx3) + c9o2 * (vx1 + vx3) * (vx1 + vx3) - cu_sq); + feq[BW] = c1o54 * (drho + 3.0 * (-vx1 - vx3) + c9o2 * (-vx1 - vx3) * (-vx1 - vx3) - cu_sq); + feq[BE] = c1o54 * (drho + 3.0 * (vx1 - vx3) + c9o2 * (vx1 - vx3) * (vx1 - vx3) - cu_sq); + feq[TW] = c1o54 * (drho + 3.0 * (-vx1 + vx3) + c9o2 * (-vx1 + vx3) * (-vx1 + vx3) - cu_sq); + feq[TN] = c1o54 * (drho + 3.0 * (vx2 + vx3) + c9o2 * (vx2 + vx3) * (vx2 + vx3) - cu_sq); + feq[BS] = c1o54 * (drho + 3.0 * (-vx2 - vx3) + c9o2 * (-vx2 - vx3) * (-vx2 - vx3) - cu_sq); + feq[BN] = c1o54 * (drho + 3.0 * (vx2 - vx3) + c9o2 * (vx2 - vx3) * (vx2 - vx3) - cu_sq); + feq[TS] = c1o54 * (drho + 3.0 * (-vx2 + vx3) + c9o2 * (-vx2 + vx3) * (-vx2 + vx3) - cu_sq); + feq[TNE] = c1o216 * (drho + 3.0 * (vx1 + vx2 + vx3) + c9o2 * (vx1 + vx2 + vx3) * (vx1 + vx2 + vx3) - cu_sq); + feq[BSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 - vx3) + c9o2 * (-vx1 - vx2 - vx3) * (-vx1 - vx2 - vx3) - cu_sq); + feq[BNE] = c1o216 * (drho + 3.0 * (vx1 + vx2 - vx3) + c9o2 * (vx1 + vx2 - vx3) * (vx1 + vx2 - vx3) - cu_sq); + feq[TSW] = c1o216 * (drho + 3.0 * (-vx1 - vx2 + vx3) + c9o2 * (-vx1 - vx2 + vx3) * (-vx1 - vx2 + vx3) - cu_sq); + feq[TSE] = c1o216 * (drho + 3.0 * (vx1 - vx2 + vx3) + c9o2 * (vx1 - vx2 + vx3) * (vx1 - vx2 + vx3) - cu_sq); + feq[BNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 - vx3) + c9o2 * (-vx1 + vx2 - vx3) * (-vx1 + vx2 - vx3) - cu_sq); + feq[BSE] = c1o216 * (drho + 3.0 * (vx1 - vx2 - vx3) + c9o2 * (vx1 - vx2 - vx3) * (vx1 - vx2 - vx3) - cu_sq); + feq[TNW] = c1o216 * (drho + 3.0 * (-vx1 + vx2 + vx3) + c9o2 * (-vx1 + vx2 + vx3) * (-vx1 + vx2 + vx3) - cu_sq); +} +////////////////////////////////////////////////////////////////////////// +static inline float getBoundaryVelocityForDirection(const int &direction, const float &bcVelocityX1, + const float &bcVelocityX2, const float &bcVelocityX3) +{ + using namespace UbMath; - switch(direction) - { - case E: return (float)( UbMath::c4o9*(+bcVelocityX1) ); - case W: return (float)( UbMath::c4o9*(-bcVelocityX1) ); - case N: return (float)( UbMath::c4o9*(+bcVelocityX2) ); - case S: return (float)( UbMath::c4o9*(-bcVelocityX2) ); - case T: return (float)( UbMath::c4o9*(+bcVelocityX3) ); - case B: return (float)( UbMath::c4o9*(-bcVelocityX3) ); - case NE: return (float)( UbMath::c1o9*(+bcVelocityX1+bcVelocityX2 ) ); - case SW: return (float)( UbMath::c1o9*(-bcVelocityX1-bcVelocityX2 ) ); - case SE: return (float)( UbMath::c1o9*(+bcVelocityX1-bcVelocityX2 ) ); - case NW: return (float)( UbMath::c1o9*(-bcVelocityX1+bcVelocityX2 ) ); - case TE: return (float)( UbMath::c1o9*(+bcVelocityX1 +bcVelocityX3) ); - case BW: return (float)( UbMath::c1o9*(-bcVelocityX1 -bcVelocityX3) ); - case BE: return (float)( UbMath::c1o9*(+bcVelocityX1 -bcVelocityX3) ); - case TW: return (float)( UbMath::c1o9*(-bcVelocityX1 +bcVelocityX3) ); - case TN: return (float)( UbMath::c1o9*( +bcVelocityX2+bcVelocityX3) ); - case BS: return (float)( UbMath::c1o9*( -bcVelocityX2-bcVelocityX3) ); - case BN: return (float)( UbMath::c1o9*( +bcVelocityX2-bcVelocityX3) ); - case TS: return (float)( UbMath::c1o9*( -bcVelocityX2+bcVelocityX3) ); - case TNE: return (float)( UbMath::c1o36*(+bcVelocityX1+bcVelocityX2+bcVelocityX3) ); - case BSW: return (float)( UbMath::c1o36*(-bcVelocityX1-bcVelocityX2-bcVelocityX3) ); - case BNE: return (float)( UbMath::c1o36*(+bcVelocityX1+bcVelocityX2-bcVelocityX3) ); - case TSW: return (float)( UbMath::c1o36*(-bcVelocityX1-bcVelocityX2+bcVelocityX3) ); - case TSE: return (float)( UbMath::c1o36*(+bcVelocityX1-bcVelocityX2+bcVelocityX3) ); - case BNW: return (float)( UbMath::c1o36*(-bcVelocityX1+bcVelocityX2-bcVelocityX3) ); - case BSE: return (float)( UbMath::c1o36*(+bcVelocityX1-bcVelocityX2-bcVelocityX3) ); - case TNW: return (float)( UbMath::c1o36*(-bcVelocityX1+bcVelocityX2+bcVelocityX3) ); - default: throw UbException(UB_EXARGS,"unknown direction"); - } - } - /*=====================================================================*/ - static const int& getInvertDirection(const int& direction) - { - #ifdef _DEBUG - if(direction<STARTDIR || direction>ENDDIR) - throw UbException(UB_EXARGS,"unknown direction"); - #endif - return INVDIR[direction]; - } - /*=====================================================================*/ - static void getLBMDirections(std::vector<int>& dirs, bool onlyLBdirs = false) - { - std::vector<int> D3Q27Dirs; - if(onlyLBdirs) /*FSTARTDIR->FENDDIR*/ - { - dirs.resize(FENDDIR+1); - for(int dir=FSTARTDIR; dir<=FENDDIR; ++dir) + switch (direction) { + case E: + return (float)(UbMath::c4o9 * (+bcVelocityX1)); + case W: + return (float)(UbMath::c4o9 * (-bcVelocityX1)); + case N: + return (float)(UbMath::c4o9 * (+bcVelocityX2)); + case S: + return (float)(UbMath::c4o9 * (-bcVelocityX2)); + case T: + return (float)(UbMath::c4o9 * (+bcVelocityX3)); + case B: + return (float)(UbMath::c4o9 * (-bcVelocityX3)); + case NE: + return (float)(UbMath::c1o9 * (+bcVelocityX1 + bcVelocityX2)); + case SW: + return (float)(UbMath::c1o9 * (-bcVelocityX1 - bcVelocityX2)); + case SE: + return (float)(UbMath::c1o9 * (+bcVelocityX1 - bcVelocityX2)); + case NW: + return (float)(UbMath::c1o9 * (-bcVelocityX1 + bcVelocityX2)); + case TE: + return (float)(UbMath::c1o9 * (+bcVelocityX1 + bcVelocityX3)); + case BW: + return (float)(UbMath::c1o9 * (-bcVelocityX1 - bcVelocityX3)); + case BE: + return (float)(UbMath::c1o9 * (+bcVelocityX1 - bcVelocityX3)); + case TW: + return (float)(UbMath::c1o9 * (-bcVelocityX1 + bcVelocityX3)); + case TN: + return (float)(UbMath::c1o9 * (+bcVelocityX2 + bcVelocityX3)); + case BS: + return (float)(UbMath::c1o9 * (-bcVelocityX2 - bcVelocityX3)); + case BN: + return (float)(UbMath::c1o9 * (+bcVelocityX2 - bcVelocityX3)); + case TS: + return (float)(UbMath::c1o9 * (-bcVelocityX2 + bcVelocityX3)); + case TNE: + return (float)(UbMath::c1o36 * (+bcVelocityX1 + bcVelocityX2 + bcVelocityX3)); + case BSW: + return (float)(UbMath::c1o36 * (-bcVelocityX1 - bcVelocityX2 - bcVelocityX3)); + case BNE: + return (float)(UbMath::c1o36 * (+bcVelocityX1 + bcVelocityX2 - bcVelocityX3)); + case TSW: + return (float)(UbMath::c1o36 * (-bcVelocityX1 - bcVelocityX2 + bcVelocityX3)); + case TSE: + return (float)(UbMath::c1o36 * (+bcVelocityX1 - bcVelocityX2 + bcVelocityX3)); + case BNW: + return (float)(UbMath::c1o36 * (-bcVelocityX1 + bcVelocityX2 - bcVelocityX3)); + case BSE: + return (float)(UbMath::c1o36 * (+bcVelocityX1 - bcVelocityX2 - bcVelocityX3)); + case TNW: + return (float)(UbMath::c1o36 * (-bcVelocityX1 + bcVelocityX2 + bcVelocityX3)); + default: + throw UbException(UB_EXARGS, "unknown direction"); + } +} +/*=====================================================================*/ +static const int &getInvertDirection(const int &direction) +{ +#ifdef _DEBUG + if (direction < STARTDIR || direction > ENDDIR) + throw UbException(UB_EXARGS, "unknown direction"); +#endif + return INVDIR[direction]; +} +/*=====================================================================*/ +static void getLBMDirections(std::vector<int> &dirs, bool onlyLBdirs = false) +{ + std::vector<int> D3Q27Dirs; + if (onlyLBdirs) /*FSTARTDIR->FENDDIR*/ + { + dirs.resize(FENDDIR + 1); + for (int dir = FSTARTDIR; dir <= FENDDIR; ++dir) dirs[dir] = dir; - } - else /*STARTDIR->ENDDIR*/ - { - dirs.resize(ENDDIR+1); - for(int dir=STARTDIR; dir<=ENDDIR; ++dir) + } else /*STARTDIR->ENDDIR*/ + { + dirs.resize(ENDDIR + 1); + for (int dir = STARTDIR; dir <= ENDDIR; ++dir) dirs[dir] = dir; - } - } + } +} ////////////////////////////////////////////////////////////////////////// - static std::vector<int> getEX(const int& exn) - { - std::vector<int> ex; - ex.resize(ENDDIR+1); - switch (exn) - { - case 1: - for(int dir=STARTDIR; dir<ENDDIR; ++dir) - ex[dir] = DX1[dir]; - break; - case 2: - for(int dir=STARTDIR; dir<ENDDIR; ++dir) - ex[dir] = DX2[dir]; - break; - case 3: - for(int dir=STARTDIR; dir<ENDDIR; ++dir) - ex[dir] = DX3[dir]; - break; - } - return ex; - } +static std::vector<int> getEX(const int &exn) +{ + std::vector<int> ex; + ex.resize(ENDDIR + 1); + switch (exn) { + case 1: + for (int dir = STARTDIR; dir < ENDDIR; ++dir) + ex[dir] = DX1[dir]; + break; + case 2: + for (int dir = STARTDIR; dir < ENDDIR; ++dir) + ex[dir] = DX2[dir]; + break; + case 3: + for (int dir = STARTDIR; dir < ENDDIR; ++dir) + ex[dir] = DX3[dir]; + break; + } + return ex; +} ////////////////////////////////////////////////////////////////////////// - static inline void calcDistanceToNeighbors(std::vector<double>& distNeigh, const double& deltaX1) - { - //distNeigh.resize(FENDDIR+1, UbMath::sqrt2*deltaX1); - double sqrt3 = UbMath::sqrt3; - double sqrt2 = UbMath::sqrt2; - distNeigh[E] = distNeigh[W] = distNeigh[N] = deltaX1; - distNeigh[S] = distNeigh[T] = distNeigh[B] = deltaX1; - distNeigh[NE] = distNeigh[NW] = distNeigh[SW] = distNeigh[SE] = sqrt2*deltaX1; - distNeigh[TE] = distNeigh[TN] = distNeigh[TW] = distNeigh[TS] = sqrt2*deltaX1; - distNeigh[BE] = distNeigh[BN] = distNeigh[BW] = distNeigh[BS] = sqrt2*deltaX1; - distNeigh[TNE] = distNeigh[TNW] = distNeigh[TSE] = distNeigh[TSW] = sqrt3*deltaX1; - distNeigh[BNE] = distNeigh[BNW] = distNeigh[BSE] = distNeigh[BSW] = sqrt3*deltaX1; - } +static inline void calcDistanceToNeighbors(std::vector<double> &distNeigh, const double &deltaX1) +{ + // distNeigh.resize(FENDDIR+1, UbMath::sqrt2*deltaX1); + double sqrt3 = UbMath::sqrt3; + double sqrt2 = UbMath::sqrt2; + distNeigh[E] = distNeigh[W] = distNeigh[N] = deltaX1; + distNeigh[S] = distNeigh[T] = distNeigh[B] = deltaX1; + distNeigh[NE] = distNeigh[NW] = distNeigh[SW] = distNeigh[SE] = sqrt2 * deltaX1; + distNeigh[TE] = distNeigh[TN] = distNeigh[TW] = distNeigh[TS] = sqrt2 * deltaX1; + distNeigh[BE] = distNeigh[BN] = distNeigh[BW] = distNeigh[BS] = sqrt2 * deltaX1; + distNeigh[TNE] = distNeigh[TNW] = distNeigh[TSE] = distNeigh[TSW] = sqrt3 * deltaX1; + distNeigh[BNE] = distNeigh[BNW] = distNeigh[BSE] = distNeigh[BSW] = sqrt3 * deltaX1; +} ////////////////////////////////////////////////////////////////////////// - static inline void calcDistanceToNeighbors(std::vector<double>& distNeigh, const double& deltaX1,const double& deltaX2,const double& deltaX3) - { - //distNeigh.resize(FENDDIR+1, UbMath::sqrt2*deltaX1); - distNeigh[E] = distNeigh[W] = deltaX1; - distNeigh[N] = distNeigh[S] = deltaX2; - distNeigh[T] = distNeigh[B] = deltaX3; - distNeigh[NE] = distNeigh[NW] = distNeigh[SW] = distNeigh[SE] = sqrt(deltaX1*deltaX1+deltaX2*deltaX2); - distNeigh[TE] = distNeigh[TN] = distNeigh[TW] = distNeigh[TS] = sqrt(deltaX1*deltaX1+deltaX3*deltaX3); - distNeigh[BE] = distNeigh[BN] = distNeigh[BW] = distNeigh[BS] = sqrt(deltaX2*deltaX2+deltaX3*deltaX3); - distNeigh[TNE] = distNeigh[TNW] = distNeigh[TSE] = distNeigh[TSW] = sqrt(deltaX1*deltaX1+deltaX2*deltaX2+deltaX3*deltaX3); - distNeigh[BNE] = distNeigh[BNW] = distNeigh[BSE] = distNeigh[BSW] = sqrt(deltaX1*deltaX1+deltaX2*deltaX2+deltaX3*deltaX3); - } +static inline void calcDistanceToNeighbors(std::vector<double> &distNeigh, const double &deltaX1, const double &deltaX2, + const double &deltaX3) +{ + // distNeigh.resize(FENDDIR+1, UbMath::sqrt2*deltaX1); + distNeigh[E] = distNeigh[W] = deltaX1; + distNeigh[N] = distNeigh[S] = deltaX2; + distNeigh[T] = distNeigh[B] = deltaX3; + distNeigh[NE] = distNeigh[NW] = distNeigh[SW] = distNeigh[SE] = sqrt(deltaX1 * deltaX1 + deltaX2 * deltaX2); + distNeigh[TE] = distNeigh[TN] = distNeigh[TW] = distNeigh[TS] = sqrt(deltaX1 * deltaX1 + deltaX3 * deltaX3); + distNeigh[BE] = distNeigh[BN] = distNeigh[BW] = distNeigh[BS] = sqrt(deltaX2 * deltaX2 + deltaX3 * deltaX3); + distNeigh[TNE] = distNeigh[TNW] = distNeigh[TSE] = distNeigh[TSW] = + sqrt(deltaX1 * deltaX1 + deltaX2 * deltaX2 + deltaX3 * deltaX3); + distNeigh[BNE] = distNeigh[BNW] = distNeigh[BSE] = distNeigh[BSW] = + sqrt(deltaX1 * deltaX1 + deltaX2 * deltaX2 + deltaX3 * deltaX3); +} ////////////////////////////////////////////////////////////////////////// - static inline void initRayVectors(double* const& rayX1, double* const& rayX2, double* const& rayX3) - { - using namespace UbMath; +static inline void initRayVectors(double *const &rayX1, double *const &rayX2, double *const &rayX3) +{ + using namespace UbMath; - int fdir; - double c1oS2 = UbMath::one_over_sqrt2; - double c1oS3 = UbMath::one_over_sqrt3; - fdir = E; rayX1[fdir] = 1.0; rayX2[fdir] = 0.0; rayX3[fdir] = 0.0; - fdir = W; rayX1[fdir] = -1.0; rayX2[fdir] = 0.0; rayX3[fdir] = 0.0; - fdir = N; rayX1[fdir] = 0.0; rayX2[fdir] = 1.0; rayX3[fdir] = 0.0; - fdir = S; rayX1[fdir] = 0.0; rayX2[fdir] = -1.0; rayX3[fdir] = 0.0; - fdir = T; rayX1[fdir] = 0.0; rayX2[fdir] = 0.0; rayX3[fdir] = 1.0; - fdir = B; rayX1[fdir] = 0.0; rayX2[fdir] = 0.0; rayX3[fdir] = -1.0; - fdir = NE; rayX1[fdir] = c1oS2; rayX2[fdir] = c1oS2; rayX3[fdir] = 0.0; - fdir = SW; rayX1[fdir] = -c1oS2; rayX2[fdir] = -c1oS2; rayX3[fdir] = 0.0; - fdir = SE; rayX1[fdir] = c1oS2; rayX2[fdir] = -c1oS2; rayX3[fdir] = 0.0; - fdir = NW; rayX1[fdir] = -c1oS2; rayX2[fdir] = c1oS2; rayX3[fdir] = 0.0; - fdir = TE; rayX1[fdir] = c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = c1oS2; - fdir = BW; rayX1[fdir] = -c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = -c1oS2; - fdir = BE; rayX1[fdir] = c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = -c1oS2; - fdir = TW; rayX1[fdir] = -c1oS2; rayX2[fdir] = 0.0; rayX3[fdir] = c1oS2; - fdir = TN; rayX1[fdir] = 0.0; rayX2[fdir] = c1oS2; rayX3[fdir] = c1oS2; - fdir = BS; rayX1[fdir] = 0.0; rayX2[fdir] =-c1oS2; rayX3[fdir] = -c1oS2; - fdir = BN; rayX1[fdir] = 0.0; rayX2[fdir] = c1oS2; rayX3[fdir] = -c1oS2; - fdir = TS; rayX1[fdir] = 0.0; rayX2[fdir] =-c1oS2; rayX3[fdir] = c1oS2; - fdir = TNE; rayX1[fdir] = c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = c1oS3; - fdir = TNW; rayX1[fdir] = -c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = c1oS3; - fdir = TSE; rayX1[fdir] = c1oS3; rayX2[fdir] = -c1oS3; rayX3[fdir] = c1oS3; - fdir = TSW; rayX1[fdir] = -c1oS3; rayX2[fdir] = -c1oS3; rayX3[fdir] = c1oS3; - fdir = BNE; rayX1[fdir] = c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = -c1oS3; - fdir = BNW; rayX1[fdir] = -c1oS3; rayX2[fdir] = c1oS3; rayX3[fdir] = -c1oS3; - fdir = BSE; rayX1[fdir] = c1oS3; rayX2[fdir] = -c1oS3; rayX3[fdir] = -c1oS3; - fdir = BSW; rayX1[fdir] = -c1oS3; rayX2[fdir] = -c1oS3; rayX3[fdir] = -c1oS3; - } + int fdir; + double c1oS2 = UbMath::one_over_sqrt2; + double c1oS3 = UbMath::one_over_sqrt3; + fdir = E; + rayX1[fdir] = 1.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 0.0; + fdir = W; + rayX1[fdir] = -1.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 0.0; + fdir = N; + rayX1[fdir] = 0.0; + rayX2[fdir] = 1.0; + rayX3[fdir] = 0.0; + fdir = S; + rayX1[fdir] = 0.0; + rayX2[fdir] = -1.0; + rayX3[fdir] = 0.0; + fdir = T; + rayX1[fdir] = 0.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = 1.0; + fdir = B; + rayX1[fdir] = 0.0; + rayX2[fdir] = 0.0; + rayX3[fdir] = -1.0; + fdir = NE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = c1oS2; + rayX3[fdir] = 0.0; + fdir = SW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = 0.0; + fdir = SE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = 0.0; + fdir = NW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = c1oS2; + rayX3[fdir] = 0.0; + fdir = TE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = c1oS2; + fdir = BW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = -c1oS2; + fdir = BE; + rayX1[fdir] = c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = -c1oS2; + fdir = TW; + rayX1[fdir] = -c1oS2; + rayX2[fdir] = 0.0; + rayX3[fdir] = c1oS2; + fdir = TN; + rayX1[fdir] = 0.0; + rayX2[fdir] = c1oS2; + rayX3[fdir] = c1oS2; + fdir = BS; + rayX1[fdir] = 0.0; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = -c1oS2; + fdir = BN; + rayX1[fdir] = 0.0; + rayX2[fdir] = c1oS2; + rayX3[fdir] = -c1oS2; + fdir = TS; + rayX1[fdir] = 0.0; + rayX2[fdir] = -c1oS2; + rayX3[fdir] = c1oS2; + fdir = TNE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = c1oS3; + fdir = TNW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = c1oS3; + fdir = TSE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = c1oS3; + fdir = TSW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = c1oS3; + fdir = BNE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = -c1oS3; + fdir = BNW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = c1oS3; + rayX3[fdir] = -c1oS3; + fdir = BSE; + rayX1[fdir] = c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = -c1oS3; + fdir = BSW; + rayX1[fdir] = -c1oS3; + rayX2[fdir] = -c1oS3; + rayX3[fdir] = -c1oS3; +} ////////////////////////////////////////////////////////////////////////// - static inline LBMReal calcPress(const LBMReal* const f, LBMReal rho, LBMReal vx1, LBMReal vx2, LBMReal vx3) - { - using namespace UbMath; - LBMReal OxxPyyPzz = c1; - return ((f[E]+f[W]+f[N]+f[S]+f[T]+f[B]+c2*(f[NE]+f[SW]+f[SE]+f[NW]+f[TE]+f[BW]+f[BE]+f[TW]+f[TN]+f[BS]+f[BN]+f[TS])+ - c3*(f[TNE]+f[TSW]+f[TSE]+f[TNW]+f[BNE]+f[BSW]+f[BSE]+f[BNW])-(vx1*vx1+vx2*vx2+vx3*vx3))*(c1-c1o2*OxxPyyPzz)+OxxPyyPzz*c1o2*(rho))*c1o3; - } +static inline LBMReal calcPress(const LBMReal *const f, LBMReal rho, LBMReal vx1, LBMReal vx2, LBMReal vx3) +{ + using namespace UbMath; + LBMReal OxxPyyPzz = c1; + return ((f[E] + f[W] + f[N] + f[S] + f[T] + f[B] + + c2 * (f[NE] + f[SW] + f[SE] + f[NW] + f[TE] + f[BW] + f[BE] + f[TW] + f[TN] + f[BS] + f[BN] + f[TS]) + + c3 * (f[TNE] + f[TSW] + f[TSE] + f[TNW] + f[BNE] + f[BSW] + f[BSE] + f[BNW]) - + (vx1 * vx1 + vx2 * vx2 + vx3 * vx3)) * + (c1 - c1o2 * OxxPyyPzz) + + OxxPyyPzz * c1o2 * (rho)) * + c1o3; } +} // namespace D3Q27System #endif - - - diff --git a/src/cpu/VirtualFluidsCore/LBM/ICell.h b/src/cpu/VirtualFluidsCore/LBM/ICell.h index 897a4134f..c080033b8 100644 --- a/src/cpu/VirtualFluidsCore/LBM/ICell.h +++ b/src/cpu/VirtualFluidsCore/LBM/ICell.h @@ -4,30 +4,29 @@ #include "LBMSystem.h" #include <vector> -struct ICell3D -{ - ICell3D(int size); +struct ICell3D { + ICell3D(int size); - std::vector<LBMReal> TSW; - std::vector<LBMReal> TNW; - std::vector<LBMReal> TNE; - std::vector<LBMReal> TSE; - std::vector<LBMReal> BSW; - std::vector<LBMReal> BNW; - std::vector<LBMReal> BNE; - std::vector<LBMReal> BSE; + std::vector<LBMReal> TSW; + std::vector<LBMReal> TNW; + std::vector<LBMReal> TNE; + std::vector<LBMReal> TSE; + std::vector<LBMReal> BSW; + std::vector<LBMReal> BNW; + std::vector<LBMReal> BNE; + std::vector<LBMReal> BSE; }; inline ICell3D::ICell3D(int size) { - TSW.resize(size); - TNW.resize(size); - TNE.resize(size); - TSE.resize(size); - BSW.resize(size); - BNW.resize(size); - BNE.resize(size); - BSE.resize(size); + TSW.resize(size); + TNW.resize(size); + TNE.resize(size); + TSE.resize(size); + BSW.resize(size); + BNW.resize(size); + BNE.resize(size); + BSE.resize(size); } #endif diff --git a/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h index 71ed3246c..4dbe8eee0 100644 --- a/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/ILBMKernel.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -45,20 +45,20 @@ class ILBMKernel public: virtual ~ILBMKernel() = default; - virtual void calculate(int step) = 0; + virtual void calculate(int step) = 0; virtual double getCalculationTime() = 0; - virtual void swapDistributions() = 0; + virtual void swapDistributions() = 0; - virtual bool getCompressible() const = 0; - virtual SPtr<BCProcessor> getBCProcessor() const = 0; - virtual void setBCProcessor(SPtr<BCProcessor> bcProcessor) = 0; - virtual SPtr<DataSet3D> getDataSet() const = 0; - virtual double getCollisionFactor() const = 0; - virtual void setCollisionFactor(double collFactor) = 0; + virtual bool getCompressible() const = 0; + virtual SPtr<BCProcessor> getBCProcessor() const = 0; + virtual void setBCProcessor(SPtr<BCProcessor> bcProcessor) = 0; + virtual SPtr<DataSet3D> getDataSet() const = 0; + virtual double getCollisionFactor() const = 0; + virtual void setCollisionFactor(double collFactor) = 0; virtual bool isInsideOfDomain(const int &x1, const int &x2, const int &x3) const = 0; - virtual int getGhostLayerWidth() const = 0; - virtual double getDeltaT() const = 0; - virtual bool getWithForcing() const = 0; + virtual int getGhostLayerWidth() const = 0; + virtual double getDeltaT() const = 0; + virtual bool getWithForcing() const = 0; }; #endif diff --git a/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.cpp b/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.cpp index 0942a9f06..efe2c8e7c 100644 --- a/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.cpp @@ -1,37 +1,34 @@ #include "InterpolationHelper.h" - - -InterpolationHelper::InterpolationHelper(InterpolationProcessorPtr iProcessor) : iProcessor(iProcessor) -{ - -} +InterpolationHelper::InterpolationHelper(InterpolationProcessorPtr iProcessor) : iProcessor(iProcessor) {} ////////////////////////////////////////////////////////////////////////// -InterpolationHelper::~InterpolationHelper() -= default; +InterpolationHelper::~InterpolationHelper() = default; ////////////////////////////////////////////////////////////////////////// -void InterpolationHelper::interpolate8to1( D3Q27ICell& icellF, LBMReal* icellC, double /*x1*/, double /*x2*/, double /*x3*/, LBMReal omega ) +void InterpolationHelper::interpolate8to1(D3Q27ICell &icellF, LBMReal *icellC, double /*x1*/, double /*x2*/, + double /*x3*/, LBMReal omega) { - iProcessor->calcInterpolatedCoefficiets(icellF, omega, 1.0); - iProcessor->calcInterpolatedNodeFC(icellC, omega); + iProcessor->calcInterpolatedCoefficiets(icellF, omega, 1.0); + iProcessor->calcInterpolatedNodeFC(icellC, omega); } ////////////////////////////////////////////////////////////////////////// -void InterpolationHelper::interpolate8to1WithVelocity( D3Q27ICell& icellF, double x1, double x2, double x3, LBMReal omega, LBMReal &vx1, LBMReal &vx2, LBMReal &vx3 ) +void InterpolationHelper::interpolate8to1WithVelocity(D3Q27ICell &icellF, double x1, double x2, double x3, + LBMReal omega, LBMReal &vx1, LBMReal &vx2, LBMReal &vx3) { - iProcessor->setOffsets(0.0, 0.0, 0.0); - iProcessor->calcInterpolatedCoefficiets(icellF, omega, 0.0); - iProcessor->calcInterpolatedVelocity(x1, x2, x3, vx1, vx2, vx3); + iProcessor->setOffsets(0.0, 0.0, 0.0); + iProcessor->calcInterpolatedCoefficiets(icellF, omega, 0.0); + iProcessor->calcInterpolatedVelocity(x1, x2, x3, vx1, vx2, vx3); } ////////////////////////////////////////////////////////////////////////// -void InterpolationHelper::interpolate8to1WithVelocityWithShearStress( D3Q27ICell& icellF, double x1, double x2, double x3, LBMReal omega, - LBMReal &vx1, LBMReal &vx2, LBMReal &vx3, - LBMReal &tauxx, LBMReal &tauyy, LBMReal &tauzz,LBMReal &tauxy, LBMReal &tauxz, LBMReal &tauyz ) +void InterpolationHelper::interpolate8to1WithVelocityWithShearStress(D3Q27ICell &icellF, double x1, double x2, + double x3, LBMReal omega, LBMReal &vx1, + LBMReal &vx2, LBMReal &vx3, LBMReal &tauxx, + LBMReal &tauyy, LBMReal &tauzz, LBMReal &tauxy, + LBMReal &tauxz, LBMReal &tauyz) { - iProcessor->setOffsets(0.0, 0.0, 0.0); - iProcessor->calcInterpolatedCoefficiets(icellF, omega, 0.0); - iProcessor->calcInterpolatedVelocity(x1, x2, x3, vx1, vx2, vx3); - iProcessor->calcInterpolatedShearStress(x1,x2,x3,tauxx,tauyy,tauzz,tauxy,tauxz,tauyz); + iProcessor->setOffsets(0.0, 0.0, 0.0); + iProcessor->calcInterpolatedCoefficiets(icellF, omega, 0.0); + iProcessor->calcInterpolatedVelocity(x1, x2, x3, vx1, vx2, vx3); + iProcessor->calcInterpolatedShearStress(x1, x2, x3, tauxx, tauyy, tauzz, tauxy, tauxz, tauyz); } ////////////////////////////////////////////////////////////////////////// - diff --git a/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.h b/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.h index 56cedd8f7..0e7318a8c 100644 --- a/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.h +++ b/src/cpu/VirtualFluidsCore/LBM/InterpolationHelper.h @@ -9,17 +9,19 @@ using InterpolationHelperPtr = SPtr<InterpolationHelper>; class InterpolationHelper { public: - InterpolationHelper(InterpolationProcessorPtr iProcessor); - ~InterpolationHelper(); - void interpolate8to1(D3Q27ICell& icellF, LBMReal* icellC, double x1, double x2, double x3, LBMReal omega); - void interpolate8to1WithVelocity(D3Q27ICell& icellF, double x1, double x2, double x3, LBMReal omega, LBMReal &vx1, LBMReal &vx2, LBMReal &vx3); - void interpolate8to1WithVelocityWithShearStress(D3Q27ICell& icellF, double x1, double x2, double x3, LBMReal omega, - LBMReal &vx1, LBMReal &vx2, LBMReal &vx3, - LBMReal &tauxx, LBMReal &tauyy, LBMReal &tauzz,LBMReal &tauxy, LBMReal &tauxz, LBMReal &tauyz); + InterpolationHelper(InterpolationProcessorPtr iProcessor); + ~InterpolationHelper(); + void interpolate8to1(D3Q27ICell &icellF, LBMReal *icellC, double x1, double x2, double x3, LBMReal omega); + void interpolate8to1WithVelocity(D3Q27ICell &icellF, double x1, double x2, double x3, LBMReal omega, LBMReal &vx1, + LBMReal &vx2, LBMReal &vx3); + void interpolate8to1WithVelocityWithShearStress(D3Q27ICell &icellF, double x1, double x2, double x3, LBMReal omega, + LBMReal &vx1, LBMReal &vx2, LBMReal &vx3, LBMReal &tauxx, + LBMReal &tauyy, LBMReal &tauzz, LBMReal &tauxy, LBMReal &tauxz, + LBMReal &tauyz); + protected: private: - InterpolationProcessorPtr iProcessor; + InterpolationProcessorPtr iProcessor; }; #endif - diff --git a/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.cpp b/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.cpp index 60893e2b2..8d2a4163b 100644 --- a/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.cpp @@ -1,309 +1,333 @@ #include "InterpolationProcessor.h" - ////////////////////////////////////////////////////////////////////////// -InterpolationProcessor::InterpolationProcessor() -= default; +InterpolationProcessor::InterpolationProcessor() = default; ////////////////////////////////////////////////////////////////////////// -InterpolationProcessor::~InterpolationProcessor() -= default; +InterpolationProcessor::~InterpolationProcessor() = default; ////////////////////////////////////////////////////////////////////////// -void InterpolationProcessor::readICell(SPtr<DistributionArray3D> f, D3Q27ICell& icell, int x1, int x2, int x3) +void InterpolationProcessor::readICell(SPtr<DistributionArray3D> f, D3Q27ICell &icell, int x1, int x2, int x3) { - f->getDistribution(icell.BSW, x1, x2, x3); - f->getDistribution(icell.BSE, x1+1, x2, x3); - f->getDistribution(icell.BNW, x1, x2+1, x3); - f->getDistribution(icell.BNE, x1+1, x2+1, x3); - f->getDistribution(icell.TSW, x1, x2, x3+1); - f->getDistribution(icell.TSE, x1+1, x2, x3+1); - f->getDistribution(icell.TNW, x1, x2+1, x3+1); - f->getDistribution(icell.TNE, x1+1, x2+1, x3+1); + f->getDistribution(icell.BSW, x1, x2, x3); + f->getDistribution(icell.BSE, x1 + 1, x2, x3); + f->getDistribution(icell.BNW, x1, x2 + 1, x3); + f->getDistribution(icell.BNE, x1 + 1, x2 + 1, x3); + f->getDistribution(icell.TSW, x1, x2, x3 + 1); + f->getDistribution(icell.TSE, x1 + 1, x2, x3 + 1); + f->getDistribution(icell.TNW, x1, x2 + 1, x3 + 1); + f->getDistribution(icell.TNE, x1 + 1, x2 + 1, x3 + 1); } ////////////////////////////////////////////////////////////////////////// -void InterpolationProcessor::writeICell(SPtr<DistributionArray3D> f, const D3Q27ICell& icell, int x1, int x2, int x3) +void InterpolationProcessor::writeICell(SPtr<DistributionArray3D> f, const D3Q27ICell &icell, int x1, int x2, int x3) { - f->setDistribution(icell.BSW, x1, x2, x3); - f->setDistribution(icell.BSE, x1+1, x2, x3); - f->setDistribution(icell.BNW, x1, x2+1, x3); - f->setDistribution(icell.BNE, x1+1, x2+1, x3); - f->setDistribution(icell.TSW, x1, x2, x3+1); - f->setDistribution(icell.TSE, x1+1, x2, x3+1); - f->setDistribution(icell.TNW, x1, x2+1, x3+1); - f->setDistribution(icell.TNE, x1+1, x2+1, x3+1); + f->setDistribution(icell.BSW, x1, x2, x3); + f->setDistribution(icell.BSE, x1 + 1, x2, x3); + f->setDistribution(icell.BNW, x1, x2 + 1, x3); + f->setDistribution(icell.BNE, x1 + 1, x2 + 1, x3); + f->setDistribution(icell.TSW, x1, x2, x3 + 1); + f->setDistribution(icell.TSE, x1 + 1, x2, x3 + 1); + f->setDistribution(icell.TNW, x1, x2 + 1, x3 + 1); + f->setDistribution(icell.TNE, x1 + 1, x2 + 1, x3 + 1); } ////////////////////////////////////////////////////////////////////////// -void InterpolationProcessor::writeICellInv(SPtr<DistributionArray3D> f, const D3Q27ICell& icell, int x1, int x2, int x3) +void InterpolationProcessor::writeICellInv(SPtr<DistributionArray3D> f, const D3Q27ICell &icell, int x1, int x2, int x3) { - f->setDistributionInv(icell.BSW, x1, x2, x3); - f->setDistributionInv(icell.BSE, x1+1, x2, x3); - f->setDistributionInv(icell.BNW, x1, x2+1, x3); - f->setDistributionInv(icell.BNE, x1+1, x2+1, x3); - f->setDistributionInv(icell.TSW, x1, x2, x3+1); - f->setDistributionInv(icell.TSE, x1+1, x2, x3+1); - f->setDistributionInv(icell.TNW, x1, x2+1, x3+1); - f->setDistributionInv(icell.TNE, x1+1, x2+1, x3+1); + f->setDistributionInv(icell.BSW, x1, x2, x3); + f->setDistributionInv(icell.BSE, x1 + 1, x2, x3); + f->setDistributionInv(icell.BNW, x1, x2 + 1, x3); + f->setDistributionInv(icell.BNE, x1 + 1, x2 + 1, x3); + f->setDistributionInv(icell.TSW, x1, x2, x3 + 1); + f->setDistributionInv(icell.TSE, x1 + 1, x2, x3 + 1); + f->setDistributionInv(icell.TNW, x1, x2 + 1, x3 + 1); + f->setDistributionInv(icell.TNE, x1 + 1, x2 + 1, x3 + 1); } ////////////////////////////////////////////////////////////////////////// -void InterpolationProcessor::writeINode(SPtr<DistributionArray3D> f, const LBMReal* const inode, int x1, int x2, int x3) +void InterpolationProcessor::writeINode(SPtr<DistributionArray3D> f, const LBMReal *const inode, int x1, int x2, int x3) { - f->setDistribution(inode, x1, x2, x3); + f->setDistribution(inode, x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -void InterpolationProcessor::writeINodeInv(SPtr<DistributionArray3D> f, const LBMReal* const inode, int x1, int x2, int x3) +void InterpolationProcessor::writeINodeInv(SPtr<DistributionArray3D> f, const LBMReal *const inode, int x1, int x2, + int x3) { - f->setDistributionInv(inode, x1, x2, x3); + f->setDistributionInv(inode, x1, x2, x3); } ////////////////////////////////////////////////////////////////////////// -bool InterpolationProcessor::iCellHasSolid(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3) +bool InterpolationProcessor::iCellHasSolid(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3) { - for (int ix3 = x3; ix3 <= x3 + 1; ix3++) - for(int ix2 = x2; ix2 <= x2 + 1; ix2++) - for(int ix1 = x1; ix1 <= x1 + 1; ix1++) - { - if(bcArray->isSolid(ix1, ix2, ix3)) - return true; - } - return false; + for (int ix3 = x3; ix3 <= x3 + 1; ix3++) + for (int ix2 = x2; ix2 <= x2 + 1; ix2++) + for (int ix1 = x1; ix1 <= x1 + 1; ix1++) { + if (bcArray->isSolid(ix1, ix2, ix3)) + return true; + } + return false; } ////////////////////////////////////////////////////////////////////////// -bool InterpolationProcessor::findNeighborICell(const SPtr<BCArray3D> bcArray, SPtr<DistributionArray3D> f, - D3Q27ICell& icell, int maxX1, int maxX2, int maxX3, - int x1, int x2, int x3, LBMReal& xoff, LBMReal& yoff, LBMReal& zoff) +bool InterpolationProcessor::findNeighborICell(const SPtr<BCArray3D> bcArray, SPtr<DistributionArray3D> f, + D3Q27ICell &icell, int maxX1, int maxX2, int maxX3, int x1, int x2, + int x3, LBMReal &xoff, LBMReal &yoff, LBMReal &zoff) { - m_maxX1 = maxX1; - m_maxX2 = maxX2; - m_maxX3 = maxX3; + m_maxX1 = maxX1; + m_maxX2 = maxX2; + m_maxX3 = maxX3; - //GoWest - if(inRange(x1-1,x2,x3) && !iCellHasSolid(bcArray, x1-1,x2,x3)) - { - readICell(f,icell,x1-1,x2,x3); - xoff = 1; - yoff = 0; - zoff = 0; - } - //GoEast - else if(inRange(x1+2,x2,x3) && !iCellHasSolid(bcArray, x1+1,x2,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2,x3); - xoff = -1; - yoff = 0; - zoff = 0; - } - //GoSouth - else if(inRange(x1,x2-1,x3) && !iCellHasSolid(bcArray, x1,x2-1,x3)) - { - readICell(f,icell,x1,x2-1,x3); - xoff = 0; - yoff = 1; - zoff = 0; - } - //GoNorth - else if(inRange(x1,x2+2,x3) && !iCellHasSolid(bcArray, x1,x2+1,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1,x2+1,x3); - xoff = 0; - yoff = -1; - zoff = 0; - } - //GoBottom - else if(inRange(x1,x2,x3-1) && !iCellHasSolid(bcArray, x1,x2,x3-1)) - { - readICell(f,icell,x1,x2,x3-1); - xoff = 0; - yoff = 0; - zoff = 1; - } - //GoTop - else if(inRange(x1,x2,x3+2) && !iCellHasSolid(bcArray, x1,x2,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1,x2,x3+1); - xoff = 0; - yoff = 0; - zoff = -1; - } - //GoNW - else if(inRange(x1-1,x2+2,x3) && !iCellHasSolid(bcArray, x1-1,x2+1,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2+1,x3); - xoff = 1; - yoff = -1; - zoff = 0; - } - //GoNE - else if(inRange(x1+2,x2+2,x3) && !iCellHasSolid(bcArray, x1+1,x2+1,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2+1,x3); - xoff = -1; - yoff = -1; - zoff = 0; - } - //GoSW - else if(inRange(x1-1,x2-1,x3) && !iCellHasSolid(bcArray, x1-1,x2-1,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2-1,x3); - xoff = 1; - yoff = 1; - zoff = 0; - } - //GoSE - else if(inRange(x1+2,x2-1,x3) && !iCellHasSolid(bcArray, x1+1,x2-1,x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2-1,x3); - xoff = -1; - yoff = 1; - zoff = 0; - } - //GoBW - else if(inRange(x1-1,x2,x3-1) && !iCellHasSolid(bcArray, x1-1,x2,x3-1)) - { - readICell(f,icell,x1-1,x2,x3-1); - xoff = 1; - yoff = 0; - zoff = 1; - } - //GoBE - else if(inRange(x1+2,x2,x3-1) && !iCellHasSolid(bcArray, x1+1,x2,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2,x3-1); - xoff = -1; - yoff = 0; - zoff = 1; - } - //GoBS - else if(inRange(x1,x2-1,x3-1) && !iCellHasSolid(bcArray, x1,x2-1,x3-1)) - { - readICell(f,icell,x1,x2-1,x3-1); - xoff = 0; - yoff = 1; - zoff = 1; - } - //GoBN - else if(inRange(x1,x2+2,x3-1) && !iCellHasSolid(bcArray, x1,x2+1,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1,x2+1,x3-1); - xoff = 0; - yoff = -1; - zoff = 1; - } - //GoTW - else if(inRange(x1-1,x2,x3+2) && !iCellHasSolid(bcArray, x1-1,x2,x3+1)) - { - readICell(f,icell,x1-1,x2,x3+1); - xoff = 1; - yoff = 0; - zoff = -1; - } - //GoTE - else if(inRange(x1+2,x2,x3+2) && !iCellHasSolid(bcArray, x1+1,x2,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2,x3+1); - xoff = -1; - yoff = 0; - zoff = -1; - } - //GoTS - else if(inRange(x1,x2-1,x3+2) && !iCellHasSolid(bcArray, x1,x2-1,x3+1)) - { - readICell(f,icell,x1,x2-1,x3+1); - xoff = 0; - yoff = 1; - zoff = -1; - } - //GoTN - else if(inRange(x1,x2+2,x3+2) && !iCellHasSolid(bcArray, x1,x2+1,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1,x2+1,x3+1); - xoff = 0; - yoff = -1; - zoff = -1; - } - //GoTNW - else if(inRange(x1-1,x2+2,x3+2) && !iCellHasSolid(bcArray, x1-1,x2+1,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2+1,x3+1); - xoff = 1; - yoff = -1; - zoff = -1; - } - //GoTNE - else if(inRange(x1+2,x2+2,x3+2) && !iCellHasSolid(bcArray, x1+1,x2+1,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2+1,x3+1); - xoff = -1; - yoff = -1; - zoff = -1; - } - //GoTSE - else if(inRange(x1+2,x2-1,x3+2) && !iCellHasSolid(bcArray, x1+1,x2-1,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2-1,x3+1); - xoff = -1; - yoff = 1; - zoff = -1; - } - //GoTSW - else if(inRange(x1-1,x2-1,x3+2) && !iCellHasSolid(bcArray, x1-1,x2-1,x3+1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2-1,x3+1); - xoff = 1; - yoff = 1; - zoff = -1; - } - //GoBNW - else if(inRange(x1-1,x2+2,x3-1) && !iCellHasSolid(bcArray, x1-1,x2+1,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2+1,x3-1); - xoff = 1; - yoff = -1; - zoff = 1; - } - //GoBNE - else if(inRange(x1+2,x2+2,x3-1) && !iCellHasSolid(bcArray, x1+1,x2+1,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2+1,x3-1); - xoff = -1; - yoff = -1; - zoff = 1; - } - //GoBSE - else if(inRange(x1+2,x2-1,x3-1) && !iCellHasSolid(bcArray, x1+1,x2-1,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1+1,x2-1,x3-1); - xoff = -1; - yoff = 1; - zoff = 1; - } - //GoBSW - else if(inRange(x1-1,x2-1,x3-1) && !iCellHasSolid(bcArray, x1-1,x2-1,x3-1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 - { - readICell(f,icell,x1-1,x2-1,x3-1); - xoff = 1; - yoff = 1; - zoff = 1; - } - //default - else - { - //std::string err = "For x1="+StringUtil::toString(x1)+", x2=" + StringUtil::toString(x2)+", x3=" + StringUtil::toString(x3)+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - //UB_THROW(UbException(UB_EXARGS, err)); - return false; - } - return true; + // GoWest + if (inRange(x1 - 1, x2, x3) && !iCellHasSolid(bcArray, x1 - 1, x2, x3)) { + readICell(f, icell, x1 - 1, x2, x3); + xoff = 1; + yoff = 0; + zoff = 0; + } + // GoEast + else if (inRange(x1 + 2, x2, x3) && + !iCellHasSolid(bcArray, x1 + 1, x2, x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2, x3); + xoff = -1; + yoff = 0; + zoff = 0; + } + // GoSouth + else if (inRange(x1, x2 - 1, x3) && !iCellHasSolid(bcArray, x1, x2 - 1, x3)) { + readICell(f, icell, x1, x2 - 1, x3); + xoff = 0; + yoff = 1; + zoff = 0; + } + // GoNorth + else if (inRange(x1, x2 + 2, x3) && + !iCellHasSolid(bcArray, x1, x2 + 1, x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1, x2 + 1, x3); + xoff = 0; + yoff = -1; + zoff = 0; + } + // GoBottom + else if (inRange(x1, x2, x3 - 1) && !iCellHasSolid(bcArray, x1, x2, x3 - 1)) { + readICell(f, icell, x1, x2, x3 - 1); + xoff = 0; + yoff = 0; + zoff = 1; + } + // GoTop + else if (inRange(x1, x2, x3 + 2) && + !iCellHasSolid(bcArray, x1, x2, x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1, x2, x3 + 1); + xoff = 0; + yoff = 0; + zoff = -1; + } + // GoNW + else if (inRange(x1 - 1, x2 + 2, x3) && + !iCellHasSolid(bcArray, x1 - 1, x2 + 1, + x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 + 1, x3); + xoff = 1; + yoff = -1; + zoff = 0; + } + // GoNE + else if (inRange(x1 + 2, x2 + 2, x3) && + !iCellHasSolid(bcArray, x1 + 1, x2 + 1, + x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 + 1, x3); + xoff = -1; + yoff = -1; + zoff = 0; + } + // GoSW + else if (inRange(x1 - 1, x2 - 1, x3) && + !iCellHasSolid(bcArray, x1 - 1, x2 - 1, + x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 - 1, x3); + xoff = 1; + yoff = 1; + zoff = 0; + } + // GoSE + else if (inRange(x1 + 2, x2 - 1, x3) && + !iCellHasSolid(bcArray, x1 + 1, x2 - 1, + x3)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 - 1, x3); + xoff = -1; + yoff = 1; + zoff = 0; + } + // GoBW + else if (inRange(x1 - 1, x2, x3 - 1) && !iCellHasSolid(bcArray, x1 - 1, x2, x3 - 1)) { + readICell(f, icell, x1 - 1, x2, x3 - 1); + xoff = 1; + yoff = 0; + zoff = 1; + } + // GoBE + else if (inRange(x1 + 2, x2, x3 - 1) && + !iCellHasSolid(bcArray, x1 + 1, x2, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2, x3 - 1); + xoff = -1; + yoff = 0; + zoff = 1; + } + // GoBS + else if (inRange(x1, x2 - 1, x3 - 1) && !iCellHasSolid(bcArray, x1, x2 - 1, x3 - 1)) { + readICell(f, icell, x1, x2 - 1, x3 - 1); + xoff = 0; + yoff = 1; + zoff = 1; + } + // GoBN + else if (inRange(x1, x2 + 2, x3 - 1) && + !iCellHasSolid(bcArray, x1, x2 + 1, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1, x2 + 1, x3 - 1); + xoff = 0; + yoff = -1; + zoff = 1; + } + // GoTW + else if (inRange(x1 - 1, x2, x3 + 2) && !iCellHasSolid(bcArray, x1 - 1, x2, x3 + 1)) { + readICell(f, icell, x1 - 1, x2, x3 + 1); + xoff = 1; + yoff = 0; + zoff = -1; + } + // GoTE + else if (inRange(x1 + 2, x2, x3 + 2) && + !iCellHasSolid(bcArray, x1 + 1, x2, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2, x3 + 1); + xoff = -1; + yoff = 0; + zoff = -1; + } + // GoTS + else if (inRange(x1, x2 - 1, x3 + 2) && !iCellHasSolid(bcArray, x1, x2 - 1, x3 + 1)) { + readICell(f, icell, x1, x2 - 1, x3 + 1); + xoff = 0; + yoff = 1; + zoff = -1; + } + // GoTN + else if (inRange(x1, x2 + 2, x3 + 2) && + !iCellHasSolid(bcArray, x1, x2 + 1, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1, x2 + 1, x3 + 1); + xoff = 0; + yoff = -1; + zoff = -1; + } + // GoTNW + else if (inRange(x1 - 1, x2 + 2, x3 + 2) && + !iCellHasSolid(bcArray, x1 - 1, x2 + 1, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 + 1, x3 + 1); + xoff = 1; + yoff = -1; + zoff = -1; + } + // GoTNE + else if (inRange(x1 + 2, x2 + 2, x3 + 2) && + !iCellHasSolid(bcArray, x1 + 1, x2 + 1, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 + 1, x3 + 1); + xoff = -1; + yoff = -1; + zoff = -1; + } + // GoTSE + else if (inRange(x1 + 2, x2 - 1, x3 + 2) && + !iCellHasSolid(bcArray, x1 + 1, x2 - 1, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 - 1, x3 + 1); + xoff = -1; + yoff = 1; + zoff = -1; + } + // GoTSW + else if (inRange(x1 - 1, x2 - 1, x3 + 2) && + !iCellHasSolid(bcArray, x1 - 1, x2 - 1, + x3 + 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 - 1, x3 + 1); + xoff = 1; + yoff = 1; + zoff = -1; + } + // GoBNW + else if (inRange(x1 - 1, x2 + 2, x3 - 1) && + !iCellHasSolid(bcArray, x1 - 1, x2 + 1, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 + 1, x3 - 1); + xoff = 1; + yoff = -1; + zoff = 1; + } + // GoBNE + else if (inRange(x1 + 2, x2 + 2, x3 - 1) && + !iCellHasSolid(bcArray, x1 + 1, x2 + 1, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 + 1, x3 - 1); + xoff = -1; + yoff = -1; + zoff = 1; + } + // GoBSE + else if (inRange(x1 + 2, x2 - 1, x3 - 1) && + !iCellHasSolid(bcArray, x1 + 1, x2 - 1, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 + 1, x2 - 1, x3 - 1); + xoff = -1; + yoff = 1; + zoff = 1; + } + // GoBSW + else if (inRange(x1 - 1, x2 - 1, x3 - 1) && + !iCellHasSolid(bcArray, x1 - 1, x2 - 1, + x3 - 1)) // ist �bern�chster Knoten auch im Gebiet (Grundknoten bei 0,0,0 + { + readICell(f, icell, x1 - 1, x2 - 1, x3 - 1); + xoff = 1; + yoff = 1; + zoff = 1; + } + // default + else { + // std::string err = "For x1="+StringUtil::toString(x1)+", x2=" + StringUtil::toString(x2)+", x3=" + + // StringUtil::toString(x3)+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + // UB_THROW(UbException(UB_EXARGS, err)); + return false; + } + return true; } ////////////////////////////////////////////////////////////////////////// -int InterpolationProcessor::iCellHowManySolids( const SPtr<BCArray3D> bcArray, int x1, int x2, int x3 ) +int InterpolationProcessor::iCellHowManySolids(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3) { - int count = 0; - for (int ix3 = x3; ix3 <= x3 + 1; ix3++) - for(int ix2 = x2; ix2 <= x2 + 1; ix2++) - for(int ix1 = x1; ix1 <= x1 + 1; ix1++) - { - if(bcArray->isSolid(ix1, ix2, ix3)) - count++; - } - return count; + int count = 0; + for (int ix3 = x3; ix3 <= x3 + 1; ix3++) + for (int ix2 = x2; ix2 <= x2 + 1; ix2++) + for (int ix1 = x1; ix1 <= x1 + 1; ix1++) { + if (bcArray->isSolid(ix1, ix2, ix3)) + count++; + } + return count; } diff --git a/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.h b/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.h index fb9ade9aa..b3de5c873 100644 --- a/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.h +++ b/src/cpu/VirtualFluidsCore/LBM/InterpolationProcessor.h @@ -1,23 +1,21 @@ #ifndef D3Q27INTRPOLATIOPROCESSOR_H_ #define D3Q27INTRPOLATIOPROCESSOR_H_ +#include "BCArray3D.h" +#include "BoundaryConditions.h" +#include "DistributionArray3D.h" #include "InterpolationProcessor.h" #include "LBMSystem.h" -#include "DistributionArray3D.h" -#include "BoundaryConditions.h" -#include "BCArray3D.h" - -struct D3Q27ICell -{ - LBMReal TSW[27]; - LBMReal TNW[27]; - LBMReal TNE[27]; - LBMReal TSE[27]; - LBMReal BSW[27]; - LBMReal BNW[27]; - LBMReal BNE[27]; - LBMReal BSE[27]; +struct D3Q27ICell { + LBMReal TSW[27]; + LBMReal TNW[27]; + LBMReal TNE[27]; + LBMReal TSE[27]; + LBMReal BSW[27]; + LBMReal BNW[27]; + LBMReal BNE[27]; + LBMReal BSE[27]; }; class InterpolationProcessor; @@ -28,43 +26,48 @@ using InterpolationProcessorPtr = SPtr<InterpolationProcessor>; class InterpolationProcessor { public: - InterpolationProcessor(); - virtual ~InterpolationProcessor(); - virtual InterpolationProcessorPtr clone() = 0; - virtual void setOmegas(LBMReal omegaC, LBMReal omegaF) = 0; - virtual void interpolateCoarseToFine(D3Q27ICell& icellC, D3Q27ICell& icellF) = 0; - virtual void interpolateCoarseToFine(D3Q27ICell& icellC, D3Q27ICell& icellF, LBMReal xoff, LBMReal yoff, LBMReal zoff) = 0; - virtual void interpolateFineToCoarse(D3Q27ICell& icellF, LBMReal* icellC) = 0; - virtual void interpolateFineToCoarse(D3Q27ICell& icellF, LBMReal* icellC, LBMReal xoff, LBMReal yoff, LBMReal zoff) = 0; + InterpolationProcessor(); + virtual ~InterpolationProcessor(); + virtual InterpolationProcessorPtr clone() = 0; + virtual void setOmegas(LBMReal omegaC, LBMReal omegaF) = 0; + virtual void interpolateCoarseToFine(D3Q27ICell &icellC, D3Q27ICell &icellF) = 0; + virtual void interpolateCoarseToFine(D3Q27ICell &icellC, D3Q27ICell &icellF, LBMReal xoff, LBMReal yoff, + LBMReal zoff) = 0; + virtual void interpolateFineToCoarse(D3Q27ICell &icellF, LBMReal *icellC) = 0; + virtual void interpolateFineToCoarse(D3Q27ICell &icellF, LBMReal *icellC, LBMReal xoff, LBMReal yoff, + LBMReal zoff) = 0; - static void readICell(SPtr<DistributionArray3D> f, D3Q27ICell& icell, int x1, int x2, int x3); - static void writeICell(SPtr<DistributionArray3D> f, const D3Q27ICell& icell, int x1, int x2, int x3); - static void writeICellInv(SPtr<DistributionArray3D> f, const D3Q27ICell& icell, int x1, int x2, int x3); - static void writeINode(SPtr<DistributionArray3D> f, const LBMReal* const inode, int x1, int x2, int x3); - static void writeINodeInv(SPtr<DistributionArray3D> f, const LBMReal* const inode, int x1, int x2, int x3); - static bool iCellHasSolid(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3); - static int iCellHowManySolids(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3); + static void readICell(SPtr<DistributionArray3D> f, D3Q27ICell &icell, int x1, int x2, int x3); + static void writeICell(SPtr<DistributionArray3D> f, const D3Q27ICell &icell, int x1, int x2, int x3); + static void writeICellInv(SPtr<DistributionArray3D> f, const D3Q27ICell &icell, int x1, int x2, int x3); + static void writeINode(SPtr<DistributionArray3D> f, const LBMReal *const inode, int x1, int x2, int x3); + static void writeINodeInv(SPtr<DistributionArray3D> f, const LBMReal *const inode, int x1, int x2, int x3); + static bool iCellHasSolid(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3); + static int iCellHowManySolids(const SPtr<BCArray3D> bcArray, int x1, int x2, int x3); - bool findNeighborICell(const SPtr<BCArray3D> bcArray, SPtr<DistributionArray3D> f, - D3Q27ICell& icell, int maxX1, int maxX2, int maxX3, - int x1, int x2, int x3, LBMReal& xoff, LBMReal& yoff, LBMReal& zoff); + bool findNeighborICell(const SPtr<BCArray3D> bcArray, SPtr<DistributionArray3D> f, D3Q27ICell &icell, int maxX1, + int maxX2, int maxX3, int x1, int x2, int x3, LBMReal &xoff, LBMReal &yoff, LBMReal &zoff); protected: - virtual void calcInterpolatedCoefficiets(const D3Q27ICell& icell, LBMReal omega, LBMReal eps_new){} - virtual void calcInterpolatedNodeFC(LBMReal* f, LBMReal omega){} - virtual void calcInterpolatedVelocity(LBMReal x, LBMReal y, LBMReal z,LBMReal& vx1, LBMReal& vx2, LBMReal& vx3){} - virtual void calcInterpolatedShearStress(LBMReal x, LBMReal y, LBMReal z,LBMReal& tauxx, LBMReal& tauyy, LBMReal& tauzz,LBMReal& tauxy, LBMReal& tauxz, LBMReal& tauyz){} - virtual void setOffsets(LBMReal xoff, LBMReal yoff, LBMReal zoff){} - friend class InterpolationHelper; + virtual void calcInterpolatedCoefficiets(const D3Q27ICell &icell, LBMReal omega, LBMReal eps_new) {} + virtual void calcInterpolatedNodeFC(LBMReal *f, LBMReal omega) {} + virtual void calcInterpolatedVelocity(LBMReal x, LBMReal y, LBMReal z, LBMReal &vx1, LBMReal &vx2, LBMReal &vx3) {} + virtual void calcInterpolatedShearStress(LBMReal x, LBMReal y, LBMReal z, LBMReal &tauxx, LBMReal &tauyy, + LBMReal &tauzz, LBMReal &tauxy, LBMReal &tauxz, LBMReal &tauyz) + { + } + virtual void setOffsets(LBMReal xoff, LBMReal yoff, LBMReal zoff) {} + friend class InterpolationHelper; + private: - bool inRange(int x1, int x2, int x3); - int m_maxX1, m_maxX2, m_maxX3; + bool inRange(int x1, int x2, int x3); + int m_maxX1, m_maxX2, m_maxX3; }; ////////////////////////////////////////////////////////////////////////// inline bool InterpolationProcessor::inRange(int x1, int x2, int x3) { - return x1 >= 0 && x1 < m_maxX1 && x2 >= 0 && x2 < m_maxX2 && x3 >= 0 && x3 < m_maxX3; + return x1 >= 0 && x1 < m_maxX1 && x2 >= 0 && x2 < m_maxX2 && x3 >= 0 && x3 < m_maxX3; } #endif diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.cpp b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.cpp index 7004a4d73..1d387655b 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,221 +32,155 @@ //======================================================================================= #include "LBMKernel.h" -#include "DataSet3D.h" +#include "BCArray3D.h" #include "BCProcessor.h" #include "Block3D.h" -#include "BCArray3D.h" +#include "DataSet3D.h" + +LBMKernel::LBMKernel() -LBMKernel::LBMKernel() - { - this->setForcingX1(0.0); - this->setForcingX2(0.0); - this->setForcingX3(0.0); - dataSet = std::make_shared<DataSet3D>(); - this->nx[0] = 0; - this->nx[1] = 0; - this->nx[2] = 0; + this->setForcingX1(0.0); + this->setForcingX2(0.0); + this->setForcingX3(0.0); + dataSet = std::make_shared<DataSet3D>(); + this->nx[0] = 0; + this->nx[1] = 0; + this->nx[2] = 0; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setBCProcessor(SPtr<BCProcessor> bcp) -{ - bcProcessor = bcp; -} +void LBMKernel::setBCProcessor(SPtr<BCProcessor> bcp) { bcProcessor = bcp; } ////////////////////////////////////////////////////////////////////////// -SPtr<BCProcessor> LBMKernel::getBCProcessor() const -{ - return bcProcessor; -} +SPtr<BCProcessor> LBMKernel::getBCProcessor() const { return bcProcessor; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setCollisionFactor(double collFactor) -{ - this->collFactor = collFactor; -} +void LBMKernel::setCollisionFactor(double collFactor) { this->collFactor = collFactor; } ////////////////////////////////////////////////////////////////////////// -double LBMKernel::getCollisionFactor() const -{ - return collFactor; -} +double LBMKernel::getCollisionFactor() const { return collFactor; } ////////////////////////////////////////////////////////////////////////// void LBMKernel::setForcingX1(LBMReal forcingX1) { - this->muForcingX1.SetExpr( UbSystem::toString(forcingX1,LBMRealLim::digits10) ); - this->checkFunction(muForcingX1); + this->muForcingX1.SetExpr(UbSystem::toString(forcingX1, LBMRealLim::digits10)); + this->checkFunction(muForcingX1); } ////////////////////////////////////////////////////////////////////////// void LBMKernel::setForcingX2(LBMReal forcingX2) { - this->muForcingX2.SetExpr( UbSystem::toString(forcingX2,LBMRealLim::digits10) ); - this->checkFunction(muForcingX2); + this->muForcingX2.SetExpr(UbSystem::toString(forcingX2, LBMRealLim::digits10)); + this->checkFunction(muForcingX2); } void LBMKernel::setForcingX3(LBMReal forcingX3) { - this->muForcingX3.SetExpr( UbSystem::toString(forcingX3,LBMRealLim::digits10) ); - this->checkFunction(muForcingX3); + this->muForcingX3.SetExpr(UbSystem::toString(forcingX3, LBMRealLim::digits10)); + this->checkFunction(muForcingX3); } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setForcingX1( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muForcingX1 = parser; +void LBMKernel::setForcingX1(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muForcingX1 = parser; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setForcingX2( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muForcingX2 = parser; +void LBMKernel::setForcingX2(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muForcingX2 = parser; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setForcingX3( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muForcingX3 = parser; +void LBMKernel::setForcingX3(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muForcingX3 = parser; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setForcingX1( const std::string& muParserString) -{ - this->muForcingX1.SetExpr(muParserString); - this->checkFunction(muForcingX1); +void LBMKernel::setForcingX1(const std::string &muParserString) +{ + this->muForcingX1.SetExpr(muParserString); + this->checkFunction(muForcingX1); } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setForcingX2( const std::string& muParserString) -{ - this->muForcingX2.SetExpr(muParserString); - this->checkFunction(muForcingX2); +void LBMKernel::setForcingX2(const std::string &muParserString) +{ + this->muForcingX2.SetExpr(muParserString); + this->checkFunction(muForcingX2); } -void LBMKernel::setForcingX3( const std::string& muParserString) -{ - this->muForcingX3.SetExpr(muParserString); - this->checkFunction(muForcingX3); +void LBMKernel::setForcingX3(const std::string &muParserString) +{ + this->muForcingX3.SetExpr(muParserString); + this->checkFunction(muForcingX3); } ////////////////////////////////////////////////////////////////////////// void LBMKernel::checkFunction(mu::Parser fct) { - double x1=1.0,x2=1.0,x3=1.0, dt=1.0, nue=1.0; - fct.DefineVar("x1",&x1); - fct.DefineVar("x2",&x2); - fct.DefineVar("x3",&x3); - fct.DefineVar("dt",&dt); - fct.DefineVar("nue",&nue); + double x1 = 1.0, x2 = 1.0, x3 = 1.0, dt = 1.0, nue = 1.0; + fct.DefineVar("x1", &x1); + fct.DefineVar("x2", &x2); + fct.DefineVar("x3", &x3); + fct.DefineVar("dt", &dt); + fct.DefineVar("nue", &nue); - try - { - fct.Eval(); - fct.ClearVar(); - } - catch(mu::ParserError& e) - { - throw UbException(UB_EXARGS,"function: "+e.GetExpr() + (std::string)"error: "+e.GetMsg() - +(std::string)", only x1,x2,x3,dx are allowed as variables" ); - } + try { + fct.Eval(); + fct.ClearVar(); + } catch (mu::ParserError &e) { + throw UbException(UB_EXARGS, "function: " + e.GetExpr() + (std::string) "error: " + e.GetMsg() + + (std::string) ", only x1,x2,x3,dx are allowed as variables"); + } } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setGhostLayerWidth(int witdh) -{ - ghostLayerWidth = witdh; -} +void LBMKernel::setGhostLayerWidth(int witdh) { ghostLayerWidth = witdh; } ////////////////////////////////////////////////////////////////////////// -int LBMKernel::getGhostLayerWidth() const -{ - return ghostLayerWidth; -} +int LBMKernel::getGhostLayerWidth() const { return ghostLayerWidth; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setIndex( int x1, int x2, int x3 ) +void LBMKernel::setIndex(int x1, int x2, int x3) { - this->ix1 = x1; - this->ix2 = x2; - this->ix3 = x3; + this->ix1 = x1; + this->ix2 = x2; + this->ix3 = x3; } ////////////////////////////////////////////////////////////////////////// -SPtr<DataSet3D> LBMKernel::getDataSet() const -{ - return this->dataSet; -} +SPtr<DataSet3D> LBMKernel::getDataSet() const { return this->dataSet; } ////////////////////////////////////////////////////////////////////////// -LBMReal LBMKernel::getDeltaT() const -{ - return this->deltaT; -} +LBMReal LBMKernel::getDeltaT() const { return this->deltaT; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setDeltaT( LBMReal dt ) -{ - deltaT = dt; -} +void LBMKernel::setDeltaT(LBMReal dt) { deltaT = dt; } ////////////////////////////////////////////////////////////////////////// -bool LBMKernel::getCompressible() const -{ - return compressible; -} +bool LBMKernel::getCompressible() const { return compressible; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setCompressible(bool val) -{ - compressible = val; -} +void LBMKernel::setCompressible(bool val) { compressible = val; } ////////////////////////////////////////////////////////////////////////// -bool LBMKernel::getWithForcing() const -{ - return withForcing; -} +bool LBMKernel::getWithForcing() const { return withForcing; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setWithForcing( bool val ) -{ - withForcing = val; -} +void LBMKernel::setWithForcing(bool val) { withForcing = val; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setBlock( SPtr<Block3D> block ) -{ - this->block = block; -} +void LBMKernel::setBlock(SPtr<Block3D> block) { this->block = block; } ////////////////////////////////////////////////////////////////////////// -SPtr<Block3D> LBMKernel::getBlock() const -{ - return block.lock(); -} +SPtr<Block3D> LBMKernel::getBlock() const { return block.lock(); } ////////////////////////////////////////////////////////////////////////// -bool LBMKernel::getWithSpongeLayer() const -{ - return withSpongeLayer; -} +bool LBMKernel::getWithSpongeLayer() const { return withSpongeLayer; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setWithSpongeLayer( bool val ) -{ - withSpongeLayer = val; -} +void LBMKernel::setWithSpongeLayer(bool val) { withSpongeLayer = val; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setSpongeLayer( const mu::Parser& parser ) +void LBMKernel::setSpongeLayer(const mu::Parser &parser) { - this->checkFunction(parser); - this->muSpongeLayer = parser; + this->checkFunction(parser); + this->muSpongeLayer = parser; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setSpongeLayer( const std::string& muParserString ) +void LBMKernel::setSpongeLayer(const std::string &muParserString) { - this->muSpongeLayer.SetExpr(muParserString); - this->checkFunction(muSpongeLayer); + this->muSpongeLayer.SetExpr(muParserString); + this->checkFunction(muSpongeLayer); } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setDataSet(SPtr<DataSet3D> dataSet) -{ - this->dataSet = dataSet; -} +void LBMKernel::setDataSet(SPtr<DataSet3D> dataSet) { this->dataSet = dataSet; } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::swapDistributions() -{ - dataSet->getFdistributions()->swap(); -} +void LBMKernel::swapDistributions() { dataSet->getFdistributions()->swap(); } ////////////////////////////////////////////////////////////////////////// -void LBMKernel::setNX(std::array<int, 3> nx) -{ - this->nx = nx; -} +void LBMKernel::setNX(std::array<int, 3> nx) { this->nx = nx; } ////////////////////////////////////////////////////////////////////////// -std::array<int, 3> LBMKernel::getNX() -{ - return nx; -} +std::array<int, 3> LBMKernel::getNX() { return nx; } ////////////////////////////////////////////////////////////////////////// -bool LBMKernel::isInsideOfDomain(const int& x1, const int& x2, const int& x3) const +bool LBMKernel::isInsideOfDomain(const int &x1, const int &x2, const int &x3) const { const SPtr<BCArray3D> bcArray = this->bcProcessor->getBCArray(); return bcArray->isInsideOfDomain(x1, x2, x3, ghostLayerWidth); diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h index 9703bf6c5..be29589b9 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/LBMKernel.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,9 +34,9 @@ #ifndef LBMKERNEL_H #define LBMKERNEL_H -#include <PointerDefinitions.h> -#include "LBMSystem.h" #include "ILBMKernel.h" +#include "LBMSystem.h" +#include <PointerDefinitions.h> #include <array> #include <limits> #include <muParser.h> @@ -45,17 +45,18 @@ class BCProcessor; class DataSet3D; class Block3D; -//! \brief A base class provides basic functionality for LBM kernel +//! \brief A base class provides basic functionality for LBM kernel class LBMKernel : public ILBMKernel, public enableSharedFromThis<LBMKernel> { public: using LBMRealLim = std::numeric_limits<LBMReal>; + public: LBMKernel(); virtual SPtr<LBMKernel> clone() = 0; - void calculate(int step) override = 0; + void calculate(int step) override = 0; double getCalculationTime() override = 0; void setBCProcessor(SPtr<BCProcessor> bcp) override; @@ -65,7 +66,7 @@ public: double getCollisionFactor() const override; void setGhostLayerWidth(int witdh); - int getGhostLayerWidth() const override; + int getGhostLayerWidth() const override; void setDataSet(SPtr<DataSet3D> dataSet); SPtr<DataSet3D> getDataSet() const override; @@ -74,13 +75,13 @@ public: void setForcingX2(LBMReal forcingX2); void setForcingX3(LBMReal forcingX3); - void setForcingX1(const mu::Parser& parser); - void setForcingX2(const mu::Parser& parser); - void setForcingX3(const mu::Parser& parser); + void setForcingX1(const mu::Parser &parser); + void setForcingX2(const mu::Parser &parser); + void setForcingX3(const mu::Parser &parser); - void setForcingX1(const std::string& muParserString); - void setForcingX2(const std::string& muParserString); - void setForcingX3(const std::string& muParserString); + void setForcingX1(const std::string &muParserString); + void setForcingX2(const std::string &muParserString); + void setForcingX3(const std::string &muParserString); void setIndex(int x1, int x2, int x3); @@ -96,8 +97,8 @@ public: bool getWithSpongeLayer() const; void setWithSpongeLayer(bool val); - void setSpongeLayer(const mu::Parser& parser); - void setSpongeLayer(const std::string& muParserString); + void setSpongeLayer(const mu::Parser &parser); + void setSpongeLayer(const std::string &muParserString); void setBlock(SPtr<Block3D> block); SPtr<Block3D> getBlock() const; @@ -113,19 +114,19 @@ protected: SPtr<DataSet3D> dataSet; SPtr<BCProcessor> bcProcessor; LBMReal collFactor; - int ghostLayerWidth{1}; - bool compressible{false}; + int ghostLayerWidth{ 1 }; + bool compressible{ false }; - //forcing - bool withForcing{false}; + // forcing + bool withForcing{ false }; mu::Parser muForcingX1; mu::Parser muForcingX2; mu::Parser muForcingX3; int ix1, ix2, ix3; - LBMReal deltaT{1.0}; + LBMReal deltaT{ 1.0 }; - //sponge layer - bool withSpongeLayer{false}; + // sponge layer + bool withSpongeLayer{ false }; mu::Parser muSpongeLayer; WPtr<Block3D> block; diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.cpp b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.cpp index b6fcbe12f..9c8e8990b 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,5 +35,5 @@ namespace LBMSystem { - real SMAG_CONST = REAL_CAST(0.18); +real SMAG_CONST = REAL_CAST(0.18); } diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h index 7b016a3b7..d24775aef 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h +++ b/src/cpu/VirtualFluidsCore/LBM/LBMSystem.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,9 +34,8 @@ #define LBMSYSTEM_H #include <cmath> -#include <string> #include <iostream> - +#include <string> //! \brief namespace for global system-functions @@ -46,50 +45,43 @@ namespace LBMSystem //#define SINGLEPRECISION #ifdef SINGLEPRECISION - typedef float real; - #define REAL_CAST(x) ( (LBMSystem::real)(x) ) +typedef float real; +#define REAL_CAST(x) ((LBMSystem::real)(x)) #else - using real = double; - #define REAL_CAST(x) ( x ) +using real = double; +#define REAL_CAST(x) (x) #endif - extern real SMAG_CONST; +extern real SMAG_CONST; - ////////////////////////////////////////////////////////////////////////// - //!get LBM deltaT is equal LBM DeltaX - //!deltaT is dependent from grid level - //!for first grid level is deltaT = 1.0 - //!for next grid level 1/2 etc. - static real getDeltaT(int level) - { - return REAL_CAST(1.0/REAL_CAST(1<<level)); - } +////////////////////////////////////////////////////////////////////////// +//! get LBM deltaT is equal LBM DeltaX +//! deltaT is dependent from grid level +//! for first grid level is deltaT = 1.0 +//! for next grid level 1/2 etc. +static real getDeltaT(int level) { return REAL_CAST(1.0 / REAL_CAST(1 << level)); } - ////////////////////////////////////////////////////////////////////////// - //!calculate collision factor omega = 1.0/(3.0*viscosity/deltaT+0.5) - //!deltaT is dependent from grid level - //!for first grid level is deltaT = 1.0 - //!for next grid level 1/2 etc. - static real calcCollisionFactor(real viscosity, int level) - { - //return REAL_CAST(1.0/(3.0*viscosity/deltaT+0.5)); - return REAL_CAST(1.0/(3.0*viscosity/(1.0/REAL_CAST(1<<level))+0.5)); - } +////////////////////////////////////////////////////////////////////////// +//! calculate collision factor omega = 1.0/(3.0*viscosity/deltaT+0.5) +//! deltaT is dependent from grid level +//! for first grid level is deltaT = 1.0 +//! for next grid level 1/2 etc. +static real calcCollisionFactor(real viscosity, int level) +{ + // return REAL_CAST(1.0/(3.0*viscosity/deltaT+0.5)); + return REAL_CAST(1.0 / (3.0 * viscosity / (1.0 / REAL_CAST(1 << level)) + 0.5)); +} - //!bulk viscosity - static real calcOmega2(real viscosity, int level) - { - return REAL_CAST(1.0/(4.5*viscosity/(1.0/REAL_CAST(1<<level))+0.5)); - } - //!bulk viscosity - static real calcOmega2(real viscosity, real deltaT) - { - return REAL_CAST(1.0/(4.5*viscosity/deltaT+0.5)); - } +//! bulk viscosity +static real calcOmega2(real viscosity, int level) +{ + return REAL_CAST(1.0 / (4.5 * viscosity / (1.0 / REAL_CAST(1 << level)) + 0.5)); } +//! bulk viscosity +static real calcOmega2(real viscosity, real deltaT) { return REAL_CAST(1.0 / (4.5 * viscosity / deltaT + 0.5)); } +} // namespace LBMSystem -//some typedefs for global namespace +// some typedefs for global namespace using LBMReal = LBMSystem::real; #endif - diff --git a/src/cpu/VirtualFluidsCore/LBM/LBMUnitConverter.h b/src/cpu/VirtualFluidsCore/LBM/LBMUnitConverter.h index 89514acd6..3059fd383 100644 --- a/src/cpu/VirtualFluidsCore/LBM/LBMUnitConverter.h +++ b/src/cpu/VirtualFluidsCore/LBM/LBMUnitConverter.h @@ -1,11 +1,11 @@ #ifndef LBMUNITCONVERTER_H #define LBMUNITCONVERTER_H -#include <iostream> +#include <cmath> #include <iomanip> -#include <string> +#include <iostream> #include <sstream> -#include <cmath> +#include <string> //#include "LBMUnitConverter.h" @@ -16,171 +16,187 @@ // LBMUnitConverter conv( 100 /*L_World*/, 1484/*cs_water*/ , 1000/*rho_water*/ // , 1000/*L_LB*/ , 1./srqt(3.)/*cs_Lb*/, 1/*rho_Lb*/ ); // cout<<conv.toString()<<endl; -// +// // cout<<"100m = "<< 100 * conv.getFactorLentghWToLb() << "dx " << std::endl; // cout<<"1000dx = "<< 1000 * conv.getFactorLentghLbToW() << "m " << std::endl; -// +// // cout<<"25m/s = "<< 25 * conv.getFactorVelocityWToLb() << "dx/dt " << std::endl; // cout<<"0.04 dx/dt = "<< 0.04 * conv.getFactorVelocityLbToW() << "m/s " << std::endl; // -//alternativ +// alternativ // LBMUnitConverter conv(, 100 /*L_World*/, LBMUnitConverter::WATER, 1000/*L_LB*/ ); - class LBMUnitConverter { public: - - enum WORLD_MATERIAL { WATER = 0, SEAWWATER = 1, AIR_20C = 2, OIL = 3 }; - - LBMUnitConverter() = default; - - LBMUnitConverter( const double& refLengthWorld, const double& csWorld, const double& rhoWorld - , const double& refLengthLb , const double& csLb = 1.0/std::sqrt(3.0) , const double& rhoLb = 1.0 ) - { - this->init( refLengthWorld, csWorld, rhoWorld, csWorld, refLengthLb, rhoLb, csLb ); - - } - - LBMUnitConverter( const double& refLengthWorld, WORLD_MATERIAL worldMaterial - , const double& refLengthLb , const double& csLb = 1.0/std::sqrt(3.0) , const double& rhoLb = 1.0 ) - { - double csWorld; - double rhoWorld; - - if ( worldMaterial == WATER ) { csWorld = 1484/*m/s*/; rhoWorld = 1000/*kg/m^3*/; } - else if( worldMaterial == SEAWWATER) { csWorld = 1500/*m/s*/; rhoWorld = 1025/*kg/m^3*/; } - else if( worldMaterial == AIR_20C ) { csWorld = 343/*m/s*/; rhoWorld = 1.290/*kg/m^3*/; } - else if( worldMaterial == OIL ) { csWorld = 1740/*m/s*/; rhoWorld = 830/*kg/m^3*/; } - else throw UbException(UB_EXARGS,"unknown material"); - - this->init( refLengthWorld, csWorld, rhoWorld, csWorld, refLengthLb, rhoLb, csLb ); - - } - - LBMUnitConverter(int /*dummy*/, double uReal, double uLB, double nuReal, double nuLB) - { - factorVelocityLbToW = uReal/uLB; - factorViscosityLbToW = nuReal/nuLB; - factorDensityLbToW = factorViscosityLbToW * factorVelocityLbToW * factorVelocityLbToW; - factorPressureLbToW = factorDensityLbToW; - } - - virtual ~LBMUnitConverter() = default; - - double getRefRhoLb() { return refRhoLb; } - - double getFactorLentghLbToW() { return factorLengthLbToW; } - double getFactorLentghWToLb() { return 1.0/this->getFactorLentghLbToW(); } - - double getFactorTimeLbToW() { return factorTimeLbToW; } - double getFactorTimeWToLb() { return 1.0/this->getFactorTimeLbToW(); } - - double getFactorVelocityLbToW() { return factorLengthLbToW/factorTimeLbToW; } - double getFactorVelocityWToLb() { return 1.0/this->getFactorVelocityLbToW(); } - - double getFactorViscosityLbToW() { return factorLengthLbToW*factorLengthLbToW/factorTimeLbToW; } - double getFactorViscosityWToLb() { return 1.0/this->getFactorViscosityLbToW(); } - - double getFactorDensityLbToW() { return this->factorMassLbToW/std::pow(factorLengthLbToW,3.0); } - double getFactorDensityWToLb() { return 1.0/this->getFactorDensityLbToW(); } - - double getFactorPressureLbToW() { return this->factorMassLbToW/(std::pow(factorTimeLbToW,2.0)*factorLengthLbToW); } - double getFactorPressureWToLb() { return 1.0/this->getFactorPressureLbToW(); } - - double getFactorMassLbToW() { return this->factorMassLbToW; } - double getFactorMassWToLb() { return 1.0/this->getFactorMassLbToW(); } - - double getFactorForceLbToW() { return factorMassLbToW*factorLengthLbToW/(factorTimeLbToW*factorTimeLbToW); } - double getFactorForceWToLb() { return 1.0/this->getFactorForceLbToW(); } - - double getFactorAccLbToW() { return factorLengthLbToW/(factorTimeLbToW*factorTimeLbToW); } - double getFactorAccWToLb() { return 1.0/this->getFactorAccLbToW(); } - - double getFactorTimeLbToW(double deltaX) const { return factorTimeWithoutDx * deltaX; } - ////////////////////////////////////////////////////////////////////////// - double getFactorVelocityLbToW2() { return factorVelocityLbToW; } - double getFactorDensityLbToW2() { return factorDensityLbToW; } - double getFactorPressureLbToW2() { return factorPressureLbToW; } - - - - /*==========================================================*/ - friend inline std::ostream& operator << (std::ostream& os, LBMUnitConverter c) - { - os<<c.toString(); - return os; - } - /*==========================================================*/ - std::string toString() - { - std::ostringstream out; - out<<"LB --> WORLD" << std::endl; - out<<" * lentgh 1[dx ] = " << std::setw(12) << this->getFactorLentghLbToW() << " [m ] " << std::endl; - out<<" * time 1[dt ] = " << std::setw(12) << this->getFactorTimeLbToW() << " [s ] " << std::endl; - out<<" * mass 1[mass] = " << std::setw(12) << this->getFactorMassLbToW() << " [kg ] " << std::endl; - out<<std::endl; - out<<"WORLD --> LB" << std::endl; - out<<" * lentgh 1[m ] = " << std::setw(12) << this->getFactorLentghWToLb() << " [dx ] " << std::endl; - out<<" * time 1[s ] = " << std::setw(12) << this->getFactorTimeWToLb() << " [dt ] " << std::endl; - out<<" * mass 1[kg ] = " << std::setw(12) << this->getFactorMassWToLb() << " [mass] " << std::endl; - out<<std::endl; - out<<"LB --> WORLD (combined units)" << std::endl; - out<<" * velocity 1 [dx/dt ] = " << std::setw(12) << this->getFactorVelocityLbToW() << " [m/s ]" << std::endl; - out<<" * density 1 [mass/dx^3] = " << std::setw(12) << this->getFactorDensityLbToW() << " [kg/m^3 ]" << std::endl; - out<<" * pressure 1 [F_lb/dx^2] = " << std::setw(12) << this->getFactorPressureLbToW() << " [N/m^2 ]" << std::endl; - out<<" * viscosity 1 [dx^2/dt ] = " << std::setw(12) << this->getFactorViscosityLbToW() << " [m^2/s ]" << std::endl; - out<<" * force 1 [F_lb ] = " << std::setw(12) << this->getFactorForceLbToW() << " [N ]" << std::endl; - out<<" * acceleration 1 [dx/dt^2 ] = " << std::setw(12) << this->getFactorAccLbToW() << " [m/s^2 ]" << std::endl; - out<<std::endl; - out<<"WORLD --> LB (combined units)" << std::endl; - out<<" * velocity 1 [m/s ] = " << std::setw(12) << this->getFactorVelocityWToLb() << " [dx/dt ]" << std::endl; - out<<" * density 1 [kg/m^3 ] = " << std::setw(12) << this->getFactorDensityWToLb() << " [mass/dx^3]" << std::endl; - out<<" * pressure 1 [N/m^2 ] = " << std::setw(12) << this->getFactorPressureWToLb() << " [F_lb/dx^2]" << std::endl; - out<<" * viscosity 1 [m^2/s ] = " << std::setw(12) << this->getFactorViscosityWToLb() << " [dx^2/dt ]" << std::endl; - out<<" * force 1 [N ] = " << std::setw(12) << this->getFactorForceWToLb() << " [F_lb ]" << std::endl; - out<<" * acceleration 1 [m/s^2 ] = " << std::setw(12) << this->getFactorAccWToLb() << " [dx/dt^2 ]" << std::endl; - - return out.str(); - } - /*==========================================================*/ - virtual void write(UbFileOutput* out) - { - out->writeDouble(factorLengthLbToW); - out->writeDouble(factorTimeLbToW ); - out->writeDouble(factorMassLbToW ); - } - /*==========================================================*/ - virtual void read(UbFileInput* in) - { - factorLengthLbToW = in->readDouble(); - factorTimeLbToW = in->readDouble(); - factorMassLbToW = in->readDouble(); - } - - - - void init( const double& refLengthWorld, const double& /*csWorld*/, const double& rhoWorld, const double& vWorld, - const double& refLengthLb, const double& rhoLb, const double& vLb ) - { - factorLengthLbToW = refLengthWorld / refLengthLb; - factorTimeLbToW = vLb / vWorld * factorLengthLbToW; - factorMassLbToW = rhoWorld/rhoLb*factorLengthLbToW*factorLengthLbToW*factorLengthLbToW; - factorTimeWithoutDx=vLb/vWorld; - this->refRhoLb = rhoLb; - } - protected: - double factorLengthLbToW{1.0}; - double factorTimeLbToW{1.0}; - double factorMassLbToW{1.0}; - double refRhoLb{1.0}; - double factorTimeWithoutDx{0.0}; - - double factorVelocityLbToW{1.0}; - double factorViscosityLbToW{1.0}; - double factorDensityLbToW{1.0}; - double factorPressureLbToW{1.0}; - + enum WORLD_MATERIAL { WATER = 0, SEAWWATER = 1, AIR_20C = 2, OIL = 3 }; + + LBMUnitConverter() = default; + + LBMUnitConverter(const double &refLengthWorld, const double &csWorld, const double &rhoWorld, + const double &refLengthLb, const double &csLb = 1.0 / std::sqrt(3.0), const double &rhoLb = 1.0) + { + this->init(refLengthWorld, csWorld, rhoWorld, csWorld, refLengthLb, rhoLb, csLb); + } + + LBMUnitConverter(const double &refLengthWorld, WORLD_MATERIAL worldMaterial, const double &refLengthLb, + const double &csLb = 1.0 / std::sqrt(3.0), const double &rhoLb = 1.0) + { + double csWorld; + double rhoWorld; + + if (worldMaterial == WATER) { + csWorld = 1484 /*m/s*/; + rhoWorld = 1000 /*kg/m^3*/; + } else if (worldMaterial == SEAWWATER) { + csWorld = 1500 /*m/s*/; + rhoWorld = 1025 /*kg/m^3*/; + } else if (worldMaterial == AIR_20C) { + csWorld = 343 /*m/s*/; + rhoWorld = 1.290 /*kg/m^3*/; + } else if (worldMaterial == OIL) { + csWorld = 1740 /*m/s*/; + rhoWorld = 830 /*kg/m^3*/; + } else + throw UbException(UB_EXARGS, "unknown material"); + + this->init(refLengthWorld, csWorld, rhoWorld, csWorld, refLengthLb, rhoLb, csLb); + } + + LBMUnitConverter(int /*dummy*/, double uReal, double uLB, double nuReal, double nuLB) + { + factorVelocityLbToW = uReal / uLB; + factorViscosityLbToW = nuReal / nuLB; + factorDensityLbToW = factorViscosityLbToW * factorVelocityLbToW * factorVelocityLbToW; + factorPressureLbToW = factorDensityLbToW; + } + + virtual ~LBMUnitConverter() = default; + + double getRefRhoLb() { return refRhoLb; } + + double getFactorLentghLbToW() { return factorLengthLbToW; } + double getFactorLentghWToLb() { return 1.0 / this->getFactorLentghLbToW(); } + + double getFactorTimeLbToW() { return factorTimeLbToW; } + double getFactorTimeWToLb() { return 1.0 / this->getFactorTimeLbToW(); } + + double getFactorVelocityLbToW() { return factorLengthLbToW / factorTimeLbToW; } + double getFactorVelocityWToLb() { return 1.0 / this->getFactorVelocityLbToW(); } + + double getFactorViscosityLbToW() { return factorLengthLbToW * factorLengthLbToW / factorTimeLbToW; } + double getFactorViscosityWToLb() { return 1.0 / this->getFactorViscosityLbToW(); } + + double getFactorDensityLbToW() { return this->factorMassLbToW / std::pow(factorLengthLbToW, 3.0); } + double getFactorDensityWToLb() { return 1.0 / this->getFactorDensityLbToW(); } + + double getFactorPressureLbToW() + { + return this->factorMassLbToW / (std::pow(factorTimeLbToW, 2.0) * factorLengthLbToW); + } + double getFactorPressureWToLb() { return 1.0 / this->getFactorPressureLbToW(); } + + double getFactorMassLbToW() { return this->factorMassLbToW; } + double getFactorMassWToLb() { return 1.0 / this->getFactorMassLbToW(); } + + double getFactorForceLbToW() { return factorMassLbToW * factorLengthLbToW / (factorTimeLbToW * factorTimeLbToW); } + double getFactorForceWToLb() { return 1.0 / this->getFactorForceLbToW(); } + + double getFactorAccLbToW() { return factorLengthLbToW / (factorTimeLbToW * factorTimeLbToW); } + double getFactorAccWToLb() { return 1.0 / this->getFactorAccLbToW(); } + + double getFactorTimeLbToW(double deltaX) const { return factorTimeWithoutDx * deltaX; } + ////////////////////////////////////////////////////////////////////////// + double getFactorVelocityLbToW2() { return factorVelocityLbToW; } + double getFactorDensityLbToW2() { return factorDensityLbToW; } + double getFactorPressureLbToW2() { return factorPressureLbToW; } + + /*==========================================================*/ + friend inline std::ostream &operator<<(std::ostream &os, LBMUnitConverter c) + { + os << c.toString(); + return os; + } + /*==========================================================*/ + std::string toString() + { + std::ostringstream out; + out << "LB --> WORLD" << std::endl; + out << " * lentgh 1[dx ] = " << std::setw(12) << this->getFactorLentghLbToW() << " [m ] " << std::endl; + out << " * time 1[dt ] = " << std::setw(12) << this->getFactorTimeLbToW() << " [s ] " << std::endl; + out << " * mass 1[mass] = " << std::setw(12) << this->getFactorMassLbToW() << " [kg ] " << std::endl; + out << std::endl; + out << "WORLD --> LB" << std::endl; + out << " * lentgh 1[m ] = " << std::setw(12) << this->getFactorLentghWToLb() << " [dx ] " << std::endl; + out << " * time 1[s ] = " << std::setw(12) << this->getFactorTimeWToLb() << " [dt ] " << std::endl; + out << " * mass 1[kg ] = " << std::setw(12) << this->getFactorMassWToLb() << " [mass] " << std::endl; + out << std::endl; + out << "LB --> WORLD (combined units)" << std::endl; + out << " * velocity 1 [dx/dt ] = " << std::setw(12) << this->getFactorVelocityLbToW() << " [m/s ]" + << std::endl; + out << " * density 1 [mass/dx^3] = " << std::setw(12) << this->getFactorDensityLbToW() << " [kg/m^3 ]" + << std::endl; + out << " * pressure 1 [F_lb/dx^2] = " << std::setw(12) << this->getFactorPressureLbToW() << " [N/m^2 ]" + << std::endl; + out << " * viscosity 1 [dx^2/dt ] = " << std::setw(12) << this->getFactorViscosityLbToW() << " [m^2/s ]" + << std::endl; + out << " * force 1 [F_lb ] = " << std::setw(12) << this->getFactorForceLbToW() << " [N ]" + << std::endl; + out << " * acceleration 1 [dx/dt^2 ] = " << std::setw(12) << this->getFactorAccLbToW() << " [m/s^2 ]" + << std::endl; + out << std::endl; + out << "WORLD --> LB (combined units)" << std::endl; + out << " * velocity 1 [m/s ] = " << std::setw(12) << this->getFactorVelocityWToLb() << " [dx/dt ]" + << std::endl; + out << " * density 1 [kg/m^3 ] = " << std::setw(12) << this->getFactorDensityWToLb() << " [mass/dx^3]" + << std::endl; + out << " * pressure 1 [N/m^2 ] = " << std::setw(12) << this->getFactorPressureWToLb() << " [F_lb/dx^2]" + << std::endl; + out << " * viscosity 1 [m^2/s ] = " << std::setw(12) << this->getFactorViscosityWToLb() << " [dx^2/dt ]" + << std::endl; + out << " * force 1 [N ] = " << std::setw(12) << this->getFactorForceWToLb() << " [F_lb ]" + << std::endl; + out << " * acceleration 1 [m/s^2 ] = " << std::setw(12) << this->getFactorAccWToLb() << " [dx/dt^2 ]" + << std::endl; + + return out.str(); + } + /*==========================================================*/ + virtual void write(UbFileOutput *out) + { + out->writeDouble(factorLengthLbToW); + out->writeDouble(factorTimeLbToW); + out->writeDouble(factorMassLbToW); + } + /*==========================================================*/ + virtual void read(UbFileInput *in) + { + factorLengthLbToW = in->readDouble(); + factorTimeLbToW = in->readDouble(); + factorMassLbToW = in->readDouble(); + } + + void init(const double &refLengthWorld, const double & /*csWorld*/, const double &rhoWorld, const double &vWorld, + const double &refLengthLb, const double &rhoLb, const double &vLb) + { + factorLengthLbToW = refLengthWorld / refLengthLb; + factorTimeLbToW = vLb / vWorld * factorLengthLbToW; + factorMassLbToW = rhoWorld / rhoLb * factorLengthLbToW * factorLengthLbToW * factorLengthLbToW; + factorTimeWithoutDx = vLb / vWorld; + this->refRhoLb = rhoLb; + } + +protected: + double factorLengthLbToW{ 1.0 }; + double factorTimeLbToW{ 1.0 }; + double factorMassLbToW{ 1.0 }; + double refRhoLb{ 1.0 }; + double factorTimeWithoutDx{ 0.0 }; + + double factorVelocityLbToW{ 1.0 }; + double factorViscosityLbToW{ 1.0 }; + double factorDensityLbToW{ 1.0 }; + double factorPressureLbToW{ 1.0 }; }; -#endif //LBMUNITCONVERTER_H +#endif // LBMUNITCONVERTER_H diff --git a/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.cpp b/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.cpp index 8e4a73a7b..d9ce56aa8 100644 --- a/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.cpp +++ b/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.cpp @@ -1,42 +1,34 @@ #include "VoidLBMKernel.h" -#include "VoidData3D.h" #include "BCProcessor.h" #include "DataSet3D.h" +#include "VoidData3D.h" -VoidLBMKernel::VoidLBMKernel() -= default; +VoidLBMKernel::VoidLBMKernel() = default; ////////////////////////////////////////////////////////////////////////// -VoidLBMKernel::~VoidLBMKernel() -= default; +VoidLBMKernel::~VoidLBMKernel() = default; ////////////////////////////////////////////////////////////////////////// void VoidLBMKernel::initDataSet() { - SPtr<DistributionArray3D> d(new VoidData3D(nx[0]+2, nx[1]+2, nx[2]+2, -999.9)); - dataSet->setFdistributions(d); + SPtr<DistributionArray3D> d(new VoidData3D(nx[0] + 2, nx[1] + 2, nx[2] + 2, -999.9)); + dataSet->setFdistributions(d); } ////////////////////////////////////////////////////////////////////////// SPtr<LBMKernel> VoidLBMKernel::clone() { - SPtr<LBMKernel> kernel(new VoidLBMKernel()); - kernel->setNX(nx); - dynamicPointerCast<VoidLBMKernel>(kernel)->initDataSet(); - kernel->setCollisionFactor(this->collFactor); - kernel->setBCProcessor(bcProcessor->clone(kernel)); - kernel->setWithForcing(withForcing); - kernel->setForcingX1(muForcingX1); - kernel->setForcingX2(muForcingX2); - kernel->setForcingX3(muForcingX3); - kernel->setIndex(ix1, ix2, ix3); - kernel->setDeltaT(deltaT); - return kernel; + SPtr<LBMKernel> kernel(new VoidLBMKernel()); + kernel->setNX(nx); + dynamicPointerCast<VoidLBMKernel>(kernel)->initDataSet(); + kernel->setCollisionFactor(this->collFactor); + kernel->setBCProcessor(bcProcessor->clone(kernel)); + kernel->setWithForcing(withForcing); + kernel->setForcingX1(muForcingX1); + kernel->setForcingX2(muForcingX2); + kernel->setForcingX3(muForcingX3); + kernel->setIndex(ix1, ix2, ix3); + kernel->setDeltaT(deltaT); + return kernel; } ////////////////////////////////////////////////////////////////////////// -void VoidLBMKernel::calculate(int step) -{ - -} +void VoidLBMKernel::calculate(int step) {} ////////////////////////////////////////////////////////////////////////// -double VoidLBMKernel::getCalculationTime() -{ - return 0.0; -} +double VoidLBMKernel::getCalculationTime() { return 0.0; } diff --git a/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.h b/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.h index 4ae754cca..b9b4b5d2d 100644 --- a/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.h +++ b/src/cpu/VirtualFluidsCore/LBM/VoidLBMKernel.h @@ -6,13 +6,13 @@ class VoidLBMKernel : public LBMKernel { public: - VoidLBMKernel(); - ~VoidLBMKernel() override; - SPtr<LBMKernel> clone() override; - void calculate(int step) override; - double getCalculationTime() override; - void initDataSet(); -protected: + VoidLBMKernel(); + ~VoidLBMKernel() override; + SPtr<LBMKernel> clone() override; + void calculate(int step) override; + double getCalculationTime() override; + void initDataSet(); +protected: }; #endif // VoidLBMKernel_h__ diff --git a/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.cpp b/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.cpp index aa010ef63..09f0af7ac 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.cpp @@ -1,7 +1,3 @@ #include "BlocksDistributor.h" -BlocksDistributor::BlocksDistributor(SPtr<Grid3D> grid, SPtr<Communicator> comm) : grid(grid), comm(comm) -{ - -} - +BlocksDistributor::BlocksDistributor(SPtr<Grid3D> grid, SPtr<Communicator> comm) : grid(grid), comm(comm) {} diff --git a/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.h b/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.h index 08ab5a8a8..7af79dc29 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.h +++ b/src/cpu/VirtualFluidsCore/Parallel/BlocksDistributor.h @@ -9,15 +9,13 @@ class BlocksDistributor { public: - BlocksDistributor(SPtr<Grid3D> grid, SPtr<Communicator> comm); - ~BlocksDistributor(); + BlocksDistributor(SPtr<Grid3D> grid, SPtr<Communicator> comm); + ~BlocksDistributor(); protected: private: - SPtr<Grid3D> grid; - SPtr<Communicator> comm; + SPtr<Grid3D> grid; + SPtr<Communicator> comm; }; #endif - - diff --git a/src/cpu/VirtualFluidsCore/Parallel/Communicator.cpp b/src/cpu/VirtualFluidsCore/Parallel/Communicator.cpp index 2b6938267..b7ea54267 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/Communicator.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/Communicator.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,8 +38,8 @@ SPtr<Communicator> Communicator::instance = SPtr<Communicator>(); ////////////////////////////////////////////////////////////////////////// SPtr<Communicator> Communicator::getInstance() { - if( !instance ) - UB_THROW(UbException(UB_EXARGS,"Communicator isn't initialized correctly! You can not create a new instance of abstract Communicator class!")); - return instance; + if (!instance) + UB_THROW(UbException(UB_EXARGS, "Communicator isn't initialized correctly! You can not create a new instance " + "of abstract Communicator class!")); + return instance; } - diff --git a/src/cpu/VirtualFluidsCore/Parallel/Communicator.h b/src/cpu/VirtualFluidsCore/Parallel/Communicator.h index 1ab893e56..28ba70548 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/Communicator.h +++ b/src/cpu/VirtualFluidsCore/Parallel/Communicator.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,8 +34,8 @@ #ifndef COMMUNICATOR_H #define COMMUNICATOR_H -#include <vector> #include <string> +#include <vector> #include <PointerDefinitions.h> @@ -43,50 +43,50 @@ class Communicator { public: - virtual ~Communicator()= default; - static SPtr<Communicator> getInstance(); - virtual int getBundleID() = 0; - virtual int getNumberOfBundles() = 0; - virtual int getProcessID() = 0; - virtual int getProcessID(int bundle, int rank) = 0; - virtual int getNumberOfProcesses() = 0; - virtual bool isRoot() = 0; - virtual void* getNativeCommunicator() = 0; + virtual ~Communicator() = default; + static SPtr<Communicator> getInstance(); + virtual int getBundleID() = 0; + virtual int getNumberOfBundles() = 0; + virtual int getProcessID() = 0; + virtual int getProcessID(int bundle, int rank) = 0; + virtual int getNumberOfProcesses() = 0; + virtual bool isRoot() = 0; + virtual void *getNativeCommunicator() = 0; - virtual void sendSerializedObject(std::stringstream& ss, int target) = 0; - virtual void receiveSerializedObject(std::stringstream& ss, int source) = 0; + virtual void sendSerializedObject(std::stringstream &ss, int target) = 0; + virtual void receiveSerializedObject(std::stringstream &ss, int source) = 0; - virtual int getRoot() = 0; - virtual int getBundleRoot() = 0; - virtual int getProcessRoot() = 0; - virtual int getNumberOfProcessesInBundle(int bundle) = 0; - virtual void barrier() = 0; - virtual void abort(int errorcode) = 0; + virtual int getRoot() = 0; + virtual int getBundleRoot() = 0; + virtual int getProcessRoot() = 0; + virtual int getNumberOfProcessesInBundle(int bundle) = 0; + virtual void barrier() = 0; + virtual void abort(int errorcode) = 0; - virtual std::vector<std::string> gather(const std::string& str) = 0; - virtual std::vector<int> gather(std::vector<int>& values) = 0; - virtual std::vector<float> gather(std::vector<float>& values) = 0; - virtual std::vector<double> gather(std::vector<double>& values) = 0; - virtual std::vector<unsigned long long> gather(std::vector<unsigned long long>& values) = 0; + virtual std::vector<std::string> gather(const std::string &str) = 0; + virtual std::vector<int> gather(std::vector<int> &values) = 0; + virtual std::vector<float> gather(std::vector<float> &values) = 0; + virtual std::vector<double> gather(std::vector<double> &values) = 0; + virtual std::vector<unsigned long long> gather(std::vector<unsigned long long> &values) = 0; + + virtual void allGather(std::vector<int> &svalues, std::vector<int> &rvalues) = 0; + virtual void allGather(std::vector<float> &svalues, std::vector<float> &rvalues) = 0; + virtual void allGather(std::vector<double> &svalues, std::vector<double> &rvalues) = 0; + virtual void allGather(std::vector<unsigned long long> &svalues, std::vector<unsigned long long> &rvalues) = 0; + + virtual void broadcast(int &value) = 0; + virtual void broadcast(float &value) = 0; + virtual void broadcast(double &value) = 0; + virtual void broadcast(long int &value) = 0; + virtual void broadcast(std::vector<int> &values) = 0; + virtual void broadcast(std::vector<float> &values) = 0; + virtual void broadcast(std::vector<double> &values) = 0; + virtual void broadcast(std::vector<long int> &values) = 0; - virtual void allGather(std::vector<int>& svalues, std::vector<int>& rvalues) = 0; - virtual void allGather(std::vector<float>& svalues, std::vector<float>& rvalues) = 0; - virtual void allGather(std::vector<double>& svalues, std::vector<double>& rvalues) = 0; - virtual void allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues) = 0; - - virtual void broadcast(int& value) = 0; - virtual void broadcast(float& value) = 0; - virtual void broadcast(double& value) = 0; - virtual void broadcast(long int& value) = 0; - virtual void broadcast(std::vector<int>& values) = 0; - virtual void broadcast(std::vector<float>& values) = 0; - virtual void broadcast(std::vector<double>& values) = 0; - virtual void broadcast(std::vector<long int>& values) = 0; protected: - Communicator()= default; - Communicator( const Communicator& )= default; - static SPtr<Communicator> instance; + Communicator() = default; + Communicator(const Communicator &) = default; + static SPtr<Communicator> instance; }; #endif - diff --git a/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.cpp b/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.cpp index 0c785fc3d..4e5b5cb79 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.cpp @@ -8,238 +8,160 @@ using namespace std; ////////////////////////////////////////////////////////////////////////// MPICommunicator::MPICommunicator() { - //proof if MPI is initialized - int mpiInitialized = (int)false; - MPI_Initialized(&mpiInitialized); - if (!mpiInitialized) - { - MPI_Init(NULL, NULL); - //MPI_Init_thread(NULL, NULL, MPI_THREAD_FUNNELED, NULL); - } - MPI_Comm_rank(MPI_COMM_WORLD, &PID); - MPI_Comm_size(MPI_COMM_WORLD, &numprocs); - //numprocs = 1000; - comm = MPI_COMM_WORLD; - root = 0; + // proof if MPI is initialized + int mpiInitialized = (int)false; + MPI_Initialized(&mpiInitialized); + if (!mpiInitialized) { + MPI_Init(NULL, NULL); + // MPI_Init_thread(NULL, NULL, MPI_THREAD_FUNNELED, NULL); + } + MPI_Comm_rank(MPI_COMM_WORLD, &PID); + MPI_Comm_size(MPI_COMM_WORLD, &numprocs); + // numprocs = 1000; + comm = MPI_COMM_WORLD; + root = 0; } ////////////////////////////////////////////////////////////////////////// MPICommunicator::~MPICommunicator() { - //proof if MPI is finalized - int _mpiFinalized = (int)false; - MPI_Finalized(&_mpiFinalized); - if (!_mpiFinalized) - { - MPI_Finalize(); - //UBLOG(logINFO, "MPI_Finalize()"); - } - } + // proof if MPI is finalized + int _mpiFinalized = (int)false; + MPI_Finalized(&_mpiFinalized); + if (!_mpiFinalized) { + MPI_Finalize(); + // UBLOG(logINFO, "MPI_Finalize()"); + } +} ////////////////////////////////////////////////////////////////////////// SPtr<Communicator> MPICommunicator::getInstance() { - if( !Communicator::instance ) - Communicator::instance = SPtr<Communicator>(new MPICommunicator()); - return Communicator::instance; + if (!Communicator::instance) + Communicator::instance = SPtr<Communicator>(new MPICommunicator()); + return Communicator::instance; } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::abort(int errorcode) -{ - MPI_Abort(comm, errorcode); -} +void MPICommunicator::abort(int errorcode) { MPI_Abort(comm, errorcode); } //////////////////////////////////////////////////////////////////////////// -vector<string> MPICommunicator::gather(const string& str) -{ - vector<string> parts; - vector<string> strings; - int scount; - vector<char> rbuf(1); - vector<int> rcounts(1); - MPI_Status status; +vector<string> MPICommunicator::gather(const string &str) +{ + vector<string> parts; + vector<string> strings; + int scount; + vector<char> rbuf(1); + vector<int> rcounts(1); + MPI_Status status; - if (PID == root) - { - rcounts.resize(numprocs - 1); - strings.push_back(str); + if (PID == root) { + rcounts.resize(numprocs - 1); + strings.push_back(str); - for (int i = 1; i < numprocs; i++) - { - MPI_Recv(&rcounts[i-1], 1, MPI_INT, i, 0, comm, &status); - } - for (int i = 1; i < numprocs; i++) - { - rbuf.resize(rcounts[i-1]); - MPI_Recv(&rbuf[0], rcounts[i-1], MPI_CHAR, i, 0, comm, &status); - string s(&rbuf[0], rcounts[i-1]); - if (s != "") strings.push_back(s); - } - } - else - { - scount = (int)str.length(); - MPI_Send(&scount, 1, MPI_INT, root, 0, comm); - MPI_Send((char *)str.c_str(), scount, MPI_CHAR, root, 0, comm); - } - return strings; + for (int i = 1; i < numprocs; i++) { + MPI_Recv(&rcounts[i - 1], 1, MPI_INT, i, 0, comm, &status); + } + for (int i = 1; i < numprocs; i++) { + rbuf.resize(rcounts[i - 1]); + MPI_Recv(&rbuf[0], rcounts[i - 1], MPI_CHAR, i, 0, comm, &status); + string s(&rbuf[0], rcounts[i - 1]); + if (s != "") + strings.push_back(s); + } + } else { + scount = (int)str.length(); + MPI_Send(&scount, 1, MPI_INT, root, 0, comm); + MPI_Send((char *)str.c_str(), scount, MPI_CHAR, root, 0, comm); + } + return strings; } ////////////////////////////////////////////////////////////////////////// -vector<int> MPICommunicator::gather(vector<int>& values) -{ - return gather<int>(values); -} +vector<int> MPICommunicator::gather(vector<int> &values) { return gather<int>(values); } ////////////////////////////////////////////////////////////////////////// -vector<float> MPICommunicator::gather(vector<float>& values) -{ - return gather<float>(values); -} +vector<float> MPICommunicator::gather(vector<float> &values) { return gather<float>(values); } ////////////////////////////////////////////////////////////////////////// -vector<double> MPICommunicator::gather(vector<double>& values) -{ - return gather<double>(values); -} +vector<double> MPICommunicator::gather(vector<double> &values) { return gather<double>(values); } ////////////////////////////////////////////////////////////////////////// -std::vector<unsigned long long> MPICommunicator::gather(std::vector<unsigned long long>& values) +std::vector<unsigned long long> MPICommunicator::gather(std::vector<unsigned long long> &values) { - return gather<unsigned long long>(values); + return gather<unsigned long long>(values); } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getProcessID() -{ - return PID; -} +int MPICommunicator::getProcessID() { return PID; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getProcessID(int /*bundle*/, int /*rank*/) -{ - return PID; -} +int MPICommunicator::getProcessID(int /*bundle*/, int /*rank*/) { return PID; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getNumberOfProcesses() -{ - return numprocs; -} +int MPICommunicator::getNumberOfProcesses() { return numprocs; } ////////////////////////////////////////////////////////////////////////// -void* MPICommunicator::getNativeCommunicator() -{ - return &comm; -} +void *MPICommunicator::getNativeCommunicator() { return &comm; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getBundleID() -{ - return 0; -} +int MPICommunicator::getBundleID() { return 0; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getNumberOfBundles() -{ - return 1; -} +int MPICommunicator::getNumberOfBundles() { return 1; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getRoot() -{ - return root; -} +int MPICommunicator::getRoot() { return root; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getBundleRoot() -{ - return 0; -} +int MPICommunicator::getBundleRoot() { return 0; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getProcessRoot() -{ - return 0; -} +int MPICommunicator::getProcessRoot() { return 0; } ////////////////////////////////////////////////////////////////////////// -int MPICommunicator::getNumberOfProcessesInBundle(int /*bundle*/) -{ - return numprocs; -} +int MPICommunicator::getNumberOfProcessesInBundle(int /*bundle*/) { return numprocs; } ////////////////////////////////////////////////////////////////////////// -bool MPICommunicator::isRoot() -{ - return PID == root; -} +bool MPICommunicator::isRoot() { return PID == root; } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::sendSerializedObject( std::stringstream& ss, int target) +void MPICommunicator::sendSerializedObject(std::stringstream &ss, int target) { - string str = ss.str(); - int scount = static_cast<int> (str.length()); - MPI_Send(&scount,1,MPI_INT,target,0,comm); - MPI_Send((char *)str.c_str(),scount,MPI_CHAR,target,0,comm); + string str = ss.str(); + int scount = static_cast<int>(str.length()); + MPI_Send(&scount, 1, MPI_INT, target, 0, comm); + MPI_Send((char *)str.c_str(), scount, MPI_CHAR, target, 0, comm); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::receiveSerializedObject( std::stringstream& ss, int source ) +void MPICommunicator::receiveSerializedObject(std::stringstream &ss, int source) { - vector<char> rbuf; - int rcount; - MPI_Status status; - MPI_Recv(&rcount,1,MPI_INT,source,0,comm,&status); - rbuf.resize(rcount); - MPI_Recv(&rbuf[0],rcount,MPI_CHAR,source,0,comm,&status); - ss.rdbuf()->pubsetbuf(&rbuf[0],rcount); - string str (&rbuf[0]); - ss.str(str); + vector<char> rbuf; + int rcount; + MPI_Status status; + MPI_Recv(&rcount, 1, MPI_INT, source, 0, comm, &status); + rbuf.resize(rcount); + MPI_Recv(&rbuf[0], rcount, MPI_CHAR, source, 0, comm, &status); + ss.rdbuf()->pubsetbuf(&rbuf[0], rcount); + string str(&rbuf[0]); + ss.str(str); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::barrier() -{ - MPI_Barrier(comm); -} +void MPICommunicator::barrier() { MPI_Barrier(comm); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::allGather(std::vector<int>& svalues, std::vector<int>& rvalues) +void MPICommunicator::allGather(std::vector<int> &svalues, std::vector<int> &rvalues) { - allGather<int>(svalues, rvalues); + allGather<int>(svalues, rvalues); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::allGather(std::vector<float>& svalues, std::vector<float>& rvalues) +void MPICommunicator::allGather(std::vector<float> &svalues, std::vector<float> &rvalues) { - allGather<float>(svalues, rvalues); + allGather<float>(svalues, rvalues); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::allGather(std::vector<double>& svalues, std::vector<double>& rvalues) +void MPICommunicator::allGather(std::vector<double> &svalues, std::vector<double> &rvalues) { - allGather<double>(svalues, rvalues); + allGather<double>(svalues, rvalues); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues) +void MPICommunicator::allGather(std::vector<unsigned long long> &svalues, std::vector<unsigned long long> &rvalues) { - allGather<unsigned long long>(svalues, rvalues); + allGather<unsigned long long>(svalues, rvalues); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(std::vector<int>& values) -{ - broadcast<int>(values); -} +void MPICommunicator::broadcast(std::vector<int> &values) { broadcast<int>(values); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(std::vector<float>& values) -{ - broadcast<float>(values); -} +void MPICommunicator::broadcast(std::vector<float> &values) { broadcast<float>(values); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(std::vector<double>& values) -{ - broadcast<double>(values); -} +void MPICommunicator::broadcast(std::vector<double> &values) { broadcast<double>(values); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(std::vector<long int>& values) -{ - broadcast<long int>(values); -} +void MPICommunicator::broadcast(std::vector<long int> &values) { broadcast<long int>(values); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(int& value) -{ - broadcast<int>(value); -} +void MPICommunicator::broadcast(int &value) { broadcast<int>(value); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(float& value) -{ - broadcast<float>(value); -} +void MPICommunicator::broadcast(float &value) { broadcast<float>(value); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(double& value) -{ - broadcast<double>(value); -} +void MPICommunicator::broadcast(double &value) { broadcast<double>(value); } ////////////////////////////////////////////////////////////////////////// -void MPICommunicator::broadcast(long int& value) -{ - broadcast<long int>(value); -} +void MPICommunicator::broadcast(long int &value) { broadcast<long int>(value); } #endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.h b/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.h index 20b6b85b3..26f814476 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.h +++ b/src/cpu/VirtualFluidsCore/Parallel/MPICommunicator.h @@ -3,14 +3,13 @@ #ifndef MPICOMMUNICATOR_H #define MPICOMMUNICATOR_H -#include <mpi.h> -#include <vector> -#include <string> +#include "Communicator.h" #include <PointerDefinitions.h> #include <basics/utilities/UbException.h> #include <basics/utilities/UbLogger.h> -#include "Communicator.h" - +#include <mpi.h> +#include <string> +#include <vector> //! \brief A class uses MPI library to communication. //! \details Support MPI communication. Implements singleton pattern. @@ -19,169 +18,186 @@ class MPICommunicator : public Communicator { private: - MPICommunicator(); - MPICommunicator( const MPICommunicator& ){} + MPICommunicator(); + MPICommunicator(const MPICommunicator &) {} + public: - ~MPICommunicator() override; - static SPtr<Communicator> getInstance(); - int getBundleID() override; - int getNumberOfBundles() override; - int getProcessID() override; - int getProcessID(int bundle, int rank) override; - int getNumberOfProcesses() override; - void* getNativeCommunicator() override; - int getRoot() override; - int getBundleRoot() override; - int getProcessRoot() override; - int getNumberOfProcessesInBundle(int bundle) override; - bool isRoot() override; - void abort(int errorcode) override; - - void sendSerializedObject(std::stringstream& ss, int target) override; - void receiveSerializedObject(std::stringstream& ss, int source) override; - - void barrier() override; - - std::vector<std::string> gather(const std::string& str) override; - std::vector<int> gather(std::vector<int>& values) override; - std::vector<float> gather(std::vector<float>& values) override; - std::vector<double> gather(std::vector<double>& values) override; - std::vector<unsigned long long> gather(std::vector<unsigned long long>& values) override; - - void allGather(std::vector<int>& svalues, std::vector<int>& rvalues) override; - void allGather(std::vector<float>& svalues, std::vector<float>& rvalues) override; - void allGather(std::vector<double>& svalues, std::vector<double>& rvalues) override; - void allGather(std::vector<unsigned long long>& svalues, std::vector<unsigned long long>& rvalues) override; - - void broadcast(int& value) override; - void broadcast(float& value) override; - void broadcast(double& value) override; - void broadcast(long int& value) override; - void broadcast(std::vector<int>& values) override; - void broadcast(std::vector<float>& values) override; - void broadcast(std::vector<double>& values) override; - void broadcast(std::vector<long int>& values) override; - - template <class T> - std::vector<T> gather(std::vector<T>& values); - - template <class T> - void allGather(std::vector<T>& svalues, std::vector<T>& rvalues); - - template <class T> - void broadcast(std::vector<T>& values); - - template <class T> - void broadcast(T& value); + ~MPICommunicator() override; + static SPtr<Communicator> getInstance(); + int getBundleID() override; + int getNumberOfBundles() override; + int getProcessID() override; + int getProcessID(int bundle, int rank) override; + int getNumberOfProcesses() override; + void *getNativeCommunicator() override; + int getRoot() override; + int getBundleRoot() override; + int getProcessRoot() override; + int getNumberOfProcessesInBundle(int bundle) override; + bool isRoot() override; + void abort(int errorcode) override; + + void sendSerializedObject(std::stringstream &ss, int target) override; + void receiveSerializedObject(std::stringstream &ss, int source) override; + + void barrier() override; + + std::vector<std::string> gather(const std::string &str) override; + std::vector<int> gather(std::vector<int> &values) override; + std::vector<float> gather(std::vector<float> &values) override; + std::vector<double> gather(std::vector<double> &values) override; + std::vector<unsigned long long> gather(std::vector<unsigned long long> &values) override; + + void allGather(std::vector<int> &svalues, std::vector<int> &rvalues) override; + void allGather(std::vector<float> &svalues, std::vector<float> &rvalues) override; + void allGather(std::vector<double> &svalues, std::vector<double> &rvalues) override; + void allGather(std::vector<unsigned long long> &svalues, std::vector<unsigned long long> &rvalues) override; + + void broadcast(int &value) override; + void broadcast(float &value) override; + void broadcast(double &value) override; + void broadcast(long int &value) override; + void broadcast(std::vector<int> &values) override; + void broadcast(std::vector<float> &values) override; + void broadcast(std::vector<double> &values) override; + void broadcast(std::vector<long int> &values) override; + + template <class T> + std::vector<T> gather(std::vector<T> &values); + + template <class T> + void allGather(std::vector<T> &svalues, std::vector<T> &rvalues); + + template <class T> + void broadcast(std::vector<T> &values); + + template <class T> + void broadcast(T &value); private: - int numprocs, PID; - MPI_Comm comm; - int root; + int numprocs, PID; + MPI_Comm comm; + int root; }; ////////////////////////////////////////////////////////////////////////// template <class T> -std::vector<T> MPICommunicator::gather(std::vector<T>& values) +std::vector<T> MPICommunicator::gather(std::vector<T> &values) { - MPI_Datatype mpiDataType; - if ((std::string)typeid(T).name()==(std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE; - else if ((std::string)typeid(T).name()==(std::string)typeid(float).name()) mpiDataType = MPI_FLOAT; - else if ((std::string)typeid(T).name()==(std::string)typeid(int).name()) mpiDataType = MPI_INT; - else if ((std::string)typeid(T).name()==(std::string)typeid(unsigned long long).name()) mpiDataType = MPI_UNSIGNED_LONG_LONG; - else throw UbException(UB_EXARGS, "no MpiDataType for T"+(std::string)typeid(T).name()); - - int count = static_cast<int> (values.size()); - std::vector<T> rvalues(1); - - if (PID == root) - { - rvalues.resize(numprocs*count); - } - - MPI_Gather(&values[0], count, mpiDataType, &rvalues[0], count, mpiDataType, root, comm); - - return rvalues; + MPI_Datatype mpiDataType; + if ((std::string) typeid(T).name() == (std::string) typeid(double).name()) + mpiDataType = MPI_DOUBLE; + else if ((std::string) typeid(T).name() == (std::string) typeid(float).name()) + mpiDataType = MPI_FLOAT; + else if ((std::string) typeid(T).name() == (std::string) typeid(int).name()) + mpiDataType = MPI_INT; + else if ((std::string) typeid(T).name() == (std::string) typeid(unsigned long long).name()) + mpiDataType = MPI_UNSIGNED_LONG_LONG; + else + throw UbException(UB_EXARGS, "no MpiDataType for T" + (std::string) typeid(T).name()); + + int count = static_cast<int>(values.size()); + std::vector<T> rvalues(1); + + if (PID == root) { + rvalues.resize(numprocs * count); + } + + MPI_Gather(&values[0], count, mpiDataType, &rvalues[0], count, mpiDataType, root, comm); + + return rvalues; } ////////////////////////////////////////////////////////////////////////// template <class T> -void MPICommunicator::allGather(std::vector<T>& svalues, std::vector<T>& rvalues) +void MPICommunicator::allGather(std::vector<T> &svalues, std::vector<T> &rvalues) { - MPI_Datatype mpiDataType; - if ((std::string)typeid(T).name()==(std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE; - else if ((std::string)typeid(T).name()==(std::string)typeid(float).name()) mpiDataType = MPI_FLOAT; - else if ((std::string)typeid(T).name()==(std::string)typeid(int).name()) mpiDataType = MPI_INT; - else if ((std::string)typeid(T).name()==(std::string)typeid(unsigned long long).name()) mpiDataType = MPI_UNSIGNED_LONG_LONG; - else throw UbException(UB_EXARGS, "no MpiDataType for T"+(std::string)typeid(T).name()); - - int scount; - std::vector<int> displs, rcounts; - - scount = (int)(svalues.size()); - - rcounts.resize(numprocs); - MPI_Allgather(&scount, 1, MPI_INT, &rcounts[0], 1, MPI_INT, comm); - displs.resize(numprocs); - - displs[0] = 0; - for (int i=1; i<numprocs; ++i) - { - displs[i] = displs[i-1]+rcounts[i-1]; - } - - rvalues.resize(displs[numprocs-1]+rcounts[numprocs-1]); - - if (rvalues.size() == 0) - { - rvalues.resize(1); - rvalues[0] = -999; //FIXME warning C4245: As svalues and rvalues are of type vector<T> there could be a potenial signed/unsigned mismatch storring a negative number - } - if (scount == 0) - { - svalues.resize(1); - svalues[0] = -999; //FIXME warning C4245: As svalues and rvalues are of type vector<T> there could be a potenial signed/unsigned mismatch storring a negative number - } - - MPI_Allgatherv(&svalues[0], scount, mpiDataType, &rvalues[0], &rcounts[0], &displs[0], mpiDataType, comm); + MPI_Datatype mpiDataType; + if ((std::string) typeid(T).name() == (std::string) typeid(double).name()) + mpiDataType = MPI_DOUBLE; + else if ((std::string) typeid(T).name() == (std::string) typeid(float).name()) + mpiDataType = MPI_FLOAT; + else if ((std::string) typeid(T).name() == (std::string) typeid(int).name()) + mpiDataType = MPI_INT; + else if ((std::string) typeid(T).name() == (std::string) typeid(unsigned long long).name()) + mpiDataType = MPI_UNSIGNED_LONG_LONG; + else + throw UbException(UB_EXARGS, "no MpiDataType for T" + (std::string) typeid(T).name()); + + int scount; + std::vector<int> displs, rcounts; + + scount = (int)(svalues.size()); + + rcounts.resize(numprocs); + MPI_Allgather(&scount, 1, MPI_INT, &rcounts[0], 1, MPI_INT, comm); + displs.resize(numprocs); + + displs[0] = 0; + for (int i = 1; i < numprocs; ++i) { + displs[i] = displs[i - 1] + rcounts[i - 1]; + } + + rvalues.resize(displs[numprocs - 1] + rcounts[numprocs - 1]); + + if (rvalues.size() == 0) { + rvalues.resize(1); + rvalues[0] = -999; // FIXME warning C4245: As svalues and rvalues are of type vector<T> there could be a + // potenial signed/unsigned mismatch storring a negative number + } + if (scount == 0) { + svalues.resize(1); + svalues[0] = -999; // FIXME warning C4245: As svalues and rvalues are of type vector<T> there could be a + // potenial signed/unsigned mismatch storring a negative number + } + + MPI_Allgatherv(&svalues[0], scount, mpiDataType, &rvalues[0], &rcounts[0], &displs[0], mpiDataType, comm); } ////////////////////////////////////////////////////////////////////////// template <class T> -void MPICommunicator::broadcast(std::vector<T>& values) +void MPICommunicator::broadcast(std::vector<T> &values) { - MPI_Datatype mpiDataType; - if ((std::string)typeid(T).name()==(std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE; - else if ((std::string)typeid(T).name()==(std::string)typeid(float).name()) mpiDataType = MPI_FLOAT; - else if ((std::string)typeid(T).name()==(std::string)typeid(int).name()) mpiDataType = MPI_INT; - else if ((std::string)typeid(T).name()==(std::string)typeid(long int).name()) mpiDataType = MPI_LONG_INT; - else throw UbException(UB_EXARGS, "no MpiDataType for T"+(std::string)typeid(T).name()); - - int rcount; - if (this->PID == this->root) - { - rcount = (int)values.size(); - } - - MPI_Bcast(&rcount, 1, MPI_INT, this->root, comm); - - if (this->PID != this->root) - { - values.resize(rcount); - } - - MPI_Bcast(&values[0], (int)values.size(), mpiDataType, this->root, comm); + MPI_Datatype mpiDataType; + if ((std::string) typeid(T).name() == (std::string) typeid(double).name()) + mpiDataType = MPI_DOUBLE; + else if ((std::string) typeid(T).name() == (std::string) typeid(float).name()) + mpiDataType = MPI_FLOAT; + else if ((std::string) typeid(T).name() == (std::string) typeid(int).name()) + mpiDataType = MPI_INT; + else if ((std::string) typeid(T).name() == (std::string) typeid(long int).name()) + mpiDataType = MPI_LONG_INT; + else + throw UbException(UB_EXARGS, "no MpiDataType for T" + (std::string) typeid(T).name()); + + int rcount; + if (this->PID == this->root) { + rcount = (int)values.size(); + } + + MPI_Bcast(&rcount, 1, MPI_INT, this->root, comm); + + if (this->PID != this->root) { + values.resize(rcount); + } + + MPI_Bcast(&values[0], (int)values.size(), mpiDataType, this->root, comm); } ////////////////////////////////////////////////////////////////////////// template <class T> -void MPICommunicator::broadcast(T& value) +void MPICommunicator::broadcast(T &value) { - MPI_Datatype mpiDataType; - if ((std::string)typeid(T).name() == (std::string)typeid(double).name()) mpiDataType = MPI_DOUBLE; - else if ((std::string)typeid(T).name() == (std::string)typeid(float).name()) mpiDataType = MPI_FLOAT; - else if ((std::string)typeid(T).name() == (std::string)typeid(int).name()) mpiDataType = MPI_INT; - else if ((std::string)typeid(T).name()==(std::string)typeid(long int).name()) mpiDataType = MPI_LONG_INT; - else throw UbException(UB_EXARGS, "no MpiDataType for T" + (std::string)typeid(T).name()); - - MPI_Bcast(&value, 1, mpiDataType, this->root, comm); + MPI_Datatype mpiDataType; + if ((std::string) typeid(T).name() == (std::string) typeid(double).name()) + mpiDataType = MPI_DOUBLE; + else if ((std::string) typeid(T).name() == (std::string) typeid(float).name()) + mpiDataType = MPI_FLOAT; + else if ((std::string) typeid(T).name() == (std::string) typeid(int).name()) + mpiDataType = MPI_INT; + else if ((std::string) typeid(T).name() == (std::string) typeid(long int).name()) + mpiDataType = MPI_LONG_INT; + else + throw UbException(UB_EXARGS, "no MpiDataType for T" + (std::string) typeid(T).name()); + + MPI_Bcast(&value, 1, mpiDataType, this->root, comm); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Parallel/MPIIODataStructures.h b/src/cpu/VirtualFluidsCore/Parallel/MPIIODataStructures.h index c50e67cfb..6a21caab6 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/MPIIODataStructures.h +++ b/src/cpu/VirtualFluidsCore/Parallel/MPIIODataStructures.h @@ -3,179 +3,167 @@ namespace MPIIODataStructures { - //! \struct GridParam - //! \brief Structure describes parameters of the grid - //! \details The structure is nessasary to restore the grid correctly - struct GridParam - { - double trafoParams[33]; - double deltaX; - int blockNx1; - int blockNx2; - int blockNx3; - int nx1; - int nx2; - int nx3; - bool periodicX1; - bool periodicX2; - bool periodicX3; - bool active; - bool transformation; - }; +//! \struct GridParam +//! \brief Structure describes parameters of the grid +//! \details The structure is nessasary to restore the grid correctly +struct GridParam { + double trafoParams[33]; + double deltaX; + int blockNx1; + int blockNx2; + int blockNx3; + int nx1; + int nx2; + int nx3; + bool periodicX1; + bool periodicX2; + bool periodicX3; + bool active; + bool transformation; +}; - //! \struct Block3d - //! \brief Structure contains information of the block - //! \details The structure is used to write the data describing the block in the grid when saving the grid - //! and to read it when restoring the grid - struct Block3d - { - int x1; - int x2; - int x3; - int bundle; - int rank; - int lrank; - int part; - int globalID; - int localID; - int level; - int interpolationFlagCF; - int interpolationFlagFC; - int counter; - bool active; - }; +//! \struct Block3d +//! \brief Structure contains information of the block +//! \details The structure is used to write the data describing the block in the grid when saving the grid +//! and to read it when restoring the grid +struct Block3d { + int x1; + int x2; + int x3; + int bundle; + int rank; + int lrank; + int part; + int globalID; + int localID; + int level; + int interpolationFlagCF; + int interpolationFlagFC; + int counter; + bool active; +}; - //! \struct dataSetParam - //! \brief Structure describes parameters of the dataSet that are equal in all blocks - //! \details The structure used to store some parameters needed to restore dataSet arrays - struct dataSetParam - { - int nx1; - int nx2; - int nx3; - int nx[4]; //nx1, nx2, nx3, nx4 - }; +//! \struct dataSetParam +//! \brief Structure describes parameters of the dataSet that are equal in all blocks +//! \details The structure used to store some parameters needed to restore dataSet arrays +struct dataSetParam { + int nx1; + int nx2; + int nx3; + int nx[4]; // nx1, nx2, nx3, nx4 +}; - //! \struct DataSetRestart - //! \brief Structure describes parameters of the dataSet in MPIIORestartCoProcessor format - //! \details The structure is used when reading from the file - struct DataSetRestart - { - double collFactor; - double deltaT; - int x1; - int x2; - int x3; - int level; - int ghostLayerWidth; - bool compressible; - bool withForcing; - }; +//! \struct DataSetRestart +//! \brief Structure describes parameters of the dataSet in MPIIORestartCoProcessor format +//! \details The structure is used when reading from the file +struct DataSetRestart { + double collFactor; + double deltaT; + int x1; + int x2; + int x3; + int level; + int ghostLayerWidth; + bool compressible; + bool withForcing; +}; - //! \struct DataSetMigration - //! \brief Structure describes parameters of the dataSet in MPIIOMigrationCoProcessor format - //! \details The structure is used to find the needed block in the grid when restoring a dataSet - struct DataSetMigration - { - double collFactor; - double deltaT; - int globalID; - int ghostLayerWidth; - bool compressible; - bool withForcing; - }; +//! \struct DataSetMigration +//! \brief Structure describes parameters of the dataSet in MPIIOMigrationCoProcessor format +//! \details The structure is used to find the needed block in the grid when restoring a dataSet +struct DataSetMigration { + double collFactor; + double deltaT; + int globalID; + int ghostLayerWidth; + bool compressible; + bool withForcing; +}; - //! \struct DataSetSmallRead - //! \brief Structure describes parameters of the DataSetSmall in MPIIORestartCoProcessor format - //! \details The structure is used when reading from the file - struct DataSetSmallRestart - { - int x1; - int x2; - int x3; - int level; - }; - //! \struct dataSetSmall - //! \brief Structure containes information identifying the block in MPIIOMigrationCoProcessor format - //! \details The structure is used to find the needed block in the grid when restoring a dataSet arrays - struct DataSetSmallMigration - { - int globalID; - }; +//! \struct DataSetSmallRead +//! \brief Structure describes parameters of the DataSetSmall in MPIIORestartCoProcessor format +//! \details The structure is used when reading from the file +struct DataSetSmallRestart { + int x1; + int x2; + int x3; + int level; +}; +//! \struct dataSetSmall +//! \brief Structure containes information identifying the block in MPIIOMigrationCoProcessor format +//! \details The structure is used to find the needed block in the grid when restoring a dataSet arrays +struct DataSetSmallMigration { + int globalID; +}; - //! \struct BoundaryCondition - //! \brief Structure containes information about boundary conditions of the block - //! \details The structure is used to write data describing boundary conditions of the blocks when saving the grid - //! and to read it when restoring the grid - struct BoundaryCondition - { - long long noslipBoundaryFlags; // MPI_LONG_LONG - long long slipBoundaryFlags; - long long velocityBoundaryFlags; - long long densityBoundaryFlags; - long long wallModelBoundaryFlags; +//! \struct BoundaryCondition +//! \brief Structure containes information about boundary conditions of the block +//! \details The structure is used to write data describing boundary conditions of the blocks when saving the grid +//! and to read it when restoring the grid +struct BoundaryCondition { + long long noslipBoundaryFlags; // MPI_LONG_LONG + long long slipBoundaryFlags; + long long velocityBoundaryFlags; + long long densityBoundaryFlags; + long long wallModelBoundaryFlags; - float bcVelocityX1; - float bcVelocityX2; - float bcVelocityX3; - float bcDensity; + float bcVelocityX1; + float bcVelocityX2; + float bcVelocityX3; + float bcDensity; - float bcLodiDensity; - float bcLodiVelocityX1; - float bcLodiVelocityX2; - float bcLodiVelocityX3; - float bcLodiLentgh; + float bcLodiDensity; + float bcLodiVelocityX1; + float bcLodiVelocityX2; + float bcLodiVelocityX3; + float bcLodiLentgh; - float nx1, nx2, nx3; - float q[26]; + float nx1, nx2, nx3; + float q[26]; - char algorithmType; - }; + char algorithmType; +}; - //! \struct boundCondParam - //! \brief Structure describes parameters of the boundaryConditions that are equal in all blocks - //! \details The structure used to store some parameters needed to restore boundaryConditions arrays - struct boundCondParam - { - int nx1; - int nx2; - int nx3; - int bcindexmatrixCount; // how many bcindexmatrix-values in one (any) block - }; +//! \struct boundCondParam +//! \brief Structure describes parameters of the boundaryConditions that are equal in all blocks +//! \details The structure used to store some parameters needed to restore boundaryConditions arrays +struct boundCondParam { + int nx1; + int nx2; + int nx3; + int bcindexmatrixCount; // how many bcindexmatrix-values in one (any) block +}; - //! \struct BCAddRead - //! \brief Structure describes parameters of the BCAdd in MPIIORestartCoProcessor format - //! \details The structure is used when reading from the file - struct BCAddRestart - { - int x1; // to find the right block - int x2; - int x3; - int level; - int boundCond_count; // how many BoundaryCondition-structures are in this block - int indexContainer_count; // how many indexContainer-values are in this block - }; +//! \struct BCAddRead +//! \brief Structure describes parameters of the BCAdd in MPIIORestartCoProcessor format +//! \details The structure is used when reading from the file +struct BCAddRestart { + int x1; // to find the right block + int x2; + int x3; + int level; + int boundCond_count; // how many BoundaryCondition-structures are in this block + int indexContainer_count; // how many indexContainer-values are in this block +}; - //! \struct BCAdd - //! \brief Structure containes information identifying the block and some parameters of the arrays - //! \of boundary conditions that are equal in all blocks in MPIIOMigrationCoProcessor format - //! \details The structure is used to find the needed block in the grid when restoring a dataSet - //! and to set common parameters - struct BCAddMigration - { - int globalID; - int boundCond_count; // how many BoundaryCondition-structures are in this block - int indexContainer_count; // how many indexContainer-values are in this block - }; +//! \struct BCAdd +//! \brief Structure containes information identifying the block and some parameters of the arrays +//! \of boundary conditions that are equal in all blocks in MPIIOMigrationCoProcessor format +//! \details The structure is used to find the needed block in the grid when restoring a dataSet +//! and to set common parameters +struct BCAddMigration { + int globalID; + int boundCond_count; // how many BoundaryCondition-structures are in this block + int indexContainer_count; // how many indexContainer-values are in this block +}; - struct DSArraysPresence - { - bool isAverageDensityArrayPresent; - bool isAverageVelocityArrayPresent; - bool isAverageFluktuationsArrayPresent; - bool isAverageTripleArrayPresent; - bool isShearStressValArrayPresent; - bool isRelaxationFactorPresent; - }; +struct DSArraysPresence { + bool isAverageDensityArrayPresent; + bool isAverageVelocityArrayPresent; + bool isAverageFluktuationsArrayPresent; + bool isAverageTripleArrayPresent; + bool isShearStressValArrayPresent; + bool isRelaxationFactorPresent; }; -#endif \ No newline at end of file +}; // namespace MPIIODataStructures +#endif \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.cpp b/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.cpp index 86a8e1e72..937766684 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.cpp @@ -2,78 +2,76 @@ #include "MetisPartitioner.h" - MetisPartitioner::MetisPartitioner() { - METIS_SetDefaultOptions(options); - options[METIS_OPTION_NUMBERING] = 0; - vsize = NULL; - tpwgts = NULL; - ubvec = NULL; + METIS_SetDefaultOptions(options); + options[METIS_OPTION_NUMBERING] = 0; + vsize = NULL; + tpwgts = NULL; + ubvec = NULL; - //options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT; - ////options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_VOL; + // options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_CUT; + ////options[METIS_OPTION_OBJTYPE] = METIS_OBJTYPE_VOL; - //options[METIS_OPTION_CTYPE] = METIS_CTYPE_SHEM; - //options[METIS_OPTION_IPTYPE] = METIS_IPTYPE_GROW; + // options[METIS_OPTION_CTYPE] = METIS_CTYPE_SHEM; + // options[METIS_OPTION_IPTYPE] = METIS_IPTYPE_GROW; } ////////////////////////////////////////////////////////////////////////// -MetisPartitioner::~MetisPartitioner() -= default; +MetisPartitioner::~MetisPartitioner() = default; ////////////////////////////////////////////////////////////////////////// -idx_t* MetisPartitioner::getMetisOptions() -{ - return options; -} -void MetisPartitioner::setMetisOptions(int option, idx_t value) -{ - options[option] = value; -} +idx_t *MetisPartitioner::getMetisOptions() { return options; } +void MetisPartitioner::setMetisOptions(int option, idx_t value) { options[option] = value; } ////////////////////////////////////////////////////////////////////////// int MetisPartitioner::partition(int nofParts, MetisPartitioner::PartType ptype) { - int rc; - idx_t nvtxs = (idx_t)xadj.size()-1; // number of nodes - idx_t ncon = (idx_t)vwgt.size()/nvtxs; // number Of node constraints; - part.resize(nvtxs); - idx_t edgecutCount = 0; - idx_t nofPartsMetis = (idx_t)nofParts; + int rc; + idx_t nvtxs = (idx_t)xadj.size() - 1; // number of nodes + idx_t ncon = (idx_t)vwgt.size() / nvtxs; // number Of node constraints; + part.resize(nvtxs); + idx_t edgecutCount = 0; + idx_t nofPartsMetis = (idx_t)nofParts; + + switch (ptype) { + case MetisPartitioner::RECURSIVE: + if (nofParts < 1) + UB_THROW(UbException(UB_EXARGS, "invalid nofParts<1")); + else if (nofParts == 1) { + part.resize(nvtxs, 0); + return 0; + } + // else if( nofParts > 8 ) UBLOG(logWARNING, "MetisPartitioner::Recursive: !!!Warning!!! best for + // nofParts<=8 --> Kway is maybe a better option"); - switch (ptype) - { - case MetisPartitioner::RECURSIVE: - if ( nofParts < 1 ) UB_THROW( UbException(UB_EXARGS,"invalid nofParts<1") ); - else if (nofParts == 1) { part.resize(nvtxs, 0); return 0; } - //else if( nofParts > 8 ) UBLOG(logWARNING, "MetisPartitioner::Recursive: !!!Warning!!! best for nofParts<=8 --> Kway is maybe a better option"); - - rc = METIS_PartGraphRecursive(&nvtxs, &ncon, &xadj[0], &adjncy[0], - &vwgt[0], vsize, &adjwgt[0], &nofPartsMetis, - tpwgts, ubvec, options, &edgecutCount, &part[0]); - break; - case MetisPartitioner::KWAY: - if ( nofParts < 1 ) UB_THROW( UbException(UB_EXARGS,"invalid nofParts<1") ); - else if (nofParts == 1) { part.resize(nvtxs, 0); return 0; } - //else if( nofParts < 9 ) UBLOG(logWARNING, "MetisPartitioner::Kway: !!!Warning!!! best for nofParts>8 --> Recursive is maybe a better option"); + rc = METIS_PartGraphRecursive(&nvtxs, &ncon, &xadj[0], &adjncy[0], &vwgt[0], vsize, &adjwgt[0], + &nofPartsMetis, tpwgts, ubvec, options, &edgecutCount, &part[0]); + break; + case MetisPartitioner::KWAY: + if (nofParts < 1) + UB_THROW(UbException(UB_EXARGS, "invalid nofParts<1")); + else if (nofParts == 1) { + part.resize(nvtxs, 0); + return 0; + } + // else if( nofParts < 9 ) UBLOG(logWARNING, "MetisPartitioner::Kway: !!!Warning!!! best for nofParts>8 + // --> Recursive is maybe a better option"); - rc = METIS_PartGraphKway(&nvtxs, &ncon, &xadj[0], &adjncy[0], - &vwgt[0], vsize, &adjwgt[0], &nofPartsMetis, - tpwgts, ubvec, options, &edgecutCount, &part[0]); - break; - } + rc = METIS_PartGraphKway(&nvtxs, &ncon, &xadj[0], &adjncy[0], &vwgt[0], vsize, &adjwgt[0], &nofPartsMetis, + tpwgts, ubvec, options, &edgecutCount, &part[0]); + break; + } - switch (rc) - { - case METIS_ERROR_INPUT: - throw UbException(UB_EXARGS,"METIS: input error"); - break; - case METIS_ERROR_MEMORY: - throw UbException(UB_EXARGS,"METIS: it could not allocate the required memory"); - break; - case METIS_ERROR: - throw UbException(UB_EXARGS,"METIS: error"); - break; - } + switch (rc) { + case METIS_ERROR_INPUT: + throw UbException(UB_EXARGS, "METIS: input error"); + break; + case METIS_ERROR_MEMORY: + throw UbException(UB_EXARGS, "METIS: it could not allocate the required memory"); + break; + case METIS_ERROR: + throw UbException(UB_EXARGS, "METIS: error"); + break; + } - return edgecutCount; + return edgecutCount; } #endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.h b/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.h index 339238684..8fd7a82d5 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.h +++ b/src/cpu/VirtualFluidsCore/Parallel/MetisPartitioner.h @@ -1,59 +1,63 @@ /** -* @file MetisPartitioner.h -* @brief Class use METIS library for graph-based partitioning. -* @author Kostyantyn Kucher -* @date 22.09.2011 -*/ + * @file MetisPartitioner.h + * @brief Class use METIS library for graph-based partitioning. + * @author Kostyantyn Kucher + * @date 22.09.2011 + */ #ifndef METISPARTITIONER_H #define METISPARTITIONER_H #if defined VF_METIS -#include "metis.h" -#include <vector> -#include <string> -#include <PointerDefinitions.h> #include "basics/utilities/UbLogger.h" #include "basics/utilities/UbSystem.h" +#include "metis.h" +#include <PointerDefinitions.h> +#include <string> +#include <vector> class MetisPartitioner { public: - enum PartType { RECURSIVE, KWAY }; + enum PartType { RECURSIVE, KWAY }; + public: - MetisPartitioner(); - virtual ~MetisPartitioner(); - idx_t* getMetisOptions(); - void setMetisOptions(int option, idx_t value); - int partition(int nofParts, PartType ptype); + MetisPartitioner(); + virtual ~MetisPartitioner(); + idx_t *getMetisOptions(); + void setMetisOptions(int option, idx_t value); + int partition(int nofParts, PartType ptype); + public: - std::vector<idx_t> xadj; // adjncy offset of nodes - //(size = n+1, n=nofNodes) - std::vector<idx_t> adjncy; // array that stores the adjacency lists of nodes - //(size = m*2, m= nofEdged, factor 2 because edge A->B AND B->A has to be stored) - std::vector<idx_t> vwgt; // vertex weights (size=n*ncon, ncon=nofNodeWeightsPerNode) - std::vector<idx_t> adjwgt; // array that stores the weights of the adjacency lists - // (size=2*m) - idx_t * vsize; // array that stores the computation weights per node - // (size=n) - - real_t * tpwgts; // holds the wished fratcion of segment i, e.g. tpwgts={0.2, 0.2, 0.6} - // -> patisions 0 and one will get 20% of the weight each and part 3 60%! - // (size=nofPartitions) sum of tpwgts must be 1.0 - - real_t * ubvec; //This is an array of size ncon that specifies the allowed load imbalance tolerance for each constraint. - //For the ith partition and jth constraint the allowed weight is the ubvec[j]*tpwgts[i*ncon+j] fraction - //of the jth’s constraint total weight. The load imbalances must be greater than 1.0. - //A NULL value can be passed indicating that the load imbalance tolerance for each constraint should - //be 1.001 (for ncon=1) or 1.01 (for ncon¿1). - - std::vector<idx_t> part; // This is a vector of size n that upon successful completion stores the partition vector of the graph. - // The numbering of this vector starts from 0 + std::vector<idx_t> xadj; // adjncy offset of nodes + //(size = n+1, n=nofNodes) + std::vector<idx_t> adjncy; // array that stores the adjacency lists of nodes + //(size = m*2, m= nofEdged, factor 2 because edge A->B AND B->A has to be stored) + std::vector<idx_t> vwgt; // vertex weights (size=n*ncon, ncon=nofNodeWeightsPerNode) + std::vector<idx_t> adjwgt; // array that stores the weights of the adjacency lists + // (size=2*m) + idx_t *vsize; // array that stores the computation weights per node + // (size=n) + + real_t *tpwgts; // holds the wished fratcion of segment i, e.g. tpwgts={0.2, 0.2, 0.6} + // -> patisions 0 and one will get 20% of the weight each and part 3 60%! + // (size=nofPartitions) sum of tpwgts must be 1.0 + + real_t * + ubvec; // This is an array of size ncon that specifies the allowed load imbalance tolerance for each constraint. + // For the ith partition and jth constraint the allowed weight is the ubvec[j]*tpwgts[i*ncon+j] fraction + // of the jth’s constraint total weight. The load imbalances must be greater than 1.0. + // A NULL value can be passed indicating that the load imbalance tolerance for each constraint should + // be 1.001 (for ncon=1) or 1.01 (for ncon¿1). + + std::vector<idx_t> + part; // This is a vector of size n that upon successful completion stores the partition vector of the graph. + // The numbering of this vector starts from 0 private: - idx_t options[METIS_NOPTIONS]; + idx_t options[METIS_NOPTIONS]; }; #endif -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.cpp b/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.cpp index 520206d48..d3846dfd3 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,74 +33,32 @@ #include "NullCommunicator.h" - -NullCommunicator::NullCommunicator() -= default; +NullCommunicator::NullCommunicator() = default; ////////////////////////////////////////////////////////////////////////// -NullCommunicator::~NullCommunicator() -= default; +NullCommunicator::~NullCommunicator() = default; ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getBundleID() -{ - return 0; -} +int NullCommunicator::getBundleID() { return 0; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getNumberOfBundles() -{ - return 0; -} +int NullCommunicator::getNumberOfBundles() { return 0; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getProcessID() -{ - return 0; -} +int NullCommunicator::getProcessID() { return 0; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getNumberOfProcesses() -{ - return 0; -} +int NullCommunicator::getNumberOfProcesses() { return 0; } ////////////////////////////////////////////////////////////////////////// -void* NullCommunicator::getNativeCommunicator() -{ - return NULL; -} +void *NullCommunicator::getNativeCommunicator() { return NULL; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getRoot() -{ - return 0; -} +int NullCommunicator::getRoot() { return 0; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getBundleRoot() -{ - return 0; -} +int NullCommunicator::getBundleRoot() { return 0; } ////////////////////////////////////////////////////////////////////////// -int NullCommunicator::getProcessRoot() -{ - return 0; -} +int NullCommunicator::getProcessRoot() { return 0; } ////////////////////////////////////////////////////////////////////////// -std::vector<std::string> NullCommunicator::gather(const std::string& /*str*/) -{ - return std::vector<std::string>(); -} +std::vector<std::string> NullCommunicator::gather(const std::string & /*str*/) { return std::vector<std::string>(); } ////////////////////////////////////////////////////////////////////////// -std::vector<double> NullCommunicator::gatherDoubles(std::vector<double>& /*values*/) -{ - return std::vector<double>(); -} +std::vector<double> NullCommunicator::gatherDoubles(std::vector<double> & /*values*/) { return std::vector<double>(); } ////////////////////////////////////////////////////////////////////////// -void NullCommunicator::allGatherInts(std::vector<int>& svalues, std::vector<int>& rvalues) -{ - -} +void NullCommunicator::allGatherInts(std::vector<int> &svalues, std::vector<int> &rvalues) {} ////////////////////////////////////////////////////////////////////////// -void NullCommunicator::sendSerializedObject(std::stringstream& ss, int target) -{ - -} +void NullCommunicator::sendSerializedObject(std::stringstream &ss, int target) {} ////////////////////////////////////////////////////////////////////////// -void NullCommunicator::receiveSerializedObject(std::stringstream& ss, int source) -{ - -} +void NullCommunicator::receiveSerializedObject(std::stringstream &ss, int source) {} diff --git a/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.h b/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.h index 2495b7766..3dad3395a 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.h +++ b/src/cpu/VirtualFluidsCore/Parallel/NullCommunicator.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -43,21 +43,22 @@ class NullCommunicator : public Communicator { public: - NullCommunicator(); - ~NullCommunicator() override; - int getBundleID() override; - int getNumberOfBundles() override; - int getProcessID() override; - int getNumberOfProcesses() override; - void* getNativeCommunicator() override; - int getRoot() override; - int getBundleRoot() override; - int getProcessRoot() override; - std::vector<std::string> gather(const std::string& str) override; - std::vector<double> gatherDoubles(std::vector<double>& values); - void allGatherInts(std::vector<int>& svalues, std::vector<int>& rvalues); - void sendSerializedObject(std::stringstream& ss, int target) override; - void receiveSerializedObject(std::stringstream& ss, int source) override; + NullCommunicator(); + ~NullCommunicator() override; + int getBundleID() override; + int getNumberOfBundles() override; + int getProcessID() override; + int getNumberOfProcesses() override; + void *getNativeCommunicator() override; + int getRoot() override; + int getBundleRoot() override; + int getProcessRoot() override; + std::vector<std::string> gather(const std::string &str) override; + std::vector<double> gatherDoubles(std::vector<double> &values); + void allGatherInts(std::vector<int> &svalues, std::vector<int> &rvalues); + void sendSerializedObject(std::stringstream &ss, int target) override; + void receiveSerializedObject(std::stringstream &ss, int source) override; + protected: private: }; diff --git a/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.cpp b/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.cpp index 4d3ad4201..75c16210d 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.cpp @@ -1,2 +1 @@ #include "PriorityQueueDecompositor.h" - diff --git a/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.h b/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.h index a5234fd95..b6d8d8f0a 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.h +++ b/src/cpu/VirtualFluidsCore/Parallel/PriorityQueueDecompositor.h @@ -1,66 +1,62 @@ /** -* @file PriorityQueueDecompositor.h -* @brief Priority Queue for threads decomposition. -* @author Kostyantyn Kucher -* @date 06/06/2011 -*/ + * @file PriorityQueueDecompositor.h + * @brief Priority Queue for threads decomposition. + * @author Kostyantyn Kucher + * @date 06/06/2011 + */ #ifndef PRIORITYQUEUEDECOMPOSITOR_H #define PRIORITYQUEUEDECOMPOSITOR_H #include <algorithm> -#include <vector> #include <map> +#include <vector> struct sortMinMax { - bool operator() (int i,int j) const { return (i<j);} + bool operator()(int i, int j) const { return (i < j); } }; struct sortMaxMin { - bool operator() (int i,int j) const { return (i>j);} + bool operator()(int i, int j) const { return (i > j); } }; template <class T> class PriorityQueueDecompositor { public: - PriorityQueueDecompositor(const std::vector<T>& objcts, const std::vector<int>& weights, const int& numberOfParts) - { - for (int i = 0; i < (int)objcts.size(); i++) - { - objects.insert(std::pair<int, T>(weights[i], objcts[i])); - } - for (int i = 0; i < numberOfParts; i++) - { - std::vector<T> part; - parts.insert(std::pair<int,std::vector<T> >(0, part)); - } - } - virtual ~PriorityQueueDecompositor() - = default; - void getDecomposition(std::vector< std::vector<T> >& prts) - { - for( itOb=objects.begin() ; itOb != objects.end(); itOb++) - { - itP = parts.begin(); - int weight = (*itP).first; - std::vector<T> obj = (*itP).second; - parts.erase(itP); - weight += (*itOb).first; - obj.push_back((*itOb).second); - parts.insert(std::pair<int,std::vector<T> >(weight, obj)); - } + PriorityQueueDecompositor(const std::vector<T> &objcts, const std::vector<int> &weights, const int &numberOfParts) + { + for (int i = 0; i < (int)objcts.size(); i++) { + objects.insert(std::pair<int, T>(weights[i], objcts[i])); + } + for (int i = 0; i < numberOfParts; i++) { + std::vector<T> part; + parts.insert(std::pair<int, std::vector<T>>(0, part)); + } + } + virtual ~PriorityQueueDecompositor() = default; + void getDecomposition(std::vector<std::vector<T>> &prts) + { + for (itOb = objects.begin(); itOb != objects.end(); itOb++) { + itP = parts.begin(); + int weight = (*itP).first; + std::vector<T> obj = (*itP).second; + parts.erase(itP); + weight += (*itOb).first; + obj.push_back((*itOb).second); + parts.insert(std::pair<int, std::vector<T>>(weight, obj)); + } + + for (itP = parts.begin(); itP != parts.end(); itP++) { + prts.push_back((*itP).second); + } + } - for( itP=parts.begin() ; itP != parts.end(); itP++) - { - prts.push_back((*itP).second); - } - } protected: private: - std::multimap<int, T, sortMaxMin> objects; - typename std::multimap<int, T, sortMaxMin>::iterator itOb; - std::multimap<int, std::vector<T>, sortMinMax> parts; - typename std::multimap<int, std::vector<T>, sortMinMax>::iterator itP; + std::multimap<int, T, sortMaxMin> objects; + typename std::multimap<int, T, sortMaxMin>::iterator itOb; + std::multimap<int, std::vector<T>, sortMinMax> parts; + typename std::multimap<int, std::vector<T>, sortMinMax>::iterator itP; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/SimpleGeometricPartitioner.h b/src/cpu/VirtualFluidsCore/Parallel/SimpleGeometricPartitioner.h index b7b62c1dd..ee9e56af9 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/SimpleGeometricPartitioner.h +++ b/src/cpu/VirtualFluidsCore/Parallel/SimpleGeometricPartitioner.h @@ -1,97 +1,96 @@ /** -* @file SimpleGeometricPartitioner.h -* @author Kostyantyn Kucher -* @date 06/06/2011 -* -* @section DESCRIPTION -* -* This class make simple geometric partitioning. -*/ + * @file SimpleGeometricPartitioner.h + * @author Kostyantyn Kucher + * @date 06/06/2011 + * + * @section DESCRIPTION + * + * This class make simple geometric partitioning. + */ -#ifndef SIMPLEGEOMETRICPARTITIONER_H +#ifndef SIMPLEGEOMETRICPARTITIONER_H #define SIMPLEGEOMETRICPARTITIONER_H -#include "basics/utilities/UbTuple.h" -#include "basics/utilities/UbException.h" #include "MathUtil.hpp" +#include "basics/utilities/UbException.h" +#include "basics/utilities/UbTuple.h" class SimpleGeometricPartitioner { public: - static UbTupleInt3 createDimensions(const int& x, const int& y, const int& z, const int& numberOfProcess) - { - int xyz = x*y*z; + static UbTupleInt3 createDimensions(const int &x, const int &y, const int &z, const int &numberOfProcess) + { + int xyz = x * y * z; - int p = numberOfProcess; + int p = numberOfProcess; - if (p == 1) - return {1, 1, 1}; + if (p == 1) + return { 1, 1, 1 }; - double a = pow(p*pow(x,3.0)/xyz,1.0/3.0); - double b = pow(p*pow(y,3.0)/xyz,1.0/3.0); - double c = pow(p*pow(z,3.0)/xyz,1.0/3.0); + double a = pow(p * pow(x, 3.0) / xyz, 1.0 / 3.0); + double b = pow(p * pow(y, 3.0) / xyz, 1.0 / 3.0); + double c = pow(p * pow(z, 3.0) / xyz, 1.0 / 3.0); - MaxDim maxDim; - - if(c >= a && c >= b) - maxDim = cDim; - if(b >= a && b >= c) - maxDim = bDim; - if(a >= b && a >= c) - maxDim = aDim; + MaxDim maxDim; - int dim1, dim2, dim3; - dim1 = (int)Utilities::cint(a); - dim2 = (int)Utilities::cint(b); - dim3 = (int)Utilities::cint(c); - if(dim1 <= 0) dim1 = 1; - if(dim2 <= 0) dim2 = 1; - if(dim3 <= 0) dim3 = 1; + if (c >= a && c >= b) + maxDim = cDim; + if (b >= a && b >= c) + maxDim = bDim; + if (a >= b && a >= c) + maxDim = aDim; - switch (maxDim) - { - case aDim: - dim1 = p/(dim2*dim3); - if (dim1*dim2*dim3 != p) - { - dim2 = 1; - dim3 = 1; - dim1 = p; - } - break; - case bDim: - dim2 = p/(dim1*dim3); - if (dim1*dim2*dim3 != p) - { - dim1 = 1; - dim3 = 1; - dim2 = p; - } - break; - case cDim: - dim3 = p/(dim1*dim2); - if (dim1*dim2*dim3 != p) - { + int dim1, dim2, dim3; + dim1 = (int)Utilities::cint(a); + dim2 = (int)Utilities::cint(b); + dim3 = (int)Utilities::cint(c); + if (dim1 <= 0) dim1 = 1; + if (dim2 <= 0) dim2 = 1; - dim3 = p; - } - break; - } + if (dim3 <= 0) + dim3 = 1; + + switch (maxDim) { + case aDim: + dim1 = p / (dim2 * dim3); + if (dim1 * dim2 * dim3 != p) { + dim2 = 1; + dim3 = 1; + dim1 = p; + } + break; + case bDim: + dim2 = p / (dim1 * dim3); + if (dim1 * dim2 * dim3 != p) { + dim1 = 1; + dim3 = 1; + dim2 = p; + } + break; + case cDim: + dim3 = p / (dim1 * dim2); + if (dim1 * dim2 * dim3 != p) { + dim1 = 1; + dim2 = 1; + dim3 = p; + } + break; + } + + if (dim1 > x || dim2 > y || dim3 > z) { + UB_THROW(UbException( + UB_EXARGS, "SimpleGeometricPartitioner::createDimensions: Segmentation fault - bad number of prozess")); + } - if (dim1>x || dim2>y || dim3>z) - { - UB_THROW( UbException(UB_EXARGS,"SimpleGeometricPartitioner::createDimensions: Segmentation fault - bad number of prozess") ); - } + UbTupleInt3 dims(dim1, dim2, dim3); - UbTupleInt3 dims(dim1, dim2, dim3); - - return dims; - } + return dims; + } protected: private: - enum MaxDim {aDim,bDim,cDim}; + enum MaxDim { aDim, bDim, cDim }; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.cpp b/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.cpp index 3aa51f030..220fe67c5 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.cpp +++ b/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.cpp @@ -9,196 +9,172 @@ using namespace std; ////////////////////////////////////////////////////////////////////////// -ZoltanPartitioner::ZoltanPartitioner(MPI_Comm comm, int rank, int numberOfLocalParts): - comm(comm), rank(rank), numberOfLocalParts(numberOfLocalParts),lb_approach("PARTITION") +ZoltanPartitioner::ZoltanPartitioner(MPI_Comm comm, int rank, int numberOfLocalParts) + : comm(comm), rank(rank), numberOfLocalParts(numberOfLocalParts), lb_approach("PARTITION") { - int rc; - float ver; - - rc = Zoltan_Initialize(0, NULL, &ver); - - if (rc != ZOLTAN_OK){ - cout<<"Sorry, Zoltan can't be initialized\n"<<endl; - MPI_Finalize(); - exit(0); - } - /****************************************************************** - ** Create a Zoltan library structure for this instance of load - ** balancing. Set the parameters and query functions that will - ** govern the library's calculation. See the Zoltan User's - ** Guide for the definition of these and many other parameters. - ******************************************************************/ - - zz = Zoltan_Create(comm); + int rc; + float ver; + + rc = Zoltan_Initialize(0, NULL, &ver); + + if (rc != ZOLTAN_OK) { + cout << "Sorry, Zoltan can't be initialized\n" << endl; + MPI_Finalize(); + exit(0); + } + /****************************************************************** + ** Create a Zoltan library structure for this instance of load + ** balancing. Set the parameters and query functions that will + ** govern the library's calculation. See the Zoltan User's + ** Guide for the definition of these and many other parameters. + ******************************************************************/ + + zz = Zoltan_Create(comm); } ////////////////////////////////////////////////////////////////////////// -ZoltanPartitioner::~ZoltanPartitioner() -{ - Zoltan_Destroy(&zz); -} +ZoltanPartitioner::~ZoltanPartitioner() { Zoltan_Destroy(&zz); } ////////////////////////////////////////////////////////////////////////// void ZoltanPartitioner::partition() { - //General parameters - Zoltan_Set_Param(zz, "DEBUG_LEVEL", "0"); - Zoltan_Set_Param(zz, "LB_METHOD", "GRAPH"); - Zoltan_Set_Param(zz, "LB_APPROACH", lb_approach.c_str()); - Zoltan_Set_Param(zz, "NUM_GID_ENTRIES", "1"); - Zoltan_Set_Param(zz, "NUM_LID_ENTRIES", "1"); - Zoltan_Set_Param(zz, "RETURN_LISTS", "ALL"); - string nparts(UbSystem::toString<int>(numberOfLocalParts)); - Zoltan_Set_Param(zz, "NUM_LOCAL_PARTS", nparts.c_str()); - - /* Query functions - defined in simpleQueries.h */ - - Zoltan_Set_Num_Obj_Fn(zz, get_number_of_vertices, &graph); - Zoltan_Set_Obj_List_Fn(zz, get_vertex_list, &graph); - Zoltan_Set_Num_Edges_Multi_Fn(zz, get_num_edges_list, &graph); - Zoltan_Set_Edge_List_Multi_Fn(zz, get_edge_list, &graph); - - /****************************************************************** - ** Zoltan can now partition the graph. - ** In this case, we assume the number of partitions is - ** equal to the number of processes. Process rank 0 will own - ** partition 0, process rank 1 will own partition 1, and so on. - ******************************************************************/ - - int rc = Zoltan_LB_Partition(zz, /* input (all remaining fields are output) */ - &changes, /* 1 if partitioning was changed, 0 otherwise */ - &numGidEntries, /* Number of integers used for a global ID */ - &numLidEntries, /* Number of integers used for a local ID */ - &numImport, /* Number of vertices to be sent to me */ - &importGlobalGids, /* Global IDs of vertices to be sent to me */ - &importLocalGids, /* Local IDs of vertices to be sent to me */ - &importProcs, /* Process rank for source of each incoming vertex */ - &importToPart, /* New partition for each incoming vertex */ - &numExport, /* Number of vertices I must send to other processes*/ - &exportGlobalGids, /* Global IDs of the vertices I must send */ - &exportLocalGids, /* Local IDs of the vertices I must send */ - &exportProcs, /* Process to which I send each of the vertices */ - &exportToPart); /* Partition to which each vertex will belong */ - - - - if (rc != ZOLTAN_OK){ - cout << "Partitioning failed on process " << rank <<"\n" << endl; - MPI_Finalize(); - Zoltan_Destroy(&zz); - exit(0); - } + // General parameters + Zoltan_Set_Param(zz, "DEBUG_LEVEL", "0"); + Zoltan_Set_Param(zz, "LB_METHOD", "GRAPH"); + Zoltan_Set_Param(zz, "LB_APPROACH", lb_approach.c_str()); + Zoltan_Set_Param(zz, "NUM_GID_ENTRIES", "1"); + Zoltan_Set_Param(zz, "NUM_LID_ENTRIES", "1"); + Zoltan_Set_Param(zz, "RETURN_LISTS", "ALL"); + string nparts(UbSystem::toString<int>(numberOfLocalParts)); + Zoltan_Set_Param(zz, "NUM_LOCAL_PARTS", nparts.c_str()); + + /* Query functions - defined in simpleQueries.h */ + + Zoltan_Set_Num_Obj_Fn(zz, get_number_of_vertices, &graph); + Zoltan_Set_Obj_List_Fn(zz, get_vertex_list, &graph); + Zoltan_Set_Num_Edges_Multi_Fn(zz, get_num_edges_list, &graph); + Zoltan_Set_Edge_List_Multi_Fn(zz, get_edge_list, &graph); + + /****************************************************************** + ** Zoltan can now partition the graph. + ** In this case, we assume the number of partitions is + ** equal to the number of processes. Process rank 0 will own + ** partition 0, process rank 1 will own partition 1, and so on. + ******************************************************************/ + + int rc = Zoltan_LB_Partition(zz, /* input (all remaining fields are output) */ + &changes, /* 1 if partitioning was changed, 0 otherwise */ + &numGidEntries, /* Number of integers used for a global ID */ + &numLidEntries, /* Number of integers used for a local ID */ + &numImport, /* Number of vertices to be sent to me */ + &importGlobalGids, /* Global IDs of vertices to be sent to me */ + &importLocalGids, /* Local IDs of vertices to be sent to me */ + &importProcs, /* Process rank for source of each incoming vertex */ + &importToPart, /* New partition for each incoming vertex */ + &numExport, /* Number of vertices I must send to other processes*/ + &exportGlobalGids, /* Global IDs of the vertices I must send */ + &exportLocalGids, /* Local IDs of the vertices I must send */ + &exportProcs, /* Process to which I send each of the vertices */ + &exportToPart); /* Partition to which each vertex will belong */ + + if (rc != ZOLTAN_OK) { + cout << "Partitioning failed on process " << rank << "\n" << endl; + MPI_Finalize(); + Zoltan_Destroy(&zz); + exit(0); + } } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::setLB_APPROACH(std::string lb_approach) -{ - this->lb_approach = lb_approach; -} +void ZoltanPartitioner::setLB_APPROACH(std::string lb_approach) { this->lb_approach = lb_approach; } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::setNumberOfLocalParts(int numberOfLocalParts) -{ - this->numberOfLocalParts = numberOfLocalParts; -} +void ZoltanPartitioner::setNumberOfLocalParts(int numberOfLocalParts) { this->numberOfLocalParts = numberOfLocalParts; } ////////////////////////////////////////////////////////////////////////// // Application defined query functions // ////////////////////////////////////////////////////////////////////////// int ZoltanPartitioner::get_number_of_vertices(void *data, int *ierr) { - ZoltanGraph *graph = (ZoltanGraph *)data; - *ierr = ZOLTAN_OK; - return graph->numLocalVertices; + ZoltanGraph *graph = (ZoltanGraph *)data; + *ierr = ZOLTAN_OK; + return graph->numLocalVertices; } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::get_vertex_list(void *data, int sizeGID, int sizeLID, - ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int wgt_dim, float *obj_wgts, int *ierr) +void ZoltanPartitioner::get_vertex_list(void *data, int sizeGID, int sizeLID, ZOLTAN_ID_PTR globalID, + ZOLTAN_ID_PTR localID, int wgt_dim, float *obj_wgts, int *ierr) { - ZoltanGraph *graph = (ZoltanGraph *)data; - *ierr = ZOLTAN_OK; + ZoltanGraph *graph = (ZoltanGraph *)data; + *ierr = ZOLTAN_OK; - /* In this case, return the IDs of our vertices, but no weights. - * Zoltan will assume equally weighted vertices. - */ + /* In this case, return the IDs of our vertices, but no weights. + * Zoltan will assume equally weighted vertices. + */ - for (int i=0; i<graph->numLocalVertices; i++){ - globalID[i] = graph->vvertexGID[i]; - localID[i] = i; - } + for (int i = 0; i < graph->numLocalVertices; i++) { + globalID[i] = graph->vvertexGID[i]; + localID[i] = i; + } } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::get_num_edges_list(void *data, int sizeGID, int sizeLID, - int num_obj, - ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int *numEdges, int *ierr) +void ZoltanPartitioner::get_num_edges_list(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, + ZOLTAN_ID_PTR localID, int *numEdges, int *ierr) { - ZoltanGraph *graph = (ZoltanGraph *)data; + ZoltanGraph *graph = (ZoltanGraph *)data; - if ( (sizeGID != 1) || (sizeLID != 1) || (num_obj != graph->numLocalVertices)){ - *ierr = ZOLTAN_FATAL; - return; - } + if ((sizeGID != 1) || (sizeLID != 1) || (num_obj != graph->numLocalVertices)) { + *ierr = ZOLTAN_FATAL; + return; + } - for (int i=0; i < num_obj ; i++){ - numEdges[i] = graph->vnumEdges[i]; - } + for (int i = 0; i < num_obj; i++) { + numEdges[i] = graph->vnumEdges[i]; + } - *ierr = ZOLTAN_OK; - return; + *ierr = ZOLTAN_OK; + return; } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::get_edge_list(void *data, int sizeGID, int sizeLID, - int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int *num_edges, - ZOLTAN_ID_PTR nborGID, int *nborProc, +void ZoltanPartitioner::get_edge_list(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, + ZOLTAN_ID_PTR localID, int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborProc, int wgt_dim, float *ewgts, int *ierr) { - int *nextNbor, *nextProc; - - ZoltanGraph *graph = (ZoltanGraph *)data; - *ierr = ZOLTAN_OK; - - if ( (sizeGID != 1) || (sizeLID != 1) || - (num_obj != graph->numLocalVertices)|| - (wgt_dim != 0)){ - *ierr = ZOLTAN_FATAL; - return; - } - - nextNbor = (int *)nborGID; - nextProc = nborProc; - - int n=0; - for (int i=0; i < num_obj; i++){ - - /* - * In this case, we are not setting edge weights. Zoltan will - * set each edge to weight 1.0. - */ - - for (int j=0; j < num_edges[i]; j++){ - nborGID[n] = graph->vnborGID[n]; - nborProc[n] = graph->vnborProc[n]; - n++; - } - } - return; + int *nextNbor, *nextProc; + + ZoltanGraph *graph = (ZoltanGraph *)data; + *ierr = ZOLTAN_OK; + + if ((sizeGID != 1) || (sizeLID != 1) || (num_obj != graph->numLocalVertices) || (wgt_dim != 0)) { + *ierr = ZOLTAN_FATAL; + return; + } + + nextNbor = (int *)nborGID; + nextProc = nborProc; + + int n = 0; + for (int i = 0; i < num_obj; i++) { + + /* + * In this case, we are not setting edge weights. Zoltan will + * set each edge to weight 1.0. + */ + + for (int j = 0; j < num_edges[i]; j++) { + nborGID[n] = graph->vnborGID[n]; + nborProc[n] = graph->vnborProc[n]; + n++; + } + } + return; } ////////////////////////////////////////////////////////////////////////// -ZoltanGraph* ZoltanPartitioner::getGraphData() -{ - return &graph; -} +ZoltanGraph *ZoltanPartitioner::getGraphData() { return &graph; } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioner::getExportData(vector<int>& exportGlobalGids, vector<int>& exportToPart, vector<int>& exportProcs) +void ZoltanPartitioner::getExportData(vector<int> &exportGlobalGids, vector<int> &exportToPart, + vector<int> &exportProcs) { - for (int i = 0; i < this->numExport; i++) - { - exportGlobalGids.push_back(static_cast<int> (this->exportGlobalGids[i])); - exportToPart.push_back(this->exportToPart[i]); - exportProcs.push_back(this->exportProcs[i]); - } + for (int i = 0; i < this->numExport; i++) { + exportGlobalGids.push_back(static_cast<int>(this->exportGlobalGids[i])); + exportToPart.push_back(this->exportToPart[i]); + exportProcs.push_back(this->exportProcs[i]); + } } ////////////////////////////////////////////////////////////////////////// - bool ZoltanPartitioner::areChanges() - { - return static_cast<bool>(this->changes); - } +bool ZoltanPartitioner::areChanges() { return static_cast<bool>(this->changes); } #endif diff --git a/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.h b/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.h index 2bfea8877..402e6b960 100644 --- a/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.h +++ b/src/cpu/VirtualFluidsCore/Parallel/ZoltanPartitioner.h @@ -1,9 +1,9 @@ /** -* @file ZoltanPartitioner.h -* @brief Class use Zoltan library for graph-based partitioning. -* @author Kostyantyn Kucher -* @date 10.06.2011 -*/ + * @file ZoltanPartitioner.h + * @brief Class use Zoltan library for graph-based partitioning. + * @author Kostyantyn Kucher + * @date 10.06.2011 + */ #ifndef ZOLTANPARTITIONER_H #define ZOLTANPARTITIONER_H @@ -11,64 +11,60 @@ #if defined VF_ZOLTAN && defined VF_MPI #include "zoltan.h" -#include <vector> #include <string> +#include <vector> /* Structure to hold graph data */ -struct ZoltanGraph{ - int numLocalVertices; // total vertices in in this partition - std::vector<int> vvertexGID; // global ID of each of my vertices - std::vector<int> vnumEdges; // number of Edges - std::vector<int> vnborGID; // global ID of neighbors - std::vector<int> vnborProc; // process owning each nbor in nborGID +struct ZoltanGraph { + int numLocalVertices; // total vertices in in this partition + std::vector<int> vvertexGID; // global ID of each of my vertices + std::vector<int> vnumEdges; // number of Edges + std::vector<int> vnborGID; // global ID of neighbors + std::vector<int> vnborProc; // process owning each nbor in nborGID }; -struct Zoltan_Output{ - ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids, exportLocalGids; - int *importProcs, *importToPart, *exportProcs, *exportToPart; - int changes, numGidEntries, numLidEntries, numImport, numExport; +struct Zoltan_Output { + ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids, exportLocalGids; + int *importProcs, *importToPart, *exportProcs, *exportToPart; + int changes, numGidEntries, numLidEntries, numImport, numExport; }; class ZoltanPartitioner { public: - ZoltanPartitioner(MPI_Comm comm , int rank, int numberOfLocalParts); - virtual ~ZoltanPartitioner(); - void partition(); - ZoltanGraph* getGraphData(); - void setLB_APPROACH(std::string lb_approach); - void setNumberOfLocalParts(int numberOfLocalParts); - void getExportData(std::vector<int>& exportGlobalGids, std::vector<int>& exportToPart, std::vector<int>& exportProcs); - bool areChanges(); + ZoltanPartitioner(MPI_Comm comm, int rank, int numberOfLocalParts); + virtual ~ZoltanPartitioner(); + void partition(); + ZoltanGraph *getGraphData(); + void setLB_APPROACH(std::string lb_approach); + void setNumberOfLocalParts(int numberOfLocalParts); + void getExportData(std::vector<int> &exportGlobalGids, std::vector<int> &exportToPart, + std::vector<int> &exportProcs); + bool areChanges(); protected: - static int get_number_of_vertices(void *data, int *ierr); - static void get_vertex_list(void *data, int sizeGID, int sizeLID, - ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int wgt_dim, float *obj_wgts, int *ierr); - static void get_num_edges_list(void *data, int sizeGID, int sizeLID, - int num_obj, - ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int *numEdges, int *ierr); - static void get_edge_list(void *data, int sizeGID, int sizeLID, - int num_obj, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, - int *num_edges, - ZOLTAN_ID_PTR nborGID, int *nborProc, - int wgt_dim, float *ewgts, int *ierr); + static int get_number_of_vertices(void *data, int *ierr); + static void get_vertex_list(void *data, int sizeGID, int sizeLID, ZOLTAN_ID_PTR globalID, ZOLTAN_ID_PTR localID, + int wgt_dim, float *obj_wgts, int *ierr); + static void get_num_edges_list(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, + ZOLTAN_ID_PTR localID, int *numEdges, int *ierr); + static void get_edge_list(void *data, int sizeGID, int sizeLID, int num_obj, ZOLTAN_ID_PTR globalID, + ZOLTAN_ID_PTR localID, int *num_edges, ZOLTAN_ID_PTR nborGID, int *nborProc, int wgt_dim, + float *ewgts, int *ierr); private: - MPI_Comm comm; - int rank; - int numberOfLocalParts; - struct Zoltan_Struct *zz; - std::string lb_approach; - ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids, exportLocalGids; - int *importProcs, *importToPart, *exportProcs, *exportToPart; - int changes, numGidEntries, numLidEntries, numImport, numExport; - ZoltanGraph graph; + MPI_Comm comm; + int rank; + int numberOfLocalParts; + struct Zoltan_Struct *zz; + std::string lb_approach; + ZOLTAN_ID_PTR importGlobalGids, importLocalGids, exportGlobalGids, exportLocalGids; + int *importProcs, *importToPart, *exportProcs, *exportToPart; + int changes, numGidEntries, numLidEntries, numImport, numExport; + ZoltanGraph graph; }; #endif -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.cpp b/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.cpp index fe58829b1..914659afa 100644 --- a/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.cpp +++ b/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.cpp @@ -1,595 +1,650 @@ #include "CheckpointConverter.h" -#include <MemoryUtil.h> -#include "BoundaryConditions.h" #include "Block3D.h" -#include "DataSet3D.h" -#include "Grid3D.h" +#include "BoundaryConditions.h" #include "Communicator.h" #include "CoordinateTransformation3D.h" +#include "DataSet3D.h" +#include "Grid3D.h" +#include <MemoryUtil.h> #include <cstdio> #define BLOCK_SIZE 1024 using namespace MPIIODataStructures; -CheckpointConverter::CheckpointConverter(SPtr<Grid3D> grid, const std::string& path, SPtr<Communicator> comm) : - grid(grid), path(path), comm(comm) +CheckpointConverter::CheckpointConverter(SPtr<Grid3D> grid, const std::string &path, SPtr<Communicator> comm) + : grid(grid), path(path), comm(comm) { - UbSystem::makeDirectory(path + "/mpi_io_cp"); - - memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); + UbSystem::makeDirectory(path + "/mpi_io_cp"); - //------------------------- define MPI types --------------------------------- + memset(&boundCondParamStr, 0, sizeof(boundCondParamStr)); - MPI_Datatype typesGP[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksGP[3] = { 34, 6, 5 }; - MPI_Aint offsetsGP[3], lbGP, extentGP; + //------------------------- define MPI types --------------------------------- - offsetsGP[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbGP, &extentGP); - offsetsGP[1] = blocksGP[0] * extentGP; + MPI_Datatype typesGP[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksGP[3] = { 34, 6, 5 }; + MPI_Aint offsetsGP[3], lbGP, extentGP; - MPI_Type_get_extent(MPI_INT, &lbGP, &extentGP); - offsetsGP[2] = offsetsGP[1] + blocksGP[1] * extentGP; + offsetsGP[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbGP, &extentGP); + offsetsGP[1] = blocksGP[0] * extentGP; - MPI_Type_create_struct(3, blocksGP, offsetsGP, typesGP, &gridParamType); - MPI_Type_commit(&gridParamType); + MPI_Type_get_extent(MPI_INT, &lbGP, &extentGP); + offsetsGP[2] = offsetsGP[1] + blocksGP[1] * extentGP; - //----------------------------------------------------------------------- + MPI_Type_create_struct(3, blocksGP, offsetsGP, typesGP, &gridParamType); + MPI_Type_commit(&gridParamType); - MPI_Datatype typesBlock[2] = { MPI_INT, MPI_CHAR }; - int blocksBlock[2] = { 13, 1 }; - MPI_Aint offsetsBlock[2], lbBlock, extentBlock; + //----------------------------------------------------------------------- - offsetsBlock[0] = 0; - MPI_Type_get_extent(MPI_INT, &lbBlock, &extentBlock); - offsetsBlock[1] = blocksBlock[0] * extentBlock; + MPI_Datatype typesBlock[2] = { MPI_INT, MPI_CHAR }; + int blocksBlock[2] = { 13, 1 }; + MPI_Aint offsetsBlock[2], lbBlock, extentBlock; - MPI_Type_create_struct(2, blocksBlock, offsetsBlock, typesBlock, &block3dType); - MPI_Type_commit(&block3dType); + offsetsBlock[0] = 0; + MPI_Type_get_extent(MPI_INT, &lbBlock, &extentBlock); + offsetsBlock[1] = blocksBlock[0] * extentBlock; - //----------------------------------------------------------------------- + MPI_Type_create_struct(2, blocksBlock, offsetsBlock, typesBlock, &block3dType); + MPI_Type_commit(&block3dType); - MPI_Datatype typesBC[3] = { MPI_LONG_LONG_INT, MPI_FLOAT, MPI_CHAR }; - int blocksBC[3] = { 5, 38, 1 }; - MPI_Aint offsetsBC[3], lbBC, extentBC; + //----------------------------------------------------------------------- - offsetsBC[0] = 0; - MPI_Type_get_extent(MPI_LONG_LONG_INT, &lbBC, &extentBC); - offsetsBC[1] = blocksBC[0] * extentBC; + MPI_Datatype typesBC[3] = { MPI_LONG_LONG_INT, MPI_FLOAT, MPI_CHAR }; + int blocksBC[3] = { 5, 38, 1 }; + MPI_Aint offsetsBC[3], lbBC, extentBC; - MPI_Type_get_extent(MPI_FLOAT, &lbBC, &extentBC); - offsetsBC[2] = offsetsBC[1] + blocksBC[1] * extentBC; + offsetsBC[0] = 0; + MPI_Type_get_extent(MPI_LONG_LONG_INT, &lbBC, &extentBC); + offsetsBC[1] = blocksBC[0] * extentBC; - MPI_Type_create_struct(3, blocksBC, offsetsBC, typesBC, &boundCondType); - MPI_Type_commit(&boundCondType); + MPI_Type_get_extent(MPI_FLOAT, &lbBC, &extentBC); + offsetsBC[2] = offsetsBC[1] + blocksBC[1] * extentBC; - //----------------------------------------------------------------------- + MPI_Type_create_struct(3, blocksBC, offsetsBC, typesBC, &boundCondType); + MPI_Type_commit(&boundCondType); - MPI_Type_contiguous(BLOCK_SIZE, boundCondType, &boundCondType1000); - MPI_Type_commit(&boundCondType1000); + //----------------------------------------------------------------------- - //--------------------------------------- + MPI_Type_contiguous(BLOCK_SIZE, boundCondType, &boundCondType1000); + MPI_Type_commit(&boundCondType1000); - MPI_Type_contiguous(7, MPI_INT, &dataSetParamType); - MPI_Type_commit(&dataSetParamType); + //--------------------------------------- - //--------------------------------------- + MPI_Type_contiguous(7, MPI_INT, &dataSetParamType); + MPI_Type_commit(&dataSetParamType); - MPI_Datatype typesDataSetRead[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksDataSetRead[3] = { 2, 5, 2 }; - MPI_Aint offsetsDataSetRead[3], lbDataSetRead, extentDataSetRead; + //--------------------------------------- - offsetsDataSetRead[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbDataSetRead, &extentDataSetRead); - offsetsDataSetRead[1] = blocksDataSetRead[0] * extentDataSetRead; + MPI_Datatype typesDataSetRead[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksDataSetRead[3] = { 2, 5, 2 }; + MPI_Aint offsetsDataSetRead[3], lbDataSetRead, extentDataSetRead; - MPI_Type_get_extent(MPI_INT, &lbDataSetRead, &extentDataSetRead); - offsetsDataSetRead[2] = offsetsDataSetRead[1] + blocksDataSetRead[1] * extentDataSetRead; + offsetsDataSetRead[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbDataSetRead, &extentDataSetRead); + offsetsDataSetRead[1] = blocksDataSetRead[0] * extentDataSetRead; - MPI_Type_create_struct(3, blocksDataSetRead, offsetsDataSetRead, typesDataSetRead, &dataSetTypeRead); - MPI_Type_commit(&dataSetTypeRead); + MPI_Type_get_extent(MPI_INT, &lbDataSetRead, &extentDataSetRead); + offsetsDataSetRead[2] = offsetsDataSetRead[1] + blocksDataSetRead[1] * extentDataSetRead; - //----------------------------------------------------------------------- + MPI_Type_create_struct(3, blocksDataSetRead, offsetsDataSetRead, typesDataSetRead, &dataSetTypeRead); + MPI_Type_commit(&dataSetTypeRead); - MPI_Datatype typesDataSetWrite[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; - int blocksDataSetWrite[3] = { 2, 2, 2 }; - MPI_Aint offsetsDataSetWrite[3], lbDataSetWrite, extentDataSetWrite; + //----------------------------------------------------------------------- - offsetsDataSetWrite[0] = 0; - MPI_Type_get_extent(MPI_DOUBLE, &lbDataSetWrite, &extentDataSetWrite); - offsetsDataSetWrite[1] = blocksDataSetWrite[0] * extentDataSetWrite; + MPI_Datatype typesDataSetWrite[3] = { MPI_DOUBLE, MPI_INT, MPI_CHAR }; + int blocksDataSetWrite[3] = { 2, 2, 2 }; + MPI_Aint offsetsDataSetWrite[3], lbDataSetWrite, extentDataSetWrite; - MPI_Type_get_extent(MPI_INT, &lbDataSetWrite, &extentDataSetWrite); - offsetsDataSetWrite[2] = offsetsDataSetWrite[1] + blocksDataSetWrite[1] * extentDataSetWrite; + offsetsDataSetWrite[0] = 0; + MPI_Type_get_extent(MPI_DOUBLE, &lbDataSetWrite, &extentDataSetWrite); + offsetsDataSetWrite[1] = blocksDataSetWrite[0] * extentDataSetWrite; - MPI_Type_create_struct(3, blocksDataSetWrite, offsetsDataSetWrite, typesDataSetWrite, &dataSetTypeWrite); - MPI_Type_commit(&dataSetTypeWrite); + MPI_Type_get_extent(MPI_INT, &lbDataSetWrite, &extentDataSetWrite); + offsetsDataSetWrite[2] = offsetsDataSetWrite[1] + blocksDataSetWrite[1] * extentDataSetWrite; + MPI_Type_create_struct(3, blocksDataSetWrite, offsetsDataSetWrite, typesDataSetWrite, &dataSetTypeWrite); + MPI_Type_commit(&dataSetTypeWrite); } ////////////////////////////////////////////////////////////////////////// CheckpointConverter::~CheckpointConverter() { - MPI_Type_free(&gridParamType); - MPI_Type_free(&block3dType); - MPI_Type_free(&boundCondType); - MPI_Type_free(&dataSetParamType); - MPI_Type_free(&dataSetTypeRead); - MPI_Type_free(&dataSetTypeWrite); - MPI_Type_free(&boundCondType1000); + MPI_Type_free(&gridParamType); + MPI_Type_free(&block3dType); + MPI_Type_free(&boundCondType); + MPI_Type_free(&dataSetParamType); + MPI_Type_free(&dataSetTypeRead); + MPI_Type_free(&dataSetTypeWrite); + MPI_Type_free(&boundCondType1000); } //------------------------------------------- READ ----------------------------------------------- void CheckpointConverter::convert(int step, int procCount) { - UBLOG(logINFO, "UtilConvertor::convert start "); + UBLOG(logINFO, "UtilConvertor::convert start "); + + convertBlocks(step, procCount); + convertDataSet(step, procCount); + convertBC(step, procCount); - convertBlocks(step, procCount); - convertDataSet(step, procCount); - convertBC(step, procCount); - - UBLOG(logINFO, "UtilConvertor::convert finish "); + UBLOG(logINFO, "UtilConvertor::convert finish "); } void CheckpointConverter::convertBlocks(int step, int procCount) { - double start, finish; - start = MPI_Wtime(); - - // file to read from - MPI_File file_handlerR; - std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; - int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); - if (rcR != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameR); - - // file to write to - MPI_File file_handlerW; - UbSystem::makeDirectory(path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); - std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; - int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handlerW); - if (rcW != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameW); - - // read count of blocks - int blocksCount = 0; - MPI_File_read_at(file_handlerR, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - Block3d* block3dArray = new Block3d[blocksCount]; - GridParam* gridParameters = new GridParam; - - // calculate the read offset - procCount = 1; // readBlocks and writeBlocks in both MPIIORestartCoProcessor and MPIIOMigrationCoProcessor have size == 1! - MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); - - // read parameters of the grid and blocks - MPI_File_read_at(file_handlerR, read_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, block3dType, MPI_STATUS_IGNORE); - - // clear the grid - std::vector<SPtr<Block3D>> blocksVector[25]; - int minInitLevel = this->grid->getCoarsestInitializedLevel(); - if (minInitLevel > -1) - { - int maxInitLevel = this->grid->getFinestInitializedLevel(); - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - grid->getBlocks(level, blocksVector[level]); - for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level - grid->deleteBlock(block); - } - } - - // restore the grid - SPtr<CoordinateTransformation3D> trafo(new CoordinateTransformation3D()); - trafo->Tx1 = gridParameters->trafoParams[0]; - trafo->Tx2 = gridParameters->trafoParams[1]; - trafo->Tx3 = gridParameters->trafoParams[2]; - trafo->Sx1 = gridParameters->trafoParams[3]; - trafo->Sx2 = gridParameters->trafoParams[4]; - trafo->Sx3 = gridParameters->trafoParams[5]; - trafo->alpha = gridParameters->trafoParams[6]; - trafo->beta = gridParameters->trafoParams[7]; - trafo->gamma = gridParameters->trafoParams[8]; - - trafo->toX1factorX1 = gridParameters->trafoParams[9]; - trafo->toX1factorX2 = gridParameters->trafoParams[10]; - trafo->toX1factorX3 = gridParameters->trafoParams[11]; - trafo->toX1delta = gridParameters->trafoParams[12]; - trafo->toX2factorX1 = gridParameters->trafoParams[13]; - trafo->toX2factorX2 = gridParameters->trafoParams[14]; - trafo->toX2factorX3 = gridParameters->trafoParams[15]; - trafo->toX2delta = gridParameters->trafoParams[16]; - trafo->toX3factorX1 = gridParameters->trafoParams[17]; - trafo->toX3factorX2 = gridParameters->trafoParams[18]; - trafo->toX3factorX3 = gridParameters->trafoParams[19]; - trafo->toX3delta = gridParameters->trafoParams[20]; - - trafo->fromX1factorX1 = gridParameters->trafoParams[21]; - trafo->fromX1factorX2 = gridParameters->trafoParams[22]; - trafo->fromX1factorX3 = gridParameters->trafoParams[23]; - trafo->fromX1delta = gridParameters->trafoParams[24]; - trafo->fromX2factorX1 = gridParameters->trafoParams[25]; - trafo->fromX2factorX2 = gridParameters->trafoParams[26]; - trafo->fromX2factorX3 = gridParameters->trafoParams[27]; - trafo->fromX2delta = gridParameters->trafoParams[28]; - trafo->fromX3factorX1 = gridParameters->trafoParams[29]; - trafo->fromX3factorX2 = gridParameters->trafoParams[30]; - trafo->fromX3factorX3 = gridParameters->trafoParams[31]; - trafo->fromX3delta = gridParameters->trafoParams[32]; - - trafo->active = gridParameters->active; - trafo->transformation = gridParameters->transformation; - - grid->setCoordinateTransformator(trafo); - - grid->setDeltaX(gridParameters->deltaX); - grid->setBlockNX(gridParameters->blockNx1, gridParameters->blockNx2, gridParameters->blockNx3); - grid->setNX1(gridParameters->nx1); - grid->setNX2(gridParameters->nx2); - grid->setNX3(gridParameters->nx3); - grid->setPeriodicX1(gridParameters->periodicX1); - grid->setPeriodicX2(gridParameters->periodicX2); - grid->setPeriodicX3(gridParameters->periodicX3); - - // regenerate blocks - for (int n = 0; n < blocksCount; n++) - { - SPtr<Block3D> block(new Block3D(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level)); - block->setActive(block3dArray[n].active); - block->setBundle(block3dArray[n].bundle); - block->setRank(block3dArray[n].rank); - block->setLocalRank(block3dArray[n].lrank); - block->setGlobalID(block3dArray[n].globalID); - block->setLocalID(block3dArray[n].localID); - block->setPart(block3dArray[n].part); - block->setLevel(block3dArray[n].level); - block->setCollectionOfInterpolationFlagCF(block3dArray[n].interpolationFlagCF); - block->setCollectionOfInterpolationFlagFC(block3dArray[n].interpolationFlagFC); - - grid->addBlock(block); - } - - // renumber blocks - grid->renumberBlockIDs(); - - // refresh globalID in all the blocks - SPtr<Block3D> block; - for (int n = 0; n < blocksCount; n++) - { - block = grid->getBlock(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level); - block3dArray[n].globalID = block->getGlobalID(); - } - - // write all data to the file - MPI_Offset write_offset = read_offset; - - MPI_File_write_at(file_handlerW, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, write_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, block3dType, MPI_STATUS_IGNORE); - - MPI_File_close(&file_handlerR); - MPI_File_close(&file_handlerW); - - finish = MPI_Wtime(); - UBLOG(logINFO, "UtilConvertor::convertBlocks time: " << finish - start << " s"); - - delete gridParameters; - delete[] block3dArray; + double start, finish; + start = MPI_Wtime(); + + // file to read from + MPI_File file_handlerR; + std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; + int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); + if (rcR != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameR); + + // file to write to + MPI_File file_handlerW; + UbSystem::makeDirectory(path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step)); + std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBlocks.bin"; + int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handlerW); + if (rcW != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameW); + + // read count of blocks + int blocksCount = 0; + MPI_File_read_at(file_handlerR, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + Block3d *block3dArray = new Block3d[blocksCount]; + GridParam *gridParameters = new GridParam; + + // calculate the read offset + procCount = + 1; // readBlocks and writeBlocks in both MPIIORestartCoProcessor and MPIIOMigrationCoProcessor have size == 1! + MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); + + // read parameters of the grid and blocks + MPI_File_read_at(file_handlerR, read_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, + block3dType, MPI_STATUS_IGNORE); + + // clear the grid + std::vector<SPtr<Block3D>> blocksVector[25]; + int minInitLevel = this->grid->getCoarsestInitializedLevel(); + if (minInitLevel > -1) { + int maxInitLevel = this->grid->getFinestInitializedLevel(); + for (int level = minInitLevel; level <= maxInitLevel; level++) { + grid->getBlocks(level, blocksVector[level]); + for (SPtr<Block3D> block : blocksVector[level]) // blocks of the current level + grid->deleteBlock(block); + } + } + + // restore the grid + SPtr<CoordinateTransformation3D> trafo(new CoordinateTransformation3D()); + trafo->Tx1 = gridParameters->trafoParams[0]; + trafo->Tx2 = gridParameters->trafoParams[1]; + trafo->Tx3 = gridParameters->trafoParams[2]; + trafo->Sx1 = gridParameters->trafoParams[3]; + trafo->Sx2 = gridParameters->trafoParams[4]; + trafo->Sx3 = gridParameters->trafoParams[5]; + trafo->alpha = gridParameters->trafoParams[6]; + trafo->beta = gridParameters->trafoParams[7]; + trafo->gamma = gridParameters->trafoParams[8]; + + trafo->toX1factorX1 = gridParameters->trafoParams[9]; + trafo->toX1factorX2 = gridParameters->trafoParams[10]; + trafo->toX1factorX3 = gridParameters->trafoParams[11]; + trafo->toX1delta = gridParameters->trafoParams[12]; + trafo->toX2factorX1 = gridParameters->trafoParams[13]; + trafo->toX2factorX2 = gridParameters->trafoParams[14]; + trafo->toX2factorX3 = gridParameters->trafoParams[15]; + trafo->toX2delta = gridParameters->trafoParams[16]; + trafo->toX3factorX1 = gridParameters->trafoParams[17]; + trafo->toX3factorX2 = gridParameters->trafoParams[18]; + trafo->toX3factorX3 = gridParameters->trafoParams[19]; + trafo->toX3delta = gridParameters->trafoParams[20]; + + trafo->fromX1factorX1 = gridParameters->trafoParams[21]; + trafo->fromX1factorX2 = gridParameters->trafoParams[22]; + trafo->fromX1factorX3 = gridParameters->trafoParams[23]; + trafo->fromX1delta = gridParameters->trafoParams[24]; + trafo->fromX2factorX1 = gridParameters->trafoParams[25]; + trafo->fromX2factorX2 = gridParameters->trafoParams[26]; + trafo->fromX2factorX3 = gridParameters->trafoParams[27]; + trafo->fromX2delta = gridParameters->trafoParams[28]; + trafo->fromX3factorX1 = gridParameters->trafoParams[29]; + trafo->fromX3factorX2 = gridParameters->trafoParams[30]; + trafo->fromX3factorX3 = gridParameters->trafoParams[31]; + trafo->fromX3delta = gridParameters->trafoParams[32]; + + trafo->active = gridParameters->active; + trafo->transformation = gridParameters->transformation; + + grid->setCoordinateTransformator(trafo); + + grid->setDeltaX(gridParameters->deltaX); + grid->setBlockNX(gridParameters->blockNx1, gridParameters->blockNx2, gridParameters->blockNx3); + grid->setNX1(gridParameters->nx1); + grid->setNX2(gridParameters->nx2); + grid->setNX3(gridParameters->nx3); + grid->setPeriodicX1(gridParameters->periodicX1); + grid->setPeriodicX2(gridParameters->periodicX2); + grid->setPeriodicX3(gridParameters->periodicX3); + + // regenerate blocks + for (int n = 0; n < blocksCount; n++) { + SPtr<Block3D> block( + new Block3D(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level)); + block->setActive(block3dArray[n].active); + block->setBundle(block3dArray[n].bundle); + block->setRank(block3dArray[n].rank); + block->setLocalRank(block3dArray[n].lrank); + block->setGlobalID(block3dArray[n].globalID); + block->setLocalID(block3dArray[n].localID); + block->setPart(block3dArray[n].part); + block->setLevel(block3dArray[n].level); + block->setCollectionOfInterpolationFlagCF(block3dArray[n].interpolationFlagCF); + block->setCollectionOfInterpolationFlagFC(block3dArray[n].interpolationFlagFC); + + grid->addBlock(block); + } + + // renumber blocks + grid->renumberBlockIDs(); + + // refresh globalID in all the blocks + SPtr<Block3D> block; + for (int n = 0; n < blocksCount; n++) { + block = grid->getBlock(block3dArray[n].x1, block3dArray[n].x2, block3dArray[n].x3, block3dArray[n].level); + block3dArray[n].globalID = block->getGlobalID(); + } + + // write all data to the file + MPI_Offset write_offset = read_offset; + + MPI_File_write_at(file_handlerW, 0, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, write_offset, gridParameters, 1, gridParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(GridParam)), &block3dArray[0], blocksCount, + block3dType, MPI_STATUS_IGNORE); + + MPI_File_close(&file_handlerR); + MPI_File_close(&file_handlerW); + + finish = MPI_Wtime(); + UBLOG(logINFO, "UtilConvertor::convertBlocks time: " << finish - start << " s"); + + delete gridParameters; + delete[] block3dArray; } void CheckpointConverter::convertDataSet(int step, int procCount) { - // file to read from - MPI_File file_handlerR; - std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); - if (rcR != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameR); - - // file to write to - MPI_File file_handlerW; - std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; - int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handlerW); - if (rcW != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameW); - - double start, finish; - start = MPI_Wtime(); - - int blocksCount = 0; - dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; - DataSetRestart* dataSetReadArray; - DataSetMigration* dataSetWriteArray; - size_t doubleCountInBlock; - std::vector<double> doubleValuesArray; - size_t sizeofOneDataSet; - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); - MPI_Offset write_offset; - - for (int pc = 0; pc < procCount; pc++) - { - // read count of blocks and parameters of data arrays - MPI_File_read_at(file_handlerR, (MPI_Offset)(pc * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, read_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - doubleCountInBlock = dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + - dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + - dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; - - dataSetReadArray = new DataSetRestart[blocksCount]; - dataSetWriteArray = new DataSetMigration[blocksCount]; - doubleValuesArray.resize(blocksCount * doubleCountInBlock); - - // read data - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam)), dataSetReadArray, blocksCount, dataSetTypeRead, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), - &doubleValuesArray[0], int(blocksCount * doubleCountInBlock), MPI_DOUBLE, MPI_STATUS_IGNORE); - - // offset to read the data of the next process - read_offset = read_offset + (MPI_Offset)(3 * sizeof(dataSetParam) + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double))); - - // write parameters of data arrays - MPI_File_write_at(file_handlerW, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, MPI_STATUS_IGNORE); - - sizeofOneDataSet = sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double); - - // write blocks and their data arrays - for (int nb = 0; nb < blocksCount; nb++) - { - SPtr<Block3D> block = grid->getBlock(dataSetReadArray[nb].x1, dataSetReadArray[nb].x2, dataSetReadArray[nb].x3, dataSetReadArray[nb].level); - dataSetWriteArray[nb].globalID = block->getGlobalID(); - dataSetWriteArray[nb].ghostLayerWidth = dataSetReadArray[nb].ghostLayerWidth; - dataSetWriteArray[nb].collFactor = dataSetReadArray[nb].collFactor; - dataSetWriteArray[nb].deltaT = dataSetReadArray[nb].deltaT; - dataSetWriteArray[nb].compressible = dataSetReadArray[nb].compressible; - dataSetWriteArray[nb].withForcing = dataSetReadArray[nb].withForcing; - - write_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + dataSetWriteArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handlerW, write_offset, &dataSetWriteArray[nb], 1, dataSetTypeWrite, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(DataSetMigration)), &doubleValuesArray[nb * doubleCountInBlock], - int(doubleCountInBlock), MPI_DOUBLE, MPI_STATUS_IGNORE); - } - - delete[] dataSetReadArray; - delete[] dataSetWriteArray; - } - - MPI_File_close(&file_handlerR); - - MPI_File_sync(file_handlerW); - MPI_File_close(&file_handlerW); - - DSArraysPresence arrPresence; - MPI_File file_handler1; - std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - int rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); - if (rc != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename1); - MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 6, MPI_CHAR, MPI_STATUS_IGNORE); - MPI_File_close(&file_handler1); - - MPI_File file_handler2; - std::string filename2 = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; - int rc2 = MPI_File_open(MPI_COMM_WORLD, filename2.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handler2); - if (rc2 != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filename2); - MPI_File_write_at(file_handler2, (MPI_Offset)0, &arrPresence, 6, MPI_CHAR, MPI_STATUS_IGNORE); - MPI_File_sync(file_handler2); - MPI_File_close(&file_handler2); - - std::string filenameRR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step); - std::string filenameWW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step); - - if (arrPresence.isAverageDensityArrayPresent) - convert___Array(step, procCount, filenameRR + "/cpAverageDensityArray.bin", filenameWW + "/cpAverageDensityArray.bin"); - - if (arrPresence.isAverageVelocityArrayPresent) - convert___Array(step, procCount, filenameRR + "/cpAverageVelocityArray.bin", filenameWW + "/cpAverageVelocityArray.bin"); - - if (arrPresence.isAverageFluktuationsArrayPresent) - convert___Array(step, procCount, filenameRR + "/cpAverageFluktuationsArray.bin", filenameWW + "/cpAverageFluktuationsArray.bin"); - - if (arrPresence.isAverageTripleArrayPresent) - convert___Array(step, procCount, filenameRR + "/cpAverageTripleArray.bin", filenameWW + "/cpAverageTripleArray.bin"); - - if (arrPresence.isShearStressValArrayPresent) - convert___Array(step, procCount, filenameRR + "/cpShearStressValArray.bin", filenameWW + "/cpShearStressValArray.bin"); - - if (arrPresence.isRelaxationFactorPresent) - convert___Array(step, procCount, filenameRR + "/cpRelaxationFactor.bin", filenameWW + "/cpRelaxationFactor.bin"); - - finish = MPI_Wtime(); - UBLOG(logINFO, "UtilConvertor::convertDataSet time: " << finish - start << " s"); - + // file to read from + MPI_File file_handlerR; + std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); + if (rcR != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameR); + + // file to write to + MPI_File file_handlerW; + std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpDataSet.bin"; + int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handlerW); + if (rcW != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameW); + + double start, finish; + start = MPI_Wtime(); + + int blocksCount = 0; + dataSetParam dataSetParamStr1, dataSetParamStr2, dataSetParamStr3; + DataSetRestart *dataSetReadArray; + DataSetMigration *dataSetWriteArray; + size_t doubleCountInBlock; + std::vector<double> doubleValuesArray; + size_t sizeofOneDataSet; + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); + MPI_Offset write_offset; + + for (int pc = 0; pc < procCount; pc++) { + // read count of blocks and parameters of data arrays + MPI_File_read_at(file_handlerR, (MPI_Offset)(pc * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, read_offset, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(dataSetParam)), &dataSetParamStr2, 1, + dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, + dataSetParamType, MPI_STATUS_IGNORE); + doubleCountInBlock = + dataSetParamStr1.nx[0] * dataSetParamStr1.nx[1] * dataSetParamStr1.nx[2] * dataSetParamStr1.nx[3] + + dataSetParamStr2.nx[0] * dataSetParamStr2.nx[1] * dataSetParamStr2.nx[2] * dataSetParamStr2.nx[3] + + dataSetParamStr3.nx[0] * dataSetParamStr3.nx[1] * dataSetParamStr3.nx[2] * dataSetParamStr3.nx[3]; + + dataSetReadArray = new DataSetRestart[blocksCount]; + dataSetWriteArray = new DataSetMigration[blocksCount]; + doubleValuesArray.resize(blocksCount * doubleCountInBlock); + + // read data + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam)), dataSetReadArray, + blocksCount, dataSetTypeRead, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, + (MPI_Offset)(read_offset + 3 * sizeof(dataSetParam) + blocksCount * sizeof(DataSetRestart)), + &doubleValuesArray[0], int(blocksCount * doubleCountInBlock), MPI_DOUBLE, MPI_STATUS_IGNORE); + + // offset to read the data of the next process + read_offset = + read_offset + (MPI_Offset)(3 * sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetRestart) + doubleCountInBlock * sizeof(double))); + + // write parameters of data arrays + MPI_File_write_at(file_handlerW, (MPI_Offset)0, &dataSetParamStr1, 1, dataSetParamType, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, (MPI_Offset)(sizeof(dataSetParam)), &dataSetParamStr2, 1, dataSetParamType, + MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, (MPI_Offset)(2 * sizeof(dataSetParam)), &dataSetParamStr3, 1, dataSetParamType, + MPI_STATUS_IGNORE); + + sizeofOneDataSet = sizeof(DataSetMigration) + doubleCountInBlock * sizeof(double); + + // write blocks and their data arrays + for (int nb = 0; nb < blocksCount; nb++) { + SPtr<Block3D> block = grid->getBlock(dataSetReadArray[nb].x1, dataSetReadArray[nb].x2, + dataSetReadArray[nb].x3, dataSetReadArray[nb].level); + dataSetWriteArray[nb].globalID = block->getGlobalID(); + dataSetWriteArray[nb].ghostLayerWidth = dataSetReadArray[nb].ghostLayerWidth; + dataSetWriteArray[nb].collFactor = dataSetReadArray[nb].collFactor; + dataSetWriteArray[nb].deltaT = dataSetReadArray[nb].deltaT; + dataSetWriteArray[nb].compressible = dataSetReadArray[nb].compressible; + dataSetWriteArray[nb].withForcing = dataSetReadArray[nb].withForcing; + + write_offset = (MPI_Offset)(3 * sizeof(dataSetParam) + dataSetWriteArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handlerW, write_offset, &dataSetWriteArray[nb], 1, dataSetTypeWrite, + MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(DataSetMigration)), + &doubleValuesArray[nb * doubleCountInBlock], int(doubleCountInBlock), MPI_DOUBLE, + MPI_STATUS_IGNORE); + } + + delete[] dataSetReadArray; + delete[] dataSetWriteArray; + } + + MPI_File_close(&file_handlerR); + + MPI_File_sync(file_handlerW); + MPI_File_close(&file_handlerW); + + DSArraysPresence arrPresence; + MPI_File file_handler1; + std::string filename1 = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + int rc = MPI_File_open(MPI_COMM_WORLD, filename1.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handler1); + if (rc != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename1); + MPI_File_read_at(file_handler1, (MPI_Offset)0, &arrPresence, 6, MPI_CHAR, MPI_STATUS_IGNORE); + MPI_File_close(&file_handler1); + + MPI_File file_handler2; + std::string filename2 = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpArrays.bin"; + int rc2 = MPI_File_open(MPI_COMM_WORLD, filename2.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handler2); + if (rc2 != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filename2); + MPI_File_write_at(file_handler2, (MPI_Offset)0, &arrPresence, 6, MPI_CHAR, MPI_STATUS_IGNORE); + MPI_File_sync(file_handler2); + MPI_File_close(&file_handler2); + + std::string filenameRR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step); + std::string filenameWW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step); + + if (arrPresence.isAverageDensityArrayPresent) + convert___Array(step, procCount, filenameRR + "/cpAverageDensityArray.bin", + filenameWW + "/cpAverageDensityArray.bin"); + + if (arrPresence.isAverageVelocityArrayPresent) + convert___Array(step, procCount, filenameRR + "/cpAverageVelocityArray.bin", + filenameWW + "/cpAverageVelocityArray.bin"); + + if (arrPresence.isAverageFluktuationsArrayPresent) + convert___Array(step, procCount, filenameRR + "/cpAverageFluktuationsArray.bin", + filenameWW + "/cpAverageFluktuationsArray.bin"); + + if (arrPresence.isAverageTripleArrayPresent) + convert___Array(step, procCount, filenameRR + "/cpAverageTripleArray.bin", + filenameWW + "/cpAverageTripleArray.bin"); + + if (arrPresence.isShearStressValArrayPresent) + convert___Array(step, procCount, filenameRR + "/cpShearStressValArray.bin", + filenameWW + "/cpShearStressValArray.bin"); + + if (arrPresence.isRelaxationFactorPresent) + convert___Array(step, procCount, filenameRR + "/cpRelaxationFactor.bin", + filenameWW + "/cpRelaxationFactor.bin"); + + finish = MPI_Wtime(); + UBLOG(logINFO, "UtilConvertor::convertDataSet time: " << finish - start << " s"); } -void CheckpointConverter::convert___Array(int /*step*/, int procCount, std::string filenameR, std::string filenameW) +void CheckpointConverter::convert___Array(int /*step*/, int procCount, std::string filenameR, std::string filenameW) { - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - MPI_File file_handlerR; - int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); - if (rcR != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameR); - - MPI_File file_handlerW; - int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handlerW); - if (rcW != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameW); - - int blocksCount = 0; - dataSetParam dataSetParamStr; - memset(&dataSetParamStr, 0, sizeof(dataSetParam)); - DataSetSmallRestart* dataSetSmallReadArray; - DataSetSmallMigration* dataSetSmallWriteArray; - int doubleCountInBlock; - std::vector<double> doubleValuesArray; - - // calculate the read offset - MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); - MPI_Offset write_offset; - size_t sizeofOneDataSet; - - for (int pc = 0; pc < procCount; pc++) - { - MPI_File_read_at(file_handlerR, (MPI_Offset)(pc * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, read_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - dataSetSmallReadArray = new DataSetSmallRestart[blocksCount]; - dataSetSmallWriteArray = new DataSetSmallMigration[blocksCount]; - doubleCountInBlock = dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; - doubleValuesArray.resize(blocksCount * doubleCountInBlock); - - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallReadArray, blocksCount * 4, MPI_INT, MPI_STATUS_IGNORE); - if (doubleCountInBlock > 0) - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), - &doubleValuesArray[0], blocksCount * doubleCountInBlock, MPI_DOUBLE, MPI_STATUS_IGNORE); - - read_offset = read_offset + sizeof(dataSetParam) + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); - - sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); - - MPI_File_write_at(file_handlerW, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); - - for (int nb = 0; nb < blocksCount; nb++) - { - SPtr<Block3D> block = grid->getBlock(dataSetSmallReadArray[nb].x1, dataSetSmallReadArray[nb].x2, dataSetSmallReadArray[nb].x3, dataSetSmallReadArray[nb].level); - dataSetSmallWriteArray[nb].globalID = block->getGlobalID(); - - write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallWriteArray[nb].globalID * sizeofOneDataSet); - MPI_File_write_at(file_handlerW, write_offset, &dataSetSmallWriteArray[nb], 1, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), - &doubleValuesArray[nb * doubleCountInBlock], doubleCountInBlock, MPI_DOUBLE, MPI_STATUS_IGNORE); - } - - delete[] dataSetSmallReadArray; - delete[] dataSetSmallWriteArray; - } - MPI_File_close(&file_handlerR); - - MPI_File_sync(file_handlerW); - MPI_File_close(&file_handlerW); - - finish = MPI_Wtime(); - UBLOG(logINFO, "UtilConvertor::convert___Array time: " << finish - start << " s"); - + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + MPI_File file_handlerR; + int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); + if (rcR != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameR); + + MPI_File file_handlerW; + int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handlerW); + if (rcW != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameW); + + int blocksCount = 0; + dataSetParam dataSetParamStr; + memset(&dataSetParamStr, 0, sizeof(dataSetParam)); + DataSetSmallRestart *dataSetSmallReadArray; + DataSetSmallMigration *dataSetSmallWriteArray; + int doubleCountInBlock; + std::vector<double> doubleValuesArray; + + // calculate the read offset + MPI_Offset read_offset = (MPI_Offset)(procCount * sizeof(int)); + MPI_Offset write_offset; + size_t sizeofOneDataSet; + + for (int pc = 0; pc < procCount; pc++) { + MPI_File_read_at(file_handlerR, (MPI_Offset)(pc * sizeof(int)), &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, read_offset, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + + dataSetSmallReadArray = new DataSetSmallRestart[blocksCount]; + dataSetSmallWriteArray = new DataSetSmallMigration[blocksCount]; + doubleCountInBlock = + dataSetParamStr.nx[0] * dataSetParamStr.nx[1] * dataSetParamStr.nx[2] * dataSetParamStr.nx[3]; + doubleValuesArray.resize(blocksCount * doubleCountInBlock); + + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(dataSetParam)), dataSetSmallReadArray, + blocksCount * 4, MPI_INT, MPI_STATUS_IGNORE); + if (doubleCountInBlock > 0) + MPI_File_read_at( + file_handlerR, + (MPI_Offset)(read_offset + sizeof(dataSetParam) + blocksCount * sizeof(DataSetSmallRestart)), + &doubleValuesArray[0], blocksCount * doubleCountInBlock, MPI_DOUBLE, MPI_STATUS_IGNORE); + + read_offset = read_offset + sizeof(dataSetParam) + + blocksCount * (sizeof(DataSetSmallRestart) + doubleCountInBlock * sizeof(double)); + + sizeofOneDataSet = sizeof(DataSetSmallMigration) + doubleCountInBlock * sizeof(double); + + MPI_File_write_at(file_handlerW, 0, &dataSetParamStr, 1, dataSetParamType, MPI_STATUS_IGNORE); + + for (int nb = 0; nb < blocksCount; nb++) { + SPtr<Block3D> block = grid->getBlock(dataSetSmallReadArray[nb].x1, dataSetSmallReadArray[nb].x2, + dataSetSmallReadArray[nb].x3, dataSetSmallReadArray[nb].level); + dataSetSmallWriteArray[nb].globalID = block->getGlobalID(); + + write_offset = (MPI_Offset)(sizeof(dataSetParam) + dataSetSmallWriteArray[nb].globalID * sizeofOneDataSet); + MPI_File_write_at(file_handlerW, write_offset, &dataSetSmallWriteArray[nb], 1, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(DataSetSmallMigration)), + &doubleValuesArray[nb * doubleCountInBlock], doubleCountInBlock, MPI_DOUBLE, + MPI_STATUS_IGNORE); + } + + delete[] dataSetSmallReadArray; + delete[] dataSetSmallWriteArray; + } + MPI_File_close(&file_handlerR); + + MPI_File_sync(file_handlerW); + MPI_File_close(&file_handlerW); + + finish = MPI_Wtime(); + UBLOG(logINFO, "UtilConvertor::convert___Array time: " << finish - start << " s"); } void CheckpointConverter::convertBC(int step, int procCount) { - // file to read from - MPI_File file_handlerR; - std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); - if (rcR != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameR); - - // file to write to - MPI_File file_handlerW; - std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; - int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, &file_handlerW); - if (rcW != MPI_SUCCESS) throw UbException(UB_EXARGS, "couldn't open file " + filenameW); - - double start, finish; - if (comm->isRoot()) start = MPI_Wtime(); - - int blocksCount = 0; - int dataCount1000 = 0; - int dataCount2 = 0; - size_t dataCount; - BCAddRestart* bcAddReadArray; - BCAddMigration* bcAddWriteArray; - BoundaryCondition* bcArray; - BoundaryCondition* nullBouCond = new BoundaryCondition(); - memset(nullBouCond, 0, sizeof(BoundaryCondition)); - int* intArray1; - int* intArray2; - int indexBC; - int indexC; - - MPI_Offset read_offset; - MPI_Offset read_offset1 = (MPI_Offset)(procCount * (3 * sizeof(int) + sizeof(boundCondParam))); - MPI_Offset write_offset = (MPI_Offset)(sizeof(boundCondParam) + grid->getNumberOfBlocks() * sizeof(size_t)); - MPI_Offset write_offsetIndex; - - for (int pc = 0; pc < procCount; pc++) - { - read_offset = (MPI_Offset)(pc * (3 * sizeof(int) + sizeof(boundCondParam))); - - // read count of blocks - MPI_File_read_at(file_handlerR, read_offset, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of big BoundaryCondition blocks - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(int)), &dataCount1000, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of indexContainer values in all blocks - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 2 * sizeof(int)), &dataCount2, 1, MPI_INT, MPI_STATUS_IGNORE); - // read count of bcindexmatrix values in every block - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(int)), &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); - //MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(int)), &boundCondParamStr, 1, boundCondParamType, MPI_STATUS_IGNORE); - - bcAddReadArray = new BCAddRestart[blocksCount]; - bcAddWriteArray = new BCAddMigration[blocksCount]; - dataCount = dataCount1000 * BLOCK_SIZE; - bcArray = new BoundaryCondition[dataCount]; - intArray1 = new int[blocksCount * boundCondParamStr.bcindexmatrixCount]; - intArray2 = new int[dataCount2]; - - // read data arrays - MPI_File_read_at(file_handlerR, read_offset1, bcAddReadArray, blocksCount * 6, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart)), - &bcArray[0], dataCount1000, boundCondType1000, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition)), - &intArray1[0], blocksCount * boundCondParamStr.bcindexmatrixCount, MPI_INT, MPI_STATUS_IGNORE); - MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + blocksCount * boundCondParamStr.bcindexmatrixCount * sizeof(int)), - &intArray2[0], dataCount2, MPI_INT, MPI_STATUS_IGNORE); - - // offset to read the data of the next process - read_offset1 = read_offset1 + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); - - MPI_File_write_at(file_handlerW, 0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); - - indexBC = 0; - indexC = 0; - // write blocks and their BC data arrays - for (int nb = 0; nb < blocksCount; nb++) - { - SPtr<Block3D> block = grid->getBlock(bcAddReadArray[nb].x1, bcAddReadArray[nb].x2, bcAddReadArray[nb].x3, bcAddReadArray[nb].level); - bcAddWriteArray[nb].globalID = block->getGlobalID(); - bcAddWriteArray[nb].boundCond_count = bcAddReadArray[nb].boundCond_count; // how many BoundaryConditions in this block - bcAddWriteArray[nb].indexContainer_count = bcAddReadArray[nb].indexContainer_count; // how many indexContainer-values in this block - - write_offsetIndex = (MPI_Offset)(sizeof(boundCondParam) + bcAddWriteArray[nb].globalID * sizeof(size_t)); - MPI_File_write_at(file_handlerW, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); - - MPI_File_write_at(file_handlerW, write_offset, &bcAddWriteArray[nb], 3, MPI_INT, MPI_STATUS_IGNORE); - if (bcAddWriteArray[nb].boundCond_count > 0) - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(BCAddMigration)), &bcArray[indexBC], bcAddWriteArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); - indexBC += bcAddWriteArray[nb].boundCond_count; - - if (boundCondParamStr.bcindexmatrixCount > 0) - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(BCAddMigration) + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition)), - &intArray1[nb * boundCondParamStr.bcindexmatrixCount], boundCondParamStr.bcindexmatrixCount, MPI_INT, MPI_STATUS_IGNORE); - - if (bcAddWriteArray[nb].indexContainer_count > 0) - MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(BCAddMigration) + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition) + boundCondParamStr.bcindexmatrixCount * sizeof(int)), - &intArray2[indexC], bcAddWriteArray[nb].indexContainer_count, MPI_INT, MPI_STATUS_IGNORE); - indexC += bcAddWriteArray[nb].indexContainer_count; - - write_offset += sizeof(BCAddMigration) + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition) + boundCondParamStr.bcindexmatrixCount * sizeof(int) + bcAddWriteArray[nb].indexContainer_count * sizeof(int); - } - - delete[] bcAddReadArray; - delete[] bcAddWriteArray; - delete[] bcArray; - delete[] intArray1; - delete[] intArray2; - } - - delete nullBouCond; - - MPI_File_close(&file_handlerR); - - MPI_File_sync(file_handlerW); - MPI_File_close(&file_handlerW); - - finish = MPI_Wtime(); - UBLOG(logINFO, "UtilConvertor::convertBC time: " << finish - start << " s"); - + // file to read from + MPI_File file_handlerR; + std::string filenameR = path + "/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rcR = MPI_File_open(MPI_COMM_WORLD, filenameR.c_str(), MPI_MODE_RDONLY, MPI_INFO_NULL, &file_handlerR); + if (rcR != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameR); + + // file to write to + MPI_File file_handlerW; + std::string filenameW = path + "/mig/mpi_io_cp/mpi_io_cp_" + UbSystem::toString(step) + "/cpBC.bin"; + int rcW = MPI_File_open(MPI_COMM_WORLD, filenameW.c_str(), MPI_MODE_CREATE | MPI_MODE_WRONLY, MPI_INFO_NULL, + &file_handlerW); + if (rcW != MPI_SUCCESS) + throw UbException(UB_EXARGS, "couldn't open file " + filenameW); + + double start, finish; + if (comm->isRoot()) + start = MPI_Wtime(); + + int blocksCount = 0; + int dataCount1000 = 0; + int dataCount2 = 0; + size_t dataCount; + BCAddRestart *bcAddReadArray; + BCAddMigration *bcAddWriteArray; + BoundaryCondition *bcArray; + BoundaryCondition *nullBouCond = new BoundaryCondition(); + memset(nullBouCond, 0, sizeof(BoundaryCondition)); + int *intArray1; + int *intArray2; + int indexBC; + int indexC; + + MPI_Offset read_offset; + MPI_Offset read_offset1 = (MPI_Offset)(procCount * (3 * sizeof(int) + sizeof(boundCondParam))); + MPI_Offset write_offset = (MPI_Offset)(sizeof(boundCondParam) + grid->getNumberOfBlocks() * sizeof(size_t)); + MPI_Offset write_offsetIndex; + + for (int pc = 0; pc < procCount; pc++) { + read_offset = (MPI_Offset)(pc * (3 * sizeof(int) + sizeof(boundCondParam))); + + // read count of blocks + MPI_File_read_at(file_handlerR, read_offset, &blocksCount, 1, MPI_INT, MPI_STATUS_IGNORE); + // read count of big BoundaryCondition blocks + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + sizeof(int)), &dataCount1000, 1, MPI_INT, + MPI_STATUS_IGNORE); + // read count of indexContainer values in all blocks + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 2 * sizeof(int)), &dataCount2, 1, MPI_INT, + MPI_STATUS_IGNORE); + // read count of bcindexmatrix values in every block + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(int)), &boundCondParamStr, 4, MPI_INT, + MPI_STATUS_IGNORE); + // MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset + 3 * sizeof(int)), &boundCondParamStr, 1, + // boundCondParamType, MPI_STATUS_IGNORE); + + bcAddReadArray = new BCAddRestart[blocksCount]; + bcAddWriteArray = new BCAddMigration[blocksCount]; + dataCount = dataCount1000 * BLOCK_SIZE; + bcArray = new BoundaryCondition[dataCount]; + intArray1 = new int[blocksCount * boundCondParamStr.bcindexmatrixCount]; + intArray2 = new int[dataCount2]; + + // read data arrays + MPI_File_read_at(file_handlerR, read_offset1, bcAddReadArray, blocksCount * 6, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart)), &bcArray[0], + dataCount1000, boundCondType1000, MPI_STATUS_IGNORE); + MPI_File_read_at( + file_handlerR, + (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition)), + &intArray1[0], blocksCount * boundCondParamStr.bcindexmatrixCount, MPI_INT, MPI_STATUS_IGNORE); + MPI_File_read_at(file_handlerR, + (MPI_Offset)(read_offset1 + blocksCount * sizeof(BCAddRestart) + + dataCount * sizeof(BoundaryCondition) + + blocksCount * boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &intArray2[0], dataCount2, MPI_INT, MPI_STATUS_IGNORE); + + // offset to read the data of the next process + read_offset1 = read_offset1 + blocksCount * sizeof(BCAddRestart) + dataCount * sizeof(BoundaryCondition) + + (blocksCount * boundCondParamStr.bcindexmatrixCount + dataCount2) * sizeof(int); + + MPI_File_write_at(file_handlerW, 0, &boundCondParamStr, 4, MPI_INT, MPI_STATUS_IGNORE); + + indexBC = 0; + indexC = 0; + // write blocks and their BC data arrays + for (int nb = 0; nb < blocksCount; nb++) { + SPtr<Block3D> block = grid->getBlock(bcAddReadArray[nb].x1, bcAddReadArray[nb].x2, bcAddReadArray[nb].x3, + bcAddReadArray[nb].level); + bcAddWriteArray[nb].globalID = block->getGlobalID(); + bcAddWriteArray[nb].boundCond_count = + bcAddReadArray[nb].boundCond_count; // how many BoundaryConditions in this block + bcAddWriteArray[nb].indexContainer_count = + bcAddReadArray[nb].indexContainer_count; // how many indexContainer-values in this block + + write_offsetIndex = (MPI_Offset)(sizeof(boundCondParam) + bcAddWriteArray[nb].globalID * sizeof(size_t)); + MPI_File_write_at(file_handlerW, write_offsetIndex, &write_offset, 1, MPI_LONG_LONG_INT, MPI_STATUS_IGNORE); + + MPI_File_write_at(file_handlerW, write_offset, &bcAddWriteArray[nb], 3, MPI_INT, MPI_STATUS_IGNORE); + if (bcAddWriteArray[nb].boundCond_count > 0) + MPI_File_write_at(file_handlerW, (MPI_Offset)(write_offset + sizeof(BCAddMigration)), &bcArray[indexBC], + bcAddWriteArray[nb].boundCond_count, boundCondType, MPI_STATUS_IGNORE); + indexBC += bcAddWriteArray[nb].boundCond_count; + + if (boundCondParamStr.bcindexmatrixCount > 0) + MPI_File_write_at(file_handlerW, + (MPI_Offset)(write_offset + sizeof(BCAddMigration) + + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition)), + &intArray1[nb * boundCondParamStr.bcindexmatrixCount], + boundCondParamStr.bcindexmatrixCount, MPI_INT, MPI_STATUS_IGNORE); + + if (bcAddWriteArray[nb].indexContainer_count > 0) + MPI_File_write_at(file_handlerW, + (MPI_Offset)(write_offset + sizeof(BCAddMigration) + + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition) + + boundCondParamStr.bcindexmatrixCount * sizeof(int)), + &intArray2[indexC], bcAddWriteArray[nb].indexContainer_count, MPI_INT, + MPI_STATUS_IGNORE); + indexC += bcAddWriteArray[nb].indexContainer_count; + + write_offset += sizeof(BCAddMigration) + bcAddWriteArray[nb].boundCond_count * sizeof(BoundaryCondition) + + boundCondParamStr.bcindexmatrixCount * sizeof(int) + + bcAddWriteArray[nb].indexContainer_count * sizeof(int); + } + + delete[] bcAddReadArray; + delete[] bcAddWriteArray; + delete[] bcArray; + delete[] intArray1; + delete[] intArray2; + } + + delete nullBouCond; + + MPI_File_close(&file_handlerR); + + MPI_File_sync(file_handlerW); + MPI_File_close(&file_handlerW); + + finish = MPI_Wtime(); + UBLOG(logINFO, "UtilConvertor::convertBC time: " << finish - start << " s"); } diff --git a/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.h b/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.h index 7a5ee2e4b..bad6116cc 100644 --- a/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.h +++ b/src/cpu/VirtualFluidsCore/Utilities/CheckpointConverter.h @@ -1,40 +1,40 @@ #ifndef _UTILITACONVERTOR_H_ #define _UTILITACONVERTOR_H_ -#include <mpi.h> +#include "MPIIODataStructures.h" #include <PointerDefinitions.h> +#include <mpi.h> #include <string> #include <vector> -#include "MPIIODataStructures.h" class Grid3D; class Communicator; -//! \class UtilConvertor -//! \brief Converts timestep data from MPIIORestartCoProcessor format into MPIIOMigrationCoProcessor format +//! \class UtilConvertor +//! \brief Converts timestep data from MPIIORestartCoProcessor format into MPIIOMigrationCoProcessor format class CheckpointConverter { public: - CheckpointConverter(SPtr<Grid3D> grid, const std::string& path, SPtr<Communicator> comm); - virtual ~CheckpointConverter(); + CheckpointConverter(SPtr<Grid3D> grid, const std::string &path, SPtr<Communicator> comm); + virtual ~CheckpointConverter(); - void convert(int step, int procCount); - void convertBlocks(int step, int procCount); - void convertDataSet(int step, int procCount); - void convertBC(int step, int procCount); - void convert___Array(int step, int procCount, std::string filenameR, std::string filenameW); + void convert(int step, int procCount); + void convertBlocks(int step, int procCount); + void convertDataSet(int step, int procCount); + void convertBC(int step, int procCount); + void convert___Array(int step, int procCount, std::string filenameR, std::string filenameW); protected: - std::string path; - SPtr<Communicator> comm; - SPtr<Grid3D> grid; + std::string path; + SPtr<Communicator> comm; + SPtr<Grid3D> grid; private: - MPI_Datatype gridParamType, block3dType; - MPI_Datatype dataSetParamType, dataSetTypeRead, dataSetTypeWrite; - MPI_Datatype boundCondType, boundCondType1000; + MPI_Datatype gridParamType, block3dType; + MPI_Datatype dataSetParamType, dataSetTypeRead, dataSetTypeWrite; + MPI_Datatype boundCondType, boundCondType1000; - MPIIODataStructures::boundCondParam boundCondParamStr; + MPIIODataStructures::boundCondParam boundCondParamStr; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Utilities/MemoryUtil.h b/src/cpu/VirtualFluidsCore/Utilities/MemoryUtil.h index 863b4d4f1..b476fd775 100644 --- a/src/cpu/VirtualFluidsCore/Utilities/MemoryUtil.h +++ b/src/cpu/VirtualFluidsCore/Utilities/MemoryUtil.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,129 +35,130 @@ #define _MEMORYUTIL_H_ #if defined(_WIN32) || defined(_WIN64) - #define MEMORYUTIL_WINDOWS - #include "windows.h" - #include "psapi.h" - #pragma comment(lib, "psapi.lib") +#define MEMORYUTIL_WINDOWS +#include "psapi.h" +#include "windows.h" +#pragma comment(lib, "psapi.lib") #elif defined __APPLE__ #define MEMORYUTIL_APPLE - #include "sys/types.h" - #include "sys/sysctl.h" - #include <cstdlib> - #include <cstdio> - #include <cstring> +#include "sys/sysctl.h" +#include "sys/types.h" +#include <cstdio> +#include <cstdlib> +#include <cstring> #elif (defined(__amd64) || defined(__amd64__) || defined(__unix__) || defined(__CYGWIN__)) && !defined(__AIX__) - #define MEMORYUTIL_LINUX - #include "sys/types.h" - #include "sys/sysinfo.h" - #include "cstdlib" - #include "cstdio" - #include "cstring" +#define MEMORYUTIL_LINUX +#include "cstdio" +#include "cstdlib" +#include "cstring" +#include "sys/sysinfo.h" +#include "sys/types.h" #else - #error "MemoryUtil::UnknownMachine" +#error "MemoryUtil::UnknownMachine" #endif #if defined(__CYGWIN__) - #define MEMORYUTIL_CYGWIN +#define MEMORYUTIL_CYGWIN #endif ////////////////////////////////////////////////////////////////////////// -//MemoryUtil +// MemoryUtil ////////////////////////////////////////////////////////////////////////// namespace Utilities { ////////////////////////////////////////////////////////////////////////// - static long long getTotalPhysMem() - { - #if defined(MEMORYUTIL_WINDOWS) - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&memInfo); - DWORDLONG totalPhysMem = memInfo.ullTotalPhys; - #elif defined(MEMORYUTIL_LINUX) - struct sysinfo memInfo; - sysinfo (&memInfo); - long long totalPhysMem = memInfo.totalram; - //Multiply in next statement to avoid int overflow on right hand side... - totalPhysMem *= memInfo.mem_unit; - #elif defined(MEMORYUTIL_APPLE) - int mib [] = { CTL_HW, HW_MEMSIZE }; - int64_t totalPhysMem; - size_t length = sizeof(totalPhysMem); +static long long getTotalPhysMem() +{ +#if defined(MEMORYUTIL_WINDOWS) + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + DWORDLONG totalPhysMem = memInfo.ullTotalPhys; +#elif defined(MEMORYUTIL_LINUX) + struct sysinfo memInfo; + sysinfo(&memInfo); + long long totalPhysMem = memInfo.totalram; + // Multiply in next statement to avoid int overflow on right hand side... + totalPhysMem *= memInfo.mem_unit; +#elif defined(MEMORYUTIL_APPLE) + int mib[] = { CTL_HW, HW_MEMSIZE }; + int64_t totalPhysMem; + size_t length = sizeof(totalPhysMem); - if(sysctl(mib, 2, &totalPhysMem, &length, nullptr, 0) == -1) - return 0; - #else - #error "MemoryUtil::getTotalPhysMem - UnknownMachine" - #endif + if (sysctl(mib, 2, &totalPhysMem, &length, nullptr, 0) == -1) + return 0; +#else +#error "MemoryUtil::getTotalPhysMem - UnknownMachine" +#endif - return (long long)totalPhysMem; - } + return (long long)totalPhysMem; +} ////////////////////////////////////////////////////////////////////////// - static long long getPhysMemUsed() - { - #if defined(MEMORYUTIL_WINDOWS) - MEMORYSTATUSEX memInfo; - memInfo.dwLength = sizeof(MEMORYSTATUSEX); - GlobalMemoryStatusEx(&memInfo); - DWORDLONG physMemUsed = memInfo.ullTotalPhys - memInfo.ullAvailPhys; - #elif defined(MEMORYUTIL_LINUX) - struct sysinfo memInfo; - sysinfo (&memInfo); - long long physMemUsed = memInfo.totalram - memInfo.freeram; - //Multiply in next statement to avoid int overflow on right hand side... - physMemUsed *= memInfo.mem_unit; - #elif defined(MEMORYUTIL_APPLE) - long long physMemUsed = 0; - #else - #error "MemoryUtil::getPhysMemUsed - UnknownMachine" - #endif +static long long getPhysMemUsed() +{ +#if defined(MEMORYUTIL_WINDOWS) + MEMORYSTATUSEX memInfo; + memInfo.dwLength = sizeof(MEMORYSTATUSEX); + GlobalMemoryStatusEx(&memInfo); + DWORDLONG physMemUsed = memInfo.ullTotalPhys - memInfo.ullAvailPhys; +#elif defined(MEMORYUTIL_LINUX) + struct sysinfo memInfo; + sysinfo(&memInfo); + long long physMemUsed = memInfo.totalram - memInfo.freeram; + // Multiply in next statement to avoid int overflow on right hand side... + physMemUsed *= memInfo.mem_unit; +#elif defined(MEMORYUTIL_APPLE) + long long physMemUsed = 0; +#else +#error "MemoryUtil::getPhysMemUsed - UnknownMachine" +#endif - return (long long)physMemUsed; - } + return (long long)physMemUsed; +} ////////////////////////////////////////////////////////////////////////// #if defined(MEMORYUTIL_LINUX) || defined(MEMORYUTIL_APPLE) || defined(MEMORYUTIL_CYGWIN) - static int parseLine(char* line){ - int i = strlen(line); - while (*line < '0' || *line > '9') line++; - line[i-3] = '\0'; - i = atoi(line); - return i; - } - - static int getValue(){ //Note: this value is in KB! - FILE* file = fopen("/proc/self/status", "r"); - int result = -1; - char line[128]; +static int parseLine(char *line) +{ + int i = strlen(line); + while (*line < '0' || *line > '9') + line++; + line[i - 3] = '\0'; + i = atoi(line); + return i; +} +static int getValue() +{ // Note: this value is in KB! + FILE *file = fopen("/proc/self/status", "r"); + int result = -1; + char line[128]; - while (fgets(line, 128, file) != NULL){ - if (strncmp(line, "VmRSS:", 6) == 0){ + while (fgets(line, 128, file) != NULL) { + if (strncmp(line, "VmRSS:", 6) == 0) { result = parseLine(line); break; - } - } - fclose(file); - return result; - } + } + } + fclose(file); + return result; +} #endif ////////////////////////////////////////////////////////////////////////// - static long long getPhysMemUsedByMe() - { - #if defined(MEMORYUTIL_WINDOWS) && !defined(__CYGWIN__) - PROCESS_MEMORY_COUNTERS pmc; - GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); - SIZE_T physMemUsedByMe = pmc.WorkingSetSize; - #elif defined(MEMORYUTIL_LINUX) || defined(MEMORYUTIL_APPLE) || defined(MEMORYUTIL_CYGWIN) - long long physMemUsedByMe = (long long)getValue() * (long long)1024; - #else - #error "MemoryUtil::getPhysMemUsedByMe - UnknownMachine" - #endif +static long long getPhysMemUsedByMe() +{ +#if defined(MEMORYUTIL_WINDOWS) && !defined(__CYGWIN__) + PROCESS_MEMORY_COUNTERS pmc; + GetProcessMemoryInfo(GetCurrentProcess(), &pmc, sizeof(pmc)); + SIZE_T physMemUsedByMe = pmc.WorkingSetSize; +#elif defined(MEMORYUTIL_LINUX) || defined(MEMORYUTIL_APPLE) || defined(MEMORYUTIL_CYGWIN) + long long physMemUsedByMe = (long long)getValue() * (long long)1024; +#else +#error "MemoryUtil::getPhysMemUsedByMe - UnknownMachine" +#endif - return (long long)physMemUsedByMe; - } + return (long long)physMemUsedByMe; +} ////////////////////////////////////////////////////////////////////////// -} +} // namespace Utilities #endif - diff --git a/src/cpu/VirtualFluidsCore/Visitors/Block3DVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/Block3DVisitor.h index e3ce94216..0c3adfb89 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/Block3DVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/Block3DVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -43,44 +43,30 @@ class Grid3D; class Block3DVisitor { public: - Block3DVisitor() = default; + Block3DVisitor() = default; + + Block3DVisitor(int startLevel, int stopLevel) : startLevel(startLevel), stopLevel(stopLevel) {} + + virtual ~Block3DVisitor() = default; - Block3DVisitor(int startLevel, int stopLevel) : startLevel(startLevel), stopLevel(stopLevel) - { - } + virtual void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) = 0; - virtual ~Block3DVisitor() = default; - - virtual void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) = 0; - - int getStartLevel() const; - int getStopLevel() const; - void setStartLevel(int level); - void setStopLevel(int level); + int getStartLevel() const; + int getStopLevel() const; + void setStartLevel(int level); + void setStopLevel(int level); private: - int startLevel{-1}; - int stopLevel{-1}; + int startLevel{ -1 }; + int stopLevel{ -1 }; }; ////////////////////////////////////////////////////////////////////////// -inline int Block3DVisitor::getStartLevel() const -{ - return this->startLevel; -} +inline int Block3DVisitor::getStartLevel() const { return this->startLevel; } ////////////////////////////////////////////////////////////////////////// -inline int Block3DVisitor::getStopLevel() const -{ - return this->stopLevel; -} +inline int Block3DVisitor::getStopLevel() const { return this->stopLevel; } ////////////////////////////////////////////////////////////////////////// -inline void Block3DVisitor::setStartLevel(int level) -{ - this->startLevel = level; -} +inline void Block3DVisitor::setStartLevel(int level) { this->startLevel = level; } ////////////////////////////////////////////////////////////////////////// -inline void Block3DVisitor::setStopLevel(int level) -{ - this->stopLevel = level; -} +inline void Block3DVisitor::setStopLevel(int level) { this->stopLevel = level; } -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.cpp index 7f1e57b24..49d945ceb 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,96 +32,79 @@ //======================================================================================= #include "BoundaryConditionsBlockVisitor.h" -#include "LBMKernel.h" +#include "BCAdapter.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "Grid3DSystem.h" +#include "Block3D.h" #include "D3Q27EsoTwist3DSplittedVector.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "BCAdapter.h" -#include "Block3D.h" -#include "BCArray3D.h" - -BoundaryConditionsBlockVisitor::BoundaryConditionsBlockVisitor() : -Block3DVisitor(0, Grid3DSystem::MAXLEVEL) -{ +#include "Grid3DSystem.h" +#include "LBMKernel.h" -} +BoundaryConditionsBlockVisitor::BoundaryConditionsBlockVisitor() : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) {} ////////////////////////////////////////////////////////////////////////// -BoundaryConditionsBlockVisitor::~BoundaryConditionsBlockVisitor() -= default; +BoundaryConditionsBlockVisitor::~BoundaryConditionsBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// void BoundaryConditionsBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getRank() == grid->getRank()) - { - SPtr<ILBMKernel> kernel = block->getKernel(); + if (block->getRank() == grid->getRank()) { + SPtr<ILBMKernel> kernel = block->getKernel(); - if (!kernel) - { - throw UbException(UB_EXARGS, "LBMKernel in " + block->toString() + "is not exist!"); - } + if (!kernel) { + throw UbException(UB_EXARGS, "LBMKernel in " + block->toString() + "is not exist!"); + } - SPtr<BCProcessor> bcProcessor = kernel->getBCProcessor(); + SPtr<BCProcessor> bcProcessor = kernel->getBCProcessor(); - if (!bcProcessor) - { - throw UbException(UB_EXARGS,"Boundary Conditions Processor is not exist!" ); - } + if (!bcProcessor) { + throw UbException(UB_EXARGS, "Boundary Conditions Processor is not exist!"); + } - SPtr<BCArray3D> bcArray = bcProcessor->getBCArray(); + SPtr<BCArray3D> bcArray = bcProcessor->getBCArray(); - bool compressible = kernel->getCompressible(); - double collFactor = kernel->getCollisionFactor(); + bool compressible = kernel->getCompressible(); + double collFactor = kernel->getCollisionFactor(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - int maxX1 = (int)bcArray->getNX1(); - int maxX2 = (int)bcArray->getNX2(); - int maxX3 = (int)bcArray->getNX3(); - SPtr<BoundaryConditions> bcPtr; + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + int maxX1 = (int)bcArray->getNX1(); + int maxX2 = (int)bcArray->getNX2(); + int maxX3 = (int)bcArray->getNX3(); + SPtr<BoundaryConditions> bcPtr; - bcProcessor->clearBC(); + bcProcessor->clearBC(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - for (int x3 = minX3; x3 < maxX3; x3++) - { - for (int x2 = minX2; x2 < maxX2; x2++) - { - for (int x1 = minX1; x1 < maxX1; x1++) - { - if (!bcArray->isSolid(x1, x2, x3) && !bcArray->isUndefined(x1, x2, x3)) - { - if ((bcPtr = bcArray->getBC(x1, x2, x3)) != NULL) - { - char alg = bcPtr->getBcAlgorithmType(); - SPtr<BCAlgorithm> bca = bcMap[alg]; - - if (bca) - { - bca = bca->clone(); - bca->setNodeIndex(x1, x2, x3); - bca->setBcPointer(bcPtr); - bca->addDistributions(distributions); - bca->setCollFactor(collFactor); - bca->setCompressible(compressible); - bca->setBcArray(bcArray); - bcProcessor->addBC(bca); - } - } - } + for (int x3 = minX3; x3 < maxX3; x3++) { + for (int x2 = minX2; x2 < maxX2; x2++) { + for (int x1 = minX1; x1 < maxX1; x1++) { + if (!bcArray->isSolid(x1, x2, x3) && !bcArray->isUndefined(x1, x2, x3)) { + if ((bcPtr = bcArray->getBC(x1, x2, x3)) != NULL) { + char alg = bcPtr->getBcAlgorithmType(); + SPtr<BCAlgorithm> bca = bcMap[alg]; + + if (bca) { + bca = bca->clone(); + bca->setNodeIndex(x1, x2, x3); + bca->setBcPointer(bcPtr); + bca->addDistributions(distributions); + bca->setCollFactor(collFactor); + bca->setCompressible(compressible); + bca->setBcArray(bcArray); + bcProcessor->addBC(bca); + } + } + } + } } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void BoundaryConditionsBlockVisitor::addBC(SPtr<BCAdapter> bc) { - bcMap.insert(std::make_pair(bc->getBcAlgorithmType(), bc->getAlgorithm())); + bcMap.insert(std::make_pair(bc->getBcAlgorithmType(), bc->getAlgorithm())); } - - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.h index c7ea28e58..42eefd930 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/BoundaryConditionsBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,12 +34,11 @@ #ifndef BoundaryConditionBlockVisitor_h__ #define BoundaryConditionBlockVisitor_h__ -#include <map> #include <PointerDefinitions.h> +#include <map> #include "Block3DVisitor.h" - class Grid3D; class Block3D; class BCAlgorithm; @@ -49,13 +48,14 @@ class BCAdapter; class BoundaryConditionsBlockVisitor : public Block3DVisitor { public: - BoundaryConditionsBlockVisitor(); - ~BoundaryConditionsBlockVisitor() override; - - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - void addBC(SPtr<BCAdapter> bc); + BoundaryConditionsBlockVisitor(); + ~BoundaryConditionsBlockVisitor() override; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void addBC(SPtr<BCAdapter> bc); + protected: private: - std::map<char, SPtr<BCAlgorithm> > bcMap; + std::map<char, SPtr<BCAlgorithm>> bcMap; }; #endif // BoundaryConditionBlockVisitor_h__ diff --git a/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.cpp index c0dabd959..b222d2c67 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.cpp @@ -1,60 +1,49 @@ #include "ChangeBoundaryDensityBlockVisitor.h" -#include "LBMKernel.h" -#include "Grid3DSystem.h" -#include "BoundaryConditions.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "Grid3D.h" #include "Block3D.h" -#include "BCArray3D.h" +#include "BoundaryConditions.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" +#include "LBMKernel.h" -ChangeBoundaryDensityBlockVisitor::ChangeBoundaryDensityBlockVisitor(float oldBoundaryDensity, float newBoundaryDensity) : -Block3DVisitor(0, Grid3DSystem::MAXLEVEL), -oldBoundaryDensity(oldBoundaryDensity), -newBoundaryDensity(newBoundaryDensity) +ChangeBoundaryDensityBlockVisitor::ChangeBoundaryDensityBlockVisitor(float oldBoundaryDensity, float newBoundaryDensity) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), oldBoundaryDensity(oldBoundaryDensity), + newBoundaryDensity(newBoundaryDensity) { - } ////////////////////////////////////////////////////////////////////////// -ChangeBoundaryDensityBlockVisitor::~ChangeBoundaryDensityBlockVisitor() -= default; +ChangeBoundaryDensityBlockVisitor::~ChangeBoundaryDensityBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// void ChangeBoundaryDensityBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getRank() == grid->getRank()) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + if (block->getRank() == grid->getRank()) { + SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - int maxX1 = (int)bcArray->getNX1(); - int maxX2 = (int)bcArray->getNX2(); - int maxX3 = (int)bcArray->getNX3(); + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + int maxX1 = (int)bcArray->getNX1(); + int maxX2 = (int)bcArray->getNX2(); + int maxX3 = (int)bcArray->getNX3(); - for (int x3 = minX3; x3 < maxX3; x3++) - { - for (int x2 = minX2; x2 < maxX2; x2++) - { - for (int x1 = minX1; x1 < maxX1; x1++) - { - if (!bcArray->isSolid(x1, x2, x3) && !bcArray->isUndefined(x1, x2, x3)) - { - bcPtr = bcArray->getBC(x1, x2, x3); - if (bcPtr) - { - if (bcPtr->hasDensityBoundary()) - { - float bcDensity = (float) bcPtr->getBoundaryDensity(); - if (bcDensity == oldBoundaryDensity) - { - bcPtr->setBoundaryDensity(newBoundaryDensity); + for (int x3 = minX3; x3 < maxX3; x3++) { + for (int x2 = minX2; x2 < maxX2; x2++) { + for (int x1 = minX1; x1 < maxX1; x1++) { + if (!bcArray->isSolid(x1, x2, x3) && !bcArray->isUndefined(x1, x2, x3)) { + bcPtr = bcArray->getBC(x1, x2, x3); + if (bcPtr) { + if (bcPtr->hasDensityBoundary()) { + float bcDensity = (float)bcPtr->getBoundaryDensity(); + if (bcDensity == oldBoundaryDensity) { + bcPtr->setBoundaryDensity(newBoundaryDensity); + } + } } - } - } - } + } + } } - } - } - } + } + } } diff --git a/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.h index 1baefe7ad..256448a06 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/ChangeBoundaryDensityBlockVisitor.h @@ -12,13 +12,14 @@ class BoundaryConditions; class ChangeBoundaryDensityBlockVisitor : public Block3DVisitor { public: - ChangeBoundaryDensityBlockVisitor(float oldBoundaryDensity, float newBoundaryDensity); - ~ChangeBoundaryDensityBlockVisitor() override; + ChangeBoundaryDensityBlockVisitor(float oldBoundaryDensity, float newBoundaryDensity); + ~ChangeBoundaryDensityBlockVisitor() override; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - float oldBoundaryDensity; - float newBoundaryDensity; - SPtr<BoundaryConditions> bcPtr; + float oldBoundaryDensity; + float newBoundaryDensity; + SPtr<BoundaryConditions> bcPtr; }; #endif // ChangeBoundaryDensityBlockVisitor_h__ diff --git a/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.cpp index 5c18afa0a..1f8a9c30e 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.cpp @@ -1,77 +1,58 @@ #include "CheckRatioBlockVisitor.h" -#include "Grid3DSystem.h" #include "Block3D.h" #include "Grid3D.h" +#include "Grid3DSystem.h" -CheckRatioBlockVisitor::CheckRatioBlockVisitor(int levelDepth/*shut be maxGridLevel*/, bool includeNotActiveBlocks) - : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) - , levelDepth(levelDepth) - , includeNotActiveBlocks(includeNotActiveBlocks) - , state(true) +CheckRatioBlockVisitor::CheckRatioBlockVisitor(int levelDepth /*shut be maxGridLevel*/, bool includeNotActiveBlocks) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), levelDepth(levelDepth), includeNotActiveBlocks(includeNotActiveBlocks), + state(true) { } ////////////////////////////////////////////////////////////////////////// void CheckRatioBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); - -// int nix1, nix2, nix3; - int nlev; -// int neighix1, neighix2, neighix3, - int neighlev; - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); -// bool hasAdded = false; - for (size_t i = 0; i<neighbors.size(); i++) - { - if ((neighbors[i]->isActive()||includeNotActiveBlocks) - &&neighbors[i]->getLevel()>level) - { - // neighix1 = neighbors[i]->getX1(); - // neighix2 = neighbors[i]->getX2(); - // neighix3 = neighbors[i]->getX3(); - neighlev = neighbors[i]->getLevel(); - // nix1 = neighix1>>1; - // nix2 = neighix2>>1; - // nix3 = neighix3>>1; - nlev = neighlev-1; + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); - if (nlev!=level) - { - //throw UbException(UB_EXARGS, "OverlapBlockVisitor::adaptBlock - leveldifferenz passt nicht, block: "+block->toString()); - //grid->expandBlock(ix1, ix2, ix3, level); - state = state&&false; - falseBlock = block; + // int nix1, nix2, nix3; + int nlev; + // int neighix1, neighix2, neighix3, + int neighlev; + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + // bool hasAdded = false; + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && neighbors[i]->getLevel() > level) { + // neighix1 = neighbors[i]->getX1(); + // neighix2 = neighbors[i]->getX2(); + // neighix3 = neighbors[i]->getX3(); + neighlev = neighbors[i]->getLevel(); + // nix1 = neighix1>>1; + // nix2 = neighix2>>1; + // nix3 = neighix3>>1; + nlev = neighlev - 1; - } - else - { - state = state&&true; - } + if (nlev != level) { + // throw UbException(UB_EXARGS, "OverlapBlockVisitor::adaptBlock - leveldifferenz passt nicht, block: + // "+block->toString()); grid->expandBlock(ix1, ix2, ix3, level); + state = state && false; + falseBlock = block; - //UBLOG(logINFO, "OverlapBlockVisitor::state= "<<state); + } else { + state = state && true; + } - - } - } + // UBLOG(logINFO, "OverlapBlockVisitor::state= "<<state); + } + } } ////////////////////////////////////////////////////////////////////////// -bool CheckRatioBlockVisitor::getState() -{ - return state; -} +bool CheckRatioBlockVisitor::getState() { return state; } ////////////////////////////////////////////////////////////////////////// -void CheckRatioBlockVisitor::resetState() -{ - state = true; -} +void CheckRatioBlockVisitor::resetState() { state = true; } ////////////////////////////////////////////////////////////////////////// -std::string CheckRatioBlockVisitor::getStateString() -{ - return falseBlock->toString(); -} +std::string CheckRatioBlockVisitor::getStateString() { return falseBlock->toString(); } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.h index da666fe47..c727447ff 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/CheckRatioBlockVisitor.h @@ -1,8 +1,8 @@ #ifndef CheckRatioBlockVisitor_H #define CheckRatioBlockVisitor_H -#include <string> #include <PointerDefinitions.h> +#include <string> #include "Block3DVisitor.h" @@ -12,22 +12,21 @@ class Block3D; class CheckRatioBlockVisitor : public Block3DVisitor { public: - CheckRatioBlockVisitor(int levelDepth, bool includeNotActiveBlocks = true); + CheckRatioBlockVisitor(int levelDepth, bool includeNotActiveBlocks = true); - ~CheckRatioBlockVisitor() override = default; + ~CheckRatioBlockVisitor() override = default; - bool getState(); - void resetState(); - std::string getStateString(); + bool getState(); + void resetState(); + std::string getStateString(); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - int levelDepth; - bool includeNotActiveBlocks; - bool state; - SPtr<Block3D> falseBlock; + int levelDepth; + bool includeNotActiveBlocks; + bool state; + SPtr<Block3D> falseBlock; }; -#endif //OverlapBlockVisitor_H - +#endif // OverlapBlockVisitor_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.cpp index 85047e258..384983726 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.cpp @@ -3,38 +3,32 @@ #include "Grid3D.h" #include <geometry3d/GbObject3D.h> -CoarsenCrossAndInsideGbObjectBlockVisitor::CoarsenCrossAndInsideGbObjectBlockVisitor() - : Block3DVisitor() -{ -} +CoarsenCrossAndInsideGbObjectBlockVisitor::CoarsenCrossAndInsideGbObjectBlockVisitor() : Block3DVisitor() {} ////////////////////////////////////////////////////////////////////////// -CoarsenCrossAndInsideGbObjectBlockVisitor::CoarsenCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int fineLevel, int coarseLevel) - : Block3DVisitor(fineLevel, fineLevel), geoObject(geoObject), coarseLevel(coarseLevel) +CoarsenCrossAndInsideGbObjectBlockVisitor::CoarsenCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, + int fineLevel, int coarseLevel) + : Block3DVisitor(fineLevel, fineLevel), geoObject(geoObject), coarseLevel(coarseLevel) { - } ////////////////////////////////////////////////////////////////////////// -CoarsenCrossAndInsideGbObjectBlockVisitor::~CoarsenCrossAndInsideGbObjectBlockVisitor() -= default; +CoarsenCrossAndInsideGbObjectBlockVisitor::~CoarsenCrossAndInsideGbObjectBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// void CoarsenCrossAndInsideGbObjectBlockVisitor::visit(const SPtr<Grid3D> grid, SPtr<Block3D> block) { - int fineLevel = block->getLevel(); - if (notActive && block->isNotActive()) return; - if (fineLevel>this->getStopLevel()) return; + int fineLevel = block->getLevel(); + if (notActive && block->isNotActive()) + return; + if (fineLevel > this->getStopLevel()) + return; - UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 deltas = grid->getBlockLengths(block); - if (geoObject->isCellInsideOrCuttingGbObject3D(val<1>(coords) - , val<2>(coords) - , val<3>(coords) - , val<1>(coords)+val<1>(deltas) - , val<2>(coords)+val<2>(deltas) - , val<3>(coords)+val<3>(deltas))) - { - grid->collapseBlock(block->getX1(), block->getX2(), block->getX3(), fineLevel, coarseLevel); - } + UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 deltas = grid->getBlockLengths(block); + if (geoObject->isCellInsideOrCuttingGbObject3D(val<1>(coords), val<2>(coords), val<3>(coords), + val<1>(coords) + val<1>(deltas), val<2>(coords) + val<2>(deltas), + val<3>(coords) + val<3>(deltas))) { + grid->collapseBlock(block->getX1(), block->getX2(), block->getX3(), fineLevel, coarseLevel); + } - return; + return; } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h index a62e6dc8d..0c234358d 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/CoarsenCrossAndInsideGbObjectBlockVisitor.h @@ -10,24 +10,24 @@ class Block3D; class Grid3D; //! \brief Refine blocks on base of bounding box which is defined with <i>geoObject</i> -//! \details The class uses a geometry object for define a bounding box. Inside and across this bounding box will be grid on block basis refinement. -//! \author K. Kutscher +//! \details The class uses a geometry object for define a bounding box. Inside and across this bounding box will be +//! grid on block basis refinement. \author K. Kutscher class CoarsenCrossAndInsideGbObjectBlockVisitor : public Block3DVisitor { public: - //! A default constructor - CoarsenCrossAndInsideGbObjectBlockVisitor(); - //! A constructor - //! \param geoObject a smart pointer to bounding box - //! \param refineLevel an integer for refine on this level - CoarsenCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int fineLevel, int coarseLevel); - ~CoarsenCrossAndInsideGbObjectBlockVisitor() override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - ////////////////////////////////////////////////////////////////////////// + //! A default constructor + CoarsenCrossAndInsideGbObjectBlockVisitor(); + //! A constructor + //! \param geoObject a smart pointer to bounding box + //! \param refineLevel an integer for refine on this level + CoarsenCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int fineLevel, int coarseLevel); + ~CoarsenCrossAndInsideGbObjectBlockVisitor() override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + ////////////////////////////////////////////////////////////////////////// protected: SPtr<GbObject3D> geoObject; - bool notActive{true}; - int coarseLevel; + bool notActive{ true }; + int coarseLevel; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.cpp index 01256a40c..df20a2de7 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.cpp @@ -1,471 +1,464 @@ #include "ConnectorBlockVisitor.h" -#include "Grid3DSystem.h" -#include "ConnectorFactory.h" -#include "InterpolationProcessor.h" #include "Communicator.h" +#include "ConnectorFactory.h" #include "Grid3D.h" +#include "Grid3DSystem.h" +#include "InterpolationProcessor.h" -ConnectorBlockVisitor::ConnectorBlockVisitor(SPtr<Communicator> comm, LBMReal nu, InterpolationProcessorPtr iProcessor, SPtr<ConnectorFactory> cFactory) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), - comm(comm), - nu(nu), - iProcessor(iProcessor), - cFactory(cFactory) +ConnectorBlockVisitor::ConnectorBlockVisitor(SPtr<Communicator> comm, LBMReal nu, InterpolationProcessorPtr iProcessor, + SPtr<ConnectorFactory> cFactory) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), comm(comm), nu(nu), iProcessor(iProcessor), cFactory(cFactory) { } ////////////////////////////////////////////////////////////////////////// -ConnectorBlockVisitor::~ConnectorBlockVisitor(void) -= default; +ConnectorBlockVisitor::~ConnectorBlockVisitor(void) = default; ////////////////////////////////////////////////////////////////////////// void ConnectorBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (!block) return; + if (!block) + return; - UBLOG(logDEBUG5, "ConnectorBlockVisitor::visit() - start"); - UBLOG(logDEBUG5, block->toString()); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::visit() - start"); + UBLOG(logDEBUG5, block->toString()); - gridRank = comm->getProcessID(); - grid->setRank(gridRank); + gridRank = comm->getProcessID(); + grid->setRank(gridRank); - setSameLevelConnectors(grid, block); + setSameLevelConnectors(grid, block); - if (grid->getFinestInitializedLevel() > grid->getCoarsestInitializedLevel()) - setInterpolationConnectors(grid, block); + if (grid->getFinestInitializedLevel() > grid->getCoarsestInitializedLevel()) + setInterpolationConnectors(grid, block); - if (block->getGlobalID()==2234) - { - UBLOG(logINFO, block->toString()); - } + if (block->getGlobalID() == 2234) { + UBLOG(logINFO, block->toString()); + } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::visit() - end"); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::visit() - end"); } ////////////////////////////////////////////////////////////////////////// void ConnectorBlockVisitor::setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getGlobalID()==2234) - { - UBLOG(logINFO, block->toString()); - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setSameLevelConnectors() - start"); - int blockRank = block->getRank(); - if (gridRank == blockRank && block->isActive()) - { - block->clearWeight(); - std::vector<SPtr<Block3D>> neighbors; - int ix1 = block->getX1(); - int ix2 = block->getX2(); - int ix3 = block->getX3(); - int level = block->getLevel(); - - for (int dir = 0; dir < D3Q27System::ENDDIR; dir++) - { - SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); - - if (neighBlock) - { - int neighBlockRank = neighBlock->getRank(); - if (blockRank == neighBlockRank && neighBlock->isActive()) - { - SPtr<Block3DConnector> connector; - connector = cFactory->createSameLevelDirectConnector(block, neighBlock, dir); - block->setConnector(connector); - } - else if (blockRank != neighBlockRank && neighBlock->isActive()) - { - setRemoteConnectors(block, neighBlock, dir); + if (block->getGlobalID() == 2234) { + UBLOG(logINFO, block->toString()); + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setSameLevelConnectors() - start"); + int blockRank = block->getRank(); + if (gridRank == blockRank && block->isActive()) { + block->clearWeight(); + std::vector<SPtr<Block3D>> neighbors; + int ix1 = block->getX1(); + int ix2 = block->getX2(); + int ix3 = block->getX3(); + int level = block->getLevel(); + + for (int dir = 0; dir < D3Q27System::ENDDIR; dir++) { + SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); + + if (neighBlock) { + int neighBlockRank = neighBlock->getRank(); + if (blockRank == neighBlockRank && neighBlock->isActive()) { + SPtr<Block3DConnector> connector; + connector = cFactory->createSameLevelDirectConnector(block, neighBlock, dir); + block->setConnector(connector); + } else if (blockRank != neighBlockRank && neighBlock->isActive()) { + setRemoteConnectors(block, neighBlock, dir); + } } - } - } - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setSameLevelConnectors() - end"); - if (block->getGlobalID()==2234) - { - UBLOG(logINFO, block->toString()); - } + } + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setSameLevelConnectors() - end"); + if (block->getGlobalID() == 2234) { + UBLOG(logINFO, block->toString()); + } } ////////////////////////////////////////////////////////////////////////// void ConnectorBlockVisitor::setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir) { - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setRemoteConnectors() - start"); - CreateTransmittersHelper helper; - CreateTransmittersHelper::TransmitterPtr sender, receiver; - helper.createTransmitters(sblock, tblock, dir, CreateTransmittersHelper::NONE, sender, receiver, comm, CreateTransmittersHelper::MPI); - - - SPtr<Block3DConnector> connector; - connector = cFactory->createSameLevelVectorConnector(sblock, sender, receiver, dir); - sblock->setConnector(connector); - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setRemoteConnectors() - end"); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setRemoteConnectors() - start"); + CreateTransmittersHelper helper; + CreateTransmittersHelper::TransmitterPtr sender, receiver; + helper.createTransmitters(sblock, tblock, dir, CreateTransmittersHelper::NONE, sender, receiver, comm, + CreateTransmittersHelper::MPI); + + SPtr<Block3DConnector> connector; + connector = cFactory->createSameLevelVectorConnector(sblock, sender, receiver, dir); + sblock->setConnector(connector); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setRemoteConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// void ConnectorBlockVisitor::setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getGlobalID()==2234) - { - UBLOG(logINFO, block->toString()); - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors() - start"); -// int blockRank = block->getRank(); - - //search for all blocks with different ranks - if (block->hasInterpolationFlagCF() && block->isActive()) - { - int fbx1 = block->getX1() << 1; - int fbx2 = block->getX2() << 1; - int fbx3 = block->getX3() << 1; - int level = block->getLevel() + 1; - - if (block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::E); - } - if (block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::W); - } - if (block->hasInterpolationFlagCF(D3Q27System::N)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::N); - } - if (block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::S); - } - if (block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::T); - } - if (block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock11 = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::B); - } - - //////NE-NW-SE-SW - if (block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::NE); - } - if (block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::SW); - } - if (block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::SE); - } - if (block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::NW); - } - - /////////TE-BW-BE-TW 1-0 - if (block->hasInterpolationFlagCF(D3Q27System::TE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2+0, fbx3+1, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TE); - } - if (block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+0, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BW); - } - if (block->hasInterpolationFlagCF(D3Q27System::BE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2+0, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BE); - } - if (block->hasInterpolationFlagCF(D3Q27System::TW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+0, fbx3+1, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TW); - } - - //////TN-BS-BN-TS - if (block->hasInterpolationFlagCF(D3Q27System::TN)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+0, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TN); - } - if (block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::S) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+0, fbx2, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BS); - } - if (block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+0, fbx2+1, fbx3, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BN); - } - if (block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::S) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+0, fbx2, fbx3+1, level); - SPtr<Block3D> fblock10 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock01; - SPtr<Block3D> fblock11; - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TS); - } - - - - - //////corners - if (block->hasInterpolationFlagCF(D3Q27System::TNE)&&!block->hasInterpolationFlagCF(D3Q27System::TE)&&!block->hasInterpolationFlagCF(D3Q27System::TN)&&!block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::T)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TNE); - } - if (block->hasInterpolationFlagCF(D3Q27System::TSW)&&!block->hasInterpolationFlagCF(D3Q27System::TW)&&!block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TSW); - } - if (block->hasInterpolationFlagCF(D3Q27System::TSE)&&!block->hasInterpolationFlagCF(D3Q27System::TE)&&!block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TSE); - } - if (block->hasInterpolationFlagCF(D3Q27System::TNW)&&!block->hasInterpolationFlagCF(D3Q27System::TW)&&!block->hasInterpolationFlagCF(D3Q27System::TN)&& !block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TNW); - } - if (block->hasInterpolationFlagCF(D3Q27System::BNE)&&!block->hasInterpolationFlagCF(D3Q27System::BE)&&!block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::B)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BNE); - } - if (block->hasInterpolationFlagCF(D3Q27System::BSW)&& !block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3+0, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BSW); - } - if (block->hasInterpolationFlagCF(D3Q27System::BSE)&& !block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::BE)&& !block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BSE); - } - if (block->hasInterpolationFlagCF(D3Q27System::BNW)&& !block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblock10;// = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblock01;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblock11;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BNW); - } - - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors() - end"); + if (block->getGlobalID() == 2234) { + UBLOG(logINFO, block->toString()); + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors() - start"); + // int blockRank = block->getRank(); + + // search for all blocks with different ranks + if (block->hasInterpolationFlagCF() && block->isActive()) { + int fbx1 = block->getX1() << 1; + int fbx2 = block->getX2() << 1; + int fbx3 = block->getX3() << 1; + int level = block->getLevel() + 1; + + if (block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::E); + } + if (block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::W); + } + if (block->hasInterpolationFlagCF(D3Q27System::N)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::N); + } + if (block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::S); + } + if (block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::T); + } + if (block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblock01 = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock11 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::B); + } + + //////NE-NW-SE-SW + if (block->hasInterpolationFlagCF(D3Q27System::NE) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::NE); + } + if (block->hasInterpolationFlagCF(D3Q27System::SW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::SW); + } + if (block->hasInterpolationFlagCF(D3Q27System::SE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 0, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::SE); + } + if (block->hasInterpolationFlagCF(D3Q27System::NW) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::NW); + } + + /////////TE-BW-BE-TW 1-0 + if (block->hasInterpolationFlagCF(D3Q27System::TE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2 + 0, fbx3 + 1, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 0, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2 + 0, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 0, fbx3 + 1, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TW); + } + + //////TN-BS-BN-TS + if (block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 0, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TN); + } + if (block->hasInterpolationFlagCF(D3Q27System::BS) && !block->hasInterpolationFlagCF(D3Q27System::S) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 0, fbx2, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BS); + } + if (block->hasInterpolationFlagCF(D3Q27System::BN) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 0, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BN); + } + if (block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::S) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 0, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock10 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock01; + SPtr<Block3D> fblock11; + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TS); + } + + //////corners + if (block->hasInterpolationFlagCF(D3Q27System::TNE) && !block->hasInterpolationFlagCF(D3Q27System::TE) && + !block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::NE) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TNE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TSW) && !block->hasInterpolationFlagCF(D3Q27System::TW) && + !block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::SW) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TSW); + } + if (block->hasInterpolationFlagCF(D3Q27System::TSE) && !block->hasInterpolationFlagCF(D3Q27System::TE) && + !block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::SE) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TSE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TNW) && !block->hasInterpolationFlagCF(D3Q27System::TW) && + !block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::NW) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1, fbx2+1, fbx3, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::TNW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BNE) && !block->hasInterpolationFlagCF(D3Q27System::BE) && + !block->hasInterpolationFlagCF(D3Q27System::BN) && !block->hasInterpolationFlagCF(D3Q27System::NE) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BNE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BSW) && !block->hasInterpolationFlagCF(D3Q27System::BS) && + !block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::SW) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2, fbx3 + 0, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BSW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BSE) && !block->hasInterpolationFlagCF(D3Q27System::BS) && + !block->hasInterpolationFlagCF(D3Q27System::BE) && !block->hasInterpolationFlagCF(D3Q27System::SE) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BSE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BNW) && !block->hasInterpolationFlagCF(D3Q27System::BN) && + !block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::NW) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblock00 = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblock10; // = grid->getBlock(fbx1, fbx2+1, fbx3, level); + SPtr<Block3D> fblock01; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblock11; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblock00, fblock10, fblock01, fblock11, block, D3Q27System::BNW); + } + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// -void ConnectorBlockVisitor::setInterpolationConnectors(SPtr<Block3D> fblock00, SPtr<Block3D> fblock10, SPtr<Block3D> fblock01, SPtr<Block3D> fblock11, SPtr<Block3D> cBlock, int dir) +void ConnectorBlockVisitor::setInterpolationConnectors(SPtr<Block3D> fblock00, SPtr<Block3D> fblock10, + SPtr<Block3D> fblock01, SPtr<Block3D> fblock11, + SPtr<Block3D> cBlock, int dir) { - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors(...) - start"); - int fblock00Rank = -999, fblock10Rank = -999, fblock01Rank = -999, fblock11Rank = -999; - if (fblock00) fblock00Rank = fblock00->getRank(); - if (fblock01) fblock01Rank = fblock01->getRank(); - if (fblock10) fblock10Rank = fblock10->getRank(); - if (fblock11) fblock11Rank = fblock11->getRank(); - int cBlockRank = cBlock->getRank(); - - LBMReal omegaF; - if (fblock00) omegaF = LBMSystem::calcCollisionFactor(nu, fblock00->getLevel()); - if (fblock01) omegaF = LBMSystem::calcCollisionFactor(nu, fblock01->getLevel()); - if (fblock10) omegaF = LBMSystem::calcCollisionFactor(nu, fblock10->getLevel()); - if (fblock11) omegaF = LBMSystem::calcCollisionFactor(nu, fblock11->getLevel()); - LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, cBlock->getLevel()); - iProcessor->setOmegas(omegaC, omegaF); - - InterpolationProcessorPtr cIProcessor(iProcessor->clone()); - InterpolationProcessorPtr fIProcessor00(iProcessor->clone()); - InterpolationProcessorPtr fIProcessor10(iProcessor->clone()); - InterpolationProcessorPtr fIProcessor01(iProcessor->clone()); - InterpolationProcessorPtr fIProcessor11(iProcessor->clone()); - - CreateTransmittersHelper::TransmitterPtr senderCF00, receiverCF00, - senderCF01, receiverCF01, - senderCF10, receiverCF10, - senderCF11, receiverCF11, - senderFC00, receiverFC00, - senderFC01, receiverFC01, - senderFC10, receiverFC10, - senderFC11, receiverFC11; - - if (fblock00) createTransmitters(cBlock, fblock00, dir, CreateTransmittersHelper::SW, senderCF00, receiverCF00, senderFC00, receiverFC00); - if (fblock01) createTransmitters(cBlock, fblock01, dir, CreateTransmittersHelper::NW, senderCF01, receiverCF01, senderFC01, receiverFC01); - if (fblock10) createTransmitters(cBlock, fblock10, dir, CreateTransmittersHelper::SE, senderCF10, receiverCF10, senderFC10, receiverFC10); - if (fblock11) createTransmitters(cBlock, fblock11, dir, CreateTransmittersHelper::NE, senderCF11, receiverCF11, senderFC11, receiverFC11); - - if (cBlockRank == gridRank) - { - SPtr<Block3DConnector> connector = cFactory->createCoarseToFineConnector(cBlock, - senderCF00, receiverCF00, senderCF01, receiverCF01, - senderCF10, receiverCF10, senderCF11, receiverCF11, - dir, cIProcessor); - cBlock->setConnector(connector); - } - if (fblock00 && fblock00Rank == gridRank) - { - SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector(fblock00, - senderFC00, receiverFC00, dir, fIProcessor00, FineToCoarseBlock3DConnector::Type00); - fblock00->setConnector(connector); - } - if (fblock01 && fblock01Rank == gridRank) - { - SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector(fblock01, - senderFC01, receiverFC01, dir, fIProcessor01, FineToCoarseBlock3DConnector::Type01); - fblock01->setConnector(connector); - } - if (fblock10 && fblock10Rank == gridRank) - { - SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector(fblock10, - senderFC10, receiverFC10, dir, fIProcessor10, FineToCoarseBlock3DConnector::Type10); - fblock10->setConnector(connector); - } - if (fblock11 && fblock11Rank == gridRank) - { - SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector(fblock11, - senderFC11, receiverFC11, dir, fIProcessor11, FineToCoarseBlock3DConnector::Type11); - fblock11->setConnector(connector); - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors(...) - end"); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors(...) - start"); + int fblock00Rank = -999, fblock10Rank = -999, fblock01Rank = -999, fblock11Rank = -999; + if (fblock00) + fblock00Rank = fblock00->getRank(); + if (fblock01) + fblock01Rank = fblock01->getRank(); + if (fblock10) + fblock10Rank = fblock10->getRank(); + if (fblock11) + fblock11Rank = fblock11->getRank(); + int cBlockRank = cBlock->getRank(); + + LBMReal omegaF; + if (fblock00) + omegaF = LBMSystem::calcCollisionFactor(nu, fblock00->getLevel()); + if (fblock01) + omegaF = LBMSystem::calcCollisionFactor(nu, fblock01->getLevel()); + if (fblock10) + omegaF = LBMSystem::calcCollisionFactor(nu, fblock10->getLevel()); + if (fblock11) + omegaF = LBMSystem::calcCollisionFactor(nu, fblock11->getLevel()); + LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, cBlock->getLevel()); + iProcessor->setOmegas(omegaC, omegaF); + + InterpolationProcessorPtr cIProcessor(iProcessor->clone()); + InterpolationProcessorPtr fIProcessor00(iProcessor->clone()); + InterpolationProcessorPtr fIProcessor10(iProcessor->clone()); + InterpolationProcessorPtr fIProcessor01(iProcessor->clone()); + InterpolationProcessorPtr fIProcessor11(iProcessor->clone()); + + CreateTransmittersHelper::TransmitterPtr senderCF00, receiverCF00, senderCF01, receiverCF01, senderCF10, + receiverCF10, senderCF11, receiverCF11, senderFC00, receiverFC00, senderFC01, receiverFC01, senderFC10, + receiverFC10, senderFC11, receiverFC11; + + if (fblock00) + createTransmitters(cBlock, fblock00, dir, CreateTransmittersHelper::SW, senderCF00, receiverCF00, senderFC00, + receiverFC00); + if (fblock01) + createTransmitters(cBlock, fblock01, dir, CreateTransmittersHelper::NW, senderCF01, receiverCF01, senderFC01, + receiverFC01); + if (fblock10) + createTransmitters(cBlock, fblock10, dir, CreateTransmittersHelper::SE, senderCF10, receiverCF10, senderFC10, + receiverFC10); + if (fblock11) + createTransmitters(cBlock, fblock11, dir, CreateTransmittersHelper::NE, senderCF11, receiverCF11, senderFC11, + receiverFC11); + + if (cBlockRank == gridRank) { + SPtr<Block3DConnector> connector = + cFactory->createCoarseToFineConnector(cBlock, senderCF00, receiverCF00, senderCF01, receiverCF01, + senderCF10, receiverCF10, senderCF11, receiverCF11, dir, cIProcessor); + cBlock->setConnector(connector); + } + if (fblock00 && fblock00Rank == gridRank) { + SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector( + fblock00, senderFC00, receiverFC00, dir, fIProcessor00, FineToCoarseBlock3DConnector::Type00); + fblock00->setConnector(connector); + } + if (fblock01 && fblock01Rank == gridRank) { + SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector( + fblock01, senderFC01, receiverFC01, dir, fIProcessor01, FineToCoarseBlock3DConnector::Type01); + fblock01->setConnector(connector); + } + if (fblock10 && fblock10Rank == gridRank) { + SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector( + fblock10, senderFC10, receiverFC10, dir, fIProcessor10, FineToCoarseBlock3DConnector::Type10); + fblock10->setConnector(connector); + } + if (fblock11 && fblock11Rank == gridRank) { + SPtr<Block3DConnector> connector = cFactory->createFineToCoarseConnector( + fblock11, senderFC11, receiverFC11, dir, fIProcessor11, FineToCoarseBlock3DConnector::Type11); + fblock11->setConnector(connector); + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::setInterpolationConnectors(...) - end"); } ////////////////////////////////////////////////////////////////////////// void ConnectorBlockVisitor::createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, - CreateTransmittersHelper::IBlock ib, - CreateTransmittersHelper::TransmitterPtr& senderCF, - CreateTransmittersHelper::TransmitterPtr& receiverCF, - CreateTransmittersHelper::TransmitterPtr& senderFC, - CreateTransmittersHelper::TransmitterPtr& receiverFC) + CreateTransmittersHelper::IBlock ib, + CreateTransmittersHelper::TransmitterPtr &senderCF, + CreateTransmittersHelper::TransmitterPtr &receiverCF, + CreateTransmittersHelper::TransmitterPtr &senderFC, + CreateTransmittersHelper::TransmitterPtr &receiverFC) { - UBLOG(logDEBUG5, "ConnectorBlockVisitor::createTransmitters(...) - start"); - CreateTransmittersHelper helper; -// bool MPIpool = true; -// bool orthogonal = false; - int fBlockRank = fBlock->getRank(); - int cBlockRank = cBlock->getRank(); - if (fBlockRank == cBlockRank && fBlockRank == gridRank) - { - senderCF = receiverFC = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - senderFC = receiverCF = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter< CbVector< LBMReal > >()); - } - else if (cBlockRank == gridRank) - { - helper.createTransmitters(cBlock, fBlock, dir, ib, senderCF, receiverCF, comm, CreateTransmittersHelper::MPI); - } - else if (fBlockRank == gridRank) - { - helper.createTransmitters(fBlock, cBlock, dir, ib, senderFC, receiverFC, comm, CreateTransmittersHelper::MPI); - } - UBLOG(logDEBUG5, "ConnectorBlockVisitor::createTransmitters(...) - end"); + UBLOG(logDEBUG5, "ConnectorBlockVisitor::createTransmitters(...) - start"); + CreateTransmittersHelper helper; + // bool MPIpool = true; + // bool orthogonal = false; + int fBlockRank = fBlock->getRank(); + int cBlockRank = cBlock->getRank(); + if (fBlockRank == cBlockRank && fBlockRank == gridRank) { + senderCF = receiverFC = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + senderFC = receiverCF = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + } else if (cBlockRank == gridRank) { + helper.createTransmitters(cBlock, fBlock, dir, ib, senderCF, receiverCF, comm, CreateTransmittersHelper::MPI); + } else if (fBlockRank == gridRank) { + helper.createTransmitters(fBlock, cBlock, dir, ib, senderFC, receiverFC, comm, CreateTransmittersHelper::MPI); + } + UBLOG(logDEBUG5, "ConnectorBlockVisitor::createTransmitters(...) - end"); } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.h index f40083001..973716555 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/ConnectorBlockVisitor.h @@ -4,8 +4,8 @@ #include <PointerDefinitions.h> #include "Block3DVisitor.h" -#include "D3Q27System.h" #include "CreateTransmittersHelper.h" +#include "D3Q27System.h" class Grid3D; class Block3D; @@ -15,27 +15,27 @@ class ConnectorFactory; class ConnectorBlockVisitor : public Block3DVisitor { public: - ConnectorBlockVisitor(SPtr<Communicator> comm, LBMReal nu, SPtr<InterpolationProcessor> iProcessor, SPtr<ConnectorFactory> cFactory); - ~ConnectorBlockVisitor() override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - ////////////////////////////////////////////////////////////////////////// + ConnectorBlockVisitor(SPtr<Communicator> comm, LBMReal nu, SPtr<InterpolationProcessor> iProcessor, + SPtr<ConnectorFactory> cFactory); + ~ConnectorBlockVisitor() override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + ////////////////////////////////////////////////////////////////////////// protected: - void setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); - void setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir); - void setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); - void setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, SPtr<Block3D> fBlockNW, SPtr<Block3D> fBlockNE, SPtr<Block3D> cBlock, int dir); - void createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, - CreateTransmittersHelper::IBlock ib, - CreateTransmittersHelper::TransmitterPtr& senderCF, - CreateTransmittersHelper::TransmitterPtr& receiverCF, - CreateTransmittersHelper::TransmitterPtr& senderFC, - CreateTransmittersHelper::TransmitterPtr& receiverFC); - SPtr<Communicator> comm; - int gridRank; - LBMReal nu; - SPtr<InterpolationProcessor> iProcessor; - SPtr<ConnectorFactory> cFactory; + void setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); + void setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir); + void setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); + void setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, SPtr<Block3D> fBlockNW, + SPtr<Block3D> fBlockNE, SPtr<Block3D> cBlock, int dir); + void createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, CreateTransmittersHelper::IBlock ib, + CreateTransmittersHelper::TransmitterPtr &senderCF, + CreateTransmittersHelper::TransmitterPtr &receiverCF, + CreateTransmittersHelper::TransmitterPtr &senderFC, + CreateTransmittersHelper::TransmitterPtr &receiverFC); + SPtr<Communicator> comm; + int gridRank; + LBMReal nu; + SPtr<InterpolationProcessor> iProcessor; + SPtr<ConnectorFactory> cFactory; }; -#endif //ConnectorBlockVisitor_H - +#endif // ConnectorBlockVisitor_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.cpp b/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.cpp index 24177504c..6a5cdbf82 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.cpp @@ -1,10 +1,10 @@ #include "CreateTransmittersHelper.h" -#include <D3Q27System.h> #include <Communicator.h> +#include <D3Q27System.h> #include <string> #ifdef VF_FETOL - #include <FETOLTransmitterBondPool.h> +#include <FETOLTransmitterBondPool.h> #endif #include <MathUtil.hpp> @@ -13,146 +13,152 @@ unsigned CreateTransmittersHelper::vKey = 0; using namespace std; ////////////////////////////////////////////////////////////////////////// -CreateTransmittersHelper::CreateTransmittersHelper() -= default; +CreateTransmittersHelper::CreateTransmittersHelper() = default; ////////////////////////////////////////////////////////////////////////// void CreateTransmittersHelper::createTransmitters(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir, IBlock ib, - TransmitterPtr& sender, TransmitterPtr& receiver, SPtr<Communicator> comm, TransmitterType tType) + TransmitterPtr &sender, TransmitterPtr &receiver, + SPtr<Communicator> comm, TransmitterType tType) { - //SourceBlock - int srcLevel = sblock->getLevel(); -// int srcID = sblock->getGlobalID(); - - //TargetBlock - int tgtLevel = tblock->getLevel(); -// int tgtID = tblock->getGlobalID(); - - int invDir = D3Q27System::INVDIR[dir]; - - if( srcLevel != tgtLevel ) invDir = dir; - - int srcRank = 0; - int tgtRank = 0; - - if (tType == MPI) - { - srcRank = sblock->getRank(); - tgtRank = tblock->getRank(); - } -#ifdef VF_FETOL - else if (tType == MPI2BOND) - { - srcRank = sblock->getLocalRank(); - tgtRank = tblock->getLocalRank(); - } -#endif + // SourceBlock + int srcLevel = sblock->getLevel(); + // int srcID = sblock->getGlobalID(); - if (tType == MPI -#ifdef VF_FETOL - || tType == MPI2BOND -#endif - ) - { - string sendPoolKey = generatePoolKey(srcRank, srcLevel, tgtRank, tgtLevel); - string receivePoolKey = generatePoolKey(tgtRank, tgtLevel, srcRank, srcLevel); - - TbCbVectorMpiPool <LBMReal>::MpiPoolPtr sendPool = TbCbVectorMpiPool <LBMReal>::getTbCbVectorMpiPool(sendPoolKey ); - TbCbVectorMpiPool <LBMReal>::MpiPoolPtr recvPool = TbCbVectorMpiPool <LBMReal>::getTbCbVectorMpiPool(receivePoolKey); - - MPI_Comm mpi_comm = *((MPI_Comm*) comm->getNativeCommunicator()); - - if( !sendPool ) sendPool = TbCbVectorMpiPool <LBMReal>::createTbCbVectorMpiPool(sendPoolKey ,tgtRank, generateMPITag(srcLevel, tgtLevel), mpi_comm); - if( !recvPool ) recvPool = TbCbVectorMpiPool <LBMReal>::createTbCbVectorMpiPool(receivePoolKey,tgtRank, generateMPITag(tgtLevel, srcLevel), mpi_comm); - - TbCbVectorMpiPool <LBMReal>::CbVectorKey keyOfSendCbVectorKey = generateVectorKey(sblock->getX1(), sblock->getX2(), sblock->getX3()/*tgtID*/, dir, ib); - TbCbVectorMpiPool <LBMReal>::CbVectorKey keyOfRecvCbVectorKey = generateVectorKey(tblock->getX1(), tblock->getX2(), tblock->getX3()/*srcID*/, invDir, ib); - - //////////////////////////////////////////////////////// - //DEBUG - //int myid = comm->getProcessID(); - //FILE * file; - ////char * name = "d:/temp/sendPoolKey.csv"; - //std::string name = "d:/temp/VectorKey" + UbSystem::toString(myid) + ".csv"; - //file = fopen(name.c_str(), "a"); - //fprintf(file, "%d;%d%;%d;%d;%d;%u;%d;%d%;%d;%d;%d;%u\n", sblock->getX1(), sblock->getX2(), sblock->getX3()/*tgtID*/, dir, ib, keyOfSendCbVectorKey, tblock->getX1(), tblock->getX2(), tblock->getX3()/*srcID*/, invDir, ib, keyOfRecvCbVectorKey); - //fclose(file); - //////////////////////////////////////////////////////// - - //create sender-/receiver - sender = TransmitterPtr( new TbCbVectorSenderMpiPool< LBMReal >(keyOfSendCbVectorKey,sendPool.get()) ); - receiver = TransmitterPtr( new TbCbVectorReceiverMpiPool< LBMReal >(keyOfRecvCbVectorKey,recvPool.get()) ); - } -#ifdef VF_FETOL - if (tType == BOND) - { - int srcBondRank = sblock->getRank(); - int tgtBondRank = tblock->getRank(); + // TargetBlock + int tgtLevel = tblock->getLevel(); + // int tgtID = tblock->getGlobalID(); - int sendBondPoolKey = generatePoolKey(srcBondRank,srcLevel,tgtBondRank,tgtLevel); - int receiveBondPoolKey = generatePoolKey(tgtBondRank,tgtLevel,srcBondRank,srcLevel); + int invDir = D3Q27System::INVDIR[dir]; - TbCbVectorBondPool <LBMReal>::BondPoolPtr sendPool = TbCbVectorBondPool <LBMReal>::getTbCbVectorBondPool(sendBondPoolKey ); - TbCbVectorBondPool <LBMReal>::BondPoolPtr recvPool = TbCbVectorBondPool <LBMReal>::getTbCbVectorBondPool(receiveBondPoolKey); + if (srcLevel != tgtLevel) + invDir = dir; - if( !sendPool ) sendPool = TbCbVectorBondPool <LBMReal>::createTbCbVectorBondPool(sendBondPoolKey ,tgtBondRank, generateMPITag(srcLevel, tgtLevel)); - if( !recvPool ) recvPool = TbCbVectorBondPool <LBMReal>::createTbCbVectorBondPool(receiveBondPoolKey,tgtBondRank, generateMPITag(tgtLevel, srcLevel)); + int srcRank = 0; + int tgtRank = 0; - TbCbVectorBondPool <LBMReal>::CbVectorKey keyOfSendCbVectorKey = generateVectorKey(tgtID, dir, ib); - TbCbVectorBondPool <LBMReal>::CbVectorKey keyOfRecvCbVectorKey = generateVectorKey(srcID, invDir, ib); + if (tType == MPI) { + srcRank = sblock->getRank(); + tgtRank = tblock->getRank(); + } +#ifdef VF_FETOL + else if (tType == MPI2BOND) { + srcRank = sblock->getLocalRank(); + tgtRank = tblock->getLocalRank(); + } +#endif - //create sender-/receiver - sender = TransmitterPtr( new TbCbVectorSenderBondPool< LBMReal >(keyOfSendCbVectorKey,sendPool.get()) ); - receiver = TransmitterPtr( new TbCbVectorReceiverBondPool< LBMReal >(keyOfRecvCbVectorKey,recvPool.get()) ); - } + if (tType == MPI +#ifdef VF_FETOL + || tType == MPI2BOND +#endif + ) { + string sendPoolKey = generatePoolKey(srcRank, srcLevel, tgtRank, tgtLevel); + string receivePoolKey = generatePoolKey(tgtRank, tgtLevel, srcRank, srcLevel); + + TbCbVectorMpiPool<LBMReal>::MpiPoolPtr sendPool = TbCbVectorMpiPool<LBMReal>::getTbCbVectorMpiPool(sendPoolKey); + TbCbVectorMpiPool<LBMReal>::MpiPoolPtr recvPool = + TbCbVectorMpiPool<LBMReal>::getTbCbVectorMpiPool(receivePoolKey); + + MPI_Comm mpi_comm = *((MPI_Comm *)comm->getNativeCommunicator()); + + if (!sendPool) + sendPool = TbCbVectorMpiPool<LBMReal>::createTbCbVectorMpiPool( + sendPoolKey, tgtRank, generateMPITag(srcLevel, tgtLevel), mpi_comm); + if (!recvPool) + recvPool = TbCbVectorMpiPool<LBMReal>::createTbCbVectorMpiPool( + receivePoolKey, tgtRank, generateMPITag(tgtLevel, srcLevel), mpi_comm); + + TbCbVectorMpiPool<LBMReal>::CbVectorKey keyOfSendCbVectorKey = + generateVectorKey(sblock->getX1(), sblock->getX2(), sblock->getX3() /*tgtID*/, dir, ib); + TbCbVectorMpiPool<LBMReal>::CbVectorKey keyOfRecvCbVectorKey = + generateVectorKey(tblock->getX1(), tblock->getX2(), tblock->getX3() /*srcID*/, invDir, ib); + + //////////////////////////////////////////////////////// + // DEBUG + // int myid = comm->getProcessID(); + // FILE * file; + ////char * name = "d:/temp/sendPoolKey.csv"; + // std::string name = "d:/temp/VectorKey" + UbSystem::toString(myid) + ".csv"; + // file = fopen(name.c_str(), "a"); + // fprintf(file, "%d;%d%;%d;%d;%d;%u;%d;%d%;%d;%d;%d;%u\n", sblock->getX1(), sblock->getX2(), + // sblock->getX3()/*tgtID*/, dir, ib, keyOfSendCbVectorKey, tblock->getX1(), tblock->getX2(), + // tblock->getX3()/*srcID*/, invDir, ib, keyOfRecvCbVectorKey); fclose(file); + //////////////////////////////////////////////////////// + + // create sender-/receiver + sender = TransmitterPtr(new TbCbVectorSenderMpiPool<LBMReal>(keyOfSendCbVectorKey, sendPool.get())); + receiver = TransmitterPtr(new TbCbVectorReceiverMpiPool<LBMReal>(keyOfRecvCbVectorKey, recvPool.get())); + } +#ifdef VF_FETOL + if (tType == BOND) { + int srcBondRank = sblock->getRank(); + int tgtBondRank = tblock->getRank(); + + int sendBondPoolKey = generatePoolKey(srcBondRank, srcLevel, tgtBondRank, tgtLevel); + int receiveBondPoolKey = generatePoolKey(tgtBondRank, tgtLevel, srcBondRank, srcLevel); + + TbCbVectorBondPool<LBMReal>::BondPoolPtr sendPool = + TbCbVectorBondPool<LBMReal>::getTbCbVectorBondPool(sendBondPoolKey); + TbCbVectorBondPool<LBMReal>::BondPoolPtr recvPool = + TbCbVectorBondPool<LBMReal>::getTbCbVectorBondPool(receiveBondPoolKey); + + if (!sendPool) + sendPool = TbCbVectorBondPool<LBMReal>::createTbCbVectorBondPool(sendBondPoolKey, tgtBondRank, + generateMPITag(srcLevel, tgtLevel)); + if (!recvPool) + recvPool = TbCbVectorBondPool<LBMReal>::createTbCbVectorBondPool(receiveBondPoolKey, tgtBondRank, + generateMPITag(tgtLevel, srcLevel)); + + TbCbVectorBondPool<LBMReal>::CbVectorKey keyOfSendCbVectorKey = generateVectorKey(tgtID, dir, ib); + TbCbVectorBondPool<LBMReal>::CbVectorKey keyOfRecvCbVectorKey = generateVectorKey(srcID, invDir, ib); + + // create sender-/receiver + sender = TransmitterPtr(new TbCbVectorSenderBondPool<LBMReal>(keyOfSendCbVectorKey, sendPool.get())); + receiver = TransmitterPtr(new TbCbVectorReceiverBondPool<LBMReal>(keyOfRecvCbVectorKey, recvPool.get())); + } #endif } ////////////////////////////////////////////////////////////////////////// int CreateTransmittersHelper::generateMPITag(int srcLevel, int tgtLevel) { - //The MPI standard guarantees that integers 0-32767 can be used as tags - if (srcLevel == tgtLevel) - { - return srcLevel; - } - else - { - srcLevel++; - tgtLevel++; - std::string str = UbSystem::toString<int>(srcLevel) + UbSystem::toString<int>(tgtLevel); - int r = UbSystem::stringTo<int>(str); - return r; - } + // The MPI standard guarantees that integers 0-32767 can be used as tags + if (srcLevel == tgtLevel) { + return srcLevel; + } else { + srcLevel++; + tgtLevel++; + std::string str = UbSystem::toString<int>(srcLevel) + UbSystem::toString<int>(tgtLevel); + int r = UbSystem::stringTo<int>(str); + return r; + } } ////////////////////////////////////////////////////////////////////////// string CreateTransmittersHelper::generatePoolKey(int srcRank, int srcLevel, int tgtRank, int tgtLevel) { - std::string str; - str = UbSystem::toString<int>(srcLevel); - str += "#"; - str += UbSystem::toString<int>(tgtLevel); - str += "#"; - str += UbSystem::toString<int>(srcRank); - str += "#"; - str += UbSystem::toString<int>(tgtRank); - - return str; + std::string str; + str = UbSystem::toString<int>(srcLevel); + str += "#"; + str += UbSystem::toString<int>(tgtLevel); + str += "#"; + str += UbSystem::toString<int>(srcRank); + str += "#"; + str += UbSystem::toString<int>(tgtRank); + + return str; } ////////////////////////////////////////////////////////////////////////// string CreateTransmittersHelper::generateVectorKey(int x1, int x2, int x3, int dir, IBlock ib) { - std::string str; - - str += UbSystem::toString<int>(x1); - str += "#"; - str += UbSystem::toString<int>(x2); - str += "#"; - str += UbSystem::toString<int>(x3); - str += "#"; - str += UbSystem::toString<int>(dir); - str += "#"; - str += UbSystem::toString<int>(ib); - - return str; + std::string str; + + str += UbSystem::toString<int>(x1); + str += "#"; + str += UbSystem::toString<int>(x2); + str += "#"; + str += UbSystem::toString<int>(x3); + str += "#"; + str += UbSystem::toString<int>(dir); + str += "#"; + str += UbSystem::toString<int>(ib); + + return str; } - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.h b/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.h index d339bdfb4..f34adb326 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.h +++ b/src/cpu/VirtualFluidsCore/Visitors/CreateTransmittersHelper.h @@ -1,4 +1,4 @@ -#ifndef CREATETRANSMITTERSHELPER_H +#ifndef CREATETRANSMITTERSHELPER_H #define CREATETRANSMITTERSHELPER_H #include "Block3D.h" @@ -6,33 +6,38 @@ #include "LBMSystem.h" +#include <basics/container/CbVector.h> #include <basics/transmitter/TbTransmitter.h> #include <basics/transmitter/TbTransmitterMpiPool.h> -#include <basics/container/CbVector.h> -//! \brief The class helps to create Transmitters. +//! \brief The class helps to create Transmitters. //! \details It is created two types of Transmitters: MPI and BOND //! \author K. Kucher class CreateTransmittersHelper { public: - //! Switch between same level and interpolation Connectors. NONE - for same level Connectors; SW, NW, NE, SE - source/target fine blocks in grid interface - enum IBlock {NONE, SW, NW, NE, SE}; - //! Switch between MPI and BOND Transmitters - enum TransmitterType {MPI, BOND, MPI2BOND}; + //! Switch between same level and interpolation Connectors. NONE - for same level Connectors; SW, NW, NE, SE - + //! source/target fine blocks in grid interface + enum IBlock { NONE, SW, NW, NE, SE }; + //! Switch between MPI and BOND Transmitters + enum TransmitterType { MPI, BOND, MPI2BOND }; + public: - using DataType = CbVector<LBMReal>; - using TransmitterPtr = SPtr<TbTransmitter<DataType> >; + using DataType = CbVector<LBMReal>; + using TransmitterPtr = SPtr<TbTransmitter<DataType>>; + public: - CreateTransmittersHelper(); - void createTransmitters(const SPtr<Block3D> sblock, const SPtr<Block3D> tblock, int dir, IBlock ib, - TransmitterPtr& sender, TransmitterPtr& receiver, SPtr<Communicator> comm, TransmitterType tType); + CreateTransmittersHelper(); + void createTransmitters(const SPtr<Block3D> sblock, const SPtr<Block3D> tblock, int dir, IBlock ib, + TransmitterPtr &sender, TransmitterPtr &receiver, SPtr<Communicator> comm, + TransmitterType tType); + protected: private: - std::string generatePoolKey(int srcRank, int srcLevel, int tgtRank, int tgtLevel); - std::string generateVectorKey(int x1, int x2, int x3,/*int id,*/ int dir, IBlock ib); - int generateMPITag(int srcLevel, int tgtLevel); - static unsigned int vKey; + std::string generatePoolKey(int srcRank, int srcLevel, int tgtRank, int tgtLevel); + std::string generateVectorKey(int x1, int x2, int x3, /*int id,*/ int dir, IBlock ib); + int generateMPITag(int srcLevel, int tgtLevel); + static unsigned int vKey; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.cpp index df8ce92ea..a8270d40d 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,18 +32,14 @@ //======================================================================================= #include "GenBlocksGridVisitor.h" -#include "Grid3DSystem.h" -#include "CoordinateTransformation3D.h" #include "Block3D.h" +#include "CoordinateTransformation3D.h" #include "Grid3D.h" +#include "Grid3DSystem.h" #include <geometry3d/GbObject3D.h> -GenBlocksGridVisitor::GenBlocksGridVisitor(SPtr<GbObject3D> boundingBox) : - boundingBox(boundingBox) -{ - -} +GenBlocksGridVisitor::GenBlocksGridVisitor(SPtr<GbObject3D> boundingBox) : boundingBox(boundingBox) {} ////////////////////////////////////////////////////////////////////////// void GenBlocksGridVisitor::visit(const SPtr<Grid3D> grid) { @@ -55,53 +51,53 @@ void GenBlocksGridVisitor::visit(const SPtr<Grid3D> grid) UbTupleInt3 blockNX = grid->getBlockNX(); - double blockLentghX1 = (double)val<1>(blockNX)*dx; - double blockLentghX2 = (double)val<2>(blockNX)*dx; - double blockLentghX3 = (double)val<3>(blockNX)*dx; + double blockLentghX1 = (double)val<1>(blockNX) * dx; + double blockLentghX2 = (double)val<2>(blockNX) * dx; + double blockLentghX3 = (double)val<3>(blockNX) * dx; - SPtr<CoordinateTransformation3D> trafo(new CoordinateTransformation3D(orgX1, orgX2, orgX3, blockLentghX1, blockLentghX2, blockLentghX3)); + SPtr<CoordinateTransformation3D> trafo( + new CoordinateTransformation3D(orgX1, orgX2, orgX3, blockLentghX1, blockLentghX2, blockLentghX3)); grid->setCoordinateTransformator(trafo); genBlocks(grid); } ////////////////////////////////////////////////////////////////////////// -void GenBlocksGridVisitor::fillExtentWithBlocks( SPtr<Grid3D> grid ) +void GenBlocksGridVisitor::fillExtentWithBlocks(SPtr<Grid3D> grid) { - for(int x3 = val<3>(minInd); x3 < val<3>(maxInd); x3++) - { - for(int x2 = val<2>(minInd); x2 < val<2>(maxInd); x2++) - { - for(int x1 = val<1>(minInd); x1 < val<1>(maxInd); x1++) - { - SPtr<Block3D> block( new Block3D(x1,x2,x3,0) ); - grid->addBlock(block); - } - } - } + for (int x3 = val<3>(minInd); x3 < val<3>(maxInd); x3++) { + for (int x2 = val<2>(minInd); x2 < val<2>(maxInd); x2++) { + for (int x1 = val<1>(minInd); x1 < val<1>(maxInd); x1++) { + SPtr<Block3D> block(new Block3D(x1, x2, x3, 0)); + grid->addBlock(block); + } + } + } } ////////////////////////////////////////////////////////////////////////// void GenBlocksGridVisitor::genBlocks(SPtr<Grid3D> grid) { - minInd = grid->getBlockIndexes(boundingBox->getX1Minimum(), boundingBox->getX2Minimum(), boundingBox->getX3Minimum()); - double geoMaxX1 = boundingBox->getX1Maximum(); - double geoMaxX2 = boundingBox->getX2Maximum(); - double geoMaxX3 = boundingBox->getX3Maximum(); - maxInd = grid->getBlockIndexes(geoMaxX1, geoMaxX2, geoMaxX3); - UbTupleDouble3 blockCoord = grid->getBlockWorldCoordinates(static_cast<int>(val<1>(maxInd)), static_cast<int>(val<2>(maxInd)), static_cast<int>(val<3>(maxInd)), 0); - //if (geoMaxX1 > val<1>(blockCoord)) + minInd = + grid->getBlockIndexes(boundingBox->getX1Minimum(), boundingBox->getX2Minimum(), boundingBox->getX3Minimum()); + double geoMaxX1 = boundingBox->getX1Maximum(); + double geoMaxX2 = boundingBox->getX2Maximum(); + double geoMaxX3 = boundingBox->getX3Maximum(); + maxInd = grid->getBlockIndexes(geoMaxX1, geoMaxX2, geoMaxX3); + UbTupleDouble3 blockCoord = grid->getBlockWorldCoordinates( + static_cast<int>(val<1>(maxInd)), static_cast<int>(val<2>(maxInd)), static_cast<int>(val<3>(maxInd)), 0); + // if (geoMaxX1 > val<1>(blockCoord)) // val<1>(maxInd) += 1; - //if (geoMaxX2 > val<2>(blockCoord)) + // if (geoMaxX2 > val<2>(blockCoord)) // val<2>(maxInd) += 1; - //if (geoMaxX3 > val<3>(blockCoord)) + // if (geoMaxX3 > val<3>(blockCoord)) // val<3>(maxInd) += 1; double dx = grid->getDeltaX(0); - if (fabs(geoMaxX1-val<1>(blockCoord)) > dx) - val<1>(maxInd) += 1; - if (fabs(geoMaxX2-val<2>(blockCoord)) > dx) - val<2>(maxInd) += 1; - if (fabs(geoMaxX3-val<3>(blockCoord)) > dx) - val<3>(maxInd) += 1; + if (fabs(geoMaxX1 - val<1>(blockCoord)) > dx) + val<1>(maxInd) += 1; + if (fabs(geoMaxX2 - val<2>(blockCoord)) > dx) + val<2>(maxInd) += 1; + if (fabs(geoMaxX3 - val<3>(blockCoord)) > dx) + val<3>(maxInd) += 1; this->fillExtentWithBlocks(grid); diff --git a/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.h index 65db6fa10..ddfdf4b16 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/GenBlocksGridVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -38,7 +38,7 @@ #include <basics/utilities/UbTuple.h> -#include "Grid3DVisitor.h" +#include "Grid3DVisitor.h" class GbObject3D; class Grid3D; @@ -47,16 +47,16 @@ class Grid3D; class GenBlocksGridVisitor : public Grid3DVisitor { public: - GenBlocksGridVisitor(SPtr<GbObject3D> boundingBox); - ~GenBlocksGridVisitor() override= default; + GenBlocksGridVisitor(SPtr<GbObject3D> boundingBox); + ~GenBlocksGridVisitor() override = default; - void visit(SPtr<Grid3D> grid) override; + void visit(SPtr<Grid3D> grid) override; private: - UbTupleInt3 minInd, maxInd; - SPtr<GbObject3D> boundingBox; - void fillExtentWithBlocks(SPtr<Grid3D> grid); - void genBlocks(SPtr<Grid3D> grid); + UbTupleInt3 minInd, maxInd; + SPtr<GbObject3D> boundingBox; + void fillExtentWithBlocks(SPtr<Grid3D> grid); + void genBlocks(SPtr<Grid3D> grid); }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/Grid3DVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/Grid3DVisitor.h index 5484ac442..80c39e66c 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/Grid3DVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/Grid3DVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -36,17 +36,16 @@ #include <PointerDefinitions.h> - class Grid3D; //! Abstract class provides interface for visitor design pettern class Grid3DVisitor { public: - Grid3DVisitor() = default; - virtual ~Grid3DVisitor() = default; + Grid3DVisitor() = default; + virtual ~Grid3DVisitor() = default; - virtual void visit(SPtr<Grid3D> grid) = 0; + virtual void visit(SPtr<Grid3D> grid) = 0; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.cpp index 055cf6a2b..c424a6376 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,292 +32,301 @@ //======================================================================================= #include "InitDistributionsBlockVisitor.h" -#include "LBMKernel.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "Grid3DSystem.h" +#include "Block3D.h" #include "DataSet3D.h" #include "EsoTwist3D.h" #include "Grid3D.h" -#include "Block3D.h" -#include "BCArray3D.h" +#include "Grid3DSystem.h" +#include "LBMKernel.h" -InitDistributionsBlockVisitor::InitDistributionsBlockVisitor() - : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) +InitDistributionsBlockVisitor::InitDistributionsBlockVisitor() : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) { - this->setVx1(0.0); - this->setVx2(0.0); - this->setVx3(0.0); - this->setRho(0.0); + this->setVx1(0.0); + this->setVx2(0.0); + this->setVx3(0.0); + this->setRho(0.0); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx1( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muVx1 = parser; +void InitDistributionsBlockVisitor::setVx1(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muVx1 = parser; } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx2( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muVx2 = parser; +void InitDistributionsBlockVisitor::setVx2(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muVx2 = parser; } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx3( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muVx3 = parser; +void InitDistributionsBlockVisitor::setVx3(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muVx3 = parser; } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setRho( const mu::Parser& parser) -{ - this->checkFunction(parser); - this->muRho = parser; +void InitDistributionsBlockVisitor::setRho(const mu::Parser &parser) +{ + this->checkFunction(parser); + this->muRho = parser; } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx1( const std::string& muParserString) -{ - this->muVx1.SetExpr(muParserString); - this->checkFunction(muVx1); +void InitDistributionsBlockVisitor::setVx1(const std::string &muParserString) +{ + this->muVx1.SetExpr(muParserString); + this->checkFunction(muVx1); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx2( const std::string& muParserString) -{ - this->muVx2.SetExpr(muParserString); - this->checkFunction(muVx2); +void InitDistributionsBlockVisitor::setVx2(const std::string &muParserString) +{ + this->muVx2.SetExpr(muParserString); + this->checkFunction(muVx2); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx3( const std::string& muParserString) -{ - this->muVx3.SetExpr(muParserString); - this->checkFunction(muVx3); +void InitDistributionsBlockVisitor::setVx3(const std::string &muParserString) +{ + this->muVx3.SetExpr(muParserString); + this->checkFunction(muVx3); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setRho( const std::string& muParserString) -{ - this->muRho.SetExpr(muParserString); - this->checkFunction(muRho); +void InitDistributionsBlockVisitor::setRho(const std::string &muParserString) +{ + this->muRho.SetExpr(muParserString); + this->checkFunction(muRho); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx1( LBMReal vx1 ) -{ - this->muVx1.SetExpr( UbSystem::toString(vx1,D3Q27RealLim::digits10) ); - this->checkFunction(muVx1); +void InitDistributionsBlockVisitor::setVx1(LBMReal vx1) +{ + this->muVx1.SetExpr(UbSystem::toString(vx1, D3Q27RealLim::digits10)); + this->checkFunction(muVx1); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx2( LBMReal vx2 ) -{ - this->muVx2.SetExpr( UbSystem::toString(vx2,D3Q27RealLim::digits10) ); - this->checkFunction(muVx2); +void InitDistributionsBlockVisitor::setVx2(LBMReal vx2) +{ + this->muVx2.SetExpr(UbSystem::toString(vx2, D3Q27RealLim::digits10)); + this->checkFunction(muVx2); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setVx3( LBMReal vx3 ) -{ - this->muVx3.SetExpr( UbSystem::toString(vx3,D3Q27RealLim::digits10) ); - this->checkFunction(muVx3); +void InitDistributionsBlockVisitor::setVx3(LBMReal vx3) +{ + this->muVx3.SetExpr(UbSystem::toString(vx3, D3Q27RealLim::digits10)); + this->checkFunction(muVx3); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::setRho( LBMReal rho ) -{ - this->muRho.SetExpr( UbSystem::toString(rho,D3Q27RealLim::digits10) ); - this->checkFunction(muRho); +void InitDistributionsBlockVisitor::setRho(LBMReal rho) +{ + this->muRho.SetExpr(UbSystem::toString(rho, D3Q27RealLim::digits10)); + this->checkFunction(muRho); } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsBlockVisitor::visit(const SPtr<Grid3D> grid, SPtr<Block3D> block) +void InitDistributionsBlockVisitor::visit(const SPtr<Grid3D> grid, SPtr<Block3D> block) { - using namespace D3Q27System; - - if(!block) UB_THROW( UbException(UB_EXARGS,"block is not exist") ); - - //UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - //UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); - double dx = grid->getDeltaX(block); - - //define vars for functions - mu::value_type x1,x2,x3; - this->muVx1.DefineVar("x1",&x1); this->muVx1.DefineVar("x2",&x2); this->muVx1.DefineVar("x3",&x3); - this->muVx2.DefineVar("x1",&x1); this->muVx2.DefineVar("x2",&x2); this->muVx2.DefineVar("x3",&x3); - this->muVx3.DefineVar("x1",&x1); this->muVx3.DefineVar("x2",&x2); this->muVx3.DefineVar("x3",&x3); - this->muRho.DefineVar("x1",&x1); this->muRho.DefineVar("x2",&x2); this->muRho.DefineVar("x3",&x3); - - using CalcFeqsFct = void (*)(LBMReal* const& /*feq[27]*/,const LBMReal& /*(d)rho*/,const LBMReal& /*vx1*/,const LBMReal& /*vx2*/,const LBMReal& /*vx3*/); - CalcFeqsFct calcFeqsFct = NULL; - - LBMReal vx1,vx2,vx3,rho; - - int gridRank = grid->getRank(); - int blockRank = block->getRank(); - - if (blockRank == gridRank && block->isActive()) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - if (!kernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+block->toString()); - - if(kernel->getCompressible()) - calcFeqsFct = &D3Q27System::calcCompFeq; - else - calcFeqsFct = &D3Q27System::calcIncompFeq; - - //UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); - - LBMReal o = kernel->getCollisionFactor(); - - LBMReal f[D3Q27System::ENDF+1]; - - for(size_t ix3=0; ix3<bcArray->getNX3(); ix3++) - for(size_t ix2=0; ix2<bcArray->getNX2(); ix2++) - for(size_t ix1=0; ix1<bcArray->getNX1(); ix1++) - { - Vector3D coords = grid->getNodeCoordinates(block, ix1, ix2, ix3); - x1 = coords[0]; - x2 = coords[1]; - x3 = coords[2]; - - vx1 = muVx1.Eval(); - vx2 = muVx2.Eval(); - vx3 = muVx3.Eval(); - rho = muRho.Eval(); - - //x-derivative - double deltaX=dx*0.5; - x1 = coords[0]+deltaX; - double vx1Plusx1 = muVx1.Eval(); - double vx2Plusx1 = muVx2.Eval(); - double vx3Plusx1 = muVx3.Eval(); - - x1 = coords[0]-deltaX; - double vx1Minusx1 = muVx1.Eval(); - double vx2Minusx1 = muVx2.Eval(); - double vx3Minusx1 = muVx3.Eval(); - - //y-derivative - x1 = coords[0]; - x2 = coords[1]+deltaX; - double vx1Plusx2 = muVx1.Eval(); - double vx2Plusx2 = muVx2.Eval(); - double vx3Plusx2 = muVx3.Eval(); - - x2 = coords[1]-deltaX; - double vx1Minusx2 = muVx1.Eval(); - double vx2Minusx2 = muVx2.Eval(); - double vx3Minusx2 = muVx3.Eval(); - - //z-derivative - x2 = coords[1]; - x3 = coords[2]+deltaX; - double vx1Plusx3 = muVx1.Eval(); - double vx2Plusx3 = muVx2.Eval(); - double vx3Plusx3 = muVx3.Eval(); - - x3 = coords[2]-deltaX; - double vx1Minusx3 = muVx1.Eval(); - double vx2Minusx3 = muVx2.Eval(); - double vx3Minusx3 = muVx3.Eval(); - - double ax=(vx1Plusx1-vx1Minusx1)/(2.0*deltaX)*dx; - double bx=(vx2Plusx1-vx2Minusx1)/(2.0*deltaX)*dx; - double cx=(vx3Plusx1-vx3Minusx1)/(2.0*deltaX)*dx; - - double ay=(vx1Plusx2-vx1Minusx2)/(2.0*deltaX)*dx; - double by=(vx2Plusx2-vx2Minusx2)/(2.0*deltaX)*dx; - double cy=(vx3Plusx2-vx3Minusx2)/(2.0*deltaX)*dx; - - double az=(vx1Plusx3-vx1Minusx3)/(2.0*deltaX)*dx; - double bz=(vx2Plusx3-vx2Minusx3)/(2.0*deltaX)*dx; - double cz=(vx3Plusx3-vx3Minusx3)/(2.0*deltaX)*dx; - double eps_new=1.0; - LBMReal op = 1.; - - LBMReal feq[27]; - - calcFeqsFct(feq,rho,vx1,vx2,vx3); - - double f_E = eps_new *((5.*ax*o + 5.*by*o + 5.*cz*o - 8.*ax*op + 4.*by*op + 4.*cz*op)/(54.*o*op)); - double f_N = f_E + eps_new *((2.*(ax - by))/(9.*o)); - double f_T = f_E + eps_new *((2.*(ax - cz))/(9.*o)); - double f_NE = eps_new *(-(5.*cz*o + 3.*(ay + bx)*op - 2.*cz*op + ax*(5.*o + op) + by*(5.*o + op))/(54.*o*op)); - double f_SE = f_NE + eps_new *(( ay + bx )/(9.*o)); - double f_TE = eps_new *(-(5.*cz*o + by*(5.*o - 2.*op) + 3.*(az + cx)*op + cz*op + ax*(5.*o + op))/(54.*o*op)); - double f_BE = f_TE + eps_new *(( az + cx )/(9.*o)); - double f_TN = eps_new *(-(5.*ax*o + 5.*by*o + 5.*cz*o - 2.*ax*op + by*op + 3.*bz*op + 3.*cy*op + cz*op)/(54.*o*op)); - double f_BN = f_TN + eps_new *(( bz + cy )/(9.*o)); - double f_ZERO = eps_new *((5.*(ax + by + cz))/(9.*op)); - double f_TNE = eps_new *(-(ay + az + bx + bz + cx + cy)/(72.*o)); - double f_TSW = - eps_new *((ay + bx)/(36.*o)) - f_TNE; - double f_TSE = - eps_new *((az + cx)/(36.*o)) - f_TNE; - double f_TNW = - eps_new *((bz + cy)/(36.*o)) - f_TNE; - - - f[E] = f_E + feq[E]; - f[W] = f_E + feq[W]; - f[N] = f_N + feq[N]; - f[S] = f_N + feq[S]; - f[T] = f_T + feq[T]; - f[B] = f_T + feq[B]; - f[NE] = f_NE + feq[NE]; - f[SW] = f_NE + feq[SW]; - f[SE] = f_SE + feq[SE]; - f[NW] = f_SE + feq[NW]; - f[TE] = f_TE + feq[TE]; - f[BW] = f_TE + feq[BW]; - f[BE] = f_BE + feq[BE]; - f[TW] = f_BE + feq[TW]; - f[TN] = f_TN + feq[TN]; - f[BS] = f_TN + feq[BS]; - f[BN] = f_BN + feq[BN]; - f[TS] = f_BN + feq[TS]; - f[TNE] = f_TNE + feq[TNE]; - f[TNW] = f_TNW + feq[TNW]; - f[TSE] = f_TSE + feq[TSE]; - f[TSW] = f_TSW + feq[TSW]; - f[BNE] = f_TSW + feq[BNE]; - f[BNW] = f_TSE + feq[BNW]; - f[BSE] = f_TNW + feq[BSE]; - f[BSW] = f_TNE + feq[BSW]; - f[ZERO] = f_ZERO + feq[ZERO]; - - //calcFeqsFct(f,rho,vx1,vx2,vx3); - //distributions->setDistribution(f, ix1, ix2, ix3); - distributions->setDistributionInv(f, ix1, ix2, ix3); - - //distributions->swap(); - //distributions->setDistribution(f, ix1, ix2, ix3); - //distributions->setDistributionInv(f, ix1, ix2, ix3); - //distributions->swap(); - - } - } - - //variablen der functions loeschen, da die verwiesenen Objecte nach dem verlassen des scopes ungueltig sind! - this->muVx1.ClearVar(); - this->muVx2.ClearVar(); - this->muVx3.ClearVar(); - this->muRho.ClearVar(); - + using namespace D3Q27System; + + if (!block) + UB_THROW(UbException(UB_EXARGS, "block is not exist")); + + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + // UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + double dx = grid->getDeltaX(block); + + // define vars for functions + mu::value_type x1, x2, x3; + this->muVx1.DefineVar("x1", &x1); + this->muVx1.DefineVar("x2", &x2); + this->muVx1.DefineVar("x3", &x3); + this->muVx2.DefineVar("x1", &x1); + this->muVx2.DefineVar("x2", &x2); + this->muVx2.DefineVar("x3", &x3); + this->muVx3.DefineVar("x1", &x1); + this->muVx3.DefineVar("x2", &x2); + this->muVx3.DefineVar("x3", &x3); + this->muRho.DefineVar("x1", &x1); + this->muRho.DefineVar("x2", &x2); + this->muRho.DefineVar("x3", &x3); + + using CalcFeqsFct = void (*)(LBMReal *const & /*feq[27]*/, const LBMReal & /*(d)rho*/, const LBMReal & /*vx1*/, + const LBMReal & /*vx2*/, const LBMReal & /*vx3*/); + CalcFeqsFct calcFeqsFct = NULL; + + LBMReal vx1, vx2, vx3, rho; + + int gridRank = grid->getRank(); + int blockRank = block->getRank(); + + if (blockRank == gridRank && block->isActive()) { + SPtr<ILBMKernel> kernel = block->getKernel(); + if (!kernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + block->toString()); + + if (kernel->getCompressible()) + calcFeqsFct = &D3Q27System::calcCompFeq; + else + calcFeqsFct = &D3Q27System::calcIncompFeq; + + // UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<DistributionArray3D> distributions = kernel->getDataSet()->getFdistributions(); + + LBMReal o = kernel->getCollisionFactor(); + + LBMReal f[D3Q27System::ENDF + 1]; + + for (size_t ix3 = 0; ix3 < bcArray->getNX3(); ix3++) + for (size_t ix2 = 0; ix2 < bcArray->getNX2(); ix2++) + for (size_t ix1 = 0; ix1 < bcArray->getNX1(); ix1++) { + Vector3D coords = grid->getNodeCoordinates(block, ix1, ix2, ix3); + x1 = coords[0]; + x2 = coords[1]; + x3 = coords[2]; + + vx1 = muVx1.Eval(); + vx2 = muVx2.Eval(); + vx3 = muVx3.Eval(); + rho = muRho.Eval(); + + // x-derivative + double deltaX = dx * 0.5; + x1 = coords[0] + deltaX; + double vx1Plusx1 = muVx1.Eval(); + double vx2Plusx1 = muVx2.Eval(); + double vx3Plusx1 = muVx3.Eval(); + + x1 = coords[0] - deltaX; + double vx1Minusx1 = muVx1.Eval(); + double vx2Minusx1 = muVx2.Eval(); + double vx3Minusx1 = muVx3.Eval(); + + // y-derivative + x1 = coords[0]; + x2 = coords[1] + deltaX; + double vx1Plusx2 = muVx1.Eval(); + double vx2Plusx2 = muVx2.Eval(); + double vx3Plusx2 = muVx3.Eval(); + + x2 = coords[1] - deltaX; + double vx1Minusx2 = muVx1.Eval(); + double vx2Minusx2 = muVx2.Eval(); + double vx3Minusx2 = muVx3.Eval(); + + // z-derivative + x2 = coords[1]; + x3 = coords[2] + deltaX; + double vx1Plusx3 = muVx1.Eval(); + double vx2Plusx3 = muVx2.Eval(); + double vx3Plusx3 = muVx3.Eval(); + + x3 = coords[2] - deltaX; + double vx1Minusx3 = muVx1.Eval(); + double vx2Minusx3 = muVx2.Eval(); + double vx3Minusx3 = muVx3.Eval(); + + double ax = (vx1Plusx1 - vx1Minusx1) / (2.0 * deltaX) * dx; + double bx = (vx2Plusx1 - vx2Minusx1) / (2.0 * deltaX) * dx; + double cx = (vx3Plusx1 - vx3Minusx1) / (2.0 * deltaX) * dx; + + double ay = (vx1Plusx2 - vx1Minusx2) / (2.0 * deltaX) * dx; + double by = (vx2Plusx2 - vx2Minusx2) / (2.0 * deltaX) * dx; + double cy = (vx3Plusx2 - vx3Minusx2) / (2.0 * deltaX) * dx; + + double az = (vx1Plusx3 - vx1Minusx3) / (2.0 * deltaX) * dx; + double bz = (vx2Plusx3 - vx2Minusx3) / (2.0 * deltaX) * dx; + double cz = (vx3Plusx3 - vx3Minusx3) / (2.0 * deltaX) * dx; + double eps_new = 1.0; + LBMReal op = 1.; + + LBMReal feq[27]; + + calcFeqsFct(feq, rho, vx1, vx2, vx3); + + double f_E = + eps_new * + ((5. * ax * o + 5. * by * o + 5. * cz * o - 8. * ax * op + 4. * by * op + 4. * cz * op) / + (54. * o * op)); + double f_N = f_E + eps_new * ((2. * (ax - by)) / (9. * o)); + double f_T = f_E + eps_new * ((2. * (ax - cz)) / (9. * o)); + double f_NE = + eps_new * + (-(5. * cz * o + 3. * (ay + bx) * op - 2. * cz * op + ax * (5. * o + op) + by * (5. * o + op)) / + (54. * o * op)); + double f_SE = f_NE + eps_new * ((ay + bx) / (9. * o)); + double f_TE = + eps_new * + (-(5. * cz * o + by * (5. * o - 2. * op) + 3. * (az + cx) * op + cz * op + ax * (5. * o + op)) / + (54. * o * op)); + double f_BE = f_TE + eps_new * ((az + cx) / (9. * o)); + double f_TN = eps_new * (-(5. * ax * o + 5. * by * o + 5. * cz * o - 2. * ax * op + by * op + + 3. * bz * op + 3. * cy * op + cz * op) / + (54. * o * op)); + double f_BN = f_TN + eps_new * ((bz + cy) / (9. * o)); + double f_ZERO = eps_new * ((5. * (ax + by + cz)) / (9. * op)); + double f_TNE = eps_new * (-(ay + az + bx + bz + cx + cy) / (72. * o)); + double f_TSW = -eps_new * ((ay + bx) / (36. * o)) - f_TNE; + double f_TSE = -eps_new * ((az + cx) / (36. * o)) - f_TNE; + double f_TNW = -eps_new * ((bz + cy) / (36. * o)) - f_TNE; + + f[E] = f_E + feq[E]; + f[W] = f_E + feq[W]; + f[N] = f_N + feq[N]; + f[S] = f_N + feq[S]; + f[T] = f_T + feq[T]; + f[B] = f_T + feq[B]; + f[NE] = f_NE + feq[NE]; + f[SW] = f_NE + feq[SW]; + f[SE] = f_SE + feq[SE]; + f[NW] = f_SE + feq[NW]; + f[TE] = f_TE + feq[TE]; + f[BW] = f_TE + feq[BW]; + f[BE] = f_BE + feq[BE]; + f[TW] = f_BE + feq[TW]; + f[TN] = f_TN + feq[TN]; + f[BS] = f_TN + feq[BS]; + f[BN] = f_BN + feq[BN]; + f[TS] = f_BN + feq[TS]; + f[TNE] = f_TNE + feq[TNE]; + f[TNW] = f_TNW + feq[TNW]; + f[TSE] = f_TSE + feq[TSE]; + f[TSW] = f_TSW + feq[TSW]; + f[BNE] = f_TSW + feq[BNE]; + f[BNW] = f_TSE + feq[BNW]; + f[BSE] = f_TNW + feq[BSE]; + f[BSW] = f_TNE + feq[BSW]; + f[ZERO] = f_ZERO + feq[ZERO]; + + // calcFeqsFct(f,rho,vx1,vx2,vx3); + // distributions->setDistribution(f, ix1, ix2, ix3); + distributions->setDistributionInv(f, ix1, ix2, ix3); + + // distributions->swap(); + // distributions->setDistribution(f, ix1, ix2, ix3); + // distributions->setDistributionInv(f, ix1, ix2, ix3); + // distributions->swap(); + } + } + + // variablen der functions loeschen, da die verwiesenen Objecte nach dem verlassen des scopes ungueltig sind! + this->muVx1.ClearVar(); + this->muVx2.ClearVar(); + this->muVx3.ClearVar(); + this->muRho.ClearVar(); } ////////////////////////////////////////////////////////////////////////// void InitDistributionsBlockVisitor::checkFunction(mu::Parser fct) { - double x1=1.0,x2=1.0,x3=1.0; - fct.DefineVar("x1",&x1); - fct.DefineVar("x2",&x2); - fct.DefineVar("x3",&x3); - - try - { - fct.Eval(); - fct.ClearVar(); - } - catch(mu::ParserError& e) - { - throw UbException(UB_EXARGS,"function: "+e.GetExpr() + (std::string)"error: "+e.GetMsg() - +(std::string)", only x1,x2,x3 are allowed as variables" ); - } + double x1 = 1.0, x2 = 1.0, x3 = 1.0; + fct.DefineVar("x1", &x1); + fct.DefineVar("x2", &x2); + fct.DefineVar("x3", &x3); + + try { + fct.Eval(); + fct.ClearVar(); + } catch (mu::ParserError &e) { + throw UbException(UB_EXARGS, "function: " + e.GetExpr() + (std::string) "error: " + e.GetMsg() + + (std::string) ", only x1,x2,x3 are allowed as variables"); + } } ////////////////////////////////////////////////////////////////////////// - - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h index bddda7901..c64f0ed93 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -45,13 +45,13 @@ class Grid3D; class Block3D; //! \brief A class implements an initialization of the flow area. -//! \details +//! \details //! It is more flexible way to initialize flow area. -//! You can define functions to calculate macroscopic values for feq. +//! You can define functions to calculate macroscopic values for feq. //! x1,x2,x3 are automatically defined via this adapter and are the real world //! vertex coordinates. //! -//!if function is invalid an UbException with detailed information is thrown +//! if function is invalid an UbException with detailed information is thrown //! //! Example: //! \code @@ -63,39 +63,39 @@ class Block3D; class InitDistributionsBlockVisitor : public Block3DVisitor { public: - using D3Q27RealLim = std::numeric_limits<LBMReal>; + using D3Q27RealLim = std::numeric_limits<LBMReal>; public: - InitDistributionsBlockVisitor(); - ////////////////////////////////////////////////////////////////////////// - //automatic vars are: x1,x2, x3 - //ussage example: setVx1("x1*0.01+x2*0.003") - ////////////////////////////////////////////////////////////////////////// - void setVx1( const mu::Parser& parser); - void setVx2( const mu::Parser& parser); - void setVx3( const mu::Parser& parser); - void setRho( const mu::Parser& parser); + InitDistributionsBlockVisitor(); + ////////////////////////////////////////////////////////////////////////// + // automatic vars are: x1,x2, x3 + // ussage example: setVx1("x1*0.01+x2*0.003") + ////////////////////////////////////////////////////////////////////////// + void setVx1(const mu::Parser &parser); + void setVx2(const mu::Parser &parser); + void setVx3(const mu::Parser &parser); + void setRho(const mu::Parser &parser); - void setVx1( const std::string& muParserString); - void setVx2( const std::string& muParserString); - void setVx3( const std::string& muParserString); - void setRho( const std::string& muParserString); - ////////////////////////////////////////////////////////////////////////// - void setVx1( LBMReal vx1 ); - void setVx2( LBMReal vx2 ); - void setVx3( LBMReal vx3 ); - void setRho( LBMReal rho ); + void setVx1(const std::string &muParserString); + void setVx2(const std::string &muParserString); + void setVx3(const std::string &muParserString); + void setRho(const std::string &muParserString); + ////////////////////////////////////////////////////////////////////////// + void setVx1(LBMReal vx1); + void setVx2(LBMReal vx2); + void setVx3(LBMReal vx3); + void setRho(LBMReal rho); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: - void checkFunction(mu::Parser fct); + void checkFunction(mu::Parser fct); private: - mu::Parser muVx1; - mu::Parser muVx2; - mu::Parser muVx3; - mu::Parser muRho; + mu::Parser muVx1; + mu::Parser muVx2; + mu::Parser muVx3; + mu::Parser muRho; }; -#endif //D3Q27INITDISTRIBUTIONSPATCHVISITOR_H +#endif // D3Q27INITDISTRIBUTIONSPATCHVISITOR_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.cpp index c03e82310..73431d928 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.cpp @@ -1,255 +1,241 @@ #include "InitDistributionsFromFileBlockVisitor.h" -#include <basics/utilities/UbFileInputASCII.h> -#include "LBMKernel.h" +#include "BCArray3D.h" #include "BCProcessor.h" -#include "Grid3DSystem.h" -#include "InitDensityLBMKernel.h" +#include "Block3D.h" #include "DataSet3D.h" #include "EsoTwist3D.h" #include "Grid3D.h" -#include "Block3D.h" -#include "BCArray3D.h" - +#include "Grid3DSystem.h" +#include "InitDensityLBMKernel.h" +#include "LBMKernel.h" +#include <basics/utilities/UbFileInputASCII.h> -InitDistributionsFromFileBlockVisitor::InitDistributionsFromFileBlockVisitor(/*LBMReal nu, */LBMReal rho, std::string filename) - : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), /*nu(nu),*/ rho(rho) +InitDistributionsFromFileBlockVisitor::InitDistributionsFromFileBlockVisitor(/*LBMReal nu, */ LBMReal rho, + std::string filename) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), /*nu(nu),*/ rho(rho) { - UbFileInputASCII in(filename); - if (!in) - { - throw UbException(UB_EXARGS, "could not open file "+filename); - } - - int nodesX1 = in.readInteger(); - int nodesX2 = in.readInteger(); - int nodesX3 = in.readInteger(); - - matrix = CbArray4D<LBMReal, IndexerX4X3X2X1>(3, nodesX1, nodesX2, nodesX3, 0); - - for (int x3 = 0; x3<nodesX3; x3++) - for (int x2 = 0; x2<nodesX2; x2++) - for (int x1 = 0; x1<nodesX1; x1++) - { - //for (int x1 = 0; x1<nodesX1; x1++) - // for (int x2 = 0; x2<nodesX2; x2++) - // for (int x3 = 0; x3<nodesX3; x3++) - // { - matrix(Vx1, x1, x2, x3) = in.readDouble(); - matrix(Vx2, x1, x2, x3) = in.readDouble(); - matrix(Vx3, x1, x2, x3) = in.readDouble(); - } + UbFileInputASCII in(filename); + if (!in) { + throw UbException(UB_EXARGS, "could not open file " + filename); + } + + int nodesX1 = in.readInteger(); + int nodesX2 = in.readInteger(); + int nodesX3 = in.readInteger(); + + matrix = CbArray4D<LBMReal, IndexerX4X3X2X1>(3, nodesX1, nodesX2, nodesX3, 0); + + for (int x3 = 0; x3 < nodesX3; x3++) + for (int x2 = 0; x2 < nodesX2; x2++) + for (int x1 = 0; x1 < nodesX1; x1++) { + // for (int x1 = 0; x1<nodesX1; x1++) + // for (int x2 = 0; x2<nodesX2; x2++) + // for (int x3 = 0; x3<nodesX3; x3++) + // { + matrix(Vx1, x1, x2, x3) = in.readDouble(); + matrix(Vx2, x1, x2, x3) = in.readDouble(); + matrix(Vx3, x1, x2, x3) = in.readDouble(); + } } ////////////////////////////////////////////////////////////////////////// void InitDistributionsFromFileBlockVisitor::visit(const SPtr<Grid3D> grid, SPtr<Block3D> block) { - using namespace D3Q27System; - - if (!block) UB_THROW(UbException(UB_EXARGS, "block is not exist")); - -// UbTupleDouble3 blockLengths = grid->getBlockLengths(block); -// UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); -// double dx = grid->getDeltaX(block); -// LBMReal o = LBMSystem::calcCollisionFactor(nu, block->getLevel()); - - - //Funktionszeiger - typedef void(*CalcFeqsFct)(LBMReal* const& /*feq[27]*/, const LBMReal& /*(d)rho*/, const LBMReal& /*vx1*/, const LBMReal& /*vx2*/, const LBMReal& /*vx3*/); - CalcFeqsFct calcFeqsFct = NULL; - - LBMReal vx1, vx2, vx3; - - int gridRank = grid->getRank(); - int blockRank = block->getRank(); - - if (blockRank==gridRank && block->isActive()) - { - SPtr<ILBMKernel> kernel = block->getKernel(); - if (!kernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+block->toString()); - - if (kernel->getCompressible()) - calcFeqsFct = &D3Q27System::calcCompFeq; - else - calcFeqsFct = &D3Q27System::calcIncompFeq; - -// UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - - SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); - SPtr<EsoTwist3D> distributions = dynamicPointerCast<EsoTwist3D>(kernel->getDataSet()->getFdistributions()); - - LBMReal f[D3Q27System::ENDF+1]; - -// size_t nx1 = distributions->getNX1(); -// size_t nx2 = distributions->getNX2(); -// size_t nx3 = distributions->getNX3(); - - int minX1 = 0; - int minX2 = 0; -// int minX3 = 0; - - int maxX1 = (int)bcArray->getNX1(); - int maxX2 = (int)bcArray->getNX2(); - int maxX3 = (int)bcArray->getNX3(); - - int maxMX1 = (int)matrix.getNX2(); - int maxMX2 = (int)matrix.getNX3(); - int maxMX3 = (int)matrix.getNX4(); - - int blockix1 = block->getX1(); - int blockix2 = block->getX2(); - int blockix3 = block->getX3(); - - UbTupleInt3 blockNx = grid->getBlockNX(); - - for (int ix3 = minX1; ix3<maxX3; ix3++) - for (int ix2 = minX2; ix2<maxX2; ix2++) - for (int ix1 = minX1; ix1<maxX1; ix1++) - { - int x1 = blockix1*val<1>(blockNx)+ix1-1; - int x2 = blockix2*val<2>(blockNx)+ix2-1; - int x3 = blockix3*val<3>(blockNx)+ix3-1; - - if (x1==-1) - { - x1 = maxMX1-1; - } - if (x2==-1) - { - x2 = maxMX2-1; - } - if (x3==-1) - { - x3 = maxMX3-1; - } - - if (x1==maxMX1) - { - x1 = 1; - } - if (x2==maxMX2) - { - x2 = 1; - } - if (x3==maxMX3) - { - x3 = 1; - } - - vx1 = matrix(Vx1, x1, x2, x3); - vx2 = matrix(Vx2, x1, x2, x3); - vx3 = matrix(Vx3, x1, x2, x3); - - //int x1p, x2p, x3p; - - ////x-derivative - //if (x1+1 >= maxMX1) x1p = x1; - //else x1p = x1+1; - //double vx1Plusx1 = matrix(Vx1, x1p, x2, x3); - //double vx2Plusx1 = matrix(Vx2, x1p, x2, x3); - //double vx3Plusx1 = matrix(Vx3, x1p, x2, x3); - - //if (x1-1 < minX1) x1p = x1; - //else x1p = x1-1; - //double vx1Minusx1 = matrix(Vx1, x1p, x2, x3); - //double vx2Minusx1 = matrix(Vx2, x1p, x2, x3); - //double vx3Minusx1 = matrix(Vx3, x1p, x2, x3); - - ////y-derivative - //if (x2+1 >= maxMX2) x2p = x2; - //else x2p = x2+1; - //double vx1Plusx2 = matrix(Vx1, x1, x2p, x3); - //double vx2Plusx2 = matrix(Vx2, x1, x2p, x3); - //double vx3Plusx2 = matrix(Vx3, x1, x2p, x3); - - //if (x2-1 < minX2) x2p = x2; - //else x2p = x2-1; - //double vx1Minusx2 = matrix(Vx1, x1, x2p, x3); - //double vx2Minusx2 = matrix(Vx2, x1, x2p, x3); - //double vx3Minusx2 = matrix(Vx3, x1, x2p, x3); - - ////z-derivative - //if (x3+1 >= maxMX3) x3p = x3; - //else x3p = x3+1; - //double vx1Plusx3 = matrix(Vx1, x1, x2, x3p); - //double vx2Plusx3 = matrix(Vx2, x1, x2, x3p); - //double vx3Plusx3 = matrix(Vx3, x1, x2, x3p); - - //if (x3-1 < minX3) x3p = x3; - //else x3p = x3-1; - //double vx1Minusx3 = matrix(Vx1, x1, x2, x3); - //double vx2Minusx3 = matrix(Vx2, x1, x2, x3); - //double vx3Minusx3 = matrix(Vx3, x1, x2, x3); - - //double ax = (vx1Plusx1 - vx1Minusx1) / (2.0); - //double bx = (vx2Plusx1 - vx2Minusx1) / (2.0); - //double cx = (vx3Plusx1 - vx3Minusx1) / (2.0); - - //double ay = (vx1Plusx2 - vx1Minusx2) / (2.0); - //double by = (vx2Plusx2 - vx2Minusx2) / (2.0); - //double cy = (vx3Plusx2 - vx3Minusx2) / (2.0); - - //double az = (vx1Plusx3 - vx1Minusx3) / (2.0); - //double bz = (vx2Plusx3 - vx2Minusx3) / (2.0); - //double cz = (vx3Plusx3 - vx3Minusx3) / (2.0); - //double eps_new = 1.0; - //LBMReal op = 1.; - - //LBMReal feq[27]; - - //calcFeqsFct(feq, rho, vx1, vx2, vx3); - - //double f_E = eps_new *((5.*ax*o + 5.*by*o + 5.*cz*o - 8.*ax*op + 4.*by*op + 4.*cz*op) / (54.*o*op)); - //double f_N = f_E + eps_new *((2.*(ax - by)) / (9.*o)); - //double f_T = f_E + eps_new *((2.*(ax - cz)) / (9.*o)); - //double f_NE = eps_new *(-(5.*cz*o + 3.*(ay + bx)*op - 2.*cz*op + ax*(5.*o + op) + by*(5.*o + op)) / (54.*o*op)); - //double f_SE = f_NE + eps_new *((ay + bx) / (9.*o)); - //double f_TE = eps_new *(-(5.*cz*o + by*(5.*o - 2.*op) + 3.*(az + cx)*op + cz*op + ax*(5.*o + op)) / (54.*o*op)); - //double f_BE = f_TE + eps_new *((az + cx) / (9.*o)); - //double f_TN = eps_new *(-(5.*ax*o + 5.*by*o + 5.*cz*o - 2.*ax*op + by*op + 3.*bz*op + 3.*cy*op + cz*op) / (54.*o*op)); - //double f_BN = f_TN + eps_new *((bz + cy) / (9.*o)); - //double f_ZERO = eps_new *((5.*(ax + by + cz)) / (9.*op)); - //double f_TNE = eps_new *(-(ay + az + bx + bz + cx + cy) / (72.*o)); - //double f_TSW = -eps_new *((ay + bx) / (36.*o)) - f_TNE; - //double f_TSE = -eps_new *((az + cx) / (36.*o)) - f_TNE; - //double f_TNW = -eps_new *((bz + cy) / (36.*o)) - f_TNE; - - - //f[E] = f_E + feq[E]; - //f[W] = f_E + feq[W]; - //f[N] = f_N + feq[N]; - //f[S] = f_N + feq[S]; - //f[T] = f_T + feq[T]; - //f[B] = f_T + feq[B]; - //f[NE] = f_NE + feq[NE]; - //f[SW] = f_NE + feq[SW]; - //f[SE] = f_SE + feq[SE]; - //f[NW] = f_SE + feq[NW]; - //f[TE] = f_TE + feq[TE]; - //f[BW] = f_TE + feq[BW]; - //f[BE] = f_BE + feq[BE]; - //f[TW] = f_BE + feq[TW]; - //f[TN] = f_TN + feq[TN]; - //f[BS] = f_TN + feq[BS]; - //f[BN] = f_BN + feq[BN]; - //f[TS] = f_BN + feq[TS]; - //f[TNE] = f_TNE + feq[TNE]; - //f[TNW] = f_TNW + feq[TNW]; - //f[TSE] = f_TSE + feq[TSE]; - //f[TSW] = f_TSW + feq[TSW]; - //f[BNE] = f_TSW + feq[BNE]; - //f[BNW] = f_TSE + feq[BNW]; - //f[BSE] = f_TNW + feq[BSE]; - //f[BSW] = f_TNE + feq[BSW]; - //f[ZERO] = f_ZERO + feq[ZERO]; - - calcFeqsFct(f, rho, vx1, vx2, vx3); - - distributions->setDistribution(f, ix1, ix2, ix3); - distributions->setDistributionInv(f, ix1, ix2, ix3); - dynamicPointerCast<InitDensityLBMKernel>(kernel)->setVelocity(ix1, ix2, ix3, vx1, vx2, vx3); - } - - } + using namespace D3Q27System; + + if (!block) + UB_THROW(UbException(UB_EXARGS, "block is not exist")); + + // UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + // UbTupleDouble3 nodeOffset = grid->getNodeOffset(block); + // double dx = grid->getDeltaX(block); + // LBMReal o = LBMSystem::calcCollisionFactor(nu, block->getLevel()); + + // Funktionszeiger + typedef void (*CalcFeqsFct)(LBMReal *const & /*feq[27]*/, const LBMReal & /*(d)rho*/, const LBMReal & /*vx1*/, + const LBMReal & /*vx2*/, const LBMReal & /*vx3*/); + CalcFeqsFct calcFeqsFct = NULL; + + LBMReal vx1, vx2, vx3; + + int gridRank = grid->getRank(); + int blockRank = block->getRank(); + + if (blockRank == gridRank && block->isActive()) { + SPtr<ILBMKernel> kernel = block->getKernel(); + if (!kernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + block->toString()); + + if (kernel->getCompressible()) + calcFeqsFct = &D3Q27System::calcCompFeq; + else + calcFeqsFct = &D3Q27System::calcIncompFeq; + + // UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + + SPtr<BCArray3D> bcArray = kernel->getBCProcessor()->getBCArray(); + SPtr<EsoTwist3D> distributions = dynamicPointerCast<EsoTwist3D>(kernel->getDataSet()->getFdistributions()); + + LBMReal f[D3Q27System::ENDF + 1]; + + // size_t nx1 = distributions->getNX1(); + // size_t nx2 = distributions->getNX2(); + // size_t nx3 = distributions->getNX3(); + + int minX1 = 0; + int minX2 = 0; + // int minX3 = 0; + + int maxX1 = (int)bcArray->getNX1(); + int maxX2 = (int)bcArray->getNX2(); + int maxX3 = (int)bcArray->getNX3(); + + int maxMX1 = (int)matrix.getNX2(); + int maxMX2 = (int)matrix.getNX3(); + int maxMX3 = (int)matrix.getNX4(); + + int blockix1 = block->getX1(); + int blockix2 = block->getX2(); + int blockix3 = block->getX3(); + + UbTupleInt3 blockNx = grid->getBlockNX(); + + for (int ix3 = minX1; ix3 < maxX3; ix3++) + for (int ix2 = minX2; ix2 < maxX2; ix2++) + for (int ix1 = minX1; ix1 < maxX1; ix1++) { + int x1 = blockix1 * val<1>(blockNx) + ix1 - 1; + int x2 = blockix2 * val<2>(blockNx) + ix2 - 1; + int x3 = blockix3 * val<3>(blockNx) + ix3 - 1; + + if (x1 == -1) { + x1 = maxMX1 - 1; + } + if (x2 == -1) { + x2 = maxMX2 - 1; + } + if (x3 == -1) { + x3 = maxMX3 - 1; + } + + if (x1 == maxMX1) { + x1 = 1; + } + if (x2 == maxMX2) { + x2 = 1; + } + if (x3 == maxMX3) { + x3 = 1; + } + + vx1 = matrix(Vx1, x1, x2, x3); + vx2 = matrix(Vx2, x1, x2, x3); + vx3 = matrix(Vx3, x1, x2, x3); + + // int x1p, x2p, x3p; + + ////x-derivative + // if (x1+1 >= maxMX1) x1p = x1; + // else x1p = x1+1; + // double vx1Plusx1 = matrix(Vx1, x1p, x2, x3); + // double vx2Plusx1 = matrix(Vx2, x1p, x2, x3); + // double vx3Plusx1 = matrix(Vx3, x1p, x2, x3); + + // if (x1-1 < minX1) x1p = x1; + // else x1p = x1-1; + // double vx1Minusx1 = matrix(Vx1, x1p, x2, x3); + // double vx2Minusx1 = matrix(Vx2, x1p, x2, x3); + // double vx3Minusx1 = matrix(Vx3, x1p, x2, x3); + + ////y-derivative + // if (x2+1 >= maxMX2) x2p = x2; + // else x2p = x2+1; + // double vx1Plusx2 = matrix(Vx1, x1, x2p, x3); + // double vx2Plusx2 = matrix(Vx2, x1, x2p, x3); + // double vx3Plusx2 = matrix(Vx3, x1, x2p, x3); + + // if (x2-1 < minX2) x2p = x2; + // else x2p = x2-1; + // double vx1Minusx2 = matrix(Vx1, x1, x2p, x3); + // double vx2Minusx2 = matrix(Vx2, x1, x2p, x3); + // double vx3Minusx2 = matrix(Vx3, x1, x2p, x3); + + ////z-derivative + // if (x3+1 >= maxMX3) x3p = x3; + // else x3p = x3+1; + // double vx1Plusx3 = matrix(Vx1, x1, x2, x3p); + // double vx2Plusx3 = matrix(Vx2, x1, x2, x3p); + // double vx3Plusx3 = matrix(Vx3, x1, x2, x3p); + + // if (x3-1 < minX3) x3p = x3; + // else x3p = x3-1; + // double vx1Minusx3 = matrix(Vx1, x1, x2, x3); + // double vx2Minusx3 = matrix(Vx2, x1, x2, x3); + // double vx3Minusx3 = matrix(Vx3, x1, x2, x3); + + // double ax = (vx1Plusx1 - vx1Minusx1) / (2.0); + // double bx = (vx2Plusx1 - vx2Minusx1) / (2.0); + // double cx = (vx3Plusx1 - vx3Minusx1) / (2.0); + + // double ay = (vx1Plusx2 - vx1Minusx2) / (2.0); + // double by = (vx2Plusx2 - vx2Minusx2) / (2.0); + // double cy = (vx3Plusx2 - vx3Minusx2) / (2.0); + + // double az = (vx1Plusx3 - vx1Minusx3) / (2.0); + // double bz = (vx2Plusx3 - vx2Minusx3) / (2.0); + // double cz = (vx3Plusx3 - vx3Minusx3) / (2.0); + // double eps_new = 1.0; + // LBMReal op = 1.; + + // LBMReal feq[27]; + + // calcFeqsFct(feq, rho, vx1, vx2, vx3); + + // double f_E = eps_new *((5.*ax*o + 5.*by*o + 5.*cz*o - 8.*ax*op + 4.*by*op + 4.*cz*op) / + // (54.*o*op)); double f_N = f_E + eps_new *((2.*(ax - by)) / (9.*o)); double f_T = f_E + eps_new + // *((2.*(ax - cz)) / (9.*o)); double f_NE = eps_new *(-(5.*cz*o + 3.*(ay + bx)*op - 2.*cz*op + + // ax*(5.*o + op) + by*(5.*o + op)) / (54.*o*op)); double f_SE = f_NE + eps_new *((ay + bx) / + // (9.*o)); double f_TE = eps_new *(-(5.*cz*o + by*(5.*o - 2.*op) + 3.*(az + cx)*op + cz*op + + // ax*(5.*o + op)) / (54.*o*op)); double f_BE = f_TE + eps_new *((az + cx) / (9.*o)); double f_TN = + // eps_new *(-(5.*ax*o + 5.*by*o + 5.*cz*o - 2.*ax*op + by*op + 3.*bz*op + 3.*cy*op + cz*op) / + // (54.*o*op)); double f_BN = f_TN + eps_new *((bz + cy) / (9.*o)); double f_ZERO = eps_new *((5.*(ax + // + by + cz)) / (9.*op)); double f_TNE = eps_new *(-(ay + az + bx + bz + cx + cy) / (72.*o)); double + // f_TSW = -eps_new *((ay + bx) / (36.*o)) - f_TNE; double f_TSE = -eps_new *((az + cx) / (36.*o)) - + // f_TNE; double f_TNW = -eps_new *((bz + cy) / (36.*o)) - f_TNE; + + // f[E] = f_E + feq[E]; + // f[W] = f_E + feq[W]; + // f[N] = f_N + feq[N]; + // f[S] = f_N + feq[S]; + // f[T] = f_T + feq[T]; + // f[B] = f_T + feq[B]; + // f[NE] = f_NE + feq[NE]; + // f[SW] = f_NE + feq[SW]; + // f[SE] = f_SE + feq[SE]; + // f[NW] = f_SE + feq[NW]; + // f[TE] = f_TE + feq[TE]; + // f[BW] = f_TE + feq[BW]; + // f[BE] = f_BE + feq[BE]; + // f[TW] = f_BE + feq[TW]; + // f[TN] = f_TN + feq[TN]; + // f[BS] = f_TN + feq[BS]; + // f[BN] = f_BN + feq[BN]; + // f[TS] = f_BN + feq[TS]; + // f[TNE] = f_TNE + feq[TNE]; + // f[TNW] = f_TNW + feq[TNW]; + // f[TSE] = f_TSE + feq[TSE]; + // f[TSW] = f_TSW + feq[TSW]; + // f[BNE] = f_TSW + feq[BNE]; + // f[BNW] = f_TSE + feq[BNW]; + // f[BSE] = f_TNW + feq[BSE]; + // f[BSW] = f_TNE + feq[BSW]; + // f[ZERO] = f_ZERO + feq[ZERO]; + + calcFeqsFct(f, rho, vx1, vx2, vx3); + + distributions->setDistribution(f, ix1, ix2, ix3); + distributions->setDistributionInv(f, ix1, ix2, ix3); + dynamicPointerCast<InitDensityLBMKernel>(kernel)->setVelocity(ix1, ix2, ix3, vx1, vx2, vx3); + } + } } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.h index bb059fc11..1f40abade 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsFromFileBlockVisitor.h @@ -12,16 +12,14 @@ class Block3D; class InitDistributionsFromFileBlockVisitor : public Block3DVisitor { public: - InitDistributionsFromFileBlockVisitor(/*LBMReal nu, */LBMReal rho, std::string file); + InitDistributionsFromFileBlockVisitor(/*LBMReal nu, */ LBMReal rho, std::string file); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - CbArray4D<LBMReal, IndexerX4X3X2X1> matrix; - enum Velocity { Vx1, Vx2, Vx3 }; -// LBMReal nu; - LBMReal rho; + CbArray4D<LBMReal, IndexerX4X3X2X1> matrix; + enum Velocity { Vx1, Vx2, Vx3 }; + // LBMReal nu; + LBMReal rho; }; #endif // InitDistributionsFromFileBlockVisitor_h__ - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.cpp index 279714e35..343353c7b 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.cpp @@ -2,608 +2,623 @@ #include "mpi.h" -#include <basics/utilities/UbFileInputASCII.h> -#include "LBMKernel.h" #include "BCProcessor.h" -#include "Grid3DSystem.h" -#include <CbArray2D.h> +#include "Block3D.h" #include "D3Q27EsoTwist3DSplittedVector.h" -#include "InterpolationProcessor.h" #include "DataSet3D.h" #include "Grid3D.h" -#include "Block3D.h" +#include "Grid3DSystem.h" +#include "InterpolationProcessor.h" +#include "LBMKernel.h" +#include <CbArray2D.h> +#include <basics/utilities/UbFileInputASCII.h> using namespace std; -InitDistributionsWithInterpolationGridVisitor::InitDistributionsWithInterpolationGridVisitor(SPtr<Grid3D> oldGrid, InterpolationProcessorPtr iProcessor, LBMReal nu) - : oldGrid(oldGrid), iProcessor(iProcessor), nu(nu) +InitDistributionsWithInterpolationGridVisitor::InitDistributionsWithInterpolationGridVisitor( + SPtr<Grid3D> oldGrid, InterpolationProcessorPtr iProcessor, LBMReal nu) + : oldGrid(oldGrid), iProcessor(iProcessor), nu(nu) { - } ////////////////////////////////////////////////////////////////////////// -InitDistributionsWithInterpolationGridVisitor::~InitDistributionsWithInterpolationGridVisitor() -= default; +InitDistributionsWithInterpolationGridVisitor::~InitDistributionsWithInterpolationGridVisitor() = default; ////////////////////////////////////////////////////////////////////////// void InitDistributionsWithInterpolationGridVisitor::visit(SPtr<Grid3D> grid) { - newGrid = grid; - int minInitLevel = newGrid->getCoarsestInitializedLevel(); - int maxInitLevel = newGrid->getFinestInitializedLevel(); - int newGridRank = newGrid->getRank(); - - for (int l = minInitLevel; l<=maxInitLevel; l++) - { -// int n = 0; - vector<SPtr<Block3D>> blockVector; - newGrid->getBlocks(l, blockVector); - vector<SPtr<Block3D>> tBlockID; - - for(SPtr<Block3D> newBlock : blockVector) - { - if (!newBlock) - UB_THROW(UbException(UB_EXARGS, "block is not exist")); - - int newBlockRank = newBlock->getRank(); -// int newBlockLevel = newBlock->getLevel(); - - SPtr<Block3D> oldBlock = oldGrid->getBlock(newBlock->getX1(), newBlock->getX2(), newBlock->getX3(), newBlock->getLevel()); - if (oldBlock) - { - int oldBlockRank = oldBlock->getRank(); - if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && newBlock->isActive()) - { - copyLocalBlock(oldBlock, newBlock); - } - else - { - copyRemoteBlock(oldBlock, newBlock); - } - } - else - { - int newlevel = newBlock->getLevel(); - Vector3D coords = newGrid->getNodeCoordinates(newBlock, 1, 1, 1); - - UbTupleInt3 oldGridBlockIndexes = oldGrid->getBlockIndexes(coords[0], coords[1], coords[2], newlevel-1); - oldBlock = oldGrid->getBlock(val<1>(oldGridBlockIndexes), val<2>(oldGridBlockIndexes), val<3>(oldGridBlockIndexes), newlevel-1); - - if (oldBlock) - { - int oldBlockRank = oldBlock->getRank(); -// int oldBlockLevel = oldBlock->getLevel(); - - if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && newBlock->isActive()) - { - interpolateLocalBlockCoarseToFine(oldBlock, newBlock); - } - else - { - interpolateRemoteBlockCoarseToFine(oldBlock, newBlock); - } + newGrid = grid; + int minInitLevel = newGrid->getCoarsestInitializedLevel(); + int maxInitLevel = newGrid->getFinestInitializedLevel(); + int newGridRank = newGrid->getRank(); + + for (int l = minInitLevel; l <= maxInitLevel; l++) { + // int n = 0; + vector<SPtr<Block3D>> blockVector; + newGrid->getBlocks(l, blockVector); + vector<SPtr<Block3D>> tBlockID; + + for (SPtr<Block3D> newBlock : blockVector) { + if (!newBlock) + UB_THROW(UbException(UB_EXARGS, "block is not exist")); + + int newBlockRank = newBlock->getRank(); + // int newBlockLevel = newBlock->getLevel(); + + SPtr<Block3D> oldBlock = + oldGrid->getBlock(newBlock->getX1(), newBlock->getX2(), newBlock->getX3(), newBlock->getLevel()); + if (oldBlock) { + int oldBlockRank = oldBlock->getRank(); + if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && + newBlock->isActive()) { + copyLocalBlock(oldBlock, newBlock); + } else { + copyRemoteBlock(oldBlock, newBlock); + } + } else { + int newlevel = newBlock->getLevel(); + Vector3D coords = newGrid->getNodeCoordinates(newBlock, 1, 1, 1); + + UbTupleInt3 oldGridBlockIndexes = + oldGrid->getBlockIndexes(coords[0], coords[1], coords[2], newlevel - 1); + oldBlock = oldGrid->getBlock(val<1>(oldGridBlockIndexes), val<2>(oldGridBlockIndexes), + val<3>(oldGridBlockIndexes), newlevel - 1); + + if (oldBlock) { + int oldBlockRank = oldBlock->getRank(); + // int oldBlockLevel = oldBlock->getLevel(); + + if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && + newBlock->isActive()) { + interpolateLocalBlockCoarseToFine(oldBlock, newBlock); + } else { + interpolateRemoteBlockCoarseToFine(oldBlock, newBlock); + } + } else { + oldGridBlockIndexes = oldGrid->getBlockIndexes(coords[0], coords[1], coords[2], newlevel + 1); + oldBlock = oldGrid->getBlock(val<1>(oldGridBlockIndexes), val<2>(oldGridBlockIndexes), + val<3>(oldGridBlockIndexes), newlevel + 1); + if (oldBlock) { + int oldBlockRank = oldBlock->getRank(); + // int oldBlockLevel = oldBlock->getLevel(); + + if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && + newBlock->isActive()) { + interpolateLocalBlockFineToCoarse(oldBlock, newBlock); + } else { + interpolateRemoteBlockFineToCoarse(oldBlock, newBlock); + } + } + } } - else - { - oldGridBlockIndexes = oldGrid->getBlockIndexes(coords[0], coords[1], coords[2], newlevel+1); - oldBlock = oldGrid->getBlock(val<1>(oldGridBlockIndexes), val<2>(oldGridBlockIndexes), val<3>(oldGridBlockIndexes), newlevel+1); - if (oldBlock) - { - int oldBlockRank = oldBlock->getRank(); -// int oldBlockLevel = oldBlock->getLevel(); - - if (oldBlockRank == newBlockRank && oldBlock->isActive() && newBlockRank == newGridRank && newBlock->isActive()) - { - interpolateLocalBlockFineToCoarse(oldBlock, newBlock); - } - else - { - interpolateRemoteBlockFineToCoarse(oldBlock, newBlock); - } - } - } - } - } - } + } + } } ////////////////////////////////////////////////////////////////////////// void InitDistributionsWithInterpolationGridVisitor::copyLocalBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) { - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+oldBlock->toString()); - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - SPtr<ILBMKernel> kernel = newBlock->getKernel(); - if (!kernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()); - kernel->getDataSet()->setFdistributions(oldDistributions); + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + oldBlock->toString()); + SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + SPtr<ILBMKernel> kernel = newBlock->getKernel(); + if (!kernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString()); + kernel->getDataSet()->setFdistributions(oldDistributions); } ////////////////////////////////////////////////////////////////////////// void InitDistributionsWithInterpolationGridVisitor::copyRemoteBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) { - int newGridRank = newGrid->getRank(); - int oldBlockRank = oldBlock->getRank(); - int newBlockRank = newBlock->getRank(); - - if (oldBlockRank == newGridRank && oldBlock->isActive()) - { - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+oldBlock->toString()); - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); - - MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - } - else if (newBlockRank == newGridRank && newBlock->isActive()) - { - SPtr<ILBMKernel> newKernel = newBlock->getKernel(); - if (!newKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()+UbSystem::toString(newGridRank)); - - SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getZeroDistributions(); - - MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - } + int newGridRank = newGrid->getRank(); + int oldBlockRank = oldBlock->getRank(); + int newBlockRank = newBlock->getRank(); + + if (oldBlockRank == newGridRank && oldBlock->isActive()) { + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + oldBlock->toString()); + SPtr<EsoTwist3D> oldDistributions = + dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); + + MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + } else if (newBlockRank == newGridRank && newBlock->isActive()) { + SPtr<ILBMKernel> newKernel = newBlock->getKernel(); + if (!newKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString() + + UbSystem::toString(newGridRank)); + + SPtr<EsoTwist3D> newDistributions = + dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(newDistributions)->getZeroDistributions(); + + MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + } } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsWithInterpolationGridVisitor::interpolateLocalBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) +void InitDistributionsWithInterpolationGridVisitor::interpolateLocalBlockCoarseToFine(SPtr<Block3D> oldBlock, + SPtr<Block3D> newBlock) { - D3Q27ICell icellC; - D3Q27ICell icellF; - LBMReal xoff, yoff, zoff; - - LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); - LBMReal omegaF =LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); - - iProcessor->setOmegas(omegaC, omegaF); - - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in old block: "+oldBlock->toString()); - - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); - - SPtr<ILBMKernel> newKernel = newBlock->getKernel(); - if (!newKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()); - - SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)newDistributions->getNX1()-1; - int maxX2 = (int)newDistributions->getNX2()-1; - int maxX3 = (int)newDistributions->getNX3()-1; - - int bMaxX1 = (int)newDistributions->getNX1(); - int bMaxX2 = (int)newDistributions->getNX2(); - int bMaxX3 = (int)newDistributions->getNX3(); - - for (int ix3 = minX3; ix3 < maxX3; ix3+=2) - for (int ix2 = minX2; ix2 < maxX2; ix2+=2) - for (int ix1 = minX1; ix1 < maxX1; ix1+=2) - { - Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); - UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); - int howManySolids= iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - - if (howManySolids == 0 || howManySolids == 8) - { - iProcessor->readICell(oldDistributions, icellC, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - iProcessor->interpolateCoarseToFine(icellC, icellF); - } - else - { - if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellC, bMaxX1, bMaxX2, bMaxX3, - val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin), xoff, yoff, zoff)) - { - //std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - //UB_THROW(UbException(UB_EXARGS, err)); - iProcessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); - } - else - { - for (int i=0; i<27; i++) - { - icellF.BSW[i]=0.0; - icellF.BSE[i]=0.0; - icellF.BNW[i]=0.0; - icellF.BNE[i]=0.0; - icellF.TSW[i]=0.0; - icellF.TSE[i]=0.0; - icellF.TNW[i]=0.0; - icellF.TNE[i]=0.0; - } - // std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - ////UB_THROW(UbException(UB_EXARGS, err)); - // UBLOG(logINFO, err); - } + D3Q27ICell icellC; + D3Q27ICell icellF; + LBMReal xoff, yoff, zoff; + + LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); + LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); + + iProcessor->setOmegas(omegaC, omegaF); + + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in old block: " + oldBlock->toString()); + + SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); + + SPtr<ILBMKernel> newKernel = newBlock->getKernel(); + if (!newKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString()); + + SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)newDistributions->getNX1() - 1; + int maxX2 = (int)newDistributions->getNX2() - 1; + int maxX3 = (int)newDistributions->getNX3() - 1; + + int bMaxX1 = (int)newDistributions->getNX1(); + int bMaxX2 = (int)newDistributions->getNX2(); + int bMaxX3 = (int)newDistributions->getNX3(); + + for (int ix3 = minX3; ix3 < maxX3; ix3 += 2) + for (int ix2 = minX2; ix2 < maxX2; ix2 += 2) + for (int ix1 = minX1; ix1 < maxX1; ix1 += 2) { + Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); + UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); + int howManySolids = iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), + val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + + if (howManySolids == 0 || howManySolids == 8) { + iProcessor->readICell(oldDistributions, icellC, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin)); + iProcessor->interpolateCoarseToFine(icellC, icellF); + } else { + if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellC, bMaxX1, bMaxX2, bMaxX3, + val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin), xoff, yoff, zoff)) { + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + // UB_THROW(UbException(UB_EXARGS, err)); + iProcessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); + } else { + for (int i = 0; i < 27; i++) { + icellF.BSW[i] = 0.0; + icellF.BSE[i] = 0.0; + icellF.BNW[i] = 0.0; + icellF.BNE[i] = 0.0; + icellF.TSW[i] = 0.0; + icellF.TSE[i] = 0.0; + icellF.TNW[i] = 0.0; + icellF.TNE[i] = 0.0; + } + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + ////UB_THROW(UbException(UB_EXARGS, err)); + // UBLOG(logINFO, err); + } + } + + iProcessor->writeICell(newDistributions, icellF, ix1, ix2, ix3); + iProcessor->writeICellInv(newDistributions, icellF, ix1, ix2, ix3); } - - iProcessor->writeICell(newDistributions, icellF, ix1, ix2, ix3); - iProcessor->writeICellInv(newDistributions, icellF, ix1, ix2, ix3); - } } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsWithInterpolationGridVisitor::interpolateRemoteBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) +void InitDistributionsWithInterpolationGridVisitor::interpolateRemoteBlockCoarseToFine(SPtr<Block3D> oldBlock, + SPtr<Block3D> newBlock) { - int newGridRank = newGrid->getRank(); - int oldBlockRank = oldBlock->getRank(); - int newBlockRank = newBlock->getRank(); - - if (oldBlockRank == newGridRank) - { - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+oldBlock->toString()); - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); - - MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - - SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); - std::vector< int >& bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); - MPI_Send(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, newBlockRank, 0, MPI_COMM_WORLD); - } - else if (newBlockRank == newGridRank && newBlock->isActive()) - { - D3Q27ICell icellC; - D3Q27ICell icellF; - LBMReal xoff, yoff, zoff; - - LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); - LBMReal omegaF =LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); - - iProcessor->setOmegas(omegaC, omegaF); - - SPtr<ILBMKernel> newKernel = newBlock->getKernel(); - if (!newKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()); - - SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)newDistributions->getNX1()-1; - int maxX2 = (int)newDistributions->getNX2()-1; - int maxX3 = (int)newDistributions->getNX3()-1; - - int bMaxX1 = (int)newDistributions->getNX1(); - int bMaxX2 = (int)newDistributions->getNX2(); - int bMaxX3 = (int)newDistributions->getNX3(); - - SPtr<EsoTwist3D> oldDistributions(new D3Q27EsoTwist3DSplittedVector(bMaxX1, bMaxX2, bMaxX3, 0)); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); - - MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - - SPtr<BCArray3D> bcArrayOldBlock(new BCArray3D(bMaxX1, bMaxX2, bMaxX3, BCArray3D::FLUID)); - std::vector< int >& bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); - MPI_Recv(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - - for (int ix3 = minX3; ix3 < maxX3; ix3+=2) - for (int ix2 = minX2; ix2 < maxX2; ix2+=2) - for (int ix1 = minX1; ix1 < maxX1; ix1+=2) - { - Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); - UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); - - int howManySolids= iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - - if (howManySolids == 0 || howManySolids == 8) - { - iProcessor->readICell(oldDistributions, icellC, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - iProcessor->interpolateCoarseToFine(icellC, icellF); - } - else - { - if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellC, bMaxX1, bMaxX2, bMaxX3, - val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin), xoff, yoff, zoff)) - { - //std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - //UB_THROW(UbException(UB_EXARGS, err)); - iProcessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); - } - else - { - for (int i=0; i<27; i++) - { - icellF.BSW[i]=0.0; - icellF.BSE[i]=0.0; - icellF.BNW[i]=0.0; - icellF.BNE[i]=0.0; - icellF.TSW[i]=0.0; - icellF.TSE[i]=0.0; - icellF.TNW[i]=0.0; - icellF.TNE[i]=0.0; - } - // std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - ////UB_THROW(UbException(UB_EXARGS, err)); - // UBLOG(logINFO, err); - } - } - - - - iProcessor->writeICell(newDistributions, icellF, ix1, ix2, ix3); - iProcessor->writeICellInv(newDistributions, icellF, ix1, ix2, ix3); - } - } + int newGridRank = newGrid->getRank(); + int oldBlockRank = oldBlock->getRank(); + int newBlockRank = newBlock->getRank(); + + if (oldBlockRank == newGridRank) { + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + oldBlock->toString()); + SPtr<EsoTwist3D> oldDistributions = + dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); + + MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + + SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); + std::vector<int> &bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); + MPI_Send(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, newBlockRank, 0, MPI_COMM_WORLD); + } else if (newBlockRank == newGridRank && newBlock->isActive()) { + D3Q27ICell icellC; + D3Q27ICell icellF; + LBMReal xoff, yoff, zoff; + + LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); + LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); + + iProcessor->setOmegas(omegaC, omegaF); + + SPtr<ILBMKernel> newKernel = newBlock->getKernel(); + if (!newKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString()); + + SPtr<EsoTwist3D> newDistributions = + dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)newDistributions->getNX1() - 1; + int maxX2 = (int)newDistributions->getNX2() - 1; + int maxX3 = (int)newDistributions->getNX3() - 1; + + int bMaxX1 = (int)newDistributions->getNX1(); + int bMaxX2 = (int)newDistributions->getNX2(); + int bMaxX3 = (int)newDistributions->getNX3(); + + SPtr<EsoTwist3D> oldDistributions(new D3Q27EsoTwist3DSplittedVector(bMaxX1, bMaxX2, bMaxX3, 0)); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); + + MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + SPtr<BCArray3D> bcArrayOldBlock(new BCArray3D(bMaxX1, bMaxX2, bMaxX3, BCArray3D::FLUID)); + std::vector<int> &bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); + MPI_Recv(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + for (int ix3 = minX3; ix3 < maxX3; ix3 += 2) + for (int ix2 = minX2; ix2 < maxX2; ix2 += 2) + for (int ix1 = minX1; ix1 < maxX1; ix1 += 2) { + Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); + UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); + + int howManySolids = iProcessor->iCellHowManySolids( + bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + + if (howManySolids == 0 || howManySolids == 8) { + iProcessor->readICell(oldDistributions, icellC, val<1>(oldGridIndexMin), + val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + iProcessor->interpolateCoarseToFine(icellC, icellF); + } else { + if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellC, bMaxX1, bMaxX2, + bMaxX3, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin), xoff, yoff, zoff)) { + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + // UB_THROW(UbException(UB_EXARGS, err)); + iProcessor->interpolateCoarseToFine(icellC, icellF, xoff, yoff, zoff); + } else { + for (int i = 0; i < 27; i++) { + icellF.BSW[i] = 0.0; + icellF.BSE[i] = 0.0; + icellF.BNW[i] = 0.0; + icellF.BNE[i] = 0.0; + icellF.TSW[i] = 0.0; + icellF.TSE[i] = 0.0; + icellF.TNW[i] = 0.0; + icellF.TNE[i] = 0.0; + } + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + ////UB_THROW(UbException(UB_EXARGS, err)); + // UBLOG(logINFO, err); + } + } + + iProcessor->writeICell(newDistributions, icellF, ix1, ix2, ix3); + iProcessor->writeICellInv(newDistributions, icellF, ix1, ix2, ix3); + } + } } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsWithInterpolationGridVisitor::interpolateLocalBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) +void InitDistributionsWithInterpolationGridVisitor::interpolateLocalBlockFineToCoarse(SPtr<Block3D> oldBlock, + SPtr<Block3D> newBlock) { - LBMReal icellC[27]; - D3Q27ICell icellF; - LBMReal xoff, yoff, zoff; - - LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); - LBMReal omegaC =LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); - - iProcessor->setOmegas(omegaC, omegaF); - - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in old block: "+oldBlock->toString()); - - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); - - SPtr<ILBMKernel> newKernel = newBlock->getKernel(); - if (!newKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()); - - SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)newDistributions->getNX1()-1; - int maxX2 = (int)newDistributions->getNX2()-1; - int maxX3 = (int)newDistributions->getNX3()-1; - - int bMaxX1 = (int)newDistributions->getNX1(); - int bMaxX2 = (int)newDistributions->getNX2(); - int bMaxX3 = (int)newDistributions->getNX3(); - - for (int ix3 = minX3; ix3 < maxX3; ix3+=2) - for (int ix2 = minX2; ix2 < maxX2; ix2+=2) - for (int ix1 = minX1; ix1 < maxX1; ix1+=2) - { - Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); - UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); - - int howManySolids= iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - - if (howManySolids == 0 || howManySolids == 8) - { - iProcessor->readICell(oldDistributions, icellF, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - iProcessor->interpolateFineToCoarse(icellF, icellC); - } - else - { - if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellF, bMaxX1, bMaxX2, bMaxX3, - val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin), xoff, yoff, zoff)) - { - //std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - //UB_THROW(UbException(UB_EXARGS, err)); - iProcessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); - } - else - { - for (int i=0; i<27; i++) - { - icellF.BSW[i]=0.0; - icellF.BSE[i]=0.0; - icellF.BNW[i]=0.0; - icellF.BNE[i]=0.0; - icellF.TSW[i]=0.0; - icellF.TSE[i]=0.0; - icellF.TNW[i]=0.0; - icellF.TNE[i]=0.0; - } - // std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - ////UB_THROW(UbException(UB_EXARGS, err)); - // UBLOG(logINFO, err); - } + LBMReal icellC[27]; + D3Q27ICell icellF; + LBMReal xoff, yoff, zoff; + + LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); + LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); + + iProcessor->setOmegas(omegaC, omegaF); + + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in old block: " + oldBlock->toString()); + + SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); + + SPtr<ILBMKernel> newKernel = newBlock->getKernel(); + if (!newKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString()); + + SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)newDistributions->getNX1() - 1; + int maxX2 = (int)newDistributions->getNX2() - 1; + int maxX3 = (int)newDistributions->getNX3() - 1; + + int bMaxX1 = (int)newDistributions->getNX1(); + int bMaxX2 = (int)newDistributions->getNX2(); + int bMaxX3 = (int)newDistributions->getNX3(); + + for (int ix3 = minX3; ix3 < maxX3; ix3 += 2) + for (int ix2 = minX2; ix2 < maxX2; ix2 += 2) + for (int ix1 = minX1; ix1 < maxX1; ix1 += 2) { + Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); + UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); + + int howManySolids = iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), + val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + + if (howManySolids == 0 || howManySolids == 8) { + iProcessor->readICell(oldDistributions, icellF, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin)); + iProcessor->interpolateFineToCoarse(icellF, icellC); + } else { + if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellF, bMaxX1, bMaxX2, bMaxX3, + val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin), xoff, yoff, zoff)) { + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + // UB_THROW(UbException(UB_EXARGS, err)); + iProcessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); + } else { + for (int i = 0; i < 27; i++) { + icellF.BSW[i] = 0.0; + icellF.BSE[i] = 0.0; + icellF.BNW[i] = 0.0; + icellF.BNE[i] = 0.0; + icellF.TSW[i] = 0.0; + icellF.TSE[i] = 0.0; + icellF.TNW[i] = 0.0; + icellF.TNE[i] = 0.0; + } + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + ////UB_THROW(UbException(UB_EXARGS, err)); + // UBLOG(logINFO, err); + } + } + + iProcessor->writeINode(newDistributions, icellC, ix1, ix2, ix3); + // iProcessor->writeINodeInv(newDistributions, icellC, ix1, ix2, ix3); } - - iProcessor->writeINode(newDistributions, icellC, ix1, ix2, ix3); - //iProcessor->writeINodeInv(newDistributions, icellC, ix1, ix2, ix3); - } } ////////////////////////////////////////////////////////////////////////// -void InitDistributionsWithInterpolationGridVisitor::interpolateRemoteBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock) +void InitDistributionsWithInterpolationGridVisitor::interpolateRemoteBlockFineToCoarse(SPtr<Block3D> oldBlock, + SPtr<Block3D> newBlock) { - int newGridRank = newGrid->getRank(); - int oldBlockRank = oldBlock->getRank(); - int newBlockRank = newBlock->getRank(); - - if (oldBlockRank == newGridRank) - { - SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); - if (!oldKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: "+oldBlock->toString()); - SPtr<EsoTwist3D> oldDistributions = dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); - - MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); - - SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); - std::vector< int >& bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); - MPI_Send(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, newBlockRank, 0, MPI_COMM_WORLD); - } - else if (newBlockRank == newGridRank && newBlock->isActive()) - { - LBMReal icellC[27]; - D3Q27ICell icellF; - LBMReal xoff, yoff, zoff; - - LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); - LBMReal omegaC =LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); - - iProcessor->setOmegas(omegaC, omegaF); - - SPtr<ILBMKernel> newKernel = newBlock->getKernel(); - if (!newKernel) - throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: "+newBlock->toString()); - - SPtr<EsoTwist3D> newDistributions = dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); - - int minX1 = 0; - int minX2 = 0; - int minX3 = 0; - - int maxX1 = (int)newDistributions->getNX1()-1; - int maxX2 = (int)newDistributions->getNX2()-1; - int maxX3 = (int)newDistributions->getNX3()-1; - - int bMaxX1 = (int)newDistributions->getNX1(); - int bMaxX2 = (int)newDistributions->getNX2(); - int bMaxX3 = (int)newDistributions->getNX3(); - - SPtr<EsoTwist3D> oldDistributions(new D3Q27EsoTwist3DSplittedVector(bMaxX1, bMaxX2, bMaxX3, 0)); - - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); - CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); - CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); - - MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - - SPtr<BCArray3D> bcArrayOldBlock(new BCArray3D(bMaxX1, bMaxX2, bMaxX3, BCArray3D::FLUID)); - std::vector< int >& bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); - MPI_Recv(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, oldBlockRank, 0, MPI_COMM_WORLD, MPI_STATUS_IGNORE); - - for (int ix3 = minX3; ix3 < maxX3; ix3+=2) - for (int ix2 = minX2; ix2 < maxX2; ix2+=2) - for (int ix1 = minX1; ix1 < maxX1; ix1+=2) - { - Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); - UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); - - int howManySolids= iProcessor->iCellHowManySolids(bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - - if (howManySolids == 0 || howManySolids == 8) - { - iProcessor->readICell(oldDistributions, icellF, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); - iProcessor->interpolateFineToCoarse(icellF, icellC); - } - else - { - if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellF, bMaxX1, bMaxX2, bMaxX3, - val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin), xoff, yoff, zoff)) - { - //std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - //UB_THROW(UbException(UB_EXARGS, err)); - iProcessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); - } - else - { - for (int i=0; i<27; i++) - { - icellF.BSW[i]=0.0; - icellF.BSE[i]=0.0; - icellF.BNW[i]=0.0; - icellF.BNE[i]=0.0; - icellF.TSW[i]=0.0; - icellF.TSE[i]=0.0; - icellF.TNW[i]=0.0; - icellF.TNE[i]=0.0; - } - // std::string err = "For "+oldBlock->toString()+ - // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ - // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ - // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ - // " interpolation is not implemented for other direction"+ - // " by using in: "+(std::string)typeid(*this).name()+ - // " or maybe you have a solid on the block boundary"; - ////UB_THROW(UbException(UB_EXARGS, err)); - // UBLOG(logINFO, err); - } - } - - iProcessor->writeINode(newDistributions, icellC, ix1, ix2, ix3); - //iProcessor->writeINodeInv(newDistributions, icellC, ix1, ix2, ix3); - } - } + int newGridRank = newGrid->getRank(); + int oldBlockRank = oldBlock->getRank(); + int newBlockRank = newBlock->getRank(); + + if (oldBlockRank == newGridRank) { + SPtr<ILBMKernel> oldKernel = oldBlock->getKernel(); + if (!oldKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in block: " + oldBlock->toString()); + SPtr<EsoTwist3D> oldDistributions = + dynamicPointerCast<EsoTwist3D>(oldKernel->getDataSet()->getFdistributions()); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); + + MPI_Send(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + MPI_Send(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, newBlockRank, 0, MPI_COMM_WORLD); + + SPtr<BCArray3D> bcArrayOldBlock = oldBlock->getKernel()->getBCProcessor()->getBCArray(); + std::vector<int> &bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); + MPI_Send(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, newBlockRank, 0, MPI_COMM_WORLD); + } else if (newBlockRank == newGridRank && newBlock->isActive()) { + LBMReal icellC[27]; + D3Q27ICell icellF; + LBMReal xoff, yoff, zoff; + + LBMReal omegaF = LBMSystem::calcCollisionFactor(nu, oldBlock->getLevel()); + LBMReal omegaC = LBMSystem::calcCollisionFactor(nu, newBlock->getLevel()); + + iProcessor->setOmegas(omegaC, omegaF); + + SPtr<ILBMKernel> newKernel = newBlock->getKernel(); + if (!newKernel) + throw UbException(UB_EXARGS, "The LBM kernel isn't exist in new block: " + newBlock->toString()); + + SPtr<EsoTwist3D> newDistributions = + dynamicPointerCast<EsoTwist3D>(newKernel->getDataSet()->getFdistributions()); + + int minX1 = 0; + int minX2 = 0; + int minX3 = 0; + + int maxX1 = (int)newDistributions->getNX1() - 1; + int maxX2 = (int)newDistributions->getNX2() - 1; + int maxX3 = (int)newDistributions->getNX3() - 1; + + int bMaxX1 = (int)newDistributions->getNX1(); + int bMaxX2 = (int)newDistributions->getNX2(); + int bMaxX3 = (int)newDistributions->getNX3(); + + SPtr<EsoTwist3D> oldDistributions(new D3Q27EsoTwist3DSplittedVector(bMaxX1, bMaxX2, bMaxX3, 0)); + + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr localDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getLocalDistributions(); + CbArray4D<LBMReal, IndexerX4X3X2X1>::CbArray4DPtr nonLocalDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getNonLocalDistributions(); + CbArray3D<LBMReal, IndexerX3X2X1>::CbArray3DPtr zeroDistributions = + dynamicPointerCast<D3Q27EsoTwist3DSplittedVector>(oldDistributions)->getZeroDistributions(); + + MPI_Recv(localDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)localDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(nonLocalDistributions->getStartAdressOfSortedArray(0, 0, 0, 0), + (int)nonLocalDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + MPI_Recv(zeroDistributions->getStartAdressOfSortedArray(0, 0, 0), + (int)zeroDistributions->getDataVector().size(), MPI_DOUBLE, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + SPtr<BCArray3D> bcArrayOldBlock(new BCArray3D(bMaxX1, bMaxX2, bMaxX3, BCArray3D::FLUID)); + std::vector<int> &bcDataVector = bcArrayOldBlock->getBcindexmatrixDataVector(); + MPI_Recv(&bcDataVector[0], (int)bcDataVector.size(), MPI_INT, oldBlockRank, 0, MPI_COMM_WORLD, + MPI_STATUS_IGNORE); + + for (int ix3 = minX3; ix3 < maxX3; ix3 += 2) + for (int ix2 = minX2; ix2 < maxX2; ix2 += 2) + for (int ix1 = minX1; ix1 < maxX1; ix1 += 2) { + Vector3D coords = newGrid->getNodeCoordinates(newBlock, ix1, ix2, ix3); + UbTupleInt3 oldGridIndexMin = oldGrid->getNodeIndexes(oldBlock, coords[0], coords[1], coords[2]); + + int howManySolids = iProcessor->iCellHowManySolids( + bcArrayOldBlock, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + + if (howManySolids == 0 || howManySolids == 8) { + iProcessor->readICell(oldDistributions, icellF, val<1>(oldGridIndexMin), + val<2>(oldGridIndexMin), val<3>(oldGridIndexMin)); + iProcessor->interpolateFineToCoarse(icellF, icellC); + } else { + if (iProcessor->findNeighborICell(bcArrayOldBlock, oldDistributions, icellF, bMaxX1, bMaxX2, + bMaxX3, val<1>(oldGridIndexMin), val<2>(oldGridIndexMin), + val<3>(oldGridIndexMin), xoff, yoff, zoff)) { + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + // UB_THROW(UbException(UB_EXARGS, err)); + iProcessor->interpolateFineToCoarse(icellF, icellC, xoff, yoff, zoff); + } else { + for (int i = 0; i < 27; i++) { + icellF.BSW[i] = 0.0; + icellF.BSE[i] = 0.0; + icellF.BNW[i] = 0.0; + icellF.BNE[i] = 0.0; + icellF.TSW[i] = 0.0; + icellF.TSE[i] = 0.0; + icellF.TNW[i] = 0.0; + icellF.TNE[i] = 0.0; + } + // std::string err = "For "+oldBlock->toString()+ + // " x1="+UbSystem::toString(val<1>(oldGridIndexMin))+ + // ", x2=" + UbSystem::toString(val<2>(oldGridIndexMin))+ + // ", x3=" + UbSystem::toString(val<3>(oldGridIndexMin))+ + // " interpolation is not implemented for other direction"+ + // " by using in: "+(std::string)typeid(*this).name()+ + // " or maybe you have a solid on the block boundary"; + ////UB_THROW(UbException(UB_EXARGS, err)); + // UBLOG(logINFO, err); + } + } + + iProcessor->writeINode(newDistributions, icellC, ix1, ix2, ix3); + // iProcessor->writeINodeInv(newDistributions, icellC, ix1, ix2, ix3); + } + } } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.h index bdc373e14..207656e1f 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/InitDistributionsWithInterpolationGridVisitor.h @@ -13,22 +13,24 @@ class InterpolationProcessor; class InitDistributionsWithInterpolationGridVisitor : public Grid3DVisitor { public: - InitDistributionsWithInterpolationGridVisitor(SPtr<Grid3D> oldGrid, SPtr<InterpolationProcessor> iProcessor, LBMReal nu); - ~InitDistributionsWithInterpolationGridVisitor() override; - void visit(SPtr<Grid3D> grid) override; + InitDistributionsWithInterpolationGridVisitor(SPtr<Grid3D> oldGrid, SPtr<InterpolationProcessor> iProcessor, + LBMReal nu); + ~InitDistributionsWithInterpolationGridVisitor() override; + void visit(SPtr<Grid3D> grid) override; + private: - void copyLocalBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - void copyRemoteBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - void interpolateLocalBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - void interpolateRemoteBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - void interpolateLocalBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - void interpolateRemoteBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); - - SPtr<Grid3D> newGrid; - SPtr<Grid3D> oldGrid; - LBMReal nu; - - SPtr<InterpolationProcessor> iProcessor; + void copyLocalBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + void copyRemoteBlock(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + void interpolateLocalBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + void interpolateRemoteBlockCoarseToFine(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + void interpolateLocalBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + void interpolateRemoteBlockFineToCoarse(SPtr<Block3D> oldBlock, SPtr<Block3D> newBlock); + + SPtr<Grid3D> newGrid; + SPtr<Grid3D> oldGrid; + LBMReal nu; + + SPtr<InterpolationProcessor> iProcessor; }; #endif // InitDistributionsWithVelocityProfileBlockVisitor_h__ diff --git a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp index 23f3260e9..7b516fc75 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.cpp @@ -1,28 +1,24 @@ #if defined VF_METIS && defined VF_MPI #include "MetisPartitioningGridVisitor.h" -#include <cmath> #include "Block3D.h" -#include "Grid3D.h" #include "Communicator.h" #include "D3Q27System.h" +#include "Grid3D.h" +#include <cmath> using namespace std; -MetisPartitioningGridVisitor::MetisPartitioningGridVisitor(SPtr<Communicator> comm, GraphType graphType, int numOfDirs, MetisPartitioner::PartType partType, bool threads, int numberOfThreads) - : Grid3DVisitor(), - numberOfThreads(numberOfThreads), - numOfDirs(numOfDirs), - comm(comm), - threads(threads), - graphType(graphType), - partType(partType) -{ - numberOfProcesses = comm->getNumberOfProcesses(); +MetisPartitioningGridVisitor::MetisPartitioningGridVisitor(SPtr<Communicator> comm, GraphType graphType, int numOfDirs, + MetisPartitioner::PartType partType, bool threads, + int numberOfThreads) + : Grid3DVisitor(), numberOfThreads(numberOfThreads), numOfDirs(numOfDirs), comm(comm), threads(threads), + graphType(graphType), partType(partType) +{ + numberOfProcesses = comm->getNumberOfProcesses(); } ////////////////////////////////////////////////////////////////////////// -MetisPartitioningGridVisitor::~MetisPartitioningGridVisitor() -= default; +MetisPartitioningGridVisitor::~MetisPartitioningGridVisitor() = default; ////////////////////////////////////////////////////////////////////////// void MetisPartitioningGridVisitor::visit(SPtr<Grid3D> grid) { @@ -30,11 +26,10 @@ void MetisPartitioningGridVisitor::visit(SPtr<Grid3D> grid) this->clear(); - bundleRoot = comm->getBundleRoot(); - bundleID = comm->getBundleID(); + bundleRoot = comm->getBundleRoot(); + bundleID = comm->getBundleID(); numberOfBundles = comm->getNumberOfBundles(); - if (numberOfBundles > 1) - { + if (numberOfBundles > 1) { if (bundleRoot == bundleID && processRoot == processID) collectData(grid, numberOfBundles, BUNDLE); comm->broadcast(blockID); @@ -44,32 +39,27 @@ void MetisPartitioningGridVisitor::visit(SPtr<Grid3D> grid) } processRoot = comm->getProcessRoot(); - processID = comm->getProcessID(); + processID = comm->getProcessID(); /*int numberOfProcesses = comm->getNumberOfProcesses();*/ - if (numberOfProcesses > 1) - { - int temp = bundleID; - for (int i = 0; i < numberOfBundles; i++) - { - if (bundleRoot == bundleID && processRoot == processID) - { - bundleID = i; - //numberOfProcesses = comm->getNumberOfProcessesInBundle(i); - collectData(grid, numberOfProcesses, PROCESS); - bundleID = temp; - } - comm->broadcast(blockID); - //UBLOG(logINFO, "blockID="<<blockID.size()); - comm->broadcast(parts); - //UBLOG(logINFO, "parts="<<parts.size()); - distributePartitionData(grid, PROCESS); - } + if (numberOfProcesses > 1) { + int temp = bundleID; + for (int i = 0; i < numberOfBundles; i++) { + if (bundleRoot == bundleID && processRoot == processID) { + bundleID = i; + // numberOfProcesses = comm->getNumberOfProcessesInBundle(i); + collectData(grid, numberOfProcesses, PROCESS); + bundleID = temp; + } + comm->broadcast(blockID); + // UBLOG(logINFO, "blockID="<<blockID.size()); + comm->broadcast(parts); + // UBLOG(logINFO, "parts="<<parts.size()); + distributePartitionData(grid, PROCESS); + } } - if (threads) - { - if (numberOfThreads > 1) - { + if (threads) { + if (numberOfThreads > 1) { collectData(grid, numberOfThreads, THREAD); distributePartitionData(grid, THREAD); } @@ -81,14 +71,13 @@ void MetisPartitioningGridVisitor::collectData(SPtr<Grid3D> grid, int nofSegment { clear(); - switch (graphType) - { - case LevelIntersected: - buildMetisGraphLevelIntersected(grid, nofSegments, level); - break; - case LevelBased: - buildMetisGraphLevelBased(grid, nofSegments, level); - break; + switch (graphType) { + case LevelIntersected: + buildMetisGraphLevelIntersected(grid, nofSegments, level); + break; + case LevelBased: + buildMetisGraphLevelBased(grid, nofSegments, level); + break; } } ////////////////////////////////////////////////////////////////////////// @@ -96,30 +85,24 @@ void MetisPartitioningGridVisitor::distributePartitionData(SPtr<Grid3D> grid, Pa { SPtr<Block3D> block; - for(size_t p=0; p<parts.size(); p++) - { + for (size_t p = 0; p < parts.size(); p++) { block = grid->getBlock(blockID[p]); - if (block) - { - switch (level) - { - case BUNDLE: - block->setBundle(parts[p]); - break; - case PROCESS: - if (numberOfBundles == 1) - { - block->setRank(parts[p]); - } - else - { - block->setLocalRank(parts[p]); - block->setRank(comm->getProcessID(block->getBundle(),parts[p])); - } - break; - case THREAD: - block->setPart(parts[p]); - break; + if (block) { + switch (level) { + case BUNDLE: + block->setBundle(parts[p]); + break; + case PROCESS: + if (numberOfBundles == 1) { + block->setRank(parts[p]); + } else { + block->setLocalRank(parts[p]); + block->setRank(comm->getProcessID(block->getBundle(), parts[p])); + } + break; + case THREAD: + block->setPart(parts[p]); + break; } } } @@ -127,16 +110,14 @@ void MetisPartitioningGridVisitor::distributePartitionData(SPtr<Grid3D> grid, Pa ////////////////////////////////////////////////////////////////////////// void MetisPartitioningGridVisitor::buildMetisGraphLevelIntersected(SPtr<Grid3D> grid, int nofSegments, PartLevel level) { - int edges = 0; - const int edgeWeight= 1; + int edges = 0; + const int edgeWeight = 1; const int edgeWeightChildFactor = 8; - int n = 0; + int n = 0; - for(Grid3D::BlockIDMap::value_type b : grid->getBlockIDs()) - { + for (Grid3D::BlockIDMap::value_type b : grid->getBlockIDs()) { SPtr<Block3D> block = b.second; - if (this->getPartitionCondition(block, level)) - { + if (this->getPartitionCondition(block, level)) { block->setLocalID(n); blockID.push_back(block->getGlobalID()); n++; @@ -145,22 +126,17 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelIntersected(SPtr<Grid3D> MetisPartitioner metis; - for(Grid3D::BlockIDMap::value_type b : grid->getBlockIDs()) - { + for (Grid3D::BlockIDMap::value_type b : grid->getBlockIDs()) { const SPtr<Block3D> block = b.second; - if (this->getPartitionCondition(block, level)) - { - metis.xadj.push_back(edges); - //the weights of the vertices are 2^level of grid (1, 2, 4, 8 .....) 1<<level - metis.vwgt.push_back((idx_t)(1<<block->getLevel())); + if (this->getPartitionCondition(block, level)) { + metis.xadj.push_back(edges); + // the weights of the vertices are 2^level of grid (1, 2, 4, 8 .....) 1<<level + metis.vwgt.push_back((idx_t)(1 << block->getLevel())); - for( int dir = 0; dir <= numOfDirs; dir++) - { + for (int dir = 0; dir <= numOfDirs; dir++) { SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, block); - if(neighBlock) - { - if (this->getPartitionCondition(neighBlock, level)) - { + if (neighBlock) { + if (this->getPartitionCondition(neighBlock, level)) { edges++; metis.adjwgt.push_back(edgeWeight); metis.adjncy.push_back(neighBlock->getLocalID()); @@ -169,14 +145,11 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelIntersected(SPtr<Grid3D> } vector<SPtr<Block3D>> subBlocks; grid->getSubBlocks(block, 1, subBlocks); - for(SPtr<Block3D> subBlock : subBlocks) - { - if (subBlock) - { - if (this->getPartitionCondition(subBlock, level)) - { + for (SPtr<Block3D> subBlock : subBlocks) { + if (subBlock) { + if (this->getPartitionCondition(subBlock, level)) { edges++; - metis.adjwgt.push_back(edgeWeight*edgeWeightChildFactor); + metis.adjwgt.push_back(edgeWeight * edgeWeightChildFactor); metis.adjncy.push_back(subBlock->getLocalID()); } } @@ -185,10 +158,11 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelIntersected(SPtr<Grid3D> } metis.xadj.push_back(static_cast<idx_t>(metis.adjncy.size())); - if ((metis.adjncy.size()%2)!=0) - throw UbException(UB_EXARGS,"number of edges is odd - probable adjncy-vector doesn't contain all pairs (A->B) and (B->A)!!!" ); + if ((metis.adjncy.size() % 2) != 0) + throw UbException( + UB_EXARGS, + "number of edges is odd - probable adjncy-vector doesn't contain all pairs (A->B) and (B->A)!!!"); - metis.partition(nofSegments, partType); parts = metis.part; } @@ -198,17 +172,14 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelBased(SPtr<Grid3D> grid, int minInitLevel = grid->getCoarsestInitializedLevel(); int maxInitLevel = grid->getFinestInitializedLevel(); - for(int l = minInitLevel; l<=maxInitLevel;l++) - { + for (int l = minInitLevel; l <= maxInitLevel; l++) { int n = 0; vector<SPtr<Block3D>> blockVector; grid->getBlocks(l, blockVector); vector<SPtr<Block3D>> tBlockID; - for(SPtr<Block3D> block : blockVector) - { - if (this->getPartitionCondition(block, level)) - { + for (SPtr<Block3D> block : blockVector) { + if (this->getPartitionCondition(block, level)) { block->setLocalID(n); blockID.push_back(block->getGlobalID()); tBlockID.push_back(block); @@ -216,28 +187,23 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelBased(SPtr<Grid3D> grid, } } - if (tBlockID.size() == 0) - { - UB_THROW(UbException(UB_EXARGS,"Blocks for decomposition don't exist!")); + if (tBlockID.size() == 0) { + UB_THROW(UbException(UB_EXARGS, "Blocks for decomposition don't exist!")); } MetisPartitioner metis; const int vertexWeight = 1; - int edges = 0; + int edges = 0; - for(SPtr<Block3D> block : tBlockID) - { + for (SPtr<Block3D> block : tBlockID) { metis.xadj.push_back(edges); metis.vwgt.push_back(vertexWeight); - for( int dir = 0; dir <= numOfDirs; dir++) - { + for (int dir = 0; dir <= numOfDirs; dir++) { SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, block); - if(neighBlock) - { - if (this->getPartitionCondition(neighBlock, level)) - { + if (neighBlock) { + if (this->getPartitionCondition(neighBlock, level)) { edges++; metis.adjwgt.push_back(getEdgeWeight(dir)); metis.adjncy.push_back(neighBlock->getLocalID()); @@ -246,19 +212,19 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelBased(SPtr<Grid3D> grid, } } metis.xadj.push_back(static_cast<idx_t>(metis.adjncy.size())); - if ((metis.adjncy.size()%2)!=0) - throw UbException(UB_EXARGS,"number of edges is odd - probable adjncy-vector doesn't contain all pairs (A->B) and (B->A)!!!" ); + if ((metis.adjncy.size() % 2) != 0) + throw UbException( + UB_EXARGS, + "number of edges is odd - probable adjncy-vector doesn't contain all pairs (A->B) and (B->A)!!!"); - int nofBlocks = grid->getNumberOfBlocks(l); + int nofBlocks = grid->getNumberOfBlocks(l); int tnofSegments = nofSegments; - if (nofBlocks < nofSegments) - { - tnofSegments = nofBlocks; + if (nofBlocks < nofSegments) { + tnofSegments = nofBlocks; } metis.partition(tnofSegments, partType); - for(idx_t p : metis.part) - { + for (idx_t p : metis.part) { parts.push_back(p); } } @@ -266,23 +232,16 @@ void MetisPartitioningGridVisitor::buildMetisGraphLevelBased(SPtr<Grid3D> grid, ////////////////////////////////////////////////////////////////////////// bool MetisPartitioningGridVisitor::getPartitionCondition(SPtr<Block3D> block, PartLevel level) { - if (level == BUNDLE) - { - return true; - } - else if(level == PROCESS) - { - if (block->getBundle() == bundleID) - { - return true; - } - } - else if(level == THREAD) - { - if (block->getBundle() == bundleID && block->getRank() == processID) - { - return true; - } + if (level == BUNDLE) { + return true; + } else if (level == PROCESS) { + if (block->getBundle() == bundleID) { + return true; + } + } else if (level == THREAD) { + if (block->getBundle() == bundleID && block->getRank() == processID) { + return true; + } } return false; @@ -296,28 +255,19 @@ void MetisPartitioningGridVisitor::clear() ////////////////////////////////////////////////////////////////////////// int MetisPartitioningGridVisitor::getEdgeWeight(int dir) { - using namespace D3Q27System; - if (dir <= B) - { - return 100; - } - else if (dir >= NE && dir <= TS) - { - return 10; - } - else if (dir >= TNE) - { - return 1; - } + using namespace D3Q27System; + if (dir <= B) { + return 100; + } else if (dir >= NE && dir <= TS) { + return 10; + } else if (dir >= TNE) { + return 1; + } -// FIXME: non-void function does not return a value in all control paths + // FIXME: non-void function does not return a value in all control paths return 0; } ////////////////////////////////////////////////////////////////////////// -void MetisPartitioningGridVisitor::setNumberOfProcesses(int np) -{ - numberOfProcesses = np; -} - +void MetisPartitioningGridVisitor::setNumberOfProcesses(int np) { numberOfProcesses = np; } -#endif //VF_METIS +#endif // VF_METIS diff --git a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.h index 2d241359c..d1bc5ba30 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/MetisPartitioningGridVisitor.h @@ -1,15 +1,14 @@ -#ifndef MetisPartitioningGridVisitor_h +#ifndef MetisPartitioningGridVisitor_h #define MetisPartitioningGridVisitor_h #if defined VF_METIS && defined VF_MPI -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "Grid3DVisitor.h" #include "MetisPartitioner.h" - class Communicator; //////////////////////////////////////////////////////////////////////// @@ -21,48 +20,50 @@ class Grid3D; class Block3D; class MetisPartitioningGridVisitor : public Grid3DVisitor -{ +{ public: - //! This describe different types of decomposition - enum GraphType{LevelIntersected, LevelBased}; + //! This describe different types of decomposition + enum GraphType { LevelIntersected, LevelBased }; public: - //! Constructor - //! \param comm - communicator - //! \param graphType - type of decomposition - //! \param numOfDirs - maximum number of neighbors for each process - //! \param threads - on/off decomposition for threads - //! \param numberOfThreads - number of threads - MetisPartitioningGridVisitor(SPtr<Communicator> comm, GraphType graphType, int numOfDirs, MetisPartitioner::PartType partType = MetisPartitioner::KWAY, bool threads = false, int numberOfThreads = 0); - ~MetisPartitioningGridVisitor() override; - void visit(SPtr<Grid3D> grid) override; - void setNumberOfProcesses(int np); + //! Constructor + //! \param comm - communicator + //! \param graphType - type of decomposition + //! \param numOfDirs - maximum number of neighbors for each process + //! \param threads - on/off decomposition for threads + //! \param numberOfThreads - number of threads + MetisPartitioningGridVisitor(SPtr<Communicator> comm, GraphType graphType, int numOfDirs, + MetisPartitioner::PartType partType = MetisPartitioner::KWAY, bool threads = false, + int numberOfThreads = 0); + ~MetisPartitioningGridVisitor() override; + void visit(SPtr<Grid3D> grid) override; + void setNumberOfProcesses(int np); protected: - enum PartLevel {BUNDLE, PROCESS, THREAD}; - void collectData(SPtr<Grid3D> grid, int nofSegments, PartLevel level); - void buildMetisGraphLevelIntersected(SPtr<Grid3D> grid, int nofSegments, PartLevel level); - void buildMetisGraphLevelBased(SPtr<Grid3D> grid, int nofSegments, PartLevel level); - bool getPartitionCondition(SPtr<Block3D> block, PartLevel level); - void distributePartitionData(SPtr<Grid3D> grid, PartLevel level); - void clear(); - int getEdgeWeight(int dir); - int nofSegments; - int numOfDirs; - std::vector<int> blockID; - std::vector<idx_t> parts; - SPtr<Communicator> comm; - int bundleRoot; - int processRoot; - int bundleID; - int processID; - int numberOfBundles; - int numberOfThreads; - bool threads; - GraphType graphType; - MetisPartitioner::PartType partType; - int numberOfProcesses; + enum PartLevel { BUNDLE, PROCESS, THREAD }; + void collectData(SPtr<Grid3D> grid, int nofSegments, PartLevel level); + void buildMetisGraphLevelIntersected(SPtr<Grid3D> grid, int nofSegments, PartLevel level); + void buildMetisGraphLevelBased(SPtr<Grid3D> grid, int nofSegments, PartLevel level); + bool getPartitionCondition(SPtr<Block3D> block, PartLevel level); + void distributePartitionData(SPtr<Grid3D> grid, PartLevel level); + void clear(); + int getEdgeWeight(int dir); + int nofSegments; + int numOfDirs; + std::vector<int> blockID; + std::vector<idx_t> parts; + SPtr<Communicator> comm; + int bundleRoot; + int processRoot; + int bundleID; + int processID; + int numberOfBundles; + int numberOfThreads; + bool threads; + GraphType graphType; + MetisPartitioner::PartType partType; + int numberOfProcesses; }; -#endif //VF_MPI -#endif +#endif // VF_MPI +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.cpp index 5a1c24423..338c6de90 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.cpp @@ -1,60 +1,54 @@ #include "OverlapBlockVisitor.h" -#include "Grid3DSystem.h" #include "Block3D.h" #include "Grid3D.h" +#include "Grid3DSystem.h" -OverlapBlockVisitor::OverlapBlockVisitor(int levelDepth/*shut be maxGridLevel*/, bool includeNotActiveBlocks) - : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) - , levelDepth(levelDepth) - , includeNotActiveBlocks(includeNotActiveBlocks) +OverlapBlockVisitor::OverlapBlockVisitor(int levelDepth /*shut be maxGridLevel*/, bool includeNotActiveBlocks) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), levelDepth(levelDepth), includeNotActiveBlocks(includeNotActiveBlocks) { } ////////////////////////////////////////////////////////////////////////// void OverlapBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); - int nix1, nix2,nix3, nlev; - int neighix1, neighix2, neighix3, neighlev; - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); -// bool hasAdded = false; - for(size_t i=0; i<neighbors.size(); i++) - { - if( ( neighbors[i]->isActive() || includeNotActiveBlocks ) - && neighbors[i]->getLevel() > level) - { - neighix1 = neighbors[i]->getX1(); - neighix2 = neighbors[i]->getX2(); - neighix3 = neighbors[i]->getX3(); - neighlev = neighbors[i]->getLevel(); - nix1 = neighix1>>1; - nix2 = neighix2>>1; - nix3 = neighix3>>1; - nlev = neighlev-1; + int nix1, nix2, nix3, nlev; + int neighix1, neighix2, neighix3, neighlev; + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + // bool hasAdded = false; + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && neighbors[i]->getLevel() > level) { + neighix1 = neighbors[i]->getX1(); + neighix2 = neighbors[i]->getX2(); + neighix3 = neighbors[i]->getX3(); + neighlev = neighbors[i]->getLevel(); + nix1 = neighix1 >> 1; + nix2 = neighix2 >> 1; + nix3 = neighix3 >> 1; + nlev = neighlev - 1; - if(nlev != level) - { - throw UbException(UB_EXARGS, "OverlapBlockVisitor::adaptBlock - leveldifferenz passt nicht, block: " + block->toString()); - } + if (nlev != level) { + throw UbException(UB_EXARGS, "OverlapBlockVisitor::adaptBlock - leveldifferenz passt nicht, block: " + + block->toString()); + } - SPtr<Block3D> newBlock = grid->getBlock(nix1,nix2,nix3,nlev); - if(!newBlock) - { - newBlock = SPtr<Block3D>(new Block3D(nix1,nix2,nix3,nlev)); - grid->addBlock(newBlock); - // hasAdded=true; - } - } - } + SPtr<Block3D> newBlock = grid->getBlock(nix1, nix2, nix3, nlev); + if (!newBlock) { + newBlock = SPtr<Block3D>(new Block3D(nix1, nix2, nix3, nlev)); + grid->addBlock(newBlock); + // hasAdded=true; + } + } + } } ////////////////////////////////////////////////////////////////////////// std::string OverlapBlockVisitor::getSpecificDescription() { - std::string str("Overlap:"); - return str; + std::string str("Overlap:"); + return str; } diff --git a/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.h index 49f34438c..d839d8041 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/OverlapBlockVisitor.h @@ -1,8 +1,8 @@ #ifndef OverlapBlockVisitor_H #define OverlapBlockVisitor_H -#include <string> #include <PointerDefinitions.h> +#include <string> #include "Block3DVisitor.h" @@ -12,20 +12,19 @@ class Block3D; class OverlapBlockVisitor : public Block3DVisitor { public: - OverlapBlockVisitor(int levelDepth, bool includeNotActiveBlocks = true); - - ~OverlapBlockVisitor() override= default; + OverlapBlockVisitor(int levelDepth, bool includeNotActiveBlocks = true); - bool isIterative() { return false; } + ~OverlapBlockVisitor() override = default; - std::string getSpecificDescription(); + bool isIterative() { return false; } - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + std::string getSpecificDescription(); + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - int levelDepth; - bool includeNotActiveBlocks; + int levelDepth; + bool includeNotActiveBlocks; }; -#endif //OverlapBlockVisitor_H +#endif // OverlapBlockVisitor_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.cpp index 51fe5e8c8..f4b0136c9 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.cpp @@ -2,53 +2,44 @@ #include <vector> -#include "PriorityQueueDecompositor.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "PriorityQueueDecompositor.h" #include "UbLogger.h" - -PQueuePartitioningGridVisitor::PQueuePartitioningGridVisitor(int numOfParts) : numOfParts(numOfParts) -{ - -} +PQueuePartitioningGridVisitor::PQueuePartitioningGridVisitor(int numOfParts) : numOfParts(numOfParts) {} ////////////////////////////////////////////////////////////////////////// void PQueuePartitioningGridVisitor::visit(SPtr<Grid3D> grid) { - UBLOG(logDEBUG5, "PQueuePartitioningGridVisitor::visit() - start"); - std::vector<SPtr<Block3D>> blocks; - std::vector<int> weights; - std::vector< std::vector <SPtr<Block3D>> > parts; - int gridRank = grid->getRank(); - - int minInitLevel = grid->getCoarsestInitializedLevel(); - int maxInitLevel = grid->getFinestInitializedLevel(); - - for(int level = minInitLevel; level<=maxInitLevel; level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, gridRank, true, blockVector); - for(SPtr<Block3D> block : blockVector) - { - if (block) - { - blocks.push_back(block); - weights.push_back(block->getNumberOfLocalConnectors()*(1<<block->getLevel())); - } - } - } - PriorityQueueDecompositor <SPtr<Block3D>> dec = PriorityQueueDecompositor <SPtr<Block3D>> (blocks, weights, numOfParts); - dec.getDecomposition(parts); - - int i = 0; - for(std::vector<SPtr<Block3D>> p : parts) - { - for(SPtr<Block3D> block : p) - { - block->setPart(i); - } - i++; - - } - UBLOG(logDEBUG5, "PQueuePartitioningGridVisitor::visit() - end"); + UBLOG(logDEBUG5, "PQueuePartitioningGridVisitor::visit() - start"); + std::vector<SPtr<Block3D>> blocks; + std::vector<int> weights; + std::vector<std::vector<SPtr<Block3D>>> parts; + int gridRank = grid->getRank(); + + int minInitLevel = grid->getCoarsestInitializedLevel(); + int maxInitLevel = grid->getFinestInitializedLevel(); + + for (int level = minInitLevel; level <= maxInitLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, gridRank, true, blockVector); + for (SPtr<Block3D> block : blockVector) { + if (block) { + blocks.push_back(block); + weights.push_back(block->getNumberOfLocalConnectors() * (1 << block->getLevel())); + } + } + } + PriorityQueueDecompositor<SPtr<Block3D>> dec = + PriorityQueueDecompositor<SPtr<Block3D>>(blocks, weights, numOfParts); + dec.getDecomposition(parts); + + int i = 0; + for (std::vector<SPtr<Block3D>> p : parts) { + for (SPtr<Block3D> block : p) { + block->setPart(i); + } + i++; + } + UBLOG(logDEBUG5, "PQueuePartitioningGridVisitor::visit() - end"); } diff --git a/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.h index d1fdbeda7..e31fdb4b5 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/PQueuePartitioningGridVisitor.h @@ -1,10 +1,10 @@ /** -* @file PQueuePartitioningPatchVisitor.h -* @brief Visitor class which apply Priority Queue for threads decomposition. -* @author Kostyantyn Kucher -* @date 06.06.2011 -*/ -#ifndef PQUEUEPARTITIONINGPATCHVISITOR_H + * @file PQueuePartitioningPatchVisitor.h + * @brief Visitor class which apply Priority Queue for threads decomposition. + * @author Kostyantyn Kucher + * @date 06.06.2011 + */ +#ifndef PQUEUEPARTITIONINGPATCHVISITOR_H #define PQUEUEPARTITIONINGPATCHVISITOR_H #include <PointerDefinitions.h> @@ -16,12 +16,12 @@ class Grid3D; class PQueuePartitioningGridVisitor : public Grid3DVisitor { public: - PQueuePartitioningGridVisitor(int numOfParts); + PQueuePartitioningGridVisitor(int numOfParts); - void visit(SPtr<Grid3D> grid) override; + void visit(SPtr<Grid3D> grid) override; private: - int numOfParts; + int numOfParts; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.cpp index 9fd72e75b..bf25b8876 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.cpp @@ -1,129 +1,154 @@ #include "RatioBlockVisitor.h" -#include "Grid3DSystem.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" RatioBlockVisitor::RatioBlockVisitor(int levelDepth, bool includeNotActiveBlocks) - : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) - , maxLevelRatio(1) - , expandBlocks(true) - , levelDepth(levelDepth) - , includeNotActiveBlocks(includeNotActiveBlocks) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), maxLevelRatio(1), expandBlocks(true), levelDepth(levelDepth), + includeNotActiveBlocks(includeNotActiveBlocks) { - } ////////////////////////////////////////////////////////////////////////// void RatioBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); - if( block->isActive() || includeNotActiveBlocks ) - { - if(this->expandBlocks) - { - if(this->lookForExpand(grid,ix1, ix2, ix3, level)) - { - grid->expandBlock(ix1, ix2, ix3, level); - } - } - else - { - if(this->lookForCollapse(grid,ix1, ix2, ix3, level)) - { - grid->collapseBlock(ix1, ix2, ix3, level, levelDepth); - } - } - } + if (block->isActive() || includeNotActiveBlocks) { + if (this->expandBlocks) { + if (this->lookForExpand(grid, ix1, ix2, ix3, level)) { + grid->expandBlock(ix1, ix2, ix3, level); + } + } else { + if (this->lookForCollapse(grid, ix1, ix2, ix3, level)) { + grid->collapseBlock(ix1, ix2, ix3, level, levelDepth); + } + } + } } ////////////////////////////////////////////////////////////////////////// -bool RatioBlockVisitor::lookForExpand(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level) +bool RatioBlockVisitor::lookForExpand(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, + const int &level) { - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); - for(size_t i=0; i<neighbors.size(); i++) - { - if( ( neighbors[i]->isActive() || includeNotActiveBlocks ) - && neighbors[i]->getLevel() > level+this->maxLevelRatio) - { - return true; - } - } + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && + neighbors[i]->getLevel() > level + this->maxLevelRatio) { + return true; + } + } - return false; + return false; } ////////////////////////////////////////////////////////////////////////// -bool RatioBlockVisitor::lookForCollapse(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level) +bool RatioBlockVisitor::lookForCollapse(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, + const int &level) { - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2,ix3, level, this->levelDepth, neighbors); - for(size_t i=0; i<neighbors.size(); i++) - { - if( ( neighbors[i]->isActive() || includeNotActiveBlocks ) - && neighbors[i]->getLevel() < level-this->maxLevelRatio) - { - return true; - } - } + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && + neighbors[i]->getLevel() < level - this->maxLevelRatio) { + return true; + } + } - return false; + return false; } ////////////////////////////////////////////////////////////////////////// void RatioBlockVisitor::setExpandByAdaptation(bool expandBlocks) { - if(this->expandBlocks != expandBlocks) - { - this->expandBlocks = expandBlocks; + if (this->expandBlocks != expandBlocks) { + this->expandBlocks = expandBlocks; - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(expandBlocks) { if(l1 < l2) { Block3DVisitor::setStartLevel(l2); Block3DVisitor::setStopLevel(l1); } } - else { if(l2 < l1) { Block3DVisitor::setStartLevel(l2); Block3DVisitor::setStopLevel(l1); } } - } + if (expandBlocks) { + if (l1 < l2) { + Block3DVisitor::setStartLevel(l2); + Block3DVisitor::setStopLevel(l1); + } + } else { + if (l2 < l1) { + Block3DVisitor::setStartLevel(l2); + Block3DVisitor::setStopLevel(l1); + } + } + } } ////////////////////////////////////////////////////////////////////////// void RatioBlockVisitor::setLevelRatio(int ratio) { - if(ratio < 1) throw UbException(UB_EXARGS,"illegal ratio specified"); - this->maxLevelRatio = ratio; + if (ratio < 1) + throw UbException(UB_EXARGS, "illegal ratio specified"); + this->maxLevelRatio = ratio; } ////////////////////////////////////////////////////////////////////////// std::string RatioBlockVisitor::getSpecificDescription() { - std::string str("Ratio:"); - return str; + std::string str("Ratio:"); + return str; } ////////////////////////////////////////////////////////////////////////// int RatioBlockVisitor::getStartLevel() { - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(this->expandBlocks) { if(l2 < l1) return(l1); else return(l2); } - else { if(l2 < l1) return(l2); else return(l1); } + if (this->expandBlocks) { + if (l2 < l1) + return (l1); + else + return (l2); + } else { + if (l2 < l1) + return (l2); + else + return (l1); + } } ////////////////////////////////////////////////////////////////////////// int RatioBlockVisitor::getStopLevel() { - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(this->expandBlocks) { if(l2 < l1) return(l2); else return(l1); } - else { if(l2 < l1) return(l1); else return(l2); } + if (this->expandBlocks) { + if (l2 < l1) + return (l2); + else + return (l1); + } else { + if (l2 < l1) + return (l1); + else + return (l2); + } } ////////////////////////////////////////////////////////////////////////// void RatioBlockVisitor::setStartLevel(int level) { - if(this->expandBlocks) { if(level >= Block3DVisitor::getStopLevel()) Block3DVisitor::setStartLevel(level); } - else { if(level <= Block3DVisitor::getStopLevel()) Block3DVisitor::setStartLevel(level); } + if (this->expandBlocks) { + if (level >= Block3DVisitor::getStopLevel()) + Block3DVisitor::setStartLevel(level); + } else { + if (level <= Block3DVisitor::getStopLevel()) + Block3DVisitor::setStartLevel(level); + } } ////////////////////////////////////////////////////////////////////////// void RatioBlockVisitor::setStopLevel(int level) { - if(this->expandBlocks) { if(level <= Block3DVisitor::getStartLevel()) Block3DVisitor::setStopLevel(level); } - else { if(level >= Block3DVisitor::getStartLevel()) Block3DVisitor::setStopLevel(level); } + if (this->expandBlocks) { + if (level <= Block3DVisitor::getStartLevel()) + Block3DVisitor::setStopLevel(level); + } else { + if (level >= Block3DVisitor::getStartLevel()) + Block3DVisitor::setStopLevel(level); + } } diff --git a/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.h index f3f42d9cf..037d06dbf 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RatioBlockVisitor.h @@ -1,8 +1,8 @@ #ifndef RatioBlockVisitor_H #define RatioBlockVisitor_H -#include <string> #include <PointerDefinitions.h> +#include <string> #include "Block3DVisitor.h" @@ -12,38 +12,38 @@ class Block3D; class RatioBlockVisitor : public Block3DVisitor { public: - RatioBlockVisitor(int levelDepth, bool includeNotActiveBlocks = false); + RatioBlockVisitor(int levelDepth, bool includeNotActiveBlocks = false); - ~RatioBlockVisitor() override = default; + ~RatioBlockVisitor() override = default; - bool expandsByAdaptation() { return this->expandBlocks; } + bool expandsByAdaptation() { return this->expandBlocks; } - void setExpandByAdaptation(bool expandBlocks); + void setExpandByAdaptation(bool expandBlocks); - int getLevelRatio() { return this->maxLevelRatio; } - bool isIterative() { return true; } + int getLevelRatio() { return this->maxLevelRatio; } + bool isIterative() { return true; } - void setLevelRatio(int ratio); + void setLevelRatio(int ratio); - int getStartLevel(); - int getStopLevel(); + int getStartLevel(); + int getStopLevel(); - void setStartLevel(int level); - void setStopLevel(int level); + void setStartLevel(int level); + void setStopLevel(int level); - std::string getSpecificDescription(); + std::string getSpecificDescription(); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: - bool lookForExpand(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level); - bool lookForCollapse(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level); + bool lookForExpand(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, const int &level); + bool lookForCollapse(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, const int &level); private: - int maxLevelRatio; - bool expandBlocks; - int levelDepth; - bool includeNotActiveBlocks; + int maxLevelRatio; + bool expandBlocks; + int levelDepth; + bool includeNotActiveBlocks; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.cpp index b067fcad4..3bcdd2929 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.cpp @@ -1,145 +1,167 @@ #include "RatioSmoothBlockVisitor.h" -#include "Grid3DSystem.h" #include "Block3D.h" #include "Grid3D.h" +#include "Grid3DSystem.h" RatioSmoothBlockVisitor::RatioSmoothBlockVisitor(int levelDepth, bool includeNotActiveBlocks) - : Block3DVisitor(Grid3DSystem::MAXLEVEL, 0) - , maxLevelRatio(1) - , expandBlocks(true) - , levelDepth(levelDepth) - , includeNotActiveBlocks(includeNotActiveBlocks) + : Block3DVisitor(Grid3DSystem::MAXLEVEL, 0), maxLevelRatio(1), expandBlocks(true), levelDepth(levelDepth), + includeNotActiveBlocks(includeNotActiveBlocks) { } ////////////////////////////////////////////////////////////////////////// void RatioSmoothBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); - if( block->isActive() || includeNotActiveBlocks ) - { - if(this->expandBlocks) - { - if(this->lookForExpand(grid,ix1, ix2, ix3, level)) - { - grid->expandBlock(ix1, ix2, ix3, level); - } - } - else - { - if(this->lookForCollapse(grid,ix1, ix2, ix3, level)) - { - grid->collapseBlock(ix1, ix2, ix3, level, levelDepth); - } - } - } + if (block->isActive() || includeNotActiveBlocks) { + if (this->expandBlocks) { + if (this->lookForExpand(grid, ix1, ix2, ix3, level)) { + grid->expandBlock(ix1, ix2, ix3, level); + } + } else { + if (this->lookForCollapse(grid, ix1, ix2, ix3, level)) { + grid->collapseBlock(ix1, ix2, ix3, level, levelDepth); + } + } + } } ////////////////////////////////////////////////////////////////////////// -bool RatioSmoothBlockVisitor::lookForExpand(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level) +bool RatioSmoothBlockVisitor::lookForExpand(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, + const int &level) { - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); - int nix1, nix2,nix3, nlev; - for(size_t i=0; i<neighbors.size(); i++) - { - if( ( neighbors[i]->isActive() || includeNotActiveBlocks ) - && neighbors[i]->getLevel() > level) - { - nix1 = (neighbors)[i]->getX1(); - nix2 = (neighbors)[i]->getX2(); - nix3 = (neighbors)[i]->getX3(); - nlev = (neighbors)[i]->getLevel(); + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + int nix1, nix2, nix3, nlev; + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && neighbors[i]->getLevel() > level) { + nix1 = (neighbors)[i]->getX1(); + nix2 = (neighbors)[i]->getX2(); + nix3 = (neighbors)[i]->getX3(); + nlev = (neighbors)[i]->getLevel(); - std::vector<SPtr<Block3D>> neighbors1; - grid->getAllNeighbors(nix1, nix2, nix3, nlev, nlev+1, neighbors1); - for(size_t j=0; j<neighbors1.size(); j++) - { - if( ( neighbors1[j]->isActive() || includeNotActiveBlocks ) - && neighbors1[j]->getLevel() > level+this->maxLevelRatio) - { - return true; + std::vector<SPtr<Block3D>> neighbors1; + grid->getAllNeighbors(nix1, nix2, nix3, nlev, nlev + 1, neighbors1); + for (size_t j = 0; j < neighbors1.size(); j++) { + if ((neighbors1[j]->isActive() || includeNotActiveBlocks) && + neighbors1[j]->getLevel() > level + this->maxLevelRatio) { + return true; + } } - } - } - } - return false; + } + } + return false; } ////////////////////////////////////////////////////////////////////////// -bool RatioSmoothBlockVisitor::lookForCollapse(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level) +bool RatioSmoothBlockVisitor::lookForCollapse(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, + const int &level) { - std::vector<SPtr<Block3D>> neighbors; - grid->getAllNeighbors(ix1, ix2,ix3, level, this->levelDepth, neighbors); - for(size_t i=0; i<neighbors.size(); i++) - { - if( ( neighbors[i]->isActive() || includeNotActiveBlocks ) - && neighbors[i]->getLevel() < level-this->maxLevelRatio) - { - throw UbException(UB_EXARGS," not implemented till now"); - return true; - } - } + std::vector<SPtr<Block3D>> neighbors; + grid->getAllNeighbors(ix1, ix2, ix3, level, this->levelDepth, neighbors); + for (size_t i = 0; i < neighbors.size(); i++) { + if ((neighbors[i]->isActive() || includeNotActiveBlocks) && + neighbors[i]->getLevel() < level - this->maxLevelRatio) { + throw UbException(UB_EXARGS, " not implemented till now"); + return true; + } + } - return false; + return false; } ////////////////////////////////////////////////////////////////////////// void RatioSmoothBlockVisitor::setExpandByAdaptation(bool expandBlocks) { - if(this->expandBlocks != expandBlocks) - { - this->expandBlocks = expandBlocks; + if (this->expandBlocks != expandBlocks) { + this->expandBlocks = expandBlocks; - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(expandBlocks) { if(l1 < l2) { Block3DVisitor::setStartLevel(l2); Block3DVisitor::setStopLevel(l1); } } - else { if(l2 < l1) { Block3DVisitor::setStartLevel(l2); Block3DVisitor::setStopLevel(l1); } } - } + if (expandBlocks) { + if (l1 < l2) { + Block3DVisitor::setStartLevel(l2); + Block3DVisitor::setStopLevel(l1); + } + } else { + if (l2 < l1) { + Block3DVisitor::setStartLevel(l2); + Block3DVisitor::setStopLevel(l1); + } + } + } } ////////////////////////////////////////////////////////////////////////// void RatioSmoothBlockVisitor::setLevelRatio(int ratio) { - if(ratio < 1) throw UbException(UB_EXARGS,"illegal ratio specified"); - this->maxLevelRatio = ratio; + if (ratio < 1) + throw UbException(UB_EXARGS, "illegal ratio specified"); + this->maxLevelRatio = ratio; } ////////////////////////////////////////////////////////////////////////// std::string RatioSmoothBlockVisitor::getSpecificDescription() { - std::string str("Ratio:"); - return str; + std::string str("Ratio:"); + return str; } ////////////////////////////////////////////////////////////////////////// int RatioSmoothBlockVisitor::getStartLevel() { - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(this->expandBlocks) { if(l2 < l1) return(l1); else return(l2); } - else { if(l2 < l1) return(l2); else return(l1); } + if (this->expandBlocks) { + if (l2 < l1) + return (l1); + else + return (l2); + } else { + if (l2 < l1) + return (l2); + else + return (l1); + } } ////////////////////////////////////////////////////////////////////////// int RatioSmoothBlockVisitor::getStopLevel() { - int l1 = Block3DVisitor::getStartLevel(); - int l2 = Block3DVisitor::getStopLevel(); + int l1 = Block3DVisitor::getStartLevel(); + int l2 = Block3DVisitor::getStopLevel(); - if(this->expandBlocks) { if(l2 < l1) return(l2); else return(l1); } - else { if(l2 < l1) return(l1); else return(l2); } + if (this->expandBlocks) { + if (l2 < l1) + return (l2); + else + return (l1); + } else { + if (l2 < l1) + return (l1); + else + return (l2); + } } ////////////////////////////////////////////////////////////////////////// void RatioSmoothBlockVisitor::setStartLevel(int level) { - if(this->expandBlocks) { if(level >= Block3DVisitor::getStopLevel()) Block3DVisitor::setStartLevel(level); } - else { if(level <= Block3DVisitor::getStopLevel()) Block3DVisitor::setStartLevel(level); } + if (this->expandBlocks) { + if (level >= Block3DVisitor::getStopLevel()) + Block3DVisitor::setStartLevel(level); + } else { + if (level <= Block3DVisitor::getStopLevel()) + Block3DVisitor::setStartLevel(level); + } } ////////////////////////////////////////////////////////////////////////// void RatioSmoothBlockVisitor::setStopLevel(int level) { - if(this->expandBlocks) { if(level <= Block3DVisitor::getStartLevel()) Block3DVisitor::setStopLevel(level); } - else { if(level >= Block3DVisitor::getStartLevel()) Block3DVisitor::setStopLevel(level); } + if (this->expandBlocks) { + if (level <= Block3DVisitor::getStartLevel()) + Block3DVisitor::setStopLevel(level); + } else { + if (level >= Block3DVisitor::getStartLevel()) + Block3DVisitor::setStopLevel(level); + } } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.h index 856e51779..b9347c847 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RatioSmoothBlockVisitor.h @@ -11,39 +11,38 @@ class Block3D; class RatioSmoothBlockVisitor : public Block3DVisitor { public: - RatioSmoothBlockVisitor(int levelDepth, bool includeNotActiveBlocks = false); + RatioSmoothBlockVisitor(int levelDepth, bool includeNotActiveBlocks = false); - ~RatioSmoothBlockVisitor() override = default; + ~RatioSmoothBlockVisitor() override = default; - bool expandsByAdaptation() { return this->expandBlocks; } + bool expandsByAdaptation() { return this->expandBlocks; } - void setExpandByAdaptation(bool expandBlocks); + void setExpandByAdaptation(bool expandBlocks); - int getLevelRatio() { return this->maxLevelRatio; } - bool isIterative() { return true; } + int getLevelRatio() { return this->maxLevelRatio; } + bool isIterative() { return true; } - void setLevelRatio(int ratio); + void setLevelRatio(int ratio); - int getStartLevel(); - int getStopLevel(); + int getStartLevel(); + int getStopLevel(); - void setStartLevel(int level); - void setStopLevel(int level); + void setStartLevel(int level); + void setStopLevel(int level); - std::string getSpecificDescription(); + std::string getSpecificDescription(); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: - bool lookForExpand(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level); - bool lookForCollapse(SPtr<Grid3D> grid, const int& ix1, const int& ix2, const int& ix3, const int& level); + bool lookForExpand(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, const int &level); + bool lookForCollapse(SPtr<Grid3D> grid, const int &ix1, const int &ix2, const int &ix3, const int &level); private: - int maxLevelRatio; - bool expandBlocks; - int levelDepth; - bool includeNotActiveBlocks; - + int maxLevelRatio; + bool expandBlocks; + int levelDepth; + bool includeNotActiveBlocks; }; -#endif //RatioSmoothBlockVisitor_H +#endif // RatioSmoothBlockVisitor_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.cpp b/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.cpp index 59ffd9dfe..88ff49408 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.cpp @@ -1,54 +1,50 @@ #include "RefineAroundGbObjectHelper.h" +#include "Communicator.h" +#include "OverlapBlockVisitor.h" #include "RatioBlockVisitor.h" #include "RatioSmoothBlockVisitor.h" -#include "OverlapBlockVisitor.h" #include "SetInterpolationDirsBlockVisitor.h" #include <D3Q27System.h> -#include <Grid3D.h> #include <D3Q27TriFaceMeshInteractor.h> -#include "Communicator.h" +#include <Grid3D.h> -RefineAroundGbObjectHelper::RefineAroundGbObjectHelper(SPtr<Grid3D> grid, int refineLevel, SPtr<D3Q27TriFaceMeshInteractor> objectIter, double startDistance, double stopDistance, SPtr<Communicator> comm) : - grid(grid), - refineLevel(refineLevel), - objectIter(objectIter), - startDistance(startDistance), - stopDistance(stopDistance), - comm(comm) +RefineAroundGbObjectHelper::RefineAroundGbObjectHelper(SPtr<Grid3D> grid, int refineLevel, + SPtr<D3Q27TriFaceMeshInteractor> objectIter, + double startDistance, double stopDistance, + SPtr<Communicator> comm) + : grid(grid), refineLevel(refineLevel), objectIter(objectIter), startDistance(startDistance), + stopDistance(stopDistance), comm(comm) { } ////////////////////////////////////////////////////////////////////////// -RefineAroundGbObjectHelper::~RefineAroundGbObjectHelper(void) -= default; +RefineAroundGbObjectHelper::~RefineAroundGbObjectHelper(void) = default; ////////////////////////////////////////////////////////////////////////// void RefineAroundGbObjectHelper::refine() { - UBLOG(logDEBUG5,"RefineCrossAndInsideGbObjectHelper: refine - start"); + UBLOG(logDEBUG5, "RefineCrossAndInsideGbObjectHelper: refine - start"); - int rank = grid->getRank(); - grid->setRank(0); + int rank = grid->getRank(); + grid->setRank(0); - objectIter->refineBlockGridToLevel(refineLevel, startDistance, stopDistance); + objectIter->refineBlockGridToLevel(refineLevel, startDistance, stopDistance); - RatioBlockVisitor ratioVisitor(refineLevel); - grid->accept(ratioVisitor); + RatioBlockVisitor ratioVisitor(refineLevel); + grid->accept(ratioVisitor); - RatioSmoothBlockVisitor ratioSmoothVisitor(refineLevel); - grid->accept(ratioSmoothVisitor); + RatioSmoothBlockVisitor ratioSmoothVisitor(refineLevel); + grid->accept(ratioSmoothVisitor); - OverlapBlockVisitor overlapVisitor(refineLevel, false); - grid->accept(overlapVisitor); + OverlapBlockVisitor overlapVisitor(refineLevel, false); + grid->accept(overlapVisitor); - std::vector<int> dirs; - for (int i=D3Q27System::E; i<=D3Q27System::TS; i++) - { - dirs.push_back(i); - } - SetInterpolationDirsBlockVisitor interDirsVisitor(dirs); - grid->accept(interDirsVisitor); + std::vector<int> dirs; + for (int i = D3Q27System::E; i <= D3Q27System::TS; i++) { + dirs.push_back(i); + } + SetInterpolationDirsBlockVisitor interDirsVisitor(dirs); + grid->accept(interDirsVisitor); - grid->setRank(rank); + grid->setRank(rank); - UBLOG(logDEBUG5,"RefineCrossAndInsideGbObjectHelper: refine - end"); + UBLOG(logDEBUG5, "RefineCrossAndInsideGbObjectHelper: refine - end"); } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.h b/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.h index 76a7bb385..766c290a7 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineAroundGbObjectHelper.h @@ -13,22 +13,24 @@ class D3Q27TriFaceMeshInteractor; class RefineAroundGbObjectHelper { public: - //! Constructor - //! \param grid a smart pointer to the grid object - //! \param maxRefineLevel an integer for maximal refinement level - //! \param objectIter a D3Q27TriFaceMeshInteractor object - represent geometry which should be refinement - //! \param startDistance start distance from geometry for refinement - //! \param stopDistance stop distance from geometry for refinement - RefineAroundGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, SPtr<D3Q27TriFaceMeshInteractor> objectIter, double startDistance, double stopDistance, SPtr<Communicator> comm); - virtual ~RefineAroundGbObjectHelper(); - //! start refinement - void refine(); + //! Constructor + //! \param grid a smart pointer to the grid object + //! \param maxRefineLevel an integer for maximal refinement level + //! \param objectIter a D3Q27TriFaceMeshInteractor object - represent geometry which should be refinement + //! \param startDistance start distance from geometry for refinement + //! \param stopDistance stop distance from geometry for refinement + RefineAroundGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, SPtr<D3Q27TriFaceMeshInteractor> objectIter, + double startDistance, double stopDistance, SPtr<Communicator> comm); + virtual ~RefineAroundGbObjectHelper(); + //! start refinement + void refine(); + private: SPtr<Grid3D> grid; SPtr<D3Q27TriFaceMeshInteractor> objectIter; - int refineLevel; - double startDistance, stopDistance; - SPtr<Communicator> comm; + int refineLevel; + double startDistance, stopDistance; + SPtr<Communicator> comm; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.cpp index cb503f368..9d5126d99 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.cpp @@ -1,42 +1,35 @@ #include "RefineCrossAndInsideGbObjectBlockVisitor.h" -#include <geometry3d/GbObject3D.h> -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include <geometry3d/GbObject3D.h> - -RefineCrossAndInsideGbObjectBlockVisitor::RefineCrossAndInsideGbObjectBlockVisitor() -: Block3DVisitor() -{ -} +RefineCrossAndInsideGbObjectBlockVisitor::RefineCrossAndInsideGbObjectBlockVisitor() : Block3DVisitor() {} ////////////////////////////////////////////////////////////////////////// -RefineCrossAndInsideGbObjectBlockVisitor::RefineCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int refineLevel) - : Block3DVisitor(0,refineLevel-1), geoObject(geoObject) +RefineCrossAndInsideGbObjectBlockVisitor::RefineCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, + int refineLevel) + : Block3DVisitor(0, refineLevel - 1), geoObject(geoObject) { - } ////////////////////////////////////////////////////////////////////////// -RefineCrossAndInsideGbObjectBlockVisitor::~RefineCrossAndInsideGbObjectBlockVisitor() -= default; +RefineCrossAndInsideGbObjectBlockVisitor::~RefineCrossAndInsideGbObjectBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// void RefineCrossAndInsideGbObjectBlockVisitor::visit(const SPtr<Grid3D> grid, SPtr<Block3D> block) { - int level = block->getLevel(); - if( notActive && block->isNotActive() ) return; - if( level > this->getStopLevel() ) return; + int level = block->getLevel(); + if (notActive && block->isNotActive()) + return; + if (level > this->getStopLevel()) + return; - UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 deltas = grid->getBlockLengths(block); - if(geoObject->isCellInsideOrCuttingGbObject3D( val<1>(coords) - , val<2>(coords) - , val<3>(coords) - , val<1>(coords)+val<1>(deltas) - , val<2>(coords)+val<2>(deltas) - , val<3>(coords)+val<3>(deltas)) ) - { - grid->expandBlock(block->getX1(),block->getX2(),block->getX3(),level); - } + UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 deltas = grid->getBlockLengths(block); + if (geoObject->isCellInsideOrCuttingGbObject3D(val<1>(coords), val<2>(coords), val<3>(coords), + val<1>(coords) + val<1>(deltas), val<2>(coords) + val<2>(deltas), + val<3>(coords) + val<3>(deltas))) { + grid->expandBlock(block->getX1(), block->getX2(), block->getX3(), level); + } - return; + return; } ////////////////////////////////////////////////////////////////////////// diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.h index 07e3e3b70..9696b447c 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectBlockVisitor.h @@ -1,8 +1,8 @@ #ifndef RefineCrossAndInsideGbObjectBlockVisitor_H #define RefineCrossAndInsideGbObjectBlockVisitor_H -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "Block3DVisitor.h" @@ -11,23 +11,24 @@ class Block3D; class GbObject3D; //! \brief Refine blocks on base of bounding box which is defined with <i>geoObject</i> -//! \details The class uses a geometry object for define a bounding box. Inside and across this bounding box will be grid on block basis refinement. -//! \author K. Kucher +//! \details The class uses a geometry object for define a bounding box. Inside and across this bounding box will be +//! grid on block basis refinement. \author K. Kucher class RefineCrossAndInsideGbObjectBlockVisitor : public Block3DVisitor { public: - //! A default constructor - RefineCrossAndInsideGbObjectBlockVisitor(); - //! A constructor - //! \param geoObject a smart pointer to bounding box - //! \param refineLevel an integer for refine on this level - RefineCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int refineLevel); - ~RefineCrossAndInsideGbObjectBlockVisitor() override; + //! A default constructor + RefineCrossAndInsideGbObjectBlockVisitor(); + //! A constructor + //! \param geoObject a smart pointer to bounding box + //! \param refineLevel an integer for refine on this level + RefineCrossAndInsideGbObjectBlockVisitor(SPtr<GbObject3D> geoObject, int refineLevel); + ~RefineCrossAndInsideGbObjectBlockVisitor() override; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: SPtr<GbObject3D> geoObject; - bool notActive{true}; + bool notActive{ true }; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.cpp b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.cpp index 912a551ba..14ea2b073 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.cpp @@ -1,77 +1,70 @@ #include "RefineCrossAndInsideGbObjectHelper.h" -#include "RefineCrossAndInsideGbObjectBlockVisitor.h" -#include "RatioBlockVisitor.h" -#include "RatioSmoothBlockVisitor.h" #include "CheckRatioBlockVisitor.h" +#include "Communicator.h" #include "OverlapBlockVisitor.h" +#include "RatioBlockVisitor.h" +#include "RatioSmoothBlockVisitor.h" +#include "RefineCrossAndInsideGbObjectBlockVisitor.h" #include "SetInterpolationDirsBlockVisitor.h" #include <D3Q27System.h> -#include "Communicator.h" -#include <Grid3D.h> #include <GbObject3D.h> +#include <Grid3D.h> - -RefineCrossAndInsideGbObjectHelper::RefineCrossAndInsideGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, SPtr<Communicator> comm) : - grid(grid), - maxRefineLevel(maxRefineLevel), - comm(comm) +RefineCrossAndInsideGbObjectHelper::RefineCrossAndInsideGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, + SPtr<Communicator> comm) + : grid(grid), maxRefineLevel(maxRefineLevel), comm(comm) { } ////////////////////////////////////////////////////////////////////////// -RefineCrossAndInsideGbObjectHelper::~RefineCrossAndInsideGbObjectHelper(void) -= default; +RefineCrossAndInsideGbObjectHelper::~RefineCrossAndInsideGbObjectHelper(void) = default; ////////////////////////////////////////////////////////////////////////// void RefineCrossAndInsideGbObjectHelper::refine() { - UBLOG(logDEBUG5,"RefineCrossAndInsideGbObjectHelper: refine - start"); - - if (comm->isRoot()) - { - int size = (int)objects.size(); + UBLOG(logDEBUG5, "RefineCrossAndInsideGbObjectHelper: refine - start"); - for (int i = 0; i<size; i++) - { - RefineCrossAndInsideGbObjectBlockVisitor refVisitor(objects[i], levels[i]); - grid->accept(refVisitor); - } + if (comm->isRoot()) { + int size = (int)objects.size(); - //RatioBlockVisitor ratioVisitor(maxRefineLevel); - //grid->accept(ratioVisitor); + for (int i = 0; i < size; i++) { + RefineCrossAndInsideGbObjectBlockVisitor refVisitor(objects[i], levels[i]); + grid->accept(refVisitor); + } - //RatioSmoothBlockVisitor ratioSmoothVisitor(maxRefineLevel); - //grid->accept(ratioSmoothVisitor); + // RatioBlockVisitor ratioVisitor(maxRefineLevel); + // grid->accept(ratioVisitor); - RatioBlockVisitor ratioVisitor(maxRefineLevel); - CheckRatioBlockVisitor checkRatio(maxRefineLevel); - int count = 0; + // RatioSmoothBlockVisitor ratioSmoothVisitor(maxRefineLevel); + // grid->accept(ratioSmoothVisitor); - do { - grid->accept(ratioVisitor); - checkRatio.resetState(); - grid->accept(checkRatio); - UBLOG(logINFO, "count = "<<count++<<" state = "<<checkRatio.getState()); - } while (!checkRatio.getState()); + RatioBlockVisitor ratioVisitor(maxRefineLevel); + CheckRatioBlockVisitor checkRatio(maxRefineLevel); + int count = 0; + do { + grid->accept(ratioVisitor); + checkRatio.resetState(); + grid->accept(checkRatio); + UBLOG(logINFO, "count = " << count++ << " state = " << checkRatio.getState()); + } while (!checkRatio.getState()); - OverlapBlockVisitor overlapVisitor(maxRefineLevel, false); - grid->accept(overlapVisitor); - } + OverlapBlockVisitor overlapVisitor(maxRefineLevel, false); + grid->accept(overlapVisitor); + } - grid->updateDistributedBlocks(comm); + grid->updateDistributedBlocks(comm); - std::vector<int> dirs; + std::vector<int> dirs; - for (int i=D3Q27System::E; i<D3Q27System::ENDDIR; i++) - { - dirs.push_back(i); - } - SetInterpolationDirsBlockVisitor interDirsVisitor(dirs); - grid->accept(interDirsVisitor); - UBLOG(logDEBUG5,"RefineCrossAndInsideGbObjectHelper: refine - end"); + for (int i = D3Q27System::E; i < D3Q27System::ENDDIR; i++) { + dirs.push_back(i); + } + SetInterpolationDirsBlockVisitor interDirsVisitor(dirs); + grid->accept(interDirsVisitor); + UBLOG(logDEBUG5, "RefineCrossAndInsideGbObjectHelper: refine - end"); } ////////////////////////////////////////////////////////////////////////// -void RefineCrossAndInsideGbObjectHelper::addGbObject( SPtr<GbObject3D> object, int refineLevel ) +void RefineCrossAndInsideGbObjectHelper::addGbObject(SPtr<GbObject3D> object, int refineLevel) { - objects.push_back(object); - levels.push_back(refineLevel); + objects.push_back(object); + levels.push_back(refineLevel); } diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.h b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.h index c7ea0b3bd..fd1fefe3d 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineCrossAndInsideGbObjectHelper.h @@ -1,8 +1,8 @@ #ifndef RefineCrossAndInsideGbObjectHelper_H #define RefineCrossAndInsideGbObjectHelper_H -#include <vector> #include <PointerDefinitions.h> +#include <vector> class Communicator; class Grid3D; @@ -14,23 +14,24 @@ class GbObject3D; class RefineCrossAndInsideGbObjectHelper { public: - //! Constructor - //! \param grid a smart pointer to the grid object - //! \param maxRefineLevel an integer for maximal refinement level - RefineCrossAndInsideGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, SPtr<Communicator> comm); - virtual ~RefineCrossAndInsideGbObjectHelper(); - //! add geometric object - //! \param object a smart pointer to bounding box - //! \param refineLevel a value of refinement level for corresponding bounding box - void addGbObject(SPtr<GbObject3D> object, int refineLevel); - //! start refinement - void refine(); + //! Constructor + //! \param grid a smart pointer to the grid object + //! \param maxRefineLevel an integer for maximal refinement level + RefineCrossAndInsideGbObjectHelper(SPtr<Grid3D> grid, int maxRefineLevel, SPtr<Communicator> comm); + virtual ~RefineCrossAndInsideGbObjectHelper(); + //! add geometric object + //! \param object a smart pointer to bounding box + //! \param refineLevel a value of refinement level for corresponding bounding box + void addGbObject(SPtr<GbObject3D> object, int refineLevel); + //! start refinement + void refine(); + private: SPtr<Grid3D> grid; - std::vector<SPtr<GbObject3D> > objects; - std::vector<int> levels; - int maxRefineLevel; - SPtr<Communicator> comm; + std::vector<SPtr<GbObject3D>> objects; + std::vector<int> levels; + int maxRefineLevel; + SPtr<Communicator> comm; }; -#endif +#endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.cpp index f7b2b208d..7fa6a6283 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.cpp @@ -1,68 +1,65 @@ #include "RefineInterGbObjectsVisitor.h" -#include <geometry3d/GbObject3D.h> -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include <geometry3d/GbObject3D.h> - -RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor() - : Block3DVisitor(-1, -1) -{ -} +RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor() : Block3DVisitor(-1, -1) {} ////////////////////////////////////////////////////////////////////////// -RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor(SPtr<GbObject3D> includeGbObject3D, SPtr<GbObject3D> excludeGbObject3D, int startlevel, int stoplevel) - : Block3DVisitor(startlevel, stoplevel) +RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor(SPtr<GbObject3D> includeGbObject3D, + SPtr<GbObject3D> excludeGbObject3D, int startlevel, + int stoplevel) + : Block3DVisitor(startlevel, stoplevel) { - this->includeGbObjects3D.push_back(includeGbObject3D); - this->excludeGbObjects3D.push_back(excludeGbObject3D); + this->includeGbObjects3D.push_back(includeGbObject3D); + this->excludeGbObjects3D.push_back(excludeGbObject3D); } ////////////////////////////////////////////////////////////////////////// -RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor(std::vector<SPtr<GbObject3D>> includeGbObjects3D, std::vector<SPtr<GbObject3D>> excludeGbObjects3D, int startlevel, int stoplevel) - : Block3DVisitor(startlevel, stoplevel) +RefineInterGbObjectsBlockVisitor::RefineInterGbObjectsBlockVisitor(std::vector<SPtr<GbObject3D>> includeGbObjects3D, + std::vector<SPtr<GbObject3D>> excludeGbObjects3D, + int startlevel, int stoplevel) + : Block3DVisitor(startlevel, stoplevel) { - this->includeGbObjects3D = includeGbObjects3D; - this->excludeGbObjects3D = excludeGbObjects3D; + this->includeGbObjects3D = includeGbObjects3D; + this->excludeGbObjects3D = excludeGbObjects3D; } ////////////////////////////////////////////////////////////////////////// void RefineInterGbObjectsBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 delta = grid->getBlockLengths(block); + UbTupleDouble3 coords = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 delta = grid->getBlockLengths(block); - double cellMinX1 = val<1>(coords); - double cellMinX2 = val<2>(coords); - double cellMinX3 = val<3>(coords); - double cellMaxX1 = val<1>(coords)+val<1>(delta); - double cellMaxX2 = val<2>(coords)+val<2>(delta); - double cellMaxX3 = val<3>(coords)+val<3>(delta); + double cellMinX1 = val<1>(coords); + double cellMinX2 = val<2>(coords); + double cellMinX3 = val<3>(coords); + double cellMaxX1 = val<1>(coords) + val<1>(delta); + double cellMaxX2 = val<2>(coords) + val<2>(delta); + double cellMaxX3 = val<3>(coords) + val<3>(delta); - bool insideInclude = false; - for(size_t i=0; i<includeGbObjects3D.size(); i++) - { - if( includeGbObjects3D[i]->isCellInsideOrCuttingGbObject3D(cellMinX1,cellMinX2,cellMinX3,cellMaxX1,cellMaxX2,cellMaxX3) ) - { - insideInclude = true; - break; - } - } + bool insideInclude = false; + for (size_t i = 0; i < includeGbObjects3D.size(); i++) { + if (includeGbObjects3D[i]->isCellInsideOrCuttingGbObject3D(cellMinX1, cellMinX2, cellMinX3, cellMaxX1, + cellMaxX2, cellMaxX3)) { + insideInclude = true; + break; + } + } - bool insideExclude = false; - for(size_t e=0; e<excludeGbObjects3D.size(); e++) - { - if(excludeGbObjects3D[e]->isCellInsideGbObject3D(cellMinX1, cellMinX2, cellMinX3, cellMaxX1, cellMaxX2, cellMaxX3)) - { - insideExclude = true; - break; - } - } + bool insideExclude = false; + for (size_t e = 0; e < excludeGbObjects3D.size(); e++) { + if (excludeGbObjects3D[e]->isCellInsideGbObject3D(cellMinX1, cellMinX2, cellMinX3, cellMaxX1, cellMaxX2, + cellMaxX3)) { + insideExclude = true; + break; + } + } - if(insideInclude && !insideExclude) - { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); - grid->expandBlock(ix1,ix2,ix3,level); - } + if (insideInclude && !insideExclude) { + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); + grid->expandBlock(ix1, ix2, ix3, level); + } } diff --git a/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.h index ed0a85018..6bcf41e04 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RefineInterGbObjectsVisitor.h @@ -1,8 +1,8 @@ #ifndef RefineInterGbObjectsVisirtor_H #define RefineInterGbObjectsVisirtor_H -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "Block3DVisitor.h" @@ -14,14 +14,16 @@ class GbObject3D; class RefineInterGbObjectsBlockVisitor : public Block3DVisitor { public: - RefineInterGbObjectsBlockVisitor(); - RefineInterGbObjectsBlockVisitor(SPtr<GbObject3D> includeGbObject3D, SPtr<GbObject3D> excludeGbObject3D, int startlevel, int stoplevel); - RefineInterGbObjectsBlockVisitor(std::vector<SPtr<GbObject3D> > includeGbObjects3D, std::vector<SPtr<GbObject3D> > excludeGbObjects3D, int startlevel, int stoplevel); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + RefineInterGbObjectsBlockVisitor(); + RefineInterGbObjectsBlockVisitor(SPtr<GbObject3D> includeGbObject3D, SPtr<GbObject3D> excludeGbObject3D, + int startlevel, int stoplevel); + RefineInterGbObjectsBlockVisitor(std::vector<SPtr<GbObject3D>> includeGbObjects3D, + std::vector<SPtr<GbObject3D>> excludeGbObjects3D, int startlevel, int stoplevel); + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - std::vector<SPtr<GbObject3D> > includeGbObjects3D; - std::vector<SPtr<GbObject3D> > excludeGbObjects3D; + std::vector<SPtr<GbObject3D>> includeGbObjects3D; + std::vector<SPtr<GbObject3D>> excludeGbObjects3D; }; -#endif //RefineInterGbObjectsVisirtor_H +#endif // RefineInterGbObjectsVisirtor_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.cpp index 65def1940..538fd9511 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.cpp @@ -1,22 +1,17 @@ #include "RenumberBlockVisitor.h" +#include "Block3D.h" +#include "Grid3D.h" #include "Grid3DSystem.h" #include "LBMSystem.h" -#include "Grid3D.h" -#include "Block3D.h" int RenumberBlockVisitor::counter = 0; -RenumberBlockVisitor::RenumberBlockVisitor() : -Block3DVisitor(0, Grid3DSystem::MAXLEVEL) -{ - -} +RenumberBlockVisitor::RenumberBlockVisitor() : Block3DVisitor(0, Grid3DSystem::MAXLEVEL) {} ////////////////////////////////////////////////////////////////////////// void RenumberBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - block->setGlobalID(counter); - Grid3D::BlockIDMap blockIdMap = grid->getBlockIDs(); - blockIdMap.insert(std::make_pair(counter, block)); - counter++; + block->setGlobalID(counter); + Grid3D::BlockIDMap blockIdMap = grid->getBlockIDs(); + blockIdMap.insert(std::make_pair(counter, block)); + counter++; } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.h index 874039548..e0ceb4a74 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RenumberBlockVisitor.h @@ -1,9 +1,9 @@ /** -* @file RenumberBlockVisitor.h -* @brief Visitor class which renumber blocks. -* @author Konstantin Kutscher -* @date 06.06.2011 -*/ + * @file RenumberBlockVisitor.h + * @brief Visitor class which renumber blocks. + * @author Konstantin Kutscher + * @date 06.06.2011 + */ #ifndef RenumberBlockVisitor_h #define RenumberBlockVisitor_h @@ -14,19 +14,19 @@ class Grid3D; class Block3D; //! \brief Visitor class which renumber blocks. -//! \details Visitor class which renumber blocks. -//! \author Konstantin Kutscher +//! \details Visitor class which renumber blocks. +//! \author Konstantin Kutscher class RenumberBlockVisitor : public Block3DVisitor { public: - RenumberBlockVisitor(); + RenumberBlockVisitor(); - ~RenumberBlockVisitor() override = default; + ~RenumberBlockVisitor() override = default; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - static int counter; + static int counter; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.cpp index 1d01aac23..433e08cea 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.cpp @@ -1,49 +1,42 @@ #include "RenumberGridVisitor.h" -#include "Grid3DSystem.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" //#include <mpi.h> -RenumberGridVisitor::RenumberGridVisitor(SPtr<Communicator> com) - : comm(com) -{ -} +RenumberGridVisitor::RenumberGridVisitor(SPtr<Communicator> com) : comm(com) {} ////////////////////////////////////////////////////////////////////////// void RenumberGridVisitor::visit(SPtr<Grid3D> grid) { - int counter = 0; + int counter = 0; - //UBLOG(logDEBUG5, "RenumberGridVisitor::visit() - start"); - std::vector<SPtr<Block3D>> blocks; -// int gridRank = grid->getRank(); - int size; - //MPI_Comm_size(MPI_COMM_WORLD, &size); - size = comm->getNumberOfProcesses(); + // UBLOG(logDEBUG5, "RenumberGridVisitor::visit() - start"); + std::vector<SPtr<Block3D>> blocks; + // int gridRank = grid->getRank(); + int size; + // MPI_Comm_size(MPI_COMM_WORLD, &size); + size = comm->getNumberOfProcesses(); - int minInitLevel = grid->getCoarsestInitializedLevel(); - int maxInitLevel = grid->getFinestInitializedLevel(); + int minInitLevel = grid->getCoarsestInitializedLevel(); + int maxInitLevel = grid->getFinestInitializedLevel(); - Grid3D::BlockIDMap& blockIdMap = grid->getBlockIDs(); - blockIdMap.clear(); + Grid3D::BlockIDMap &blockIdMap = grid->getBlockIDs(); + blockIdMap.clear(); - for(int rank = 0; rank < size; rank++) - { - for (int level = minInitLevel; level <= maxInitLevel; level++) - { - std::vector<SPtr<Block3D>> blockVector; - grid->getBlocks(level, blockVector); - for (SPtr<Block3D> block : blockVector) - { - if(block->getRank() == rank) - { - block->setGlobalID(counter); - blockIdMap.insert(std::make_pair(counter, block)); - counter++; + for (int rank = 0; rank < size; rank++) { + for (int level = minInitLevel; level <= maxInitLevel; level++) { + std::vector<SPtr<Block3D>> blockVector; + grid->getBlocks(level, blockVector); + for (SPtr<Block3D> block : blockVector) { + if (block->getRank() == rank) { + block->setGlobalID(counter); + blockIdMap.insert(std::make_pair(counter, block)); + counter++; + } } - } - } - } + } + } - //UBLOG(logDEBUG5, "RenumberGridVisitor::visit() - end"); + // UBLOG(logDEBUG5, "RenumberGridVisitor::visit() - end"); } diff --git a/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.h index f4b27b58e..eabb0cafd 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/RenumberGridVisitor.h @@ -1,33 +1,33 @@ /** -* @file RenumberGridVisitor.h -* @brief Visitor class which renumber blocks. -* @author Konstantin Kutscher -* @date 06.06.2011 -*/ + * @file RenumberGridVisitor.h + * @brief Visitor class which renumber blocks. + * @author Konstantin Kutscher + * @date 06.06.2011 + */ #ifndef RenumberGridVisitor_h #define RenumberGridVisitor_h -#include "Grid3DVisitor.h" #include "Communicator.h" +#include "Grid3DVisitor.h" class Grid3D; //! \brief Visitor class which renumber blocks in order: rank->level. -//! \details Visitor class which renumber blocks. -//! \author Konstantin Kutscher +//! \details Visitor class which renumber blocks. +//! \author Konstantin Kutscher class RenumberGridVisitor : public Grid3DVisitor { public: - RenumberGridVisitor(SPtr<Communicator> com); + RenumberGridVisitor(SPtr<Communicator> com); - ~RenumberGridVisitor() override = default; + ~RenumberGridVisitor() override = default; - void visit(SPtr<Grid3D> grid) override; + void visit(SPtr<Grid3D> grid) override; private: SPtr<Communicator> comm; -// static int counter; + // static int counter; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.cpp index 3ef67f289..bbccaa785 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -33,25 +33,21 @@ #include "SetBcBlocksBlockVisitor.h" -#include "Interactor3D.h" -#include "Grid3DSystem.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" +#include "Interactor3D.h" -SetBcBlocksBlockVisitor::SetBcBlocksBlockVisitor(SPtr<Interactor3D> interactor) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), interactor(interactor) +SetBcBlocksBlockVisitor::SetBcBlocksBlockVisitor(SPtr<Interactor3D> interactor) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), interactor(interactor) { - } void SetBcBlocksBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if(block->getRank() == grid->getRank()) - { - if (block->isActive()) - { - interactor->setBCBlock(block); - } - } + if (block->getRank() == grid->getRank()) { + if (block->isActive()) { + interactor->setBCBlock(block); + } + } } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.h index 5db362a3b..feda68310 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetBcBlocksBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -46,15 +46,12 @@ class Interactor3D; class SetBcBlocksBlockVisitor : public Block3DVisitor { public: - SetBcBlocksBlockVisitor(SPtr<Interactor3D> interactor); - ~SetBcBlocksBlockVisitor() override = default; + SetBcBlocksBlockVisitor(SPtr<Interactor3D> interactor); + ~SetBcBlocksBlockVisitor() override = default; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - SPtr<Interactor3D> interactor; + SPtr<Interactor3D> interactor; }; #endif // SetBcBlocksBlockVisitor_h__ - - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.cpp index c6f1f9608..067b93bba 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -32,487 +32,484 @@ //======================================================================================= #include "SetConnectorsBlockVisitor.h" -#include "D3Q27ETFullDirectConnector.h" -#include "D3Q27ETFullVectorConnector.h" #include "D3Q27ETCFOffVectorConnector.h" #include "D3Q27ETFCOffVectorConnector.h" +#include "D3Q27ETFullDirectConnector.h" +#include "D3Q27ETFullVectorConnector.h" #include "Grid3DSystem.h" #include <basics/transmitter/TbTransmitterLocal.h> #include "Communicator.h" #include "InterpolationProcessor.h" -SetConnectorsBlockVisitor::SetConnectorsBlockVisitor(SPtr<Communicator> comm, bool fullConnector, int dirs, - LBMReal nue, InterpolationProcessorPtr iProcessor) : -Block3DVisitor(0, Grid3DSystem::MAXLEVEL), - comm(comm), - fullConnector(fullConnector), - dirs(dirs), - nue(nue), - iProcessor(iProcessor) +SetConnectorsBlockVisitor::SetConnectorsBlockVisitor(SPtr<Communicator> comm, bool fullConnector, int dirs, LBMReal nue, + InterpolationProcessorPtr iProcessor) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), comm(comm), fullConnector(fullConnector), dirs(dirs), nue(nue), + iProcessor(iProcessor) { } ////////////////////////////////////////////////////////////////////////// -SetConnectorsBlockVisitor::~SetConnectorsBlockVisitor(void) -= default; +SetConnectorsBlockVisitor::~SetConnectorsBlockVisitor(void) = default; ////////////////////////////////////////////////////////////////////////// void SetConnectorsBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if(!block) return; + if (!block) + return; - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::visit() - start"); - UBLOG(logDEBUG5, block->toString()); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::visit() - start"); + UBLOG(logDEBUG5, block->toString()); - gridRank = comm->getProcessID(); - grid->setRank(gridRank); + gridRank = comm->getProcessID(); + grid->setRank(gridRank); - setSameLevelConnectors(grid, block); + setSameLevelConnectors(grid, block); - if(grid->getFinestInitializedLevel() > grid->getCoarsestInitializedLevel()) - setInterpolationConnectors(grid, block); + if (grid->getFinestInitializedLevel() > grid->getCoarsestInitializedLevel()) + setInterpolationConnectors(grid, block); - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::visit() - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::visit() - end"); } ////////////////////////////////////////////////////////////////////////// void SetConnectorsBlockVisitor::setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block) { - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setSameLevelConnectors() - start"); - int blockRank = block->getRank(); - if (gridRank == blockRank && block->isActive()) - { - block->clearWeight(); - std::vector<SPtr<Block3D>> neighbors; - int ix1 = block->getX1(); - int ix2 = block->getX2(); - int ix3 = block->getX3(); - int level = block->getLevel(); - //grid->getAllNeighbors(ix1, ix2, ix3, level, level, neighbors); - - //if (block->getGlobalID()==2512) - //{ - // int test = 0; - //} - - for( int dir = 0; dir < dirs; dir++) - { - SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); - - if(neighBlock) - { - int neighBlockRank = neighBlock->getRank(); - if(blockRank == neighBlockRank && neighBlock->isActive()) - { - SPtr<Block3DConnector> connector; - connector = SPtr<Block3DConnector>(new D3Q27ETFullDirectConnector( block, neighBlock, dir)); - block->setConnector(connector); - } - else if(blockRank != neighBlockRank && neighBlock->isActive()) - { - setRemoteConnectors(block, neighBlock, dir, fullConnector); - - if(dir >=0 && dir<=5) - { - int weight = block->getWeight(neighBlockRank); - weight++; - block->setWeight(neighBlockRank, weight); - } - } - } - } - - //if (block->getGlobalID()==2794) - //{ - // UBLOG(logINFO, block->toString()); - //} - - int weight = block->getNumberOfLocalConnectorsForSurfaces(); - weight = 6 - weight; - block->addWeightForAll(weight); - } - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setSameLevelConnectors() - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setSameLevelConnectors() - start"); + int blockRank = block->getRank(); + if (gridRank == blockRank && block->isActive()) { + block->clearWeight(); + std::vector<SPtr<Block3D>> neighbors; + int ix1 = block->getX1(); + int ix2 = block->getX2(); + int ix3 = block->getX3(); + int level = block->getLevel(); + // grid->getAllNeighbors(ix1, ix2, ix3, level, level, neighbors); + + // if (block->getGlobalID()==2512) + //{ + // int test = 0; + //} + + for (int dir = 0; dir < dirs; dir++) { + SPtr<Block3D> neighBlock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); + + if (neighBlock) { + int neighBlockRank = neighBlock->getRank(); + if (blockRank == neighBlockRank && neighBlock->isActive()) { + SPtr<Block3DConnector> connector; + connector = SPtr<Block3DConnector>(new D3Q27ETFullDirectConnector(block, neighBlock, dir)); + block->setConnector(connector); + } else if (blockRank != neighBlockRank && neighBlock->isActive()) { + setRemoteConnectors(block, neighBlock, dir, fullConnector); + + if (dir >= 0 && dir <= 5) { + int weight = block->getWeight(neighBlockRank); + weight++; + block->setWeight(neighBlockRank, weight); + } + } + } + } + + // if (block->getGlobalID()==2794) + //{ + // UBLOG(logINFO, block->toString()); + //} + + int weight = block->getNumberOfLocalConnectorsForSurfaces(); + weight = 6 - weight; + block->addWeightForAll(weight); + } + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setSameLevelConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// -void SetConnectorsBlockVisitor::setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir, bool /*fullConnector*/) +void SetConnectorsBlockVisitor::setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir, + bool /*fullConnector*/) { - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setRemoteConnectors() - start"); - CreateTransmittersHelper helper; - CreateTransmittersHelper::TransmitterPtr sender, receiver; - helper.createTransmitters(sblock, tblock, dir, CreateTransmittersHelper::NONE, sender, receiver, comm, CreateTransmittersHelper::MPI); - - - SPtr<Block3DConnector> connector; - connector = SPtr<Block3DConnector>(new D3Q27ETFullVectorConnector(sblock, sender, receiver, dir)); - sblock->setConnector(connector); - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setRemoteConnectors() - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setRemoteConnectors() - start"); + CreateTransmittersHelper helper; + CreateTransmittersHelper::TransmitterPtr sender, receiver; + helper.createTransmitters(sblock, tblock, dir, CreateTransmittersHelper::NONE, sender, receiver, comm, + CreateTransmittersHelper::MPI); + + SPtr<Block3DConnector> connector; + connector = SPtr<Block3DConnector>(new D3Q27ETFullVectorConnector(sblock, sender, receiver, dir)); + sblock->setConnector(connector); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setRemoteConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// void SetConnectorsBlockVisitor::setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block) { - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors() - start"); -// int blockRank = block->getRank(); -// if (block->getGlobalID()==394) -// { -// int test=0; -// } - - //search for all blocks with different ranks - if (block->hasInterpolationFlagCF() && block->isActive()) - { - int fbx1 = block->getX1() << 1; - int fbx2 = block->getX2() << 1; - int fbx3 = block->getX3() << 1; - int level = block->getLevel() + 1; - - if( block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1+1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::E); - } - if( block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1,fbx2+1,fbx3+1,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::W); - } - if( block->hasInterpolationFlagCF(D3Q27System::N)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::N); - } - if( block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1+1,fbx2,fbx3+1,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::S); - } - if( block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::T); - } - if( block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3,level); - SPtr<Block3D> fblockNW = grid->getBlock(fbx1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNE = grid->getBlock(fbx1+1,fbx2+1,fbx3,level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::B); - } - - //////NE-NW-SE-SW - if( block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1,fbx2+1,fbx3+0,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::NE); - } - if( block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::SW); - } - if( block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1,fbx2,fbx3+0,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::SE); - } - if( block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::NW); - } - - /////////TE-BW-BE-TW 1-0 - if( block->hasInterpolationFlagCF(D3Q27System::TE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1,fbx2+0,fbx3+1,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2+0, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TE); - } - if( block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2+0,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2+0, fbx3, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2+1, fbx3, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BW); - } - if( block->hasInterpolationFlagCF(D3Q27System::BE)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1,fbx2+0,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2+0, fbx3, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BE); - } - if( block->hasInterpolationFlagCF(D3Q27System::TW)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1,fbx2+0,fbx3+1,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2+0, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TW); - } - - //////TN-BS-BN-TS - if( block->hasInterpolationFlagCF(D3Q27System::TN)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+0,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+0, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TN); - } - if( block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::S) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+0,fbx2,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+0, fbx2, fbx3, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2, fbx3, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BS); - } - if( block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::B)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+0,fbx2+1,fbx3,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2+1,fbx3,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+0, fbx2+1, fbx3, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BN); - } - if( block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::S) && !block->hasInterpolationFlagCF(D3Q27System::T)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+0,fbx2,fbx3+1,level); - SPtr<Block3D> fblockSE = grid->getBlock(fbx1+1,fbx2,fbx3+1,level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+0, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TS); - } - - - - - //////corners - if (block->hasInterpolationFlagCF(D3Q27System::TNE)&&!block->hasInterpolationFlagCF(D3Q27System::TE)&&!block->hasInterpolationFlagCF(D3Q27System::TN)&&!block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::T)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TNE); - } - if (block->hasInterpolationFlagCF(D3Q27System::TSW)&&!block->hasInterpolationFlagCF(D3Q27System::TW)&&!block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TSW); - } - if (block->hasInterpolationFlagCF(D3Q27System::TSE)&&!block->hasInterpolationFlagCF(D3Q27System::TE)&&!block->hasInterpolationFlagCF(D3Q27System::TS)&& !block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TSE); - } - if (block->hasInterpolationFlagCF(D3Q27System::TNW)&&!block->hasInterpolationFlagCF(D3Q27System::TW)&&!block->hasInterpolationFlagCF(D3Q27System::TN)&& !block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::T)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TNW); - } - if (block->hasInterpolationFlagCF(D3Q27System::BNE)&&!block->hasInterpolationFlagCF(D3Q27System::BE)&&!block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::NE)&&!block->hasInterpolationFlagCF(D3Q27System::B)&&!block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::E)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BNE); - } - if (block->hasInterpolationFlagCF(D3Q27System::BSW)&& !block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::SW)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::W) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3+0, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1, fbx2, fbx3, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BSW); - } - if (block->hasInterpolationFlagCF(D3Q27System::BSE)&& !block->hasInterpolationFlagCF(D3Q27System::BS)&& !block->hasInterpolationFlagCF(D3Q27System::BE)&& !block->hasInterpolationFlagCF(D3Q27System::SE)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::E) && !block->hasInterpolationFlagCF(D3Q27System::S)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1+1, fbx2, fbx3, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BSE); - } - if (block->hasInterpolationFlagCF(D3Q27System::BNW)&& !block->hasInterpolationFlagCF(D3Q27System::BN)&& !block->hasInterpolationFlagCF(D3Q27System::BW)&& !block->hasInterpolationFlagCF(D3Q27System::NW)&& !block->hasInterpolationFlagCF(D3Q27System::B)&& !block->hasInterpolationFlagCF(D3Q27System::N) && !block->hasInterpolationFlagCF(D3Q27System::W)) - { - SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2+1, fbx3+0, level); - SPtr<Block3D> fblockSE;// = grid->getBlock(fbx1, fbx2+1, fbx3, level); - SPtr<Block3D> fblockNW;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - SPtr<Block3D> fblockNE;// = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); - - setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BNW); - } - - } - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors() - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors() - start"); + // int blockRank = block->getRank(); + // if (block->getGlobalID()==394) + // { + // int test=0; + // } + + // search for all blocks with different ranks + if (block->hasInterpolationFlagCF() && block->isActive()) { + int fbx1 = block->getX1() << 1; + int fbx2 = block->getX2() << 1; + int fbx3 = block->getX3() << 1; + int level = block->getLevel() + 1; + + if (block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::E); + } + if (block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::W); + } + if (block->hasInterpolationFlagCF(D3Q27System::N)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::N); + } + if (block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::S); + } + if (block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::T); + } + if (block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblockNW = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::B); + } + + //////NE-NW-SE-SW + if (block->hasInterpolationFlagCF(D3Q27System::NE) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::NE); + } + if (block->hasInterpolationFlagCF(D3Q27System::SW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::SW); + } + if (block->hasInterpolationFlagCF(D3Q27System::SE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 0, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::SE); + } + if (block->hasInterpolationFlagCF(D3Q27System::NW) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::NW); + } + + /////////TE-BW-BE-TW 1-0 + if (block->hasInterpolationFlagCF(D3Q27System::TE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2 + 0, fbx3 + 1, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2+0, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 0, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2+0, fbx3, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2+1, fbx3, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BE) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2 + 0, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2+0, fbx3, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TW) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 0, fbx3 + 1, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2+0, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TW); + } + + //////TN-BS-BN-TS + if (block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 0, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+0, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TN); + } + if (block->hasInterpolationFlagCF(D3Q27System::BS) && !block->hasInterpolationFlagCF(D3Q27System::S) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 0, fbx2, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+0, fbx2, fbx3, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2, fbx3, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BS); + } + if (block->hasInterpolationFlagCF(D3Q27System::BN) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::B)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 0, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+0, fbx2+1, fbx3, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BN); + } + if (block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::S) && + !block->hasInterpolationFlagCF(D3Q27System::T)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 0, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockSE = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+0, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TS); + } + + //////corners + if (block->hasInterpolationFlagCF(D3Q27System::TNE) && !block->hasInterpolationFlagCF(D3Q27System::TE) && + !block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::NE) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TNE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TSW) && !block->hasInterpolationFlagCF(D3Q27System::TW) && + !block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::SW) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TSW); + } + if (block->hasInterpolationFlagCF(D3Q27System::TSE) && !block->hasInterpolationFlagCF(D3Q27System::TE) && + !block->hasInterpolationFlagCF(D3Q27System::TS) && !block->hasInterpolationFlagCF(D3Q27System::SE) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2, fbx3 + 1, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TSE); + } + if (block->hasInterpolationFlagCF(D3Q27System::TNW) && !block->hasInterpolationFlagCF(D3Q27System::TW) && + !block->hasInterpolationFlagCF(D3Q27System::TN) && !block->hasInterpolationFlagCF(D3Q27System::NW) && + !block->hasInterpolationFlagCF(D3Q27System::T) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 1, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1, fbx2+1, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::TNW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BNE) && !block->hasInterpolationFlagCF(D3Q27System::BE) && + !block->hasInterpolationFlagCF(D3Q27System::BN) && !block->hasInterpolationFlagCF(D3Q27System::NE) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::E)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+0, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BNE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BSW) && !block->hasInterpolationFlagCF(D3Q27System::BS) && + !block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::SW) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::W) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2, fbx3 + 0, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1, fbx2, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BSW); + } + if (block->hasInterpolationFlagCF(D3Q27System::BSE) && !block->hasInterpolationFlagCF(D3Q27System::BS) && + !block->hasInterpolationFlagCF(D3Q27System::BE) && !block->hasInterpolationFlagCF(D3Q27System::SE) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::E) && + !block->hasInterpolationFlagCF(D3Q27System::S)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1 + 1, fbx2, fbx3, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1+1, fbx2, fbx3+0, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1+1, fbx2, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BSE); + } + if (block->hasInterpolationFlagCF(D3Q27System::BNW) && !block->hasInterpolationFlagCF(D3Q27System::BN) && + !block->hasInterpolationFlagCF(D3Q27System::BW) && !block->hasInterpolationFlagCF(D3Q27System::NW) && + !block->hasInterpolationFlagCF(D3Q27System::B) && !block->hasInterpolationFlagCF(D3Q27System::N) && + !block->hasInterpolationFlagCF(D3Q27System::W)) { + SPtr<Block3D> fblockSW = grid->getBlock(fbx1, fbx2 + 1, fbx3 + 0, level); + SPtr<Block3D> fblockSE; // = grid->getBlock(fbx1, fbx2+1, fbx3, level); + SPtr<Block3D> fblockNW; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + SPtr<Block3D> fblockNE; // = grid->getBlock(fbx1, fbx2+1, fbx3+1, level); + + setInterpolationConnectors(fblockSW, fblockSE, fblockNW, fblockNE, block, D3Q27System::BNW); + } + } + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors() - end"); } ////////////////////////////////////////////////////////////////////////// -void SetConnectorsBlockVisitor::setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, SPtr<Block3D> fBlockNW, SPtr<Block3D> fBlockNE, SPtr<Block3D> cBlock, int dir) +void SetConnectorsBlockVisitor::setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, + SPtr<Block3D> fBlockNW, SPtr<Block3D> fBlockNE, + SPtr<Block3D> cBlock, int dir) { - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors(...) - start"); - int fBlockSWRank = -999, fBlockSERank = -999, fBlockNWRank = -999, fBlockNERank = -999; - if(fBlockSW) fBlockSWRank = fBlockSW->getRank(); - if(fBlockNW) fBlockNWRank = fBlockNW->getRank(); - if(fBlockSE) fBlockSERank = fBlockSE->getRank(); - if(fBlockNE) fBlockNERank = fBlockNE->getRank(); - int cBlockRank = cBlock->getRank(); - - LBMReal omegaF; - if(fBlockSW) omegaF =LBMSystem::calcCollisionFactor(nue, fBlockSW->getLevel()); - if(fBlockNW) omegaF =LBMSystem::calcCollisionFactor(nue, fBlockNW->getLevel()); - if(fBlockSE) omegaF =LBMSystem::calcCollisionFactor(nue, fBlockSE->getLevel()); - if(fBlockNE) omegaF =LBMSystem::calcCollisionFactor(nue, fBlockNE->getLevel()); - LBMReal omegaC = LBMSystem::calcCollisionFactor(nue, cBlock->getLevel()); - iProcessor->setOmegas(omegaC, omegaF); - - InterpolationProcessorPtr cIProcessor(iProcessor->clone()); - InterpolationProcessorPtr fIProcessorSW(iProcessor->clone()); - InterpolationProcessorPtr fIProcessorSE(iProcessor->clone()); - InterpolationProcessorPtr fIProcessorNW(iProcessor->clone()); - InterpolationProcessorPtr fIProcessorNE(iProcessor->clone()); - - CreateTransmittersHelper::TransmitterPtr senderCFevenEvenSW, receiverCFevenEvenSW, - senderCFevenOddNW, receiverCFevenOddNW, - senderCFoddEvenSE, receiverCFoddEvenSE, - senderCFoddOddNE, receiverCFoddOddNE, - senderFCevenEvenSW, receiverFCevenEvenSW, - senderFCevenOddNW, receiverFCevenOddNW, - senderFCoddEvenSE, receiverFCoddEvenSE, - senderFCoddOddNE, receiverFCoddOddNE; - - if(fBlockSW) createTransmitters(cBlock, fBlockSW, dir, CreateTransmittersHelper::SW, senderCFevenEvenSW, receiverCFevenEvenSW, senderFCevenEvenSW, receiverFCevenEvenSW); - if(fBlockNW) createTransmitters(cBlock, fBlockNW, dir, CreateTransmittersHelper::NW, senderCFevenOddNW, receiverCFevenOddNW, senderFCevenOddNW, receiverFCevenOddNW); - if(fBlockSE) createTransmitters(cBlock, fBlockSE, dir, CreateTransmittersHelper::SE, senderCFoddEvenSE, receiverCFoddEvenSE, senderFCoddEvenSE, receiverFCoddEvenSE); - if(fBlockNE) createTransmitters(cBlock, fBlockNE, dir, CreateTransmittersHelper::NE, senderCFoddOddNE, receiverCFoddOddNE, senderFCoddOddNE, receiverFCoddOddNE); - - if(cBlockRank == gridRank) - { - SPtr<Block3DConnector> connector(new D3Q27ETCFOffVectorConnector< TbTransmitter< CbVector< LBMReal > > >(cBlock, - senderCFevenEvenSW, receiverCFevenEvenSW, senderCFevenOddNW, receiverCFevenOddNW, - senderCFoddEvenSE, receiverCFoddEvenSE, senderCFoddOddNE, receiverCFoddOddNE, - dir, cIProcessor) ); - cBlock->setConnector(connector); - } - if(fBlockSW && fBlockSWRank == gridRank) - { - SPtr<Block3DConnector> connector( new D3Q27ETFCOffVectorConnector< TbTransmitter< CbVector< LBMReal > > >(fBlockSW, - senderFCevenEvenSW, receiverFCevenEvenSW, dir, fIProcessorSW, EvenEvenSW) ); - fBlockSW->setConnector(connector); - } - if(fBlockNW && fBlockNWRank == gridRank) - { - SPtr<Block3DConnector> connector( new D3Q27ETFCOffVectorConnector< TbTransmitter< CbVector< LBMReal > > >(fBlockNW, - senderFCevenOddNW, receiverFCevenOddNW, dir, fIProcessorNW, EvenOddNW) ); - fBlockNW->setConnector(connector); - } - if(fBlockSE && fBlockSERank == gridRank) - { - SPtr<Block3DConnector> connector( new D3Q27ETFCOffVectorConnector< TbTransmitter< CbVector< LBMReal > > >(fBlockSE, - senderFCoddEvenSE, receiverFCoddEvenSE, dir, fIProcessorSE, OddEvenSE) ); - fBlockSE->setConnector(connector); - } - if(fBlockNE && fBlockNERank == gridRank) - { - SPtr<Block3DConnector> connector( new D3Q27ETFCOffVectorConnector< TbTransmitter< CbVector< LBMReal > > >(fBlockNE, - senderFCoddOddNE, receiverFCoddOddNE, dir, fIProcessorNE, OddOddNE) ); - fBlockNE->setConnector(connector); - } - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors(...) - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors(...) - start"); + int fBlockSWRank = -999, fBlockSERank = -999, fBlockNWRank = -999, fBlockNERank = -999; + if (fBlockSW) + fBlockSWRank = fBlockSW->getRank(); + if (fBlockNW) + fBlockNWRank = fBlockNW->getRank(); + if (fBlockSE) + fBlockSERank = fBlockSE->getRank(); + if (fBlockNE) + fBlockNERank = fBlockNE->getRank(); + int cBlockRank = cBlock->getRank(); + + LBMReal omegaF; + if (fBlockSW) + omegaF = LBMSystem::calcCollisionFactor(nue, fBlockSW->getLevel()); + if (fBlockNW) + omegaF = LBMSystem::calcCollisionFactor(nue, fBlockNW->getLevel()); + if (fBlockSE) + omegaF = LBMSystem::calcCollisionFactor(nue, fBlockSE->getLevel()); + if (fBlockNE) + omegaF = LBMSystem::calcCollisionFactor(nue, fBlockNE->getLevel()); + LBMReal omegaC = LBMSystem::calcCollisionFactor(nue, cBlock->getLevel()); + iProcessor->setOmegas(omegaC, omegaF); + + InterpolationProcessorPtr cIProcessor(iProcessor->clone()); + InterpolationProcessorPtr fIProcessorSW(iProcessor->clone()); + InterpolationProcessorPtr fIProcessorSE(iProcessor->clone()); + InterpolationProcessorPtr fIProcessorNW(iProcessor->clone()); + InterpolationProcessorPtr fIProcessorNE(iProcessor->clone()); + + CreateTransmittersHelper::TransmitterPtr senderCFevenEvenSW, receiverCFevenEvenSW, senderCFevenOddNW, + receiverCFevenOddNW, senderCFoddEvenSE, receiverCFoddEvenSE, senderCFoddOddNE, receiverCFoddOddNE, + senderFCevenEvenSW, receiverFCevenEvenSW, senderFCevenOddNW, receiverFCevenOddNW, senderFCoddEvenSE, + receiverFCoddEvenSE, senderFCoddOddNE, receiverFCoddOddNE; + + if (fBlockSW) + createTransmitters(cBlock, fBlockSW, dir, CreateTransmittersHelper::SW, senderCFevenEvenSW, + receiverCFevenEvenSW, senderFCevenEvenSW, receiverFCevenEvenSW); + if (fBlockNW) + createTransmitters(cBlock, fBlockNW, dir, CreateTransmittersHelper::NW, senderCFevenOddNW, receiverCFevenOddNW, + senderFCevenOddNW, receiverFCevenOddNW); + if (fBlockSE) + createTransmitters(cBlock, fBlockSE, dir, CreateTransmittersHelper::SE, senderCFoddEvenSE, receiverCFoddEvenSE, + senderFCoddEvenSE, receiverFCoddEvenSE); + if (fBlockNE) + createTransmitters(cBlock, fBlockNE, dir, CreateTransmittersHelper::NE, senderCFoddOddNE, receiverCFoddOddNE, + senderFCoddOddNE, receiverFCoddOddNE); + + if (cBlockRank == gridRank) { + SPtr<Block3DConnector> connector(new D3Q27ETCFOffVectorConnector<TbTransmitter<CbVector<LBMReal>>>( + cBlock, senderCFevenEvenSW, receiverCFevenEvenSW, senderCFevenOddNW, receiverCFevenOddNW, senderCFoddEvenSE, + receiverCFoddEvenSE, senderCFoddOddNE, receiverCFoddOddNE, dir, cIProcessor)); + cBlock->setConnector(connector); + } + if (fBlockSW && fBlockSWRank == gridRank) { + SPtr<Block3DConnector> connector(new D3Q27ETFCOffVectorConnector<TbTransmitter<CbVector<LBMReal>>>( + fBlockSW, senderFCevenEvenSW, receiverFCevenEvenSW, dir, fIProcessorSW, EvenEvenSW)); + fBlockSW->setConnector(connector); + } + if (fBlockNW && fBlockNWRank == gridRank) { + SPtr<Block3DConnector> connector(new D3Q27ETFCOffVectorConnector<TbTransmitter<CbVector<LBMReal>>>( + fBlockNW, senderFCevenOddNW, receiverFCevenOddNW, dir, fIProcessorNW, EvenOddNW)); + fBlockNW->setConnector(connector); + } + if (fBlockSE && fBlockSERank == gridRank) { + SPtr<Block3DConnector> connector(new D3Q27ETFCOffVectorConnector<TbTransmitter<CbVector<LBMReal>>>( + fBlockSE, senderFCoddEvenSE, receiverFCoddEvenSE, dir, fIProcessorSE, OddEvenSE)); + fBlockSE->setConnector(connector); + } + if (fBlockNE && fBlockNERank == gridRank) { + SPtr<Block3DConnector> connector(new D3Q27ETFCOffVectorConnector<TbTransmitter<CbVector<LBMReal>>>( + fBlockNE, senderFCoddOddNE, receiverFCoddOddNE, dir, fIProcessorNE, OddOddNE)); + fBlockNE->setConnector(connector); + } + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::setInterpolationConnectors(...) - end"); } ////////////////////////////////////////////////////////////////////////// -void SetConnectorsBlockVisitor::createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, - CreateTransmittersHelper::IBlock ib, - CreateTransmittersHelper::TransmitterPtr& senderCF, - CreateTransmittersHelper::TransmitterPtr& receiverCF, - CreateTransmittersHelper::TransmitterPtr& senderFC, - CreateTransmittersHelper::TransmitterPtr& receiverFC) +void SetConnectorsBlockVisitor::createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, + CreateTransmittersHelper::IBlock ib, + CreateTransmittersHelper::TransmitterPtr &senderCF, + CreateTransmittersHelper::TransmitterPtr &receiverCF, + CreateTransmittersHelper::TransmitterPtr &senderFC, + CreateTransmittersHelper::TransmitterPtr &receiverFC) { - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::createTransmitters(...) - start"); - CreateTransmittersHelper helper; -// bool MPIpool = true; -// bool orthogonal = false; - int fBlockRank = fBlock->getRank(); - int cBlockRank = cBlock->getRank(); - if(fBlockRank == cBlockRank && fBlockRank == gridRank) - { - senderCF = receiverFC = CreateTransmittersHelper::TransmitterPtr( new TbLocalTransmitter< CbVector< LBMReal > >()); - senderFC = receiverCF = CreateTransmittersHelper::TransmitterPtr( new TbLocalTransmitter< CbVector< LBMReal > >()); - } - else if(cBlockRank == gridRank) - { - helper.createTransmitters(cBlock, fBlock, dir, ib, senderCF, receiverCF, comm, CreateTransmittersHelper::MPI); - } - else if(fBlockRank == gridRank) - { - helper.createTransmitters(fBlock, cBlock, dir, ib, senderFC, receiverFC, comm, CreateTransmittersHelper::MPI); - } - UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::createTransmitters(...) - end"); + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::createTransmitters(...) - start"); + CreateTransmittersHelper helper; + // bool MPIpool = true; + // bool orthogonal = false; + int fBlockRank = fBlock->getRank(); + int cBlockRank = cBlock->getRank(); + if (fBlockRank == cBlockRank && fBlockRank == gridRank) { + senderCF = receiverFC = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + senderFC = receiverCF = CreateTransmittersHelper::TransmitterPtr(new TbLocalTransmitter<CbVector<LBMReal>>()); + } else if (cBlockRank == gridRank) { + helper.createTransmitters(cBlock, fBlock, dir, ib, senderCF, receiverCF, comm, CreateTransmittersHelper::MPI); + } else if (fBlockRank == gridRank) { + helper.createTransmitters(fBlock, cBlock, dir, ib, senderFC, receiverFC, comm, CreateTransmittersHelper::MPI); + } + UBLOG(logDEBUG5, "D3Q27SetConnectorsBlockVisitor::createTransmitters(...) - end"); } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h index 7e7f13931..9d855de05 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetConnectorsBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -50,27 +50,28 @@ class InterpolationProcessor; class SetConnectorsBlockVisitor : public Block3DVisitor { public: - SetConnectorsBlockVisitor(SPtr<Communicator> comm, bool fullConnector, int dirs, LBMReal nue, SPtr<InterpolationProcessor> iProcessor); - ~SetConnectorsBlockVisitor() override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - ////////////////////////////////////////////////////////////////////////// + SetConnectorsBlockVisitor(SPtr<Communicator> comm, bool fullConnector, int dirs, LBMReal nue, + SPtr<InterpolationProcessor> iProcessor); + ~SetConnectorsBlockVisitor() override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + ////////////////////////////////////////////////////////////////////////// protected: - void setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); - void setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir, bool fullConnector); - void setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); - void setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, SPtr<Block3D> fBlockNW, SPtr<Block3D> fBlockNE, SPtr<Block3D> cBlock, int dir); - void createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, - CreateTransmittersHelper::IBlock ib, - CreateTransmittersHelper::TransmitterPtr& senderCF, - CreateTransmittersHelper::TransmitterPtr& receiverCF, - CreateTransmittersHelper::TransmitterPtr& senderFC, - CreateTransmittersHelper::TransmitterPtr& receiverFC); + void setSameLevelConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); + void setRemoteConnectors(SPtr<Block3D> sblock, SPtr<Block3D> tblock, int dir, bool fullConnector); + void setInterpolationConnectors(SPtr<Grid3D> grid, SPtr<Block3D> block); + void setInterpolationConnectors(SPtr<Block3D> fBlockSW, SPtr<Block3D> fBlockSE, SPtr<Block3D> fBlockNW, + SPtr<Block3D> fBlockNE, SPtr<Block3D> cBlock, int dir); + void createTransmitters(SPtr<Block3D> cBlock, SPtr<Block3D> fBlock, int dir, CreateTransmittersHelper::IBlock ib, + CreateTransmittersHelper::TransmitterPtr &senderCF, + CreateTransmittersHelper::TransmitterPtr &receiverCF, + CreateTransmittersHelper::TransmitterPtr &senderFC, + CreateTransmittersHelper::TransmitterPtr &receiverFC); SPtr<Communicator> comm; - bool fullConnector; - int dirs; - int gridRank; - LBMReal nue; + bool fullConnector; + int dirs; + int gridRank; + LBMReal nue; SPtr<InterpolationProcessor> iProcessor; }; -#endif //SETCONNECTORSBLOCKVISITOR_H +#endif // SETCONNECTORSBLOCKVISITOR_H diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.cpp index ec83d8de4..679b63de4 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.cpp @@ -1,70 +1,64 @@ #include "SetForcingBlockVisitor.h" +#include "Block3D.h" +#include "Grid3D.h" #include "Grid3DSystem.h" #include "LBMSystem.h" -#include "Grid3D.h" -#include "Block3D.h" -SetForcingBlockVisitor::SetForcingBlockVisitor(LBMReal forcingX1, LBMReal forcingX2, LBMReal forcingX3) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), forcingX1(forcingX1), - forcingX2(forcingX2), - forcingX3(forcingX3) +SetForcingBlockVisitor::SetForcingBlockVisitor(LBMReal forcingX1, LBMReal forcingX2, LBMReal forcingX3) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), forcingX1(forcingX1), forcingX2(forcingX2), forcingX3(forcingX3) { - ftype = 0; + ftype = 0; } ////////////////////////////////////////////////////////////////////////// -SetForcingBlockVisitor::SetForcingBlockVisitor(const mu::Parser& muForcingX1, const mu::Parser& muForcingX2, const mu::Parser& muForcingX3) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), muForcingX1(muForcingX1), - muForcingX2(muForcingX2), - muForcingX3(muForcingX3) +SetForcingBlockVisitor::SetForcingBlockVisitor(const mu::Parser &muForcingX1, const mu::Parser &muForcingX2, + const mu::Parser &muForcingX3) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), muForcingX1(muForcingX1), muForcingX2(muForcingX2), + muForcingX3(muForcingX3) { - ftype = 1; + ftype = 1; } ////////////////////////////////////////////////////////////////////////// -SetForcingBlockVisitor::SetForcingBlockVisitor(const std::string& sForcingX1, const std::string& sForcingX2, const std::string& sForcingX3) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), sForcingX1(sForcingX1), - sForcingX2(sForcingX2), - sForcingX3(sForcingX3) +SetForcingBlockVisitor::SetForcingBlockVisitor(const std::string &sForcingX1, const std::string &sForcingX2, + const std::string &sForcingX3) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), sForcingX1(sForcingX1), sForcingX2(sForcingX2), sForcingX3(sForcingX3) { - ftype = 2; + ftype = 2; } ////////////////////////////////////////////////////////////////////////// void SetForcingBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if(block->getRank() == grid->getRank()) - { - SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); - if (!kernel) - throw UbException(UB_EXARGS, "LBMKernel is not exist"); + if (block->getRank() == grid->getRank()) { + SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); + if (!kernel) + throw UbException(UB_EXARGS, "LBMKernel is not exist"); - switch (ftype) - { - case 0: - kernel->setForcingX1(forcingX1); - kernel->setForcingX2(forcingX2); - kernel->setForcingX3(forcingX3); - kernel->setWithForcing(true); - break; - case 1: - kernel->setForcingX1(muForcingX1); - kernel->setForcingX2(muForcingX2); - kernel->setForcingX3(muForcingX3); - kernel->setWithForcing(true); - break; - case 2: - kernel->setForcingX1(sForcingX1); - kernel->setForcingX2(sForcingX2); - kernel->setForcingX3(sForcingX3); - kernel->setWithForcing(true); - break; - default: - kernel->setForcingX1(0.0); - kernel->setForcingX2(0.0); - kernel->setForcingX3(0.0); - kernel->setWithForcing(false); - break; - } - } + switch (ftype) { + case 0: + kernel->setForcingX1(forcingX1); + kernel->setForcingX2(forcingX2); + kernel->setForcingX3(forcingX3); + kernel->setWithForcing(true); + break; + case 1: + kernel->setForcingX1(muForcingX1); + kernel->setForcingX2(muForcingX2); + kernel->setForcingX3(muForcingX3); + kernel->setWithForcing(true); + break; + case 2: + kernel->setForcingX1(sForcingX1); + kernel->setForcingX2(sForcingX2); + kernel->setForcingX3(sForcingX3); + kernel->setWithForcing(true); + break; + default: + kernel->setForcingX1(0.0); + kernel->setForcingX2(0.0); + kernel->setForcingX3(0.0); + kernel->setWithForcing(false); + break; + } + } } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.h index ac8936a13..a6d13c2a7 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetForcingBlockVisitor.h @@ -8,32 +8,32 @@ class Block3D; class Grid3D; //! \brief Set forcing for all kernels of grid -//! \details This visitor is useful if you need to set or reset forcing in kernels (e.g. after restart because forcing is not serializable). -//! \author K. Kucher +//! \details This visitor is useful if you need to set or reset forcing in kernels (e.g. after restart because forcing +//! is not serializable). \author K. Kucher class SetForcingBlockVisitor : public Block3DVisitor { public: - SetForcingBlockVisitor(LBMReal forcingX1, LBMReal forcingX2, LBMReal forcingX3); - - SetForcingBlockVisitor(const mu::Parser& muForcingX1, const mu::Parser& muForcingX2, const mu::Parser& muForcingX3); + SetForcingBlockVisitor(LBMReal forcingX1, LBMReal forcingX2, LBMReal forcingX3); - SetForcingBlockVisitor(const std::string& sForcingX1, const std::string& sForcingX2, const std::string& sForcingX3); + SetForcingBlockVisitor(const mu::Parser &muForcingX1, const mu::Parser &muForcingX2, const mu::Parser &muForcingX3); - ~SetForcingBlockVisitor() override = default; + SetForcingBlockVisitor(const std::string &sForcingX1, const std::string &sForcingX2, const std::string &sForcingX3); - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + ~SetForcingBlockVisitor() override = default; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - int ftype; - LBMReal forcingX1; - LBMReal forcingX2; - LBMReal forcingX3; - mu::Parser muForcingX1; - mu::Parser muForcingX2; - mu::Parser muForcingX3; - std::string sForcingX1; - std::string sForcingX2; - std::string sForcingX3; + int ftype; + LBMReal forcingX1; + LBMReal forcingX2; + LBMReal forcingX3; + mu::Parser muForcingX1; + mu::Parser muForcingX2; + mu::Parser muForcingX3; + std::string sForcingX1; + std::string sForcingX2; + std::string sForcingX3; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.cpp index eeb1ba691..bb1ae7962 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.cpp @@ -1,131 +1,148 @@ #include "SetInterpolationDirsBlockVisitor.h" +#include "Block3D.h" +#include "Grid3D.h" #include "Grid3DSystem.h" #include <D3Q27System.h> -#include "Grid3D.h" -#include "Block3D.h" - -SetInterpolationDirsBlockVisitor::SetInterpolationDirsBlockVisitor(std::vector<int>& dirs) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), dirs(dirs) +SetInterpolationDirsBlockVisitor::SetInterpolationDirsBlockVisitor(std::vector<int> &dirs) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), dirs(dirs) { - } ////////////////////////////////////////////////////////////////////////// void SetInterpolationDirsBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - int ix1, ix2, ix3, level; - ix1 = block->getX1(); - ix2 = block->getX2(); - ix3 = block->getX3(); - level = block->getLevel(); - using namespace D3Q27System; - if(level==0) return; + int ix1, ix2, ix3, level; + ix1 = block->getX1(); + ix2 = block->getX2(); + ix3 = block->getX3(); + level = block->getLevel(); + using namespace D3Q27System; + if (level == 0) + return; - SPtr<Block3D> parentblock = grid->getSuperBlock(ix1,ix2,ix3,level); - if(!parentblock) return; + SPtr<Block3D> parentblock = grid->getSuperBlock(ix1, ix2, ix3, level); + if (!parentblock) + return; - for(int dir : dirs) - { - SPtr<Block3D> nblock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); - if(!nblock) - { - SPtr<Block3D> p_nblock = grid->getNeighborBlock(dir, parentblock); + for (int dir : dirs) { + SPtr<Block3D> nblock = grid->getNeighborBlock(dir, ix1, ix2, ix3, level); + if (!nblock) { + SPtr<Block3D> p_nblock = grid->getNeighborBlock(dir, parentblock); - if (p_nblock) - { - bool flagDir; - switch (dir) - { - case NE: - checkFlagDir(grid, E, N, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case SW: - checkFlagDir(grid, W, S, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case SE: - checkFlagDir(grid, E, S, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case NW: - checkFlagDir(grid, W, N, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case TE: - checkFlagDir(grid, E, T, flagDir, ix1, ix2, ix3, level); - if(!flagDir)continue; - break; - case BW: - checkFlagDir(grid, W, B, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case BE: - checkFlagDir(grid, E, B, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case TW: - checkFlagDir(grid, W, T, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case TN: - checkFlagDir(grid, N, T, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case BS: - checkFlagDir(grid, S, B, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case BN: - checkFlagDir(grid, N, B, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case TS: - checkFlagDir(grid, S, T, flagDir, ix1, ix2, ix3, level); - if(!flagDir) continue; - break; - case TNE: - checkFlagDir(grid, E, N, T, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case TSW: - checkFlagDir(grid, W, S, T, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case TSE: - checkFlagDir(grid, E, S, T, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case TNW: - checkFlagDir(grid, W, N, T, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case BNE: - checkFlagDir(grid, E, N, B, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case BSW: - checkFlagDir(grid, W, S, B, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case BSE: - checkFlagDir(grid, E, S, B, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - case BNW: - checkFlagDir(grid, W, N, B, flagDir, ix1, ix2, ix3, level); - if (!flagDir) continue; - break; - } + if (p_nblock) { + bool flagDir; + switch (dir) { + case NE: + checkFlagDir(grid, E, N, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case SW: + checkFlagDir(grid, W, S, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case SE: + checkFlagDir(grid, E, S, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case NW: + checkFlagDir(grid, W, N, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TE: + checkFlagDir(grid, E, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BW: + checkFlagDir(grid, W, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BE: + checkFlagDir(grid, E, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TW: + checkFlagDir(grid, W, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TN: + checkFlagDir(grid, N, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BS: + checkFlagDir(grid, S, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BN: + checkFlagDir(grid, N, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TS: + checkFlagDir(grid, S, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TNE: + checkFlagDir(grid, E, N, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TSW: + checkFlagDir(grid, W, S, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TSE: + checkFlagDir(grid, E, S, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case TNW: + checkFlagDir(grid, W, N, T, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BNE: + checkFlagDir(grid, E, N, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BSW: + checkFlagDir(grid, W, S, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BSE: + checkFlagDir(grid, E, S, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + case BNW: + checkFlagDir(grid, W, N, B, flagDir, ix1, ix2, ix3, level); + if (!flagDir) + continue; + break; + } - block->setInterpolationFlagFC(dir); - parentblock->setInterpolationFlagCF(dir); - } - } - } + block->setInterpolationFlagFC(dir); + parentblock->setInterpolationFlagCF(dir); + } + } + } } ////////////////////////////////////////////////////////////////////////// -//void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int ix1, int ix2, int ix3, int level) +// void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int +// ix1, int ix2, int ix3, int level) //{ // SPtr<Block3D> block1 = grid->getNeighborBlock(dir1, ix1, ix2, ix3, level); // SPtr<Block3D> block2 = grid->getNeighborBlock(dir2, ix1, ix2, ix3, level); @@ -135,28 +152,30 @@ void SetInterpolationDirsBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> bl // flagDirection = true; //} -void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int ix1, int ix2, int ix3, int level) +void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int ix1, + int ix2, int ix3, int level) { - SPtr<Block3D> block1 = grid->getNeighborBlock(dir1, ix1, ix2, ix3, level); - SPtr<Block3D> block2 = grid->getNeighborBlock(dir2, ix1, ix2, ix3, level); + SPtr<Block3D> block1 = grid->getNeighborBlock(dir1, ix1, ix2, ix3, level); + SPtr<Block3D> block2 = grid->getNeighborBlock(dir2, ix1, ix2, ix3, level); - SPtr<Block3D> pblock = grid->getSuperBlock(ix1,ix2,ix3,level); - SPtr<Block3D> pblock1 = grid->getNeighborBlock(dir1, pblock); - SPtr<Block3D> pblock2 = grid->getNeighborBlock(dir2, pblock); + SPtr<Block3D> pblock = grid->getSuperBlock(ix1, ix2, ix3, level); + SPtr<Block3D> pblock1 = grid->getNeighborBlock(dir1, pblock); + SPtr<Block3D> pblock2 = grid->getNeighborBlock(dir2, pblock); - if (!((block1 && block2)||(!block1 && !block2)) || !((pblock1 && pblock2)||(!pblock1 && !pblock2))) - flagDirection = false; - else - flagDirection = true; + if (!((block1 && block2) || (!block1 && !block2)) || !((pblock1 && pblock2) || (!pblock1 && !pblock2))) + flagDirection = false; + else + flagDirection = true; } ////////////////////////////////////////////////////////////////////////// -void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, int dir3, bool &flagDirection, int ix1, int ix2, int ix3, int level) +void SetInterpolationDirsBlockVisitor::checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, int dir3, + bool &flagDirection, int ix1, int ix2, int ix3, int level) { - SPtr<Block3D> block1 = grid->getNeighborBlock(dir1, ix1, ix2, ix3, level); - SPtr<Block3D> block2 = grid->getNeighborBlock(dir2, ix1, ix2, ix3, level); - SPtr<Block3D> block3 = grid->getNeighborBlock(dir3, ix1, ix2, ix3, level); - if (!((block1 && block2 && block3) || (!block1 && !block2 && !block3))) - flagDirection=false; - else - flagDirection=true; + SPtr<Block3D> block1 = grid->getNeighborBlock(dir1, ix1, ix2, ix3, level); + SPtr<Block3D> block2 = grid->getNeighborBlock(dir2, ix1, ix2, ix3, level); + SPtr<Block3D> block3 = grid->getNeighborBlock(dir3, ix1, ix2, ix3, level); + if (!((block1 && block2 && block3) || (!block1 && !block2 && !block3))) + flagDirection = false; + else + flagDirection = true; } diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.h index 75dafc899..078a06766 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetInterpolationDirsBlockVisitor.h @@ -1,8 +1,8 @@ #ifndef SetInterpolationDirsBlockVisitor_h #define SetInterpolationDirsBlockVisitor_h -#include <vector> #include <PointerDefinitions.h> +#include <vector> #include "Block3DVisitor.h" @@ -12,16 +12,17 @@ class Block3D; class SetInterpolationDirsBlockVisitor : public Block3DVisitor { public: - SetInterpolationDirsBlockVisitor(std::vector<int>& dirs); + SetInterpolationDirsBlockVisitor(std::vector<int> &dirs); - ~SetInterpolationDirsBlockVisitor() override = default; + ~SetInterpolationDirsBlockVisitor() override = default; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - std::vector<int> dirs; - void checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int ix1, int ix2, int ix3, int level); - void checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, int dir3, bool &flagDirection, int ix1, int ix2, int ix3, int level); + std::vector<int> dirs; + void checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, bool &flagDirection, int ix1, int ix2, int ix3, int level); + void checkFlagDir(SPtr<Grid3D> grid, int dir1, int dir2, int dir3, bool &flagDirection, int ix1, int ix2, int ix3, + int level); }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.cpp index d3ec9e85e..5c813d289 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.cpp @@ -1,29 +1,29 @@ #include "MemoryUtil.h" //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -34,111 +34,90 @@ #include "SetKernelBlockVisitor.h" -#include <utility> -#include "Grid3DSystem.h" -#include "LBMSystem.h" -#include "DataSet3D.h" #include "BCProcessor.h" -#include "Grid3D.h" #include "Block3D.h" +#include "DataSet3D.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" #include "LBMKernel.h" +#include "LBMSystem.h" +#include <utility> ////////////////////////////////////////////////////////////////////////// SetKernelBlockVisitor::SetKernelBlockVisitor(SPtr<LBMKernel> kernel, LBMReal nue, double availMem, double needMem, - SetKernelBlockVisitor::Action action) : Block3DVisitor(0, - Grid3DSystem::MAXLEVEL), - kernel(std::move(kernel)), nue(nue), - action(action), dataSetFlag(true) + SetKernelBlockVisitor::Action action) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), kernel(std::move(kernel)), nue(nue), action(action), dataSetFlag(true) { - if (needMem > availMem) - { + if (needMem > availMem) { throw UbException(UB_EXARGS, "SetKernelBlockVisitor: Not enough memory!!!"); } } -SetKernelBlockVisitor::SetKernelBlockVisitor(SPtr<LBMKernel> kernel, - LBMReal nue, - int &numberOfProcesses, - SetKernelBlockVisitor::Action action) : Block3DVisitor(0, - Grid3DSystem::MAXLEVEL), - kernel(std::move(kernel)), - nue(nue), - action(action), - dataSetFlag(true), - numberOfProcesses( - numberOfProcesses) -{} +SetKernelBlockVisitor::SetKernelBlockVisitor(SPtr<LBMKernel> kernel, LBMReal nue, int &numberOfProcesses, + SetKernelBlockVisitor::Action action) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), kernel(std::move(kernel)), nue(nue), action(action), dataSetFlag(true), + numberOfProcesses(numberOfProcesses) +{ +} ////////////////////////////////////////////////////////////////////////// void SetKernelBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { throwExceptionIfNotEnoughMemory(grid); - if (kernel && (block->getRank() == grid->getRank())) - { + if (kernel && (block->getRank() == grid->getRank())) { LBMReal collFactor = LBMSystem::calcCollisionFactor(nue, block->getLevel()); kernel->setCollisionFactor(collFactor); kernel->setIndex(block->getX1(), block->getX2(), block->getX3()); kernel->setDeltaT(LBMSystem::getDeltaT(block->getLevel())); kernel->setBlock(block); UbTupleInt3 blockNX = grid->getBlockNX(); - kernel->setNX(std::array<int, 3>{{val<1>(blockNX), val<2>(blockNX), val<3>(blockNX)}}); + kernel->setNX(std::array<int, 3>{ { val<1>(blockNX), val<2>(blockNX), val<3>(blockNX) } }); SPtr<LBMKernel> newKernel = kernel->clone(); - switch (action) - { + switch (action) { case SetKernelBlockVisitor::NewKernel: block->setKernel(newKernel); break; - case SetKernelBlockVisitor::ChangeKernel: - { + case SetKernelBlockVisitor::ChangeKernel: { SPtr<DataSet3D> dataSet = block->getKernel()->getDataSet(); - if (!dataSet) - { - UB_THROW(UbException(UB_EXARGS, - "It is not possible to change a DataSet in kernel! Old DataSet is not exist!")); + if (!dataSet) { + UB_THROW(UbException( + UB_EXARGS, "It is not possible to change a DataSet in kernel! Old DataSet is not exist!")); } newKernel->setDataSet(dataSet); SPtr<BCProcessor> bcProc = block->getKernel()->getBCProcessor(); - if (!bcProc) - { - UB_THROW(UbException(UB_EXARGS, - "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); + if (!bcProc) { + UB_THROW(UbException( + UB_EXARGS, + "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); } newKernel->setBCProcessor(bcProc); block->setKernel(newKernel); - } - break; + } break; - case SetKernelBlockVisitor::ChangeKernelWithData: - { + case SetKernelBlockVisitor::ChangeKernelWithData: { SPtr<BCProcessor> bcProc = block->getKernel()->getBCProcessor(); - if (!bcProc) - { - UB_THROW(UbException(UB_EXARGS, - "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); + if (!bcProc) { + UB_THROW(UbException( + UB_EXARGS, + "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); } newKernel->setBCProcessor(bcProc); block->setKernel(newKernel); - } - break; + } break; } - } } - -void SetKernelBlockVisitor::setNoDataSetFlag(bool flag) -{ - dataSetFlag = flag; -} +void SetKernelBlockVisitor::setNoDataSetFlag(bool flag) { dataSetFlag = flag; } void SetKernelBlockVisitor::throwExceptionIfNotEnoughMemory(const SPtr<Grid3D> &grid) { auto availableMemory = Utilities::getTotalPhysMem(); - auto requiredMemory = getRequiredPhysicalMemory(grid); + auto requiredMemory = getRequiredPhysicalMemory(grid); if (requiredMemory > availableMemory) throw UbException(UB_EXARGS, "SetKernelBlockVisitor: Not enough memory!!!"); } @@ -146,20 +125,15 @@ void SetKernelBlockVisitor::throwExceptionIfNotEnoughMemory(const SPtr<Grid3D> & double SetKernelBlockVisitor::getRequiredPhysicalMemory(const SPtr<Grid3D> &grid) const { unsigned long long numberOfNodesPerBlockWithGhostLayer; - auto numberOfBlocks = (unsigned long long) grid->getNumberOfBlocks(); - auto blockNx = grid->getBlockNX(); - int ghostLayer = 3; + auto numberOfBlocks = (unsigned long long)grid->getNumberOfBlocks(); + auto blockNx = grid->getBlockNX(); + int ghostLayer = 3; - numberOfNodesPerBlockWithGhostLayer = numberOfBlocks - * (val<1>(blockNx) + ghostLayer) - * (val<2>(blockNx) + ghostLayer) - * (val<3>(blockNx) + ghostLayer); + numberOfNodesPerBlockWithGhostLayer = numberOfBlocks * (val<1>(blockNx) + ghostLayer) * + (val<2>(blockNx) + ghostLayer) * (val<3>(blockNx) + ghostLayer); - auto needMemAll = double(numberOfNodesPerBlockWithGhostLayer - * (27 * sizeof(double) - + sizeof(int) - + sizeof(float) * 4)); + auto needMemAll = + double(numberOfNodesPerBlockWithGhostLayer * (27 * sizeof(double) + sizeof(int) + sizeof(float) * 4)); return needMemAll / double(numberOfProcesses); } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.h index e676d3f7e..6eb8f6577 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetKernelBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -47,14 +47,11 @@ class LBMKernel; class SetKernelBlockVisitor : public Block3DVisitor { public: - enum Action - { - NewKernel, ChangeKernel, ChangeKernelWithData - }; + enum Action { NewKernel, ChangeKernel, ChangeKernelWithData }; - //SetKernelBlockVisitor(LBMKernel3DPtr kernel, LBMReal nue); + // SetKernelBlockVisitor(LBMKernel3DPtr kernel, LBMReal nue); - //SetKernelBlockVisitor(LBMKernel3DPtr kernel, LBMReal nue, double availMem, double needMem); + // SetKernelBlockVisitor(LBMKernel3DPtr kernel, LBMReal nue, double availMem, double needMem); SetKernelBlockVisitor(SPtr<LBMKernel> kernel, LBMReal nue, double availMem, double needMem, SetKernelBlockVisitor::Action action = SetKernelBlockVisitor::NewKernel); @@ -74,7 +71,7 @@ private: Action action; bool dataSetFlag; - int numberOfProcesses{1}; + int numberOfProcesses{ 1 }; double getRequiredPhysicalMemory(const SPtr<Grid3D> &grid) const; diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.cpp index de9edef09..3354755f2 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.cpp @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -35,24 +35,21 @@ #include <utility> -#include "Interactor3D.h" -#include "Grid3DSystem.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "Grid3DSystem.h" +#include "Interactor3D.h" -SetSolidBlocksBlockVisitor::SetSolidBlocksBlockVisitor(SPtr<Interactor3D> interactor) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), interactor(std::move(interactor)) +SetSolidBlocksBlockVisitor::SetSolidBlocksBlockVisitor(SPtr<Interactor3D> interactor) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), interactor(std::move(interactor)) { - } void SetSolidBlocksBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getRank() == grid->getRank()) - { - if (block->isActive()) - { - interactor->setSolidBlock(block); - } - } + if (block->getRank() == grid->getRank()) { + if (block->isActive()) { + interactor->setSolidBlock(block); + } + } } \ No newline at end of file diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.h index fe5456be9..fcbb3de0c 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetSolidBlocksBlockVisitor.h @@ -1,28 +1,28 @@ //======================================================================================= -// ____ ____ __ ______ __________ __ __ __ __ -// \ \ | | | | | _ \ |___ ___| | | | | / \ | | -// \ \ | | | | | |_) | | | | | | | / \ | | -// \ \ | | | | | _ / | | | | | | / /\ \ | | -// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ -// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| -// \ \ | | ________________________________________________________________ -// \ \ | | | ______________________________________________________________| -// \ \| | | | __ __ __ __ ______ _______ -// \ | | |_____ | | | | | | | | | _ \ / _____) -// \ | | _____| | | | | | | | | | | \ \ \_______ +// ____ ____ __ ______ __________ __ __ __ __ +// \ \ | | | | | _ \ |___ ___| | | | | / \ | | +// \ \ | | | | | |_) | | | | | | | / \ | | +// \ \ | | | | | _ / | | | | | | / /\ \ | | +// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____ +// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______| +// \ \ | | ________________________________________________________________ +// \ \ | | | ______________________________________________________________| +// \ \| | | | __ __ __ __ ______ _______ +// \ | | |_____ | | | | | | | | | _ \ / _____) +// \ | | _____| | | | | | | | | | | \ \ \_______ // \ | | | | |_____ | \_/ | | | | |_/ / _____ | -// \ _____| |__| |________| \_______/ |__| |______/ (_______/ +// \ _____| |__| |________| \_______/ |__| |______/ (_______/ // -// This file is part of VirtualFluids. VirtualFluids is free software: you can +// This file is part of VirtualFluids. VirtualFluids is free software: you can // redistribute it and/or modify it under the terms of the GNU General Public -// License as published by the Free Software Foundation, either version 3 of +// License as published by the Free Software Foundation, either version 3 of // the License, or (at your option) any later version. -// -// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// +// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License // for more details. -// +// // You should have received a copy of the GNU General Public License along // with VirtualFluids (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>. // @@ -46,13 +46,13 @@ class Interactor3D; class SetSolidBlocksBlockVisitor : public Block3DVisitor { public: - SetSolidBlocksBlockVisitor(SPtr<Interactor3D> interactor); - ~SetSolidBlocksBlockVisitor() override = default; + SetSolidBlocksBlockVisitor(SPtr<Interactor3D> interactor); + ~SetSolidBlocksBlockVisitor() override = default; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - SPtr<Interactor3D> interactor; + SPtr<Interactor3D> interactor; } #endif // SetSolidBlocksBlockVisitor_h__ ; diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.cpp index 68c338d86..040f54b0f 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.cpp @@ -2,28 +2,24 @@ #include "Grid3DSystem.h" #include "LBMSystem.h" -#include "LBMKernel.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "LBMKernel.h" -SetSpongeLayerBlockVisitor::SetSpongeLayerBlockVisitor( const mu::Parser& spongeLayer ) : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), spongeLayer(spongeLayer) +SetSpongeLayerBlockVisitor::SetSpongeLayerBlockVisitor(const mu::Parser &spongeLayer) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), spongeLayer(spongeLayer) { - } ////////////////////////////////////////////////////////////////////////// -SetSpongeLayerBlockVisitor::~SetSpongeLayerBlockVisitor() -= default; +SetSpongeLayerBlockVisitor::~SetSpongeLayerBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// -void SetSpongeLayerBlockVisitor::visit( SPtr<Grid3D> grid, SPtr<Block3D> block ) +void SetSpongeLayerBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if(block->getRank() == grid->getRank()) - { - SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); - if (!kernel) - throw std::runtime_error("SetSpongeLayerBlockVisitor: Kernel is not a LBMKernel"); - kernel->setWithSpongeLayer(true); - kernel->setSpongeLayer(spongeLayer); - } + if (block->getRank() == grid->getRank()) { + SPtr<LBMKernel> kernel = dynamicPointerCast<LBMKernel>(block->getKernel()); + if (!kernel) + throw std::runtime_error("SetSpongeLayerBlockVisitor: Kernel is not a LBMKernel"); + kernel->setWithSpongeLayer(true); + kernel->setSpongeLayer(spongeLayer); + } } - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.h index 27d48a1cf..dfa4fdda8 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetSpongeLayerBlockVisitor.h @@ -11,18 +11,19 @@ class Grid3D; class Block3D; //! \brief Set sponge layer for all kernels of grid -//! \details This visitor is useful if you need to set or reset sponge layer in kernels (e.g. after restart because sponge layer is not serializable). -//! \author K. Kucher +//! \details This visitor is useful if you need to set or reset sponge layer in kernels (e.g. after restart because +//! sponge layer is not serializable). \author K. Kucher class SetSpongeLayerBlockVisitor : public Block3DVisitor { public: - SetSpongeLayerBlockVisitor(const mu::Parser& spongeLayer); - ~SetSpongeLayerBlockVisitor() override; + SetSpongeLayerBlockVisitor(const mu::Parser &spongeLayer); + ~SetSpongeLayerBlockVisitor() override; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: private: - mu::Parser spongeLayer; + mu::Parser spongeLayer; }; #endif // SetSpongeLayerBlockVisitor_h__ diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.cpp index 66b200c22..15c8b82ba 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.cpp @@ -1,682 +1,676 @@ #include "SetUndefinedNodesBlockVisitor.h" #include "BCArray3D.h" -#include "BoundaryConditions.h" #include "BCProcessor.h" -#include "Grid3DSystem.h" +#include "Block3D.h" +#include "BoundaryConditions.h" #include "D3Q27System.h" -#include "BCArray3D.h" #include "Grid3D.h" -#include "Block3D.h" +#include "Grid3DSystem.h" #include "ILBMKernel.h" - -SetUndefinedNodesBlockVisitor::SetUndefinedNodesBlockVisitor(bool twoTypeOfConnectorsCheck) : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), twoTypeOfConnectorsCheck(twoTypeOfConnectorsCheck) +SetUndefinedNodesBlockVisitor::SetUndefinedNodesBlockVisitor(bool twoTypeOfConnectorsCheck) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), twoTypeOfConnectorsCheck(twoTypeOfConnectorsCheck) { - } ////////////////////////////////////////////////////////////////////////// void SetUndefinedNodesBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if(!block->hasInterpolationFlag()) return; + if (!block->hasInterpolationFlag()) + return; - SPtr<ILBMKernel> kernel = block->getKernel(); + SPtr<ILBMKernel> kernel = block->getKernel(); - if(!kernel && (block->getRank() != grid->getRank())) return; + if (!kernel && (block->getRank() != grid->getRank())) + return; - //width of ghost layer - //int gl = kernel->getGhostLayerWidth(); - int gl = 0; - - SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); + // width of ghost layer + // int gl = kernel->getGhostLayerWidth(); + int gl = 0; - int minX1 = gl; - int minX2 = gl; - int minX3 = gl; + SPtr<BCArray3D> bcMatrix = kernel->getBCProcessor()->getBCArray(); - int maxX1 = static_cast<int>(bcMatrix->getNX1())-1-gl; - int maxX2 = static_cast<int>(bcMatrix->getNX2())-1-gl; - int maxX3 = static_cast<int>(bcMatrix->getNX3())-1-gl; + int minX1 = gl; + int minX2 = gl; + int minX3 = gl; - //int offset = 2; - int offset = 3; + int maxX1 = static_cast<int>(bcMatrix->getNX1()) - 1 - gl; + int maxX2 = static_cast<int>(bcMatrix->getNX2()) - 1 - gl; + int maxX3 = static_cast<int>(bcMatrix->getNX3()) - 1 - gl; - if(block->hasInterpolationFlag(D3Q27System::E)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::W)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::N)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::S)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::T)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::B)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::NE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::SW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::SE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::NW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TN)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BS)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BN)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TS)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TNE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TNW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TSE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::TSW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = maxX3; - int endix3 = maxX3; - if(block->hasInterpolationFlagCF()) startix3 = startix3-offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BNE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BNW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = maxX2; - int endix2 = maxX2; - if(block->hasInterpolationFlagCF()) startix2 = startix2-offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BSE)) - { - int startix1 = maxX1; - int endix1 = maxX1; - if(block->hasInterpolationFlagCF()) startix1 = startix1-offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlag(D3Q27System::BSW)) - { - int startix1 = minX1; - int endix1 = minX1; - if(block->hasInterpolationFlagCF()) endix1 = endix1+offset; - int startix2 = minX2; - int endix2 = minX2; - if(block->hasInterpolationFlagCF()) endix2 = endix2+offset; - int startix3 = minX3; - int endix3 = minX3; - if(block->hasInterpolationFlagCF()) endix3 = endix3+offset; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } + // int offset = 2; + int offset = 3; + if (block->hasInterpolationFlag(D3Q27System::E)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::W)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::N)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::S)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::T)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::B)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::NE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::SW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::SE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::NW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TN)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BS)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BN)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TS)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TNE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TNW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TSE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::TSW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = maxX3; + int endix3 = maxX3; + if (block->hasInterpolationFlagCF()) + startix3 = startix3 - offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BNE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BNW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = maxX2; + int endix2 = maxX2; + if (block->hasInterpolationFlagCF()) + startix2 = startix2 - offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BSE)) { + int startix1 = maxX1; + int endix1 = maxX1; + if (block->hasInterpolationFlagCF()) + startix1 = startix1 - offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlag(D3Q27System::BSW)) { + int startix1 = minX1; + int endix1 = minX1; + if (block->hasInterpolationFlagCF()) + endix1 = endix1 + offset; + int startix2 = minX2; + int endix2 = minX2; + if (block->hasInterpolationFlagCF()) + endix2 = endix2 + offset; + int startix3 = minX3; + int endix3 = minX3; + if (block->hasInterpolationFlagCF()) + endix3 = endix3 + offset; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + ////////////////////////////////////////////////////////////////////////// + int offset2 = 1; + int ll = 0; - ////////////////////////////////////////////////////////////////////////// - int offset2 = 1; - int ll = 0; + minX1 = ll; + minX2 = ll; + minX3 = ll; - minX1 = ll; - minX2 = ll; - minX3 = ll; + maxX1 = static_cast<int>(bcMatrix->getNX1()) - 1 - ll; + maxX2 = static_cast<int>(bcMatrix->getNX2()) - 1 - ll; + maxX3 = static_cast<int>(bcMatrix->getNX3()) - 1 - ll; - maxX1 = static_cast<int>(bcMatrix->getNX1())-1-ll; - maxX2 = static_cast<int>(bcMatrix->getNX2())-1-ll; - maxX3 = static_cast<int>(bcMatrix->getNX3())-1-ll; + if (block->hasInterpolationFlagFC(D3Q27System::E)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::W)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::N)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::S)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::T)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::B)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::NE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::SW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::SE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::NW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TN)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BS)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BN)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TS)) { + int startix1 = minX1; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TNE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TNW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TSE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::TSW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = maxX3 - offset2; + int endix3 = maxX3; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BNE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BNW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = maxX2 - offset2; + int endix2 = maxX2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BSE)) { + int startix1 = maxX1 - offset2; + int endix1 = maxX1; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } + if (block->hasInterpolationFlagFC(D3Q27System::BSW)) { + int startix1 = minX1; + int endix1 = minX1 + offset2; + int startix2 = minX2; + int endix2 = minX2 + offset2; + int startix3 = minX3; + int endix3 = minX3 + offset2; + this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); + } - if(block->hasInterpolationFlagFC(D3Q27System::E)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::W)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::N)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::S)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::T)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::B)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::NE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::SW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::SE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::NW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TN)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BS)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BN)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TS)) - { - int startix1 = minX1; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TNE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TNW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TSE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::TSW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = maxX3-offset2; - int endix3 = maxX3; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BNE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BNW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = maxX2-offset2; - int endix2 = maxX2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BSE)) - { - int startix1 = maxX1-offset2; - int endix1 = maxX1; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - if(block->hasInterpolationFlagFC(D3Q27System::BSW)) - { - int startix1 = minX1; - int endix1 = minX1+offset2; - int startix2 = minX2; - int endix2 = minX2+offset2; - int startix3 = minX3; - int endix3 = minX3+offset2; - this->setNodesUndefined(startix1, endix1, startix2, endix2, startix3, endix3, bcMatrix); - } - - //invert scaleCF blocks - if(block->hasInterpolationFlagCF()) - { - if(block->hasInterpolationFlagFC() && twoTypeOfConnectorsCheck) - { - for (int i = D3Q27System::E; i <= D3Q27System::BSW; i++) - { - UBLOG(logINFO, "FC in dir="<<i<<" "<<block->hasInterpolationFlagFC(i)); - } - for (int i = D3Q27System::E; i<=D3Q27System::BSW; i++) - { - UBLOG(logINFO, "CF in dir="<<i<<" "<<block->hasInterpolationFlagCF(i)); - } - throw UbException(UB_EXARGS, "block "+block->toString()+" has CF and FC"); - } + // invert scaleCF blocks + if (block->hasInterpolationFlagCF()) { + if (block->hasInterpolationFlagFC() && twoTypeOfConnectorsCheck) { + for (int i = D3Q27System::E; i <= D3Q27System::BSW; i++) { + UBLOG(logINFO, "FC in dir=" << i << " " << block->hasInterpolationFlagFC(i)); + } + for (int i = D3Q27System::E; i <= D3Q27System::BSW; i++) { + UBLOG(logINFO, "CF in dir=" << i << " " << block->hasInterpolationFlagCF(i)); + } + throw UbException(UB_EXARGS, "block " + block->toString() + " has CF and FC"); + } - minX1 = gl; - minX2 = gl; - minX3 = gl; + minX1 = gl; + minX2 = gl; + minX3 = gl; - maxX1 = static_cast<int>(bcMatrix->getNX1())-1-gl; - maxX2 = static_cast<int>(bcMatrix->getNX2())-1-gl; - maxX3 = static_cast<int>(bcMatrix->getNX3())-1-gl; + maxX1 = static_cast<int>(bcMatrix->getNX1()) - 1 - gl; + maxX2 = static_cast<int>(bcMatrix->getNX2()) - 1 - gl; + maxX3 = static_cast<int>(bcMatrix->getNX3()) - 1 - gl; - for (int ix3=minX3; ix3<=maxX3; ix3++) { - for (int ix2=minX2; ix2<=maxX2; ix2++) { - for (int ix1=minX1; ix1<=maxX1; ix1++) - { - if(bcMatrix->isUndefined(ix1, ix2, ix3)) - bcMatrix->setFluid(ix1, ix2, ix3); - else - bcMatrix->setUndefined(ix1, ix2, ix3); + for (int ix3 = minX3; ix3 <= maxX3; ix3++) { + for (int ix2 = minX2; ix2 <= maxX2; ix2++) { + for (int ix1 = minX1; ix1 <= maxX1; ix1++) { + if (bcMatrix->isUndefined(ix1, ix2, ix3)) + bcMatrix->setFluid(ix1, ix2, ix3); + else + bcMatrix->setUndefined(ix1, ix2, ix3); + } } - } - } - - return; - } + } + return; + } } ////////////////////////////////////////////////////////////////////////// -void SetUndefinedNodesBlockVisitor::setNodesUndefined( int startix1, int endix1, int startix2, int endix2, int startix3, int endix3, SPtr<BCArray3D> bcMatrix ) +void SetUndefinedNodesBlockVisitor::setNodesUndefined(int startix1, int endix1, int startix2, int endix2, int startix3, + int endix3, SPtr<BCArray3D> bcMatrix) { - for (int ix3=startix3; ix3<=endix3; ix3++) - for (int ix2=startix2; ix2<=endix2; ix2++) - for (int ix1=startix1; ix1<=endix1; ix1++) - { - bcMatrix->setUndefined(ix1, ix2, ix3); - } + for (int ix3 = startix3; ix3 <= endix3; ix3++) + for (int ix2 = startix2; ix2 <= endix2; ix2++) + for (int ix1 = startix1; ix1 <= endix1; ix1++) { + bcMatrix->setUndefined(ix1, ix2, ix3); + } } diff --git a/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.h index 8e40ada12..329662ec8 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SetUndefinedNodesBlockVisitor.h @@ -12,15 +12,17 @@ class BCArray3D; class SetUndefinedNodesBlockVisitor : public Block3DVisitor { public: - SetUndefinedNodesBlockVisitor(bool twoTypeOfConnectorsCheck=true); + SetUndefinedNodesBlockVisitor(bool twoTypeOfConnectorsCheck = true); - ~SetUndefinedNodesBlockVisitor() override = default; + ~SetUndefinedNodesBlockVisitor() override = default; + + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; protected: - void setNodesUndefined( int startix1, int endix1, int startix2, int endix2, int startix3, int endix3, SPtr<BCArray3D> bcMatix ); -private: - bool twoTypeOfConnectorsCheck; + void setNodesUndefined(int startix1, int endix1, int startix2, int endix2, int startix3, int endix3, + SPtr<BCArray3D> bcMatix); +private: + bool twoTypeOfConnectorsCheck; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.cpp index bc8892968..c5dce4102 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.cpp @@ -2,120 +2,101 @@ #include "Grid3DSystem.h" #include "LBMSystem.h" -#include "Grid3D.h" +#include "BCArray3D.h" +#include "BCProcessor.h" #include "Block3D.h" +#include "D3Q27System.h" +#include "Grid3D.h" #include "LBMKernel.h" #include "UbException.h" -#include "D3Q27System.h" -#include "BCArray3D.h" -#include "BCProcessor.h" #include <geometry3d/GbCuboid3D.h> using namespace std; -SpongeLayerBlockVisitor::SpongeLayerBlockVisitor(SPtr<GbCuboid3D> boundingBox, SPtr<LBMKernel> kernel, double nue, int dir) : - Block3DVisitor(0, Grid3DSystem::MAXLEVEL), - boundingBox(boundingBox), - kernel(kernel), - nue(nue), - dir(dir) +SpongeLayerBlockVisitor::SpongeLayerBlockVisitor(SPtr<GbCuboid3D> boundingBox, SPtr<LBMKernel> kernel, double nue, + int dir) + : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), boundingBox(boundingBox), kernel(kernel), nue(nue), dir(dir) { - } ////////////////////////////////////////////////////////////////////////// -SpongeLayerBlockVisitor::~SpongeLayerBlockVisitor() -= default; +SpongeLayerBlockVisitor::~SpongeLayerBlockVisitor() = default; ////////////////////////////////////////////////////////////////////////// void SpongeLayerBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (!boundingBox) - { - UB_THROW(UbException(UB_EXARGS, "The bounding box isn't set!")); - } - if (!kernel) - { - UB_THROW(UbException(UB_EXARGS, "The kernel isn't set!")); - } - if (kernel && (block->getRank() == grid->getRank())) - { - UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); - UbTupleDouble3 blockLengths = grid->getBlockLengths(block); - - double minX1 = val<1>(org); - double minX2 = val<2>(org); - double minX3 = val<3>(org); - double maxX1 = val<1>(org)+val<1>(blockLengths); - double maxX2 = val<2>(org)+val<2>(blockLengths); - double maxX3 = val<3>(org)+val<3>(blockLengths); - - if (boundingBox->isCellInsideGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)) - { - LBMReal collFactor = LBMSystem::calcCollisionFactor(nue, block->getLevel()); - kernel->setCollisionFactor(collFactor); - kernel->setIndex(block->getX1(), block->getX2(), block->getX3()); - kernel->setDeltaT(LBMSystem::getDeltaT(block->getLevel())); - kernel->setBlock(block); - SPtr<LBMKernel> newKernel = kernel->clone(); - - SPtr<DataSet3D> dataSet = block->getKernel()->getDataSet(); - if (!dataSet) - { - UB_THROW(UbException(UB_EXARGS, "It is not possible to change a DataSet in kernel! Old DataSet is not exist!")); - } - - newKernel->setDataSet(dataSet); - - SPtr<BCProcessor> bcProc = block->getKernel()->getBCProcessor(); - if (!bcProc) - { - UB_THROW(UbException(UB_EXARGS, "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); - } - newKernel->setBCProcessor(bcProc); - - double oldCollFactor = newKernel->getCollisionFactor(); - - - UbTupleInt3 ixMin = grid->getBlockIndexes(boundingBox->getX1Minimum(),boundingBox->getX2Minimum(),boundingBox->getX3Minimum()); - UbTupleInt3 ixMax = grid->getBlockIndexes(boundingBox->getX1Maximum(),boundingBox->getX2Maximum(),boundingBox->getX3Maximum()); - - double newCollFactor; - - if (dir == D3Q27System::E) - { - int ibX1 = block->getX1(); - int ibMax = val<1>(ixMax)-val<1>(ixMin)+1; - double index = (double)(ibX1-val<1>(ixMin)+1); - newCollFactor = oldCollFactor - (oldCollFactor-1.0)/(double)(ibMax)*index; - } - else if (dir == D3Q27System::W) - { - int ibX1 = block->getX1(); - int ibMax = val<1>(ixMax)-val<1>(ixMin)+1; - double index = (double)(ibX1-val<1>(ixMin)+1); - newCollFactor = (oldCollFactor-1.0)/(double)(ibMax)*index; - } - else if (dir == D3Q27System::T) - { - int ibX3 = block->getX3(); - int ibMax = val<3>(ixMax)-val<3>(ixMin)+1; - double index = (double)(ibX3-val<3>(ixMin)+1); - newCollFactor = oldCollFactor - (oldCollFactor-1.0)/(double)(ibMax)*index; - } - else if (dir == D3Q27System::B) - { - int ibX3 = block->getX3(); - int ibMax = val<3>(ixMax)-val<3>(ixMin)+1; - double index = (double)(ibX3-val<3>(ixMin)+1); - newCollFactor = (oldCollFactor-1.0)/(double)(ibMax)*index; - } - - - newKernel->setCollisionFactor(newCollFactor); - block->setKernel(newKernel); - } - } + if (!boundingBox) { + UB_THROW(UbException(UB_EXARGS, "The bounding box isn't set!")); + } + if (!kernel) { + UB_THROW(UbException(UB_EXARGS, "The kernel isn't set!")); + } + if (kernel && (block->getRank() == grid->getRank())) { + UbTupleDouble3 org = grid->getBlockWorldCoordinates(block); + UbTupleDouble3 blockLengths = grid->getBlockLengths(block); + + double minX1 = val<1>(org); + double minX2 = val<2>(org); + double minX3 = val<3>(org); + double maxX1 = val<1>(org) + val<1>(blockLengths); + double maxX2 = val<2>(org) + val<2>(blockLengths); + double maxX3 = val<3>(org) + val<3>(blockLengths); + + if (boundingBox->isCellInsideGbObject3D(minX1, minX2, minX3, maxX1, maxX2, maxX3)) { + LBMReal collFactor = LBMSystem::calcCollisionFactor(nue, block->getLevel()); + kernel->setCollisionFactor(collFactor); + kernel->setIndex(block->getX1(), block->getX2(), block->getX3()); + kernel->setDeltaT(LBMSystem::getDeltaT(block->getLevel())); + kernel->setBlock(block); + SPtr<LBMKernel> newKernel = kernel->clone(); + + SPtr<DataSet3D> dataSet = block->getKernel()->getDataSet(); + if (!dataSet) { + UB_THROW(UbException(UB_EXARGS, + "It is not possible to change a DataSet in kernel! Old DataSet is not exist!")); + } + + newKernel->setDataSet(dataSet); + + SPtr<BCProcessor> bcProc = block->getKernel()->getBCProcessor(); + if (!bcProc) { + UB_THROW(UbException( + UB_EXARGS, "It is not possible to change a BCProcessor in kernel! Old BCProcessor is not exist!")); + } + newKernel->setBCProcessor(bcProc); + + double oldCollFactor = newKernel->getCollisionFactor(); + + UbTupleInt3 ixMin = grid->getBlockIndexes(boundingBox->getX1Minimum(), boundingBox->getX2Minimum(), + boundingBox->getX3Minimum()); + UbTupleInt3 ixMax = grid->getBlockIndexes(boundingBox->getX1Maximum(), boundingBox->getX2Maximum(), + boundingBox->getX3Maximum()); + + double newCollFactor; + + if (dir == D3Q27System::E) { + int ibX1 = block->getX1(); + int ibMax = val<1>(ixMax) - val<1>(ixMin) + 1; + double index = (double)(ibX1 - val<1>(ixMin) + 1); + newCollFactor = oldCollFactor - (oldCollFactor - 1.0) / (double)(ibMax)*index; + } else if (dir == D3Q27System::W) { + int ibX1 = block->getX1(); + int ibMax = val<1>(ixMax) - val<1>(ixMin) + 1; + double index = (double)(ibX1 - val<1>(ixMin) + 1); + newCollFactor = (oldCollFactor - 1.0) / (double)(ibMax)*index; + } else if (dir == D3Q27System::T) { + int ibX3 = block->getX3(); + int ibMax = val<3>(ixMax) - val<3>(ixMin) + 1; + double index = (double)(ibX3 - val<3>(ixMin) + 1); + newCollFactor = oldCollFactor - (oldCollFactor - 1.0) / (double)(ibMax)*index; + } else if (dir == D3Q27System::B) { + int ibX3 = block->getX3(); + int ibMax = val<3>(ixMax) - val<3>(ixMin) + 1; + double index = (double)(ibX3 - val<3>(ixMin) + 1); + newCollFactor = (oldCollFactor - 1.0) / (double)(ibMax)*index; + } + + newKernel->setCollisionFactor(newCollFactor); + block->setKernel(newKernel); + } + } } ////////////////////////////////////////////////////////////////////////// - - - diff --git a/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.h index 43ee4e614..0896db065 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/SpongeLayerBlockVisitor.h @@ -10,15 +10,15 @@ class GbCuboid3D; class LBMKernel; //! \brief Set sponge layer for all blocks inside boundingBox -//! \details This visitor sets viscosity gradient inside bounding box. +//! \details This visitor sets viscosity gradient inside bounding box. //! \author K. Kutscher class SpongeLayerBlockVisitor : public Block3DVisitor { public: - SpongeLayerBlockVisitor(SPtr<GbCuboid3D> boundingBox, SPtr<LBMKernel> kernel, double nue, int dir); - ~SpongeLayerBlockVisitor() override; + SpongeLayerBlockVisitor(SPtr<GbCuboid3D> boundingBox, SPtr<LBMKernel> kernel, double nue, int dir); + ~SpongeLayerBlockVisitor() override; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: SPtr<GbCuboid3D> boundingBox; diff --git a/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.cpp index ba1002ef8..67d185d6a 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.cpp @@ -1,22 +1,16 @@ #include "ViscosityBlockVisitor.h" -#include "Grid3DSystem.h" -#include "LBMSystem.h" #include "Block3D.h" #include "Grid3D.h" +#include "Grid3DSystem.h" #include "ILBMKernel.h" +#include "LBMSystem.h" -ViscosityBlockVisitor::ViscosityBlockVisitor(LBMReal nu) : -Block3DVisitor(0, Grid3DSystem::MAXLEVEL), nu(nu) -{ - -} +ViscosityBlockVisitor::ViscosityBlockVisitor(LBMReal nu) : Block3DVisitor(0, Grid3DSystem::MAXLEVEL), nu(nu) {} ////////////////////////////////////////////////////////////////////////// void ViscosityBlockVisitor::visit(SPtr<Grid3D> grid, SPtr<Block3D> block) { - if (block->getRank() == grid->getRank()) - { - LBMReal collFactor = LBMSystem::calcCollisionFactor(nu, block->getLevel()); - block->getKernel()->setCollisionFactor(collFactor); - } + if (block->getRank() == grid->getRank()) { + LBMReal collFactor = LBMSystem::calcCollisionFactor(nu, block->getLevel()); + block->getKernel()->setCollisionFactor(collFactor); + } } - diff --git a/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.h index 603a47462..003bd41e1 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/ViscosityBlockVisitor.h @@ -12,14 +12,14 @@ class Block3D; class ViscosityBlockVisitor : public Block3DVisitor { public: - ViscosityBlockVisitor(LBMReal nu); + ViscosityBlockVisitor(LBMReal nu); - ~ViscosityBlockVisitor() override = default; + ~ViscosityBlockVisitor() override = default; - void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; + void visit(SPtr<Grid3D> grid, SPtr<Block3D> block) override; private: - LBMReal nu; + LBMReal nu; }; #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.cpp b/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.cpp index ebbc5ec54..9a148a4f9 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.cpp +++ b/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.cpp @@ -1,148 +1,132 @@ #if defined VF_ZOLTAN && defined VF_MPI #include "ZoltanPartitioningGridVisitor.h" -#include <vector> -#include "UbLogger.h" -#include "UbException.h" -#include "Grid3D.h" #include "Block3D.h" +#include "Grid3D.h" +#include "UbException.h" +#include "UbLogger.h" +#include <vector> using namespace std; -ZoltanPartitioningGridVisitor::ZoltanPartitioningGridVisitor(SPtr<Communicator> comm, int numOfDirs, int numOfLocalParts) : -comm(comm), -numOfDirs(numOfDirs), -numOfLocalParts(numOfLocalParts) +ZoltanPartitioningGridVisitor::ZoltanPartitioningGridVisitor(SPtr<Communicator> comm, int numOfDirs, + int numOfLocalParts) + : comm(comm), numOfDirs(numOfDirs), numOfLocalParts(numOfLocalParts) { } ////////////////////////////////////////////////////////////////////////// -ZoltanPartitioningGridVisitor::~ZoltanPartitioningGridVisitor() -{ - -} +ZoltanPartitioningGridVisitor::~ZoltanPartitioningGridVisitor() {} ////////////////////////////////////////////////////////////////////////// void ZoltanPartitioningGridVisitor::visit(SPtr<Grid3D> grid) { - UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::visit() - start"); + UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::visit() - start"); + + // MPI_Comm mpi_comm = *((MPI_Comm*) comm->getNativeCommunicator()); - //MPI_Comm mpi_comm = *((MPI_Comm*) comm->getNativeCommunicator()); + // ZoltanPartitioner zp(mpi_comm, comm->getProcessID(), numOfLocalParts); + // + // graph = zp.getGraphData(); - //ZoltanPartitioner zp(mpi_comm, comm->getProcessID(), numOfLocalParts); - // - //graph = zp.getGraphData(); - - collectData(grid); + collectData(grid); - //zp.partition(); + // zp.partition(); - //repartGrid(grid, zp); + // repartGrid(grid, zp); - UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::visit() - end"); + UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::visit() - end"); } ////////////////////////////////////////////////////////////////////////// void ZoltanPartitioningGridVisitor::collectData(SPtr<Grid3D> grid) { - int myRank = comm->getProcessID(); - int numOfProc = comm->getNumberOfProcesses(); - - if (numOfProc < 2) - { - return; - } - - int minInitLevel = grid->getCoarsestInitializedLevel(); - int maxInitLevel = grid->getFinestInitializedLevel(); - - for (int l = minInitLevel; l<=maxInitLevel; l++) - { - MPI_Comm mpi_comm = *((MPI_Comm*)comm->getNativeCommunicator()); - ZoltanPartitioner zp(mpi_comm, comm->getProcessID(), numOfLocalParts); - graph = zp.getGraphData(); - - int n = 0; - vector<SPtr<Block3D>> blockVector; - grid->getBlocks(l, blockVector); - - if (blockVector.size() == 0) - { - UB_THROW(UbException(UB_EXARGS, "Blocks for decomposition don't exist!")); - } - - //Verteilung von Ranks - int rank = 0; - for(SPtr<Block3D> block : blockVector) - { - block->setRank(rank); - block->setPart(rank); - rank++; - if (rank > numOfProc - 1) - rank = 0; - } - - int vertices = 0; - - for(SPtr<Block3D> block : blockVector) - { - if (block->getRank() == myRank) - { - vertices++; - - vertexGID.push_back(block->getGlobalID()); - - int edges = 0; - for (int dir = 0; dir <= numOfDirs; dir++) - { - SPtr<Block3D> neighBlock = (grid->getNeighborBlock(dir, - block->getX1(), block->getX2(), block->getX3(), l)); - - if (neighBlock) - { - edges++; - nborGID.push_back(neighBlock->getGlobalID()); - nborProc.push_back(neighBlock->getRank()); - } + int myRank = comm->getProcessID(); + int numOfProc = comm->getNumberOfProcesses(); + + if (numOfProc < 2) { + return; + } + + int minInitLevel = grid->getCoarsestInitializedLevel(); + int maxInitLevel = grid->getFinestInitializedLevel(); + + for (int l = minInitLevel; l <= maxInitLevel; l++) { + MPI_Comm mpi_comm = *((MPI_Comm *)comm->getNativeCommunicator()); + ZoltanPartitioner zp(mpi_comm, comm->getProcessID(), numOfLocalParts); + graph = zp.getGraphData(); + + int n = 0; + vector<SPtr<Block3D>> blockVector; + grid->getBlocks(l, blockVector); + + if (blockVector.size() == 0) { + UB_THROW(UbException(UB_EXARGS, "Blocks for decomposition don't exist!")); + } + + // Verteilung von Ranks + int rank = 0; + for (SPtr<Block3D> block : blockVector) { + block->setRank(rank); + block->setPart(rank); + rank++; + if (rank > numOfProc - 1) + rank = 0; + } + + int vertices = 0; + + for (SPtr<Block3D> block : blockVector) { + if (block->getRank() == myRank) { + vertices++; + + vertexGID.push_back(block->getGlobalID()); + + int edges = 0; + for (int dir = 0; dir <= numOfDirs; dir++) { + SPtr<Block3D> neighBlock = + (grid->getNeighborBlock(dir, block->getX1(), block->getX2(), block->getX3(), l)); + + if (neighBlock) { + edges++; + nborGID.push_back(neighBlock->getGlobalID()); + nborProc.push_back(neighBlock->getRank()); + } + } + numEdges.push_back(edges); } - numEdges.push_back(edges); - } - } - graph->numLocalVertices = vertices; - graph->vnumEdges = numEdges; - graph->vvertexGID = vertexGID; - graph->vnborGID = nborGID; - graph->vnborProc = nborProc; - - zp.partition(); - repartGrid(grid, zp); - } + } + graph->numLocalVertices = vertices; + graph->vnumEdges = numEdges; + graph->vvertexGID = vertexGID; + graph->vnborGID = nborGID; + graph->vnborProc = nborProc; + + zp.partition(); + repartGrid(grid, zp); + } } ////////////////////////////////////////////////////////////////////////// -void ZoltanPartitioningGridVisitor::repartGrid(SPtr<Grid3D> grid, ZoltanPartitioner& zp) +void ZoltanPartitioningGridVisitor::repartGrid(SPtr<Grid3D> grid, ZoltanPartitioner &zp) { - if (zp.areChanges()) - { - UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::repartGrid - start" ); - vector<int> sExportGlobalGids, sExportToPart, sExportProcs; - vector<int> rExportGlobalGids, rExportToPart, rExportProcs; - - zp.getExportData(sExportGlobalGids, sExportToPart, sExportProcs); - - comm->allGather(sExportGlobalGids, rExportGlobalGids); - comm->allGather(sExportToPart, rExportToPart); - comm->allGather(sExportProcs, rExportProcs); - - for (int i = 0; i < (int)rExportGlobalGids.size(); i++) - { - if (rExportGlobalGids[i] != -1) - { - SPtr<Block3D> block = grid->getBlock(rExportGlobalGids[i]); - if(block) - { - block->setRank(rExportProcs[i]); - block->setPart(rExportToPart[i]); + if (zp.areChanges()) { + UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::repartGrid - start"); + vector<int> sExportGlobalGids, sExportToPart, sExportProcs; + vector<int> rExportGlobalGids, rExportToPart, rExportProcs; + + zp.getExportData(sExportGlobalGids, sExportToPart, sExportProcs); + + comm->allGather(sExportGlobalGids, rExportGlobalGids); + comm->allGather(sExportToPart, rExportToPart); + comm->allGather(sExportProcs, rExportProcs); + + for (int i = 0; i < (int)rExportGlobalGids.size(); i++) { + if (rExportGlobalGids[i] != -1) { + SPtr<Block3D> block = grid->getBlock(rExportGlobalGids[i]); + if (block) { + block->setRank(rExportProcs[i]); + block->setPart(rExportToPart[i]); + } } - } - } - UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::repartGrid - end" ); - } + } + UBLOG(logDEBUG5, "ZoltanPartitioningPatchVisitor::repartGrid - end"); + } } #endif diff --git a/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.h b/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.h index f99134e4f..4d9cd63c5 100644 --- a/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.h +++ b/src/cpu/VirtualFluidsCore/Visitors/ZoltanPartitioningGridVisitor.h @@ -1,37 +1,39 @@ /** -* @file ZoltanPartitioningPatchVisitor.h -* @brief Visitor class wich apply Zoltan library partitioning. -* @author Kostyantyn Kucher -* @date 10.06.2011 -*/ + * @file ZoltanPartitioningPatchVisitor.h + * @brief Visitor class wich apply Zoltan library partitioning. + * @author Kostyantyn Kucher + * @date 10.06.2011 + */ #ifndef ZoltanPartitioningGridVisitor_H #define ZoltanPartitioningGridVisitor_H #if defined VF_ZOLTAN && defined VF_MPI -#include "Grid3DVisitor.h" #include "Communicator.h" +#include "Grid3DVisitor.h" #include "ZoltanPartitioner.h" class ZoltanPartitioningGridVisitor : public Grid3DVisitor { public: - ZoltanPartitioningGridVisitor(SPtr<Communicator> comm, int numOfDirs, int numOfLocalParts = 1); - ~ZoltanPartitioningGridVisitor(); - void visit(SPtr<Grid3D> grid); + ZoltanPartitioningGridVisitor(SPtr<Communicator> comm, int numOfDirs, int numOfLocalParts = 1); + ~ZoltanPartitioningGridVisitor(); + void visit(SPtr<Grid3D> grid); + protected: - void collectData(SPtr<Grid3D> grid); - void repartGrid(SPtr<Grid3D> grid, ZoltanPartitioner& zp); + void collectData(SPtr<Grid3D> grid); + void repartGrid(SPtr<Grid3D> grid, ZoltanPartitioner &zp); + private: - SPtr<Communicator> comm; - int numOfDirs; - int numOfLocalParts; - ZoltanGraph *graph; - std::vector<int> vertexGID; - std::vector<int> numEdges; - std::vector<int> nborGID; - std::vector<int> nborProc; + SPtr<Communicator> comm; + int numOfDirs; + int numOfLocalParts; + ZoltanGraph *graph; + std::vector<int> vertexGID; + std::vector<int> numEdges; + std::vector<int> nborGID; + std::vector<int> nborProc; }; #endif -- GitLab