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] Fixed several code smells #12182

Merged
merged 3 commits into from
Mar 14, 2024

Conversation

avdg81
Copy link
Contributor

@avdg81 avdg81 commented Mar 14, 2024

📝 Description
Last night SonarQube detected a few "new" code smells, after merging the branch which reordered the degrees of freedom of the non-diff U-Pw elements. Those are addressed by this PR. In addition, a few more code smells (low hanging fruit) were fixed.

- Rephrased a comment to avoid it being detected as commented out code.
- Don't declare multiple variables (of the same type) using a single
  statement.
- Avoid loss of precision due to explicit (mismatching) type names.
- Renamed a few local variables to adhere to the Kratos Style Guide.
@avdg81 avdg81 added the GeoMechanics Issues related to the GeoMechanicsApplication label Mar 14, 2024
@avdg81 avdg81 requested a review from rfaasse March 14, 2024 08:37
@avdg81 avdg81 self-assigned this Mar 14, 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.

Thanks for making these changes, got 2 comments, but non-blocking (merging this will improve the code anyway)

rValues.resize(IntegrationPointsNumber);
}
for (unsigned int i = 0; i < IntegrationPointsNumber; ++i) {
rValues.resize(number_of_integration_points);
Copy link
Contributor

Choose a reason for hiding this comment

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

Just out of curiosity, do you know if the resize checks if it's necessary to do it? (In any case I don't think it really improves performance if we manually check like we did before, but I don't know enough about boost::ublas)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

First of all, note that rValues has type std::vector<int>&, which means that we need to refer to the STL documentation. There it is says:

Resizes the container to contain count elements, does nothing if count == size().

In other words, the caller doesn't need to explicitly check the container's size. Calling resize on a std::vector that already has the desired size, has no effect.

Copy link
Contributor

Choose a reason for hiding this comment

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

Perfect, thanks!

}
for (unsigned int i = 0; i < IntegrationPointsNumber; ++i) {
rValues.resize(number_of_integration_points);
for (auto i = SizeType{0}; i < number_of_integration_points; ++i) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Could be a std::transform 😄 , but leave it up to you if you want to do it, or just merge these improvements (since we're going to tackle the rest later anyway)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, in this case that is unfortunately not so clean, since the value we're trying to retrieve is also returned through the parameter list. Bleeeh! (In addition to returning the value through the function's return value.) Since inside the lambda expression (which you need to pass to std::transform) you don't have access to the object where the transformed value will be stored, it means that you would need to create a dummy variable, just in order to call GetValue. In my opinion, that is not a clean solution (since you probably need a comment to explain what is happening there). So I'd rather leave it the way it is now. I would be in favor of changing it to std::transform if the function signature of GetValue would be improved (i.e. don't return the value through the parameter list, but only through its return value).

Copy link
Contributor

Choose a reason for hiding this comment

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

Yep, I fell again for that one. I'll just try to keep in mind to check twice before making any suggestion which involves the GetValue function.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No worries :-)

@avdg81 avdg81 merged commit 5778b80 into master Mar 14, 2024
15 of 16 checks passed
@avdg81 avdg81 deleted the geo/fix-some-code-smells branch March 14, 2024 12:29
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants