VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Simulation.h
Go to the documentation of this file.
1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
15//
16// This file is part of VirtualFluids. VirtualFluids is free software: you can
17// redistribute it and/or modify it under the terms of the GNU General Public
18// License as published by the Free Software Foundation, either version 3 of
19// the License, or (at your option) any later version.
20//
21// VirtualFluids is distributed in the hope that it will be useful, but WITHOUT
22// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
23// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
24// for more details.
25//
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
28//
33//=======================================================================================
34#ifndef GPU_SIMULATION_H_
35#define GPU_SIMULATION_H_
36
37#include <memory>
38#include <vector>
39
42#include <basics/Timer/Timer.h>
43
46
47namespace vf::parallel
48{
49class Communicator;
50}
51
52namespace vf::gpu {
53
54class GridBuilder;
55class CudaMemoryManager;
56class Parameter;
57class GridProvider;
58class RestartObject;
59class ForceCalculations;
60class DataWriter;
61class Kernel;
62class AdvectionDiffusionKernel;
63class KernelFactory;
64class PreProcessor;
65class PreProcessorFactory;
67class UpdateGrid27;
68class KineticEnergyAnalyzer;
69class EnstrophyAnalyzer;
70class BoundaryConditionFactory;
71class GridScalingFactory;
72class TurbulenceModelFactory;
73
75{
76public:
77 Simulation(std::shared_ptr<Parameter> para, std::shared_ptr<GridBuilder> builder, const BoundaryConditionFactory* bcFactory,
78 GridScalingFactory* scalingFactory = nullptr);
79 Simulation(std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> memoryManager, std::shared_ptr<GridBuilder> builder, const BoundaryConditionFactory* bcFactory,
80 GridScalingFactory* scalingFactory = nullptr);
81
82 Simulation(std::shared_ptr<Parameter> para, std::shared_ptr<GridBuilder> builder, const BoundaryConditionFactory* bcFactory,
83 SPtr<TurbulenceModelFactory> tmFactory, GridScalingFactory* scalingFactory = nullptr);
84 Simulation(std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> memoryManager, std::shared_ptr<GridBuilder> builder, const BoundaryConditionFactory* bcFactory,
85 SPtr<TurbulenceModelFactory> tmFactory, GridScalingFactory* scalingFactory = nullptr);
86
87 Simulation(std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> memoryManager,
88 vf::parallel::Communicator &communicator, GridProvider &gridProvider, const BoundaryConditionFactory* bcFactory, GridScalingFactory* scalingFactory = nullptr);
89
91 void run();
92
93 void setFactories(std::unique_ptr<KernelFactory> &&kernelFactory,
94 std::unique_ptr<PreProcessorFactory> &&preProcessorFactory);
95 void setDataWriter(std::shared_ptr<DataWriter> dataWriter);
98
100 void calculateTimestep(uint timestep);
102 void initTimers();
104 void finalize();
105
106private:
107 void init(GridProvider &gridProvider, const BoundaryConditionFactory *bcFactory, SPtr<TurbulenceModelFactory> tmFactory, GridScalingFactory *scalingFactory);
108 void allocNeighborsOffsetsScalesAndBoundaries(GridProvider& gridProvider, const BoundaryConditionFactory* bcFactory);
109 void readAndWriteFiles(uint timestep);
110
111 std::unique_ptr<KernelFactory> kernelFactory;
112 std::shared_ptr<PreProcessorFactory> preProcessorFactory;
113
114 vf::parallel::Communicator& communicator;
115 SPtr<Parameter> para;
116 std::shared_ptr<DataWriter> dataWriter;
117 std::shared_ptr<CudaMemoryManager> cudaMemoryManager;
118 std::vector < SPtr< Kernel>> kernels;
119 std::vector < SPtr< AdvectionDiffusionKernel>> adKernels;
120 std::shared_ptr<PreProcessor> preProcessor;
121 std::shared_ptr<PreProcessor> preProcessorAD;
123
124 SPtr<RestartObject> restart_object;
125
126 // Timer
127 vf::basics::Timer averageTimer;
128 std::unique_ptr<PerformanceMeasurement> performanceOutput;
129 uint previousTimestepForAveraging;
130 uint previousTimestepForTurbulenceIntensityCalculation;
131 uint timestepForMeasuringPoints;
132
133 // Forcing Calculation
134 std::shared_ptr<ForceCalculations> forceCalculator;
135
136 std::unique_ptr<KineticEnergyAnalyzer> kineticEnergyAnalyzer;
137 std::unique_ptr<EnstrophyAnalyzer> enstrophyAnalyzer;
138 std::unique_ptr<UpdateGrid27> updateGrid27;
139
140 vf::basics::MetaData metaData;
141};
142
143}
144
145#endif
146
void setFactories(std::unique_ptr< KernelFactory > &&kernelFactory, std::unique_ptr< PreProcessorFactory > &&preProcessorFactory)
void addKineticEnergyAnalyzer(uint tAnalyse)
void addEnstrophyAnalyzer(uint tAnalyse)
void setDataWriter(std::shared_ptr< DataWriter > dataWriter)
void finalize()
finalize simulation. Only needs to be called when using calculateTimestep!
void calculateTimestep(uint timestep)
can be used as an alternative to run(), if the simulation needs to be controlled from the outside (e....
void initTimers()
needed to initialize the simulation timers if calculateTimestep is used instead of run()
An abstract class for communication between processes in parallel computation.
std::shared_ptr< T > SPtr
unsigned int uint
Definition DataTypes.h:47