diff --git a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp b/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp index 4a666b13ea697c002573d6aa08f263b6346430f9..3e75d3c4cc29f8c963dfe4d2edc78fec884385d3 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/Simulation.cpp +++ b/src/gpu/VirtualFluids_GPU/LBM/Simulation.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/>. // @@ -31,160 +31,160 @@ //! \author Martin Schoenherr //======================================================================================= #include "Simulation.h" -#include "LBM/LB.h" -#include "Parameter/Parameter.h" #include "AdvectionDiffusion/AdvectionDiffusion.h" +#include "DataStructureInitializer/GridProvider.h" +#include "GPU/CudaKernelManager.h" +#include "GPU/CudaMemoryManager.h" #include "GPU/devCheck.h" -#include "GPU/CudaMemoryManager.h" -#include "GPU/CudaKernelManager.h" #include "Init/InitLattice.h" -#include "DataStructureInitializer/GridProvider.h" +#include "LBM/LB.h" #include "Output/DataWriter.h" +#include "Parameter/Parameter.h" #include "Core/Timer/Timer.h" #include <cuda_runtime.h> #include <helper_cuda.h> -#include <stdio.h> #include <memory> +#include <stdio.h> ////////////////////////////////////////////////////////////////////////// -Simulation::Simulation() -{} +Simulation::Simulation() {} -Simulation::~Simulation() -{} +Simulation::~Simulation() {} -void Simulation::init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, SPtr<DataWriter> dataWriter, SPtr<CudaMemoryManager> cudaMemoryManager) +void Simulation::init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, SPtr<DataWriter> dataWriter, + SPtr<CudaMemoryManager> cudaMemoryManager) { - devCheck(0); + devCheck(0); - this->dataWriter = dataWriter; - this->gridProvider = gridProvider; - this->cudaMemoryManager = cudaMemoryManager; - this->para = para; + this->dataWriter = dataWriter; + this->gridProvider = gridProvider; + this->cudaMemoryManager = cudaMemoryManager; + this->para = para; this->cudaKernelManager = CudaKernelManager::make(para); - - para->initParameter(); - para->setRe(para->getVelocityLB() * (real)1.0 / para->getViscosityLB()); - - gridProvider->allocAndCopyForcing(); - - ////////////////////////////////////////////////////////////////////////// - // create and use log file - output.setName(para->getPathAndFilename() + ".log"); - output.setConsoleOut(true); - output.clearLogFile(); - - output << "Re: " << para->getRe() << "\n"; - output << "vis_ratio: " << para->getViscosityRatio() << "\n"; - output << "u0_ratio: " << para->getVelocityRatio() << "\n"; - output << "rho_ratio: " << para->getDensityRatio() << "\n"; - output << "velocityLB: " << para->getVelocityLB() << "\n"; - output << "viscosityLB:" << para->getViscosityLB() << "\n"; + + para->initParameter(); + para->setRe(para->getVelocityLB() * (real)1.0 / para->getViscosityLB()); + + gridProvider->allocAndCopyForcing(); + + ////////////////////////////////////////////////////////////////////////// + // create and use log file + output.setName(para->getPathAndFilename() + ".log"); + output.setConsoleOut(true); + output.clearLogFile(); + + output << "Re: " << para->getRe() << "\n"; + output << "vis_ratio: " << para->getViscosityRatio() << "\n"; + output << "u0_ratio: " << para->getVelocityRatio() << "\n"; + output << "rho_ratio: " << para->getDensityRatio() << "\n"; + output << "velocityLB: " << para->getVelocityLB() << "\n"; + output << "viscosityLB:" << para->getViscosityLB() << "\n"; output << "Fx: " << para->getParH()->forcing[0] << "\n"; - ///////////////////////////////////////////////////////////////////////// - // set the used device memory to 0 before starting the calculation - cudaMemoryManager->setMemsizeGPU(0, true); - - ////////////////////////////////////////////////////////////////////////// - // allocate the memory for several arrays - gridProvider->allocArrays_CoordNeighborGeo(); - gridProvider->allocArrays_BoundaryValues(); - gridProvider->allocArrays_BoundaryQs(); - - // Advection Diffusion - if (para->getIsADcalculationOn()) - { - para->getParH()->diffusivity = para->getViscosityLB()/para->getSc(); - para->getParD()->diffusivity = para->getParH()->diffusivity; - cudaMemoryManager->cudaAllocConcentrationDistributions(); - cudaMemoryManager->cudaAllocConcentration(); - setInitialNodeValuesAD(para, cudaMemoryManager); - } - - ////////////////////////////////////////////////////////////////////////// - // initialize the grid - output << "init lattice..."; - initLattice(para); - output << "done.\n"; - - ////////////////////////////////////////////////////////////////////////// - // print initialized grid - output << "Print files Init..."; + ///////////////////////////////////////////////////////////////////////// + // set the used device memory to 0 before starting the calculation + cudaMemoryManager->setMemsizeGPU(0, true); + + ////////////////////////////////////////////////////////////////////////// + // allocate the memory for several arrays + gridProvider->allocArrays_CoordNeighborGeo(); + gridProvider->allocArrays_BoundaryValues(); + gridProvider->allocArrays_BoundaryQs(); + + // Advection Diffusion + if (para->getIsADcalculationOn()) { + para->getParH()->diffusivity = para->getViscosityLB() / para->getSc(); + para->getParD()->diffusivity = para->getParH()->diffusivity; + cudaMemoryManager->cudaAllocConcentrationDistributions(); + cudaMemoryManager->cudaAllocConcentration(); + setInitialNodeValuesAD(para, cudaMemoryManager); + } + + ////////////////////////////////////////////////////////////////////////// + // initialize the grid + output << "init lattice..."; + initLattice(para); + output << "done.\n"; + + ////////////////////////////////////////////////////////////////////////// + // print initialized grid + output << "Print files Init..."; dataWriter->writeInit(para, cudaMemoryManager, cudaKernelManager); - output << "done.\n"; + output << "done.\n"; - ////////////////////////////////////////////////////////////////////////// - // print the amount of used device memory - output << "used device memory: " << cudaMemoryManager->getMemsizeGPU() / 1000000.0 << " MB\n"; + ////////////////////////////////////////////////////////////////////////// + // print the amount of used device memory + output << "used device memory: " << cudaMemoryManager->getMemsizeGPU() / 1000000.0 << " MB\n"; } void Simulation::run() { - uint timestep; - ////////////////////////////////////////////////////////////////////////// - // Timer - auto timer = Timer::makeStart(); - real timeComplete = 0.0; - // MNUPS(million node updates per second) - output << "Processing time (s) \t NUPS * 10^6\n"; - - //////////////////////////////////////////////////////////////////////////////// - // Time loop - for (timestep = para->getTimestepStart(); timestep <= para->getTimestepEnd(); timestep++) - { - //////////////////////////////////////////////////////////////////////////////// - // Advection Diffusion calculation ... Advection first -> fluid second - if (para->getIsADcalculationOn()) - calcAD(para); - - //////////////////////////////////////////////////////////////////////////////// - // LBM Kernel - cudaKernelManager->runLBMKernel(para); - - //////////////////////////////////////////////////////////////////////////////// - //velocity boundary condition - if(para->getParD()->numberOfInflowBCnodes > 1) - cudaKernelManager->runVelocityBCKernel(para); - - //////////////////////////////////////////////////////////////////////////////// - if (para->getParD()->isEvenTimestep) para->getParD()->isEvenTimestep = false; - else para->getParD()->isEvenTimestep = true; - //////////////////////////////////////////////////////////////////////////////// - // File IO and calculation of MNUPS(million node updates per second) - if (para->getTimestepOut() > 0 && timestep%para->getTimestepOut() == 0 && timestep >= para->getTimestepStartOut()) - { - checkCudaErrors(cudaDeviceSynchronize()); - ////////////////////////////////////////////////////////////////////////// - // Timer - timer->end(); - real timeInterval = timer->getTimeInSeconds(); - timeComplete += timeInterval; - real fnups = ((real)(timestep - para->getTimestepStart()) * (real)para->getParH()->numberOfNodes) / ((real)timeComplete*(real)1.0E6); - output << timeInterval << " / " << timeComplete << " \t " << fnups << "\n"; - ////////////////////////////////////////////////////////////////////////// - //IO - if (para->getPrintFiles()) - { - output << "File IO for t=" << timestep << "..."; + uint timestep; + ////////////////////////////////////////////////////////////////////////// + // Timer + auto timer = Timer::makeStart(); + real timeComplete = 0.0; + // MNUPS(million node updates per second) + output << "Processing time (s) \t NUPS * 10^6\n"; + + //////////////////////////////////////////////////////////////////////////////// + // Time loop + for (timestep = para->getTimestepStart(); timestep <= para->getTimestepEnd(); timestep++) { + //////////////////////////////////////////////////////////////////////////////// + // Advection Diffusion calculation ... Advection first -> fluid second + if (para->getIsADcalculationOn()) + calcAD(para); + + //////////////////////////////////////////////////////////////////////////////// + // LBM Kernel + cudaKernelManager->runLBMKernel(para); + + //////////////////////////////////////////////////////////////////////////////// + // velocity boundary condition + if (para->getParD()->numberOfInflowBCnodes > 1) + cudaKernelManager->runVelocityBCKernel(para); + + //////////////////////////////////////////////////////////////////////////////// + if (para->getParD()->isEvenTimestep) + para->getParD()->isEvenTimestep = false; + else + para->getParD()->isEvenTimestep = true; + //////////////////////////////////////////////////////////////////////////////// + // File IO and calculation of MNUPS(million node updates per second) + if (para->getTimestepOut() > 0 && timestep % para->getTimestepOut() == 0 && + timestep >= para->getTimestepStartOut()) { + checkCudaErrors(cudaDeviceSynchronize()); + ////////////////////////////////////////////////////////////////////////// + // Timer + timer->end(); + real timeInterval = timer->getTimeInSeconds(); + timeComplete += timeInterval; + real fnups = ((real)(timestep - para->getTimestepStart()) * (real)para->getParH()->numberOfNodes) / + ((real)timeComplete * (real)1.0E6); + output << timeInterval << " / " << timeComplete << " \t " << fnups << "\n"; + ////////////////////////////////////////////////////////////////////////// + // IO + if (para->getPrintFiles()) { + output << "File IO for t=" << timestep << "..."; dataWriter->writeTimestep(para, cudaMemoryManager, cudaKernelManager, timestep); - output << "done.\n"; - } - timer->start(); - } - } - - ////////////////////////////////////////////////////////////////////////// - // Timer - timer->end(); - real timeInterval = timer->getTimeInSeconds(); - timeComplete += timeInterval; - real fnups = ((real)(timestep - para->getTimestepStart()) * para->getParH()->numberOfNodes) / (timeComplete*1.0E6); - output << "Processing time: " << timeComplete << "(ms)\n"; - output << "NUPS: " << fnups << " * 10^6\n"; + output << "done.\n"; + } + timer->start(); + } + } + + ////////////////////////////////////////////////////////////////////////// + // Timer + timer->end(); + real timeInterval = timer->getTimeInSeconds(); + timeComplete += timeInterval; + real fnups = + ((real)(timestep - para->getTimestepStart()) * para->getParH()->numberOfNodes) / (timeComplete * 1.0E6); + output << "Processing time: " << timeComplete << "(ms)\n"; + output << "NUPS: " << fnups << " * 10^6\n"; } void Simulation::free() @@ -205,8 +205,4 @@ void Simulation::free() // Advection Diffusion if (para->getIsADcalculationOn()) this->cudaMemoryManager->cudaFreeConcentration(); - - para->~Parameter(); - gridProvider->~GridProvider(); - dataWriter->~DataWriter(); } \ No newline at end of file diff --git a/src/gpu/VirtualFluids_GPU/LBM/Simulation.h b/src/gpu/VirtualFluids_GPU/LBM/Simulation.h index 52f9b998a3b34d9510937ab7fded17049f379797..569a4b63e4c263eceb3c302d6c022aa930292c6f 100644 --- a/src/gpu/VirtualFluids_GPU/LBM/Simulation.h +++ b/src/gpu/VirtualFluids_GPU/LBM/Simulation.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,9 +33,9 @@ #ifndef _SIMULATION_H_ #define _SIMULATION_H_ -#include <PointerDefinitions.h> #include "Output/LogWriter.hpp" #include "VirtualFluids_GPU_export.h" +#include <PointerDefinitions.h> //! \brief Class forwarding for CudaMemoryManager, Parameter, GridProvider and DataWriter class CudaMemoryManager; @@ -49,30 +49,31 @@ class DataWriter; class VIRTUALFLUIDS_GPU_EXPORT Simulation { public: - //! Class default constructor - Simulation(); - //! Class destructor - ~Simulation(); - //! \brief includes the time loop over all LB-timesteps - void run(); - //! \brief initialize the lattice (incl. distribution functions) - void init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, SPtr<DataWriter> dataWriter, SPtr<CudaMemoryManager> cudaMemoryManager); - //! \brief frees the pinned host memory - void free(); + //! Class default constructor + Simulation(); + //! Class destructor + ~Simulation(); + //! \brief includes the time loop over all LB-timesteps + void run(); + //! \brief initialize the lattice (incl. distribution functions) + void init(SPtr<Parameter> para, SPtr<GridProvider> gridProvider, SPtr<DataWriter> dataWriter, + SPtr<CudaMemoryManager> cudaMemoryManager); + //! \brief frees the pinned host memory + void free(); protected: - //! \property output is an object of LogWriter - LogWriter output; + //! \property output is an object of LogWriter + LogWriter output; - //! \brief shared pointer to parameter, gridProvider, dataWriter and cudaManager objects - //! \property para is a shared pointer to an object of Parameter - SPtr<Parameter> para; - //! \property gridProvider is a shared pointer to an object of GridProvider - SPtr<GridProvider> gridProvider; - //! \property dataWriter is a shared pointer to an object of DataWriter - SPtr<DataWriter> dataWriter; - //! \property cudaMemoryManager is a shared pointer to an object of CudaMemoryManager - SPtr<CudaMemoryManager> cudaMemoryManager; + //! \brief shared pointer to parameter, gridProvider, dataWriter and cudaManager objects + //! \property para is a shared pointer to an object of Parameter + SPtr<Parameter> para; + //! \property gridProvider is a shared pointer to an object of GridProvider + SPtr<GridProvider> gridProvider; + //! \property dataWriter is a shared pointer to an object of DataWriter + SPtr<DataWriter> dataWriter; + //! \property cudaMemoryManager is a shared pointer to an object of CudaMemoryManager + SPtr<CudaMemoryManager> cudaMemoryManager; //! \property cudaKernelManager is a shared pointer to an object of CudaKernelManager SPtr<CudaKernelManager> cudaKernelManager; };