Skip to content
Snippets Groups Projects
Commit 8e30a4dc authored by Anna's avatar Anna
Browse files

Add ability to read config files

parent 477e2516
No related branches found
No related tags found
1 merge request!122Merge changes from develop into open source
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
//======================================================================================= //=======================================================================================
#define _USE_MATH_DEFINES #define _USE_MATH_DEFINES
#include <exception> #include <exception>
#include <filesystem>
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <math.h> #include <math.h>
...@@ -46,8 +47,8 @@ ...@@ -46,8 +47,8 @@
#include "Core/LbmOrGks.h" #include "Core/LbmOrGks.h"
#include "Core/Logger/Logger.h" #include "Core/Logger/Logger.h"
#include "Core/VectorTypes.h" #include "Core/VectorTypes.h"
#include "config/ConfigurationFile.h"
#include "PointerDefinitions.h" #include "PointerDefinitions.h"
#include "config/ConfigurationFile.h"
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
...@@ -75,8 +76,7 @@ int main(int argc, char *argv[]) ...@@ -75,8 +76,7 @@ int main(int argc, char *argv[])
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// Simulation parameters // Simulation parameters
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
std::string outputPath("./output/Sphere"); const bool useConfigFile = true;
std::string simulationName("Sphere");
const real L = 1.0; const real L = 1.0;
const real Re = 1000.0; const real Re = 1000.0;
...@@ -95,6 +95,34 @@ int main(int argc, char *argv[]) ...@@ -95,6 +95,34 @@ int main(int argc, char *argv[])
logging::Logger::setDebugLevel(logging::Logger::Level::INFO_LOW); logging::Logger::setDebugLevel(logging::Logger::Level::INFO_LOW);
logging::Logger::timeStamp(logging::Logger::ENABLE); logging::Logger::timeStamp(logging::Logger::ENABLE);
logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE); logging::Logger::enablePrintedRankNumbers(logging::Logger::ENABLE);
//////////////////////////////////////////////////////////////////////////
// setup simulation parameters
//////////////////////////////////////////////////////////////////////////
SPtr<Parameter> para;
if (useConfigFile) {
//////////////////////////////////////////////////////////////////////////
// read simulation parameters from config file
//////////////////////////////////////////////////////////////////////////
// assuming that a config files is stored parallel to this file.
std::filesystem::path configPath = __FILE__;
// the config file's default name can be replaced by passing a command line argument
std::string configName("config.txt");
if (argc == 2) {
configName = argv[1];
std::cout << "Using configFile command line argument: " << configName << std::endl;
}
configPath.replace_filename(configName);
vf::basics::ConfigurationFile config;
config.load(configPath);
para = std::make_shared<Parameter>(config);
} else {
para = std::make_shared<Parameter>();
}
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// setup gridGenerator // setup gridGenerator
...@@ -120,12 +148,6 @@ int main(int argc, char *argv[]) ...@@ -120,12 +148,6 @@ int main(int argc, char *argv[])
gridBuilder->buildGrids(LBM, false); gridBuilder->buildGrids(LBM, false);
//////////////////////////////////////////////////////////////////////////
// setup simulation parameters
//////////////////////////////////////////////////////////////////////////
SPtr<Parameter> para =std::make_shared<Parameter>();
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
// compute parameters in lattice units // compute parameters in lattice units
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
...@@ -143,11 +165,6 @@ int main(int argc, char *argv[]) ...@@ -143,11 +165,6 @@ int main(int argc, char *argv[])
// set parameters // set parameters
////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////
para->setOutputPath(outputPath);
para->setOutputPrefix(simulationName);
para->setPathAndFilename(para->getOutputPath() + "/" + para->getOutputPrefix());
para->setPrintFiles(true); para->setPrintFiles(true);
para->setVelocityLB(velocityLB); para->setVelocityLB(velocityLB);
......
##################################################
# informations for Writing
##################################################
OutputPath = output/Sphere/
OutputPrefix = Sphere
##################################################
# simulation time
##################################################
# TimeEnd=100000
# TimeOut=1000
\ No newline at end of file
...@@ -35,10 +35,11 @@ ...@@ -35,10 +35,11 @@
#include <stdio.h> #include <stdio.h>
#include <stdlib.h> #include <stdlib.h>
#include <math.h> #include <math.h>
#include "Core/Logger/Logger.h"
Parameter::Parameter() Parameter::Parameter()
{ {
this->setOutputPath("C:/Output/"); this->setOutputPath("output/");
this->setOutputPrefix("MyFile"); this->setOutputPrefix("MyFile");
...@@ -68,7 +69,7 @@ Parameter::Parameter() ...@@ -68,7 +69,7 @@ Parameter::Parameter()
this->setPressureRatio((real)1.0); this->setPressureRatio((real)1.0);
this->setPathAndFilename(this->getOutputPath() + "/" + this->getOutputPrefix()); this->setPathAndFilename(this->getOutputPath() + this->getOutputPrefix());
this->setlimitOfNodesForVTK((uint)30000000); this->setlimitOfNodesForVTK((uint)30000000);
...@@ -77,6 +78,41 @@ Parameter::Parameter() ...@@ -77,6 +78,41 @@ Parameter::Parameter()
this->setIsADcalculationOn(false); this->setIsADcalculationOn(false);
} }
Parameter::Parameter(const vf::basics::ConfigurationFile &configData) : Parameter()
{
readConfigData(configData);
}
void Parameter::readConfigData(const vf::basics::ConfigurationFile &configData){
if (configData.contains("OutputPath"))
this->setOutputPath(configData.getValue<std::string>("OutputPath"));
// deprecated, this is only in here for backward compatibility
if (configData.contains("Path")){
*logging::out << logging::Logger::INFO_INTERMEDIATE << "The config option \"Path\" is deprecated, please use \"OutputPath\" instead." << "\n";
this->setOutputPath(configData.getValue<std::string>("Path"));
}
if (configData.contains("OutputPrefix"))
this->setOutputPrefix(configData.getValue<std::string>("OutputPrefix"));
// deprecated, this is only in here for backward compatibility
if (configData.contains("Prefix")){
*logging::out << logging::Logger::INFO_INTERMEDIATE << "The config option \"Prefix\" is deprecated, please use \"OutputPrefix\" instead." << "\n";
this->setOutputPath(configData.getValue<std::string>("Prefix"));
}
// overwrite PathAndFilename when OutputPath or OutputPrefix are set in the config file
this->setPathAndFilename(this->getOutputPath() + this->getOutputPrefix());
if (configData.contains("TimeEnd"))
this->setTimestepEnd(configData.getValue<int>("TimeEnd"));
if (configData.contains("TimeOut"))
this->setTimestepOut(configData.getValue<int>("TimeOut"));
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//init-method //init-method
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
...@@ -125,6 +161,10 @@ void Parameter::setTimestepStartOut(uint timestepStartOut) ...@@ -125,6 +161,10 @@ void Parameter::setTimestepStartOut(uint timestepStartOut)
} }
void Parameter::setOutputPath(std::string outputPath) void Parameter::setOutputPath(std::string outputPath)
{ {
// add missing slash to outputPath
if (outputPath.back() != '/')
outputPath += "/";
this->outputPath = outputPath; this->outputPath = outputPath;
} }
void Parameter::setOutputPrefix(std::string outputPrefix) void Parameter::setOutputPrefix(std::string outputPrefix)
......
...@@ -114,6 +114,9 @@ public: ...@@ -114,6 +114,9 @@ public:
//////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////
//! \brief generate a new instance of parameter object, sets some defaults //! \brief generate a new instance of parameter object, sets some defaults
Parameter(); Parameter();
//! \brief generate a new instance of parameter object using a config file
//! \details calls Parameter(): Variables which are not set in the config files use the defaults
Parameter(const vf::basics::ConfigurationFile &configData);
~Parameter() = default; ~Parameter() = default;
...@@ -151,8 +154,10 @@ public: ...@@ -151,8 +154,10 @@ public:
//! \param string "oPrefix" represents the file-name-prefix //! \param string "oPrefix" represents the file-name-prefix
void setOutputPrefix(std::string outputPrefix); void setOutputPrefix(std::string outputPrefix);
//! \brief sets the complete string for the vtk-files with results //! \brief sets the complete string for the vtk-files with results
//! \param string "fname" represents the combination of path and prefix //! \param string "pathAndFilename" represents the combination of path and prefix
void setPathAndFilename(std::string pathAndFilename); void setPathAndFilename(std::string pathAndFilename);
//! \brief sets the path for reading and writing the grid
void setGridPath(std::string gridPath);
//! \brief sets the status, if Advection Diffusion should be calculated //! \brief sets the status, if Advection Diffusion should be calculated
//! \param if calcAD is true, the Advection Diffusion will be calculated //! \param if calcAD is true, the Advection Diffusion will be calculated
void setIsADcalculationOn(bool calcAD); void setIsADcalculationOn(bool calcAD);
...@@ -257,6 +262,9 @@ public: ...@@ -257,6 +262,9 @@ public:
void setInitialConditionAD(std::function<void(real, real, real, real &)> initialConditionAD); void setInitialConditionAD(std::function<void(real, real, real, real &)> initialConditionAD);
std::function<void(real, real, real, real &)> &getInitialConditionAD(); std::function<void(real, real, real, real &)> &getInitialConditionAD();
private:
//! read configuration data from a config file
void readConfigData(const vf::basics::ConfigurationFile &configData);
private: private:
//! \brief stencil for the LB simulation, number of node neighbors //! \brief stencil for the LB simulation, number of node neighbors
int D3Qxx; int D3Qxx;
......
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