diff --git a/src/core/src/EnvironmentOptions.C b/src/core/src/EnvironmentOptions.C index 7f5724555..16890cace 100644 --- a/src/core/src/EnvironmentOptions.C +++ b/src/core/src/EnvironmentOptions.C @@ -47,9 +47,6 @@ namespace QUESO { EnvOptionsValues::EnvOptionsValues() : m_env(NULL) -#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - , m_parser() -#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS { this->set_defaults(); this->set_prefix(""); @@ -264,7 +261,7 @@ EnvOptionsValues::parse(const BaseEnvironment& env, const std::string& prefix) m_parser->scanInputFile(); // Retrieve parsed options - m_parser->getOption(m_option_help, m_help); + m_parser->getOption(m_option_help, m_help); m_parser->getOption(m_option_numSubEnvironments, m_numSubEnvironments); m_parser->getOption(m_option_subDisplayFileName, m_subDisplayFileName); m_parser->getOption(m_option_subDisplayAllowAll, m_subDisplayAllowAll); diff --git a/src/stats/inc/StatisticalInverseProblemOptions.h b/src/stats/inc/StatisticalInverseProblemOptions.h index 13f04f100..64b78b450 100644 --- a/src/stats/inc/StatisticalInverseProblemOptions.h +++ b/src/stats/inc/StatisticalInverseProblemOptions.h @@ -86,6 +86,15 @@ class SipOptionsValues /*! It assigns the same options values from \c src to \c this.*/ SipOptionsValues (const SipOptionsValues& src); + //! Set parameter option names to begin with prefix + void set_prefix(const std::string& prefix); + + //! Set default values for parameter options + void set_defaults(); + + //! Given prefix, read the input file for parameters named "prefix"+* + void parse(const BaseEnvironment& env, const std::string& prefix); + //! Destructor virtual ~SipOptionsValues (); //@} diff --git a/src/stats/src/StatisticalInverseProblemOptions.C b/src/stats/src/StatisticalInverseProblemOptions.C index 3aede441b..8998ee47d 100644 --- a/src/stats/src/StatisticalInverseProblemOptions.C +++ b/src/stats/src/StatisticalInverseProblemOptions.C @@ -43,99 +43,18 @@ namespace QUESO { // Default constructor ----------------------------- SipOptionsValues::SipOptionsValues() - : - m_prefix("ip_"), - m_help(UQ_SIP_HELP), - m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ), - m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV), - m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR), - m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR), -//m_dataOutputAllowedSet(), -#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - m_parser(), -#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - m_option_help (m_prefix + "help" ), - m_option_computeSolution (m_prefix + "computeSolution" ), - m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), -#ifdef UQ_SIP_READS_SOLVER_OPTION - m_option_solver (m_prefix + "solver" ), - m_solverString (UQ_SIP_SOLVER_ODV) -#endif - m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), - m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") { + this->set_defaults(); + this->set_prefix(""); } -SipOptionsValues::SipOptionsValues(const BaseEnvironment * env, const char * - prefix) - : - m_prefix((std::string)(prefix) + "ip_"), - m_help(UQ_SIP_HELP), - m_computeSolution (UQ_SIP_COMPUTE_SOLUTION_ODV ), - m_dataOutputFileName (UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV), - m_seedWithMAPEstimator(UQ_SIP_SEEDWITHMAPESTIMATOR), - m_useOptimizerMonitor(UQ_SIP_USEOPTIMIZERMONITOR), -//m_dataOutputAllowedSet(), -#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - m_parser(new BoostInputOptionsParser(env->optionsInputFileName())), -#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - m_option_help (m_prefix + "help" ), - m_option_computeSolution (m_prefix + "computeSolution" ), - m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ), - m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet"), -#ifdef UQ_SIP_READS_SOLVER_OPTION - m_option_solver (m_prefix + "solver" ), - m_solverString (UQ_SIP_SOLVER_ODV) -#endif - m_option_seedWithMAPEstimator(m_prefix + "seedWithMAPEstimator"), - m_option_useOptimizerMonitor(m_prefix + "useOptimizerMonitor") +SipOptionsValues::SipOptionsValues(const BaseEnvironment* env, + const char* prefix) { -#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - m_parser->registerOption(m_option_help, UQ_SIP_HELP, "produce help message for statistical inverse problem"); - m_parser->registerOption(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV , "compute solution process" ); - m_parser->registerOption(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" ); - m_parser->registerOption(m_option_dataOutputAllowedSet, UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" ); -#ifdef UQ_SIP_READS_SOLVER_OPTION - m_parser->registerOption(m_option_solver, UQ_SIP_SOLVER_ODV , "algorithm for calibration" ); -#endif - m_parser->registerOption(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR , "toggle for seeding chain at MAP" ); - m_parser->registerOption(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR , "toggle for using optimizer monitor (prints diagnostics"); - - m_parser->scanInputFile(); - - m_parser->getOption(m_option_help, m_help); - m_parser->getOption(m_option_computeSolution, m_computeSolution); - m_parser->getOption(m_option_dataOutputFileName, m_dataOutputFileName); - m_parser->getOption >(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet); -#ifdef UQ_SIP_READS_SOLVER_OPTION - m_parser->getOption(m_option_solver, m_solver); -#endif - m_parser->getOption(m_option_seedWithMAPEstimator, m_seedWithMAPEstimator); - m_parser->getOption(m_option_useOptimizerMonitor, m_useOptimizerMonitor); -#else - m_help = env->input()(m_option_help, UQ_SIP_HELP); - m_computeSolution = env->input()(m_option_computeSolution, UQ_SIP_COMPUTE_SOLUTION_ODV); - m_dataOutputFileName = env->input()(m_option_dataOutputFileName, UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV); - - // UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default - unsigned int size = env->input().vector_variable_size(m_option_dataOutputAllowedSet); - for (unsigned int i = 0; i < size; i++) { - // We default to empty set, so the default values are actually never - // used here - unsigned int allowed = env->input()(m_option_dataOutputAllowedSet, i, i); - m_dataOutputAllowedSet.insert(allowed); - } - -#ifdef UQ_SIP_READS_SOLVER_OPTION - m_solver = env->input()(m_option_solver, UQ_SIP_SOLVER_ODV); -#endif - m_seedWithMAPEstimator = env->input()(m_option_seedWithMAPEstimator, UQ_SIP_SEEDWITHMAPESTIMATOR); - m_useOptimizerMonitor = env->input()(m_option_useOptimizerMonitor, UQ_SIP_USEOPTIMIZERMONITOR); -#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS - - checkOptions(); + this->set_defaults(); + this->parse(*env, prefix); } + // Copy constructor - ----------------------------- SipOptionsValues::SipOptionsValues(const SipOptionsValues& src) { @@ -189,4 +108,113 @@ operator<<(std::ostream& os, const SipOptionsValues & obj) return os; } + +void +SipOptionsValues::set_defaults() +{ + m_help = UQ_SIP_HELP; + m_computeSolution = UQ_SIP_COMPUTE_SOLUTION_ODV; + m_dataOutputFileName = UQ_SIP_DATA_OUTPUT_FILE_NAME_ODV; + m_seedWithMAPEstimator = UQ_SIP_SEEDWITHMAPESTIMATOR; + m_useOptimizerMonitor = UQ_SIP_USEOPTIMIZERMONITOR; +//m_dataOutputAllowedSet() +#ifdef UQ_SIP_READS_SOLVER_OPTION + m_solverString = UQ_SIP_SOLVER_ODV; +#endif +} + +void +SipOptionsValues::set_prefix(const std::string& prefix) +{ + m_prefix = prefix + "ip_"; + + m_option_help = m_prefix + "help"; + m_option_computeSolution = m_prefix + "computeSolution"; + m_option_dataOutputFileName = m_prefix + "dataOutputFileName"; + m_option_dataOutputAllowedSet = m_prefix + "dataOutputAllowedSet"; +#ifdef UQ_SIP_READS_SOLVER_OPTION + m_option_solver = m_prefix + "solver"; +#endif + m_option_seedWithMAPEstimator = m_prefix + "seedWithMAPEstimator"; + m_option_useOptimizerMonitor = m_prefix + "useOptimizerMonitor"; +} + +void +SipOptionsValues::parse(const BaseEnvironment& env, const std::string& prefix) +{ + this->set_prefix(prefix); + +#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS + + m_parser.reset(new BoostInputOptionsParser(env.optionsInputFileName())); + + m_parser->registerOption + (m_option_help, m_help, + "produce help message for statistical inverse problem"); + m_parser->registerOption + (m_option_computeSolution, m_computeSolution, + "compute solution process"); + m_parser->registerOption + (m_option_dataOutputFileName, m_dataOutputFileName, + "name of data output file"); + m_parser->registerOption + (m_option_dataOutputAllowedSet, container_to_string(m_dataOutputAllowedSet), + "subEnvs that will write to data output file"); +#ifdef UQ_SIP_READS_SOLVER_OPTION + m_parser->registerOption + (m_option_solver, m_solver, + "algorithm for calibration"); +#endif + m_parser->registerOption + (m_option_seedWithMAPEstimator, m_seedWithMAPEstimator, + "toggle for seeding chain at MAP"); + m_parser->registerOption + (m_option_useOptimizerMonitor, m_useOptimizerMonitor, + "toggle for using optimizer monitor (prints diagnostics"); + + m_parser->scanInputFile(); + + m_parser->getOption(m_option_help, m_help); + m_parser->getOption(m_option_computeSolution, m_computeSolution); + m_parser->getOption + (m_option_dataOutputFileName, m_dataOutputFileName); + m_parser->getOption > + (m_option_dataOutputAllowedSet, m_dataOutputAllowedSet); +#ifdef UQ_SIP_READS_SOLVER_OPTION + m_parser->getOption(m_option_solver, m_solver); +#endif + m_parser->getOption + (m_option_seedWithMAPEstimator, m_seedWithMAPEstimator); + m_parser->getOption + (m_option_useOptimizerMonitor, m_useOptimizerMonitor); + +#else + + m_help = env.input()(m_option_help, m_help); + m_computeSolution = env.input()(m_option_computeSolution, m_computeSolution); + m_dataOutputFileName = env.input() + (m_option_dataOutputFileName, m_dataOutputFileName); + + // UQ_SIP_DATA_OUTPUT_ALLOWED_SET_ODV is the empty set (string) by default + unsigned int size = + env.input().vector_variable_size(m_option_dataOutputAllowedSet); + for (unsigned int i = 0; i < size; i++) { + // We default to empty set, so the default values are actually never + // used here + unsigned int allowed = env.input()(m_option_dataOutputAllowedSet, i, i); + m_dataOutputAllowedSet.insert(allowed); + } + +#ifdef UQ_SIP_READS_SOLVER_OPTION + m_solver = env.input()(m_option_solver, m_solver); +#endif + m_seedWithMAPEstimator = env.input() + (m_option_seedWithMAPEstimator, m_seedWithMAPEstimator); + m_useOptimizerMonitor = env.input() + (m_option_useOptimizerMonitor, m_useOptimizerMonitor); +#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS + + checkOptions(); +} + } // End namespace QUESO