queso-0.56.1
StatisticalForwardProblemOptions.C
Go to the documentation of this file.
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-2015 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 DISABLE_BOOST_PROGRAM_OPTIONS
26 #include <boost/program_options.hpp>
27 #endif
28 
29 #include <queso/Defines.h>
30 #include <queso/StatisticalForwardProblemOptions.h>
31 #include <queso/Miscellaneous.h>
32 
33 namespace QUESO {
34 
35 // --------------------------------------------------
36 // SfpOptionsValues---------------------------
37 // --------------------------------------------------
38 
39 // Default constructor -----------------------------
41  :
42  m_prefix ("fp_"),
43  m_help(UQ_SFP_HELP),
44  m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
45  m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
46  m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
47  m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
48  //m_dataOutputAllowedSet(),
49 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
50  m_parser(NULL),
51 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
52  m_option_help (m_prefix + "help" ),
53  m_option_computeSolution (m_prefix + "computeSolution" ),
54  m_option_computeCovariances (m_prefix + "computeCovariances" ),
55  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
56  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
57  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
58 #ifdef UQ_SFP_READS_SOLVER_OPTION
59  m_option_solver (m_prefix + "solver" ),
60  m_solverString (UQ_SFP_SOLVER_ODV )
61 #endif
62 {
63 }
64 
66  prefix)
67  :
68  m_prefix ((std::string)(prefix) + "fp_"),
69  m_help(UQ_SFP_HELP),
70  m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
71  m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
72  m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
73  m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
74  //m_dataOutputAllowedSet(),
75 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
76  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
77 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
78  m_option_help (m_prefix + "help" ),
79  m_option_computeSolution (m_prefix + "computeSolution" ),
80  m_option_computeCovariances (m_prefix + "computeCovariances" ),
81  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
82  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
83  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
84 #ifdef UQ_SFP_READS_SOLVER_OPTION
85  m_option_solver (m_prefix + "solver" ),
86  m_solverString (UQ_SFP_SOLVER_ODV )
87 #endif
88 {
89 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
90  m_parser->registerOption<std::string>(m_option_help, UQ_SFP_HELP, "produce help message for statistical forward problem");
91  m_parser->registerOption<bool >(m_option_computeSolution, UQ_SFP_COMPUTE_SOLUTION_ODV , "compute solution process" );
94  m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
95  m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
96 #ifdef UQ_SFP_READS_SOLVER_OPTION
97  m_parser->registerOption<std::string>(m_option_solver, UQ_SFP_SOLVER_ODV , "algorithm for propagation" );
98 #endif
99 
101 
102  m_parser->getOption<std::string>(m_option_help, m_help);
108 #ifdef UQ_SFP_READS_SOLVER_OPTION
109  m_parser->getOption<std::string>(m_option_solver, m_solver);
110 #endif
111 #else
117 
118  // UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default
119  unsigned int size = env->input().vector_variable_size(m_option_dataOutputAllowedSet);
120  for (unsigned int i = 0; i < size; i++) {
121  // We default to empty set, so the default values are actually never
122  // used here
123  unsigned int allowed = env->input()(m_option_dataOutputAllowedSet, i, i);
124  m_dataOutputAllowedSet.insert(allowed);
125  }
126 
127 #ifdef UQ_SFP_READS_SOLVER_OPTION
128  m_solver = env->input()(m_option_solver, UQ_SFP_SOLVER_ODV);
129 #endif
130 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
131 
132  checkOptions();
133 }
134 
135 // Copy constructor----------------------------------
137 {
138  this->copy(src);
139 }
140 // Destructor ---------------------------------------
142 {
143 }
144 // Set methods --------------------------------------
147 {
148  this->copy(rhs);
149  return *this;
150 }
151 
152 void
154 {
155  // Do nothing
156 }
157 
158 // Private methods-----------------------------------
159 void
161 {
167 #ifdef UQ_SFP_READS_SOLVER_OPTION
168  m_solverString = src.m_solverString;
169 #endif
170 
171  //m_mcOptionsValues = src.m_mcOptionsValues;
172 
173  return;
174 }
175 
176 std::ostream &
177 operator<<(std::ostream & os, const SfpOptionsValues & obj)
178 {
179 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
180  os << (*(obj.m_parser)) << std::endl;
181 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
182 
183  os << obj.m_option_computeSolution << " = " << obj.m_computeSolution
184  << "\n" << obj.m_option_computeCovariances << " = " << obj.m_computeCovariances
185  << "\n" << obj.m_option_computeCorrelations << " = " << obj.m_computeCorrelations
186  << "\n" << obj.m_option_dataOutputFileName << " = " << obj.m_dataOutputFileName;
187  os << "\n" << obj.m_option_dataOutputAllowedSet << " = ";
188  for (std::set<unsigned int>::iterator setIt = obj.m_dataOutputAllowedSet.begin(); setIt != obj.m_dataOutputAllowedSet.end(); ++setIt) {
189  os << *setIt << " ";
190  }
191 #ifdef UQ_SFP_READS_SOLVER_OPTION
192  << "\n" << obj.m_option_solver << " = " << obj.m_solverString
193 #endif
194  os << std::endl;
195  return os;
196 }
197 
198 // --------------------------------------------------
199 // StatisticalForwardProblemOptions-----------
200 // --------------------------------------------------
201 
202 // Default constructor -----------------------------
204  const BaseEnvironment& env,
205  const char* prefix)
206  :
207  m_ov (),
208  m_prefix ((std::string)(prefix) + "fp_" ),
209  m_env (env),
210 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
211  m_optionsDesc (new boost::program_options::options_description("Statistical Forward Problem options")),
212 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
213  m_option_help (m_prefix + "help" ),
214  m_option_computeSolution (m_prefix + "computeSolution" ),
215  m_option_computeCovariances (m_prefix + "computeCovariances" ),
216  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
217  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
218  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
219 #ifdef UQ_SFP_READS_SOLVER_OPTION
220  m_option_solver (m_prefix + "solver" )
221 #endif
222 {
224 
225  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the absence of an options input file"));
226 }
227 
229  const BaseEnvironment& env,
230  const char* prefix,
231  const SfpOptionsValues& alternativeOptionsValues)
232  :
233  m_ov (alternativeOptionsValues ),
234  m_prefix ((std::string)(prefix) + "fp_" ),
235  m_env (env),
236 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
237  m_optionsDesc (NULL),
238 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
239  m_option_help (m_prefix + "help" ),
240  m_option_computeSolution (m_prefix + "computeSolution" ),
241  m_option_computeCovariances (m_prefix + "computeCovariances" ),
242  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
243  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
244  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
245 #ifdef UQ_SFP_READS_SOLVER_OPTION
246  m_option_solver (m_prefix + "solver" )
247 #endif
248 {
250 
251  queso_require_equal_to_msg(m_env.optionsInputFileName(), std::string(""), std::string("this constructor is incompatible with the existence of an options input file"));
252 
253  if (m_env.subDisplayFile() != NULL) {
254  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::constructor(2)"
255  << ": after setting values of options with prefix '" << m_prefix
256  << "', state of object is:"
257  << "\n" << *this
258  << std::endl;
259  }
260 }
261 // Destructor --------------------------------------
263 {
265 
266 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
267  if (m_optionsDesc) delete m_optionsDesc;
268 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
269 }
270 
271 // I/O methods -------------------------------------
272 void
274 {
276 
277 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
278  queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL");
279 
283 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
284 
285  if (m_env.subDisplayFile() != NULL) {
286  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::scanOptionsValues()"
287  << ": after reading values of options with prefix '" << m_prefix
288  << "', state of object is:"
289  << "\n" << *this
290  << std::endl;
291  }
292 
293  return;
294 }
295 //--------------------------------------------------
296 void
298 {
300 
305  os << "\n" << m_option_dataOutputAllowedSet << " = ";
306  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
307  os << *setIt << " ";
308  }
309 #ifdef UQ_SFP_READS_SOLVER_OPTION
310  << "\n" << m_option_solver << " = " << m_ov.m_solverString
311 #endif
312  os << std::endl;
313 
314  return;
315 }
316 
317 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
318 // Private methods ---------------------------------
319 void
320 StatisticalForwardProblemOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const
321 {
323 
324  optionsDesc.add_options()
325  (m_option_help.c_str(), "produce help message for statistical forward problem")
326  (m_option_computeSolution.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
327  (m_option_computeCovariances.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_COVARIANCES_ODV ), "compute pq covariances" )
328  (m_option_computeCorrelations.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_CORRELATIONS_ODV ), "compute pq correlations" )
329  (m_option_dataOutputFileName.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV ), "name of data output file" )
330  (m_option_dataOutputAllowedSet.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to data output file" )
331 #ifdef UQ_SFP_READS_SOLVER_OPTION
332  (m_option_solver.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SFP_SOLVER_ODV ), "algorithm for propagation" )
333 #endif
334  ;
335 
336  return;
337 }
338 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
339 
340 #ifndef DISABLE_BOOST_PROGRAM_OPTIONS
341 //--------------------------------------------------
342 void
343 StatisticalForwardProblemOptions::getMyOptionValues(boost::program_options::options_description& optionsDesc)
344 {
346 
347  if (m_env.allOptionsMap().count(m_option_help)) {
348  if (m_env.subDisplayFile()) {
349  *m_env.subDisplayFile() << optionsDesc
350  << std::endl;
351  }
352  }
353 
355  m_ov.m_computeSolution = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
356  }
357 
359  m_ov.m_computeCovariances = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeCovariances]).as<bool>();
360  }
361 
363  m_ov.m_computeCorrelations = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeCorrelations]).as<bool>();
364  }
365 
367  m_ov.m_dataOutputFileName = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
368  }
369 
372  std::vector<double> tmpAllow(0,0.);
373  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
374  MiscReadDoublesFromString(inputString,tmpAllow);
375 
376  if (tmpAllow.size() > 0) {
377  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
378  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
379  }
380  }
381  }
382 
383 #ifdef UQ_SFP_READS_SOLVER_OPTION
384  if (m_env.allOptionsMap().count(m_option_solver)) {
385  m_ov.m_solverString = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
386  }
387 #endif
388 
389  return;
390 }
391 #endif // DISABLE_BOOST_PROGRAM_OPTIONS
392 
393 // --------------------------------------------------
394 // Operator declared outside class definition ------
395 // --------------------------------------------------
396 
397 std::ostream& operator<<(std::ostream& os, const StatisticalForwardProblemOptions& obj)
398 {
400 
401  obj.print(os);
402 
403  return os;
404 }
405 
406 } // End namespace QUESO
SfpOptionsValues()
Constructor/Destructor methods.
StatisticalForwardProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
const GetPot & input() const
The GetPot input file parser.
Definition: Environment.C:1148
std::string m_help
If non-empty string, options and values are printed to the output file.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:320
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:353
void defineMyOptions(boost::program_options::options_description &optionsDesc) const
Define my SFP options as the default options.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:197
unsigned vector_variable_size(const char *VarName) const
Definition: getpot.h:2532
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:73
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:385
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
#define queso_deprecated()
Definition: Defines.h:134
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
void scanInputFileForMyOptions(const boost::program_options::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:396
void scanInputFile()
This is the method that parses the input file.
#define UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV
#define UQ_SFP_COMPUTE_COVARIANCES_ODV
void scanOptionsValues()
It scans the option values from the options input file.
#define UQ_SFP_COMPUTE_SOLUTION_ODV
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:74
void print(std::ostream &os) const
It prints the option values.
This class provides options for a Statistical Forward Problem if no input file is available...
#define UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
void copy(const SfpOptionsValues &src)
Copies the option values from src to this.
std::set< unsigned int > m_dataOutputAllowedSet
void getMyOptionValues(boost::program_options::options_description &optionsDesc)
Gets the option values of the SFP.
SfpOptionsValues & operator=(const SfpOptionsValues &rhs)
Assignment operator; it copies rhs to this.
#define UQ_SFP_COMPUTE_CORRELATIONS_ODV
boost::program_options::options_description * m_optionsDesc
This class reads option values for a Statistical Forward Problem from an input file.

Generated on Thu Dec 15 2016 13:23:11 for queso-0.56.1 by  doxygen 1.8.5