VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
L2NormTest.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 "L2NormTest.h"
34
37
40
41#include <iomanip>
42#include <sstream>
43
44std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData)
45{
46 return std::shared_ptr<L2NormTest>(new L2NormTest(colorOutput, testParameter, dataToCalculate, maxL2NormDiff, normalizeData));
47}
48
53
54void L2NormTest::addSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormPostProcessingStrategy> postProStrategy)
55{
57 l2NormPostProStrategies.push_back(postProStrategy);
58}
59
61{
62 std::vector<double> results = l2NormPostProStrategies.at(0)->getL2Norm(dataToCalculate, normalizeData);
63
64 resultBasicTimestep = results.at(0);
65 resultDivergentTimeStep = results.at(1);
66 diffL2Norm = resultDivergentTimeStep - resultBasicTimestep;
67
68 if (resultBasicTimestep < 0 || resultDivergentTimeStep < 0) {
70 }
71 else
72 {
73 testPassed = maxL2NormDiff > diffL2Norm;
74 if (testPassed)
76 else
78 }
79
81}
82
84{
85 std::ostringstream oss;
86 oss << "L2Norm_BasicTimeStep_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "_" << normalizeData << "=" << resultBasicTimestep << std::endl;
87 oss << "L2Norm_DivergentTimeStep_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "_" << normalizeData << "=" << resultDivergentTimeStep << std::endl;
88 oss << "L2Norm_Diff_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "_" << normalizeData << "=" << diffL2Norm << std::endl << std::endl;
89 return oss.str();
90}
91
93{
94 std::ostringstream oss;
95 oss << "L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "_" << normalizeData;
96 return oss.str();
97}
98
99L2NormTest::L2NormTest(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData)
100 : TestImp(colorOutput), dataToCalculate(dataToCalculate), normalizeData(normalizeData)
101{
102 basicTimeStep = testParameter->basicTimeStep;
103 divergentTimeStep = testParameter->divergentTimeStep;
104 this->maxL2NormDiff = maxL2NormDiff;
105}
106
107std::vector<std::string> L2NormTest::buildTestOutput()
108{
109 std::vector<std::string> output = buildBasicTestOutput();
110 std::ostringstream oss;
111
112 oss << "L2Norm BasicTimeStep: " << resultBasicTimestep;
113 output.push_back(oss.str());
114 oss.str(std::string());
115
116 oss << "L2Norm DivergentTimeStep: " << resultDivergentTimeStep;
117 output.push_back(oss.str());
118 oss.str(std::string());
119
120 oss << "L2NormDiff: " << diffL2Norm;
121 output.push_back(oss.str());
122 oss.str(std::string());
123
124 return output;
125}
126
127std::vector<std::string> L2NormTest::buildBasicTestOutput()
128{
129 std::vector<std::string> output;
130 std::ostringstream oss;
131
132 output.push_back("L2 Norm Test");
133
134 oss << "Kernel: " << simInfos.at(0)->getKernelName();
135 output.push_back(oss.str());
136 oss.str(std::string());
137
138 oss << "Viscosity: " << simInfos.at(0)->getViscosity();
139 output.push_back(oss.str());
140 oss.str(std::string());
141
142 output.push_back(oss.str());
143
144 oss << simInfos.at(0)->getSimulationName();
145 output.push_back(oss.str());
146 oss.str(std::string());
147
148 oss << "L: " << simInfos.at(0)->getLx() << simInfos.at(0)->getSimulationParameterString();
149 output.push_back(oss.str());
150 oss.str(std::string());
151
152 output.push_back(oss.str());
153
154 oss << "DataToCalculate: " << dataToCalculate;
155 output.push_back(oss.str());
156 oss.str(std::string());
157
158 oss << "NormalizeData: " << normalizeData;
159 output.push_back(oss.str());
160 oss.str(std::string());
161
162 output.push_back(oss.str());
163
164 oss << "BasicTimeStep: " << basicTimeStep;
165 output.push_back(oss.str());
166 oss.str(std::string());
167
168 oss << "DivergentTimeStep: " << divergentTimeStep;
169 output.push_back(oss.str());
170 oss.str(std::string());
171
172 output.push_back(oss.str());
173
174 return output;
175}
176
177std::vector<std::string> L2NormTest::buildErrorTestOutput()
178{
179 std::vector<std::string> output = buildBasicTestOutput();
180 std::ostringstream oss;
181
182 oss << "Error Message: " << l2NormPostProStrategies.at(0)->getErrorMessage(normalizeData);
183 output.push_back(oss.str());
184 oss.str(std::string());
185
186 return output;
187}
188
std::shared_ptr< ColorConsoleOutput > colorOutput
Definition TestImp.h:72
std::vector< std::shared_ptr< SimulationInfo > > simInfos
Definition TestImp.h:70
TestStatus testStatus
Definition TestImp.h:73
std::string getLogFileOutput()
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 addSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< L2NormPostProcessingStrategy > postProStrategy)
void evaluate()
void update()
static std::shared_ptr< L2NormTest > getNewInstance(std::shared_ptr< ColorConsoleOutput > colorOutput, std::shared_ptr< L2NormTestParameterStruct > testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData)
std::string getErrorLogFileOutput()
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