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] Extract pre-calculated lists for strain vectors and (determinants of) deformation gradients #12363

Merged
merged 27 commits into from
May 13, 2024

Conversation

rfaasse
Copy link
Contributor

@rfaasse rfaasse commented May 8, 2024

📝 Description
This PR starts to extract element-wide lists (all integration point at the same time) for:

  • The deformation gradients
  • The determinants of the integration coefficients
  • The strain vectors

Although we add some duplication, which later we would like to remove when compressing diff-order/normal upw element into one, we start seeing here already we can start removing quite a bit of code because of this restructuring.

rfaasse added 16 commits May 7, 2024 11:11
…Strain` to return a vector and takes relevant inputs instead of variables
…rn a vector and takes relevant inputs instead of variables
…) to return a vector instead of using the ElementVariables
…rmation gradient, instead of getting it from ElementVariables
…deformation gradient, instead of getting it from ElementVariables
…trix, displacements and UseHenckyStrainFlag instead of using ElementVariables
…b matrix, displacements and UseHenckyStrainFlag instead of using ElementVariables
…element, and used it to calculate lists up front
Base automatically changed from geo/12319-extract-strain-vector-calculations to master May 10, 2024 11:30
@rfaasse rfaasse changed the title Geo/12319 extract strain and f lists [GeoMechanicsApplication] Extract pre-calculated lists for strain vectors and (determinants of) deformation gradients May 13, 2024
@rfaasse rfaasse marked this pull request as ready for review May 13, 2024 09:13
@rfaasse rfaasse requested review from avdg81, WPK4FEM and markelov208 May 13, 2024 09:13
Copy link
Contributor

@markelov208 markelov208 left a comment

Choose a reason for hiding this comment

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

Richard, thank you for the next step. The code is getting to be shorter and clear. My comments about movement of some functions to utilities. After changes made they look very similar for different elements.

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.

Hi Richard,
After you explained the capture lists to me, most is clear.
Now that this has taken the strain, F and detF computations out of the integration point loops, I expect that Variables.B can be removed. Variables.B only has a purpose for the strain computation and that has be handled already.
Regards, Wijtze Pieter

const auto determinants_of_deformation_gradients =
CalculateDeterminantsOfDeformationGradients(deformation_gradients);
const auto strain_vectors = CalculateStrains(
deformation_gradients, b_matrices, Variables.DisplacementVector, Variables.UseHenckyStrain);

// Loop over integration points
for (unsigned int GPoint = 0; GPoint < NumGPoints; ++GPoint) {
this->CalculateKinematics(Variables, GPoint);
Variables.B = b_matrices[GPoint];

// Compute infinitesimal strain
Copy link
Contributor

Choose a reason for hiding this comment

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

These comments are now not true anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, I could still remove them in this PR, or wait for the next, what do you prefer?

@@ -1568,6 +1571,22 @@ Vector UPwSmallStrainElement<TDim, TNumNodes>::CalculateStrain(const Matrix& rDe
: this->CalculateCauchyStrain(rB, rDisplacements);
}

template <unsigned int TDim, unsigned int TNumNodes>
std::vector<Vector> UPwSmallStrainElement<TDim, TNumNodes>::CalculateStrains(const std::vector<Matrix>& rDeformationGradients,
Copy link
Contributor

Choose a reason for hiding this comment

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

I wondered if only the s of strains would be enough to indicate that this is for all integration points ( e.g. for all components. ) CalculateStrain already is for all components in 1 integration point.

I don't know a better name, they soon become very long.

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'm also not too sure about better naming unfortunately

Copy link
Contributor Author

Choose a reason for hiding this comment

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

On second thought, would CalculateStrainVectors be a more suitable name?

@@ -547,11 +556,9 @@ void SmallStrainUPwDiffOrderElement::FinalizeSolutionStep(const ProcessInfo& rCu
Variables.B = b_matrices[GPoint];
Copy link
Contributor

Choose a reason for hiding this comment

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

Now that strains are computed outside the loop, I expect that the B matrices can be removed from Variables already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Just to document what we already discussed: it is still used in the calculation of the stiffness matrix, so it unfortunately cannot be removed yet:

template <unsigned int TDim, unsigned int TNumNodes>
void UPwSmallStrainElement<TDim, TNumNodes>::CalculateAndAddStiffnessMatrix(MatrixType& rLeftHandSideMatrix,
                                                                            ElementVariables& rVariables)
{
    KRATOS_TRY

    noalias(rVariables.UVoigtMatrix) = prod(trans(rVariables.B), rVariables.ConstitutiveMatrix);
    noalias(rVariables.UUMatrix) = prod(rVariables.UVoigtMatrix, rVariables.B) * rVariables.IntegrationCoefficient;

    // Distribute stiffness block matrix into the elemental matrix
    GeoElementUtilities::AssembleUUBlockMatrix(rLeftHandSideMatrix, rVariables.UUMatrix);

    KRATOS_CATCH("")
}

@rfaasse rfaasse self-assigned this May 13, 2024
@rfaasse rfaasse added GeoMechanics Issues related to the GeoMechanicsApplication Refactor When code is moved or rewrote keeping the same behavior labels May 13, 2024
@rfaasse rfaasse requested review from markelov208 and WPK4FEM May 13, 2024 13:57
Copy link
Contributor

@markelov208 markelov208 left a comment

Choose a reason for hiding this comment

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

Richard, thank you for the quick changes.

Variables.StrainVector = this->CalculateStrain(
Variables.F, Variables.B, Variables.DisplacementVector, Variables.UseHenckyStrain);
permeability_update_factors.push_back(this->CalculatePermeabilityUpdateFactor(Variables.StrainVector));
permeability_update_factors.push_back(this->CalculatePermeabilityUpdateFactor(strain_vectors[GPoint]));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, this could be a transform now

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.

Good to go.

Copy link
Contributor

@avdg81 avdg81 left a comment

Choose a reason for hiding this comment

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

This looks like a nice improvement to me. I have no further suggestions.

Comment on lines +797 to +799
const auto deformation_gradients = CalculateDeformationGradients();
rOutput = CalculateStrains(deformation_gradients, b_matrices, Variables.DisplacementVector,
Variables.UseHenckyStrain);
Copy link
Contributor

Choose a reason for hiding this comment

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

Very nice cleanup :-)

@rfaasse rfaasse enabled auto-merge (squash) May 13, 2024 15:14
@rfaasse rfaasse merged commit c2a05d7 into master May 13, 2024
11 checks passed
@rfaasse rfaasse deleted the geo/12319-extract-strain-and-F-lists branch May 13, 2024 15:44
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 Refactor When code is moved or rewrote keeping the same behavior
Projects
None yet
4 participants