queso-0.53.0
StatisticalInverseProblemOptions.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/StatisticalInverseProblemOptions.h>
29 #include <queso/Miscellaneous.h>
30 
31 // -------------------------------------------------
32 // SipOptionsValues--------------------------
33 // -------------------------------------------------
34 
35 namespace QUESO {
36 
37 // Default constructor -----------------------------
39  :
40  m_prefix("ip_"),
41  m_help(UQ_SIP_HELP),
42  m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
43  m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
44 //m_dataOutputAllowedSet(),
45  m_parser(NULL),
46  m_option_help (m_prefix + "help" ),
47  m_option_computeSolution (m_prefix + "computeSolution" ),
48  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
49  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
50 #ifdef UQ_SIP_READS_SOLVER_OPTION
51  m_option_solver (m_prefix + "solver" ),
52  m_solverString (UQ_SIP_SOLVER_ODV)
53 #endif
54 {
55 }
56 
58  prefix)
59  :
60  m_prefix((std::string)(prefix) + "ip_"),
61  m_help(UQ_SIP_HELP),
62  m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
63  m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV),
64 //m_dataOutputAllowedSet(),
65  m_parser(new BoostInputOptionsParser(env->optionsInputFileName())),
66  m_option_help (m_prefix + "help" ),
67  m_option_computeSolution (m_prefix + "computeSolution" ),
68  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
69  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
70 #ifdef UQ_SIP_READS_SOLVER_OPTION
71  m_option_solver (m_prefix + "solver" ),
72  m_solverString (UQ_SIP_SOLVER_ODV)
73 #endif
74 {
75  m_parser->registerOption<std::string>(m_option_help, UQ_SIP_HELP, "produce help message for statistical inverse problem");
76  m_parser->registerOption<bool >(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV , "compute solution process" );
77  m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
78  m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
79 #ifdef UQ_SIP_READS_SOLVER_OPTION
80  m_parser->registerOption<std::string>(m_option_solver, UQ_SIP_SOLVER_ODV , "algorithm for calibration" );
81 #endif
82 
84 
85  m_parser->getOption<std::string>(m_option_help, m_help);
89 #ifdef UQ_SIP_READS_SOLVER_OPTION
90  m_parser->getOption<std::string>(m_option_solver, m_solver);
91 #endif
92 
93  checkOptions();
94 }
95 // Copy constructor - -----------------------------
97 {
98  this->copy(src);
99 }
100 // Destructor ---------------------------------------
102 {
103 }
104 
105 // Set methods --------------------------------------
108 {
109  this->copy(rhs);
110  return *this;
111 }
112 // Private methods-----------------------------------
113 void
115 {
116  // Nothing
117 }
118 
119 void
121 {
125 #ifdef UQ_SIP_READS_SOLVER_OPTION
126  m_solverString = src.m_solverString;
127 #endif
128 //m_mhOptionsValues = src.m_mhOptionsValues;
129 
130  return;
131 }
132 
133 std::ostream &
134 operator<<(std::ostream& os, const SipOptionsValues & obj)
135 {
136  os << "\n" << obj.m_option_computeSolution << " = " << obj.m_computeSolution
137  << "\n" << obj.m_option_dataOutputFileName << " = " << obj.m_dataOutputFileName;
138  os << "\n" << obj.m_option_dataOutputAllowedSet << " = ";
139  for (std::set<unsigned int>::iterator setIt = obj.m_dataOutputAllowedSet.begin(); setIt != obj.m_dataOutputAllowedSet.end(); ++setIt) {
140  os << *setIt << " ";
141  }
142 #ifdef UQ_SIP_READS_SOLVER_OPTION
143  << "\n" << obj.m_option_solver << " = " << obj.m_solverString
144 #endif
145  os << std::endl;
146  return os;
147 }
148 
149 // -------------------------------------------------
150 // StatisticalInverseProblemOptions----------
151 // -------------------------------------------------
152 
153 // Default constructor -----------------------------
155  const BaseEnvironment& env,
156  const char* prefix)
157 :
158  m_ov (),
159  m_prefix ((std::string)(prefix) + "ip_"),
160  m_env (env),
161  m_optionsDesc (new boost::program_options::options_description("Statistical Inverse Problem options")),
162  m_option_help (m_prefix + "help" ),
163  m_option_computeSolution (m_prefix + "computeSolution" ),
164  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
165  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
166 #ifdef UQ_SIP_READS_SOLVER_OPTION
167  m_option_solver (m_prefix + "solver" )
168 #endif
169 {
171  queso_require_not_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the absence of an options input file");
172 }
173 
174 // Constructor 2------------------------------------
176  const BaseEnvironment& env,
177  const char* prefix,
178  const SipOptionsValues& alternativeOptionsValues)
179 :
180  m_ov (alternativeOptionsValues),
181  m_prefix ((std::string)(prefix) + "ip_"),
182  m_env (env),
183  m_optionsDesc (NULL),
184  m_option_help (m_prefix + "help" ),
185  m_option_computeSolution (m_prefix + "computeSolution" ),
186  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
187  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
188 #ifdef UQ_SIP_READS_SOLVER_OPTION
189  m_option_solver (m_prefix + "solver" )
190 #endif
191 {
193 
194  queso_require_equal_to_msg(m_env.optionsInputFileName(), "", "this constructor is incompatible with the existence of an options input file");
195 
196  if (m_env.subDisplayFile() != NULL) {
197  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::constructor(2)"
198  << ": after setting values of options with prefix '" << m_prefix
199  << "', state of object is:"
200  << "\n" << *this
201  << std::endl;
202  }
203 }
204 // Destructor --------------------------------------
206 {
208  if (m_optionsDesc) delete m_optionsDesc;
209 }
210 
211 // I/O methods --------------------------------------
212 void
214 {
215  queso_require_msg(m_optionsDesc, "m_optionsDesc variable is NULL");
216 
219  //std::cout << "scan 000\n"
220  // << std::endl;
222  //std::cout << "scan 001\n"
223  // << std::endl;
224 
225  if (m_env.subDisplayFile() != NULL) {
226  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::scanOptionsValues()"
227  << ": after reading values of options with prefix '" << m_prefix
228  << "', state of object is:"
229  << "\n" << *this
230  << std::endl;
231  }
232 
233  return;
234 }
235 
236 // --------------------------------------------------
237 void
239 {
241 
242  os << "\n" << m_option_computeSolution << " = " << m_ov.m_computeSolution
244  os << "\n" << m_option_dataOutputAllowedSet << " = ";
245  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
246  os << *setIt << " ";
247  }
248 #ifdef UQ_SIP_READS_SOLVER_OPTION
249  << "\n" << m_option_solver << " = " << m_ov.m_solverString
250 #endif
251  os << std::endl;
252 
253  return;
254 }
255 // Private methods ---------------------------------
256 void
257 StatisticalInverseProblemOptions::defineMyOptions(boost::program_options::options_description& optionsDesc) const
258 {
260 
261  optionsDesc.add_options()
262  (m_option_help.c_str(), "produce help message for statistical inverse problem")
263  (m_option_computeSolution.c_str(), boost::program_options::value<bool >()->default_value(UQ_SIP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
264  (m_option_dataOutputFileName.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV ), "name of data output file" )
265  (m_option_dataOutputAllowedSet.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to data output file" )
266 #ifdef UQ_SIP_READS_SOLVER_OPTION
267  (m_option_solver.c_str(), boost::program_options::value<std::string>()->default_value(UQ_SIP_SOLVER_ODV ), "algorithm for calibration" )
268 #endif
269  ;
270 
271  return;
272 }
273 //--------------------------------------------------
274 void
275 StatisticalInverseProblemOptions::getMyOptionValues(boost::program_options::options_description& optionsDesc)
276 {
278 
279  if (m_env.allOptionsMap().count(m_option_help)) {
280  if (m_env.subDisplayFile()) {
281  *m_env.subDisplayFile() << optionsDesc
282  << std::endl;
283  }
284  }
285 
287  m_ov.m_computeSolution = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
288  }
289 
291  m_ov.m_dataOutputFileName = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
292  }
293 
296  std::vector<double> tmpAllow(0,0.);
297  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
298  MiscReadDoublesFromString(inputString,tmpAllow);
299 
300  if (tmpAllow.size() > 0) {
301  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
302  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
303  }
304  }
305  }
306 
307 #ifdef UQ_SIP_READS_SOLVER_OPTION
308  if (m_env.allOptionsMap().count(m_option_solver)) {
309  m_ov.m_solverString = ((const boost::program_options::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
310  }
311 #endif
312 
313  return;
314 }
315 
316 // --------------------------------------------------
317 // Operator declared outside class definition ------
318 // --------------------------------------------------
319 
320 std::ostream& operator<<(std::ostream& os, const StatisticalInverseProblemOptions& obj)
321 {
323  obj.print(os);
324 
325  return os;
326 }
327 
328 } // End namespace QUESO
This class provides options for a Statistical Inverse Problem if no input file is available...
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
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
SipOptionsValues & operator=(const SipOptionsValues &rhs)
Assignment operator; it copies rhs to this.
void defineMyOptions(boost::program_options::options_description &optionsDesc) const
Define my SIP options as the default options.
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
#define UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV
#define UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV
boost::program_options::variables_map & allOptionsMap() const
Definition: Environment.C:336
#define queso_require_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:85
StatisticalInverseProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
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 queso_require_msg(asserted, msg)
Definition: asserts.h:69
void getMyOptionValues(boost::program_options::options_description &optionsDesc)
Gets the option values of the SIP.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
#define UQ_SIP_COMPUTE_SOLUTION_ODV
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
void copy(const SipOptionsValues &src)
Copies the option values from src to this.
std::set< unsigned int > m_dataOutputAllowedSet
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
void print(std::ostream &os) const
It prints the option values.
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:40
#define queso_deprecated()
Definition: Defines.h:120
std::string m_help
If this string is non-empty, options are print to the output file.
void scanOptionsValues()
It scans the option values from the options input file.
This class reads option values for a Statistical Inverse Problem from an input file.
boost::program_options::options_description * m_optionsDesc
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.

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