queso-0.51.1
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,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/StatisticalForwardProblemOptions.h>
26 #include <queso/Miscellaneous.h>
27 
28 namespace QUESO {
29 
30 // --------------------------------------------------
31 // SfpOptionsValues---------------------------
32 // --------------------------------------------------
33 
34 // Default constructor -----------------------------
36  :
37  m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
38  m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
39  m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
40  m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV)
41 //m_dataOutputAllowedSet(),
42 #ifdef UQ_SFP_READS_SOLVER_OPTION
43  m_solverString (UQ_SFP_SOLVER_ODV ),
44 #endif
45 {
46 }
47 // Copy constructor----------------------------------
49 {
50  this->copy(src);
51 }
52 // Destructor ---------------------------------------
54 {
55 }
56 // Set methods --------------------------------------
59 {
60  this->copy(rhs);
61  return *this;
62 }
63 // Private methods-----------------------------------
64 void
66 {
72 #ifdef UQ_SFP_READS_SOLVER_OPTION
73  m_solverString = src.m_solverString;
74 #endif
75 
76  //m_mcOptionsValues = src.m_mcOptionsValues;
77 
78  return;
79 }
80 
81 
82 // --------------------------------------------------
83 // StatisticalForwardProblemOptions-----------
84 // --------------------------------------------------
85 
86 // Default constructor -----------------------------
88  const BaseEnvironment& env,
89  const char* prefix)
90  :
91  m_ov (),
92  m_prefix ((std::string)(prefix) + "fp_" ),
93  m_env (env),
94  m_optionsDesc (new po::options_description("Statistical Forward Problem options")),
95  m_option_help (m_prefix + "help" ),
96  m_option_computeSolution (m_prefix + "computeSolution" ),
97  m_option_computeCovariances (m_prefix + "computeCovariances" ),
98  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
99  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
100  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
101 #ifdef UQ_SFP_READS_SOLVER_OPTION
102  m_option_solver (m_prefix + "solver" )
103 #endif
104 {
106  m_env.worldRank(),
107  "StatisticalForwardProblemOptions::constructor(1)",
108  "this constructor is incompatible with the absence of an options input file");
109 }
110 
112  const BaseEnvironment& env,
113  const char* prefix,
114  const SfpOptionsValues& alternativeOptionsValues)
115  :
116  m_ov (alternativeOptionsValues ),
117  m_prefix ((std::string)(prefix) + "fp_" ),
118  m_env (env),
119  m_optionsDesc (NULL),
120  m_option_help (m_prefix + "help" ),
121  m_option_computeSolution (m_prefix + "computeSolution" ),
122  m_option_computeCovariances (m_prefix + "computeCovariances" ),
123  m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
124  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
125  m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
126 #ifdef UQ_SFP_READS_SOLVER_OPTION
127  m_option_solver (m_prefix + "solver" )
128 #endif
129 {
131  m_env.worldRank(),
132  "StatisticalForwardProblemOptions::constructor(2)",
133  "this constructor is incompatible with the existence of an options input file");
134 
135  if (m_env.subDisplayFile() != NULL) {
136  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::constructor(2)"
137  << ": after setting values of options with prefix '" << m_prefix
138  << "', state of object is:"
139  << "\n" << *this
140  << std::endl;
141  }
142 }
143 // Destructor --------------------------------------
145 {
146  if (m_optionsDesc) delete m_optionsDesc;
147 }
148 
149 // I/O methods -------------------------------------
150 void
152 {
154  m_env.worldRank(),
155  "StatisticalForwardProblemOptions::scanOptionsValues()",
156  "m_optionsDesc variable is NULL");
157 
161 
162  if (m_env.subDisplayFile() != NULL) {
163  *m_env.subDisplayFile() << "In StatisticalForwardProblemOptions::scanOptionsValues()"
164  << ": after reading values of options with prefix '" << m_prefix
165  << "', state of object is:"
166  << "\n" << *this
167  << std::endl;
168  }
169 
170  return;
171 }
172 //--------------------------------------------------
173 void
175 {
180  os << "\n" << m_option_dataOutputAllowedSet << " = ";
181  for (std::set<unsigned int>::iterator setIt = m_ov.m_dataOutputAllowedSet.begin(); setIt != m_ov.m_dataOutputAllowedSet.end(); ++setIt) {
182  os << *setIt << " ";
183  }
184 #ifdef UQ_SFP_READS_SOLVER_OPTION
185  << "\n" << m_option_solver << " = " << m_ov.m_solverString
186 #endif
187  os << std::endl;
188 
189  return;
190 }
191 
192 // Private methods ---------------------------------
193 void
194 StatisticalForwardProblemOptions::defineMyOptions(po::options_description& optionsDesc) const
195 {
196  optionsDesc.add_options()
197  (m_option_help.c_str(), "produce help message for statistical forward problem")
198  (m_option_computeSolution.c_str(), po::value<bool >()->default_value(UQ_SFP_COMPUTE_SOLUTION_ODV ), "compute solution process" )
199  (m_option_computeCovariances.c_str(), po::value<bool >()->default_value(UQ_SFP_COMPUTE_COVARIANCES_ODV ), "compute pq covariances" )
200  (m_option_computeCorrelations.c_str(), po::value<bool >()->default_value(UQ_SFP_COMPUTE_CORRELATIONS_ODV ), "compute pq correlations" )
201  (m_option_dataOutputFileName.c_str(), po::value<std::string>()->default_value(UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV ), "name of data output file" )
202  (m_option_dataOutputAllowedSet.c_str(), po::value<std::string>()->default_value(UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to data output file" )
203 #ifdef UQ_SFP_READS_SOLVER_OPTION
204  (m_option_solver.c_str(), po::value<std::string>()->default_value(UQ_SFP_SOLVER_ODV ), "algorithm for propagation" )
205 #endif
206  ;
207 
208  return;
209 }
210 //--------------------------------------------------
211 void
212 StatisticalForwardProblemOptions::getMyOptionValues(po::options_description& optionsDesc)
213 {
214  if (m_env.allOptionsMap().count(m_option_help)) {
215  if (m_env.subDisplayFile()) {
216  *m_env.subDisplayFile() << optionsDesc
217  << std::endl;
218  }
219  }
220 
222  m_ov.m_computeSolution = ((const po::variable_value&) m_env.allOptionsMap()[m_option_computeSolution]).as<bool>();
223  }
224 
226  m_ov.m_computeCovariances = ((const po::variable_value&) m_env.allOptionsMap()[m_option_computeCovariances]).as<bool>();
227  }
228 
230  m_ov.m_computeCorrelations = ((const po::variable_value&) m_env.allOptionsMap()[m_option_computeCorrelations]).as<bool>();
231  }
232 
234  m_ov.m_dataOutputFileName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName]).as<std::string>();
235  }
236 
239  std::vector<double> tmpAllow(0,0.);
240  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet].as<std::string>();
241  MiscReadDoublesFromString(inputString,tmpAllow);
242 
243  if (tmpAllow.size() > 0) {
244  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
245  m_ov.m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
246  }
247  }
248  }
249 
250 #ifdef UQ_SFP_READS_SOLVER_OPTION
251  if (m_env.allOptionsMap().count(m_option_solver)) {
252  m_ov.m_solverString = ((const po::variable_value&) m_env.allOptionsMap()[m_option_solver]).as<std::string>();
253  }
254 #endif
255 
256  return;
257 }
258 
259 // --------------------------------------------------
260 // Operator declared outside class definition ------
261 // --------------------------------------------------
262 
263 std::ostream& operator<<(std::ostream& os, const StatisticalForwardProblemOptions& obj)
264 {
265  obj.print(os);
266 
267  return os;
268 }
269 
270 } // End namespace QUESO
void copy(const SfpOptionsValues &src)
Copies the option values from src to this.
void scanOptionsValues()
It scans the option values from the options input file.
StatisticalForwardProblemOptions(const BaseEnvironment &env, const char *prefix)
Constructor: reads options from the input file.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
This class provides options for a Statistical Forward Problem if no input file is available...
void defineMyOptions(po::options_description &optionsDesc) const
Define my SFP options as the default options.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
This class reads option values for a Statistical Forward Problem from an input file.
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)
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
SfpOptionsValues()
Constructor/Destructor methods.
#define UQ_SFP_COMPUTE_SOLUTION_ODV
#define UQ_SFP_COMPUTE_COVARIANCES_ODV
std::set< unsigned int > m_dataOutputAllowedSet
SfpOptionsValues & operator=(const SfpOptionsValues &rhs)
Assignment operator; it copies rhs to this.
void getMyOptionValues(po::options_description &optionsDesc)
Gets the option values of the SFP.
#define UQ_SFP_COMPUTE_CORRELATIONS_ODV
#define UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV
#define UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
void print(std::ostream &os) const
It prints the option values.
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