-
Notifications
You must be signed in to change notification settings - Fork 90
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
Refactor FieldData
to be base class of Field
#2313
Conversation
The Coordinates' metric elements can hold shared_ptrs that result in a cyclic dependency between the Fields and the Coordinates, with the result that some unit tests have memory leaks. One place the issue can arise is when multiplying fields by metric elements with `CHECK > 0`. Then, `ASSERT1_FIELDS_COMPATIBLE` checks that both fields share a `Coordinates` -- but this has the side effect of initialising the `shared_ptr` in the metric elements. This means that when the `Mesh` gets destroyed, the `coords_map` starts to destroy its contents, but because the `Coordinates` metric elements members have references to the `Coordinates`, the `Coordinates` in `coords_map` doesn't get destroyed. The end result is that the `Coordinates` gets leaked. The fix here is to use a `weak_ptr` in `Field`. This only gets a reference to the `Coordinates` when needed.
This removes the double-inheritance from `Field2D` and `Field3D`, as well as making `FieldPerp` a subclass of `FieldData`
* fix-field-coords-leak: Fix memory leak of Coordinates in unit tests
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.
clang-tidy made some suggestions
Boundary operators should only be copied in copy construction
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.
clang-tidy made some suggestions
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.
Nice! Thanks @ZedThree
And braces around if-statement body
@bendudson I just fixed the few clang-tidy warnings, please could you re-approve? |
The reason for doing all of this was originally to be able to remove uses of
bout::global::mesh
fromFieldData
, so that I could add the fix for the case-sensitiveOptions
for ignoring the boundary region inputs without adding more uses of the global mesh. There were a few other plus points to doing this, namely removing the double-inheritance fromField2/3D
, and tidying up the code a bit. It has turned out to be a bit of a bigger effort than I had anticipated/hoped for!Make
FieldData
the base class ofField
, and move some members forField
intoFieldData
. This does a few things:Field2D
andField3D
FieldPerp
now also ultimately inherits fromFieldData
, where it previously was onlyField
Mesh
,Coordinates
, andCELL_LOC
members fromField
toFieldData
Vector2/3D
now havegetMesh()
andgetCoordinates()
methods, which means we don't need to do the hackyv.x.getMesh()
etc.Field::copyFieldMembers
with more idiomaticField::operator=(rhs)
calls in the derived classes, and makes sure the copy-constructor methods delegate to theField
constructorFieldData
membersprivate
rather thanprotected
protected
members are bad now! They make refactoring that much more awkwardfieldmesh
is stillprotected
because it's used in a lot of places. I should probably also bite the bullet and make thisprivate
tooFieldData
, and the unused experimentalFieldVisitor
bout::globals::mesh
fromFieldData
Also includes #2306 so that I didn't have to deal with the conflicts separately.
If we were to go further here, I think we could do some or all of the following:
FieldData::applyBoundary(bool)
have a default implementation -- it appears to be basically the same between all the implementationsField
toScalarField
and add aVectorField
base class to remove duplicated code from the vector classesderiv
) into one of the base-classes and make it aunique_ptr
-- or even just a value?