-
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 31 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 |
|---|---|---|
|
|
@@ -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 | ||
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 f; | ||
| } | ||
|
|
||
| #endif /* FIELD_H */ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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() { | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tracking = nullptr; | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| tracking_state = 0; | ||
| return *this; | ||
| } | ||
|
|
||
| ///////////////////////////////////////////////////////// | ||
| // Data access | ||
|
|
||
|
|
@@ -499,6 +510,8 @@ public: | |
|
|
||
| int size() const override { return nx * ny * nz; }; | ||
|
|
||
| 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}; | ||
|
|
@@ -514,6 +527,13 @@ private: | |
|
|
||
| /// RegionID over which the field is valid | ||
| std::optional<size_t> regionID; | ||
|
|
||
| int tracking_state{0}; | ||
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| Options* tracking{nullptr}; | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| 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 <class T> | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| Options* track(const T& change, std::string operation); | ||
| Options* track(const BoutReal& change, std::string operation); | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| // Non-member overloaded operators | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -949,6 +949,9 @@ Tensor<BoutReal> Options::as<Tensor<BoutReal>>(const Tensor<BoutReal>& similar_t | |
| /// Convert \p value to string | ||
| std::string toString(const Options& value); | ||
|
|
||
| /// Save the parallel fields | ||
| void saveParallel(Options& opt, const std::string name, const Field3D& tosave); | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| /// Output a stringified \p value to a stream | ||
| /// | ||
| /// This is templated to avoid implict casting: anything is | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |
| } | ||
|
|
||
| TRACE("Field3D: Assignment from Field3D"); | ||
| track(rhs, "operator="); | ||
|
|
||
| // Copy base slice | ||
| Field::operator=(rhs); | ||
|
|
@@ -265,6 +266,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); | ||
|
|
@@ -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()); | ||
|
|
@@ -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. | ||
|
|
@@ -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) { | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||
| tracking->set(outname, change, "tracking"); | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| (*tracking)[outname].setAttributes({ | ||
| {"operation", operation}, | ||
| {"rhs.name", "BR"}, | ||
dschwoerer marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }); | ||
| return &(*tracking)[outname]; | ||
| } | ||
| return nullptr; | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.