Skip to content

Commit

Permalink
Granular construction of SfpOptionsValues
Browse files Browse the repository at this point in the history
Refactor in support of libqueso#569 to enable various layered
phases of constructing SfpOptionsValues.  This mirrors work done in
other *OptionsValues.
  • Loading branch information
briadam committed Oct 13, 2017
1 parent 5398d53 commit e6bbc02
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 89 deletions.
11 changes: 10 additions & 1 deletion src/stats/inc/StatisticalForwardProblemOptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class SfpOptionsValues
/*! It assigns the same options values from \c src to \c this.*/
SfpOptionsValues (const SfpOptionsValues& 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 ~SfpOptionsValues ();
//@}
Expand Down Expand Up @@ -109,7 +118,7 @@ class SfpOptionsValues

private:
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
BoostInputOptionsParser * m_parser;
ScopedPtr<BoostInputOptionsParser>::Type m_parser;
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

// The input options as strings so we can parse the input file later
Expand Down
196 changes: 108 additions & 88 deletions src/stats/src/StatisticalForwardProblemOptions.C
Original file line number Diff line number Diff line change
Expand Up @@ -43,98 +43,15 @@ namespace QUESO {

// Default constructor -----------------------------
SfpOptionsValues::SfpOptionsValues()
:
m_prefix ("fp_"),
m_help(UQ_SFP_HELP),
m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
//m_dataOutputAllowedSet(),
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_parser(NULL),
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_option_help (m_prefix + "help" ),
m_option_computeSolution (m_prefix + "computeSolution" ),
m_option_computeCovariances (m_prefix + "computeCovariances" ),
m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_option_solver (m_prefix + "solver" ),
m_solverString (UQ_SFP_SOLVER_ODV )
#endif
{
this->set_defaults();
this->set_prefix("");
}

SfpOptionsValues::SfpOptionsValues(const BaseEnvironment * env, const char *
prefix)
:
m_prefix ((std::string)(prefix) + "fp_"),
m_help(UQ_SFP_HELP),
m_computeSolution (UQ_SFP_COMPUTE_SOLUTION_ODV ),
m_computeCovariances (UQ_SFP_COMPUTE_COVARIANCES_ODV ),
m_computeCorrelations (UQ_SFP_COMPUTE_CORRELATIONS_ODV ),
m_dataOutputFileName (UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV),
//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_computeCovariances (m_prefix + "computeCovariances" ),
m_option_computeCorrelations (m_prefix + "computeCorrelations" ),
m_option_dataOutputFileName (m_prefix + "dataOutputFileName" ),
m_option_dataOutputAllowedSet(m_prefix + "dataOutputAllowedSet")
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_option_solver (m_prefix + "solver" ),
m_solverString (UQ_SFP_SOLVER_ODV )
#endif
SfpOptionsValues::SfpOptionsValues(const BaseEnvironment* env, const char* prefix)
{
#ifndef QUESO_DISABLE_BOOST_PROGRAM_OPTIONS
m_parser->registerOption<std::string>(m_option_help, UQ_SFP_HELP, "produce help message for statistical forward problem");
m_parser->registerOption<bool >(m_option_computeSolution, UQ_SFP_COMPUTE_SOLUTION_ODV , "compute solution process" );
m_parser->registerOption<bool >(m_option_computeCovariances, UQ_SFP_COMPUTE_COVARIANCES_ODV , "compute pq covariances" );
m_parser->registerOption<bool >(m_option_computeCorrelations, UQ_SFP_COMPUTE_CORRELATIONS_ODV , "compute pq correlations" );
m_parser->registerOption<std::string>(m_option_dataOutputFileName, UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV , "name of data output file" );
m_parser->registerOption<std::string>(m_option_dataOutputAllowedSet, UQ_SFP_DATA_OUTPUT_ALLOWED_SET_ODV, "subEnvs that will write to data output file" );
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_parser->registerOption<std::string>(m_option_solver, UQ_SFP_SOLVER_ODV , "algorithm for propagation" );
#endif

m_parser->scanInputFile();

m_parser->getOption<std::string>(m_option_help, m_help);
m_parser->getOption<bool >(m_option_computeSolution, m_computeSolution);
m_parser->getOption<bool >(m_option_computeCovariances, m_computeCovariances);
m_parser->getOption<bool >(m_option_computeCorrelations, m_computeCorrelations);
m_parser->getOption<std::string>(m_option_dataOutputFileName, m_dataOutputFileName);
m_parser->getOption<std::set<unsigned int> >(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet);
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_parser->getOption<std::string>(m_option_solver, m_solver);
#endif
#else
m_help = env->input()(m_option_help, UQ_SFP_HELP);
m_computeSolution = env->input()(m_option_computeSolution, UQ_SFP_COMPUTE_SOLUTION_ODV);
m_computeCovariances = env->input()(m_option_computeCovariances, UQ_SFP_COMPUTE_COVARIANCES_ODV);
m_computeCorrelations = env->input()(m_option_computeCorrelations, UQ_SFP_COMPUTE_CORRELATIONS_ODV);
m_dataOutputFileName = env->input()(m_option_dataOutputFileName, UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV);

// UQ_SFP_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_SFP_READS_SOLVER_OPTION
m_solver = env->input()(m_option_solver, UQ_SFP_SOLVER_ODV);
#endif
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

checkOptions();
this->set_defaults();
this->parse(*env, prefix);
}

// Copy constructor----------------------------------
Expand Down Expand Up @@ -200,4 +117,107 @@ operator<<(std::ostream & os, const SfpOptionsValues & obj)
return os;
}

void
SfpOptionsValues::set_defaults()
{
m_help = UQ_SFP_HELP;
m_computeSolution = UQ_SFP_COMPUTE_SOLUTION_ODV;
m_computeCovariances = UQ_SFP_COMPUTE_COVARIANCES_ODV ;
m_computeCorrelations = UQ_SFP_COMPUTE_CORRELATIONS_ODV;
m_dataOutputFileName = UQ_SFP_DATA_OUTPUT_FILE_NAME_ODV;
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_solverString = UQ_SFP_SOLVER_ODV;
#endif
}

void
SfpOptionsValues::set_prefix(const std::string& prefix)
{
m_prefix = prefix + "fp_";

m_option_help = m_prefix + "help";
m_option_computeSolution = m_prefix + "computeSolution";
m_option_computeCovariances = m_prefix + "computeCovariances";
m_option_computeCorrelations = m_prefix + "computeCorrelations";
m_option_dataOutputFileName = m_prefix + "dataOutputFileName";
m_option_dataOutputAllowedSet = m_prefix + "dataOutputAllowedSet";
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_option_solver = m_prefix + "solver";
#endif
}

void
SfpOptionsValues::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<std::string>
(m_option_help, m_help,
"produce help message for statistical forward problem");
m_parser->registerOption<bool>
(m_option_computeSolution, m_computeSolution,
"compute solution process");
m_parser->registerOption<bool>
(m_option_computeCovariances, m_computeCovariances,
"compute pq covariances");
m_parser->registerOption<bool>
(m_option_computeCorrelations, m_computeCorrelations,
"compute pq correlations");
m_parser->registerOption<std::string>
(m_option_dataOutputFileName, m_dataOutputFileName,
"name of data output file");
m_parser->registerOption<std::string>
(m_option_dataOutputAllowedSet, container_to_string(m_dataOutputAllowedSet),
"subEnvs that will write to data output file");
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_parser->registerOption<std::string>
(m_option_solver, m_solver,
"algorithm for propagation");
#endif

m_parser->scanInputFile();

m_parser->getOption<std::string>(m_option_help, m_help);
m_parser->getOption<bool>(m_option_computeSolution, m_computeSolution);
m_parser->getOption<bool>(m_option_computeCovariances, m_computeCovariances);
m_parser->getOption<bool>(m_option_computeCorrelations, m_computeCorrelations);
m_parser->getOption<std::string>
(m_option_dataOutputFileName, m_dataOutputFileName);
m_parser->getOption<std::set<unsigned int> >
(m_option_dataOutputAllowedSet, m_dataOutputAllowedSet);
#ifdef UQ_SFP_READS_SOLVER_OPTION
m_parser->getOption<std::string>(m_option_solver, m_solver);
#endif
#else
m_help = env.input()(m_option_help, UQ_SFP_HELP);
m_computeSolution = env.input()(m_option_computeSolution, m_computeSolution);
m_computeCovariances = env.input()
(m_option_computeCovariances, m_computeCovariances);
m_computeCorrelations = env.input()
(m_option_computeCorrelations, m_computeCorrelations);
m_dataOutputFileName = env.input()
(m_option_dataOutputFileName, m_dataOutputFileName);

// UQ_SFP_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_SFP_READS_SOLVER_OPTION
m_solver = env.input()(m_option_solver, m_solver);
#endif
#endif // QUESO_DISABLE_BOOST_PROGRAM_OPTIONS

checkOptions();
}

} // End namespace QUESO

0 comments on commit e6bbc02

Please sign in to comment.