1//=======================================================================================
2// ____ ____ __ ______ __________ __ __ __ __
3// \ \ | | | | | _ \ |___ ___| | | | | / \ | |
4// \ \ | | | | | |_) | | | | | | | / \ | |
5// \ \ | | | | | _ / | | | | | | / /\ \ | |
6// \ \ | | | | | | \ \ | | | \__/ | / ____ \ | |____
7// \ \ | | |__| |__| \__\ |__| \________/ /__/ \__\ |_______|
8// \ \ | | ________________________________________________________________
9// \ \ | | | ______________________________________________________________|
10// \ \| | | | __ __ __ __ ______ _______
11// \ | | |_____ | | | | | | | | | _ \ / _____)
12// \ | | _____| | | | | | | | | | | \ \ \_______
13// \ | | | | |_____ | \_/ | | | | |_/ / _____ |
14// \ _____| |__| |________| \_______/ |__| |______/ (_______/
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.
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
26// SPDX-License-Identifier: GPL-3.0-or-later
27// SPDX-FileCopyrightText: Copyright © VirtualFluids Project contributors, see AUTHORS.md in root folder
29//! \addtogroup gpu_Samplers
30//! \ingroup gpu_core core
32//! \author Henry Korb, Henrik Asmuth
33//=======================================================================================
44#include <basics/DataTypes.h>
45#include <basics/constants/NumericConstants.h>
46#include <basics/geometry3d/GbCuboid3D.h>
47#include <basics/geometry3d/GbObject3D.h>
48#include <basics/geometry3d/GbPoint3D.h>
50#include <logger/Logger.h>
53#include "gpu/core/Calculation/Calculation.h"
54#include "gpu/core/Cuda/CudaMemoryManager.h"
55#include "gpu/core/DataStructureInitializer/GridProvider.h"
56#include "gpu/core/Output/FilePartCalculator.h"
57#include "gpu/core/Parameter/Parameter.h"
58#include "gpu/core/Utilities/GeometryUtils.h"
59#include "gpu/cuda_helper/CudaGrid.h"
60#include "gpu/cuda_helper/CudaIndexCalculation.h"
65using namespace vf::basics::constant;
69Probe::Probe(std::shared_ptr<Parameter> para, std::shared_ptr<CudaMemoryManager> cudaMemoryManager,
70 const std::string& outputPath, const std::string& probeName, uint tStartSampling, uint tBetweenSamples,
71 uint tStartWritingOutput, uint tBetweenWriting, bool outputTimeSeries, bool sampleEveryTimestep,
73 : para(std::move(para)), cudaMemoryManager(std::move(cudaMemoryManager)), tStartSampling(tStartSampling),
74 tBetweenSamples(tBetweenSamples), tStartWritingOutput(tStartWritingOutput), tBetweenWriting(tBetweenWriting),
75 outputTimeSeries(outputTimeSeries), sampleEveryTimestep(sampleEveryTimestep), sampleScalar(sampleScalar),
76 Sampler(outputPath, probeName)
78 if(tBetweenSamples == 0)
79 throw std::runtime_error("Probe: tBetweenSamples is 0! If you want to sample every time step set sampleEveryTimestep to true");
80 if(tBetweenWriting == 0)
81 throw std::runtime_error("Probe: tBetweenWriting is 0! tBetweenWriting must be larger than 0");
82 if (tStartWritingOutput < tStartSampling)
83 throw std::runtime_error("Probe: tStartWritingOutput must be larger than tStartSampling!");
84 if (sampleEveryTimestep)
85 VF_LOG_INFO("Probe: sampleEveryTimestep is true, ignoring tBetweenSamples");
86 if (sampleScalar && !this->para->getDiffOn())
87 throw std::runtime_error("Probe: can only sample scalar if diffusion is enabled in parameter");
89 "Created probe, output path: " + outputPath + ", probe name: " + probeName +
90 " start sampling: {}, time steps between sampling: {}, start writing: {}, time steps between writing: {}",
91 tStartSampling, tBetweenSamples, tStartWritingOutput, tBetweenWriting);
94void Probe::addProbePlane(real startX, real startY, real startZ, real length, real width, real height)
96 probeObjects.emplace_back(
97 std::make_shared<GbCuboid3D>(startX, startY, startZ, startX + length, startY + width, startZ + height));
100void Probe::addProbePoint(real x, real y, real z)
102 probeObjects.emplace_back(std::make_shared<GbPoint3D>(x, y, z));
105void Probe::addProbeVolume(const std::shared_ptr<GbObject3D>& probeVolume)
107 probeObjects.push_back(probeVolume);
110void Probe::addProbePointsFromList(std::vector<real> coordsX, std::vector<real> coordY, std::vector<real> coordZ)
112 if (coordsX.size() != coordY.size() || coordsX.size() != coordZ.size())
113 throw std::runtime_error("Probe: Point coordinates must have the same size!");
114 for (uint i = 0; i < coordsX.size(); i++)
115 addProbePoint(coordsX[i], coordY[i], coordZ[i]);
118constexpr int calcArrayIndex(int node, int nNodes, int timestep, int nTimesteps, int quantity)
120 return node + nNodes * (timestep + nTimesteps * quantity);
123uint calcOldTimestep(uint currentTimestep, uint lastTimestepInOldSeries)
125 return currentTimestep > 0 ? currentTimestep - 1 : lastTimestepInOldSeries;
128real* getStatisticArray(Probe::ProbeData probeData, Probe::Statistic statistic)
131 case Probe::Statistic::Instantaneous:
132 return probeData.instantaneous;
133 case Probe::Statistic::Means:
134 return probeData.means;
135 case Probe::Statistic::Variances:
136 return probeData.variances;
138 throw std::runtime_error("getStatisticArray: Statistic unavailable!");
142constexpr real computeMean(real oldMean, real newValue, real inverseCount)
144 return oldMean + (newValue - oldMean) * inverseCount;
147constexpr real computeAndSaveMean(real* quantityArray, real oldValue, uint index, real currentValue, real invCount)
149 const real newValue = computeMean(oldValue, currentValue, invCount);
150 quantityArray[index] = newValue;
154constexpr real computeVariance(real oldVariance, real oldMean, real newMean, real currentValue, uint numberOfAveragedValues,
157 return (numberOfAveragedValues * oldVariance + (currentValue - oldMean) * (currentValue - newMean)) * inverseCount;
160constexpr real computeAndSaveVariance(real* quantityArray, real oldVariance, uint indexNew, real currentValue, real oldMean,
161 real newMean, uint numberOfAveragedValues, real inverseCount)
163 const real newVariance =
164 computeVariance(oldVariance, oldMean, newMean, currentValue, numberOfAveragedValues, inverseCount);
165 quantityArray[indexNew] = newVariance;
169constexpr void computeStatistics(uint nAveragedValues, uint currentTimestep, uint lastTimestep, uint nPoints, uint nodeIndex,
170 bool computeInstant, bool computeMean, bool computeVariance, uint iQuantity,
171 real currentValue, const Probe::ProbeData& probeData, real invCount)
173 const uint indexCurrent = calcArrayIndex(nodeIndex, nPoints, currentTimestep, probeData.numberOfTimesteps, iQuantity);
174 const uint indexLast = calcArrayIndex(nodeIndex, nPoints, lastTimestep, probeData.numberOfTimesteps, iQuantity);
176 probeData.instantaneous[indexCurrent] = currentValue;
178 const real meanOld = probeData.means[indexLast];
179 const real meanNew = computeAndSaveMean(probeData.means, meanOld, indexCurrent, currentValue, invCount);
180 if (nAveragedValues == 0)
182 if (computeVariance) {
183 const real varianceOld = probeData.variances[indexLast];
184 computeAndSaveVariance(probeData.variances, varianceOld, indexCurrent, currentValue, meanOld, meanNew,
185 nAveragedValues, invCount);
190__global__ void calculateQuantitiesKernel(uint numberOfAveragedValues, Probe::GridParams gridParams,
191 Probe::ProbeData probeData, uint currentTimestep, uint lastTimestep)
193 const uint nodeIndex = vf::cuda::get1DIndexFrom2DBlock();
195 if (nodeIndex >= probeData.numberOfPoints)
198 const uint gridNodeIndex = probeData.indices[nodeIndex];
200 const real invCount = c1o1 / real(numberOfAveragedValues + 1);
201 const real nPoints = probeData.numberOfPoints;
203 computeStatistics(numberOfAveragedValues, currentTimestep, lastTimestep, nPoints, nodeIndex,
204 probeData.computeInstantaneous, probeData.computeMeans, probeData.computeVariances, 0,
205 gridParams.velocityX[gridNodeIndex], probeData, invCount);
206 computeStatistics(numberOfAveragedValues, currentTimestep, lastTimestep, nPoints, nodeIndex,
207 probeData.computeInstantaneous, probeData.computeMeans, probeData.computeVariances, 1,
208 gridParams.velocityY[gridNodeIndex], probeData, invCount);
209 computeStatistics(numberOfAveragedValues, currentTimestep, lastTimestep, nPoints, nodeIndex,
210 probeData.computeInstantaneous, probeData.computeMeans, probeData.computeVariances, 2,
211 gridParams.velocityZ[gridNodeIndex], probeData, invCount);
212 computeStatistics(numberOfAveragedValues, currentTimestep, lastTimestep, nPoints, nodeIndex,
213 probeData.computeInstantaneous, probeData.computeMeans, probeData.computeVariances, 3,
214 gridParams.density[gridNodeIndex], probeData, invCount);
215 if (probeData.sampleScalar)
216 computeStatistics(numberOfAveragedValues, currentTimestep, lastTimestep, nPoints, nodeIndex,
217 probeData.computeInstantaneous, probeData.computeMeans, probeData.computeVariances, 4,
218 gridParams.scalar[gridNodeIndex], probeData, invCount);
221std::vector<Probe::PostProcessingVariable> Probe::getPostProcessingVariables(Statistic statistic, int level) const
223 const real velocityRatio = para->getScaledVelocityRatio(level);
224 const real stressRatio = para->getScaledStressRatio(level);
225 const real densityRatio = para->getScaledDensityRatio(level);
226 std::vector<PostProcessingVariable> postProcessingVariables;
228 case Statistic::Instantaneous:
229 postProcessingVariables.emplace_back("vx", velocityRatio);
230 postProcessingVariables.emplace_back("vy", velocityRatio);
231 postProcessingVariables.emplace_back("vz", velocityRatio);
232 postProcessingVariables.emplace_back("rho", densityRatio);
234 postProcessingVariables.emplace_back("phi", c1o1);
236 case Statistic::Means:
237 postProcessingVariables.emplace_back("vx_mean", velocityRatio);
238 postProcessingVariables.emplace_back("vy_mean", velocityRatio);
239 postProcessingVariables.emplace_back("vz_mean", velocityRatio);
240 postProcessingVariables.emplace_back("rho_mean", densityRatio);
242 postProcessingVariables.emplace_back("phi_mean", c1o1);
244 case Statistic::Variances:
245 postProcessingVariables.emplace_back("vx_var", stressRatio);
246 postProcessingVariables.emplace_back("vy_var", stressRatio);
247 postProcessingVariables.emplace_back("vz_var", stressRatio);
248 postProcessingVariables.emplace_back("rho_var", densityRatio);
250 postProcessingVariables.emplace_back("phi_var", c1o1);
254 throw std::runtime_error("Probe::getPostProcessingVariables: Statistic unavailable!");
257 return postProcessingVariables;
260std::vector<Probe::PostProcessingVariable> Probe::getAllPostProcessingVariables(int level) const
262 std::vector<PostProcessingVariable> postProcessingVariables;
263 if (enableComputationInstantaneous) {
264 for (const auto& p : getPostProcessingVariables(Statistic::Instantaneous, level))
265 postProcessingVariables.push_back(p);
267 if (enableComputationMeans) {
268 for (const auto& p : getPostProcessingVariables(Statistic::Means, level))
269 postProcessingVariables.push_back(p);
271 if (enableComputationVariances) {
272 for (const auto& p : getPostProcessingVariables(Statistic::Variances, level))
273 postProcessingVariables.push_back(p);
275 return postProcessingVariables;
280 for (int level = 0; level <= para->getMaxLevel(); level++) {
281 this->addLevelData(level);
283 if (this->outputTimeSeries) {
284 auto levelData = levelDatas[level];
285 const std::string fileName = outputPath + makeTimeseriesFileName(probeName, level, para->getMyProcessID());
286 auto variableNames = getVarNames();
287 writeTimeseriesFileHeader(fileName, levelData.probeDataH.numberOfPoints, variableNames,
288 levelData.coordinatesX.data(), levelData.coordinatesY.data(),
289 levelData.coordinatesZ.data());
290 timeseriesFileNames.push_back(fileName);
295void Probe::addLevelData(int level)
297 std::vector<uint> indices;
299 const real* nodeCoordinatesX = para->getParH(level)->coordinateX;
300 const real* nodeCoordinatesY = para->getParH(level)->coordinateY;
301 const real* nodeCoordinatesZ = para->getParH(level)->coordinateZ;
302 const uint* typeOfGridNode = para->getParH(level)->typeOfGridNode;
303 const real deltaX = para->getScaledLengthRatio(level);
305 for (unsigned long long pos = 1; pos < para->getParH(level)->numberOfNodes; pos++) {
306 if (GEO_FLUID != typeOfGridNode[pos])
308 const real nodeCoordX = nodeCoordinatesX[pos];
309 const real nodeCoordY = nodeCoordinatesY[pos];
310 const real nodeCoordZ = nodeCoordinatesZ[pos];
311 const real maxX = nodeCoordX + deltaX;
312 const real maxY = nodeCoordY + deltaX;
313 const real maxZ = nodeCoordZ + deltaX;
314 for (auto& object : probeObjects) {
315 if ((object->isInsideCell(nodeCoordX, nodeCoordY, nodeCoordZ, maxX, maxY, maxZ) ||
316 object->isPointInGbObject3D(nodeCoordX, nodeCoordY, nodeCoordZ))) {
317 indices.push_back(static_cast<uint>(pos));
323 removeInterpolationCells(indices, para.get(), level);
324 removeReceiveNodes(indices, para.get(), level);
325 std::vector<real> coordinatesX, coordinatesY, coordinatesZ;
326 coordinatesX.reserve(indices.size());
327 coordinatesY.reserve(indices.size());
328 coordinatesZ.reserve(indices.size());
330 for (auto index : indices) {
331 coordinatesX.push_back(nodeCoordinatesX[index]);
332 coordinatesY.push_back(nodeCoordinatesY[index]);
333 coordinatesZ.push_back(nodeCoordinatesZ[index]);
336 const uint numberOfQuantities = static_cast<uint>(getPostProcessingVariables(Statistic::Instantaneous, 0).size());
338 ProbeData probeData(enableComputationInstantaneous, enableComputationMeans, enableComputationVariances, sampleScalar,
339 static_cast<uint>(indices.size()), numberOfQuantities, getNumberOfTimestepsInTimeseries(level));
341 const uint sizeData = probeData.numberOfPoints * probeData.numberOfTimesteps * numberOfQuantities;
343 levelDatas.emplace_back(probeData, probeData, coordinatesX, coordinatesY, coordinatesZ);
345 cudaMemoryManager->cudaAllocProbeData(this, level);
347 std::copy(indices.begin(), indices.end(), levelDatas[level].probeDataH.indices);
349 if (enableComputationInstantaneous)
350 std::fill_n(levelDatas[level].probeDataH.instantaneous, sizeData, c0o1);
351 if (enableComputationMeans)
352 std::fill_n(levelDatas[level].probeDataH.means, sizeData, c0o1);
353 if (enableComputationVariances)
354 std::fill_n(levelDatas[level].probeDataH.variances, sizeData, c0o1);
356 cudaMemoryManager->cudaCopyProbeDataHtoD(this, level);
357 VF_LOG_INFO("Probe {} found {} points on level {}", probeName, indices.size(), level);
360void Probe::sample(int level, uint t)
362 auto* levelData = &levelDatas[level];
363 if (levelData->probeDataH.numberOfPoints == 0)
365 const uint tLevel = para->getTimeStep(level, t, false);
367 //! if sampleEveryTimestep the probe will be evaluated in every sub-timestep of each respective level
368 //! else, the probe will only be evaluated in each synchronous time step tBetweenSamples
370 const uint levelFactor = exp2(level);
372 const uint tStartAvgLevel = this->tStartSampling * levelFactor;
373 const uint tAfterStartAvg = tLevel - tStartAvgLevel;
374 const uint tAvgLevel = this->tBetweenSamples * levelFactor;
375 const bool averageThisTimestep = this->sampleEveryTimestep || (tAfterStartAvg % tAvgLevel == 0);
377 const uint tStartOutLevel = this->tStartWritingOutput * levelFactor;
378 const uint tAfterStartOut = tLevel - tStartOutLevel;
379 const uint tOutLevel = this->tBetweenWriting * levelFactor;
380 const bool outputThisTimestep = tAfterStartOut % tOutLevel == 0;
382 auto gridParams = getGridParams(para->getParD(level).get());
384 const vf::cuda::CudaGrid grid(para->getParD(level)->numberofthreads, levelData->probeDataD.numberOfPoints);
386 if ((t > this->tStartSampling) && averageThisTimestep) {
387 if (outputTimeSeries) {
388 const uint lastTimestep = calcOldTimestep(levelData->timeseriesParams.currentTimestep,
389 levelData->timeseriesParams.lastTimestepInOldTimeseries);
390 const uint currentTimestep = levelData->timeseriesParams.currentTimestep;
391 calculateQuantitiesKernel<<<grid.grid, grid.threads>>>(levelData->numberOfAveragedValues, gridParams,
392 levelData->probeDataD, currentTimestep, lastTimestep);
393 if (tLevel >= tStartOutLevel)
394 levelData->timeseriesParams.currentTimestep++;
396 calculateQuantitiesKernel<<<grid.grid, grid.threads>>>(levelData->numberOfAveragedValues, gridParams,
397 levelData->probeDataD, 0, 0);
399 levelData->numberOfAveragedValues++;
401 //! output only in synchronous timesteps
402 if ((t > this->tStartWritingOutput) && outputThisTimestep) {
403 cudaMemoryManager->cudaCopyProbeDataDtoH(this, level);
404 if (outputTimeSeries) {
405 this->appendTimeseriesFile(level, t);
406 levelData->timeseriesParams.lastTimestepInOldTimeseries =
407 levelData->timeseriesParams.currentTimestep > 0 ? levelData->timeseriesParams.currentTimestep - 1 : 0;
408 levelData->timeseriesParams.currentTimestep = 0;
410 this->writeGridFiles(level, t);
412 this->writeParallelFile(t);
419 for (int level = 0; level <= para->getMaxLevel(); level++) {
420 cudaMemoryManager->cudaFreeProbeData(this, level);
424void Probe::addStatistic(Statistic variable)
427 case Statistic::Instantaneous:
428 enableComputationInstantaneous = true;
430 case Statistic::Means:
431 enableComputationMeans = true;
433 case Statistic::Variances:
434 enableComputationVariances = true;
435 enableComputationMeans = true;
438 throw std::runtime_error("Probe::addStatistic: Statistic unavailable!");
443void Probe::writeGridFiles(int level, int t)
445 const int tWrite = this->fileNameLU ? t : (t - tStartWritingOutput) / this->tBetweenWriting;
447 const uint numberOfParts = levelDatas[level].probeDataH.numberOfPoints / FilePartCalculator::limitOfNodesForVTK + 1;
449 std::vector<std::string> fnames;
450 for (uint i = 1; i <= numberOfParts; i++) {
451 this->writeGridFile(level, tWrite, i);
455void Probe::writeParallelFile(int t)
457 const int t_write = this->fileNameLU ? t : t / this->tBetweenWriting;
458 const std::string filename = this->outputPath + makeParallelFileName(probeName, para->getMyProcessID(), t_write);
460 std::vector<std::string> nodedatanames = this->getVarNames();
461 std::vector<std::string> cellNames;
463 getWriter()->writeParallelFile(filename, fileNamesForCollectionFile, nodedatanames, cellNames);
465 this->fileNamesForCollectionFile.clear();
468void Probe::appendStatisticToNodeData(Statistic statistic, uint startPos, uint endPos, uint timestep, int level,
469 std::vector<std::vector<double>>& nodedata)
471 auto* levelData = &levelDatas[level];
472 const uint numberOfNodes = levelData->probeDataH.numberOfPoints;
473 const real* data = getStatisticArray(levelData->probeDataH, statistic);
474 std::vector<PostProcessingVariable> postProcessingVariables = this->getPostProcessingVariables(statistic, level);
475 for (uint arr = 0; arr < uint(postProcessingVariables.size()); arr++) {
476 std::vector<double> quantityData(numberOfNodes);
477 const real coeff = postProcessingVariables[arr].conversionFactor;
478 const int startIndex =
479 calcArrayIndex(startPos, numberOfNodes, timestep, levelData->probeDataH.numberOfTimesteps, arr);
480 for (uint idx = 0; idx < endPos - startPos; idx++) {
481 quantityData[idx] = double(data[startIndex + idx] * coeff);
483 nodedata.push_back(quantityData);
487void Probe::writeGridFile(int level, int t, uint part)
489 const std::string fname = this->outputPath + makeGridFileName(probeName, level, para->getMyProcessID(), t, part);
491 std::vector<UbTupleFloat3> nodes;
492 std::vector<std::string> nodedatanames = this->getVarNames();
494 std::vector<std::vector<double>> nodedata;
496 auto* levelData = &levelDatas[level];
498 const uint startpos = (part - 1) * FilePartCalculator::limitOfNodesForVTK;
499 const uint sizeOfNodes =
500 std::min(FilePartCalculator::limitOfNodesForVTK, levelData->probeDataH.numberOfPoints - startpos);
501 const uint endpos = startpos + sizeOfNodes;
503 //////////////////////////////////////////////////////////////////////////
504 nodes.resize(sizeOfNodes);
506 for (uint pos = startpos; pos < endpos; pos++) {
507 nodes[pos - startpos] = makeUbTuple(float(levelData->coordinatesX[pos]), float(levelData->coordinatesY[pos]),
508 float(levelData->coordinatesZ[pos]));
511 if (enableComputationInstantaneous)
512 appendStatisticToNodeData(Statistic::Instantaneous, startpos, endpos, 0, level, nodedata);
513 if (enableComputationMeans)
514 appendStatisticToNodeData(Statistic::Means, startpos, endpos, 0, level, nodedata);
515 if (enableComputationVariances)
516 appendStatisticToNodeData(Statistic::Variances, startpos, endpos, 0, level, nodedata);
517 std::string fullName = getWriter()->writeNodesWithNodeData(fname, nodes, nodedatanames, nodedata);
518 this->fileNamesForCollectionFile.push_back(fullName.substr(fullName.find_last_of('/') + 1));
521void Probe::appendStatisticToTimestepData(int timestep, std::vector<real>& timestepData, Statistic statistic, int level)
523 std::vector<PostProcessingVariable> variables = this->getPostProcessingVariables(statistic, level);
524 auto probeData = levelDatas[level].probeDataH;
525 const real* data = getStatisticArray(probeData, statistic);
527 for (uint variable = 0; variable < uint(variables.size()); variable++) {
528 const real conversionFactor = variables[variable].conversionFactor;
529 const uint startIndex = calcArrayIndex(0, probeData.numberOfPoints, timestep, probeData.numberOfTimesteps, variable);
531 for (uint point = 0; point < probeData.numberOfPoints; point++) {
532 timestepData.push_back(data[startIndex + point] * conversionFactor);
537std::vector<real> Probe::getTimestepData(real time, int timestep, int level)
539 std::vector<real> timestepData;
540 timestepData.push_back(time);
542 if (enableComputationInstantaneous)
543 appendStatisticToTimestepData(timestep, timestepData, Statistic::Instantaneous, level);
544 if (enableComputationMeans)
545 appendStatisticToTimestepData(timestep, timestepData, Statistic::Means, level);
546 if (enableComputationVariances)
547 appendStatisticToTimestepData(timestep, timestepData, Statistic::Variances, level);
551void Probe::appendTimeseriesFile(int level, int t)
553 const uint tAvg_level = this->tBetweenSamples == 1 ? this->tBetweenSamples : this->tBetweenSamples * exp2(-level);
554 const real deltaT = para->getTimeRatio() * tAvg_level;
555 auto levelData = levelDatas[level];
557 const real tStart = (t - this->tBetweenWriting) * para->getTimeRatio();
559 std::vector<std::vector<real>> timestepData;
561 for (uint timestep = 0; timestep < levelData.timeseriesParams.currentTimestep; timestep++) {
562 const real time = tStart + timestep * deltaT;
563 timestepData.push_back(this->getTimestepData(time, timestep, level));
565 appendDataToTimeseriesFile(this->timeseriesFileNames[level], timestepData);
566 levelData.timeseriesParams.lastTimestepInOldTimeseries = levelData.timeseriesParams.currentTimestep;
567 levelData.timeseriesParams.currentTimestep = 0;
570std::vector<std::string> Probe::getVarNames()
572 std::vector<std::string> varNames;
573 for (const auto& variable : getAllPostProcessingVariables(0))
574 varNames.push_back(variable.name);
578void Probe::getTaggedFluidNodes(GridProvider* gridProvider)
580 for (int level = 0; level <= para->getMaxLevel(); level++) {
581 auto probeData = levelDatas[level].probeDataH;
582 std::vector<uint> probeIndices(probeData.indices, probeData.indices + probeData.numberOfPoints);
583 gridProvider->tagFluidNodeIndices(probeIndices, CollisionTemplate::WriteMacroVars, level);
587Probe::GridParams Probe::getGridParams(LBMSimulationParameter* para)
589 return { para->velocityX, para->velocityY, para->velocityZ, para->rho, para->concentration };
592void removeCells(std::vector<uint>& indices, std::vector<uint>& cellIndices)
594 std::sort(cellIndices.begin(), cellIndices.end());
595 cellIndices.erase(std::unique(cellIndices.begin(), cellIndices.end()), cellIndices.end());
596 std::vector<uint> newIndices;
597 std::set_difference(indices.begin(), indices.end(), cellIndices.begin(), cellIndices.end(), std::back_inserter(newIndices));
598 std::swap(newIndices, indices);
601void removeCoarseInterpolationCells(std::vector<uint>& indices, Parameter* para, int level)
603 if (level == para->getMaxLevel())
605 auto interpolationCells = para->getParH(level)->fineToCoarse;
606 std::vector<uint> coarseCells(interpolationCells.coarseCellIndices,
607 interpolationCells.coarseCellIndices + interpolationCells.numberOfCells);
608 removeCells(indices, coarseCells);
611void removeFineInterpolationCells(std::vector<uint>& indices, Parameter* para, int level)
615 auto interpolationCells = para->getParH(level - 1)->coarseToFine;
616 const uint* neighborX = para->getParH(level)->neighborX;
617 const uint* neighborY = para->getParH(level)->neighborY;
618 const uint* neighborZ = para->getParH(level)->neighborZ;
619 std::vector<uint> allFineCells;
620 allFineCells.reserve(8 * std::size_t(interpolationCells.numberOfCells));
621 for (uint i = 0; i < interpolationCells.numberOfCells; i++) {
622 const uint kMMM = interpolationCells.fineCellIndices[i];
623 uint kPMM, kMPM, kMMP, kPPM, kPMP, kMPP, kPPP;
624 getNeighborIndicesOfBSW(kMMM, kPMM, kMPM, kMMP, kPPM, kPMP, kMPP, kPPP, neighborX, neighborY, neighborZ);
625 allFineCells.push_back(kMMM);
626 allFineCells.push_back(kPMM);
627 allFineCells.push_back(kMPM);
628 allFineCells.push_back(kMMP);
629 allFineCells.push_back(kPPM);
630 allFineCells.push_back(kPMP);
631 allFineCells.push_back(kMPP);
632 allFineCells.push_back(kPPP);
634 removeCells(indices, allFineCells);
637void removeInterpolationCells(std::vector<uint>& indices, Parameter* para, int level)
639 removeCoarseInterpolationCells(indices, para, level);
640 removeFineInterpolationCells(indices, para, level);
644void removeReceiveNodes(std::vector<uint>& indices, Parameter* para, int level) {
645 auto& parH = para->getParHostAsReference(level);
646 for(auto neighbor : parH.recvProcessNeighborsX)
648 std::vector<uint> recvIndices(neighbor.index, neighbor.index + neighbor.numberOfNodes);
649 removeCells(indices, recvIndices);
651 for(auto neighbor : parH.recvProcessNeighborsY)
653 std::vector<uint> recvIndices(neighbor.index, neighbor.index + neighbor.numberOfNodes);
654 removeCells(indices, recvIndices);
656 for(auto neighbor : parH.recvProcessNeighborsZ)
658 std::vector<uint> recvIndices(neighbor.index, neighbor.index + neighbor.numberOfNodes);
659 removeCells(indices, recvIndices);