[GeoMechanicsApplication] Extract B matrix calculations#12337
[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
markelov208
left a comment
There was a problem hiding this comment.
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
avdg81
left a comment
There was a problem hiding this comment.
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).
|
|
||
| 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.
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 |
| 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.
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.
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.
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.
| 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.
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))); |
| 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.
Here, the virtual keyword is redundant, since this member is never overridden.
There was a problem hiding this comment.
Ah, I only removed it in upw small strain, forgot in diff order, good catch!
WPK4FEM
left a comment
There was a problem hiding this comment.
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.
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
| 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.
With b_matrix as return value this becomes more readable for me:
result.push_back(this->CalculateBMatrix(DN_DXContainer[GPoint], row(NContainer, GPoint));
…nstead of using input args
…`CalculateBMatrix` function
…form kratos style guide
…-matrix-calculations
…ck into this branch
WPK4FEM
left a comment
There was a problem hiding this comment.
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.
Now this really has become a "rotting" comment.
|
|
||
| // 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.
Maybe remove this comment, B is not computed here anymore.
|
|
||
| const auto b_matrices = CalculateBMatrices(Variables.DN_DXContainer, Variables.NContainer); | ||
|
|
||
| // Loop over integration points |
There was a problem hiding this comment.
what else? Needless repeated comment on integration point loops.
|
|
||
| Matrix AxisymmetricStressState::CalculateBMatrix(const Matrix& rGradNpT, | ||
| const Vector& rNp, | ||
| Matrix AxisymmetricStressState::CalculateBMatrix(const Matrix& rDN_DX, |
There was a problem hiding this comment.
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.
This now seems redundant. It was input for the B computation, which now already has taken place.
| const auto integration_coefficients = | ||
| this->CalculateIntegrationCoefficients(IntegrationPoints, Variables.detJContainer); | ||
|
|
||
There was a problem hiding this comment.
Unintended addition of spaces?
📝 Description
In this PR we extract the calculation of the b-matrices for all integration points. This is done by: