VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
NyTest.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 "NyTest.h"
34
38
41
42#include <iomanip>
43#include <cmath>
44
45std::shared_ptr<NyTest> NyTest::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, double viscosity, std::shared_ptr<NyTestParameterStruct> testPara, std::string dataToCalculate)
46{
47 return std::shared_ptr<NyTest>(new NyTest(colorOutput, viscosity, testPara, dataToCalculate));
48}
49
51{
52 for (int i = 0; i < postProStrategies.size(); i++)
53 ny.push_back(postProStrategies.at(i)->getNy(dataToCalculate));
54
55 if (checkNy(ny)) {
56 nyDiff = calcNyDiff(ny);
57 orderOfAccuracy = calcOrderOfAccuracy(nyDiff);
58 testStatus = checkTestPassed(orderOfAccuracy);
59 }
60 else
62
63
65}
66
68{
70}
71
72void NyTest::addSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<NyTestPostProcessingStrategy> postProStrategy)
73{
75 postProStrategies.push_back(postProStrategy);
76 lx.push_back(postProStrategy->getNumberOfXNodes());
77}
78
80{
81 return dataToCalculate;
82}
83
84std::vector<int> NyTest::getLx()
85{
86 std::vector<int> lxINT;
87 for (int i = 0; i < lx.size(); i++)
88 lxINT.push_back((int)lx.at(i));
89 return lxINT;
90}
91
92std::vector<double> NyTest::getNy()
93{
94 return ny;
95}
96
97std::vector<double> NyTest::getNyDiff()
98{
99 return nyDiff;
100}
101
103{
104 return orderOfAccuracy;
105}
106
107NyTest::NyTest(std::shared_ptr<ColorConsoleOutput> colorOutput, double viscosity, std::shared_ptr<NyTestParameterStruct> testPara, std::string dataToCalculate)
108 : TestImp(colorOutput), viscosity(viscosity), dataToCalculate(dataToCalculate)
109{
110 minOrderOfAccuracy = testPara->minOrderOfAccuracy;
111 startStepCalculation = testPara->startTimeStepCalculation;
112 endStepCalculation = testPara->endTimeStepCalculation;
113
114 lx.resize(0);
115 nyDiff.resize(0);
116}
117
118double NyTest::calcOrderOfAccuracy(std::vector<double> data)
119{
120 double ooa = std::log(data.at(0) / data.at(1)) / std::log(lx.at(1) / lx.at(0));
121
122 return ooa;
123}
124
125TestStatus NyTest::checkTestPassed(double orderOfAccuracy)
126{
127 if (orderOfAccuracy > minOrderOfAccuracy)
128 return passed;
129 else
130 return failed;
131}
132
133bool NyTest::checkNy(std::vector<double> ny)
134{
135 for(int i = 0; i < ny.size(); i++)
136 if(ny.at(i) < 0.0)
137 return false;
138 return true;
139}
140
141std::vector<double> NyTest::calcNyDiff(std::vector<double> ny)
142{
143 std::vector<double> results;
144 for (int i = 0; i < ny.size(); i++)
145 results.push_back(std::fabs((ny.at(i) - viscosity) / viscosity));
146 return results;
147}
148
149std::vector<std::string> NyTest::buildTestOutput()
150{
151 std::vector<std::string> output = buildBasicTestOutput();
152 std::ostringstream oss;
153
154 for (int i = 0; i < ny.size(); i++) {
155 oss << "Ny" << simInfos.at(i)->getLx() << ": " << ny.at(i);
156 output.push_back(oss.str());
157 oss.str(std::string());
158
159 oss << "NyDiff" << simInfos.at(i)->getLx() << ": " << nyDiff.at(i);
160 output.push_back(oss.str());
161 oss.str(std::string());
162 }
163 oss << "OrderOfAccuracy: " << orderOfAccuracy;
164 output.push_back(oss.str());
165 oss.str(std::string());
166
167 return output;
168}
169
170std::vector<std::string> NyTest::buildBasicTestOutput()
171{
172 std::vector<std::string> output;
173 std::ostringstream oss;
174
175 output.push_back("Ny Test");
176
177 oss << "Kernel: " << simInfos.at(0)->getKernelName();
178 output.push_back(oss.str());
179 oss.str(std::string());
180
181 oss << "Viscosity: " << simInfos.at(0)->getViscosity();
182 output.push_back(oss.str());
183 oss.str(std::string());
184
185 output.push_back(oss.str());
186
187 oss << simInfos.at(0)->getSimulationName();
188 output.push_back(oss.str());
189 oss.str(std::string());
190
191 for (int i = 0; i < simInfos.size(); i++) {
192 oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfos.at(i)->getLx() << simInfos.at(i)->getSimulationParameterString();
193 output.push_back(oss.str());
194 oss.str(std::string());
195 }
196
197 output.push_back(oss.str());
198
199 oss << "DataToCalculate: " << dataToCalculate;
200 output.push_back(oss.str());
201 oss.str(std::string());
202
203 oss << "StartTimeStep: " << startStepCalculation;
204 output.push_back(oss.str());
205 oss.str(std::string());
206
207 oss << "EndTimeStep: " << endStepCalculation;
208 output.push_back(oss.str());
209 oss.str(std::string());
210
211 output.push_back(oss.str());
212
213 return output;
214}
215
216std::vector<std::string> NyTest::buildErrorTestOutput()
217{
218 std::vector<std::string> output = buildBasicTestOutput();
219 std::ostringstream oss;
220
221 oss << "Error Message: Ny < 0";
222 output.push_back(oss.str());
223 oss.str(std::string());
224
225 return output;
226}
227
228std::vector<std::string> NyTest::buildSimulationFailedTestOutput()
229{
230 std::vector<std::string> output = buildBasicTestOutput();
231 std::ostringstream oss;
232
233 oss << "Simulation crashed!";
234 output.push_back(oss.str());
235 oss.str(std::string());
236
237 return output;
238}
239
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::vector< double > getNyDiff()
Definition NyTest.cpp:97
void update()
Definition NyTest.cpp:67
std::vector< int > getLx()
Definition NyTest.cpp:84
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
std::string getDataToCalculate()
Definition NyTest.cpp:79
void evaluate()
Definition NyTest.cpp:50
double getOrderOfAccuracyNyDiff()
Definition NyTest.cpp:102
void addSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< NyTestPostProcessingStrategy > postProStrategy)
Definition NyTest.cpp:72
void makeConsoleOutput() override
Definition TestImp.cpp:98
static std::shared_ptr< NyTest > getNewInstance(std::shared_ptr< ColorConsoleOutput > colorOutput, double viscosity, std::shared_ptr< NyTestParameterStruct > testPara, std::string dataToCalculate)
Definition NyTest.cpp:45
std::vector< double > getNy()
Definition NyTest.cpp:92
TestStatus
Definition TestStatus.h:36
@ test_error
Definition TestStatus.h:36
@ failed
Definition TestStatus.h:36
@ passed
Definition TestStatus.h:36
std::shared_ptr< T > SPtr