Commit 75a411e8 authored by steffen.schotthoefer's avatar steffen.schotthoefer
Browse files

Implemented EnumListOption. Introduced VOLUME_OUTPUT as .cfg option.

parent c125cf75
......@@ -87,6 +87,10 @@ class Config
unsigned short _newtonLineSearchIter; /*!< @brief Maximal Number of line search iterations for newton optimizer */
bool _newtonFastMode; /*!< @brief If true, we skip the NewtonOptimizer for quadratic entropy and assign alpha = u */
// Output Options
unsigned short _nVolumeOutput; /*!< @brief Number of volume outputs */
std::vector<VOLUME_OUTPUT> _volumeOutput; /*!< @brief Output groups for volume output*/
// --- Parsing Functionality and Initializing of Options ---
/*!
* @brief Set default values for all options not yet set.
......@@ -178,7 +182,13 @@ class Config
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::vector<std::string>& option_field );
void AddStringListOption( const std::string name, unsigned short& input_size, std::vector<std::string>& option_field );
template <class Tenum>
void AddEnumListOption( const std::string name,
unsigned short& num_marker,
std::vector<Tenum>& option_field,
const std::map<std::string, Tenum>& enum_map );
// Initialize the cmdline and file logger
void InitLogger();
......@@ -244,6 +254,8 @@ class Config
KERNEL_NAME inline GetKernelName() const { return _kernelName; }
// Output Structure
std::vector<VOLUME_OUTPUT> inline GetVolumeOutput() { return _volumeOutput; }
unsigned short inline GetNVolumeOutput() { return _nVolumeOutput; }
// ---- Setters for option structure
......
......@@ -70,8 +70,14 @@ enum ENTROPY_NAME { QUADRATIC, MAXWELL_BOLZMANN, BOSE_EINSTEIN, FERMI_DIRAC };
inline std::map<std::string, ENTROPY_NAME> Entropy_Map{
{ "QUADRATIC", QUADRATIC }, { "MAXWELL_BOLZMANN", MAXWELL_BOLZMANN }, { "BOSE_EINSTEIN", BOSE_EINSTEIN }, { "FERMI_DIRAC", FERMI_DIRAC } };
// Otpimizer
// Optimizer
enum OPTIMIZER_NAME { NEWTON, ML };
inline std::map<std::string, OPTIMIZER_NAME> Optimizer_Map{ { "NEWTON", NEWTON }, { "ML", ML } };
// Volume output
enum VOLUME_OUTPUT { MINIMAL, MOMENTS };
inline std::map<std::string, VOLUME_OUTPUT> VolOutput_Map{ { "MINIMAL", MINIMAL }, { "MOMENTS", MOMENTS } };
#endif // GLOBAL_CONSTANTS_H
......@@ -9,9 +9,15 @@
class Config;
class Mesh;
/*! @brief: Function to export solver Volume output to VTK file.
* @param: filename: Filename of output file
* @param: outputFields: numerical output of the solver. Dimensions: (OutputGroupSize, OutputFieldSize, NumberMeshCells)
* @param: outputFieldNames: names of the outputfields. Dimensions: (OutputGroupSize, OutputFieldSize)
* @param: mesh: Mesh with <NumberMeshCells> cells (the mesh used for the computation)
*/
void ExportVTK( const std::string fileName,
const std::vector<std::vector<std::vector<double>>>& results,
const std::vector<std::string> fieldNames,
const std::vector<std::vector<std::vector<double>>>& outputFields,
const std::vector<std::vector<std::string>>& outputFieldNames,
const Mesh* mesh );
Mesh* LoadSU2MeshFromFile( const Config* settings );
......
......@@ -22,13 +22,14 @@ class OptionBase
std::vector<std::string> _value;
public:
OptionBase(){};
virtual ~OptionBase() = 0;
OptionBase() {}
virtual std::string SetValue( std::vector<std::string> value );
virtual ~OptionBase() {}
std::vector<std::string> GetValue();
virtual std::string SetValue( std::vector<std::string> value );
virtual void SetDefault() = 0;
std::string optionCheckMultipleValues( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
......@@ -36,49 +37,6 @@ class OptionBase
std::string badValue( std::vector<std::string>& option_value, std::string type_id, std::string option_name );
};
template <class Tenum> class OptionEnum : public OptionBase
{
std::map<std::string, Tenum> _map;
Tenum& _field; // Reference to the fieldname
Tenum _def; // Default value
std::string _name; // identifier for the option
public:
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;
}
~OptionEnum() override{};
std::string SetValue( std::vector<std::string> option_value ) override {
OptionBase::SetValue( option_value );
// Check if there is more than one string
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->_map.find( option_value[0] ) == _map.end() ) {
std::string str;
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->_map[option_value[0]];
this->_field = val;
return "";
}
void SetDefault() override { this->_field = this->_def; }
};
class OptionDouble : public OptionBase
{
double& _field; // Reference to the fieldname
......@@ -88,7 +46,7 @@ class OptionDouble : public OptionBase
public:
OptionDouble( std::string option_field_name, double& option_field, double default_value );
~OptionDouble() override{};
~OptionDouble() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -104,7 +62,7 @@ class OptionString : public OptionBase
public:
OptionString( std::string option_field_name, std::string& option_field, std::string default_value );
~OptionString() override{};
~OptionString() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -120,7 +78,7 @@ class OptionInt : public OptionBase
public:
OptionInt( std::string option_field_name, int& option_field, int default_value );
~OptionInt() override{};
~OptionInt() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -136,7 +94,7 @@ class OptionULong : public OptionBase
public:
OptionULong( std::string option_field_name, unsigned long& option_field, unsigned long default_value );
~OptionULong() override{};
~OptionULong() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -152,7 +110,7 @@ class OptionUShort : public OptionBase
public:
OptionUShort( std::string option_field_name, unsigned short& option_field, unsigned short default_value );
~OptionUShort() override{};
~OptionUShort() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -168,7 +126,7 @@ class OptionLong : public OptionBase
public:
OptionLong( std::string option_field_name, long& option_field, long default_value );
~OptionLong() override{};
~OptionLong() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -184,7 +142,7 @@ class OptionBool : public OptionBase
public:
OptionBool( std::string option_field_name, bool& option_field, bool default_value );
~OptionBool() override{};
~OptionBool() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
......@@ -200,11 +158,106 @@ class OptionStringList : public OptionBase
public:
OptionStringList( std::string option_field_name, unsigned short& list_size, std::vector<std::string>& option_field );
~OptionStringList() override{};
~OptionStringList() override {}
std::string SetValue( std::vector<std::string> option_value ) override;
void SetDefault() override;
};
// Template classes (TODO: Find a way to split code to .cpp)
template <class Tenum> class OptionEnum : public OptionBase
{
std::map<std::string, Tenum> _map;
Tenum& _field; // Reference to the fieldname
Tenum _def; // Default value
std::string _name; // identifier for the option
public:
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;
}
~OptionEnum() override {}
std::string SetValue( std::vector<std::string> option_value ) override {
OptionBase::SetValue( option_value );
// Check if there is more than one string
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->_map.find( option_value[0] ) == _map.end() ) {
std::string str;
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->_map[option_value[0]];
this->_field = val;
return "";
}
void SetDefault() override { this->_field = this->_def; }
};
template <class Tenum> class OptionEnumList : public OptionBase
{
std::map<std::string, Tenum> _map;
std::vector<Tenum>& _field; // Reference to the fieldname
std::string _name; // identifier for the option
unsigned short& _size;
public:
OptionEnumList( std::string option_field_name, const std::map<std::string, Tenum> m, std::vector<Tenum>& option_field, unsigned short& list_size )
: _field( option_field ), _size( list_size ) {
this->_map = m;
this->_name = option_field_name;
}
~OptionEnumList() override {}
std::string SetValue( std::vector<std::string> option_value ) override {
OptionBase::SetValue( option_value );
if( option_value.size() == 1 && option_value[0].compare( "NONE" ) == 0 ) {
this->_size = 0;
return "";
}
// size is the length of the option list
this->_size = option_value.size();
std::vector<Tenum> enums( _size );
// unsigned short* enums = new unsigned short[_size];
for( int i = 0; i < this->_size; i++ ) {
// Check to see if the enum value is in the map
if( this->_map.find( option_value[i] ) == _map.end() ) {
std::string str;
str.append( this->_name );
str.append( ": invalid option value " );
str.append( option_value[i] );
str.append( ". Check current RTSN options in config_template.cfg." );
return str;
}
// If it is there, set the option value
enums[i] = this->_map[option_value[i]];
}
this->_field = enums;
return "";
}
void SetDefault() override {
// No default to set
_size = 0;
}
};
#endif // OPTION_STRUCTURE_H
......@@ -55,3 +55,8 @@ QUAD_TYPE = GAUSS_LEGENDRE_TENSORIZED
%
% Quadrature Order
QUAD_ORDER = 12
%
%
% ----- Output ----
%
VOLUME_OUTPUT = (MINIMAL, MOMENTS)
......@@ -36,4 +36,7 @@ MAX_MOMENT_SOLVER = 2
% Dirichlet Boundary
BC_DIRICHLET = ( void )
%
% ----- Output ----
%
VOLUME_OUTPUT = (MINIMAL)
......@@ -158,6 +158,18 @@ void Config::AddStringListOption( const string name, unsigned short& num_marker,
_optionMap.insert( pair<string, OptionBase*>( name, val ) );
}
template <class Tenum>
void Config::AddEnumListOption( const std::string name,
unsigned short& input_size,
std::vector<Tenum>& option_field,
const map<std::string, Tenum>& enum_map ) {
input_size = 0;
assert( _optionMap.find( name ) == _optionMap.end() );
_allOptions.insert( pair<string, bool>( name, true ) );
OptionBase* val = new OptionEnumList<Tenum>( name, enum_map, option_field, input_size );
_optionMap.insert( pair<string, OptionBase*>( name, val ) );
}
// ---- Getter Functions ----
BOUNDARY_TYPE Config::GetBoundaryType( std::string name ) const {
......@@ -258,6 +270,9 @@ void Config::SetConfigOptions() {
AddStringListOption( "BC_NEUMANN", _nMarkerNeumann, _MarkerNeumann );
AddEnumOption( "KERNEL", _kernelName, Kernel_Map, KERNEL_Isotropic );
// Output related options
AddEnumListOption( "VOLUME_OUTPUT", _nVolumeOutput, _volumeOutput, VolOutput_Map );
}
void Config::SetConfigParsing( string case_filename ) {
......@@ -391,6 +406,12 @@ void Config::SetPostprocessing() {
CURRENT_FUNCTION );
}
}
// Output Postprocessing
if( _nVolumeOutput == 0 ) { // If no specific output is chosen, use "MINIMAL"
_nVolumeOutput = 1;
_volumeOutput.push_back( MINIMAL );
}
}
void Config::SetOutput() {
......
......@@ -10,8 +10,6 @@
// --- Members of OptionBase ----
OptionBase::~OptionBase() {}
std::vector<std::string> OptionBase::GetValue() { return _value; }
std::string OptionBase::SetValue( std::vector<std::string> value ) {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment