VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
PlanarAverageProbe.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//
34//=======================================================================================
35
36#ifndef PlanarAverageProbe_H
37#define PlanarAverageProbe_H
38
39#include "Sampler.h"
40
41#include <stdexcept>
42#include <string>
43#include <vector>
44
45#include <basics/DataTypes.h>
47#include <logger/Logger.h>
48
49namespace vf::gpu {
50
51class Parameter;
52class CudaMemoryManager;
53
59{
60public:
61 enum class Statistic {
62 Means,
66 };
67 struct LevelData;
68
69public:
79 PlanarAverageProbe(SPtr<Parameter> para, SPtr<CudaMemoryManager> cudaMemoryManager, const std::string& outputPath,
80 const std::string& probeName, uint tStartSampling, uint tStartTemporalAveraging, uint tBetweenSamples,
81 uint tStartWritingOutput, uint tBetweenWriting, Axis planeNormal, bool computeTimeAverages,
82 bool sampleScalar = false, bool sampleSubgridScaleFluxes = false)
83 : para(std::move(para)), cudaMemoryManager(std::move(cudaMemoryManager)), tStartSampling(tStartSampling),
84 tStartTemporalAveraging(tStartTemporalAveraging), tBetweenSamples(tBetweenSamples),
85 tStartWritingOutput(tStartWritingOutput), tBetweenWriting(tBetweenWriting),
86 computeTimeAverages(computeTimeAverages), planeNormal(planeNormal), sampleScalar(sampleScalar),
87 sampleSubgridScaleFluxes(sampleSubgridScaleFluxes), Sampler(outputPath, probeName)
88 {
89 if (tBetweenSamples == 0)
90 throw std::runtime_error("PlanarAverageProbe: tBetweenSamples is 0! tBetweenSamples must be larger than 0");
91 if (tBetweenWriting == 0)
92 throw std::runtime_error("PlanarAverageProbe: tBetweenWriting is 0! tBetweenWriting must be larger than 0");
93 if (tStartTemporalAveraging < tStartSampling && computeTimeAverages)
94 throw std::runtime_error("PlaneAverageProbe: tStartTemporalAveraging must be larger than tStartSampling!");
95
97 "Created planar averaging probe, output path: " + outputPath + ", probe name: " + probeName +
98 " start sampling: {}, time steps between sampling: {}, start writing: {}, time steps between writing: {}",
99 tStartSampling, tBetweenSamples, tStartWritingOutput, tBetweenWriting);
100 if(sampleScalar)
101 VF_LOG_INFO("sampling scalar.");
102 if(sampleSubgridScaleFluxes)
103 VF_LOG_INFO("sampling sub-gridscale fluxes.");
104 }
106
107 void init() override;
108 void sample(int level, uint t) override;
111 {
112 return &levelData[level];
113 }
123 {
124 nameFilesWithFileCount = true;
125 }
126 bool getSampleScalar() const
127 {
128 return sampleScalar;
129 }
130
131private:
132 std::vector<std::string> getVariableNames(Statistic statistic, bool namesForTimeAverages) const;
133 void copyDataToNodedata(std::vector<std::vector<real>>& data, std::vector<std::vector<double>>& nodeData);
134 void calculateQuantities(int level, bool doTimeAverages);
135 void findCoordinatesForPlanes(int level, std::vector<real>& coordinateX, std::vector<real>& coordinateY,
136 std::vector<real>& coordinateZ, std::vector<uint>& numberOfNodesPerPlane);
137 std::vector<real> computePlaneStatistics(int level, uint nNodes);
138
139 std::vector<std::string> getAllVariableNames();
140 const uint* getNeighborIndicesInPlaneNormal(int level);
141 const real* getPlaneNormalCoordinatesH(int level);
142 const real* getPlaneNormalCoordinatesD(int level);
143 void writeGridFile(int level, uint tWrite);
144 void writeParallelFile(uint tWrite);
145
146private:
147 SPtr<Parameter> para;
148 SPtr<CudaMemoryManager> cudaMemoryManager;
149 const uint tStartSampling, tStartTemporalAveraging, tBetweenSamples, tStartWritingOutput, tBetweenWriting;
150 const bool computeTimeAverages, sampleScalar, sampleSubgridScaleFluxes;
151 bool nameFilesWithFileCount = false;
152 const Axis planeNormal;
153 std::vector<Statistic> statistics;
154 std::vector<LevelData> levelData;
155 std::vector<std::string> fileNamesForCollectionFile;
156};
157
158bool isStatisticIn(PlanarAverageProbe::Statistic statistic, std::vector<PlanarAverageProbe::Statistic> statistics);
159
171
172}
173
174#endif
#define VF_LOG_INFO(...)
Definition Logger.h:50
Computes spatial statistics across x, y or z-normal planes defined by planeNormal....
void sample(int level, uint t) override
void getTaggedFluidNodes(GridProvider *) override
PlanarAverageProbe(SPtr< Parameter > para, SPtr< CudaMemoryManager > cudaMemoryManager, const std::string &outputPath, const std::string &probeName, uint tStartSampling, uint tStartTemporalAveraging, uint tBetweenSamples, uint tStartWritingOutput, uint tBetweenWriting, Axis planeNormal, bool computeTimeAverages, bool sampleScalar=false, bool sampleSubgridScaleFluxes=false)
LevelData * getLevelData(int level)
void addStatistic(Statistic statistic)
Base class for all samplers.
Definition Sampler.h:58
std::string outputPath
Definition Sampler.h:72
std::string probeName
Definition Sampler.h:73
std::shared_ptr< T > SPtr
float real
Definition DataTypes.h:42
unsigned int uint
Definition DataTypes.h:47
Axis
Definition Axis.h:41
bool isStatisticIn(PlanarAverageProbe::Statistic statistic, std::vector< PlanarAverageProbe::Statistic > statistics)
std::vector< std::vector< real > > timeAverages
std::vector< std::vector< real > > instantaneous