1 //-----------------------------------------------------------------------bl-
2 //--------------------------------------------------------------------------
3 //
4 // QUESO - a library to support the Quantification of Uncertainty
5 // for Estimation, Simulation and Optimization
6 //
7 // Copyright (C) 2008-2017 The PECOS Development Team
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the Version 2.1 GNU Lesser General
11 // Public License as published by the Free Software Foundation.
12 //
13 // This library is distributed in the hope that it will be useful,
14 // but WITHOUT ANY WARRANTY; without even the implied warranty of
15 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 // Lesser General Public License for more details.
17 //
18 // You should have received a copy of the GNU Lesser General Public
19 // License along with this library; if not, write to the Free Software
20 // Foundation, Inc. 51 Franklin Street, Fifth Floor,
21 // Boston, MA  02110-1301  USA
22 //
23 //-----------------------------------------------------------------------el-
24 
25 #ifndef UQ_ENVIRONMENT_OPTIONS_H
26 #define UQ_ENVIRONMENT_OPTIONS_H
27 
28 #include <string>
29 #include <set>
30 #include <vector>
31 
32 #include <queso/config_queso.h>
33 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
34 #include <queso/BoostInputOptionsParser.h>
35 #endif  // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
36 
37 #include <queso/ScopedPtr.h>
38 
39 #define UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE "."
40 #define UQ_ENV_FILENAME_FOR_NO_INPUT_FILE  "."
41 
42 #define UQ_ENV_HELP                         ""
43 #define UQ_ENV_NUM_SUB_ENVIRONMENTS_ODV     1
44 #define UQ_ENV_SUB_SCREEN_WRITE_ODV         0
45 #define UQ_ENV_SUB_DISPLAY_FILE_NAME_ODV    UQ_ENV_FILENAME_FOR_NO_OUTPUT_FILE
46 #define UQ_ENV_SUB_DISPLAY_ALLOW_ALL_ODV    0
47 #define UQ_ENV_SUB_DISPLAY_ALLOW_INTER0_ODV 0
48 #define UQ_ENV_SUB_DISPLAY_ALLOWED_SET_ODV  ""
49 #define UQ_ENV_DISPLAY_VERBOSITY_ODV        0
50 #define UQ_ENV_SYNC_VERBOSITY_ODV           0
51 #define UQ_ENV_CHECKING_LEVEL_ODV           0
52 #define UQ_ENV_RNG_TYPE_ODV                 "gsl"
53 #define UQ_ENV_SEED_ODV                     0
54 #define UQ_ENV_IDENTIFYING_STRING_ODV       ""
55 #define UQ_ENV_PLATFORM_NAME_ODV            ""
56 #define UQ_ENV_NUM_DEBUG_PARAMS_ODV         0
57 #define UQ_ENV_DEBUG_PARAM_ODV              0.
58 
59 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
60 // Forward declarations
61 namespace boost {
62   namespace program_options {
63     class options_description;
64     }
65 }
66 #endif  // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
67 
68 namespace QUESO {
69 
70 // Forward declarations
71 class BaseEnvironment;
72 
73 /*! \file EnvironmentOptions.h
74     \brief Class to allow options to be passed to a QUESO environment.
75 */
76 
77 /*! \class EnvOptionsValues
78  *  \brief This class provides a suite options one can pass to a QUESO environment.
79  *
80  *  QUESO expects the user to provide an input file with environment options for the library variables.
81  *  If no input file, a collection of default values is assigned to some of the variables. The class
82  *  EnvOptionsValues is responsible for this task.
83  */
84 
85 class EnvOptionsValues
86 {
87 public:
88   //! @name Constructor/Destructor methods
89   //@{
90   //! Default constructor
91   EnvOptionsValues();
92   EnvOptionsValues(const BaseEnvironment * env, const char * prefix);
93 
94   //! Copy constructor
95   EnvOptionsValues(const EnvOptionsValues& src);
96 
97   //! Set parameter option names to begin with prefix
98   void set_prefix(const std::string& prefix);
99 
100   //! Set default values for parameter options
101   void set_defaults();
102 
103   //! Given prefix, read the input file for parameters named "prefix"+*
104   void parse(const BaseEnvironment& env, const std::string& prefix);
105 
106   //! Destructor
107   virtual ~EnvOptionsValues();
108   //@}
109 
110   //! @name Set methods
111   //@{
112   //! Operator for copying the options of an environment.
113   EnvOptionsValues & operator=(const EnvOptionsValues& rhs);
114   //@}
115 
116   std::string m_prefix;
117 
118   //! @name Attributes
119   //! If this string is non-empty, print the options object to the output file
120   std::string m_help;
121 
122   //! Number of sub-environments (chains).  Each chain may have multiple
123   //! processes.
124   unsigned int m_numSubEnvironments;
125 
126   //! Output filename for sub-screen writing.
127   std::string m_subDisplayFileName;
128 
129   //! Allows (or not) all sub-environments to write to output file.
130   /*!
131    * If this option is true, m_subDisplayAllowedSet is ignored.
132    */
133   bool m_subDisplayAllowAll;
134 
135   //! Allows (or not) all inter0 nodes to write to output file
136   /*!
137    * If this option is true, m_subDisplayAllowedSet is ignored.
138    */
139   bool m_subDisplayAllowInter0;
140 
141   //! Sub-environments that will write to output.
142   /*!
143    * This option is ignored if either m_subDisplayAllowAll or
144    * m_subDisplayAllowInter0 are true.
145    */
146   std::set<unsigned int> m_subDisplayAllowedSet;
147 
148   //! Verbosity.
149   unsigned int m_displayVerbosity;
150 
151   //! Synchronized verbosity.
152   unsigned int m_syncVerbosity;
153 
154   //! Checking level
155   unsigned int m_checkingLevel;
156 
157   //! Type of the random number generator.
158   std::string m_rngType;
159 
160   //! Seed of the random number generator.
161   /*!
162    * If env_seed = -z, with z>=1, then each processor sets the seed to value
163    * MPI_RANK + z.  It is crucial that \verb+env_seed+ takes a
164    * \underline{negative} value, otherwise all chain samples are going to be
165    * the same.
166    */
167   int m_seed;
168 
169   //! Platform name.
170   std::string m_platformName;
171 
172   //! Identifying string.
173   std::string m_identifyingString;
174 
175   //! Number of debug parameters.  Unused?
176   unsigned int m_numDebugParams;
177 
178   //! Debug parameters.  Unused?
179   std::vector<double> m_debugParams;
180   //@}
181 
182 private:
183   const BaseEnvironment * m_env;
184 
185 #ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
186   ScopedPtr<BoostInputOptionsParser>::Type m_parser;
187 #endif  // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
188 
189   //! Input file option name for flagging helpful printing output
190   std::string m_option_help;
191 
192   //! Input file option name for m_numSubEnvironments.
193   std::string m_option_numSubEnvironments;
194 
195   //! Input file option name for m_subDisplayFileName
196   std::string m_option_subDisplayFileName;
197 
198   //! Input file option name for m_subDisplayAllowAll
199   std::string m_option_subDisplayAllowAll;
200 
201   //! Input file option name for m_subDisplayAllowInter0
202   std::string m_option_subDisplayAllowInter0;
203 
204   //! Input file option name for m_subDisplayAllowedSet
205   std::string m_option_subDisplayAllowedSet;
206 
207   //! Input file option name for m_displayVerbosity
208   std::string m_option_displayVerbosity;
209 
210   //! Input file option name for m_syncVerbosity
211   std::string m_option_syncVerbosity;
212 
213   //! Input file option name for m_checkingLevel
214   std::string m_option_checkingLevel;
215 
216   //! Input file option name for m_rngType
217   std::string m_option_rngType;
218 
219   //! Input file option name for m_seed
220   std::string m_option_seed;
221 
222   //! Input file option name for m_platformName
223   std::string m_option_platformName;
224 
225   //! Input file option name for m_identifyingString
226   std::string m_option_identifyingString;
227 
228   //! Makes an exact copy of an existing EnvOptionsValues instance.
229   void copy(const EnvOptionsValues& src);
230 
231   //! Sorts out any inter-option conflicts
232   void checkOptions();
233 
234   //! Print values of the options chosen.
235   friend std::ostream& operator<<(std::ostream& os,
236       const EnvOptionsValues & obj);
237 };
238 
239 
240 }  // End namespace QUESO
241 
242 #endif // UQ_ENVIRONMENT_CLASS_H
243