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

[StructuralMechanicsApplication] Add PK2_STRESS_VECTOR in LinearTrussElement2D #12915

Merged
merged 9 commits into from
Dec 13, 2024

Conversation

markelov208
Copy link
Contributor

@markelov208 markelov208 commented Dec 9, 2024

📝 Description
A brief description of the PR.

  • Added CalculateOnIntegrationPoints function with PK2_STRESS_VECTOR and TRUSS_PRESTRESS_PK2 for LinearTrussElement<3D/2D>
  • added two unit tests for this function (based on TrussElementLinear3D2N_CalculatesPK2Stress)

@markelov208 markelov208 self-assigned this Dec 9, 2024
@markelov208 markelov208 requested a review from a team as a code owner December 9, 2024 11:37
@markelov208 markelov208 changed the title Geo/12868 pk2 linear truss element2 d [StructuralMechanicsApplication] Add PK2_STRESS_VECTOR in LinearTrussElement2D Dec 9, 2024
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 Gennady,
Thank you for the implementation. On the implementation itself I have no comments, it follows what the element already is doing. Some nagging about following the style.
However, there is 1 thing to be aware of. To create also the 3D variants of this 2 and 3 node element Alejandro has a pull request pending ( #12894 ) that removes the file that you have done the implementation in. It may be wise to wait with your PR until Aljandro has merged and then put your implementation in the new file for both 2 and 3D. That would save doing it again.
Regards, Wijtze Pieter

SystemSizeBoundedArrayType B;

// Loop over the integration points
for (SizeType IP = 0; IP < integration_points.size(); ++IP) {
Copy link
Contributor

Choose a reason for hiding this comment

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

The Kratos style guide ( https://github.com/KratosMultiphysics/Kratos/wiki/Style-Guide ) says lower case with underscores for local variables. Here that would result in:, c, b, integration_point i.s.o. C, B, IP

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thank you for the comment. Fixed names and replaced C/B with longer names.

p_element->CalculateOnIntegrationPoints(PK2_STRESS_VECTOR, stress_vector, r_process_info);
KRATOS_EXPECT_DOUBLE_EQ(expected_stress + pre_stress, stress_vector[0][0]);
}
KRATOS_TEST_CASE_IN_SUITE(LienarTrussElement2D_CalculatesPK2Stress, KratosStructuralMechanicsFastSuite)
Copy link
Contributor

Choose a reason for hiding this comment

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

Lienar --> Linear

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Many thanks. Fixed the typo.

@markelov208
Copy link
Contributor Author

Hi Gennady, Thank you for the implementation. On the implementation itself I have no comments, it follows what the element already is doing. Some nagging about following the style. However, there is 1 thing to be aware of. To create also the 3D variants of this 2 and 3 node element Alejandro has a pull request pending ( #12894 ) that removes the file that you have done the implementation in. It may be wise to wait with your PR until Aljandro has merged and then put your implementation in the new file for both 2 and 3D. That would save doing it again. Regards, Wijtze Pieter

Hi Wijtze-Pieter, thank you for the info. In any case, this PR would be merged only when Alejandro approves it.

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.

Nice addition of PK2 stress to the new element with tests, I've got a few suggestions, but none of them blocking

if (rVariable == PK2_STRESS_VECTOR) {
ConstitutiveLaw::Parameters cl_values(GetGeometry(), GetProperties(), rProcessInfo);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_STRESS , true);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR, true);
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we only need the stress vector in the end, do you know if it's possible to set COMPUTE_CONSTITUTIVE_TENSOR to false?

Copy link
Member

Choose a reason for hiding this comment

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

yes, if the stiffness (E) is not required, you can set this to false

Copy link
Member

Choose a reason for hiding this comment

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

Actually, if I am not wrong, the stress could be retrieved by the CalculateOnIntegrationPoints(AXIAL_FORCE, --, --) and then divided by the GetPRoperties()[CROSS_AREA] right? I mean implementing the new CalculateOnIntegrationPoints(PK2_STRESS) and calling the CalculateOnIntegrationPoints(AXIAL_FORCE, --, --) inside

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Richard, you are absolutely right.
Alejandro, thank you for the info on COMPUTE_CONSTITUTIVE_TENSOR. I also made it false for other CalculateOnIntegrationPoints functions and there are no any failed tests.
You are right it is possible to re-use CalculateOnIntegrationPoints(AXIAL_FORCE,); however, 1) I have added TRUSS_PRESTRESS_PK2, 2) I would like to keep theses functions separately because CalculateOnIntegrationPoints(AXIAL_FORCE,) could be changed in future, for example, PK2 could be replaced with other stress.
Next, Aljandro please could you advice how to get the stress vector for TImoshenko beams? As far as I can see there are two areas, CROSS_AREA and AREA_EFFECTIVE_Y.

Copy link
Member

Choose a reason for hiding this comment

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

The Timoshenko constitutive laws compute the axial force, moment and shear forces. To obtain the stress vector one should compose the bending and axial contributions as the normal stress and the shear stresses with respecto to the shear force and shear area.

The CROSS_AREA is the area of the cross section used in axial loading. The AREA_EFFECTIVE_Y is the reduced shear area for evaluating the shear forces.

Comment on lines 390 to 415
Model current_model;
auto &r_model_part = current_model.CreateModelPart("ModelPart",1);
r_model_part.GetProcessInfo().SetValue(DOMAIN_SIZE, 3);
r_model_part.AddNodalSolutionStepVariable(DISPLACEMENT);

// Set the element properties
auto p_elem_prop = r_model_part.CreateNewProperties(0);
constexpr auto youngs_modulus = 2.0e+06;
p_elem_prop->SetValue(YOUNG_MODULUS, youngs_modulus);
const auto &r_clone_cl = KratosComponents<ConstitutiveLaw>::Get("TrussConstitutiveLaw");
p_elem_prop->SetValue(CONSTITUTIVE_LAW, r_clone_cl.Clone());

// Create the test element
constexpr double directional_length = 2.0;
auto p_node_1 = r_model_part.CreateNewNode(1, 0.0, 0.0, 0.0);
auto p_node_2 = r_model_part.CreateNewNode(2, directional_length, directional_length, directional_length);

AddDisplacementDofsElement(r_model_part);

std::vector<ModelPart::IndexType> element_nodes {1,2};
auto p_element = r_model_part.CreateNewElement("LinearTrussElement2D2N", 1, element_nodes, p_elem_prop);
const auto& r_process_info = r_model_part.GetProcessInfo();
p_element->Initialize(r_process_info); // Initialize the element to initialize the constitutive law

constexpr auto induced_strain = 0.1;
p_element->GetGeometry()[1].FastGetSolutionStepValue(DISPLACEMENT) += ScalarVector(3, induced_strain * directional_length);
Copy link
Contributor

Choose a reason for hiding this comment

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

If I'm correct, the setup of this test is almost identical to the setup of the previous unit test. I'd propose to create a setup function which takes the name of the element as an input (so "LinearTrussElement2D2N" or "TrussLinearElement3D2N"), to avoid some duplication.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It is a very good proposal. Currently, one more test is added. Hopefully, it will be extended for Timoshenko beams.

Comment on lines 658 to 688
ConstitutiveLaw::Parameters cl_values(GetGeometry(), GetProperties(), rProcessInfo);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_STRESS , true);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR, true);

const double length = CalculateLength();

// Let's initialize the cl values
VectorType strain_vector(1), stress_vector(1);
MatrixType constitutive_matrix(1,1);
strain_vector.clear();
cl_values.SetStrainVector(strain_vector);
cl_values.SetStressVector(stress_vector);
cl_values.SetConstitutiveMatrix(constitutive_matrix);
SystemSizeBoundedArrayType nodal_values(SystemSize);
GetNodalValuesVector(nodal_values);

SystemSizeBoundedArrayType dN_dX;

// Loop over the integration points
for (SizeType integration_point = 0; integration_point < integration_points.size(); ++integration_point) {
GetFirstDerivativesShapeFunctionsValues(dN_dX, length, integration_points[integration_point].X());

strain_vector[0] = inner_prod(dN_dX, nodal_values);

mConstitutiveLawVector[integration_point]->CalculateMaterialResponsePK2(cl_values);
auto stress = cl_values.GetStressVector()[0];
if (GetProperties().Has(TRUSS_PRESTRESS_PK2)) {
stress += GetProperties()[TRUSS_PRESTRESS_PK2];
}

rOutput[integration_point] = ScalarVector(1, stress);
Copy link
Contributor

Choose a reason for hiding this comment

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

If this part of code is identical to another part in this class, we could extract a function for the common functionality

Copy link
Contributor Author

Choose a reason for hiding this comment

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

A few lines are extracted as a function.

@AlejandroCornejo
Copy link
Member

HI! I just merged the linear_truss_element generic 2D/3D for 2N and 3N in the other PR. I'll review the changes in this PR soon

@AlejandroCornejo
Copy link
Member

AlejandroCornejo commented Dec 11, 2024

Actually, I believe that these additions should be done to the new linear_truss_element that I just added. Now the element in 2D has been generalized to 3D also. Please move the implementation to the new file.

@@ -644,6 +644,54 @@ void LinearTrussElement2D<TNNodes>::CalculateOnIntegrationPoints(
/***********************************************************************************/
/***********************************************************************************/

template<SizeType TNNodes>
Copy link
Member

Choose a reason for hiding this comment

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

now you'll need anothe template entry

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added

if (rVariable == PK2_STRESS_VECTOR) {
ConstitutiveLaw::Parameters cl_values(GetGeometry(), GetProperties(), rProcessInfo);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_STRESS , true);
cl_values.GetOptions().Set(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR, true);
Copy link
Member

Choose a reason for hiding this comment

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

yes, if the stiffness (E) is not required, you can set this to false

Copy link
Contributor Author

@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.

Hi everybody, thank you very much for the suggestions and info.

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.

Nicely reduced the duplication, thanks for the effort! from my side this is ready to go, but I leave the approval to @AlejandroCornejo / @loumalouomega 👍

@markelov208 markelov208 merged commit 5958552 into master Dec 13, 2024
10 of 11 checks passed
@markelov208 markelov208 deleted the geo/12868-pk2_LinearTrussElement2D branch December 13, 2024 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants