queso-0.51.1
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,2009,2010,2011,2012,2013 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/StatisticalInverseProblemOptions.h>
26 #include <queso/Miscellaneous.h>
27 
28 // -------------------------------------------------
29 // SipOptionsValues--------------------------
30 // -------------------------------------------------
31 
32 namespace QUESO {
33 
34 // Default constructor -----------------------------
36  :
37  m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ),
38  m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV)
39 //m_dataOutputAllowedSet(),
40 #ifdef UQ_SIP_READS_SOLVER_OPTION
41  m_solverString (UQ_SIP_SOLVER_ODV),
42 #endif
43 {
44 }
45 // Copy constructor - -----------------------------
47 {
48  this->copy(src);
49 }
50 // Destructor ---------------------------------------
52 {
53 }
54 
55 // Set methods --------------------------------------
58 {
59  this->copy(rhs);
60  return *this;
61 }
62 // Private methods-----------------------------------
63 void
65 {
69 #ifdef UQ_SIP_READS_SOLVER_OPTION
70  m_solverString = src.m_solverString;
71 #endif
72 //m_mhOptionsValues = src.m_mhOptionsValues;
73 
74  return;
75 }
76 
77 // -------------------------------------------------
78 // StatisticalInverseProblemOptions----------
79 // -------------------------------------------------
80 
81 // Default constructor -----------------------------
83  const BaseEnvironment& env,
84  const char* prefix)
85  :
86  m_ov (),
87  m_prefix ((std::string)(prefix) + "ip_"),
88  m_env (env),
89  m_optionsDesc (new po::options_description("Statistical Inverse Problem options")),
90  m_option_help (m_prefix + "help" ),
91  m_option_computeSolution (m_prefix + "computeSolution" ),
92  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
93  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
94 #ifdef UQ_SIP_READS_SOLVER_OPTION
95  m_option_solver (m_prefix + "solver" )
96 #endif
97 {
99  m_env.worldRank(),
100  "StatisticalInverseProblemOptions::constructor(1)",
101  "this constructor is incompatible with the absence of an options input file");
102 }
103 
104 // Constructor 2------------------------------------
106  const BaseEnvironment& env,
107  const char* prefix,
108  const SipOptionsValues& alternativeOptionsValues)
109  :
110  m_ov (alternativeOptionsValues),
111  m_prefix ((std::string)(prefix) + "ip_"),
112  m_env (env),
113  m_optionsDesc (NULL),
114  m_option_help (m_prefix + "help" ),
115  m_option_computeSolution (m_prefix + "computeSolution" ),
116  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
117  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
118 #ifdef UQ_SIP_READS_SOLVER_OPTION
119  m_option_solver (m_prefix + "solver" )
120 #endif
121 {
123  m_env.worldRank(),
124  "StatisticalInverseProblemOptions::constructor(2)",
125  "this constructor is incompatible with the existence of an options input file");
126 
127  if (m_env.subDisplayFile() != NULL) {
128  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::constructor(2)"
129  << ": after setting values of options with prefix '" << m_prefix
130  << "', state of object is:"
131  << "\n" << *this
132  << std::endl;
133  }
134 }
135 // Destructor --------------------------------------
137 {
138  if (m_optionsDesc) delete m_optionsDesc;
139 }
140 
141 // I/O methods --------------------------------------
142 void
144 {
146  m_env.worldRank(),
147  "StatisticalInverseProblemOptions::scanOptionsValues()",
148  "m_optionsDesc variable is NULL");
149 
152  //std::cout << "scan 000\n"
153  // << std::endl;
155  //std::cout << "scan 001\n"
156  // << std::endl;
157 
158  if (m_env.subDisplayFile() != NULL) {
159  *m_env.subDisplayFile() << "In StatisticalInverseProblemOptions::scanOptionsValues()"
160  << ": after reading values of options with prefix '" << m_prefix
161  << "', state of object is:"
162  << "\n" << *this
163  << std::endl;
164  }
165 
166  return;
167 }
168 // --------------------------------------------------
169 void
171 {
172  os << "\n" << m_option_computeSolution << " = " << m_ov.m_computeSolution
174  os << "\n" << m_option_dataOutputAllowedSet << " = ";
175  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
176  os << *setIt << " ";
177  }
178 #ifdef UQ_SIP_READS_SOLVER_OPTION
179  << "\n" << m_option_solver << " = " << m_ov.m_solverString
180 #endif
181  os << std::endl;
182 
183  return;
184 }
185 // Private methods ---------------------------------
186 void
187 StatisticalInverseProblemOptions::defineMyOptions(po::options_description& optionsDesc) const
188 {
189  optionsDesc.add_options()
190  (m_option_help.c_str(), "produce help message for statistical inverse problem")
191  (m_option_computeSolution.c_str(), po::value<bool >()->default_value(UQ_SIP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
192  (m_option_dataOutputFileName.c_str(), po::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV ), "name of data output file" )
193  (m_option_dataOutputAllowedSet.c_str(), po::value<std::string>()->default_value(UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to data output file" )
194 #ifdef UQ_SIP_READS_SOLVER_OPTION
195  (m_option_solver.c_str(), po::value<std::string>()->default_value(UQ_SIP_SOLVER_ODV ), "algorithm for calibration" )
196 #endif
197  ;
198 
199  return;
200 }
201 //--------------------------------------------------
202 void
203 StatisticalInverseProblemOptions::getMyOptionValues(po::options_description& optionsDesc)
204 {
205  if (m_env.allOptionsMap().count(m_option_help)) {
206  if (m_env.subDisplayFile()) {
207  *m_env.subDisplayFile() << optionsDesc
208  << std::endl;
209  }
210  }
211 
213  m_ov.m_computeSolution = ((const po::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
214  }
215 
217  m_ov.m_dataOutputFileName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
218  }
219 
222  std::vector<double> tmpAllow(0,0.);
223  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
224  MiscReadDoublesFromString(inputString,tmpAllow);
225 
226  if (tmpAllow.size() > 0) {
227  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
228  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
229  }
230  }
231  }
232 
233 #ifdef UQ_SIP_READS_SOLVER_OPTION
234  if (m_env.allOptionsMap().count(m_option_solver)) {
235  m_ov.m_solverString = ((const po::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
236  }
237 #endif
238 
239  return;
240 }
241 
242 // --------------------------------------------------
243 // Operator declared outside class definition ------
244 // --------------------------------------------------
245 
246 std::ostream& operator<<(std::ostream& os, const StatisticalInverseProblemOptions& obj)
247 {
248  obj.print(os);
249 
250  return os;
251 }
252 
253 } // End namespace QUESO
#define UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV
void getMyOptionValues(po::options_description &optionsDesc)
Gets the option values of the SIP.
void print(std::ostream &os) const
It prints the option values.
void scanOptionsValues()
It scans the option values from the options input file.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
SipOptionsValues & operator=(const SipOptionsValues &rhs)
Assignment operator; it copies rhs to this.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
void defineMyOptions(po::options_description &optionsDesc) const
Define my SIP options as the default options.
po::variables_map & allOptionsMap() const
Definition: Environment.C:368
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:187
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
std::set< unsigned int > m_dataOutputAllowedSet
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:39
std::string optionsInputFileName() const
Access to the attribute m_optionsInputFileName, which stores the name of the input file passed by the...
Definition: Environment.C:341
void copy(const SipOptionsValues &src)
Copies the option values from src to this.
#define UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV
This class reads option values for a Statistical Inverse Problem from an input file.
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
StatisticalInverseProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
#define UQ_SIP_COMPUTE_SOLUTION_ODV
This class provides options for a Statistical Inverse Problem if no input file is available...
void scanInputFileForMyOptions(const po::options_description &optionsDesc) const
This method scans the input file provided by the user to QUESO.
Definition: Environment.C:378

Generated on Thu Apr 23 2015 19:26:16 for queso-0.51.1 by  doxygen 1.8.5