VirtualFluids 0.2.0
Parallel CFD LBM Solver
Loading...
Searching...
No Matches
ColorConsoleOutputImp.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
36
37#include <ctime>
38#include <iomanip>
39
40#include <logger/Logger.h>
41
42#include <basics/DataTypes.h>
43
44void log(const char* fmt) {
45 VF_LOG_INFO("{}", fmt);
46}
47
48std::shared_ptr<ColorConsoleOutput> ColorConsoleOutputImp::getInstance()
49{
50 static std::shared_ptr<ColorConsoleOutput> uniqueInstance;
51 if (!uniqueInstance)
52 uniqueInstance = std::shared_ptr<ColorConsoleOutput>(new ColorConsoleOutputImp());
53 return uniqueInstance;
54}
55
56void ColorConsoleOutputImp::makeSimulationHeadOutput(std::shared_ptr<SimulationInfo> simInfo)
57{
58 std::ostringstream ossLine0;
59 ossLine0 << "# Simulation Number " << simInfo->getSimulationID() << " of " << simInfo->getNumberOfSimulations();
60 int length = 49 - ossLine0.str().size();
61 ossLine0 << std::setfill(' ') << std::right << std::setw(length) << "#";
62
63 std::ostringstream ossLine1;
64 ossLine1 << "# Kernel: " << std::setfill(' ') << std::left << std::setw(38) << simInfo->getKernelName() << "#";
65
66 std::ostringstream ossLine2;
67 ossLine2 << "# Viscosity: " << std::setfill(' ') << std::left << std::setw(35) << simInfo->getViscosity() << "#";
68
69 std::ostringstream ossLine3;
70 ossLine3 << "# SIMULATION: " << std::setfill(' ') << std::left << std::setw(34) << simInfo->getSimulationName() << "#";
71
72 std::ostringstream ossLine4;
73 ossLine4 << std::setfill(' ') << std::left << std::setw(14) << "#" << std::setw(34) << simInfo->getSimulationParameterString() << "#";
74
75 std::ostringstream ossLine5;
76 ossLine5 << "# L: " << std::setfill(' ') << std::left << std::setw(43) << simInfo->getLx() << "#";
77
78 std::ostringstream ossLine6;
79 time_t now;
80 struct tm nowLocal;
81 now = time(NULL);
82 nowLocal = *localtime(&now);
83 ossLine6 << "# DATE: " << std::setfill('0') << std::setw(2) << nowLocal.tm_mday << "." << std::setw(2) << nowLocal.tm_mon + 1 << "." << nowLocal.tm_year + 1900 << " TIME: " << std::setw(2) << nowLocal.tm_hour << ":" << std::setw(2) << nowLocal.tm_min << ":" << std::setw(2) << nowLocal.tm_sec << "\t" << "\t#";
84
85 printGreenHashLine();
86 printGreen(ossLine0.str());
87 printGreen(ossLine1.str());
88 printGreen(ossLine2.str());
89 printGreen(ossLine3.str());
90 printGreen(ossLine4.str());
91 printGreen(ossLine5.str());
92 printGreen(ossLine6.str());
93 printGreenHashLine();
94}
95
96void ColorConsoleOutputImp::makeTestOutput(std::vector<std::string> testOutput, TestStatus status)
97{
98 setColor(status);
99 printTestStart();
100
101 printColor("");
102 printColor(testOutput.at(0));
103 printColor("");
104
105 for (uint i = 1; i < testOutput.size(); i++)
106 print(testOutput.at(i));
107
108 printColor("");
109 printColor(testOutput.at(0));
110 printColor("");
111
112 printTestEnd(status);
113}
114
115void ColorConsoleOutputImp::makeFinalTestOutputHead(int numberOfTests, int numberOfExecutedTest, int numberOfPassedTest, int numberOfFailedTest, int numberOfErrorTest, int numberOfNotExecutedTest)
116{
117 setColor(numberOfTests == numberOfPassedTest);
118 printTestPassed(numberOfTests, numberOfExecutedTest, numberOfPassedTest, numberOfFailedTest, numberOfErrorTest, numberOfNotExecutedTest);
119 printLine();
120}
121
122void ColorConsoleOutputImp::makeFinalTestOutputFoot(int numberOfTests, int numberOfExecutedTest, int numberOfPassedTest, int numberOfFailedTest, int numberOfErrorTest, int numberOfNotExecutedTest)
123{
124 setColor(numberOfTests == numberOfPassedTest);
125 printLine();
126 printTestPassed(numberOfTests, numberOfExecutedTest, numberOfPassedTest, numberOfFailedTest, numberOfErrorTest, numberOfNotExecutedTest);
127}
128
129void ColorConsoleOutputImp::printTestStart()
130{
131 log( "[-----------]");
132 log( "[Run Test ]");
133 log( "[TestInfo ]");
134}
135
136void ColorConsoleOutputImp::printTestEnd(TestStatus status)
137{
138 log( "[ TestInfo]");
139 switch (status)
140 {
141 case passed: log( "[ PASSED]");
142 break;
143 case failed: log( "[ FAILED]");
144 break;
145 case test_error: log( "[ ERROR]");
146 break;
147 case simulationCrashed: log( "[Sim crashed]");
148 break;
149 default:
150 break;
151 }
152
153 log( "[-----------]");
154}
155
156void ColorConsoleOutputImp::print(std::string output)
157{
158 log("[ ] ");
159 log(output.c_str());
160}
161
162void ColorConsoleOutputImp::printColor(std::string output)
163{
164 log("[-----------] ");
165 log(output.c_str());
166}
167
168void ColorConsoleOutputImp::setColor(TestStatus status)
169{
170 switch (status)
171 {
172 case passed: color = "green";
173 break;
174 case failed: color = "red";
175 break;
176 case test_error: color = "yellow";
177 break;
178 case simulationCrashed: color = "yellow";
179 break;
180 default:
181 break;
182 }
183}
184
185void ColorConsoleOutputImp::setColor(bool passed)
186{
187 if (passed)
188 color = "green";
189 else
190 color = "red";
191}
192
193void ColorConsoleOutputImp::printTestPassed(int numberOfTests, int numberOfExecutedTest, int numberOfPassedTest, int numberOfFailedTest, int numberOfErrorTest, int numberOfNotExecutedTest)
194{
195 std::ostringstream test;
196 test << "[-----------]" << std::endl;
197 test << "[-----------] Test Summary" << std::endl;
198 test << "[-----------] " << numberOfTests << " initialized Tests" << std::endl;
199 test << "[-----------]" << std::endl;
200 test << "[-----------] " << numberOfExecutedTest << " out of " << numberOfTests << " Tests executed" << std::endl;
201 test << "[-----------] " << numberOfErrorTest << " out of " << numberOfTests << " Tests executed and completed with error" << std::endl;
202 test << "[-----------] " << numberOfNotExecutedTest << " out of " << numberOfTests << " Tests not executed" << std::endl;
203 test << "[-----------]" << std::endl;
204 test << "[-----------] " << numberOfPassedTest << " out of " << numberOfExecutedTest << " executed Tests passed" << std::endl;
205 test << "[-----------] " << numberOfFailedTest << " out of " << numberOfExecutedTest << " executed Tests failed" << std::endl;
206 test << "[-----------]" << std::endl;
207 log(test.str().c_str());
208}
209
210void ColorConsoleOutputImp::printLine()
211{
212 log("----------------------------------------------------------------------");
213}
214
215void ColorConsoleOutputImp::printGreen(std::string output)
216{
217 log(output.c_str());
218}
219
220void ColorConsoleOutputImp::printGreenHashLine()
221{
222 log("#################################################");
223}
224
#define VF_LOG_INFO(...)
Definition Logger.h:50
static std::shared_ptr< ColorConsoleOutput > getInstance()
void makeSimulationHeadOutput(std::shared_ptr< SimulationInfo > simInfo)
void makeFinalTestOutputHead(int numberOfTests, int numberOfExecutedTest, int numberOfPassedTest, int numberOfFailedTest, int numberOfErrorTest, int numberOfNotExecutedTest)
void makeTestOutput(std::vector< std::string > testOutput, TestStatus status)
void makeFinalTestOutputFoot(int numberOfTests, int numberOfExecutedTest, int numberOfPassedTest, int numberOfFailedTest, int numberOfErrorTest, int numberOfNotExecutedTest)
void log(const char *fmt)
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
unsigned int uint
Definition DataTypes.h:47