From 44143c1aa7dcea104de6c53b9c31acbff0eee82c Mon Sep 17 00:00:00 2001 From: Timon Habenicht <t.habenicht@tu-bs.de> Date: Tue, 27 Nov 2018 19:17:07 +0100 Subject: [PATCH] adds PostProcessingResults --- .../Tests/L2NormTest/L2NormTest.cpp | 68 +++---- .../Tests/L2NormTest/L2NormTest.h | 13 +- .../Tests/PhiAndNuTest/PhiAndNuTest.cpp | 60 +++--- .../Tests/PhiAndNuTest/PhiAndNuTest.h | 10 +- .../FFTCalculator/FFTCalculator.cpp | 109 ++++------- .../Calculator/FFTCalculator/FFTCalculator.h | 34 ++-- .../L2NormCalculator/L2NormCalculator.cpp | 7 +- .../ColorConsoleOutput/ColorConsoleOutput.h | 5 +- .../ColorConsoleOutputImp.cpp | 93 +++++++++- .../ColorConsoleOutputImp.h | 5 +- .../Utilities/ConfigFileReader/ConfigData.h | 4 +- .../ConfigFileReader/ConfigFileReader.cpp | 4 +- .../Y2dSliceToResults/Y2dSliceToResults.cpp | 5 + .../Y2dSliceToResults/Y2dSliceToResults.h | 3 +- .../NumericalTestFactoryImp.cpp | 53 ++++-- .../NumericalTestFactoryImp.h | 8 +- .../PostProcessingResults.h | 32 ++++ .../PostProcessingResultsImp.cpp | 175 ++++++++++++++++++ .../PostProcessingResultsImp.h | 60 ++++++ .../PostProcessingResults/package.include | 0 .../NumericalTests/Utilities/Test/Test.h | 3 +- .../NumericalTests/Utilities/Test/TestImp.cpp | 8 +- .../NumericalTests/Utilities/Test/TestImp.h | 4 +- .../TestSimulation/TestSimulationImp.cpp | 9 +- .../TestSimulation/TestSimulationImp.h | 4 +- targets/tests/NumericalTests/config.txt | 10 +- targets/tests/NumericalTests/main.cpp | 2 - 27 files changed, 562 insertions(+), 226 deletions(-) create mode 100644 targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResults.h create mode 100644 targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.cpp create mode 100644 targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.h create mode 100644 targets/tests/NumericalTests/Utilities/PostProcessingResults/package.include diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp index 98f815d16..2dcefca65 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp +++ b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp @@ -1,15 +1,14 @@ #include "L2NormTest.h" #include "Utilities/ColorConsoleOutput/ColorConsoleOutput.h" -#include "Utilities\Calculator\L2NormCalculator\L2NormCalculator.h" -#include "Utilities\Results\AnalyticalResults\AnalyticalResult.h" +#include "Utilities\PostProcessingResults\PostProcessingResults.h" #include "Utilities\Results\SimulationResults\SimulationResults.h" #include <iomanip> -std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep) +std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr< PostProcessingResults> postProResults, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep) { - return std::shared_ptr<L2NormTest>(new L2NormTest(analyticalResult, colorOutput, dataToCalculate, maxL2NormDiff, basicTimeStep, divergentTimeStep)); + return std::shared_ptr<L2NormTest>(new L2NormTest(postProResults, colorOutput, dataToCalculate, maxL2NormDiff, basicTimeStep, divergentTimeStep)); } void L2NormTest::update() @@ -17,21 +16,28 @@ void L2NormTest::update() TestImp::update(); } -void L2NormTest::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo) +void L2NormTest::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResults) { - TestImp::addSimulation(sim, simInfo); + TestImp::addSimulation(sim, simInfo, postProResults); } void L2NormTest::evaluate() { - analyticalResult->calc(simResults.at(0)); - - int basicTimeStepInResults = calcTimeStepInResults(basicTimeStep); - int divergentTimeStepInResults = calcTimeStepInResults(divergentTimeStep); - - resultBasicTimestep = calcL2NormForTimeStep(basicTimeStepInResults); - resultDivergentTimeStep = calcL2NormForTimeStep(divergentTimeStepInResults); + std::vector<double> results; + if (dataToCalculate == "Vx") + results = postProResults->getL2NormVx(); + if (dataToCalculate == "Vy") + results = postProResults->getL2NormVy(); + if (dataToCalculate == "Vz") + results = postProResults->getL2NormVz(); + if (dataToCalculate == "Press") + results = postProResults->getL2NormPress(); + if (dataToCalculate == "Rho") + results = postProResults->getL2NormRho(); + + resultBasicTimestep = results.at(0); + resultDivergentTimeStep = results.at(1); diffL2Norm = resultDivergentTimeStep - resultBasicTimestep; testPassed = maxL2NormDiff > diffL2Norm; @@ -42,9 +48,9 @@ void L2NormTest::evaluate() std::string L2NormTest::getLogFileOutput() { std::ostringstream oss; - oss << "L2Norm_BasicTimeStep_L" << simResults.at(0)->getNumberOfXNodes() << ":" << resultBasicTimestep << std::endl; - oss << "L2Norm_DivergentTimeStep_L" << simResults.at(0)->getNumberOfXNodes() << ":" << resultDivergentTimeStep << std::endl; - oss << "L2Norm_Diff_L" << simResults.at(0)->getNumberOfXNodes() << ":" << diffL2Norm << std::endl << std::endl; + oss << "L2Norm_BasicTimeStep_L" << postProResults->getNumberOfXNodes() << "=" << resultBasicTimestep << std::endl; + oss << "L2Norm_DivergentTimeStep_L" << postProResults->getNumberOfXNodes() << "=" << resultDivergentTimeStep << std::endl; + oss << "L2Norm_Diff_L" << postProResults->getNumberOfXNodes() << "=" << diffL2Norm << std::endl << std::endl; return oss.str(); } @@ -55,33 +61,11 @@ std::vector<bool> L2NormTest::getPassedTests() void L2NormTest::makeConsoleOutput() { - colorOutput->makeL2NormTestOutput(testPassed, simInfos.at(0), basicTimeStep, divergentTimeStep, resultBasicTimestep, resultDivergentTimeStep, diffL2Norm); -} - -int L2NormTest::calcTimeStepInResults(unsigned int timeStep) -{ - for (int i = 0; i < simResults.at(0)->getTimeSteps().size(); i++) { - if (timeStep == simResults.at(0)->getTimeSteps().at(i)) - return simResults.at(0)->getTimeSteps().at(i); - } -} - -double L2NormTest::calcL2NormForTimeStep(unsigned int timeStep) -{ - if (dataToCalculate == "Vx") - return calculator->calc(analyticalResult->getVx().at(timeStep), simResults.at(0)->getVx().at(timeStep), simResults.at(0)->getLevels().at(timeStep)); - if (dataToCalculate == "Vy") - return calculator->calc(analyticalResult->getVy().at(timeStep), simResults.at(0)->getVy().at(timeStep), simResults.at(0)->getLevels().at(timeStep)); - if (dataToCalculate == "Vz") - return calculator->calc(analyticalResult->getVz().at(timeStep), simResults.at(0)->getVz().at(timeStep), simResults.at(0)->getLevels().at(timeStep)); - if (dataToCalculate == "Press") - return calculator->calc(analyticalResult->getPress().at(timeStep), simResults.at(0)->getPress().at(timeStep), simResults.at(0)->getLevels().at(timeStep)); - if (dataToCalculate == "Rho") - return calculator->calc(analyticalResult->getRho().at(timeStep), simResults.at(0)->getRho().at(timeStep), simResults.at(0)->getLevels().at(timeStep)); - + colorOutput->makeL2NormTestOutput(testPassed, simInfos.at(0), basicTimeStep, divergentTimeStep, dataToCalculate, resultBasicTimestep, resultDivergentTimeStep, diffL2Norm); } -L2NormTest::L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep) : TestImp(colorOutput), analyticalResult(analyticalResult), basicTimeStep(basicTimeStep), divergentTimeStep(divergentTimeStep), dataToCalculate(dataToCalculate), maxL2NormDiff(maxL2NormDiff) +L2NormTest::L2NormTest(std::shared_ptr< PostProcessingResults> postProResults, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep) + : TestImp(colorOutput), basicTimeStep(basicTimeStep), divergentTimeStep(divergentTimeStep), dataToCalculate(dataToCalculate), maxL2NormDiff(maxL2NormDiff), postProResults(postProResults) { - calculator = L2NormCalculator::getNewInstance(); + } \ No newline at end of file diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h index 54aa4c7e0..adb657bd2 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h +++ b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h @@ -7,27 +7,24 @@ class L2NormCalculator; class AnalyticalResults; +class PostProcessingResults; class L2NormTest : public TestImp { public: - static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep); + static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr< PostProcessingResults> postProResults, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep); void update(); - void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo); + void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResults); void evaluate(); std::string getLogFileOutput(); std::vector< bool> getPassedTests(); void makeConsoleOutput(); - int calcTimeStepInResults(unsigned int timeStep); - double calcL2NormForTimeStep(unsigned int timeStep); - private: - L2NormTest(std::shared_ptr< AnalyticalResults> analyticalResult, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep); + L2NormTest(std::shared_ptr< PostProcessingResults> postProResults, std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double maxL2NormDiff, unsigned int basicTimeStep, unsigned int divergentTimeStep); - std::shared_ptr< L2NormCalculator> calculator; - std::shared_ptr< AnalyticalResults> analyticalResult; + std::shared_ptr< PostProcessingResults> postProResults; unsigned int basicTimeStep, divergentTimeStep; double resultBasicTimestep, resultDivergentTimeStep; std::string dataToCalculate; diff --git a/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.cpp b/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.cpp index 16f10f04e..6ba3f2657 100644 --- a/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.cpp +++ b/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.cpp @@ -1,8 +1,7 @@ #include "PhiAndNuTest.h" #include "Utilities/ColorConsoleOutput/ColorConsoleOutput.h" -#include "Utilities/Results/SimulationResults/SimulationResults.h" -#include "Utilities\Calculator\FFTCalculator\FFTCalculator.h" +#include "Utilities\PostProcessingResults\PostProcessingResults.h" #include "Utilities\TestSimulation\TestSimulation.h" #include "Utilities\SimulationInfo\SimulationInfo.h" @@ -15,17 +14,22 @@ std::shared_ptr<PhiAndNuTest> PhiAndNuTest::getNewInstance(std::shared_ptr< Colo void PhiAndNuTest::evaluate() { - for (int i = 0; i < simResults.size(); i++) { - lx.push_back(simResults.at(i)->getNumberOfXNodes()); - calculator->setSimulationResults(simResults.at(i)); - if (dataToCalculate == "Vx") - calculator->setVectorToCalc(simResults.at(i)->getVx()); - if (dataToCalculate == "Vz") - calculator->setVectorToCalc(simResults.at(i)->getVz()); - calculator->calc(startStepCalculation, endStepCalculation); - phiDiff.push_back(calculator->getPhiDiff()); - nuDiff.push_back(calculator->getNuDiff()); + for (int i = 0; i < postProResults.size(); i++) { + lx.push_back(postProResults.at(i)->getNumberOfXNodes()); + if (dataToCalculate == "Vx") { + nu.push_back(postProResults.at(i)->getNuVx()); + phiDiff.push_back(postProResults.at(i)->getPhiDiffVx()); + } + if (dataToCalculate == "Vy") { + nu.push_back(postProResults.at(i)->getNuVy()); + phiDiff.push_back(postProResults.at(i)->getPhiDiffVy()); + } + if (dataToCalculate == "Vz") { + nu.push_back(postProResults.at(i)->getNuVz()); + phiDiff.push_back(postProResults.at(i)->getPhiDiffVz()); + } } + nuDiff = calcNuDiff(nu); orderOfAccuracyPhiDiff = calcOrderOfAccuracy(phiDiff); orderOfAccuracyNuDiff = calcOrderOfAccuracy(nuDiff); phiDiffTestPassed = checkTestPassed(orderOfAccuracyPhiDiff); @@ -39,9 +43,9 @@ void PhiAndNuTest::update() TestImp::update(); } -void PhiAndNuTest::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo) +void PhiAndNuTest::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResults) { - TestImp::addSimulation(sim, simInfo); + TestImp::addSimulation(sim, simInfo, postProResults); } std::vector<bool> PhiAndNuTest::getPassedTests() @@ -54,16 +58,23 @@ std::vector<bool> PhiAndNuTest::getPassedTests() void PhiAndNuTest::makeConsoleOutput() { - colorOutput->makePhiAndNuTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), startStepCalculation, endStepCalculation, "NuDiff", "NuDiff", "OrderOfAccuracy", nuDiff.at(0), nuDiff.at(1), orderOfAccuracyNuDiff); - colorOutput->makePhiAndNuTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), startStepCalculation, endStepCalculation, "PhiDiff", "PhiDiff", "OrderOfAccuracy", phiDiff.at(0), phiDiff.at(1), orderOfAccuracyPhiDiff); + colorOutput->makeNuTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), startStepCalculation, endStepCalculation, dataToCalculate, nu.at(0), nu.at(1), nuDiff.at(0), nuDiff.at(1), orderOfAccuracyNuDiff); + colorOutput->makePhiTestOutput(nuDiffTestPassed, simInfos.at(0), simInfos.at(1), startStepCalculation, endStepCalculation, dataToCalculate, phiDiff.at(0), phiDiff.at(1), orderOfAccuracyPhiDiff); } std::string PhiAndNuTest::getLogFileOutput() { std::ostringstream oss; - oss << std::setfill(' ') << std::left << std::setw(4) << lx.at(0) << std::setw(45) << nuDiff.at(0) << phiDiff.at(0) << std::endl; - oss << std::setfill(' ') << std::left << std::setw(19) << " " << std::setw(45) << orderOfAccuracyNuDiff << orderOfAccuracyPhiDiff << std::endl; - oss << std::setfill(' ') << std::left << std::setw(4) << lx.at(1) << std::setw(45) << nuDiff.at(1) << phiDiff.at(1) << std::endl; + + oss << "Nu_" << lx.at(0) << "=" << nu.at(0) << std::endl; + oss << "NuDiff_" << lx.at(0) << "=" << nuDiff.at(0) << std::endl; + oss << "Nu_" << lx.at(1) << "=" << nu.at(1) << std::endl; + oss << "NuDiff_" << lx.at(1) << "=" << nuDiff.at(1) << std::endl; + oss << "OrderOfAccuracy_NuDiff_" << lx.at(0) << lx.at(1) << "=" << orderOfAccuracyNuDiff << std::endl << std::endl; + + oss << "PhiDiff_" << lx.at(0) << "=" << phiDiff.at(0) << std::endl; + oss << "PhiDiff_" << lx.at(1) << "=" << phiDiff.at(1) << std::endl; + oss << "OrderOfAccuracy_NuDiff_" << lx.at(0) << lx.at(1) << "=" << orderOfAccuracyPhiDiff << std::endl << std::endl; return oss.str(); } @@ -73,7 +84,6 @@ PhiAndNuTest::PhiAndNuTest(std::shared_ptr< ColorConsoleOutput> colorOutput, std lx.resize(0); phiDiff.resize(0); nuDiff.resize(0); - calculator = FFTCalculator::getNewInstance(viscosity); } double PhiAndNuTest::calcOrderOfAccuracy(std::vector<double> data) @@ -86,4 +96,12 @@ double PhiAndNuTest::calcOrderOfAccuracy(std::vector<double> data) bool PhiAndNuTest::checkTestPassed(double orderOfAccuracy) { return orderOfAccuracy > minOrderOfAccuracy; -} \ No newline at end of file +} + +std::vector<double> PhiAndNuTest::calcNuDiff(std::vector<double> nu) +{ + std::vector< double> results; + for(int i = 0; i < nu.size(); i++) + results.push_back((nu.at(i) - viscosity) / viscosity); + return results; +} diff --git a/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.h b/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.h index b997c83b6..ee465debd 100644 --- a/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.h +++ b/targets/tests/NumericalTests/Tests/PhiAndNuTest/PhiAndNuTest.h @@ -15,7 +15,7 @@ public: static std::shared_ptr<PhiAndNuTest> getNewInstance(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity, unsigned int startStepCalculation, unsigned int endStepCalculation); void update(); - void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo); + void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResults); void evaluate(); std::string getLogFileOutput(); std::vector< bool> getPassedTests(); @@ -25,12 +25,12 @@ private: PhiAndNuTest(std::shared_ptr< ColorConsoleOutput> colorOutput, std::string dataToCalculate, double minOrderOfAccuracy, double viscosity, unsigned int startStepCalculation, unsigned int endStepCalculation); double calcOrderOfAccuracy(std::vector<double> data); bool checkTestPassed(double orderOfAccuracy); - - std::shared_ptr< FFTCalculator> calculator; + std::vector< double> calcNuDiff(std::vector< double> nu); + unsigned int startStepCalculation, endStepCalculation; std::vector<double> lx; std::vector<double> phiDiff; - std::vector<double> nuDiff; + std::vector<double> nu, nuDiff; double orderOfAccuracyPhiDiff; double orderOfAccuracyNuDiff; double minOrderOfAccuracy; @@ -38,5 +38,7 @@ private: bool phiDiffTestPassed; bool nuDiffTestPassed; std::string dataToCalculate; + + }; #endif diff --git a/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.cpp b/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.cpp index 7e559955f..bae5ff01f 100644 --- a/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.cpp +++ b/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.cpp @@ -7,72 +7,46 @@ #include <math.h> #include <stdlib.h> -void FFTCalculator::calc(unsigned int startStep, unsigned int endStep) +std::shared_ptr<FFTCalculator> FFTCalculator::getNewInstance(int lx, int lz, int timeStepLength) { - init(); - - nu = calcNu(startStep, endStep); - nudiff = calcNuDiff(nu); - phidiff = calcPhiDiff(startStep, endStep); -} - -double FFTCalculator::getNuDiff() -{ - return nudiff; -} - -double FFTCalculator::getPhiDiff() -{ - return phidiff; + return std::shared_ptr<FFTCalculator>(new FFTCalculator(lx, lz, timeStepLength)); } -std::shared_ptr<FFTCalculator> FFTCalculator::getNewInstance(double viscosity) +FFTCalculator::FFTCalculator(int lx, int lz, int timeStepLength) { - return std::shared_ptr<FFTCalculator>(new FFTCalculator(viscosity)); + this->lx = (double)lx; + this->lz = (double)lz; + this->timeStepLength = (double)timeStepLength; } -void FFTCalculator::setSimulationResults(std::shared_ptr<SimulationResults> simResults) -{ - this->simResults = simResults; -} - -void FFTCalculator::setVectorToCalc(std::vector<std::vector<double>> data) +void FFTCalculator::calc(std::vector<std::vector<double>> data) { this->data = data; + init(); + + nu = calcNu(); + phidiff = calcPhiDiff(); } void FFTCalculator::init() { fftResultsIm.clear(); fftResultsRe.clear(); - lz = (double)simResults->getNumberOfZNodes(); - lx = (double)simResults->getNumberOfXNodes(); - timeStepLength = simResults->getTimeStepLength(); fftCalculated = false; } -FFTCalculator::FFTCalculator(double viscosity) : vis(viscosity) -{ -} - -double FFTCalculator::calcNu(unsigned int startStep, unsigned int endStep) +double FFTCalculator::calcNu() { - std::vector<double> logAmplitude = calcLogAmplitudeForTimeSteps(startStep, endStep); + std::vector<double> logAmplitude = calcLogAmplitudeForAllSteps(); std::vector<double> linReg = calcLinReg(logAmplitude); double nu = -(1.0 / (((2.0 * M_PI / lz) * (2.0 * M_PI / lz) + (2.0 * M_PI / lx)*(2.0 * M_PI / lx)) * timeStepLength)) * linReg.at(0); return nu; } -double FFTCalculator::calcNuDiff(double nu) -{ - double nudiff = abs((nu - vis) / vis); - return nudiff; -} - -double FFTCalculator::calcPhiDiff(unsigned int startStep, unsigned int endStep) +double FFTCalculator::calcPhiDiff() { - std::vector<double> phi = calcPhiForTimeSteps(startStep, endStep); + std::vector<double> phi = calcPhiForAllSteps(); std::vector<double> linReg = calcLinReg(phi); return linReg.at(0); @@ -117,9 +91,9 @@ std::vector<double> FFTCalculator::calcLinReg(std::vector<double> y) return result; } -std::vector<double> FFTCalculator::calcLogAmplitudeForTimeSteps(unsigned int startStep, unsigned int endStep) +std::vector<double> FFTCalculator::calcLogAmplitudeForAllSteps() { - std::vector<double> amplitude = calcAmplitudeForTimeSteps(startStep, endStep); + std::vector<double> amplitude = calcAmplitudeForAllSteps(); std::vector<double> logAmplitude; for (int i = 0; i < amplitude.size(); i++) logAmplitude.push_back(log(amplitude.at(i))); @@ -127,34 +101,32 @@ std::vector<double> FFTCalculator::calcLogAmplitudeForTimeSteps(unsigned int sta return logAmplitude; } -std::vector<double> FFTCalculator::calcAmplitudeForTimeSteps(unsigned int startStep, unsigned int endStep) +std::vector<double> FFTCalculator::calcAmplitudeForAllSteps() { std::vector<double> amplitude; if (fftCalculated == false) { - for (int timeStep = startStep; timeStep <= endStep; timeStep++) - calcFFT2D(timeStep); + for (int step = 0; step < data.size(); step++) + calcFFT2D(step); fftCalculated = true; } int pos = 2 + (lx - 1); - numberOfTimeSteps = endStep - startStep; - for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) - amplitude.push_back(4.0 / (lx * lz) * sqrt(fftResultsRe.at(timeStep).at(pos) * fftResultsRe.at(timeStep).at(pos) + fftResultsIm.at(timeStep).at(pos) * fftResultsIm.at(timeStep).at(pos))); + for (int step = 0; step < data.size(); step++) + amplitude.push_back(4.0 / (lx * lz) * sqrt(fftResultsRe.at(step).at(pos) * fftResultsRe.at(step).at(pos) + fftResultsIm.at(step).at(pos) * fftResultsIm.at(step).at(pos))); return amplitude; } -std::vector<double> FFTCalculator::calcPhiForTimeSteps(unsigned int startStep, unsigned int endStep) +std::vector<double> FFTCalculator::calcPhiForAllSteps() { std::vector<double> phi; if (fftCalculated == false) { - for (int timeStep = startStep; timeStep <= endStep; timeStep++) - calcFFT2D(timeStep); + for (int step = 0; step < data.size(); step++) + calcFFT2D(step); fftCalculated = true; } int pos = 2 + (lx - 1); - numberOfTimeSteps = endStep - startStep; - for (int timeStep = 0; timeStep < numberOfTimeSteps; timeStep++) - phi.push_back(atan(fftResultsIm.at(timeStep).at(pos) / fftResultsRe.at(timeStep).at(pos))); + for (int step = 0; step < data.size(); step++) + phi.push_back(atan(fftResultsIm.at(step).at(pos) / fftResultsRe.at(step).at(pos))); return phi; } @@ -175,24 +147,23 @@ void FFTCalculator::calcFFT2D(unsigned int timeStep) fftw_free(out); } -void FFTCalculator::initDataForFFT(fftw_complex * input, unsigned int timeStep) +void FFTCalculator::initDataForFFT(fftw_complex * input, unsigned int step) { - int timeStepInResult = calcTimeStepInResults(timeStep); - for (int i = 0; i < data.at(timeStepInResult).size(); i++) + for (int i = 0; i < data.at(step).size(); i++) { - input[i][0] = data.at(timeStepInResult).at(i); + input[i][0] = data.at(step).at(i); input[i][1] = 0; } } -void FFTCalculator::setFFTResults(fftw_complex * result, unsigned int timeStep) +void FFTCalculator::setFFTResults(fftw_complex * result, unsigned int step) { std::vector<double> fftRe, fftIm; - fftRe.resize(data.at(timeStep).size()); - fftIm.resize(data.at(timeStep).size()); + fftRe.resize(data.at(step).size()); + fftIm.resize(data.at(step).size()); - for (int i = 0; i < data.at(timeStep).size(); i++) + for (int i = 0; i < data.at(step).size(); i++) { fftRe.at(i) = result[i][0]; fftIm.at(i) = result[i][1]; @@ -201,10 +172,12 @@ void FFTCalculator::setFFTResults(fftw_complex * result, unsigned int timeStep) fftResultsRe.push_back(fftRe); } -int FFTCalculator::calcTimeStepInResults(unsigned int timeStep) +double FFTCalculator::getNu() { - for (int i = 0; i < simResults->getTimeSteps().size(); i++) { - if (timeStep == simResults->getTimeSteps().at(i)) - return simResults->getTimeSteps().at(i); - } + return nu; +} + +double FFTCalculator::getPhiDiff() +{ + return phidiff; } diff --git a/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.h b/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.h index 9dd97cbcd..ac584517f 100644 --- a/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.h +++ b/targets/tests/NumericalTests/Utilities/Calculator/FFTCalculator/FFTCalculator.h @@ -13,41 +13,35 @@ class PhiAndNuTest; class FFTCalculator { public: - static std::shared_ptr<FFTCalculator> getNewInstance(double viscosity); - void setSimulationResults(std::shared_ptr<SimulationResults> simResults); - void setVectorToCalc(std::vector<std::vector<double>> data); + static std::shared_ptr<FFTCalculator> getNewInstance(int lx, int lz, int timeStepLength); - void calc(unsigned int startStep, unsigned int endStep); + void calc(std::vector<std::vector<double>> data); - double getNuDiff(); + double getNu(); double getPhiDiff(); private: - FFTCalculator(double viscosity); + FFTCalculator() {}; + FFTCalculator(int lx, int lz, int timeStepLength); void init(); - double calcNu(unsigned int startStep, unsigned int endStep); - double calcNuDiff(double nu); - double calcPhiDiff(unsigned int startStep, unsigned int endStep); - std::vector< double> calcPhiForTimeSteps(unsigned int startStep, unsigned int endStep); + double calcNu(); + double calcPhiDiff(); + std::vector< double> calcPhiForAllSteps(); std::vector< double> calcLinReg(std::vector<double> y); - std::vector<double> calcLogAmplitudeForTimeSteps(unsigned int startStep, unsigned int endStep); - std::vector<double> calcAmplitudeForTimeSteps(unsigned int startStep, unsigned int endStep); - void calcFFT2D(unsigned int timeStep); - void initDataForFFT(fftw_complex* input, unsigned int timeStep); - void setFFTResults(fftw_complex* result, unsigned int timeStep); - int calcTimeStepInResults(unsigned int timeStep); + std::vector<double> calcLogAmplitudeForAllSteps(); + std::vector<double> calcAmplitudeForAllSteps(); + void calcFFT2D(unsigned int step); + void initDataForFFT(fftw_complex* input, unsigned int step); + void setFFTResults(fftw_complex* result, unsigned int step); - std::shared_ptr<SimulationResults> simResults; std::vector<std::vector<double>> data; std::vector<std::vector<double>> fftResultsIm; std::vector<std::vector<double>> fftResultsRe; bool fftCalculated; double lx, lz; - double vis; double timeStepLength; - int numberOfTimeSteps; double nu; - double nudiff, phidiff; + double phidiff; }; #endif diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp index 3e80e7ef5..211971987 100644 --- a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp @@ -10,14 +10,15 @@ std::shared_ptr<L2NormCalculator> L2NormCalculator::getNewInstance() double L2NormCalculator::calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level) { - double zaehler = 0; - double nenner = 0; + double zaehler = 0.0; + double nenner = 0.0; for (int i = 0; i < basicData.size(); i++) { double flaeche = (1 / pow(2.0, level.at(i))) * (1 / pow(2.0, level.at(i))); zaehler += ((divergentData.at(i) - basicData.at(i))*(divergentData.at(i) - basicData.at(i))) * flaeche; nenner += (basicData.at(i)*basicData.at(i)) * flaeche; } - + if (nenner == 0.0) + return sqrt(zaehler); return sqrt(zaehler / nenner); } diff --git a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h index d669947a7..84fe65a36 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h @@ -9,8 +9,9 @@ class SimulationInfo; class ColorConsoleOutput { public: - virtual void makePhiAndNuTestOutput(bool testPassed, std::shared_ptr< SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3) = 0; - virtual void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, double testWert1, double testWert2, double testWert3) = 0; + virtual void makeNuTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double nu1, double nu2, double nuDiff1, double nuDiff2, double ooa) = 0; + virtual void makePhiTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double phiDiff1, double phiDiff2, double ooa) = 0; + virtual void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3) = 0; 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; diff --git a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp index decf403ce..e9c0b4f08 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp @@ -14,13 +14,13 @@ std::shared_ptr<ColorConsoleOutput> ColorConsoleOutputImp::getInstance() return uniqueInstance; } -void ColorConsoleOutputImp::makePhiAndNuTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3) +void ColorConsoleOutputImp::makeNuTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double nu1, double nu2, double nuDiff1, double nuDiff2, double ooa) { setColor(testPassed); printTestStart(); printColor(""); - printColor("Phi and Nu Test"); + printColor("Nu Test"); printColor(""); std::ostringstream oss; @@ -37,15 +37,19 @@ void ColorConsoleOutputImp::makePhiAndNuTestOutput(bool testPassed, std::shared_ print(oss.str()); oss.str(std::string()); - oss << "L: " << simInfo1->getLx() << simInfo1->getSimulationParameterString(); + oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfo1->getLx() << simInfo1->getSimulationParameterString(); print(oss.str()); oss.str(std::string()); - oss << "L: " << simInfo2->getLx() << simInfo2->getSimulationParameterString(); + oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfo2->getLx() << simInfo2->getSimulationParameterString(); print(oss.str()); oss.str(std::string()); print(oss.str()); + oss << "DataToCalculate: " << dataToCalc; + print(oss.str()); + oss.str(std::string()); + oss << "StartTimeStep: " << startTimeStep; print(oss.str()); oss.str(std::string()); @@ -55,22 +59,92 @@ void ColorConsoleOutputImp::makePhiAndNuTestOutput(bool testPassed, std::shared_ oss.str(std::string()); print(oss.str()); - oss << nameWerte1 << ": " << testWert1 << std::setw(5) << "\t" << nameWerte2 << ": " << testWert2; + oss << "Nu" << simInfo1->getLx() << ": " << nu1; + print(oss.str()); + oss.str(std::string()); + oss << "Nu" << simInfo2->getLx() << ": " << nu2; + print(oss.str()); + oss.str(std::string()); + oss << "NuDiff" << simInfo1->getLx() << ": " << nuDiff1; + print(oss.str()); + oss.str(std::string()); + oss << "NuDiff" << simInfo2->getLx() << ": " << nuDiff2; + print(oss.str()); + oss.str(std::string()); + oss << "OrderOfAccuracy: " << ooa; + print(oss.str()); + oss.str(std::string()); + + printColor(""); + printColor("Nu Test"); + printColor(""); + + printTestEnd(testPassed); +} + +void ColorConsoleOutputImp::makePhiTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double phiDiff1, double phiDiff2, double ooa) +{ + setColor(testPassed); + printTestStart(); + + printColor(""); + printColor("Phi Test"); + printColor(""); + + std::ostringstream oss; + oss << "Kernel: " << simInfo1->getKernelName(); print(oss.str()); oss.str(std::string()); - oss << nameWerte3 << ": " << testWert3; + oss << "Viscosity: " << simInfo1->getViscosity(); + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << simInfo1->getSimulationName(); + print(oss.str()); + oss.str(std::string()); + + oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfo1->getLx() << simInfo1->getSimulationParameterString(); + print(oss.str()); + oss.str(std::string()); + + oss << "L: " << std::setfill(' ') << std::right << std::setw(4) << simInfo2->getLx() << simInfo2->getSimulationParameterString(); + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << "DataToCalculate: " << dataToCalc; + print(oss.str()); + oss.str(std::string()); + + oss << "StartTimeStep: " << startTimeStep; + print(oss.str()); + oss.str(std::string()); + + oss << "EndTimeStep: " << endTimeStep; + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << "PhiDiff" << simInfo1->getLx() << ": " << phiDiff1; + print(oss.str()); + oss.str(std::string()); + oss << "PhiDiff" << simInfo2->getLx() << ": " << phiDiff2; + print(oss.str()); + oss.str(std::string()); + oss << "OrderOfAccuracy: " << ooa; print(oss.str()); oss.str(std::string()); printColor(""); - printColor("Phi and Nu Test"); + printColor("Phi Test"); printColor(""); printTestEnd(testPassed); } -void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, double testWert1, double testWert2, double testWert3) +void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3) { setColor(testPassed); printTestStart(); @@ -98,6 +172,9 @@ void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_pt oss.str(std::string()); print(oss.str()); + oss << "DataToCalculate: " << dataToCalc; + print(oss.str()); + oss.str(std::string()); oss << "BasicTimeStep: " << basicTimeStep; print(oss.str()); oss.str(std::string()); diff --git a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h index f315c7dbe..dd3ca9638 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h @@ -33,8 +33,9 @@ class ColorConsoleOutputImp : public ColorConsoleOutput public: static std::shared_ptr<ColorConsoleOutput> getInstance(); - void makePhiAndNuTestOutput(bool testPassed, std::shared_ptr< SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string nameWerte1, std::string nameWerte2, std::string nameWerte3, double testWert1, double testWert2, double testWert3); - void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, double testWert1, double testWert2, double testWert3); + void makeNuTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double nu1, double nu2, double nuDiff1, double nuDiff2, double ooa); + void makePhiTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo1, std::shared_ptr<SimulationInfo> simInfo2, unsigned int startTimeStep, unsigned int endTimeStep, std::string dataToCalc, double phiDiff1, double phiDiff2, double ooa); + void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3); void makeSimulationHeadOutput(std::shared_ptr< SimulationInfo> simInfo); void makeFinalTestOutputHead(int numberOfPassedTests, int numberOfTests); void makeFinalTestOutputFoot(int numberOfPassedTests, int numberOfTests); diff --git a/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigData.h b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigData.h index 1c24b43e7..70915fffc 100644 --- a/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigData.h +++ b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigData.h @@ -19,14 +19,14 @@ struct ConfigDataStruct unsigned int ySliceForCalculation; double minOrderOfAccuracy; - std::string dataToCalcPhiAndNuTest; + std::vector<std::string> dataToCalcPhiAndNuTest; unsigned int startTimeStepCalculationPhiNu; unsigned int endTimeStepCalculationPhiNu; bool nuAndPhiTestTGV; bool nuAndPhiTestSW; double maxL2NormDiff; - std::string dataToCalcL2Test; + std::vector<std::string> dataToCalcL2Test; unsigned int basicTimeStepL2Norm; unsigned int divergentTimeStepL2Norm; bool l2NormTestTGV; diff --git a/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp index f8a374ac0..d09cd4ec7 100644 --- a/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp +++ b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp @@ -48,11 +48,11 @@ void ConfigFileReader::readConfigFile(const std::string aFilePath) configData->kernelsToTest = StringUtil::toStringVector(input->getValue("KernelsToTest")); configData->viscosity = StringUtil::toDoubleVector(input->getValue("Viscosity")); configData->minOrderOfAccuracy = StringUtil::toDouble(input->getValue("MinOrderOfAccuracy")); - configData->dataToCalcPhiAndNuTest = StringUtil::toString(input->getValue("DataToCalc_PhiAndNu")); + configData->dataToCalcPhiAndNuTest = StringUtil::toStringVector(input->getValue("DataToCalc_PhiAndNu")); configData->startTimeStepCalculationPhiNu = StringUtil::toInt(input->getValue("StartTimeStepCalculation_PhiNu")); configData->endTimeStepCalculationPhiNu = StringUtil::toInt(input->getValue("EndTimeStepCalculation_PhiNu")); configData->maxL2NormDiff = StringUtil::toDouble(input->getValue("MaxL2NormDiff")); - configData->dataToCalcL2Test = StringUtil::toString(input->getValue("DataToCalc_L2")); + configData->dataToCalcL2Test = StringUtil::toStringVector(input->getValue("DataToCalc_L2")); configData->basicTimeStepL2Norm = StringUtil::toInt(input->getValue("BasicTimeStep_L2")); configData->divergentTimeStepL2Norm = StringUtil::toInt(input->getValue("DivergentTimeStep_L2")); configData->amplitudeTGV = StringUtil::toDoubleVector(input->getValue("Amplitude_TGV")); diff --git a/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp b/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp index 3a10d7833..fc5df8973 100644 --- a/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp +++ b/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.cpp @@ -4,6 +4,11 @@ #include "Utilities/Results/SimulationResults/SimulationResults.h" +std::shared_ptr<Y2dSliceToResults> Y2dSliceToResults::getNewInstance(std::shared_ptr<SimulationResults> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter) +{ + return std::shared_ptr<Y2dSliceToResults>(new Y2dSliceToResults(simResults, ySliceForCalculation, startTimeY2dSliceToVector, endTime, timeStepLength, writeFiles, fileWriter, startTimeDataWriter)); +} + Y2dSliceToResults::Y2dSliceToResults(std::shared_ptr<SimulationResults> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter): ToVectorWriter(ySliceForCalculation, startTimeY2dSliceToVector, endTime, timeStepLength, writeFiles, fileWriter, startTimeDataWriter) { this->simResults = simResults; diff --git a/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h b/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h index c71077bf4..b85333421 100644 --- a/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h +++ b/targets/tests/NumericalTests/Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h @@ -11,9 +11,10 @@ class Parameter; class Y2dSliceToResults : public ToVectorWriter { public: - Y2dSliceToResults(std::shared_ptr<SimulationResults> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter); + static std::shared_ptr< Y2dSliceToResults> getNewInstance(std::shared_ptr<SimulationResults> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter); private: + Y2dSliceToResults(std::shared_ptr<SimulationResults> simResults, unsigned int ySliceForCalculation, unsigned int startTimeY2dSliceToVector, unsigned int endTime, unsigned int timeStepLength, bool writeFiles, std::shared_ptr<FileWriter> fileWriter, unsigned int startTimeDataWriter); void writeTimestep(std::shared_ptr<Parameter> para, unsigned int t, int level); std::shared_ptr<SimulationResults> simResults; diff --git a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp index dedd08461..72546151a 100644 --- a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp +++ b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp @@ -19,6 +19,8 @@ #include "Utilities\LogFileInformation\LogFileTimeInformation\LogFileTimeInformation.h" #include "Utilities\LogFileWriter\LogFileWriterImp.h" #include "Utilities\LogFileQueue\LogFileQueueImp.h" +#include "Utilities\PostProcessingResults\PostProcessingResultsImp.h" +#include "Utilities\Results\SimulationResults\SimulationResults.h" #include "Utilities\TestQueue\TestQueueImp.h" #include "Utilities/TestSimulation/TestSimulationImp.h" @@ -109,18 +111,26 @@ void NumericalTestFactoryImp::makeShearWaveSimulations(std::string kernelName, d void NumericalTestFactoryImp::makePeriodicBoundaryConditionSimulationAndTests(std::vector<std::shared_ptr<SimulationParameter>> simPara, std::vector<std::shared_ptr<SimulationInfo>> simInfo, std::vector<std::shared_ptr<AnalyticalResults>> analyResult, std::shared_ptr<SimulationLogFileInformation> simlogFileInfo, std::string kernelName, std::vector<bool> simulationsRun, double viscosity, bool nuAndPhiTest, bool l2NormTest) { - std::vector< std::shared_ptr< TestSimulation>> testSim = buildTestSimulation(simPara, simInfo); + std::vector< std::shared_ptr< SimulationResults>> simResults; + std::vector< std::shared_ptr< PostProcessingResults>> postProResults; + for (int i = 0; i < simPara.size(); i++) { + std::shared_ptr< SimulationResults> simResult = SimulationResults::getNewInstance(simPara.at(i)->getLx(), 1, simPara.at(i)->getLz(), simPara.at(i)->getTimeStepLength()); + simResults.push_back(simResult); + postProResults.push_back(PostProcessingResultsImp::getNewInstance(simResult, analyResult.at(i), cfd->dataToCalcPhiAndNuTest, cfd->dataToCalcL2Test, cfd->startTimeStepCalculationPhiNu, cfd->endTimeStepCalculationPhiNu, cfd->basicTimeStepL2Norm, cfd->divergentTimeStepL2Norm)); + } + + std::vector< std::shared_ptr< TestSimulation>> testSim = buildTestSimulation(simPara, simInfo, simResults); std::vector< std::shared_ptr< TestLogFileInformation>> testLogFileInfo; if (nuAndPhiTest && checkNuAndPhiTestCouldRun(simulationsRun)) { - std::vector< std::shared_ptr< PhiAndNuTest>> phiAndNuTests = makePhiAndNuTests(testSim, simInfo, viscosity); + std::vector< std::shared_ptr< PhiAndNuTest>> phiAndNuTests = makePhiAndNuTests(testSim, simInfo, postProResults, viscosity); std::shared_ptr< PhiAndNuInformation> phiNuLogFileInfo = PhiAndNuInformation::getNewInstance(phiAndNuTests, cfd->startTimeStepCalculationPhiNu, cfd->endTimeStepCalculationPhiNu); testLogFileInfo.push_back(phiNuLogFileInfo); } if (l2NormTest) { - std::vector< std::shared_ptr< L2NormTest>> l2NormTests = makeL2NormTests(testSim, simInfo, analyResult); + std::vector< std::shared_ptr< L2NormTest>> l2NormTests = makeL2NormTests(testSim, simInfo, postProResults); std::shared_ptr< L2NormInformation> l2NormLogFileInfo = L2NormInformation::getNewInstance(l2NormTests, cfd->basicTimeStepL2Norm, cfd->divergentTimeStepL2Norm); testLogFileInfo.push_back(l2NormLogFileInfo); } @@ -133,47 +143,52 @@ void NumericalTestFactoryImp::makePeriodicBoundaryConditionSimulationAndTests(st makeLogFileWriter(testLogFileInfo, logFileTimeInfo, simlogFileInfo, kernelName, viscosity); } -std::vector<std::shared_ptr<TestSimulation>> NumericalTestFactoryImp::buildTestSimulation(std::vector<std::shared_ptr<SimulationParameter>> simPara, std::vector<std::shared_ptr<SimulationInfo>> simInfo) +std::vector<std::shared_ptr<TestSimulation>> NumericalTestFactoryImp::buildTestSimulation(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector< std::shared_ptr< SimulationResults>> simResults) { std::vector< std::shared_ptr< TestSimulation>> testSim; testSim.resize(0); for (int i = 0; i < simPara.size(); i++) { - testSim.push_back(TestSimulationImp::getNewInsance(simID, simPara.at(i), simInfo.at(i), colorOutput)); + testSim.push_back(TestSimulationImp::getNewInsance(simID, simPara.at(i), simInfo.at(i), colorOutput, simResults.at(i))); simID++; } return testSim; } -std::vector<std::shared_ptr<PhiAndNuTest>> NumericalTestFactoryImp::makePhiAndNuTests(std::vector<std::shared_ptr<TestSimulation>> testSim, std::vector<std::shared_ptr<SimulationInfo>> simInfo, double viscosity) +std::vector<std::shared_ptr<PhiAndNuTest>> NumericalTestFactoryImp::makePhiAndNuTests(std::vector<std::shared_ptr<TestSimulation>> testSim, std::vector<std::shared_ptr<SimulationInfo>> simInfo, std::vector< std::shared_ptr< PostProcessingResults>> postProResults, double viscosity) { std::vector< std::shared_ptr< PhiAndNuTest>> phiAndNuTests; for (int i = 1; i < testSim.size(); i++) { for (int j = 0; j < i; j++) { - std::shared_ptr< PhiAndNuTest> test = PhiAndNuTest::getNewInstance(colorOutput, cfd->dataToCalcPhiAndNuTest, cfd->minOrderOfAccuracy, viscosity, cfd->startTimeStepCalculationPhiNu, cfd->endTimeStepCalculationPhiNu); - test->addSimulation(testSim.at(j), simInfo.at(j)); - test->addSimulation(testSim.at(i), simInfo.at(i)); + for (int k = 0; k < cfd->dataToCalcPhiAndNuTest.size(); k++) { + std::shared_ptr< PhiAndNuTest> test = PhiAndNuTest::getNewInstance(colorOutput, cfd->dataToCalcPhiAndNuTest.at(k), cfd->minOrderOfAccuracy, viscosity, cfd->startTimeStepCalculationPhiNu, cfd->endTimeStepCalculationPhiNu); + test->addSimulation(testSim.at(j), simInfo.at(j), postProResults.at(j)); + test->addSimulation(testSim.at(i), simInfo.at(i), postProResults.at(i)); - testSim.at(j)->registerSimulationObserver(test); - testSim.at(i)->registerSimulationObserver(test); + testSim.at(j)->registerSimulationObserver(test); + testSim.at(i)->registerSimulationObserver(test); - phiAndNuTests.push_back(test); - testQueue->addTest(test); + phiAndNuTests.push_back(test); + testQueue->addTest(test); + } } } return phiAndNuTests; } -std::vector<std::shared_ptr<L2NormTest>> NumericalTestFactoryImp::makeL2NormTests(std::vector<std::shared_ptr<TestSimulation>> testSim, std::vector<std::shared_ptr<SimulationInfo>> simInfo, std::vector<std::shared_ptr<AnalyticalResults>> analyticalResults) +std::vector<std::shared_ptr<L2NormTest>> NumericalTestFactoryImp::makeL2NormTests(std::vector<std::shared_ptr<TestSimulation>> testSim, std::vector<std::shared_ptr<SimulationInfo>> simInfo, std::vector< std::shared_ptr< PostProcessingResults>> postProResults) { 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), colorOutput, cfd->dataToCalcL2Test, cfd->maxL2NormDiff, cfd->basicTimeStepL2Norm, cfd->divergentTimeStepL2Norm); - test->addSimulation(testSim.at(i), simInfo.at(i)); - testSim.at(i)->registerSimulationObserver(test); - l2Tests.push_back(test); - testQueue->addTest(test); + for (int j = 0; j < cfd->dataToCalcL2Test.size(); j++) { + std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(postProResults.at(i), colorOutput, cfd->dataToCalcL2Test.at(j), cfd->maxL2NormDiff, cfd->basicTimeStepL2Norm, cfd->divergentTimeStepL2Norm); + test->addSimulation(testSim.at(i), simInfo.at(i), postProResults.at(i)); + testSim.at(i)->registerSimulationObserver(test); + l2Tests.push_back(test); + testQueue->addTest(test); + } + } return l2Tests; } diff --git a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h index a6d135036..63ee9ebd8 100644 --- a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h +++ b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h @@ -10,9 +10,11 @@ class L2NormTest; class LogFileTimeInformation; class LogFileQueueImp; class PhiAndNuTest; +class PostProcessingResults; class SimulationInfo; class SimulationLogFileInformation; class SimulationParameter; +class SimulationResults; class TestQueueImp; class TestLogFileInformation; @@ -33,9 +35,9 @@ private: void makeTaylorGreenSimulations(std::string kernelName, double viscosity, double u0, double amplitude); void makeShearWaveSimulations(std::string kernelName, double viscosity, double u0, double v0); void makePeriodicBoundaryConditionSimulationAndTests(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector< std::shared_ptr< AnalyticalResults>> analyResult, std::shared_ptr< SimulationLogFileInformation> simlogFileInfo, std::string kernelName, std::vector< bool> simulationsRun, double viscosity, bool nuAndPhiTest, bool l2NormTest); - std::vector< std::shared_ptr< TestSimulation>> buildTestSimulation(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo); - std::vector< std::shared_ptr< PhiAndNuTest>> makePhiAndNuTests(std::vector< std::shared_ptr< TestSimulation>> testSim, std::vector< std::shared_ptr< SimulationInfo>> simInfo, double viscosity); - std::vector< std::shared_ptr< L2NormTest>> makeL2NormTests(std::vector<std::shared_ptr< TestSimulation>> testSim, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector<std::shared_ptr< AnalyticalResults>> analyticalResults); + std::vector< std::shared_ptr< TestSimulation>> buildTestSimulation(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector< std::shared_ptr< SimulationResults>> simResults); + std::vector< std::shared_ptr< PhiAndNuTest>> makePhiAndNuTests(std::vector< std::shared_ptr< TestSimulation>> testSim, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector< std::shared_ptr< PostProcessingResults>> postProResults, double viscosity); + std::vector< std::shared_ptr< L2NormTest>> makeL2NormTests(std::vector<std::shared_ptr< TestSimulation>> testSim, std::vector< std::shared_ptr< SimulationInfo>> simInfo, std::vector< std::shared_ptr< PostProcessingResults>> postProResults); void makeLogFileWriter(std::vector< std::shared_ptr< TestLogFileInformation>> testLogFiles, std::shared_ptr< LogFileTimeInformation> logFileTimeInfo, std::shared_ptr< SimulationLogFileInformation> simLogInfo, std::string kernelName, double viscosity); bool shouldSimulationGroupRun(std::vector<bool> test); diff --git a/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResults.h b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResults.h new file mode 100644 index 000000000..581229b56 --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResults.h @@ -0,0 +1,32 @@ +#ifndef POST_PROCESSING_RESULTS_H +#define POST_PROCESSING_RESULTS_H + +#include <vector> + +class PostProcessingResults +{ +public: + virtual void evaluate() = 0; + + virtual double getNuVx() = 0; + virtual double getNuVy() = 0; + virtual double getNuVz() = 0; + virtual double getPhiDiffVx() = 0; + virtual double getPhiDiffVy() = 0; + virtual double getPhiDiffVz() = 0; + + virtual std::vector< double> getL2NormVx() = 0; + virtual std::vector< double> getL2NormVy() = 0; + virtual std::vector< double> getL2NormVz() = 0; + virtual std::vector< double> getL2NormPress() = 0; + virtual std::vector< double> getL2NormRho() = 0; + + virtual int getNumberOfXNodes() = 0; + virtual int getNumberOfYNodes() = 0; + virtual int getNumberOfZNodes() = 0; + +private: + + +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.cpp b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.cpp new file mode 100644 index 000000000..cb24aa8b6 --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.cpp @@ -0,0 +1,175 @@ +#include "PostProcessingResultsImp.h" + +#include "Utilities\Calculator\FFTCalculator\FFTCalculator.h" +#include "Utilities\Calculator\L2NormCalculator\L2NormCalculator.h" +#include "Utilities\Results\SimulationResults\SimulationResults.h" +#include "Utilities\Results\AnalyticalResults\AnalyticalResult.h" + +std::shared_ptr<PostProcessingResultsImp> PostProcessingResultsImp::getNewInstance(std::shared_ptr< SimulationResults> simResult, std::shared_ptr< AnalyticalResults> analyticalResult, std::vector<std::string> dataToCalculatePhiAndNu, std::vector<std::string> dataToCalculateL2, unsigned int startTimeStepCalculationPhiNu, unsigned int endTimeStepCalculationPhiNu, unsigned int basicTimeStepL2Norm, unsigned int divergentTimeStepL2Norm) +{ + return std::shared_ptr<PostProcessingResultsImp>(new PostProcessingResultsImp(simResult, analyticalResult, dataToCalculatePhiAndNu, dataToCalculateL2, startTimeStepCalculationPhiNu, endTimeStepCalculationPhiNu, basicTimeStepL2Norm, divergentTimeStepL2Norm)); +} + +PostProcessingResultsImp::PostProcessingResultsImp(std::shared_ptr< SimulationResults> simResult, std::shared_ptr< AnalyticalResults> analyticalResult, std::vector<std::string> dataToCalculatePhiAndNu, std::vector<std::string> dataToCalculateL2, unsigned int startTimeStepCalculationPhiNu, unsigned int endTimeStepCalculationPhiNu, unsigned int basicTimeStepL2Norm, unsigned int divergentTimeStepL2Norm) + : simResult(simResult), analyticalResult(analyticalResult), dataToCalculatePhiAndNu(dataToCalculatePhiAndNu), dataToCalculateL2(dataToCalculateL2), startTimeStepCalculationPhiNu(startTimeStepCalculationPhiNu), endTimeStepCalculationPhiNu(endTimeStepCalculationPhiNu), basicTimeStepL2Norm(basicTimeStepL2Norm), divergentTimeStepL2Norm(divergentTimeStepL2Norm) +{ + isEvaluated = false; + fftCalculator = FFTCalculator::getNewInstance(simResult->getNumberOfXNodes(), simResult->getNumberOfZNodes(), simResult->getTimeStepLength()); + l2Normcalculator = L2NormCalculator::getNewInstance(); +} + +void PostProcessingResultsImp::evaluate() +{ + if (!isEvaluated) { + analyticalResult->calc(simResult); + for (int i = 0; i < dataToCalculatePhiAndNu.size(); i++) { + if (dataToCalculatePhiAndNu.at(i) == "Vx") { + fftCalculator->calc(reduceDataToTimeSteps(simResult->getVx(), startTimeStepCalculationPhiNu, endTimeStepCalculationPhiNu)); + nuVx = fftCalculator->getNu(); + phiDiffVx = fftCalculator->getPhiDiff(); + } + if (dataToCalculatePhiAndNu.at(i) == "Vz") { + fftCalculator->calc(reduceDataToTimeSteps(simResult->getVz(), startTimeStepCalculationPhiNu, endTimeStepCalculationPhiNu)); + nuVz = fftCalculator->getNu(); + phiDiffVz = fftCalculator->getPhiDiff(); + } + } + analyticalResult->calc(simResult); + int bS = calcTimeStepInResults(basicTimeStepL2Norm); + int dS = calcTimeStepInResults(divergentTimeStepL2Norm); + + for (int i = 0; i < dataToCalculateL2.size(); i++) { + if (dataToCalculateL2.at(i) == "Vx"){ + l2VxBasic = l2Normcalculator->calc(analyticalResult->getVx().at(bS), simResult->getVx().at(bS), simResult->getLevels().at(bS)); + l2VxDivergent = l2Normcalculator->calc(analyticalResult->getVx().at(dS), simResult->getVx().at(dS), simResult->getLevels().at(dS)); + } + if (dataToCalculateL2.at(i) == "Vy") { + l2VyBasic = l2Normcalculator->calc(analyticalResult->getVy().at(bS), simResult->getVy().at(bS), simResult->getLevels().at(bS)); + l2VyDivergent = l2Normcalculator->calc(analyticalResult->getVy().at(dS), simResult->getVy().at(dS), simResult->getLevels().at(dS)); + } + if (dataToCalculateL2.at(i) == "Vz") { + l2VzBasic = l2Normcalculator->calc(analyticalResult->getVz().at(bS), simResult->getVz().at(bS), simResult->getLevels().at(bS)); + l2VzDivergent = l2Normcalculator->calc(analyticalResult->getVz().at(dS), simResult->getVz().at(dS), simResult->getLevels().at(dS)); + } + if (dataToCalculateL2.at(i) == "Press") { + l2PressBasic = l2Normcalculator->calc(analyticalResult->getPress().at(bS), simResult->getPress().at(bS), simResult->getLevels().at(bS)); + l2PressDivergent = l2Normcalculator->calc(analyticalResult->getPress().at(dS), simResult->getPress().at(dS), simResult->getLevels().at(dS)); + } + if (dataToCalculateL2.at(i) == "Rho") { + l2RhoBasic = l2Normcalculator->calc(analyticalResult->getRho().at(bS), simResult->getRho().at(bS), simResult->getLevels().at(bS)); + l2RhoDivergent = l2Normcalculator->calc(analyticalResult->getRho().at(dS), simResult->getRho().at(dS), simResult->getLevels().at(dS)); + } + } + isEvaluated = true; + } +} + +double PostProcessingResultsImp::getNuVx() +{ + return nuVx; +} + +double PostProcessingResultsImp::getNuVy() +{ + return nuVy; +} + +double PostProcessingResultsImp::getNuVz() +{ + return nuVz; +} + +double PostProcessingResultsImp::getPhiDiffVx() +{ + return phiDiffVx; +} + +double PostProcessingResultsImp::getPhiDiffVy() +{ + return phiDiffVy; +} + +double PostProcessingResultsImp::getPhiDiffVz() +{ + return phiDiffVz; +} + +std::vector<double> PostProcessingResultsImp::getL2NormVx() +{ + std::vector<double> v; + v.push_back(l2VxBasic); + v.push_back(l2VxDivergent); + return v; +} + +std::vector<double> PostProcessingResultsImp::getL2NormVy() +{ + std::vector<double> v; + v.push_back(l2VyBasic); + v.push_back(l2VyDivergent); + return v; +} + +std::vector<double> PostProcessingResultsImp::getL2NormVz() +{ + std::vector<double> v; + v.push_back(l2VzBasic); + v.push_back(l2VzDivergent); + return v; +} + +std::vector<double> PostProcessingResultsImp::getL2NormPress() +{ + std::vector<double> v; + v.push_back(l2PressBasic); + v.push_back(l2PressDivergent); + return v; +} + +std::vector<double> PostProcessingResultsImp::getL2NormRho() +{ + std::vector<double> v; + v.push_back(l2RhoBasic); + v.push_back(l2RhoDivergent); + return v; +} + +int PostProcessingResultsImp::getNumberOfXNodes() +{ + return simResult->getNumberOfXNodes(); +} + +int PostProcessingResultsImp::getNumberOfYNodes() +{ + return simResult->getNumberOfYNodes(); +} + +int PostProcessingResultsImp::getNumberOfZNodes() +{ + return simResult->getNumberOfZNodes(); +} + +std::vector<std::vector<double>> PostProcessingResultsImp::reduceDataToTimeSteps(std::vector<std::vector<double>> data, unsigned int startTimeStep, unsigned int endTimeStep) +{ + std::vector<int> timeStepsToDelete; + + for (int i = simResult->getTimeSteps().size() - 1; i >= 0; i--) { + if (simResult->getTimeSteps().at(i) > endTimeStep) + timeStepsToDelete.push_back(i); + if (simResult->getTimeSteps().at(i) < startTimeStep) + timeStepsToDelete.push_back(i); + } + + for (int i = 0; i < timeStepsToDelete.size(); i++) + data.erase(data.begin() + timeStepsToDelete.at(i)); + + return data; +} + +int PostProcessingResultsImp::calcTimeStepInResults(unsigned int timeStep) +{ + for (int i = 0; i < simResult->getTimeSteps().size(); i++) { + if (timeStep == simResult->getTimeSteps().at(i)) + return simResult->getTimeSteps().at(i); + } +} diff --git a/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.h b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.h new file mode 100644 index 000000000..e03776bfa --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/PostProcessingResults/PostProcessingResultsImp.h @@ -0,0 +1,60 @@ +#ifndef POST_PROCESSING_RESULTS_IMP_H +#define POST_PROCESSING_RESULTS_IMP_H + +#include "PostProcessingResults.h" + +#include <memory> +#include <string> + +class AnalyticalResults; +class FFTCalculator; +class L2NormCalculator; +class SimulationResults; + +class PostProcessingResultsImp : public PostProcessingResults +{ +public: + static std::shared_ptr< PostProcessingResultsImp> getNewInstance(std::shared_ptr< SimulationResults> simResult, std::shared_ptr< AnalyticalResults> analyticalResult, std::vector<std::string> dataToCalculatePhiAndNu, std::vector<std::string> dataToCalculateL2, unsigned int startTimeStepCalculationPhiNu, unsigned int endTimeStepCalculationPhiNu, unsigned int basicTimeStepL2Norm, unsigned int divergentTimeStepL2Norm); + + void evaluate(); + + double getNuVx(); + double getNuVy(); + double getNuVz(); + double getPhiDiffVx(); + double getPhiDiffVy(); + double getPhiDiffVz(); + std::vector< double> getL2NormVx(); + std::vector< double> getL2NormVy(); + std::vector< double> getL2NormVz(); + std::vector< double> getL2NormPress(); + std::vector< double> getL2NormRho(); + int getNumberOfXNodes(); + int getNumberOfYNodes(); + int getNumberOfZNodes(); + +private: + PostProcessingResultsImp() {}; + PostProcessingResultsImp(std::shared_ptr< SimulationResults> simResult, std::shared_ptr< AnalyticalResults> analyticalResult, std::vector<std::string> dataToCalculatePhiAndNu, std::vector<std::string> dataToCalculateL2, unsigned int startTimeStepCalculationPhiNu, unsigned int endTimeStepCalculationPhiNu, unsigned int basicTimeStepL2Norm, unsigned int divergentTimeStepL2Norm); + + std::vector<std::vector<double>> reduceDataToTimeSteps(std::vector<std::vector<double>> data, unsigned int startTimeStep, unsigned int endTimeStep); + int calcTimeStepInResults(unsigned int timeStep); + + std::shared_ptr< SimulationResults> simResult; + std::shared_ptr< FFTCalculator> fftCalculator; + std::shared_ptr< L2NormCalculator> l2Normcalculator; + std::shared_ptr< AnalyticalResults> analyticalResult; + std::vector<std::string> dataToCalculatePhiAndNu; + std::vector<std::string> dataToCalculateL2; + unsigned int startTimeStepCalculationPhiNu; + unsigned int endTimeStepCalculationPhiNu; + unsigned int basicTimeStepL2Norm; + unsigned int divergentTimeStepL2Norm; + bool isEvaluated; + + double nuVx, nuVy, nuVz; + double phiDiffVx, phiDiffVy, phiDiffVz; + double l2VxBasic, l2VyBasic, l2VzBasic, l2RhoBasic, l2PressBasic; + double l2VxDivergent, l2VyDivergent, l2VzDivergent, l2RhoDivergent, l2PressDivergent; +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/PostProcessingResults/package.include b/targets/tests/NumericalTests/Utilities/PostProcessingResults/package.include new file mode 100644 index 000000000..e69de29bb diff --git a/targets/tests/NumericalTests/Utilities/Test/Test.h b/targets/tests/NumericalTests/Utilities/Test/Test.h index b9acd56dc..7cfe20811 100644 --- a/targets/tests/NumericalTests/Utilities/Test/Test.h +++ b/targets/tests/NumericalTests/Utilities/Test/Test.h @@ -9,12 +9,13 @@ class TestSimulation; class SimulationInfo; +class PostProcessingResults; class Test : public SimulationObserver { public: virtual void update() = 0; - virtual void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo) = 0; + virtual void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResults) = 0; virtual std::string getLogFileOutput() = 0; virtual std::vector< bool> getPassedTests() = 0; virtual void makeConsoleOutput() = 0; diff --git a/targets/tests/NumericalTests/Utilities/Test/TestImp.cpp b/targets/tests/NumericalTests/Utilities/Test/TestImp.cpp index eb6b42159..8710316d3 100644 --- a/targets/tests/NumericalTests/Utilities/Test/TestImp.cpp +++ b/targets/tests/NumericalTests/Utilities/Test/TestImp.cpp @@ -1,5 +1,6 @@ #include "TestImp.h" +#include "Utilities\PostProcessingResults\PostProcessingResults.h" #include "Utilities\TestSimulation\TestSimulation.h" void TestImp::update() @@ -11,7 +12,7 @@ void TestImp::update() if (simulations.at(i)->getSimulationRun()) { simulationRun.at(i) = true; - simResults.at(i) = simulations.at(i)->getSimulationResults(); + postProResults.at(i)->evaluate(); } } } @@ -20,12 +21,12 @@ void TestImp::update() evaluate(); } -void TestImp::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo) +void TestImp::addSimulation(std::shared_ptr<TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResult) { simulations.push_back(sim); simInfos.push_back(simInfo); + postProResults.push_back(postProResult); simulationRun.push_back(false); - simResults.resize(simResults.size() + 1); } std::string TestImp::getSimulationName() @@ -37,7 +38,6 @@ TestImp::TestImp(std::shared_ptr<ColorConsoleOutput> colorOutput) : colorOutput( { simulationRun.resize(0); simulations.resize(0); - simResults.resize(0); simInfos.resize(0); } diff --git a/targets/tests/NumericalTests/Utilities/Test/TestImp.h b/targets/tests/NumericalTests/Utilities/Test/TestImp.h index 41299075f..d30574980 100644 --- a/targets/tests/NumericalTests/Utilities/Test/TestImp.h +++ b/targets/tests/NumericalTests/Utilities/Test/TestImp.h @@ -14,7 +14,7 @@ class TestImp : public Test { public: void update(); - void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo); + void addSimulation(std::shared_ptr< TestSimulation> sim, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< PostProcessingResults> postProResult); virtual void evaluate() = 0; virtual std::string getLogFileOutput() = 0; @@ -31,7 +31,7 @@ protected: 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< PostProcessingResults>> postProResults; std::vector< std::shared_ptr< SimulationInfo>> simInfos; std::string kernelName; diff --git a/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.cpp b/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.cpp index c36a1ca85..ed5c97820 100644 --- a/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.cpp +++ b/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.cpp @@ -13,9 +13,9 @@ #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< ColorConsoleOutput> colorOutput) +std::shared_ptr<TestSimulation> TestSimulationImp::getNewInsance(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput, std::shared_ptr< SimulationResults> simResults) { - return std::shared_ptr< TestSimulation>(new TestSimulationImp(simID, simPara, simInfo, colorOutput)); + return std::shared_ptr< TestSimulation>(new TestSimulationImp(simID, simPara, simInfo, colorOutput, simResults)); } std::shared_ptr<SimulationParameter> TestSimulationImp::getSimulationParameter() @@ -97,14 +97,13 @@ std::string TestSimulationImp::getRunTimeOutput() return oss.str(); } -TestSimulationImp::TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput) : simID(simID), colorOutput(colorOutput) +TestSimulationImp::TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput, std::shared_ptr< SimulationResults> simResults) : simID(simID), colorOutput(colorOutput), simResults(simResults) { this->simPara = simPara; this->simInfo = simInfo; this->simInfo->setSimulationID(simID); - 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())); + writeToVector = Y2dSliceToResults::getNewInstance(simResults, simPara->getYSliceForCalculation(), simPara->getStartTimeCalculation(), simPara->getEndTime(), simPara->getTimeStepLength(), simPara->getWriteFiles(), std::shared_ptr<FileWriter>(new FileWriter()), simPara->getStartTimeDataWriter()); simObserver.resize(0); simualtionRun = false; diff --git a/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.h b/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.h index 4b06b1700..37109afab 100644 --- a/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.h +++ b/targets/tests/NumericalTests/Utilities/TestSimulation/TestSimulationImp.h @@ -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, std::shared_ptr< ColorConsoleOutput> colorOutput); + 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< SimulationResults> simResults); std::shared_ptr< SimulationParameter> getSimulationParameter(); std::shared_ptr< DataWriter> getDataWriter(); @@ -28,7 +28,7 @@ public: std::string getRunTimeOutput(); private: - TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput); + TestSimulationImp(int simID, std::shared_ptr< SimulationParameter> simPara, std::shared_ptr< SimulationInfo> simInfo, std::shared_ptr< ColorConsoleOutput> colorOutput, std::shared_ptr< SimulationResults> simResults); void notifyObserver(); void setTestStartTime(); void setTestEndTime(); diff --git a/targets/tests/NumericalTests/config.txt b/targets/tests/NumericalTests/config.txt index ea0aef7e1..c30a7bf40 100644 --- a/targets/tests/NumericalTests/config.txt +++ b/targets/tests/NumericalTests/config.txt @@ -7,7 +7,7 @@ Devices="1" # Kernels # ################################################## KernelsToTest="CumulantOneCompSP27" -CumulantAA2016CompSP27 CumulantAll4CompSP27" + CumulantAA2016CompSP27 CumulantAll4CompSP27" ################################################## # Basic Simulation Parameter # @@ -37,7 +37,7 @@ ySliceForCalculation=0 # PhiAndNu Test Parameter # ################################################## MinOrderOfAccuracy=1.95 -DataToCalc_PhiAndNu="Vx" +DataToCalc_PhiAndNu="Vx Vz" StartTimeStepCalculation_PhiNu=11 EndTimeStepCalculation_PhiNu=20 PhiAndNuTest_TGV=true @@ -47,7 +47,7 @@ PhiAndNuTest_SW=true # L2-Norm Test Parameter # ################################################## MaxL2NormDiff=0.05 -DataToCalc_L2="Vx" +DataToCalc_L2="Vx Vy Vz" BasicTimeStep_L2=0 DivergentTimeStep_L2=20 L2NormTest_TGV=true @@ -57,8 +57,8 @@ L2NormTest_SW=true # Simulation To Perform # ################################################## TaylorGreenVortex32=true -TaylorGreenVortex64=false -TaylorGreenVortex128=false +TaylorGreenVortex64=true +TaylorGreenVortex128=true TaylorGreenVortex256=false TaylorGreenVortex512=false diff --git a/targets/tests/NumericalTests/main.cpp b/targets/tests/NumericalTests/main.cpp index 8c0697cab..741ed72d1 100644 --- a/targets/tests/NumericalTests/main.cpp +++ b/targets/tests/NumericalTests/main.cpp @@ -22,9 +22,7 @@ static void startNumericalTests(const std::string &configFile) std::vector< std::shared_ptr< VirtualFluidSimulation> > vfSimulations = factory->makeVirtualFluidSimulations(testSim); for (int i = 0; i < vfSimulations.size(); i++) - { vfSimulations.at(i)->run(); - } testQueue->makeFinalOutput(); logFileQueue->writeLogFiles(); -- GitLab