-
Notifications
You must be signed in to change notification settings - Fork 104
Pvcode + Cvode improvements #2889
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
base: next
Are you sure you want to change the base?
Changes from all commits
fee27c9
96da2e9
e56981c
6b2c132
df2d661
263f9fe
bac4ca9
708bdcb
d88b454
023bc41
affc995
71f5b6a
31fd461
17e46cf
9c0ae16
4a17b49
2f7c3c0
d611758
db96b7e
84bfcef
73265df
8ff388a
6724e75
28212c2
9cf0fba
97b67e1
77e08ec
ba6fc6c
3c0d6a8
8e578fc
d0669cd
291e4af
42fc8ff
c9c13d4
ff93406
a096cc5
27db46d
24610c3
f6db2df
d1c137f
ee8a9d6
00fbaac
12c6c00
e684304
b75d020
b824cfc
90815fa
69457b8
b265c90
9c47bb8
02cc7d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,6 +36,7 @@ class Field; | |
| #include "bout/bout_types.hxx" | ||
| #include "bout/boutcomm.hxx" | ||
| #include "bout/boutexception.hxx" | ||
| #include "bout/build_defines.hxx" | ||
| #include "bout/field_data.hxx" | ||
| #include "bout/msg_stack.hxx" | ||
| #include "bout/region.hxx" | ||
|
|
@@ -678,4 +679,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 | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| template <typename T, typename = bout::utils::EnableIfField<T>, class... Types> | ||
| inline T setName(T&& f, const std::string& name, Types... args) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think most other setters like this are member functions
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To make this a member function, make it virtual: field.hxx: virtual Field& setName(std::string name) {
self->name = std::move(name);
return *self;
}field2d.hxx: Field2D& setName(std::string name) override {
Field::setName(name);
return *self;
}Formatting will have to be done at the calling site, but I think that's fine
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would really love this to be not be done on the caller side, because then the formatting can be easily disabled, and the overhead disappears. If that is not done, in order to avoid the overhead of name tracking, all the calls need to be done using from https://en.cppreference.com/w/cpp/language/member_template
So I guess we would be stuck with not having the member function on the base class, but only on the derived class.
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #if BOUT_USE_TRACK | ||
| f.name = fmt::format(name, args...); | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| #endif | ||
| return std::forward<T>(f); | ||
| } | ||
|
|
||
| #endif /* FIELD_H */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,11 +33,15 @@ class Field3D; | |
| #include "bout/field2d.hxx" | ||
| #include "bout/fieldperp.hxx" | ||
| #include "bout/region.hxx" | ||
| #include "bout/traits.hxx" | ||
|
|
||
| #include <memory> | ||
| #include <optional> | ||
| #include <string> | ||
| #include <vector> | ||
|
|
||
| class Mesh; | ||
| class Options; | ||
|
|
||
| /// Class for 3D X-Y-Z scalar fields | ||
| /*! | ||
|
|
@@ -291,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, std::weak_ptr<Options> tracking); | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| /// Disable tracking | ||
| Field3D& disableTracking() { | ||
| tracking.reset(); | ||
| tracking_state = 0; | ||
| return *this; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////// | ||
| // Data access | ||
|
|
||
|
|
@@ -493,6 +508,8 @@ public: | |
|
|
||
| int size() const override { return nx * ny * nz; }; | ||
|
|
||
| std::weak_ptr<Options> getTracking() { return tracking; }; | ||
|
|
||
| private: | ||
| /// Array sizes (from fieldmesh). These are valid only if fieldmesh is not null | ||
| int nx{-1}, ny{-1}, nz{-1}; | ||
|
|
@@ -508,6 +525,22 @@ private: | |
|
|
||
| /// RegionID over which the field is valid | ||
| std::optional<size_t> regionID; | ||
|
|
||
| /// counter for tracking, to assign unique names to the variable names | ||
| int tracking_state{0}; | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| std::weak_ptr<Options> tracking; | ||
| // name is changed if we assign to the variable, while selfname is a | ||
| // non-changing copy that is used for the variable names in the dump files | ||
| std::string selfname; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need this if we already have
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have added:
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| template <typename T> | ||
| void track(const T& change, const std::string& operation) { | ||
| if (tracking_state != 0) { | ||
| _track(change, operation); | ||
| } | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
| template <typename T, typename = bout::utils::EnableIfField<T>> | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| void _track(const T& change, std::string operation); | ||
| void _track(const BoutReal& change, std::string operation); | ||
| }; | ||
|
|
||
| // Non-member overloaded operators | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -31,6 +31,8 @@ | |
| #include <bout/globals.hxx> | ||
|
|
||
| #include <cmath> | ||
| #include <memory> | ||
| #include <utility> | ||
|
|
||
| #include "bout/parallel_boundary_op.hxx" | ||
| #include "bout/parallel_boundary_region.hxx" | ||
|
|
@@ -47,6 +49,8 @@ | |
| #include <bout/output.hxx> | ||
| #include <bout/utils.hxx> | ||
|
|
||
| #include "fmt/format.h" | ||
|
|
||
| /// Constructor | ||
| Field3D::Field3D(Mesh* localmesh, CELL_LOC location_in, DirectionTypes directions_in) | ||
| : Field(localmesh, location_in, directions_in) { | ||
|
|
@@ -246,6 +250,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |
| } | ||
|
|
||
| TRACE("Field3D: Assignment from Field3D"); | ||
| track(rhs, "operator="); | ||
|
|
||
| // Copy base slice | ||
| Field::operator=(rhs); | ||
|
|
@@ -267,6 +272,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |
|
|
||
| Field3D& Field3D::operator=(Field3D&& rhs) { | ||
| TRACE("Field3D: Assignment from Field3D"); | ||
| track(rhs, "operator="); | ||
ZedThree marked this conversation as resolved.
Show resolved
Hide resolved
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I really think this should be a macro that is only enabled at higher |
||
|
|
||
| // Move parallel slices or delete existing ones. | ||
| yup_fields = std::move(rhs.yup_fields); | ||
|
|
@@ -288,6 +294,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()); | ||
|
|
@@ -334,6 +341,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. | ||
|
|
@@ -864,3 +872,57 @@ 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, | ||
| std::weak_ptr<Options> _tracking) { | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| tracking = std::move(_tracking); | ||
| tracking_state = 1; | ||
| selfname = name; | ||
| return *this; | ||
| } | ||
|
|
||
| template <typename T, typename> | ||
| void Field3D::_track(const T& change, std::string operation) { | ||
| if (tracking_state == 0) { | ||
| return; | ||
| } | ||
| auto locked = tracking.lock(); | ||
| if (locked == nullptr) { | ||
| return; | ||
| } | ||
| const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| locked->set(outname, change, "tracking"); | ||
| // Workaround for bug in gcc9.4 | ||
| #if BOUT_USE_TRACK | ||
| const std::string changename = change.name; | ||
| #endif | ||
| (*locked)[outname].setAttributes({ | ||
| {"operation", operation}, | ||
| #if BOUT_USE_TRACK | ||
| {"rhs.name", changename}, | ||
| #endif | ||
| }); | ||
| } | ||
|
|
||
| template void | ||
| Field3D::_track<Field3D, bout::utils::EnableIfField<Field3D>>(const Field3D&, | ||
| std::string); | ||
| template void Field3D::_track<Field2D>(const Field2D&, std::string); | ||
| template void Field3D::_track<>(const FieldPerp&, std::string); | ||
|
|
||
| void Field3D::_track(const BoutReal& change, std::string operation) { | ||
| if (tracking_state == 0) { | ||
| return; | ||
| } | ||
| auto locked = tracking.lock(); | ||
| if (locked == nullptr) { | ||
| return; | ||
| } | ||
| const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||
| locked->set(outname, change, "tracking"); | ||
| (*locked)[outname].setAttributes({ | ||
| {"operation", operation}, | ||
| {"rhs.name", "BoutReal"}, | ||
| }); | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.