queso-0.53.0
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-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/MLSamplingOptions.h>
28 #include <queso/Miscellaneous.h>
29 
30 namespace QUESO {
31 
33  :
34  m_prefix ((std::string)(prefix) + "ml_" ),
35  m_help (UQ_ML_SAMPLING_HELP),
37  m_restartOutput_levelPeriod (UQ_ML_SAMPLING_RESTART_OUTPUT_LEVEL_PERIOD_ODV ),
38  m_restartOutput_baseNameForFiles (UQ_ML_SAMPLING_RESTART_OUTPUT_BASE_NAME_FOR_FILES_ODV),
39  m_restartOutput_fileType (UQ_ML_SAMPLING_RESTART_OUTPUT_FILE_TYPE_ODV ),
40  m_restartInput_baseNameForFiles (UQ_ML_SAMPLING_RESTART_INPUT_BASE_NAME_FOR_FILES_ODV ),
41  m_restartInput_fileType (UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV ),
42 #else
43  m_restartInputFileName (UQ_ML_SAMPLING_RESTART_INPUT_FILE_NAME_ODV),
44  m_restartInputFileType (UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV),
45  m_restartChainSize (UQ_ML_SAMPLING_RESTART_CHAIN_SIZE_ODV ),
46 #endif
47  m_dataOutputFileName (UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV ),
48  //m_dataOutputAllowedSet (),
49  m_env (env),
50  m_parser(new BoostInputOptionsParser(env.optionsInputFileName())),
51  m_option_help (m_prefix + "help" ),
53  m_option_restartOutput_levelPeriod (m_prefix + "restartOutput_levelPeriod" ),
54  m_option_restartOutput_baseNameForFiles(m_prefix + "restartOutput_baseNameForFiles"),
55  m_option_restartOutput_fileType (m_prefix + "restartOutput_fileType" ),
56  m_option_restartInput_baseNameForFiles (m_prefix + "restartInput_baseNameForFiles" ),
57  m_option_restartInput_fileType (m_prefix + "restartInput_fileType" ),
58 #else
59  m_option_restartInputFileName (m_prefix + "restartInputFileName"),
60  m_option_restartInputFileType (m_prefix + "restartInputFileType"),
61  m_option_restartChainSize (m_prefix + "restartChainSize" ),
62 #endif
63  m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
64  m_option_dataOutputAllowedSet (m_prefix + "dataOutputAllowedSet")
65 {
66  m_parser->registerOption<std::string >(m_option_help, UQ_ML_SAMPLING_HELP, "produce help msg for ML sampling options" );
67 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
68  m_parser->registerOption<unsigned int>(m_option_restartOutput_levelPeriod, UQ_ML_SAMPLING_RESTART_OUTPUT_LEVEL_PERIOD_ODV, "restartOutput_levelPeriod" );
69  m_parser->registerOption<std::string >(m_option_restartOutput_baseNameForFiles, UQ_ML_SAMPLING_RESTART_OUTPUT_BASE_NAME_FOR_FILES_ODV, "restartOutput_baseNameForFiles" );
70  m_parser->registerOption<std::string >(m_option_restartOutput_fileType, UQ_ML_SAMPLING_RESTART_OUTPUT_FILE_TYPE_ODV, "restartOutput_fileType" );
71  m_parser->registerOption<std::string >(m_option_restartInput_baseNameForFiles, UQ_ML_SAMPLING_RESTART_INPUT_BASE_NAME_FOR_FILES_ODV, "restartInput_baseNameForFiles" );
72  m_parser->registerOption<std::string >(m_option_restartInput_fileType, UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV, "restartInput_fileType" );
73 #else
77 #endif
78  m_parser->registerOption<std::string >(m_option_dataOutputFileName, UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV , "name of generic output file" );
79  m_parser->registerOption<std::string >(m_option_dataOutputAllowedSet, UQ_ML_SAMPLING_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to generic output file");
80 
82 
83  m_parser->getOption<std::string >(m_option_help, m_help);
84 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
85  m_parser->getOption<unsigned int>(m_option_restartOutput_levelPeriod, m_restartOutput_levelPeriod);
86  m_parser->getOption<std::string >(m_option_restartOutput_baseNameForFiles, m_restartOutput_baseNameForFiles);
87  m_parser->getOption<std::string >(m_option_restartOutput_fileType, m_restartOutput_fileType);
88  m_parser->getOption<std::string >(m_option_restartInput_baseNameForFiles, m_restartInput_baseNameForFiles);
89  m_parser->getOption<std::string >(m_option_restartInput_fileType, m_restartInput_fileType);
90 #else
94 #endif
97 
98  checkOptions(&env);
99 }
100 
102 {
103 }
104 
105 void
107 {
108  // DM: I'm printing here because I'm not sure where this object is created
109  // in the statistical inverse problem
110  if (m_help != "") {
111  if (env->subDisplayFile()) {
112  *(env->subDisplayFile()) << (*this) << std::endl;
113  }
114  }
115 
116 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
117  if ((m_restartOutput_levelPeriod > 0)) queso_require_not_equal_to_msg(m_restartOutput_baseNameForFiles, ".", "Option 'restartOutput_levelPeriod' is > 0, but 'restartOutput_baseNameForFiles' is not specified...");
118 #endif
119 }
120 
121 void
122 MLSamplingOptions::print(std::ostream& os) const
123 {
124 #ifdef ML_CODE_HAS_NEW_RESTART_CAPABILITY
125  os << m_option_restartOutput_levelPeriod << " = " << m_restartOutput_levelPeriod
126  << "\n" << m_option_restartOutput_baseNameForFiles << " = " << m_restartOutput_baseNameForFiles
127  << "\n" << m_option_restartOutput_fileType << " = " << m_restartOutput_fileType
128  << "\n" << m_option_restartInput_baseNameForFiles << " = " << m_restartInput_baseNameForFiles
129  << "\n" << m_option_restartInput_fileType << " = " << m_restartInput_fileType
130 #else
133  << "\n" << m_option_restartChainSize << " = " << m_restartChainSize
134 #endif
136  << "\n" << m_option_dataOutputAllowedSet << " = ";
137  for (std::set<unsigned int>::iterator setIt = m_dataOutputAllowedSet.begin(); setIt != m_dataOutputAllowedSet.end(); ++setIt) {
138  os << *setIt << " ";
139  }
140  os << "\n";
141 
142  return;
143 }
144 
145 std::ostream& operator<<(std::ostream& os, const MLSamplingOptions& obj)
146 {
147  os << (*(obj.m_parser)) << std::endl;
148 
149  obj.print(os);
150  return os;
151 }
152 
153 } // End namespace QUESO
#define UQ_ML_SAMPLING_RESTART_INPUT_FILE_NAME_ODV
void print(std::ostream &os) const
It prints the option values.
#define queso_require_not_equal_to_msg(expr1, expr2, msg)
Definition: asserts.h:86
#define UQ_ML_SAMPLING_DATA_OUTPUT_ALLOWED_SET_ODV
#define ML_CODE_HAS_NEW_RESTART_CAPABILITY
Definition: Defines.h:65
std::ostream & operator<<(std::ostream &os, const BaseEnvironment &obj)
std::set< unsigned int > m_dataOutputAllowedSet
std::string m_dataOutputFileName
Name of generic output file.
unsigned int m_restartChainSize
Size of restart chain.
void scanInputFile()
This is the method that parses the input file.
std::ofstream * subDisplayFile() const
Access function for m_subDisplayFile (displays file on stream).
Definition: Environment.C:274
std::string m_option_restartInputFileType
This (virtual) class sets up the environment underlying the use of the QUESO library by an executable...
Definition: Environment.h:193
std::string m_restartInputFileType
Type of restart input file.
std::string m_option_dataOutputAllowedSet
void registerOption(std::string name, T defaultValue, std::string description)
Call this to register an option with the parser.
virtual ~MLSamplingOptions()
Destructor.
std::string m_option_restartInputFileName
MLSamplingOptions(const BaseEnvironment &env, const char *prefix)
Default constructor.
std::string m_help
If non-empty string, options and values are printed to the output file.
void checkOptions(const BaseEnvironment *env)
#define UQ_ML_SAMPLING_DATA_OUTPUT_FILE_NAME_ODV
std::string m_option_dataOutputFileName
void getOption(std::string &name, T &value)
Get option name from the parser and set value to the parsed value.
#define UQ_ML_SAMPLING_RESTART_INPUT_FILE_TYPE_ODV
std::string m_restartInputFileName
Name of restart input file.
BoostInputOptionsParser * m_parser
#define UQ_ML_SAMPLING_RESTART_CHAIN_SIZE_ODV
This class provides options for the Multilevel sequence generator if no input file is available...

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