VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
L2NormTestBetweenKernels.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
42
43#include <iomanip>
44
45std::shared_ptr<L2NormTestBetweenKernels> L2NormTestBetweenKernels::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith, std::shared_ptr<L2NormCalculatorFactory> factory)
46{
47 return std::shared_ptr<L2NormTestBetweenKernels>(new L2NormTestBetweenKernels(colorOutput, dataToCalculate, timeStep, normalizeWith, factory));
48}
49
54
56{
57 basicPostProcessingStrategy->evaluate();
58 divergentPostProcessingStrategy->evaluate();
59
60 int tS = calcTimeStepInResults(timeStep);
61
62 basicL2Result = basicPostProcessingStrategy->getL2Norm(dataToCalculate, normalizeData, timeStep);
63 divergentL2Result = divergentPostProcessingStrategy->getL2Norm(dataToCalculate, normalizeData, timeStep);
64
65 if (dataToCalculate == "Vx")
66 resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getVx().at(tS), divergentSimResults->getVx().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getL0());
67 if (dataToCalculate == "Vy")
68 resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getVy().at(tS), divergentSimResults->getVy().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getL0());
69 if (dataToCalculate == "Vz")
70 resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getVz().at(tS), divergentSimResults->getVz().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getL0());
71 if (dataToCalculate == "Press")
72 resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getPress().at(tS), divergentSimResults->getPress().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getL0());
73 if (dataToCalculate == "Rho")
74 resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getRho().at(tS), divergentSimResults->getRho().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getL0());
75
76
77
78 if (basicL2Result < 0 || divergentL2Result < 0 || resultL2ToBasicKernel < 0)
80 else if (basicL2Result <= divergentL2Result)
82 else
84
86}
87
89{
90 std::ostringstream oss;
91 oss << "L2Norm_BasicKernel_" << "L" << basicPostProcessingStrategy->getNumberOfXNodes() << "_"<< dataToCalculate << "_TimeStep_" << timeStep << "_" << normalizeData << "=" << basicL2Result << std::endl;
92 oss << "L2Norm_DivergentKernel_" << "L" << basicPostProcessingStrategy->getNumberOfXNodes() << "_"<< dataToCalculate << "_TimeStep_" << timeStep << "_" << normalizeData << "=" << divergentL2Result << std::endl;
93 oss << "L2Norm_Between_Kernels_" << "L" << basicPostProcessingStrategy->getNumberOfXNodes() << "_"<< dataToCalculate << "_TimeStep_" << timeStep << "_" << normalizeData << "=" << resultL2ToBasicKernel << std::endl << std::endl;
94 return oss.str();
95}
96
98{
99 std::ostringstream oss;
100 oss << "L" << basicPostProcessingStrategy->getNumberOfXNodes() << "_"<< dataToCalculate << "_TimeStep_" << timeStep << "_" << normalizeData;
101 return oss.str();
102}
103
105{
106 return basicL2Result;
107}
108
109void L2NormTestBetweenKernels::setBasicSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> postProcessingStrategy)
110{
112 this->basicSim = sim;
113 this->basicSimInfo = simInfo;
114 this->basicPostProcessingStrategy = postProcessingStrategy;
115 this->basicSimResults = basicPostProcessingStrategy->getSimulationResult();
116}
117
118void L2NormTestBetweenKernels::setDivergentKernelSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> postProcessingStrategy)
119{
121 this->divergentSim = sim;
122 this->divergentSimInfo = simInfo;
123 this->divergentPostProcessingStrategy = postProcessingStrategy;
124 this->divergentSimResults = divergentPostProcessingStrategy->getSimulationResult();
125}
126
127L2NormTestBetweenKernels::L2NormTestBetweenKernels(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith, std::shared_ptr<L2NormCalculatorFactory> factory)
128 : TestImp(colorOutput), timeStep(timeStep), dataToCalculate(dataToCalculate), normalizeData(normalizeWith)
129{
130 l2Normcalculator = factory->makeL2NormCalculator(normalizeWith);
131}
132
133int L2NormTestBetweenKernels::calcTimeStepInResults(unsigned int timeStep)
134{
135 for (int i = 0; i < basicSimResults->getTimeSteps().size(); i++) {
136 if (timeStep == basicSimResults->getTimeSteps().at(i))
137 return basicSimResults->getTimeSteps().at(i);
138 }
139}
140
141std::vector<std::string> L2NormTestBetweenKernels::buildTestOutput()
142{
143 std::vector<std::string> output = buildBasicTestOutput();
144 std::ostringstream oss;
145
146 oss << "L2Norm BasicKernel: " << basicL2Result;
147 output.push_back(oss.str());
148 oss.str(std::string());
149
150 oss << "L2Norm DivergentKernel: " << divergentL2Result;
151 output.push_back(oss.str());
152 oss.str(std::string());
153
154 oss << "L2NormDiff: " << resultL2ToBasicKernel;
155 output.push_back(oss.str());
156 oss.str(std::string());
157
158 return output;
159}
160
161std::vector<std::string> L2NormTestBetweenKernels::buildBasicTestOutput()
162{
163 std::vector<std::string> output;
164 std::ostringstream oss;
165
166 output.push_back("L2 Norm Between Kernels Test");
167
168 oss << "Basic Kernel: " << basicSimInfo->getKernelName();
169 output.push_back(oss.str());
170 oss.str(std::string());
171
172 oss << "Divergent Kernel: " << divergentSimInfo->getKernelName();
173 output.push_back(oss.str());
174 oss.str(std::string());
175
176 oss << "Viscosity: " << basicSimInfo->getViscosity();
177 output.push_back(oss.str());
178 oss.str(std::string());
179
180 output.push_back(oss.str());
181
182 oss << basicSimInfo->getSimulationName();
183 output.push_back(oss.str());
184 oss.str(std::string());
185
186 oss << "L: " << basicSimInfo->getLx() << basicSimInfo->getSimulationParameterString();
187 output.push_back(oss.str());
188 oss.str(std::string());
189
190 output.push_back(oss.str());
191
192 oss << "DataToCalculate: " << dataToCalculate;
193 output.push_back(oss.str());
194 oss.str(std::string());
195
196 oss << "NormalizeData: " << normalizeData;
197 output.push_back(oss.str());
198 oss.str(std::string());
199
200 oss << "TimeStep: " << timeStep;
201 output.push_back(oss.str());
202 oss.str(std::string());
203
204 output.push_back(oss.str());
205
206 return output;
207}
208
209std::vector<std::string> L2NormTestBetweenKernels::buildErrorTestOutput()
210{
211 std::vector<std::string> output = buildBasicTestOutput();
212 std::ostringstream oss;
213
214 oss << "Error Message: " << basicPostProcessingStrategy->getErrorMessage(normalizeData);
215 output.push_back(oss.str());
216 oss.str(std::string());
217
218 return output;
219}
220
std::shared_ptr< ColorConsoleOutput > colorOutput
Definition TestImp.h:72
TestStatus testStatus
Definition TestImp.h:73
void setBasicSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< L2NormBetweenKernelPostProcessingStrategy > postProcessingStrategy)
void addSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< PostProcessingStrategy > postProStrategy)
Definition TestImp.cpp:84
void update() override
Definition TestImp.cpp:55
void setDivergentKernelSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< L2NormBetweenKernelPostProcessingStrategy > postProcessingStrategy)
static std::shared_ptr< L2NormTestBetweenKernels > getNewInstance(std::shared_ptr< ColorConsoleOutput > colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith, std::shared_ptr< L2NormCalculatorFactory > factory)
void makeConsoleOutput() override
Definition TestImp.cpp:98
@ test_error
Definition TestStatus.h:36
@ failed
Definition TestStatus.h:36
@ passed
Definition TestStatus.h:36
std::shared_ptr< T > SPtr