-
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 30 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,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 | ||
|
||
|
@@ -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}; | ||
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 | ||||
---|---|---|---|---|---|---|
|
@@ -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); | ||||||
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: parameter 'name' is const-qualified in the function declaration; const-qualification of parameters only has an effect in function definitions [readability-avoid-const-params-in-decls]
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. Could this be a method rather than a free function? Then it can be called like 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 do not think that works, as we assign to |
||||||
|
||||||
/// 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
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.
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