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

Allow descriptions of output variables; save some diagnostics for solvers #2064

Merged
merged 19 commits into from
Dec 28, 2020

Conversation

johnomotani
Copy link
Contributor

@johnomotani johnomotani commented Aug 6, 2020

Descriptions of output variables

Adds an optional argument to Datafile::add(), Solver::add() and bout_solve() which can be passed a description as a std::string. The description is then added to the output files as an attribute of the variable. This should be useful for making the output files self-documenting. This PR adds the mechanism, but variables written by BOUT++ still need a description adding in a future PR (apart from the new solver diagnostic variables described below).

Save some diagnostics for solvers

When solver:diagnose=true is set, CVODE and ARKODE print out some useful information. This PR saves those numbers to the dump files to make them easier to access in post-processing.

The diagnostics are always saved, regardless of solver:diagnose setting. The setting is useful to avoid cluttering up stdout, but I don't see any benefit to not saving into dump files - the diagnostics are scalars so don't take up much space, and it's nice to be able to go back and look at them without having decided to set the setting before the run.

The diagnostic variables have descriptions copied from the CVODE and ARKODE manuals which are written as attributes using the new description argument described above. These help make the output files a little less cryptic, since SUNDIALS variable names are not very descriptive (e.g. nliters).

  • add documentation of the 'description' arguments of Datafile::add() and Solver::add() to the manual.

@johnomotani
Copy link
Contributor Author

This PR implements descriptions for output variables, which would be useful for #2065, because I wanted to add descriptions of the diagnostic variables here. The description-handling parts (09b5fa2 and 6fbf9cb) could be split into a separate PR easily if that helps.

BTW the way this is implemented means PhysicsModels can also add descriptions, with the new, optional 'description' arguments to Datafile::add() and Solver::add(). Should probably add some description of that in the manual, but let's agree on the interface design first...

@johnomotani johnomotani added work in progress Not ready for merging backport candidiate Does not break backward compatibility, so can be back-ported to v4.4 labels Aug 6, 2020
Datafile::setAttribute() opens the DataFormat object and then calls its
setAttribute() method. Don't want to do this inside Datafile::write()
where the DataFormat is already opened.
Poiner to the int or BoutReal is stored in a VarStr, so need to pass by
reference and not by value, otherwise the pointer ends up pointing to
some random place.
@johnomotani
Copy link
Contributor Author

I think I fixed the memory errors. Had accidentally passed int or BoutReal by value before storing a pointer to the address.

If solver type is changed, diagnostic variables will change and so might
cause errors if they are added to restart files but cannot be read. So
do not add diagnostic variables to the restart files.
@johnomotani johnomotani removed the work in progress Not ready for merging label Aug 21, 2020
@johnomotani
Copy link
Contributor Author

I've added the description argument to the manual. Noticed that we recommend using bout_solve() there rather than solver->add() so added the description argument to bout_solve() as well.

This PR is ready for review now.

@johnomotani johnomotani changed the title Save some diagnostics for solvers Allow descriptions of output variables; save some diagnostics for solvers Aug 21, 2020
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

@@ -409,6 +410,24 @@ protected:
std::vector<VarStr<Vector2D>> v2d;
std::vector<VarStr<Vector3D>> v3d;

/// Vectors of diagnostic variables to save
std::vector<VarStr<int>> diagnostic_int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable diagnostic_int has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

std::vector<VarStr<int>> diagnostic_int;
                         ^

@@ -409,6 +410,24 @@ protected:
std::vector<VarStr<Vector2D>> v2d;
std::vector<VarStr<Vector3D>> v3d;

/// Vectors of diagnostic variables to save
std::vector<VarStr<int>> diagnostic_int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable diagnostic_int has protected visibility [misc-non-private-member-variables-in-classes]

@@ -409,6 +410,24 @@ protected:
std::vector<VarStr<Vector2D>> v2d;
std::vector<VarStr<Vector3D>> v3d;

/// Vectors of diagnostic variables to save
std::vector<VarStr<int>> diagnostic_int;
std::vector<VarStr<BoutReal>> diagnostic_BoutReal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable diagnostic_BoutReal has protected visibility [cppcoreguidelines-non-private-member-variables-in-classes]

std::vector<VarStr<BoutReal>> diagnostic_BoutReal;
                              ^

@@ -409,6 +410,24 @@ protected:
std::vector<VarStr<Vector2D>> v2d;
std::vector<VarStr<Vector3D>> v3d;

/// Vectors of diagnostic variables to save
std::vector<VarStr<int>> diagnostic_int;
std::vector<VarStr<BoutReal>> diagnostic_BoutReal;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: member variable diagnostic_BoutReal has protected visibility [misc-non-private-member-variables-in-classes]

include/bout/solver.hxx Show resolved Hide resolved
include/bout/solver.hxx Show resolved Hide resolved
@@ -506,15 +518,22 @@ int ArkodeSolver::run() {
throw BoutException("ARKode timestep failed\n");
}

// Get additional diagnostics
long int temp_long_int, temp_long_int2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: multiple declarations in a single statement reduces readability [readability-isolate-declaration]

long int temp_long_int, temp_long_int2;
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

@@ -506,15 +518,22 @@ int ArkodeSolver::run() {
throw BoutException("ARKode timestep failed\n");
}

// Get additional diagnostics
long int temp_long_int, temp_long_int2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable temp_long_int is not initialized [cppcoreguidelines-init-variables]

long int temp_long_int, temp_long_int2;
         ^
                       = 0

@@ -506,15 +518,22 @@ int ArkodeSolver::run() {
throw BoutException("ARKode timestep failed\n");
}

// Get additional diagnostics
long int temp_long_int, temp_long_int2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable temp_long_int2 is not initialized [cppcoreguidelines-init-variables]

long int temp_long_int, temp_long_int2;
                        ^
                                       = 0

@@ -385,16 +404,39 @@ int CvodeSolver::run() {
throw BoutException("SUNDIALS CVODE timestep failed\n");
}

// Get additional diagnostics
long int temp_long_int;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: variable temp_long_int is not initialized [cppcoreguidelines-init-variables]

long int temp_long_int;
         ^
                       = 0

@johnomotani
Copy link
Contributor Author

What's the clang-tidy bot supposed to do if you 'fix' the things it suggests? It doesn't seem to have removed the comments like I'd hope. The changes I made weren't directly what it suggested though (I passed by reference instead of using a std::move), so that might be why?

@ZedThree
Copy link
Member

ZedThree commented Dec 11, 2020 via email

@johnomotani
Copy link
Contributor Author

No, I'm afraid it's not as clever as that. For now you can just click
"resolve" on the comment. I can probably make it do that automatically if
there's an API for it though

Thanks @ZedThree! The PEP8 bot somehow does this, but I don't know how. Would be nice, but clicking 'resolve' on addressed issues is fine with me - I was just wondering if there was a feature that wasn't working right.

@ZedThree
Copy link
Member

ZedThree commented Dec 11, 2020 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport candidiate Does not break backward compatibility, so can be back-ported to v4.4 documentation feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants