VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
Y2dSliceToResults.cpp
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//
32//=======================================================================================
33#include "Y2dSliceToResults.h"
34
37
38#include <cmath>
39#include <sstream>
40
41using namespace vf::gpu;
42
43std::shared_ptr<Y2dSliceToResults>
44Y2dSliceToResults::getNewInstance(std::shared_ptr<VectorWriterInformationStruct> vectorWriterInfo,
45 unsigned int timeStepLength, std::shared_ptr<SimulationResults> simResults,
46 unsigned int ySliceForCalculation)
47{
48 return std::shared_ptr<Y2dSliceToResults>(
49 new Y2dSliceToResults(vectorWriterInfo, timeStepLength, simResults, ySliceForCalculation));
50}
51
52Y2dSliceToResults::Y2dSliceToResults()
53{
54}
55
56Y2dSliceToResults::Y2dSliceToResults(std::shared_ptr<VectorWriterInformationStruct> vectorWriterInfo,
57 unsigned int timeStepLength, std::shared_ptr<SimulationResults> simResults,
58 unsigned int ySliceForCalculation)
59 : ToVectorWriter(vectorWriterInfo, timeStepLength)
60{
61 this->simResults = simResults;
62 this->ySliceForCalculation = ySliceForCalculation;
63}
64
65void Y2dSliceToResults::writeTimestep(std::shared_ptr<Parameter> para, unsigned int t, int level)
66{
67 int timestep = t / timeStepLength;
68 maxX = para->getGridX().at(level);
69 maxY = para->getGridY().at(level);
70 maxZ = para->getGridZ().at(level);
71
72 int numberNodes = (maxX - 1) * (maxZ - 1);
73 std::vector<double> x(numberNodes), y(numberNodes), z(numberNodes);
74 std::vector<double> vx(numberNodes), vy(numberNodes), vz(numberNodes);
75 std::vector<double> press(numberNodes), rho(numberNodes);
76 std::vector<unsigned int> levels(numberNodes);
77
78 ySliceForCalculation = maxY / 2;
79 for (int posZ = 0; posZ < maxZ - 1; posZ++) {
80 for (int posX = 0; posX < maxX - 1; posX++) {
81 int posResults = CoordResults2DTo1D(posX, posZ);
82 int posPara = CoordPara3DTo1D(posX, ySliceForCalculation, posZ);
83
84 x.at(posResults) = (double)para->getParH(level)->coordinateX[posPara] - (double)1.0;
85 y.at(posResults) = (double)para->getParH(level)->coordinateY[posPara] - (double)1.0;
86 z.at(posResults) = (double)para->getParH(level)->coordinateZ[posPara] - (double)1.0;
87 vx.at(posResults) = (double)para->getParH(level)->velocityX[posPara] * (double)para->getVelocityRatio();
88 vy.at(posResults) = (double)para->getParH(level)->velocityY[posPara] * (double)para->getVelocityRatio();
89 vz.at(posResults) = (double)para->getParH(level)->velocityZ[posPara] * (double)para->getVelocityRatio();
90 press.at(posResults) = (double)para->getParH(level)->pressure[posPara] / (double)3.0 *
91 (double)para->getDensityRatio() * (double)para->getVelocityRatio() *
92 (double)para->getVelocityRatio();
93 rho.at(posResults) = (double)para->getParH(level)->rho[posPara] / (double)3.0 *
94 (double)para->getDensityRatio() * (double)para->getVelocityRatio() *
95 (double)para->getVelocityRatio();
96 levels.at(posResults) = level;
97 }
98 }
99 simResults->addTimeStep(timestep, t, levels, x, y, z, vx, vy, vz, press, rho);
100}
101
102int Y2dSliceToResults::CoordPara3DTo1D(int x, int y, int z)
103{
104 return z * maxY * maxX + y * maxX + x + 1;
105}
106
107int Y2dSliceToResults::CoordResults2DTo1D(int x, int z)
108{
109 return z * (maxX - 1) + x;
110}
111
unsigned int timeStepLength
static std::shared_ptr< Y2dSliceToResults > getNewInstance(std::shared_ptr< VectorWriterInformationStruct > vectorWriterInfo, unsigned int timeStepLength, std::shared_ptr< SimulationResults > simResults, unsigned int ySliceForCalculation)
std::shared_ptr< T > SPtr
@ z
Definition Axis.h:44
@ x
Definition Axis.h:42
@ y
Definition Axis.h:43