Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Should ParameterHandler::add_parameter() execute the action? #13970

Closed
peterrum opened this issue Jun 13, 2022 · 0 comments · Fixed by #14562
Closed

Should ParameterHandler::add_parameter() execute the action? #13970

peterrum opened this issue Jun 13, 2022 · 0 comments · Fixed by #14562

Comments

@peterrum
Copy link
Member

As pointed out by @mschreter, the following program has an odd behavior:

#include <deal.II/base/parameter_handler.h>

using namespace dealii;

int
main()
{
  double a = std::numeric_limits<double>::lowest();

  std::cout << (a == std::numeric_limits<double>::lowest())
            << std::endl; // true

  ParameterHandler prm;
  prm.add_parameter("test", a);

  std::cout << (a == std::numeric_limits<double>::lowest())
            << std::endl; // false
}

The function ParameterHandler::add_parameter() overrides the old value with a new values plus minus a small rounding error.

The problem is that the created action (which serializes the double to a string and than back o double)

auto action = [&, pattern_index](const std::string &val) {
parameter = Patterns::Tools::Convert<ParameterType>::to_value(
val, *patterns[pattern_index]);
};
add_action(entry, action);

is executed during ParameterHandler::add_parameter()/ParameterHandler::add_action()

// as documented, run the action on the default value at the very end
const std::string default_value = entries->get<std::string>(
get_current_full_path(entry) + path_separator + "default_value");
action(default_value);

We noticed that something is odd when we saw that parameters have been modified that should have not, since they were not listed in the parameter file.

Our suggestion would be to not executed the action when calling ParameterHandler::add_parameter(), i.e., to introduce an additional parameter to ParameterHandler::add_action(), which allows to disable the execution of the action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant