VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
TestImp.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 "TestImp.h"
34#include <algorithm>
35
40
42{
43 for (size_t i = 0; i < simulations.size(); i++) {
44 auto sim = simulations.at(i);
45 auto simInfo = simInfos.at(i);
46
47 // NOTE: Simulations can be in this vector multiple times
48 // Therefore, we skip the simulation if it has been run already
49 if (simulationRun.at(i))
50 continue;
51 sim->run();
52 }
53}
54
56{
57 for (size_t i = 0; i < simulations.size(); i++) {
58 if (simulationRun.at(i) == false) {
59 switch (simulations.at(i)->getSimulationStatus()) {
60 case executed:
61 simulationRun.at(i) = true;
62 postProStrategies.at(i)->evaluate();
63 break;
64 case crashed:
65 simulationRun.at(i) = true;
67 break;
68 case initialized:
69 simulationRun.at(i) = false;
70 break;
71 default:
72 break;
73 }
74 }
75 }
78 evaluate();
79 else
81 }
82}
83
84void TestImp::addSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo,
85 std::shared_ptr<PostProcessingStrategy> postProStrategy)
86{
87 simulations.push_back(sim);
88 simInfos.push_back(simInfo);
90 simulationRun.push_back(false);
91}
92
97
99{
100 switch (testStatus) {
101 case passed:
102 colorOutput->makeTestOutput(buildTestOutput(), testStatus);
103 break;
104 case failed:
105 colorOutput->makeTestOutput(buildTestOutput(), testStatus);
106 break;
107 case test_error:
108 colorOutput->makeTestOutput(buildErrorTestOutput(), testStatus);
109 break;
112 break;
113 default:
114 break;
115 }
116}
117
118TestImp::TestImp(std::shared_ptr<ColorConsoleOutput> colorOutput) : colorOutput(colorOutput)
119{
120 simulationRun.resize(0);
121 simulations.resize(0);
122 simInfos.resize(0);
123}
124
126{
127 return std::all_of(simulationRun.begin(), simulationRun.end(), [](bool run) { return run; });
128}
129
131{
132 std::vector<std::string> output = buildBasicTestOutput();
133 std::ostringstream oss;
134
135 oss << "Simulation crashed!";
136 output.push_back(oss.str());
137 oss.str(std::string());
138
139 return output;
140}
141
std::vector< bool > simulationRun
Definition TestImp.h:71
std::vector< std::shared_ptr< NumericalTestSimulation > > simulations
Definition TestImp.h:68
std::shared_ptr< ColorConsoleOutput > colorOutput
Definition TestImp.h:72
virtual std::vector< std::string > buildTestOutput()=0
std::vector< std::shared_ptr< PostProcessingStrategy > > postProStrategies
Definition TestImp.h:69
virtual std::vector< std::string > buildErrorTestOutput()=0
std::vector< std::shared_ptr< SimulationInfo > > simInfos
Definition TestImp.h:70
virtual void evaluate()=0
virtual std::vector< std::string > buildBasicTestOutput()=0
TestStatus testStatus
Definition TestImp.h:73
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 run() override
Definition TestImp.cpp:41
std::vector< std::string > buildSimulationFailedTestOutput()
Definition TestImp.cpp:130
bool CheckAllSimulationRun()
Definition TestImp.cpp:125
TestStatus getTestStatus() override
Definition TestImp.cpp:93
void makeConsoleOutput() override
Definition TestImp.cpp:98
TestImp(std::shared_ptr< ColorConsoleOutput > colorOutput)
Definition TestImp.cpp:118
TestStatus
Definition TestStatus.h:36
@ test_error
Definition TestStatus.h:36
@ simulationCrashed
Definition TestStatus.h:36
@ failed
Definition TestStatus.h:36
@ passed
Definition TestStatus.h:36
std::shared_ptr< T > SPtr