config.h 16.1 KB
Newer Older
1
/*!
2
 * @file config.h
3
 * @brief Class to handle all options and their pre and postprocessing.
4
5
 *         DO NOT CREATE SETTERS FOR THIS CLASS! ALL OPTIONS ARE CONSTANT (after SetPostprocessing).
 *
6
 * @author S. Schotthöfer
7
8
9
10
11
 */

#ifndef CONFIG_H
#define CONFIG_H

jannick.wolters's avatar
jannick.wolters committed
12
#include <filesystem>
13
#include <map>
14
#include <vector>
15

16
#include "globalconstants.h"
steffen.schotthoefer's avatar
steffen.schotthoefer committed
17
18
19

// Forward declaration
class OptionBase;
20
21

/*!
22
23
 * @class Config
 * @brief Main class for defining the problem; basically this class reads the configuration file, and
24
25
26
 *        stores all the information.
 */

27
28
29
class Config
{
  private:
Steffen Schotthöfer's avatar
Steffen Schotthöfer committed
30
    std::string _fileName; /*!< @brief Name of the current file without extension */
31
32
    bool _baseConfig;

33
    // int _commRank, _commSize; /*!< @brief MPI rank and size.*/    // Not yet used!!
34
35
36

    // --- Options ---
    // File Structure
37
38
39
40
41
42
43
    std::string _inputDir;    /*!< @brief Directory for input files*/
    std::string _outputDir;   /*!< @brief Directory for output files*/
    std::string _outputFile;  /*!< @brief Name of output file*/
    std::string _logDir;      /*!< @brief Directory of log file*/
    std::string _logFileName; /*!< @brief Name of log file*/
    std::string _meshFile;    /*!< @brief Name of mesh file*/
    std::string _ctFile;      /*!< @brief Name of CT file*/
44
45

    // Quadrature
46
47
    QUAD_NAME _quadName;       /*!< @brief Quadrature Name*/
    unsigned short _quadOrder; /*!< @brief Quadrature Order*/
48
49
50
    unsigned _nQuadPoints;

    // Mesh
51
52
    unsigned _nCells;    /*!< @brief Number of cells in the mesh */
    unsigned short _dim; /*!< @brief spatial dimensionality of the mesh/test case */
53
54
55
56
57
58
59
60
61

    // Boundary Conditions
    /*!< @brief List of all Pairs (marker, BOUNDARY_TYPE), e.g. (farfield,DIRICHLET).
         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 */
    unsigned short _nMarkerNeumann;            /*!< @brief Number of Neumann BC markers. Enum entry: Neumann */
    std::vector<std::string> _MarkerDirichlet; /*!< @brief Dirichlet BC markers. */
    std::vector<std::string> _MarkerNeumann;   /*!< @brief Neumann BC markers. */
62

63
    // Solver
64
65
66
67
    double _CFL;                     /*!< @brief CFL Number for Solver*/
    double _tEnd;                    /*!< @brief Final Time for Simulation */
    PROBLEM_NAME _problemName;       /*!< @brief Name of predefined Problem   */
    SOLVER_NAME _solverName;         /*!< @brief Name of the used Solver */
68
    ENTROPY_NAME _entropyName;       /*!< @brief Name of the used Entropy Functional */
69
    unsigned short _maxMomentDegree; /*!< @brief Maximal Order of Moments for PN and MN Solver */
70
    unsigned short _reconsOrder;     /*!< @brief Spatial Order of Accuracy for Solver */
71

steffen.schotthoefer's avatar
steffen.schotthoefer committed
72
73
    /*!< @brief If true, very low entries (10^-10 or smaller) of the flux matrices will be set to zero,
     * to improve floating point accuracy */
74
    bool _cleanFluxMat;
75
    bool _allGaussPts; /*!< @brief If true, the SN Solver uses all Gauss pts in the quadrature */
76
    bool _csd;         /*!< @brief If true, continuous slowing down approximation will be used */
77

78
    // --- Problems ---
79

80
81
82
83
84
85
86
87
88
    // Linesource
    double _sigmaS; /*!< @brief Scattering coeffient for Linesource test case */

    // Database ICRU
    std::string _dataDir; /*!< @brief material directory */
    // ElectronRT
    std::string _hydrogenFile;      /*!< @brief Name of hydrogen cross section file path*/
    std::string _oxygenFile;        /*!< @brief Name of oxygen cross section file path */
    std::string _stoppingPowerFile; /*!< @brief Name of stopping power file path */
89

90
91
92
93
    // CSD
    double _maxEnergyCSD; /*!< @brief Maximum energy for CSD simulation */

    // --- other variables ---
jannick.wolters's avatar
jannick.wolters committed
94
    // Scattering Kernel
95
    KERNEL_NAME _kernelName; /*!< @brief Scattering Kernel Name*/
jannick.wolters's avatar
jannick.wolters committed
96

97
    // Spherical Basis
98
    SPHERICAL_BASIS_NAME _sphericalBasisName; /*!< @brief Name of the basis on the unit sphere */
99

100
    // Optimizer
101
102
    OPTIMIZER_NAME _entropyOptimizerName; /*!< @brief Choice of optimizer */
    double _optimizerEpsilon;             /*!< @brief termination criterion epsilon for Newton Optmizer */
103
    unsigned long _newtonIter;            /*!< @brief Maximal Number of newton iterations */
104
    double _newtonStepSize;               /*!< @brief Stepsize factor for newton optimizer */
105
    unsigned long _newtonLineSearchIter;  /*!< @brief Maximal Number of line search iterations for newton optimizer */
106
    bool _newtonFastMode;                 /*!< @brief If true, we skip the NewtonOptimizer for quadratic entropy and assign alpha = u */
107

108
    // NeuralModel
109
    unsigned short _neuralModel; /*!< @brief  Version number of the employed neural model */
110
111
112
    // Output Options
    unsigned short _nVolumeOutput;            /*!< @brief Number of volume outputs */
    std::vector<VOLUME_OUTPUT> _volumeOutput; /*!< @brief Output groups for volume output*/
113
114
115
    unsigned short _volumeOutputFrequency;    /*!< @brief Frequency of vtk write of volume output*/

    unsigned short _nScreenOutput;            /*!< @brief Number of screen outputs */
116
    std::vector<SCALAR_OUTPUT> _screenOutput; /*!< @brief Output groups for screen output*/
117
    unsigned short _screenOutputFrequency;    /*!< @brief Frequency of screen output*/
118

119
120
121
122
    unsigned short _nHistoryOutput;            /*!< @brief Number of screen outputs */
    std::vector<SCALAR_OUTPUT> _historyOutput; /*!< @brief Output groups for screen output*/
    unsigned short _historyOutputFrequency;    /*!< @brief Frequency of screen output*/

123
124
125
    // Data Generator Settings
    /*!< @brief Check, if data generator mode is active. If yes, no solver is called, but instead the data generator is executed */
    bool _dataGeneratorMode;
126
127
    unsigned long _tainingSetSize;    /*!< @brief Size of training data set for data generator */
    unsigned long _maxValFirstMoment; /*!< @brief Size of training data set for data generator */
128
    double _RealizableSetEpsilonU0;   /*!< @brief Distance to 0 of the sampled moments to the boundary of the realizable set */
129
130
    double _RealizableSetEpsilonU1;   /*!< @brief norm(u_1)/u_0 !< _RealizableSetEpsilonU1 */
    bool _normalizedSampling;         /*!< @brief Flag for sampling of normalized moments, i.e. u_0 =1 */
131

132
133
    // --- Parsing Functionality and Initializing of Options ---
    /*!
134
     * @brief Set default values for all options not yet set.
135
136
137
138
     */
    void SetDefault( void );

    /*!
139
     * @brief Set the config options.
140
141
142
143
144
     *        ==> Set new config options here.
     */
    void SetConfigOptions( void );

    /*!
145
     * @brief Set the config file parsing.
146
     */
147
    void SetConfigParsing( std::string case_filename );
148
149

    /*!
150
     * @brief Config file screen output.
151
152
153
154
     */
    void SetOutput( void );

    /*!
155
     * @brief Initializes pointers to null
156
157
158
159
     */
    void SetPointersNull( void );

    /*!
160
     * @brief Config file postprocessing.
161
162
163
164
     */
    void SetPostprocessing( void );

    /*!
165
166
167
168
169
     * @brief breaks an input line from the config file into a set of tokens
     * @param[in] str - the input line string
     * @param[out] option_name - the name of the option found at the beginning of the line
     * @param[out] option_value - the tokens found after the "=" sign on the line
     * @return false if the line is empty or a commment, true otherwise
170
171
172
173
174
175
176
177
178
     */
    bool TokenizeString( std::string& str, std::string& option_name, std::vector<std::string>& option_value );

    /*--- all_options is a map containing all of the options. This is used during config file parsing
     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> _allOptions;

    /*--- brief param is a map from the option name (config file string) to its decoder (the specific child
179
     class of OptionBase that turns the string into a value) ---*/
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
    std::map<std::string, OptionBase*> _optionMap;

    // ---- Option Types ----

    // All of the addXxxOptions take in the name of the option, and a refernce to the field of that option
    // in the option structure. Depending on the specific type, it may take in a default value, and may
    // take in extra options. The addXxxOptions mostly follow the same pattern, so please see addDoubleOption
    // for detailed comments.
    //
    // List options are those that can be an unknown number of elements, and also take in a reference to
    // an integer. This integer will be populated with the number of elements of that type unmarshaled.
    //
    // Array options are those with a fixed number of elements.
    //
    // List and Array options should also be able to be specified with the string "NONE" indicating that there
    // are no elements. This allows the option to be present in a config file but left blank.

197
    /*!< @brief addDoubleOption creates a config file parser for an option with the given name whose
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
     value can be represented by a su2double.*/

    // Simple Options
    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 AddIntegerOption( const std::string name, int& option_field, int 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 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 );

    // 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 );

    // List Options
221
222
223
224
225
226
227
    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 );
228
229

    // Initialize the cmdline and file logger
230
    void InitLogger();
231
232
233

  public:
    /*!
234
     * @brief Constructor of the class which reads the input file.
235
     */
236
    Config( std::string case_filename );
237
238

    /*!
239
     * @brief Destructor of the class.
240
241
242
243
     */
    ~Config( void );

    // ---- Getters for option values ----
244

245
    /*!
246
     * @brief Get Value of this option.
247
248
249
     *        Please keep alphabetical order within each subcategory
     */
    // File structure
steffen.schotthoefer's avatar
steffen.schotthoefer committed
250
    std::string inline GetCTFile() const { return std::filesystem::path( _ctFile ).lexically_normal(); }
251

steffen.schotthoefer's avatar
steffen.schotthoefer committed
252
    std::string inline GetLogDir() const { return std::filesystem::path( _logDir ).lexically_normal(); }
253
    std::string inline GetLogFile() const { return std::filesystem::path( _logFileName ).lexically_normal(); }
jannick.wolters's avatar
jannick.wolters committed
254
255
256
    std::string inline GetMeshFile() const { return std::filesystem::path( _meshFile ).lexically_normal(); }
    std::string inline GetOutputDir() const { return std::filesystem::path( _outputDir ).lexically_normal(); }
    std::string inline GetOutputFile() const { return std::filesystem::path( _outputFile ).lexically_normal(); }
257
258
259

    // Problem Files
    std::string inline GetHydrogenFile() const { return std::filesystem::path( _hydrogenFile ).lexically_normal(); }
jannick.wolters's avatar
jannick.wolters committed
260
    std::string inline GetOxygenFile() const { return std::filesystem::path( _oxygenFile ).lexically_normal(); }
261
262
    std::string inline GetStoppingPowerFile() const { return std::filesystem::path( _stoppingPowerFile ).lexically_normal(); }
    std::string inline GetDataDir() const { return std::filesystem::path( _dataDir ).lexically_normal(); }
263

264
    // Quadrature Structure
steffen.schotthoefer's avatar
steffen.schotthoefer committed
265
    unsigned GetNQuadPoints() { return _nQuadPoints; }
266
267
    QUAD_NAME inline GetQuadName() const { return _quadName; }
    unsigned short inline GetQuadOrder() const { return _quadOrder; }
268
269
270

    // Mesh Structure
    unsigned GetNCells() { return _nCells; }
271
    unsigned short GetDim() { return _dim; }
272

273
274
    // Solver Structure
    double inline GetCFL() const { return _CFL; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
275
276
277
    bool inline GetCleanFluxMat() const { return _cleanFluxMat; }
    ENTROPY_NAME inline GetEntropyName() const { return _entropyName; }
    unsigned short inline GetMaxMomentDegree() const { return _maxMomentDegree; }
278
    PROBLEM_NAME inline GetProblemName() const { return _problemName; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
279
    unsigned inline GetReconsOrder() { return _reconsOrder; }
280
    SOLVER_NAME inline GetSolverName() const { return _solverName; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
281
    double inline GetTEnd() const { return _tEnd; }
282
    bool inline GetSNAllGaussPts() const { return _allGaussPts; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
283
    bool inline GetIsCSD() const { return _csd; }
284

285
286
    // Linesource
    double inline GetSigmaS() const { return _sigmaS; }
287

288
289
    // CSD
    double inline GetMaxEnergyCSD() const { return _maxEnergyCSD; }
290
    //  Optimizer
291
    double inline GetNewtonOptimizerEpsilon() const { return _optimizerEpsilon; }
292
    unsigned long inline GetNewtonIter() const { return _newtonIter; }
293
    double inline GetNewtonStepSize() const { return _newtonStepSize; }
294
    unsigned long inline GetNewtonMaxLineSearches() const { return _newtonLineSearchIter; }
295
    bool inline GetNewtonFastMode() const { return _newtonFastMode; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
296
    OPTIMIZER_NAME inline GetOptimizerName() const { return _entropyOptimizerName; }
297

298
299
300
    // Neural Closure
    unsigned short inline GetNeuralModel() { return _neuralModel; }

301
    // Boundary Conditions
302
    BOUNDARY_TYPE GetBoundaryType( std::string nameMarker ) const; /*!< @brief Get Boundary Type of given marker */
303

jannick.wolters's avatar
jannick.wolters committed
304
305
306
    // Scattering Kernel
    KERNEL_NAME inline GetKernelName() const { return _kernelName; }

307
308
    // Basis name
    SPHERICAL_BASIS_NAME inline GetSphericalBasisName() const { return _sphericalBasisName; }
309
    // Output Structure
310
311
    std::vector<VOLUME_OUTPUT> inline GetVolumeOutput() { return _volumeOutput; }
    unsigned short inline GetNVolumeOutput() { return _nVolumeOutput; }
312
    unsigned short inline GetVolumeOutputFrequency() { return _volumeOutputFrequency; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
313

314
    std::vector<SCALAR_OUTPUT> inline GetScreenOutput() { return _screenOutput; }
315
316
    unsigned short inline GetNScreenOutput() { return _nScreenOutput; }
    unsigned short inline GetScreenOutputFrequency() { return _screenOutputFrequency; }
317
318
319
320

    std::vector<SCALAR_OUTPUT> inline GetHistoryOutput() { return _historyOutput; }
    unsigned short inline GetNHistoryOutput() { return _nHistoryOutput; }
    unsigned short inline GetHistoryOutputFrequency() { return _historyOutputFrequency; }
steffen.schotthoefer's avatar
steffen.schotthoefer committed
321

322
323
324
325
    // Data generator
    bool inline GetDataGeneratorMode() { return _dataGeneratorMode; }
    unsigned long inline GetTrainingDataSetSize() { return _tainingSetSize; }
    unsigned long inline GetMaxValFirstMoment() { return _maxValFirstMoment; }
326
327
    double GetRealizableSetEpsilonU0() { return _RealizableSetEpsilonU0; }
    double GetRealizableSetEpsilonU1() { return _RealizableSetEpsilonU1; }
328
    bool inline GetNormalizedSampling() { return _normalizedSampling; }
329
330
331

    // ---- Setters for option structure
    // This section is dangerous
steffen.schotthoefer's avatar
steffen.schotthoefer committed
332
    // Quadrature Structure
333
334
335
336
337
338
    void SetNQuadPoints( unsigned nq ) { _nQuadPoints = nq; }        /*!< @brief Never change the nq! This is only for the test framework. */
    void SetQuadName( QUAD_NAME quadName ) { _quadName = quadName; } /*!< @brief Never change the quadName! This is only for the test framework. */
    void SetQuadOrder( unsigned quadOrder ) {
        _quadOrder = quadOrder;
    }                                                               /*!< @brief Never change the quadOrder! This is only for the test framework. */
    void SetSNAllGaussPts( bool useall ) { _allGaussPts = useall; } /*!< @brief Never change the this! This is only for the test framework. */
steffen.schotthoefer's avatar
steffen.schotthoefer committed
339
340
    // Mesh Structure
    void SetNCells( unsigned nCells ) { _nCells = nCells; }
341
342
};

343
#endif    // CONFIG_H