Skip to content

Commit 6b54550

Browse files
authored
Merge pull request #524 from dmcdougall/fix_getpot_fwd_decl
Fix finite diff step size option with getpot
2 parents e87e7a1 + b7fc1f5 commit 6b54550

File tree

1 file changed

+24
-15
lines changed

1 file changed

+24
-15
lines changed

src/basic/src/ScalarFunction.C

+24-15
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,12 @@
2727
#include <queso/VectorSpace.h>
2828
#include <queso/GslVector.h>
2929
#include <queso/GslMatrix.h>
30+
31+
#ifndef DISABLE_BOOST_PROGRAM_OPTIONS
3032
#include <queso/BoostInputOptionsParser.h>
33+
#else
34+
#include <queso/getpot.h>
35+
#endif
3136

3237
#include <cstdlib>
3338

@@ -73,23 +78,27 @@ BaseScalarFunction<V, M>::BaseScalarFunction(const char * prefix,
7378
#else
7479
unsigned int size = m_env.input().vector_variable_size(m_prefix + "fdStepSize");
7580

76-
queso_require_msg(size == 1 || size == dim,
77-
"Finite difference vector is not the correct size");
78-
79-
m_fdStepSize.resize(size);
80-
for (unsigned int i = 0; i < size; i++) {
81-
m_fdStepSize[i] = m_env.input()(m_prefix + "fdStepSize",
82-
QUESO_BASESCALARFN_FD_STEPSIZE_ODV,
83-
i);
81+
if (size == 0) {
82+
m_fdStepSize.resize(dim, std::atof(QUESO_BASESCALARFN_FD_STEPSIZE_ODV));
8483
}
84+
else if (size == 1) {
85+
double value = m_env.input()(m_prefix + "fdStepSize",
86+
std::atof(QUESO_BASESCALARFN_FD_STEPSIZE_ODV),
87+
0);
8588

86-
// If the user provided a scalar for a multi-dimensional function...
87-
if (dim > 1 && size == 1) {
88-
// ...get the only element
89-
double stepSize = m_fdStepSize[0];
90-
91-
// and use it to fill a vector of length dim
92-
m_fdStepSize.resize(dim, stepSize);
89+
m_fdStepSize.resize(dim, value);
90+
}
91+
else if (size == dim) {
92+
for (unsigned int i = 0; i < size; i++) {
93+
m_fdStepSize[i] = m_env.input()(m_prefix + "fdStepSize",
94+
std::atof(QUESO_BASESCALARFN_FD_STEPSIZE_ODV),
95+
i);
96+
}
97+
}
98+
else {
99+
// Either the user provides nothing, a scalar, or the whole vector.
100+
// Any other possiblities are not allowed so we error in this case.
101+
queso_error_msg("Finite difference vector must be a scalar or a vector of length parameter dimension");
93102
}
94103
#endif
95104

0 commit comments

Comments
 (0)