-
Notifications
You must be signed in to change notification settings - Fork 248
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] Extract B matrix calculations #12337
Conversation
… made `CalculateBMatrix` const and used this construction in the `CalculateAll` of the UPwSmallStrain element
… we now calculate the b matrices up front and set the variables using that list
…'s only used in CalculateBMatrices
…since it's only used in CalculateBMatrices" This reverts commit 6d983ea.
…e strains, the mass matrix and water pressure based outputs
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Richard, a very dedicated PR that is very easy to review. Just a small comment on possible improvement.
applications/GeoMechanicsApplication/custom_elements/small_strain_U_Pw_diff_order_element.cpp
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a very clear and clean PR. In essence, you apply the same transformation in several locations. I have checked the usage of ElementVariables::B
and as far as I could see you have modified the correct usages (i.e. where this member wasn't used in the first place, no additional changes are required).
{ | ||
rB = this->GetStressStatePolicy().CalculateBMatrix(GradNpT, Np, this->GetGeometry()); | ||
} | ||
|
||
template <unsigned int TDim, unsigned int TNumNodes> | ||
std::vector<Matrix> UPwSmallStrainElement<TDim, TNumNodes>::CalculateBMatrices( | ||
const Matrix& NContainer, const GeometryType::ShapeFunctionsGradientsType& DN_DXContainer) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to follow the Kratos Style Guide:
const Matrix& NContainer, const GeometryType::ShapeFunctionsGradientsType& DN_DXContainer) const | |
const Matrix& rNContainer, const GeometryType::ShapeFunctionsGradientsType& rDN_DXContainer) const |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Matrix b_matrix; | ||
this->CalculateBMatrix(b_matrix, DN_DXContainer[GPoint], row(NContainer, GPoint)); | ||
result.push_back(b_matrix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would suggest to let CalculateBMatrix
return a Matrix
object (rather than void
). In that case, you can simplify the code as follows:
Matrix b_matrix; | |
this->CalculateBMatrix(b_matrix, DN_DXContainer[GPoint], row(NContainer, GPoint)); | |
result.push_back(b_matrix); | |
result.push_back(this->CalculateBMatrix(DN_DXContainer[GPoint], row(NContainer, GPoint))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done (every reviewer suggested the same, such harmony 😄 )
void CalculateBMatrix(Matrix& rB, const Matrix& GradNpT, const Vector& Np) const; | ||
std::vector<Matrix> CalculateBMatrices(const Matrix& NContainer, | ||
const GeometryType::ShapeFunctionsGradientsType& DN_DXContainer) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The ordering of the function parameters for the shape functions (Np
and NContainer
) and the gradients of the shape functions (GradNpT
and DN_DXContainer
) is not consistent between CalculateBMatrix
and CalculateBMatrices
. Perhaps we should stick to the ordering adopted by CalculateBMatrix
, since that order is consistent with the one adopted by StressStatePolicy::CalculateBMatrix
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point, done!
Matrix b_matrix; | ||
this->CalculateBMatrix(b_matrix, DN_DXContainer[GPoint], row(NContainer, GPoint)); | ||
result.push_back(b_matrix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to point out that here we may consider similar changes as proposed before:
Matrix b_matrix; | |
this->CalculateBMatrix(b_matrix, DN_DXContainer[GPoint], row(NContainer, GPoint)); | |
result.push_back(b_matrix); | |
result.push_back(this->CalculateBMatrix(DN_DXContainer[GPoint], row(NContainer, GPoint))); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
@@ -287,7 +287,9 @@ class KRATOS_API(GEO_MECHANICS_APPLICATION) SmallStrainUPwDiffOrderElement : pub | |||
double CalculateBulkModulus(const Matrix& ConstitutiveMatrix) const; | |||
double CalculateBiotCoefficient(const ElementVariables& rVariables, const bool& hasBiotCoefficient) const; | |||
|
|||
virtual void CalculateBMatrix(Matrix& rB, const Matrix& DNu_DX, const Vector& Np); | |||
virtual void CalculateBMatrix(Matrix& rB, const Matrix& DNu_DX, const Vector& Np) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here, the virtual
keyword is redundant, since this member is never overridden.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I only removed it in upw small strain, forgot in diff order, good catch!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi Richard,
Tried to go trough the CalculateKinematics places where B is not used afterwards. Could not find mistakes there. See my other remarks. Keeping similar function setup with return values and arguments in the same order would help me read faster.
For the b_matrices you correctly adopt snake_case, but the argument names for & lack the r's and ofter p is used where I see no reason for the p. Obviouly these are existing anomalies that only happen to coincide with the lines you had to adapt.
Regards, Wijtze Pieter
void CalculateBMatrix(Matrix& rB, const Matrix& GradNpT, const Vector& Np) const; | ||
std::vector<Matrix> CalculateBMatrices(const Matrix& NContainer, | ||
const GeometryType::ShapeFunctionsGradientsType& DN_DXContainer) const; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably only confusion for me:
the stress state policies have a CalculateBMatrix which return a matrix and take the 3 arguments rGradNpT, rNp and rGeometry
the elements have a CalculateBMatrix with return type void and 3 arguments rB, GradNpT and Np
and a CalculateBMatrices which returns a std::vector<Matrix> and 2 arguments NContainer and DN_DXContainer
The naming and order of the arguments is confusing for me. Please have the same order for GradNpT and Np
GradNpT and the elements of DN_DXContainer are the same thing.
The p I don't understand, we look at the N for displacement here, so Nu or just N
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
Matrix b_matrix; | ||
this->CalculateBMatrix(b_matrix, DN_DXContainer[GPoint], row(NContainer, GPoint)); | ||
result.push_back(b_matrix); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With b_matrix as return value this becomes more readable for me:
result.push_back(this->CalculateBMatrix(DN_DXContainer[GPoint], row(NContainer, GPoint));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done!
…nstead of using input args
…`CalculateBMatrix` function
…form kratos style guide
…-matrix-calculations
…ck into this branch
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The remarks about redundant or now incorrect comments can be made far more often than I did here. I think that changing that can be taken up in next PR's, because we are continuing to unravel these functionalities.
@@ -91,6 +92,7 @@ void UPwUpdatedLagrangianElement<TDim, TNumNodes>::CalculateAll(MatrixType& rLef | |||
for (IndexType GPoint = 0; GPoint < IntegrationPoints.size(); ++GPoint) { | |||
// Compute element kinematics B, F, GradNpT ... |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now this really has become a "rotting" comment.
@@ -149,10 +149,13 @@ void UPwSmallStrainElement<TDim, TNumNodes>::InitializeSolutionStep(const Proces | |||
// Create general parameters of retention law | |||
RetentionLaw::Parameters RetentionParameters(this->GetProperties(), rCurrentProcessInfo); | |||
|
|||
const auto b_matrices = CalculateBMatrices(Variables.DN_DXContainer, Variables.NContainer); | |||
|
|||
// Loop over integration points | |||
for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) { | |||
// Compute Np, GradNpT, B and StrainVector |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe remove this comment, B is not computed here anymore.
@@ -253,9 +256,12 @@ void UPwSmallStrainElement<TDim, TNumNodes>::InitializeNonLinearIteration(const | |||
ElementVariables Variables; | |||
this->InitializeElementVariables(Variables, rCurrentProcessInfo); | |||
|
|||
const auto b_matrices = CalculateBMatrices(Variables.DN_DXContainer, Variables.NContainer); | |||
|
|||
// Loop over integration points |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what else? Needless repeated comment on integration point loops.
@@ -17,11 +17,11 @@ | |||
namespace Kratos | |||
{ | |||
|
|||
Matrix AxisymmetricStressState::CalculateBMatrix(const Matrix& rGradNpT, | |||
const Vector& rNp, | |||
Matrix AxisymmetricStressState::CalculateBMatrix(const Matrix& rDN_DX, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is better, I did not understand the p in the old name GradNpT.
An alternative would have been GradNT ( I guess the T is for transposed ) DX also refers to a spatial gradient.
@@ -1666,9 +1683,6 @@ void SmallStrainUPwDiffOrderElement::CalculateKinematics(ElementVariables& rVari | |||
noalias(rVariables.DNu_DX) = rVariables.DNu_DXContainer[GPoint]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This now seems redundant. It was input for the B computation, which now already has taken place.
@@ -157,7 +157,7 @@ void SteadyStatePwElement<TDim, TNumNodes>::CalculateAll(MatrixType& rLef | |||
|
|||
const auto integration_coefficients = | |||
this->CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJContainer); | |||
|
|||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unintended addition of spaces?
📝 Description
In this PR we extract the calculation of the b-matrices for all integration points. This is done by: