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

Generated on Sat Apr 22 2017 14:04:36 for queso-0.57.0 by  doxygen 1.8.5