Commit c6a2ce77 authored by steffen.schotthoefer's avatar steffen.schotthoefer
Browse files

Code refactoring: Adaption to name conventions. Legacy Code Removed. Removed...

Code refactoring: Adaption to name conventions. Legacy Code Removed. Removed String array options in Config and replaced by safer vector<string> variants
parent 5bde8a95
Pipeline #87629 passed with stages
in 4 minutes and 19 seconds
......@@ -26,9 +26,8 @@
#include <vtkUnstructuredGridWriter.h>
#include "mesh.h"
#include "settings.h"
#include "settings/CConfig.h"
#include "settings/config.h"
using vtkPointsSP = vtkSmartPointer<vtkPoints>;
......@@ -44,12 +43,15 @@ using vtkPointDataToCellDataSP = vtkSmartPointer<vtkPointDataToCellData>;
void ExportVTK( const std::string fileName,
const std::vector<std::vector<std::vector<double>>>& results,
const std::vector<std::string> fieldNames,
const CConfig* settings,
const Config* settings,
const Mesh* mesh );
void InitLogger( std::string logDir, spdlog::level::level_enum terminalLogLvl, spdlog::level::level_enum fileLogLvl );
Mesh* LoadSU2MeshFromFile( const CConfig* settings );
Mesh* LoadSU2MeshFromFile( const Config* settings );
std::string ParseArguments( int argc, char* argv[] );
Settings* ReadInputFile( std::string inputFile );
void PrintLogHeader( std::string inputFile );
#endif // IO_H
......@@ -12,7 +12,7 @@ public:
* @brief LaxFriedrichsFlux
* @param settings
*/
LaxFriedrichsFlux(CConfig* settings);
LaxFriedrichsFlux(Config* settings);
/**
* @brief Flux computes flux on edge for fixed ordinate at a given edge
......
......@@ -13,7 +13,7 @@
#include "typedef.h"
#include "settings/GlobalConstants.h"
#include "settings/globalconstants.h"
class Mesh
{
......
......@@ -2,13 +2,13 @@
#define NUMERICALFLUX_H
#include "typedef.h"
#include "settings/CConfig.h"
#include "settings/config.h"
class NumericalFlux
{
public:
NumericalFlux(CConfig* settings);
static NumericalFlux* Create( CConfig* settings );
NumericalFlux(Config* settings);
static NumericalFlux* Create( Config* settings );
/**
* @brief Flux computes flux on edge for fixed ordinate at a given edge
* @param Omega fixed ordinate for flux computation
......
......@@ -3,7 +3,7 @@
// include Matrix, Vector definitions
#include "typedef.h"
#include "settings.h"
#include "settings/config.h"
class Physics {
......@@ -46,15 +46,15 @@ public:
* @brief Physics constructor
* @param settings stores all needed user information
*/
Physics ( Settings* settings );
Physics ( Config* settings );
/**
* @brief Create constructor
* @param settings stores all needed information
* @return pointer to Physics
*/
static Physics* Create (Settings* settings);
static Physics* Create (Config* settings);
};
#endif
\ No newline at end of file
#endif
......@@ -12,9 +12,9 @@
#ifndef QDUMMY_H
#define QDUMMY_H
#include "quadrature.h"
#include "quadraturebase.h"
class QDummy : public Quadrature
class QDummy : public QuadratureBase
{
public:
QDummy( unsigned order );
......
#ifndef QGAUSSLEGENDRETENSORIZED_H
#define QGAUSSLEGENDRETENSORIZED_H
#include "quadrature.h"
#include "quadraturebase.h"
class QGaussLegendreTensorized : public Quadrature
class QGaussLegendreTensorized : public QuadratureBase
{
public:
QGaussLegendreTensorized( unsigned order );
......
#ifndef QLOOKUPQUADRATURE_H
#define QLOOKUPQUADRATURE_H
#include "quadrature.h"
#include "quadraturebase.h"
class QLookupQuadrature : public Quadrature
class QLookupQuadrature : public QuadratureBase
{
public:
QLookupQuadrature( unsigned order );
......
#ifndef QMONTECARLO_H
#define QMONTECARLO_H
#include "quadrature.h"
#include "quadraturebase.h"
class QMonteCarlo : public Quadrature
class QMonteCarlo : public QuadratureBase
{
public:
QMonteCarlo( unsigned order );
......
......@@ -3,15 +3,14 @@
#include <iostream>
#include <string>
#include "settings.h"
#include "settings/globalconstants.h"
#include "typedef.h"
class Quadrature
class QuadratureBase
{
public:
Quadrature( unsigned order );
virtual ~Quadrature(){}
QuadratureBase( unsigned order );
virtual ~QuadratureBase(){}
// Aux functions
void PrintWeights(); /*! @brief prints: Weight vector */
......@@ -32,7 +31,7 @@ class Quadrature
* @param: std::string name: Name of the quadrature rule
* @param: unsigned order: Order of the quadrature rule
* @returns Quadrature* quadrature: returns pointer to instance of the given derived quadrature class */
static Quadrature* CreateQuadrature( QUAD_NAME name, unsigned order );
static QuadratureBase* CreateQuadrature( QUAD_NAME name, unsigned order );
// Getter
inline std::string GetName() const { return _name; } /*! @returns std::string _name: name of the quadrature */
......
#ifndef RECONSTRUCTOR_H
#define RECONSTRUCTOR_H
#include "settings.h"
#include "settings/config.h"
#include "typedef.h"
class Reconstructor
......@@ -11,7 +11,7 @@ class Reconstructor
* @brief Reconstruction
* @param settings
*/
Reconstructor( Settings* settings );
Reconstructor( Config* settings );
/** Method 1: structured developing
* @brief Slope of angular flux psi inside a given cell
......
#ifndef SETTINGS_H
#define SETTINGS_H
#include <filesystem>
#include <string>
#include "mesh.h"
#include "settings/GlobalConstants.h"
class Settings
{
private:
// IO
std::filesystem::path _inputFile;
std::filesystem::path _inputDir;
std::filesystem::path _outputFile;
std::filesystem::path _outputDir;
std::filesystem::path _logDir;
std::filesystem::path _meshFile;
std::vector<std::pair<std::string, BOUNDARY_TYPE>> _boundaries;
// Mesh
unsigned _meshDimension;
// Solver
unsigned _quadOrder;
QUAD_NAME _quadName;
double _CFL;
double _tEnd;
// MPI
int _comm_rank;
int _comm_size;
public:
Settings();
std::string GetInputFile() const;
std::string GetInputDir() const;
std::string GetOutputFile() const;
std::string GetOutputDir() const;
std::string GetLogDir() const;
std::string GetMeshFile() const;
// mesh Getters
BOUNDARY_TYPE GetBoundaryType( std::string name ) const;
// solver Getters
unsigned GetQuadOrder() const;
QUAD_NAME GetQuadName() const;
double GetCFL() const;
double GetTEnd() const;
friend Settings* ReadInputFile( std::string fileName );
};
#endif // SETTINGS_H
......@@ -10,8 +10,8 @@
#define CONFIG_H
#include <map>
#include "OptionStructure.h"
#include "GlobalConstants.h"
#include "optionstructure.h"
#include "globalconstants.h"
/*!
* \class CConfig
......@@ -19,12 +19,12 @@
* stores all the information.
*/
class CConfig {
class Config {
private:
std::string _fileName; /*!< \brief Name of the current file without extension */
bool _base_config;
bool _baseConfig;
int _comm_rank, _comm_size; /*!< \brief MPI rank and size.*/
int _commRank, _commSize; /*!< \brief MPI rank and size.*/ //Not yet used!!
// --- Options ---
// File Structure
......@@ -44,7 +44,7 @@ private:
Each Boundary Conditions must have an entry in enum BOUNDARY_TYPE*/
std::vector<std::pair<std::string, BOUNDARY_TYPE>> _boundaries;
unsigned short _nMarkerDirichlet; /*!< \brief Number of Dirichlet BC markers. Enum entry: DIRICHLET */
std::string *_MarkerDirichlet; /*!< \brief Dirichlet BC markers. */
std::vector<std::string> _MarkerDirichlet; /*!< \brief Dirichlet BC markers. */
// --- Parsing Functionality and Initializing of Options ---
......@@ -95,12 +95,12 @@ private:
to track the options which have not been set (so the default values can be used). Without this map
there would be no list of all the config file options. ---*/
std::map<std::string, bool> all_options;
std::map<std::string, bool> _allOptions;
/*--- brief param is a map from the option name (config file string) to its decoder (the specific child
class of COptionBase that turns the string into a value) ---*/
std::map<std::string, COptionBase*> option_map;
std::map<std::string, OptionBase*> _optionMap;
// ---- Option Types ----
......@@ -122,38 +122,38 @@ private:
value can be represented by a su2double.*/
// Simple Options
void addBoolOption(const std::string name, bool & option_field, bool default_value);
void AddBoolOption(const std::string name, bool & option_field, bool default_value);
void addDoubleOption(const std::string name, double & option_field, double default_value);
void AddDoubleOption(const std::string name, double & option_field, double default_value);
void addIntegerOption(const std::string name, int & option_field, int default_value);
void AddIntegerOption(const std::string name, int & option_field, int default_value);
void addLongOption(const std::string name, long & option_field, long default_value);
void AddLongOption(const std::string name, long & option_field, long default_value);
void addStringOption(const std::string name, std::string & option_field, std::string default_value);
void AddStringOption(const std::string name, std::string & option_field, std::string default_value);
void addUnsignedLongOption(const std::string name, unsigned long & option_field, unsigned long default_value);
void AddUnsignedLongOption(const std::string name, unsigned long & option_field, unsigned long default_value);
void addUnsignedShortOption(const std::string name, unsigned short & option_field, unsigned short default_value);
void AddUnsignedShortOption(const std::string name, unsigned short & option_field, unsigned short default_value);
// enum types work differently than all of the others because there are a small number of valid
// string entries for the type. One must also provide a list of all the valid strings of that type.
template <class Tenum>
void addEnumOption(const std::string name, Tenum & option_field, const std::map<std::string, Tenum> & enum_map, Tenum default_value);
void AddEnumOption(const std::string name, Tenum & option_field, const std::map<std::string, Tenum> & enum_map, Tenum default_value);
//List Options
void addStringListOption(const std::string name, unsigned short & num_marker, std::string* & option_field);
void AddStringListOption(const std::string name, unsigned short & num_marker, std::vector<std::string> & option_field);
public:
/*!
* \brief Constructor of the class which reads the input file.
*/
CConfig(char case_filename[MAX_STRING_SIZE]);
Config(char case_filename[MAX_STRING_SIZE]);
/*!
* \brief Destructor of the class.
*/
~CConfig(void);
~Config(void);
// ---- Getters for option values ----
......
......@@ -15,16 +15,16 @@
#include <sstream>
// Base Class for all kinds of options
class COptionBase {
class OptionBase {
private:
std::vector<std::string> value;
std::vector<std::string> _value;
public:
COptionBase() {};
virtual ~COptionBase() = 0;
OptionBase() {};
virtual ~OptionBase() = 0;
virtual std::string SetValue(std::vector<std::string> value){this->value = value; return "";}
std::vector<std::string> GetValue() {return value;}
virtual std::string SetValue(std::vector<std::string> value){this->_value = value; return "";}
std::vector<std::string> GetValue() {return _value;}
virtual void SetDefault() = 0;
std::string optionCheckMultipleValues(std::vector<std::string> & option_value, std::string type_id, std::string option_name) {
......@@ -47,303 +47,302 @@ public:
}
};
inline COptionBase::~COptionBase() {}
inline OptionBase::~OptionBase() {}
template <class Tenum>
class COptionEnum : public COptionBase {
class OptionEnum : public OptionBase {
std::map<std::string, Tenum> m;
Tenum & field; // Reference to the feildname
Tenum def; // Default value
std::string name; // identifier for the option
std::map<std::string, Tenum> _map;
Tenum & _field; // Reference to the fieldname
Tenum _def; // Default value
std::string _name; // identifier for the option
public:
COptionEnum(std::string option_field_name, const std::map<std::string, Tenum> m, Tenum & option_field, Tenum default_value) : field(option_field) {
this->m = m;
this->def = default_value;
this->name = option_field_name;
OptionEnum(std::string option_field_name, const std::map<std::string, Tenum> m, Tenum & option_field, Tenum default_value) : _field(option_field) {
this->_map = m;
this->_def = default_value;
this->_name = option_field_name;
}
~COptionEnum() override {};
~OptionEnum() override {};
std::string SetValue(std::vector<std::string> option_value) override {
COptionBase::SetValue(option_value);
OptionBase::SetValue(option_value);
// Check if there is more than one string
std::string out = optionCheckMultipleValues(option_value, "enum", this->name);
std::string out = optionCheckMultipleValues(option_value, "enum", this->_name);
if (out.compare("") != 0) {
return out;
}
// Check to see if the enum value is in the map
if (this->m.find(option_value[0]) == m.end()) {
if (this->_map.find(option_value[0]) == _map.end()) {
std::string str;
str.append(this->name);
str.append(this->_name);
str.append(": invalid option value ");
str.append(option_value[0]);
str.append(". Check current RTSN options in config_template.cfg.");
return str;
}
// If it is there, set the option value
Tenum val = this->m[option_value[0]];
this->field = val;
Tenum val = this->_map[option_value[0]];
this->_field = val;
return "";
}
void SetDefault() override {
this->field = this->def;
this->_field = this->_def;
}
};
class COptionDouble : public COptionBase {
double & field; // Reference to the fieldname
double def; // Default value
std::string name; // identifier for the option
class OptionDouble : public OptionBase {
double & _field; // Reference to the fieldname
double _def; // Default value
std::string _name; // identifier for the option
public:
COptionDouble(std::string option_field_name, double & option_field, double default_value) : field(option_field) {
this->def = default_value;
this->name = option_field_name;
OptionDouble(std::string option_field_name, double & option_field, double default_value) : _field(option_field) {
this->_def = default_value;
this->_name = option_field_name;
}
~COptionDouble() override {};
~OptionDouble() override {};
std::string SetValue(std::vector<std::string> option_value) override {
COptionBase::SetValue(option_value);
OptionBase::SetValue(option_value);
// check if there is more than one value
std::string out = optionCheckMultipleValues(option_value, "double", this->name);
std::string out = optionCheckMultipleValues(option_value, "double", this->_name);
if (out.compare("") != 0) {
return out;
}
std::istringstream is(option_value[0]);
double val;
if (is >> val) {
this->field = val;
this->_field = val;
return "";
}
return badValue(option_value, "double", this->name);
return badValue(option_value, "double", this->_name);
}
void SetDefault() override {
this->field = this->def;
this->_field = this->_def;
}
};
class COptionString : public COptionBase {
std::string & field; // Reference to the fieldname
std::string def; // Default value
std::string name; // identifier for the option
class OptionString : public OptionBase {
std::string & _field; // Reference to the fieldname
std::string _def; // Default value
std::string _name; // identifier for the option
public:
COptionString(std::string option_field_name, std::string & option_field, std::string default_value) : field(option_field) {
this->def = default_value;
this->name = option_field_name;
OptionString(std::string option_field_name, std::string & option_field, std::string default_value) : _field(option_field) {
this->_def = default_value;
this->_name = option_field_name;
}
~COptionString() override {};
~OptionString() override {};
std::string SetValue(std::vector<std::string> option_value) override {
COptionBase::SetValue(option_value);
OptionBase::SetValue(option_value);
// check if there is more than one value
std::string out = optionCheckMultipleValues(option_value, "double", this->name);
std::string out = optionCheckMultipleValues(option_value, "double", this->_name);
if (out.compare("") != 0) {
return out;
}
this->field.assign(option_value[0]);
this->_field.assign(option_value[0]);
return "";
}
void SetDefault() override {
this->field = this->def;
this->_field = this->_def;
}
};
class COptionInt : public COptionBase {
int & field; // Reference to the feildname
int def; // Default value
std::string name; // identifier for the option
class OptionInt : public OptionBase {
int & _field; // Reference to the feildname
int _def; // Default value
std::string _name; // identifier for the option
public:
COptionInt(std::string option_field_name, int & option_field, int default_value) : field(option_field) {
this->def = default_value;
this->name = option_field_name;
OptionInt(std::string option_field_name, int & option_field, int default_value) : _field(option_field) {
this->_def = default_value;
this->_name = option_field_name;
}
~COptionInt() override {};
~OptionInt() override {};
std::string SetValue(std::vector<std::string> option_value) override {
COptionBase::SetValue(option_value);
std::string out = optionCheckMultipleValues(option_value, "int", this->name);
OptionBase::SetValue(option_value);
std::string out = optionCheckMultipleValues(option_value, "int", this->_name);
if (out.compare("") != 0) {
return out;
}
std::istringstream is(option_value[0]);
int val;
if (is >> val) {
this->field = val;
this->_field = val;
return "";
}
return badValue(option_value, "int", this->name);
return badValue(option_value, "int", this->_name);
}
void SetDefault() override {
this->field = this->def;
this->_field = this->_def;
}
};
class COptionULong : public COptionBase {
unsigned long & field; // Reference to the feildname
unsigned long def; // Default value
std::string name; // identifier for the option
class OptionULong : public OptionBase {
unsigned long & _field; // Reference to the feildname
unsigned long _def; // Default value
std::string _name; // identifier for the option
public:
COptionULong(std::string option_field_name, unsigned long & option_field, unsigned long default_value) : field(option_field) {
this->def = default_value;
this->name = option_field_name;
OptionULong(std::string option_field_name, unsigned long & option_field, unsigned long default_value) : _field(option_field) {
this->_def = default_value;
this->_name = option_field_name;
}
~COptionULong() override {};
~OptionULong() override {};
std::string SetValue(std::vector<std::string> option_value) override {