Skip to content

Commit

Permalink
Adjust control flow to check empty vectors (#3988)
Browse files Browse the repository at this point in the history
  • Loading branch information
dschwen committed Oct 6, 2014
1 parent 0c66414 commit 041ef39
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 4 deletions.
14 changes: 10 additions & 4 deletions framework/include/utils/InputParameters.h
Expand Up @@ -564,13 +564,19 @@ InputParameters::rangeCheck(const std::string & full_name, const std::string & s

// iterate over all vector values (maybe ;)
bool need_to_iterate = false;
for (unsigned int i = 0; i < value.size(); i++)
{
unsigned int i = 0;
do {
// set parameters
for (unsigned int j = 0; j < vars.size(); j++)
{
if (vars[j] == short_name)
{
if (value.size() == 0)
{
oss << "Range checking empty vector: " << _range_functions[short_name] << '\n';
return;
}

parbuf[j] = value[i];
need_to_iterate = true;
}
Expand Down Expand Up @@ -619,8 +625,8 @@ InputParameters::rangeCheck(const std::string & full_name, const std::string & s
oss << "\t Component: " << i << '\n';
}

if (!need_to_iterate) break;
}

} while (need_to_iterate && ++i < value.size());
}

template <typename T, typename UP_T>
Expand Down
1 change: 1 addition & 0 deletions test/src/materials/VecRangeCheckMaterial.C
Expand Up @@ -12,6 +12,7 @@ InputParameters validParams<VecRangeCheckMaterial>()
params.addRequiredRangeCheckedParam<std::vector<int> >("ivg", "ivg_0 > ivg_1", "Int vector where component 0 is bigger than component 1");
params.addRequiredRangeCheckedParam<std::vector<Real> >("rvg", "rvg_0 > rvg_1", "Real vector where component 0 is bigger than component 1");
params.addRequiredRangeCheckedParam<std::vector<Real> >("rvl", "rvl_10 > 0", "Testing if component 10 is positive (usually we should have a size check here as well)");
params.addRequiredRangeCheckedParam<std::vector<Real> >("rve", "rve_size = 0 | rve_size = 3", "Vector with either 0 or 3 components");
return params;
}

Expand Down
1 change: 1 addition & 0 deletions test/tests/parser/vector_range_checking/all_pass.i
Expand Up @@ -15,6 +15,7 @@
ivg = '2 1'
rvg = '2.0 1.0'
rvl = '0.0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 1.1 1.2 1.3'
rve = ''
[../]
[]

Expand Down
6 changes: 6 additions & 0 deletions test/tests/parser/vector_range_checking/tests
Expand Up @@ -47,4 +47,10 @@
expect_err = "Error parsing expression: rvl_10 > 0\nOut of range variable rvl_10"
cli_args = Materials/vecrangecheck/rvl="1.0 2.0"
[../]
[./checkempty]
type = 'RunException'
input = 'all_pass.i'
expect_err = "Range checking empty vector: rvp > 0"
cli_args = Materials/vecrangecheck/rvp=""
[../]
[]

0 comments on commit 041ef39

Please sign in to comment.