Skip to content
Snippets Groups Projects
Commit a93b5719 authored by Timon Habenicht's avatar Timon Habenicht
Browse files

changes ColorConsoleOutput to Singleton

parent 26817bc1
No related branches found
No related tags found
No related merge requests found
Showing
with 59 additions and 47 deletions
#include "L2NormTest.h"
#include "Utilities/ColorConsoleOutput/ColorConsoleOutput.h"
#include "Utilities\Calculator\L2NormCalculator\L2NormCalculator.h"
#include "Utilities\Results\AnalyticalResults\AnalyticalResult.h"
#include "Utilities\Results\SimulationResults\SimulationResults.h"
std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult)
std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput)
{
return std::shared_ptr<L2NormTest>(new L2NormTest(analyticalResult));
return std::shared_ptr<L2NormTest>(new L2NormTest(analyticalResult, colorOutput));
}
void L2NormTest::update()
......@@ -43,7 +44,7 @@ void L2NormTest::makeConsoleOutput()
}
L2NormTest::L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult) : analyticalResult(analyticalResult)
L2NormTest::L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput) : TestImp(colorOutput), analyticalResult(analyticalResult)
{
calculator = L2NormCalculator::getNewInstance();
}
\ No newline at end of file
......@@ -11,7 +11,7 @@ class AnalyticalResults;
class L2NormTest : public TestImp
{
public:
static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult);
static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput);
void update();
void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo);
......@@ -21,8 +21,7 @@ public:
void makeConsoleOutput();
private:
L2NormTest() {};
L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult);
L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput);
std::shared_ptr< L2NormCalculator> calculator;
std::shared_ptr< AnalyticalResults> analyticalResult;
......
#include "PhiAndNuTest.h"
#include "Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h"
#include "Utilities/ColorConsoleOutput/ColorConsoleOutput.h"
#include "Utilities/Results/SimulationResults/SimulationResults.h"
#include "Utilities\Calculator\FFTCalculator\FFTCalculator.h"
#include "Utilities\TestSimulation\TestSimulation.h"
#include "Utilities\SimulationInfo\SimulationInfo.h"
std::shared_ptr<PhiAndNuTest> PhiAndNuTest::getNewInstance(std::string dataToCalculate, double minOrderOfAccuracy, double viscosity)
#include <iomanip>
std::shared_ptr<PhiAndNuTest> PhiAndNuTest::getNewInstance(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity)
{
return std::shared_ptr<PhiAndNuTest>(new PhiAndNuTest(dataToCalculate, minOrderOfAccuracy, viscosity));
return std::shared_ptr<PhiAndNuTest>(new PhiAndNuTest(colorOutput, dataToCalculate, minOrderOfAccuracy, viscosity));
}
void PhiAndNuTest::evaluate()
......@@ -52,8 +54,8 @@ std::vector<bool> PhiAndNuTest::getPassedTests()
void PhiAndNuTest::makeConsoleOutput()
{
testOut->makeTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), "NuDiff", "NuDiff", "OrderOfAccuracy", nuDiff.at(0), nuDiff.at(1), orderOfAccuracyNuDiff);
testOut->makeTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), "PhiDiff", "PhiDiff", "OrderOfAccuracy", phiDiff.at(0), phiDiff.at(1), orderOfAccuracyPhiDiff);
colorOutput->makeTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), "NuDiff", "NuDiff", "OrderOfAccuracy", nuDiff.at(0), nuDiff.at(1), orderOfAccuracyNuDiff);
colorOutput->makeTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), "PhiDiff", "PhiDiff", "OrderOfAccuracy", phiDiff.at(0), phiDiff.at(1), orderOfAccuracyPhiDiff);
}
std::string PhiAndNuTest::getLogFileOutput()
......@@ -66,13 +68,12 @@ std::string PhiAndNuTest::getLogFileOutput()
return oss.str();
}
PhiAndNuTest::PhiAndNuTest(std::string dataToCalculate, double minOrderOfAccuracy, double viscosity) : TestImp(), minOrderOfAccuracy(minOrderOfAccuracy), viscosity(viscosity), dataToCalculate(dataToCalculate)
PhiAndNuTest::PhiAndNuTest(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity) : TestImp(colorOutput), minOrderOfAccuracy(minOrderOfAccuracy), viscosity(viscosity), dataToCalculate(dataToCalculate)
{
lx.resize(0);
phiDiff.resize(0);
nuDiff.resize(0);
calculator = FFTCalculator::getNewInstance(viscosity);
testOut = ColorConsoleOutputImp::getNewInstance();
}
double PhiAndNuTest::calcOrderOfAccuracy(std::vector<double> data)
......
......@@ -7,13 +7,12 @@
#include <vector>
#include <iostream>
class ColorConsoleOutput;
class FFTCalculator;
class PhiAndNuTest : public TestImp
{
public:
static std::shared_ptr<PhiAndNuTest> getNewInstance(std::string dataToCalculate, double minOrderOfAccuracy, double viscosity);
static std::shared_ptr<PhiAndNuTest> getNewInstance(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity);
void update();
void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo);
......@@ -23,13 +22,13 @@ public:
void makeConsoleOutput();
private:
PhiAndNuTest(std::string dataToCalculate, double minOrderOfAccuracy, double viscosity);
PhiAndNuTest(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity);
double calcOrderOfAccuracy(std::vector<double> data);
bool checkTestPassed(double orderOfAccuracy);
std::shared_ptr< FFTCalculator> calculator;
std::shared_ptr< ColorConsoleOutput> testOut;
std::vector<double> lx;
std::vector<double> phiDiff;
std::vector<double> nuDiff;
......@@ -41,7 +40,6 @@ private:
bool phiDiffTestPassed;
bool nuDiffTestPassed;
std::string dataToCalculate;
};
#endif
#ifndef COLOR_CONSOLE_OUTPUT_H
#define COLOR_CONSOLE_OUTPUT_H
#include <iostream>
#include <memory>
#include <sstream>
class SimulationInfo;
......@@ -13,6 +13,8 @@ public:
virtual void makeSimulationHeadOutput(std::shared_ptr< SimulationInfo> simInfo) = 0;
virtual void makeFinalTestOutputHead(int numberOfPassedTests, int numberOfTests) = 0;
virtual void makeFinalTestOutputFoot(int numberOfPassedTests, int numberOfTests) = 0;
private:
};
#endif
\ No newline at end of file
#endif
\ No newline at end of file
......@@ -6,9 +6,12 @@
#include "Utilities\SimulationInfo\SimulationInfo.h"
std::shared_ptr<ColorConsoleOutput> ColorConsoleOutputImp::getNewInstance()
std::shared_ptr<ColorConsoleOutput> ColorConsoleOutputImp::getInstance()
{
return std::shared_ptr<ColorConsoleOutput>(new ColorConsoleOutputImp());
static std::shared_ptr<ColorConsoleOutput> uniqueInstance;
if (!uniqueInstance)
uniqueInstance = std::shared_ptr<ColorConsoleOutput>(new ColorConsoleOutputImp());
return uniqueInstance;
}
void ColorConsoleOutputImp::makeTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3)
......
......@@ -3,7 +3,7 @@
#include "ColorConsoleOutput.h"
#include <sstream>
#include <iostream>
#include <gtest/gtest.h>
......@@ -31,7 +31,7 @@ namespace testing
class ColorConsoleOutputImp : public ColorConsoleOutput
{
public:
static std::shared_ptr<ColorConsoleOutput> getNewInstance();
static std::shared_ptr<ColorConsoleOutput> getInstance();
void makeTestOutput(bool testPassed, std::shared_ptr< SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3);
void makeSimulationHeadOutput(std::shared_ptr< SimulationInfo> simInfo);
......
......@@ -30,6 +30,8 @@
#include "Utilities/LogFileInformation/BasicSimulationInfo/BasicSimulationInfo.h"
#include "Utilities\LogFileInformation\LogFileTimeInformation\LogFileTimeInformation.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutputImp.h"
std::shared_ptr<ConfigFileReader> ConfigFileReader::getNewInstance()
{
return std::shared_ptr<ConfigFileReader>(new ConfigFileReader());
......@@ -58,7 +60,9 @@ ConfigFileReader::ConfigFileReader()
l0 = 32.0;
rho0 = 1.0;
testQueue = TestQueueImp::getNewInstance();
colorOutput = ColorConsoleOutputImp::getInstance();
testQueue = TestQueueImp::getNewInstance(colorOutput);
}
void ConfigFileReader::readConfigFile(const std::string aFilePath)
......@@ -167,7 +171,7 @@ std::vector< std::shared_ptr< TestSimulation>> ConfigFileReader::buildTestSimula
testSim.resize(0);
for (int i = 0; i < simPara.size(); i++) {
testSim.push_back(TestSimulationImp::getNewInsance(simID, simPara.at(i), simInfo.at(i)));
testSim.push_back(TestSimulationImp::getNewInsance(simID, simPara.at(i), simInfo.at(i), colorOutput));
simID++;
}
return testSim;
......@@ -252,7 +256,7 @@ std::vector< std::shared_ptr< PhiAndNuTest>> ConfigFileReader::makePhiAndNuTests
for (int i = 1; i < testSim.size(); i++) {
for (int j = 0; j < i; j++) {
std::shared_ptr< PhiAndNuTest> test = PhiAndNuTest::getNewInstance(dataToCalcPhiAndNuTest, minOrderOfAccuracy, viscosity);
std::shared_ptr< PhiAndNuTest> test = PhiAndNuTest::getNewInstance(colorOutput, dataToCalcPhiAndNuTest, minOrderOfAccuracy, viscosity);
test->addSimulation(testSim.at(j), simInfo.at(j));
test->addSimulation(testSim.at(i), simInfo.at(i));
......@@ -270,7 +274,7 @@ std::vector<std::shared_ptr<L2NormTest>> ConfigFileReader::makeL2NormTests(std::
{
std::vector<std::shared_ptr<L2NormTest>> l2Tests;
for (int i = 0; i < testSim.size(); i++) {
std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(analyticalResults.at(i));
std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(analyticalResults.at(i), colorOutput);
test->addSimulation(testSim.at(i), simInfo.at(i));
testSim.at(i)->registerSimulationObserver(test);
l2Tests.push_back(test);
......
......@@ -22,6 +22,7 @@ class LogFileTimeInformation;
class TestLogFileInformation;
class SimulationLogFileInformation;
class AnalyticalResults;
class ColorConsoleOutput;
class ConfigFileReader
{
......@@ -79,10 +80,10 @@ private:
std::vector< bool> sw;
std::vector< std::shared_ptr< LogFileInformation> > logInfo;
std::shared_ptr< TestQueueImp> testQueue;
std::vector< std::shared_ptr< TestSimulation>> testSimulation;
std::shared_ptr< TestQueueImp> testQueue;
std::shared_ptr< ColorConsoleOutput> colorOutput;
std::shared_ptr< LogFileQueueImp> logFileWriterQueue;
int simID;
......
......@@ -33,7 +33,7 @@ std::string TestImp::getSimulationName()
return simulationName;
}
TestImp::TestImp()
TestImp::TestImp(std::shared_ptr<ColorConsoleOutput> colorOutput) : colorOutput(colorOutput)
{
simulationRun.resize(0);
simulations.resize(0);
......
......@@ -8,6 +8,7 @@
class TestSimulation;
class SimulationResults;
class SimulationInfo;
class ColorConsoleOutput;
class TestImp : public Test
{
......@@ -23,16 +24,20 @@ public:
std::string getSimulationName();
protected:
TestImp();
TestImp(std::shared_ptr< ColorConsoleOutput> colorOutput);
bool CheckAllSimulationRun();
std::vector< bool> simulationRun;
std::shared_ptr< ColorConsoleOutput> colorOutput;
std::vector< std::shared_ptr< TestSimulation>> simulations;
std::vector< std::shared_ptr< SimulationResults>> simResults;
std::vector< std::shared_ptr< SimulationInfo>> simInfos;
std::string kernelName;
std::string simulationName;
private:
TestImp() {};
};
#endif
\ No newline at end of file
#include "TestQueueImp.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutputImp.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutput.h"
#include "Utilities\Test\Test.h"
void TestQueueImp::makeFinalOutput()
......@@ -12,9 +12,9 @@ void TestQueueImp::makeFinalOutput()
colorOutput->makeFinalTestOutputFoot(numberOfPassedTest, numberOfTests);
}
std::shared_ptr<TestQueueImp> TestQueueImp::getNewInstance()
std::shared_ptr<TestQueueImp> TestQueueImp::getNewInstance(std::shared_ptr< ColorConsoleOutput> colorOutput)
{
return std::shared_ptr<TestQueueImp>(new TestQueueImp());
return std::shared_ptr<TestQueueImp>(new TestQueueImp(colorOutput));
}
void TestQueueImp::addTest(std::shared_ptr<Test> test)
......@@ -22,10 +22,9 @@ void TestQueueImp::addTest(std::shared_ptr<Test> test)
tests.push_back(test);
}
TestQueueImp::TestQueueImp()
TestQueueImp::TestQueueImp(std::shared_ptr< ColorConsoleOutput> colorOutput)
{
tests.resize(0);
colorOutput = ColorConsoleOutputImp::getNewInstance();
}
void TestQueueImp::calcNumberOfPassedTest()
......
......@@ -14,16 +14,16 @@ class TestQueueImp : public TestQueue
public:
void makeFinalOutput();
static std::shared_ptr< TestQueueImp> getNewInstance();
static std::shared_ptr< TestQueueImp> getNewInstance(std::shared_ptr< ColorConsoleOutput> colorOutput);
void addTest(std::shared_ptr< Test> test);
private:
TestQueueImp();
TestQueueImp(std::shared_ptr< ColorConsoleOutput> colorOutput);
void calcNumberOfPassedTest();
std::vector< std::shared_ptr< Test>> tests;
std::shared_ptr< ColorConsoleOutput> colorOutput;
std::vector< std::shared_ptr< Test>> tests;
int numberOfPassedTest;
int numberOfTests;
};
......
......@@ -7,16 +7,16 @@
#include "Utilities/Results/SimulationResults/SimulationResults.h"
#include "Utilities\Test\SimulationObserver.h"
#include "Utilities\DataWriter\Y2dSliceToResults\Y2dSliceToResults.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutputImp.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutput.h"
#include "Utilities\KernelConfiguration\KernelConfiguration.h"
#include <sstream>
#include <iomanip>
std::shared_ptr<TestSimulation> TestSimulationImp::getNewInsance(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo)
std::shared_ptr<TestSimulation> TestSimulationImp::getNewInsance(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput)
{
return std::shared_ptr< TestSimulation>(new TestSimulationImp(simID, simPara, simInfo));
return std::shared_ptr< TestSimulation>(new TestSimulationImp(simID, simPara, simInfo, colorOutput));
}
std::shared_ptr<SimulationParameter> TestSimulationImp::getSimulationParameter()
......@@ -79,14 +79,13 @@ std::string TestSimulationImp::getSimulationRunTimeOutput()
return oss.str();
}
TestSimulationImp::TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo) : simID(simID)
TestSimulationImp::TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput) : simID(simID), colorOutput(colorOutput)
{
this->simPara = simPara;
this->simInfo = simInfo;
simResults = SimulationResults::getNewInstance(simPara->getLx(), 1, simPara->getLz(), simPara->getTimeStepLength());
writeToVector = std::shared_ptr<ToVectorWriter>(new Y2dSliceToResults(simResults, simPara->getYSliceForCalculation(), simPara->getStartTimeCalculation(), simPara->getEndTime(), simPara->getTimeStepLength(), simPara->getWriteFiles(), std::shared_ptr<FileWriter>(new FileWriter()), simPara->getStartTimeDataWriter()));
colorOutput = ColorConsoleOutputImp::getNewInstance();
simObserver.resize(0);
simualtionRun = false;
......
......@@ -13,7 +13,7 @@ class SimulationInfo;
class TestSimulationImp : public TestSimulation
{
public:
static std::shared_ptr< TestSimulation> getNewInsance(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo);
static std::shared_ptr< TestSimulation> getNewInsance(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput);
std::shared_ptr< SimulationParameter> getSimulationParameter();
std::shared_ptr< DataWriter> getDataWriter();
......@@ -28,7 +28,7 @@ public:
std::string getSimulationRunTimeOutput();
private:
TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo);
TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput);
void notifyObserver();
double calcSimTime();
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment