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 Samplers
30//! \ingroup gpu_core core
32#include "Calculation/Calculation.h"
33#include "PlanarAverageProbe.h"
43#include <thrust/device_ptr.h>
44#include <thrust/device_vector.h>
45#include <thrust/execution_policy.h>
46#include <thrust/inner_product.h>
47#include <thrust/iterator/permutation_iterator.h>
48#include <thrust/iterator/zip_iterator.h>
49#include <thrust/reduce.h>
50#include <thrust/tuple.h>
52#include <basics/DataTypes.h>
53#include <basics/constants/NumericConstants.h>
54#include <basics/geometry3d/Axis.h>
55#include <basics/utilities/UbTuple.h>
56#include <basics/writer/WbWriterVtkXmlBinary.h>
58#include "gpu/core/Cuda/CudaMemoryManager.h"
59#include "gpu/core/DataStructureInitializer/GridProvider.h"
60#include "gpu/core/Parameter/Parameter.h"
61#include "gpu/core/PostProcessor/MacroscopicQuantities.cuh"
62#include "gpu/core/Samplers/Utilities.h"
64using namespace vf::basics::constant;
67using valIterator = thrust::device_vector<real>::iterator;
68using indexPointer = thrust::device_ptr<uint>;
69using indIterator = thrust::device_vector<uint>::iterator;
70using permIterator = thrust::permutation_iterator<valIterator, indIterator>;
71using iterPair = std::pair<permIterator, permIterator>;
73iterPair getIteratorPair(real* values, indexPointer indices, uint nNodes)
75 auto val_pointer = thrust::device_pointer_cast(values);
76 permIterator iter_begin(val_pointer, indices);
77 permIterator iter_end(val_pointer, indices + nNodes);
78 return std::make_pair(iter_begin, iter_end);
83 const real mean_x, mean_y;
84 covariance(real mean_x, real mean_y) : mean_x(mean_x), mean_y(mean_y)
88 template <typename Tuple>
89 constexpr real operator()(const Tuple& t) const
91 return (thrust::get<0>(t) - mean_x) * (thrust::get<1>(t) - mean_y);
98 skewness(real mean) : mean(mean)
101 constexpr real operator()(const real& x) const
103 return (x - mean) * (x - mean) * (x - mean);
110 flatness(real mean) : mean(mean)
113 constexpr real operator()(const real& x) const
115 return (x - mean) * (x - mean) * (x - mean) * (x - mean);
122 real vx, vy, vz, phi;
127 real vxvx, vyvy, vzvz, vxvy, vxvz, vyvz, phiphi, vxphi, vyphi, vzphi;
132 real Sx, Sy, Sz, Sphi;
137 real Fx, Fy, Fz, Fphi;
140std::string getName(const std::string& quantity, bool timeAverage)
143 return quantity + "_spatioTemporalMean";
145 return quantity + "_spatialMean";
148///////////////////////////////////////////////////////////////////////////////////
149std::vector<std::string> PlanarAverageProbe::getVariableNames(Statistic statistic, bool namesForTimeAverages) const
152 std::vector<std::string> variableNames;
154 case Statistic::Means:
155 variableNames.emplace_back(getName("vx", namesForTimeAverages));
156 variableNames.emplace_back(getName("vy", namesForTimeAverages));
157 variableNames.emplace_back(getName("vz", namesForTimeAverages));
158 if (para->getUseTurbulentViscosity())
159 variableNames.emplace_back(getName("EddyViscosity", namesForTimeAverages));
160 if (sampleSubgridScaleFluxes) {
161 variableNames.emplace_back(getName("SGSFluxXX", namesForTimeAverages));
162 variableNames.emplace_back(getName("SGSFluxXY", namesForTimeAverages));
163 variableNames.emplace_back(getName("SGSFluxXZ", namesForTimeAverages));
164 variableNames.emplace_back(getName("SGSFluxYY", namesForTimeAverages));
165 variableNames.emplace_back(getName("SGSFluxYZ", namesForTimeAverages));
166 variableNames.emplace_back(getName("SGSFluxZZ", namesForTimeAverages));
169 variableNames.emplace_back(getName("phi", namesForTimeAverages));
170 if (sampleScalar && para->getUseTurbulentViscosity())
171 variableNames.emplace_back(getName("EddyDiffusivity", namesForTimeAverages));
172 if (sampleScalar && sampleSubgridScaleFluxes){
173 variableNames.emplace_back(getName("SGSFluxPhiX", namesForTimeAverages));
174 variableNames.emplace_back(getName("SGSFluxPhiY", namesForTimeAverages));
175 variableNames.emplace_back(getName("SGSFluxPhiZ", namesForTimeAverages));
178 case Statistic::Covariances:
179 variableNames.emplace_back(getName("vxvx", namesForTimeAverages));
180 variableNames.emplace_back(getName("vyvy", namesForTimeAverages));
181 variableNames.emplace_back(getName("vzvz", namesForTimeAverages));
182 variableNames.emplace_back(getName("vxvy", namesForTimeAverages));
183 variableNames.emplace_back(getName("vxvz", namesForTimeAverages));
184 variableNames.emplace_back(getName("vyvz", namesForTimeAverages));
186 variableNames.emplace_back(getName("phiphi", namesForTimeAverages));
187 variableNames.emplace_back(getName("vxphi", namesForTimeAverages));
188 variableNames.emplace_back(getName("vyphi", namesForTimeAverages));
189 variableNames.emplace_back(getName("vzphi", namesForTimeAverages));
192 case Statistic::Skewness:
193 variableNames.emplace_back(getName("SkewnessX", namesForTimeAverages));
194 variableNames.emplace_back(getName("SkewnessY", namesForTimeAverages));
195 variableNames.emplace_back(getName("SkewnessZ", namesForTimeAverages));
197 variableNames.emplace_back(getName("SkewnessPhi", namesForTimeAverages));
199 case Statistic::Flatness:
200 variableNames.emplace_back(getName("FlatnessX", namesForTimeAverages));
201 variableNames.emplace_back(getName("FlatnessY", namesForTimeAverages));
202 variableNames.emplace_back(getName("FlatnessZ", namesForTimeAverages));
204 variableNames.emplace_back(getName("FlatnessPhi", namesForTimeAverages));
208 throw std::runtime_error("PlanarAverageProbe::getVariableNames: Statistic unavailable!");
212 return variableNames;
215void PlanarAverageProbe::addStatistic(Statistic statistic)
217 if (!isStatisticIn(statistic, statistics))
218 statistics.push_back(statistic);
221///////////////////////////////////////////////////////////////////////////////////
222void PlanarAverageProbe::init()
224 if (sampleScalar && !this->para->getDiffOn())
225 throw std::runtime_error("PlaneAverageProbe: Scalar can only be sampled if diff is on!");
226 if (sampleSubgridScaleFluxes && !this->para->getUseTurbulentViscosity())
227 throw std::runtime_error("PlanarAverageProbe: sampleSubgridScaleFluxes is true but useTurbulentViscosity of "
228 "parameter is false.");
230 size_t numberOfVariables = 0;
231 for (auto statistic : statistics) {
232 numberOfVariables += getVariableNames(statistic, false).size();
235 for (int level = 0; level <= para->getMaxLevel(); level++) {
236 auto* data = &levelData.emplace_back();
238 findCoordinatesForPlanes(level, data->coordinateX, data->coordinateY, data->coordinateZ,
239 data->numberOfNodesPerPlane);
240 data->numberOfPlanes = static_cast<uint>(data->coordinateX.size());
241 data->maxNumberOfPointsPerPlane =
242 std::accumulate(data->numberOfNodesPerPlane.begin(), data->numberOfNodesPerPlane.end(), uint {},
243 [](uint acc, uint nNodesPerPlane) { return std::max(acc, nNodesPerPlane); });
244 cudaMemoryManager->cudaAllocPlanarAverageProbeIndices(this, level);
245 if (sampleSubgridScaleFluxes)
246 cudaMemoryManager->cudaAllocPlanarAverageProbeSubgridScaleFluxes(this, level);
247 data->instantaneous.resize(data->numberOfPlanes, std::vector<real>(numberOfVariables, c0o1));
248 if (computeTimeAverages) {
249 data->timeAverages.resize(data->numberOfPlanes, std::vector<real>(numberOfVariables, c0o1));
254void PlanarAverageProbe::sample(int level, uint t)
256 if (t < tStartSampling)
259 const uint tLevel = para->getTimeStep(level, t, true);
260 const uint levelFactor = std::exp2(level);
261 const uint tAfterStartAveraging = tLevel - tStartSampling * levelFactor;
262 const uint tAfterStartWriting = tLevel - tStartWritingOutput * levelFactor;
263 const bool doTimeAverages = computeTimeAverages && tLevel > (tStartTemporalAveraging * levelFactor);
265 if (tAfterStartAveraging % (tBetweenSamples * levelFactor) == 0) {
266 calculateQuantities(level, doTimeAverages);
269 if (tAfterStartWriting > 0 && tAfterStartWriting % (tBetweenWriting * levelFactor) == 0) {
270 const int tWrite = this->nameFilesWithFileCount ? (t - tStartWritingOutput) / this->tBetweenWriting : t;
272 writeGridFile(level, tWrite);
274 writeParallelFile(tWrite);
278PlanarAverageProbe::~PlanarAverageProbe()
280 for (int level = 0; level <= para->getMaxLevel(); level++) {
281 cudaMemoryManager->cudaFreePlanarAverageProbeIndices(this, level);
285struct isCoordAndFluid
288 const uint* typeOfGridNode;
290 __host__ __device__ bool operator()(const unsigned long long index) const
292 return coords[index] == coord && typeOfGridNode[index] == GEO_FLUID;
296void PlanarAverageProbe::findCoordinatesForPlanes(int level, std::vector<real>& coordinateX, std::vector<real>& coordinateY,
297 std::vector<real>& coordinateZ, std::vector<uint>& numberOfNodesPerPlane)
299 const real* coords = getPlaneNormalCoordinatesH(level);
300 const uint* typeOfGridNode = para->getParH(level)->typeOfGridNode;
302 std::vector<real> planeCoords;
303 real coordOfCurrentPlane = coords[1];
305 for (unsigned long long index = 1; index < para->getParH(level)->numberOfNodes; index++) {
306 if (isCoordAndFluid { coords, typeOfGridNode, coordOfCurrentPlane }(index)) {
310 if (typeOfGridNode[index] != GEO_FLUID)
313 const real coordOfLastPlane = coordOfCurrentPlane;
314 coordOfCurrentPlane = coords[index];
316 if (count == 1) // skip empty planes
319 numberOfNodesPerPlane.emplace_back(count);
320 planeCoords.emplace_back(coordOfLastPlane);
324 switch (planeNormal) {
326 std::copy(planeCoords.begin(), planeCoords.end(), std::back_inserter(coordinateX));
327 std::fill_n(std::back_inserter(coordinateY), planeCoords.size(), 999999);
328 std::fill_n(std::back_inserter(coordinateZ), planeCoords.size(), 999999);
331 std::fill_n(std::back_inserter(coordinateX), planeCoords.size(), 999999);
332 std::copy(planeCoords.begin(), planeCoords.end(), std::back_inserter(coordinateY));
333 std::fill_n(std::back_inserter(coordinateZ), planeCoords.size(), 999999);
336 std::fill_n(std::back_inserter(coordinateX), planeCoords.size(), 999999);
337 std::fill_n(std::back_inserter(coordinateY), planeCoords.size(), 999999);
338 std::copy(planeCoords.begin(), planeCoords.end(), std::back_inserter(coordinateZ));
343real computeMean(iterPair x, uint nNodes)
345 return thrust::reduce(std::get<0>(x), std::get<1>(x)) / nNodes;
348real computeMean(real* x, indexPointer indices, uint nNodes)
350 return computeMean(getIteratorPair(x, indices, nNodes), nNodes);
353real computeMean(real* x, uint nNodes)
355 return thrust::reduce(thrust::device, x, x + nNodes) / nNodes;
358Means computeMeans(iterPair vx, iterPair vy, iterPair vz, iterPair phi, uint nNodes, bool sampleScalar)
361 means.vx = computeMean(vx, nNodes);
362 means.vy = computeMean(vy, nNodes);
363 means.vz = computeMean(vz, nNodes);
365 means.phi = computeMean(phi, nNodes);
369real computeCovariance(iterPair x, iterPair y, real mean_x, real mean_y, uint nNodes)
371 auto begin = thrust::make_zip_iterator(thrust::make_tuple(x.first, y.first));
372 auto end = thrust::make_zip_iterator(thrust::make_tuple(x.second, y.second));
373 return thrust::transform_reduce(begin, end, covariance(mean_x, mean_y), c0o1, thrust::plus<real>()) / nNodes;
376Covariances computeCovariances(iterPair vx, iterPair vy, iterPair vz, iterPair phi, Means means, uint nNodes,
379 Covariances covariances;
381 covariances.vxvx = computeCovariance(vx, vx, means.vx, means.vx, nNodes);
382 covariances.vyvy = computeCovariance(vy, vy, means.vy, means.vy, nNodes);
383 covariances.vzvz = computeCovariance(vz, vz, means.vz, means.vz, nNodes);
384 covariances.vxvy = computeCovariance(vx, vy, means.vx, means.vy, nNodes);
385 covariances.vxvz = computeCovariance(vx, vz, means.vx, means.vz, nNodes);
386 covariances.vyvz = computeCovariance(vy, vz, means.vy, means.vz, nNodes);
388 covariances.phiphi = computeCovariance(phi, phi, means.phi, means.phi, nNodes);
389 covariances.vxphi = computeCovariance(vx, phi, means.vx, means.phi, nNodes);
390 covariances.vyphi = computeCovariance(vy, phi, means.vy, means.phi, nNodes);
391 covariances.vzphi = computeCovariance(vz, phi, means.vz, means.phi, nNodes);
397real computeSkewness(iterPair x, real mean, real covariance, uint nNodes)
399 return thrust::transform_reduce(x.first, x.second, skewness(mean), c0o1, thrust::plus<real>()) /
400 (nNodes * std::pow(covariance, c3o2));
403Skewnesses computeSkewnesses(Means means, Covariances covariances, iterPair vx, iterPair vy, iterPair vz, iterPair phi,
404 uint nNodes, bool sampleScalar)
406 Skewnesses skewnesses;
408 skewnesses.Sx = computeSkewness(vx, means.vx, covariances.vxvx, nNodes);
409 skewnesses.Sy = computeSkewness(vy, means.vy, covariances.vyvy, nNodes);
410 skewnesses.Sz = computeSkewness(vz, means.vz, covariances.vzvz, nNodes);
412 skewnesses.Sphi = computeSkewness(phi, means.phi, covariances.phiphi, nNodes);
417real computeFlatness(iterPair x, real mean, real covariance, uint nNodes)
419 return thrust::transform_reduce(x.first, x.second, flatness(mean), c0o1, thrust::plus<real>()) /
420 (nNodes * std::pow(covariance, 2));
423Flatnesses computeFlatnesses(iterPair vx, iterPair vy, iterPair vz, iterPair phi, Means means, Covariances covariances,
424 uint nNodes, bool sampleScalar)
426 Flatnesses flatnesses;
428 flatnesses.Fx = computeFlatness(vx, means.vx, covariances.vxvx, nNodes);
429 flatnesses.Fy = computeFlatness(vy, means.vy, covariances.vyvy, nNodes);
430 flatnesses.Fz = computeFlatness(vz, means.vz, covariances.vzvz, nNodes);
432 flatnesses.Fphi = computeFlatness(phi, means.phi, covariances.phiphi, nNodes);
436std::vector<real> PlanarAverageProbe::computePlaneStatistics(int level, uint nNodes)
438 auto* data = &levelData[level];
439 auto parameter = para->getParD(level);
440 indexPointer indices = thrust::device_pointer_cast<uint>(data->indicesD);
442 const auto velocityX = getIteratorPair(parameter->velocityX, indices, nNodes);
443 const auto velocityY = getIteratorPair(parameter->velocityY, indices, nNodes);
444 const auto velocityZ = getIteratorPair(parameter->velocityZ, indices, nNodes);
446 const auto phi = getIteratorPair(parameter->concentration, indices, nNodes);
448 std::vector<real> averages;
450 if (!isStatisticIn(Statistic::Means, statistics))
453 const real velocityRatio = para->getScaledVelocityRatio(level);
454 const real viscosityRatio = para->getScaledViscosityRatio(level);
455 const real stressRatio = para->getScaledStressRatio(level);
457 const auto means = computeMeans(velocityX, velocityY, velocityZ, phi, nNodes, sampleScalar);
458 averages.push_back(means.vx * velocityRatio);
459 averages.push_back(means.vy * velocityRatio);
460 averages.push_back(means.vz * velocityRatio);
461 if (para->getUseTurbulentViscosity())
462 averages.push_back(computeMean(parameter->turbulentViscosity, indices, nNodes) * viscosityRatio);
463 if (sampleSubgridScaleFluxes) {
464 averages.push_back(computeMean(data->subgridScaleFluxXX, nNodes) * stressRatio);
465 averages.push_back(computeMean(data->subgridScaleFluxXY, nNodes) * stressRatio);
466 averages.push_back(computeMean(data->subgridScaleFluxXZ, nNodes) * stressRatio);
467 averages.push_back(computeMean(data->subgridScaleFluxYY, nNodes) * stressRatio);
468 averages.push_back(computeMean(data->subgridScaleFluxYZ, nNodes) * stressRatio);
469 averages.push_back(computeMean(data->subgridScaleFluxZZ, nNodes) * stressRatio);
472 averages.push_back(means.phi);
473 if (sampleScalar && para->getUseTurbulentViscosity())
474 averages.push_back(computeMean(parameter->turbulentDiffusivity, indices, nNodes) * viscosityRatio);
475 if (sampleScalar && sampleSubgridScaleFluxes) {
476 averages.push_back(computeMean(data->subgridScaleFluxPhiX, nNodes) * velocityRatio);
477 averages.push_back(computeMean(data->subgridScaleFluxPhiY, nNodes) * velocityRatio);
478 averages.push_back(computeMean(data->subgridScaleFluxPhiZ, nNodes) * velocityRatio);
481 if (!isStatisticIn(Statistic::Covariances, statistics))
484 const auto covariances = computeCovariances(velocityX, velocityY, velocityZ, phi, means, nNodes, sampleScalar);
485 averages.push_back(covariances.vxvx * stressRatio);
486 averages.push_back(covariances.vyvy * stressRatio);
487 averages.push_back(covariances.vzvz * stressRatio);
488 averages.push_back(covariances.vxvy * stressRatio);
489 averages.push_back(covariances.vxvz * stressRatio);
490 averages.push_back(covariances.vyvz * stressRatio);
493 averages.push_back(covariances.phiphi);
494 averages.push_back(covariances.vxphi * velocityRatio);
495 averages.push_back(covariances.vyphi * velocityRatio);
496 averages.push_back(covariances.vzphi * velocityRatio);
499 if (!isStatisticIn(Statistic::Skewness, statistics))
502 const auto skewnesses =
503 computeSkewnesses(means, covariances, velocityX, velocityY, velocityZ, phi, nNodes, sampleScalar);
504 averages.push_back(skewnesses.Sx);
505 averages.push_back(skewnesses.Sy);
506 averages.push_back(skewnesses.Sz);
508 averages.push_back(skewnesses.Sphi);
510 if (!isStatisticIn(Statistic::Flatness, statistics))
513 const auto flatnesses =
514 computeFlatnesses(velocityX, velocityY, velocityZ, phi, means, covariances, nNodes, sampleScalar);
515 averages.push_back(flatnesses.Fx);
516 averages.push_back(flatnesses.Fy);
517 averages.push_back(flatnesses.Fz);
519 averages.push_back(flatnesses.Fphi);
524std::vector<real> computeNewTimeAverages(std::vector<real>& oldAverages, std::vector<real>& instantaneous,
525 uint numberOfTimesteps)
527 std::vector<real> newAverages;
528 newAverages.reserve(oldAverages.size());
529 for (uint i = 0; i < oldAverages.size(); i++) {
530 newAverages.push_back(computeNewTimeAverage(oldAverages[i], instantaneous[i], numberOfTimesteps));
535void PlanarAverageProbe::calculateQuantities(int level, bool doTimeAverages)
537 auto* data = &levelData[level];
538 auto parameter = para->getParD(level);
539 calculateMacroscopicQuantitiesCompressible(
540 parameter->velocityX, parameter->velocityY, parameter->velocityZ, parameter->rho, parameter->pressure,
541 parameter->typeOfGridNode, parameter->neighborX, parameter->neighborY, parameter->neighborZ,
542 parameter->numberOfNodes, parameter->numberofthreads, parameter->distributions.f[0], parameter->isEvenTimestep);
544 auto counting = thrust::make_counting_iterator<unsigned long long>(1);
546 for (uint plane = 0; plane < data->numberOfPlanes; plane++) {
548 thrust::device, counting, counting + parameter->numberOfNodes - counting[0], data->indicesD,
549 isCoordAndFluid { getPlaneNormalCoordinatesD(level), parameter->typeOfGridNode, data->coordinateZ[plane] });
550 const uint numberOfNodesInPlane = data->numberOfNodesPerPlane[plane];
551 if (sampleSubgridScaleFluxes)
552 calculateSubGridScaleFluxesCompressible(
553 data->indicesD, numberOfNodesInPlane, data->subgridScaleFluxXX, data->subgridScaleFluxXY,
554 data->subgridScaleFluxXZ, data->subgridScaleFluxYY, data->subgridScaleFluxYZ, data->subgridScaleFluxZZ,
555 data->subgridScaleFluxPhiX, data->subgridScaleFluxPhiY, data->subgridScaleFluxPhiZ,
556 parameter->typeOfGridNode, parameter->velocityX, parameter->velocityY, parameter->velocityZ,
557 parameter->concentration, parameter->turbulentViscosity, parameter->turbulentDiffusivity,
558 parameter->neighborX, parameter->neighborY, parameter->neighborZ, parameter->numberOfNodes,
559 parameter->distributions.f[0], parameter->distributionsAD.f[0], parameter->omega, parameter->omegaDiffusivity, parameter->numberofthreads,
560 parameter->isEvenTimestep, sampleScalar);
561 data->instantaneous[plane] = computePlaneStatistics(level, numberOfNodesInPlane);
563 data->timeAverages[plane] = computeNewTimeAverages(data->timeAverages[plane], data->instantaneous[plane],
564 data->numberOfTimestepsInTimeAverage + 1U);
567 data->numberOfTimestepsInTimeAverage++;
570const real* PlanarAverageProbe::getPlaneNormalCoordinatesH(int level)
572 switch (planeNormal) {
574 return para->getParH(level)->coordinateX;
576 return para->getParH(level)->coordinateY;
578 return para->getParH(level)->coordinateZ;
580 throw std::runtime_error("PlaneNormal not defined");
582const real* PlanarAverageProbe::getPlaneNormalCoordinatesD(int level)
584 switch (planeNormal) {
586 return para->getParD(level)->coordinateX;
588 return para->getParD(level)->coordinateY;
590 return para->getParD(level)->coordinateZ;
592 throw std::runtime_error("PlaneNormal not defined");
595void PlanarAverageProbe::writeParallelFile(uint tWrite)
597 const std::string filename = this->outputPath + makeParallelFileName(probeName, para->getMyProcessID(), tWrite);
599 std::vector<std::string> nodedatanames = this->getAllVariableNames();
600 std::vector<std::string> cellNames;
602 WbWriterVtkXmlBinary::getInstance()->writeParallelFile(filename, fileNamesForCollectionFile, nodedatanames, cellNames);
604 this->fileNamesForCollectionFile.clear();
607void PlanarAverageProbe::copyDataToNodedata(std::vector<std::vector<real>>& data, std::vector<std::vector<double>>& nodedata)
611 for (auto statistic : statistics) {
612 for (auto variable : this->getVariableNames(statistic, false)) {
613 std::vector<double> array;
614 array.reserve(data.size());
615 for (auto& plane : data) {
616 array.emplace_back(plane[arrayIndex]);
618 nodedata.push_back(array);
624void PlanarAverageProbe::writeGridFile(int level, uint tWrite)
626 auto* data = &levelData[level];
627 const std::string fname = outputPath + makeGridFileName(probeName, level, para->getMyProcessID(), tWrite, 1);
629 std::vector<UbTupleFloat3> nodes;
630 nodes.reserve(data->numberOfPlanes);
631 for (uint pos = 0; pos < data->numberOfPlanes; pos++) {
633 makeUbTuple(float(data->coordinateX[pos]), float(data->coordinateY[pos]), float(data->coordinateZ[pos])));
636 std::vector<std::string> nodedatanames = this->getAllVariableNames();
638 std::vector<std::vector<double>> nodedata;
639 copyDataToNodedata(data->instantaneous, nodedata);
640 if (computeTimeAverages)
641 copyDataToNodedata(data->timeAverages, nodedata);
643 std::string fullName =
644 WbWriterVtkXmlBinary::getInstance()->writeNodesWithNodeData(fname, nodes, nodedatanames, nodedata);
645 this->fileNamesForCollectionFile.push_back(fullName.substr(fullName.find_last_of('/') + 1));
648std::vector<std::string> PlanarAverageProbe::getAllVariableNames()
650 std::vector<std::string> varNames;
651 for (auto statistic : statistics) {
652 for (const auto& variable : getVariableNames(statistic, false)) {
653 varNames.push_back(variable);
656 if (this->computeTimeAverages) {
657 for (auto statistic : statistics) {
658 for (const auto& variable : getVariableNames(statistic, true))
659 varNames.push_back(variable);
665bool isStatisticIn(PlanarAverageProbe::Statistic statistic, std::vector<PlanarAverageProbe::Statistic> statistics)
667 return std::find(statistics.begin(), statistics.end(), statistic) != statistics.end();