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

Hermes-3 merges #1

Open
wants to merge 37 commits into
base: next
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
9d7f620
Add Array<int> to Options
bendudson Jun 14, 2023
c8e3dd0
GridFile: Check sizes, allocate vector ints
bendudson Jun 15, 2023
2e9f495
Add limiters in input mesh
bendudson Jun 15, 2023
1c77e00
Merge branch 'bugfix-fvops-yalign' into hermes3-temp
bendudson Jun 15, 2023
7d261d4
Merge branch 'next' into hermes3-temp
bendudson Feb 16, 2024
30a93f7
Apply black changes
bendudson Feb 16, 2024
fee27c9
Dump field before and after rhs evaluation for debugging
dschwoerer Nov 3, 2023
96da2e9
Add setName function
dschwoerer Nov 3, 2023
e56981c
Set div_par and grad_par names
dschwoerer Jun 19, 2023
6b2c132
Dump debug file if PVODE fails
dschwoerer Jun 19, 2023
df2d661
Add tracking to Field3D
dschwoerer Jun 19, 2023
263f9fe
Add tracking to Field3D
dschwoerer Jun 19, 2023
bac4ca9
cvode: Add option to use Adams Moulton solver instead of BDF
dschwoerer Apr 25, 2023
708bdcb
Expose more pvode option to user
dschwoerer Mar 29, 2023
d88b454
Fix bad cherry-pick
dschwoerer Mar 19, 2024
023bc41
Update to new API
dschwoerer Mar 19, 2024
affc995
Fix documentation
dschwoerer Mar 19, 2024
71f5b6a
Apply clang-format changes
dschwoerer Mar 19, 2024
31fd461
Apply recomendations from code-review
dschwoerer Mar 20, 2024
17e46cf
Use more meaningful names
dschwoerer Mar 20, 2024
9c0ae16
Apply clang-format changes
dschwoerer Mar 20, 2024
4a17b49
Apply suggestions from code review
dschwoerer Mar 20, 2024
2f7c3c0
Workaround for gcc 9.4
dschwoerer Mar 20, 2024
d611758
Add option to debug on failure
dschwoerer Apr 9, 2024
db96b7e
Add option to euler solver to dump debug info
dschwoerer Apr 9, 2024
84bfcef
Disable tracking once we are done
dschwoerer Apr 15, 2024
73265df
Allow to dump every timestep with euler
dschwoerer Apr 15, 2024
8ff388a
Apply clang-format changes
dschwoerer Apr 15, 2024
d7f8807
Merge branch 'next' into hermes3-temp
bendudson Jul 5, 2024
acdc86c
Add debug_on_failure for cvode
dschwoerer Jul 24, 2024
87e6877
Add cvode_max_conv_fails option
Steven-Roberts Jul 24, 2024
ffca58c
Apply clang-format changes
mikekryjak Jul 25, 2024
bb7c0f2
Merge remote-tracking branch 'boutproject/pvcode-cvode-improvements' …
mikekryjak Jul 25, 2024
01951e8
Merge remote-tracking branch 'Steven-Roberts/cvode_max_conv_fails' in…
mikekryjak Jul 25, 2024
44022f9
Merge remote-tracking branch 'boutproject/cvode-for-mike' into hermes3
mikekryjak Jul 25, 2024
9cccd66
merge
mikekryjak Jul 25, 2024
79821e2
Apply clang-format changes
mikekryjak Jul 25, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions include/bout/field.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -683,4 +683,19 @@ inline T floor(const T& var, BoutReal f, const std::string& rgn = "RGN_ALL") {

#undef FIELD_FUNC

template <typename T, typename = bout::utils::EnableIfField<T>, class... Types>
inline void setName(T& f, const std::string& name, Types... args) {
#if BOUT_USE_TRACK
f.name = fmt::format(name, args...);
#endif
}

template <typename T, typename = bout::utils::EnableIfField<T>, class... Types>
inline T setName(T&& f, const std::string& name, Types... args) {
#if BOUT_USE_TRACK
f.name = fmt::format(name, args...);
#endif
return f;
}

#endif /* FIELD_H */
18 changes: 18 additions & 0 deletions include/bout/field3d.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,17 @@ public:
/// cuts on closed field lines?
bool requiresTwistShift(bool twist_shift_enabled);

/// Enable a special tracking mode for debugging
/// Save all changes that, are done to the field, to tracking
Field3D& enableTracking(const std::string& name, Options& tracking);

/// Disable tracking
Field3D& disableTracking() {
tracking = nullptr;
tracking_state = 0;
return *this;
}

/////////////////////////////////////////////////////////
// Data access

Expand Down Expand Up @@ -514,6 +525,13 @@ private:

/// RegionID over which the field is valid
std::optional<size_t> regionID;

int tracking_state{0};
Options* tracking{nullptr};
std::string selfname;
template <class T>
Options* track(const T& change, std::string operation);
Options* track(const BoutReal& change, std::string operation);
};

// Non-member overloaded operators
Expand Down
10 changes: 7 additions & 3 deletions include/bout/options.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,9 @@ public:
}

/// The type used to store values
using ValueType =
bout::utils::variant<bool, int, BoutReal, std::string, Field2D, Field3D, FieldPerp,
Array<BoutReal>, Matrix<BoutReal>, Tensor<BoutReal>>;
using ValueType = bout::utils::variant<bool, int, BoutReal, std::string, Field2D,
Field3D, FieldPerp, Array<BoutReal>, Array<int>,
Matrix<BoutReal>, Tensor<BoutReal>>;

/// A tree representation with leaves containing ValueType.
/// Used to construct Options from initializer lists.
Expand Down Expand Up @@ -914,6 +914,8 @@ void Options::assign<>(FieldPerp val, std::string source);
template <>
void Options::assign<>(Array<BoutReal> val, std::string source);
template <>
void Options::assign<>(Array<int> val, std::string source);
template <>
void Options::assign<>(Matrix<BoutReal> val, std::string source);
template <>
void Options::assign<>(Tensor<BoutReal> val, std::string source);
Expand Down Expand Up @@ -942,6 +944,8 @@ FieldPerp Options::as<FieldPerp>(const FieldPerp& similar_to) const;
template <>
Array<BoutReal> Options::as<Array<BoutReal>>(const Array<BoutReal>& similar_to) const;
template <>
Array<int> Options::as<Array<int>>(const Array<int>& similar_to) const;
template <>
Matrix<BoutReal> Options::as<Matrix<BoutReal>>(const Matrix<BoutReal>& similar_to) const;
template <>
Tensor<BoutReal> Options::as<Tensor<BoutReal>>(const Tensor<BoutReal>& similar_to) const;
Expand Down
4 changes: 2 additions & 2 deletions include/bout/utils.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -566,8 +566,8 @@ std::string toString(const T& val) {
/// where the type may be std::string.
inline std::string toString(const std::string& val) { return val; }

template <>
inline std::string toString<>(const Array<BoutReal>& UNUSED(val)) {
template <typename T>
inline std::string toString(const Array<T>& UNUSED(val)) {
return "<Array>";
}

Expand Down
2 changes: 1 addition & 1 deletion manual/sphinx/user_docs/bout_options.rst
Original file line number Diff line number Diff line change
Expand Up @@ -889,7 +889,7 @@ Fields can also be stored and written::
Options fields;
fields["f2d"] = Field2D(1.0);
fields["f3d"] = Field3D(2.0);
bout::OptionsIO::create("fields.nc").write(fields);
bout::OptionsIO::create("fields.nc")->write(fields);

This allows the input settings and evolving variables to be
combined into a single tree (see above on joining trees) and written
Expand Down
48 changes: 48 additions & 0 deletions src/field/field3d.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) {
}

TRACE("Field3D: Assignment from Field3D");
track(rhs, "operator=");

// Copy base slice
Field::operator=(rhs);
Expand All @@ -265,6 +266,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) {

Field3D& Field3D::operator=(Field3D&& rhs) {
TRACE("Field3D: Assignment from Field3D");
track(rhs, "operator=");

// Move parallel slices or delete existing ones.
yup_fields = std::move(rhs.yup_fields);
Expand All @@ -285,6 +287,7 @@ Field3D& Field3D::operator=(Field3D&& rhs) {

Field3D& Field3D::operator=(const Field2D& rhs) {
TRACE("Field3D = Field2D");
track(rhs, "operator=");

/// Check that the data is allocated
ASSERT1(rhs.isAllocated());
Expand Down Expand Up @@ -329,6 +332,7 @@ void Field3D::operator=(const FieldPerp& rhs) {

Field3D& Field3D::operator=(const BoutReal val) {
TRACE("Field3D = BoutReal");
track(val, "operator=");

// Delete existing parallel slices. We don't copy parallel slices, so any
// that currently exist will be incorrect.
Expand Down Expand Up @@ -833,3 +837,47 @@ Field3D::getValidRegionWithDefault(const std::string& region_name) const {
void Field3D::setRegion(const std::string& region_name) {
regionID = fieldmesh->getRegionID(region_name);
}

Field3D& Field3D::enableTracking(const std::string& name, Options& _tracking) {
tracking = &_tracking;
tracking_state = 1;
selfname = name;
return *this;
}

template <class T>
Options* Field3D::track(const T& change, std::string operation) {
if (tracking != nullptr and tracking_state != 0) {
const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)};
tracking->set(outname, change, "tracking");
// Workaround for bug in gcc9.4
#if BOUT_USE_TRACK
const std::string changename = change.name;
#endif
(*tracking)[outname].setAttributes({
{"operation", operation},
#if BOUT_USE_TRACK
{"rhs.name", changename},
#endif
});
return &(*tracking)[outname];
}
return nullptr;
}

template Options* Field3D::track<Field3D>(const Field3D&, std::string);
template Options* Field3D::track<Field2D>(const Field2D&, std::string);
template Options* Field3D::track<FieldPerp>(const FieldPerp&, std::string);

Options* Field3D::track(const BoutReal& change, std::string operation) {
if (tracking and tracking_state) {

Choose a reason for hiding this comment

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

warning: implicit conversion 'Options *' -> bool [readability-implicit-bool-conversion]

Suggested change
if (tracking and tracking_state) {
if ((tracking != nullptr) and tracking_state) {

Choose a reason for hiding this comment

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

warning: implicit conversion 'int' -> bool [readability-implicit-bool-conversion]

Suggested change
if (tracking and tracking_state) {
if (tracking and (tracking_state != 0)) {

const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)};
tracking->set(outname, change, "tracking");
(*tracking)[outname].setAttributes({
{"operation", operation},
{"rhs.name", "BR"},
});
return &(*tracking)[outname];
}
return nullptr;
}
14 changes: 14 additions & 0 deletions src/field/gen_fieldops.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@
}
{% endif %}

#if BOUT_USE_TRACK
{{out.name}}.name = fmt::format("{:s} {{operator}} {:s}", {{'"BR"' if lhs == "BoutReal" else lhs.name + ".name"}}
, {{'"BR"' if rhs == "BoutReal" else rhs.name + ".name"}});
#endif
checkData({{out.name}});
return {{out.name}};
}
Expand Down Expand Up @@ -129,9 +133,19 @@
}
{% endif %}

{% if lhs == "Field3D" %}
track(rhs, "operator{{operator}}=");
{% endif %}
#if BOUT_USE_TRACK
name = fmt::format("{:s} {{operator}}= {:s}", this->name, {{'"BR"' if rhs == "BoutReal" else rhs.name + ".name"}});
#endif

checkData(*this);

} else {
{% if lhs == "Field3D" %}
track(rhs, "operator{{operator}}=");
{% endif %}
(*this) = (*this) {{operator}} {{rhs.name}};
}
return *this;
Expand Down
Loading