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

divides ConfigFileReader in ConfigFileReader and NumericalTestFactory

parent c9392ff6
No related branches found
No related tags found
No related merge requests found
#ifndef CONFIGFILE_DATA_H
#define CONFIGFILE_DATA_H
#include "LBM\LB.h"
#include <vector>
struct ConfigDataStruct
{
std::vector<double> u0SW, v0SW;
std::vector<double> amplitudeTGV, u0TGV;
bool nuAndPhiTestTGV, nuAndPhiTestSW;
bool l2NormTestTGV, l2NormTestSW;
std::string dataToCalcPhiAndNuTest, dataToCalcL2Test;
std::vector<double> viscosity;
real rho0;
real l0;
double minOrderOfAccuracy;
double maxL2NormDiff;
unsigned int numberOfTimeSteps, basisTimeStepLength;
unsigned int startStepCalculationPhiNu, endStepCalculationPhiNu;
unsigned int basicTimeStepL2Norm, divergentTimeStepL2Norm;
unsigned int startStepFileWriter;
unsigned int ySliceForCalculation;
unsigned int maxLevel;
unsigned int numberOfGridLevels;
bool writeFiles;
std::string filePath;
std::string logFilePath;
std::vector< std::string> kernelsToTest;
std::vector< std::string> grids;
std::vector< real> lx;
std::vector< real> lz;
std::vector< int> devices;
std::vector< bool> tgv;
std::vector< bool> sw;
};
#endif
\ No newline at end of file
#include "ConfigFileReader.h"
#include <fstream>
#include <iostream>
#include "utilities/input/Input.h"
#include "utilities/StringUtil/StringUtil.h"
#include "Utilities/TestSimulation/TestSimulationImp.h"
#include "Utilities\TestQueue\TestQueueImp.h"
#include "Utilities\LogFileWriter\LogFileWriter.h"
#include "Utilities\LogFileQueue\LogFileQueueImp.h"
#include "Simulation/TaylorGreenVortex/SimulationParameter/TaylorGreenSimulationParameter.h"
#include "Simulation/TaylorGreenVortex/LogFileInformation/TaylorGreenLogFileInformation.h"
#include "Simulation\TaylorGreenVortex\SimulationInfo\TaylorGreenVortexSimulationInfo.h"
#include "Simulation\TaylorGreenVortex\AnalyticalResults\TaylorGreenVortexAnalyticalResults.h"
#include "Simulation/ShearWave/SimulationParameter/ShearWaveSimulationParameter.h"
#include "Simulation/ShearWave/LogFileInformation/ShearWaveLogFileInformation.h"
#include "Simulation\ShearWave\SimulationInfo\ShearWaveSimulationInfo.h"
#include "Simulation\ShearWave\AnalyticalResults\ShearWaveAnalyticalResults.h"
#include "Tests/PhiAndNuTest/PhiAndNuTest.h"
#include "Tests\PhiAndNuTest\LogFileInformation\PhiAndNuLogFileInformation.h"
#include "Tests\L2NormTest\L2NormTest.h"
#include "Tests\L2NormTest\LogFileInformation\L2NormLogFileInformation.h"
#include "Utilities/LogFileInformation/LogFileInformation.h"
#include "Utilities/LogFileInformation/BasicSimulationInfo/BasicSimulationInfo.h"
#include "Utilities\LogFileInformation\LogFileTimeInformation\LogFileTimeInformation.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutputImp.h"
#include <fstream>
#include <iostream>
std::shared_ptr<ConfigFileReader> ConfigFileReader::getNewInstance()
std::shared_ptr<ConfigFileReader> ConfigFileReader::getNewInstance(const std::string aFilePath)
{
return std::shared_ptr<ConfigFileReader>(new ConfigFileReader());
return std::shared_ptr<ConfigFileReader>(new ConfigFileReader(aFilePath));
}
ConfigFileReader::ConfigFileReader()
ConfigFileReader::ConfigFileReader(const std::string aFilePath)
{
logInfo.resize(0);
testSimulation.resize(0);
configData = std::shared_ptr< ConfigDataStruct>(new ConfigDataStruct);
lx.resize(5);
lx.at(0) = 32.0;
lx.at(1) = 64.0;
lx.at(2) = 128.0;
lx.at(3) = 256.0;
lx.at(4) = 512.0;
configData->lx.resize(5);
configData->lx.at(0) = 32.0;
configData->lx.at(1) = 64.0;
configData->lx.at(2) = 128.0;
configData->lx.at(3) = 256.0;
configData->lx.at(4) = 512.0;
lz.resize(5);
lz.at(0) = lx.at(0) * 3.0 / 2.0;
lz.at(1) = lx.at(1) * 3.0 / 2.0;
lz.at(2) = lx.at(2) * 3.0 / 2.0;
lz.at(3) = lx.at(3) * 3.0 / 2.0;
lz.at(4) = lx.at(4) * 3.0 / 2.0;
configData->lz.resize(5);
configData->lz.at(0) = configData->lx.at(0) * 3.0 / 2.0;
configData->lz.at(1) = configData->lx.at(1) * 3.0 / 2.0;
configData->lz.at(2) = configData->lx.at(2) * 3.0 / 2.0;
configData->lz.at(3) = configData->lx.at(3) * 3.0 / 2.0;
configData->lz.at(4) = configData->lx.at(4) * 3.0 / 2.0;
l0 = 32.0;
rho0 = 1.0;
configData->l0 = 32.0;
configData->rho0 = 1.0;
colorOutput = ColorConsoleOutputImp::getInstance();
testQueue = TestQueueImp::getNewInstance(colorOutput);
readConfigFile(aFilePath);
}
void ConfigFileReader::readConfigFile(const std::string aFilePath)
......@@ -74,259 +44,72 @@ void ConfigFileReader::readConfigFile(const std::string aFilePath)
std::unique_ptr<input::Input> input = input::Input::makeInput(stream, "config");
devices = StringUtil::toIntVector(input->getValue("Devices"));
kernelsToTest = StringUtil::toStringVector(input->getValue("KernelsToTest"));
viscosity = StringUtil::toDoubleVector(input->getValue("Viscosity"));
minOrderOfAccuracy = StringUtil::toDouble(input->getValue("MinOrderOfAccuracy"));
dataToCalcPhiAndNuTest = StringUtil::toString(input->getValue("DataToCalc_PhiAndNu"));
startStepCalculationPhiNu = StringUtil::toInt(input->getValue("StartTimeStepCalculation_PhiNu"));
endStepCalculationPhiNu = StringUtil::toInt(input->getValue("EndTimeStepCalculation_PhiNu"));
maxL2NormDiff = StringUtil::toDouble(input->getValue("MaxL2NormDiff"));
dataToCalcL2Test = StringUtil::toString(input->getValue("DataToCalc_L2"));
basicTimeStepL2Norm = StringUtil::toInt(input->getValue("BasicTimeStep_L2"));
divergentTimeStepL2Norm = StringUtil::toInt(input->getValue("DivergentTimeStep_L2"));
amplitudeTGV = StringUtil::toDoubleVector(input->getValue("Amplitude_TGV"));
u0TGV = StringUtil::toDoubleVector(input->getValue("u0_TGV"));
nuAndPhiTestTGV = StringUtil::toBool(input->getValue("PhiAndNuTest_TGV"));
l2NormTestTGV = StringUtil::toBool(input->getValue("L2NormTest_TGV"));
v0SW = StringUtil::toDoubleVector(input->getValue("v0_SW"));
u0SW = StringUtil::toDoubleVector(input->getValue("u0_SW"));
nuAndPhiTestSW = StringUtil::toBool(input->getValue("PhiAndNuTest_SW"));
l2NormTestSW = StringUtil::toBool(input->getValue("L2NormTest_SW"));
numberOfTimeSteps = StringUtil::toInt(input->getValue("NumberOfTimeSteps"));
basisTimeStepLength = StringUtil::toInt(input->getValue("BasisTimeStepLength"));
grids.resize(5);
grids.at(0) = input->getValue("GridPath32");
grids.at(1) = input->getValue("GridPath64");
grids.at(2) = input->getValue("GridPath128");
grids.at(3) = input->getValue("GridPath256");
grids.at(4) = input->getValue("GridPath512");
numberOfGridLevels = StringUtil::toInt(input->getValue("NumberOfGridLevels"));
maxLevel = numberOfGridLevels - 1;
ySliceForCalculation = StringUtil::toInt(input->getValue("ySliceForCalculation"));
writeFiles = StringUtil::toBool(input->getValue("WriteFiles"));
filePath = input->getValue("PathForFileWriting");
startStepFileWriter = StringUtil::toInt(input->getValue("StartStepFileWriter"));
logFilePath = input->getValue("PathLogFile");;
tgv.resize(5);
tgv.at(0) = StringUtil::toBool(input->getValue("TaylorGreenVortex32"));
tgv.at(1) = StringUtil::toBool(input->getValue("TaylorGreenVortex64"));
tgv.at(2) = StringUtil::toBool(input->getValue("TaylorGreenVortex128"));
tgv.at(3) = StringUtil::toBool(input->getValue("TaylorGreenVortex256"));
tgv.at(4) = StringUtil::toBool(input->getValue("TaylorGreenVortex512"));
sw.resize(5);
sw.at(0) = StringUtil::toBool(input->getValue("ShearWave32"));
sw.at(1) = StringUtil::toBool(input->getValue("ShearWave64"));
sw.at(2) = StringUtil::toBool(input->getValue("ShearWave128"));
sw.at(3) = StringUtil::toBool(input->getValue("ShearWave256"));
sw.at(4) = StringUtil::toBool(input->getValue("ShearWave512"));
configData->devices = StringUtil::toIntVector(input->getValue("Devices"));
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->startStepCalculationPhiNu = StringUtil::toInt(input->getValue("StartTimeStepCalculation_PhiNu"));
configData->endStepCalculationPhiNu = StringUtil::toInt(input->getValue("EndTimeStepCalculation_PhiNu"));
configData->maxL2NormDiff = StringUtil::toDouble(input->getValue("MaxL2NormDiff"));
configData->dataToCalcL2Test = StringUtil::toString(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"));
configData->u0TGV = StringUtil::toDoubleVector(input->getValue("u0_TGV"));
configData->nuAndPhiTestTGV = StringUtil::toBool(input->getValue("PhiAndNuTest_TGV"));
configData->l2NormTestTGV = StringUtil::toBool(input->getValue("L2NormTest_TGV"));
configData->v0SW = StringUtil::toDoubleVector(input->getValue("v0_SW"));
configData->u0SW = StringUtil::toDoubleVector(input->getValue("u0_SW"));
configData->nuAndPhiTestSW = StringUtil::toBool(input->getValue("PhiAndNuTest_SW"));
configData->l2NormTestSW = StringUtil::toBool(input->getValue("L2NormTest_SW"));
configData->numberOfTimeSteps = StringUtil::toInt(input->getValue("NumberOfTimeSteps"));
configData->basisTimeStepLength = StringUtil::toInt(input->getValue("BasisTimeStepLength"));
configData->grids.resize(5);
configData->grids.at(0) = input->getValue("GridPath32");
configData->grids.at(1) = input->getValue("GridPath64");
configData->grids.at(2) = input->getValue("GridPath128");
configData->grids.at(3) = input->getValue("GridPath256");
configData->grids.at(4) = input->getValue("GridPath512");
configData->numberOfGridLevels = StringUtil::toInt(input->getValue("NumberOfGridLevels"));
configData->maxLevel = configData->numberOfGridLevels - 1;
configData->ySliceForCalculation = StringUtil::toInt(input->getValue("ySliceForCalculation"));
configData->writeFiles = StringUtil::toBool(input->getValue("WriteFiles"));
configData->filePath = input->getValue("PathForFileWriting");
configData->startStepFileWriter = StringUtil::toInt(input->getValue("StartStepFileWriter"));
configData->logFilePath = input->getValue("PathLogFile");;
configData->tgv.resize(5);
configData->tgv.at(0) = StringUtil::toBool(input->getValue("TaylorGreenVortex32"));
configData->tgv.at(1) = StringUtil::toBool(input->getValue("TaylorGreenVortex64"));
configData->tgv.at(2) = StringUtil::toBool(input->getValue("TaylorGreenVortex128"));
configData->tgv.at(3) = StringUtil::toBool(input->getValue("TaylorGreenVortex256"));
configData->tgv.at(4) = StringUtil::toBool(input->getValue("TaylorGreenVortex512"));
configData->sw.resize(5);
configData->sw.at(0) = StringUtil::toBool(input->getValue("ShearWave32"));
configData->sw.at(1) = StringUtil::toBool(input->getValue("ShearWave64"));
configData->sw.at(2) = StringUtil::toBool(input->getValue("ShearWave128"));
configData->sw.at(3) = StringUtil::toBool(input->getValue("ShearWave256"));
configData->sw.at(4) = StringUtil::toBool(input->getValue("ShearWave512"));
stream.close();
checkConfigFileData();
logFileWriterQueue = LogFileQueueImp::getNewInstance(logFilePath);
}
init();
std::shared_ptr<ConfigDataStruct> ConfigFileReader::getConfigData()
{
return configData;
}
void ConfigFileReader::checkConfigFileData()
{
if (u0TGV.size() != amplitudeTGV.size()) {
if (configData->u0TGV.size() != configData->amplitudeTGV.size()) {
std::cout << "Length u0_TGV is unequal to Lenght Amplitude_TGV!" << std::endl << std::flush;
exit(1);
}
if (u0SW.size() != v0SW.size()) {
if (configData->u0SW.size() != configData->v0SW.size()) {
std::cout << "Length u0_SW is unequal to Lenght v0_SW!" << std::endl << std::flush;
exit(1);
}
}
void ConfigFileReader::init()
{
for (int i = 0; i < kernelsToTest.size(); i++) {
simID = 1;
for (int j = 0; j < viscosity.size(); j++) {
for (int k = 0; k < u0TGV.size(); k++) {
if (shouldSimulationGroupRun(tgv))
makeTaylorGreenSimulations(kernelsToTest.at(i), viscosity.at(j), u0TGV.at(k), amplitudeTGV.at(k));
}
for (int k = 0; k < u0SW.size(); k++) {
if (shouldSimulationGroupRun(sw))
makeShearWaveSimulations(kernelsToTest.at(i), viscosity.at(j), u0SW.at(k), v0SW.at(k));
}
}
}
}
std::vector< std::shared_ptr< TestSimulation>> ConfigFileReader::buildTestSimulation(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo)
{
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));
simID++;
}
return testSim;
}
void ConfigFileReader::makeTaylorGreenSimulations(std::string kernelName, double viscosity, double u0, double amplitude)
{
std::vector< std::shared_ptr< SimulationParameter>> simParaTGV;
std::vector< std::shared_ptr< SimulationInfo>> simInfoTGV;
std::vector< std::shared_ptr< AnalyticalResults>> analyResultTGV;
for (int i = 0; i < tgv.size(); i++) {
if (tgv.at(i)) {
simParaTGV.push_back(TaylorGreenSimulationParameter::getNewInstance(kernelName, u0, amplitude, viscosity, rho0, lx.at(i), lz.at(i), l0, numberOfTimeSteps, basisTimeStepLength, calcStartStepForToVectorWriter(), ySliceForCalculation, grids.at(i), maxLevel, numberOfGridLevels, writeFiles, startStepFileWriter, filePath, devices));
simInfoTGV.push_back(TaylorGreenVortexSimulationInfo::getNewInstance(u0, amplitude, l0, lx.at(i), viscosity, kernelName));
analyResultTGV.push_back(TaylorGreenAnalyticalResults::getNewInstance(viscosity, u0, amplitude, l0, rho0));
}
}
std::shared_ptr< TaylorGreenInformation> tgInfo = TaylorGreenInformation::getNewInstance(u0, amplitude, tgv, lx, l0);
makePeriodicBoundaryConditionSimulationAndTests(simParaTGV, simInfoTGV, analyResultTGV, tgInfo, kernelName, tgv, viscosity, nuAndPhiTestTGV, l2NormTestTGV);
}
void ConfigFileReader::makeShearWaveSimulations(std::string kernelName, double viscosity, double u0, double v0)
{
std::vector< std::shared_ptr< SimulationParameter>> simParaSW;
std::vector< std::shared_ptr< SimulationInfo>> simInfoSW;
std::vector< std::shared_ptr< AnalyticalResults>> analyResultSW;
for (int i = 0; i < sw.size(); i++)
if (sw.at(i)) {
simParaSW.push_back(ShearWaveSimulationParameter::getNewInstance(kernelName, u0, v0, viscosity, rho0, lx.at(i), lz.at(i), l0, numberOfTimeSteps, basisTimeStepLength, calcStartStepForToVectorWriter(), ySliceForCalculation, grids.at(i), maxLevel, numberOfGridLevels, writeFiles, startStepFileWriter, filePath, devices));
simInfoSW.push_back(ShearWaveSimulationInfo::getNewInstance(u0, v0, l0, lx.at(i), viscosity, kernelName));
analyResultSW.push_back(ShearWaveAnalyticalResults::getNewInstance(viscosity, u0, v0, l0, rho0));
}
std::shared_ptr< ShearWaveInformation> swInfo = ShearWaveInformation::getNewInstance(u0, v0, sw, lx, l0);
makePeriodicBoundaryConditionSimulationAndTests(simParaSW, simInfoSW, analyResultSW, swInfo, kernelName, sw, viscosity, nuAndPhiTestSW, l2NormTestSW);
}
void ConfigFileReader::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< TestLogFileInformation>> testLogFileInfo;
if (nuAndPhiTest && checkNuAndPhiTestCouldRun(simulationsRun)) {
std::vector< std::shared_ptr< PhiAndNuTest>> phiAndNuTests = makePhiAndNuTests(testSim, simInfo, viscosity);
std::shared_ptr< PhiAndNuInformation> phiNuLogFileInfo = PhiAndNuInformation::getNewInstance(phiAndNuTests);
testLogFileInfo.push_back(phiNuLogFileInfo);
}
if (l2NormTest) {
std::vector< std::shared_ptr< L2NormTest>> l2NormTests = makeL2NormTests(testSim, simInfo, analyResult);
std::shared_ptr< L2NormInformation> l2NormLogFileInfo = L2NormInformation::getNewInstance(l2NormTests);
testLogFileInfo.push_back(l2NormLogFileInfo);
}
for (int i = 0; i < testSim.size(); i++)
testSimulation.push_back(testSim.at(i));
std::shared_ptr< LogFileTimeInformation> logFileTimeInfo = LogFileTimeInformation::getNewInstance(testSim, writeFiles);
makeLogFileWriter(testLogFileInfo, logFileTimeInfo, simlogFileInfo, kernelName, viscosity);
}
std::vector< std::shared_ptr< PhiAndNuTest>> ConfigFileReader::makePhiAndNuTests(std::vector< std::shared_ptr< TestSimulation>> testSim, std::vector< std::shared_ptr< SimulationInfo>> simInfo, 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, dataToCalcPhiAndNuTest, minOrderOfAccuracy, viscosity, startStepCalculationPhiNu, endStepCalculationPhiNu);
test->addSimulation(testSim.at(j), simInfo.at(j));
test->addSimulation(testSim.at(i), simInfo.at(i));
testSim.at(j)->registerSimulationObserver(test);
testSim.at(i)->registerSimulationObserver(test);
phiAndNuTests.push_back(test);
testQueue->addTest(test);
}
}
return phiAndNuTests;
}
std::vector<std::shared_ptr<L2NormTest>> ConfigFileReader::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>> l2Tests;
for (int i = 0; i < testSim.size(); i++) {
std::shared_ptr<L2NormTest> test = L2NormTest::getNewInstance(analyticalResults.at(i), colorOutput, dataToCalcL2Test, maxL2NormDiff, basicTimeStepL2Norm, divergentTimeStepL2Norm);
test->addSimulation(testSim.at(i), simInfo.at(i));
testSim.at(i)->registerSimulationObserver(test);
l2Tests.push_back(test);
testQueue->addTest(test);
}
return l2Tests;
}
bool ConfigFileReader::shouldSimulationGroupRun(std::vector<bool> test)
{
for (int i = 0; i < test.size(); i++) {
if (test.at(i))
return true;
}
return false;
}
bool ConfigFileReader::checkNuAndPhiTestCouldRun(std::vector<bool> test)
{
int numberOfTestInGroup = 0;
for (int i = 0; i < test.size(); i++) {
if (test.at(i))
numberOfTestInGroup++;
}
return numberOfTestInGroup > 1;
}
unsigned int ConfigFileReader::calcStartStepForToVectorWriter()
{
std::vector< unsigned int> startStepsTests;
startStepsTests.push_back(basicTimeStepL2Norm);
startStepsTests.push_back(startStepCalculationPhiNu);
std::sort(startStepsTests.begin(), startStepsTests.end());
return startStepsTests.at(0);
}
void ConfigFileReader::makeLogFileWriter(std::vector< std::shared_ptr< TestLogFileInformation>> testLogFiles, std::shared_ptr< LogFileTimeInformation> logFileTimeInfo, std::shared_ptr<SimulationLogFileInformation> simLogInfo, std::string kernelName, double viscosity)
{
std::shared_ptr< LogFileWriter> logFileWriter = LogFileWriter::getNewInstance(testLogFiles, logFileTimeInfo, simLogInfo, kernelName, viscosity, devices, numberOfTimeSteps, basisTimeStepLength, calcStartStepForToVectorWriter());
logFileWriterQueue->addLogFileWriter(logFileWriter);
}
std::vector<std::shared_ptr<TestSimulation>> ConfigFileReader::getTestSimulations()
{
return testSimulation;
}
std::shared_ptr<TestQueue> ConfigFileReader::getTestQueue()
{
return testQueue;
}
std::shared_ptr<LogFileQueue> ConfigFileReader::getLogFileQueue()
{
return logFileWriterQueue;
}
\ No newline at end of file
#ifndef CONFIG_FILE_READER_H
#define CONFIG_FILE_READER_H
#include "LBM\LB.h"
#include "ConfigData.h"
#include <memory>
#include <vector>
#include <string>
class SimulationParameter;
class SimulationInfo;
class TestCout;
class PhiAndNuTest;
class L2NormTest;
class TestSimulation;
class TestQueueImp;
class TestQueue;
class LogFileQueueImp;
class LogFileQueue;
class LogFileInformation;
class LogFileTimeInformation;
class TestLogFileInformation;
class SimulationLogFileInformation;
class AnalyticalResults;
class ColorConsoleOutput;
class ConfigFileReader
{
public:
static std::shared_ptr< ConfigFileReader> getNewInstance();
void readConfigFile(const std::string aFilePath);
std::vector< std::shared_ptr< TestSimulation>> getTestSimulations();
std::shared_ptr< TestQueue> getTestQueue();
std::shared_ptr< LogFileQueue> getLogFileQueue();
protected:
ConfigFileReader();
static std::shared_ptr< ConfigFileReader> getNewInstance(const std::string aFilePath);
std::shared_ptr< ConfigDataStruct> getConfigData();
private:
ConfigFileReader() {};
ConfigFileReader(const std::string aFilePath);
void readConfigFile(const std::string aFilePath);
void checkConfigFileData();
void init();
void makeLogFileWriter(std::vector< std::shared_ptr< TestLogFileInformation>> testLogFiles, std::shared_ptr< LogFileTimeInformation> logFileTimeInfo, std::shared_ptr< SimulationLogFileInformation> simLogInfo, std::string kernelName, double viscosity);
std::vector< std::shared_ptr< TestSimulation>> buildTestSimulation(std::vector< std::shared_ptr< SimulationParameter>> simPara, std::vector< std::shared_ptr< SimulationInfo>> simInfo);
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< 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);
bool shouldSimulationGroupRun(std::vector<bool> test);
bool checkNuAndPhiTestCouldRun(std::vector<bool> test);
unsigned int calcStartStepForToVectorWriter();
std::vector<double> u0SW, v0SW;
std::vector<double> amplitudeTGV, u0TGV;
bool nuAndPhiTestTGV, nuAndPhiTestSW;
bool l2NormTestTGV, l2NormTestSW;
std::string dataToCalcPhiAndNuTest, dataToCalcL2Test;
std::vector<double> viscosity;
real rho0;
real l0;
double minOrderOfAccuracy;
double maxL2NormDiff;
unsigned int numberOfTimeSteps, basisTimeStepLength;
unsigned int startStepCalculationPhiNu, endStepCalculationPhiNu;
unsigned int basicTimeStepL2Norm, divergentTimeStepL2Norm;
unsigned int startStepFileWriter;
unsigned int ySliceForCalculation;
unsigned int maxLevel;
unsigned int numberOfGridLevels;
bool writeFiles;
std::string filePath;
std::string logFilePath;
std::vector< std::string> kernelsToTest;
std::vector< std::string> grids;
std::vector< real> lx;
std::vector< real> lz;
std::vector< int> devices;
std::vector< bool> tgv;
std::vector< bool> sw;
std::vector< std::shared_ptr< LogFileInformation> > logInfo;
std::vector< std::shared_ptr< TestSimulation>> testSimulation;
std::shared_ptr< TestQueueImp> testQueue;
std::shared_ptr< ColorConsoleOutput> colorOutput;
std::shared_ptr< LogFileQueueImp> logFileWriterQueue;
int simID;
std::shared_ptr< ConfigDataStruct> configData;
};
#endif
\ No newline at end of file
#ifndef NUMERICAL_TEST_FACTORY_H
#define NUMERICAL_TEST_FACTORY_H
#include <memory>
#include <vector>
class TestSimulation;
class TestQueue;
class LogFileQueue;
class NumericalTestFactory
{
public:
virtual std::vector< std::shared_ptr< TestSimulation>> getTestSimulations() = 0;
virtual std::shared_ptr< TestQueue> getTestQueue() = 0;
virtual std::shared_ptr< LogFileQueue> getLogFileQueue() = 0;
private:
};
#endif
\ No newline at end of file
#include "NumericalTestFactoryImp.h"
#include "Simulation/TaylorGreenVortex/SimulationParameter/TaylorGreenSimulationParameter.h"
#include "Simulation/TaylorGreenVortex/LogFileInformation/TaylorGreenLogFileInformation.h"
#include "Simulation\TaylorGreenVortex\SimulationInfo\TaylorGreenVortexSimulationInfo.h"
#include "Simulation\TaylorGreenVortex\AnalyticalResults\TaylorGreenVortexAnalyticalResults.h"
#include "Simulation/ShearWave/SimulationParameter/ShearWaveSimulationParameter.h"
#include "Simulation/ShearWave/LogFileInformation/ShearWaveLogFileInformation.h"
#include "Simulation\ShearWave\SimulationInfo\ShearWaveSimulationInfo.h"
#include "Simulation\ShearWave\AnalyticalResults\ShearWaveAnalyticalResults.h"
#include "Tests/PhiAndNuTest/PhiAndNuTest.h"
#include "Tests\PhiAndNuTest\LogFileInformation\PhiAndNuLogFileInformation.h"
#include "Tests\L2NormTest\L2NormTest.h"
#include "Tests\L2NormTest\LogFileInformation\L2NormLogFileInformation.h"
#include "Utilities\ColorConsoleOutput\ColorConsoleOutputImp.h"
#include "Utilities\LogFileInformation\LogFileTimeInformation\LogFileTimeInformation.h"
#include "Utilities\LogFileWriter\LogFileWriter.h"
#include "Utilities\LogFileQueue\LogFileQueueImp.h"
#include "Utilities\TestQueue\TestQueueImp.h"
#include "Utilities/TestSimulation/TestSimulationImp.h"
#include <algorithm>
std::shared_ptr<NumericalTestFactoryImp> NumericalTestFactoryImp::getNewInstance(std::shared_ptr<ConfigDataStruct> configFileData)
{
return std::shared_ptr<NumericalTestFactoryImp>(new NumericalTestFactoryImp(configFileData));
}
NumericalTestFactoryImp::NumericalTestFactoryImp(std::shared_ptr<ConfigDataStruct> configFileData) : cfd(configFileData)
{
colorOutput = ColorConsoleOutputImp::getInstance();
testQueue = TestQueueImp::getNewInstance(colorOutput);
logFileWriterQueue = LogFileQueueImp::getNewInstance(cfd->logFilePath);
init();
}
std::vector<std::shared_ptr<TestSimulation>> NumericalTestFactoryImp::getTestSimulations()
{
return testSimulations;
}
std::shared_ptr<TestQueue> NumericalTestFactoryImp::getTestQueue()
{
return testQueue;
}
std::shared_ptr<LogFileQueue> NumericalTestFactoryImp::getLogFileQueue()
{
return logFileWriterQueue;
}
void NumericalTestFactoryImp::init()
{
for (int i = 0; i < cfd->kernelsToTest.size(); i++) {
simID = 1;
for (int j = 0; j < cfd->viscosity.size(); j++) {
for (int k = 0; k < cfd->u0TGV.size(); k++) {
if (shouldSimulationGroupRun(cfd->tgv))
makeTaylorGreenSimulations(cfd->kernelsToTest.at(i), cfd->viscosity.at(j), cfd->u0TGV.at(k), cfd->amplitudeTGV.at(k));
}
for (int k = 0; k < cfd->u0SW.size(); k++) {
if (shouldSimulationGroupRun(cfd->sw))
makeShearWaveSimulations(cfd->kernelsToTest.at(i), cfd->viscosity.at(j), cfd->u0SW.at(k), cfd->v0SW.at(k));
}
}
}
}
void NumericalTestFactoryImp::makeTaylorGreenSimulations(std::string kernelName, double viscosity, double u0, double amplitude)
{
std::vector< std::shared_ptr< SimulationParameter>> simParaTGV;
std::vector< std::shared_ptr< SimulationInfo>> simInfoTGV;
std::vector< std::shared_ptr< AnalyticalResults>> analyResultTGV;
for (int i = 0; i < cfd->tgv.size(); i++) {
if (cfd->tgv.at(i)) {
simParaTGV.push_back(TaylorGreenSimulationParameter::getNewInstance(kernelName, u0, amplitude, viscosity, cfd->rho0, cfd->lx.at(i), cfd->lz.at(i), cfd->l0, cfd->numberOfTimeSteps, cfd->basisTimeStepLength, calcStartStepForToVectorWriter(), cfd->ySliceForCalculation, cfd->grids.at(i), cfd->maxLevel, cfd->numberOfGridLevels, cfd->writeFiles, cfd->startStepFileWriter, cfd->filePath, cfd->devices));
simInfoTGV.push_back(TaylorGreenVortexSimulationInfo::getNewInstance(u0, amplitude, cfd->l0, cfd->lx.at(i), viscosity, kernelName));
analyResultTGV.push_back(TaylorGreenAnalyticalResults::getNewInstance(viscosity, u0, amplitude, cfd->l0, cfd->rho0));
}
}
std::shared_ptr< TaylorGreenInformation> tgInfo = TaylorGreenInformation::getNewInstance(u0, amplitude, cfd->tgv, cfd->lx, cfd->l0);
makePeriodicBoundaryConditionSimulationAndTests(simParaTGV, simInfoTGV, analyResultTGV, tgInfo, kernelName, cfd->tgv, viscosity, cfd->nuAndPhiTestTGV, cfd->l2NormTestTGV);
}
void NumericalTestFactoryImp::makeShearWaveSimulations(std::string kernelName, double viscosity, double u0, double v0)
{
std::vector< std::shared_ptr< SimulationParameter>> simParaSW;
std::vector< std::shared_ptr< SimulationInfo>> simInfoSW;
std::vector< std::shared_ptr< AnalyticalResults>> analyResultSW;
for (int i = 0; i < cfd->sw.size(); i++)
if (cfd->sw.at(i)) {
simParaSW.push_back(ShearWaveSimulationParameter::getNewInstance(kernelName, u0, v0, viscosity, cfd->rho0, cfd->lx.at(i), cfd->lz.at(i), cfd->l0, cfd->numberOfTimeSteps, cfd->basisTimeStepLength, calcStartStepForToVectorWriter(), cfd->ySliceForCalculation, cfd->grids.at(i), cfd->maxLevel, cfd->numberOfGridLevels, cfd->writeFiles, cfd->startStepFileWriter, cfd->filePath, cfd->devices));
simInfoSW.push_back(ShearWaveSimulationInfo::getNewInstance(u0, v0, cfd->l0, cfd->lx.at(i), viscosity, kernelName));
analyResultSW.push_back(ShearWaveAnalyticalResults::getNewInstance(viscosity, u0, v0, cfd->l0, cfd->rho0));
}
std::shared_ptr< ShearWaveInformation> swInfo = ShearWaveInformation::getNewInstance(u0, v0, cfd->sw, cfd->lx, cfd->l0);
makePeriodicBoundaryConditionSimulationAndTests(simParaSW, simInfoSW, analyResultSW, swInfo, kernelName, cfd->sw, viscosity, cfd->nuAndPhiTestSW, cfd->l2NormTestSW);
}
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< TestLogFileInformation>> testLogFileInfo;
if (nuAndPhiTest && checkNuAndPhiTestCouldRun(simulationsRun)) {
std::vector< std::shared_ptr< PhiAndNuTest>> phiAndNuTests = makePhiAndNuTests(testSim, simInfo, viscosity);
std::shared_ptr< PhiAndNuInformation> phiNuLogFileInfo = PhiAndNuInformation::getNewInstance(phiAndNuTests);
testLogFileInfo.push_back(phiNuLogFileInfo);
}
if (l2NormTest) {
std::vector< std::shared_ptr< L2NormTest>> l2NormTests = makeL2NormTests(testSim, simInfo, analyResult);
std::shared_ptr< L2NormInformation> l2NormLogFileInfo = L2NormInformation::getNewInstance(l2NormTests);
testLogFileInfo.push_back(l2NormLogFileInfo);
}
for (int i = 0; i < testSim.size(); i++)
testSimulations.push_back(testSim.at(i));
std::shared_ptr< LogFileTimeInformation> logFileTimeInfo = LogFileTimeInformation::getNewInstance(testSim, cfd->writeFiles);
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>> 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));
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>> 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->startStepCalculationPhiNu, cfd->endStepCalculationPhiNu);
test->addSimulation(testSim.at(j), simInfo.at(j));
test->addSimulation(testSim.at(i), simInfo.at(i));
testSim.at(j)->registerSimulationObserver(test);
testSim.at(i)->registerSimulationObserver(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>> 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);
}
return l2Tests;
}
void NumericalTestFactoryImp::makeLogFileWriter(std::vector<std::shared_ptr<TestLogFileInformation>> testLogFiles, std::shared_ptr<LogFileTimeInformation> logFileTimeInfo, std::shared_ptr<SimulationLogFileInformation> simLogInfo, std::string kernelName, double viscosity)
{
std::shared_ptr< LogFileWriter> logFileWriter = LogFileWriter::getNewInstance(testLogFiles, logFileTimeInfo, simLogInfo, kernelName, viscosity, cfd->devices, cfd->numberOfTimeSteps, cfd->basisTimeStepLength, calcStartStepForToVectorWriter());
logFileWriterQueue->addLogFileWriter(logFileWriter);
}
bool NumericalTestFactoryImp::shouldSimulationGroupRun(std::vector<bool> test)
{
for (int i = 0; i < test.size(); i++) {
if (test.at(i))
return true;
}
return false;
}
unsigned int NumericalTestFactoryImp::calcStartStepForToVectorWriter()
{
std::vector< unsigned int> startStepsTests;
startStepsTests.push_back(cfd->basicTimeStepL2Norm);
startStepsTests.push_back(cfd->startStepCalculationPhiNu);
std::sort(startStepsTests.begin(), startStepsTests.end());
return startStepsTests.at(0);
}
bool NumericalTestFactoryImp::checkNuAndPhiTestCouldRun(std::vector<bool> test)
{
int numberOfTestInGroup = 0;
for (int i = 0; i < test.size(); i++) {
if (test.at(i))
numberOfTestInGroup++;
}
return numberOfTestInGroup > 1;
}
#ifndef NUMERICAL_TEST_FACTORY_IMP_H
#define NUMERICAL_TEST_FACTORY_IMP_H
#include "NumericalTestFactory.h"
#include "Utilities\ConfigFileReader\ConfigData.h"
class AnalyticalResults;
class ColorConsoleOutput;
class L2NormTest;
class LogFileTimeInformation;
class LogFileQueueImp;
class PhiAndNuTest;
class SimulationInfo;
class SimulationLogFileInformation;
class SimulationParameter;
class TestQueueImp;
class TestLogFileInformation;
class NumericalTestFactoryImp : public NumericalTestFactory
{
public:
static std::shared_ptr< NumericalTestFactoryImp> getNewInstance(std::shared_ptr<ConfigDataStruct> configFileData);
std::vector< std::shared_ptr< TestSimulation>> getTestSimulations();
std::shared_ptr< TestQueue> getTestQueue();
std::shared_ptr< LogFileQueue> getLogFileQueue();
private:
NumericalTestFactoryImp() {};
NumericalTestFactoryImp(std::shared_ptr<ConfigDataStruct> configFileData);
void init();
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);
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);
unsigned int calcStartStepForToVectorWriter();
bool checkNuAndPhiTestCouldRun(std::vector<bool> test);
std::shared_ptr<ConfigDataStruct> cfd;
std::vector< std::shared_ptr< TestSimulation>> testSimulations;
std::shared_ptr< TestQueueImp> testQueue;
std::shared_ptr< LogFileQueueImp> logFileWriterQueue;
std::shared_ptr< ColorConsoleOutput> colorOutput;
int simID;
};
#endif
\ No newline at end of file
......@@ -2,19 +2,21 @@
#include "mpi.h"
#include "Utilities/ConfigFileReader/ConfigFileReader.h"
#include "Utilities\LogFileQueue\LogFileQueue.h"
#include "Utilities\NumericalTestFactory\NumericalTestFactoryImp.h"
#include "Utilities\TestQueue\TestQueue.h"
#include "Utilities\VirtualFluidSimulation\VirtualFluidSimulation.h"
#include "Utilities\VirtualFluidSimulationFactory\VirtualFluidSimulationFactoryImp.h"
#include "Utilities\TestQueue\TestQueue.h"
#include "Utilities\LogFileQueue\LogFileQueue.h"
static void startNumericalTests(const std::string &configFile)
{
std::shared_ptr< ConfigFileReader> configReader = ConfigFileReader::getNewInstance();
configReader->readConfigFile(configFile);
std::shared_ptr< ConfigFileReader> configReader = ConfigFileReader::getNewInstance(configFile);
std::shared_ptr< NumericalTestFactoryImp> numericalTestFactory = NumericalTestFactoryImp::getNewInstance(configReader->getConfigData());
std::vector< std::shared_ptr< TestSimulation> > testSim = configReader->getTestSimulations();
std::shared_ptr< TestQueue> testQueue = configReader->getTestQueue();
std::shared_ptr< LogFileQueue> logFileQueue = configReader->getLogFileQueue();
std::vector< std::shared_ptr< TestSimulation> > testSim = numericalTestFactory->getTestSimulations();
std::shared_ptr< TestQueue> testQueue = numericalTestFactory->getTestQueue();
std::shared_ptr< LogFileQueue> logFileQueue = numericalTestFactory->getLogFileQueue();
std::shared_ptr< VirtualFluidSimulationFactory> factory = VirtualFluidSimulationFactoryImp::getNewInstance();
std::vector< std::shared_ptr< VirtualFluidSimulation> > vfSimulations = factory->makeVirtualFluidSimulations(testSim);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment