Athena++/Atmosphere
Planetary Atmosphere Simulator
parameter_input.hpp
Go to the documentation of this file.
1 #ifndef PARAMETER_INPUT_HPP_
2 #define PARAMETER_INPUT_HPP_
3 //========================================================================================
4 // Athena++ astrophysical MHD code
5 // Copyright(C) 2014 James M. Stone <jmstone@princeton.edu> and other code contributors
6 // Licensed under the 3-clause BSD License, see LICENSE file for details
7 //========================================================================================
9 // \brief definition of class ParameterInput
10 // Contains data structures used to store, and functions used to access, parameters
11 // read from the input file. See comments at start of parameter_input.cpp for more
12 // information on the Athena++ input file format.
13 
14 // C headers
15 
16 // C++ headers
17 #include <cstddef> // std::size_t
18 #include <ostream> // ostream
19 #include <string> // string
20 
21 // Athena++ headers
22 #include "athena.hpp"
23 #include "defs.hpp"
24 #include "outputs/io_wrapper.hpp"
25 
26 // OpenMP header
27 #ifdef OPENMP_PARALLEL
28 #include <omp.h>
29 #endif
30 
31 //----------------------------------------------------------------------------------------
33 // \brief node in a singly linked list of parameters contained within 1x input block
34 
35 struct InputLine {
36  std::string param_name;
37  std::string param_value; // value of the parameter is stored as a string!
38  std::string param_comment;
39  InputLine *pnext; // pointer to the next node in this nested singly linked list
40 };
41 
42 //----------------------------------------------------------------------------------------
44 // \brief node in a singly linked list of all input blocks contained within input file
45 
46 class InputBlock {
47  public:
48  InputBlock() = default;
49  ~InputBlock();
50 
51  // data
52  std::string block_name;
53  std::size_t max_len_parname; // length of longest param_name, for nice-looking output
54  std::size_t max_len_parvalue; // length of longest param_value, to format outputs
55  InputBlock *pnext; // pointer to the next node in InputBlock singly linked list
56 
57  InputLine *pline; // pointer to head node in nested singly linked list (in this block)
58  // (not storing a reference to the tail node)
59 
60  // functions
61  InputLine* GetPtrToLine(std::string name);
62 };
63 
64 //----------------------------------------------------------------------------------------
66 // \brief data and definitions of functions used to store and access input parameters
67 // Functions are implemented in parameter_input.cpp
68 
70  public:
71  // constructor/destructor
74 
75  // data
76  InputBlock* pfirst_block; // pointer to head node in singly linked list of InputBlock
77  // (not storing a reference to the tail node)
78 
79  // functions
80  void LoadFromStream(std::istream &is);
81  void LoadFromFile(IOWrapper &input);
82  void ModifyFromCmdline(int argc, char *argv[]);
83  void ParameterDump(std::ostream& os);
84  int DoesParameterExist(std::string block, std::string name);
85  int GetInteger(std::string block, std::string name);
86  int GetOrAddInteger(std::string block, std::string name, int value);
87  int SetInteger(std::string block, std::string name, int value);
88  Real GetReal(std::string block, std::string name);
89  Real GetOrAddReal(std::string block, std::string name, Real value);
90  Real SetReal(std::string block, std::string name, Real value);
91  bool GetBoolean(std::string block, std::string name);
92  bool GetOrAddBoolean(std::string block, std::string name, bool value);
93  bool SetBoolean(std::string block, std::string name, bool value);
94  std::string GetString(std::string block, std::string name);
95  std::string GetOrAddString(std::string block, std::string name, std::string value);
96  std::string SetString(std::string block, std::string name, std::string value);
97  void RollbackNextTime();
98  void ForwardNextTime(Real time);
99  InputBlock* GetPtrToBlock(std::string name);
100  void AddParameter(InputBlock *pib, std::string name, std::string value,
101  std::string comment);
102 
103  private:
104  std::string last_filename_; // last input file opened, to prevent duplicate reads
105 
106  InputBlock* FindOrAddBlock(std::string name);
107  void ParseLine(InputBlock *pib, std::string line, std::string& name,
108  std::string& value, std::string& comment);
109 
110  // thread safety
111 #ifdef OPENMP_PARALLEL
112  omp_lock_t lock_;
113 #endif
114 
115  void Lock();
116  void Unlock();
117 };
118 #endif // PARAMETER_INPUT_HPP_
double Real
Definition: athena.hpp:29
InputLine * GetPtrToLine(std::string name)
std::size_t max_len_parvalue
std::size_t max_len_parname
InputLine * pline
InputBlock()=default
InputBlock * pnext
std::string block_name
Real GetReal(std::string block, std::string name)
int DoesParameterExist(std::string block, std::string name)
void AddParameter(InputBlock *pib, std::string name, std::string value, std::string comment)
void LoadFromStream(std::istream &is)
std::string GetString(std::string block, std::string name)
void ParseLine(InputBlock *pib, std::string line, std::string &name, std::string &value, std::string &comment)
void ParameterDump(std::ostream &os)
int GetOrAddInteger(std::string block, std::string name, int value)
int GetInteger(std::string block, std::string name)
InputBlock * GetPtrToBlock(std::string name)
int SetInteger(std::string block, std::string name, int value)
Real SetReal(std::string block, std::string name, Real value)
bool GetBoolean(std::string block, std::string name)
std::string GetOrAddString(std::string block, std::string name, std::string value)
std::string last_filename_
bool GetOrAddBoolean(std::string block, std::string name, bool value)
bool SetBoolean(std::string block, std::string name, bool value)
std::string SetString(std::string block, std::string name, std::string value)
void ModifyFromCmdline(int argc, char *argv[])
void ParameterInput::ModifyFromCmdline(int argc, char *argv[])
void LoadFromFile(IOWrapper &input)
InputBlock * FindOrAddBlock(std::string name)
Real GetOrAddReal(std::string block, std::string name, Real value)
InputBlock * pfirst_block
void ForwardNextTime(Real time)
std::string param_value
std::string param_name
std::string param_comment
InputLine * pnext