VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
PhiTest.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 "PhiTest.h"
34
38
41
42#include "basics/DataTypes.h"
43
44#include <iomanip>
45#include <cmath>
46
47std::shared_ptr<PhiTest> PhiTest::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, double viscosity, std::shared_ptr<PhiTestParameterStruct> testPara, std::string dataToCalculate)
48{
49 return std::shared_ptr<PhiTest>(new PhiTest(colorOutput, viscosity, testPara, dataToCalculate));
50}
51
53{
54 for (uint i = 0; i < postProStrategies.size(); i++)
55 phiDiff.push_back(postProStrategies.at(i)->getPhiDiff(dataToCalculate));
56
57 orderOfAccuracy = calcOrderOfAccuracy(phiDiff);
58 testStatus = checkTestPassed(orderOfAccuracy);
59
61}
62
64{
66}
67
68void PhiTest::addSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<PhiTestPostProcessingStrategy> postProStrategy)
69{
71 postProStrategies.push_back(postProStrategy);
72 lx.push_back(postProStrategy->getNumberOfXNodes());
73}
74
76{
77 return dataToCalculate;
78}
79
80std::vector<int> PhiTest::getLx()
81{
82 std::vector<int> lxINT;
83 for (uint i = 0; i < lx.size(); i++)
84 lxINT.push_back((int)lx.at(i));
85 return lxINT;
86}
87
88std::vector<double> PhiTest::getPhiDiff()
89{
90 return phiDiff;
91}
92
94{
95 return orderOfAccuracy;
96}
97
98PhiTest::PhiTest(std::shared_ptr<ColorConsoleOutput> colorOutput, double viscosity, std::shared_ptr<PhiTestParameterStruct> testPara, std::string dataToCalculate)
99 : TestImp(colorOutput), dataToCalculate(dataToCalculate)
100{
101 minOrderOfAccuracy = testPara->minOrderOfAccuracy;
102 startStepCalculation = testPara->startTimeStepCalculation;
103 endStepCalculation = testPara->endTimeStepCalculation;
104
105 lx.resize(0);
106 phiDiff.resize(0);
107}
108
109double PhiTest::calcOrderOfAccuracy(std::vector<double> data)
110{
111 double ooa = std::log(data.at(0) / data.at(1)) / std::log(lx.at(1) / lx.at(0));
112
113 return ooa;
114}
115
116TestStatus PhiTest::checkTestPassed(double orderOfAccuracy)
117{
118 if (orderOfAccuracy > minOrderOfAccuracy)
119 return passed;
120 else
121 return failed;
122}
123
124std::vector<std::string> PhiTest::buildTestOutput()
125{
126 std::vector<std::string> output = buildBasicTestOutput();
127 std::ostringstream oss;
128
129 for (uint i = 0; i < phiDiff.size(); i++) {
130 oss << "PhiDiff" << simInfos.at(i)->getLx() << ": " << phiDiff.at(i);
131 output.push_back(oss.str());
132 oss.str(std::string());
133 }
134 oss << "OrderOfAccuracy: " << orderOfAccuracy;
135 output.push_back(oss.str());
136 oss.str(std::string());
137
138 return output;
139}
140
141std::vector<std::string> PhiTest::buildBasicTestOutput()
142{
143 std::vector<std::string> output;
144 std::ostringstream oss;
145
146 output.push_back("Phi Test");
147
148 oss << "Kernel: " << simInfos.at(0)->getKernelName();
149 output.push_back(oss.str());
150 oss.str(std::string());
151
152 oss << "Viscosity: " << simInfos.at(0)->getViscosity();
153 output.push_back(oss.str());
154 oss.str(std::string());
155
156 output.push_back(oss.str());
157
158 oss << simInfos.at(0)->getSimulationName();
159 output.push_back(oss.str());
160 oss.str(std::string());
161
162 for (uint i = 0; i < simInfos.size(); i++) {
163 oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfos.at(i)->getLx() << simInfos.at(i)->getSimulationParameterString();
164 output.push_back(oss.str());
165 oss.str(std::string());
166 }
167
168 output.push_back(oss.str());
169
170 oss << "DataToCalculate: " << dataToCalculate;
171 output.push_back(oss.str());
172 oss.str(std::string());
173
174 oss << "StartTimeStep: " << startStepCalculation;
175 output.push_back(oss.str());
176 oss.str(std::string());
177
178 oss << "EndTimeStep: " << endStepCalculation;
179 output.push_back(oss.str());
180 oss.str(std::string());
181
182 output.push_back(oss.str());
183
184 return output;
185}
186
187std::vector<std::string> PhiTest::buildErrorTestOutput()
188{
189 std::vector<std::string> output = buildBasicTestOutput();
190 std::ostringstream oss;
191
192 oss << "Error Message: ";
193 output.push_back(oss.str());
194 oss.str(std::string());
195
196 return output;
197}
198
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 getDataToCalculate()
Definition PhiTest.cpp:75
static std::shared_ptr< PhiTest > getNewInstance(std::shared_ptr< ColorConsoleOutput > colorOutput, double viscosity, std::shared_ptr< PhiTestParameterStruct > testPara, std::string dataToCalculate)
Definition PhiTest.cpp:47
std::vector< int > getLx()
Definition PhiTest.cpp:80
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 evaluate()
Definition PhiTest.cpp:52
void update()
Definition PhiTest.cpp:63
std::vector< double > getPhiDiff()
Definition PhiTest.cpp:88
double getOrderOfAccuracy()
Definition PhiTest.cpp:93
void addSimulation(std::shared_ptr< NumericalTestSimulation > sim, std::shared_ptr< SimulationInfo > simInfo, std::shared_ptr< PhiTestPostProcessingStrategy > postProStrategy)
Definition PhiTest.cpp:68
void makeConsoleOutput() override
Definition TestImp.cpp:98
TestStatus
Definition TestStatus.h:36
@ failed
Definition TestStatus.h:36
@ passed
Definition TestStatus.h:36
std::shared_ptr< T > SPtr
unsigned int uint
Definition DataTypes.h:47