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] Clean up strategies #12792

Merged
merged 9 commits into from
Oct 28, 2024

Conversation

avdg81
Copy link
Contributor

@avdg81 avdg81 commented Oct 25, 2024

📝 Description

Cleaned up the strategies that are offered by the GeoMechanicsApplication.

🆕 Changelog

Changes include:

  • Removed unused function parameters (all related to linear solvers) from the constructors of the strategies. The base class of all our strategies (GeoMechanicsNewtonRaphsonStrategy) used to receive a pointer to a linear solver, but that parameter was never used. Consequently, there is no point in supplying one. In fact, requesting one but not using it is very confusing. The constructors of the derived classes simply forwarded the linear solver pointers to the base class constructor. Also there, the corresponding parameters have been removed from the constructors.
  • Moved a few member functions and data members that were defined in class GeoMechanicsNewtonRaphsonStrategy to one of the derived classes (GeoMechanicsRammArcLengthStrategy), since only there they were actually being used. As a result, the moved members could be made private rather than protected.
  • Replaced a local implementation of the L2 norm calculation by calling Boost's norm_2 function. There is one thing we need to keep in mind here: the local implementation used to be done in parallel (although it was using deprecated functionality to achieve that). In other words, there might be a performance impact here. The changes made will probably also fix three code smells found by SonarQube.

@avdg81 avdg81 added Cleanup GeoMechanics Issues related to the GeoMechanicsApplication labels Oct 25, 2024
@avdg81 avdg81 requested review from rfaasse and WPK4FEM October 25, 2024 14:55
@avdg81 avdg81 self-assigned this Oct 25, 2024
The override just called the base class's version, which yields the same behavior as not providing an override.
The moved member function was used by one derived class only. The access specifier has been changed from `protected` to `private`.
The moved data members were used by one derived class only. The access specifier has been changed from `protected` to `private`.
Also reformatted the code with clang-format.
Also, "unnamed" a few other function parameters that are no longer used.
@avdg81 avdg81 force-pushed the geo/clean-up-newton-raphson-strategy branch from 54a4489 to f0685a5 Compare October 28, 2024 08:26
These changes address three code smells that were found by SonarQube.
auto get_dof_value = [](const auto& rDof) { return rDof.GetSolutionStepValue(); };
std::transform(std::begin(free_dofs), std::end(free_dofs), free_dof_values.begin(), get_dof_value);

return norm_2(free_dof_values);
Copy link
Contributor

Choose a reason for hiding this comment

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

🎉

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 doing this clean-up, only a few questions, but not blocking (since this is an improvement in any case already)

}

std::vector<ModelPart*> mSubModelPartList; // List of every SubModelPart associated to an external load
std::vector<std::string> mVariableNames; // Name of the nodal variable associated to every SubModelPart
Copy link
Contributor

Choose a reason for hiding this comment

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

Was this used anywhere in the end?

Copy link
Contributor Author

@avdg81 avdg81 Oct 28, 2024

Choose a reason for hiding this comment

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

Yes, I've found that these data members are being used. See member function UpdateExternalLoads, which uses the lists of model part pointers and variable names. Unfortunately, there are no tests that cover this code :-(

Comment on lines +546 to +556
static double CalculateReferenceDofsNorm(DofsArrayType& rDofSet)
{
auto is_free_dof = [](const auto& rDof) { return rDof.IsFree(); };
auto free_dofs = rDofSet | boost::adaptors::filtered(is_free_dof);

auto free_dof_values = Vector{boost::size(free_dofs)};
auto get_dof_value = [](const auto& rDof) { return rDof.GetSolutionStepValue(); };
std::transform(std::begin(free_dofs), std::end(free_dofs), free_dof_values.begin(), get_dof_value);

return norm_2(free_dof_values);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

At some point, we could move this to a utility (it doesn't seem to be very arc length specific, but I might be wrong)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

You are correct that this calculation of the L2 norm of the (free) degrees of freedom is not specific for arc-length control. So it could be extracted to a more generic utility function and then be called from here. However, as we discussed, if we'd like to do that, let's do it in a separate PR.

@avdg81 avdg81 merged commit 3ecd8ee into master Oct 28, 2024
11 checks passed
@avdg81 avdg81 deleted the geo/clean-up-newton-raphson-strategy branch October 28, 2024 16:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Cleanup GeoMechanics Issues related to the GeoMechanicsApplication
Development

Successfully merging this pull request may close these issues.

2 participants