VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
PrecursorWriter.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 PRECURSORPROBE_H_
37#define PRECURSORPROBE_H_
38
39#include <future>
40#include <stdexcept>
41#include <string>
42#include <vector>
43
44#include <basics/DataTypes.h>
47
48#include <logger/Logger.h>
49
50#include "Sampler.h"
51
52namespace vf::gpu {
53
54class Parameter;
55class CudaMemoryManager;
56
62{
63public:
66
67 PrecursorWriter(SPtr<Parameter> para, SPtr<CudaMemoryManager> cudaMemoryManager, const std::string& outputPath,
68 const std::string& probeName, real xPos, real yMin, real yMax, real zMin, real zMax,
69 uint tStartWritingOutput, uint tSave, OutputVariable outputVariable,
70 uint maxTimestepsPerFile = uint(1e4))
71 : para(std::move(para)), cudaMemoryManager(std::move(cudaMemoryManager)), xPos(xPos), yMin(yMin), yMax(yMax),
72 zMin(zMin), zMax(zMax), tStartWritingOutput(tStartWritingOutput), tSave(tSave), outputVariable(outputVariable),
73 maxTimestepsPerFile(maxTimestepsPerFile), Sampler(outputPath, probeName)
74 {
75 nodeDataNames = determineNodeDataNames();
76 writeFuture = std::async([]() {});
77 };
78
79 PrecursorWriter(SPtr<Parameter> para, SPtr<CudaMemoryManager> cudaMemoryManager, const std::string& outputPath,
80 const std::string& probeName, real xPos, real yMin, real yMax, real zMin, real zMax,
81 uint tStartWritingOutput, uint tSave, OutputVariable outputVariable,
82 OutputVariableTemperature tempOutputVariable,
83 uint maxTimestepsPerFile = uint(1e4))
84 : para(std::move(para)), cudaMemoryManager(std::move(cudaMemoryManager)), xPos(xPos), yMin(yMin), yMax(yMax),
85 zMin(zMin), zMax(zMax), tStartWritingOutput(tStartWritingOutput), tSave(tSave), outputVariable(outputVariable),
86 tempOutputVariable(tempOutputVariable), maxTimestepsPerFile(maxTimestepsPerFile), Sampler(outputPath, probeName)
87 {
88 nodeDataNames = determineNodeDataNames();
89 writeFuture = std::async([]() {});
90 };
91
93
94 void init() override;
95 void sample(int level, uint t) override;
97
99 {
100 return this->outputVariable;
101 }
103 {
104 return this->tempOutputVariable;
105 }
120
122 {
123 return &precursorStructs[level];
124 }
125 std::string makeFileName(int level, uint numberOfFilesWritten);
126
127 void setWritePrecision(uint writePrecision)
128 {
129 this->writePrecision = writePrecision;
130 }
131
132 static constexpr uint dP00 = 0;
133 static constexpr uint dPP0 = 1;
134 static constexpr uint dPM0 = 2;
135 static constexpr uint dP0P = 3;
136 static constexpr uint dP0M = 4;
137 static constexpr uint dPPP = 5;
138 static constexpr uint dPMP = 6;
139 static constexpr uint dPPM = 7;
140 static constexpr uint dPMM = 8;
141
142private:
143 WbWriterVtkXmlImageBinary* getWriter()
144 {
146 };
147 void write(int level, uint numberOfTimestepsBuffered);
148
149 std::vector<std::string> determineNodeDataNames()
150 {
151 std::vector<std::string> res;
152
153 switch (outputVariable) {
155 res = { "vx", "vy", "vz" };
156 break;
158 res = { "fP00", "fPP0", "fPM0", "fP0P", "fP0M", "fPPP", "fPMP", "fPPM", "fPMM" };
159 break;
160 default:
161 throw std::runtime_error("Invalid OutputVariable for PrecursorWriter");
162 }
163
164 switch (tempOutputVariable) {
166 res.push_back("T");
167 break;
169 res.insert(res.end(), {"gP00", "gPP0", "gPM0", "gP0P", "gP0M",
170 "gPPP", "gPMP", "gPPM", "gPMM"});
171 break;
172 default:
173 break;
174 }
175 return res;
176 }
177
178private:
179 SPtr<Parameter> para;
180 SPtr<CudaMemoryManager> cudaMemoryManager;
181 std::vector<PrecursorStruct> precursorStructs;
182 std::vector<std::string> nodeDataNames;
183 std::vector<std::string> cellDataNames;
184 uint tStartWritingOutput, tSave, maxTimestepsPerFile;
185 real xPos, yMin, yMax, zMin, zMax;
186 OutputVariable outputVariable;
187 OutputVariableTemperature tempOutputVariable;
188 std::future<void> writeFuture;
189 uint writePrecision = 8;
190};
191
192}
193
194#endif // PRECURSORPROBE_H_
195
static WbWriterVtkXmlImageBinary * getInstance()
Probe writing planes of data to be used as inflow data in successor simulation using PrecursorBC The ...
static constexpr uint dPMM
static constexpr uint dP00
std::string makeFileName(int level, uint numberOfFilesWritten)
OutputVariableTemperature getTempOutputVariable()
PrecursorStruct * getPrecursorStruct(int level)
void setWritePrecision(uint writePrecision)
static constexpr uint dP0M
PrecursorWriter(SPtr< Parameter > para, SPtr< CudaMemoryManager > cudaMemoryManager, const std::string &outputPath, const std::string &probeName, real xPos, real yMin, real yMax, real zMin, real zMax, uint tStartWritingOutput, uint tSave, OutputVariable outputVariable, OutputVariableTemperature tempOutputVariable, uint maxTimestepsPerFile=uint(1e4))
void init() override
static constexpr uint dPM0
static constexpr uint dP0P
static constexpr uint dPMP
static constexpr uint dPPP
static constexpr uint dPPM
PrecursorWriter(SPtr< Parameter > para, SPtr< CudaMemoryManager > cudaMemoryManager, const std::string &outputPath, const std::string &probeName, real xPos, real yMin, real yMax, real zMin, real zMax, uint tStartWritingOutput, uint tSave, OutputVariable outputVariable, uint maxTimestepsPerFile=uint(1e4))
static constexpr uint dPP0
void sample(int level, uint t) override
OutputVariable getOutputVariable()
void getTaggedFluidNodes(GridProvider *gridProvider) override
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