queso-0.53.0
ExperimentModelOptions.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/ExperimentModelOptions.h>
28 #include <queso/Miscellaneous.h>
29 
30 namespace QUESO {
31 
33  :
34  m_prefix("em_"),
35  m_Gvalues(0),
42  m_parser(NULL),
43  m_option_help(m_prefix + "help"),
44  m_option_Gvalues(m_prefix + "Gvalues"),
45  m_option_a_v(m_prefix + "a_v"),
46  m_option_b_v(m_prefix + "b_v"),
47  m_option_a_rho_v(m_prefix + "a_rho_v"),
48  m_option_b_rho_v(m_prefix + "b_rho_v"),
49  m_option_a_y(m_prefix + "a_y"),
50  m_option_b_y(m_prefix + "b_y")
51 {
52 }
53 
55  prefix)
56  :
57  m_prefix((std::string)(prefix) + "em_"),
58  m_Gvalues(0),
65  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
66  m_option_help(m_prefix + "help"),
67  m_option_Gvalues(m_prefix + "Gvalues"),
68  m_option_a_v(m_prefix + "a_v"),
69  m_option_b_v(m_prefix + "b_v"),
70  m_option_a_rho_v(m_prefix + "a_rho_v"),
71  m_option_b_rho_v(m_prefix + "b_rho_v"),
72  m_option_a_y(m_prefix + "a_y"),
73  m_option_b_y(m_prefix + "b_y")
74 {
75  m_parser->registerOption(m_option_help, "produce help message for experiment model options");
83 
85 
86  m_parser->getOption<std::vector<unsigned int> >(m_option_Gvalues, m_Gvalues);
93 }
94 
96 {
97 }
98 
100 {
101  this->copy(src);
102 }
103 
106 {
107  this->copy(rhs);
108  return *this;
109 }
110 
111 // void
112 // EmOptionsValues::defineOptions()
113 // {
114 // (*m_optionsDescription).add_options()
115 // (m_option_help.c_str(), "produce help message for experiment model options")
116 // (m_option_Gvalues.c_str(), boost::program_options::value<std::string >()->default_value(UQ_EXPERIMENT_MODEL_G_VALUES_ODV), "G values" )
117 // (m_option_a_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_V_ODV ), "a_v" )
118 // (m_option_b_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_V_ODV ), "b_v" )
119 // (m_option_a_rho_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_RHO_V_ODV ), "a_rho_v" )
120 // (m_option_b_rho_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_RHO_V_ODV ), "b_rho_v" )
121 // (m_option_a_y.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_Y_ODV ), "a_y" )
122 // (m_option_b_y.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_Y_ODV ), "b_y" )
123 // ;
124 // }
125 //
126 // void
127 // EmOptionsValues::getOptionValues()
128 // {
129 // if ((*m_optionsMap).count(m_option_help)) {
130 // if (m_env->subDisplayFile()) {
131 // *m_env->subDisplayFile() << *m_optionsDescription
132 // << std::endl;
133 // }
134 // }
135 //
136 // std::vector<double> tmpValues(0,0.);
137 // if ((*m_optionsMap).count(m_option_Gvalues)) {
138 // std::string inputString = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_Gvalues]).as<std::string>();
139 // MiscReadDoublesFromString(inputString,tmpValues);
140 // //if (m_env->subDisplayFile()) {
141 // // *m_env->subDisplayFile() << "In ExperimentModelOptions::getMyOptionValues(): tmpValues =";
142 // // for (unsigned int i = 0; i < tmpValues.size(); ++i) {
143 // // *m_env->subDisplayFile() << " " << tmpValues[i];
144 // // }
145 // // *m_env->subDisplayFile() << std::endl;
146 // //}
147 // unsigned int tmpSize = tmpValues.size();
148 // m_Gvalues.clear();
149 // m_Gvalues.resize(tmpSize,0);
150 // for (unsigned int i = 0; i < tmpSize; ++i) {
151 // m_Gvalues[i] = (unsigned int) tmpValues[i];
152 // }
153 // }
154 //
155 // if ((*m_optionsMap).count(m_option_a_v)) {
156 // m_a_v = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_a_v]).as<double>();
157 // }
158 //
159 // if ((*m_optionsMap).count(m_option_b_v)) {
160 // m_b_v = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_b_v]).as<double>();
161 // }
162 //
163 // if ((*m_optionsMap).count(m_option_a_rho_v)) {
164 // m_a_rho_v = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_a_rho_v]).as<double>();
165 // }
166 //
167 // if ((*m_optionsMap).count(m_option_b_rho_v)) {
168 // m_b_rho_v = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_b_rho_v]).as<double>();
169 // }
170 //
171 // if ((*m_optionsMap).count(m_option_a_y)) {
172 // m_a_y = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_a_y]).as<double>();
173 // }
174 //
175 // if ((*m_optionsMap).count(m_option_b_y)) {
176 // m_b_y = ((const boost::program_options::variable_value&) (*m_optionsMap)[m_option_b_y]).as<double>();
177 // }
178 // }
179 
180 void
182 {
183  m_Gvalues = src.m_Gvalues;
184  m_a_v = src.m_a_v;
185  m_b_v = src.m_b_v;
186  m_a_rho_v = src.m_a_rho_v;
187  m_b_rho_v = src.m_b_rho_v;
188  m_a_y = src.m_a_y;
189  m_b_y = src.m_b_y;
190 
191  return;
192 }
193 
195  const BaseEnvironment& env,
196  const char* prefix)
197  :
198  m_ov (),
199  m_prefix ((std::string)(prefix) + "em_"),
200  m_env (env),
201  m_optionsDesc (new boost::program_options::options_description("Experiment model options")),
202  m_option_help (m_prefix + "help" ),
203  m_option_Gvalues(m_prefix + "Gvalues"),
204  m_option_a_v (m_prefix + "a_v" ),
205  m_option_b_v (m_prefix + "b_v" ),
206  m_option_a_rho_v(m_prefix + "a_rho_v"),
207  m_option_b_rho_v(m_prefix + "b_rho_v"),
208  m_option_a_y (m_prefix + "a_y" ),
209  m_option_b_y (m_prefix + "b_y" )
210 {
212 
213  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the abscense of an options input file");
214 }
215 
217  const BaseEnvironment& env,
218  const char* prefix,
219  const EmOptionsValues& alternativeOptionsValues)
220  :
221  m_ov (alternativeOptionsValues),
222  m_prefix ((std::string)(prefix) + "em_"),
223  m_env (env),
224  m_optionsDesc (NULL),
225  m_option_help (m_prefix + "help" ),
226  m_option_Gvalues(m_prefix + "Gvalues"),
227  m_option_a_v (m_prefix + "a_v" ),
228  m_option_b_v (m_prefix + "b_v" ),
229  m_option_a_rho_v(m_prefix + "a_rho_v"),
230  m_option_b_rho_v(m_prefix + "b_rho_v"),
231  m_option_a_y (m_prefix + "a_y" ),
232  m_option_b_y (m_prefix + "b_y" )
233 {
235 
236  queso_require_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the existence of an options input file");
237 
238  if (m_env.subDisplayFile() != NULL) {
239  *m_env.subDisplayFile() << "In ExperimentModelOptions::constructor(2)"
240  << ": after setting values of options with prefix '" << m_prefix
241  << "', state of object is:"
242  << "\n" << *this
243  << std::endl;
244  }
245 }
246 
248 {
250 
251  if (m_optionsDesc) delete m_optionsDesc;
252 }
253 
254 void
256 {
258 
259  queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL");
260 
264 
265  if (m_env.subDisplayFile() != NULL) {
266  *m_env.subDisplayFile() << "In ExperimentModelOptions::scanOptionsValues()"
267  << ": after reading values of options with prefix '" << m_prefix
268  << "', state of object is:"
269  << "\n" << *this
270  << std::endl;
271  }
272 
273  return;
274 }
275 
276 void
277 ExperimentModelOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const
278 {
280 
281  optionsDesc.add_options()
282  (m_option_help.c_str(), "produce help message for experiment model options")
283  (m_option_Gvalues.c_str(), boost::program_options::value<std::string >()->default_value(UQ_EXPERIMENT_MODEL_G_VALUES_ODV), "G values" )
284  (m_option_a_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_V_ODV ), "a_v" )
285  (m_option_b_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_V_ODV ), "b_v" )
286  (m_option_a_rho_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_RHO_V_ODV ), "a_rho_v" )
287  (m_option_b_rho_v.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_RHO_V_ODV ), "b_rho_v" )
288  (m_option_a_y.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_A_Y_ODV ), "a_y" )
289  (m_option_b_y.c_str(), boost::program_options::value<double >()->default_value(UQ_EXPERIMENT_MODEL_B_Y_ODV ), "b_y" )
290  ;
291 
292  return;
293 }
294 
295 void
296 ExperimentModelOptions::getMyOptionValues(boost::program_options::options_description& optionsDesc)
297 {
299 
300  if (m_env.allOptionsMap().count(m_option_help)) {
301  if (m_env.subDisplayFile()) {
302  *m_env.subDisplayFile() << optionsDesc
303  << std::endl;
304  }
305  }
306 
307  std::vector<double> tmpValues(0,0.);
308  if (m_env.allOptionsMap().count(m_option_Gvalues)) {
309  std::string inputString = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_Gvalues]).as<std::string>();
310  MiscReadDoublesFromString(inputString,tmpValues);
311  //if (m_env.subDisplayFile()) {
312  // *m_env.subDisplayFile() << "In ExperimentModelOptions::getMyOptionValues(): tmpValues =";
313  // for (unsigned int i = 0; i < tmpValues.size(); ++i) {
314  // *m_env.subDisplayFile() << " " << tmpValues[i];
315  // }
316  // *m_env.subDisplayFile() << std::endl;
317  //}
318  unsigned int tmpSize = tmpValues.size();
319  m_ov.m_Gvalues.clear();
320  m_ov.m_Gvalues.resize(tmpSize,0);
321  for (unsigned int i = 0; i < tmpSize; ++i) {
322  m_ov.m_Gvalues[i] = (unsigned int) tmpValues[i];
323  }
324  }
325 
326  if (m_env.allOptionsMap().count(m_option_a_v)) {
327  m_ov.m_a_v = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_a_v]).as<double>();
328  }
329 
330  if (m_env.allOptionsMap().count(m_option_b_v)) {
331  m_ov.m_b_v = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_b_v]).as<double>();
332  }
333 
334  if (m_env.allOptionsMap().count(m_option_a_rho_v)) {
335  m_ov.m_a_rho_v = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_a_rho_v]).as<double>();
336  }
337 
338  if (m_env.allOptionsMap().count(m_option_b_rho_v)) {
339  m_ov.m_b_rho_v = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_b_rho_v]).as<double>();
340  }
341 
342  if (m_env.allOptionsMap().count(m_option_a_y)) {
343  m_ov.m_a_y = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_a_y]).as<double>();
344  }
345 
346  if (m_env.allOptionsMap().count(m_option_b_y)) {
347  m_ov.m_b_y = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_b_y]).as<double>();
348  }
349 
350  return;
351 }
352 
353 void
354 ExperimentModelOptions::print(std::ostream& os) const
355 {
357 
358  os << "\n" << m_option_Gvalues << " = ";
359  for (unsigned int i = 0; i < m_ov.m_Gvalues.size(); ++i) {
360  os << m_ov.m_Gvalues[i] << " ";
361  }
362  os << "\n" << m_option_a_v << " = " << m_ov.m_a_v
363  << "\n" << m_option_b_v << " = " << m_ov.m_b_v
364  << "\n" << m_option_a_rho_v << " = " << m_ov.m_a_rho_v
365  << "\n" << m_option_b_rho_v << " = " << m_ov.m_b_rho_v
366  << "\n" << m_option_a_y << " = " << m_ov.m_a_y
367  << "\n" << m_option_b_y << " = " << m_ov.m_b_y
368  << std::endl;
369 
370  return;
371 }
372 
373 std::ostream& operator<<(std::ostream& os, const ExperimentModelOptions& obj)
374 {
376 
377  obj.print(os);
378 
379  return os;
380 }
381 
382 } // End namespace QUESO
void defineMyOptions(boost::program_options::options_description &optionsDesc) const
void getMyOptionValues(boost::program_options::options_description &optionsDesc)
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
ExperimentModelOptions(const BaseEnvironment &env, const char *prefix)
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
#define UQ_EXPERIMENT_MODEL_A_RHO_V_ODV
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:336
#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_EXPERIMENT_MODEL_B_Y_ODV
#define queso_require_msg(asserted, msg)
Definition: asserts.h:69
boost::program_options::options_description * m_optionsDesc
void copy(const EmOptionsValues &src)
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
#define UQ_EXPERIMENT_MODEL_B_RHO_V_ODV
#define queso_deprecated()
Definition: Defines.h:120
#define UQ_EXPERIMENT_MODEL_A_Y_ODV
BoostInputOptionsParser * m_parser
#define UQ_EXPERIMENT_MODEL_G_VALUES_ODV
void print(std::ostream &os) const
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.
#define UQ_EXPERIMENT_MODEL_B_V_ODV
std::vector< unsigned int > m_Gvalues
#define UQ_EXPERIMENT_MODEL_A_V_ODV
EmOptionsValues & operator=(const EmOptionsValues &rhs)

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