Skip to content
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] Re-enable settlement test using the C++ route #12877

Merged
merged 30 commits into from
Nov 28, 2024

Conversation

avdg81
Copy link
Contributor

@avdg81 avdg81 commented Nov 27, 2024

📝 Description

Converted a disabled C++ unit test to a Python test. It shouldn't be a C++ unit test, since it tests a complete workflow, not just a single component. The new Python test covers the so-called "C++ route" of the settlement workflow. In other words, it uses the exact same entry point into the code as D-GeoSettlement does.

Since the KratosGeoSettlement class owns a local KratosGeoMechanicsApplication instance, running this new test will deregister all GeoMechanicsApplication components (e.g. geo elements) when that object is destroyed. To avoid that any subsequent tests start failing, we need to reload the relevant Kratos applications at the end of the new test (in its tearDown method).

With these changes, there are now two Python tests that simulate the same problem (a settlement problem), but using different entry points in our code (i.e. the "C++ route" and the "Python route"). Both ways should yield the same results. That is asserted by these tests.

The test setup creates a clean test directory that contains copies of the Kratos input files.
The new names now clearly indicate that the test covers the Python route.
C++ classes `CustomWorkflowFactory` and `KratosGeoSettlement` are now accessible from Python code.
This new class is intended to be used by the test case for the Python route as well as the one for the C++ route. It will keep common functionality.
One attribute keeps the number of stages to be analyzed, the other the names of the project parameters files.
- Make sure that the heap-allocated settlement API object is properly freed when the test has finished.
- Make sure that the GeoMechanicsApplication has been imported prior to running the Python route of the settlement analysis.
- The C++ route needs to be tested more thoroughly.
These are currently only being used by the test case for the Python route.
This method is now also used by the test case for the C++ route.
@avdg81 avdg81 added the GeoMechanics Issues related to the GeoMechanicsApplication label Nov 27, 2024
@avdg81 avdg81 self-assigned this Nov 27, 2024
@avdg81 avdg81 linked an issue Nov 27, 2024 that may be closed by this pull request
@@ -15,6 +15,7 @@
#define KRATOS_ADD_UTILITIES_TO_PYTHON_H_INCLUDED

// System includes
#include <pybind11/functional.h>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For those interested, this include is needed such that python (lambda) functions can be converted to C++ ones (since we pass functions to the exported RunStage function)

rfaasse
rfaasse previously approved these changes Nov 27, 2024
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.

Very nice we finally have the C++ test running in our pipelines, thanks for getting this done (even though there were quite specific issues on the way). I really like the table-based way of comparing the results! I don't have any blocking comments, just a few questions/minor suggestions

Copy link
Contributor

@markelov208 markelov208 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi Anne, thank you for the clear and well understandable code. I am still new, so I consulted Copilot. ;) Its conclusion is 'Overall, the code appears to be safe and follows good practices for unit testing in Python.'

WPK4FEM
WPK4FEM previously approved these changes Nov 28, 2024
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.

Dear Anne,
I don't have comments here that others haven't already raised ( or not even those ). It remains scary to me that a single test changes its environment and has to restore the environment. However that is in a place we do not directly control and you have documented what and why.
Nothing further, I'm happy that now this test will be executed regularly.
Wijtze Pieter

- Renamed a function object.
- Clarified a comment.
- Removed an unnecessary slicing operation
- Used a better way to remove the previous test directory when the test is set up
@avdg81 avdg81 dismissed stale reviews from WPK4FEM and rfaasse via b981d8f November 28, 2024 08:56
@avdg81
Copy link
Contributor Author

avdg81 commented Nov 28, 2024

Dear Anne, I don't have comments here that others haven't already raised ( or not even those ). It remains scary to me that a single test changes its environment and has to restore the environment. However that is in a place we do not directly control and you have documented what and why. Nothing further, I'm happy that now this test will be executed regularly. Wijtze Pieter

Thank you for the review.

@avdg81 avdg81 enabled auto-merge (squash) November 28, 2024 09:58
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.

Thanks for processing the changes, it's good to go!

@avdg81 avdg81 merged commit 74d5f33 into master Nov 28, 2024
10 of 11 checks passed
@avdg81 avdg81 deleted the geo/12865-re-enable-cpp-settlement-test branch November 28, 2024 14:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
GeoMechanics Issues related to the GeoMechanicsApplication
Development

Successfully merging this pull request may close these issues.

[GeoMechanicsApplication] Re-enable the C++ settlement test
4 participants