VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
L2NormBetweenKernelPostProcessingStrategy.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//=======================================================================================
34
39
41
42std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> L2NormBetweenKernelPostProcessingStrategy::getNewInstance(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> testPara, std::shared_ptr<L2NormCalculatorFactory> factory, std::vector<std::string> dataToCalcTests)
43{
44 return std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy>(new L2NormBetweenKernelPostProcessingStrategy(simResult, analyticalResult, testPara, factory, dataToCalcTests));
45}
46
48{
49 if (!isEvaluated) {
50 analyticalResult->calc(simResult);
51
52 l2Norm.resize(dataToCalculate.size());
53 for (int i = 0; i < dataToCalculate.size(); i++) {
54 l2Norm.at(i).resize(normalizeData.size());
55 for (int j = 0; j < normalizeData.size(); j++) {
56 l2Norm.at(i).at(j).resize(timeSteps.size());
57 }
58 }
59
60 for (int i = 0; i < dataToCalculate.size(); i++) {
61 for (int j = 0; j < normalizeData.size(); j++) {
62 for (int k = 0; k < timeSteps.size(); k++) {
63 int time = calcTimeStepInResults(timeSteps.at(k));
64 if (dataToCalculate.at(i) == "Vx")
65 l2Norm.at(i).at(j).at(k) = l2Normcalculator.at(j)->calc(analyticalResult->getVx().at(time), simResult->getVx().at(time), simResult->getLevels().at(time), analyticalResult->getNumberOfXNodes(), analyticalResult->getNumberOfZNodes(), analyticalResult->getL0());
66 if (dataToCalculate.at(i) == "Vy")
67 l2Norm.at(i).at(j).at(k) = l2Normcalculator.at(j)->calc(analyticalResult->getVy().at(time), simResult->getVy().at(time), simResult->getLevels().at(time), analyticalResult->getNumberOfXNodes(), analyticalResult->getNumberOfZNodes(), analyticalResult->getL0());
68 if (dataToCalculate.at(i) == "Vz")
69 l2Norm.at(i).at(j).at(k) = l2Normcalculator.at(j)->calc(analyticalResult->getVz().at(time), simResult->getVz().at(time), simResult->getLevels().at(time), analyticalResult->getNumberOfXNodes(), analyticalResult->getNumberOfZNodes(), analyticalResult->getL0());
70 if (dataToCalculate.at(i) == "Press")
71 l2Norm.at(i).at(j).at(k) = l2Normcalculator.at(j)->calc(analyticalResult->getPress().at(time), simResult->getPress().at(time), simResult->getLevels().at(time), analyticalResult->getNumberOfXNodes(), analyticalResult->getNumberOfZNodes(), analyticalResult->getL0());
72 if (dataToCalculate.at(i) == "Rho")
73 l2Norm.at(i).at(j).at(k) = l2Normcalculator.at(j)->calc(analyticalResult->getRho().at(time), simResult->getRho().at(time), simResult->getLevels().at(time), analyticalResult->getNumberOfXNodes(), analyticalResult->getNumberOfZNodes(), analyticalResult->getL0());
74 }
75 }
76 }
77 isEvaluated = true;
78 }
79}
80
82{
83 for (int i = 0; i < dataToCalculate.size(); i++) {
84 for (int j = 0; j < normalizeData.size(); j++) {
85 for (int k = 0; k < timeSteps.size(); k++) {
86 if (aDataToCalc == dataToCalculate.at(i) && aNormalizeData == normalizeData.at(j) && aTimeStep == timeSteps.at(k))
87 return l2Norm.at(i).at(j).at(k);
88 }
89 }
90 }
91
92 return 0.0;
93}
94
96{
97 for (int i = 0; i < normalizeData.size(); i++) {
98 if (aNormalizeData == normalizeData.at(i))
99 return l2Normcalculator.at(i)->getErrorMessage();
100 }
101 return std::string();
102}
103
105{
106 return simResult;
107}
108
109L2NormBetweenKernelPostProcessingStrategy::L2NormBetweenKernelPostProcessingStrategy(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> testPara, std::shared_ptr<L2NormCalculatorFactory> factory, std::vector<std::string> dataToCalcTests)
110 : PostProcessingStrategyImp(simResult), analyticalResult(analyticalResult), dataToCalculate(dataToCalcTests)
111{
112 isEvaluated = false;
113 normalizeData = testPara->normalizeData;
114 timeSteps = testPara->timeSteps;
115
116 l2Norm.resize(dataToCalculate.size());
117 for (int i = 0; i < dataToCalculate.size(); i++) {
118 l2Norm.at(i).resize(normalizeData.size());
119 for (int j = 0; j < normalizeData.size(); j++) {
120 l2Norm.at(i).at(j).resize(timeSteps.size());
121 }
122 }
123
124
125 for (int i = 0; i < normalizeData.size(); i++)
126 l2Normcalculator.push_back(factory->makeL2NormCalculator(normalizeData.at(i)));
127
128}
129
130int L2NormBetweenKernelPostProcessingStrategy::calcPosInTimeStep(int time)
131{
132 for (int i = 0; i < timeSteps.size(); i++)
133 if (timeSteps.at(i) == time)
134 return i;
135}
136
std::shared_ptr< SimulationResults > simResult
static std::shared_ptr< L2NormBetweenKernelPostProcessingStrategy > getNewInstance(std::shared_ptr< SimulationResults > simResult, std::shared_ptr< AnalyticalResults > analyticalResult, std::shared_ptr< L2NormTestBetweenKernelsParameterStruct > testPara, std::shared_ptr< L2NormCalculatorFactory > factory, std::vector< std::string > dataToCalcTests)
virtual std::shared_ptr< SimulationResults > getSimulationResult()
int calcTimeStepInResults(unsigned int timeStep)
double getL2Norm(std::string aDataToCalc, std::string aNormalizeData, int aTimeStep)
std::shared_ptr< T > SPtr