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] Make sure all 'integration scheme related' functions throw an exception #12642

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented Aug 22, 2024

📝 Description
Make sure the integration scheme related functions throw, such that when they are called it is clear that this geometry won't have that functionality.

@rfaasse rfaasse requested a review from avdg81 August 23, 2024 06:56
Comment on lines +357 to +412
KRATOS_TEST_CASE_IN_SUITE(InterfaceGeometry_Throws_WhenCallingFunctionsRelatedToIntegrationPoints,
KratosGeoMechanicsFastSuiteWithoutKernel)
{
auto geometry = CreateThreePlusThreeNodedLineInterfaceGeometry();
Geometry<Node>::JacobiansType dummy_jacobian;
Geometry<Node>::ShapeFunctionsGradientsType dummy_shape_functions_gradients;
Vector dummy_vector;
Matrix dummy_matrix;
IndexType dummy_index = 0;
GeometryData::IntegrationMethod dummy_integration_method = GeometryData::IntegrationMethod::GI_GAUSS_1;
Geometry<Node>::IntegrationPointsArrayType dummy_integration_points;
IntegrationInfo dummy_integration_info(dummy_index, dummy_integration_method);
Geometry<Node>::GeometriesArrayType dummy_geometries;
std::vector<Node::CoordinatesArrayType> dummy_coordinates;
const std::string message =
"This Geometry type does not support functionality related to integration schemes.\n";

KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.Normal(dummy_index), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.Normal(dummy_index, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.UnitNormal(dummy_index), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.UnitNormal(dummy_index, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.Jacobian(dummy_jacobian, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.Jacobian(dummy_jacobian, dummy_integration_method, dummy_matrix), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.Jacobian(dummy_matrix, dummy_index, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.Jacobian(dummy_matrix, dummy_index, dummy_integration_method, dummy_matrix), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.DeterminantOfJacobian(dummy_vector, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.DeterminantOfJacobian(dummy_index, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.InverseOfJacobian(dummy_jacobian, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.InverseOfJacobian(dummy_matrix, dummy_index, dummy_integration_method), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.ShapeFunctionsIntegrationPointsGradients(
dummy_shape_functions_gradients, dummy_integration_method),
message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.ShapeFunctionsIntegrationPointsGradients(
dummy_shape_functions_gradients, dummy_vector, dummy_integration_method),
message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.ShapeFunctionsIntegrationPointsGradients(
dummy_shape_functions_gradients, dummy_vector, dummy_integration_method, dummy_matrix),
message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.CreateIntegrationPoints(dummy_integration_points, dummy_integration_info), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(geometry.GetDefaultIntegrationInfo(), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.CreateQuadraturePointGeometries(dummy_geometries, dummy_index,
dummy_integration_points, dummy_integration_info),
message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.CreateQuadraturePointGeometries(dummy_geometries, dummy_index, dummy_integration_info), message)
KRATOS_EXPECT_EXCEPTION_IS_THROWN(
geometry.GlobalSpaceDerivatives(dummy_coordinates, dummy_index, dummy_index), message)
}
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 was thinking a bit more about this test and I'm actually doubting if we should keep it. It does not test any logic, it just repeats the list of functions that we think should throw. I'm not sure if it's worth the time it takes to set up these kinds of tests. On the other hand, it will flag if someone implements one of the functions at some point, so I'm in two minds.

In general it's good to test for exceptions, but in my opinion that's more in the sense of functions throwing when the input/state is unexpected.

If we would decide these kinds of tests are not worth the time of setting them up, we should remove this particular one in my opinion, since it would encourage making more of them.

@avdg81 I'm curious to hear your thoughts on this

Copy link
Contributor

Choose a reason for hiding this comment

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

If we start from the idea that unit tests can also be used as a form of "living" documentation (i.e. it is always up-to-date since it executes the code under test) then I do see the added value of this test case. Otherwise, the unit tests leave this part of the public API undocumented, forcing the developer to look into the implementation to see what she can expect. So I think I'd still prefer to have the new unit test in place. @WPK4FEM What do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

I would vote for having these tests. Yes they are repetitive of the code as it is now, but they will flag on behavioral changes.

On the setup of the dummy geometry for the unit tests I have a question, but that I will raise in the review.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed these are good points, then I agree they bring enough value for the effort, let's leave the test in 👍

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 Richard,
Thank you for the consistent work. I have compared against the list given by Anne in the issue and against geometry.h. Your implementation consistently overrides the functionality to block.
My remarks are not blocking, only something I'd like to understand better myself.

@rfaasse rfaasse merged commit 85aa661 into master Aug 23, 2024
9 of 11 checks passed
@rfaasse rfaasse deleted the geo/12641-disable-api-related-to-integration-schemes-for-the-new-line-interface-geometry branch August 23, 2024 13:59
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] Disable API related to integration schemes for the new line interface geometry
3 participants