-
Notifications
You must be signed in to change notification settings - Fork 251
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
[GeoMechanicsApplication] Added (de)serialization of stress state policies #13163
[GeoMechanicsApplication] Added (de)serialization of stress state policies #13163
Conversation
To make this work, we had to make a minor change to the (de)serialization code of Kratos Core. We've added a compile-time check to see whether a given class is an abstract class. If it is, we shouldn't try to instantiate it. In practice, this is not expected to ever happen.
It was no longer needed, since we make better use of the (de)serialization code offered by the Kratos Core.
…ate policy This required us to register the axisymmetric stress state policy.
… policy This required us to register the interface stress state policy.
This required us to register the 3D stress state policy.
When the data type of the shared pointer is an abstract base class, no longer attempt to instantiate it (which yields a compile-time error). This would only be attempted when the pointer type is `SP_BASE_CLASS_POINTER`. In practice, the underlying type will always be different from that abstract base class, and therefore the pointer type must always be `SP_DERIVED_CLASS_POINTER`, which looks up the underlying concrete type to instantiate.
When the data type of the intrusive pointer is an abstract base class, no longer attempt to instantiate it (which yields a compile-time error). This would only be attempted when the pointer type is `SP_BASE_CLASS_POINTER`. In practice, the underlying type will always be different from that abstract base class, and therefore the pointer type must always be `SP_DERIVED_CLASS_POINTER`, which looks up the underlying concrete type to instantiate. To make this work with the test classes, a few more members had to be defined.
When the data type of the raw owning pointer is an abstract base class, no longer attempt to instantiate it (which yields a compile-time error). This would only be attempted when the pointer type is `SP_BASE_CLASS_POINTER`. In practice, the underlying type will always be different from that abstract base class, and therefore the pointer type must always be `SP_DERIVED_CLASS_POINTER`, which looks up the underlying concrete type to instantiate. Also changed the test suite of the new unit tests to the one without a kernel, since it's not needed.
Moved the new test classes and the scoped registration class to an anonymous namespace. Need to see whether GCC and Clang then build without errors.
Use a `Serializer` instance rather than a `StreamSerializer` instance.
Made the `Serializer` class a `friend` of the derived test class.
The branch that contains the required changes for Kratos Core has been merged into this branch by copying two files from there to here. This should fix the build problems with GCC and Clang.
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 Anne, that is another nice step to have serialization for all classes. I do not have a blocking comment.
void AxisymmetricStressState::save(Serializer&) const | ||
{ | ||
// No data members to be saved (yet) | ||
} | ||
|
||
void AxisymmetricStressState::load(Serializer&) | ||
{ | ||
// No data members to be loaded (yet) | ||
} | ||
|
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.
Currently, there are no any data members. Would it be better to have these functions as protected in the base class?
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 not sure whether I get your point. Both member functions are currently private
. Can you help me to see why you think they should be protected
?
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.
Currently, these empty functions shall be implemented in each child. As far as I understand, if the base class defines them as protected
then all children will use them.
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.
Now I start to see your point. Since the StressStatePolicy
class is intended to provide an interface only and not an implementation, I'd rather keep the save
and load
members pure virtual. In that case, any derived class must implement them, even if they are empty. Since I value this separation of interface and implementation very much, I wouldn't want to change that, unless you have good reasons why we should. Thanks.
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.
Nicely done, I don't have any blocking comments, just a minor question and suggestion.
@@ -61,6 +63,12 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) StressStatePolicy | |||
{ | |||
return Dimension == N_DIM_3D ? GetStressTensorSize3D() : GetStressTensorSize2D(); | |||
} | |||
|
|||
friend class Serializer; | |||
|
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.
Here there are some redundant blank lines
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 catch. Removed the redundant blank lines.
KRATOS_TEST_CASE_IN_SUITE(AxisymmetricStressState_CanBeSavedAndLoadedThroughInterface, KratosGeoMechanicsFastSuiteWithoutKernel) | ||
{ | ||
// Arrange | ||
RegistrationUtilities::RegisterStressStatePolicies(); |
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.
Should we deregister at the end?
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.
Yes, I agree that it's better to keep the scope of the registration as short as possible (i.e. as long as the test runs, but no longer). I have added an RAII class (ScopedSerializerRegistrationOfAllStressStatePolicies
) in test_utilties.h
that takes care of that.
…tion-of-stress-state-policies
- Extended class `RegistrationUtilities` with a member function to deregister all stress state policies. - Added a class for scoped registration of all stress state policies. The unit tests use this class to keep the registration scope as small as possible. - Removed a few redundant blank lines. - Construct `std::string` instances directly, rather than through temporary `const char*` objects.
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 Anne, from my viewpoint it is good to be merged.
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, looks good to go to me!
📝 Description
Stress state policies are typically used and manipulated through a pointer to their abstract base class (i.e.
StressStatePolicy
). This PR adds (de)serialization of the concrete stress state policy classes through a pointer to this interface. Note that it requires some changes in Kratos Core, which have been moved to a separate PR, that needs to be reviewed and approved by CIMNE. The current PR builds on top of that.Once the other PR has been merged withmaster
, we can take out the duplicated changes from this PR.