-
Notifications
You must be signed in to change notification settings - Fork 277
[GeoMechanicsApplication] Move all non-template code to .cpp files and make sure any .h file does not contain any implementations (constitutive) #14053
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
Conversation
rfaasse
left a comment
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.
Hi @markelov208, thanks for the effort for all these PRs! I didn't find any issues, so in principle it's ready to go! The only thing I'd like to wait for is a short discussion about the =default for constructors etc: do we want it in the header or the source?
| explicit GeoIncrementalLinearElasticInterfaceLaw(std::unique_ptr<ConstitutiveLawDimension> pConstitutiveLawDimension); | ||
|
|
||
| ~GeoIncrementalLinearElasticInterfaceLaw() override = default; | ||
| ~GeoIncrementalLinearElasticInterfaceLaw() override; |
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'm starting to think we should keep default constructors/destructors/operations etc (defined with =default) in the header. As we saw previous PR in the following discussion https://stackoverflow.com/questions/62580224/should-functions-declared-with-default-only-go-in-the-header-file, this could be indeed the case (I didn't find anything explicitly in the core guidelines).
At least I have no strong preference anymore towards moving it to the cpp and as we've seen, it results in extra SonarCloud smells. @avdg81 Do you want to weigh in here?
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.
Good question. I'll check some textbooks to see whether there are any recommendations that support what you've found on SO.
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.
ChatGPT gives the following:
Style | Behavior | When to use
~T() = default; in header | Inline, trivial if possible | Most classes, especially POD-like types
T::~T() = default; in .cpp | Out-of-line, user-provided & hides implementation | Pimpl or forward-declared member types
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 be able to move forward with this (and the other PRs), my proposal would be to keep =default in the header when possible (the exception indeed being forward declared variables in unique pointers, which force us to put the destructor in the source file), since I don't see any good reasons not to do it this way (and some reasons to do so).
If we find any strong argument to have default constructors/destructors in the source file of course we can still change it later.
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 moved default destructors and constructors to headers. The only weird thing is that forward declaration of ConstitutiveLawDimension stopped working in GeoIncrementalLinearElasticLaw.
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 be able to move forward with this (and the other PRs), my proposal would be to keep
=defaultin the header when possible (the exception indeed being forward declared variables in unique pointers, which force us to put the destructor in the source file), since I don't see any good reasons not to do it this way (and some reasons to do so).If we find any strong argument to have default constructors/destructors in the source file of course we can still change it later.
Indeed, as I mentioned here, that is the exception. So if there is a forward declared unique pointer (in this case of the ConstitutiveDimension), the destructor needs to be in the .cpp for it to compile
avdg81
left a comment
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.
Hi Gennady,
Thanks a lot for moving member function definitions to the corresponding implementation files. Also thanks for changing a few file extensions from .hpp to .h. Apart from a minor (and non-blocking) suggestion, I feel this PR is good to go.
applications/GeoMechanicsApplication/custom_constitutive/small_strain_umat_2D_interface_law.cpp
Outdated
Show resolved
Hide resolved
WPK4FEM
left a comment
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 me this looks like a consistent batch of changes for the custom_constitutive directory. The pipeline is green and the earlier comments by Anne and Richard were taken up and apparently resolved.
| ~GeoIncrementalLinearElasticLaw() override; | ||
| GeoIncrementalLinearElasticLaw(GeoIncrementalLinearElasticLaw&& rOther) noexcept = default; | ||
| GeoIncrementalLinearElasticLaw& operator=(GeoIncrementalLinearElasticLaw&& rOther) noexcept = default; | ||
| ~GeoIncrementalLinearElasticLaw() override = default; |
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.
As discussed in the other thread, the default destructor in case of forward declaration is the exception, that one needs to be in the cpp file, such that we can forward declare ConstitutiveLawDimension and have the include in the cpp file instead of here in the header (and improve compilation times)
I added comments to explain this in other places (see e.g. https://github.com/KratosMultiphysics/Kratos/blob/master/applications/GeoMechanicsApplication/custom_workflows/time_loop_executor.cpp#L24-L26), but here it might've been unclear, apologies.
So if you could move the relevant default destructors to the cpp (so only the ones that are needed to be able to compile forward declared unique pointer member variables), I think this PR is good to go!
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.
Hi Richard, I move the destructor for GeoIncrementalLinearElasticInterfaceLaw. As well I removed a false forward declaration in small_strain_udsm/umat_law.
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.
Richard, please could you take a look on code smells due to my recent changes? Thank you.
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.
Hi Gennady, yes, having the destructor in the cpp file results in a code smell, but in my opinion it's worth it due to being able to forward declare classes. If you and/or @avdg81 disagree, we could discuss or revert.
avdg81
left a comment
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.
Hi Gennady,
Thanks for processing my review suggestion. I believe we're almost ready to merge this PR. I'm not approving it yet, since one of Richard's suggestions is still open, see this comment.
rfaasse
left a comment
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.
For me this PR is ready to go, thanks for all the effort that went into this!
📝 Description
A brief description of the PR.
Actions have been done for files in
custom_constitutivefolder