diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp index a2c92dc9c1d08c0ad90fc97e544fb25f1aefd73d..8b41bb49414a5dc0be808b27aec255c23022cb8f 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp +++ b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.cpp @@ -8,9 +8,9 @@ #include <iomanip> -std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate) +std::shared_ptr<L2NormTest> L2NormTest::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData) { - return std::shared_ptr<L2NormTest>(new L2NormTest(colorOutput, testParameter, dataToCalculate)); + return std::shared_ptr<L2NormTest>(new L2NormTest(colorOutput, testParameter, dataToCalculate, maxL2NormDiff, normalizeData)); } void L2NormTest::update() @@ -59,6 +59,7 @@ void L2NormTest::evaluate() std::string L2NormTest::getLogFileOutput() { std::ostringstream oss; + oss << "NormalizeData_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "=" << normalizeData << std::endl; oss << "L2Norm_BasicTimeStep_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "=" << resultBasicTimestep << std::endl; oss << "L2Norm_DivergentTimeStep_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "=" << resultDivergentTimeStep << std::endl; oss << "L2Norm_Diff_L" << l2NormPostProStrategies.at(0)->getNumberOfXNodes() << "_" << dataToCalculate << "=" << diffL2Norm << std::endl << std::endl; @@ -73,17 +74,17 @@ std::vector<bool> L2NormTest::getPassedTests() void L2NormTest::makeConsoleOutput() { if (!testError) - colorOutput->makeL2NormTestOutput(testPassed, simInfos.at(0), basicTimeStep, divergentTimeStep, dataToCalculate, resultBasicTimestep, resultDivergentTimeStep, diffL2Norm); + colorOutput->makeL2NormTestOutput(testPassed, simInfos.at(0), normalizeData, basicTimeStep, divergentTimeStep, dataToCalculate, resultBasicTimestep, resultDivergentTimeStep, diffL2Norm); else - colorOutput->makeL2NormTestErrorOutput("Test could not run. Amplitude is zero. Normalization of the data is not possible.", simInfos.at(0), basicTimeStep, divergentTimeStep, dataToCalculate); + colorOutput->makeL2NormTestErrorOutput(l2NormPostProStrategies.at(0)->getErrorMessage(), simInfos.at(0), normalizeData, basicTimeStep, divergentTimeStep, dataToCalculate); } -L2NormTest::L2NormTest(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate) - : TestImp(colorOutput), dataToCalculate(dataToCalculate) +L2NormTest::L2NormTest(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData) + : TestImp(colorOutput), dataToCalculate(dataToCalculate), normalizeData(normalizeData) { basicTimeStep = testParameter->basicTimeStep; divergentTimeStep = testParameter->divergentTimeStep; - maxL2NormDiff = testParameter->maxDiff; + this->maxL2NormDiff = maxL2NormDiff; testError = false; } \ 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 71f3b753bb2b93682bf9c8374019ed51886868c5..f054f2357774330a19811d447f3ad1a62f5c8787 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h +++ b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTest.h @@ -14,7 +14,7 @@ struct L2NormTestParameterStruct; class L2NormTest : public TestImp { public: - static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate); + static std::shared_ptr<L2NormTest> getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData); void update(); void addSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormPostProcessingStrategy> postProStrategy); @@ -22,9 +22,10 @@ public: std::string getLogFileOutput(); std::vector<bool> getPassedTests(); void makeConsoleOutput(); + private: - L2NormTest(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate); + L2NormTest(std::shared_ptr<ColorConsoleOutput> colorOutput, std::shared_ptr<L2NormTestParameterStruct> testParameter, std::string dataToCalculate, double maxL2NormDiff, std::string normalizeData); unsigned int basicTimeStep, divergentTimeStep; double resultBasicTimestep, resultDivergentTimeStep; @@ -34,6 +35,7 @@ private: bool testPassed; bool testError; + std::string normalizeData; std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > l2NormPostProStrategies; }; diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTestParameterStruct.h b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTestParameterStruct.h index f4586e1063da9358ca0bfa947fd0130a26f0c5f4..dbcfb6637234c7697137ff2dcf964d76f2fba83c 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTestParameterStruct.h +++ b/targets/tests/NumericalTests/Tests/L2NormTest/L2NormTestParameterStruct.h @@ -9,9 +9,11 @@ struct L2NormTestParameterStruct { std::shared_ptr<BasicTestParameterStruct> basicTestParameter; - double maxDiff; + std::vector<double> maxDiff; unsigned int basicTimeStep; unsigned int divergentTimeStep; + + std::vector<std::string> normalizeData; }; #endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.cpp b/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.cpp index 4b9ddd1e80817aab51436a5845f6a54a7dac446b..e0527c6512edb0bec52ef5b1406373ad6dadc37f 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.cpp +++ b/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.cpp @@ -6,12 +6,12 @@ #include "Utilities/Results/AnalyticalResults/AnalyticalResult.h" #include "Utilities/Results/SimulationResults/SimulationResults.h" -std::shared_ptr<L2NormPostProcessingStrategy> L2NormPostProcessingStrategy::getNewInstance(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara) +std::shared_ptr<L2NormPostProcessingStrategy> L2NormPostProcessingStrategy::getNewInstance(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara, std::shared_ptr<L2NormCalculator> l2Normcalculator) { - return std::shared_ptr<L2NormPostProcessingStrategy>(new L2NormPostProcessingStrategy(simResult, analyticalResult, testPara)); + return std::shared_ptr<L2NormPostProcessingStrategy>(new L2NormPostProcessingStrategy(simResult, analyticalResult, testPara, l2Normcalculator)); } -L2NormPostProcessingStrategy::L2NormPostProcessingStrategy(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara) +L2NormPostProcessingStrategy::L2NormPostProcessingStrategy(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara, std::shared_ptr<L2NormCalculator> l2Normcalculator) : PostProcessingStrategyImp(simResult), analyticalResult(analyticalResult) { dataToCalculateL2 = testPara->basicTestParameter->dataToCalc; @@ -19,7 +19,7 @@ L2NormPostProcessingStrategy::L2NormPostProcessingStrategy(std::shared_ptr<Simul divergentTimeStepL2Norm = testPara->divergentTimeStep; isEvaluated = false; - l2Normcalculator = L2NormCalculator::getInstance(); + this->l2Normcalculator = l2Normcalculator; } void L2NormPostProcessingStrategy::evaluate() @@ -93,4 +93,9 @@ std::vector<double> L2NormPostProcessingStrategy::getL2NormRho() v.push_back(l2RhoBasic); v.push_back(l2RhoDivergent); return v; -} \ No newline at end of file +} + +std::string L2NormPostProcessingStrategy::getErrorMessage() +{ + return l2Normcalculator->getErrorMessage(); +} diff --git a/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.h b/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.h index 8016351850fc7abade2a0dc58c890a7bbf782841..3e12f0c7b7b586e4ec5ac6ffc7641da566eb7c0a 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.h +++ b/targets/tests/NumericalTests/Tests/L2NormTest/PostProcessingStrategy/PostProcessingStrategyL2NormTest.h @@ -12,7 +12,7 @@ struct L2NormTestParameterStruct; class L2NormPostProcessingStrategy : public PostProcessingStrategyImp { public: - static std::shared_ptr<L2NormPostProcessingStrategy> getNewInstance(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara); + static std::shared_ptr<L2NormPostProcessingStrategy> getNewInstance(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara, std::shared_ptr<L2NormCalculator> l2Normcalculator); void evaluate(); std::vector<double> getL2NormVx(); @@ -21,8 +21,10 @@ public: std::vector<double> getL2NormPress(); std::vector<double> getL2NormRho(); + std::string getErrorMessage(); + private: - L2NormPostProcessingStrategy(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara); + L2NormPostProcessingStrategy(std::shared_ptr<SimulationResults> simResult, std::shared_ptr<AnalyticalResults> analyticalResult, std::shared_ptr<L2NormTestParameterStruct> testPara, std::shared_ptr<L2NormCalculator> l2Normcalculator); bool isEvaluated; std::shared_ptr<L2NormCalculator> l2Normcalculator; diff --git a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.cpp b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.cpp index eb51948b25c9d60b8ce5a85d1906b03c69c2f01e..3c3d695d209f9cad20ce0f3a9e8cd7aedd83e419 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.cpp +++ b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.cpp @@ -1,6 +1,7 @@ #include "L2NormTestBetweenKernels.h" #include "Utilities/Calculator/L2NormCalculator/L2NormCalculator.h" +#include "Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h" #include "Utilities/ColorConsoleOutput/ColorConsoleOutput.h" #include "Utilities/Results/SimulationResults/SimulationResults.h" #include "Utilities/TestSimulation/TestSimulation.h" @@ -9,9 +10,9 @@ #include <iomanip> -std::shared_ptr<L2NormTestBetweenKernels> L2NormTestBetweenKernels::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep) +std::shared_ptr<L2NormTestBetweenKernels> L2NormTestBetweenKernels::getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith) { - return std::shared_ptr<L2NormTestBetweenKernels>(new L2NormTestBetweenKernels(colorOutput, dataToCalculate, timeStep)); + return std::shared_ptr<L2NormTestBetweenKernels>(new L2NormTestBetweenKernels(colorOutput, dataToCalculate, timeStep, normalizeWith)); } void L2NormTestBetweenKernels::update() @@ -51,9 +52,14 @@ void L2NormTestBetweenKernels::evaluate() divergentL2Result = divergentPostProcessingStrategy->getL2NormRho(timeStep); resultL2ToBasicKernel = l2Normcalculator->calc(basicSimResults->getRho().at(tS), divergentSimResults->getRho().at(tS), basicSimResults->getLevels().at(tS), basicSimResults->getNumberOfXNodes(), basicSimResults->getNumberOfZNodes(), basicSimResults->getTimeStepLength()); } - - if (basicL2Result <= divergentL2Result) - testPassed = true; + if (basicL2Result < 0 || divergentL2Result < 0 || resultL2ToBasicKernel < 0) { + testError = true; + testPassed = false; + } + else + { + testPassed = basicL2Result <= divergentL2Result; + } makeConsoleOutput(); } @@ -61,6 +67,7 @@ void L2NormTestBetweenKernels::evaluate() std::string L2NormTestBetweenKernels::getLogFileOutput() { std::ostringstream oss; + oss << "NormalizeData_L" << "_" << dataToCalculate << "_TimeStep_" << timeStep << "_L" << basicPostProcessingStrategy->getNumberOfXNodes() << "=" << normalizeWith << std::endl; oss << "L2Norm_BasicKernel_" << dataToCalculate << "_TimeStep_" << timeStep << "_L" << basicPostProcessingStrategy->getNumberOfXNodes() << "=" << basicL2Result << std::endl; oss << "L2Norm_DivergentKernel_" << dataToCalculate << "_TimeStep_" << timeStep << "_L" << basicPostProcessingStrategy->getNumberOfXNodes() << "=" << divergentL2Result << std::endl; oss << "L2Norm_Between_Kernels_" << dataToCalculate << "_TimeStep_" << timeStep << "_L" << basicPostProcessingStrategy->getNumberOfXNodes() << "=" << resultL2ToBasicKernel << std::endl << std::endl; @@ -80,7 +87,10 @@ std::vector<bool> L2NormTestBetweenKernels::getPassedTests() void L2NormTestBetweenKernels::makeConsoleOutput() { - colorOutput->makeL2NormBetweenKernelsTestOutput(testPassed, basicSimInfo, divergentSimInfo, dataToCalculate, timeStep, basicL2Result, divergentL2Result, resultL2ToBasicKernel); + if (!testError) + colorOutput->makeL2NormBetweenKernelsTestOutput(testPassed, basicSimInfo, normalizeWith, divergentSimInfo, dataToCalculate, timeStep, basicL2Result, divergentL2Result, resultL2ToBasicKernel); + else + colorOutput->makeL2NormBetweenKernelsTestErrorOutput(basicPostProcessingStrategy->getErrorMessage(), basicSimInfo, normalizeWith, divergentSimInfo, dataToCalculate, timeStep); } void L2NormTestBetweenKernels::setBasicSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> postProcessingStrategy) @@ -101,10 +111,12 @@ void L2NormTestBetweenKernels::setDivergentKernelSimulation(std::shared_ptr<Nume this->divergentSimResults = divergentPostProcessingStrategy->getSimulationResult(); } -L2NormTestBetweenKernels::L2NormTestBetweenKernels(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep) - : TestImp(colorOutput), timeStep(timeStep), dataToCalculate(dataToCalculate) +L2NormTestBetweenKernels::L2NormTestBetweenKernels(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith) + : TestImp(colorOutput), timeStep(timeStep), dataToCalculate(dataToCalculate), normalizeWith(normalizeWith) { - l2Normcalculator = L2NormCalculator::getInstance(); + std::shared_ptr<L2NormCalculatorFactory> l2NormCalculatorFactory = L2NormCalculatorFactory::getInstance(); + l2Normcalculator = l2NormCalculatorFactory->makeL2NormCalculator(normalizeWith); + testError = false; } int L2NormTestBetweenKernels::calcTimeStepInResults(unsigned int timeStep) diff --git a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.h b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.h index c63dca09bb711f504ef64b3ea21d9ad71e93fc05..a7bf15d5531923c2645486262c957b9907345a79 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.h +++ b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernels.h @@ -13,7 +13,7 @@ class SimulationResults; class L2NormTestBetweenKernels : public TestImp { public: - static std::shared_ptr<L2NormTestBetweenKernels> getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep); + static std::shared_ptr<L2NormTestBetweenKernels> getNewInstance(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith); void update(); void evaluate(); @@ -26,12 +26,13 @@ public: void setDivergentKernelSimulation(std::shared_ptr<NumericalTestSimulation> sim, std::shared_ptr<SimulationInfo> simInfo, std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> postProcessingStrategy); private: - L2NormTestBetweenKernels(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep); + L2NormTestBetweenKernels(std::shared_ptr<ColorConsoleOutput> colorOutput, std::string dataToCalculate, unsigned int timeStep, std::string normalizeWith); int calcTimeStepInResults(unsigned int timeStep); unsigned int timeStep; std::string dataToCalculate; bool testPassed; + bool testError; std::shared_ptr<NumericalTestSimulation> basicSim; std::shared_ptr<SimulationInfo> basicSimInfo; @@ -47,6 +48,8 @@ private: std::shared_ptr<L2NormCalculator> l2Normcalculator; + std::string normalizeWith; + double resultL2ToBasicKernel; }; #endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernelsParameterStruct.h b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernelsParameterStruct.h index a060b3438c558e5cb1e9939d65a8fda590f02bcb..8d653e57779dac8e9c23115748e609e287dfd65c 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernelsParameterStruct.h +++ b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernelsParameterStruct.h @@ -15,6 +15,8 @@ struct L2NormTestBetweenKernelsParameterStruct std::vector<std::string> kernelsToTest; std::vector<int> timeSteps; + + std::string normalizeWith; }; #endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.cpp b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.cpp index a219405d60a4b23a365cc69bbb8e60d33ece24c9..56ab11247267f7da86c1fc4debd1448f12358c82 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.cpp +++ b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.cpp @@ -1,6 +1,7 @@ #include "L2NormBetweenKernelPostProcessingStrategy.h" #include "Utilities/Calculator/L2NormCalculator/L2NormCalculator.h" +#include "Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h" #include "Utilities/Results/SimulationResults/SimulationResults.h" #include "Utilities/Results/AnalyticalResults/AnalyticalResult.h" @@ -61,6 +62,11 @@ double L2NormBetweenKernelPostProcessingStrategy::getL2NormRho(int timeStep) return l2Rho.at(calcPosInTimeStep(timeStep)); } +std::string L2NormBetweenKernelPostProcessingStrategy::getErrorMessage() +{ + return l2Normcalculator->getErrorMessage(); +} + std::shared_ptr<SimulationResults> L2NormBetweenKernelPostProcessingStrategy::getSimulationResult() { return simResult; @@ -71,7 +77,8 @@ L2NormBetweenKernelPostProcessingStrategy::L2NormBetweenKernelPostProcessingStra { timeSteps = testPara->timeSteps; dataToCalculate = testPara->basicTestParameter->dataToCalc; - l2Normcalculator = L2NormCalculator::getInstance(); + std::shared_ptr<L2NormCalculatorFactory> l2NormCalculatorFactory = L2NormCalculatorFactory::getInstance(); + l2Normcalculator = l2NormCalculatorFactory->makeL2NormCalculator(testPara->normalizeWith); isEvaluated = false; } diff --git a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.h b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.h index 08147ef84dfef62de5d91615d329e6513eae1a2e..f31de0cacd8f2fc93835011a1651511a591851db 100644 --- a/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.h +++ b/targets/tests/NumericalTests/Tests/L2NormTestBetweenKernels/PostProcessingStrategy/L2NormBetweenKernelPostProcessingStrategy.h @@ -21,6 +21,8 @@ public: double getL2NormPress(int timeStep); double getL2NormRho(int timeStep); + std::string getErrorMessage(); + virtual std::shared_ptr<SimulationResults> getSimulationResult(); private: diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.cpp new file mode 100644 index 0000000000000000000000000000000000000000..ea215ef2b45cfc2d1b02ae2800345aef9ba49ac1 --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.cpp @@ -0,0 +1,25 @@ +#include "L2CalculatorNormalizeWithAmplitude.h" + +#include "Utilities/Calculator/FFTCalculator/FFTCalculator.h" + +std::shared_ptr<L2NormCalculator> L2CalculatorNormalizeWithAmplitude::getInstance() +{ + static std::shared_ptr<L2NormCalculator> uniqueInstance; + if (!uniqueInstance) + uniqueInstance = std::shared_ptr<L2NormCalculator>(new L2CalculatorNormalizeWithAmplitude()); + return uniqueInstance; +} + +double L2CalculatorNormalizeWithAmplitude::calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) +{ + std::shared_ptr<FFTCalculator> fftCalc = FFTCalculator::getNewInstance(lx, lz, timeStepLength); + double amplitude = fftCalc->calcAmplitudeForTimeStep(basicData, false); + if (equalDouble(amplitude, 0.0)) + return -1.0; + double counter = calcCounter(basicData, divergentData, level, lx, lz, timeStepLength); + return sqrt(counter / (amplitude * amplitude)); +} + +L2CalculatorNormalizeWithAmplitude::L2CalculatorNormalizeWithAmplitude() : L2NormCalculatorImp("Test could not run. Amplitude is zero. Normalization of the data is not possible.") +{ +} diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.h b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.h new file mode 100644 index 0000000000000000000000000000000000000000..6308adb5624ee807abbc08208ca4a9fa1df37043 --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.h @@ -0,0 +1,16 @@ +#ifndef L2_NORM_CALCULATOR_NORMALIZE_WITH_AMPLITUDE_H +#define L2_NORM_CALCULATOR_NORMALIZE_WITH_AMPLITUDE_H + +#include "../L2NormCalculatorImp.h" + +class L2CalculatorNormalizeWithAmplitude : public L2NormCalculatorImp +{ +public: + static std::shared_ptr<L2NormCalculator> getInstance(); + + double calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength); + +private: + L2CalculatorNormalizeWithAmplitude(); +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/package.include b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.cpp new file mode 100644 index 0000000000000000000000000000000000000000..eb15dacb2b8b22d1b9ceb62c5963627ebd45a88c --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.cpp @@ -0,0 +1,28 @@ +#include "L2CalculatorNormalizeWithBasicData.h" + +std::shared_ptr<L2NormCalculator> L2CalculatorNormalizeWithBasicData::getInstance() +{ + static std::shared_ptr<L2NormCalculator> uniqueInstance; + if (!uniqueInstance) + uniqueInstance = std::shared_ptr<L2NormCalculator>(new L2CalculatorNormalizeWithBasicData()); + return uniqueInstance; +} + +double L2CalculatorNormalizeWithBasicData::calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) +{ + double counter = calcCounter(basicData, divergentData, level, lx, lz, timeStepLength); + double denominator = 0.0; + for (int i = 0; i < basicData.size(); i++) { + double area = (1 / pow(2.0, level.at(i))) * (1 / pow(2.0, level.at(i))); + denominator += (basicData.at(i)*basicData.at(i)) * area; + } + if (equalDouble(denominator, 0.0)) + return -1.0; + + return sqrt(counter / denominator); +} + +L2CalculatorNormalizeWithBasicData::L2CalculatorNormalizeWithBasicData() : L2NormCalculatorImp("Test could not run. BasicData is zero. Normalization of the data is not possible.") +{ + +} diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.h b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.h new file mode 100644 index 0000000000000000000000000000000000000000..36517aaee00ab617cffc60a997be7f191f839efc --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.h @@ -0,0 +1,16 @@ +#ifndef L2_NORM_CALCULATOR_NORMALIZE_WITH_BASIC_DATA_H +#define L2_NORM_CALCULATOR_NORMALIZE_WITH_BASIC_DATA_H + +#include "../L2NormCalculatorImp.h" + +class L2CalculatorNormalizeWithBasicData : public L2NormCalculatorImp +{ +public: + static std::shared_ptr<L2NormCalculator> getInstance(); + + double calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength); + +private: + L2CalculatorNormalizeWithBasicData(); +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/package.include b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp deleted file mode 100644 index 20f4f9cc28e03c34ee394dd06888075ab13555be..0000000000000000000000000000000000000000 --- a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.cpp +++ /dev/null @@ -1,46 +0,0 @@ -#include "L2NormCalculator.h" - -#include "Utilities/Calculator/FFTCalculator/FFTCalculator.h" -#include "Utilities/Calculator/AlmostEquals.h" - -#define _USE_MATH_DEFINES -#include <math.h> -#include <iostream> - -std::shared_ptr<L2NormCalculator> L2NormCalculator::getInstance() -{ - static std::shared_ptr<L2NormCalculator> uniqueInstance; - if (!uniqueInstance) - uniqueInstance = std::shared_ptr<L2NormCalculator>(new L2NormCalculator()); - return uniqueInstance; -} - -double L2NormCalculator::calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) -{ - fftCalc = FFTCalculator::getNewInstance(lx, lz, timeStepLength); - double amplitude = fftCalc->calcAmplitudeForTimeStep(basicData, false); - if (equalDouble(amplitude, 0.0)) - return -1.0; - double zaehler = 0.0; - //double nenner = 0.0; - for (int i = 0; i < basicData.size(); i++) { - double area = (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))) * area; - //nenner += (basicData.at(i)*basicData.at(i)) * flaeche; - } - return sqrt(zaehler / (amplitude * amplitude)); -} - -bool L2NormCalculator::equalDouble(double num1, double num2) -{ - const FloatingPoint<double> lhs(num1), rhs(num2); - - if (lhs.AlmostEquals(rhs)) - return true; - return false; -} - -L2NormCalculator::L2NormCalculator() -{ - -} \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.h b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.h index f159253da938dcb91e031e902d246a336745f304..44628af304b1c7f8e9c6a9db23c495a6e574f43b 100644 --- a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.h +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculator.h @@ -2,21 +2,14 @@ #define L2NORM_CALCULATOR_H #include <vector> -#include <memory> +#include <string> -class FFTCalculator; class L2NormCalculator { public: - static std::shared_ptr<L2NormCalculator> getInstance(); + virtual double calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) = 0; + virtual std::string getErrorMessage() = 0; - double calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength); - -private: - L2NormCalculator(); - bool equalDouble(double num1, double num2); - - std::shared_ptr<FFTCalculator> fftCalc; }; #endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.cpp new file mode 100644 index 0000000000000000000000000000000000000000..0461e270c1c3ccc43a43a5b430db7e6e3d54466f --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.cpp @@ -0,0 +1,24 @@ +#include "L2NormCalculatorFactory.h" + +#include "Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithAmplitude/L2CalculatorNormalizeWithAmplitude.h" +#include "Utilities/Calculator/L2NormCalculator/L2CalculatorNormalizeWithBasicData/L2CalculatorNormalizeWithBasicData.h" + +std::shared_ptr<L2NormCalculatorFactory> L2NormCalculatorFactory::getInstance() +{ + static std::shared_ptr<L2NormCalculatorFactory> uniqueInstance; + if (!uniqueInstance) + uniqueInstance = std::shared_ptr<L2NormCalculatorFactory>(new L2NormCalculatorFactory()); + return uniqueInstance; +} + +std::shared_ptr<L2NormCalculator> L2NormCalculatorFactory::makeL2NormCalculator(std::string type) +{ + if(type == "amplitude") + return L2CalculatorNormalizeWithAmplitude::getInstance(); + if (type == "basicData") + return L2CalculatorNormalizeWithBasicData::getInstance(); +} + +L2NormCalculatorFactory::L2NormCalculatorFactory() +{ +} diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h new file mode 100644 index 0000000000000000000000000000000000000000..6215de9198b5de87c1fc1741f457d17de6a9ce7f --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h @@ -0,0 +1,19 @@ +#ifndef L2NORM_CALCULATOR_FACTORY_H +#define L2NORM_CALCULATOR_FACTORY_H + +#include <memory> +#include <string> + +class L2NormCalculator; + +class L2NormCalculatorFactory +{ +public: + static std::shared_ptr<L2NormCalculatorFactory> getInstance(); + + std::shared_ptr<L2NormCalculator> makeL2NormCalculator(std::string type); + +private: + L2NormCalculatorFactory(); +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/package.include b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/package.include new file mode 100644 index 0000000000000000000000000000000000000000..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.cpp b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.cpp new file mode 100644 index 0000000000000000000000000000000000000000..1a5b7e1132fc421cfdcaaf4e32cebff1f983aa66 --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.cpp @@ -0,0 +1,40 @@ +#include "L2NormCalculatorImp.h" + +#include "Utilities/Calculator/AlmostEquals.h" + +#define _USE_MATH_DEFINES +#include <math.h> +#include <iostream> + +L2NormCalculatorImp::L2NormCalculatorImp(std::string errorMessage) : errorMessage(errorMessage) +{ +} + +bool L2NormCalculatorImp::equalDouble(double num1, double num2) +{ + const FloatingPoint<double> lhs(num1), rhs(num2); + + if (lhs.AlmostEquals(rhs)) + return true; + return false; +} + +double L2NormCalculatorImp::calcCounter(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) +{ + double counter = 0.0; + for (int i = 0; i < basicData.size(); i++) { + double area = (1 / pow(2.0, level.at(i))) * (1 / pow(2.0, level.at(i))); + counter += ((divergentData.at(i) - basicData.at(i))*(divergentData.at(i) - basicData.at(i))) * area; + } + return counter; +} + +std::string L2NormCalculatorImp::getErrorMessage() +{ + return errorMessage; +} + +L2NormCalculatorImp::L2NormCalculatorImp() +{ + +} \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.h b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.h new file mode 100644 index 0000000000000000000000000000000000000000..45c5b15fe410a5f9fb6b1e06e9dccc013c93c92b --- /dev/null +++ b/targets/tests/NumericalTests/Utilities/Calculator/L2NormCalculator/L2NormCalculatorImp.h @@ -0,0 +1,27 @@ +#ifndef L2NORM_CALCULATOR_IMP_H +#define L2NORM_CALCULATOR_IMP_H + +#include "L2NormCalculator.h" + +#include <memory> + +class FFTCalculator; + +class L2NormCalculatorImp : public L2NormCalculator +{ +public: + virtual double calc(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength) = 0; + std::string getErrorMessage(); + +protected: + L2NormCalculatorImp(std::string errorMessage); + + bool equalDouble(double num1, double num2); + double calcCounter(std::vector<double> basicData, std::vector<double> divergentData, std::vector<unsigned int> level, double lx, double lz, double timeStepLength); + + std::string errorMessage; + +private: + L2NormCalculatorImp(); +}; +#endif \ No newline at end of file diff --git a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h index 96af0d6c8e2c4917ff97da6557ae72e7e499044f..091430710044d4be2ea49e810590a38c57474430 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutput.h @@ -11,9 +11,10 @@ class ColorConsoleOutput public: virtual void makeNyTestOutput(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 makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc) = 0; - virtual void makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel) = 0; + virtual void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3) = 0; + virtual void makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc) = 0; + virtual void makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel) = 0; + virtual void makeL2NormBetweenKernelsTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep) = 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 d2b2b8109d9403298f5ecbe56d7b62951f6a951b..9b04ec81a11d6bf69642d96e08d1e35559de90ba 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.cpp @@ -144,7 +144,7 @@ void ColorConsoleOutputImp::makePhiTestOutput(bool testPassed, std::shared_ptr<S printTestEnd(testPassed); } -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) +void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3) { setColor(testPassed); printTestStart(); @@ -175,6 +175,9 @@ void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_pt oss << "DataToCalculate: " << dataToCalc; print(oss.str()); oss.str(std::string()); + oss << "NormalizeData: " << normalizeData; + print(oss.str()); + oss.str(std::string()); oss << "BasicTimeStep: " << basicTimeStep; print(oss.str()); oss.str(std::string()); @@ -203,7 +206,7 @@ void ColorConsoleOutputImp::makeL2NormTestOutput(bool testPassed, std::shared_pt printTestEnd(testPassed); } -void ColorConsoleOutputImp::makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc) +void ColorConsoleOutputImp::makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc) { color = testing::internal::COLOR_YELLOW; printTestStart(); @@ -234,6 +237,9 @@ void ColorConsoleOutputImp::makeL2NormTestErrorOutput(std::string errorMessage, oss << "DataToCalculate: " << dataToCalc; print(oss.str()); oss.str(std::string()); + oss << "NormalizeData: " << normalizeData; + print(oss.str()); + oss.str(std::string()); oss << "BasicTimeStep: " << basicTimeStep; print(oss.str()); oss.str(std::string()); @@ -254,7 +260,7 @@ void ColorConsoleOutputImp::makeL2NormTestErrorOutput(std::string errorMessage, printTestEndError(); } -void ColorConsoleOutputImp::makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel) +void ColorConsoleOutputImp::makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel) { setColor(testPassed); printTestStart(); @@ -288,6 +294,9 @@ void ColorConsoleOutputImp::makeL2NormBetweenKernelsTestOutput(bool testPassed, oss << "DataToCalculate: " << dataToCalc; print(oss.str()); oss.str(std::string()); + oss << "NormalizeData: " << normalizeData; + print(oss.str()); + oss.str(std::string()); oss << "TimeStep: " << timeStep; print(oss.str()); oss.str(std::string()); @@ -312,6 +321,59 @@ void ColorConsoleOutputImp::makeL2NormBetweenKernelsTestOutput(bool testPassed, printTestEnd(testPassed); } +void ColorConsoleOutputImp::makeL2NormBetweenKernelsTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep) +{ + color = testing::internal::COLOR_YELLOW; + printTestStart(); + + printColor(""); + printColor("L2 Norm Between Kernels Test"); + printColor(""); + + std::ostringstream oss; + oss << "Basic Kernel: " << basicSimInfo->getKernelName(); + print(oss.str()); + oss.str(std::string()); + oss << "Divergent Kernel: " << divergentSimInfo->getKernelName(); + print(oss.str()); + oss.str(std::string()); + + oss << "Viscosity: " << basicSimInfo->getViscosity(); + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << basicSimInfo->getSimulationName(); + print(oss.str()); + oss.str(std::string()); + + oss << "L: " << basicSimInfo->getLx() << basicSimInfo->getSimulationParameterString(); + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << "DataToCalculate: " << dataToCalc; + print(oss.str()); + oss.str(std::string()); + oss << "NormalizeData: " << normalizeData; + print(oss.str()); + oss.str(std::string()); + oss << "TimeStep: " << timeStep; + print(oss.str()); + oss.str(std::string()); + + print(oss.str()); + oss << "Error Message: " << errorMessage; + print(oss.str()); + oss.str(std::string()); + + printColor(""); + printColor("L2 Norm Between Kernels Test"); + printColor(""); + + printTestEndError(); +} + void ColorConsoleOutputImp::makeSimulationHeadOutput(std::shared_ptr<SimulationInfo> simInfo) { std::ostringstream ossLine0; diff --git a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h index 65813b79c00f6cf8dc849406be33f3652edba4bc..3887798f26fd5081f56e9b5f47b140bd725e6dec 100644 --- a/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h +++ b/targets/tests/NumericalTests/Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h @@ -35,9 +35,10 @@ public: void makeNyTestOutput(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 makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc); - void makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel); + void makeL2NormTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc, double testWert1, double testWert2, double testWert3); + void makeL2NormTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> simInfo, std::string normalizeData, unsigned int basicTimeStep, unsigned int divergentTimeStep, std::string dataToCalc); + void makeL2NormBetweenKernelsTestOutput(bool testPassed, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep, double l2NormBasicKernel, double l2NormDivergentKernel, double l2NormBetweenKernel); + void makeL2NormBetweenKernelsTestErrorOutput(std::string errorMessage, std::shared_ptr<SimulationInfo> basicSimInfo, std::string normalizeData, std::shared_ptr<SimulationInfo> divergentSimInfo, std::string dataToCalc, unsigned int timeStep); 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/ConfigFileReader.cpp b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp index 6d223d708855129a6f8dbd3259c3caf86447f3b6..73b53214bc34d7628088ea2305ea2913610e6d19 100644 --- a/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp +++ b/targets/tests/NumericalTests/Utilities/ConfigFileReader/ConfigFileReader.cpp @@ -202,7 +202,20 @@ std::shared_ptr<L2NormTestParameterStruct> ConfigFileReader::makeL2NormTestParam testParameter->basicTestParameter = basicTestParameter; testParameter->basicTimeStep = StringUtil::toInt(input->getValue("BasicTimeStep_L2")); testParameter->divergentTimeStep = StringUtil::toInt(input->getValue("DivergentTimeStep_L2")); - testParameter->maxDiff = StringUtil::toDouble(input->getValue("MaxL2NormDiff")); + + bool runTest = false; + if (StringUtil::toBool(input->getValue("NormalizeWithBasicData"))) { + runTest = true; + testParameter->normalizeData.push_back("basicData"); + testParameter->maxDiff.push_back(StringUtil::toDouble(input->getValue("MaxL2NormDiffBasicData"))); + } + if (StringUtil::toBool(input->getValue("NormalizeWithAmplitude"))) { + runTest = true; + testParameter->normalizeData.push_back("amplitude"); + testParameter->maxDiff.push_back(StringUtil::toDouble(input->getValue("MaxL2NormDiffAmplitude"))); + } + if (!runTest) + basicTestParameter->runTest = false; return testParameter; } @@ -219,6 +232,19 @@ std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> ConfigFileReader::makeL testParameter->basicKernel = StringUtil::toString(input->getValue("BasicKernel_L2NormBetweenKernels")); testParameter->kernelsToTest = readKernelList(input); testParameter->timeSteps = StringUtil::toIntVector(input->getValue("Timesteps_L2NormBetweenKernels")); + testParameter->normalizeWith = StringUtil::toString(input->getValue("NormalizeWith")); + + bool correct = false; + + if (testParameter->normalizeWith == "amplitude") + correct = true; + if (testParameter->normalizeWith == "basicData") + correct = true; + + if (!correct) { + std::cout << "invalid input in ConfigFile." << std::endl << "possible data for NormalizeWith Parameter in L2-Norm Test Between Kernels Parameter:" << std::endl << "amplitude, basicData" << std::endl << std::endl; + exit(1); + } return testParameter; } diff --git a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp index 0f8a7a8bf8b82cc1c54a3b294e090fa1bf3e4d6e..e75f8dc0053d50a85793a668c3ccd10bb7964190 100644 --- a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp +++ b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.cpp @@ -40,6 +40,7 @@ #include "Tests/L2NormTestBetweenKernels/L2NormTestBetweenKernelsStruct.h" #include "Utilities/ColorConsoleOutput/ColorConsoleOutputImp.h" +#include "Utilities/Calculator/L2NormCalculator/L2NormCalculatorFactory/L2NormCalculatorFactory.h" #include "Utilities/DataWriter/AnalyticalResults2DToVTKWriter/AnalyticalResults2DToVTKWriterImp.h" #include "Utilities/DataWriter/Y2dSliceToResults/Y2dSliceToResults.h" @@ -70,6 +71,7 @@ NumericalTestFactoryImp::NumericalTestFactoryImp(std::shared_ptr<ConfigDataStruc myTestQueue = TestQueueImp::getNewInstance(colorOutput); myLogFileWriterQueue = LogFileQueueImp::getNewInstance(configFileData->logFilePath); anaResultWriter = AnalyticalResults2DToVTKWriterImp::getInstance(configFileData->writeAnalyticalToVTK); + l2NormCalculatorFactory = L2NormCalculatorFactory::getInstance(); l2NormTestsBetweenKernels.resize(0); init(configFileData); } @@ -317,9 +319,15 @@ std::shared_ptr<L2NormTestStruct> NumericalTestFactoryImp::makeL2NormTestsStruct std::shared_ptr<L2NormTestStruct> testStruct = std::shared_ptr<L2NormTestStruct> (new L2NormTestStruct); if (testParameter->basicTestParameter->runTest) { - std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > postProcessingStrategies; - for (int i = 0; i < testSimumlations.size(); i++) - postProcessingStrategies.push_back(L2NormPostProcessingStrategy::getNewInstance(testSimumlations.at(i)->getSimulationResults(), testSimumlations.at(i)->getAnalyticalResults(), testParameter)); + std::vector<std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > > postProcessingStrategies; + for (int j = 0; j < testParameter->normalizeData.size(); j++) { + std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > aPostProcessingStrategiesGroup; + for (int i = 0; i < testSimumlations.size(); i++) { + std::shared_ptr<L2NormCalculator> l2NormCalculator = l2NormCalculatorFactory->makeL2NormCalculator(testParameter->normalizeData.at(j)); + aPostProcessingStrategiesGroup.push_back(L2NormPostProcessingStrategy::getNewInstance(testSimumlations.at(i)->getSimulationResults(), testSimumlations.at(i)->getAnalyticalResults(), testParameter, l2NormCalculator)); + } + postProcessingStrategies.push_back(aPostProcessingStrategiesGroup); + } testStruct->tests = makeL2NormTests(testSimumlations, postProcessingStrategies, testParameter); testStruct->logFileInfo = L2NormInformation::getNewInstance(testStruct->tests, testParameter); @@ -327,15 +335,17 @@ std::shared_ptr<L2NormTestStruct> NumericalTestFactoryImp::makeL2NormTestsStruct return testStruct; } -std::vector<std::shared_ptr<L2NormTest> > NumericalTestFactoryImp::makeL2NormTests(std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > postProStrategy, std::shared_ptr<L2NormTestParameterStruct> testParameter) +std::vector<std::shared_ptr<L2NormTest> > NumericalTestFactoryImp::makeL2NormTests(std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > > postProStrategy, std::shared_ptr<L2NormTestParameterStruct> testParameter) { std::vector<std::shared_ptr<L2NormTest> > l2Tests; - for (int i = 0; i < testSim.size(); i++) { - for (int j = 0; j < testParameter->basicTestParameter->dataToCalc.size(); j++) { - std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(colorOutput, testParameter, testParameter->basicTestParameter->dataToCalc.at(j)); - test->addSimulation(testSim.at(i), testSim.at(i)->getSimulationInfo(), postProStrategy.at(i)); - testSim.at(i)->registerSimulationObserver(test); - l2Tests.push_back(test); + for (int k = 0; k < testParameter->normalizeData.size(); k++) { + for (int i = 0; i < testSim.size(); i++) { + for (int j = 0; j < testParameter->basicTestParameter->dataToCalc.size(); j++) { + std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(colorOutput, testParameter, testParameter->basicTestParameter->dataToCalc.at(j), testParameter->maxDiff.at(k), testParameter->normalizeData.at(k)); + test->addSimulation(testSim.at(i), testSim.at(i)->getSimulationInfo(), postProStrategy.at(k).at(i)); + testSim.at(i)->registerSimulationObserver(test); + l2Tests.push_back(test); + } } } return l2Tests; @@ -383,7 +393,7 @@ std::vector<std::vector<std::shared_ptr<L2NormTestBetweenKernels> > > Numerical for (int k = 0; k < testSim.size(); k++) { for(int j = 0; j < testPara->basicTestParameter->dataToCalc.size(); j++){ for (int i = 0; i < testPara->timeSteps.size(); i++) { - std::shared_ptr<L2NormTestBetweenKernels> aTest = L2NormTestBetweenKernels::getNewInstance(colorOutput, testPara->basicTestParameter->dataToCalc.at(j), testPara->timeSteps.at(i)); + std::shared_ptr<L2NormTestBetweenKernels> aTest = L2NormTestBetweenKernels::getNewInstance(colorOutput, testPara->basicTestParameter->dataToCalc.at(j), testPara->timeSteps.at(i), testPara->normalizeWith); aTest->setBasicSimulation(testSim.at(k), testSim.at(k)->getSimulationInfo(), postProcessingStrategies.at(k)); testSim.at(k)->registerSimulationObserver(aTest); testForOneKernel.push_back(aTest); diff --git a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h index ae895b65ee9701e18429d37cc16e818b7052ad05..06f360f94392b8e540958462b6037d0e0094e58a 100644 --- a/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h +++ b/targets/tests/NumericalTests/Utilities/NumericalTestFactory/NumericalTestFactoryImp.h @@ -23,6 +23,7 @@ struct VectorWriterInformationStruct; class AnalyticalResults2DToVTKWriter; class BasicTestLogFileInformation; class ColorConsoleOutput; +class L2NormCalculatorFactory; class L2NormTest; class L2NormPostProcessingStrategy; class L2NormBetweenKernelPostProcessingStrategy; @@ -69,7 +70,7 @@ private: std::shared_ptr<L2NormTestStruct> makeL2NormTestsStructs(std::shared_ptr<L2NormTestParameterStruct> testParameter, std::vector<std::shared_ptr<TestSimulationImp> > testSimumlations); std::shared_ptr<L2NormTestBetweenKernelsStruct> makeL2NormTestsBetweenKernelsStructs(std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> testPara, std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::string kernelName); std::vector<std::shared_ptr<PhiAndNyTest> > makePhiAndNyTests(std::shared_ptr<PhiAndNyTestParameterStruct> testParameter, std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::shared_ptr<PhiAndNyTestPostProcessingStrategy> > phiAndNuPostProStrategy, double viscosity, std::string dataToCalculate); - std::vector<std::shared_ptr<L2NormTest> > makeL2NormTests(std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > postProStrategy, std::shared_ptr<L2NormTestParameterStruct> testParameter); + std::vector<std::shared_ptr<L2NormTest> > makeL2NormTests(std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::vector<std::shared_ptr<L2NormPostProcessingStrategy> > > postProStrategy, std::shared_ptr<L2NormTestParameterStruct> testParameter); std::vector<std::vector<std::shared_ptr<L2NormTestBetweenKernels> > > makeL2NormTestsBetweenKernels(std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> testPara, std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> > postProcessingStrategies); std::vector<std::shared_ptr<L2NormTestBetweenKernels> > linkL2NormTestsBetweenKernels(std::shared_ptr<L2NormTestBetweenKernelsParameterStruct> testPara, std::vector<std::shared_ptr<TestSimulationImp> > testSim, std::vector<std::shared_ptr<L2NormBetweenKernelPostProcessingStrategy> > postProcessingStrategies); @@ -86,6 +87,7 @@ private: std::shared_ptr<ColorConsoleOutput> colorOutput; std::shared_ptr<AnalyticalResults2DToVTKWriter> anaResultWriter; std::shared_ptr<BasicTestLogFileInformation> basicTestLogFileInfo; + std::shared_ptr<L2NormCalculatorFactory> l2NormCalculatorFactory; int simID; int numberOfSimulations; diff --git a/targets/tests/NumericalTests/config.txt b/targets/tests/NumericalTests/config.txt index e735e0696d2459c40dc8528207f6b634995a3f7f..8e5bc52e915367f48fcc6b5f852136a7ffc0a76c 100644 --- a/targets/tests/NumericalTests/config.txt +++ b/targets/tests/NumericalTests/config.txt @@ -6,8 +6,7 @@ Devices="1" ################################################## # Basic Simulation Parameter # ################################################## -KernelsToTest="CumulantOneCompSP27" - CumulantAA2016CompSP27 CumulantAll4CompSP27" +KernelsToTest="CumulantOneCompSP27 CumulantAA2016CompSP27 CumulantAll4CompSP27" NumberOfTimeSteps=20 Viscosity="0.001" Rho0=1.0 @@ -50,8 +49,13 @@ EndTimeStepCalculation_PhiNu=20 ################################################## # L2-Norm Test Parameter # ################################################## -L2NormTest=true -MaxL2NormDiff=2.5 +L2NormTest=false + +NormalizeWithBasicData=true +MaxL2NormDiffBasicData=0.5 +NormalizeWithAmplitude=true +MaxL2NormDiffAmplitude=2.5 + DataToCalc_L2="Vx Vz" BasicTimeStep_L2=0 DivergentTimeStep_L2=20 @@ -59,10 +63,11 @@ DivergentTimeStep_L2=20 ################################################## # L2-Norm Test Between Kernels Parameter # ################################################## -L2NormBetweenKernelsTest=false +L2NormBetweenKernelsTest=true BasicKernel_L2NormBetweenKernels=CumulantOneCompSP27 Timesteps_L2NormBetweenKernels="0 20" DataToCalc_L2NormBetweenKernels="Vx Vz" +NormalizeWith=amplitude ################################################## # Simulation To Perform # @@ -99,10 +104,10 @@ GridPath512="C:\Users\Timon\Documents\studienarbeitIRMB\grids\gridUni512x4x768" ################################################## # File Writing Information # ################################################## -WriteVTKFiles=true +WriteVTKFiles=false PathForVTKFileWriting="C:\Users\Timon\Documents\studienarbeitIRMB\Output" StartStepFileWriter=0 -WriteAnalyResultsToVTK=true +WriteAnalyResultsToVTK=false PathLogFile="C:\Users\Timon\Documents\studienarbeitIRMB\logFiles" \ No newline at end of file