queso-0.53.0
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 #include <boost/program_options.hpp>
26 
27 #include <queso/Defines.h>
28 #include <queso/StatisticalForwardProblemOptions.h>
29 #include <queso/Miscellaneous.h>
30 
31 namespace QUESO {
32 
33 // --------------------------------------------------
34 // SfpOptionsValues---------------------------
35 // --------------------------------------------------
36 
37 // Default constructor -----------------------------
39  :
40  m_prefix ("fp_"),
41  m_help(UQ_SFP_HELP),
42  m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
43  m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
44  m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
45  m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
46  //m_dataOutputAllowedSet(),
47  m_parser(NULL),
48  m_option_help (m_prefix + "help" ),
49  m_option_computeSolution (m_prefix + "computeSolution" ),
50  m_option_computeCovariances (m_prefix + "computeCovariances" ),
51  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
52  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
53  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
54 #ifdef UQ_SFP_READS_SOLVER_OPTION
55  m_option_solver (m_prefix + "solver" ),
56  m_solverString (UQ_SFP_SOLVER_ODV )
57 #endif
58 {
59 }
60 
62  prefix)
63  :
64  m_prefix ((std::string)(prefix) + "fp_"),
65  m_help(UQ_SFP_HELP),
66  m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
67  m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
68  m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
69  m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
70  //m_dataOutputAllowedSet(),
71  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
72  m_option_help (m_prefix + "help" ),
73  m_option_computeSolution (m_prefix + "computeSolution" ),
74  m_option_computeCovariances (m_prefix + "computeCovariances" ),
75  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
76  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
77  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
78 #ifdef UQ_SFP_READS_SOLVER_OPTION
79  m_option_solver (m_prefix + "solver" ),
80  m_solverString (UQ_SFP_SOLVER_ODV )
81 #endif
82 {
83  m_parser->registerOption<std::string>(m_option_help, UQ_SFP_HELP, "produce help message for statistical forward problem");
84  m_parser->registerOption<bool >(m_option_computeSolution, UQ_SFP_COMPUTE_SOLUTION_ODV , "compute solution process" );
87  m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
88  m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
89 #ifdef UQ_SFP_READS_SOLVER_OPTION
90  m_parser->registerOption<std::string>(m_option_solver, UQ_SFP_SOLVER_ODV , "algorithm for propagation" );
91 #endif
92 
94 
95  m_parser->getOption<std::string>(m_option_help, m_help);
101 #ifdef UQ_SFP_READS_SOLVER_OPTION
102  m_parser->getOption<std::string>(m_option_solver, m_solver);
103 #endif
104 
105  checkOptions();
106 }
107 
108 // Copy constructor----------------------------------
110 {
111  this->copy(src);
112 }
113 // Destructor ---------------------------------------
115 {
116 }
117 // Set methods --------------------------------------
120 {
121  this->copy(rhs);
122  return *this;
123 }
124 
125 void
127 {
128  // Do nothing
129 }
130 
131 // Private methods-----------------------------------
132 void
134 {
140 #ifdef UQ_SFP_READS_SOLVER_OPTION
141  m_solverString = src.m_solverString;
142 #endif
143 
144  //m_mcOptionsValues = src.m_mcOptionsValues;
145 
146  return;
147 }
148 
149 std::ostream &
150 operator<<(std::ostream & os, const SfpOptionsValues & obj)
151 {
152  os << (*(obj.m_parser)) << std::endl;
153 
154  os << obj.m_option_computeSolution << " = " << obj.m_computeSolution
155  << "\n" << obj.m_option_computeCovariances << " = " << obj.m_computeCovariances
156  << "\n" << obj.m_option_computeCorrelations << " = " << obj.m_computeCorrelations
157  << "\n" << obj.m_option_dataOutputFileName << " = " << obj.m_dataOutputFileName;
158  os << "\n" << obj.m_option_dataOutputAllowedSet << " = ";
159  for (std::set<unsigned int>::iterator setIt = obj.m_dataOutputAllowedSet.begin(); setIt != obj.m_dataOutputAllowedSet.end(); ++setIt) {
160  os << *setIt << " ";
161  }
162 #ifdef UQ_SFP_READS_SOLVER_OPTION
163  << "\n" << obj.m_option_solver << " = " << obj.m_solverString
164 #endif
165  os << std::endl;
166  return os;
167 }
168 
169 // --------------------------------------------------
170 // StatisticalForwardProblemOptions-----------
171 // --------------------------------------------------
172 
173 // Default constructor -----------------------------
175  const BaseEnvironment& env,
176  const char* prefix)
177  :
178  m_ov (),
179  m_prefix ((std::string)(prefix) + "fp_" ),
180  m_env (env),
181  m_optionsDesc (new boost::program_options::options_description("Statistical Forward Problem options")),
182  m_option_help (m_prefix + "help" ),
183  m_option_computeSolution (m_prefix + "computeSolution" ),
184  m_option_computeCovariances (m_prefix + "computeCovariances" ),
185  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
186  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
187  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
188 #ifdef UQ_SFP_READS_SOLVER_OPTION
189  m_option_solver (m_prefix + "solver" )
190 #endif
191 {
193 
194  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the absence of an options input file");
195 }
196 
198  const BaseEnvironment& env,
199  const char* prefix,
200  const SfpOptionsValues& alternativeOptionsValues)
201  :
202  m_ov (alternativeOptionsValues ),
203  m_prefix ((std::string)(prefix) + "fp_" ),
204  m_env (env),
205  m_optionsDesc (NULL),
206  m_option_help (m_prefix + "help" ),
207  m_option_computeSolution (m_prefix + "computeSolution" ),
208  m_option_computeCovariances (m_prefix + "computeCovariances" ),
209  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
210  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
211  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
212 #ifdef UQ_SFP_READS_SOLVER_OPTION
213  m_option_solver (m_prefix + "solver" )
214 #endif
215 {
217 
218  queso_require_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the existence of an options input file");
219 
220  if (m_env.subDisplayFile() != NULL) {
221  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::constructor(2)"
222  << ": after setting values of options with prefix '" << m_prefix
223  << "', state of object is:"
224  << "\n" << *this
225  << std::endl;
226  }
227 }
228 // Destructor --------------------------------------
230 {
232 
233  if (m_optionsDesc) delete m_optionsDesc;
234 }
235 
236 // I/O methods -------------------------------------
237 void
239 {
241 
242  queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL");
243 
247 
248  if (m_env.subDisplayFile() != NULL) {
249  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::scanOptionsValues()"
250  << ": after reading values of options with prefix '" << m_prefix
251  << "', state of object is:"
252  << "\n" << *this
253  << std::endl;
254  }
255 
256  return;
257 }
258 //--------------------------------------------------
259 void
261 {
263 
268  os << "\n" << m_option_dataOutputAllowedSet << " = ";
269  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
270  os << *setIt << " ";
271  }
272 #ifdef UQ_SFP_READS_SOLVER_OPTION
273  << "\n" << m_option_solver << " = " << m_ov.m_solverString
274 #endif
275  os << std::endl;
276 
277  return;
278 }
279 
280 // Private methods ---------------------------------
281 void
282 StatisticalForwardProblemOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const
283 {
285 
286  optionsDesc.add_options()
287  (m_option_help.c_str(), "produce help message for statistical forward problem")
288  (m_option_computeSolution.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
289  (m_option_computeCovariances.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_COVARIANCES_ODV ), "compute pq covariances" )
290  (m_option_computeCorrelations.c_str(), boost::program_options::value<bool >()->default_value(UQ_SFP_COMPUTE_CORRELATIONS_ODV ), "compute pq correlations" )
291  (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" )
292  (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" )
293 #ifdef UQ_SFP_READS_SOLVER_OPTION
294  (m_option_solver.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SFP_SOLVER_ODV ), "algorithm for propagation" )
295 #endif
296  ;
297 
298  return;
299 }
300 //--------------------------------------------------
301 void
302 StatisticalForwardProblemOptions::getMyOptionValues(boost::program_options::options_description& optionsDesc)
303 {
305 
306  if (m_env.allOptionsMap().count(m_option_help)) {
307  if (m_env.subDisplayFile()) {
308  *m_env.subDisplayFile() << optionsDesc
309  << std::endl;
310  }
311  }
312 
314  m_ov.m_computeSolution = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
315  }
316 
318  m_ov.m_computeCovariances = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeCovariances]).as<bool>();
319  }
320 
322  m_ov.m_computeCorrelations = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeCorrelations]).as<bool>();
323  }
324 
326  m_ov.m_dataOutputFileName = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
327  }
328 
331  std::vector<double> tmpAllow(0,0.);
332  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
333  MiscReadDoublesFromString(inputString,tmpAllow);
334 
335  if (tmpAllow.size() > 0) {
336  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
337  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
338  }
339  }
340  }
341 
342 #ifdef UQ_SFP_READS_SOLVER_OPTION
343  if (m_env.allOptionsMap().count(m_option_solver)) {
344  m_ov.m_solverString = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
345  }
346 #endif
347 
348  return;
349 }
350 
351 // --------------------------------------------------
352 // Operator declared outside class definition ------
353 // --------------------------------------------------
354 
355 std::ostream& operator<<(std::ostream& os, const StatisticalForwardProblemOptions& obj)
356 {
358 
359  obj.print(os);
360 
361  return os;
362 }
363 
364 } // End namespace QUESO
#define UQ_SFP_COMPUTE_SOLUTION_ODV
#define UQ_SFP_COMPUTE_CORRELATIONS_ODV
StatisticalForwardProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
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:345
void copy(const SfpOptionsValues &src)
Copies the option values from src to this.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
#define UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
std::set< unsigned int > m_dataOutputAllowedSet
This class reads option values for a Statistical Forward Problem from an input file.
This class provides options for a Statistical Forward Problem if no input file is available...
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:336
boost::program_options::options_description * m_optionsDesc
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:307
void scanInputFile()
This is the method that parses the input file.
#define UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
void print(std::ostream &os) const
It prints the option values.
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
SfpOptionsValues & operator=(const SfpOptionsValues &rhs)
Assignment operator; it copies rhs to this.
SfpOptionsValues()
Constructor/Destructor methods.
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
void getMyOptionValues(boost::program_options::options_description &optionsDesc)
Gets the option values of the SFP.
std::string m_help
If non-empty string, options and values are printed to the output file.
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
#define queso_deprecated()
Definition: Defines.h:120
void defineMyOptions(boost::program_options::options_description &optionsDesc) const
Define my SFP options as the default options.
#define UQ_SFP_COMPUTE_COVARIANCES_ODV
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.
void scanOptionsValues()
It scans the option values from the options input file.

Generated on Thu Jun 11 2015 13:52:33 for queso-0.53.0 by  doxygen 1.8.5