Skip to content

Commit c780d04

Browse files
committed
Throw an error if base class RBTheta::evaluate() is called with a multi-step RBParameters object
1 parent ecf8e33 commit c780d04

1 file changed

Lines changed: 27 additions & 4 deletions

File tree

src/reduced_basis/rb_theta.C

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,14 +25,37 @@
2525
namespace libMesh
2626
{
2727

28-
Number RBTheta::evaluate(const RBParameters &) { return 1.; }
28+
Number RBTheta::evaluate(const RBParameters & mu)
29+
{
30+
// The RBTheta::evaluate() API is not general enough to handle the
31+
// multi-step RBParameters case, and you must therefore call
32+
// RBTheta::evaluate_vec() instead.
33+
libmesh_error_msg_if(mu.n_steps() > 1,
34+
"You should only call the evaluate_vec() API when using multi-step RBParameters objects.");
35+
36+
return 1.;
37+
}
2938

3039
std::vector<Number>
3140
RBTheta::evaluate_vec(const std::vector<RBParameters> & mus)
3241
{
33-
std::vector<Number> result(mus.size());
34-
for (auto i : index_range(mus))
35-
result[i] = evaluate(mus[i]);
42+
// Eventual return value
43+
std::vector<Number> result;
44+
45+
for (const auto & mu : mus)
46+
{
47+
// Backwards-compatible behavior: for single-step RBParameters objects, we fall back on
48+
// calling the scalar evaluate() function for this RBTheta object, which may have been
49+
// overridden by the user.
50+
if (mu.n_steps() == 1)
51+
result.push_back( this->evaluate(mu) );
52+
else
53+
{
54+
// For multistep RBParameters objects, all we can do is return
55+
// mu.n_steps() copies of 1 here at the base class level.
56+
result.insert(result.end(), /*count=*/mu.n_steps(), /*val=*/1.);
57+
}
58+
}
3659

3760
return result;
3861
}

0 commit comments

Comments
 (0)