queso-0.51.1
MLSamplingOptions.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/MLSamplingOptions.h>
26 #include <queso/Miscellaneous.h>
27 
28 namespace QUESO {
29 
31  :
32  m_prefix ((std::string)(prefix) + "ml_" ),
34  m_restartOutput_levelPeriod (UQ_ML_SAMPLING_RESTART_OUTPUT_LEVEL_PERIOD_ODV ),
35  m_restartOutput_baseNameForFiles (UQ_ML_SAMPLING_RESTART_OUTPUT_BASE_NAME_FOR_FILES_ODV),
36  m_restartOutput_fileType (UQ_ML_SAMPLING_RESTART_OUTPUT_FILE_TYPE_ODV ),
37  m_restartInput_baseNameForFiles (UQ_ML_SAMPLING_RESTART_INPUT_BASE_NAME_FOR_FILES_ODV ),
38  m_restartInput_fileType (UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV ),
39 #else
40  m_restartInputFileName (UQ_ML_SAMPLING_RESTART_INPUT_FILE_NAME_ODV),
41  m_restartInputFileType (UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV),
42  m_restartChainSize (UQ_ML_SAMPLING_RESTART_CHAIN_SIZE_ODV ),
43 #endif
44  m_dataOutputFileName (UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV ),
45 //m_dataOutputAllowedSet (),
46  m_env (env),
47  m_optionsDesc (new po::options_description("Multilevel sampling options")),
48  m_option_help (m_prefix + "help" ),
50  m_option_restartOutput_levelPeriod (m_prefix + "restartOutput_levelPeriod" ),
51  m_option_restartOutput_baseNameForFiles(m_prefix + "restartOutput_baseNameForFiles"),
52  m_option_restartOutput_fileType (m_prefix + "restartOutput_fileType" ),
53  m_option_restartInput_baseNameForFiles (m_prefix + "restartInput_baseNameForFiles" ),
54  m_option_restartInput_fileType (m_prefix + "restartInput_fileType" ),
55 #else
56  m_option_restartInputFileName (m_prefix + "restartInputFileName"),
57  m_option_restartInputFileType (m_prefix + "restartInputFileType"),
58  m_option_restartChainSize (m_prefix + "restartChainSize" ),
59 #endif
60  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
61  m_option_dataOutputAllowedSet (m_prefix + "dataOutputAllowedSet")
62 {
63 }
64 
66 {
67  if (m_optionsDesc) delete m_optionsDesc;
68 }
69 
70 void
72 {
76 
77  if (m_env.subDisplayFile() != NULL) {
78  *m_env.subDisplayFile() << "In MLSamplingOptions::scanOptionsValues()"
79  << ": after getting values of options with prefix '" << m_prefix
80  << "', state of object is:"
81  << "\n" << *this
82  << std::endl;
83  }
84 
85  return;
86 }
87 
88 void
89 MLSamplingOptions::defineMyOptions(po::options_description& optionsDesc) const
90 {
91  optionsDesc.add_options()
92  (m_option_help.c_str(), "produce help msg for ML sampling options" )
94  (m_option_restartOutput_levelPeriod.c_str(), po::value<unsigned int>()->default_value(UQ_ML_SAMPLING_RESTART_OUTPUT_LEVEL_PERIOD_ODV), "restartOutput_levelPeriod" )
95  (m_option_restartOutput_baseNameForFiles.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_OUTPUT_BASE_NAME_FOR_FILES_ODV), "restartOutput_baseNameForFiles" )
96  (m_option_restartOutput_fileType.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_OUTPUT_FILE_TYPE_ODV), "restartOutput_fileType" )
97  (m_option_restartInput_baseNameForFiles.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_INPUT_BASE_NAME_FOR_FILES_ODV), "restartInput_baseNameForFiles" )
98  (m_option_restartInput_fileType.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV), "restartInput_fileType" )
99 #else
100  (m_option_restartInputFileName.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_INPUT_FILE_NAME_ODV), "name of restart input file" )
101  (m_option_restartInputFileType.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV), "type of restart input file" )
102  (m_option_restartChainSize.c_str(), po::value<unsigned int>()->default_value(UQ_ML_SAMPLING_RESTART_CHAIN_SIZE_ODV), "size of restart chain" )
103 #endif
104  (m_option_dataOutputFileName.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV ), "name of generic output file" )
105  (m_option_dataOutputAllowedSet.c_str(), po::value<std::string >()->default_value(UQ_ML_SAMPLING_DATA_OUTPUT_ALLOWED_SET_ODV), "subEnvs that will write to generic output file")
106  ;
107 
108  return;
109 }
110 
111 void
112 MLSamplingOptions::getMyOptionValues(po::options_description& optionsDesc)
113 {
114  if (m_env.allOptionsMap().count(m_option_help.c_str())) {
115  if (m_env.subDisplayFile()) {
116  *m_env.subDisplayFile() << optionsDesc
117  << std::endl;
118  }
119  }
120 
121 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
122  if (m_env.allOptionsMap().count(m_option_restartOutput_levelPeriod.c_str())) {
123  m_restartOutput_levelPeriod = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartOutput_levelPeriod.c_str()]).as<unsigned int>();
124  }
125 
126  if (m_env.allOptionsMap().count(m_option_restartOutput_baseNameForFiles.c_str())) {
127  m_restartOutput_baseNameForFiles = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartOutput_baseNameForFiles.c_str()]).as<std::string>();
128  }
129 
130  UQ_FATAL_TEST_MACRO((m_restartOutput_levelPeriod > 0) && (m_restartOutput_baseNameForFiles == "."),
131  m_env.worldRank(),
132  "MLSamplingOptions::getMyOptionsValues()",
133  "Option 'restartOutput_levelPeriod' is > 0, but 'restartOutput_baseNameForFiles' is not specified...");
134 
135  if (m_env.allOptionsMap().count(m_option_restartOutput_fileType.c_str())) {
136  m_restartOutput_fileType = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartOutput_fileType.c_str()]).as<std::string>();
137  }
138 
139  if (m_env.allOptionsMap().count(m_option_restartInput_baseNameForFiles.c_str())) {
140  m_restartInput_baseNameForFiles = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartInput_baseNameForFiles.c_str()]).as<std::string>();
141  }
142 
143  if (m_env.allOptionsMap().count(m_option_restartInput_fileType.c_str())) {
144  m_restartInput_fileType = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartInput_fileType.c_str()]).as<std::string>();
145  }
146 #else
147  if (m_env.allOptionsMap().count(m_option_restartInputFileName.c_str())) {
148  m_restartInputFileName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartInputFileName.c_str()]).as<std::string>();
149  }
150 
151  if (m_env.allOptionsMap().count(m_option_restartInputFileType.c_str())) {
152  m_restartInputFileType = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartInputFileType.c_str()]).as<std::string>();
153  }
154 
155  if (m_env.allOptionsMap().count(m_option_restartChainSize.c_str())) {
156  m_restartChainSize = ((const po::variable_value&) m_env.allOptionsMap()[m_option_restartChainSize.c_str()]).as<unsigned int>();
157  }
158 #endif
159  if (m_env.allOptionsMap().count(m_option_dataOutputFileName.c_str())) {
160  m_dataOutputFileName = ((const po::variable_value&) m_env.allOptionsMap()[m_option_dataOutputFileName.c_str()]).as<std::string>();
161  }
162 
163  if (m_env.allOptionsMap().count(m_option_dataOutputAllowedSet.c_str())) {
164  m_dataOutputAllowedSet.clear();
165  std::vector<double> tmpAllow(0,0.);
166  std::string inputString = m_env.allOptionsMap()[m_option_dataOutputAllowedSet.c_str()].as<std::string>();
167  MiscReadDoublesFromString(inputString,tmpAllow);
168 
169  if (tmpAllow.size() > 0) {
170  for (unsigned int i = 0; i < tmpAllow.size(); ++i) {
171  m_dataOutputAllowedSet.insert((unsigned int) tmpAllow[i]);
172  }
173  }
174  }
175 
176  return;
177 }
178 
179 void
180 MLSamplingOptions::print(std::ostream& os) const
181 {
182 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
183  os << m_option_restartOutput_levelPeriod << " = " << m_restartOutput_levelPeriod
184  << "\n" << m_option_restartOutput_baseNameForFiles << " = " << m_restartOutput_baseNameForFiles
185  << "\n" << m_option_restartOutput_fileType << " = " << m_restartOutput_fileType
186  << "\n" << m_option_restartInput_baseNameForFiles << " = " << m_restartInput_baseNameForFiles
187  << "\n" << m_option_restartInput_fileType << " = " << m_restartInput_fileType
188 #else
191  << "\n" << m_option_restartChainSize << " = " << m_restartChainSize
192 #endif
194  << "\n" << m_option_dataOutputAllowedSet << " = ";
195  for (std::set<unsigned int>::iterator setIt = m_dataOutputAllowedSet.begin(); setIt != m_dataOutputAllowedSet.end(); ++setIt) {
196  os << *setIt << " ";
197  }
198  os << "\n";
199 
200  return;
201 }
202 
203 std::ostream& operator<<(std::ostream& os, const MLSamplingOptions& obj)
204 {
205  obj.print(os);
206 
207  return os;
208 }
209 
210 } // End namespace QUESO
const BaseEnvironment & m_env
unsigned int m_restartChainSize
Size of restart chain.
int worldRank() const
Returns the process world rank.
Definition: Environment.C:235
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:305
po::options_description * m_optionsDesc
#define UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV
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::string m_dataOutputFileName
Name of generic output file.
void MiscReadDoublesFromString(const std::string &inputString, std::vector< double > &outputDoubles)
Definition: Miscellaneous.C:39
std::string m_restartInputFileType
Type of restart input file.
MLSamplingOptions(const BaseEnvironment &env, const char *prefix)
Default constructor.
#define UQ_ML_SAMPLING_DATA_OUTPUT_ALLOWED_SET_ODV
std::string m_option_restartInputFileName
std::set< unsigned int > m_dataOutputAllowedSet
std::string m_option_restartInputFileType
std::string m_prefix
Class prefix. (ml)
void scanOptionsValues()
It scans the option values from the options input file.
This class provides options for the Multilevel sequence generator if no input file is available...
void getMyOptionValues(po::options_description &optionsDesc)
Gets the sequence options defined to the Multilevel algorithm.
std::string m_option_dataOutputFileName
#define ML_CODE_HAS_NEW_RESTART_CAPABILITY
Definition: Defines.h:65
void print(std::ostream &os) const
It prints the option values.
~MLSamplingOptions()
Destructor.
#define UQ_ML_SAMPLING_RESTART_INPUT_FILE_NAME_ODV
#define UQ_ML_SAMPLING_RESTART_CHAIN_SIZE_ODV
#define UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV
#define UQ_FATAL_TEST_MACRO(test, givenRank, where, what)
Definition: Defines.h:223
std::string m_option_dataOutputAllowedSet
void defineMyOptions(po::options_description &optionsDesc) const
Defines the options for the Multilevel generator of samples as the default options.
std::string m_restartInputFileName
Name of restart input file.
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