-
Notifications
You must be signed in to change notification settings - Fork 95
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
Pvcode + Cvode improvements #2889
base: next
Are you sure you want to change the base?
Changes from 16 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
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 |
---|---|---|
|
@@ -295,6 +295,10 @@ 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); | ||
|
||
///////////////////////////////////////////////////////// | ||
// Data access | ||
|
||
|
@@ -514,6 +518,13 @@ private: | |
|
||
/// RegionID over which the field is valid | ||
std::optional<size_t> regionID; | ||
|
||
int tracking_state{0}; | ||
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. What is this for? |
||
Options* tracking{nullptr}; | ||
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 don't like storing raw pointers. Probably this makes most sense as |
||
std::string selfname; | ||
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 |
||
template <class T> | ||
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 know we only provide implementations for some Actually, does this even need to be a template? Could just take |
||
Options* track(const T& change, std::string operation); | ||
Options* track(const BoutReal& change, std::string operation); | ||
Comment on lines
+535
to
+536
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. The return value seems to never be used -- just return |
||
}; | ||
|
||
// Non-member overloaded operators | ||
|
Original file line number | Diff line number | Diff line change | ||||||||
---|---|---|---|---|---|---|---|---|---|---|
|
@@ -243,6 +243,7 @@ Field3D& Field3D::operator=(const Field3D& rhs) { | |||||||||
} | ||||||||||
|
||||||||||
TRACE("Field3D: Assignment from Field3D"); | ||||||||||
track(rhs, "operator="); | ||||||||||
|
||||||||||
// Copy base slice | ||||||||||
Field::operator=(rhs); | ||||||||||
|
@@ -263,6 +264,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
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); | ||||||||||
|
@@ -283,6 +285,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()); | ||||||||||
|
@@ -327,6 +330,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. | ||||||||||
|
@@ -831,3 +835,43 @@ 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"); | ||||||||||
(*tracking)[outname].setAttributes({ | ||||||||||
{"operation", operation}, | ||||||||||
#if BOUT_USE_TRACK | ||||||||||
{"rhs.name", change.name}, | ||||||||||
#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.
Show resolved
Hide resolved
dschwoerer marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||
const std::string outname{fmt::format("track_{:s}_{:d}", selfname, tracking_state++)}; | ||||||||||
tracking->set(outname, change, "tracking"); | ||||||||||
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. warning: implicit conversion 'Options *' -> bool [readability-implicit-bool-conversion]
Suggested change
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. warning: implicit conversion 'int' -> bool [readability-implicit-bool-conversion]
Suggested change
|
||||||||||
(*tracking)[outname].setAttributes({ | ||||||||||
{"operation", operation}, | ||||||||||
{"rhs.name", "BR"}, | ||||||||||
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.
Suggested change
|
||||||||||
}); | ||||||||||
return &(*tracking)[outname]; | ||||||||||
} | ||||||||||
return nullptr; | ||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think most other setters like this are member functions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make this a member function, make it virtual:
field.hxx:
field2d.hxx:
Formatting will have to be done at the calling site, but I think that's fine