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] Unit tests for TransientPwElement #13012

Merged
merged 24 commits into from
Jan 20, 2025

Conversation

markelov208
Copy link
Contributor

@markelov208 markelov208 commented Jan 16, 2025

📝 Description
A brief description of the PR.

Unit tests have been created for the following TransientPwElement functions

  1. Create
  2. Initialize
  3. Check
  4. InitializeSolutionStep
  5. InitializeNonLinearIteration
  6. FinalizeNonLinearIteration
  7. FinalizeSolutionStep
  8. three CalculateOnIntegrationPoints
    Two unit tests (2D and 3D elements) call CalculateLocalSystem that calls
  9. CalculateAll
  10. InitializeElementVariables
  11. CalculateAndAddLHS
  12. CalculateAndAddCompressibilityMatrix
  13. CalculateAndAddRHS
  14. CalculateAndAddPermeabilityFlow
  15. CalculateAndAddFluidBodyFlow
  16. CalculateAndAddCompressibilityFlow
  17. CalculateKinematics

An extra unit test is created for functions that return zero values:
18. CalculateMassMatrix
19. CalculateDampingMatrix
20. GetValuesVector
21. GetFirstDerivativesVector
22. GetSecondDerivativesVector

The following function have an empty body:
23. InitializeNonLinearIteration
24. FinalizeNonLinearIteration

@markelov208 markelov208 self-assigned this Jan 16, 2025
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.

Thank you for the (tedious) work you put int adding unit tests and increasing our coverage! I just have some ideas for using algorithms, but this is very valuable!

@@ -19,7 +19,6 @@
#include "custom_elements/U_Pw_small_strain_element.hpp"
#include "custom_utilities/element_utilities.hpp"
#include "custom_utilities/stress_strain_utilities.h"
#include "geo_mechanics_application_variables.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Nice catch! Removing these when redundant will speed up compilation times (especially large headers like this one)

Comment on lines 190 to 192
for (auto p_dof : degrees_of_freedom) {
KRATOS_EXPECT_EQ(p_dof->GetVariable(), WATER_PRESSURE);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we could use an algorithm here (might be syntax errors here, but something like this):

Suggested change
for (auto p_dof : degrees_of_freedom) {
KRATOS_EXPECT_EQ(p_dof->GetVariable(), WATER_PRESSURE);
}
KRATOS_EXPECT_TRUE(std::all_of(degrees_of_freedom.begin(), degrees_of_freedom.end(), [](auto pdof){return p_dof->GetVariable() == WATER_PRESSURE;});

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 431 to 433
for (const auto& retention_law : r_retention_law_vector) {
KRATOS_EXPECT_NE(dynamic_cast<SaturatedLaw*>(retention_law.get()), nullptr);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Similar to my other comment, we should be able to use std::none_of here (KRATOS_EXPECT_TRUE(std::none_of... etc)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Comment on lines 449 to 451
for (auto& node : p_element->GetGeometry()) {
KRATOS_EXPECT_EQ(node.FastGetSolutionStepValue(HYDRAULIC_DISCHARGE), 0.0);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

We can use a std::all_of here (and also in some other places in the next tests 👍 )

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

@markelov208 markelov208 requested a review from rfaasse January 17, 2025 12:58
Copy link
Contributor Author

@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 Richard and Wijtze-Pieter, thank you very much for making the code better. I added on more unit test and remove a few lines from the code. Hope the coverage will be higher now.

rfaasse
rfaasse previously approved these changes Jan 20, 2025
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.

Good to go in my opinion, I have one discussion point left (about calling some now empty functions and not asserting anything for the coverage), but I don't think it is blocking

Comment on lines 748 to 750
// Act empty functions to increase the coverage
element.InitializeNonLinearIteration(dummy_process_info);
element.FinalizeNonLinearIteration(dummy_process_info);
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 not sure if we should add these lines, since nothing is asserted (of course right now there's nothing to be asserted). However, if we ever add any functionality to these functions, it seems like they're covered (because of this test), but actually they're only called.

@@ -187,8 +187,8 @@ KRATOS_TEST_CASE_IN_SUITE(CheckFailureEmptyModelPartApplyCPhiReductionProcess, K

KRATOS_TEST_CASE_IN_SUITE(CheckReturnsZeroForValidModelPartApplyCPhiReductionProcess, KratosGeoMechanicsFastSuite)
{
Model model;
auto& r_model_part = PrepareCPhiTestModelPart(model);
Model model;
Copy link
Contributor

Choose a reason for hiding this comment

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

Thanks for formatting these (where I forgot to)!

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.

In my opinion, this is good to go!

@markelov208 markelov208 enabled auto-merge (squash) January 20, 2025 10:06
@markelov208 markelov208 merged commit f6759db into master Jan 20, 2025
11 checks passed
@markelov208 markelov208 deleted the geo/12996-unit-tests-transientPwElement branch January 20, 2025 16:54
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] Assessment of making TransientPwElement inherent from Element
2 participants