Skip to content

Conversation

@markelov208
Copy link
Contributor

@markelov208 markelov208 commented Dec 9, 2025

📝 Description
A brief description of the PR.

Actions have been done for files in custom_constitutive folder

  • moved GetStrainSize function to cpp file
  • renamed hpp to h

Copy link
Contributor

@rfaasse rfaasse left a 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;
Copy link
Contributor

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?

Copy link
Contributor

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.

Copy link
Contributor Author

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

Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

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

Copy link
Contributor

@avdg81 avdg81 left a 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.

WPK4FEM
WPK4FEM previously approved these changes Jan 5, 2026
Copy link
Contributor

@WPK4FEM WPK4FEM left a 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;
Copy link
Contributor

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!

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor

@avdg81 avdg81 left a 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.

Copy link
Contributor

@rfaasse rfaasse left a 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!

@markelov208 markelov208 merged commit 007e25c into master Jan 7, 2026
10 checks passed
@markelov208 markelov208 deleted the geo/14046-move-non-template-code-from-h-to-cpp-constitutive branch January 7, 2026 10:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Move all non-template code to .cpp files and make sure any .h file does not contain any implementations

5 participants