From 264421b77960ac5a840b4eb651e575d62d5664df Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Tue, 31 Mar 2026 12:02:56 +0200 Subject: [PATCH 01/32] initial creation of the base 3d beam element in kratos --- .../custom_elements/base_3d_beam_element.cpp | 25 ++ .../custom_elements/base_3d_beam_element.h | 254 ++++++++++++++++++ 2 files changed, 279 insertions(+) create mode 100644 applications/IgaApplication/custom_elements/base_3d_beam_element.cpp create mode 100644 applications/IgaApplication/custom_elements/base_3d_beam_element.h diff --git a/applications/IgaApplication/custom_elements/base_3d_beam_element.cpp b/applications/IgaApplication/custom_elements/base_3d_beam_element.cpp new file mode 100644 index 000000000000..d80d873a4f58 --- /dev/null +++ b/applications/IgaApplication/custom_elements/base_3d_beam_element.cpp @@ -0,0 +1,25 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// + +// System includes + +// External includes + +// Project includes + +// Application includes +#include "custom_elements/base_3d_beam_element.h" + +namespace Kratos +{ + +} // Namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/base_3d_beam_element.h b/applications/IgaApplication/custom_elements/base_3d_beam_element.h new file mode 100644 index 000000000000..4e763732e6e7 --- /dev/null +++ b/applications/IgaApplication/custom_elements/base_3d_beam_element.h @@ -0,0 +1,254 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// + +#pragma once + +// System includes + +// External includes + +// Project includes +#include "includes/define.h" +#include "includes/element.h" + +// Application includes +#include "iga_application_variables.h" + +namespace Kratos{ +///@name Kratos Classes +///@{ +/// Short class definition. +/** Base class for IGA 3D Beams. +*/ +class KRATOS_API(IGA_APPLICATION) Base3DBeamElement + : public Element +{ +protected: + /** + * Internal variables used in the constitutive equations + */ + struct ConstitutiveVariables + { + Vector StrainVector; + Vector StressVector; + Matrix ConstitutiveMatrix; + + ConstitutiveVariables(SizeType StrainSize = 3) + { + StrainVector = ZeroVector(StrainSize); + StressVector = ZeroVector(StrainSize); + ConstitutiveMatrix = ZeroMatrix(StrainSize, StrainSize); + } + }; + + static inline void ComputeSkewSymmetricMatrix( + BoundedMatrix& rSkewMatrix, + const array_1d& rVec) + { + noalias(rSkewMatrix) = ZeroMatrix(3, 3); + + rSkewMatrix(0, 1) = -rVec[2]; + rSkewMatrix(0, 2) = rVec[1]; + rSkewMatrix(1, 0) = rVec[2]; + rSkewMatrix(1, 2) = -rVec[0]; + rSkewMatrix(2, 0) = -rVec[1]; + rSkewMatrix(2, 1) = rVec[0]; + } +public: + ///@name Type Definitions + ///@{ + + /// Counted pointer of Shell3pElement + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Base3DBeamElement); + + /// Size types + typedef std::size_t SizeType; + typedef std::size_t IndexType; + + // GometryType + typedef Geometry GeometryType; + + /// Constructor using an array of nodes + Base3DBeamElement( + IndexType NewId, + GeometryType::Pointer pGeometry) + : Element(NewId, pGeometry) + {}; + + /// Constructor using an array of nodes with properties + Base3DBeamElement( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) + : Element(NewId, pGeometry, pProperties) + {}; + + /// Default constructor necessary for serialization + Base3DBeamElement() + : Element() + {}; + + /// Destructor. + virtual ~Base3DBeamElement() = default; + + ///@} + ///@name Life Cycle + ///@{ + /// Create with Id, pointer to geometry and pointer to property + Element::Pointer Create( + IndexType NewId, + GeometryType::Pointer pGeom, + PropertiesType::Pointer pProperties + ) const override + { + return Kratos::make_intrusive( + NewId, pGeom, pProperties); + }; + + /// Create with Id, pointer to geometry and pointer to property + Element::Pointer Create( + IndexType NewId, + NodesArrayType const& ThisNodes, + PropertiesType::Pointer pProperties + ) const override + { + return Kratos::make_intrusive< Base3DBeamElement >( + NewId, GetGeometry().Create(ThisNodes), pProperties); + }; + + ///@} + ///@name Operators + ///@{ + + + ///@} + ///@name Operations + ///@{ + + /** + * this determines the elemental equation ID vector for all elemental + * DOFs + * @param rResult: the elemental equation ID vector + * @param rCurrentProcessInfo: the current process info instance + */ + void EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo& CurrentProcessInfo) const override; + + /** + * determines the elemental list of DOFs + * @param ElementalDofList: the list of DOFs + * @param rCurrentProcessInfo: the current process info instance + */ + void GetDofList(DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo) const override; + + void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override; + + void CalculateLeftHandSide(MatrixType& rLeftHandSideMatrix, + const ProcessInfo& rCurrentProcessInfo) override; + + void CalculateRightHandSide(VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override; + + /** + * @brief This functions calculates both the RHS and the LHS + * @param rLeftHandSideMatrix The LHS + * @param rRightHandSideVector The RHS + * @param rCurrentProcessInfo The current process info instance + * @param CalculateStiffnessMatrixFlag The flag to set if compute the LHS + * @param CalculateResidualVectorFlag The flag to set if compute the RHS + */ + virtual void CalculateAll( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo, + const bool CalculateStiffnessMatrixFlag, + const bool CalculateResidualVectorFlag + ); + + static inline void ComputeRotationMatrix( + MatrixType& rMatRod, + const array_1d& rVec, + const double Phi) + { + if (rMatRod.size1() != 3 || rMatRod.size2() != 3) { + rMatRod.resize(3, 3, false); + } + + const double c = std::cos(Phi); + const double s = std::sin(Phi); + + BoundedMatrix skew_matrix; + ComputeSkewSymmetricMatrix(skew_matrix, rVec); + + noalias(rMatRod) = c * IdentityMatrix(3) + s * skew_matrix; + } + + static inline void ComputeRotationMatrixDeriv( + MatrixType& rMatRodDer, + const array_1d& rVec, + const array_1d& rVecDeriv, + const double Phi, + const double PhiDeriv) + { + if (rMatRodDer.size1() != 3 || rMatRodDer.size2() != 3) { + rMatRodDer.resize(3, 3, false); + } + + const double c = std::cos(Phi); + const double s = std::sin(Phi); + + BoundedMatrix skew_vec; + BoundedMatrix skew_vec_deriv; + + ComputeSkewSymmetricMatrix(skew_vec, rVec); + ComputeSkewSymmetricMatrix(skew_vec_deriv, rVecDeriv); + + noalias(rMatRodDer) = + (-PhiDeriv * s) * IdentityMatrix(3) + + (PhiDeriv * c) * skew_vec + + s * skew_vec_deriv; + } + +private: + + ///@name Static Member Variables + ///@{ + + + ///@} + ///@name Member Variables + ///@{ + + + + ///@} + ///@name Private Operators + ///@{ + + ///@} + ///@name Private Operations + ///@{ + + ///@} + ///@name Serialization + ///@{ + + friend class Serializer; + + void save(Serializer& rSerializer) const override; + void load(Serializer& rSerializer) override; + + +}; // Class Base3DBeamElement + +} // Namespace Kratos \ No newline at end of file From 02f00f167a043a4bb6bcbac7a3ac62c08a5f15f9 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 2 Apr 2026 14:55:04 +0200 Subject: [PATCH 02/32] new methods added to the base 3d beam element --- .../custom_elements/base_3d_beam_element.h | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/applications/IgaApplication/custom_elements/base_3d_beam_element.h b/applications/IgaApplication/custom_elements/base_3d_beam_element.h index 4e763732e6e7..c6e6cbfa9939 100644 --- a/applications/IgaApplication/custom_elements/base_3d_beam_element.h +++ b/applications/IgaApplication/custom_elements/base_3d_beam_element.h @@ -33,6 +33,8 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement : public Element { protected: + struct KinematicVariables{}; + /** * Internal variables used in the constitutive equations */ @@ -66,17 +68,16 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement public: ///@name Type Definitions ///@{ + using BaseType = Element; + using NodeType = Node; + using GeometryType = Geometry; + using NodesArrayType = GeometryType::PointsArrayType; + using SizeType = typename BaseType::SizeType; + using IndexType = typename BaseType::IndexType; /// Counted pointer of Shell3pElement KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Base3DBeamElement); - /// Size types - typedef std::size_t SizeType; - typedef std::size_t IndexType; - - // GometryType - typedef Geometry GeometryType; - /// Constructor using an array of nodes Base3DBeamElement( IndexType NewId, @@ -108,22 +109,14 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement IndexType NewId, GeometryType::Pointer pGeom, PropertiesType::Pointer pProperties - ) const override - { - return Kratos::make_intrusive( - NewId, pGeom, pProperties); - }; + ) const override = 0; /// Create with Id, pointer to geometry and pointer to property Element::Pointer Create( IndexType NewId, NodesArrayType const& ThisNodes, PropertiesType::Pointer pProperties - ) const override - { - return Kratos::make_intrusive< Base3DBeamElement >( - NewId, GetGeometry().Create(ThisNodes), pProperties); - }; + ) const override = 0; ///@} ///@name Operators @@ -140,40 +133,52 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement * @param rResult: the elemental equation ID vector * @param rCurrentProcessInfo: the current process info instance */ - void EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo& CurrentProcessInfo) const override; + void EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo& CurrentProcessInfo) const override = 0; /** * determines the elemental list of DOFs * @param ElementalDofList: the list of DOFs * @param rCurrentProcessInfo: the current process info instance */ - void GetDofList(DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo) const override; + void GetDofList(DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo) const override = 0; - void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, + /** + * @brief This function provides a more general interface to the element. + * @details It is designed so that rLHSvariables and rRHSvariables are + * passed to the element thus telling what is the desired output + * @param rLeftHandSideMatrix container with the output Left Hand Side matrix + * @param rRightHandSideVector container for the desired RHS output + * @param rCurrentProcessInfo the current process info instance + */ + virtual void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) override; + const ProcessInfo& rCurrentProcessInfo) = 0; - void CalculateLeftHandSide(MatrixType& rLeftHandSideMatrix, - const ProcessInfo& rCurrentProcessInfo) override; - - void CalculateRightHandSide(VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) override; + /** + * @brief This is called during the assembling process in order + * to calculate the element left hand side matrix + * @param rLeftHandSideMatrix the element left hand side matrix + * @param rCurrentProcessInfo the current process info + */ + virtual void CalculateLeftHandSide(MatrixType& rLeftHandSideMatrix, + const ProcessInfo& rCurrentProcessInfo) = 0; /** - * @brief This functions calculates both the RHS and the LHS - * @param rLeftHandSideMatrix The LHS - * @param rRightHandSideVector The RHS - * @param rCurrentProcessInfo The current process info instance - * @param CalculateStiffnessMatrixFlag The flag to set if compute the LHS - * @param CalculateResidualVectorFlag The flag to set if compute the RHS - */ + * @brief This is called during the assembling process in order + * to calculate the element right hand side matrix + * @param rLeftHandSideMatrix the element right hand side matrix + * @param rCurrentProcessInfo the current process info + */ + virtual void CalculateRightHandSide(VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) = 0; + virtual void CalculateAll( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, const ProcessInfo& rCurrentProcessInfo, const bool CalculateStiffnessMatrixFlag, const bool CalculateResidualVectorFlag - ); + ) = 0; static inline void ComputeRotationMatrix( MatrixType& rMatRod, @@ -245,8 +250,8 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement friend class Serializer; - void save(Serializer& rSerializer) const override; - void load(Serializer& rSerializer) override; + void save(Serializer& rSerializer) const override = 0; + void load(Serializer& rSerializer) override = 0 ; }; // Class Base3DBeamElement From fc33704e81768123af8b3dcc5c666415476a9ac1 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 2 Apr 2026 14:55:26 +0200 Subject: [PATCH 03/32] initial creation of the bernoulli 3d beam element --- .../bernoulli_3d_beam_element.cpp | 80 +++++ .../bernoulli_3d_beam_element.h | 280 ++++++++++++++++++ 2 files changed, 360 insertions(+) create mode 100644 applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp create mode 100644 applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h diff --git a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp b/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp new file mode 100644 index 000000000000..47b9dda6c136 --- /dev/null +++ b/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp @@ -0,0 +1,80 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// + +// System includes + +// External includes + +// Project includes + +// Application includes +#include "custom_elements/bernoulli_3d_beam_element.h" + +namespace Kratos +{ + void Bernoulli3DBeamElement::GetDofList( + DofsVectorType& rElementalDofList, + const ProcessInfo& rCurrentProcessInfo + ) const + { + KRATOS_TRY; + const auto& r_geometry = this->GetGeometry(); + const SizeType number_of_control_points = r_geometry.size(); + + rElementalDofList.resize(0); + rElementalDofList.reserve(4 * number_of_control_points); + + for (IndexType i = 0; i < number_of_control_points; ++i) { + rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_X)); + rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_Y)); + rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_Z)); + rElementalDofList.push_back(GetGeometry()[i].pGetDof(ROTATION_X)); + } + KRATOS_CATCH("") + } + + void Bernoulli3DBeamElement::EquationIdVector( + EquationIdVectorType& rResult, + const ProcessInfo& rCurrentProcessInfo + ) const + { + KRATOS_TRY; + + const auto& r_geometry = this->GetGeometry(); + const SizeType number_of_control_points = r_geometry.size(); + + if (rResult.size() != 4 * number_of_control_points) + rResult.resize(4 * number_of_control_points, false); + + const IndexType pos = r_geometry[0].GetDofPosition(DISPLACEMENT_X); + + for (IndexType i = 0; i < number_of_control_points; ++i) { + const IndexType index = i * 4; + rResult[index] = r_geometry[i].GetDof(DISPLACEMENT_X, pos).EquationId(); + rResult[index + 1] = r_geometry[i].GetDof(DISPLACEMENT_Y, pos + 1).EquationId(); + rResult[index + 2] = r_geometry[i].GetDof(DISPLACEMENT_Z, pos + 2).EquationId(); + rResult[index + 3] = r_geometry[i].GetDof(ROTATION_X, pos + 3).EquationId(); + } + + KRATOS_CATCH("") + }; + + void Bernoulli3DBeamElement::ComputeGAxial( + const IndexType IntegrationPointIndex, + Matrix& rGAxial, + KinematicVariables& rKinematicVariables) const + { + KRATOS_TRY; + KRATOS_CATCH(""); + } + +} // Namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h b/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h new file mode 100644 index 000000000000..911201b17324 --- /dev/null +++ b/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h @@ -0,0 +1,280 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// + +#pragma once + +// System includes + +// External includes + +// Project includes +#include "includes/define.h" +#include "includes/element.h" + +// Application includes +#include "iga_application_variables.h" +#include "base_3d_beam_element.h" + +namespace Kratos{ +///@name Kratos Classes +///@{ +/// Short class definition. +/** 3D Bernoulli beam element. +*/ +class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement + : public Base3DBeamElement +{ +protected: + struct KinematicVariables + { + // Reference configuration + array_1d R1; // Reference tangent vector + array_1d R2; // Reference curvature vector + array_1d R3; // Reference third derivative + double A; // Reference length measure + double B; // Reference curvature measure + + // Current configuration + array_1d r1; // Current tangent vector + array_1d r2; // Current curvature vector + array_1d r3; // Current third derivative + double a; // Current length measure + double b; // Current curvature measure + + // Cross-section directors + array_1d N0, V0; // Reference directors + array_1d n, v; // Current directors + + // Curvature components + double B_n, B_v; // Reference curvatures + double b_n, b_v; // Current curvatures + double C_12, C_13; // Reference twist + double c_12, c_13; // Current twist + + // Rotations + double Phi, Phi_der; // Reference rotation + double phi, phi_der; // Current rotation + + KinematicVariables(SizeType Dimension = 3) + { + R1 = ZeroVector(Dimension); + R2 = ZeroVector(Dimension); + R3 = ZeroVector(Dimension); + r1 = ZeroVector(Dimension); + r2 = ZeroVector(Dimension); + r3 = ZeroVector(Dimension); + N0 = ZeroVector(Dimension); + V0 = ZeroVector(Dimension); + n = ZeroVector(Dimension); + v = ZeroVector(Dimension); + A = B = a = b = 0.0; + B_n = B_v = b_n = b_v = 0.0; + C_12 = C_13 = c_12 = c_13 = 0.0; + Phi = Phi_der = 0.0; + phi = phi_der = 0.0; + } + }; + +public: + ///@name Type Definitions + ///@{ + + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Bernoulli3DBeamElement); + + using BaseType = Base3DBeamElement; + using SizeType = typename BaseType::SizeType; + using IndexType = typename BaseType::IndexType; + + // GeometryType + using GeometryType = Geometry; + + //@} + ///@name Life Cycle + ///@{ + + /// Constructor using an array of nodes + Bernoulli3DBeamElement( + IndexType NewId, + GeometryType::Pointer pGeometry) + : Base3DBeamElement(NewId, pGeometry) + { + }; + + /// Constructor using an array of nodes with properties + Bernoulli3DBeamElement( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) + : Base3DBeamElement(NewId, pGeometry, pProperties) + { + }; + + /// Default constructor necessary for serialization + Bernoulli3DBeamElement() + : Base3DBeamElement() + { + }; + + /// Destructor. + ~Bernoulli3DBeamElement() override = default; + + /// Create with Id, pointer to geometry and pointer to property + Element::Pointer Create( + IndexType NewId, + GeometryType::Pointer pGeom, + PropertiesType::Pointer pProperties + ) const override + { + return Kratos::make_intrusive( + NewId, pGeom, pProperties); + }; + + /// Create with Id, pointer to geometry and pointer to property + Element::Pointer Create( + IndexType NewId, + NodesArrayType const& ThisNodes, + PropertiesType::Pointer pProperties + ) const override + { + return Kratos::make_intrusive( + NewId, GetGeometry().Create(ThisNodes), pProperties); + }; + + ///@} + ///@name Degrees of freedom + ///@{ + + /// Relates the degrees of freedom of the element geometry + void GetDofList( + DofsVectorType& rElementalDofList, + const ProcessInfo& rCurrentProcessInfo + ) const override; + + /// Sets the ID's of the element degrees of freedom + void EquationIdVector( + EquationIdVectorType& rResult, + const ProcessInfo& rCurrentProcessInfo + ) const override; + + void ComputeGAxial( + const IndexType IntegrationPointIndex, + Matrix& rGAxial, + KinematicVariables& rKinematicVariables) const; + + void ComputeGBending( + const IndexType IntegrationPointIndex, + Matrix& rGBending1, + Matrix& rGBending2, + KinematicVariables& rKinematicVariables) const; + + void ComputeGTorsion( + const IndexType IntegrationPointIndex, + Matrix& rGTorsion1, + Matrix& rGTorsion2, + KinematicVariables& rKinematicVariables) const; + + void ComputeBAxial( + const IndexType IntegrationPointIndex, + Matrix& rBAxial, + KinematicVariables& rKinematicVariables) const; + + void ComputeBBending( + const IndexType IntegrationPointIndex, + Matrix& rBBending1, + Matrix& rBBending2, + KinematicVariables& rKinematicVariables) const; + + void ComputeBTorsion( + const IndexType IntegrationPointIndex, + Matrix& rBTorsion1, + Matrix& rBTorsion2, + KinematicVariables& rKinematicVariables) const; + +private: + + void CalculateRightHandSide( + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType nb_nodes = this->GetGeometry().size(); + const SizeType number_dofs_per_node = 4; + const SizeType nb_dofs = nb_nodes * number_dofs_per_node; + + if (rRightHandSideVector.size() != nb_dofs) + rRightHandSideVector.resize(nb_dofs); + noalias(rRightHandSideVector) = ZeroVector(nb_dofs); + + MatrixType left_hand_side_matrix; + + CalculateAll(left_hand_side_matrix, rRightHandSideVector, + rCurrentProcessInfo, false, true); + } + + void CalculateLeftHandSide( + MatrixType& rLeftHandSideMatrix, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType nb_nodes = this->GetGeometry().size(); + const SizeType number_dofs_per_node = 4; + const SizeType nb_dofs = nb_nodes * number_dofs_per_node; + + VectorType right_hand_side_vector; + + if (rLeftHandSideMatrix.size1() != nb_dofs && rLeftHandSideMatrix.size2() != nb_dofs) + rLeftHandSideMatrix.resize(nb_dofs, nb_dofs); + noalias(rLeftHandSideMatrix) = ZeroMatrix(nb_dofs, nb_dofs); + + CalculateAll(rLeftHandSideMatrix, right_hand_side_vector, + rCurrentProcessInfo, true, false); + } + + void CalculateLocalSystem( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType nb_nodes = GetGeometry().size(); + const SizeType number_dofs_per_node = 4; + const SizeType nb_dofs = nb_nodes * number_dofs_per_node; + + if (rRightHandSideVector.size() != nb_dofs) + rRightHandSideVector.resize(nb_dofs); + noalias(rRightHandSideVector) = ZeroVector(nb_dofs); + + if (rLeftHandSideMatrix.size1() != nb_dofs && rLeftHandSideMatrix.size2() != nb_dofs) + rLeftHandSideMatrix.resize(nb_dofs, nb_dofs); + noalias(rLeftHandSideMatrix) = ZeroMatrix(nb_dofs, nb_dofs); + + CalculateAll(rLeftHandSideMatrix, rRightHandSideVector, + rCurrentProcessInfo, true, true); + } + + void CalculateAll( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo, + const bool CalculateStiffnessMatrixFlag, + const bool CalculateResidualVectorFlag + ) override + {} + + friend class Serializer; + + void save(Serializer& rSerializer) const override + { + } + + void load(Serializer& rSerializer) override + { + } +}; +} \ No newline at end of file From a43e2018745bffc41bebb836db985898cef6d971 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 2 Apr 2026 16:38:32 +0200 Subject: [PATCH 04/32] adding the bernoulli beam elemen to kratos --- applications/IgaApplication/iga_application.cpp | 3 +++ applications/IgaApplication/iga_application.h | 2 ++ 2 files changed, 5 insertions(+) diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 5b0268500a49..84c695045209 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -24,6 +24,8 @@ KratosIgaApplication::KratosIgaApplication() new Geometry(Element::GeometryType::PointsArrayType(1)))) , mBeamThickElement2D(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) + , mBeamBernoulliElement3D(0, Element::GeometryType::Pointer( + new Geometry(Element::GeometryType::PointsArrayType(1)))) , mIgaMembraneElement(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) , mShell3pElement(0, Element::GeometryType::Pointer( @@ -92,6 +94,7 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_ELEMENT("TrussEmbeddedEdgeElement", mTrussEmbeddedEdgeElement) KRATOS_REGISTER_ELEMENT("BeamThinElement2D", mBeamThinElement2D) KRATOS_REGISTER_ELEMENT("BeamThickElement2D", mBeamThickElement2D) + KRATOS_REGISTER_ELEMENT("BeamBernoulliElement3D", mBeamBernoulliElement3D) KRATOS_REGISTER_ELEMENT("IgaMembraneElement", mIgaMembraneElement) KRATOS_REGISTER_ELEMENT("Shell3pElement", mShell3pElement) KRATOS_REGISTER_ELEMENT("Shell5pHierarchicElement", mShell5pHierarchicElement) diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index e81a1454b691..be207af841f0 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -21,6 +21,7 @@ #include "custom_elements/truss_embedded_edge_element.h" #include "custom_elements/beam_thin_element_2D.h" #include "custom_elements/beam_thick_element_2D.h" +#include "custom_elements/beam_bernoulli_element_3D.h" #include "custom_elements/iga_membrane_element.h" #include "custom_elements/shell_3p_element.h" #include "custom_elements/shell_5p_hierarchic_element.h" @@ -137,6 +138,7 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio const TrussEmbeddedEdgeElement mTrussEmbeddedEdgeElement; const BeamThinElement2D mBeamThinElement2D; const BeamThickElement2D mBeamThickElement2D; + const BeamThickElement2D mBeamBernoulliElement3D; const IgaMembraneElement mIgaMembraneElement; const Shell3pElement mShell3pElement; const Shell5pHierarchicElement mShell5pHierarchicElement; From 4f48fe08014dd169eb90f53839a39c9b2a89c1f2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 2 Apr 2026 16:38:47 +0200 Subject: [PATCH 05/32] change names --- ...m_element.cpp => beam_base_element_3D.cpp} | 2 +- ..._beam_element.h => beam_base_element_3D.h} | 14 +++++----- ...ment.cpp => beam_bernoulli_element_3D.cpp} | 8 +++--- ..._element.h => beam_bernoulli_element_3D.h} | 28 +++++++++---------- 4 files changed, 26 insertions(+), 26 deletions(-) rename applications/IgaApplication/custom_elements/{base_3d_beam_element.cpp => beam_base_element_3D.cpp} (90%) rename applications/IgaApplication/custom_elements/{base_3d_beam_element.h => beam_base_element_3D.h} (96%) rename applications/IgaApplication/custom_elements/{bernoulli_3d_beam_element.cpp => beam_bernoulli_element_3D.cpp} (92%) rename applications/IgaApplication/custom_elements/{bernoulli_3d_beam_element.h => beam_bernoulli_element_3D.h} (92%) diff --git a/applications/IgaApplication/custom_elements/base_3d_beam_element.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp similarity index 90% rename from applications/IgaApplication/custom_elements/base_3d_beam_element.cpp rename to applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index d80d873a4f58..e9a82bf25d4f 100644 --- a/applications/IgaApplication/custom_elements/base_3d_beam_element.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -17,7 +17,7 @@ // Project includes // Application includes -#include "custom_elements/base_3d_beam_element.h" +#include "custom_elements/beam_base_element_3D.h" namespace Kratos { diff --git a/applications/IgaApplication/custom_elements/base_3d_beam_element.h b/applications/IgaApplication/custom_elements/beam_base_element_3D.h similarity index 96% rename from applications/IgaApplication/custom_elements/base_3d_beam_element.h rename to applications/IgaApplication/custom_elements/beam_base_element_3D.h index c6e6cbfa9939..b5f6f2a82a54 100644 --- a/applications/IgaApplication/custom_elements/base_3d_beam_element.h +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.h @@ -29,7 +29,7 @@ namespace Kratos{ /// Short class definition. /** Base class for IGA 3D Beams. */ -class KRATOS_API(IGA_APPLICATION) Base3DBeamElement +class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D : public Element { protected: @@ -76,17 +76,17 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement using IndexType = typename BaseType::IndexType; /// Counted pointer of Shell3pElement - KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Base3DBeamElement); + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BeamBaseElement3D); /// Constructor using an array of nodes - Base3DBeamElement( + BeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry) : Element(NewId, pGeometry) {}; /// Constructor using an array of nodes with properties - Base3DBeamElement( + BeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) @@ -94,12 +94,12 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement {}; /// Default constructor necessary for serialization - Base3DBeamElement() + BeamBaseElement3D() : Element() {}; /// Destructor. - virtual ~Base3DBeamElement() = default; + virtual ~BeamBaseElement3D() = default; ///@} ///@name Life Cycle @@ -254,6 +254,6 @@ class KRATOS_API(IGA_APPLICATION) Base3DBeamElement void load(Serializer& rSerializer) override = 0 ; -}; // Class Base3DBeamElement +}; // Class BeamBaseElement3D } // Namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp similarity index 92% rename from applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp rename to applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp index 47b9dda6c136..637d93b24c42 100644 --- a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.cpp +++ b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp @@ -17,11 +17,11 @@ // Project includes // Application includes -#include "custom_elements/bernoulli_3d_beam_element.h" +#include "custom_elements/beam_bernoulli_element_3D.h" namespace Kratos { - void Bernoulli3DBeamElement::GetDofList( + void BeamBernoulliElement3D::GetDofList( DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo ) const @@ -42,7 +42,7 @@ namespace Kratos KRATOS_CATCH("") } - void Bernoulli3DBeamElement::EquationIdVector( + void BeamBernoulliElement3D::EquationIdVector( EquationIdVectorType& rResult, const ProcessInfo& rCurrentProcessInfo ) const @@ -68,7 +68,7 @@ namespace Kratos KRATOS_CATCH("") }; - void Bernoulli3DBeamElement::ComputeGAxial( + void BeamBernoulliElement3D::ComputeGAxial( const IndexType IntegrationPointIndex, Matrix& rGAxial, KinematicVariables& rKinematicVariables) const diff --git a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h similarity index 92% rename from applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h rename to applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h index 911201b17324..dc6647fc2647 100644 --- a/applications/IgaApplication/custom_elements/bernoulli_3d_beam_element.h +++ b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h @@ -22,7 +22,7 @@ // Application includes #include "iga_application_variables.h" -#include "base_3d_beam_element.h" +#include "custom_elements/beam_base_element_3D.h" namespace Kratos{ ///@name Kratos Classes @@ -30,8 +30,8 @@ namespace Kratos{ /// Short class definition. /** 3D Bernoulli beam element. */ -class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement - : public Base3DBeamElement +class KRATOS_API(IGA_APPLICATION) BeamBernoulliElement3D + : public BeamBaseElement3D { protected: struct KinematicVariables @@ -88,9 +88,9 @@ class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement ///@name Type Definitions ///@{ - KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(Bernoulli3DBeamElement); + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BeamBernoulliElement3D); - using BaseType = Base3DBeamElement; + using BaseType = BeamBaseElement3D; using SizeType = typename BaseType::SizeType; using IndexType = typename BaseType::IndexType; @@ -102,30 +102,30 @@ class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement ///@{ /// Constructor using an array of nodes - Bernoulli3DBeamElement( + BeamBernoulliElement3D( IndexType NewId, GeometryType::Pointer pGeometry) - : Base3DBeamElement(NewId, pGeometry) + : BeamBaseElement3D(NewId, pGeometry) { }; /// Constructor using an array of nodes with properties - Bernoulli3DBeamElement( + BeamBernoulliElement3D( IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) - : Base3DBeamElement(NewId, pGeometry, pProperties) + : BeamBaseElement3D(NewId, pGeometry, pProperties) { }; /// Default constructor necessary for serialization - Bernoulli3DBeamElement() - : Base3DBeamElement() + BeamBernoulliElement3D() + : BeamBaseElement3D() { }; /// Destructor. - ~Bernoulli3DBeamElement() override = default; + ~BeamBernoulliElement3D() override = default; /// Create with Id, pointer to geometry and pointer to property Element::Pointer Create( @@ -134,7 +134,7 @@ class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement PropertiesType::Pointer pProperties ) const override { - return Kratos::make_intrusive( + return Kratos::make_intrusive( NewId, pGeom, pProperties); }; @@ -145,7 +145,7 @@ class KRATOS_API(IGA_APPLICATION) Bernoulli3DBeamElement PropertiesType::Pointer pProperties ) const override { - return Kratos::make_intrusive( + return Kratos::make_intrusive( NewId, GetGeometry().Create(ThisNodes), pProperties); }; From 320cfcb15c3375513b7c4f0cad3139ef9745f6de Mon Sep 17 00:00:00 2001 From: Alicia Date: Wed, 16 Sep 2026 17:48:00 +0200 Subject: [PATCH 06/32] Added beam_base_element_3d and non_linear_bernoulli_beam_element_3d --- ...ernoulli_beam_elastic_constitutive_law.cpp | 139 + .../bernoulli_beam_elastic_constitutive_law.h | 158 + .../custom_elements/beam_base_element_3D.cpp | 3259 ++++++++++++++++- .../custom_elements/beam_base_element_3D.h | 519 ++- .../beam_bernoulli_element_3D.cpp | 80 - .../beam_bernoulli_element_3D.h | 280 -- .../non_linear_bernoulli_beam_element_3D.cpp | 1886 ++++++++++ .../non_linear_bernoulli_beam_element_3D.h | 469 +++ .../IgaApplication/iga_application.cpp | 10 + applications/IgaApplication/iga_application.h | 2 +- .../iga_application_variables.cpp | 9 + .../iga_application_variables.h | 8 + 12 files changed, 6305 insertions(+), 514 deletions(-) create mode 100644 applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp create mode 100644 applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h delete mode 100644 applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp delete mode 100644 applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h create mode 100644 applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp create mode 100644 applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp new file mode 100644 index 000000000000..b0d601158c33 --- /dev/null +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -0,0 +1,139 @@ +// KRATOS ___| | | | +// \___ \ __| __| | | __| __| | | __| _` | | +// | | | | | ( | | | | ( | | +// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// +// License: BSD License +// license: IgaApplication/license.txt +// + +// System includes + +// External includes + +// Project includes +#include "bernoulli_beam_elastic_constitutive_law.h" +#include "iga_application_variables.h" + +namespace Kratos +{ + +BernoulliBeamElasticConstitutiveLaw::BernoulliBeamElasticConstitutiveLaw() + : ConstitutiveLaw() +{ +} + +BernoulliBeamElasticConstitutiveLaw::BernoulliBeamElasticConstitutiveLaw(const BernoulliBeamElasticConstitutiveLaw& rOther) + : ConstitutiveLaw(rOther) +{ +} + +ConstitutiveLaw::Pointer BernoulliBeamElasticConstitutiveLaw::Clone() const +{ + BernoulliBeamElasticConstitutiveLaw::Pointer p_clone(new BernoulliBeamElasticConstitutiveLaw(*this)); + return p_clone; +} + +BernoulliBeamElasticConstitutiveLaw::~BernoulliBeamElasticConstitutiveLaw() +{ +} + +void BernoulliBeamElasticConstitutiveLaw::GetLawFeatures(Features& rFeatures) +{ + rFeatures.mStrainSize = 5; + rFeatures.mSpaceDimension = 3; +} + +int BernoulliBeamElasticConstitutiveLaw::Check( + const Properties& rMaterialProperties, + const GeometryType& rElementGeometry, + const ProcessInfo& rCurrentProcessInfo +) const +{ + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(YOUNG_MODULUS)) << "YOUNG_MODULUS is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(POISSON_RATIO)) << "POISSON_RATIO is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[YOUNG_MODULUS] > 0.0) << "The YOUNG_MODULUS value is lower than 0.0" << std::endl; + KRATOS_ERROR_IF (rMaterialProperties[POISSON_RATIO] < 0.0) << "The POISSON_RATIO value is lower than 0.0" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[POISSON_RATIO] < 0.5) << "The POISSON_RATIO cannot be greater than or equal 0.5." << std::endl; + + // Check for IGA beam cross-section properties + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(CROSS_AREA)) << "CROSS_AREA is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_V)) << "I_V is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_N)) << "I_N is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_T)) << "I_T is not defined in the properties" << std::endl; + + // Validate property values + KRATOS_ERROR_IF_NOT(rMaterialProperties[CROSS_AREA] > 0.0) << "CROSS_AREA must be positive" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[I_V] > 0.0) << "I_V must be positive" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[I_N] > 0.0) << "I_N must be positive" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[I_T] > 0.0) << "I_T must be positive" << std::endl; + + return 0; +} + +void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponsePK2(ConstitutiveLaw::Parameters& rValues) +{ + CalculateMaterialResponseCauchy(rValues); +} + +void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseKirchhoff(ConstitutiveLaw::Parameters& rValues) +{ + CalculateMaterialResponseCauchy(rValues); +} + +void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponsePK1(ConstitutiveLaw::Parameters& rValues) +{ + CalculateMaterialResponseCauchy(rValues); +} + +void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(ConstitutiveLaw::Parameters& rValues) +{ + const auto& r_cl_law_options = rValues.GetOptions(); + const auto &r_material_properties = rValues.GetMaterialProperties(); + auto &r_strain_vector = rValues.GetStrainVector(); + + AddInitialStrainVectorContribution(r_strain_vector); + const auto strain_size = GetStrainSize(); + + const double E = r_material_properties[YOUNG_MODULUS]; + const double nu = r_material_properties[POISSON_RATIO]; + const double G = E / (2.0 * (1.0 + nu)); + + // Retrieve beam cross-section properties + const double A = r_material_properties[CROSS_AREA]; + const double I_v = r_material_properties[I_V]; + const double I_n = r_material_properties[I_N]; + const double I_t = r_material_properties[I_T]; + + if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_STRESS)) { + auto &r_stress_vector = rValues.GetStressVector(); + if (r_stress_vector.size() != strain_size) + r_stress_vector.resize(strain_size, false); + + // Compute stresses according to 5x5 diagonal constitutive matrix with beam properties + r_stress_vector[0] = E * A * r_strain_vector[0]; // N = E*A*ε (normal force) + r_stress_vector[1] = E * I_v * r_strain_vector[1]; // M_y = E*I_y*κ_y (bending about y-axis) + r_stress_vector[2] = E * I_n * r_strain_vector[2]; // M_z = E*I_z*κ_z (bending about z-axis) + r_stress_vector[3] = G * I_t * r_strain_vector[3]; // T = G*I_t*γ_t1 (torsion) + r_stress_vector[4] = G * I_t * r_strain_vector[4]; // T = G*I_t*γ_t2 (torsion) + + AddInitialStressVectorContribution(r_stress_vector); + + + if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR)) { + auto &r_constitutive_matrix = rValues.GetConstitutiveMatrix(); + if (r_constitutive_matrix.size1() != strain_size || r_constitutive_matrix.size2() != strain_size) + r_constitutive_matrix.resize(strain_size, strain_size, false); + r_constitutive_matrix.clear(); + + // 5x5 diagonal constitutive matrix with beam cross-section properties + r_constitutive_matrix(0,0) = E * A; // Normal stiffness + r_constitutive_matrix(1,1) = E * I_v; // Bending stiffness about y-axis + r_constitutive_matrix(2,2) = E * I_n; // Bending stiffness about z-axis + r_constitutive_matrix(3,3) = 0.5 * G * I_t; // Torsional stiffness + r_constitutive_matrix(4,4) = 0.5 * G * I_t; // Torsional stiffness + } + } +} + +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h new file mode 100644 index 000000000000..a945e5699823 --- /dev/null +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h @@ -0,0 +1,158 @@ +// KRATOS ___| | | | +// \___ \ __| __| | | __| __| | | __| _` | | +// | | | | | ( | | | | ( | | +// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// +// License: BSD License +// license: IgaApplication/license.txt + +// + +#pragma once + +// System includes + +// External includes + +// Project includes +#include "includes/constitutive_law.h" + +namespace Kratos +{ + +class KRATOS_API(IGA_APPLICATION) BernoulliBeamElasticConstitutiveLaw : public ConstitutiveLaw +{ +public: + /** + * Type Definitions + */ + using ProcessInfoType = ProcessInfo; + using BaseType = ConstitutiveLaw; + using SizeType = std::size_t; + + /** + * Counted pointer of BernoulliBeamElasticConstitutiveLaw + */ + KRATOS_CLASS_POINTER_DEFINITION(BernoulliBeamElasticConstitutiveLaw); + + /** + * Life Cycle + */ + + /** + * Default constructor. + */ + BernoulliBeamElasticConstitutiveLaw(); + + ConstitutiveLaw::Pointer Clone() const override; + + /** + * Copy constructor. + */ + BernoulliBeamElasticConstitutiveLaw(const BernoulliBeamElasticConstitutiveLaw& rOther); + + /** + * Destructor. + */ + ~BernoulliBeamElasticConstitutiveLaw() override; + + /** + * Operators + */ + + /** + * Operations needed by the base class: + */ + + /** + * This function is designed to be called once to check compatibility with element + * @param rFeatures + */ + void GetLawFeatures(Features& rFeatures) override; + + /** + * Voigt tensor size: + */ + SizeType GetStrainSize() const override + { + return 5; + } + + /** + * This function provides the place to perform checks on the completeness of the input. + * It is designed to be called only once (or anyway, not often) typically at the beginning + * of the calculations, so to verify that nothing is missing from the input + * or that no common error is found. + * @param rMaterialProperties: The properties of the material + * @param rElementGeometry: The geometry of the element + * @param rCurrentProcessInfo: The current process info instance + */ + int Check( + const Properties& rMaterialProperties, + const GeometryType& rElementGeometry, + const ProcessInfo& rCurrentProcessInfo + ) const override; + + /** + * @brief Computes the material response in terms of 1st Piola-Kirchhoff stresses and constitutive tensor + * @see Parameters + */ + void CalculateMaterialResponsePK1(ConstitutiveLaw::Parameters &rValues) override; + + /** + * @brief Computes the material response in terms of 2nd Piola-Kirchhoff stresses and constitutive tensor + * @see Parameters + */ + void CalculateMaterialResponsePK2(ConstitutiveLaw::Parameters &rValues) override; + + /** + * @brief Computes the material response in terms of Kirchhoff stresses and constitutive tensor + * @see Parameters + */ + void CalculateMaterialResponseKirchhoff(ConstitutiveLaw::Parameters &rValues) override; + + /** + * @brief Computes the material response in terms of Cauchy stresses and constitutive tensor + * @see Parameters + */ + void CalculateMaterialResponseCauchy(ConstitutiveLaw::Parameters &rValues) override; + + /** + * @brief If the CL requires to initialize the material response, called by the element in InitializeSolutionStep. + */ + bool RequiresFinalizeMaterialResponse() override + { + return false; + } + + /** + * @brief If the CL requires to initialize the material response, called by the element in InitializeSolutionStep. + */ + bool RequiresInitializeMaterialResponse() override + { + return false; + } + +protected: + + +private: + + + ///@} + ///@name Serialization + ///@{ + friend class Serializer; + + void save(Serializer& rSerializer) const override + { + KRATOS_SERIALIZE_SAVE_BASE_CLASS(rSerializer, ConstitutiveLaw) + } + + void load(Serializer& rSerializer) override + { + KRATOS_SERIALIZE_LOAD_BASE_CLASS(rSerializer, ConstitutiveLaw) + } + +}; // Class BernoulliBeamElasticConstitutiveLaw +} // namespace Kratos. \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index e9a82bf25d4f..fde525be8db7 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -7,14 +7,18 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // // System includes +#include +#include // External includes // Project includes +#include "utilities/math_utils.h" // Application includes #include "custom_elements/beam_base_element_3D.h" @@ -22,4 +26,3255 @@ namespace Kratos { -} // Namespace Kratos \ No newline at end of file + void BeamBaseElement3D::EquationIdVector( + EquationIdVectorType& rResult, + const ProcessInfo& rCurrentProcessInfo) const + { + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + const SizeType number_of_control_points = r_geometry.size(); + + if (rResult.size() != 4 * number_of_control_points) { + rResult.resize(4 * number_of_control_points, false); + } + + const IndexType dof_position = + r_geometry[0].GetDofPosition(DISPLACEMENT_X); + + for (IndexType i = 0; i < number_of_control_points; ++i) { + const IndexType index = i * 4; + + rResult[index] = + r_geometry[i] + .GetDof(DISPLACEMENT_X, dof_position) + .EquationId(); + + rResult[index + 1] = + r_geometry[i] + .GetDof(DISPLACEMENT_Y, dof_position + 1) + .EquationId(); + + rResult[index + 2] = + r_geometry[i] + .GetDof(DISPLACEMENT_Z, dof_position + 2) + .EquationId(); + + rResult[index + 3] = + r_geometry[i] + .GetDof(ROTATION_X, dof_position + 3) + .EquationId(); + } + + KRATOS_CATCH("") + } + + + void BeamBaseElement3D::GetDofList( + DofsVectorType& rElementalDofList, + const ProcessInfo& rCurrentProcessInfo) const + { + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + const SizeType number_of_control_points = r_geometry.size(); + + rElementalDofList.resize(0); + rElementalDofList.reserve(4 * number_of_control_points); + + for (IndexType i = 0; i < number_of_control_points; ++i) { + rElementalDofList.push_back( + r_geometry[i].pGetDof(DISPLACEMENT_X)); + + rElementalDofList.push_back( + r_geometry[i].pGetDof(DISPLACEMENT_Y)); + + rElementalDofList.push_back( + r_geometry[i].pGetDof(DISPLACEMENT_Z)); + + rElementalDofList.push_back( + r_geometry[i].pGetDof(ROTATION_X)); + } + + KRATOS_CATCH("") + } + + + void BeamBaseElement3D::InitializeMaterial() + { + KRATOS_TRY + + const GeometryType& r_geometry = GetGeometry(); + const Properties& r_properties = GetProperties(); + const auto& r_shape_functions = + r_geometry.ShapeFunctionsValues(); + + const SizeType number_of_integration_points = + r_geometry.IntegrationPointsNumber(); + + if (mConstitutiveLawVector.size() != number_of_integration_points) { + mConstitutiveLawVector.resize(number_of_integration_points); + } + + for ( + IndexType point_number = 0; + point_number < number_of_integration_points; + ++point_number) + { + mConstitutiveLawVector[point_number] = + GetProperties()[CONSTITUTIVE_LAW]->Clone(); + + mConstitutiveLawVector[point_number]->InitializeMaterial( + r_properties, + r_geometry, + row(r_shape_functions, point_number)); + } + + KRATOS_CATCH("") + } + + + void BeamBaseElement3D::GetValuesVector( + Vector& rValues, + const int Step) const + { + const auto& r_geometry = GetGeometry(); + const IndexType number_of_nodes = r_geometry.size(); + + if (rValues.size() != number_of_nodes * 4) { + rValues.resize(number_of_nodes * 4, false); + } + + for (IndexType i = 0; i < number_of_nodes; ++i) { + const IndexType index = i * 4; + + const auto& r_displacement = + r_geometry[i].FastGetSolutionStepValue( + DISPLACEMENT, + Step); + + const double rotation = + r_geometry[i].FastGetSolutionStepValue( + ROTATION_X, + Step); + + rValues[index] = r_displacement[0]; + rValues[index + 1] = r_displacement[1]; + rValues[index + 2] = r_displacement[2]; + rValues[index + 3] = rotation; + } + } + + int BeamBaseElement3D::Check( + const ProcessInfo& rCurrentProcessInfo) const + { + KRATOS_TRY + + const double numerical_limit = + std::numeric_limits::epsilon(); + + const auto& r_geometry = GetGeometry(); + + for (IndexType i = 0; i < r_geometry.size(); ++i) { + if (r_geometry[i].SolutionStepsDataHas(DISPLACEMENT) == false) { + KRATOS_ERROR + << "missing variable DISPLACEMENT on node " + << r_geometry[i].Id() << std::endl; + } + + if (r_geometry[i].SolutionStepsDataHas(ROTATION_X) == false) { + KRATOS_ERROR + << "missing variable ROTATION_X on node " + << r_geometry[i].Id() << std::endl; + } + + if ( + r_geometry[i].HasDofFor(DISPLACEMENT_X) == false || + r_geometry[i].HasDofFor(DISPLACEMENT_Y) == false || + r_geometry[i].HasDofFor(DISPLACEMENT_Z) == false) + { + KRATOS_ERROR + << "missing one of the dofs for the variable " + << "DISPLACEMENT on node " + << r_geometry[i].Id() << std::endl; + } + + if (r_geometry[i].HasDofFor(ROTATION_X) == false) { + KRATOS_ERROR + << "missing dof for the variable ROTATION_X on node " + << r_geometry[i].Id() << std::endl; + } + } + + KRATOS_ERROR_IF( + !GetProperties().Has(CROSS_AREA) || + GetProperties()[CROSS_AREA] <= numerical_limit) + << "Please provide a reasonable value for \"CROSS_AREA\" " + << "for element #" << Id() << std::endl; + + KRATOS_ERROR_IF( + !GetProperties().Has(YOUNG_MODULUS) || + GetProperties()[YOUNG_MODULUS] <= numerical_limit) + << "Please provide a reasonable value for \"YOUNG_MODULUS\" " + << "for element #" << Id() << std::endl; + + KRATOS_ERROR_IF( + !GetProperties().Has(DENSITY) || + GetProperties()[DENSITY] <= numerical_limit) + << "Please provide a reasonable value for \"DENSITY\" " + << "for element #" << Id() + << ". Provided density: " + << GetProperties()[DENSITY] << std::endl; + + KRATOS_ERROR_IF(!GetProperties().Has(POISSON_RATIO)) + << "\"POISSON_RATIO\" not provided for element #" + << Id() << std::endl; + + KRATOS_ERROR_IF(!GetProperties().Has(CONSTITUTIVE_LAW)) + << "\"CONSTITUTIVE_LAW\" not provided for element #" + << Id() << std::endl; + + return 0; + + KRATOS_CATCH("") + } + + // --------------------------------------------------------------------- + // Beam kinematics + // --------------------------------------------------------------------- + + void BeamBaseElement3D::ComputeTangentVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Vector& rTangentVariation) const + { + rTangentVariation.resize(3 * mNumberOfDofs); + rTangentVariation.clear(); + + const double first_base_vector_norm = + norm_2(rFirstBaseVector); + + const double first_base_vector_norm_cubed = + pow(first_base_vector_norm, 3); + + Vector first_base_vector_variation; + first_base_vector_variation.resize( + 3 * mNumberOfDofs); + first_base_vector_variation.clear(); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if (component == dof_component) { + first_base_vector_variation( + component * mNumberOfDofs + + dof_index) += + rShapeFunctionDerivatives[ + control_point_index]; + } + } + } + + Vector base_vector_product_variation; + base_vector_product_variation.resize( + mNumberOfDofs); + base_vector_product_variation.clear(); + + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + for (size_t component = 0; + component < 3; + ++component) + { + base_vector_product_variation(dof_index) += + first_base_vector_variation[ + component * mNumberOfDofs + + dof_index] * + rFirstBaseVector[component]; + } + } + + for (size_t component = 0; + component < 3; + ++component) + { + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + rTangentVariation( + component * mNumberOfDofs + + dof_index) += + first_base_vector_variation[ + component * mNumberOfDofs + + dof_index] / + first_base_vector_norm + - + rFirstBaseVector[component] * + base_vector_product_variation[dof_index] / + first_base_vector_norm_cubed; + } + } + } + + + void BeamBaseElement3D::ComputeTangentSecondVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Matrix& rTangentSecondVariation) const + { + rTangentSecondVariation.resize( + 3 * mNumberOfDofs, + mNumberOfDofs); + + rTangentSecondVariation.clear(); + + const double first_base_vector_norm = + norm_2(rFirstBaseVector); + + const double first_base_vector_norm_cubed = + pow(first_base_vector_norm, 3); + + const double first_base_vector_norm_fifth = + pow(first_base_vector_norm, 5); + + Vector first_base_vector_variation; + first_base_vector_variation.resize( + 3 * mNumberOfDofs); + first_base_vector_variation.clear(); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if ( + component == dof_component && + dof_component < 3) + { + first_base_vector_variation( + component * mNumberOfDofs + + dof_index) = + rShapeFunctionDerivatives[ + control_point_index]; + } + } + } + + Vector base_vector_product_variation; + base_vector_product_variation.resize( + mNumberOfDofs); + base_vector_product_variation.clear(); + + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + base_vector_product_variation(dof_index) = 0; + } else { + for (size_t component = 0; + component < 3; + ++component) + { + base_vector_product_variation(dof_index) += + first_base_vector_variation( + component * mNumberOfDofs + + dof_index) * + rFirstBaseVector[component]; + } + } + } + + Matrix variation_product; + variation_product.resize( + mNumberOfDofs, + mNumberOfDofs); + + variation_product.clear(); + + for (size_t component = 0; + component < 3; + ++component) + { + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + for (size_t second_dof_index = 0; + second_dof_index < mNumberOfDofs; + ++second_dof_index) + { + variation_product( + dof_index, + second_dof_index) += + first_base_vector_variation[ + component * mNumberOfDofs + + dof_index] * + first_base_vector_variation[ + component * mNumberOfDofs + + second_dof_index]; + } + } + } + + for (size_t component = 0; + component < 3; + ++component) + { + for (size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % mDofsPerNode; + + for (size_t second_dof_index = 0; + second_dof_index < mNumberOfDofs; + ++second_dof_index) + { + const size_t second_dof_component = + second_dof_index % mDofsPerNode; + + if ( + dof_component > 2 || + second_dof_component > 2) + { + continue; + } + + rTangentSecondVariation( + component * mNumberOfDofs + + dof_index, + second_dof_index) += + 3.0 * + base_vector_product_variation[dof_index] * + base_vector_product_variation[ + second_dof_index] * + rFirstBaseVector[component] / + first_base_vector_norm_fifth; + + rTangentSecondVariation( + component * mNumberOfDofs + + dof_index, + second_dof_index) += + -( + first_base_vector_variation[ + component * mNumberOfDofs + + dof_index] * + base_vector_product_variation[ + second_dof_index] + + + first_base_vector_variation[ + component * mNumberOfDofs + + second_dof_index] * + base_vector_product_variation[ + dof_index]) + / + first_base_vector_norm_cubed; + + rTangentSecondVariation( + component * mNumberOfDofs + + dof_index, + second_dof_index) += + -variation_product( + dof_index, + second_dof_index) * + rFirstBaseVector[component] / + first_base_vector_norm_cubed; + } + } + } + } + + + void BeamBaseElement3D::ComputeTangentDerivativeVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + Vector& rTangentDerivativeVariation) const + { + rTangentDerivativeVariation.resize(3 * mNumberOfDofs); + rTangentDerivativeVariation.clear(); + + const double first_second_base_vector_product = + inner_prod(rFirstBaseVector, rSecondBaseVector); + + const double first_base_vector_norm = + norm_2(rFirstBaseVector); + + Vector first_base_vector_variation; + first_base_vector_variation.resize(3 * mNumberOfDofs); + first_base_vector_variation.clear(); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if (component == dof_component) { + first_base_vector_variation( + component * mNumberOfDofs + dof_index) = + rShapeFunctionDerivatives[control_point_index]; + } + } + } + + Vector second_base_vector_variation; + second_base_vector_variation.resize(3 * mNumberOfDofs); + second_base_vector_variation.clear(); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if (component == dof_component) { + second_base_vector_variation( + component * mNumberOfDofs + dof_index) = + rShapeFunctionSecondDerivatives[control_point_index]; + } + } + } + + Vector first_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector second_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector first_base_vector_dot_second_variation = + ZeroVector(mNumberOfDofs); + + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + continue; + } + + for (size_t component = 0; component < 3; ++component) { + first_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rFirstBaseVector[component]; + + second_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rSecondBaseVector[component]; + + first_base_vector_dot_second_variation[dof_index] += + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rFirstBaseVector[component]; + } + } + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + rTangentDerivativeVariation[ + component * mNumberOfDofs + dof_index] = 0.0; + + continue; + } + + rTangentDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] / + first_base_vector_norm + - + rSecondBaseVector[component] * + first_base_vector_dot_first_variation[dof_index] / + pow(first_base_vector_norm, 3); + + rTangentDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + 3.0 * + first_base_vector_dot_first_variation[dof_index] * + first_second_base_vector_product * + rFirstBaseVector[component] / + pow(first_base_vector_norm, 5) + - + ( + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_second_base_vector_product + + + ( + first_base_vector_dot_second_variation[dof_index] + + + second_base_vector_dot_first_variation[dof_index] + ) * + rFirstBaseVector[component] + ) / + pow(first_base_vector_norm, 3); + } + } + } + + + void BeamBaseElement3D::ComputeTangentDerivativeSecondVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + Matrix& rTangentDerivativeSecondVariation) const + { + rTangentDerivativeSecondVariation.resize( + 3 * mNumberOfDofs, + mNumberOfDofs); + + rTangentDerivativeSecondVariation.clear(); + + const double first_second_base_vector_product = + inner_prod(rFirstBaseVector, rSecondBaseVector); + + const double first_base_vector_norm = + norm_2(rFirstBaseVector); + + const double first_base_vector_norm_cubed = + pow(first_base_vector_norm, 3); + + const double first_base_vector_norm_fifth = + pow(first_base_vector_norm, 5); + + const double first_base_vector_norm_seventh = + pow(first_base_vector_norm, 7); + + Vector first_base_vector_variation = + ZeroVector(3 * mNumberOfDofs); + + Vector second_base_vector_variation = + ZeroVector(3 * mNumberOfDofs); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if (component == dof_component) { + first_base_vector_variation( + component * mNumberOfDofs + dof_index) += + rShapeFunctionDerivatives[control_point_index]; + + second_base_vector_variation( + component * mNumberOfDofs + dof_index) += + rShapeFunctionSecondDerivatives[control_point_index]; + } + } + } + + Vector first_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector second_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector first_base_vector_dot_second_variation = + ZeroVector(mNumberOfDofs); + + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + continue; + } + + for (size_t component = 0; component < 3; ++component) { + first_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation( + component * mNumberOfDofs + dof_index) * + rFirstBaseVector[component]; + + second_base_vector_dot_first_variation[dof_index] += + rSecondBaseVector[component] * + first_base_vector_variation( + component * mNumberOfDofs + dof_index); + + first_base_vector_dot_second_variation[dof_index] += + rFirstBaseVector[component] * + second_base_vector_variation( + component * mNumberOfDofs + dof_index); + } + } + + Matrix first_variation_product( + mNumberOfDofs, + mNumberOfDofs, + 0.0); + + Matrix first_second_variation_product( + mNumberOfDofs, + mNumberOfDofs, + 0.0); + + Matrix second_first_variation_product( + mNumberOfDofs, + mNumberOfDofs, + 0.0); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + for ( + size_t second_dof_index = 0; + second_dof_index < mNumberOfDofs; + ++second_dof_index) + { + first_variation_product( + dof_index, + second_dof_index) += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_base_vector_variation[ + component * mNumberOfDofs + second_dof_index]; + + first_second_variation_product( + dof_index, + second_dof_index) += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + second_base_vector_variation[ + component * mNumberOfDofs + second_dof_index]; + + second_first_variation_product( + dof_index, + second_dof_index) += + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_base_vector_variation[ + component * mNumberOfDofs + second_dof_index]; + } + } + } + + for (size_t component = 0; component < 3; ++component) { + for ( + size_t second_dof_index = 0; + second_dof_index < mNumberOfDofs; + ++second_dof_index) + { + for ( + size_t dof_index = 0; + dof_index < mNumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % mNumberOfDofs; + + const size_t second_dof_component = + second_dof_index % mNumberOfDofs; + + if ( + dof_component > 2 || + second_dof_component > 2) + { + continue; + } + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + -( + second_base_vector_variation( + component * mNumberOfDofs + dof_index) * + first_base_vector_dot_first_variation[ + second_dof_index] + + + second_base_vector_variation( + component * mNumberOfDofs + second_dof_index) * + first_base_vector_dot_first_variation[ + dof_index] + + + rSecondBaseVector[component] * + first_variation_product( + dof_index, + second_dof_index) + ) / + first_base_vector_norm_cubed; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_base_vector_dot_first_variation[dof_index] * + rSecondBaseVector[component] * + first_base_vector_dot_first_variation[ + second_dof_index] / + first_base_vector_norm_fifth; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_variation_product( + dof_index, + second_dof_index) * + first_second_base_vector_product * + rFirstBaseVector[component] / + first_base_vector_norm_fifth; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_base_vector_dot_first_variation[dof_index] * + ( + second_base_vector_dot_first_variation[ + second_dof_index] + + + first_base_vector_dot_second_variation[ + second_dof_index] + ) * + rFirstBaseVector[component] / + first_base_vector_norm_fifth; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_base_vector_dot_first_variation[dof_index] * + first_base_vector_variation[ + component * mNumberOfDofs + + second_dof_index] * + first_second_base_vector_product / + first_base_vector_norm_fifth; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_base_vector_dot_first_variation[ + second_dof_index] * + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_second_base_vector_product / + first_base_vector_norm_fifth; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + -15.0 * + first_base_vector_dot_first_variation[dof_index] * + first_base_vector_dot_first_variation[ + second_dof_index] * + first_second_base_vector_product * + rFirstBaseVector[component] / + first_base_vector_norm_seventh; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + -( + ( + first_second_variation_product( + dof_index, + second_dof_index) + + + second_first_variation_product( + dof_index, + second_dof_index) + ) * + rFirstBaseVector[component] + + + ( + first_base_vector_dot_second_variation[ + dof_index] + + + second_base_vector_dot_first_variation[ + dof_index] + ) * + first_base_vector_variation[ + component * mNumberOfDofs + + second_dof_index] + + + ( + first_base_vector_dot_second_variation[ + second_dof_index] + + + second_base_vector_dot_first_variation[ + second_dof_index] + ) * + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] + ) / + first_base_vector_norm_cubed; + + rTangentDerivativeSecondVariation( + component * mNumberOfDofs + dof_index, + second_dof_index) += + 3.0 * + first_base_vector_dot_first_variation[ + second_dof_index] * + ( + second_base_vector_dot_first_variation[ + dof_index] + + + first_base_vector_dot_second_variation[ + dof_index] + ) * + rFirstBaseVector[component] / + first_base_vector_norm_fifth; + } + } + } + } + + + void BeamBaseElement3D::ComputeTangentSecondDerivativeVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const Vector& rShapeFunctionThirdDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + const array_1d& rThirdBaseVector, + Vector& rTangentSecondDerivativeVariation) const + { + rTangentSecondDerivativeVariation.resize( + 3 * mNumberOfDofs); + + rTangentSecondDerivativeVariation.clear(); + + const double first_second_base_vector_product = + inner_prod( + rFirstBaseVector, + rSecondBaseVector); + + const double first_second_base_vector_product_derivative = + inner_prod( + rSecondBaseVector, + rSecondBaseVector) + + + inner_prod( + rFirstBaseVector, + rThirdBaseVector); + + const double first_base_vector_norm = + norm_2(rFirstBaseVector); + + Vector first_base_vector_variation = + ZeroVector(3 * mNumberOfDofs); + + Vector second_base_vector_variation = + ZeroVector(3 * mNumberOfDofs); + + Vector third_base_vector_variation = + ZeroVector(3 * mNumberOfDofs); + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + const size_t control_point_index = + dof_index / mDofsPerNode; + + if (component == dof_component) { + first_base_vector_variation( + component * mNumberOfDofs + dof_index) = + rShapeFunctionDerivatives[ + control_point_index]; + + second_base_vector_variation( + component * mNumberOfDofs + dof_index) = + rShapeFunctionSecondDerivatives[ + control_point_index]; + + third_base_vector_variation( + component * mNumberOfDofs + dof_index) = + rShapeFunctionThirdDerivatives[ + control_point_index]; + } + } + } + + Vector first_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector second_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + Vector first_base_vector_dot_second_variation = + ZeroVector(mNumberOfDofs); + + Vector first_base_vector_dot_third_variation = + ZeroVector(mNumberOfDofs); + + Vector second_base_vector_dot_second_variation = + ZeroVector(mNumberOfDofs); + + Vector third_base_vector_dot_first_variation = + ZeroVector(mNumberOfDofs); + + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + continue; + } + + for (size_t component = 0; component < 3; ++component) { + first_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rFirstBaseVector[component]; + + second_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rSecondBaseVector[component]; + + first_base_vector_dot_second_variation[dof_index] += + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rFirstBaseVector[component]; + + first_base_vector_dot_third_variation[dof_index] += + third_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rFirstBaseVector[component]; + + second_base_vector_dot_second_variation[dof_index] += + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rSecondBaseVector[component]; + + third_base_vector_dot_first_variation[dof_index] += + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + rThirdBaseVector[component]; + } + } + + const Vector first_second_product_variation = + first_base_vector_dot_second_variation + + second_base_vector_dot_first_variation; + + const Vector first_second_product_derivative_variation = + 2.0 * second_base_vector_dot_second_variation + + + third_base_vector_dot_first_variation + + + first_base_vector_dot_third_variation; + + for (size_t component = 0; component < 3; ++component) { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % mDofsPerNode; + + if (dof_component > 2) { + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] = 0.0; + + continue; + } + + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + third_base_vector_variation[ + component * mNumberOfDofs + dof_index] / + first_base_vector_norm + - + rThirdBaseVector[component] * + first_base_vector_dot_first_variation[dof_index] / + pow(first_base_vector_norm, 3); + + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + -( + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_second_base_vector_product + + + rSecondBaseVector[component] * + first_second_product_variation[dof_index] + ) / + pow(first_base_vector_norm, 3) + + + 3.0 * + rSecondBaseVector[component] * + first_second_base_vector_product * + first_base_vector_dot_first_variation[dof_index] / + pow(first_base_vector_norm, 5); + + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + -( + second_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_second_base_vector_product + + + rSecondBaseVector[component] * + first_second_product_variation[dof_index] + + + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + first_second_base_vector_product_derivative + + + rFirstBaseVector[component] * + first_second_product_derivative_variation[dof_index] + ) / + pow(first_base_vector_norm, 3) + + + 3.0 * + ( + rSecondBaseVector[component] * + first_second_base_vector_product + + + rFirstBaseVector[component] * + first_second_base_vector_product_derivative + ) * + first_base_vector_dot_first_variation[dof_index] / + pow(first_base_vector_norm, 5); + + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + 3.0 * + ( + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + pow(first_second_base_vector_product, 2) + + + rFirstBaseVector[component] * + 2.0 * + first_second_base_vector_product * + first_second_product_variation[dof_index] + ) / + pow(first_base_vector_norm, 5) + - + 15.0 * + rFirstBaseVector[component] * + pow(first_second_base_vector_product, 2) * + first_base_vector_dot_first_variation[dof_index] / + pow(first_base_vector_norm, 7); + } + } + } + // --------------------------------------------------------------------- + // Beam rotation helpers + // --------------------------------------------------------------------- + // These helpers are local to this translation unit and are not part of + // the BeamBaseElement3D interface. + + namespace + { + + using Matrix3d = BoundedMatrix; + + constexpr double tolerance = 1.0e-8; + + template + auto CrossProduct(Args&&... args) + { + return MathUtils::CrossProduct( + std::forward(args)...); + } + + Matrix3d CrossProductVectorMatrix( + const array_1d& rVector, + const Matrix3d& rMatrix) + { + Matrix3d matrix_vector; + matrix_vector.clear(); + + int levi_civita[3][3][3] = {}; + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + for (std::size_t i = 0; i < 3; ++i) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t l = 0; l < 3; ++l) { + matrix_vector(i, j) += + levi_civita[j][k][l] * + rMatrix(i, k) * + rVector(l); + } + } + } + } + + return matrix_vector; + } + + } + + + void BeamBaseElement3D::ComputeRodriguesMatrix(const array_1d& rAxis, + const double Phi, Matrix3d& rRodriguesMatrix) + { + rRodriguesMatrix.clear(); + + Matrix3d identity_matrix; + identity_matrix.resize(3, 3, false); + identity_matrix.clear(); + + for (SizeType i = 0; i < 3; ++i) { + identity_matrix(i, i) = 1.0; + } + + for (SizeType i = 0; i < 3; ++i) { + rRodriguesMatrix(i, i) = cos(Phi); + } + + rRodriguesMatrix += + CrossProductVectorMatrix( + rAxis, + identity_matrix) * + sin(Phi); + } + + void BeamBaseElement3D::ComputeRodriguesMatrixDerivative( + const array_1d& rAxis, + const array_1d& rAxisDerivative, + const double Phi, + const double PhiDerivative, + Matrix3d& rRodriguesMatrixDerivative) + { + rRodriguesMatrixDerivative.clear(); + + Matrix3d identity_matrix; + identity_matrix.resize(3, 3, false); + identity_matrix.clear(); + + for (SizeType i = 0; i < 3; ++i) { + identity_matrix(i, i) = 1.0; + } + + for (SizeType i = 0; i < 3; ++i) { + rRodriguesMatrixDerivative(i, i) = + -PhiDerivative * sin(Phi); + } + + rRodriguesMatrixDerivative += + CrossProductVectorMatrix( + rAxis, + identity_matrix) * + cos(Phi) * + PhiDerivative; + + rRodriguesMatrixDerivative += + CrossProductVectorMatrix( + rAxisDerivative, + identity_matrix) * + sin(Phi); + } + + void BeamBaseElement3D::ComputeRodriguesMatrixVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const Vector& rShapeFunctions, + const double Phi, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixVariation) + { + rRodriguesMatrixVariation.clear(); + + int levi_civita[3][3][3] = {}; + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + for (size_t row_component = 0; row_component < 3; ++row_component) { + for (size_t column_component = 0; column_component < 3; ++column_component) { + for (size_t dof_index = 0; dof_index < NumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % DofsPerNode; + + const size_t control_point_index = + dof_index / DofsPerNode; + + if (row_component == column_component) { + if (dof_component > 2) { + rRodriguesMatrixVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + -sin(Phi) * + rShapeFunctions[control_point_index]; + } + } else if (dof_component > 2) { + for (SizeType k = 0; k < 3; ++k) { + rRodriguesMatrixVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + cos(Phi) * + rShapeFunctions[control_point_index] * + levi_civita[row_component][k][column_component] * + rAxis[k]; + } + } + + for (SizeType k = 0; k < 3; ++k) { + rRodriguesMatrixVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + dof_index]; + } + } + } + } + } + + + void BeamBaseElement3D::ComputeRodriguesMatrixSecondVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const Matrix& rAxisSecondVariation, + const Vector& rShapeFunctions, + const double Phi, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixSecondVariation) + { + rRodriguesMatrixSecondVariation.clear(); + + int levi_civita[3][3][3] = {}; + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector phi_variation = + ZeroVector(NumberOfDofs); + + for (size_t dof_index = 0; dof_index < NumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % DofsPerNode; + + const size_t control_point_index = + dof_index / DofsPerNode; + + if (dof_component > 2) { + phi_variation(dof_index) = + rShapeFunctions[control_point_index]; + } + } + + for (size_t row_component = 0; row_component < 3; ++row_component) { + for (size_t column_component = 0; column_component < 3; ++column_component) { + for (size_t second_dof_index = 0; + second_dof_index < NumberOfDofs; + ++second_dof_index) + { + const size_t second_dof_component = + second_dof_index % DofsPerNode; + + for (size_t dof_index = 0; + dof_index < NumberOfDofs; + ++dof_index) + { + const size_t dof_component = + dof_index % DofsPerNode; + + if ( + row_component == column_component && + (dof_component > 2 || + second_dof_component > 2)) + { + rRodriguesMatrixSecondVariation( + row_component * NumberOfDofs + dof_index, + column_component * NumberOfDofs + + second_dof_index) += + -cos(Phi) * + phi_variation[dof_index] * + phi_variation[second_dof_index]; + } + + for (SizeType k = 0; k < 3; ++k) { + if ( + dof_component > 2 || + second_dof_component > 2) + { + rRodriguesMatrixSecondVariation( + row_component * NumberOfDofs + dof_index, + column_component * NumberOfDofs + + second_dof_index) += + -sin(Phi) * + phi_variation[dof_index] * + phi_variation[second_dof_index] * + levi_civita[row_component][k][column_component] * + rAxis[k] + + + phi_variation[dof_index] * + cos(Phi) * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + + second_dof_index] + + + phi_variation[second_dof_index] * + cos(Phi) * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + + dof_index]; + } else { + rRodriguesMatrixSecondVariation( + row_component * NumberOfDofs + dof_index, + column_component * NumberOfDofs + + second_dof_index) += + sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisSecondVariation( + k * NumberOfDofs + dof_index, + second_dof_index); + } + } + } + } + } + } + } + + + void BeamBaseElement3D::ComputeRodriguesMatrixDerivativeVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixDerivativeVariation) + { + rRodriguesMatrixDerivativeVariation.clear(); + + int levi_civita[3][3][3] = {}; + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector phi_variation = + ZeroVector(NumberOfDofs); + + for ( + size_t control_point_index = 0; + control_point_index < NumberOfDofs / DofsPerNode; + ++control_point_index) + { + phi_variation( + control_point_index * DofsPerNode + 3) = + rShapeFunctions(control_point_index); + } + + Vector phi_derivative_variation = + ZeroVector(NumberOfDofs); + + for ( + size_t control_point_index = 0; + control_point_index < NumberOfDofs / DofsPerNode; + ++control_point_index) + { + phi_derivative_variation( + control_point_index * DofsPerNode + 3) = + rShapeFunctionDerivatives(control_point_index); + } + + for (size_t row_component = 0; row_component < 3; ++row_component) { + for (size_t column_component = 0; column_component < 3; ++column_component) { + for (size_t dof_index = 0; dof_index < NumberOfDofs; ++dof_index) { + const size_t dof_component = + dof_index % DofsPerNode; + + const size_t control_point_index = + dof_index / DofsPerNode; + + if ( + row_component == column_component && + dof_component > 2) + { + rRodriguesMatrixDerivativeVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + -phi_derivative_variation(dof_index) * + sin(Phi) + - + cos(Phi) * + PhiDerivative * + rShapeFunctions[control_point_index]; + } + + for (SizeType k = 0; k < 3; ++k) { + if (dof_component > 2) { + rRodriguesMatrixDerivativeVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + ( + phi_derivative_variation(dof_index) * + cos(Phi) + - + PhiDerivative * + rShapeFunctions[control_point_index] * + sin(Phi) + ) * + levi_civita[row_component][k][column_component] * + rAxis[k] + + + cos(Phi) * + phi_variation(dof_index) * + levi_civita[row_component][k][column_component] * + rAxisDerivative[k]; + } else { + rRodriguesMatrixDerivativeVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + cos(Phi) * + PhiDerivative * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + dof_index] + + + sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisDerivativeVariation[ + k * NumberOfDofs + dof_index]; + } + } + } + } + } + } + + + void BeamBaseElement3D::ComputeRodriguesMatrixDerivativeSecondVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Matrix& rAxisSecondVariation, + const Matrix& rAxisDerivativeSecondVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixDerivativeSecondVariation) + { + rRodriguesMatrixDerivativeSecondVariation.clear(); + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + + Vector phi_variation; + phi_variation.resize(NumberOfDofs); + phi_variation.clear(); + Vector phi_derivative_variation; + phi_derivative_variation.resize(NumberOfDofs); + phi_derivative_variation.clear(); + + for (size_t r = 0;r < NumberOfDofs / DofsPerNode;r++) + { + phi_variation(r * DofsPerNode + 3) = rShapeFunctions[r]; + phi_derivative_variation(r * DofsPerNode + 3) = rShapeFunctionDerivatives(r); + } + + double cos_phi; + cos_phi = cos(Phi); + double sin_phi; + sin_phi = sin(Phi); + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + + for (size_t s = 0;s < NumberOfDofs;s++) + { + + + if (t == u) + { + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * cos_phi - phi_derivative_variation(s) * phi_variation(r) * cos_phi + sin_phi * PhiDerivative * phi_variation[r] * phi_variation[s]; + } + + { + for (int k = 0; k < 3; k++) + { + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * sin_phi * levi_civita[t][k][u] * rAxis[k] + - phi_derivative_variation(s) * phi_variation(r) * sin_phi * levi_civita[t][k][u] * rAxis[k] + + phi_derivative_variation(r) * cos_phi * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + + phi_derivative_variation(s) * cos_phi * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + - cos_phi * PhiDerivative * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + - sin_phi * PhiDerivative * phi_variation[r] * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + - sin_phi * PhiDerivative * phi_variation[s] * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + + cos_phi * PhiDerivative * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s) + - phi_variation[r] * phi_variation[s] * sin_phi * levi_civita[t][k][u] * rAxisDerivative[k] + + phi_variation[r] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + s] + + phi_variation[s] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + ; + + + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); + + } + } + } + } + } + } + } + + void BeamBaseElement3D::ComputeRodriguesMatrixSecondDerivativeVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const array_1d& rAxisSecondDerivative, + const Vector& rAxisSecondDerivativeVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const double Phi, + const double PhiDerivative, + const double PhiSecondDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixSecondDerivativeVariation) + { + + rRodriguesMatrixSecondDerivativeVariation.resize(3 * NumberOfDofs, 3); + rRodriguesMatrixSecondDerivativeVariation.clear(); + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + for (size_t t = 0; t < 3; t++) + { + for (size_t u = 0; u < 3; u++) + { + for (size_t r = 0; r < NumberOfDofs; r++) + { + size_t xyz = r % DofsPerNode; + size_t i= r / DofsPerNode; + if (t == u) + { + if (xyz > 2) + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -rShapeFunctionSecondDerivatives[i] * sin(Phi) - cos(Phi) * PhiSecondDerivative * rShapeFunctions[i] - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * cos(Phi) + sin(Phi) * pow(PhiDerivative, 2) * rShapeFunctions[i]; + else + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 0; + } + + { + for (int k = 0; k < 3; k++) + { + if (xyz > 2) + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (rShapeFunctionSecondDerivatives[i] * cos(Phi) - PhiSecondDerivative * rShapeFunctions[i] * sin(Phi) - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * sin(Phi) - pow(PhiDerivative, 2) * rShapeFunctions[i] * cos(Phi)) * levi_civita[t][k][u] * rAxis[k] + 2 * (cos(Phi) * rShapeFunctionDerivatives[i] - sin(Phi) * rShapeFunctions[i] * PhiDerivative) * levi_civita[t][k][u] * rAxisDerivative[k] + cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxisSecondDerivative[k]; + else + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + 2 * PhiDerivative * cos(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisSecondDerivativeVariation[k * NumberOfDofs + r]; + } + } + } + } + } + + } + + void BeamBaseElement3D::ComputeRodriguesMatrixVariations( + const array_1d& rAxis, + const array_1d& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Matrix& rAxisSecondVariation, + const Matrix& rAxisDerivativeSecondVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixVariation, + Matrix& rRodriguesMatrixDerivativeVariation, + Matrix& rRodriguesMatrixSecondVariation, + Matrix& rRodriguesMatrixDerivativeSecondVariation) + { + + rRodriguesMatrixVariation.clear(); + + rRodriguesMatrixDerivativeVariation.clear(); + + rRodriguesMatrixSecondVariation.clear(); + + rRodriguesMatrixDerivativeSecondVariation.clear(); + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector phi_variation; + phi_variation.resize(NumberOfDofs); + phi_variation.clear(); + Vector phi_derivative_variation; + phi_derivative_variation.resize(NumberOfDofs); + phi_derivative_variation.clear(); + + for (size_t r = 0;r < NumberOfDofs / DofsPerNode;r++) + { + phi_variation(r * DofsPerNode + 3) = rShapeFunctions[r]; + phi_derivative_variation(r * DofsPerNode + 3) = rShapeFunctionDerivatives(r); + } + + double cos_phi; + cos_phi = cos(Phi); + double sin_phi; + sin_phi = sin(Phi); + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + size_t i= r / DofsPerNode; + if (t == u) + { + if (xyz_r > 2) + { + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += -sin(Phi) * rShapeFunctions[i]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -phi_derivative_variation(r) * sin(Phi) - cos(Phi) * PhiDerivative * rShapeFunctions[i]; + } + } + for (int k = 0; k < 3; k++) + { + if (xyz_r > 2) + { + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxis[k]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (phi_derivative_variation(r) * cos(Phi) - PhiDerivative * rShapeFunctions[i] * sin(Phi)) * levi_civita[t][k][u] * rAxis[k] + cos(Phi) * phi_variation(r) * levi_civita[t][k][u] * rAxisDerivative[k]; + } + else + { + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += sin(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += cos(Phi) * PhiDerivative * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r]; + } + } + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyz_s = s % DofsPerNode; + + if (t == u) + { + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -cos(Phi) * phi_variation[r] * phi_variation[s]; + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * cos_phi - phi_derivative_variation(s) * phi_variation(r) * cos_phi + sin_phi * PhiDerivative * phi_variation[r] * phi_variation[s]; + } + + { + for (int k = 0; k < 3; k++) + { + if (xyz_r > 2 || xyz_s > 2) + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -sin(Phi) * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + phi_variation[r] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + phi_variation[s] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; + else + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin(Phi) * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s); + + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * sin_phi * levi_civita[t][k][u] * rAxis[k] + - phi_derivative_variation(s) * phi_variation(r) * sin_phi * levi_civita[t][k][u] * rAxis[k] + + phi_derivative_variation(r) * cos_phi * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + + phi_derivative_variation(s) * cos_phi * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + - cos_phi * PhiDerivative * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + - sin_phi * PhiDerivative * phi_variation[r] * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + - sin_phi * PhiDerivative * phi_variation[s] * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + + cos_phi * PhiDerivative * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s) + - phi_variation[r] * phi_variation[s] * sin_phi * levi_civita[t][k][u] * rAxisDerivative[k] + + phi_variation[r] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + s] + + phi_variation[s] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + ; + + + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); + } + } + } + } + } + } + } + + + + void BeamBaseElement3D::ComputeRodriguesMatrixSecondDerivative( + const array_1d& rAxis, + const array_1d& rAxisDerivative, + const array_1d& rAxisSecondDerivative, + const double Phi, + const double PhiDerivative, + const double PhiSecondDerivative, + Matrix3d& rRodriguesMatrixSecondDerivative) + { + rRodriguesMatrixSecondDerivative.clear(); + + Matrix3d identity_matrix; + identity_matrix.clear(); + for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1; } + + for (int i = 0; i < 3; i++) { rRodriguesMatrixSecondDerivative(i, i) = -PhiSecondDerivative * sin(Phi) - pow(PhiDerivative, 2) * cos(Phi); } + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxis, identity_matrix) * (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)); + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisDerivative, identity_matrix) * 2 * PhiDerivative * cos(Phi); + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisSecondDerivative, identity_matrix) * sin(Phi); + } + + void BeamBaseElement3D::ComputeLambdaMatrix(const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, Matrix3d& rLambdaMatrix) + { + rLambdaMatrix.clear(); + Matrix3d lambda_matrix_auxiliary; + lambda_matrix_auxiliary.clear(); + double scaling_factor; + + Matrix3d identity_matrix; + identity_matrix.resize(3, 3, false); + identity_matrix.clear(); + for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } + array_1d reference_cross_current; + CrossProduct(reference_cross_current, rReferenceTangent, rCurrentTangent); + double cross_product_norm = norm_2(reference_cross_current); + array_1d& rotation_axis = reference_cross_current; + if (cross_product_norm > 0.000000000001) rotation_axis = rotation_axis / cross_product_norm; + + if ((inner_prod(rReferenceTangent, rCurrentTangent) + 1.0)> tolerance) + { + for (int i = 0; i < 3; i++) { rLambdaMatrix(i, i) = inner_prod(rReferenceTangent, rCurrentTangent); } + rLambdaMatrix += CrossProductVectorMatrix(CrossProduct(rReferenceTangent, rCurrentTangent), identity_matrix); + + array_1d cross_product = CrossProduct(rReferenceTangent, rCurrentTangent); + lambda_matrix_auxiliary = outer_prod(cross_product, cross_product); + scaling_factor = 1.0 / (1.0 + inner_prod(rReferenceTangent, rCurrentTangent)); + lambda_matrix_auxiliary = lambda_matrix_auxiliary * scaling_factor; + rLambdaMatrix += lambda_matrix_auxiliary; + } + else + { + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + rLambdaMatrix(i, j) = (rotation_axis(i) * rotation_axis(j)) * (1 - inner_prod(rReferenceTangent, rCurrentTangent)) + inner_prod(rReferenceTangent, rCurrentTangent) * identity_matrix(i, j); + } + } + rLambdaMatrix += CrossProductVectorMatrix(reference_cross_current, identity_matrix); + } + + } + + + void BeamBaseElement3D::ComputeLambdaMatrixDerivative( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rCurrentTangentDerivative, + Matrix3d& rLambdaMatrixDerivative) + { + rLambdaMatrixDerivative.clear(); + + double scaling_factor; + + Matrix3d identity_matrix; + identity_matrix.clear(); + for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + array_1d reference_cross_current = CrossProduct(rReferenceTangent, rCurrentTangent); + array_1d reference_cross_current_derivative = CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + array_1d reference_derivative_cross_current = CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + array_1d tangent_cross_product_derivative = reference_cross_current_derivative + reference_derivative_cross_current; + + for (int i = 0; i < 3; i++) { rLambdaMatrixDerivative(i, i) = reference_dot_current_derivative + reference_derivative_dot_current; } + rLambdaMatrixDerivative += CrossProductVectorMatrix(tangent_cross_product_derivative, identity_matrix); + scaling_factor = -(reference_dot_current_derivative + reference_derivative_dot_current) / pow((1.0 + tangent_dot_product), 2); + rLambdaMatrixDerivative += outer_prod(reference_cross_current, reference_cross_current) * scaling_factor; + scaling_factor = 1.0 / (1.0 + tangent_dot_product); + rLambdaMatrixDerivative += outer_prod(tangent_cross_product_derivative, reference_cross_current) * scaling_factor; + rLambdaMatrixDerivative += outer_prod(reference_cross_current, tangent_cross_product_derivative) * scaling_factor; + + } + + + void BeamBaseElement3D::ComputeLambdaMatrixSecondDerivative( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rCurrentTangentDerivative, + const array_1d& rReferenceTangentSecondDerivative, + const array_1d& rCurrentTangentSecondDerivative, + Matrix3d& rLambdaMatrixSecondDerivative) + { + rLambdaMatrixSecondDerivative.clear(); + + double scaling_factor; + + Matrix3d identity_matrix; + identity_matrix.clear(); + for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + double tangent_derivative_dot_product = inner_prod(rReferenceTangentDerivative, rCurrentTangentDerivative); + double reference_second_derivative_dot_current = inner_prod(rReferenceTangentSecondDerivative, rCurrentTangent); + double reference_dot_current_second_derivative = inner_prod(rReferenceTangent, rCurrentTangentSecondDerivative); + double tangent_dot_product_derivative = reference_derivative_dot_current + reference_dot_current_derivative; + double tangent_dot_product_second_derivative = reference_second_derivative_dot_current + 2 * tangent_derivative_dot_product + reference_dot_current_second_derivative; + array_1d reference_cross_current = CrossProduct(rReferenceTangent, rCurrentTangent); + array_1d reference_cross_current_derivative = CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + array_1d reference_derivative_cross_current = CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + array_1d reference_derivative_cross_current_derivative = CrossProduct(rReferenceTangentDerivative, rCurrentTangentDerivative); + array_1d reference_second_derivative_cross_current = CrossProduct(rReferenceTangentSecondDerivative, rCurrentTangent); + array_1d reference_cross_current_second_derivative = CrossProduct(rReferenceTangent, rCurrentTangentSecondDerivative); + array_1d tangent_cross_product_derivative = reference_cross_current_derivative + reference_derivative_cross_current; + array_1d tangent_cross_product_second_derivative = reference_second_derivative_cross_current + 2 * reference_derivative_cross_current_derivative + reference_cross_current_second_derivative; + + for (int i = 0; i < 3; i++) { rLambdaMatrixSecondDerivative(i, i) = tangent_dot_product_second_derivative; } + + rLambdaMatrixSecondDerivative += CrossProductVectorMatrix(tangent_cross_product_second_derivative, identity_matrix); + scaling_factor = 2 * pow(tangent_dot_product_derivative, 2) / pow((1.0 + tangent_dot_product), 3) - tangent_dot_product_second_derivative / pow((1.0 + tangent_dot_product), 2); + rLambdaMatrixSecondDerivative += outer_prod(reference_cross_current, reference_cross_current) * scaling_factor; + scaling_factor = -tangent_dot_product_derivative / pow((1.0 + tangent_dot_product), 2) * 2; + rLambdaMatrixSecondDerivative += outer_prod(tangent_cross_product_derivative, reference_cross_current) * scaling_factor; + rLambdaMatrixSecondDerivative += outer_prod(reference_cross_current, tangent_cross_product_derivative) * scaling_factor; + scaling_factor = 1.0 / (1.0 + tangent_dot_product); + rLambdaMatrixSecondDerivative += outer_prod(tangent_cross_product_second_derivative, reference_cross_current) * scaling_factor; + rLambdaMatrixSecondDerivative += outer_prod(tangent_cross_product_derivative, tangent_cross_product_derivative) * 2 * scaling_factor; + rLambdaMatrixSecondDerivative += outer_prod(reference_cross_current, tangent_cross_product_second_derivative) * scaling_factor; + + } + + + void BeamBaseElement3D::ComputeLambdaMatrixVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const Vector& rCurrentTangentVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixVariation) + { + + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + + rLambdaMatrixVariation.clear(); + + Matrix3d identity_matrix; + identity_matrix.clear(); + for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Vector reference_cross_current; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current.resize(3); + + reference_cross_current_variation.clear(); + reference_cross_current.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + for (size_t u = 0;u < 3;u++) + { + for (size_t k = 0;k < 3;k++) + { + if (xyz > 2) + reference_cross_current_variation[t * NumberOfDofs + r] += 0; + else + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + } + } + } + } + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + + if (xyz > 2) + tangent_dot_product_variation(r) = 0; + else + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (t == u) + { + if (xyz > 2) + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += 0; + else + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += tangent_dot_product_variation(r); + } + for (int k = 0; k < 3; k++) + { + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; + } + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + } + } + } + } + + void BeamBaseElement3D::ComputeLambdaMatrixSecondVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const Vector& rCurrentTangentVariation, + const Matrix& rCurrentTangentSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixSecondVariation) + { + + + rLambdaMatrixSecondVariation.clear(); + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Matrix reference_cross_current_second_variation; + Vector reference_cross_current; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_cross_current.resize(3); + + reference_cross_current_variation.clear(); + reference_cross_current_second_variation.clear(); + reference_cross_current.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + tangent_dot_product_variation(r) = 0; + else + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + } + } + + Matrix tangent_dot_product_second_variation; + tangent_dot_product_second_variation.resize(NumberOfDofs, NumberOfDofs); + tangent_dot_product_second_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzr = r % DofsPerNode; + size_t xyzs = s % DofsPerNode; + + if (xyzr > 2 || xyzs > 2) + tangent_dot_product_second_variation(r, s) += 0; + else + tangent_dot_product_second_variation(r, s) += rCurrentTangentSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangent[t]; + } + } + } + + + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t u = 0;u < 3;u++) + { + for (size_t k = 0;k < 3;k++) + { + if (xyz_r > 2) + reference_cross_current_variation[t * NumberOfDofs + r] += 0; + else + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyz_s = s % DofsPerNode; + for (size_t k = 0;k < 3;k++) + { + if (xyz_r > 2 || xyz_s > 2) + reference_cross_current_second_variation(t * NumberOfDofs + r, s) += 0; + else + reference_cross_current_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentSecondVariation(u * NumberOfDofs + r, s); + } + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyzr = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzs = s % DofsPerNode; + if (xyzr > 2 || xyzs > 2) rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) = 0; + else + { + if (t == u) + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += tangent_dot_product_second_variation(r, s); + else + { + for (int k = 0; k < 3; k++) + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); + } + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + - tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + s, r)); + } + } + } + } + } + } + + void BeamBaseElement3D::ComputeLambdaMatrixDerivativeVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixDerivativeVariation) + { + + rLambdaMatrixDerivativeVariation.clear(); + + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Vector reference_cross_current_derivative_variation; + Vector reference_derivative_cross_current_variation; + Vector reference_cross_current; + Vector tangent_cross_product_derivative; + Vector reference_derivative_cross_current; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current_derivative_variation.resize(NumberOfDofs * 3); + reference_derivative_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current.resize(3); + tangent_cross_product_derivative.resize(3); + reference_derivative_cross_current.resize(3); + + reference_cross_current_variation.clear(); + reference_cross_current_derivative_variation.clear(); + reference_derivative_cross_current_variation.clear(); + reference_cross_current.clear(); + tangent_cross_product_derivative.clear(); + reference_derivative_cross_current.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + tangent_cross_product_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t k = 0;k < 3;k++) + { + size_t xyz = r % DofsPerNode; + if (xyz > 2) + { + reference_cross_current_variation[t * NumberOfDofs + r] = 0; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] = 0; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] = 0; + } + else + { + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeVariation[u * NumberOfDofs + r]; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + } + } + } + } + } + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + Vector tangent_dot_product_derivative_variation; + tangent_dot_product_derivative_variation.resize(NumberOfDofs); + tangent_dot_product_derivative_variation.clear(); + Vector reference_derivative_dot_current_variation; + reference_derivative_dot_current_variation.resize(NumberOfDofs); + reference_derivative_dot_current_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + { + tangent_dot_product_variation(r) += 0; + tangent_dot_product_derivative_variation(r) += 0; + reference_derivative_dot_current_variation(r) += 0; + } + else + { + + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + tangent_dot_product_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; + } + } + } + + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 0; + else + { + if (t == u) + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r); + + else + { + { + for (int k = 0; k < 3; k++) + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; + } + + } + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / pow(1.0 + tangent_dot_product, 2) * ((tangent_cross_product_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (tangent_cross_product_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_variation[t * NumberOfDofs + r] + reference_derivative_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + (reference_cross_current_variation[t * NumberOfDofs + r]) * (tangent_cross_product_derivative[u] + reference_derivative_cross_current[u]) + (tangent_cross_product_derivative[t] + reference_derivative_cross_current[t]) * (reference_cross_current_variation[u * NumberOfDofs + r]) + reference_cross_current[t] * (reference_cross_current_derivative_variation[u * NumberOfDofs + r] + reference_derivative_cross_current_variation[u * NumberOfDofs + r])); + } + + } + } + } + + } + + + void BeamBaseElement3D::ComputeLambdaMatrixSecondDerivativeVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rReferenceTangentSecondDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const array_1d& rCurrentTangentSecondDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Vector& rCurrentTangentSecondDerivativeVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixSecondDerivativeVariation) + { + + rLambdaMatrixSecondDerivativeVariation.resize(3 * NumberOfDofs, 3); + rLambdaMatrixSecondDerivativeVariation.clear(); + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + double reference_second_derivative_dot_current = inner_prod(rReferenceTangentSecondDerivative, rCurrentTangent); + double tangent_derivative_dot_product = inner_prod(rReferenceTangentDerivative, rCurrentTangentDerivative); + double reference_dot_current_second_derivative = inner_prod(rReferenceTangent, rCurrentTangentSecondDerivative); + double tangent_dot_product_derivative = reference_derivative_dot_current + reference_dot_current_derivative; + double tangent_dot_product_second_derivative = reference_second_derivative_dot_current + 2 * tangent_derivative_dot_product + reference_dot_current_second_derivative; + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Vector reference_cross_current_derivative_variation; + Vector reference_derivative_cross_current_variation; + Vector reference_second_derivative_cross_current_variation; + Vector reference_derivative_cross_current_derivative_variation; + Vector reference_cross_current_second_derivative_variation; + Vector reference_cross_current; + Vector reference_cross_current_derivative; + Vector reference_derivative_cross_current; + Vector reference_cross_current_second_derivative; + Vector reference_second_derivative_cross_current; + Vector reference_derivative_cross_current_derivative; + Vector tangent_cross_product_derivative; + Vector tangent_cross_product_second_derivative; + Vector tangent_cross_product_derivative_variation; + Vector tangent_cross_product_second_derivative_variation; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current_derivative_variation.resize(NumberOfDofs * 3); + reference_derivative_cross_current_variation.resize(NumberOfDofs * 3); + reference_second_derivative_cross_current_variation.resize(NumberOfDofs * 3); + reference_derivative_cross_current_derivative_variation.resize(NumberOfDofs * 3); + reference_cross_current_second_derivative_variation.resize(NumberOfDofs * 3); + tangent_cross_product_derivative_variation.resize(NumberOfDofs * 3); + tangent_cross_product_second_derivative_variation.resize(NumberOfDofs * 3); + reference_cross_current.resize(3); + reference_cross_current_derivative.resize(3); + reference_derivative_cross_current.resize(3); + reference_second_derivative_cross_current.resize(3); + reference_derivative_cross_current_derivative.resize(3); + reference_cross_current_second_derivative.resize(3); + tangent_cross_product_derivative.resize(3); + tangent_cross_product_second_derivative.resize(3); + + reference_cross_current_variation.clear(); + reference_cross_current_derivative_variation.clear(); + reference_derivative_cross_current_variation.clear(); + reference_second_derivative_cross_current_variation.clear(); + reference_derivative_cross_current_derivative_variation.clear(); + reference_cross_current_second_derivative_variation.clear(); + reference_cross_current.clear(); + reference_cross_current_derivative.clear(); + reference_derivative_cross_current.clear(); + reference_second_derivative_cross_current.clear(); + reference_derivative_cross_current_derivative.clear(); + reference_cross_current_second_derivative.clear(); + tangent_cross_product_derivative.clear(); + tangent_cross_product_second_derivative.clear(); + tangent_cross_product_derivative_variation.clear(); + tangent_cross_product_second_derivative_variation.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + reference_cross_current_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + reference_second_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentSecondDerivative, rCurrentTangent); + reference_derivative_cross_current_derivative = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangentDerivative); + reference_cross_current_second_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentSecondDerivative); + tangent_cross_product_derivative = reference_cross_current_derivative + reference_derivative_cross_current; + tangent_cross_product_second_derivative = 2 * reference_derivative_cross_current_derivative + reference_second_derivative_cross_current + reference_cross_current_second_derivative; + + for (size_t t = 0; t < 3; t++) + { + for (size_t r = 0; r < NumberOfDofs; r++) + { + for (size_t u = 0; u < 3; u++) + { + for (size_t k = 0; k < 3; k++) + { + size_t xyz = r % DofsPerNode; + if (xyz > 2) + { + reference_cross_current_variation[t * NumberOfDofs + r] = 0; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] = 0; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] = 0; + reference_second_derivative_cross_current_variation[t * NumberOfDofs + r] = 0; + reference_derivative_cross_current_derivative_variation[t * NumberOfDofs + r] = 0; + reference_cross_current_second_derivative_variation[t * NumberOfDofs + r] = 0; + } + else + { + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeVariation[u * NumberOfDofs + r]; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_second_derivative_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentSecondDerivative[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_derivative_cross_current_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentDerivativeVariation[u * NumberOfDofs + r]; + reference_cross_current_second_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentSecondDerivativeVariation[u * NumberOfDofs + r]; + } + } + } + } + } + tangent_cross_product_derivative_variation = reference_cross_current_derivative_variation + reference_derivative_cross_current_variation; + tangent_cross_product_second_derivative_variation = 2 * reference_derivative_cross_current_derivative_variation + reference_second_derivative_cross_current_variation + reference_cross_current_second_derivative_variation; + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + Vector reference_dot_current_derivative_variation; + reference_dot_current_derivative_variation.resize(NumberOfDofs); + reference_dot_current_derivative_variation.clear(); + Vector reference_derivative_dot_current_variation; + reference_derivative_dot_current_variation.resize(NumberOfDofs); + reference_derivative_dot_current_variation.clear(); + Vector tangent_derivative_dot_product_variation; + tangent_derivative_dot_product_variation.resize(NumberOfDofs); + tangent_derivative_dot_product_variation.clear(); + Vector reference_second_derivative_dot_current_variation; + reference_second_derivative_dot_current_variation.resize(NumberOfDofs); + reference_second_derivative_dot_current_variation.clear(); + Vector reference_dot_current_second_derivative_variation; + reference_dot_current_second_derivative_variation.resize(NumberOfDofs); + reference_dot_current_second_derivative_variation.clear(); + + for (size_t t = 0; t < 3; t++) + { + for (size_t r = 0; r < NumberOfDofs; r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + { + tangent_dot_product_variation(r) += 0; + reference_dot_current_derivative_variation(r) += 0; + reference_derivative_dot_current_variation(r) += 0; + tangent_derivative_dot_product_variation(r) += 0; + reference_second_derivative_dot_current_variation(r) += 0; + reference_dot_current_second_derivative_variation(r) += 0; + } + else + { + + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + reference_dot_current_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; + reference_second_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentSecondDerivative[t]; + tangent_derivative_dot_product_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; + reference_dot_current_second_derivative_variation(r) += rCurrentTangentSecondDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + } + } + } + Vector tangent_dot_product_derivative_variation; + tangent_dot_product_derivative_variation.resize(NumberOfDofs); + tangent_dot_product_derivative_variation.clear(); + Vector tangent_dot_product_second_derivative_variation; + tangent_dot_product_second_derivative_variation.resize(NumberOfDofs); + tangent_dot_product_second_derivative_variation.clear(); + + tangent_dot_product_derivative_variation = reference_derivative_dot_current_variation + reference_dot_current_derivative_variation; + tangent_dot_product_second_derivative_variation = reference_second_derivative_dot_current_variation + 2 * tangent_derivative_dot_product_variation + reference_dot_current_second_derivative_variation; + + double inverse_one_plus_tangent_dot_squared = 1.0 / pow(1.0 + tangent_dot_product, 2); + double inverse_one_plus_tangent_dot_cubed = 1.0 / pow(1.0 + tangent_dot_product, 3); + double inverse_one_plus_tangent_dot_fourth = 1.0 / pow(1.0 + tangent_dot_product, 4); + + for (size_t t = 0; t < 3; t++) + { + for (size_t u = 0; u < 3; u++) + { + for (size_t r = 0; r < NumberOfDofs; r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 0; + else + { + if (t == u) + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += tangent_dot_product_second_derivative_variation(r); + + else + { + { + for (int k = 0; k < 3; k++) + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * tangent_cross_product_second_derivative_variation[r + k * NumberOfDofs]; + } + + } + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative_variation(r) * inverse_one_plus_tangent_dot_squared + 2 * (tangent_dot_product_variation(r) * tangent_dot_product_second_derivative + 2 * tangent_dot_product_derivative_variation[r] * tangent_dot_product_derivative) * inverse_one_plus_tangent_dot_cubed - 6 * (pow(tangent_dot_product_derivative, 2) * tangent_dot_product_variation[r]) * inverse_one_plus_tangent_dot_fourth) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative * inverse_one_plus_tangent_dot_squared + 2 * pow(tangent_dot_product_derivative, 2) * inverse_one_plus_tangent_dot_cubed) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (4 * tangent_dot_product_derivative * tangent_dot_product_variation[r] * inverse_one_plus_tangent_dot_cubed - 2 * tangent_dot_product_derivative_variation[r] * inverse_one_plus_tangent_dot_squared) * (tangent_cross_product_derivative[t] * reference_cross_current[u] + reference_cross_current[t] * tangent_cross_product_derivative[u]); + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -2 * tangent_dot_product_derivative * inverse_one_plus_tangent_dot_squared * (tangent_cross_product_derivative_variation[t * NumberOfDofs + r] * reference_cross_current[u] + tangent_cross_product_derivative[t] * reference_cross_current_variation[u * NumberOfDofs + r] + reference_cross_current_variation[t * NumberOfDofs + r] * tangent_cross_product_derivative[u] + reference_cross_current[t] * tangent_cross_product_derivative_variation[u * NumberOfDofs + r]); + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation(r) * inverse_one_plus_tangent_dot_squared * (tangent_cross_product_second_derivative[t] * reference_cross_current[u] + 2 * tangent_cross_product_derivative[t] * tangent_cross_product_derivative[u] + reference_cross_current[t] * tangent_cross_product_second_derivative[u]); + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * (tangent_cross_product_second_derivative_variation[t * NumberOfDofs + r] * reference_cross_current[u] + tangent_cross_product_second_derivative[t] * reference_cross_current_variation[u * NumberOfDofs + r] + 2 * tangent_cross_product_derivative_variation[t * NumberOfDofs + r] * tangent_cross_product_derivative[u] + 2 * tangent_cross_product_derivative[t] * tangent_cross_product_derivative_variation[u * NumberOfDofs + r] + reference_cross_current_variation[t * NumberOfDofs + r] * tangent_cross_product_second_derivative[u] + reference_cross_current[t] * tangent_cross_product_second_derivative_variation[u * NumberOfDofs + r]); + } + + } + } + } + + } + +void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Matrix& rCurrentTangentSecondVariation, + const Matrix& rCurrentTangentDerivativeSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixDerivativeSecondVariation) + { + + rLambdaMatrixDerivativeSecondVariation.clear(); + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + double tangent_dot_product_derivative = reference_dot_current_derivative + reference_derivative_dot_current; + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Vector reference_cross_current_derivative_variation; + Vector reference_cross_current; + Vector reference_cross_current_derivative; + Vector reference_derivative_cross_current; + Vector reference_derivative_cross_current_variation; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current_derivative_variation.resize(NumberOfDofs * 3); + reference_cross_current.resize(3); + reference_cross_current_derivative.resize(3); + reference_derivative_cross_current.resize(3); + reference_derivative_cross_current_variation.resize(NumberOfDofs * 3); + + reference_cross_current_variation.clear(); + reference_cross_current_derivative_variation.clear(); + reference_cross_current.clear(); + reference_cross_current_derivative.clear(); + reference_derivative_cross_current.clear(); + reference_derivative_cross_current_variation.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + reference_cross_current_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + Vector reference_derivative_dot_current_variation; + reference_derivative_dot_current_variation.resize(NumberOfDofs); + reference_derivative_dot_current_variation.clear(); + Vector tangent_dot_product_derivative_variation; + tangent_dot_product_derivative_variation.resize(NumberOfDofs); + tangent_dot_product_derivative_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + { + tangent_dot_product_variation(r) += 0; + reference_derivative_dot_current_variation(r) += 0; + tangent_dot_product_derivative_variation(r) += 0; + } + else + { + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; + tangent_dot_product_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + } + } + } + + Matrix tangent_dot_product_second_variation; + tangent_dot_product_second_variation.resize(NumberOfDofs, NumberOfDofs); + tangent_dot_product_second_variation.clear(); + Matrix tangent_dot_product_derivative_second_variation; + tangent_dot_product_derivative_second_variation.resize(NumberOfDofs, NumberOfDofs); + tangent_dot_product_derivative_second_variation.clear(); + Matrix reference_derivative_dot_current_second_variation; + reference_derivative_dot_current_second_variation.resize(NumberOfDofs, NumberOfDofs); + reference_derivative_dot_current_second_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyzr = r % DofsPerNode; + + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzs = s % DofsPerNode; + + + if (xyzr > 2 || xyzs > 2) + { + tangent_dot_product_second_variation(r, s) = 0; + } + else + { + tangent_dot_product_second_variation(r, s) += rCurrentTangentSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangent[t]; + tangent_dot_product_derivative_second_variation(r, s) += rCurrentTangentDerivativeSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangent[t]; + reference_derivative_dot_current_second_variation(r, s) += rCurrentTangentSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangentDerivative[t]; + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t u = 0;u < 3;u++) + { + if (xyz_r > 2) + { + reference_cross_current_variation[t * NumberOfDofs + r] += 0; + } + else + { + for (size_t k = 0;k < 3;k++) + { + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeVariation[u * NumberOfDofs + r]; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + } + } + } + } + } + + Matrix reference_cross_current_second_variation; + reference_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_cross_current_second_variation.clear(); + Matrix reference_cross_current_derivative_second_variation; + reference_cross_current_derivative_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_cross_current_derivative_second_variation.clear(); + Matrix reference_derivative_cross_current_second_variation; + reference_derivative_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_derivative_cross_current_second_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyz_s = s % DofsPerNode; + if (xyz_r < 3 || xyz_s < 3) + { + for (size_t k = 0;k < 3;k++) + { + reference_cross_current_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentSecondVariation(u * NumberOfDofs + r, s); + reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeSecondVariation(u * NumberOfDofs + r, s); + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentSecondVariation(u * NumberOfDofs + r, s); + } + } + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyz_s = s % DofsPerNode; + + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + if (t == u) + { + if (xyz_r > 2 || xyz_s > 2) + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * DofsPerNode + s) += 0; + else + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s); + } + else + { + if (xyz_r > 2 || xyz_s > 2) + for (int k = 0; k < 3; k++) + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, s) += 0; + else + { + for (int k = 0; k < 3; k++) + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); + } + } + } + } + } + } + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyzr = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzs = s % DofsPerNode; + if (xyzr > 2 || xyzs > 2) + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 0; + else + { + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); + } + } + } + } + } + } + + void BeamBaseElement3D::ComputeLambdaMatrixVariations( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Matrix& rCurrentTangentSecondVariation, + const Matrix& rCurrentTangentDerivativeSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixVariation, + Matrix& rLambdaMatrixDerivativeVariation, + Matrix& rLambdaMatrixSecondVariation, + Matrix& rLambdaMatrixDerivativeSecondVariation) + { + + + + rLambdaMatrixVariation.clear(); + + rLambdaMatrixDerivativeVariation.clear(); + + rLambdaMatrixSecondVariation.clear(); + + rLambdaMatrixDerivativeSecondVariation.clear(); + + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); + double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); + double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); + double tangent_dot_product_derivative = reference_dot_current_derivative + reference_derivative_dot_current; + + int levi_civita[3][3][3]; + for (int i = 0; i < 3; i++) + { + for (int j = 0; j < 3; j++) + { + for (int k = 0; k < 3; k++) + { + levi_civita[i][j][k] = 0; + } + } + } + + levi_civita[0][1][2] = 1; + levi_civita[2][0][1] = 1; + levi_civita[1][2][0] = 1; + + levi_civita[0][2][1] = -1; + levi_civita[1][0][2] = -1; + levi_civita[2][1][0] = -1; + + Vector reference_cross_current_variation; + Vector reference_cross_current_derivative_variation; + Vector reference_cross_current; + Vector reference_cross_current_derivative; + Vector reference_derivative_cross_current; + Vector reference_derivative_cross_current_variation; + + reference_cross_current_variation.resize(NumberOfDofs * 3); + reference_cross_current_derivative_variation.resize(NumberOfDofs * 3); + reference_cross_current.resize(3); + reference_cross_current_derivative.resize(3); + reference_derivative_cross_current.resize(3); + reference_derivative_cross_current_variation.resize(NumberOfDofs * 3); + + reference_cross_current_variation.clear(); + reference_cross_current_derivative_variation.clear(); + reference_cross_current.clear(); + reference_cross_current_derivative.clear(); + reference_derivative_cross_current.clear(); + reference_derivative_cross_current_variation.clear(); + + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); + reference_cross_current_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); + reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); + + Vector tangent_dot_product_variation; + tangent_dot_product_variation.resize(NumberOfDofs); + tangent_dot_product_variation.clear(); + Vector reference_derivative_dot_current_variation; + reference_derivative_dot_current_variation.resize(NumberOfDofs); + reference_derivative_dot_current_variation.clear(); + Vector tangent_dot_product_derivative_variation; + tangent_dot_product_derivative_variation.resize(NumberOfDofs); + tangent_dot_product_derivative_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + { + tangent_dot_product_variation(r) += 0; + reference_derivative_dot_current_variation(r) += 0; + tangent_dot_product_derivative_variation(r) += 0; + } + else + { + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; + tangent_dot_product_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; + } + } + } + + Matrix tangent_dot_product_second_variation; + tangent_dot_product_second_variation.resize(NumberOfDofs, NumberOfDofs); + tangent_dot_product_second_variation.clear(); + Matrix tangent_dot_product_derivative_second_variation; + tangent_dot_product_derivative_second_variation.resize(NumberOfDofs, NumberOfDofs); + tangent_dot_product_derivative_second_variation.clear(); + Matrix reference_derivative_dot_current_second_variation; + reference_derivative_dot_current_second_variation.resize(NumberOfDofs, NumberOfDofs); + reference_derivative_dot_current_second_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyzr = r % DofsPerNode; + + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzs = s % DofsPerNode; + + + if (xyzr > 2 || xyzs > 2) + { + tangent_dot_product_second_variation(r, s) = 0; + } + else + { + tangent_dot_product_second_variation(r, s) += rCurrentTangentSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangent[t]; + tangent_dot_product_derivative_second_variation(r, s) += rCurrentTangentDerivativeSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangent[t]; + reference_derivative_dot_current_second_variation(r, s) += rCurrentTangentSecondVariation(t * NumberOfDofs + r, s) * rReferenceTangentDerivative[t]; + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t u = 0;u < 3;u++) + { + if (xyz_r > 2) + { + reference_cross_current_variation[t * NumberOfDofs + r] += 0; + } + else + { + for (size_t k = 0;k < 3;k++) + { + reference_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + reference_cross_current_derivative_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeVariation[u * NumberOfDofs + r]; + reference_derivative_cross_current_variation[t * NumberOfDofs + r] += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentVariation[u * NumberOfDofs + r]; + } + } + } + } + } + + Matrix reference_cross_current_second_variation; + reference_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_cross_current_second_variation.clear(); + Matrix reference_cross_current_derivative_second_variation; + reference_cross_current_derivative_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_cross_current_derivative_second_variation.clear(); + Matrix reference_derivative_cross_current_second_variation; + reference_derivative_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); + reference_derivative_cross_current_second_variation.clear(); + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz_r = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyz_s = s % DofsPerNode; + if (xyz_r < 3 || xyz_s < 3) + { + for (size_t k = 0;k < 3;k++) + { + reference_cross_current_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentSecondVariation(u * NumberOfDofs + r, s); + reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangent[k] * rCurrentTangentDerivativeSecondVariation(u * NumberOfDofs + r, s); + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s) += levi_civita[t][k][u] * rReferenceTangentDerivative[k] * rCurrentTangentSecondVariation(u * NumberOfDofs + r, s); + } + } + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyz = r % DofsPerNode; + + if (xyz > 2) + { + + + } + else + { + if (t == u) + { + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += tangent_dot_product_variation(r); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r); + } + else + { + for (int k = 0; k < 3; k++) + { + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; + } + } + + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_variation[t * NumberOfDofs + r] + reference_derivative_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + (reference_cross_current_variation[t * NumberOfDofs + r]) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * (reference_cross_current_variation[u * NumberOfDofs + r]) + reference_cross_current[t] * (reference_cross_current_derivative_variation[u * NumberOfDofs + r] + reference_derivative_cross_current_variation[u * NumberOfDofs + r])); + } + } + } + } + + for (size_t t = 0;t < 3;t++) + { + for (size_t u = 0;u < 3;u++) + { + for (size_t r = 0;r < NumberOfDofs;r++) + { + size_t xyzr = r % DofsPerNode; + for (size_t s = 0;s < NumberOfDofs;s++) + { + size_t xyzs = s % DofsPerNode; + if (xyzr > 2 || xyzs > 2) + { + + + } + else + { + if (t == u) + { + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += tangent_dot_product_second_variation(r, s); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s); + } + else + { + for (int k = 0; k < 3; k++) + { + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); + } + } + + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + - tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + s, r)); + + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); + + } + } + } + } + } + + } + + + +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.h b/applications/IgaApplication/custom_elements/beam_base_element_3D.h index b5f6f2a82a54..c39c96fb5e28 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.h +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.h @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // #pragma once @@ -19,241 +20,457 @@ // Project includes #include "includes/define.h" #include "includes/element.h" +#include "includes/ublas_interface.h" +#include "containers/array_1d.h" // Application includes #include "iga_application_variables.h" -namespace Kratos{ -///@name Kratos Classes -///@{ -/// Short class definition. -/** Base class for IGA 3D Beams. -*/ +namespace Kratos +{ + +/** + * @class BeamBaseElement3D + * @brief Base class for three-dimensional IGA beam elements. + * + * This class provides functionality shared by three-dimensional beam + * formulations, including degree-of-freedom handling, constitutive-law + * initialization, beam kinematics, and rotation-related operations. + */ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D : public Element { -protected: - struct KinematicVariables{}; - - /** - * Internal variables used in the constitutive equations - */ - struct ConstitutiveVariables - { - Vector StrainVector; - Vector StressVector; - Matrix ConstitutiveMatrix; - - ConstitutiveVariables(SizeType StrainSize = 3) - { - StrainVector = ZeroVector(StrainSize); - StressVector = ZeroVector(StrainSize); - ConstitutiveMatrix = ZeroMatrix(StrainSize, StrainSize); - } - }; - - static inline void ComputeSkewSymmetricMatrix( - BoundedMatrix& rSkewMatrix, - const array_1d& rVec) - { - noalias(rSkewMatrix) = ZeroMatrix(3, 3); - - rSkewMatrix(0, 1) = -rVec[2]; - rSkewMatrix(0, 2) = rVec[1]; - rSkewMatrix(1, 0) = rVec[2]; - rSkewMatrix(1, 2) = -rVec[0]; - rSkewMatrix(2, 0) = -rVec[1]; - rSkewMatrix(2, 1) = rVec[0]; - } public: + ///@name Type Definitions ///@{ + using BaseType = Element; using NodeType = Node; using GeometryType = Geometry; using NodesArrayType = GeometryType::PointsArrayType; using SizeType = typename BaseType::SizeType; using IndexType = typename BaseType::IndexType; + using Matrix3d = BoundedMatrix; - /// Counted pointer of Shell3pElement KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BeamBaseElement3D); - /// Constructor using an array of nodes + ///@} + ///@name Life Cycle + ///@{ + BeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry) : Element(NewId, pGeometry) - {}; + { + } - /// Constructor using an array of nodes with properties BeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) : Element(NewId, pGeometry, pProperties) - {}; + { + } - /// Default constructor necessary for serialization BeamBaseElement3D() : Element() - {}; + { + } - /// Destructor. - virtual ~BeamBaseElement3D() = default; + ~BeamBaseElement3D() override = default; ///@} - ///@name Life Cycle + ///@name Element Creation ///@{ - /// Create with Id, pointer to geometry and pointer to property + Element::Pointer Create( IndexType NewId, - GeometryType::Pointer pGeom, - PropertiesType::Pointer pProperties - ) const override = 0; + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) const override = 0; - /// Create with Id, pointer to geometry and pointer to property Element::Pointer Create( IndexType NewId, - NodesArrayType const& ThisNodes, - PropertiesType::Pointer pProperties - ) const override = 0; + const NodesArrayType& rThisNodes, + PropertiesType::Pointer pProperties) const override = 0; ///@} - ///@name Operators + ///@name Degrees of Freedom ///@{ + void EquationIdVector( + EquationIdVectorType& rResult, + const ProcessInfo& rCurrentProcessInfo) const override; + + void GetDofList( + DofsVectorType& rElementalDofList, + const ProcessInfo& rCurrentProcessInfo) const override; + + void GetValuesVector( + Vector& rValues, + int Step = 0) const override; ///@} - ///@name Operations + ///@name Material ///@{ - /** - * this determines the elemental equation ID vector for all elemental - * DOFs - * @param rResult: the elemental equation ID vector - * @param rCurrentProcessInfo: the current process info instance - */ - void EquationIdVector(EquationIdVectorType& rResult, const ProcessInfo& CurrentProcessInfo) const override = 0; + void InitializeMaterial(); - /** - * determines the elemental list of DOFs - * @param ElementalDofList: the list of DOFs - * @param rCurrentProcessInfo: the current process info instance - */ - void GetDofList(DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo) const override = 0; + ///@} + ///@name Element Calculations + ///@{ - /** - * @brief This function provides a more general interface to the element. - * @details It is designed so that rLHSvariables and rRHSvariables are - * passed to the element thus telling what is the desired output - * @param rLeftHandSideMatrix container with the output Left Hand Side matrix - * @param rRightHandSideVector container for the desired RHS output - * @param rCurrentProcessInfo the current process info instance - */ - virtual void CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, - VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) = 0; + void CalculateLocalSystem( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override = 0; - /** - * @brief This is called during the assembling process in order - * to calculate the element left hand side matrix - * @param rLeftHandSideMatrix the element left hand side matrix - * @param rCurrentProcessInfo the current process info - */ - virtual void CalculateLeftHandSide(MatrixType& rLeftHandSideMatrix, - const ProcessInfo& rCurrentProcessInfo) = 0; + void CalculateLeftHandSide( + MatrixType& rLeftHandSideMatrix, + const ProcessInfo& rCurrentProcessInfo) override = 0; + + void CalculateRightHandSide( + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override = 0; + + ///@} + ///@name Input and Output + ///@{ + + int Check( + const ProcessInfo& rCurrentProcessInfo) const override; + + ///@} + +protected: + + ///@name Protected Structures + ///@{ /** - * @brief This is called during the assembling process in order - * to calculate the element right hand side matrix - * @param rLeftHandSideMatrix the element right hand side matrix - * @param rCurrentProcessInfo the current process info - */ - virtual void CalculateRightHandSide(VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) = 0; + * @brief Variables used during constitutive-law calculations. + */ + struct ConstitutiveVariables + { + Vector StrainVector; + Vector StressVector; + Matrix ConstitutiveMatrix; + + explicit ConstitutiveVariables( + const SizeType StrainSize = 3) + { + StrainVector = ZeroVector(StrainSize); + StressVector = ZeroVector(StrainSize); + ConstitutiveMatrix = ZeroMatrix(StrainSize, StrainSize); + } + }; + + ///@} + ///@name Protected Operations + ///@{ + /** + * @brief Performs the formulation-specific element calculation. + */ virtual void CalculateAll( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, const ProcessInfo& rCurrentProcessInfo, const bool CalculateStiffnessMatrixFlag, - const bool CalculateResidualVectorFlag - ) = 0; - - static inline void ComputeRotationMatrix( - MatrixType& rMatRod, - const array_1d& rVec, - const double Phi) - { - if (rMatRod.size1() != 3 || rMatRod.size2() != 3) { - rMatRod.resize(3, 3, false); - } + const bool CalculateResidualVectorFlag) = 0; - const double c = std::cos(Phi); - const double s = std::sin(Phi); - - BoundedMatrix skew_matrix; - ComputeSkewSymmetricMatrix(skew_matrix, rVec); - - noalias(rMatRod) = c * IdentityMatrix(3) + s * skew_matrix; - } + /** + * @brief Computes the first variation of the beam tangent. + */ + void ComputeTangentVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Vector& rTangentVariation) const; - static inline void ComputeRotationMatrixDeriv( - MatrixType& rMatRodDer, - const array_1d& rVec, - const array_1d& rVecDeriv, - const double Phi, - const double PhiDeriv) - { - if (rMatRodDer.size1() != 3 || rMatRodDer.size2() != 3) { - rMatRodDer.resize(3, 3, false); - } + /** + * @brief Computes the second variation of the beam tangent. + */ + void ComputeTangentSecondVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Matrix& rTangentSecondVariation) const; - const double c = std::cos(Phi); - const double s = std::sin(Phi); + /** + * @brief Computes the first variation of the tangent derivative. + */ + void ComputeTangentDerivativeVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + Vector& rTangentDerivativeVariation) const; - BoundedMatrix skew_vec; - BoundedMatrix skew_vec_deriv; + /** + * @brief Computes the second variation of the tangent derivative. + */ + void ComputeTangentDerivativeSecondVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + Matrix& rTangentDerivativeSecondVariation) const; - ComputeSkewSymmetricMatrix(skew_vec, rVec); - ComputeSkewSymmetricMatrix(skew_vec_deriv, rVecDeriv); + /** + * @brief Computes the first variation of the second tangent derivative. + */ + void ComputeTangentSecondDerivativeVariation( + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const Vector& rShapeFunctionThirdDerivatives, + const array_1d& rFirstBaseVector, + const array_1d& rSecondBaseVector, + const array_1d& rThirdBaseVector, + Vector& rTangentSecondDerivativeVariation) const; - noalias(rMatRodDer) = - (-PhiDeriv * s) * IdentityMatrix(3) - + (PhiDeriv * c) * skew_vec - + s * skew_vec_deriv; - } + /** + * @brief Computes the Rodrigues rotation matrix. + */ + static void ComputeRodriguesMatrix( + const array_1d& rAxis, + const double Phi, + Matrix3d& rRodriguesMatrix); -private: + /** + * @brief Computes the first derivative of the Rodrigues rotation matrix. + */ + static void ComputeRodriguesMatrixDerivative( + const array_1d& rAxis, + const array_1d& rAxisDerivative, + const double Phi, + const double PhiDerivative, + Matrix3d& rRodriguesMatrixDerivative); - ///@name Static Member Variables - ///@{ + /** + * @brief Computes the second derivative of the Rodrigues rotation matrix. + */ + static void ComputeRodriguesMatrixSecondDerivative( + const array_1d& rAxis, + const array_1d& rAxisDerivative, + const array_1d& rAxisSecondDerivative, + const double Phi, + const double PhiDerivative, + const double PhiSecondDerivative, + Matrix3d& rRodriguesMatrixSecondDerivative); + + static void ComputeRodriguesMatrixVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const Vector& rShapeFunctions, + const double Phi, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixVariation); + + static void ComputeRodriguesMatrixSecondVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const Matrix& rAxisSecondVariation, + const Vector& rShapeFunctions, + const double Phi, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixSecondVariation); + + static void ComputeRodriguesMatrixDerivativeVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixDerivativeVariation); + + static void ComputeRodriguesMatrixDerivativeSecondVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Matrix& rAxisSecondVariation, + const Matrix& rAxisDerivativeSecondVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixDerivativeSecondVariation); + + static void ComputeRodriguesMatrixSecondDerivativeVariation( + const array_1d& rAxis, + const Vector& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const array_1d& rAxisSecondDerivative, + const Vector& rAxisSecondDerivativeVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const Vector& rShapeFunctionSecondDerivatives, + const double Phi, + const double PhiDerivative, + const double PhiSecondDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixSecondDerivativeVariation); + + static void ComputeRodriguesMatrixVariations( + const array_1d& rAxis, + const array_1d& rAxisVariation, + const array_1d& rAxisDerivative, + const Vector& rAxisDerivativeVariation, + const Matrix& rAxisSecondVariation, + const Matrix& rAxisDerivativeSecondVariation, + const Vector& rShapeFunctions, + const Vector& rShapeFunctionDerivatives, + const double Phi, + const double PhiDerivative, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rRodriguesMatrixVariation, + Matrix& rRodriguesMatrixDerivativeVariation, + Matrix& rRodriguesMatrixSecondVariation, + Matrix& rRodriguesMatrixDerivativeSecondVariation); + /** + * @brief Computes the rotation mapping between reference and current tangents. + */ + static void ComputeLambdaMatrix( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + Matrix3d& rLambdaMatrix); + + static void ComputeLambdaMatrixDerivative( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rCurrentTangentDerivative, + Matrix3d& rLambdaMatrixDerivative); + + static void ComputeLambdaMatrixSecondDerivative( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rCurrentTangentDerivative, + const array_1d& rReferenceTangentSecondDerivative, + const array_1d& rCurrentTangentSecondDerivative, + Matrix3d& rLambdaMatrixSecondDerivative); + + static void ComputeLambdaMatrixVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const Vector& rCurrentTangentVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixVariation); + + static void ComputeLambdaMatrixSecondVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const Vector& rCurrentTangentVariation, + const Matrix& rCurrentTangentSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixSecondVariation); + + static void ComputeLambdaMatrixDerivativeVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixDerivativeVariation); + + static void ComputeLambdaMatrixSecondDerivativeVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const array_1d& rReferenceTangentSecondDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const array_1d& rCurrentTangentSecondDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Vector& rCurrentTangentSecondDerivativeVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixSecondDerivativeVariation); + + static void ComputeLambdaMatrixDerivativeSecondVariation( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Matrix& rCurrentTangentSecondVariation, + const Matrix& rCurrentTangentDerivativeSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixDerivativeSecondVariation); + + static void ComputeLambdaMatrixVariations( + const array_1d& rReferenceTangent, + const array_1d& rCurrentTangent, + const array_1d& rReferenceTangentDerivative, + const Vector& rCurrentTangentVariation, + const array_1d& rCurrentTangentDerivative, + const Vector& rCurrentTangentDerivativeVariation, + const Matrix& rCurrentTangentSecondVariation, + const Matrix& rCurrentTangentDerivativeSecondVariation, + const SizeType NumberOfDofs, + const SizeType DofsPerNode, + Matrix& rLambdaMatrixVariation, + Matrix& rLambdaMatrixDerivativeVariation, + Matrix& rLambdaMatrixSecondVariation, + Matrix& rLambdaMatrixDerivativeSecondVariation); ///@} ///@name Member Variables ///@{ + std::vector mConstitutiveLawVector; + SizeType mNumberOfDofs = 0; + SizeType mDofsPerNode = 4; ///@} - ///@name Private Operators - ///@{ - ///@} - ///@name Private Operations - ///@{ +private: - ///@} ///@name Serialization ///@{ friend class Serializer; - void save(Serializer& rSerializer) const override = 0; - void load(Serializer& rSerializer) override = 0 ; + void save( + Serializer& rSerializer) const override + { + KRATOS_SERIALIZE_SAVE_BASE_CLASS( + rSerializer, + Element); + } + void load( + Serializer& rSerializer) override + { + KRATOS_SERIALIZE_LOAD_BASE_CLASS( + rSerializer, + Element); + } + + ///@} }; // Class BeamBaseElement3D -} // Namespace Kratos \ No newline at end of file +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp deleted file mode 100644 index 637d93b24c42..000000000000 --- a/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.cpp +++ /dev/null @@ -1,80 +0,0 @@ -// KRATOS _____________ -// / _/ ____/ | -// / // / __/ /| | -// _/ // /_/ / ___ | -// /___/\____/_/ |_| Application -// -// License: BSD License -// Kratos default license: kratos/license.txt -// -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio -// - -// System includes - -// External includes - -// Project includes - -// Application includes -#include "custom_elements/beam_bernoulli_element_3D.h" - -namespace Kratos -{ - void BeamBernoulliElement3D::GetDofList( - DofsVectorType& rElementalDofList, - const ProcessInfo& rCurrentProcessInfo - ) const - { - KRATOS_TRY; - const auto& r_geometry = this->GetGeometry(); - const SizeType number_of_control_points = r_geometry.size(); - - rElementalDofList.resize(0); - rElementalDofList.reserve(4 * number_of_control_points); - - for (IndexType i = 0; i < number_of_control_points; ++i) { - rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_X)); - rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_Y)); - rElementalDofList.push_back(GetGeometry()[i].pGetDof(DISPLACEMENT_Z)); - rElementalDofList.push_back(GetGeometry()[i].pGetDof(ROTATION_X)); - } - KRATOS_CATCH("") - } - - void BeamBernoulliElement3D::EquationIdVector( - EquationIdVectorType& rResult, - const ProcessInfo& rCurrentProcessInfo - ) const - { - KRATOS_TRY; - - const auto& r_geometry = this->GetGeometry(); - const SizeType number_of_control_points = r_geometry.size(); - - if (rResult.size() != 4 * number_of_control_points) - rResult.resize(4 * number_of_control_points, false); - - const IndexType pos = r_geometry[0].GetDofPosition(DISPLACEMENT_X); - - for (IndexType i = 0; i < number_of_control_points; ++i) { - const IndexType index = i * 4; - rResult[index] = r_geometry[i].GetDof(DISPLACEMENT_X, pos).EquationId(); - rResult[index + 1] = r_geometry[i].GetDof(DISPLACEMENT_Y, pos + 1).EquationId(); - rResult[index + 2] = r_geometry[i].GetDof(DISPLACEMENT_Z, pos + 2).EquationId(); - rResult[index + 3] = r_geometry[i].GetDof(ROTATION_X, pos + 3).EquationId(); - } - - KRATOS_CATCH("") - }; - - void BeamBernoulliElement3D::ComputeGAxial( - const IndexType IntegrationPointIndex, - Matrix& rGAxial, - KinematicVariables& rKinematicVariables) const - { - KRATOS_TRY; - KRATOS_CATCH(""); - } - -} // Namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h b/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h deleted file mode 100644 index dc6647fc2647..000000000000 --- a/applications/IgaApplication/custom_elements/beam_bernoulli_element_3D.h +++ /dev/null @@ -1,280 +0,0 @@ -// KRATOS _____________ -// / _/ ____/ | -// / // / __/ /| | -// _/ // /_/ / ___ | -// /___/\____/_/ |_| Application -// -// License: BSD License -// Kratos default license: kratos/license.txt -// -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio -// - -#pragma once - -// System includes - -// External includes - -// Project includes -#include "includes/define.h" -#include "includes/element.h" - -// Application includes -#include "iga_application_variables.h" -#include "custom_elements/beam_base_element_3D.h" - -namespace Kratos{ -///@name Kratos Classes -///@{ -/// Short class definition. -/** 3D Bernoulli beam element. -*/ -class KRATOS_API(IGA_APPLICATION) BeamBernoulliElement3D - : public BeamBaseElement3D -{ -protected: - struct KinematicVariables - { - // Reference configuration - array_1d R1; // Reference tangent vector - array_1d R2; // Reference curvature vector - array_1d R3; // Reference third derivative - double A; // Reference length measure - double B; // Reference curvature measure - - // Current configuration - array_1d r1; // Current tangent vector - array_1d r2; // Current curvature vector - array_1d r3; // Current third derivative - double a; // Current length measure - double b; // Current curvature measure - - // Cross-section directors - array_1d N0, V0; // Reference directors - array_1d n, v; // Current directors - - // Curvature components - double B_n, B_v; // Reference curvatures - double b_n, b_v; // Current curvatures - double C_12, C_13; // Reference twist - double c_12, c_13; // Current twist - - // Rotations - double Phi, Phi_der; // Reference rotation - double phi, phi_der; // Current rotation - - KinematicVariables(SizeType Dimension = 3) - { - R1 = ZeroVector(Dimension); - R2 = ZeroVector(Dimension); - R3 = ZeroVector(Dimension); - r1 = ZeroVector(Dimension); - r2 = ZeroVector(Dimension); - r3 = ZeroVector(Dimension); - N0 = ZeroVector(Dimension); - V0 = ZeroVector(Dimension); - n = ZeroVector(Dimension); - v = ZeroVector(Dimension); - A = B = a = b = 0.0; - B_n = B_v = b_n = b_v = 0.0; - C_12 = C_13 = c_12 = c_13 = 0.0; - Phi = Phi_der = 0.0; - phi = phi_der = 0.0; - } - }; - -public: - ///@name Type Definitions - ///@{ - - KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BeamBernoulliElement3D); - - using BaseType = BeamBaseElement3D; - using SizeType = typename BaseType::SizeType; - using IndexType = typename BaseType::IndexType; - - // GeometryType - using GeometryType = Geometry; - - //@} - ///@name Life Cycle - ///@{ - - /// Constructor using an array of nodes - BeamBernoulliElement3D( - IndexType NewId, - GeometryType::Pointer pGeometry) - : BeamBaseElement3D(NewId, pGeometry) - { - }; - - /// Constructor using an array of nodes with properties - BeamBernoulliElement3D( - IndexType NewId, - GeometryType::Pointer pGeometry, - PropertiesType::Pointer pProperties) - : BeamBaseElement3D(NewId, pGeometry, pProperties) - { - }; - - /// Default constructor necessary for serialization - BeamBernoulliElement3D() - : BeamBaseElement3D() - { - }; - - /// Destructor. - ~BeamBernoulliElement3D() override = default; - - /// Create with Id, pointer to geometry and pointer to property - Element::Pointer Create( - IndexType NewId, - GeometryType::Pointer pGeom, - PropertiesType::Pointer pProperties - ) const override - { - return Kratos::make_intrusive( - NewId, pGeom, pProperties); - }; - - /// Create with Id, pointer to geometry and pointer to property - Element::Pointer Create( - IndexType NewId, - NodesArrayType const& ThisNodes, - PropertiesType::Pointer pProperties - ) const override - { - return Kratos::make_intrusive( - NewId, GetGeometry().Create(ThisNodes), pProperties); - }; - - ///@} - ///@name Degrees of freedom - ///@{ - - /// Relates the degrees of freedom of the element geometry - void GetDofList( - DofsVectorType& rElementalDofList, - const ProcessInfo& rCurrentProcessInfo - ) const override; - - /// Sets the ID's of the element degrees of freedom - void EquationIdVector( - EquationIdVectorType& rResult, - const ProcessInfo& rCurrentProcessInfo - ) const override; - - void ComputeGAxial( - const IndexType IntegrationPointIndex, - Matrix& rGAxial, - KinematicVariables& rKinematicVariables) const; - - void ComputeGBending( - const IndexType IntegrationPointIndex, - Matrix& rGBending1, - Matrix& rGBending2, - KinematicVariables& rKinematicVariables) const; - - void ComputeGTorsion( - const IndexType IntegrationPointIndex, - Matrix& rGTorsion1, - Matrix& rGTorsion2, - KinematicVariables& rKinematicVariables) const; - - void ComputeBAxial( - const IndexType IntegrationPointIndex, - Matrix& rBAxial, - KinematicVariables& rKinematicVariables) const; - - void ComputeBBending( - const IndexType IntegrationPointIndex, - Matrix& rBBending1, - Matrix& rBBending2, - KinematicVariables& rKinematicVariables) const; - - void ComputeBTorsion( - const IndexType IntegrationPointIndex, - Matrix& rBTorsion1, - Matrix& rBTorsion2, - KinematicVariables& rKinematicVariables) const; - -private: - - void CalculateRightHandSide( - VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) override - { - const SizeType nb_nodes = this->GetGeometry().size(); - const SizeType number_dofs_per_node = 4; - const SizeType nb_dofs = nb_nodes * number_dofs_per_node; - - if (rRightHandSideVector.size() != nb_dofs) - rRightHandSideVector.resize(nb_dofs); - noalias(rRightHandSideVector) = ZeroVector(nb_dofs); - - MatrixType left_hand_side_matrix; - - CalculateAll(left_hand_side_matrix, rRightHandSideVector, - rCurrentProcessInfo, false, true); - } - - void CalculateLeftHandSide( - MatrixType& rLeftHandSideMatrix, - const ProcessInfo& rCurrentProcessInfo) override - { - const SizeType nb_nodes = this->GetGeometry().size(); - const SizeType number_dofs_per_node = 4; - const SizeType nb_dofs = nb_nodes * number_dofs_per_node; - - VectorType right_hand_side_vector; - - if (rLeftHandSideMatrix.size1() != nb_dofs && rLeftHandSideMatrix.size2() != nb_dofs) - rLeftHandSideMatrix.resize(nb_dofs, nb_dofs); - noalias(rLeftHandSideMatrix) = ZeroMatrix(nb_dofs, nb_dofs); - - CalculateAll(rLeftHandSideMatrix, right_hand_side_vector, - rCurrentProcessInfo, true, false); - } - - void CalculateLocalSystem( - MatrixType& rLeftHandSideMatrix, - VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo) override - { - const SizeType nb_nodes = GetGeometry().size(); - const SizeType number_dofs_per_node = 4; - const SizeType nb_dofs = nb_nodes * number_dofs_per_node; - - if (rRightHandSideVector.size() != nb_dofs) - rRightHandSideVector.resize(nb_dofs); - noalias(rRightHandSideVector) = ZeroVector(nb_dofs); - - if (rLeftHandSideMatrix.size1() != nb_dofs && rLeftHandSideMatrix.size2() != nb_dofs) - rLeftHandSideMatrix.resize(nb_dofs, nb_dofs); - noalias(rLeftHandSideMatrix) = ZeroMatrix(nb_dofs, nb_dofs); - - CalculateAll(rLeftHandSideMatrix, rRightHandSideVector, - rCurrentProcessInfo, true, true); - } - - void CalculateAll( - MatrixType& rLeftHandSideMatrix, - VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo, - const bool CalculateStiffnessMatrixFlag, - const bool CalculateResidualVectorFlag - ) override - {} - - friend class Serializer; - - void save(Serializer& rSerializer) const override - { - } - - void load(Serializer& rSerializer) override - { - } -}; -} \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp new file mode 100644 index 000000000000..d4417883cac0 --- /dev/null +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -0,0 +1,1886 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// + +// System includes + +// External includes + +// Project includes + +// Application includes +#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" +#include "utilities/math_utils.h" + +namespace Kratos +{ + void NonLinearBernoulliBeamElement3D::Initialize(const ProcessInfo& rCurrentProcessInfo) + { + KRATOS_TRY + InitializeMaterial(); + + + mDofsPerNode = 4; + mNumberOfDofs = this->GetGeometry().size() * mDofsPerNode; + mSMatrixRodriguesVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaRodriguesLambdaVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesDerivativeVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); + mSMatrixRodriguesSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixRodriguesDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); + KRATOS_CATCH("") + + } + + + + void NonLinearBernoulliBeamElement3D::CalculateKinematics( + const IndexType IntegrationPointIndex, + KinematicVariables& rKinematicVariables) + { + const auto& r_geometry = GetGeometry(); + + // Get shape functions and derivatives + const Matrix& r_shape_functions = + r_geometry.ShapeFunctionsValues(); + + const Matrix& r_shape_function_derivatives = + r_geometry.ShapeFunctionDerivatives( + 1, + IntegrationPointIndex); + + const Matrix& r_shape_function_second_derivatives = + r_geometry.ShapeFunctionDerivatives( + 2, + IntegrationPointIndex); + + // Clear variables + rKinematicVariables.R1.clear(); + rKinematicVariables.R2.clear(); + rKinematicVariables.r1.clear(); + rKinematicVariables.r2.clear(); + + // Calculate reference and current configurations + for (IndexType i = 0; i < r_geometry.size(); ++i) { + const array_1d& r_initial_position = + r_geometry[i].GetInitialPosition(); + + const array_1d& r_displacement = + r_geometry[i].FastGetSolutionStepValue(DISPLACEMENT); + + // Reference configuration + rKinematicVariables.R1 += + r_shape_function_derivatives(i, 0) * + r_initial_position; + + rKinematicVariables.R2 += + r_shape_function_second_derivatives(i, 0) * + r_initial_position; + + // Current configuration + const array_1d current_position = + r_initial_position + r_displacement; + + rKinematicVariables.r1 += + r_shape_function_derivatives(i, 0) * + current_position; + + rKinematicVariables.r2 += + r_shape_function_second_derivatives(i, 0) * + current_position; + + // Rotations + const double rotation = + r_geometry[i].FastGetSolutionStepValue(ROTATION_X); + + rKinematicVariables.phi += + r_shape_functions(IntegrationPointIndex, i) * + rotation; + + rKinematicVariables.phi_der += + r_shape_function_derivatives(i, 0) * + rotation; + } + + // Calculate length measures + rKinematicVariables.A = + norm_2(rKinematicVariables.R1); + + rKinematicVariables.a = + norm_2(rKinematicVariables.r1); + + // Calculate curvature measures + const double reference_base_vector_product = + inner_prod( + rKinematicVariables.R1, + rKinematicVariables.R2); + + const double current_base_vector_product = + inner_prod( + rKinematicVariables.r1, + rKinematicVariables.r2); + + rKinematicVariables.B = sqrt( + inner_prod( + rKinematicVariables.R2, + rKinematicVariables.R2) + - pow( + reference_base_vector_product / + rKinematicVariables.A, + 2)); + + rKinematicVariables.b = sqrt( + inner_prod( + rKinematicVariables.r2, + rKinematicVariables.r2) + - pow( + current_base_vector_product / + rKinematicVariables.a, + 2)); + + // Compute reference cross-section geometry + ComputeReferenceCrossSectionGeometry( + rKinematicVariables); + + // Compute current cross-section geometry + ComputeCurrentCrossSectionGeometry( + rKinematicVariables); + } + + + void NonLinearBernoulliBeamElement3D::CalculateAll( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo, + const bool CalculateStiffnessMatrixFlag, + const bool CalculateResidualVectorFlag) + { + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + const auto& r_integration_points = + r_geometry.IntegrationPoints(); + + Vector stress_axial = ZeroVector(5); + Vector stress_bending_1 = ZeroVector(5); + Vector stress_bending_2 = ZeroVector(5); + Vector stress_torsion_1 = ZeroVector(5); + Vector stress_torsion_2 = ZeroVector(5); + + for ( + IndexType point_number = 0; + point_number < r_integration_points.size(); + ++point_number) + { + // Compute kinematics and metric + KinematicVariables kinematic_variables( + GetGeometry().WorkingSpaceDimension()); + + CalculateKinematics( + point_number, + kinematic_variables); + + // Create constitutive law parameters + ConstitutiveLaw::Parameters constitutive_law_parameters( + GetGeometry(), + GetProperties(), + rCurrentProcessInfo); + + ConstitutiveVariables constitutive_variables(5); + + CalculateConstitutiveVariables( + point_number, + kinematic_variables, + constitutive_variables, + constitutive_law_parameters, + ConstitutiveLaw::StressMeasure_PK2); + + Matrix b_axial; + Matrix b_bending_1; + Matrix b_bending_2; + Matrix b_torsion_1; + Matrix b_torsion_2; + + ComputeBMatrices( + point_number, + kinematic_variables, + b_axial, + b_bending_1, + b_bending_2, + b_torsion_1, + b_torsion_2); + + Matrix g_axial; + Matrix g_bending_1; + Matrix g_bending_2; + Matrix g_torsion_1; + Matrix g_torsion_2; + + ComputeGMatrices( + point_number, + kinematic_variables, + g_axial, + g_bending_1, + g_bending_2, + g_torsion_1, + g_torsion_2); + + // Assemble stiffness with cross-sectional scaling + const double integration_weight = + r_integration_points[point_number].Weight() * + kinematic_variables.A; + + const double inverse_a2 = + 1.0 / + (kinematic_variables.A * + kinematic_variables.A); + + const double inverse_a4 = + inverse_a2 * inverse_a2; + + if (CalculateStiffnessMatrixFlag == true) { + // Material stiffness + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + prod( + trans(b_axial), + Matrix(prod( + constitutive_variables.ConstitutiveMatrix, + b_axial))); + + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + prod( + trans(b_bending_1), + Matrix(prod( + constitutive_variables.ConstitutiveMatrix, + b_bending_1))); + + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + prod( + trans(b_bending_2), + Matrix(prod( + constitutive_variables.ConstitutiveMatrix, + b_bending_2))); + + rLeftHandSideMatrix += + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_1), + Matrix(prod( + constitutive_variables.ConstitutiveMatrix, + b_torsion_1))); + + rLeftHandSideMatrix += + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_2), + Matrix(prod( + constitutive_variables.ConstitutiveMatrix, + b_torsion_2))); + + // Geometrical stiffness + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + g_axial * + constitutive_variables.StressVector[0]; + + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + g_bending_1 * + constitutive_variables.StressVector[1]; + + rLeftHandSideMatrix += + inverse_a4 * + integration_weight * + g_bending_2 * + constitutive_variables.StressVector[2]; + + rLeftHandSideMatrix += + inverse_a2 * + integration_weight * + g_torsion_1 * + constitutive_variables.StressVector[3]; + + rLeftHandSideMatrix += + inverse_a2 * + integration_weight * + g_torsion_2 * + constitutive_variables.StressVector[4]; + } + + if (CalculateResidualVectorFlag == true) { + // Map stress components to different behaviors + stress_axial[0] = + constitutive_variables.StressVector[0]; + + stress_bending_1[1] = + constitutive_variables.StressVector[1]; + + stress_bending_2[2] = + constitutive_variables.StressVector[2]; + + stress_torsion_1[3] = + constitutive_variables.StressVector[3]; + + stress_torsion_2[4] = + constitutive_variables.StressVector[4]; + + // Assemble internal forces + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_axial), + stress_axial); + + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_bending_1), + stress_bending_1); + + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_bending_2), + stress_bending_2); + + rRightHandSideVector -= + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_1), + stress_torsion_1); + + rRightHandSideVector -= + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_2), + stress_torsion_2); + } + } + + KRATOS_CATCH("") + } + + + int NonLinearBernoulliBeamElement3D::Check( + const ProcessInfo& rCurrentProcessInfo) const + { + KRATOS_TRY + + Check(rCurrentProcessInfo); + + const double numerical_limit = + std::numeric_limits::epsilon(); + + KRATOS_ERROR_IF( + !GetProperties().Has(I_T) || + GetProperties()[I_T] <= numerical_limit) + << "Please provide a reasonable value for \"I_T\" " + << "(torsional moment of inertia) for element #" + << Id() << std::endl; + + KRATOS_ERROR_IF( + !GetProperties().Has(I_N) || + GetProperties()[I_N] <= numerical_limit) + << "Please provide a reasonable value for \"I_N\" " + << "(bending moment of inertia about N axis) for element #" + << Id() << std::endl; + + KRATOS_ERROR_IF( + !GetProperties().Has(I_V) || + GetProperties()[I_V] <= numerical_limit) + << "Please provide a reasonable value for \"I_V\" " + << "(bending moment of inertia about V axis) for element #" + << Id() << std::endl; + + KRATOS_ERROR_IF( + !GetProperties().Has(LOCAL_AXIS_ORIENTATION)) + << "\"LOCAL_AXIS_ORIENTATION\" not provided for element #" + << Id() << std::endl; + + if (GetProperties().Has(T_0)) { + const Vector3d& r_reference_tangent = + GetProperties()[T_0]; + + KRATOS_ERROR_IF( + norm_2(r_reference_tangent) <= numerical_limit) + << "\"T_0\" reference director vector must have " + << "non-zero magnitude for element #" + << Id() << std::endl; + } + + if (GetProperties().Has(N_0)) { + const Vector3d& r_reference_normal = + GetProperties()[N_0]; + + KRATOS_ERROR_IF( + norm_2(r_reference_normal) <= numerical_limit) + << "\"N_0\" reference director vector must have " + << "non-zero magnitude for element #" + << Id() << std::endl; + } + + return 0; + + KRATOS_CATCH("") + } + + + void NonLinearBernoulliBeamElement3D::CalculateConstitutiveVariables( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + ConstitutiveVariables& rConstitutiveVariables, + ConstitutiveLaw::Parameters& rConstitutiveLawParameters, + const ConstitutiveLaw::StressMeasure StressMeasure) + { + rConstitutiveLawParameters.GetOptions().Set( + ConstitutiveLaw::USE_ELEMENT_PROVIDED_STRAIN, + true); + + rConstitutiveLawParameters.GetOptions().Set( + ConstitutiveLaw::COMPUTE_STRESS); + + rConstitutiveLawParameters.GetOptions().Set( + ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR); + + rConstitutiveVariables.StrainVector[0] = + 0.5 * ( + rKinematicVariables.a * rKinematicVariables.a - + rKinematicVariables.A * rKinematicVariables.A); + + rConstitutiveVariables.StrainVector[1] = + rKinematicVariables.b_n - + rKinematicVariables.B_n; + + rConstitutiveVariables.StrainVector[2] = + rKinematicVariables.b_v - + rKinematicVariables.B_v; + + rConstitutiveVariables.StrainVector[3] = + rKinematicVariables.c_12 - + rKinematicVariables.C_12; + + rConstitutiveVariables.StrainVector[4] = + rKinematicVariables.c_13 - + rKinematicVariables.C_13; + + rConstitutiveLawParameters.SetStrainVector( + rConstitutiveVariables.StrainVector); + + rConstitutiveLawParameters.SetStressVector( + rConstitutiveVariables.StressVector); + + rConstitutiveLawParameters.SetConstitutiveMatrix( + rConstitutiveVariables.ConstitutiveMatrix); + + mConstitutiveLawVector[IntegrationPointIndex] + ->CalculateMaterialResponse( + rConstitutiveLawParameters, + StressMeasure); + + noalias(rConstitutiveVariables.StressVector) = + prod( + trans(rConstitutiveVariables.ConstitutiveMatrix), + rConstitutiveVariables.StrainVector); + } + + + void NonLinearBernoulliBeamElement3D::ComputeReferenceTwistAngleAndDerivative( + const KinematicVariables& rKinematicVariables, + double& rPhi, + double& rPhiDerivative) + { + + const auto& r_geometry = GetGeometry(); + const double integration_point_coordinate = r_geometry.IntegrationPoints()[0].Coordinates()[0]; + + double lower_twist_angle; + double upper_twist_angle; + double twist_angle_difference; + double lower_parameter_coordinate; + double upper_parameter_coordinate; + int number_of_orientation_points; + + Matrix local_axis_orientation = GetProperties()[LOCAL_AXIS_ORIENTATION]; + number_of_orientation_points = local_axis_orientation.size1(); + + lower_parameter_coordinate = local_axis_orientation(0, 0); + upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - 1, 0); + + // Extract normal vector components for start and end + Vector3d lower_normal; + lower_normal[0] = local_axis_orientation(0, 1); + lower_normal[1] = local_axis_orientation(0, 2); + lower_normal[2] = local_axis_orientation(0, 3); + + Vector3d upper_normal; + upper_normal[0] = local_axis_orientation(number_of_orientation_points - 1, 1); + upper_normal[1] = local_axis_orientation(number_of_orientation_points - 1, 2); + upper_normal[2] = local_axis_orientation(number_of_orientation_points - 1, 3); + + // Convert normal vectors to rotation angles (phi) for backward compatibility + lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, lower_normal); + upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, upper_normal); + + for (int i = 1; i < number_of_orientation_points; i++) + { + if (local_axis_orientation(i, 0) > integration_point_coordinate) + { + lower_parameter_coordinate = local_axis_orientation(i - 1, 0); + Vector3d interpolated_normal(3); + interpolated_normal[0] = local_axis_orientation(i - 1, 1); + interpolated_normal[1] = local_axis_orientation(i - 1, 2); + interpolated_normal[2] = local_axis_orientation(i - 1, 3); + lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); + break; + } + } + + for (int i = 1; i < number_of_orientation_points; i++) + { + if (local_axis_orientation(number_of_orientation_points - i - 1, 0) <= integration_point_coordinate) + { + upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - i, 0); + Vector3d interpolated_normal(3); + interpolated_normal[0] = local_axis_orientation(number_of_orientation_points - i, 1); + interpolated_normal[1] = local_axis_orientation(number_of_orientation_points - i, 2); + interpolated_normal[2] = local_axis_orientation(number_of_orientation_points - i, 3); + upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); + break; + } + } + const double pi = 4.0 * std::atan(1.0); + + twist_angle_difference = (upper_twist_angle - lower_twist_angle); + if (std::abs(upper_twist_angle - lower_twist_angle) > pi) + { + twist_angle_difference = twist_angle_difference - (twist_angle_difference) / std::abs(twist_angle_difference) * 2 * pi; + } + + rPhi += lower_twist_angle + (integration_point_coordinate - lower_parameter_coordinate) / (upper_parameter_coordinate - lower_parameter_coordinate) * twist_angle_difference; + rPhiDerivative += twist_angle_difference / (upper_parameter_coordinate - lower_parameter_coordinate); + } + + double NonLinearBernoulliBeamElement3D::CalculateDeltaPhi( + const KinematicVariables& rKinematicVariables, + const Vector3d& rNormal) + { + const Vector3d initial_tangent = GetProperties()[T_0]; + const Vector3d reference_base_vector = rKinematicVariables.R1; + + const Vector3d current_reference_tangent = + reference_base_vector / norm_2(reference_base_vector); + + const Vector3d normalized_initial_tangent = + initial_tangent / norm_2(initial_tangent); + + Vector3d normal = rNormal; + + const double tangent_normal_projection = + inner_prod(current_reference_tangent, normal); + + // Project the normal onto the plane normal to the reference tangent. + normal -= tangent_normal_projection * current_reference_tangent; + normal /= norm_2(normal); + + const Vector3d reference_principal_axis = normal; + + Matrix3d lambda_matrix; + ComputeLambdaMatrix( + normalized_initial_tangent, + current_reference_tangent, + lambda_matrix); + + const Vector3d rotated_reference_axis = + prod(lambda_matrix, reference_principal_axis); + + const Vector3d orientation_reference = + MathUtils::CrossProduct(reference_base_vector, rotated_reference_axis); + + const double axis_dot_product = + inner_prod(rotated_reference_axis, normal); + + const double orientation_dot_product = + inner_prod(normal, orientation_reference); + + double cos_theta = + axis_dot_product / + (norm_2(rotated_reference_axis) * norm_2(normal)); + + if (std::abs(1.0 - std::abs(cos_theta)) < 1e-9) { + cos_theta = MathUtils::Sign(cos_theta); + } + + double phi = std::acos(cos_theta); + + const double pi = 4.0 * std::atan(1.0); + + if (orientation_dot_product < -1e-12) { + phi = 2.0 * pi - phi; + } + + return phi; + } + + + void NonLinearBernoulliBeamElement3D::ComputeReferenceCrossSectionGeometry( + KinematicVariables& rKinematicVariables) + { + const Vector3d reference_first_base_vector = rKinematicVariables.R1; + const Vector3d reference_second_base_vector = rKinematicVariables.R2; + const Vector3d initial_reference_tangent = GetProperties()[T_0]; + + ComputeReferenceTwistAngleAndDerivative( + rKinematicVariables, + rKinematicVariables.Phi, + rKinematicVariables.Phi_der); + + Matrix3d reference_lambda_matrix; + Matrix3d reference_lambda_matrix_derivative; + Matrix3d reference_rodrigues_matrix; + Matrix3d reference_rodrigues_matrix_derivative; + Matrix3d cross_section_transformation_derivative; + cross_section_transformation_derivative.clear(); + + const double reference_first_base_vector_norm = + norm_2(reference_first_base_vector); + + const Vector3d reference_tangent = + reference_first_base_vector / reference_first_base_vector_norm; + + const Vector3d reference_tangent_derivative = + reference_second_base_vector / reference_first_base_vector_norm + - inner_prod(reference_first_base_vector, reference_second_base_vector) + / pow(reference_first_base_vector_norm, 3) + * reference_first_base_vector; + + Vector3d initial_reference_tangent_derivative; + initial_reference_tangent_derivative.clear(); + + ComputeLambdaMatrix( + initial_reference_tangent, + reference_tangent, + reference_lambda_matrix); + + ComputeLambdaMatrixDerivative( + initial_reference_tangent, + reference_tangent, + initial_reference_tangent_derivative, + reference_tangent_derivative, + reference_lambda_matrix_derivative); + + ComputeRodriguesMatrix( + reference_tangent, + rKinematicVariables.Phi, + reference_rodrigues_matrix); + + ComputeRodriguesMatrixDerivative( + reference_tangent, + reference_tangent_derivative, + rKinematicVariables.Phi, + rKinematicVariables.Phi_der, + reference_rodrigues_matrix_derivative); + + rKinematicVariables.n.clear(); + rKinematicVariables.N0 = GetProperties()[N_0]; + + const double initial_reference_tangent_norm = + norm_2(initial_reference_tangent); + + const Vector3d normalized_initial_reference_tangent = + initial_reference_tangent / initial_reference_tangent_norm; + + rKinematicVariables.N0 -= + inner_prod( + normalized_initial_reference_tangent, + rKinematicVariables.N0) + * normalized_initial_reference_tangent; + + rKinematicVariables.V0 = + MathUtils::CrossProduct( + normalized_initial_reference_tangent, + rKinematicVariables.N0); + + rKinematicVariables.N0 /= + norm_2(rKinematicVariables.N0); + + rKinematicVariables.V0 /= + norm_2(rKinematicVariables.V0); + + Vector3d transformed_reference_normal; + transformed_reference_normal.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + transformed_reference_normal[i] += + reference_lambda_matrix(i, j) + * rKinematicVariables.N0[j]; + } + } + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + rKinematicVariables.n(i) += + reference_rodrigues_matrix(i, j) + * transformed_reference_normal[j]; + } + } + + rKinematicVariables.n /= + norm_2(rKinematicVariables.n); + + rKinematicVariables.v = + MathUtils::CrossProduct(reference_tangent, rKinematicVariables.n); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + for (IndexType k = 0; k < 3; ++k) { + cross_section_transformation_derivative(i, j) += + reference_rodrigues_matrix_derivative(i, k) + * reference_lambda_matrix(k, j); + + cross_section_transformation_derivative(i, j) += + reference_rodrigues_matrix(i, k) + * reference_lambda_matrix_derivative(k, j); + } + } + } + + Vector3d a21_vector; + Vector3d a31_vector; + a21_vector.clear(); + a31_vector.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + a21_vector[i] += + cross_section_transformation_derivative(i, j) + * rKinematicVariables.N0[j]; + + a31_vector[i] += + cross_section_transformation_derivative(i, j) + * rKinematicVariables.V0[j]; + } + } + + rKinematicVariables.B_n = + inner_prod(a21_vector, reference_first_base_vector); + + rKinematicVariables.B_v = + inner_prod(a31_vector, reference_first_base_vector); + + rKinematicVariables.C_12 = + inner_prod(a31_vector, rKinematicVariables.n); + + rKinematicVariables.C_13 = + inner_prod(a21_vector, rKinematicVariables.v); + } + + void NonLinearBernoulliBeamElement3D::ComputeCurrentCrossSectionGeometry( + KinematicVariables& rKinematicVariables) + { + const Vector3d current_first_base_vector = rKinematicVariables.r1; + const Vector3d current_second_base_vector = rKinematicVariables.r2; + const Vector3d reference_first_base_vector = rKinematicVariables.R1; + const Vector3d reference_second_base_vector = rKinematicVariables.R2; + const Vector3d initial_reference_tangent = GetProperties()[T_0]; + + rKinematicVariables.n.clear(); + rKinematicVariables.v.clear(); + + Matrix3d current_lambda_matrix; + Matrix3d current_lambda_matrix_derivative; + Matrix3d reference_lambda_matrix; + Matrix3d reference_lambda_matrix_derivative; + Matrix3d current_rodrigues_matrix; + Matrix3d current_rodrigues_matrix_derivative; + Matrix3d reference_rodrigues_matrix; + Matrix3d reference_rodrigues_matrix_derivative; + + const double current_first_base_vector_norm = + norm_2(current_first_base_vector); + + const double reference_first_base_vector_norm = + norm_2(reference_first_base_vector); + + const Vector3d current_tangent = + current_first_base_vector / current_first_base_vector_norm; + + const Vector3d current_tangent_derivative = + current_second_base_vector / current_first_base_vector_norm + - inner_prod(current_first_base_vector, current_second_base_vector) + / pow(current_first_base_vector_norm, 3) + * current_first_base_vector; + + const Vector3d reference_tangent = + reference_first_base_vector / reference_first_base_vector_norm; + + const Vector3d reference_tangent_derivative = + reference_second_base_vector / reference_first_base_vector_norm + - inner_prod(reference_first_base_vector, reference_second_base_vector) + / pow(reference_first_base_vector_norm, 3) + * reference_first_base_vector; + + Vector3d initial_reference_tangent_derivative; + initial_reference_tangent_derivative.clear(); + + ComputeLambdaMatrix( + reference_tangent, + current_tangent, + current_lambda_matrix); + + ComputeLambdaMatrixDerivative( + reference_tangent, + current_tangent, + reference_tangent_derivative, + current_tangent_derivative, + current_lambda_matrix_derivative); + + ComputeLambdaMatrix( + initial_reference_tangent, + reference_tangent, + reference_lambda_matrix); + + ComputeLambdaMatrixDerivative( + initial_reference_tangent, + reference_tangent, + initial_reference_tangent_derivative, + reference_tangent_derivative, + reference_lambda_matrix_derivative); + + ComputeRodriguesMatrix( + current_tangent, + rKinematicVariables.phi, + current_rodrigues_matrix); + + ComputeRodriguesMatrixDerivative( + current_tangent, + current_tangent_derivative, + rKinematicVariables.phi, + rKinematicVariables.phi_der, + current_rodrigues_matrix_derivative); + + ComputeRodriguesMatrix( + reference_tangent, + rKinematicVariables.Phi, + reference_rodrigues_matrix); + + ComputeRodriguesMatrixDerivative( + reference_tangent, + reference_tangent_derivative, + rKinematicVariables.Phi, + rKinematicVariables.Phi_der, + reference_rodrigues_matrix_derivative); + + Matrix3d reference_rodrigues_lambda_product; + Matrix3d reference_rodrigues_lambda_derivative_product; + Matrix3d reference_rodrigues_derivative_lambda_product; + reference_rodrigues_lambda_product.clear(); + reference_rodrigues_lambda_derivative_product.clear(); + reference_rodrigues_derivative_lambda_product.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + for (IndexType k = 0; k < 3; ++k) { + reference_rodrigues_lambda_product(i, j) += + reference_rodrigues_matrix(i, k) + * reference_lambda_matrix(k, j); + + reference_rodrigues_lambda_derivative_product(i, j) += + reference_rodrigues_matrix(i, k) + * reference_lambda_matrix_derivative(k, j); + + reference_rodrigues_derivative_lambda_product(i, j) += + reference_rodrigues_matrix_derivative(i, k) + * reference_lambda_matrix(k, j); + } + } + } + + Matrix3d current_lambda_reference_rodrigues_lambda_product; + Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; + Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; + Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; + current_lambda_reference_rodrigues_lambda_product.clear(); + current_lambda_reference_rodrigues_lambda_derivative_product.clear(); + current_lambda_reference_rodrigues_derivative_lambda_product.clear(); + current_lambda_derivative_reference_rodrigues_lambda_product.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + for (IndexType k = 0; k < 3; ++k) { + current_lambda_reference_rodrigues_lambda_product(i, j) += + current_lambda_matrix(i, k) + * reference_rodrigues_lambda_product(k, j); + + current_lambda_reference_rodrigues_lambda_derivative_product(i, j) += + current_lambda_matrix(i, k) + * reference_rodrigues_lambda_derivative_product(k, j); + + current_lambda_reference_rodrigues_derivative_lambda_product(i, j) += + current_lambda_matrix(i, k) + * reference_rodrigues_derivative_lambda_product(k, j); + + current_lambda_derivative_reference_rodrigues_lambda_product(i, j) += + current_lambda_matrix_derivative(i, k) + * reference_rodrigues_lambda_product(k, j); + } + } + } + + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; + Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; + Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + Matrix3d cross_section_transformation; + + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); + cross_section_transformation.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + for (IndexType k = 0; k < 3; ++k) { + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(i, j) += + current_rodrigues_matrix(i, k) + * current_lambda_reference_rodrigues_lambda_derivative_product(k, j); + + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(i, j) += + current_rodrigues_matrix(i, k) + * current_lambda_reference_rodrigues_derivative_lambda_product(k, j); + + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(i, j) += + current_rodrigues_matrix(i, k) + * current_lambda_derivative_reference_rodrigues_lambda_product(k, j); + + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(i, j) += + current_rodrigues_matrix_derivative(i, k) + * current_lambda_reference_rodrigues_lambda_product(k, j); + + cross_section_transformation(i, j) += + current_rodrigues_matrix(i, k) + * current_lambda_reference_rodrigues_lambda_product(k, j); + } + } + } + + const Matrix3d cross_section_transformation_derivative = + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + + Vector3d a21_vector; + Vector3d a31_vector; + a21_vector.clear(); + a31_vector.clear(); + + for (IndexType i = 0; i < 3; ++i) { + for (IndexType j = 0; j < 3; ++j) { + a21_vector[i] += + cross_section_transformation_derivative(i, j) + * rKinematicVariables.N0[j]; + + a31_vector[i] += + cross_section_transformation_derivative(i, j) + * rKinematicVariables.V0[j]; + + rKinematicVariables.n[i] += + cross_section_transformation(i, j) + * rKinematicVariables.N0[j]; + + rKinematicVariables.v[i] += + cross_section_transformation(i, j) + * rKinematicVariables.V0[j]; + } + } + + rKinematicVariables.b_n = + inner_prod(a21_vector, current_first_base_vector); + + rKinematicVariables.b_v = + inner_prod(a31_vector, current_first_base_vector); + + rKinematicVariables.c_12 = + inner_prod(a31_vector, rKinematicVariables.n); + + rKinematicVariables.c_13 = + inner_prod(a21_vector, rKinematicVariables.v); + } + + + void NonLinearBernoulliBeamElement3D::ComputeBMatrices( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + Matrix& rBAxial, + Matrix& rBBending1, + Matrix& rBBending2, + Matrix& rBTorsion1, + Matrix& rBTorsion2) + { + KRATOS_TRY + const auto& r_geometry = GetGeometry(); + + // Get shape functions and derivatives at integration point + Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); + Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); + Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); + + // Extract kinematic variables + Vector3d current_first_base_vector = rKinematicVariables.r1; + Vector3d current_second_base_vector = rKinematicVariables.r2; + Vector3d reference_first_base_vector = rKinematicVariables.R1; + Vector3d reference_second_base_vector = rKinematicVariables.R2; + Vector3d reference_normal = rKinematicVariables.N0; + Vector3d reference_binormal = rKinematicVariables.V0; + double current_twist_angle = rKinematicVariables.phi; + double current_twist_angle_derivative = rKinematicVariables.phi_der; + double reference_twist_angle = rKinematicVariables.Phi; + double reference_twist_angle_derivative = rKinematicVariables.Phi_der; + Vector3d initial_reference_tangent = GetProperties()[T_0]; + + // Compute curvature and torsion variations + Vector axial_variation(mNumberOfDofs); + Vector normal_curvature_variation(mNumberOfDofs); + Vector binormal_curvature_variation(mNumberOfDofs); + Vector normal_torsion_variation(mNumberOfDofs); + Vector binormal_torsion_variation(mNumberOfDofs); + axial_variation.clear(); + normal_curvature_variation.clear(); + binormal_curvature_variation.clear(); + normal_torsion_variation.clear(); + binormal_torsion_variation.clear(); + + //compute axial_variation + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + size_t dof_component = dof_index % mDofsPerNode; + size_t control_point_index = dof_index / mDofsPerNode; + if (dof_component > 2) + axial_variation[dof_index] = 0; + else + axial_variation[dof_index] = rKinematicVariables.r1[dof_component] * shape_function_derivatives[control_point_index]; + } + //compute normal_curvature_variation, binormal_curvature_variation, normal_torsion_variation, binormal_torsion_variation + Vector3d current_tangent; + current_tangent.clear(); + Vector3d current_tangent_derivative; + current_tangent_derivative.clear(); + Vector3d reference_tangent; + reference_tangent.clear(); + Vector3d reference_tangent_derivative; + reference_tangent_derivative.clear(); + Vector3d initial_reference_tangent_derivative; + initial_reference_tangent_derivative.clear(); + Vector current_tangent_variation; + Vector current_tangent_derivative_variation; + Matrix3d current_lambda_matrix; + Matrix3d current_lambda_matrix_derivative; + Matrix3d reference_lambda_matrix; + Matrix3d reference_lambda_matrix_derivative; + Matrix3d current_rodrigues_matrix; + Matrix3d current_rodrigues_matrix_derivative; + Matrix3d reference_rodrigues_matrix; + Matrix3d reference_rodrigues_matrix_derivative; + + current_tangent = current_first_base_vector / norm_2(current_first_base_vector); + current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; + reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); + reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; + ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); + ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); + + ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); + ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); + ComputeLambdaMatrixVariation(reference_tangent, current_tangent, current_tangent_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation); + ComputeLambdaMatrixDerivativeVariation(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaDerivativeVariation); + ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); + ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); + + ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); + ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); + ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); + ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); + ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); + ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); + + Matrix3d reference_rodrigues_lambda_derivative_product; + reference_rodrigues_lambda_derivative_product.clear(); + Matrix3d reference_rodrigues_derivative_lambda_product; + reference_rodrigues_derivative_lambda_product.clear(); + Matrix3d reference_rodrigues_lambda_product; + reference_rodrigues_lambda_product.clear(); + Matrix3d reference_rodrigues_lambda_product_derivative; + reference_rodrigues_lambda_product_derivative.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int column_component = 0; column_component < 3; column_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); + reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); + reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); + } + } + } + reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; + + Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; + current_lambda_reference_rodrigues_lambda_derivative_product.clear(); + Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; + current_lambda_reference_rodrigues_derivative_lambda_product.clear(); + Matrix3d current_lambda_reference_rodrigues_lambda_product; + current_lambda_reference_rodrigues_lambda_product.clear(); + Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; + current_lambda_derivative_reference_rodrigues_lambda_product.clear(); + Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; + current_lambda_reference_rodrigues_lambda_product_derivative.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int column_component = 0; column_component < 3; column_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + + current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; + + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); + Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); + Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); + Matrix3d cross_section_transformation; + cross_section_transformation.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int column_component = 0; column_component < 3; column_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + + Matrix3d cross_section_transformation_derivative; + cross_section_transformation_derivative.clear(); + cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + + mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); + mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); + mSMatrixLambdaVariationRodriguesLambda.clear(); + mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int column_component = 0; column_component < 3; column_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + { + mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + } + + Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; + current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); + current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); + + current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; + + mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); + mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); + mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int column_component = 0; column_component < 3; column_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + { + mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + } + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); + mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda + + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; + mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; + + Vector3d normal_vector; + normal_vector.clear(); + Vector3d binormal_vector; + binormal_vector.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); + binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); + } + } + + Vector normal_vector_variation; + normal_vector_variation.resize(3 * mNumberOfDofs); + normal_vector_variation.clear(); + Vector binormal_vector_variation; + binormal_vector_variation.resize(3 * mNumberOfDofs); + binormal_vector_variation.clear(); + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); + binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); + } + } + } + + Vector current_first_base_vector_variation; + current_first_base_vector_variation.resize(3 * mNumberOfDofs); + current_first_base_vector_variation.clear(); + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + { + size_t dof_component = dof_index % mDofsPerNode; + size_t control_point_index = dof_index / mDofsPerNode; + if (row_component == dof_component) + current_first_base_vector_variation(row_component * mNumberOfDofs + dof_index) = shape_function_derivatives[control_point_index]; + } + } + + for (size_t row_component = 0; row_component < 3; row_component++) + { + for (int product_index = 0; product_index < 3; product_index++) + { + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + { + normal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; + binormal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; + normal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index); + binormal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index); + } + } + } + + + // Initialize B matrices + rBAxial.resize(5, mNumberOfDofs); + rBBending1.resize(5, mNumberOfDofs); + rBBending2.resize(5, mNumberOfDofs); + rBTorsion1.resize(5, mNumberOfDofs); + rBTorsion2.resize(5, mNumberOfDofs); + rBAxial.clear(); + rBBending1.clear(); + rBBending2.clear(); + rBTorsion1.clear(); + rBTorsion2.clear(); + + noalias(row(rBAxial, 0)) = axial_variation; //Normal force + noalias(row(rBBending1, 1)) = normal_curvature_variation; // Bending about n-axis + noalias(row(rBBending2, 2)) = binormal_curvature_variation; // Bending about v-axis + noalias(row(rBTorsion1, 3)) = normal_torsion_variation; // Torsion n in row 1 (shear stress) + noalias(row(rBTorsion2, 4)) = binormal_torsion_variation; // Torsion v in row 2 (shear stress) + + KRATOS_CATCH("") + } + + + void NonLinearBernoulliBeamElement3D::ComputeGMatrices( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + Matrix& rGAxial, + Matrix& rGBending1, + Matrix& rGBending2, + Matrix& rGTorsion1, + Matrix& rGTorsion2) + { + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + + // Get shape functions and derivatives at integration point + Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); + Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); + Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); + + // Extract kinematic variables + Vector3d current_first_base_vector = rKinematicVariables.r1; + Vector3d current_second_base_vector = rKinematicVariables.r2; + Vector3d reference_first_base_vector = rKinematicVariables.R1; + Vector3d reference_second_base_vector = rKinematicVariables.R2; + Vector3d reference_normal = rKinematicVariables.N0; + Vector3d reference_binormal = rKinematicVariables.V0; + double current_twist_angle = rKinematicVariables.phi; + double current_twist_angle_derivative = rKinematicVariables.phi_der; + double reference_twist_angle = rKinematicVariables.Phi; + double reference_twist_angle_derivative = rKinematicVariables.Phi_der; + Vector3d initial_reference_tangent = GetProperties()[T_0]; + + // Compute curvature and torsion variations + Matrix axial_second_variation(mNumberOfDofs, mNumberOfDofs); + Matrix normal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); + Matrix binormal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); + Matrix normal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); + Matrix binormal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); + axial_second_variation.clear(); + normal_curvature_second_variation.clear(); + binormal_curvature_second_variation.clear(); + normal_torsion_second_variation.clear(); + binormal_torsion_second_variation.clear(); + + //compute axial_variation + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + size_t dof_component = dof_index % mDofsPerNode; + size_t control_point_index = dof_index / mDofsPerNode; + if (dof_component > 2) + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + axial_second_variation(dof_index, second_dof_index) = 0.0; + else + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + size_t second_dof_component = second_dof_index % mDofsPerNode; + int second_control_point_index = second_dof_index / mDofsPerNode; + if (second_dof_component > 2) + axial_second_variation(dof_index, second_dof_index) = 0; + else + if (dof_component == second_dof_component) + axial_second_variation(dof_index, second_dof_index) = shape_function_derivatives[control_point_index] * shape_function_derivatives[second_control_point_index]; + else + axial_second_variation(dof_index, second_dof_index) = 0; + } + } + } + + //compute normal_curvature_second_variation, binormal_curvature_second_variation, normal_torsion_second_variation, binormal_torsion_second_variation + Vector3d current_tangent; + current_tangent.clear(); + Vector3d current_tangent_derivative; + current_tangent_derivative.clear(); + Vector3d reference_tangent; + reference_tangent.clear(); + Vector3d reference_tangent_derivative; + reference_tangent_derivative.clear(); + Vector3d initial_reference_tangent_derivative; + initial_reference_tangent_derivative.clear(); + Vector current_tangent_variation; + Vector current_tangent_derivative_variation; + Matrix current_tangent_second_variation; + Matrix current_tangent_derivative_second_variation; + Matrix3d current_lambda_matrix; + Matrix3d current_lambda_matrix_derivative; + Matrix3d reference_lambda_matrix; + Matrix3d reference_lambda_matrix_derivative; + Matrix3d current_rodrigues_matrix; + Matrix3d current_rodrigues_matrix_derivative; + Matrix3d reference_rodrigues_matrix; + Matrix3d reference_rodrigues_matrix_derivative; + + current_tangent = current_first_base_vector / norm_2(current_first_base_vector); + current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; + reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); + reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; + ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); + ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); + ComputeTangentSecondVariation(shape_function_derivatives, current_first_base_vector, current_tangent_second_variation); + ComputeTangentDerivativeSecondVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_second_variation); + + ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); + ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); + + ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); + ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); + ComputeLambdaMatrixVariations(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation, mSMatrixLambdaDerivativeVariation, mSMatrixLambdaSecondVariation, mSMatrixLambdaDerivativeSecondVariation); + + ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); + ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); + ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); + ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); + ComputeRodriguesMatrixSecondVariation(current_tangent, current_tangent_variation, current_tangent_second_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesSecondVariation); + ComputeRodriguesMatrixDerivativeSecondVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeSecondVariation); + + ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); + ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); + + Matrix3d reference_rodrigues_lambda_derivative_product; + reference_rodrigues_lambda_derivative_product.clear(); + Matrix3d reference_rodrigues_derivative_lambda_product; + reference_rodrigues_derivative_lambda_product.clear(); + Matrix3d reference_rodrigues_lambda_product; + reference_rodrigues_lambda_product.clear(); + Matrix3d reference_rodrigues_lambda_product_derivative; + reference_rodrigues_lambda_product_derivative.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); + reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); + reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); + } + } + } + reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; + + Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; + current_lambda_reference_rodrigues_lambda_derivative_product.clear(); + Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; + current_lambda_reference_rodrigues_derivative_lambda_product.clear(); + Matrix3d current_lambda_reference_rodrigues_lambda_product; + current_lambda_reference_rodrigues_lambda_product.clear(); + Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; + current_lambda_derivative_reference_rodrigues_lambda_product.clear(); + Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; + current_lambda_reference_rodrigues_lambda_product_derivative.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + + current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; + + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); + Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); + Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); + Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); + Matrix3d cross_section_transformation; + cross_section_transformation.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + + Matrix3d cross_section_transformation_derivative; + cross_section_transformation_derivative.clear(); + cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; + + + mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); + mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); + mSMatrixLambdaVariationRodriguesLambda.clear(); + mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + } + + Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; + current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); + current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); + + current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; + + mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); + mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); + mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); + mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + } + + + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); + mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda + + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; + mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; + + mSMatrixLambdaSecondVariationRodriguesLambda.clear(); + mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.clear(); + mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.clear(); + mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + mSMatrixLambdaSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); + mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + } + } + } + } + } + + Matrix current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term; + current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term; + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term; + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.clear(); + Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term; + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.clear(); + + Matrix current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term; + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term; + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term; + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.clear(); + Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term; + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.clear(); + + Matrix current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term; + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term; + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term; + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.clear(); + Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term; + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.clear(); + Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term; + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term; + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); + Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term; + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + } + } + } + } + } + + Matrix cross_section_transformation_derivative_second_variation; + cross_section_transformation_derivative_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + cross_section_transformation_derivative_second_variation.clear(); + + Vector3d normal_vector; + normal_vector.clear(); + Vector3d binormal_vector; + binormal_vector.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); + binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); + } + } + + Vector normal_vector_variation; + normal_vector_variation.resize(3 * mNumberOfDofs); + normal_vector_variation.clear(); + Vector binormal_vector_variation; + binormal_vector_variation.resize(3 * mNumberOfDofs); + binormal_vector_variation.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (int product_index = 0;product_index < 3;product_index++) + { + normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); + binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); + } + } + } + + Matrix cross_section_transformation_second_variation; + cross_section_transformation_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); + cross_section_transformation_second_variation.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (int column_component = 0;column_component < 3;column_component++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + } + } + } + } + + Matrix normal_vector_second_variation; + normal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); + normal_vector_second_variation.clear(); + Matrix binormal_vector_second_variation; + binormal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); + binormal_vector_second_variation.clear(); + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + for (size_t product_index = 0;product_index < 3;product_index++) + { + normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index); + binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index); + } + } + } + } + + for (size_t row_component = 0;row_component < 3;row_component++) + { + for (size_t product_index = 0;product_index < 3;product_index++) + { + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + { + for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) + { + normal_curvature_second_variation(dof_index, second_dof_index) += 0; + normal_curvature_second_variation(dof_index, second_dof_index) += 0; + + normal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * normal_vector(row_component) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index) + + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); + + binormal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * binormal_vector(row_component) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + second_dof_index) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index) + + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); + } + } + } + } + + // Initialize G matrices + rGAxial.resize(mNumberOfDofs, mNumberOfDofs); + rGBending1.resize(mNumberOfDofs, mNumberOfDofs); + rGBending2.resize(mNumberOfDofs, mNumberOfDofs); + rGTorsion1.resize(mNumberOfDofs, mNumberOfDofs); + rGTorsion2.resize(mNumberOfDofs, mNumberOfDofs); + rGAxial.clear(); + rGBending1.clear(); + rGBending2.clear(); + rGTorsion1.clear(); + rGTorsion2.clear(); + + noalias(rGAxial) = axial_second_variation; + noalias(rGBending1) = normal_curvature_second_variation; + noalias(rGBending2) = binormal_curvature_second_variation; + noalias(rGTorsion1) = normal_torsion_second_variation; + noalias(rGTorsion1) = binormal_torsion_second_variation; + + KRATOS_CATCH("") + + } +} \ No newline at end of file diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h new file mode 100644 index 000000000000..22a5308214cd --- /dev/null +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -0,0 +1,469 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +#pragma once + +// System includes +#include + +// External includes + +// Project includes +#include "includes/define.h" +#include "includes/element.h" + +// Application includes +#include "iga_application_variables.h" +#include "custom_elements/beam_base_element_3D.h" + +namespace Kratos +{ + +///@name Kratos Classes +///@{ + +/** + * @class NonLinearBernoulliBeamElement3D + * @brief Three-dimensional Bernoulli beam element. + */ +class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D + : public BeamBaseElement3D +{ +protected: + + using Vector3d = array_1d; + using Matrix3d = BoundedMatrix; + Matrix mSMatrixRodriguesVariation; + Matrix mSMatrixLambdaVariation; + Matrix mSMatrixLambdaVariationRodriguesLambda; + Matrix mSMatrixRodriguesLambdaVariationRodriguesLambda; + Matrix mSMatrixRodriguesVariationLambdaRodriguesLambda; + Matrix mSMatrixRodriguesLambdaRodriguesLambdaVariation; + + Matrix mSMatrixRodriguesDerivativeVariation; + Matrix mSMatrixLambdaDerivativeVariation; + Matrix mSMatrixLambdaDerivativeVariationRodriguesLambda; + Matrix mSMatrixLambdaVariationRodriguesDerivativeLambda; + Matrix mSMatrixLambdaVariationRodriguesLambdaDerivative; + + Matrix mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; + Matrix mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda; + Matrix mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda; + Matrix mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative; + + Matrix mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda; + Matrix mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda; + Matrix mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda; + Matrix mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative; + Matrix mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation; + + Matrix mSMatrixRodriguesSecondVariation; + Matrix mSMatrixLambdaSecondVariation; + Matrix mSMatrixLambdaSecondVariationRodriguesLambda; + Matrix mSMatrixRodriguesDerivativeSecondVariation; + Matrix mSMatrixLambdaDerivativeSecondVariation; + Matrix mSMatrixLambdaDerivativeSecondVariationRodriguesLambda; + Matrix mSMatrixLambdaSecondVariationRodriguesDerivativeLambda; + Matrix mSMatrixLambdaSecondVariationRodriguesLambdaDerivative; + + struct KinematicVariables + { + // Reference configuration + Vector3d R1; + Vector3d R2; + Vector3d R3; + + double A; + double B; + + // Current configuration + Vector3d r1; + Vector3d r2; + Vector3d r3; + + double a; + double b; + + // Cross-section directors + Vector3d N0; + Vector3d V0; + + Vector3d n; + Vector3d v; + + // Curvature components + double B_n; + double B_v; + + double b_n; + double b_v; + + double C_12; + double C_13; + + double c_12; + double c_13; + + // Rotations + double Phi; + double Phi_der; + + double phi; + double phi_der; + + explicit KinematicVariables( + const SizeType Dimension = 3) + { + R1 = ZeroVector(Dimension); + R2 = ZeroVector(Dimension); + R3 = ZeroVector(Dimension); + + r1 = ZeroVector(Dimension); + r2 = ZeroVector(Dimension); + r3 = ZeroVector(Dimension); + + N0 = ZeroVector(Dimension); + V0 = ZeroVector(Dimension); + + n = ZeroVector(Dimension); + v = ZeroVector(Dimension); + + A = 0.0; + B = 0.0; + + a = 0.0; + b = 0.0; + + B_n = 0.0; + B_v = 0.0; + + b_n = 0.0; + b_v = 0.0; + + C_12 = 0.0; + C_13 = 0.0; + + c_12 = 0.0; + c_13 = 0.0; + + Phi = 0.0; + Phi_der = 0.0; + + phi = 0.0; + phi_der = 0.0; + } + + }; + +public: + + ///@name Type Definitions + ///@{ + + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION( + NonLinearBernoulliBeamElement3D); + + using BaseType = BeamBaseElement3D; + using SizeType = typename BaseType::SizeType; + using IndexType = typename BaseType::IndexType; + using GeometryType = typename BaseType::GeometryType; + + ///@} + ///@name Life Cycle + ///@{ + + NonLinearBernoulliBeamElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry) + : BeamBaseElement3D( + NewId, + pGeometry) + { + } + + NonLinearBernoulliBeamElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) + : BeamBaseElement3D( + NewId, + pGeometry, + pProperties) + { + } + + NonLinearBernoulliBeamElement3D() + : BeamBaseElement3D() + { + } + + ~NonLinearBernoulliBeamElement3D() override = default; + + ///@} + ///@name Element Creation + ///@{ + + Element::Pointer Create( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) const override + { + return Kratos::make_intrusive( + NewId, + pGeometry, + pProperties); + } + + Element::Pointer Create( + IndexType NewId, + const NodesArrayType& rThisNodes, + PropertiesType::Pointer pProperties) const override + { + return Kratos::make_intrusive( + NewId, + GetGeometry().Create(rThisNodes), + pProperties); + } + + ///@} + ///@name Element Calculations + ///@{ + + void Initialize( + const ProcessInfo& rCurrentProcessInfo) override; + + void CalculateKinematics( + const IndexType IntegrationPointIndex, + KinematicVariables& rKinematicVariables); + + void CalculateConstitutiveVariables( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + ConstitutiveVariables& rConstitutiveVariables, + ConstitutiveLaw::Parameters& rConstitutiveLawParameters, + const ConstitutiveLaw::StressMeasure StressMeasure); + + void ComputeBMatrices( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + Matrix& rBAxial, + Matrix& rBBending1, + Matrix& rBBending2, + Matrix& rBTorsion1, + Matrix& rBTorsion2); + + void ComputeGMatrices( + const IndexType IntegrationPointIndex, + const KinematicVariables& rKinematicVariables, + Matrix& rGAxial, + Matrix& rGBending1, + Matrix& rGBending2, + Matrix& rGTorsion1, + Matrix& rGTorsion2); + + void ComputeGAxial( + const IndexType IntegrationPointIndex, + Matrix& rGAxial, + KinematicVariables& rKinematicVariables) const; + + void ComputeGBending( + const IndexType IntegrationPointIndex, + Matrix& rGBending1, + Matrix& rGBending2, + KinematicVariables& rKinematicVariables) const; + + void ComputeGTorsion( + const IndexType IntegrationPointIndex, + Matrix& rGTorsion1, + Matrix& rGTorsion2, + KinematicVariables& rKinematicVariables) const; + + void ComputeBAxial( + const IndexType IntegrationPointIndex, + Matrix& rBAxial, + KinematicVariables& rKinematicVariables) const; + + void ComputeBBending( + const IndexType IntegrationPointIndex, + Matrix& rBBending1, + Matrix& rBBending2, + KinematicVariables& rKinematicVariables) const; + + void ComputeBTorsion( + const IndexType IntegrationPointIndex, + Matrix& rBTorsion1, + Matrix& rBTorsion2, + KinematicVariables& rKinematicVariables) const; + + ///@} + ///@name Input and Output + ///@{ + + int Check( + const ProcessInfo& rCurrentProcessInfo) const override; + + ///@} + +private: + + void CalculateRightHandSide( + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType number_of_nodes = + GetGeometry().size(); + + const SizeType number_of_dofs = + number_of_nodes * mDofsPerNode; + + if (rRightHandSideVector.size() != number_of_dofs) { + rRightHandSideVector.resize( + number_of_dofs, + false); + } + + noalias(rRightHandSideVector) = + ZeroVector(number_of_dofs); + + MatrixType left_hand_side_matrix; + + CalculateAll( + left_hand_side_matrix, + rRightHandSideVector, + rCurrentProcessInfo, + false, + true); + } + + void CalculateLeftHandSide( + MatrixType& rLeftHandSideMatrix, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType number_of_nodes = + GetGeometry().size(); + + const SizeType number_of_dofs = + number_of_nodes * mDofsPerNode; + + VectorType right_hand_side_vector; + + if ( + rLeftHandSideMatrix.size1() != number_of_dofs || + rLeftHandSideMatrix.size2() != number_of_dofs) + { + rLeftHandSideMatrix.resize( + number_of_dofs, + number_of_dofs, + false); + } + + noalias(rLeftHandSideMatrix) = + ZeroMatrix( + number_of_dofs, + number_of_dofs); + + CalculateAll( + rLeftHandSideMatrix, + right_hand_side_vector, + rCurrentProcessInfo, + true, + false); + } + + void CalculateLocalSystem( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override + { + const SizeType number_of_nodes = + GetGeometry().size(); + + const SizeType number_of_dofs = + number_of_nodes * mDofsPerNode; + + if (rRightHandSideVector.size() != number_of_dofs) { + rRightHandSideVector.resize( + number_of_dofs, + false); + } + + noalias(rRightHandSideVector) = + ZeroVector(number_of_dofs); + + if ( + rLeftHandSideMatrix.size1() != number_of_dofs || + rLeftHandSideMatrix.size2() != number_of_dofs) + { + rLeftHandSideMatrix.resize( + number_of_dofs, + number_of_dofs, + false); + } + + noalias(rLeftHandSideMatrix) = + ZeroMatrix( + number_of_dofs, + number_of_dofs); + + CalculateAll( + rLeftHandSideMatrix, + rRightHandSideVector, + rCurrentProcessInfo, + true, + true); + } + + void CalculateAll( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo, + const bool CalculateStiffnessMatrixFlag, + const bool CalculateResidualVectorFlag) override; + + void ComputeReferenceTwistAngleAndDerivative( + const KinematicVariables& rKinematicVariables, + double& rPhi, + double& rPhiDerivative); + + double CalculateDeltaPhi( + const KinematicVariables& rKinematicVariables, + const Vector3d& rNormal); + + void ComputeReferenceCrossSectionGeometry( + KinematicVariables& rKinematicVariables); + + void ComputeCurrentCrossSectionGeometry( + KinematicVariables& rKinematicVariables); + + friend class Serializer; + + void save( + Serializer& rSerializer) const override + { + KRATOS_SERIALIZE_SAVE_BASE_CLASS( + rSerializer, + BeamBaseElement3D); + } + + void load( + Serializer& rSerializer) override + { + KRATOS_SERIALIZE_LOAD_BASE_CLASS( + rSerializer, + BeamBaseElement3D); + } +}; + +///@} + +} // Namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 84c695045209..79655c9aedc8 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -221,6 +221,16 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(CONNECTED_CONDITIONS) KRATOS_REGISTER_VARIABLE(INTERPOLATION_NODES_ID) KRATOS_REGISTER_VARIABLE(BREP_ID) + + + KRATOS_REGISTER_VARIABLE(I_T) + KRATOS_REGISTER_VARIABLE(I_N) + KRATOS_REGISTER_VARIABLE(I_V) + + KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) + + KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(T_0) + KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(N_0) } } // namespace Kratos diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index be207af841f0..c55fe7ed4516 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -21,7 +21,7 @@ #include "custom_elements/truss_embedded_edge_element.h" #include "custom_elements/beam_thin_element_2D.h" #include "custom_elements/beam_thick_element_2D.h" -#include "custom_elements/beam_bernoulli_element_3D.h" +#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" #include "custom_elements/iga_membrane_element.h" #include "custom_elements/shell_3p_element.h" #include "custom_elements/shell_5p_hierarchic_element.h" diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index 22adc0b5f0c3..87b47d07ea67 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -104,5 +104,14 @@ KRATOS_CREATE_VARIABLE(std::vector, CONNECTED_CONDITIONS) KRATOS_CREATE_VARIABLE(std::vector, INTERPOLATION_NODES_ID) KRATOS_CREATE_VARIABLE(int, BREP_ID) +KRATOS_CREATE_VARIABLE(double, I_T) +KRATOS_CREATE_VARIABLE(double, I_N) +KRATOS_CREATE_VARIABLE(double, I_V) + +KRATOS_CREATE_VARIABLE(Matrix, LOCAL_AXIS_ORIENTATION) + +KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(T_0) +KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(N_0) + } // namespace Kratos diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index 58bd03e2dd02..59166dc79b60 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -119,6 +119,14 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, std::vector, CO KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, std::vector, INTERPOLATION_NODES_ID) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, int, BREP_ID) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_T) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_N) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_V) + +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Matrix, LOCAL_AXIS_ORIENTATION) + +KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, T_0) +KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, N_0) } // namespace Kratos From a535c9d227f895153174b67b3c7dc7743e82535f Mon Sep 17 00:00:00 2001 From: Alicia Date: Sat, 14 Nov 2026 15:05:15 +0100 Subject: [PATCH 07/32] debugging fixes and tests are running --- ...tion_diffusion_stationary_matrix_solver.py | 2 +- .../tests/FSI_problem_emulator_test.py | 8 +- applications/IgaApplication/CMakeLists.txt | 1 + .../custom_elements/beam_base_element_3D.cpp | 4 +- .../non_linear_bernoulli_beam_element_3D.cpp | 401 ++-- .../custom_modelers/refinement_modeler.cpp | 281 ++- .../custom_modelers/refinement_modeler.h | 1 + .../compute_beam_vectors_process.cpp | 150 ++ .../compute_beam_vectors_process.h | 118 + ...add_custom_constitutive_laws_to_python.cpp | 31 + .../add_custom_constitutive_laws_to_python.h | 27 + .../add_custom_processes_to_python.cpp | 10 +- .../add_custom_utilities_to_python.cpp | 72 + .../custom_python/iga_python_application.cpp | 21 +- .../IgaApplication/iga_application.cpp | 45 +- applications/IgaApplication/iga_application.h | 13 +- .../iga_application_variables.cpp | 29 +- .../iga_application_variables.h | 32 +- .../compute_beam_vectors_process.py | 32 + .../python_scripts/iga_vtk_output_process.py | 441 +++- ..._non_linear_bernoulli_beam_element_test.py | 769 +++++++ .../curve_h_refinements.iga.json | 13 + .../tests/test_eigen_direct_solver.py | 31 +- .../tests/test_eigensystem_solver.py | 14 +- .../tests/test_feast_eigensystem_solver.py | 29 +- .../tests/test_mkl.py | 21 +- .../python_scripts/strategy_python.py | 2 +- ...ural_mechanics_custom_scipy_base_solver.py | 6 +- kipping... | 1893 +++++++++++++++++ kratos/geometries/nurbs_curve_geometry.h | 106 + .../nurbs_curve_refinement_utilities.cpp | 646 ++++++ .../nurbs_curve_refinement_utilities.h | 62 + kratos/python/add_strategies_to_python.cpp | 2 +- .../python_linear_solver_factory.py | 2 +- kratos/tests/test_condition_number.py | 2 +- 35 files changed, 4816 insertions(+), 501 deletions(-) create mode 100644 applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp create mode 100644 applications/IgaApplication/custom_processes/compute_beam_vectors_process.h create mode 100644 applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp create mode 100644 applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h create mode 100644 applications/IgaApplication/python_scripts/compute_beam_vectors_process.py create mode 100644 applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py create mode 100644 applications/IgaApplication/tests/modeler_tests/curve_h_refinements.iga.json create mode 100644 kipping... create mode 100644 kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.cpp create mode 100644 kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h diff --git a/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py b/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py index 3486b5f60020..095524f13150 100644 --- a/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py +++ b/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py @@ -37,7 +37,7 @@ def SolveSolutionStep(self): # self._AssignSystemVector(x) # ---- - + KratosMultiphysics.Logger.PrintInfo("::[{}]:: ".format(self.__class__.__name__), "Extracted system matrix and vector.") KratosMultiphysics.Logger.PrintInfo("::[{}]:: ".format(self.__class__.__name__), "No solution triggered!") diff --git a/applications/FSIApplication/tests/FSI_problem_emulator_test.py b/applications/FSIApplication/tests/FSI_problem_emulator_test.py index 483c31012144..7f82777df93e 100644 --- a/applications/FSIApplication/tests/FSI_problem_emulator_test.py +++ b/applications/FSIApplication/tests/FSI_problem_emulator_test.py @@ -174,7 +174,7 @@ def RunTestCase(self): # Residual computation disp_residual = self.ComputeDirichletNeumannResidual() - nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual) + nl_res_norm = SparseSpace().TwoNorm(disp_residual) print("nl_it: ",nl_it," nl_res_norm: ",nl_res_norm) @@ -290,7 +290,7 @@ def RunTestCaseIBN(self): # Compute and check first residual disp_residual = self.__ComputeInitialResidual() - nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual) + nl_res_norm = SparseSpace().TwoNorm(disp_residual) if nl_res_norm > self.nl_tol: for nl_it in range(self.max_nl_it): @@ -318,7 +318,7 @@ def RunTestCaseIBN(self): disp_residual = self.__ComputeStructureResidual() # Residual computation - nl_res_norm = UblasSparseSpace().TwoNorm(disp_residual) + nl_res_norm = SparseSpace().TwoNorm(disp_residual) print("nl_it: ",nl_it," nl_res_norm: ",nl_res_norm) # Check convergence @@ -467,4 +467,4 @@ def __ComputeStructureResidual(self): # test.test_FSI_problem_emulator_with_MVQN() test.test_FSI_problem_emulator_with_IBQN_MVQN() # test.test_FSI_problem_emulator_with_MVQN_recursive() - test.tearDown() + test.tearDown() \ No newline at end of file diff --git a/applications/IgaApplication/CMakeLists.txt b/applications/IgaApplication/CMakeLists.txt index 38b16349bd7c..068228574aa7 100644 --- a/applications/IgaApplication/CMakeLists.txt +++ b/applications/IgaApplication/CMakeLists.txt @@ -14,6 +14,7 @@ file(GLOB_RECURSE KRATOS_IGA_APPLICATION_CORE ${CMAKE_CURRENT_SOURCE_DIR}/iga_application.cpp ${CMAKE_CURRENT_SOURCE_DIR}/iga_application_variables.cpp ${CMAKE_CURRENT_SOURCE_DIR}/custom_conditions/*.cpp + ${CMAKE_CURRENT_SOURCE_DIR}/custom_constitutive/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/custom_elements/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/custom_modelers/*.cpp ${CMAKE_CURRENT_SOURCE_DIR}/custom_processes/*.cpp diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index fde525be8db7..c7e8a9f02c55 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -796,10 +796,10 @@ namespace Kratos ++dof_index) { const size_t dof_component = - dof_index % mNumberOfDofs; + dof_index % mDofsPerNode; const size_t second_dof_component = - second_dof_index % mNumberOfDofs; + second_dof_index % mDofsPerNode; if ( dof_component > 2 || diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index d4417883cac0..07590d582cbf 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -178,97 +178,115 @@ namespace Kratos } - void NonLinearBernoulliBeamElement3D::CalculateAll( - MatrixType& rLeftHandSideMatrix, - VectorType& rRightHandSideVector, - const ProcessInfo& rCurrentProcessInfo, - const bool CalculateStiffnessMatrixFlag, - const bool CalculateResidualVectorFlag) +void NonLinearBernoulliBeamElement3D::CalculateAll( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo, + const bool CalculateStiffnessMatrixFlag, + const bool CalculateResidualVectorFlag) +{ + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + const auto& r_integration_points = + r_geometry.IntegrationPoints(); + + const int build_level = rCurrentProcessInfo.Has(BUILD_LEVEL) + ? rCurrentProcessInfo[BUILD_LEVEL] + : 0; + + const bool calculate_material_stiffness = + build_level != 2; + + const bool calculate_geometric_stiffness = + build_level != 1; + + Vector stress_axial = ZeroVector(5); + Vector stress_bending_1 = ZeroVector(5); + Vector stress_bending_2 = ZeroVector(5); + Vector stress_torsion_1 = ZeroVector(5); + Vector stress_torsion_2 = ZeroVector(5); + + // Temporary diagnostics for geometric stiffness entry (0, 5) + double debug_geo_axial = 0.0; + double debug_geo_bending_1 = 0.0; + double debug_geo_bending_2 = 0.0; + double debug_geo_torsion_1 = 0.0; + double debug_geo_torsion_2 = 0.0; + + for ( + IndexType point_number = 0; + point_number < r_integration_points.size(); + ++point_number) { - KRATOS_TRY - - const auto& r_geometry = GetGeometry(); - const auto& r_integration_points = - r_geometry.IntegrationPoints(); - - Vector stress_axial = ZeroVector(5); - Vector stress_bending_1 = ZeroVector(5); - Vector stress_bending_2 = ZeroVector(5); - Vector stress_torsion_1 = ZeroVector(5); - Vector stress_torsion_2 = ZeroVector(5); - - for ( - IndexType point_number = 0; - point_number < r_integration_points.size(); - ++point_number) - { - // Compute kinematics and metric - KinematicVariables kinematic_variables( - GetGeometry().WorkingSpaceDimension()); - - CalculateKinematics( - point_number, - kinematic_variables); - - // Create constitutive law parameters - ConstitutiveLaw::Parameters constitutive_law_parameters( - GetGeometry(), - GetProperties(), - rCurrentProcessInfo); - - ConstitutiveVariables constitutive_variables(5); - - CalculateConstitutiveVariables( - point_number, - kinematic_variables, - constitutive_variables, - constitutive_law_parameters, - ConstitutiveLaw::StressMeasure_PK2); - - Matrix b_axial; - Matrix b_bending_1; - Matrix b_bending_2; - Matrix b_torsion_1; - Matrix b_torsion_2; - - ComputeBMatrices( - point_number, - kinematic_variables, - b_axial, - b_bending_1, - b_bending_2, - b_torsion_1, - b_torsion_2); - - Matrix g_axial; - Matrix g_bending_1; - Matrix g_bending_2; - Matrix g_torsion_1; - Matrix g_torsion_2; - - ComputeGMatrices( - point_number, - kinematic_variables, - g_axial, - g_bending_1, - g_bending_2, - g_torsion_1, - g_torsion_2); - - // Assemble stiffness with cross-sectional scaling - const double integration_weight = - r_integration_points[point_number].Weight() * - kinematic_variables.A; - - const double inverse_a2 = - 1.0 / - (kinematic_variables.A * - kinematic_variables.A); - - const double inverse_a4 = - inverse_a2 * inverse_a2; - - if (CalculateStiffnessMatrixFlag == true) { + // Compute kinematics and metric + KinematicVariables kinematic_variables( + GetGeometry().WorkingSpaceDimension()); + + CalculateKinematics( + point_number, + kinematic_variables); + + // Create constitutive law parameters + ConstitutiveLaw::Parameters constitutive_law_parameters( + GetGeometry(), + GetProperties(), + rCurrentProcessInfo); + + ConstitutiveVariables constitutive_variables(5); + + CalculateConstitutiveVariables( + point_number, + kinematic_variables, + constitutive_variables, + constitutive_law_parameters, + ConstitutiveLaw::StressMeasure_PK2); + + Matrix b_axial; + Matrix b_bending_1; + Matrix b_bending_2; + Matrix b_torsion_1; + Matrix b_torsion_2; + + ComputeBMatrices( + point_number, + kinematic_variables, + b_axial, + b_bending_1, + b_bending_2, + b_torsion_1, + b_torsion_2); + + Matrix g_axial; + Matrix g_bending_1; + Matrix g_bending_2; + Matrix g_torsion_1; + Matrix g_torsion_2; + + ComputeGMatrices( + point_number, + kinematic_variables, + g_axial, + g_bending_1, + g_bending_2, + g_torsion_1, + g_torsion_2); + + // Assemble stiffness with cross-sectional scaling + const double integration_weight = + r_integration_points[point_number].Weight() * + kinematic_variables.A; + + const double inverse_a2 = + 1.0 / + (kinematic_variables.A * + kinematic_variables.A); + + const double inverse_a4 = + inverse_a2 * inverse_a2; + + if (CalculateStiffnessMatrixFlag == true) { + if (calculate_material_stiffness) { // Material stiffness rLeftHandSideMatrix += inverse_a4 * @@ -314,104 +332,182 @@ namespace Kratos Matrix(prod( constitutive_variables.ConstitutiveMatrix, b_torsion_2))); + } - // Geometrical stiffness - rLeftHandSideMatrix += + if (calculate_geometric_stiffness) { + // Temporary diagnostic contributions for K_geo(0, 5) + debug_geo_axial += inverse_a4 * integration_weight * - g_axial * + g_axial(0, 5) * constitutive_variables.StressVector[0]; - rLeftHandSideMatrix += + debug_geo_bending_1 += inverse_a4 * integration_weight * - g_bending_1 * + g_bending_1(0, 5) * constitutive_variables.StressVector[1]; - rLeftHandSideMatrix += + debug_geo_bending_2 += inverse_a4 * integration_weight * - g_bending_2 * + g_bending_2(0, 5) * constitutive_variables.StressVector[2]; - rLeftHandSideMatrix += + debug_geo_torsion_1 += inverse_a2 * integration_weight * - g_torsion_1 * + g_torsion_1(0, 5) * constitutive_variables.StressVector[3]; - rLeftHandSideMatrix += + debug_geo_torsion_2 += inverse_a2 * integration_weight * - g_torsion_2 * - constitutive_variables.StressVector[4]; - } - - if (CalculateResidualVectorFlag == true) { - // Map stress components to different behaviors - stress_axial[0] = - constitutive_variables.StressVector[0]; - - stress_bending_1[1] = - constitutive_variables.StressVector[1]; - - stress_bending_2[2] = - constitutive_variables.StressVector[2]; - - stress_torsion_1[3] = - constitutive_variables.StressVector[3]; - - stress_torsion_2[4] = + g_torsion_2(0, 5) * constitutive_variables.StressVector[4]; - // Assemble internal forces - rRightHandSideVector -= + // Geometrical stiffness + rLeftHandSideMatrix += inverse_a4 * integration_weight * - prod( - trans(b_axial), - stress_axial); + g_axial * + constitutive_variables.StressVector[0]; - rRightHandSideVector -= + rLeftHandSideMatrix += inverse_a4 * integration_weight * - prod( - trans(b_bending_1), - stress_bending_1); + g_bending_1 * + constitutive_variables.StressVector[1]; - rRightHandSideVector -= + rLeftHandSideMatrix += inverse_a4 * integration_weight * - prod( - trans(b_bending_2), - stress_bending_2); + g_bending_2 * + constitutive_variables.StressVector[2]; - rRightHandSideVector -= + rLeftHandSideMatrix += inverse_a2 * integration_weight * - prod( - trans(b_torsion_1), - stress_torsion_1); + g_torsion_1 * + constitutive_variables.StressVector[3]; - rRightHandSideVector -= + rLeftHandSideMatrix += inverse_a2 * integration_weight * - prod( - trans(b_torsion_2), - stress_torsion_2); + g_torsion_2 * + constitutive_variables.StressVector[4]; } } - KRATOS_CATCH("") + if (CalculateResidualVectorFlag == true) { + // Map stress components to different behaviors + stress_axial[0] = + constitutive_variables.StressVector[0]; + + stress_bending_1[1] = + constitutive_variables.StressVector[1]; + + stress_bending_2[2] = + constitutive_variables.StressVector[2]; + + stress_torsion_1[3] = + constitutive_variables.StressVector[3]; + + stress_torsion_2[4] = + constitutive_variables.StressVector[4]; + + // Assemble internal forces + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_axial), + stress_axial); + + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_bending_1), + stress_bending_1); + + rRightHandSideVector -= + inverse_a4 * + integration_weight * + prod( + trans(b_bending_2), + stress_bending_2); + + rRightHandSideVector -= + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_1), + stress_torsion_1); + + rRightHandSideVector -= + inverse_a2 * + integration_weight * + prod( + trans(b_torsion_2), + stress_torsion_2); + } } + if ( + CalculateStiffnessMatrixFlag && + calculate_geometric_stiffness && + build_level == 2) + { + std::cout + << "\n--- Geometric contribution (0,5) ---" + << std::endl; + + std::cout + << "axial = " + << debug_geo_axial + << std::endl; + + std::cout + << "bending 1 = " + << debug_geo_bending_1 + << std::endl; + + std::cout + << "bending 2 = " + << debug_geo_bending_2 + << std::endl; + + std::cout + << "torsion 1 = " + << debug_geo_torsion_1 + << std::endl; + + std::cout + << "torsion 2 = " + << debug_geo_torsion_2 + << std::endl; + + std::cout + << "sum = " + << debug_geo_axial + + debug_geo_bending_1 + + debug_geo_bending_2 + + debug_geo_torsion_1 + + debug_geo_torsion_2 + << std::endl; + } + + KRATOS_CATCH("") +} + int NonLinearBernoulliBeamElement3D::Check( const ProcessInfo& rCurrentProcessInfo) const { KRATOS_TRY - Check(rCurrentProcessInfo); + BeamBaseElement3D::Check(rCurrentProcessInfo); const double numerical_limit = std::numeric_limits::epsilon(); @@ -1845,8 +1941,23 @@ namespace Kratos { for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) { - normal_curvature_second_variation(dof_index, second_dof_index) += 0; - normal_curvature_second_variation(dof_index, second_dof_index) += 0; + const double first_base_vector_variation_dof = + row_component == dof_index % mDofsPerNode + ? shape_function_derivatives[dof_index / mDofsPerNode] + : 0.0; + + const double first_base_vector_variation_second_dof = + row_component == second_dof_index % mDofsPerNode + ? shape_function_derivatives[second_dof_index / mDofsPerNode] + : 0.0; + + normal_curvature_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * current_first_base_vector(row_component) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_second_dof + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_dof; + + binormal_curvature_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * current_first_base_vector(row_component) + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_second_dof + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_dof; normal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * normal_vector(row_component) + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) @@ -1878,7 +1989,7 @@ namespace Kratos noalias(rGBending1) = normal_curvature_second_variation; noalias(rGBending2) = binormal_curvature_second_variation; noalias(rGTorsion1) = normal_torsion_second_variation; - noalias(rGTorsion1) = binormal_torsion_second_variation; + noalias(rGTorsion2) = binormal_torsion_second_variation; KRATOS_CATCH("") diff --git a/applications/IgaApplication/custom_modelers/refinement_modeler.cpp b/applications/IgaApplication/custom_modelers/refinement_modeler.cpp index 3a7b946e248e..46bbfe45d341 100644 --- a/applications/IgaApplication/custom_modelers/refinement_modeler.cpp +++ b/applications/IgaApplication/custom_modelers/refinement_modeler.cpp @@ -68,210 +68,173 @@ namespace Kratos << "Missing \"geometry_type\".\n" << rParameters << std::endl; if (rParameters["geometry_type"].GetString() == "NurbsSurface") { + } else if (rParameters["geometry_type"].GetString() == "NurbsCurve") { for (IndexType n = 0; n < geometry_list.size(); ++n) { - auto p_nurbs_surface = (geometry_list[n].size() > 0) - ? dynamic_pointer_cast>>(geometry_list(n)) - : dynamic_pointer_cast>>(geometry_list(n)->pGetGeometryPart(GeometryType::BACKGROUND_GEOMETRY_INDEX)); + auto p_nurbs_curve = + std::dynamic_pointer_cast>>( + geometry_list(n) + ); + + if (!p_nurbs_curve) { + p_nurbs_curve = + std::dynamic_pointer_cast>>( + geometry_list(n)->pGetGeometryPart( + GeometryType::BACKGROUND_GEOMETRY_INDEX + ) + ); + } - if (rParameters["parameters"].Has("increase_degree_u")) { - SizeType increase_degree_u = rParameters["parameters"]["increase_degree_u"].GetInt(); + KRATOS_ERROR_IF_NOT(p_nurbs_curve) + << "Selected geometry is not a NurbsCurveGeometry and does not contain " + << "a NurbsCurveGeometry as BACKGROUND_GEOMETRY.\nSelected geometry:\n" + << *geometry_list(n) << std::endl; - if (increase_degree_u > 0) { - std::vector spans_local_space; - p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); + if (rParameters["parameters"].Has("increase_degree")) { + const SizeType increase_degree = + rParameters["parameters"]["increase_degree"].GetInt(); - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by elevating degree in u: " - << increase_degree_u << std::endl; + if (increase_degree > 0) { + KRATOS_INFO_IF( + "::[RefinementModeler]::ApplyRefinement", + mEchoLevel > 1 + ) + << "Refining nurbs curve #" << p_nurbs_curve->Id() + << " by elevating degree: " << increase_degree << std::endl; PointerVector PointsRefined; - Vector KnotsURefined; + Vector KnotsRefined; Vector WeightsRefined; - NurbsSurfaceRefinementUtilities::DegreeElevationU(*(p_nurbs_surface.get()), increase_degree_u, - PointsRefined, KnotsURefined, WeightsRefined); + NurbsCurveRefinementUtilities::DegreeElevation( + *p_nurbs_curve, + increase_degree, + PointsRefined, + KnotsRefined, + WeightsRefined + ); - // Recreate nodes in model part to ensure correct assignment of dofs - for (auto& r_point : p_nurbs_surface->Points()) { + for (auto& r_point : p_nurbs_curve->Points()) { r_point.Set(TO_ERASE, true); } + r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; + + IndexType node_id = r_model_part.Nodes().empty() + ? 1 + : (r_model_part.NodesEnd() - 1)->Id() + 1; for (IndexType i = 0; i < PointsRefined.size(); ++i) { if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); + PointsRefined(i) = r_model_part.CreateNewNode( + node_id, + PointsRefined[i][0], + PointsRefined[i][1], + PointsRefined[i][2] + ); node_id++; } } - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "New knot vector: " << KnotsURefined + KRATOS_INFO_IF( + "::[RefinementModeler]::ApplyRefinement", + mEchoLevel > 1 + ) + << "New knot vector: " << KnotsRefined << ", new weights vector: " << WeightsRefined << std::endl; - p_nurbs_surface->SetInternals(PointsRefined, - p_nurbs_surface->PolynomialDegreeU() + increase_degree_u, p_nurbs_surface->PolynomialDegreeV(), - KnotsURefined, p_nurbs_surface->KnotsV(), - WeightsRefined); - } else { - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() - << " by elevating degree in u, however increase_degree_u is set to 0." << std::endl; + p_nurbs_curve->SetInternals( + PointsRefined, + p_nurbs_curve->PolynomialDegree(0) + increase_degree, + KnotsRefined, + WeightsRefined + ); } } - if (rParameters["parameters"].Has("increase_degree_v")) { - SizeType increase_degree_v = rParameters["parameters"]["increase_degree_v"].GetInt(); - - if (increase_degree_v > 0) { - std::vector spans_local_space; - p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); - - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by elevating degree in v: " - << increase_degree_v << std::endl; - - PointerVector PointsRefined; - Vector KnotsVRefined; - Vector WeightsRefined; - - NurbsSurfaceRefinementUtilities::DegreeElevationV(*(p_nurbs_surface.get()), increase_degree_v, - PointsRefined, KnotsVRefined, WeightsRefined); - // Recreate nodes in model part to ensure correct assignment of dofs - for (auto& r_point : p_nurbs_surface->Points()) { - r_point.Set(TO_ERASE, true); - } - r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; + if (rParameters["parameters"].Has("insert_nb_per_span")) { + const IndexType nb_per_span = + rParameters["parameters"]["insert_nb_per_span"].GetInt(); - for (IndexType i = 0; i < PointsRefined.size(); ++i) { - if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); - node_id++; - } - } - - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "New knot vector: " << KnotsVRefined - << ", new weights vector: " << WeightsRefined << std::endl; - - p_nurbs_surface->SetInternals(PointsRefined, - p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV() + increase_degree_v, - p_nurbs_surface->KnotsU(), KnotsVRefined, - WeightsRefined); - } else { - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() - << " by elevating degree in v, however increase_degree_v is set to 0." << std::endl; - } - } - if (rParameters["parameters"].Has("insert_nb_per_span_u")) { - const IndexType nb_per_span_u = rParameters["parameters"]["insert_nb_per_span_u"].GetInt(); - - if (nb_per_span_u > 0) { + if (nb_per_span > 0) { std::vector spans_local_space; - p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); - - std::vector knots_to_insert_u; - for (IndexType i = 0; i < spans_local_space.size() - 1; ++i) { - const double delta_u = (spans_local_space[i + 1] - spans_local_space[i]) / (nb_per_span_u + 1); - for (IndexType j = 1; j < nb_per_span_u + 1; ++j) { - knots_to_insert_u.push_back(spans_local_space[i] + delta_u * j); + p_nurbs_curve->SpansLocalSpace(spans_local_space); + + std::vector knots_to_insert; + + for ( + IndexType i = 0; + i < spans_local_space.size() - 1; + ++i) + { + const double delta = + (spans_local_space[i + 1] - spans_local_space[i]) / + static_cast(nb_per_span + 1); + + for ( + IndexType j = 1; + j < nb_per_span + 1; + ++j) + { + knots_to_insert.push_back( + spans_local_space[i] + delta * j + ); } } - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by inserting knots in u: " - << knots_to_insert_u << std::endl; + KRATOS_INFO_IF( + "::[RefinementModeler]::ApplyRefinement", + mEchoLevel > 1 + ) + << "Refining nurbs curve #" << p_nurbs_curve->Id() + << " by inserting knots: " << knots_to_insert << std::endl; PointerVector PointsRefined; - Vector KnotsURefined; + Vector KnotsRefined; Vector WeightsRefined; - NurbsSurfaceRefinementUtilities::KnotRefinementU(*(p_nurbs_surface.get()), knots_to_insert_u, - PointsRefined, KnotsURefined, WeightsRefined); + NurbsCurveRefinementUtilities::KnotRefinement( + *p_nurbs_curve, + knots_to_insert, + PointsRefined, + KnotsRefined, + WeightsRefined + ); - // Recreate nodes in model part to ensure correct assignment of dofs - for (auto& r_point : p_nurbs_surface->Points()) { + for (auto& r_point : p_nurbs_curve->Points()) { r_point.Set(TO_ERASE, true); } + r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; - + + IndexType node_id = r_model_part.Nodes().empty() + ? 1 + : (r_model_part.NodesEnd() - 1)->Id() + 1; + for (IndexType i = 0; i < PointsRefined.size(); ++i) { if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); + PointsRefined(i) = r_model_part.CreateNewNode( + node_id, + PointsRefined[i][0], + PointsRefined[i][1], + PointsRefined[i][2] + ); node_id++; } } - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "New knot vector: " << KnotsURefined + KRATOS_INFO_IF( + "::[RefinementModeler]::ApplyRefinement", + mEchoLevel > 1 + ) + << "New knot vector: " << KnotsRefined << ", new weights vector: " << WeightsRefined << std::endl; - p_nurbs_surface->SetInternals(PointsRefined, - p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV(), - KnotsURefined, p_nurbs_surface->KnotsV(), - WeightsRefined); - } else { - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() - << " by inserting knots in u, however insert_nb_per_span_u is set to 0." << std::endl; - } - } - if (rParameters["parameters"].Has("insert_nb_per_span_v")) { - const IndexType nb_per_span_v = rParameters["parameters"]["insert_nb_per_span_v"].GetInt(); - - if (nb_per_span_v > 0) { - std::vector spans_local_space; - p_nurbs_surface->SpansLocalSpace(spans_local_space, 1); - - std::vector knots_to_insert_v; - for (IndexType i = 0; i < spans_local_space.size() - 1; ++i) { - const double delta_v = (spans_local_space[i + 1] - spans_local_space[i]) / (nb_per_span_v + 1); - for (IndexType j = 1; j < nb_per_span_v + 1; ++j) { - knots_to_insert_v.push_back(spans_local_space[i] + delta_v * j); - } - } - - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by inserting knots in v: " - << knots_to_insert_v << std::endl; - - PointerVector PointsRefined; - Vector KnotsVRefined; - Vector WeightsRefined; - - NurbsSurfaceRefinementUtilities::KnotRefinementV(*(p_nurbs_surface.get()), knots_to_insert_v, - PointsRefined, KnotsVRefined, WeightsRefined); - - // Recreate nodes in model part to ensure correct assignment of dofs - for (auto& r_point : p_nurbs_surface->Points()) { - r_point.Set(TO_ERASE, true); - } - r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; - - for (IndexType i = 0; i < PointsRefined.size(); ++i) { - if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); - node_id++; - } - } - - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "New knot vector: " << KnotsVRefined - << ", new weights vector: " << WeightsRefined << std::endl; - - p_nurbs_surface->SetInternals(PointsRefined, - p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV(), - p_nurbs_surface->KnotsU(), KnotsVRefined, - WeightsRefined); - } - else { - KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) - << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() - << " by inserting knots in v, however insert_nb_per_span_v is set to 0." << std::endl; + p_nurbs_curve->SetInternals( + PointsRefined, + p_nurbs_curve->PolynomialDegree(0), + KnotsRefined, + WeightsRefined + ); } } } diff --git a/applications/IgaApplication/custom_modelers/refinement_modeler.h b/applications/IgaApplication/custom_modelers/refinement_modeler.h index c1b66d1f11d1..feb2c78a34bb 100644 --- a/applications/IgaApplication/custom_modelers/refinement_modeler.h +++ b/applications/IgaApplication/custom_modelers/refinement_modeler.h @@ -24,6 +24,7 @@ #include "geometries/nurbs_shape_function_utilities/nurbs_surface_refinement_utilities.h" #include "geometries/nurbs_surface_geometry.h" #include "utilities/variable_utils.h" +#include "geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h" namespace Kratos { diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp new file mode 100644 index 000000000000..e3d2e216e495 --- /dev/null +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -0,0 +1,150 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ \. +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// + +// System includes +#include + +// External includes + +// Project includes +#include "compute_beam_vectors_process.h" +#include "utilities/math_utils.h" +#include "includes/define.h" +#include "iga_application_variables.h" +#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" +#include "custom_elements/beam_base_element_3D.h" + +namespace Kratos +{ + +//for normal beam +ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( + ModelPart& rModelPart) + : Process() + , mrThisModelPart(rModelPart) + , mpParentCurve(&(rModelPart.ElementsBegin()->GetGeometry().GetGeometryParent(0))) +{ +} + +//for normal beam +ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( + ModelPart& rModelPart, + const NurbsCurveGeometry<3, PointerVector>& rParentCurve) + : Process() + , mrThisModelPart(rModelPart) + , mpParentCurve(&rParentCurve) +{ +} + +//for embedded beam +ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( + ModelPart& rModelPart, + const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rParentCurve) + : Process() + , mrThisModelPart(rModelPart) + , mpParentCurve(&rParentCurve) +{ +} + +void ComputeBeamVectorsProcess::ComputeT0AndN0( + const NurbsCurveGeometry<3, PointerVector>& rCurve, + array_1d& rT0, + array_1d& rN0) +{ + array_1d V = ZeroVector(3); + array_1d up = ZeroVector(3); + + // Evaluate at the start of the beam (parameter = 0) + array_1d local_coordinates = ZeroVector(3); + std::vector> global_space_derivatives; + + rCurve.GlobalSpaceDerivatives(global_space_derivatives, local_coordinates, 1); + + + // Tangent vector (normalized) + rT0 = global_space_derivatives[1]; + rT0 /= norm_2(rT0); + + up[2] = 1.0; // Z-up + if (std::abs(inner_prod(rT0, up)) > 0.99) { + up[2] = 0.0; + up[1] = 1.0; // switch to Y-up + } + + MathUtils::CrossProduct(V, rT0, up); + V /= norm_2(V); + MathUtils::CrossProduct(rN0, V, rT0); + rN0 /= norm_2(rN0); +} + +void ComputeBeamVectorsProcess::ComputeT0AndN0( + const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rCurve, + array_1d& rT0, + array_1d& rN0) +{ + array_1d V = ZeroVector(3); + array_1d up = ZeroVector(3); + + // Evaluate at the start of the beam (parameter = 0) + array_1d local_coordinates = ZeroVector(3); + std::vector> global_space_derivatives; + rCurve.GlobalSpaceDerivatives(global_space_derivatives, local_coordinates, 1); + + // Compute tangent vector (normalized) + rT0 = global_space_derivatives[1]; + rT0 /= norm_2(rT0); + + // Compute normal vector (from surface) + array_1d parameter_space_coordinates; + const auto& nurbs_curve_2d = *(rCurve.pGetCurve()); + const auto p_surface_geometry = rCurve.pGetGeometryPart(Geometry::BACKGROUND_GEOMETRY_INDEX); + const auto& nurbs_surface_3d = static_cast::PointsArrayType>&>(*p_surface_geometry); + nurbs_curve_2d.GlobalCoordinates(parameter_space_coordinates, local_coordinates); + nurbs_surface_3d.GlobalSpaceDerivatives(global_space_derivatives, parameter_space_coordinates, 1); + array_1d G1 = global_space_derivatives[1]; + array_1d G2 = global_space_derivatives[2]; + MathUtils::CrossProduct(rN0, G1, G2); //surface normal = G1 × G2 + rN0 /= norm_2(rN0); + + MathUtils::CrossProduct(V, rT0, rN0); + V /= norm_2(V); +} + + +void ComputeBeamVectorsProcess::ExecuteInitialize() +{ + const auto* curve_on_surface = dynamic_cast, PointerVector>*>(mpParentCurve); + auto* nurbs_curve = dynamic_cast>*>(mpParentCurve); + const auto* brep_curve = dynamic_cast, PointerVector>*>(mpParentCurve); + + if (brep_curve != nullptr) { + nurbs_curve = dynamic_cast>*>( + &brep_curve->GetGeometryPart(Geometry::BACKGROUND_GEOMETRY_INDEX)); + } + + array_1d T; + array_1d N; + + if (curve_on_surface != nullptr) { + ComputeT0AndN0(*curve_on_surface, T, N); + } else if (nurbs_curve != nullptr) { + ComputeT0AndN0(*nurbs_curve, T, N); + } else { + KRATOS_ERROR << "Unknown geometry type in ComputeBeamVectorsProcess"; + } + + for (auto& r_element : mrThisModelPart.Elements()) { + r_element.GetProperties().SetValue(T_0, T); + r_element.GetProperties().SetValue(N_0, N); + } +} + + +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h new file mode 100644 index 000000000000..e68de5ae5ade --- /dev/null +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h @@ -0,0 +1,118 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ \. +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// + +#if !defined(KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED ) +#define KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED + +// System includes + +// External includes + +// Project includes +#include "containers/model.h" +#include "processes/process.h" +#include "geometries/nurbs_curve_geometry.h" +#include "geometries/nurbs_curve_on_surface_geometry.h" +#include "geometries/nurbs_surface_geometry.h" +#include "geometries/brep_curve.h" +#include "includes/model_part.h" +#include "includes/kratos_parameters.h" +#include "iga_application_variables.h" +#include "utilities/math_utils.h" +#include + + +namespace Kratos +{ + +///@name Kratos Classes +///@{ + +/* @class ComputeBeamVectorsProcess + * @ingroup IgaApplication + * @brief This process computes the tangential (T0) and normal (N0) vectors for isogeometric beam elements during initialization. */ +class KRATOS_API(IGA_APPLICATION) ComputeBeamVectorsProcess + : public Process +{ +public: + ///@name Type Definitions + ///@{ + + /// Pointer definition of ComputeBeamVectorsProcess + KRATOS_CLASS_POINTER_DEFINITION(ComputeBeamVectorsProcess); + + typedef std::size_t IndexType; + typedef std::size_t SizeType; + + ///@} + ///@name Life Cycle + ///@{ + + ComputeBeamVectorsProcess(ModelPart& rModelPart); + + ComputeBeamVectorsProcess(ModelPart& rModelPart, + const NurbsCurveGeometry<3, PointerVector>& rParentCurve); + + ComputeBeamVectorsProcess(ModelPart& rModelPart, + const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rParentCurve); + + ~ComputeBeamVectorsProcess() = default; + + ///@} + ///@name Operations + ///@{ + + /// Called once before the solution loop to compute T0 and N0 vectors + void ExecuteInitialize() override; + + /// Compute T0 and N0 vectors for a given NURBS curve geometry + void ComputeT0AndN0( + const NurbsCurveGeometry<3, PointerVector>& rCurve, + array_1d& rT0, + array_1d& rN0); + + /// Compute T0 and N0 vectors for a given NURBS curve on surface geometry + void ComputeT0AndN0( + const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rCurve, + array_1d& rT0, + array_1d& rN0); + + + ///@} + ///@name Input and output + ///@{ + + /// Turn back information as a string. + std::string Info() const override + { + return "ComputeBeamVectorsProcess"; + } + + /// Print information about this object. + void PrintInfo(std::ostream& rOStream) const override + { + rOStream << "ComputeBeamVectorsProcess"; + } + + /// Print object's data. + void PrintData(std::ostream& rOStream) const override + { + } + +private: + ///@name Member Variables + ///@{ + ModelPart& mrThisModelPart; + const Geometry* mpParentCurve; + ///@} +}; // Class ComputeBeamVectorsProcess +} // namespace Kratos. + +#endif // KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED defined \ No newline at end of file diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp new file mode 100644 index 000000000000..fe75015cd93a --- /dev/null +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp @@ -0,0 +1,31 @@ +// KRATOS ___| | | | +// \___ \ __| __| | | __| __| | | __| _` | | +// | | | | | ( | | | | ( | | +// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// +// License: BSD License +// license: IgaApplication/license.txt +// + +// System includes + +// External includes + +// Project includes +#include "custom_python/add_custom_constitutive_laws_to_python.h" + +// Constitutive laws +#include "custom_constitutive/bernoulli_beam_elastic_constitutive_law.h" + +namespace Kratos::Python { + +void AddCustomConstitutiveLawsToPython(pybind11::module& m) +{ + namespace py = pybind11; + + py::class_< BernoulliBeamElasticConstitutiveLaw, typename BernoulliBeamElasticConstitutiveLaw::Pointer, ConstitutiveLaw > + (m, "BernoulliBeamElasticConstitutiveLaw").def(py::init<>() ) + ; +} + +} // namespace Kratos::Python. \ No newline at end of file diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h new file mode 100644 index 000000000000..d89760c8cc7e --- /dev/null +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h @@ -0,0 +1,27 @@ +// KRATOS ___| | | | +// \___ \ __| __| | | __| __| | | __| _` | | +// | | | | | ( | | | | ( | | +// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// +// License: BSD License +// license: IgaApplication/license.txt +// + +#if !defined(KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED ) +#define KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED + +// System includes +#include + +// External includes + +// Project includes +#include "includes/define.h" + +namespace Kratos::Python { + +void AddCustomConstitutiveLawsToPython(pybind11::module& m); + +} // namespace Kratos::Python + +#endif // KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED \ No newline at end of file diff --git a/applications/IgaApplication/custom_python/add_custom_processes_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_processes_to_python.cpp index a649a739afce..bc71c6d76f44 100644 --- a/applications/IgaApplication/custom_python/add_custom_processes_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_processes_to_python.cpp @@ -14,6 +14,7 @@ #include "includes/define.h" #include "custom_python/add_custom_processes_to_python.h" +#include "custom_processes/compute_beam_vectors_process.h" #include "custom_processes/output_quadrature_domain_process.h" #include "custom_processes/output_eigen_values_process.h" #include "custom_processes/nitsche_stabilization_model_part_process.h" @@ -32,6 +33,14 @@ void AddCustomProcessesToPython( { namespace py = pybind11; + py::class_( + m, "ComputeBeamVectorsProcess") + .def(py::init()) + .def(py::init< + ModelPart&, + const NurbsCurveGeometry<3, PointerVector>&>()) + ; + py::class_(m, "OutputQuadratureDomainProcess") .def(py::init()) ; @@ -56,7 +65,6 @@ void AddCustomProcessesToPython( py::class_(m, "AssignIgaExternalConditionsProcess") .def(py::init()) ; - } } // namespace Python diff --git a/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp index 8c48fe87e77b..a6c3c7c562c6 100644 --- a/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp @@ -22,6 +22,7 @@ #include "spaces/ublas_space.h" #include "custom_utilities/director_utilities.h" #include "custom_utilities/iga_flags.h" +#include "geometries/nurbs_curve_geometry.h" namespace Kratos { @@ -46,6 +47,77 @@ void AddCustomUtilitiesToPython( iga_flags.attr("FIX_ROTATION_X") = IgaFlags::FIX_ROTATION_X; iga_flags.attr("FIX_ROTATION_Y") = IgaFlags::FIX_ROTATION_Y; iga_flags.attr("FIX_ROTATION_Z") = IgaFlags::FIX_ROTATION_Z; + + m.def( + "EvaluateNurbsCurveShapeFunctions", + [](Geometry& rGeometry, const double Parameter) { + + using NurbsCurveType = + NurbsCurveGeometry<3, PointerVector>; + + NurbsCurveType* p_nurbs_curve = + dynamic_cast(&rGeometry); + + NurbsCurveType::Pointer p_background_curve; + + if (p_nurbs_curve == nullptr) { + p_background_curve = + std::dynamic_pointer_cast( + rGeometry.pGetGeometryPart( + Geometry::BACKGROUND_GEOMETRY_INDEX)); + + KRATOS_ERROR_IF_NOT(p_background_curve) + << "Geometry does not contain a NurbsCurveGeometry." + << std::endl; + + p_nurbs_curve = p_background_curve.get(); + } + + array_1d local_coordinates = + ZeroVector(3); + + local_coordinates[0] = Parameter; + + std::vector control_point_ids; + Vector shape_function_values; + + p_nurbs_curve->ShapeFunctionsValuesAndCPIndices( + local_coordinates, + control_point_ids, + shape_function_values); + + return pybind11::make_tuple( + control_point_ids, + shape_function_values); + }); + + + m.def( + "GetNurbsCurveKnots", + [](Geometry& rGeometry) { + using NurbsCurveType = + NurbsCurveGeometry<3, PointerVector>; + + NurbsCurveType* p_nurbs_curve = + dynamic_cast(&rGeometry); + + NurbsCurveType::Pointer p_background_curve; + + if (p_nurbs_curve == nullptr) { + p_background_curve = + std::dynamic_pointer_cast( + rGeometry.pGetGeometryPart( + Geometry::BACKGROUND_GEOMETRY_INDEX)); + + KRATOS_ERROR_IF_NOT(p_background_curve) + << "Geometry does not contain a NurbsCurveGeometry." + << std::endl; + + p_nurbs_curve = p_background_curve.get(); + } + + return p_nurbs_curve->Knots(); + }); } } // namespace Python diff --git a/applications/IgaApplication/custom_python/iga_python_application.cpp b/applications/IgaApplication/custom_python/iga_python_application.cpp index 028609714310..e32fe5475f9f 100644 --- a/applications/IgaApplication/custom_python/iga_python_application.cpp +++ b/applications/IgaApplication/custom_python/iga_python_application.cpp @@ -23,6 +23,7 @@ #include "custom_python/add_custom_processes_to_python.h" #include "custom_python/add_custom_strategies_to_python.h" #include "custom_python/add_custom_solvers_to_python.h" +#include "custom_python/add_custom_constitutive_laws_to_python.h" namespace Kratos { namespace Python { @@ -62,6 +63,22 @@ PYBIND11_MODULE(KratosIgaApplication, m) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, RAYLEIGH_ALPHA) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, RAYLEIGH_BETA) + //Beam Variables + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_AXIS_ORIENTATION) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, T_0) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, N_0) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_V) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_N) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_T) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, HEIGHT) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, WIDTH) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_N) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_n) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_V) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_v) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, VON_MISES_STRESS) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ROTATIONAL_DOF_ACTIVE) + // 5p Director Shell Variables KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DIRECTOR_COMPUTED) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DIRECTOR) @@ -91,6 +108,7 @@ PYBIND11_MODULE(KratosIgaApplication, m) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, INTEGRATE_CONSERVATIVE) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, PENALTY_FACTOR) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, PENALTY_ROTATION_FACTOR) KRATOS_REGISTER_IN_PYTHON_3D_VARIABLE_WITH_COMPONENTS(m, VECTOR_LAGRANGE_MULTIPLIER_REACTION) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, NITSCHE_STABILIZATION_FACTOR) @@ -104,9 +122,10 @@ PYBIND11_MODULE(KratosIgaApplication, m) AddCustomProcessesToPython(m); AddCustomStrategiesToPython(m); AddCustomSolversToPython(m); + AddCustomConstitutiveLawsToPython(m); } } // namespace Python } // namespace Kratos -#endif // defined(KRATOS_PYTHON) +#endif // defined(KRATOS_PYTHON) \ No newline at end of file diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 79655c9aedc8..475f46ae61fa 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -20,12 +20,12 @@ KratosIgaApplication::KratosIgaApplication() new Geometry(Element::GeometryType::PointsArrayType(1)))) , mTrussEmbeddedEdgeElement(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) + , mNonLinearBernoulliBeamElement3D(0, Element::GeometryType::Pointer( + new Geometry(Element::GeometryType::PointsArrayType(1)))) , mBeamThinElement2D(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) , mBeamThickElement2D(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) - , mBeamBernoulliElement3D(0, Element::GeometryType::Pointer( - new Geometry(Element::GeometryType::PointsArrayType(1)))) , mIgaMembraneElement(0, Element::GeometryType::Pointer( new Geometry(Element::GeometryType::PointsArrayType(1)))) , mShell3pElement(0, Element::GeometryType::Pointer( @@ -76,6 +76,7 @@ KratosIgaApplication::KratosIgaApplication() new Geometry(Condition::GeometryType::PointsArrayType(1)))) , mLoadSolidCondition(0, Condition::GeometryType::Pointer( new Geometry(Condition::GeometryType::PointsArrayType(1)))) + , mBernoulliBeamElasticConstitutiveLaw() { } @@ -92,9 +93,9 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" // ELEMENTS KRATOS_REGISTER_ELEMENT("TrussElement", mTrussElement) KRATOS_REGISTER_ELEMENT("TrussEmbeddedEdgeElement", mTrussEmbeddedEdgeElement) + KRATOS_REGISTER_ELEMENT("NonLinearBernoulliBeamElement3D", mNonLinearBernoulliBeamElement3D) KRATOS_REGISTER_ELEMENT("BeamThinElement2D", mBeamThinElement2D) KRATOS_REGISTER_ELEMENT("BeamThickElement2D", mBeamThickElement2D) - KRATOS_REGISTER_ELEMENT("BeamBernoulliElement3D", mBeamBernoulliElement3D) KRATOS_REGISTER_ELEMENT("IgaMembraneElement", mIgaMembraneElement) KRATOS_REGISTER_ELEMENT("Shell3pElement", mShell3pElement) KRATOS_REGISTER_ELEMENT("Shell5pHierarchicElement", mShell5pHierarchicElement) @@ -134,9 +135,12 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_MODELER("NurbsGeometryModelerGapSbm", mNurbsGeometryModelerGapSbm); KRATOS_REGISTER_MODELER("ImportNurbsSbmModeler", mImportNurbsSbmModeler); + // CONSTITUTIVE LAWS + KRATOS_REGISTER_CONSTITUTIVE_LAW("BernoulliBeamElasticConstitutiveLaw", mBernoulliBeamElasticConstitutiveLaw); + // VARIABLES KRATOS_REGISTER_VARIABLE(CROSS_AREA) - + KRATOS_REGISTER_VARIABLE(TRUSS_PRESTRESS_CAUCHY) KRATOS_REGISTER_VARIABLE(TRUSS_PRESTRESS_PK2) KRATOS_REGISTER_VARIABLE(TRUSS_STRESS_CAUCHY) @@ -176,6 +180,7 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(POINT_LOAD) KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(LINE_LOAD) KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(SURFACE_LOAD) + KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(INTERFACE_TRACTION) KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(DEAD_LOAD) KRATOS_REGISTER_VARIABLE(PRESSURE_FOLLOWER_LOAD) @@ -196,6 +201,7 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(INTEGRATE_CONSERVATIVE) KRATOS_REGISTER_VARIABLE(PENALTY_FACTOR) + KRATOS_REGISTER_VARIABLE(PENALTY_ROTATION_FACTOR) KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(VECTOR_LAGRANGE_MULTIPLIER_REACTION) KRATOS_REGISTER_VARIABLE(NITSCHE_STABILIZATION_FACTOR) @@ -203,7 +209,24 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(EIGENVALUE_NITSCHE_STABILIZATION_VECTOR) KRATOS_REGISTER_VARIABLE(BUILD_LEVEL) - // SBM Variables + // Beam variables + KRATOS_REGISTER_VARIABLE(LOCAL_CS_N) + KRATOS_REGISTER_VARIABLE(LOCAL_CS_n) + KRATOS_REGISTER_VARIABLE(LOCAL_CS_V) + KRATOS_REGISTER_VARIABLE(LOCAL_CS_v) + KRATOS_REGISTER_VARIABLE(T_0) + KRATOS_REGISTER_VARIABLE(N_0) + KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) + KRATOS_REGISTER_VARIABLE(I_V) + KRATOS_REGISTER_VARIABLE(I_N) + KRATOS_REGISTER_VARIABLE(I_T) + KRATOS_REGISTER_VARIABLE(HEIGHT) + KRATOS_REGISTER_VARIABLE(WIDTH) + KRATOS_REGISTER_VARIABLE(VON_MISES_STRESS) + KRATOS_REGISTER_VARIABLE(ROTATIONAL_DOF_ACTIVE) + + + // SBM Variables KRATOS_REGISTER_VARIABLE(INTEGRATION_POINTS) KRATOS_REGISTER_VARIABLE(INTEGRATION_WEIGHTS) KRATOS_REGISTER_VARIABLE(BOUNDARY_CONDITION_TYPE) @@ -221,16 +244,6 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(CONNECTED_CONDITIONS) KRATOS_REGISTER_VARIABLE(INTERPOLATION_NODES_ID) KRATOS_REGISTER_VARIABLE(BREP_ID) - - - KRATOS_REGISTER_VARIABLE(I_T) - KRATOS_REGISTER_VARIABLE(I_N) - KRATOS_REGISTER_VARIABLE(I_V) - - KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) - - KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(T_0) - KRATOS_REGISTER_3D_VARIABLE_WITH_COMPONENTS(N_0) } -} // namespace Kratos +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index c55fe7ed4516..47b2ed49d0c5 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -19,9 +19,10 @@ //elements #include "custom_elements/truss_element.h" #include "custom_elements/truss_embedded_edge_element.h" +#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" #include "custom_elements/beam_thin_element_2D.h" #include "custom_elements/beam_thick_element_2D.h" -#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" #include "custom_elements/iga_membrane_element.h" #include "custom_elements/shell_3p_element.h" #include "custom_elements/shell_5p_hierarchic_element.h" @@ -62,6 +63,9 @@ #include "custom_modelers/nurbs_geometry_modeler_gap_sbm.h" #include "custom_modelers/import_nurbs_sbm_modeler.h" +//constitutive +#include "custom_constitutive/bernoulli_beam_elastic_constitutive_law.h" + namespace Kratos { ///@name Kratos Classes @@ -136,9 +140,9 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio const TrussElement mTrussElement; const TrussEmbeddedEdgeElement mTrussEmbeddedEdgeElement; + const NonLinearBernoulliBeamElement3D mNonLinearBernoulliBeamElement3D; const BeamThinElement2D mBeamThinElement2D; const BeamThickElement2D mBeamThickElement2D; - const BeamThickElement2D mBeamBernoulliElement3D; const IgaMembraneElement mIgaMembraneElement; const Shell3pElement mShell3pElement; const Shell5pHierarchicElement mShell5pHierarchicElement; @@ -179,6 +183,9 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio const NurbsGeometryModelerGapSbm mNurbsGeometryModelerGapSbm; const ImportNurbsSbmModeler mImportNurbsSbmModeler; + // Constitutive Laws + const BernoulliBeamElasticConstitutiveLaw mBernoulliBeamElasticConstitutiveLaw; + ///@} ///@name Private methods ///@{ @@ -195,4 +202,4 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio ///@} -} // namespace Kratos +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index 87b47d07ea67..f141dd1851f1 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -42,6 +42,22 @@ KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(NODAL_INERTIA) KRATOS_CREATE_VARIABLE(double, RAYLEIGH_ALPHA) KRATOS_CREATE_VARIABLE(double, RAYLEIGH_BETA) +// Beam Variables +KRATOS_CREATE_VARIABLE(Vector, T_0) +KRATOS_CREATE_VARIABLE(Vector, N_0) +KRATOS_CREATE_VARIABLE(Matrix, LOCAL_AXIS_ORIENTATION) +KRATOS_CREATE_VARIABLE(double, I_V) +KRATOS_CREATE_VARIABLE(double, I_N) +KRATOS_CREATE_VARIABLE(double, I_T) +KRATOS_CREATE_VARIABLE(double, HEIGHT) +KRATOS_CREATE_VARIABLE(double, WIDTH) +KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_N) +KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_n) +KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_V) +KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_v) +KRATOS_CREATE_VARIABLE(double, VON_MISES_STRESS) +KRATOS_CREATE_VARIABLE(bool, ROTATIONAL_DOF_ACTIVE) + // 5p Director Shell Variables KRATOS_CREATE_VARIABLE(bool, DIRECTOR_COMPUTED) KRATOS_CREATE_VARIABLE(Vector, DIRECTOR) @@ -54,6 +70,7 @@ KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(MOMENT_LINE_LOAD) KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(POINT_LOAD) KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(LINE_LOAD) KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(SURFACE_LOAD) +KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(INTERFACE_TRACTION) KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(DEAD_LOAD) KRATOS_CREATE_VARIABLE(double, PRESSURE_FOLLOWER_LOAD) @@ -77,6 +94,7 @@ KRATOS_CREATE_VARIABLE(bool, INTEGRATE_CONSERVATIVE) //Penalty Variables KRATOS_CREATE_VARIABLE(double, PENALTY_FACTOR) +KRATOS_CREATE_VARIABLE(double, PENALTY_ROTATION_FACTOR) KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(VECTOR_LAGRANGE_MULTIPLIER_REACTION) //Nitsche Variables @@ -104,14 +122,5 @@ KRATOS_CREATE_VARIABLE(std::vector, CONNECTED_CONDITIONS) KRATOS_CREATE_VARIABLE(std::vector, INTERPOLATION_NODES_ID) KRATOS_CREATE_VARIABLE(int, BREP_ID) -KRATOS_CREATE_VARIABLE(double, I_T) -KRATOS_CREATE_VARIABLE(double, I_N) -KRATOS_CREATE_VARIABLE(double, I_V) - -KRATOS_CREATE_VARIABLE(Matrix, LOCAL_AXIS_ORIENTATION) - -KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(T_0) -KRATOS_CREATE_3D_VARIABLE_WITH_COMPONENTS(N_0) - -} // namespace Kratos +} // namespace Kratos \ No newline at end of file diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index 59166dc79b60..b8300f476218 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -23,9 +23,6 @@ namespace Kratos { - -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, CROSS_AREA) - KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, TRUSS_PRESTRESS_CAUCHY) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, TRUSS_PRESTRESS_PK2) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, TRUSS_STRESS_CAUCHY) @@ -41,6 +38,7 @@ KRATOS_DEFINE_SYMMETRIC_2D_TENSOR_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLI KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, TANGENTS) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, CROSS_SECTIONAL_ROTATION) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, CROSS_AREA) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, FORCE_PK2_1D) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, FORCE_CAUCHY_1D) @@ -54,6 +52,22 @@ KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, LOCAL_PRE KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, RAYLEIGH_ALPHA) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, RAYLEIGH_BETA) +//beam Variables +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, T_0) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, N_0) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Matrix, LOCAL_AXIS_ORIENTATION) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_V) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_N) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_T) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, HEIGHT) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, WIDTH) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_N) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_n) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_V) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_v) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, VON_MISES_STRESS) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, ROTATIONAL_DOF_ACTIVE) + // 5p Director Shell Variables KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, DIRECTOR_COMPUTED) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, DIRECTOR) @@ -66,6 +80,7 @@ KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, MOMENT_LI KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, POINT_LOAD) KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, LINE_LOAD) KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, SURFACE_LOAD) +KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, INTERFACE_TRACTION) KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, DEAD_LOAD) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, PRESSURE_FOLLOWER_LOAD) @@ -89,6 +104,7 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, INTEGRATE_CONSERVATIVE //Penalty Variables KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, PENALTY_FACTOR) +KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, PENALTY_ROTATION_FACTOR) KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, VECTOR_LAGRANGE_MULTIPLIER_REACTION) //Nitsche Variables @@ -119,15 +135,7 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, std::vector, CO KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, std::vector, INTERPOLATION_NODES_ID) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, int, BREP_ID) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_T) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_N) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_V) - -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Matrix, LOCAL_AXIS_ORIENTATION) - -KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, T_0) -KRATOS_DEFINE_3D_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLICATION, N_0) } // namespace Kratos -#endif // !defined(KRATOS_IGA_APPLICATION_VARIABLES_H_INCLUDED) +#endif // !defined(KRATOS_IGA_APPLICATION_VARIABLES_H_INCLUDED) \ No newline at end of file diff --git a/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py b/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py new file mode 100644 index 000000000000..c3d00f10d0e5 --- /dev/null +++ b/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py @@ -0,0 +1,32 @@ +# Importing the Kratos Library +import KratosMultiphysics +import KratosMultiphysics.IgaApplication as IGA + + +def Factory(settings, model): + if not isinstance(settings, KratosMultiphysics.Parameters): + raise Exception("Expected input shall be a Parameters object, encapsulating a json string") + return ComputeBeamVectorsProcess(model, settings["Parameters"]) + +class ComputeBeamVectorsProcess(KratosMultiphysics.Process): + """This process computes the tangential (T0) and normal (N0) vectors for isogeometric beam elements during initialization. + """ + def __init__(self, model, params): + KratosMultiphysics.Process.__init__(self) + + ## Settings string in json format + default_parameters = KratosMultiphysics.Parameters("""{ + "model_part_name" : "" + }""") + + ## Overwrite the default settings with user-provided parameters + self.params = params + self.params.RecursivelyValidateAndAssignDefaults(default_parameters) + + self.model = model + self.model_part_beam = self.model[self.params["model_part_name"].GetString()] + + self.process = IGA.ComputeBeamVectorsProcess(self.model_part_beam) + + def ExecuteInitialize(self): + self.process.ExecuteInitialize() \ No newline at end of file diff --git a/applications/IgaApplication/python_scripts/iga_vtk_output_process.py b/applications/IgaApplication/python_scripts/iga_vtk_output_process.py index d80b15a98086..15ffc811267c 100644 --- a/applications/IgaApplication/python_scripts/iga_vtk_output_process.py +++ b/applications/IgaApplication/python_scripts/iga_vtk_output_process.py @@ -6,6 +6,7 @@ VTK_QUAD = 9 VTK_TRIANGLE = 5 +VTK_LINE = 3 VERSION = (2, 4) GLOBAL_TYPE = 'UnstructuredGrid' @@ -26,34 +27,54 @@ def __init__(self, model, params): default_parameters = KM.Parameters("""{ "output_file_name" : "", "brep_surface_ids" : [], + "brep_curve_ids": [], "model_part_name" : "", "nodal_solution_step_data_variables" : [], - "output_refinement" : [], - "output_control_type" : "none", + "output_refinement_surface" : [], + "output_refinement_curve" : [], + "output_control_type" : "step", "output_frequency" : 1, "output_interval" : 0.0, "interval" : [0.0, "End"] }""") params.ValidateAndAssignDefaults(default_parameters) - self.interval_utility = KM.IntervalUtility(params) + self.model = model self.model_part = model[params["model_part_name"].GetString()] self.output_file_name = Path(params["output_file_name"].GetString()) + self.settings = params + # Ensure correct file extension self.output_file_name = self.output_file_name.with_suffix(".vtkhdf") + # Remove old VTKHDF file at the beginning of a fresh analysis + if self.output_file_name.exists(): + self.output_file_name.unlink() + # IDs of Brep surfaces to be exported self.brep_surface_ids = [ params["brep_surface_ids"][i].GetInt() for i in range(params["brep_surface_ids"].size()) ] + # IDs of Brep curves to be exported + self.brep_curve_ids = [ + params["brep_curve_ids"][i].GetInt() + for i in range(params["brep_curve_ids"].size()) + ] + # Refinement level per parametric direction - self.output_refinement = [ - params["output_refinement"][i].GetInt() - for i in range(params["output_refinement"].size()) + self.output_refinement_surface = [ + params["output_refinement_surface"][i].GetInt() + for i in range(params["output_refinement_surface"].size()) + ] + + # Refinement level per parametric direction + self.output_refinement_curve = [ + params["output_refinement_curve"][i].GetInt() + for i in range(params["output_refinement_curve"].size()) ] self.printed_step_count = 0 @@ -63,7 +84,7 @@ def __init__(self, model, params): for i in range(params["nodal_solution_step_data_variables"].size()): var_name = params["nodal_solution_step_data_variables"][i].GetString() self.nodal_variables.append(KM.KratosGlobals.GetVariable(var_name)) - + for var in self.nodal_variables: if not self.model_part.HasNodalSolutionStepVariable(var): raise Exception( @@ -71,57 +92,20 @@ def __init__(self, model, params): f"Make sure to call AddNodalSolutionStepVariable." ) - # Output control settings - self.output_control_type = params["output_control_type"].GetString() - - if self.output_control_type == "none": - pass - - elif self.output_control_type == "step": - self.output_frequency = params["output_frequency"].GetInt() - self.step_counter = -1 # ensures first output at step 0 - - elif self.output_control_type == "time": - self.output_interval = params["output_interval"].GetDouble() - if self.output_interval <= 0.0: - raise Exception('"output_interval" must be > 0.0 for "time" control.') - self.next_output_time = self.interval_utility.GetIntervalBegin() - - else: - err_msg = 'The requested "output_control_type" "' + self.output_control_type - err_msg += '" is not available!\nAvailable options are: "time", "step"' - raise Exception(err_msg) - - # Cached parametric sampling (shared across time steps) + # Cached parametric sampling and shape function data self.cached_uv = None + self.cached_shape_function_data = None KM.Logger.PrintWarning( "IgaVTKOutputProcess", "VTKHDF requires ParaView 5.11 or newer. Older versions may not support it reliably." ) - # Decide whether to output or not a time - def IsOutputStep(self): - if self.output_control_type == "none": - return self.printed_step_count == 0 - - elif self.output_control_type == "step": - return (self.step_counter % int(self.output_frequency)) == 0 + def ExecuteBeforeSolutionLoop(self): + self.__controller = KM.OutputController(self.model, self.settings) - elif self.output_control_type == "time": - current_time = self.model_part.ProcessInfo[KM.TIME] - - if not self.interval_utility.IsInInterval(current_time): - return False - - if current_time >= self.next_output_time: - while current_time >= self.next_output_time: - self.next_output_time += self.output_interval - return True - - return False - - return False + def IsOutputStep(self): + return self.__controller.Evaluate() # Print the output in the HDFVTK file def PrintOutput(self): @@ -131,40 +115,87 @@ def PrintOutput(self): # Create or retrieve root group if "VTKHDF" not in file: root = file.create_group("VTKHDF") - root.attrs["Version"] = VERSION - root.attrs["Type"] = GLOBAL_TYPE + + root.attrs["Version"] = np.array( + VERSION, + dtype=np.int64 + ) + + ascii_type = h5.string_dtype( + encoding="ascii", + length=len(GLOBAL_TYPE) + ) + + root.attrs.create( + "Type", + GLOBAL_TYPE.encode("ascii"), + dtype=ascii_type + ) else: root = file["VTKHDF"] - # Rebuild UV sampling if needed (when reopening file) + # Rebuild parametric sampling if needed when reopening the file if self.cached_uv is None and "Points" in root: - all_uv = [] + all_local_coordinates = [] + all_shape_function_data = [] self.cached_uv_sizes = [] + # BRep surfaces for brep_id in self.brep_surface_ids: brep_surface = self.model_part.GetGeometry(brep_id) - _, _, _, _, uv = self.__compute_full_grid(brep_surface) - all_uv.extend(uv) + + _, _, _, _, uv = self.__compute_full_grid_brep_surface( + brep_surface + ) + + all_local_coordinates.extend(uv) + all_shape_function_data.extend(self.__compute_shape_function_data(brep_surface, uv)) self.cached_uv_sizes.append(len(uv)) - self.cached_uv = all_uv + # IGA beam curves + for curve_id in self.brep_curve_ids: + curve = self.model_part.GetGeometry(curve_id) + + _, _, _, _, u_coordinates = self.__compute_full_grid_brep_curve( + curve + ) + + # Store curve coordinates in the same format as surface coordinates + curve_uv = [(u, 0.0) for u in u_coordinates] + all_local_coordinates.extend(curve_uv) + all_shape_function_data.extend(self.__compute_shape_function_data(curve, curve_uv, is_curve=True)) + self.cached_uv_sizes.append(len(u_coordinates)) + + self.cached_uv = all_local_coordinates + self.cached_shape_function_data = all_shape_function_data # Geometry is written only once if "Points" not in root: self.cached_uv_sizes = [] + all_pts = [] all_conn = [] all_offsets = [] all_types = [] all_uv = [] + all_shape_function_data = [] point_shift = 0 conn_shift = 0 + # BRep surfaces for brep_id in self.brep_surface_ids: brep_surface = self.model_part.GetGeometry(brep_id) - pts, conn, offs, types, uv = self.__compute_full_grid(brep_surface) + pts, conn, offs, types, uv = ( + self.__compute_full_grid_brep_surface(brep_surface) + ) + + if len(pts) == 0: + raise RuntimeError( + f"No visualization points were generated for " + f"BRep surface {brep_id}." + ) self.cached_uv_sizes.append(len(uv)) @@ -176,11 +207,54 @@ def PrintOutput(self): all_conn.append(conn_shifted) all_offsets.append(offs_shifted) all_types.append(types) + + # Surface local coordinates: (u, v) all_uv.extend(uv) + all_shape_function_data.extend(self.__compute_shape_function_data(brep_surface, uv)) + + point_shift += len(pts) + conn_shift += len(conn) + + # IGA curves / beams + for curve_id in self.brep_curve_ids: + curve = self.model_part.GetGeometry(curve_id) + + pts, conn, offs, types, u_coordinates = ( + self.__compute_full_grid_brep_curve(curve) + ) + + if len(pts) == 0: + raise RuntimeError( + f"No visualization points were generated for " + f"IGA curve {curve_id}." + ) + + self.cached_uv_sizes.append(len(u_coordinates)) + + # Shift indices for global assembly + conn_shifted = conn + point_shift + offs_shifted = offs[:-1] + conn_shift + + all_pts.append(pts) + all_conn.append(conn_shifted) + all_offsets.append(offs_shifted) + all_types.append(types) + + # Store curve coordinates using the same (u, v) format + curve_uv = [(u, 0.0) for u in u_coordinates] + all_uv.extend(curve_uv) + all_shape_function_data.extend(self.__compute_shape_function_data(curve, curve_uv, is_curve=True)) point_shift += len(pts) conn_shift += len(conn) + if len(all_pts) == 0: + raise RuntimeError( + "No geometry was provided for VTK output. " + f"brep_surface_ids={self.brep_surface_ids}, " + f"brep_curve_ids={self.brep_curve_ids}" + ) + # Assemble global arrays points = np.vstack(all_pts) conn = np.concatenate(all_conn) @@ -189,6 +263,7 @@ def PrintOutput(self): types = np.concatenate(all_types) self.cached_uv = all_uv + self.cached_shape_function_data = all_shape_function_data # Write geometry root.create_dataset("Points", data=points) @@ -205,51 +280,92 @@ def PrintOutput(self): # Initial write of nodal variables for var in self.nodal_variables: data = [] - uv_counter = 0 + shape_function_data_counter = 0 + patch_index = 0 - for patch_index, brep_id in enumerate(self.brep_surface_ids): - brep_surface = self.model_part.GetGeometry(brep_id) + # Evaluate variables on BRep surfaces + for brep_id in self.brep_surface_ids: n_local = self.cached_uv_sizes[patch_index] - local_uv = self.cached_uv[uv_counter:uv_counter + n_local] + local_shape_function_data = self.cached_shape_function_data[ + shape_function_data_counter:shape_function_data_counter + n_local + ] - for u, v in local_uv: - val = self.__eval_variable(brep_surface, u, v, var) + for nodes, N in local_shape_function_data: + val = self.__eval_variable(nodes, N, var) data.append(val) - uv_counter += n_local + shape_function_data_counter += n_local + patch_index += 1 + + # Evaluate variables on IGA curves / beams + for curve_id in self.brep_curve_ids: + n_local = self.cached_uv_sizes[patch_index] + + local_shape_function_data = self.cached_shape_function_data[ + shape_function_data_counter:shape_function_data_counter + n_local + ] + + for nodes, N in local_shape_function_data: + val = self.__eval_variable(nodes, N, var) + data.append(val) + + shape_function_data_counter += n_local + patch_index += 1 data = np.array(data) - # Ensure 2D array (scalar → (n,1)) + # Ensure 2D array: scalar -> (n, 1) if data.ndim == 1: data = data[:, np.newaxis] - pd.create_dataset(var.Name(), data=data, maxshape=(None, data.shape[1])) + pd.create_dataset( + var.Name(), + data=data, + maxshape=(None, data.shape[1]) + ) n_pts = len(points) else: - # Append new time step data + # Append new time-step data pd = root["PointData"] n_pts = int(root["NumberOfPoints"][0]) for var in self.nodal_variables: - data = [] - uv_counter = 0 + shape_function_data_counter = 0 + patch_index = 0 - for patch_index, brep_id in enumerate(self.brep_surface_ids): - brep_surface = self.model_part.GetGeometry(brep_id) + # Evaluate variables on BRep surfaces + for brep_id in self.brep_surface_ids: n_local = self.cached_uv_sizes[patch_index] - local_uv = self.cached_uv[uv_counter:uv_counter + n_local] + local_shape_function_data = self.cached_shape_function_data[ + shape_function_data_counter:shape_function_data_counter + n_local + ] - for u, v in local_uv: - val = self.__eval_variable(brep_surface, u, v, var) + for nodes, N in local_shape_function_data: + val = self.__eval_variable(nodes, N, var) data.append(val) - uv_counter += n_local + shape_function_data_counter += n_local + patch_index += 1 + + # Evaluate variables on IGA curves / beams + for curve_id in self.brep_curve_ids: + n_local = self.cached_uv_sizes[patch_index] + + local_shape_function_data = self.cached_shape_function_data[ + shape_function_data_counter:shape_function_data_counter + n_local + ] + + for nodes, N in local_shape_function_data: + val = self.__eval_variable(nodes, N, var) + data.append(val) + + shape_function_data_counter += n_local + patch_index += 1 data = np.array(data) @@ -257,7 +373,10 @@ def PrintOutput(self): data = data[:, np.newaxis] if data.shape[0] != n_pts: - raise RuntimeError("Non-constant number of points across time steps!") + raise RuntimeError( + "Non-constant number of points across time steps! " + f"Expected {n_pts}, obtained {data.shape[0]}." + ) ds = pd[var.Name()] @@ -332,20 +451,18 @@ def create_ds(name): self.printed_step_count += 1 steps.attrs["NSteps"] = self.printed_step_count - def ExecuteFinalizeSolutionStep(self): - if self.output_control_type == "step": - self.step_counter += 1 + self.__controller.Update() - # Compute the visualization grid - def __compute_full_grid(self, brep_surface): + # Compute the visualization grid for brep surfaces + def __compute_full_grid_brep_surface(self, brep_surface): knots_u = brep_surface.KnotsU() knots_v = brep_surface.KnotsV() u_min, u_max = knots_u[0], knots_u[-1] v_min, v_max = knots_v[0], knots_v[-1] - ku = self.__refine(knots_u, self.output_refinement[0]) - kv = self.__refine(knots_v, self.output_refinement[1]) + ku = self.__refine(knots_u, self.output_refinement_surface[0]) + kv = self.__refine(knots_v, self.output_refinement_surface[1]) pts, conn, offs, types = [], [], [], [] uv_coords = [] @@ -440,26 +557,152 @@ def __compute_full_grid(self, brep_surface): np.array(types,np.uint8), uv_coords ) + + # Compute the visualization grid for a BRep curve + def __compute_full_grid_brep_curve(self, brep_curve): + knots = (KratosMultiphysics.IgaApplication.GetNurbsCurveKnots(brep_curve)) - # Evaluate the desired variable at a local coordinate position (u, v, 0) - def __eval_variable(self, brep, u, v, variable): - lc = KM.Array3() - lc[0], lc[1], lc[2] = u, v, 0.0 + if len(knots) < 2: + raise RuntimeError( + f"BRep curve {brep_curve.Id} has fewer than two knots." + ) - ids, N = brep.EvaluateShapeFunctionsAtLocalCoordinates(lc, 0) + u_min = knots[0] + u_max = knots[len(knots) - 1] - sample_node = self.model_part.GetNode(ids[0]) - value = sample_node.GetSolutionStepValue(variable) + if len(self.output_refinement_curve) == 0: + refinement = 0 + else: + refinement = self.output_refinement_curve[0] + + refined_knots = self.__refine(knots, refinement) + + pts = [] + conn = [] + offs = [] + types = [] + u_coordinates = [] + + point_id = 0 + connectivity_counter = 0 + + # Loop over the refined knot spans + for i in range(len(refined_knots) - 1): + u0 = refined_knots[i] + u1 = refined_knots[i + 1] + + # Skip zero-length knot spans + if abs(u1 - u0) < 1e-12: + continue + + local_point_ids = [] + + # Create both endpoints of the VTK line + for u in (u0, u1): + u = max(u_min, min(u_max, u)) + + if not np.isfinite(u): + raise RuntimeError( + f"Non-finite local coordinate u={u} encountered " + f"for BRep curve {brep_curve.Id}." + ) + + local_coordinates = KM.Array3() + local_coordinates[0] = u + local_coordinates[1] = 0.0 + local_coordinates[2] = 0.0 + + try: + global_coordinates = brep_curve.GlobalCoordinates( + local_coordinates + ) + except Exception as exception: + raise RuntimeError( + f"Failed to compute global coordinates for " + f"BRep curve {brep_curve.Id} at u={u}." + ) from exception + + pts.append([ + global_coordinates[0], + global_coordinates[1], + global_coordinates[2], + ]) + + u_coordinates.append(u) + local_point_ids.append(point_id) + point_id += 1 + + offs.append(connectivity_counter) + conn.extend(local_point_ids) + + connectivity_counter += 2 + types.append(VTK_LINE) + + offs.append(connectivity_counter) + + if len(pts) == 0: + raise RuntimeError( + f"No visualization points were generated for " + f"BRep curve {brep_curve.Id}. " + f"Knots: {list(knots)}" + ) + + return ( + np.array(pts, dtype=float), + np.array(conn, dtype=np.int64), + np.array(offs, dtype=np.int64), + np.array(types, dtype=np.uint8), + u_coordinates, + ) + + # Evaluate the active control points and shape function values at a local coordinate position + def __compute_shape_function_data(self, brep, local_coords, is_curve=False): + + shape_function_data = [] + + for u, v in local_coords: + if is_curve: + ids, N = (KratosMultiphysics.IgaApplication.EvaluateNurbsCurveShapeFunctions(brep, u)) + else: + lc = KM.Array3() + lc[0] = u + lc[1] = v + lc[2] = 0.0 + + ids, N = brep.EvaluateShapeFunctionsAtLocalCoordinates(lc, 0) + + if len(ids) == 0: + raise RuntimeError( + f"No active control points found for geometry {brep.Id} " + f"at local coordinates ({u}, {v})." + ) + + nodes = [ + self.model_part.GetNode(node_id) + for node_id in ids + ] + + shape_function_data.append((nodes, N)) + + return shape_function_data + + # Evaluate the desired variable from cached shape function data + def __eval_variable(self, nodes, N, variable): + value = nodes[0].GetSolutionStepValue(variable) if hasattr(value, "__len__"): - result = np.zeros(len(value)) - for i, id in enumerate(ids): - node = self.model_part.GetNode(id) - result += N[i] * np.array(node.GetSolutionStepValue(variable)) + size = len(value) + result = [0.0] * size + + for i, node in enumerate(nodes): + node_value = node.GetSolutionStepValue(variable) + weight = N[i] + for k in range(size): + result[k] += weight * node_value[k] else: result = 0.0 - for i, id in enumerate(ids): - node = self.model_part.GetNode(id) + + for i, node in enumerate(nodes): result += N[i] * node.GetSolutionStepValue(variable) return result @@ -477,5 +720,5 @@ def __refine(self, knots, n): t = j/(n+1) out.append((1-t)*a + t*b) - out.append(knots[-1]) - return out \ No newline at end of file + out.append(knots[len(knots) - 1]) + return out diff --git a/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py b/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py new file mode 100644 index 000000000000..192083702ee8 --- /dev/null +++ b/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py @@ -0,0 +1,769 @@ +import KratosMultiphysics as KM +import KratosMultiphysics.IgaApplication as IGA +import KratosMultiphysics.StructuralMechanicsApplication as SMA +import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory + +import KratosMultiphysics.KratosUnittest as KratosUnittest +import numpy as np + +class TestBeam4pElement(KratosUnittest.TestCase): + + def analytical_solution_bending(x, F, E, I, L): + return F / (6 * E * I) * (3 * L * x**2 - x**3) + + def analytical_solution_torsion(x, M, E, It, nu = 0): + G = 1 / (2 * (1 + nu)) * E + return M / (G * It) * x + + def analytical_solution_normalforce(x, F, E, A): + return (F / (E * A)) * x + + def solve_linear_examples(last_node_force, last_node_moment): + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + w = 2.5 + h = 5 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, w*h) + beam_properties.SetValue(IGA.HEIGHT, h) + beam_properties.SetValue(IGA.WIDTH, w) + beam_properties.SetValue(IGA.I_T, w*h**3/3) + beam_properties.SetValue(IGA.I_N, w * h**3 / 12) + beam_properties.SetValue(IGA.I_V, h * w**3 / 12) + beam_properties.SetValue(KM.YOUNG_MODULUS , 70000) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 7856) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + controllpoints = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0],[2.0, 0.0, 0.0],[3.0, 0.0, 0.0],[4.0, 0.0, 0.0]] + knotvector = [0,0,0,0,1,1,1,1] + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(controllpoints, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[len(controllpoints)-1].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, last_node_force) + moment_condition = model_part.CreateNewCondition('PointMomentCondition3D1N', 2, [nodes[len(controllpoints)-1].Id], prop) + moment_condition.SetValue(SMA.POINT_MOMENT, last_node_moment ) + + model_part.SetBufferSize(1) + + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + + linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( + r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) + + relative_tolerance = 1e-7 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 1 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = False + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(0) + model_part.CloneTimeStep(1) + solver.Solve() + + return nodes, curve + + def solve_nonlinear_example1(): + load = -15 + + controllpoints = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] + knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] + + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + w = 0.1 + h = 0.1 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, w*h) + beam_properties.SetValue(IGA.HEIGHT, h) + beam_properties.SetValue(IGA.WIDTH, w) + beam_properties.SetValue(IGA.I_T, w*h**3/3) + beam_properties.SetValue(IGA.I_V, w * h**3 / 12) + beam_properties.SetValue(IGA.I_N, h * w**3 / 12) + beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 1) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(controllpoints, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + last_node = node + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, load])) + + model_part.SetBufferSize(1) + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + linear_solver = linear_solver_factory.ConstructSolver( + KM.Parameters(r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) + + relative_tolerance = 1e-8 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 10 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = True + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(1) + model_part.CloneTimeStep(1) + solver.Solve() + + return last_node + + def solve_nonlinear_example2(): + k = 0.6 + load = k * 25000 + controllpoints = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] + knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] + + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + r = 0.5*0.1 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, np.pi * r**2) + beam_properties.SetValue(IGA.HEIGHT, 2*r) + beam_properties.SetValue(IGA.WIDTH, 2*r) + beam_properties.SetValue(IGA.I_T, np.pi * r**4/2) + beam_properties.SetValue(IGA.I_V, np.pi * r**4/4) + beam_properties.SetValue(IGA.I_N, np.pi * r**4/4) + beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 0) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(controllpoints, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + last_node = node + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, -load])) + + model_part.SetBufferSize(1) + + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + + linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( + r'{"solver_type": "skyline_lu_factorization"}')) + + relative_tolerance = 1e-7 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 3 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = True + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(1) + model_part.CloneTimeStep(1) + solver.Solve() + + return last_node + + def testClampedFXLinear(self): + last_node_force = KM.Array3([1, 0, 0]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], TestBeam4pElement.analytical_solution_normalforce(nodes[4].X, 1, 70000, 2.5*5)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0 ) + + def testClampedFYLinear(self): + last_node_force = KM.Array3([0, -1, 0]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(nodes[1].X, 1.0 ) + self.assertAlmostEqual(nodes[1].Y, 0.0 ) + self.assertAlmostEqual(nodes[1].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], TestBeam4pElement.analytical_solution_bending(nodes[4].X, -1, 70000,5**3*2.5/12,4)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0) + + def testClampedFZLinear(self): + last_node_force = KM.Array3([0, 0, -1]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(nodes[1].X, 1.0 ) + self.assertAlmostEqual(nodes[1].Y, 0.0 ) + self.assertAlmostEqual(nodes[1].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], TestBeam4pElement.analytical_solution_bending(nodes[4].X,-1, 70000,2.5**3*5/12,4)) + + def testClampedMXLinear(self): + last_node_force = KM.Array3([0, 0, 0]) + last_node_moment = KM.Array3([1, 0, 0]) + nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[0], 0.0 ) + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[1], 0.0 ) + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[2], 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[0], TestBeam4pElement.analytical_solution_torsion(nodes[4].X, 1, 70000,2.5*5**3/3)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[2], 0.0 ) + +E_MOD = 70000.0 +NU = 0.0 +WIDTH = 2.5 +HEIGHT = 5.0 +LENGTH = 4.0 +I_N_ = WIDTH * HEIGHT ** 3 / 12.0 +I_V_ = HEIGHT * WIDTH ** 3 / 12.0 +I_T_ = WIDTH * HEIGHT ** 3 / 3.0 +G_MOD = E_MOD / (2.0 * (1.0 + NU)) +DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) + +class TestBeam4pElementNonlinear(KratosUnittest.TestCase): + + @staticmethod + def build_cantilever(n_cp=5, degree=4): + + model = KM.Model() + mp = model.CreateModelPart('IgaModelPart') + for var in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, + KM.REACTION_MOMENT, SMA.POINT_LOAD): + mp.AddNodalSolutionStepVariable(var) + + props = mp.GetProperties()[0] + props.SetValue(IGA.CROSS_AREA, WIDTH * HEIGHT) + props.SetValue(IGA.HEIGHT, HEIGHT) + props.SetValue(IGA.WIDTH, WIDTH) + props.SetValue(IGA.I_T, I_T_) + props.SetValue(IGA.I_N, I_N_) + props.SetValue(IGA.I_V, I_V_) + props.SetValue(KM.YOUNG_MODULUS, E_MOD) + props.SetValue(KM.POISSON_RATIO, NU) + props.SetValue(KM.DENSITY, 7856) + props.SetValue(IGA.LOCAL_AXIS_ORIENTATION, + np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], + [0.75, 0, 0, 1], [1, 0, 0, 1]])) + props.SetValue(KM.CONSTITUTIVE_LAW, IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i in range(n_cp): + nodes.append(mp.CreateNewNode(i + 1, LENGTH * i / (n_cp - 1), 0.0, 0.0)) + + kv = ([0.0] * degree + + [float(i) / (n_cp - degree) for i in range(1, n_cp - degree)] + + [1.0] * degree) + knots = KM.Vector(len(kv)) + for i, k in enumerate(kv): + knots[i] = k + + curve = KM.NurbsCurveGeometry3D(nodes, degree, knots) + curve.SetId(2) + mp.AddGeometry(curve) + + from KratosMultiphysics.modeler_factory import KratosModelerFactory + modeler_parameters = KM.Parameters(r'''[{ + "modeler_name": "RefinementModeler", + "Parameters": { + "echo_level": 0, + "refinements_file_name": "modeler_tests/curve_h_refinements.iga.json" + } + }]''') + refinement_modeler = KratosModelerFactory().ConstructListOfModelers( + model, modeler_parameters)[0] + refinement_modeler.PrepareGeometryModel() + + curve = mp.GetGeometry(2) + # vtk_curve = KM.BrepCurve(curve) + # vtk_curve.SetId(3) + # mp.AddGeometry(vtk_curve) + nodes = KM.NodesVector() + for node in mp.Nodes: + nodes.append(node) + + qpg = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(qpg, 3) + for eid in range(len(qpg)): + mp.CreateNewElement('NonLinearBernoulliBeamElement3D', eid + 1, qpg[eid], props) + + IGA.ComputeBeamVectorsProcess(mp, curve).ExecuteInitialize() + + for dof, reaction in zip(DOFS, (KM.REACTION_X, KM.REACTION_Y, + KM.REACTION_Z, KM.REACTION_MOMENT_X)): + KM.VariableUtils().AddDof(dof, reaction, mp) + + for var in DOFS: + nodes[0].Fix(var) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + mp.SetBufferSize(1) + mp.CloneTimeStep(1) + for element in mp.Elements: + element.Initialize(mp.ProcessInfo) + return model, mp, nodes + + @staticmethod + def free_dofs(nodes): + fixed = {4 * i + j + for i in range(len(nodes)) + for j, var in enumerate(DOFS) if nodes[i].IsFixed(var)} + return [i for i in range(4 * len(nodes)) if i not in fixed] + + @staticmethod + def element_dof_index(element): + idx = [] + for node in element.GetGeometry(): + base = 4 * (node.Id - 1) + idx += [base, base + 1, base + 2, base + 3] + return np.array(idx) + + @classmethod + def apply_state(cls, nodes, u): + for i in range(len(nodes)): + nodes[i].SetSolutionStepValue( + KM.DISPLACEMENT, KM.Array3([u[4 * i], u[4 * i + 1], u[4 * i + 2]])) + nodes[i].SetSolutionStepValue(KM.ROTATION_X, float(u[4 * i + 3])) + + + @staticmethod + def write_vtk_output(model, mp, output_file_name="beam_deformation"): + from KratosMultiphysics.IgaApplication.iga_vtk_output_process import IgaVTKOutputProcess + + settings = KM.Parameters(r'''{ + "model_part_name": "IgaModelPart", + "output_file_name": "beam_deformation", + "brep_curve_ids": [3], + "nodal_solution_step_data_variables": ["DISPLACEMENT", "ROTATION"], + "output_refinement_curve": [10], + "output_control_type": "step", + "output_frequency": 1 + }''') + settings["output_file_name"].SetString(output_file_name) + + output_process = IgaVTKOutputProcess(model, settings) + output_process.ExecuteInitialize() + output_process.ExecuteBeforeSolutionLoop() + mp.ProcessInfo[KM.TIME] = 1.0 + if output_process.IsOutputStep(): + output_process.PrintOutput() + + @classmethod + def assemble(cls, mp, nodes, u, build_level=0): + + cls.apply_state(nodes, u) + mp.ProcessInfo[IGA.BUILD_LEVEL] = build_level + ndof = 4 * len(nodes) + K = np.zeros((ndof, ndof)) + R = np.zeros(ndof) + for element in mp.Elements: + lhs, rhs = KM.Matrix(), KM.Vector() + element.CalculateLocalSystem(lhs, rhs, mp.ProcessInfo) + idx = cls.element_dof_index(element) + K[np.ix_(idx, idx)] += np.array(lhs, copy=True) + R[idx] += np.array(rhs, copy=True) + return K, R + + @classmethod + def newton(cls, mp, nodes, f_ext, n_steps=8, tol=1e-10, max_it=40): + + free = cls.free_dofs(nodes) + u = np.zeros(4 * len(nodes)) + norms = [] + for step in range(1, n_steps + 1): + f = f_ext * step / n_steps + scale = max(1.0, np.linalg.norm(f[free])) + norms = [] + for _ in range(max_it): + K, R = cls.assemble(mp, nodes, u) + residual = R + f + norm = np.linalg.norm(residual[free]) + norms.append(norm) + if norm < tol * scale: + break + u[free] += np.linalg.solve(K[np.ix_(free, free)], residual[free]) + return u, norms + + def testTangentMatchesFiniteDifferences(self): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + ndof = 4 * n_cp + + u0 = np.zeros(ndof) + for i in range(n_cp): + x = nodes[i].X0 + u0[4 * i] = 0.004 * x + u0[4 * i + 1] = 0.010 * x ** 2 + u0[4 * i + 2] = -0.006 * x ** 2 + u0[4 * i + 3] = 0.003 * x + + K, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=0) + + K_mat, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=1) + + K_geo, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=2) + + h = 1e-7 + K_fd = np.zeros_like(K) + for j in range(ndof): + up = u0.copy(); up[j] += h + um = u0.copy(); um[j] -= h + _, rp = TestBeam4pElementNonlinear.assemble(mp, nodes, up) + _, rm = TestBeam4pElementNonlinear.assemble(mp, nodes, um) + K_fd[:, j] = -(rp - rm) / (2.0 * h) + + # error diagonistics block + #--------------- + K_reconstructed = K_mat + K_geo + + diff = K - K_fd + reconstruction_diff = K - K_reconstructed + + max_index = np.unravel_index( + np.argmax(np.abs(diff)), + diff.shape) + + i, j = max_index + + print("\n--- Tangent diagnostics ---") + print("||K|| =", np.linalg.norm(K)) + print("||K_mat|| =", np.linalg.norm(K_mat)) + print("||K_geo|| =", np.linalg.norm(K_geo)) + print("||K_fd|| =", np.linalg.norm(K_fd)) + + print( + "||K - (K_mat + K_geo)|| =", + np.linalg.norm(reconstruction_diff) + ) + + print( + "relative total error =", + np.abs(diff).max() / np.abs(K).max() + ) + + print("largest mismatch at (row, col) =", max_index) + print("K =", K[i, j]) + print("K_fd =", K_fd[i, j]) + print("diff =", diff[i, j]) + print("K_mat =", K_mat[i, j]) + print("K_geo =", K_geo[i, j]) + + K_geo_required = K_fd - K_mat + geo_diff = K_geo - K_geo_required + + print( + "relative geometric-part error =", + np.abs(geo_diff).max() / + max(np.abs(K_geo_required).max(), 1e-16) + ) + + geo_index = np.unravel_index( + np.argmax(np.abs(geo_diff)), + geo_diff.shape) + + print("largest geometric mismatch =", geo_index) + print("K_geo =", K_geo[geo_index]) + print("K_geo_required =", K_geo_required[geo_index]) + print("geo diff =", geo_diff[geo_index]) + + #--------------------------end + + error = np.abs(diff).max() / np.abs(K).max() + + self.assertLess( + error, + 1e-5, + 'tangent stiffness is not the derivative of the internal ' + 'force (relative error %.3e) -- a missing or wrong ' + 'geometric-stiffness term' % error) + + error = np.abs(K - K_fd).max() / np.abs(K).max() + self.assertLess(error, 1e-5, + 'tangent stiffness is not the derivative of the internal ' + 'force (relative error %.3e) -- a missing or wrong ' + 'geometric-stiffness term' % error) + + def testQuadraticNewtonConvergence(self): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + + _, norms = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=4) + + self.assertGreaterEqual(len(norms), 3) + self.assertLess(norms[-1], 1e-6, 'Newton did not converge') + + self.assertLess(norms[-1], norms[-2] ** 1.5, + 'convergence is not quadratic: %s' + % ' '.join('%.2e' % n for n in norms)) + + def testLargeDeflectionElastica(self): + EI = E_MOD * I_N_ + alpha = 0.5 + load = alpha * EI / LENGTH ** 2 + ux_exact, uy_exact = -0.0636758499, -0.6485743026 + + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=8) + # TestBeam4pElementNonlinear.write_vtk_output(model, mp) + + uy = u[4 * (n_cp - 1) + 1] + ux = u[4 * (n_cp - 1)] + + self.assertLess(abs(uy), abs(-load * LENGTH ** 3 / (3 * EI)) * 1.02) + self.assertLess(abs(uy - uy_exact) / abs(uy_exact), 0.06) + self.assertLess(abs(ux - ux_exact) / abs(ux_exact), 0.15) + + @classmethod + def buckling_loads(cls, mp, nodes, load_vector, p_ref): + n_cp = len(nodes) + f_ext = np.zeros(4 * n_cp) + for j, value in enumerate(load_vector): + f_ext[4 * (n_cp - 1) + j] = value + + u, _ = cls.newton(mp, nodes, f_ext, n_steps=1) + + cls.apply_state(nodes, u) + k_mat, _ = cls.assemble(mp, nodes, u, build_level=1) + k_geo, _ = cls.assemble(mp, nodes, u, build_level=2) + + free = cls.free_dofs(nodes) + A = k_mat[np.ix_(free, free)] + B = k_geo[np.ix_(free, free)] + + mu = np.linalg.eigvals(-np.linalg.solve(A, B)) + mu = mu[np.abs(mu.imag) < 1e-8 * (1.0 + np.abs(mu.real))].real + lam = np.sort(1.0 / mu[np.abs(mu) > 1e-12]) + return np.sort(lam[lam > 1e-8]) * p_ref + + def testEulerBucklingWeakAxis(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + euler = np.pi ** 2 * E_MOD * I_V_ / (4.0 * LENGTH ** 2) + self.assertAlmostEqual(loads[0] / euler, 1.0, delta=0.005) + + def testEulerBucklingStrongAxis(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + euler = np.pi ** 2 * E_MOD * I_N_ / (4.0 * LENGTH ** 2) + self.assertAlmostEqual(loads[1] / euler, 1.0, delta=0.005) + + def testLateralTorsionalBuckling(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [0.0, -p_ref, 0.0], p_ref) + timoshenko = 4.013 * np.sqrt(E_MOD * I_V_ * G_MOD * I_T_) / LENGTH ** 2 + + self.assertAlmostEqual(loads[0] / timoshenko, 1.0, delta=0.05) + + @KratosUnittest.expectedFailure + def testLinearBendingIsMeshIndependent(self): + EI = E_MOD * I_N_ + load = 1e-4 * EI / LENGTH ** 2 + reference = -load * LENGTH ** 3 / (3.0 * EI) + for n_cp in (5, 7, 9, 13): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever(n_cp) + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=1) + uy = u[4 * (n_cp - 1) + 1] + self.assertLess(abs(uy - reference) / abs(reference), 1e-6, + 'n_cp=%d (%d knot spans) is off by %.3e' + % (n_cp, mp.NumberOfElements() // 5, + abs(uy - reference) / abs(reference))) + +if __name__ == "__main__": + KratosUnittest.main() \ No newline at end of file diff --git a/applications/IgaApplication/tests/modeler_tests/curve_h_refinements.iga.json b/applications/IgaApplication/tests/modeler_tests/curve_h_refinements.iga.json new file mode 100644 index 000000000000..7313d5c8b66b --- /dev/null +++ b/applications/IgaApplication/tests/modeler_tests/curve_h_refinements.iga.json @@ -0,0 +1,13 @@ +{ + "refinements": [ + { + "brep_ids": [ 2 ], + "geometry_type": "NurbsCurve", + "model_part_name": "IgaModelPart", + "parameters": { + "insert_nb_per_span": 2, + "increase_degree": 0 + } + } + ] +} diff --git a/applications/LinearSolversApplication/tests/test_eigen_direct_solver.py b/applications/LinearSolversApplication/tests/test_eigen_direct_solver.py index 1cdca36e30cd..60ad13098d5a 100644 --- a/applications/LinearSolversApplication/tests/test_eigen_direct_solver.py +++ b/applications/LinearSolversApplication/tests/test_eigen_direct_solver.py @@ -10,13 +10,13 @@ class TestEigenDirectSolver(KratosUnittest.TestCase): def __ExecuteEigenDirectSolverTest(self, class_name: str, solver_type: str) -> None: - space = KratosMultiphysics.UblasSparseSpace() + space = KratosMultiphysics.SparseSpace() settings = KratosMultiphysics.Parameters('{ "solver_type" : "LinearSolversApplication.' + solver_type + '" }') solver = ConstructSolver(settings) - a = KratosMultiphysics.CompressedMatrix() + a = KratosMultiphysics.SparseMatrix() base_dir = Path(__file__).resolve().parents[3] @@ -36,31 +36,31 @@ def __ExecuteEigenDirectSolverTest(self, self.assertEqual(dimension, 900) - b_exp = KratosMultiphysics.Vector(dimension) # [1, 2, ..., dimension-1, dimension] + b_exp = KratosMultiphysics.SparseVector(dimension) # [1, 2, ..., dimension-1, dimension] for i in range(dimension): b_exp[i] = i + 1 - x = KratosMultiphysics.Vector(dimension) + x = KratosMultiphysics.SparseVector(dimension) solver.Solve(a, x, b_exp) - b_act = KratosMultiphysics.Vector(dimension) + b_act = KratosMultiphysics.SparseVector(dimension) space.Mult(a, x, b_act) for i in range(dimension): self.assertAlmostEqual(b_act[i], b_exp[i], 7) def __ExecuteEigenDirectSolverMatrixRHSTest(self, solver_type: str) -> None: - space = KratosMultiphysics.UblasSparseSpace() - + space = KratosMultiphysics.SparseSpace() + settings = KratosMultiphysics.Parameters( '{ "solver_type" : "LinearSolversApplication.' + solver_type + '" }' ) solver = ConstructSolver(settings) - - a = KratosMultiphysics.CompressedMatrix() - + + a = KratosMultiphysics.SparseMatrix() + this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file_dir))) matrix_file_path = os.path.join( @@ -93,8 +93,8 @@ def __ExecuteEigenDirectSolverMatrixRHSTest(self, solver_type: str) -> None: b_act = KratosMultiphysics.Matrix(dimension, num_rhs) for j in range(num_rhs): - x_col = KratosMultiphysics.Vector(dimension) - b_col = KratosMultiphysics.Vector(dimension) + x_col = KratosMultiphysics.SparseVector(dimension) + b_col = KratosMultiphysics.SparseVector(dimension) for i in range(dimension): x_col[i] = x[i, j] @@ -156,6 +156,9 @@ def test_EigenSparseLU_MatrixRHS(self): def test_EigenSparseCG(self): self.__ExecuteEigenDirectSolverTest('SparseCGSolver', 'sparse_cg') + def test_EigenSparseCG_MatrixRHS(self): + self.__ExecuteEigenDirectSolverMatrixRHSTest('sparse_cg') + def test_EigenSparseQR(self): self.__ExecuteEigenDirectSolverTest('SparseQRSolver', 'sparse_qr') @@ -182,6 +185,10 @@ def test_EigenPardisoLDLT_MatrixRHS(self): def test_EigenPardisoLLT(self): self.__ExecuteEigenDirectSolverTest('PardisoLLTSolver', 'pardiso_llt') + @KratosUnittest.skipIf(not LinearSolversApplication.HasMKL(), "Kratos was compiled without MKL support.") + def test_EigenPardisoLLT_MatrixRHS(self): + self.__ExecuteEigenDirectSolverMatrixRHSTest('pardiso_llt') + def test_EigenComplexSparseLU(self): self.__ExecuteEigenDirectComplexSolverTest('ComplexSparseLUSolver', 'sparse_lu_complex') diff --git a/applications/LinearSolversApplication/tests/test_eigensystem_solver.py b/applications/LinearSolversApplication/tests/test_eigensystem_solver.py index 8812ffc6ec1b..9850d37dd4a8 100644 --- a/applications/LinearSolversApplication/tests/test_eigensystem_solver.py +++ b/applications/LinearSolversApplication/tests/test_eigensystem_solver.py @@ -8,9 +8,9 @@ class TestEigensystemSolver(KratosUnittest.TestCase): def _run_test(self, settings): - space = KratosMultiphysics.UblasSparseSpace() + space = KratosMultiphysics.SparseSpace() - K = KratosMultiphysics.CompressedMatrix() + K = KratosMultiphysics.SparseMatrix() this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file_dir))) @@ -22,12 +22,10 @@ def _run_test(self, settings): n = K.Size1() self.assertEqual(n, 900) - M = KratosMultiphysics.CompressedMatrix(n, n) + M = KratosMultiphysics.SparseMatrix(n, n) for i in range(n): - for j in range(n): - if (i == j): - M[i, j] = 1.0 + M[i, i] = 1.0 # create result containers (they will be resized inside the solver) eigenvalues = KratosMultiphysics.Vector(n) @@ -46,11 +44,11 @@ def _run_test(self, settings): # test mass normalization of eigenvectors for i in range(eigenvectors.Size1()): - eigenvector = KratosMultiphysics.Vector(n) + eigenvector = KratosMultiphysics.SparseVector(n) for j in range(n): eigenvector[j] = eigenvectors[i,j] - _aux = KratosMultiphysics.Vector(n) + _aux = KratosMultiphysics.SparseVector(n) space.Mult(M, eigenvector, _aux) value = 0.0 diff --git a/applications/LinearSolversApplication/tests/test_feast_eigensystem_solver.py b/applications/LinearSolversApplication/tests/test_feast_eigensystem_solver.py index 7d8aa2b1bc15..f75b9e7ce8d8 100644 --- a/applications/LinearSolversApplication/tests/test_feast_eigensystem_solver.py +++ b/applications/LinearSolversApplication/tests/test_feast_eigensystem_solver.py @@ -11,7 +11,7 @@ class TestFeastEigensystemSolver(KratosUnittest.TestCase): def test_real_symmetric_gev(self): - space = KratosMultiphysics.UblasSparseSpace() + space = KratosMultiphysics.SparseSpace() settings = KratosMultiphysics.Parameters('''{ "solver_type": "feast", @@ -25,7 +25,7 @@ def test_real_symmetric_gev(self): "echo_level": 0 }''') - K = KratosMultiphysics.CompressedMatrix() + K = KratosMultiphysics.SparseMatrix() this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file_dir))) @@ -38,7 +38,7 @@ def test_real_symmetric_gev(self): self.assertEqual(n, 900) # create an identity matrix - M = KratosMultiphysics.CompressedMatrix(n, n) + M = KratosMultiphysics.SparseMatrix(n, n) for i in range(n): M[i, i] = 1.0 @@ -57,18 +57,23 @@ def test_real_symmetric_gev(self): self.assertAlmostEqual(eigenvalues[2], 0.153184311127333, 7) for i in range(eigenvalues.Size()): - eigenvector = KratosMultiphysics.Vector(n) + # System-space vectors so space.Mult operates in place on both backends + eigenvector = KratosMultiphysics.SparseVector(n) for j in range(n): eigenvector[j] = eigenvectors[i,j] - _aux_1 = KratosMultiphysics.Vector(n,0) - _aux_2 = KratosMultiphysics.Vector(n,0) + _aux_1 = KratosMultiphysics.SparseVector(n) + _aux_2 = KratosMultiphysics.SparseVector(n) + space.SetToZeroVector(_aux_1) + space.SetToZeroVector(_aux_2) space.Mult(K,eigenvector,_aux_1) space.Mult(M,eigenvector,_aux_2) - _aux_2 *= eigenvalues[i] - self.assertVectorAlmostEqual(_aux_1, _aux_2) + # K*phi == lambda*M*phi, compared element-wise (the eigen backend + # vector exposes no python arithmetic operators) + for j in range(n): + self.assertAlmostEqual(_aux_1[j], eigenvalues[i] * _aux_2[j], 7) def test_real_general_gev(self): @@ -86,7 +91,7 @@ def test_real_general_gev(self): "echo_level": 0 }''') - K = KratosMultiphysics.CompressedMatrix() + K = KratosMultiphysics.SparseMatrix() this_file_dir = os.path.dirname(os.path.realpath(__file__)) base_dir = os.path.dirname(os.path.dirname(os.path.dirname(this_file_dir))) @@ -98,7 +103,7 @@ def test_real_general_gev(self): n = K.Size1() # create an identity matrix - M = KratosMultiphysics.CompressedMatrix(n, n) + M = KratosMultiphysics.SparseMatrix(n, n) for i in range(n): M[i, i] = 1 @@ -153,13 +158,13 @@ def test_real_general_gev_complex_result(self): "echo_level": 0 }''') - K = KratosMultiphysics.CompressedMatrix(2,2) + K = KratosMultiphysics.SparseMatrix(2,2) K[0,0] = 1/sqrt(2) K[1,1] = 1 n = K.Size1() - M = KratosMultiphysics.CompressedMatrix(n, n) + M = KratosMultiphysics.SparseMatrix(n, n) M[0,1] = 1 M[1,0] = -1/sqrt(2) diff --git a/applications/LinearSolversApplication/tests/test_mkl.py b/applications/LinearSolversApplication/tests/test_mkl.py index b3f648d74228..e9a26fbda9cf 100644 --- a/applications/LinearSolversApplication/tests/test_mkl.py +++ b/applications/LinearSolversApplication/tests/test_mkl.py @@ -19,25 +19,28 @@ def __Run(self, solver_type: str): base_dir: pathlib.Path = this_file_dir.parent.parent.parent matrix_file_path: pathlib.Path = base_dir / "kratos" / "tests" / "auxiliar_files_for_python_unittest" / "sparse_matrix_files" / "A.mm" - lhs = KratosMultiphysics.CompressedMatrix() + space = KratosMultiphysics.SparseSpace() + + lhs = KratosMultiphysics.SparseMatrix() file_read = KratosMultiphysics.ReadMatrixMarketMatrix(str(matrix_file_path), lhs) self.assertTrue(file_read, msg="The MatrixFile could not be read") dimension = lhs.Size1() - rhs = KratosMultiphysics.Vector(dimension) + rhs = KratosMultiphysics.SparseVector(dimension) for i in range(dimension): rhs[i] = i + 1 # Iteratively call the smoother on the residual, and check whether it decreases its norm. - residual_norm: float = KratosMultiphysics.UblasSparseSpace().TwoNorm(rhs) + residual_norm: float = space.TwoNorm(rhs) for _ in range(10): - solution = KratosMultiphysics.Vector(dimension) + solution = KratosMultiphysics.SparseVector(dimension) solver.Solve(lhs, solution, rhs) - residual = KratosMultiphysics.Vector(dimension) - KratosMultiphysics.UblasSparseSpace().Mult(lhs, solution, residual) - rhs -= residual - new_residual_norm: float = KratosMultiphysics.UblasSparseSpace().TwoNorm(rhs) + residual = KratosMultiphysics.SparseVector(dimension) + space.Mult(lhs, solution, residual) + # rhs -= residual (the EigenVector binding has no in-place arithmetic operators) + space.UnaliasedAdd(rhs, -1.0, residual) + new_residual_norm: float = space.TwoNorm(rhs) self.assertLess(new_residual_norm, residual_norm) residual_norm = new_residual_norm @@ -53,4 +56,4 @@ def test_MKLILUT(self): if __name__ == '__main__': - KratosUnittest.main() + KratosUnittest.main() \ No newline at end of file diff --git a/applications/PFEM2Application/python_scripts/strategy_python.py b/applications/PFEM2Application/python_scripts/strategy_python.py index e70c4cc849dc..cd3a1052d7f5 100644 --- a/applications/PFEM2Application/python_scripts/strategy_python.py +++ b/applications/PFEM2Application/python_scripts/strategy_python.py @@ -13,7 +13,7 @@ def __init__(self,model_part,time_scheme,linear_solver,convergence_criteria,Calc self.ReformDofSetAtEachStep = ReformDofSetAtEachStep self.MoveMeshFlag = MoveMeshFlag - self.space_utils = UblasSparseSpace() + self.space_utils = SparseSpace() #default values for some variables self.rebuild_level = 1 #rebuild at each solution step diff --git a/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py b/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py index ab60e1ce4102..aff9e4991d62 100644 --- a/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py +++ b/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py @@ -78,7 +78,7 @@ def _CreateSolutionStrategy(self): False ) def _MassMatrixComputation(self): - space = KratosMultiphysics.UblasSparseSpace() + space = KratosMultiphysics.SparseSpace() self.GetComputingModelPart().ProcessInfo.SetValue(StructuralMechanicsApplication.BUILD_LEVEL,1) #Mass Matrix scheme = self._GetSolutionStrategy().GetScheme() @@ -107,7 +107,7 @@ def _MassMatrixComputation(self): return M def _StiffnessMatrixComputation(self): - space = KratosMultiphysics.UblasSparseSpace() + space = KratosMultiphysics.SparseSpace() self.GetComputingModelPart().ProcessInfo.SetValue(StructuralMechanicsApplication.BUILD_LEVEL,2) #Stiffness Matrix scheme = self._GetSolutionStrategy().GetScheme() @@ -190,4 +190,4 @@ def SolveSolutionStep(self): ## Assign results to Kratos variables self._AssignVariables(vals,vecs) - return True #converged + return True #converged \ No newline at end of file diff --git a/kipping... b/kipping... new file mode 100644 index 000000000000..2e8484d4f9ec --- /dev/null +++ b/kipping... @@ -0,0 +1,1893 @@ +diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +new file mode 100644 +index 00000000000..d4417883cac +--- /dev/null ++++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +@@ -0,0 +1,1886 @@ ++// KRATOS _____________ ++// / _/ ____/ | ++// / // / __/ /| | ++// _/ // /_/ / ___ | ++// /___/\____/_/ |_| Application ++// ++// License: BSD License ++// Kratos default license: kratos/license.txt ++// ++// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio ++// ++ ++// System includes ++ ++// External includes ++ ++// Project includes ++ ++// Application includes ++#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" ++#include "utilities/math_utils.h" ++ ++namespace Kratos ++{ ++ void NonLinearBernoulliBeamElement3D::Initialize(const ProcessInfo& rCurrentProcessInfo) ++ { ++ KRATOS_TRY ++ InitializeMaterial(); ++ ++ ++ mDofsPerNode = 4; ++ mNumberOfDofs = this->GetGeometry().size() * mDofsPerNode; ++ mSMatrixRodriguesVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaRodriguesLambdaVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesDerivativeVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); ++ mSMatrixRodriguesSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixRodriguesDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); ++ KRATOS_CATCH("") ++  ++ } ++ ++ ++ ++ void NonLinearBernoulliBeamElement3D::CalculateKinematics( ++ const IndexType IntegrationPointIndex, ++ KinematicVariables& rKinematicVariables) ++ { ++ const auto& r_geometry = GetGeometry(); ++ ++ // Get shape functions and derivatives ++ const Matrix& r_shape_functions = ++ r_geometry.ShapeFunctionsValues(); ++ ++ const Matrix& r_shape_function_derivatives = ++ r_geometry.ShapeFunctionDerivatives( ++ 1, ++ IntegrationPointIndex); ++ ++ const Matrix& r_shape_function_second_derivatives = ++ r_geometry.ShapeFunctionDerivatives( ++ 2, ++ IntegrationPointIndex); ++ ++ // Clear variables ++ rKinematicVariables.R1.clear(); ++ rKinematicVariables.R2.clear(); ++ rKinematicVariables.r1.clear(); ++ rKinematicVariables.r2.clear(); ++ ++ // Calculate reference and current configurations ++ for (IndexType i = 0; i < r_geometry.size(); ++i) { ++ const array_1d& r_initial_position = ++ r_geometry[i].GetInitialPosition(); ++ ++ const array_1d& r_displacement = ++ r_geometry[i].FastGetSolutionStepValue(DISPLACEMENT); ++ ++ // Reference configuration ++ rKinematicVariables.R1 += ++ r_shape_function_derivatives(i, 0) * ++ r_initial_position; ++ ++ rKinematicVariables.R2 += ++ r_shape_function_second_derivatives(i, 0) * ++ r_initial_position; ++ ++ // Current configuration ++ const array_1d current_position = ++ r_initial_position + r_displacement; ++ ++ rKinematicVariables.r1 += ++ r_shape_function_derivatives(i, 0) * ++ current_position; ++ ++ rKinematicVariables.r2 += ++ r_shape_function_second_derivatives(i, 0) * ++ current_position; ++ ++ // Rotations ++ const double rotation = ++ r_geometry[i].FastGetSolutionStepValue(ROTATION_X); ++ ++ rKinematicVariables.phi += ++ r_shape_functions(IntegrationPointIndex, i) * ++ rotation; ++ ++ rKinematicVariables.phi_der += ++ r_shape_function_derivatives(i, 0) * ++ rotation; ++ } ++ ++ // Calculate length measures ++ rKinematicVariables.A = ++ norm_2(rKinematicVariables.R1); ++ ++ rKinematicVariables.a = ++ norm_2(rKinematicVariables.r1); ++ ++ // Calculate curvature measures ++ const double reference_base_vector_product = ++ inner_prod( ++ rKinematicVariables.R1, ++ rKinematicVariables.R2); ++ ++ const double current_base_vector_product = ++ inner_prod( ++ rKinematicVariables.r1, ++ rKinematicVariables.r2); ++ ++ rKinematicVariables.B = sqrt( ++ inner_prod( ++ rKinematicVariables.R2, ++ rKinematicVariables.R2) ++ - pow( ++ reference_base_vector_product / ++ rKinematicVariables.A, ++ 2)); ++ ++ rKinematicVariables.b = sqrt( ++ inner_prod( ++ rKinematicVariables.r2, ++ rKinematicVariables.r2) ++ - pow( ++ current_base_vector_product / ++ rKinematicVariables.a, ++ 2)); ++ ++ // Compute reference cross-section geometry ++ ComputeReferenceCrossSectionGeometry( ++ rKinematicVariables); ++ ++ // Compute current cross-section geometry ++ ComputeCurrentCrossSectionGeometry( ++ rKinematicVariables); ++ } ++  ++ ++ void NonLinearBernoulliBeamElement3D::CalculateAll( ++ MatrixType& rLeftHandSideMatrix, ++ VectorType& rRightHandSideVector, ++ const ProcessInfo& rCurrentProcessInfo, ++ const bool CalculateStiffnessMatrixFlag, ++ const bool CalculateResidualVectorFlag) ++ { ++ KRATOS_TRY ++ ++ const auto& r_geometry = GetGeometry(); ++ const auto& r_integration_points = ++ r_geometry.IntegrationPoints(); ++ ++ Vector stress_axial = ZeroVector(5); ++ Vector stress_bending_1 = ZeroVector(5); ++ Vector stress_bending_2 = ZeroVector(5); ++ Vector stress_torsion_1 = ZeroVector(5); ++ Vector stress_torsion_2 = ZeroVector(5); ++ ++ for ( ++ IndexType point_number = 0; ++ point_number < r_integration_points.size(); ++ ++point_number) ++ { ++ // Compute kinematics and metric ++ KinematicVariables kinematic_variables( ++ GetGeometry().WorkingSpaceDimension()); ++ ++ CalculateKinematics( ++ point_number, ++ kinematic_variables); ++ ++ // Create constitutive law parameters ++ ConstitutiveLaw::Parameters constitutive_law_parameters( ++ GetGeometry(), ++ GetProperties(), ++ rCurrentProcessInfo); ++ ++ ConstitutiveVariables constitutive_variables(5); ++ ++ CalculateConstitutiveVariables( ++ point_number, ++ kinematic_variables, ++ constitutive_variables, ++ constitutive_law_parameters, ++ ConstitutiveLaw::StressMeasure_PK2); ++ ++ Matrix b_axial; ++ Matrix b_bending_1; ++ Matrix b_bending_2; ++ Matrix b_torsion_1; ++ Matrix b_torsion_2; ++ ++ ComputeBMatrices( ++ point_number, ++ kinematic_variables, ++ b_axial, ++ b_bending_1, ++ b_bending_2, ++ b_torsion_1, ++ b_torsion_2); ++ ++ Matrix g_axial; ++ Matrix g_bending_1; ++ Matrix g_bending_2; ++ Matrix g_torsion_1; ++ Matrix g_torsion_2; ++ ++ ComputeGMatrices( ++ point_number, ++ kinematic_variables, ++ g_axial, ++ g_bending_1, ++ g_bending_2, ++ g_torsion_1, ++ g_torsion_2); ++ ++ // Assemble stiffness with cross-sectional scaling ++ const double integration_weight = ++ r_integration_points[point_number].Weight() * ++ kinematic_variables.A; ++ ++ const double inverse_a2 = ++ 1.0 / ++ (kinematic_variables.A * ++ kinematic_variables.A); ++ ++ const double inverse_a4 = ++ inverse_a2 * inverse_a2; ++ ++ if (CalculateStiffnessMatrixFlag == true) { ++ // Material stiffness ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_axial), ++ Matrix(prod( ++ constitutive_variables.ConstitutiveMatrix, ++ b_axial))); ++ ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_bending_1), ++ Matrix(prod( ++ constitutive_variables.ConstitutiveMatrix, ++ b_bending_1))); ++ ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_bending_2), ++ Matrix(prod( ++ constitutive_variables.ConstitutiveMatrix, ++ b_bending_2))); ++ ++ rLeftHandSideMatrix += ++ inverse_a2 * ++ integration_weight * ++ prod( ++ trans(b_torsion_1), ++ Matrix(prod( ++ constitutive_variables.ConstitutiveMatrix, ++ b_torsion_1))); ++ ++ rLeftHandSideMatrix += ++ inverse_a2 * ++ integration_weight * ++ prod( ++ trans(b_torsion_2), ++ Matrix(prod( ++ constitutive_variables.ConstitutiveMatrix, ++ b_torsion_2))); ++ ++ // Geometrical stiffness ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ g_axial * ++ constitutive_variables.StressVector[0]; ++ ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ g_bending_1 * ++ constitutive_variables.StressVector[1]; ++ ++ rLeftHandSideMatrix += ++ inverse_a4 * ++ integration_weight * ++ g_bending_2 * ++ constitutive_variables.StressVector[2]; ++ ++ rLeftHandSideMatrix += ++ inverse_a2 * ++ integration_weight * ++ g_torsion_1 * ++ constitutive_variables.StressVector[3]; ++ ++ rLeftHandSideMatrix += ++ inverse_a2 * ++ integration_weight * ++ g_torsion_2 * ++ constitutive_variables.StressVector[4]; ++ } ++ ++ if (CalculateResidualVectorFlag == true) { ++ // Map stress components to different behaviors ++ stress_axial[0] = ++ constitutive_variables.StressVector[0]; ++ ++ stress_bending_1[1] = ++ constitutive_variables.StressVector[1]; ++ ++ stress_bending_2[2] = ++ constitutive_variables.StressVector[2]; ++ ++ stress_torsion_1[3] = ++ constitutive_variables.StressVector[3]; ++ ++ stress_torsion_2[4] = ++ constitutive_variables.StressVector[4]; ++ ++ // Assemble internal forces ++ rRightHandSideVector -= ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_axial), ++ stress_axial); ++ ++ rRightHandSideVector -= ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_bending_1), ++ stress_bending_1); ++ ++ rRightHandSideVector -= ++ inverse_a4 * ++ integration_weight * ++ prod( ++ trans(b_bending_2), ++ stress_bending_2); ++ ++ rRightHandSideVector -= ++ inverse_a2 * ++ integration_weight * ++ prod( ++ trans(b_torsion_1), ++ stress_torsion_1); ++ ++ rRightHandSideVector -= ++ inverse_a2 * ++ integration_weight * ++ prod( ++ trans(b_torsion_2), ++ stress_torsion_2); ++ } ++ } ++ ++ KRATOS_CATCH("") ++ } ++ ++  ++ int NonLinearBernoulliBeamElement3D::Check( ++ const ProcessInfo& rCurrentProcessInfo) const ++ { ++ KRATOS_TRY ++ ++ Check(rCurrentProcessInfo); ++ ++ const double numerical_limit = ++ std::numeric_limits::epsilon(); ++ ++ KRATOS_ERROR_IF( ++ !GetProperties().Has(I_T) || ++ GetProperties()[I_T] <= numerical_limit) ++ << "Please provide a reasonable value for \"I_T\" " ++ << "(torsional moment of inertia) for element #" ++ << Id() << std::endl; ++ ++ KRATOS_ERROR_IF( ++ !GetProperties().Has(I_N) || ++ GetProperties()[I_N] <= numerical_limit) ++ << "Please provide a reasonable value for \"I_N\" " ++ << "(bending moment of inertia about N axis) for element #" ++ << Id() << std::endl; ++ ++ KRATOS_ERROR_IF( ++ !GetProperties().Has(I_V) || ++ GetProperties()[I_V] <= numerical_limit) ++ << "Please provide a reasonable value for \"I_V\" " ++ << "(bending moment of inertia about V axis) for element #" ++ << Id() << std::endl; ++ ++ KRATOS_ERROR_IF( ++ !GetProperties().Has(LOCAL_AXIS_ORIENTATION)) ++ << "\"LOCAL_AXIS_ORIENTATION\" not provided for element #" ++ << Id() << std::endl; ++ ++ if (GetProperties().Has(T_0)) { ++ const Vector3d& r_reference_tangent = ++ GetProperties()[T_0]; ++ ++ KRATOS_ERROR_IF( ++ norm_2(r_reference_tangent) <= numerical_limit) ++ << "\"T_0\" reference director vector must have " ++ << "non-zero magnitude for element #" ++ << Id() << std::endl; ++ } ++ ++ if (GetProperties().Has(N_0)) { ++ const Vector3d& r_reference_normal = ++ GetProperties()[N_0]; ++ ++ KRATOS_ERROR_IF( ++ norm_2(r_reference_normal) <= numerical_limit) ++ << "\"N_0\" reference director vector must have " ++ << "non-zero magnitude for element #" ++ << Id() << std::endl; ++ } ++ ++ return 0; ++ ++ KRATOS_CATCH("") ++ } ++ ++ ++ void NonLinearBernoulliBeamElement3D::CalculateConstitutiveVariables( ++ const IndexType IntegrationPointIndex, ++ const KinematicVariables& rKinematicVariables, ++ ConstitutiveVariables& rConstitutiveVariables, ++ ConstitutiveLaw::Parameters& rConstitutiveLawParameters, ++ const ConstitutiveLaw::StressMeasure StressMeasure) ++ { ++ rConstitutiveLawParameters.GetOptions().Set( ++ ConstitutiveLaw::USE_ELEMENT_PROVIDED_STRAIN, ++ true); ++ ++ rConstitutiveLawParameters.GetOptions().Set( ++ ConstitutiveLaw::COMPUTE_STRESS); ++ ++ rConstitutiveLawParameters.GetOptions().Set( ++ ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR); ++ ++ rConstitutiveVariables.StrainVector[0] = ++ 0.5 * ( ++ rKinematicVariables.a * rKinematicVariables.a - ++ rKinematicVariables.A * rKinematicVariables.A); ++ ++ rConstitutiveVariables.StrainVector[1] = ++ rKinematicVariables.b_n - ++ rKinematicVariables.B_n; ++ ++ rConstitutiveVariables.StrainVector[2] = ++ rKinematicVariables.b_v - ++ rKinematicVariables.B_v; ++ ++ rConstitutiveVariables.StrainVector[3] = ++ rKinematicVariables.c_12 - ++ rKinematicVariables.C_12; ++ ++ rConstitutiveVariables.StrainVector[4] = ++ rKinematicVariables.c_13 - ++ rKinematicVariables.C_13; ++ ++ rConstitutiveLawParameters.SetStrainVector( ++ rConstitutiveVariables.StrainVector); ++ ++ rConstitutiveLawParameters.SetStressVector( ++ rConstitutiveVariables.StressVector); ++ ++ rConstitutiveLawParameters.SetConstitutiveMatrix( ++ rConstitutiveVariables.ConstitutiveMatrix); ++ ++ mConstitutiveLawVector[IntegrationPointIndex] ++ ->CalculateMaterialResponse( ++ rConstitutiveLawParameters, ++ StressMeasure); ++ ++ noalias(rConstitutiveVariables.StressVector) = ++ prod( ++ trans(rConstitutiveVariables.ConstitutiveMatrix), ++ rConstitutiveVariables.StrainVector); ++ }  ++ ++ ++ void NonLinearBernoulliBeamElement3D::ComputeReferenceTwistAngleAndDerivative( ++ const KinematicVariables& rKinematicVariables, ++ double& rPhi, ++ double& rPhiDerivative) ++ { ++ ++ const auto& r_geometry = GetGeometry(); ++ const double integration_point_coordinate = r_geometry.IntegrationPoints()[0].Coordinates()[0]; ++ ++ double lower_twist_angle; ++ double upper_twist_angle; ++ double twist_angle_difference; ++ double lower_parameter_coordinate; ++ double upper_parameter_coordinate; ++ int number_of_orientation_points; ++ ++ Matrix local_axis_orientation = GetProperties()[LOCAL_AXIS_ORIENTATION]; ++ number_of_orientation_points = local_axis_orientation.size1(); ++ ++ lower_parameter_coordinate = local_axis_orientation(0, 0); ++ upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - 1, 0); ++  ++ // Extract normal vector components for start and end ++ Vector3d lower_normal; ++ lower_normal[0] = local_axis_orientation(0, 1); ++ lower_normal[1] = local_axis_orientation(0, 2); ++ lower_normal[2] = local_axis_orientation(0, 3); ++  ++ Vector3d upper_normal; ++ upper_normal[0] = local_axis_orientation(number_of_orientation_points - 1, 1); ++ upper_normal[1] = local_axis_orientation(number_of_orientation_points - 1, 2); ++ upper_normal[2] = local_axis_orientation(number_of_orientation_points - 1, 3); ++  ++ // Convert normal vectors to rotation angles (phi) for backward compatibility ++ lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, lower_normal); ++ upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, upper_normal); ++ ++ for (int i = 1; i < number_of_orientation_points; i++) ++ { ++ if (local_axis_orientation(i, 0) > integration_point_coordinate) ++ { ++ lower_parameter_coordinate = local_axis_orientation(i - 1, 0); ++ Vector3d interpolated_normal(3); ++ interpolated_normal[0] = local_axis_orientation(i - 1, 1); ++ interpolated_normal[1] = local_axis_orientation(i - 1, 2); ++ interpolated_normal[2] = local_axis_orientation(i - 1, 3); ++ lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); ++ break; ++ } ++ } ++ ++ for (int i = 1; i < number_of_orientation_points; i++) ++ { ++ if (local_axis_orientation(number_of_orientation_points - i - 1, 0) <= integration_point_coordinate) ++ { ++ upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - i, 0); ++ Vector3d interpolated_normal(3); ++ interpolated_normal[0] = local_axis_orientation(number_of_orientation_points - i, 1); ++ interpolated_normal[1] = local_axis_orientation(number_of_orientation_points - i, 2); ++ interpolated_normal[2] = local_axis_orientation(number_of_orientation_points - i, 3); ++ upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); ++ break; ++ } ++ } ++ const double pi = 4.0 * std::atan(1.0); ++ ++ twist_angle_difference = (upper_twist_angle - lower_twist_angle); ++ if (std::abs(upper_twist_angle - lower_twist_angle) > pi) ++ { ++ twist_angle_difference = twist_angle_difference - (twist_angle_difference) / std::abs(twist_angle_difference) * 2 * pi; ++ } ++ ++ rPhi += lower_twist_angle + (integration_point_coordinate - lower_parameter_coordinate) / (upper_parameter_coordinate - lower_parameter_coordinate) * twist_angle_difference; ++ rPhiDerivative += twist_angle_difference / (upper_parameter_coordinate - lower_parameter_coordinate); ++ } ++ ++ double NonLinearBernoulliBeamElement3D::CalculateDeltaPhi( ++ const KinematicVariables& rKinematicVariables, ++ const Vector3d& rNormal) ++ { ++ const Vector3d initial_tangent = GetProperties()[T_0]; ++ const Vector3d reference_base_vector = rKinematicVariables.R1; ++ ++ const Vector3d current_reference_tangent = ++ reference_base_vector / norm_2(reference_base_vector); ++ ++ const Vector3d normalized_initial_tangent = ++ initial_tangent / norm_2(initial_tangent); ++ ++ Vector3d normal = rNormal; ++ ++ const double tangent_normal_projection = ++ inner_prod(current_reference_tangent, normal); ++ ++ // Project the normal onto the plane normal to the reference tangent. ++ normal -= tangent_normal_projection * current_reference_tangent; ++ normal /= norm_2(normal); ++ ++ const Vector3d reference_principal_axis = normal; ++ ++ Matrix3d lambda_matrix; ++ ComputeLambdaMatrix( ++ normalized_initial_tangent, ++ current_reference_tangent, ++ lambda_matrix); ++ ++ const Vector3d rotated_reference_axis = ++ prod(lambda_matrix, reference_principal_axis); ++ ++ const Vector3d orientation_reference = ++ MathUtils::CrossProduct(reference_base_vector, rotated_reference_axis); ++ ++ const double axis_dot_product = ++ inner_prod(rotated_reference_axis, normal); ++ ++ const double orientation_dot_product = ++ inner_prod(normal, orientation_reference); ++ ++ double cos_theta = ++ axis_dot_product / ++ (norm_2(rotated_reference_axis) * norm_2(normal)); ++ ++ if (std::abs(1.0 - std::abs(cos_theta)) < 1e-9) { ++ cos_theta = MathUtils::Sign(cos_theta); ++ } ++ ++ double phi = std::acos(cos_theta); ++ ++ const double pi = 4.0 * std::atan(1.0); ++ ++ if (orientation_dot_product < -1e-12) { ++ phi = 2.0 * pi - phi; ++ } ++ ++ return phi; ++ } ++  ++ ++ void NonLinearBernoulliBeamElement3D::ComputeReferenceCrossSectionGeometry( ++ KinematicVariables& rKinematicVariables) ++ { ++ const Vector3d reference_first_base_vector = rKinematicVariables.R1; ++ const Vector3d reference_second_base_vector = rKinematicVariables.R2; ++ const Vector3d initial_reference_tangent = GetProperties()[T_0]; ++ ++ ComputeReferenceTwistAngleAndDerivative( ++ rKinematicVariables, ++ rKinematicVariables.Phi, ++ rKinematicVariables.Phi_der); ++ ++ Matrix3d reference_lambda_matrix; ++ Matrix3d reference_lambda_matrix_derivative; ++ Matrix3d reference_rodrigues_matrix; ++ Matrix3d reference_rodrigues_matrix_derivative; ++ Matrix3d cross_section_transformation_derivative; ++ cross_section_transformation_derivative.clear(); ++ ++ const double reference_first_base_vector_norm = ++ norm_2(reference_first_base_vector); ++ ++ const Vector3d reference_tangent = ++ reference_first_base_vector / reference_first_base_vector_norm; ++ ++ const Vector3d reference_tangent_derivative = ++ reference_second_base_vector / reference_first_base_vector_norm ++ - inner_prod(reference_first_base_vector, reference_second_base_vector) ++ / pow(reference_first_base_vector_norm, 3) ++ * reference_first_base_vector; ++ ++ Vector3d initial_reference_tangent_derivative; ++ initial_reference_tangent_derivative.clear(); ++ ++ ComputeLambdaMatrix( ++ initial_reference_tangent, ++ reference_tangent, ++ reference_lambda_matrix); ++ ++ ComputeLambdaMatrixDerivative( ++ initial_reference_tangent, ++ reference_tangent, ++ initial_reference_tangent_derivative, ++ reference_tangent_derivative, ++ reference_lambda_matrix_derivative); ++ ++ ComputeRodriguesMatrix( ++ reference_tangent, ++ rKinematicVariables.Phi, ++ reference_rodrigues_matrix); ++ ++ ComputeRodriguesMatrixDerivative( ++ reference_tangent, ++ reference_tangent_derivative, ++ rKinematicVariables.Phi, ++ rKinematicVariables.Phi_der, ++ reference_rodrigues_matrix_derivative); ++ ++ rKinematicVariables.n.clear(); ++ rKinematicVariables.N0 = GetProperties()[N_0]; ++ ++ const double initial_reference_tangent_norm = ++ norm_2(initial_reference_tangent); ++ ++ const Vector3d normalized_initial_reference_tangent = ++ initial_reference_tangent / initial_reference_tangent_norm; ++ ++ rKinematicVariables.N0 -= ++ inner_prod( ++ normalized_initial_reference_tangent, ++ rKinematicVariables.N0) ++ * normalized_initial_reference_tangent; ++ ++ rKinematicVariables.V0 = ++ MathUtils::CrossProduct( ++ normalized_initial_reference_tangent, ++ rKinematicVariables.N0); ++ ++ rKinematicVariables.N0 /= ++ norm_2(rKinematicVariables.N0); ++ ++ rKinematicVariables.V0 /= ++ norm_2(rKinematicVariables.V0); ++ ++ Vector3d transformed_reference_normal; ++ transformed_reference_normal.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ transformed_reference_normal[i] += ++ reference_lambda_matrix(i, j) ++ * rKinematicVariables.N0[j]; ++ } ++ } ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ rKinematicVariables.n(i) += ++ reference_rodrigues_matrix(i, j) ++ * transformed_reference_normal[j]; ++ } ++ } ++ ++ rKinematicVariables.n /= ++ norm_2(rKinematicVariables.n); ++ ++ rKinematicVariables.v = ++ MathUtils::CrossProduct(reference_tangent, rKinematicVariables.n); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ for (IndexType k = 0; k < 3; ++k) { ++ cross_section_transformation_derivative(i, j) += ++ reference_rodrigues_matrix_derivative(i, k) ++ * reference_lambda_matrix(k, j); ++ ++ cross_section_transformation_derivative(i, j) += ++ reference_rodrigues_matrix(i, k) ++ * reference_lambda_matrix_derivative(k, j); ++ } ++ } ++ } ++ ++ Vector3d a21_vector; ++ Vector3d a31_vector; ++ a21_vector.clear(); ++ a31_vector.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ a21_vector[i] += ++ cross_section_transformation_derivative(i, j) ++ * rKinematicVariables.N0[j]; ++ ++ a31_vector[i] += ++ cross_section_transformation_derivative(i, j) ++ * rKinematicVariables.V0[j]; ++ } ++ } ++ ++ rKinematicVariables.B_n = ++ inner_prod(a21_vector, reference_first_base_vector); ++ ++ rKinematicVariables.B_v = ++ inner_prod(a31_vector, reference_first_base_vector); ++ ++ rKinematicVariables.C_12 = ++ inner_prod(a31_vector, rKinematicVariables.n); ++ ++ rKinematicVariables.C_13 = ++ inner_prod(a21_vector, rKinematicVariables.v); ++ } ++ ++ void NonLinearBernoulliBeamElement3D::ComputeCurrentCrossSectionGeometry( ++ KinematicVariables& rKinematicVariables) ++ { ++ const Vector3d current_first_base_vector = rKinematicVariables.r1; ++ const Vector3d current_second_base_vector = rKinematicVariables.r2; ++ const Vector3d reference_first_base_vector = rKinematicVariables.R1; ++ const Vector3d reference_second_base_vector = rKinematicVariables.R2; ++ const Vector3d initial_reference_tangent = GetProperties()[T_0]; ++ ++ rKinematicVariables.n.clear(); ++ rKinematicVariables.v.clear(); ++ ++ Matrix3d current_lambda_matrix; ++ Matrix3d current_lambda_matrix_derivative; ++ Matrix3d reference_lambda_matrix; ++ Matrix3d reference_lambda_matrix_derivative; ++ Matrix3d current_rodrigues_matrix; ++ Matrix3d current_rodrigues_matrix_derivative; ++ Matrix3d reference_rodrigues_matrix; ++ Matrix3d reference_rodrigues_matrix_derivative; ++ ++ const double current_first_base_vector_norm = ++ norm_2(current_first_base_vector); ++ ++ const double reference_first_base_vector_norm = ++ norm_2(reference_first_base_vector); ++ ++ const Vector3d current_tangent = ++ current_first_base_vector / current_first_base_vector_norm; ++ ++ const Vector3d current_tangent_derivative = ++ current_second_base_vector / current_first_base_vector_norm ++ - inner_prod(current_first_base_vector, current_second_base_vector) ++ / pow(current_first_base_vector_norm, 3) ++ * current_first_base_vector; ++ ++ const Vector3d reference_tangent = ++ reference_first_base_vector / reference_first_base_vector_norm; ++ ++ const Vector3d reference_tangent_derivative = ++ reference_second_base_vector / reference_first_base_vector_norm ++ - inner_prod(reference_first_base_vector, reference_second_base_vector) ++ / pow(reference_first_base_vector_norm, 3) ++ * reference_first_base_vector; ++ ++ Vector3d initial_reference_tangent_derivative; ++ initial_reference_tangent_derivative.clear(); ++ ++ ComputeLambdaMatrix( ++ reference_tangent, ++ current_tangent, ++ current_lambda_matrix); ++ ++ ComputeLambdaMatrixDerivative( ++ reference_tangent, ++ current_tangent, ++ reference_tangent_derivative, ++ current_tangent_derivative, ++ current_lambda_matrix_derivative); ++ ++ ComputeLambdaMatrix( ++ initial_reference_tangent, ++ reference_tangent, ++ reference_lambda_matrix); ++ ++ ComputeLambdaMatrixDerivative( ++ initial_reference_tangent, ++ reference_tangent, ++ initial_reference_tangent_derivative, ++ reference_tangent_derivative, ++ reference_lambda_matrix_derivative); ++ ++ ComputeRodriguesMatrix( ++ current_tangent, ++ rKinematicVariables.phi, ++ current_rodrigues_matrix); ++ ++ ComputeRodriguesMatrixDerivative( ++ current_tangent, ++ current_tangent_derivative, ++ rKinematicVariables.phi, ++ rKinematicVariables.phi_der, ++ current_rodrigues_matrix_derivative); ++ ++ ComputeRodriguesMatrix( ++ reference_tangent, ++ rKinematicVariables.Phi, ++ reference_rodrigues_matrix); ++ ++ ComputeRodriguesMatrixDerivative( ++ reference_tangent, ++ reference_tangent_derivative, ++ rKinematicVariables.Phi, ++ rKinematicVariables.Phi_der, ++ reference_rodrigues_matrix_derivative); ++ ++ Matrix3d reference_rodrigues_lambda_product; ++ Matrix3d reference_rodrigues_lambda_derivative_product; ++ Matrix3d reference_rodrigues_derivative_lambda_product; ++ reference_rodrigues_lambda_product.clear(); ++ reference_rodrigues_lambda_derivative_product.clear(); ++ reference_rodrigues_derivative_lambda_product.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ for (IndexType k = 0; k < 3; ++k) { ++ reference_rodrigues_lambda_product(i, j) += ++ reference_rodrigues_matrix(i, k) ++ * reference_lambda_matrix(k, j); ++ ++ reference_rodrigues_lambda_derivative_product(i, j) += ++ reference_rodrigues_matrix(i, k) ++ * reference_lambda_matrix_derivative(k, j); ++ ++ reference_rodrigues_derivative_lambda_product(i, j) += ++ reference_rodrigues_matrix_derivative(i, k) ++ * reference_lambda_matrix(k, j); ++ } ++ } ++ } ++ ++ Matrix3d current_lambda_reference_rodrigues_lambda_product; ++ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; ++ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; ++ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; ++ current_lambda_reference_rodrigues_lambda_product.clear(); ++ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); ++ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); ++ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ for (IndexType k = 0; k < 3; ++k) { ++ current_lambda_reference_rodrigues_lambda_product(i, j) += ++ current_lambda_matrix(i, k) ++ * reference_rodrigues_lambda_product(k, j); ++ ++ current_lambda_reference_rodrigues_lambda_derivative_product(i, j) += ++ current_lambda_matrix(i, k) ++ * reference_rodrigues_lambda_derivative_product(k, j); ++ ++ current_lambda_reference_rodrigues_derivative_lambda_product(i, j) += ++ current_lambda_matrix(i, k) ++ * reference_rodrigues_derivative_lambda_product(k, j); ++ ++ current_lambda_derivative_reference_rodrigues_lambda_product(i, j) += ++ current_lambda_matrix_derivative(i, k) ++ * reference_rodrigues_lambda_product(k, j); ++ } ++ } ++ } ++ ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; ++ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; ++ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ Matrix3d cross_section_transformation; ++ ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); ++ cross_section_transformation.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ for (IndexType k = 0; k < 3; ++k) { ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(i, j) += ++ current_rodrigues_matrix(i, k) ++ * current_lambda_reference_rodrigues_lambda_derivative_product(k, j); ++ ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(i, j) += ++ current_rodrigues_matrix(i, k) ++ * current_lambda_reference_rodrigues_derivative_lambda_product(k, j); ++ ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(i, j) += ++ current_rodrigues_matrix(i, k) ++ * current_lambda_derivative_reference_rodrigues_lambda_product(k, j); ++ ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(i, j) += ++ current_rodrigues_matrix_derivative(i, k) ++ * current_lambda_reference_rodrigues_lambda_product(k, j); ++ ++ cross_section_transformation(i, j) += ++ current_rodrigues_matrix(i, k) ++ * current_lambda_reference_rodrigues_lambda_product(k, j); ++ } ++ } ++ } ++ ++ const Matrix3d cross_section_transformation_derivative = ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term ++ + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term ++ + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term ++ + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ ++ Vector3d a21_vector; ++ Vector3d a31_vector; ++ a21_vector.clear(); ++ a31_vector.clear(); ++ ++ for (IndexType i = 0; i < 3; ++i) { ++ for (IndexType j = 0; j < 3; ++j) { ++ a21_vector[i] += ++ cross_section_transformation_derivative(i, j) ++ * rKinematicVariables.N0[j]; ++ ++ a31_vector[i] += ++ cross_section_transformation_derivative(i, j) ++ * rKinematicVariables.V0[j]; ++ ++ rKinematicVariables.n[i] += ++ cross_section_transformation(i, j) ++ * rKinematicVariables.N0[j]; ++ ++ rKinematicVariables.v[i] += ++ cross_section_transformation(i, j) ++ * rKinematicVariables.V0[j]; ++ } ++ } ++ ++ rKinematicVariables.b_n = ++ inner_prod(a21_vector, current_first_base_vector); ++ ++ rKinematicVariables.b_v = ++ inner_prod(a31_vector, current_first_base_vector); ++ ++ rKinematicVariables.c_12 = ++ inner_prod(a31_vector, rKinematicVariables.n); ++ ++ rKinematicVariables.c_13 = ++ inner_prod(a21_vector, rKinematicVariables.v); ++ } ++ ++ ++ void NonLinearBernoulliBeamElement3D::ComputeBMatrices( ++ const IndexType IntegrationPointIndex, ++ const KinematicVariables& rKinematicVariables, ++ Matrix& rBAxial, ++ Matrix& rBBending1, ++ Matrix& rBBending2, ++ Matrix& rBTorsion1, ++ Matrix& rBTorsion2) ++ { ++ KRATOS_TRY ++ const auto& r_geometry = GetGeometry(); ++ ++ // Get shape functions and derivatives at integration point ++ Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); ++ Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); ++ Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); ++  ++ // Extract kinematic variables ++ Vector3d current_first_base_vector = rKinematicVariables.r1; ++ Vector3d current_second_base_vector = rKinematicVariables.r2; ++ Vector3d reference_first_base_vector = rKinematicVariables.R1; ++ Vector3d reference_second_base_vector = rKinematicVariables.R2; ++ Vector3d reference_normal = rKinematicVariables.N0; ++ Vector3d reference_binormal = rKinematicVariables.V0; ++ double current_twist_angle = rKinematicVariables.phi; ++ double current_twist_angle_derivative = rKinematicVariables.phi_der; ++ double reference_twist_angle = rKinematicVariables.Phi; ++ double reference_twist_angle_derivative = rKinematicVariables.Phi_der; ++ Vector3d initial_reference_tangent = GetProperties()[T_0]; ++ ++ // Compute curvature and torsion variations ++ Vector axial_variation(mNumberOfDofs); ++ Vector normal_curvature_variation(mNumberOfDofs); ++ Vector binormal_curvature_variation(mNumberOfDofs); ++ Vector normal_torsion_variation(mNumberOfDofs); ++ Vector binormal_torsion_variation(mNumberOfDofs); ++ axial_variation.clear(); ++ normal_curvature_variation.clear(); ++ binormal_curvature_variation.clear(); ++ normal_torsion_variation.clear(); ++ binormal_torsion_variation.clear(); ++ ++ //compute axial_variation ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ size_t dof_component = dof_index % mDofsPerNode;  ++ size_t control_point_index = dof_index / mDofsPerNode;  ++ if (dof_component > 2) ++ axial_variation[dof_index] = 0; ++ else ++ axial_variation[dof_index] = rKinematicVariables.r1[dof_component] * shape_function_derivatives[control_point_index]; ++ } ++ //compute normal_curvature_variation, binormal_curvature_variation, normal_torsion_variation, binormal_torsion_variation ++ Vector3d current_tangent; ++ current_tangent.clear(); ++ Vector3d current_tangent_derivative; ++ current_tangent_derivative.clear(); ++ Vector3d reference_tangent; ++ reference_tangent.clear(); ++ Vector3d reference_tangent_derivative; ++ reference_tangent_derivative.clear(); ++ Vector3d initial_reference_tangent_derivative; ++ initial_reference_tangent_derivative.clear(); ++ Vector current_tangent_variation; ++ Vector current_tangent_derivative_variation; ++ Matrix3d current_lambda_matrix; ++ Matrix3d current_lambda_matrix_derivative; ++ Matrix3d reference_lambda_matrix; ++ Matrix3d reference_lambda_matrix_derivative; ++ Matrix3d current_rodrigues_matrix; ++ Matrix3d current_rodrigues_matrix_derivative; ++ Matrix3d reference_rodrigues_matrix; ++ Matrix3d reference_rodrigues_matrix_derivative; ++ ++ current_tangent = current_first_base_vector / norm_2(current_first_base_vector); ++ current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; ++ reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); ++ reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; ++ ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); ++ ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); ++ ++ ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); ++ ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); ++ ComputeLambdaMatrixVariation(reference_tangent, current_tangent, current_tangent_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation); ++ ComputeLambdaMatrixDerivativeVariation(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaDerivativeVariation); ++ ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); ++ ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); ++ ++ ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); ++ ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); ++ ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); ++ ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); ++ ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); ++ ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); ++ ++ Matrix3d reference_rodrigues_lambda_derivative_product; ++ reference_rodrigues_lambda_derivative_product.clear(); ++ Matrix3d reference_rodrigues_derivative_lambda_product; ++ reference_rodrigues_derivative_lambda_product.clear(); ++ Matrix3d reference_rodrigues_lambda_product; ++ reference_rodrigues_lambda_product.clear(); ++ Matrix3d reference_rodrigues_lambda_product_derivative; ++ reference_rodrigues_lambda_product_derivative.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int column_component = 0; column_component < 3; column_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); ++ reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); ++ reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); ++ } ++ } ++ } ++ reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; ++ ++ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; ++ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; ++ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_lambda_product; ++ current_lambda_reference_rodrigues_lambda_product.clear(); ++ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; ++ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; ++ current_lambda_reference_rodrigues_lambda_product_derivative.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int column_component = 0; column_component < 3; column_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ ++ current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; ++ ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); ++ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); ++ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); ++ Matrix3d cross_section_transformation; ++ cross_section_transformation.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int column_component = 0; column_component < 3; column_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ ++ Matrix3d cross_section_transformation_derivative; ++ cross_section_transformation_derivative.clear(); ++ cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ ++ mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); ++ mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); ++ mSMatrixLambdaVariationRodriguesLambda.clear(); ++ mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int column_component = 0; column_component < 3; column_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) ++ { ++ mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ ++ Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); ++ ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; ++ ++ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); ++ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); ++ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); ++ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); ++ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int column_component = 0; column_component < 3; column_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) ++ { ++ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ ++ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); ++ mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); ++ ++ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda ++ + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; ++ mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; ++ ++ Vector3d normal_vector; ++ normal_vector.clear(); ++ Vector3d binormal_vector; ++ binormal_vector.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); ++ binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); ++ } ++ } ++ ++ Vector normal_vector_variation; ++ normal_vector_variation.resize(3 * mNumberOfDofs); ++ normal_vector_variation.clear(); ++ Vector binormal_vector_variation; ++ binormal_vector_variation.resize(3 * mNumberOfDofs); ++ binormal_vector_variation.clear(); ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); ++ binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); ++ } ++ } ++ } ++ ++ Vector current_first_base_vector_variation; ++ current_first_base_vector_variation.resize(3 * mNumberOfDofs); ++ current_first_base_vector_variation.clear(); ++ for (size_t row_component = 0; row_component < 3; row_component++)  ++ { ++ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++)  ++ { ++ size_t dof_component = dof_index % mDofsPerNode; ++ size_t control_point_index = dof_index / mDofsPerNode; ++ if (row_component == dof_component) ++ current_first_base_vector_variation(row_component * mNumberOfDofs + dof_index) = shape_function_derivatives[control_point_index]; ++ } ++ } ++ ++ for (size_t row_component = 0; row_component < 3; row_component++) ++ { ++ for (int product_index = 0; product_index < 3; product_index++) ++ { ++ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) ++ { ++ normal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; ++ binormal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; ++ normal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index); ++ binormal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index); ++ } ++ } ++ } ++ ++  ++ // Initialize B matrices ++ rBAxial.resize(5, mNumberOfDofs); ++ rBBending1.resize(5, mNumberOfDofs); ++ rBBending2.resize(5, mNumberOfDofs); ++ rBTorsion1.resize(5, mNumberOfDofs); ++ rBTorsion2.resize(5, mNumberOfDofs); ++ rBAxial.clear(); ++ rBBending1.clear(); ++ rBBending2.clear(); ++ rBTorsion1.clear(); ++ rBTorsion2.clear(); ++ ++ noalias(row(rBAxial, 0)) = axial_variation; //Normal force ++ noalias(row(rBBending1, 1)) = normal_curvature_variation; // Bending about n-axis ++ noalias(row(rBBending2, 2)) = binormal_curvature_variation; // Bending about v-axis ++ noalias(row(rBTorsion1, 3)) = normal_torsion_variation; // Torsion n in row 1 (shear stress) ++ noalias(row(rBTorsion2, 4)) = binormal_torsion_variation; // Torsion v in row 2 (shear stress) ++  ++ KRATOS_CATCH("") ++ } ++ ++ ++ void NonLinearBernoulliBeamElement3D::ComputeGMatrices( ++ const IndexType IntegrationPointIndex, ++ const KinematicVariables& rKinematicVariables, ++ Matrix& rGAxial, ++ Matrix& rGBending1, ++ Matrix& rGBending2, ++ Matrix& rGTorsion1, ++ Matrix& rGTorsion2) ++ { ++ KRATOS_TRY ++ ++ const auto& r_geometry = GetGeometry(); ++ ++ // Get shape functions and derivatives at integration point ++ Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); ++ Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); ++ Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); ++  ++ // Extract kinematic variables ++ Vector3d current_first_base_vector = rKinematicVariables.r1; ++ Vector3d current_second_base_vector = rKinematicVariables.r2; ++ Vector3d reference_first_base_vector = rKinematicVariables.R1; ++ Vector3d reference_second_base_vector = rKinematicVariables.R2; ++ Vector3d reference_normal = rKinematicVariables.N0; ++ Vector3d reference_binormal = rKinematicVariables.V0; ++ double current_twist_angle = rKinematicVariables.phi; ++ double current_twist_angle_derivative = rKinematicVariables.phi_der; ++ double reference_twist_angle = rKinematicVariables.Phi; ++ double reference_twist_angle_derivative = rKinematicVariables.Phi_der; ++ Vector3d initial_reference_tangent = GetProperties()[T_0]; ++ ++ // Compute curvature and torsion variations ++ Matrix axial_second_variation(mNumberOfDofs, mNumberOfDofs); ++ Matrix normal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); ++ Matrix binormal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); ++ Matrix normal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); ++ Matrix binormal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); ++ axial_second_variation.clear(); ++ normal_curvature_second_variation.clear(); ++ binormal_curvature_second_variation.clear(); ++ normal_torsion_second_variation.clear(); ++ binormal_torsion_second_variation.clear(); ++ ++ //compute axial_variation ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++)  ++ { ++ size_t dof_component = dof_index % mDofsPerNode;  ++ size_t control_point_index = dof_index / mDofsPerNode;  ++ if (dof_component > 2) ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ axial_second_variation(dof_index, second_dof_index) = 0.0; ++ else ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ size_t second_dof_component = second_dof_index % mDofsPerNode;  ++ int second_control_point_index = second_dof_index / mDofsPerNode;  ++ if (second_dof_component > 2) ++ axial_second_variation(dof_index, second_dof_index) = 0; ++ else ++ if (dof_component == second_dof_component) ++ axial_second_variation(dof_index, second_dof_index) = shape_function_derivatives[control_point_index] * shape_function_derivatives[second_control_point_index]; ++ else ++ axial_second_variation(dof_index, second_dof_index) = 0; ++ } ++ } ++ } ++  ++ //compute normal_curvature_second_variation, binormal_curvature_second_variation, normal_torsion_second_variation, binormal_torsion_second_variation ++ Vector3d current_tangent; ++ current_tangent.clear(); ++ Vector3d current_tangent_derivative; ++ current_tangent_derivative.clear(); ++ Vector3d reference_tangent; ++ reference_tangent.clear(); ++ Vector3d reference_tangent_derivative; ++ reference_tangent_derivative.clear(); ++ Vector3d initial_reference_tangent_derivative; ++ initial_reference_tangent_derivative.clear(); ++ Vector current_tangent_variation; ++ Vector current_tangent_derivative_variation; ++ Matrix current_tangent_second_variation; ++ Matrix current_tangent_derivative_second_variation; ++ Matrix3d current_lambda_matrix; ++ Matrix3d current_lambda_matrix_derivative; ++ Matrix3d reference_lambda_matrix; ++ Matrix3d reference_lambda_matrix_derivative; ++ Matrix3d current_rodrigues_matrix; ++ Matrix3d current_rodrigues_matrix_derivative; ++ Matrix3d reference_rodrigues_matrix; ++ Matrix3d reference_rodrigues_matrix_derivative; ++ ++ current_tangent = current_first_base_vector / norm_2(current_first_base_vector); ++ current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; ++ reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); ++ reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; ++ ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); ++ ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); ++ ComputeTangentSecondVariation(shape_function_derivatives, current_first_base_vector, current_tangent_second_variation); ++ ComputeTangentDerivativeSecondVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_second_variation); ++ ++ ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); ++ ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); ++ ++ ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); ++ ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); ++ ComputeLambdaMatrixVariations(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation, mSMatrixLambdaDerivativeVariation, mSMatrixLambdaSecondVariation, mSMatrixLambdaDerivativeSecondVariation); ++ ++ ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); ++ ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); ++ ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); ++ ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); ++ ComputeRodriguesMatrixSecondVariation(current_tangent, current_tangent_variation, current_tangent_second_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesSecondVariation); ++ ComputeRodriguesMatrixDerivativeSecondVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeSecondVariation); ++ ++ ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); ++ ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); ++ ++ Matrix3d reference_rodrigues_lambda_derivative_product; ++ reference_rodrigues_lambda_derivative_product.clear(); ++ Matrix3d reference_rodrigues_derivative_lambda_product; ++ reference_rodrigues_derivative_lambda_product.clear(); ++ Matrix3d reference_rodrigues_lambda_product; ++ reference_rodrigues_lambda_product.clear(); ++ Matrix3d reference_rodrigues_lambda_product_derivative; ++ reference_rodrigues_lambda_product_derivative.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); ++ reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); ++ reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); ++ } ++ } ++ } ++ reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; ++ ++ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; ++ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; ++ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_lambda_product; ++ current_lambda_reference_rodrigues_lambda_product.clear(); ++ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; ++ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); ++ Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; ++ current_lambda_reference_rodrigues_lambda_product_derivative.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ ++ current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; ++ ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); ++ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); ++ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); ++ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); ++ Matrix3d cross_section_transformation; ++ cross_section_transformation.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); ++ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ ++ Matrix3d cross_section_transformation_derivative; ++ cross_section_transformation_derivative.clear(); ++ cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; ++ ++  ++ mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); ++ mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); ++ mSMatrixLambdaVariationRodriguesLambda.clear(); ++ mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ ++ Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); ++ ++ current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; ++ ++ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); ++ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); ++ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); ++ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); ++ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); ++ mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); ++ mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); ++ mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ ++  ++  ++ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); ++ mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); ++ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda ++ + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; ++ mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; ++ ++ mSMatrixLambdaSecondVariationRodriguesLambda.clear(); ++ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.clear(); ++ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.clear(); ++ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ mSMatrixLambdaSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); ++ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ } ++ ++ Matrix current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term; ++ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.clear(); ++ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term; ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.clear(); ++ ++ Matrix current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term; ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.clear(); ++ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term; ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.clear(); ++ ++ Matrix current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term; ++ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term; ++ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term; ++ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.clear(); ++ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term; ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.clear(); ++ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term; ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); ++ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term; ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); ++ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + second_dof_index, column_component); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + second_dof_index, column_component); ++ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); ++ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); ++ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); ++ } ++ } ++ } ++ } ++ } ++ ++ Matrix cross_section_transformation_derivative_second_variation; ++ cross_section_transformation_derivative_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ cross_section_transformation_derivative_second_variation.clear(); ++ ++ Vector3d normal_vector; ++ normal_vector.clear(); ++ Vector3d binormal_vector; ++ binormal_vector.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); ++ binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); ++ } ++ } ++ ++ Vector normal_vector_variation; ++ normal_vector_variation.resize(3 * mNumberOfDofs); ++ normal_vector_variation.clear(); ++ Vector binormal_vector_variation; ++ binormal_vector_variation.resize(3 * mNumberOfDofs); ++ binormal_vector_variation.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (int product_index = 0;product_index < 3;product_index++) ++ { ++ normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); ++ binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); ++ } ++ } ++ } ++ ++ Matrix cross_section_transformation_second_variation; ++ cross_section_transformation_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); ++ cross_section_transformation_second_variation.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (int column_component = 0;column_component < 3;column_component++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) ++ + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) ++ + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) ++ + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); ++ } ++ } ++ } ++ } ++ ++ Matrix normal_vector_second_variation; ++ normal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); ++ normal_vector_second_variation.clear(); ++ Matrix binormal_vector_second_variation; ++ binormal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); ++ binormal_vector_second_variation.clear(); ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ for (size_t product_index = 0;product_index < 3;product_index++) ++ { ++ normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index); ++ binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index); ++ } ++ } ++ } ++ } ++ ++ for (size_t row_component = 0;row_component < 3;row_component++) ++ { ++ for (size_t product_index = 0;product_index < 3;product_index++) ++ { ++ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) ++ { ++ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) ++ { ++ normal_curvature_second_variation(dof_index, second_dof_index) += 0; ++ normal_curvature_second_variation(dof_index, second_dof_index) += 0; ++ ++ normal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * normal_vector(row_component) ++ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) ++ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index) ++ + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); ++ ++ binormal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * binormal_vector(row_component) ++ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + second_dof_index) ++ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index) ++ + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); ++ } ++ } ++ } ++ } ++ ++ // Initialize G matrices ++ rGAxial.resize(mNumberOfDofs, mNumberOfDofs); ++ rGBending1.resize(mNumberOfDofs, mNumberOfDofs); ++ rGBending2.resize(mNumberOfDofs, mNumberOfDofs); ++ rGTorsion1.resize(mNumberOfDofs, mNumberOfDofs); ++ rGTorsion2.resize(mNumberOfDofs, mNumberOfDofs); ++ rGAxial.clear(); ++ rGBending1.clear(); ++ rGBending2.clear(); ++ rGTorsion1.clear(); ++ rGTorsion2.clear(); ++ ++ noalias(rGAxial) = axial_second_variation; ++ noalias(rGBending1) = normal_curvature_second_variation; ++ noalias(rGBending2) = binormal_curvature_second_variation;  ++ noalias(rGTorsion1) = normal_torsion_second_variation;  ++ noalias(rGTorsion1) = binormal_torsion_second_variation;  ++  ++ KRATOS_CATCH("") ++  ++ } ++} +\ No newline at end of file diff --git a/kratos/geometries/nurbs_curve_geometry.h b/kratos/geometries/nurbs_curve_geometry.h index d681ea997ee4..fd06eab8f88f 100644 --- a/kratos/geometries/nurbs_curve_geometry.h +++ b/kratos/geometries/nurbs_curve_geometry.h @@ -751,6 +751,112 @@ class NurbsCurveGeometry : public Geometry& rControlPointIndices, + Vector& rShapeFunctionsValues, + const IndexType DerivativeOrder = 0, + DenseVector* pShapeFunctionDerivatives = nullptr + ) const + { + const double u = rCoordinates[0]; + + KRATOS_WARNING_IF( + "ShapeFunctionsValuesAndCPIndices", + DerivativeOrder > mPolynomialDegree) + << "Requested derivative order (" << DerivativeOrder + << ") exceeds the polynomial degree (" << mPolynomialDegree + << "). Higher derivatives may be zero or undefined." + << std::endl; + + NurbsCurveShapeFunction shape_function_container( + mPolynomialDegree, + DerivativeOrder + 1); + + if (IsRational()) { + shape_function_container.ComputeNurbsShapeFunctionValues( + mKnots, + mWeights, + u); + } else { + shape_function_container.ComputeBSplineShapeFunctionValues( + mKnots, + u); + } + + const SizeType number_of_nonzero_control_points = + shape_function_container.NumberOfNonzeroControlPoints(); + + const auto control_point_indices = + shape_function_container.GetNonzeroControlPointIndices(); + + rControlPointIndices.resize(control_point_indices.size()); + + for (IndexType i = 0; i < control_point_indices.size(); ++i) { + rControlPointIndices[i] = + this->pGetPoint(control_point_indices[i])->Id(); + } + + if (rShapeFunctionsValues.size() != + number_of_nonzero_control_points) { + rShapeFunctionsValues.resize( + number_of_nonzero_control_points, + false); + } + + for (IndexType i = 0; + i < number_of_nonzero_control_points; + ++i) { + rShapeFunctionsValues[i] = + shape_function_container(i, 0); + } + + if (pShapeFunctionDerivatives == nullptr || + DerivativeOrder == 0) { + return; + } + + pShapeFunctionDerivatives->resize(DerivativeOrder); + + for (IndexType derivative_order = 0; + derivative_order < DerivativeOrder; + ++derivative_order) { + + Matrix& r_derivatives = + (*pShapeFunctionDerivatives)[derivative_order]; + + r_derivatives.resize( + number_of_nonzero_control_points, + 1, + false); + + const IndexType container_derivative_index = + derivative_order + 1; + + for (IndexType i = 0; + i < number_of_nonzero_control_points; + ++i) { + r_derivatives(i, 0) = + shape_function_container( + i, + container_derivative_index); + } + } + } + + void SetInternals( + const PointsArrayType& rThisPoints, + const SizeType PolynomialDegree, + const Vector& rKnots, + const Vector& rWeights) + { + this->Points() = rThisPoints; + mPolynomialDegree = PolynomialDegree; + mKnots = rKnots; + mWeights = rWeights; + } + ///@} private: diff --git a/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.cpp b/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.cpp new file mode 100644 index 000000000000..53986bcdbbf2 --- /dev/null +++ b/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.cpp @@ -0,0 +1,646 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Juan I. Camarotti +// + +#include "nurbs_curve_refinement_utilities.h" + +namespace Kratos { + +void NurbsCurveRefinementUtilities::KnotRefinement( + NurbsCurveGeometryType& rGeometry, + std::vector& rKnotsToInsert, + PointerVector& rPointsRefined, + Vector& rKnotsRefined, + Vector& rWeightsRefined) +{ + const SizeType degree = rGeometry.PolynomialDegree(0); + + const Vector knots_old = CreateFullKnotVector(rGeometry.Knots(), degree); + + SortAndFilter(rKnotsToInsert, knots_old); + + if (rKnotsToInsert.empty()) { + KRATOS_WARNING("::NurbsCurveRefinementUtilities::KnotRefinement") + << "No refinement applied as knot vector is empty." << std::endl; + return; + } + + const SizeType nb_cp_old = rGeometry.size(); + const SizeType nb_knots_old = knots_old.size(); + const SizeType nb_knots_to_insert = rKnotsToInsert.size(); + + KRATOS_ERROR_IF_NOT(nb_knots_old == nb_cp_old + degree + 1) + << "Invalid full knot vector. knots.size() = " << nb_knots_old + << ", points.size() = " << nb_cp_old + << ", degree = " << degree + << ", expected = " << nb_cp_old + degree + 1 + << std::endl; + + Vector weights_old = rGeometry.Weights(); + if (weights_old.size() != nb_cp_old) { + weights_old.resize(nb_cp_old); + std::fill(weights_old.begin(), weights_old.end(), 1.0); + } + + const SizeType n = nb_cp_old - 1; + const SizeType m = nb_knots_old - 1; + const SizeType r = nb_knots_to_insert - 1; + + const SizeType a = NurbsUtilities::GetUpperSpan( + degree, + knots_old, + rKnotsToInsert.front() + ); + + SizeType b = NurbsUtilities::GetUpperSpan( + degree, + knots_old, + rKnotsToInsert.back() + ); + + b += 1; + + const SizeType nb_cp_refined = nb_cp_old + nb_knots_to_insert; + const SizeType nb_knots_refined = nb_knots_old + nb_knots_to_insert; + + rPointsRefined.resize(nb_cp_refined); + rWeightsRefined.resize(nb_cp_refined, false); + rKnotsRefined.resize(nb_knots_refined, false); + + rWeightsRefined = ZeroVector(nb_cp_refined); + rKnotsRefined = ZeroVector(nb_knots_refined); + + for (IndexType i = 0; i <= a - degree; ++i) { + const array_1d cp_coordinates = + rGeometry[i] * weights_old[i]; + + rPointsRefined(i) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[i] = weights_old[i]; + } + + for (IndexType i = b - 1; i <= n; ++i) { + const IndexType refined_index = i + nb_knots_to_insert; + + KRATOS_ERROR_IF(refined_index >= nb_cp_refined) + << "Out-of-bounds refined_index = " << refined_index + << ", nb_cp_refined = " << nb_cp_refined << std::endl; + + const array_1d cp_coordinates = + rGeometry[i] * weights_old[i]; + + rPointsRefined(refined_index) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[refined_index] = weights_old[i]; + } + + for (IndexType i = 0; i <= a; ++i) { + rKnotsRefined[i] = knots_old[i]; + } + + for (IndexType i = b + degree; i <= m; ++i) { + const IndexType refined_index = i + nb_knots_to_insert; + + KRATOS_ERROR_IF(refined_index >= nb_knots_refined) + << "Out-of-bounds refined knot index = " << refined_index + << ", nb_knots_refined = " << nb_knots_refined << std::endl; + + rKnotsRefined[refined_index] = knots_old[i]; + } + + IndexType i = b + degree - 1; + IndexType k = b + degree + r; + + for (int j = static_cast(r); j >= 0; --j) { + while (i > a && rKnotsToInsert[j] <= knots_old[i]) { + const IndexType old_index = i - degree - 1; + const IndexType refined_index = k - degree - 1; + + const array_1d cp_coordinates = + rGeometry[old_index] * weights_old[old_index]; + + rPointsRefined(refined_index) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[refined_index] = weights_old[old_index]; + rKnotsRefined[k] = knots_old[i]; + + --k; + --i; + } + + rPointsRefined(k - degree - 1) = + rPointsRefined(k - degree); + + rWeightsRefined[k - degree - 1] = + rWeightsRefined[k - degree]; + + for (IndexType l = 1; l <= degree; ++l) { + const IndexType index = k - degree + l; + const IndexType old_knot_index = i - degree + l; + + double alpha = + rKnotsRefined[k + l] - rKnotsToInsert[j]; + + if (std::abs(alpha) < 1.0e-7) { + rPointsRefined(index - 1) = + rPointsRefined(index); + + rWeightsRefined[index - 1] = + rWeightsRefined[index]; + } else { + const double denominator = + rKnotsRefined[k + l] - knots_old[old_knot_index]; + + KRATOS_ERROR_IF(std::abs(denominator) < 1.0e-14) + << "Zero denominator in alpha computation." << std::endl; + + alpha /= denominator; + + const array_1d cp_coordinates = + alpha * rPointsRefined[index - 1] + + (1.0 - alpha) * rPointsRefined[index]; + + rPointsRefined(index - 1) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[index - 1] = + alpha * rWeightsRefined[index - 1] + + (1.0 - alpha) * rWeightsRefined[index]; + } + } + + rKnotsRefined[k] = rKnotsToInsert[j]; + + --k; + } + + for (IndexType i_cp = 0; i_cp < nb_cp_refined; ++i_cp) { + rPointsRefined(i_cp)->Coordinates() = + rPointsRefined(i_cp)->Coordinates() + / rWeightsRefined[i_cp]; + } + + rKnotsRefined = CreateReducedKnotVector(rKnotsRefined, degree); +} + +void NurbsCurveRefinementUtilities::DegreeElevation( + NurbsCurveGeometryType& rGeometry, + SizeType rDegreeToElevate, + PointerVector& rPointsRefined, + Vector& rKnotsRefined, + Vector& rWeightsRefined) +{ + const Vector& knots_old = rGeometry.Knots(); + + if (rDegreeToElevate == 0) { + KRATOS_WARNING("::NurbsCurveRefinementUtilities::DegreeElevation") + << "No elevation applied as degree is zero." << std::endl; + return; + } + + const SizeType degree_old = rGeometry.PolynomialDegree(0); + const SizeType degree = degree_old + rDegreeToElevate; + + const SizeType nb_cp_old = rGeometry.size(); + const SizeType nb_knots_old = knots_old.size(); + + Vector weights_old = rGeometry.Weights(); + if (weights_old.size() != nb_cp_old) { + weights_old.resize(nb_cp_old); + std::fill(weights_old.begin(), weights_old.end(), 1.0); + } + + SizeType number_of_non_zero_spans = 0; + for (IndexType i = 0; i < nb_knots_old - 1; ++i) { + if (knots_old[i] != knots_old[i + 1]) { + ++number_of_non_zero_spans; + } + } + + const SizeType nb_knots_refined = + nb_knots_old + rDegreeToElevate * (number_of_non_zero_spans + 1); + + const SizeType nb_cp_refined = + nb_knots_refined - degree + 1; + + rKnotsRefined.resize(nb_knots_refined, false); + rWeightsRefined.resize(nb_cp_refined, false); + rPointsRefined.resize(nb_cp_refined); + + rKnotsRefined = ZeroVector(nb_knots_refined); + rWeightsRefined = ZeroVector(nb_cp_refined); + + Matrix bezier_alphas = ZeroMatrix(degree + 1, degree_old + 1); + + PointerVector bezier_points; + bezier_points.resize(degree_old + 1); + + Vector bezier_points_weights = ZeroVector(degree_old + 1); + + PointerVector elevate_bezier_points; + elevate_bezier_points.resize(degree + 1); + + Vector elevate_bezier_points_weights = ZeroVector(degree + 1); + + PointerVector next_bezier_points; + if (degree_old > 1) { + next_bezier_points.resize(degree_old - 1); + } + + Vector next_bezier_points_weights = + degree_old > 1 ? ZeroVector(degree_old - 1) : ZeroVector(0); + + bezier_alphas(0, 0) = 1.0; + bezier_alphas(degree, degree_old) = 1.0; + + for (IndexType i = 1; i < degree / 2 + 1; ++i) { + const double inv = + 1.0 / NurbsUtilities::GetBinomCoefficient(degree, i); + + const SizeType min_degree = std::min(degree_old, i); + const int index = std::max( + 0, + static_cast(i - rDegreeToElevate) + ); + + for (IndexType j = index; j < min_degree + 1; ++j) { + bezier_alphas(i, j) = + inv + * NurbsUtilities::GetBinomCoefficient(degree_old, j) + * NurbsUtilities::GetBinomCoefficient(rDegreeToElevate, i - j); + + bezier_alphas(degree - i, degree_old - j) = + bezier_alphas(i, j); + } + } + + SizeType a = degree_old - 1; + SizeType b = degree_old; + + int r = -1; + + IndexType knot_index = degree + 1; + IndexType control_point_index = 1; + + double knot_old_a = knots_old[a]; + + for (IndexType i = 0; i < degree; ++i) { + rKnotsRefined[i] = knot_old_a; + } + + { + const array_1d cp_coordinates = + rGeometry[0] * weights_old[0]; + + rPointsRefined(0) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[0] = weights_old[0]; + } + + for (IndexType i = 0; i < degree_old + 1; ++i) { + const array_1d cp_coordinates = + rGeometry[i] * weights_old[i]; + + bezier_points(i) = + Kratos::make_intrusive(0, cp_coordinates); + + bezier_points_weights[i] = weights_old[i]; + } + + while (b < nb_knots_old) { + IndexType i = b; + + while (b < nb_knots_old - 1 && knots_old[b] == knots_old[b + 1]) { + ++b; + } + + if (b + 1 == nb_knots_old) { + ++b; + } + + const IndexType mult = b - i + 1; + const double knot_old_b = knots_old[i]; + + const int r_old = r; + r = static_cast(degree_old - mult); + + IndexType left_bezier; + IndexType right_bezier; + + if (r_old > 0) { + left_bezier = (r_old + 2) / 2; + } else { + left_bezier = 1; + } + + if (r > 0) { + right_bezier = degree - ((r + 1) / 2); + } else { + right_bezier = degree; + } + + if (r > 0) { + Vector alphas = ZeroVector(degree_old - 1); + + for (IndexType k = degree_old; k > mult; --k) { + alphas[k - mult - 1] = + (knot_old_b - knot_old_a) + / (knots_old[a + k] - knot_old_a); + } + + for (IndexType j = 1; j < static_cast(r + 1); ++j) { + const int save = r - static_cast(j); + const IndexType s = mult + j; + + for (IndexType k = degree_old; k >= s; --k) { + const array_1d cp_coordinates = + alphas[k - s] * bezier_points[k] + + (1.0 - alphas[k - s]) * bezier_points[k - 1]; + + bezier_points(k) = + Kratos::make_intrusive(0, cp_coordinates); + + bezier_points_weights[k] = + alphas[k - s] * bezier_points_weights[k] + + (1.0 - alphas[k - s]) * bezier_points_weights[k - 1]; + + if (k == s) { + break; + } + } + + if (degree_old > 1) { + next_bezier_points(save) = bezier_points(degree_old); + next_bezier_points_weights[save] = + bezier_points_weights[degree_old]; + } + } + } + + for (IndexType i_elev = left_bezier; i_elev < degree + 1; ++i_elev) { + const array_1d zero_coordinates = ZeroVector(3); + + elevate_bezier_points(i_elev) = + Kratos::make_intrusive(0, zero_coordinates); + + elevate_bezier_points_weights[i_elev] = 0.0; + + const SizeType min_degree = std::min(degree_old, i_elev); + const int index = std::max( + 0, + static_cast(i_elev - rDegreeToElevate) + ); + + for (IndexType j = index; j < min_degree + 1; ++j) { + const array_1d cp_coordinates = + elevate_bezier_points[i_elev] + + bezier_alphas(i_elev, j) * bezier_points[j]; + + elevate_bezier_points(i_elev) = + Kratos::make_intrusive(0, cp_coordinates); + + elevate_bezier_points_weights[i_elev] += + bezier_alphas(i_elev, j) * bezier_points_weights[j]; + } + } + + if (r_old > 1) { + IndexType first = knot_index - 2; + IndexType last = knot_index; + + const double beta = + (knot_old_b - rKnotsRefined[knot_index - 2]) + / (knot_old_b - knot_old_a); + + for (IndexType t = 1; t < static_cast(r_old); ++t) { + IndexType i_remove = first; + IndexType j_remove = last; + IndexType k_remove = j_remove - knot_index + 1; + + while (j_remove - i_remove > t) { + if (i_remove < control_point_index) { + const double alpha = + (knot_old_b - rKnotsRefined[i_remove - 1]) + / (knot_old_a - rKnotsRefined[i_remove - 1]); + + const array_1d cp_coordinates = + alpha * rPointsRefined[i_remove] + + (1.0 - alpha) * rPointsRefined[i_remove - 1]; + + rPointsRefined(i_remove) = + Kratos::make_intrusive(0, cp_coordinates); + + rWeightsRefined[i_remove] = + alpha * rWeightsRefined[i_remove] + + (1.0 - alpha) * rWeightsRefined[i_remove - 1]; + } + + if (j_remove >= left_bezier) { + if ((j_remove - t) <= (knot_index - degree + r_old)) { + const double gamma = + (knot_old_b - rKnotsRefined[j_remove - t - 1]) + / (knot_old_b - knot_old_a); + + const array_1d cp_coordinates = + gamma * elevate_bezier_points[k_remove] + + (1.0 - gamma) * elevate_bezier_points[k_remove + 1]; + + elevate_bezier_points(k_remove) = + Kratos::make_intrusive(0, cp_coordinates); + + elevate_bezier_points_weights[k_remove] = + gamma * elevate_bezier_points_weights[k_remove] + + (1.0 - gamma) + * elevate_bezier_points_weights[k_remove + 1]; + } else { + const array_1d cp_coordinates = + beta * elevate_bezier_points[k_remove] + + (1.0 - beta) * elevate_bezier_points[k_remove + 1]; + + elevate_bezier_points(k_remove) = + Kratos::make_intrusive(0, cp_coordinates); + + elevate_bezier_points_weights[k_remove] = + beta * elevate_bezier_points_weights[k_remove] + + (1.0 - beta) + * elevate_bezier_points_weights[k_remove + 1]; + } + } + + ++i_remove; + --j_remove; + --k_remove; + } + + --first; + ++last; + } + } + + if ((a + 1) != degree_old) { + for (IndexType i_knot = 0; i_knot < degree - r_old; ++i_knot) { + rKnotsRefined[knot_index - 1] = knot_old_a; + ++knot_index; + } + } + + for (IndexType j = left_bezier; j < right_bezier + 1; ++j) { + rPointsRefined(control_point_index) = + elevate_bezier_points(j); + + rWeightsRefined[control_point_index] = + elevate_bezier_points_weights[j]; + + ++control_point_index; + } + + if (b < nb_knots_old) { + for (IndexType j = 0; j < static_cast(r); ++j) { + bezier_points(j) = next_bezier_points(j); + bezier_points_weights[j] = next_bezier_points_weights[j]; + } + + for (IndexType j = r; j < degree_old + 1; ++j) { + const IndexType old_index = + b - degree_old + j + 1; + + const array_1d cp_coordinates = + rGeometry[old_index] * weights_old[old_index]; + + bezier_points(j) = + Kratos::make_intrusive(0, cp_coordinates); + + bezier_points_weights[j] = + weights_old[old_index]; + } + + a = b; + ++b; + knot_old_a = knot_old_b; + } else { + for (IndexType i_knot = 0; i_knot < degree; ++i_knot) { + rKnotsRefined[knot_index - 1 + i_knot] = knot_old_b; + } + } + } + + for (IndexType i = 0; i < nb_cp_refined; ++i) { + rPointsRefined(i)->Coordinates() = + rPointsRefined(i)->Coordinates() / rWeightsRefined[i]; + } +} + +void NurbsCurveRefinementUtilities::SortAndFilter( + std::vector& rKnotsToInsert, + const Vector& rKnotsOld) +{ + std::sort(rKnotsToInsert.begin(), rKnotsToInsert.end()); + + const double lower_bound = + std::min(rKnotsOld[0], rKnotsOld[rKnotsOld.size() - 1]); + + const double upper_bound = + std::max(rKnotsOld[0], rKnotsOld[rKnotsOld.size() - 1]); + + auto start = + std::lower_bound( + rKnotsToInsert.begin(), + rKnotsToInsert.end(), + lower_bound); + + auto end = + std::upper_bound( + rKnotsToInsert.begin(), + rKnotsToInsert.end(), + upper_bound); + + rKnotsToInsert = + std::vector(start, end); +} + +Vector NurbsCurveRefinementUtilities::CreateFullKnotVector( + const Vector& rReducedKnots, + const SizeType Degree) +{ + const double first = rReducedKnots[0]; + const double last = rReducedKnots[rReducedKnots.size() - 1]; + + SizeType first_multiplicity = 0; + for (IndexType i = 0; i < rReducedKnots.size(); ++i) { + if (std::abs(rReducedKnots[i] - first) < 1.0e-12) { + ++first_multiplicity; + } else { + break; + } + } + + SizeType last_multiplicity = 0; + for (int i = static_cast(rReducedKnots.size()) - 1; i >= 0; --i) { + if (std::abs(rReducedKnots[i] - last) < 1.0e-12) { + ++last_multiplicity; + } else { + break; + } + } + + const SizeType required_multiplicity = Degree + 1; + + const SizeType add_first = + required_multiplicity > first_multiplicity + ? required_multiplicity - first_multiplicity + : 0; + + const SizeType add_last = + required_multiplicity > last_multiplicity + ? required_multiplicity - last_multiplicity + : 0; + + Vector full_knots(rReducedKnots.size() + add_first + add_last); + + IndexType index = 0; + + for (IndexType i = 0; i < add_first; ++i) { + full_knots[index++] = first; + } + + for (IndexType i = 0; i < rReducedKnots.size(); ++i) { + full_knots[index++] = rReducedKnots[i]; + } + + for (IndexType i = 0; i < add_last; ++i) { + full_knots[index++] = last; + } + + return full_knots; +} + +Vector NurbsCurveRefinementUtilities::CreateReducedKnotVector( + const Vector& rFullKnots, + const SizeType Degree) +{ + const SizeType remove_each_side = 1; + + Vector reduced_knots(rFullKnots.size() - 2 * remove_each_side); + + IndexType index = 0; + + for (IndexType i = remove_each_side; i < rFullKnots.size() - remove_each_side; ++i) { + reduced_knots[index++] = rFullKnots[i]; + } + + return reduced_knots; +} + +} // namespace Kratos \ No newline at end of file diff --git a/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h b/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h new file mode 100644 index 000000000000..644c087d56e2 --- /dev/null +++ b/kratos/geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h @@ -0,0 +1,62 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ ` +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Juan I. Camarotti +// + +#pragma once + +// System includes + +// External includes + +// Project includes +#include "geometries/nurbs_curve_geometry.h" +#include "nurbs_utilities.h" +#include "includes/node.h" + +namespace Kratos { + +class KRATOS_API(KRATOS_CORE) NurbsCurveRefinementUtilities{ + public: + using IndexType = std::size_t; + using SizeType = std::size_t; + using NodeType = Node; + + using NurbsCurveGeometryType = NurbsCurveGeometry<3, PointerVector>; + using NurbsCurveGeometryPointerType = typename NurbsCurveGeometryType::Pointer; + + static void KnotRefinement( + NurbsCurveGeometryType& rGeometry, + std::vector& rKnotsToInsert, + PointerVector& rPointsRefined, + Vector& rKnotsRefined, + Vector& rWeightsRefined); + + static void DegreeElevation( + NurbsCurveGeometryType& rGeometry, + const SizeType rDegreeToElevate, + PointerVector& rPointsRefined, + Vector& rKnotsRefined, + Vector& rWeightsRefined); + + static void SortAndFilter( + std::vector& rKnotsToInsert, + const Vector& rKnotsOld); + + static Vector CreateFullKnotVector( + const Vector& rKnots, + const SizeType Degree); + + static Vector CreateReducedKnotVector( + const Vector& rFullKnots, + const SizeType Degree); +}; + +} // namespace Kratos \ No newline at end of file diff --git a/kratos/python/add_strategies_to_python.cpp b/kratos/python/add_strategies_to_python.cpp index 2ec61648cdd5..e2911636ab3e 100644 --- a/kratos/python/add_strategies_to_python.cpp +++ b/kratos/python/add_strategies_to_python.cpp @@ -724,4 +724,4 @@ namespace Kratos:: Python } -} // namespace Kratos::Python. +} // namespace Kratos::Python. \ No newline at end of file diff --git a/kratos/python_scripts/python_linear_solver_factory.py b/kratos/python_scripts/python_linear_solver_factory.py index ab83f20e415c..86f5deed8530 100644 --- a/kratos/python_scripts/python_linear_solver_factory.py +++ b/kratos/python_scripts/python_linear_solver_factory.py @@ -25,7 +25,7 @@ def CreateFastestAvailableDirectLinearSolver(): if kratos_utils.CheckIfApplicationsAvailable("LinearSolversApplication"): from KratosMultiphysics import LinearSolversApplication - linear_solvers_by_speed = KM.UblasSparseSpace.FastestDirectSolverList() + linear_solvers_by_speed = KM.SparseSpace.FastestDirectSolverList() for solver_name in linear_solvers_by_speed: if KM.LinearSolverFactory().Has(solver_name): diff --git a/kratos/tests/test_condition_number.py b/kratos/tests/test_condition_number.py index 7a0bfb64a530..58b12edbb636 100644 --- a/kratos/tests/test_condition_number.py +++ b/kratos/tests/test_condition_number.py @@ -12,7 +12,7 @@ class TestConditionNumber(KratosUnittest.TestCase): @KratosUnittest.skipIfApplicationsNotAvailable("LinearSolversApplication") def test_condition_number(self): # Read the matrices - K = KratosMultiphysics.CompressedMatrix() + K = KratosMultiphysics.SparseMatrix() KratosMultiphysics.ReadMatrixMarketMatrix(GetFilePath("auxiliar_files_for_python_unittest/sparse_matrix_files/A.mm"),K) # Construct the solver From 6f463320cdc38c07f0c98cb9f027d6d3a2b92af4 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:16:05 +0100 Subject: [PATCH 08/32] revert noise changes in some files --- .../convection_diffusion_stationary_matrix_solver.py | 2 +- applications/FSIApplication/tests/FSI_problem_emulator_test.py | 2 +- applications/LinearSolversApplication/tests/test_mkl.py | 2 +- .../structural_mechanics_custom_scipy_base_solver.py | 2 +- kratos/python/add_strategies_to_python.cpp | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py b/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py index 6c475106bacf..948181ebb246 100644 --- a/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py +++ b/applications/ConvectionDiffusionApplication/python_scripts/convection_diffusion_stationary_matrix_solver.py @@ -37,7 +37,7 @@ def SolveSolutionStep(self): # self._AssignSystemVector(x) # ---- - + KratosMultiphysics.Logger.PrintInfo("::[{}]:: ".format(self.__class__.__name__), "Extracted system matrix and vector.") KratosMultiphysics.Logger.PrintInfo("::[{}]:: ".format(self.__class__.__name__), "No solution triggered!") diff --git a/applications/FSIApplication/tests/FSI_problem_emulator_test.py b/applications/FSIApplication/tests/FSI_problem_emulator_test.py index 7f82777df93e..d9b149ade1b7 100644 --- a/applications/FSIApplication/tests/FSI_problem_emulator_test.py +++ b/applications/FSIApplication/tests/FSI_problem_emulator_test.py @@ -467,4 +467,4 @@ def __ComputeStructureResidual(self): # test.test_FSI_problem_emulator_with_MVQN() test.test_FSI_problem_emulator_with_IBQN_MVQN() # test.test_FSI_problem_emulator_with_MVQN_recursive() - test.tearDown() \ No newline at end of file + test.tearDown() diff --git a/applications/LinearSolversApplication/tests/test_mkl.py b/applications/LinearSolversApplication/tests/test_mkl.py index e9a26fbda9cf..8dbeacaa4a52 100644 --- a/applications/LinearSolversApplication/tests/test_mkl.py +++ b/applications/LinearSolversApplication/tests/test_mkl.py @@ -56,4 +56,4 @@ def test_MKLILUT(self): if __name__ == '__main__': - KratosUnittest.main() \ No newline at end of file + KratosUnittest.main() diff --git a/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py b/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py index aff9e4991d62..ee39d77d5836 100644 --- a/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py +++ b/applications/StructuralMechanicsApplication/python_scripts/structural_mechanics_custom_scipy_base_solver.py @@ -190,4 +190,4 @@ def SolveSolutionStep(self): ## Assign results to Kratos variables self._AssignVariables(vals,vecs) - return True #converged \ No newline at end of file + return True #converged diff --git a/kratos/python/add_strategies_to_python.cpp b/kratos/python/add_strategies_to_python.cpp index ae7dbf636363..dfb955978569 100644 --- a/kratos/python/add_strategies_to_python.cpp +++ b/kratos/python/add_strategies_to_python.cpp @@ -734,4 +734,4 @@ namespace Kratos:: Python } -} // namespace Kratos::Python. \ No newline at end of file +} // namespace Kratos::Python. From 2de6a0f2ae1981e49ff461eeec01e82966925bc2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:18:43 +0100 Subject: [PATCH 09/32] erase unrelated file --- kipping... | 1893 ---------------------------------------------------- 1 file changed, 1893 deletions(-) delete mode 100644 kipping... diff --git a/kipping... b/kipping... deleted file mode 100644 index 2e8484d4f9ec..000000000000 --- a/kipping... +++ /dev/null @@ -1,1893 +0,0 @@ -diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp -new file mode 100644 -index 00000000000..d4417883cac ---- /dev/null -+++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp -@@ -0,0 +1,1886 @@ -+// KRATOS _____________ -+// / _/ ____/ | -+// / // / __/ /| | -+// _/ // /_/ / ___ | -+// /___/\____/_/ |_| Application -+// -+// License: BSD License -+// Kratos default license: kratos/license.txt -+// -+// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio -+// -+ -+// System includes -+ -+// External includes -+ -+// Project includes -+ -+// Application includes -+#include "custom_elements/non_linear_bernoulli_beam_element_3D.h" -+#include "utilities/math_utils.h" -+ -+namespace Kratos -+{ -+ void NonLinearBernoulliBeamElement3D::Initialize(const ProcessInfo& rCurrentProcessInfo) -+ { -+ KRATOS_TRY -+ InitializeMaterial(); -+ -+ -+ mDofsPerNode = 4; -+ mNumberOfDofs = this->GetGeometry().size() * mDofsPerNode; -+ mSMatrixRodriguesVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaRodriguesLambdaVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesDerivativeVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); -+ mSMatrixRodriguesSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixRodriguesDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); -+ KRATOS_CATCH("") -+  -+ } -+ -+ -+ -+ void NonLinearBernoulliBeamElement3D::CalculateKinematics( -+ const IndexType IntegrationPointIndex, -+ KinematicVariables& rKinematicVariables) -+ { -+ const auto& r_geometry = GetGeometry(); -+ -+ // Get shape functions and derivatives -+ const Matrix& r_shape_functions = -+ r_geometry.ShapeFunctionsValues(); -+ -+ const Matrix& r_shape_function_derivatives = -+ r_geometry.ShapeFunctionDerivatives( -+ 1, -+ IntegrationPointIndex); -+ -+ const Matrix& r_shape_function_second_derivatives = -+ r_geometry.ShapeFunctionDerivatives( -+ 2, -+ IntegrationPointIndex); -+ -+ // Clear variables -+ rKinematicVariables.R1.clear(); -+ rKinematicVariables.R2.clear(); -+ rKinematicVariables.r1.clear(); -+ rKinematicVariables.r2.clear(); -+ -+ // Calculate reference and current configurations -+ for (IndexType i = 0; i < r_geometry.size(); ++i) { -+ const array_1d& r_initial_position = -+ r_geometry[i].GetInitialPosition(); -+ -+ const array_1d& r_displacement = -+ r_geometry[i].FastGetSolutionStepValue(DISPLACEMENT); -+ -+ // Reference configuration -+ rKinematicVariables.R1 += -+ r_shape_function_derivatives(i, 0) * -+ r_initial_position; -+ -+ rKinematicVariables.R2 += -+ r_shape_function_second_derivatives(i, 0) * -+ r_initial_position; -+ -+ // Current configuration -+ const array_1d current_position = -+ r_initial_position + r_displacement; -+ -+ rKinematicVariables.r1 += -+ r_shape_function_derivatives(i, 0) * -+ current_position; -+ -+ rKinematicVariables.r2 += -+ r_shape_function_second_derivatives(i, 0) * -+ current_position; -+ -+ // Rotations -+ const double rotation = -+ r_geometry[i].FastGetSolutionStepValue(ROTATION_X); -+ -+ rKinematicVariables.phi += -+ r_shape_functions(IntegrationPointIndex, i) * -+ rotation; -+ -+ rKinematicVariables.phi_der += -+ r_shape_function_derivatives(i, 0) * -+ rotation; -+ } -+ -+ // Calculate length measures -+ rKinematicVariables.A = -+ norm_2(rKinematicVariables.R1); -+ -+ rKinematicVariables.a = -+ norm_2(rKinematicVariables.r1); -+ -+ // Calculate curvature measures -+ const double reference_base_vector_product = -+ inner_prod( -+ rKinematicVariables.R1, -+ rKinematicVariables.R2); -+ -+ const double current_base_vector_product = -+ inner_prod( -+ rKinematicVariables.r1, -+ rKinematicVariables.r2); -+ -+ rKinematicVariables.B = sqrt( -+ inner_prod( -+ rKinematicVariables.R2, -+ rKinematicVariables.R2) -+ - pow( -+ reference_base_vector_product / -+ rKinematicVariables.A, -+ 2)); -+ -+ rKinematicVariables.b = sqrt( -+ inner_prod( -+ rKinematicVariables.r2, -+ rKinematicVariables.r2) -+ - pow( -+ current_base_vector_product / -+ rKinematicVariables.a, -+ 2)); -+ -+ // Compute reference cross-section geometry -+ ComputeReferenceCrossSectionGeometry( -+ rKinematicVariables); -+ -+ // Compute current cross-section geometry -+ ComputeCurrentCrossSectionGeometry( -+ rKinematicVariables); -+ } -+  -+ -+ void NonLinearBernoulliBeamElement3D::CalculateAll( -+ MatrixType& rLeftHandSideMatrix, -+ VectorType& rRightHandSideVector, -+ const ProcessInfo& rCurrentProcessInfo, -+ const bool CalculateStiffnessMatrixFlag, -+ const bool CalculateResidualVectorFlag) -+ { -+ KRATOS_TRY -+ -+ const auto& r_geometry = GetGeometry(); -+ const auto& r_integration_points = -+ r_geometry.IntegrationPoints(); -+ -+ Vector stress_axial = ZeroVector(5); -+ Vector stress_bending_1 = ZeroVector(5); -+ Vector stress_bending_2 = ZeroVector(5); -+ Vector stress_torsion_1 = ZeroVector(5); -+ Vector stress_torsion_2 = ZeroVector(5); -+ -+ for ( -+ IndexType point_number = 0; -+ point_number < r_integration_points.size(); -+ ++point_number) -+ { -+ // Compute kinematics and metric -+ KinematicVariables kinematic_variables( -+ GetGeometry().WorkingSpaceDimension()); -+ -+ CalculateKinematics( -+ point_number, -+ kinematic_variables); -+ -+ // Create constitutive law parameters -+ ConstitutiveLaw::Parameters constitutive_law_parameters( -+ GetGeometry(), -+ GetProperties(), -+ rCurrentProcessInfo); -+ -+ ConstitutiveVariables constitutive_variables(5); -+ -+ CalculateConstitutiveVariables( -+ point_number, -+ kinematic_variables, -+ constitutive_variables, -+ constitutive_law_parameters, -+ ConstitutiveLaw::StressMeasure_PK2); -+ -+ Matrix b_axial; -+ Matrix b_bending_1; -+ Matrix b_bending_2; -+ Matrix b_torsion_1; -+ Matrix b_torsion_2; -+ -+ ComputeBMatrices( -+ point_number, -+ kinematic_variables, -+ b_axial, -+ b_bending_1, -+ b_bending_2, -+ b_torsion_1, -+ b_torsion_2); -+ -+ Matrix g_axial; -+ Matrix g_bending_1; -+ Matrix g_bending_2; -+ Matrix g_torsion_1; -+ Matrix g_torsion_2; -+ -+ ComputeGMatrices( -+ point_number, -+ kinematic_variables, -+ g_axial, -+ g_bending_1, -+ g_bending_2, -+ g_torsion_1, -+ g_torsion_2); -+ -+ // Assemble stiffness with cross-sectional scaling -+ const double integration_weight = -+ r_integration_points[point_number].Weight() * -+ kinematic_variables.A; -+ -+ const double inverse_a2 = -+ 1.0 / -+ (kinematic_variables.A * -+ kinematic_variables.A); -+ -+ const double inverse_a4 = -+ inverse_a2 * inverse_a2; -+ -+ if (CalculateStiffnessMatrixFlag == true) { -+ // Material stiffness -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_axial), -+ Matrix(prod( -+ constitutive_variables.ConstitutiveMatrix, -+ b_axial))); -+ -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_bending_1), -+ Matrix(prod( -+ constitutive_variables.ConstitutiveMatrix, -+ b_bending_1))); -+ -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_bending_2), -+ Matrix(prod( -+ constitutive_variables.ConstitutiveMatrix, -+ b_bending_2))); -+ -+ rLeftHandSideMatrix += -+ inverse_a2 * -+ integration_weight * -+ prod( -+ trans(b_torsion_1), -+ Matrix(prod( -+ constitutive_variables.ConstitutiveMatrix, -+ b_torsion_1))); -+ -+ rLeftHandSideMatrix += -+ inverse_a2 * -+ integration_weight * -+ prod( -+ trans(b_torsion_2), -+ Matrix(prod( -+ constitutive_variables.ConstitutiveMatrix, -+ b_torsion_2))); -+ -+ // Geometrical stiffness -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ g_axial * -+ constitutive_variables.StressVector[0]; -+ -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ g_bending_1 * -+ constitutive_variables.StressVector[1]; -+ -+ rLeftHandSideMatrix += -+ inverse_a4 * -+ integration_weight * -+ g_bending_2 * -+ constitutive_variables.StressVector[2]; -+ -+ rLeftHandSideMatrix += -+ inverse_a2 * -+ integration_weight * -+ g_torsion_1 * -+ constitutive_variables.StressVector[3]; -+ -+ rLeftHandSideMatrix += -+ inverse_a2 * -+ integration_weight * -+ g_torsion_2 * -+ constitutive_variables.StressVector[4]; -+ } -+ -+ if (CalculateResidualVectorFlag == true) { -+ // Map stress components to different behaviors -+ stress_axial[0] = -+ constitutive_variables.StressVector[0]; -+ -+ stress_bending_1[1] = -+ constitutive_variables.StressVector[1]; -+ -+ stress_bending_2[2] = -+ constitutive_variables.StressVector[2]; -+ -+ stress_torsion_1[3] = -+ constitutive_variables.StressVector[3]; -+ -+ stress_torsion_2[4] = -+ constitutive_variables.StressVector[4]; -+ -+ // Assemble internal forces -+ rRightHandSideVector -= -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_axial), -+ stress_axial); -+ -+ rRightHandSideVector -= -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_bending_1), -+ stress_bending_1); -+ -+ rRightHandSideVector -= -+ inverse_a4 * -+ integration_weight * -+ prod( -+ trans(b_bending_2), -+ stress_bending_2); -+ -+ rRightHandSideVector -= -+ inverse_a2 * -+ integration_weight * -+ prod( -+ trans(b_torsion_1), -+ stress_torsion_1); -+ -+ rRightHandSideVector -= -+ inverse_a2 * -+ integration_weight * -+ prod( -+ trans(b_torsion_2), -+ stress_torsion_2); -+ } -+ } -+ -+ KRATOS_CATCH("") -+ } -+ -+  -+ int NonLinearBernoulliBeamElement3D::Check( -+ const ProcessInfo& rCurrentProcessInfo) const -+ { -+ KRATOS_TRY -+ -+ Check(rCurrentProcessInfo); -+ -+ const double numerical_limit = -+ std::numeric_limits::epsilon(); -+ -+ KRATOS_ERROR_IF( -+ !GetProperties().Has(I_T) || -+ GetProperties()[I_T] <= numerical_limit) -+ << "Please provide a reasonable value for \"I_T\" " -+ << "(torsional moment of inertia) for element #" -+ << Id() << std::endl; -+ -+ KRATOS_ERROR_IF( -+ !GetProperties().Has(I_N) || -+ GetProperties()[I_N] <= numerical_limit) -+ << "Please provide a reasonable value for \"I_N\" " -+ << "(bending moment of inertia about N axis) for element #" -+ << Id() << std::endl; -+ -+ KRATOS_ERROR_IF( -+ !GetProperties().Has(I_V) || -+ GetProperties()[I_V] <= numerical_limit) -+ << "Please provide a reasonable value for \"I_V\" " -+ << "(bending moment of inertia about V axis) for element #" -+ << Id() << std::endl; -+ -+ KRATOS_ERROR_IF( -+ !GetProperties().Has(LOCAL_AXIS_ORIENTATION)) -+ << "\"LOCAL_AXIS_ORIENTATION\" not provided for element #" -+ << Id() << std::endl; -+ -+ if (GetProperties().Has(T_0)) { -+ const Vector3d& r_reference_tangent = -+ GetProperties()[T_0]; -+ -+ KRATOS_ERROR_IF( -+ norm_2(r_reference_tangent) <= numerical_limit) -+ << "\"T_0\" reference director vector must have " -+ << "non-zero magnitude for element #" -+ << Id() << std::endl; -+ } -+ -+ if (GetProperties().Has(N_0)) { -+ const Vector3d& r_reference_normal = -+ GetProperties()[N_0]; -+ -+ KRATOS_ERROR_IF( -+ norm_2(r_reference_normal) <= numerical_limit) -+ << "\"N_0\" reference director vector must have " -+ << "non-zero magnitude for element #" -+ << Id() << std::endl; -+ } -+ -+ return 0; -+ -+ KRATOS_CATCH("") -+ } -+ -+ -+ void NonLinearBernoulliBeamElement3D::CalculateConstitutiveVariables( -+ const IndexType IntegrationPointIndex, -+ const KinematicVariables& rKinematicVariables, -+ ConstitutiveVariables& rConstitutiveVariables, -+ ConstitutiveLaw::Parameters& rConstitutiveLawParameters, -+ const ConstitutiveLaw::StressMeasure StressMeasure) -+ { -+ rConstitutiveLawParameters.GetOptions().Set( -+ ConstitutiveLaw::USE_ELEMENT_PROVIDED_STRAIN, -+ true); -+ -+ rConstitutiveLawParameters.GetOptions().Set( -+ ConstitutiveLaw::COMPUTE_STRESS); -+ -+ rConstitutiveLawParameters.GetOptions().Set( -+ ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR); -+ -+ rConstitutiveVariables.StrainVector[0] = -+ 0.5 * ( -+ rKinematicVariables.a * rKinematicVariables.a - -+ rKinematicVariables.A * rKinematicVariables.A); -+ -+ rConstitutiveVariables.StrainVector[1] = -+ rKinematicVariables.b_n - -+ rKinematicVariables.B_n; -+ -+ rConstitutiveVariables.StrainVector[2] = -+ rKinematicVariables.b_v - -+ rKinematicVariables.B_v; -+ -+ rConstitutiveVariables.StrainVector[3] = -+ rKinematicVariables.c_12 - -+ rKinematicVariables.C_12; -+ -+ rConstitutiveVariables.StrainVector[4] = -+ rKinematicVariables.c_13 - -+ rKinematicVariables.C_13; -+ -+ rConstitutiveLawParameters.SetStrainVector( -+ rConstitutiveVariables.StrainVector); -+ -+ rConstitutiveLawParameters.SetStressVector( -+ rConstitutiveVariables.StressVector); -+ -+ rConstitutiveLawParameters.SetConstitutiveMatrix( -+ rConstitutiveVariables.ConstitutiveMatrix); -+ -+ mConstitutiveLawVector[IntegrationPointIndex] -+ ->CalculateMaterialResponse( -+ rConstitutiveLawParameters, -+ StressMeasure); -+ -+ noalias(rConstitutiveVariables.StressVector) = -+ prod( -+ trans(rConstitutiveVariables.ConstitutiveMatrix), -+ rConstitutiveVariables.StrainVector); -+ }  -+ -+ -+ void NonLinearBernoulliBeamElement3D::ComputeReferenceTwistAngleAndDerivative( -+ const KinematicVariables& rKinematicVariables, -+ double& rPhi, -+ double& rPhiDerivative) -+ { -+ -+ const auto& r_geometry = GetGeometry(); -+ const double integration_point_coordinate = r_geometry.IntegrationPoints()[0].Coordinates()[0]; -+ -+ double lower_twist_angle; -+ double upper_twist_angle; -+ double twist_angle_difference; -+ double lower_parameter_coordinate; -+ double upper_parameter_coordinate; -+ int number_of_orientation_points; -+ -+ Matrix local_axis_orientation = GetProperties()[LOCAL_AXIS_ORIENTATION]; -+ number_of_orientation_points = local_axis_orientation.size1(); -+ -+ lower_parameter_coordinate = local_axis_orientation(0, 0); -+ upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - 1, 0); -+  -+ // Extract normal vector components for start and end -+ Vector3d lower_normal; -+ lower_normal[0] = local_axis_orientation(0, 1); -+ lower_normal[1] = local_axis_orientation(0, 2); -+ lower_normal[2] = local_axis_orientation(0, 3); -+  -+ Vector3d upper_normal; -+ upper_normal[0] = local_axis_orientation(number_of_orientation_points - 1, 1); -+ upper_normal[1] = local_axis_orientation(number_of_orientation_points - 1, 2); -+ upper_normal[2] = local_axis_orientation(number_of_orientation_points - 1, 3); -+  -+ // Convert normal vectors to rotation angles (phi) for backward compatibility -+ lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, lower_normal); -+ upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, upper_normal); -+ -+ for (int i = 1; i < number_of_orientation_points; i++) -+ { -+ if (local_axis_orientation(i, 0) > integration_point_coordinate) -+ { -+ lower_parameter_coordinate = local_axis_orientation(i - 1, 0); -+ Vector3d interpolated_normal(3); -+ interpolated_normal[0] = local_axis_orientation(i - 1, 1); -+ interpolated_normal[1] = local_axis_orientation(i - 1, 2); -+ interpolated_normal[2] = local_axis_orientation(i - 1, 3); -+ lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); -+ break; -+ } -+ } -+ -+ for (int i = 1; i < number_of_orientation_points; i++) -+ { -+ if (local_axis_orientation(number_of_orientation_points - i - 1, 0) <= integration_point_coordinate) -+ { -+ upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - i, 0); -+ Vector3d interpolated_normal(3); -+ interpolated_normal[0] = local_axis_orientation(number_of_orientation_points - i, 1); -+ interpolated_normal[1] = local_axis_orientation(number_of_orientation_points - i, 2); -+ interpolated_normal[2] = local_axis_orientation(number_of_orientation_points - i, 3); -+ upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, interpolated_normal); -+ break; -+ } -+ } -+ const double pi = 4.0 * std::atan(1.0); -+ -+ twist_angle_difference = (upper_twist_angle - lower_twist_angle); -+ if (std::abs(upper_twist_angle - lower_twist_angle) > pi) -+ { -+ twist_angle_difference = twist_angle_difference - (twist_angle_difference) / std::abs(twist_angle_difference) * 2 * pi; -+ } -+ -+ rPhi += lower_twist_angle + (integration_point_coordinate - lower_parameter_coordinate) / (upper_parameter_coordinate - lower_parameter_coordinate) * twist_angle_difference; -+ rPhiDerivative += twist_angle_difference / (upper_parameter_coordinate - lower_parameter_coordinate); -+ } -+ -+ double NonLinearBernoulliBeamElement3D::CalculateDeltaPhi( -+ const KinematicVariables& rKinematicVariables, -+ const Vector3d& rNormal) -+ { -+ const Vector3d initial_tangent = GetProperties()[T_0]; -+ const Vector3d reference_base_vector = rKinematicVariables.R1; -+ -+ const Vector3d current_reference_tangent = -+ reference_base_vector / norm_2(reference_base_vector); -+ -+ const Vector3d normalized_initial_tangent = -+ initial_tangent / norm_2(initial_tangent); -+ -+ Vector3d normal = rNormal; -+ -+ const double tangent_normal_projection = -+ inner_prod(current_reference_tangent, normal); -+ -+ // Project the normal onto the plane normal to the reference tangent. -+ normal -= tangent_normal_projection * current_reference_tangent; -+ normal /= norm_2(normal); -+ -+ const Vector3d reference_principal_axis = normal; -+ -+ Matrix3d lambda_matrix; -+ ComputeLambdaMatrix( -+ normalized_initial_tangent, -+ current_reference_tangent, -+ lambda_matrix); -+ -+ const Vector3d rotated_reference_axis = -+ prod(lambda_matrix, reference_principal_axis); -+ -+ const Vector3d orientation_reference = -+ MathUtils::CrossProduct(reference_base_vector, rotated_reference_axis); -+ -+ const double axis_dot_product = -+ inner_prod(rotated_reference_axis, normal); -+ -+ const double orientation_dot_product = -+ inner_prod(normal, orientation_reference); -+ -+ double cos_theta = -+ axis_dot_product / -+ (norm_2(rotated_reference_axis) * norm_2(normal)); -+ -+ if (std::abs(1.0 - std::abs(cos_theta)) < 1e-9) { -+ cos_theta = MathUtils::Sign(cos_theta); -+ } -+ -+ double phi = std::acos(cos_theta); -+ -+ const double pi = 4.0 * std::atan(1.0); -+ -+ if (orientation_dot_product < -1e-12) { -+ phi = 2.0 * pi - phi; -+ } -+ -+ return phi; -+ } -+  -+ -+ void NonLinearBernoulliBeamElement3D::ComputeReferenceCrossSectionGeometry( -+ KinematicVariables& rKinematicVariables) -+ { -+ const Vector3d reference_first_base_vector = rKinematicVariables.R1; -+ const Vector3d reference_second_base_vector = rKinematicVariables.R2; -+ const Vector3d initial_reference_tangent = GetProperties()[T_0]; -+ -+ ComputeReferenceTwistAngleAndDerivative( -+ rKinematicVariables, -+ rKinematicVariables.Phi, -+ rKinematicVariables.Phi_der); -+ -+ Matrix3d reference_lambda_matrix; -+ Matrix3d reference_lambda_matrix_derivative; -+ Matrix3d reference_rodrigues_matrix; -+ Matrix3d reference_rodrigues_matrix_derivative; -+ Matrix3d cross_section_transformation_derivative; -+ cross_section_transformation_derivative.clear(); -+ -+ const double reference_first_base_vector_norm = -+ norm_2(reference_first_base_vector); -+ -+ const Vector3d reference_tangent = -+ reference_first_base_vector / reference_first_base_vector_norm; -+ -+ const Vector3d reference_tangent_derivative = -+ reference_second_base_vector / reference_first_base_vector_norm -+ - inner_prod(reference_first_base_vector, reference_second_base_vector) -+ / pow(reference_first_base_vector_norm, 3) -+ * reference_first_base_vector; -+ -+ Vector3d initial_reference_tangent_derivative; -+ initial_reference_tangent_derivative.clear(); -+ -+ ComputeLambdaMatrix( -+ initial_reference_tangent, -+ reference_tangent, -+ reference_lambda_matrix); -+ -+ ComputeLambdaMatrixDerivative( -+ initial_reference_tangent, -+ reference_tangent, -+ initial_reference_tangent_derivative, -+ reference_tangent_derivative, -+ reference_lambda_matrix_derivative); -+ -+ ComputeRodriguesMatrix( -+ reference_tangent, -+ rKinematicVariables.Phi, -+ reference_rodrigues_matrix); -+ -+ ComputeRodriguesMatrixDerivative( -+ reference_tangent, -+ reference_tangent_derivative, -+ rKinematicVariables.Phi, -+ rKinematicVariables.Phi_der, -+ reference_rodrigues_matrix_derivative); -+ -+ rKinematicVariables.n.clear(); -+ rKinematicVariables.N0 = GetProperties()[N_0]; -+ -+ const double initial_reference_tangent_norm = -+ norm_2(initial_reference_tangent); -+ -+ const Vector3d normalized_initial_reference_tangent = -+ initial_reference_tangent / initial_reference_tangent_norm; -+ -+ rKinematicVariables.N0 -= -+ inner_prod( -+ normalized_initial_reference_tangent, -+ rKinematicVariables.N0) -+ * normalized_initial_reference_tangent; -+ -+ rKinematicVariables.V0 = -+ MathUtils::CrossProduct( -+ normalized_initial_reference_tangent, -+ rKinematicVariables.N0); -+ -+ rKinematicVariables.N0 /= -+ norm_2(rKinematicVariables.N0); -+ -+ rKinematicVariables.V0 /= -+ norm_2(rKinematicVariables.V0); -+ -+ Vector3d transformed_reference_normal; -+ transformed_reference_normal.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ transformed_reference_normal[i] += -+ reference_lambda_matrix(i, j) -+ * rKinematicVariables.N0[j]; -+ } -+ } -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ rKinematicVariables.n(i) += -+ reference_rodrigues_matrix(i, j) -+ * transformed_reference_normal[j]; -+ } -+ } -+ -+ rKinematicVariables.n /= -+ norm_2(rKinematicVariables.n); -+ -+ rKinematicVariables.v = -+ MathUtils::CrossProduct(reference_tangent, rKinematicVariables.n); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ for (IndexType k = 0; k < 3; ++k) { -+ cross_section_transformation_derivative(i, j) += -+ reference_rodrigues_matrix_derivative(i, k) -+ * reference_lambda_matrix(k, j); -+ -+ cross_section_transformation_derivative(i, j) += -+ reference_rodrigues_matrix(i, k) -+ * reference_lambda_matrix_derivative(k, j); -+ } -+ } -+ } -+ -+ Vector3d a21_vector; -+ Vector3d a31_vector; -+ a21_vector.clear(); -+ a31_vector.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ a21_vector[i] += -+ cross_section_transformation_derivative(i, j) -+ * rKinematicVariables.N0[j]; -+ -+ a31_vector[i] += -+ cross_section_transformation_derivative(i, j) -+ * rKinematicVariables.V0[j]; -+ } -+ } -+ -+ rKinematicVariables.B_n = -+ inner_prod(a21_vector, reference_first_base_vector); -+ -+ rKinematicVariables.B_v = -+ inner_prod(a31_vector, reference_first_base_vector); -+ -+ rKinematicVariables.C_12 = -+ inner_prod(a31_vector, rKinematicVariables.n); -+ -+ rKinematicVariables.C_13 = -+ inner_prod(a21_vector, rKinematicVariables.v); -+ } -+ -+ void NonLinearBernoulliBeamElement3D::ComputeCurrentCrossSectionGeometry( -+ KinematicVariables& rKinematicVariables) -+ { -+ const Vector3d current_first_base_vector = rKinematicVariables.r1; -+ const Vector3d current_second_base_vector = rKinematicVariables.r2; -+ const Vector3d reference_first_base_vector = rKinematicVariables.R1; -+ const Vector3d reference_second_base_vector = rKinematicVariables.R2; -+ const Vector3d initial_reference_tangent = GetProperties()[T_0]; -+ -+ rKinematicVariables.n.clear(); -+ rKinematicVariables.v.clear(); -+ -+ Matrix3d current_lambda_matrix; -+ Matrix3d current_lambda_matrix_derivative; -+ Matrix3d reference_lambda_matrix; -+ Matrix3d reference_lambda_matrix_derivative; -+ Matrix3d current_rodrigues_matrix; -+ Matrix3d current_rodrigues_matrix_derivative; -+ Matrix3d reference_rodrigues_matrix; -+ Matrix3d reference_rodrigues_matrix_derivative; -+ -+ const double current_first_base_vector_norm = -+ norm_2(current_first_base_vector); -+ -+ const double reference_first_base_vector_norm = -+ norm_2(reference_first_base_vector); -+ -+ const Vector3d current_tangent = -+ current_first_base_vector / current_first_base_vector_norm; -+ -+ const Vector3d current_tangent_derivative = -+ current_second_base_vector / current_first_base_vector_norm -+ - inner_prod(current_first_base_vector, current_second_base_vector) -+ / pow(current_first_base_vector_norm, 3) -+ * current_first_base_vector; -+ -+ const Vector3d reference_tangent = -+ reference_first_base_vector / reference_first_base_vector_norm; -+ -+ const Vector3d reference_tangent_derivative = -+ reference_second_base_vector / reference_first_base_vector_norm -+ - inner_prod(reference_first_base_vector, reference_second_base_vector) -+ / pow(reference_first_base_vector_norm, 3) -+ * reference_first_base_vector; -+ -+ Vector3d initial_reference_tangent_derivative; -+ initial_reference_tangent_derivative.clear(); -+ -+ ComputeLambdaMatrix( -+ reference_tangent, -+ current_tangent, -+ current_lambda_matrix); -+ -+ ComputeLambdaMatrixDerivative( -+ reference_tangent, -+ current_tangent, -+ reference_tangent_derivative, -+ current_tangent_derivative, -+ current_lambda_matrix_derivative); -+ -+ ComputeLambdaMatrix( -+ initial_reference_tangent, -+ reference_tangent, -+ reference_lambda_matrix); -+ -+ ComputeLambdaMatrixDerivative( -+ initial_reference_tangent, -+ reference_tangent, -+ initial_reference_tangent_derivative, -+ reference_tangent_derivative, -+ reference_lambda_matrix_derivative); -+ -+ ComputeRodriguesMatrix( -+ current_tangent, -+ rKinematicVariables.phi, -+ current_rodrigues_matrix); -+ -+ ComputeRodriguesMatrixDerivative( -+ current_tangent, -+ current_tangent_derivative, -+ rKinematicVariables.phi, -+ rKinematicVariables.phi_der, -+ current_rodrigues_matrix_derivative); -+ -+ ComputeRodriguesMatrix( -+ reference_tangent, -+ rKinematicVariables.Phi, -+ reference_rodrigues_matrix); -+ -+ ComputeRodriguesMatrixDerivative( -+ reference_tangent, -+ reference_tangent_derivative, -+ rKinematicVariables.Phi, -+ rKinematicVariables.Phi_der, -+ reference_rodrigues_matrix_derivative); -+ -+ Matrix3d reference_rodrigues_lambda_product; -+ Matrix3d reference_rodrigues_lambda_derivative_product; -+ Matrix3d reference_rodrigues_derivative_lambda_product; -+ reference_rodrigues_lambda_product.clear(); -+ reference_rodrigues_lambda_derivative_product.clear(); -+ reference_rodrigues_derivative_lambda_product.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ for (IndexType k = 0; k < 3; ++k) { -+ reference_rodrigues_lambda_product(i, j) += -+ reference_rodrigues_matrix(i, k) -+ * reference_lambda_matrix(k, j); -+ -+ reference_rodrigues_lambda_derivative_product(i, j) += -+ reference_rodrigues_matrix(i, k) -+ * reference_lambda_matrix_derivative(k, j); -+ -+ reference_rodrigues_derivative_lambda_product(i, j) += -+ reference_rodrigues_matrix_derivative(i, k) -+ * reference_lambda_matrix(k, j); -+ } -+ } -+ } -+ -+ Matrix3d current_lambda_reference_rodrigues_lambda_product; -+ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; -+ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; -+ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; -+ current_lambda_reference_rodrigues_lambda_product.clear(); -+ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); -+ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); -+ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ for (IndexType k = 0; k < 3; ++k) { -+ current_lambda_reference_rodrigues_lambda_product(i, j) += -+ current_lambda_matrix(i, k) -+ * reference_rodrigues_lambda_product(k, j); -+ -+ current_lambda_reference_rodrigues_lambda_derivative_product(i, j) += -+ current_lambda_matrix(i, k) -+ * reference_rodrigues_lambda_derivative_product(k, j); -+ -+ current_lambda_reference_rodrigues_derivative_lambda_product(i, j) += -+ current_lambda_matrix(i, k) -+ * reference_rodrigues_derivative_lambda_product(k, j); -+ -+ current_lambda_derivative_reference_rodrigues_lambda_product(i, j) += -+ current_lambda_matrix_derivative(i, k) -+ * reference_rodrigues_lambda_product(k, j); -+ } -+ } -+ } -+ -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; -+ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; -+ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ Matrix3d cross_section_transformation; -+ -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); -+ cross_section_transformation.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ for (IndexType k = 0; k < 3; ++k) { -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(i, j) += -+ current_rodrigues_matrix(i, k) -+ * current_lambda_reference_rodrigues_lambda_derivative_product(k, j); -+ -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(i, j) += -+ current_rodrigues_matrix(i, k) -+ * current_lambda_reference_rodrigues_derivative_lambda_product(k, j); -+ -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(i, j) += -+ current_rodrigues_matrix(i, k) -+ * current_lambda_derivative_reference_rodrigues_lambda_product(k, j); -+ -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(i, j) += -+ current_rodrigues_matrix_derivative(i, k) -+ * current_lambda_reference_rodrigues_lambda_product(k, j); -+ -+ cross_section_transformation(i, j) += -+ current_rodrigues_matrix(i, k) -+ * current_lambda_reference_rodrigues_lambda_product(k, j); -+ } -+ } -+ } -+ -+ const Matrix3d cross_section_transformation_derivative = -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term -+ + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term -+ + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term -+ + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ -+ Vector3d a21_vector; -+ Vector3d a31_vector; -+ a21_vector.clear(); -+ a31_vector.clear(); -+ -+ for (IndexType i = 0; i < 3; ++i) { -+ for (IndexType j = 0; j < 3; ++j) { -+ a21_vector[i] += -+ cross_section_transformation_derivative(i, j) -+ * rKinematicVariables.N0[j]; -+ -+ a31_vector[i] += -+ cross_section_transformation_derivative(i, j) -+ * rKinematicVariables.V0[j]; -+ -+ rKinematicVariables.n[i] += -+ cross_section_transformation(i, j) -+ * rKinematicVariables.N0[j]; -+ -+ rKinematicVariables.v[i] += -+ cross_section_transformation(i, j) -+ * rKinematicVariables.V0[j]; -+ } -+ } -+ -+ rKinematicVariables.b_n = -+ inner_prod(a21_vector, current_first_base_vector); -+ -+ rKinematicVariables.b_v = -+ inner_prod(a31_vector, current_first_base_vector); -+ -+ rKinematicVariables.c_12 = -+ inner_prod(a31_vector, rKinematicVariables.n); -+ -+ rKinematicVariables.c_13 = -+ inner_prod(a21_vector, rKinematicVariables.v); -+ } -+ -+ -+ void NonLinearBernoulliBeamElement3D::ComputeBMatrices( -+ const IndexType IntegrationPointIndex, -+ const KinematicVariables& rKinematicVariables, -+ Matrix& rBAxial, -+ Matrix& rBBending1, -+ Matrix& rBBending2, -+ Matrix& rBTorsion1, -+ Matrix& rBTorsion2) -+ { -+ KRATOS_TRY -+ const auto& r_geometry = GetGeometry(); -+ -+ // Get shape functions and derivatives at integration point -+ Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); -+ Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); -+ Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); -+  -+ // Extract kinematic variables -+ Vector3d current_first_base_vector = rKinematicVariables.r1; -+ Vector3d current_second_base_vector = rKinematicVariables.r2; -+ Vector3d reference_first_base_vector = rKinematicVariables.R1; -+ Vector3d reference_second_base_vector = rKinematicVariables.R2; -+ Vector3d reference_normal = rKinematicVariables.N0; -+ Vector3d reference_binormal = rKinematicVariables.V0; -+ double current_twist_angle = rKinematicVariables.phi; -+ double current_twist_angle_derivative = rKinematicVariables.phi_der; -+ double reference_twist_angle = rKinematicVariables.Phi; -+ double reference_twist_angle_derivative = rKinematicVariables.Phi_der; -+ Vector3d initial_reference_tangent = GetProperties()[T_0]; -+ -+ // Compute curvature and torsion variations -+ Vector axial_variation(mNumberOfDofs); -+ Vector normal_curvature_variation(mNumberOfDofs); -+ Vector binormal_curvature_variation(mNumberOfDofs); -+ Vector normal_torsion_variation(mNumberOfDofs); -+ Vector binormal_torsion_variation(mNumberOfDofs); -+ axial_variation.clear(); -+ normal_curvature_variation.clear(); -+ binormal_curvature_variation.clear(); -+ normal_torsion_variation.clear(); -+ binormal_torsion_variation.clear(); -+ -+ //compute axial_variation -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ size_t dof_component = dof_index % mDofsPerNode;  -+ size_t control_point_index = dof_index / mDofsPerNode;  -+ if (dof_component > 2) -+ axial_variation[dof_index] = 0; -+ else -+ axial_variation[dof_index] = rKinematicVariables.r1[dof_component] * shape_function_derivatives[control_point_index]; -+ } -+ //compute normal_curvature_variation, binormal_curvature_variation, normal_torsion_variation, binormal_torsion_variation -+ Vector3d current_tangent; -+ current_tangent.clear(); -+ Vector3d current_tangent_derivative; -+ current_tangent_derivative.clear(); -+ Vector3d reference_tangent; -+ reference_tangent.clear(); -+ Vector3d reference_tangent_derivative; -+ reference_tangent_derivative.clear(); -+ Vector3d initial_reference_tangent_derivative; -+ initial_reference_tangent_derivative.clear(); -+ Vector current_tangent_variation; -+ Vector current_tangent_derivative_variation; -+ Matrix3d current_lambda_matrix; -+ Matrix3d current_lambda_matrix_derivative; -+ Matrix3d reference_lambda_matrix; -+ Matrix3d reference_lambda_matrix_derivative; -+ Matrix3d current_rodrigues_matrix; -+ Matrix3d current_rodrigues_matrix_derivative; -+ Matrix3d reference_rodrigues_matrix; -+ Matrix3d reference_rodrigues_matrix_derivative; -+ -+ current_tangent = current_first_base_vector / norm_2(current_first_base_vector); -+ current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; -+ reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); -+ reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; -+ ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); -+ ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); -+ -+ ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); -+ ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); -+ ComputeLambdaMatrixVariation(reference_tangent, current_tangent, current_tangent_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation); -+ ComputeLambdaMatrixDerivativeVariation(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaDerivativeVariation); -+ ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); -+ ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); -+ -+ ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); -+ ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); -+ ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); -+ ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); -+ ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); -+ ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); -+ -+ Matrix3d reference_rodrigues_lambda_derivative_product; -+ reference_rodrigues_lambda_derivative_product.clear(); -+ Matrix3d reference_rodrigues_derivative_lambda_product; -+ reference_rodrigues_derivative_lambda_product.clear(); -+ Matrix3d reference_rodrigues_lambda_product; -+ reference_rodrigues_lambda_product.clear(); -+ Matrix3d reference_rodrigues_lambda_product_derivative; -+ reference_rodrigues_lambda_product_derivative.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int column_component = 0; column_component < 3; column_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); -+ reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); -+ reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); -+ } -+ } -+ } -+ reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; -+ -+ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; -+ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; -+ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_lambda_product; -+ current_lambda_reference_rodrigues_lambda_product.clear(); -+ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; -+ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; -+ current_lambda_reference_rodrigues_lambda_product_derivative.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int column_component = 0; column_component < 3; column_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ -+ current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; -+ -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); -+ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); -+ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); -+ Matrix3d cross_section_transformation; -+ cross_section_transformation.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int column_component = 0; column_component < 3; column_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ -+ Matrix3d cross_section_transformation_derivative; -+ cross_section_transformation_derivative.clear(); -+ cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ -+ mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); -+ mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); -+ mSMatrixLambdaVariationRodriguesLambda.clear(); -+ mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int column_component = 0; column_component < 3; column_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) -+ { -+ mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ -+ Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); -+ -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; -+ -+ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); -+ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); -+ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); -+ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); -+ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int column_component = 0; column_component < 3; column_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) -+ { -+ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ -+ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); -+ mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); -+ -+ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda -+ + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; -+ mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; -+ -+ Vector3d normal_vector; -+ normal_vector.clear(); -+ Vector3d binormal_vector; -+ binormal_vector.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); -+ binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); -+ } -+ } -+ -+ Vector normal_vector_variation; -+ normal_vector_variation.resize(3 * mNumberOfDofs); -+ normal_vector_variation.clear(); -+ Vector binormal_vector_variation; -+ binormal_vector_variation.resize(3 * mNumberOfDofs); -+ binormal_vector_variation.clear(); -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); -+ binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); -+ } -+ } -+ } -+ -+ Vector current_first_base_vector_variation; -+ current_first_base_vector_variation.resize(3 * mNumberOfDofs); -+ current_first_base_vector_variation.clear(); -+ for (size_t row_component = 0; row_component < 3; row_component++)  -+ { -+ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++)  -+ { -+ size_t dof_component = dof_index % mDofsPerNode; -+ size_t control_point_index = dof_index / mDofsPerNode; -+ if (row_component == dof_component) -+ current_first_base_vector_variation(row_component * mNumberOfDofs + dof_index) = shape_function_derivatives[control_point_index]; -+ } -+ } -+ -+ for (size_t row_component = 0; row_component < 3; row_component++) -+ { -+ for (int product_index = 0; product_index < 3; product_index++) -+ { -+ for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) -+ { -+ normal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; -+ binormal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; -+ normal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index); -+ binormal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index); -+ } -+ } -+ } -+ -+  -+ // Initialize B matrices -+ rBAxial.resize(5, mNumberOfDofs); -+ rBBending1.resize(5, mNumberOfDofs); -+ rBBending2.resize(5, mNumberOfDofs); -+ rBTorsion1.resize(5, mNumberOfDofs); -+ rBTorsion2.resize(5, mNumberOfDofs); -+ rBAxial.clear(); -+ rBBending1.clear(); -+ rBBending2.clear(); -+ rBTorsion1.clear(); -+ rBTorsion2.clear(); -+ -+ noalias(row(rBAxial, 0)) = axial_variation; //Normal force -+ noalias(row(rBBending1, 1)) = normal_curvature_variation; // Bending about n-axis -+ noalias(row(rBBending2, 2)) = binormal_curvature_variation; // Bending about v-axis -+ noalias(row(rBTorsion1, 3)) = normal_torsion_variation; // Torsion n in row 1 (shear stress) -+ noalias(row(rBTorsion2, 4)) = binormal_torsion_variation; // Torsion v in row 2 (shear stress) -+  -+ KRATOS_CATCH("") -+ } -+ -+ -+ void NonLinearBernoulliBeamElement3D::ComputeGMatrices( -+ const IndexType IntegrationPointIndex, -+ const KinematicVariables& rKinematicVariables, -+ Matrix& rGAxial, -+ Matrix& rGBending1, -+ Matrix& rGBending2, -+ Matrix& rGTorsion1, -+ Matrix& rGTorsion2) -+ { -+ KRATOS_TRY -+ -+ const auto& r_geometry = GetGeometry(); -+ -+ // Get shape functions and derivatives at integration point -+ Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); -+ Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); -+ Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); -+  -+ // Extract kinematic variables -+ Vector3d current_first_base_vector = rKinematicVariables.r1; -+ Vector3d current_second_base_vector = rKinematicVariables.r2; -+ Vector3d reference_first_base_vector = rKinematicVariables.R1; -+ Vector3d reference_second_base_vector = rKinematicVariables.R2; -+ Vector3d reference_normal = rKinematicVariables.N0; -+ Vector3d reference_binormal = rKinematicVariables.V0; -+ double current_twist_angle = rKinematicVariables.phi; -+ double current_twist_angle_derivative = rKinematicVariables.phi_der; -+ double reference_twist_angle = rKinematicVariables.Phi; -+ double reference_twist_angle_derivative = rKinematicVariables.Phi_der; -+ Vector3d initial_reference_tangent = GetProperties()[T_0]; -+ -+ // Compute curvature and torsion variations -+ Matrix axial_second_variation(mNumberOfDofs, mNumberOfDofs); -+ Matrix normal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); -+ Matrix binormal_curvature_second_variation(mNumberOfDofs, mNumberOfDofs); -+ Matrix normal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); -+ Matrix binormal_torsion_second_variation(mNumberOfDofs, mNumberOfDofs); -+ axial_second_variation.clear(); -+ normal_curvature_second_variation.clear(); -+ binormal_curvature_second_variation.clear(); -+ normal_torsion_second_variation.clear(); -+ binormal_torsion_second_variation.clear(); -+ -+ //compute axial_variation -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++)  -+ { -+ size_t dof_component = dof_index % mDofsPerNode;  -+ size_t control_point_index = dof_index / mDofsPerNode;  -+ if (dof_component > 2) -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ axial_second_variation(dof_index, second_dof_index) = 0.0; -+ else -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ size_t second_dof_component = second_dof_index % mDofsPerNode;  -+ int second_control_point_index = second_dof_index / mDofsPerNode;  -+ if (second_dof_component > 2) -+ axial_second_variation(dof_index, second_dof_index) = 0; -+ else -+ if (dof_component == second_dof_component) -+ axial_second_variation(dof_index, second_dof_index) = shape_function_derivatives[control_point_index] * shape_function_derivatives[second_control_point_index]; -+ else -+ axial_second_variation(dof_index, second_dof_index) = 0; -+ } -+ } -+ } -+  -+ //compute normal_curvature_second_variation, binormal_curvature_second_variation, normal_torsion_second_variation, binormal_torsion_second_variation -+ Vector3d current_tangent; -+ current_tangent.clear(); -+ Vector3d current_tangent_derivative; -+ current_tangent_derivative.clear(); -+ Vector3d reference_tangent; -+ reference_tangent.clear(); -+ Vector3d reference_tangent_derivative; -+ reference_tangent_derivative.clear(); -+ Vector3d initial_reference_tangent_derivative; -+ initial_reference_tangent_derivative.clear(); -+ Vector current_tangent_variation; -+ Vector current_tangent_derivative_variation; -+ Matrix current_tangent_second_variation; -+ Matrix current_tangent_derivative_second_variation; -+ Matrix3d current_lambda_matrix; -+ Matrix3d current_lambda_matrix_derivative; -+ Matrix3d reference_lambda_matrix; -+ Matrix3d reference_lambda_matrix_derivative; -+ Matrix3d current_rodrigues_matrix; -+ Matrix3d current_rodrigues_matrix_derivative; -+ Matrix3d reference_rodrigues_matrix; -+ Matrix3d reference_rodrigues_matrix_derivative; -+ -+ current_tangent = current_first_base_vector / norm_2(current_first_base_vector); -+ current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; -+ reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); -+ reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; -+ ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); -+ ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); -+ ComputeTangentSecondVariation(shape_function_derivatives, current_first_base_vector, current_tangent_second_variation); -+ ComputeTangentDerivativeSecondVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_second_variation); -+ -+ ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); -+ ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); -+ -+ ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); -+ ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); -+ ComputeLambdaMatrixVariations(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation, mSMatrixLambdaDerivativeVariation, mSMatrixLambdaSecondVariation, mSMatrixLambdaDerivativeSecondVariation); -+ -+ ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); -+ ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); -+ ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); -+ ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); -+ ComputeRodriguesMatrixSecondVariation(current_tangent, current_tangent_variation, current_tangent_second_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesSecondVariation); -+ ComputeRodriguesMatrixDerivativeSecondVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeSecondVariation); -+ -+ ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); -+ ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); -+ -+ Matrix3d reference_rodrigues_lambda_derivative_product; -+ reference_rodrigues_lambda_derivative_product.clear(); -+ Matrix3d reference_rodrigues_derivative_lambda_product; -+ reference_rodrigues_derivative_lambda_product.clear(); -+ Matrix3d reference_rodrigues_lambda_product; -+ reference_rodrigues_lambda_product.clear(); -+ Matrix3d reference_rodrigues_lambda_product_derivative; -+ reference_rodrigues_lambda_product_derivative.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); -+ reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); -+ reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); -+ } -+ } -+ } -+ reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; -+ -+ Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; -+ current_lambda_reference_rodrigues_lambda_derivative_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_derivative_lambda_product; -+ current_lambda_reference_rodrigues_derivative_lambda_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_lambda_product; -+ current_lambda_reference_rodrigues_lambda_product.clear(); -+ Matrix3d current_lambda_derivative_reference_rodrigues_lambda_product; -+ current_lambda_derivative_reference_rodrigues_lambda_product.clear(); -+ Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; -+ current_lambda_reference_rodrigues_lambda_product_derivative.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ -+ current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; -+ -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term.clear(); -+ Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term.clear(); -+ Matrix3d current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term; -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term.clear(); -+ Matrix3d current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); -+ Matrix3d cross_section_transformation; -+ cross_section_transformation.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); -+ current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ -+ Matrix3d cross_section_transformation_derivative; -+ cross_section_transformation_derivative.clear(); -+ cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; -+ -+  -+ mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); -+ mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); -+ mSMatrixLambdaVariationRodriguesLambda.clear(); -+ mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ -+ Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); -+ -+ current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; -+ -+ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); -+ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); -+ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); -+ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); -+ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); -+ mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); -+ mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); -+ mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ -+  -+  -+ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); -+ mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); -+ mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda -+ + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; -+ mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; -+ -+ mSMatrixLambdaSecondVariationRodriguesLambda.clear(); -+ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.clear(); -+ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.clear(); -+ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ mSMatrixLambdaSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); -+ mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ } -+ -+ Matrix current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term; -+ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term.clear(); -+ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term; -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term.clear(); -+ -+ Matrix current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term; -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term.clear(); -+ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term; -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term.clear(); -+ -+ Matrix current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term; -+ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term; -+ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term; -+ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term.clear(); -+ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term; -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term.clear(); -+ Matrix current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term; -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term.clear(); -+ Matrix current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term; -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); -+ current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + second_dof_index, column_component); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + second_dof_index, column_component); -+ current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); -+ current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); -+ current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); -+ } -+ } -+ } -+ } -+ } -+ -+ Matrix cross_section_transformation_derivative_second_variation; -+ cross_section_transformation_derivative_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ cross_section_transformation_derivative_second_variation.clear(); -+ -+ Vector3d normal_vector; -+ normal_vector.clear(); -+ Vector3d binormal_vector; -+ binormal_vector.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); -+ binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); -+ } -+ } -+ -+ Vector normal_vector_variation; -+ normal_vector_variation.resize(3 * mNumberOfDofs); -+ normal_vector_variation.clear(); -+ Vector binormal_vector_variation; -+ binormal_vector_variation.resize(3 * mNumberOfDofs); -+ binormal_vector_variation.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (int product_index = 0;product_index < 3;product_index++) -+ { -+ normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); -+ binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); -+ } -+ } -+ } -+ -+ Matrix cross_section_transformation_second_variation; -+ cross_section_transformation_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); -+ cross_section_transformation_second_variation.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (int column_component = 0;column_component < 3;column_component++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) -+ + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) -+ + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) -+ + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); -+ } -+ } -+ } -+ } -+ -+ Matrix normal_vector_second_variation; -+ normal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); -+ normal_vector_second_variation.clear(); -+ Matrix binormal_vector_second_variation; -+ binormal_vector_second_variation.resize(3 * mNumberOfDofs, mNumberOfDofs); -+ binormal_vector_second_variation.clear(); -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ for (size_t product_index = 0;product_index < 3;product_index++) -+ { -+ normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index); -+ binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index) += cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index); -+ } -+ } -+ } -+ } -+ -+ for (size_t row_component = 0;row_component < 3;row_component++) -+ { -+ for (size_t product_index = 0;product_index < 3;product_index++) -+ { -+ for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) -+ { -+ for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) -+ { -+ normal_curvature_second_variation(dof_index, second_dof_index) += 0; -+ normal_curvature_second_variation(dof_index, second_dof_index) += 0; -+ -+ normal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * normal_vector(row_component) -+ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) -+ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index) -+ + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); -+ -+ binormal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * binormal_vector(row_component) -+ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + second_dof_index) -+ + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index) -+ + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); -+ } -+ } -+ } -+ } -+ -+ // Initialize G matrices -+ rGAxial.resize(mNumberOfDofs, mNumberOfDofs); -+ rGBending1.resize(mNumberOfDofs, mNumberOfDofs); -+ rGBending2.resize(mNumberOfDofs, mNumberOfDofs); -+ rGTorsion1.resize(mNumberOfDofs, mNumberOfDofs); -+ rGTorsion2.resize(mNumberOfDofs, mNumberOfDofs); -+ rGAxial.clear(); -+ rGBending1.clear(); -+ rGBending2.clear(); -+ rGTorsion1.clear(); -+ rGTorsion2.clear(); -+ -+ noalias(rGAxial) = axial_second_variation; -+ noalias(rGBending1) = normal_curvature_second_variation; -+ noalias(rGBending2) = binormal_curvature_second_variation;  -+ noalias(rGTorsion1) = normal_torsion_second_variation;  -+ noalias(rGTorsion1) = binormal_torsion_second_variation;  -+  -+ KRATOS_CATCH("") -+  -+ } -+} -\ No newline at end of file From fa435a1a3c37ff3e7071cf2f030af76afba2a2e8 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:19:49 +0100 Subject: [PATCH 10/32] erase unnecessary include --- applications/IgaApplication/custom_modelers/refinement_modeler.h | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/IgaApplication/custom_modelers/refinement_modeler.h b/applications/IgaApplication/custom_modelers/refinement_modeler.h index 89fe5e566f12..89332b70070d 100644 --- a/applications/IgaApplication/custom_modelers/refinement_modeler.h +++ b/applications/IgaApplication/custom_modelers/refinement_modeler.h @@ -25,7 +25,6 @@ #include "geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h" #include "geometries/nurbs_surface_geometry.h" #include "utilities/variable_utils.h" -#include "geometries/nurbs_shape_function_utilities/nurbs_curve_refinement_utilities.h" namespace Kratos { From 7f20b0d22bd3f6a2d4d2e5d23028f027a0894dad Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:25:16 +0100 Subject: [PATCH 11/32] revert ref modeler to master --- .../custom_modelers/refinement_modeler.cpp | 277 ++++++++++-------- 1 file changed, 157 insertions(+), 120 deletions(-) diff --git a/applications/IgaApplication/custom_modelers/refinement_modeler.cpp b/applications/IgaApplication/custom_modelers/refinement_modeler.cpp index 7890456bb7b3..32a9ca79e36f 100644 --- a/applications/IgaApplication/custom_modelers/refinement_modeler.cpp +++ b/applications/IgaApplication/custom_modelers/refinement_modeler.cpp @@ -68,173 +68,210 @@ namespace Kratos << "Missing \"geometry_type\".\n" << rParameters << std::endl; if (rParameters["geometry_type"].GetString() == "NurbsSurface") { - } else if (rParameters["geometry_type"].GetString() == "NurbsCurve") { for (IndexType n = 0; n < geometry_list.size(); ++n) { - auto p_nurbs_curve = - std::dynamic_pointer_cast>>( - geometry_list(n) - ); - - if (!p_nurbs_curve) { - p_nurbs_curve = - std::dynamic_pointer_cast>>( - geometry_list(n)->pGetGeometryPart( - GeometryType::BACKGROUND_GEOMETRY_INDEX - ) - ); - } + auto p_nurbs_surface = (geometry_list[n].size() > 0) + ? dynamic_pointer_cast>>(geometry_list(n)) + : dynamic_pointer_cast>>(geometry_list(n)->pGetGeometryPart(GeometryType::BACKGROUND_GEOMETRY_INDEX)); - KRATOS_ERROR_IF_NOT(p_nurbs_curve) - << "Selected geometry is not a NurbsCurveGeometry and does not contain " - << "a NurbsCurveGeometry as BACKGROUND_GEOMETRY.\nSelected geometry:\n" - << *geometry_list(n) << std::endl; + if (rParameters["parameters"].Has("increase_degree_u")) { + SizeType increase_degree_u = rParameters["parameters"]["increase_degree_u"].GetInt(); - if (rParameters["parameters"].Has("increase_degree")) { - const SizeType increase_degree = - rParameters["parameters"]["increase_degree"].GetInt(); + if (increase_degree_u > 0) { + std::vector spans_local_space; + p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); - if (increase_degree > 0) { - KRATOS_INFO_IF( - "::[RefinementModeler]::ApplyRefinement", - mEchoLevel > 1 - ) - << "Refining nurbs curve #" << p_nurbs_curve->Id() - << " by elevating degree: " << increase_degree << std::endl; + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by elevating degree in u: " + << increase_degree_u << std::endl; PointerVector PointsRefined; - Vector KnotsRefined; + Vector KnotsURefined; Vector WeightsRefined; - NurbsCurveRefinementUtilities::DegreeElevation( - *p_nurbs_curve, - increase_degree, - PointsRefined, - KnotsRefined, - WeightsRefined - ); + NurbsSurfaceRefinementUtilities::DegreeElevationU(*(p_nurbs_surface.get()), increase_degree_u, + PointsRefined, KnotsURefined, WeightsRefined); - for (auto& r_point : p_nurbs_curve->Points()) { + // Recreate nodes in model part to ensure correct assignment of dofs + for (auto& r_point : p_nurbs_surface->Points()) { r_point.Set(TO_ERASE, true); } - r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - - IndexType node_id = r_model_part.Nodes().empty() - ? 1 - : (r_model_part.NodesEnd() - 1)->Id() + 1; + IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; for (IndexType i = 0; i < PointsRefined.size(); ++i) { if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode( - node_id, - PointsRefined[i][0], - PointsRefined[i][1], - PointsRefined[i][2] - ); + PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); node_id++; } } - KRATOS_INFO_IF( - "::[RefinementModeler]::ApplyRefinement", - mEchoLevel > 1 - ) - << "New knot vector: " << KnotsRefined + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "New knot vector: " << KnotsURefined << ", new weights vector: " << WeightsRefined << std::endl; - p_nurbs_curve->SetInternals( - PointsRefined, - p_nurbs_curve->PolynomialDegree(0) + increase_degree, - KnotsRefined, - WeightsRefined - ); + p_nurbs_surface->SetInternals(PointsRefined, + p_nurbs_surface->PolynomialDegreeU() + increase_degree_u, p_nurbs_surface->PolynomialDegreeV(), + KnotsURefined, p_nurbs_surface->KnotsV(), + WeightsRefined); + } else { + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() + << " by elevating degree in u, however increase_degree_u is set to 0." << std::endl; } } + if (rParameters["parameters"].Has("increase_degree_v")) { + SizeType increase_degree_v = rParameters["parameters"]["increase_degree_v"].GetInt(); - if (rParameters["parameters"].Has("insert_nb_per_span")) { - const IndexType nb_per_span = - rParameters["parameters"]["insert_nb_per_span"].GetInt(); - - if (nb_per_span > 0) { + if (increase_degree_v > 0) { std::vector spans_local_space; - p_nurbs_curve->SpansLocalSpace(spans_local_space); + p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); - std::vector knots_to_insert; + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by elevating degree in v: " + << increase_degree_v << std::endl; - for ( - IndexType i = 0; - i < spans_local_space.size() - 1; - ++i) - { - const double delta = - (spans_local_space[i + 1] - spans_local_space[i]) / - static_cast(nb_per_span + 1); + PointerVector PointsRefined; + Vector KnotsVRefined; + Vector WeightsRefined; - for ( - IndexType j = 1; - j < nb_per_span + 1; - ++j) - { - knots_to_insert.push_back( - spans_local_space[i] + delta * j - ); + NurbsSurfaceRefinementUtilities::DegreeElevationV(*(p_nurbs_surface.get()), increase_degree_v, + PointsRefined, KnotsVRefined, WeightsRefined); + + // Recreate nodes in model part to ensure correct assignment of dofs + for (auto& r_point : p_nurbs_surface->Points()) { + r_point.Set(TO_ERASE, true); + } + r_model_part.RemoveNodesFromAllLevels(TO_ERASE); + IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; + + for (IndexType i = 0; i < PointsRefined.size(); ++i) { + if (PointsRefined(i)->Id() == 0) { + PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); + node_id++; } } + + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "New knot vector: " << KnotsVRefined + << ", new weights vector: " << WeightsRefined << std::endl; - KRATOS_INFO_IF( - "::[RefinementModeler]::ApplyRefinement", - mEchoLevel > 1 - ) - << "Refining nurbs curve #" << p_nurbs_curve->Id() - << " by inserting knots: " << knots_to_insert << std::endl; + p_nurbs_surface->SetInternals(PointsRefined, + p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV() + increase_degree_v, + p_nurbs_surface->KnotsU(), KnotsVRefined, + WeightsRefined); + } else { + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() + << " by elevating degree in v, however increase_degree_v is set to 0." << std::endl; + } + } + if (rParameters["parameters"].Has("insert_nb_per_span_u")) { + const IndexType nb_per_span_u = rParameters["parameters"]["insert_nb_per_span_u"].GetInt(); + + if (nb_per_span_u > 0) { + std::vector spans_local_space; + p_nurbs_surface->SpansLocalSpace(spans_local_space, 0); + + std::vector knots_to_insert_u; + for (IndexType i = 0; i < spans_local_space.size() - 1; ++i) { + const double delta_u = (spans_local_space[i + 1] - spans_local_space[i]) / (nb_per_span_u + 1); + for (IndexType j = 1; j < nb_per_span_u + 1; ++j) { + knots_to_insert_u.push_back(spans_local_space[i] + delta_u * j); + } + } + + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by inserting knots in u: " + << knots_to_insert_u << std::endl; PointerVector PointsRefined; - Vector KnotsRefined; + Vector KnotsURefined; Vector WeightsRefined; - NurbsCurveRefinementUtilities::KnotRefinement( - *p_nurbs_curve, - knots_to_insert, - PointsRefined, - KnotsRefined, - WeightsRefined - ); + NurbsSurfaceRefinementUtilities::KnotRefinementU(*(p_nurbs_surface.get()), knots_to_insert_u, + PointsRefined, KnotsURefined, WeightsRefined); - for (auto& r_point : p_nurbs_curve->Points()) { + // Recreate nodes in model part to ensure correct assignment of dofs + for (auto& r_point : p_nurbs_surface->Points()) { r_point.Set(TO_ERASE, true); } - r_model_part.RemoveNodesFromAllLevels(TO_ERASE); - - IndexType node_id = r_model_part.Nodes().empty() - ? 1 - : (r_model_part.NodesEnd() - 1)->Id() + 1; - + IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; + for (IndexType i = 0; i < PointsRefined.size(); ++i) { if (PointsRefined(i)->Id() == 0) { - PointsRefined(i) = r_model_part.CreateNewNode( - node_id, - PointsRefined[i][0], - PointsRefined[i][1], - PointsRefined[i][2] - ); + PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); node_id++; } } - KRATOS_INFO_IF( - "::[RefinementModeler]::ApplyRefinement", - mEchoLevel > 1 - ) - << "New knot vector: " << KnotsRefined + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "New knot vector: " << KnotsURefined << ", new weights vector: " << WeightsRefined << std::endl; - p_nurbs_curve->SetInternals( - PointsRefined, - p_nurbs_curve->PolynomialDegree(0), - KnotsRefined, - WeightsRefined - ); + p_nurbs_surface->SetInternals(PointsRefined, + p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV(), + KnotsURefined, p_nurbs_surface->KnotsV(), + WeightsRefined); + } else { + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() + << " by inserting knots in u, however insert_nb_per_span_u is set to 0." << std::endl; + } + } + if (rParameters["parameters"].Has("insert_nb_per_span_v")) { + const IndexType nb_per_span_v = rParameters["parameters"]["insert_nb_per_span_v"].GetInt(); + + if (nb_per_span_v > 0) { + std::vector spans_local_space; + p_nurbs_surface->SpansLocalSpace(spans_local_space, 1); + + std::vector knots_to_insert_v; + for (IndexType i = 0; i < spans_local_space.size() - 1; ++i) { + const double delta_v = (spans_local_space[i + 1] - spans_local_space[i]) / (nb_per_span_v + 1); + for (IndexType j = 1; j < nb_per_span_v + 1; ++j) { + knots_to_insert_v.push_back(spans_local_space[i] + delta_v * j); + } + } + + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Refining nurbs surface #" << p_nurbs_surface->Id() << " by inserting knots in v: " + << knots_to_insert_v << std::endl; + + PointerVector PointsRefined; + Vector KnotsVRefined; + Vector WeightsRefined; + + NurbsSurfaceRefinementUtilities::KnotRefinementV(*(p_nurbs_surface.get()), knots_to_insert_v, + PointsRefined, KnotsVRefined, WeightsRefined); + + // Recreate nodes in model part to ensure correct assignment of dofs + for (auto& r_point : p_nurbs_surface->Points()) { + r_point.Set(TO_ERASE, true); + } + r_model_part.RemoveNodesFromAllLevels(TO_ERASE); + IndexType node_id = r_model_part.Nodes().empty() ? 1 : (r_model_part.NodesEnd() - 1)->Id() + 1; + + for (IndexType i = 0; i < PointsRefined.size(); ++i) { + if (PointsRefined(i)->Id() == 0) { + PointsRefined(i) = r_model_part.CreateNewNode(node_id, PointsRefined[i][0], PointsRefined[i][1], PointsRefined[i][2]); + node_id++; + } + } + + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "New knot vector: " << KnotsVRefined + << ", new weights vector: " << WeightsRefined << std::endl; + + p_nurbs_surface->SetInternals(PointsRefined, + p_nurbs_surface->PolynomialDegreeU(), p_nurbs_surface->PolynomialDegreeV(), + p_nurbs_surface->KnotsU(), KnotsVRefined, + WeightsRefined); + } + else { + KRATOS_INFO_IF("::[RefinementModeler]::ApplyRefinement", mEchoLevel > 1) + << "Trying to refine nurbs surface #" << p_nurbs_surface->Id() + << " by inserting knots in v, however insert_nb_per_span_v is set to 0." << std::endl; } } } From 2fa0004615b0ded2893978a7f6c85d24823aa402 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:31:47 +0100 Subject: [PATCH 12/32] add test to the CI suite --- applications/IgaApplication/tests/test_IgaApplication.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/applications/IgaApplication/tests/test_IgaApplication.py b/applications/IgaApplication/tests/test_IgaApplication.py index 8e5e2affe6af..ae70894adc5e 100644 --- a/applications/IgaApplication/tests/test_IgaApplication.py +++ b/applications/IgaApplication/tests/test_IgaApplication.py @@ -12,6 +12,8 @@ from truss_element_tests import TrussElementTests as TTrussElementTests # Beam Elements tests - python based from test_beam_IGA_element import BeamIGAElementTests as TBeamIGAElementTests +from isogeometric_non_linear_bernoulli_beam_element_test import TestBeam4pElement as TTestBeam4pElement +from isogeometric_non_linear_bernoulli_beam_element_test import TestBeam4pElementNonlinear as TTestBeam4pElementNonlinear # Structural Elements test - python based from test_solid_IGA_element import SolidIGAElementTests as TSolidIGAElementTests # Sbm Structural Elements test @@ -92,6 +94,8 @@ def AssembleTestSuites(): TTrussElementTests, # Beam Elements tests TBeamIGAElementTests, + TTestBeam4pElement, + TTestBeam4pElementNonlinear, # Structural Elements tests TSolidIGAElementTests, # Sbm Elements tests From 2571e1dd0c364534d79f2fe64cfdfd85b13a7692 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Wed, 18 Nov 2026 17:51:04 +0100 Subject: [PATCH 13/32] change test name --- .../tests/test_IgaApplication.py | 4 +- ...etric_non_linear_bernoulli_beam_element.py | 769 ++++++++++++++++++ 2 files changed, 771 insertions(+), 2 deletions(-) create mode 100644 applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py diff --git a/applications/IgaApplication/tests/test_IgaApplication.py b/applications/IgaApplication/tests/test_IgaApplication.py index ae70894adc5e..a561b5999e7d 100644 --- a/applications/IgaApplication/tests/test_IgaApplication.py +++ b/applications/IgaApplication/tests/test_IgaApplication.py @@ -12,8 +12,8 @@ from truss_element_tests import TrussElementTests as TTrussElementTests # Beam Elements tests - python based from test_beam_IGA_element import BeamIGAElementTests as TBeamIGAElementTests -from isogeometric_non_linear_bernoulli_beam_element_test import TestBeam4pElement as TTestBeam4pElement -from isogeometric_non_linear_bernoulli_beam_element_test import TestBeam4pElementNonlinear as TTestBeam4pElementNonlinear +from test_isogeometric_non_linear_bernoulli_beam_element import TestBeam4pElement as TTestBeam4pElement +from test_isogeometric_non_linear_bernoulli_beam_element import TestBeam4pElementNonlinear as TTestBeam4pElementNonlinear # Structural Elements test - python based from test_solid_IGA_element import SolidIGAElementTests as TSolidIGAElementTests # Sbm Structural Elements test diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py new file mode 100644 index 000000000000..b141d1d1551c --- /dev/null +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -0,0 +1,769 @@ +import KratosMultiphysics as KM +import KratosMultiphysics.IgaApplication as IGA +import KratosMultiphysics.StructuralMechanicsApplication as SMA +import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory + +import KratosMultiphysics.KratosUnittest as KratosUnittest +import numpy as np + +class TestBeam4pElement(KratosUnittest.TestCase): + + def analytical_solution_bending(x, F, E, I, L): + return F / (6 * E * I) * (3 * L * x**2 - x**3) + + def analytical_solution_torsion(x, M, E, It, nu = 0): + G = 1 / (2 * (1 + nu)) * E + return M / (G * It) * x + + def analytical_solution_normalforce(x, F, E, A): + return (F / (E * A)) * x + + def solve_linear_examples(last_node_force, last_node_moment): + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + w = 2.5 + h = 5 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, w*h) + beam_properties.SetValue(IGA.HEIGHT, h) + beam_properties.SetValue(IGA.WIDTH, w) + beam_properties.SetValue(IGA.I_T, w*h**3/3) + beam_properties.SetValue(IGA.I_N, w * h**3 / 12) + beam_properties.SetValue(IGA.I_V, h * w**3 / 12) + beam_properties.SetValue(KM.YOUNG_MODULUS , 70000) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 7856) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + control_points = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0],[2.0, 0.0, 0.0],[3.0, 0.0, 0.0],[4.0, 0.0, 0.0]] + knotvector = [0,0,0,0,1,1,1,1] + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(control_points, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[len(control_points)-1].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, last_node_force) + moment_condition = model_part.CreateNewCondition('PointMomentCondition3D1N', 2, [nodes[len(control_points)-1].Id], prop) + moment_condition.SetValue(SMA.POINT_MOMENT, last_node_moment ) + + model_part.SetBufferSize(1) + + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + + linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( + r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) + + relative_tolerance = 1e-7 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 1 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = False + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(0) + model_part.CloneTimeStep(1) + solver.Solve() + + return nodes, curve + + def solve_nonlinear_example1(): + load = -15 + + control_points = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] + knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] + + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + w = 0.1 + h = 0.1 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, w*h) + beam_properties.SetValue(IGA.HEIGHT, h) + beam_properties.SetValue(IGA.WIDTH, w) + beam_properties.SetValue(IGA.I_T, w*h**3/3) + beam_properties.SetValue(IGA.I_V, w * h**3 / 12) + beam_properties.SetValue(IGA.I_N, h * w**3 / 12) + beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 1) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(control_points, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + last_node = node + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, load])) + + model_part.SetBufferSize(1) + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + linear_solver = linear_solver_factory.ConstructSolver( + KM.Parameters(r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) + + relative_tolerance = 1e-8 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 10 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = True + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(1) + model_part.CloneTimeStep(1) + solver.Solve() + + return last_node + + def solve_nonlinear_example2(): + k = 0.6 + load = k * 25000 + control_points = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] + knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] + + model = KM.Model() + model_part = model.CreateModelPart('Model') + + model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) + model_part.AddNodalSolutionStepVariable(KM.ROTATION) + model_part.AddNodalSolutionStepVariable(KM.REACTION) + model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) + model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) + + r = 0.5*0.1 + beam_properties = model_part.GetProperties()[0] + beam_properties.SetValue(IGA.CROSS_AREA, np.pi * r**2) + beam_properties.SetValue(IGA.HEIGHT, 2*r) + beam_properties.SetValue(IGA.WIDTH, 2*r) + beam_properties.SetValue(IGA.I_T, np.pi * r**4/2) + beam_properties.SetValue(IGA.I_V, np.pi * r**4/4) + beam_properties.SetValue(IGA.I_N, np.pi * r**4/4) + beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) + beam_properties.SetValue(KM.POISSON_RATIO , 0) + beam_properties.SetValue(KM.DENSITY , 0) + beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) + beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i, ctrlpt in enumerate(control_points, 1): + node = model_part.CreateNewNode(i, *ctrlpt) + nodes.append(node) + last_node = node + knots = KM.Vector(len(knotvector)) + for i, knot in enumerate(knotvector): + knots[i] = knot + + curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) + + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + + element_id = 1 + for i in range(0, len(quadrature_point_geometries)): + model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) + element_id += 1 + + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + + KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) + KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) + KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + + nodes[0].Fix(KM.DISPLACEMENT_X) + nodes[0].Fix(KM.DISPLACEMENT_Y) + nodes[0].Fix(KM.DISPLACEMENT_Z) + nodes[0].Fix(KM.ROTATION_X) + nodes[1].Fix(KM.DISPLACEMENT_X) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + prop = model_part.GetProperties()[2] + force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) + force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, -load])) + + model_part.SetBufferSize(1) + + time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() + + linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( + r'{"solver_type": "skyline_lu_factorization"}')) + + relative_tolerance = 1e-7 + absolute_tolerance = 1e-7 + + conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) + conv_criteria.SetEchoLevel(0) + + maximum_iterations = 3 + compute_reactions = False + reform_dofs_at_each_iteration = False + move_mesh_flag = True + + solver = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + time_scheme, + linear_solver, + conv_criteria, + maximum_iterations, + compute_reactions, + reform_dofs_at_each_iteration, + move_mesh_flag + ) + + solver.SetEchoLevel(1) + model_part.CloneTimeStep(1) + solver.Solve() + + return last_node + + def testClampedFXLinear(self): + last_node_force = KM.Array3([1, 0, 0]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], TestBeam4pElement.analytical_solution_normalforce(nodes[4].X, 1, 70000, 2.5*5)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0 ) + + def testClampedFYLinear(self): + last_node_force = KM.Array3([0, -1, 0]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(nodes[1].X, 1.0 ) + self.assertAlmostEqual(nodes[1].Y, 0.0 ) + self.assertAlmostEqual(nodes[1].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], TestBeam4pElement.analytical_solution_bending(nodes[4].X, -1, 70000,5**3*2.5/12,4)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0) + + def testClampedFZLinear(self): + last_node_force = KM.Array3([0, 0, -1]) + last_node_moment = KM.Array3([0, 0, 0]) + nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].X, 0.0 ) + self.assertAlmostEqual(nodes[0].Y, 0.0 ) + self.assertAlmostEqual(nodes[0].Z, 0.0 ) + + self.assertAlmostEqual(nodes[1].X, 1.0 ) + self.assertAlmostEqual(nodes[1].Y, 0.0 ) + self.assertAlmostEqual(nodes[1].Z, 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], TestBeam4pElement.analytical_solution_bending(nodes[4].X,-1, 70000,2.5**3*5/12,4)) + + def testClampedMXLinear(self): + last_node_force = KM.Array3([0, 0, 0]) + last_node_moment = KM.Array3([1, 0, 0]) + nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[0], 0.0 ) + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[1], 0.0 ) + self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[2], 0.0 ) + + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[0], TestBeam4pElement.analytical_solution_torsion(nodes[4].X, 1, 70000,2.5*5**3/3)) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[1], 0.0 ) + self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[2], 0.0 ) + +E_MOD = 70000.0 +NU = 0.0 +WIDTH = 2.5 +HEIGHT = 5.0 +LENGTH = 4.0 +I_N_ = WIDTH * HEIGHT ** 3 / 12.0 +I_V_ = HEIGHT * WIDTH ** 3 / 12.0 +I_T_ = WIDTH * HEIGHT ** 3 / 3.0 +G_MOD = E_MOD / (2.0 * (1.0 + NU)) +DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) + +class TestBeam4pElementNonlinear(KratosUnittest.TestCase): + + @staticmethod + def build_cantilever(n_cp=5, degree=4): + + model = KM.Model() + mp = model.CreateModelPart('IgaModelPart') + for var in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, + KM.REACTION_MOMENT, SMA.POINT_LOAD): + mp.AddNodalSolutionStepVariable(var) + + props = mp.GetProperties()[0] + props.SetValue(IGA.CROSS_AREA, WIDTH * HEIGHT) + props.SetValue(IGA.HEIGHT, HEIGHT) + props.SetValue(IGA.WIDTH, WIDTH) + props.SetValue(IGA.I_T, I_T_) + props.SetValue(IGA.I_N, I_N_) + props.SetValue(IGA.I_V, I_V_) + props.SetValue(KM.YOUNG_MODULUS, E_MOD) + props.SetValue(KM.POISSON_RATIO, NU) + props.SetValue(KM.DENSITY, 7856) + props.SetValue(IGA.LOCAL_AXIS_ORIENTATION, + np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], + [0.75, 0, 0, 1], [1, 0, 0, 1]])) + props.SetValue(KM.CONSTITUTIVE_LAW, IGA.BernoulliBeamElasticConstitutiveLaw()) + + nodes = KM.NodesVector() + for i in range(n_cp): + nodes.append(mp.CreateNewNode(i + 1, LENGTH * i / (n_cp - 1), 0.0, 0.0)) + + kv = ([0.0] * degree + + [float(i) / (n_cp - degree) for i in range(1, n_cp - degree)] + + [1.0] * degree) + knots = KM.Vector(len(kv)) + for i, k in enumerate(kv): + knots[i] = k + + curve = KM.NurbsCurveGeometry3D(nodes, degree, knots) + curve.SetId(2) + mp.AddGeometry(curve) + + from KratosMultiphysics.modeler_factory import KratosModelerFactory + modeler_parameters = KM.Parameters(r'''[{ + "modeler_name": "RefinementModeler", + "Parameters": { + "echo_level": 0, + "refinements_file_name": "modeler_tests/curve_h_refinements.iga.json" + } + }]''') + refinement_modeler = KratosModelerFactory().ConstructListOfModelers( + model, modeler_parameters)[0] + refinement_modeler.PrepareGeometryModel() + + curve = mp.GetGeometry(2) + # vtk_curve = KM.BrepCurve(curve) + # vtk_curve.SetId(3) + # mp.AddGeometry(vtk_curve) + nodes = KM.NodesVector() + for node in mp.Nodes: + nodes.append(node) + + qpg = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(qpg, 3) + for eid in range(len(qpg)): + mp.CreateNewElement('NonLinearBernoulliBeamElement3D', eid + 1, qpg[eid], props) + + IGA.ComputeBeamVectorsProcess(mp, curve).ExecuteInitialize() + + for dof, reaction in zip(DOFS, (KM.REACTION_X, KM.REACTION_Y, + KM.REACTION_Z, KM.REACTION_MOMENT_X)): + KM.VariableUtils().AddDof(dof, reaction, mp) + + for var in DOFS: + nodes[0].Fix(var) + nodes[1].Fix(KM.DISPLACEMENT_Y) + nodes[1].Fix(KM.DISPLACEMENT_Z) + + mp.SetBufferSize(1) + mp.CloneTimeStep(1) + for element in mp.Elements: + element.Initialize(mp.ProcessInfo) + return model, mp, nodes + + @staticmethod + def free_dofs(nodes): + fixed = {4 * i + j + for i in range(len(nodes)) + for j, var in enumerate(DOFS) if nodes[i].IsFixed(var)} + return [i for i in range(4 * len(nodes)) if i not in fixed] + + @staticmethod + def element_dof_index(element): + idx = [] + for node in element.GetGeometry(): + base = 4 * (node.Id - 1) + idx += [base, base + 1, base + 2, base + 3] + return np.array(idx) + + @classmethod + def apply_state(cls, nodes, u): + for i in range(len(nodes)): + nodes[i].SetSolutionStepValue( + KM.DISPLACEMENT, KM.Array3([u[4 * i], u[4 * i + 1], u[4 * i + 2]])) + nodes[i].SetSolutionStepValue(KM.ROTATION_X, float(u[4 * i + 3])) + + + @staticmethod + def write_vtk_output(model, mp, output_file_name="beam_deformation"): + from KratosMultiphysics.IgaApplication.iga_vtk_output_process import IgaVTKOutputProcess + + settings = KM.Parameters(r'''{ + "model_part_name": "IgaModelPart", + "output_file_name": "beam_deformation", + "brep_curve_ids": [3], + "nodal_solution_step_data_variables": ["DISPLACEMENT", "ROTATION"], + "output_refinement_curve": [10], + "output_control_type": "step", + "output_frequency": 1 + }''') + settings["output_file_name"].SetString(output_file_name) + + output_process = IgaVTKOutputProcess(model, settings) + output_process.ExecuteInitialize() + output_process.ExecuteBeforeSolutionLoop() + mp.ProcessInfo[KM.TIME] = 1.0 + if output_process.IsOutputStep(): + output_process.PrintOutput() + + @classmethod + def assemble(cls, mp, nodes, u, build_level=0): + + cls.apply_state(nodes, u) + mp.ProcessInfo[IGA.BUILD_LEVEL] = build_level + ndof = 4 * len(nodes) + K = np.zeros((ndof, ndof)) + R = np.zeros(ndof) + for element in mp.Elements: + lhs, rhs = KM.Matrix(), KM.Vector() + element.CalculateLocalSystem(lhs, rhs, mp.ProcessInfo) + idx = cls.element_dof_index(element) + K[np.ix_(idx, idx)] += np.array(lhs, copy=True) + R[idx] += np.array(rhs, copy=True) + return K, R + + @classmethod + def newton(cls, mp, nodes, f_ext, n_steps=8, tol=1e-10, max_it=40): + + free = cls.free_dofs(nodes) + u = np.zeros(4 * len(nodes)) + norms = [] + for step in range(1, n_steps + 1): + f = f_ext * step / n_steps + scale = max(1.0, np.linalg.norm(f[free])) + norms = [] + for _ in range(max_it): + K, R = cls.assemble(mp, nodes, u) + residual = R + f + norm = np.linalg.norm(residual[free]) + norms.append(norm) + if norm < tol * scale: + break + u[free] += np.linalg.solve(K[np.ix_(free, free)], residual[free]) + return u, norms + + def testTangentMatchesFiniteDifferences(self): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + ndof = 4 * n_cp + + u0 = np.zeros(ndof) + for i in range(n_cp): + x = nodes[i].X0 + u0[4 * i] = 0.004 * x + u0[4 * i + 1] = 0.010 * x ** 2 + u0[4 * i + 2] = -0.006 * x ** 2 + u0[4 * i + 3] = 0.003 * x + + K, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=0) + + K_mat, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=1) + + K_geo, _ = TestBeam4pElementNonlinear.assemble( + mp, nodes, u0, build_level=2) + + h = 1e-7 + K_fd = np.zeros_like(K) + for j in range(ndof): + up = u0.copy(); up[j] += h + um = u0.copy(); um[j] -= h + _, rp = TestBeam4pElementNonlinear.assemble(mp, nodes, up) + _, rm = TestBeam4pElementNonlinear.assemble(mp, nodes, um) + K_fd[:, j] = -(rp - rm) / (2.0 * h) + + # error diagonistics block + #--------------- + K_reconstructed = K_mat + K_geo + + diff = K - K_fd + reconstruction_diff = K - K_reconstructed + + max_index = np.unravel_index( + np.argmax(np.abs(diff)), + diff.shape) + + i, j = max_index + + print("\n--- Tangent diagnostics ---") + print("||K|| =", np.linalg.norm(K)) + print("||K_mat|| =", np.linalg.norm(K_mat)) + print("||K_geo|| =", np.linalg.norm(K_geo)) + print("||K_fd|| =", np.linalg.norm(K_fd)) + + print( + "||K - (K_mat + K_geo)|| =", + np.linalg.norm(reconstruction_diff) + ) + + print( + "relative total error =", + np.abs(diff).max() / np.abs(K).max() + ) + + print("largest mismatch at (row, col) =", max_index) + print("K =", K[i, j]) + print("K_fd =", K_fd[i, j]) + print("diff =", diff[i, j]) + print("K_mat =", K_mat[i, j]) + print("K_geo =", K_geo[i, j]) + + K_geo_required = K_fd - K_mat + geo_diff = K_geo - K_geo_required + + print( + "relative geometric-part error =", + np.abs(geo_diff).max() / + max(np.abs(K_geo_required).max(), 1e-16) + ) + + geo_index = np.unravel_index( + np.argmax(np.abs(geo_diff)), + geo_diff.shape) + + print("largest geometric mismatch =", geo_index) + print("K_geo =", K_geo[geo_index]) + print("K_geo_required =", K_geo_required[geo_index]) + print("geo diff =", geo_diff[geo_index]) + + #--------------------------end + + error = np.abs(diff).max() / np.abs(K).max() + + self.assertLess( + error, + 1e-5, + 'tangent stiffness is not the derivative of the internal ' + 'force (relative error %.3e) -- a missing or wrong ' + 'geometric-stiffness term' % error) + + error = np.abs(K - K_fd).max() / np.abs(K).max() + self.assertLess(error, 1e-5, + 'tangent stiffness is not the derivative of the internal ' + 'force (relative error %.3e) -- a missing or wrong ' + 'geometric-stiffness term' % error) + + def testQuadraticNewtonConvergence(self): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + + _, norms = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=4) + + self.assertGreaterEqual(len(norms), 3) + self.assertLess(norms[-1], 1e-6, 'Newton did not converge') + + self.assertLess(norms[-1], norms[-2] ** 1.5, + 'convergence is not quadratic: %s' + % ' '.join('%.2e' % n for n in norms)) + + def testLargeDeflectionElastica(self): + EI = E_MOD * I_N_ + alpha = 0.5 + load = alpha * EI / LENGTH ** 2 + ux_exact, uy_exact = -0.0636758499, -0.6485743026 + + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + n_cp = len(nodes) + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=8) + # TestBeam4pElementNonlinear.write_vtk_output(model, mp) + + uy = u[4 * (n_cp - 1) + 1] + ux = u[4 * (n_cp - 1)] + + self.assertLess(abs(uy), abs(-load * LENGTH ** 3 / (3 * EI)) * 1.02) + self.assertLess(abs(uy - uy_exact) / abs(uy_exact), 0.06) + self.assertLess(abs(ux - ux_exact) / abs(ux_exact), 0.15) + + @classmethod + def buckling_loads(cls, mp, nodes, load_vector, p_ref): + n_cp = len(nodes) + f_ext = np.zeros(4 * n_cp) + for j, value in enumerate(load_vector): + f_ext[4 * (n_cp - 1) + j] = value + + u, _ = cls.newton(mp, nodes, f_ext, n_steps=1) + + cls.apply_state(nodes, u) + k_mat, _ = cls.assemble(mp, nodes, u, build_level=1) + k_geo, _ = cls.assemble(mp, nodes, u, build_level=2) + + free = cls.free_dofs(nodes) + A = k_mat[np.ix_(free, free)] + B = k_geo[np.ix_(free, free)] + + mu = np.linalg.eigvals(-np.linalg.solve(A, B)) + mu = mu[np.abs(mu.imag) < 1e-8 * (1.0 + np.abs(mu.real))].real + lam = np.sort(1.0 / mu[np.abs(mu) > 1e-12]) + return np.sort(lam[lam > 1e-8]) * p_ref + + def testEulerBucklingWeakAxis(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + euler = np.pi ** 2 * E_MOD * I_V_ / (4.0 * LENGTH ** 2) + self.assertAlmostEqual(loads[0] / euler, 1.0, delta=0.005) + + def testEulerBucklingStrongAxis(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + euler = np.pi ** 2 * E_MOD * I_N_ / (4.0 * LENGTH ** 2) + self.assertAlmostEqual(loads[1] / euler, 1.0, delta=0.005) + + def testLateralTorsionalBuckling(self): + p_ref = 1000.0 + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() + loads = TestBeam4pElementNonlinear.buckling_loads( + mp, nodes, [0.0, -p_ref, 0.0], p_ref) + timoshenko = 4.013 * np.sqrt(E_MOD * I_V_ * G_MOD * I_T_) / LENGTH ** 2 + + self.assertAlmostEqual(loads[0] / timoshenko, 1.0, delta=0.05) + + @KratosUnittest.expectedFailure + def testLinearBendingIsMeshIndependent(self): + EI = E_MOD * I_N_ + load = 1e-4 * EI / LENGTH ** 2 + reference = -load * LENGTH ** 3 / (3.0 * EI) + for n_cp in (5, 7, 9, 13): + model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever(n_cp) + f_ext = np.zeros(4 * n_cp) + f_ext[4 * (n_cp - 1) + 1] = -load + u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=1) + uy = u[4 * (n_cp - 1) + 1] + self.assertLess(abs(uy - reference) / abs(reference), 1e-6, + 'n_cp=%d (%d knot spans) is off by %.3e' + % (n_cp, mp.NumberOfElements() // 5, + abs(uy - reference) / abs(reference))) + +if __name__ == "__main__": + KratosUnittest.main() \ No newline at end of file From b3c52936c6bf68bb1497ea14689382135f4b6cff Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 15:52:40 +0100 Subject: [PATCH 14/32] erase CROSS_AREA --- applications/IgaApplication/iga_application_variables.h | 1 - 1 file changed, 1 deletion(-) diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index b8300f476218..dd7d4019519d 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -38,7 +38,6 @@ KRATOS_DEFINE_SYMMETRIC_2D_TENSOR_APPLICATION_VARIABLE_WITH_COMPONENTS(IGA_APPLI KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, TANGENTS) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, CROSS_SECTIONAL_ROTATION) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, CROSS_AREA) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, FORCE_PK2_1D) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, FORCE_CAUCHY_1D) From 93161b4387ff2fd079f28524f16c431f5dd56da7 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 15:52:55 +0100 Subject: [PATCH 15/32] change test name --- ..._non_linear_bernoulli_beam_element_test.py | 769 ------------------ 1 file changed, 769 deletions(-) delete mode 100644 applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py diff --git a/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py b/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py deleted file mode 100644 index 192083702ee8..000000000000 --- a/applications/IgaApplication/tests/isogeometric_non_linear_bernoulli_beam_element_test.py +++ /dev/null @@ -1,769 +0,0 @@ -import KratosMultiphysics as KM -import KratosMultiphysics.IgaApplication as IGA -import KratosMultiphysics.StructuralMechanicsApplication as SMA -import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory - -import KratosMultiphysics.KratosUnittest as KratosUnittest -import numpy as np - -class TestBeam4pElement(KratosUnittest.TestCase): - - def analytical_solution_bending(x, F, E, I, L): - return F / (6 * E * I) * (3 * L * x**2 - x**3) - - def analytical_solution_torsion(x, M, E, It, nu = 0): - G = 1 / (2 * (1 + nu)) * E - return M / (G * It) * x - - def analytical_solution_normalforce(x, F, E, A): - return (F / (E * A)) * x - - def solve_linear_examples(last_node_force, last_node_moment): - model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - w = 2.5 - h = 5 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, w*h) - beam_properties.SetValue(IGA.HEIGHT, h) - beam_properties.SetValue(IGA.WIDTH, w) - beam_properties.SetValue(IGA.I_T, w*h**3/3) - beam_properties.SetValue(IGA.I_N, w * h**3 / 12) - beam_properties.SetValue(IGA.I_V, h * w**3 / 12) - beam_properties.SetValue(KM.YOUNG_MODULUS , 70000) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 7856) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) - controllpoints = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0],[2.0, 0.0, 0.0],[3.0, 0.0, 0.0],[4.0, 0.0, 0.0]] - knotvector = [0,0,0,0,1,1,1,1] - - nodes = KM.NodesVector() - for i, ctrlpt in enumerate(controllpoints, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) - - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot - - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) - - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) - - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 - - IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() - - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) - - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - prop = model_part.GetProperties()[2] - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[len(controllpoints)-1].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, last_node_force) - moment_condition = model_part.CreateNewCondition('PointMomentCondition3D1N', 2, [nodes[len(controllpoints)-1].Id], prop) - moment_condition.SetValue(SMA.POINT_MOMENT, last_node_moment ) - - model_part.SetBufferSize(1) - - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() - - linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( - r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) - - relative_tolerance = 1e-7 - absolute_tolerance = 1e-7 - - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - - maximum_iterations = 1 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = False - - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - - solver.SetEchoLevel(0) - model_part.CloneTimeStep(1) - solver.Solve() - - return nodes, curve - - def solve_nonlinear_example1(): - load = -15 - - controllpoints = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] - knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] - - model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - w = 0.1 - h = 0.1 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, w*h) - beam_properties.SetValue(IGA.HEIGHT, h) - beam_properties.SetValue(IGA.WIDTH, w) - beam_properties.SetValue(IGA.I_T, w*h**3/3) - beam_properties.SetValue(IGA.I_V, w * h**3 / 12) - beam_properties.SetValue(IGA.I_N, h * w**3 / 12) - beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 1) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) - - nodes = KM.NodesVector() - for i, ctrlpt in enumerate(controllpoints, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) - last_node = node - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot - - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) - - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) - - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 - - IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() - - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) - - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - prop = model_part.GetProperties()[2] - - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, load])) - - model_part.SetBufferSize(1) - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() - linear_solver = linear_solver_factory.ConstructSolver( - KM.Parameters(r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) - - relative_tolerance = 1e-8 - absolute_tolerance = 1e-7 - - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - - maximum_iterations = 10 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = True - - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - - solver.SetEchoLevel(1) - model_part.CloneTimeStep(1) - solver.Solve() - - return last_node - - def solve_nonlinear_example2(): - k = 0.6 - load = k * 25000 - controllpoints = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] - knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] - - model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - r = 0.5*0.1 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, np.pi * r**2) - beam_properties.SetValue(IGA.HEIGHT, 2*r) - beam_properties.SetValue(IGA.WIDTH, 2*r) - beam_properties.SetValue(IGA.I_T, np.pi * r**4/2) - beam_properties.SetValue(IGA.I_V, np.pi * r**4/4) - beam_properties.SetValue(IGA.I_N, np.pi * r**4/4) - beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 0) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) - - nodes = KM.NodesVector() - for i, ctrlpt in enumerate(controllpoints, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) - last_node = node - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot - - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) - - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) - - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 - - IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() - - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) - - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - prop = model_part.GetProperties()[2] - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, -load])) - - model_part.SetBufferSize(1) - - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() - - linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( - r'{"solver_type": "skyline_lu_factorization"}')) - - relative_tolerance = 1e-7 - absolute_tolerance = 1e-7 - - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - - maximum_iterations = 3 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = True - - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - - solver.SetEchoLevel(1) - model_part.CloneTimeStep(1) - solver.Solve() - - return last_node - - def testClampedFXLinear(self): - last_node_force = KM.Array3([1, 0, 0]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], TestBeam4pElement.analytical_solution_normalforce(nodes[4].X, 1, 70000, 2.5*5)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0 ) - - def testClampedFYLinear(self): - last_node_force = KM.Array3([0, -1, 0]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) - - self.assertAlmostEqual(nodes[1].X, 1.0 ) - self.assertAlmostEqual(nodes[1].Y, 0.0 ) - self.assertAlmostEqual(nodes[1].Z, 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], TestBeam4pElement.analytical_solution_bending(nodes[4].X, -1, 70000,5**3*2.5/12,4)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0) - - def testClampedFZLinear(self): - last_node_force = KM.Array3([0, 0, -1]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) - - self.assertAlmostEqual(nodes[1].X, 1.0 ) - self.assertAlmostEqual(nodes[1].Y, 0.0 ) - self.assertAlmostEqual(nodes[1].Z, 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], TestBeam4pElement.analytical_solution_bending(nodes[4].X,-1, 70000,2.5**3*5/12,4)) - - def testClampedMXLinear(self): - last_node_force = KM.Array3([0, 0, 0]) - last_node_moment = KM.Array3([1, 0, 0]) - nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[0], 0.0 ) - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[1], 0.0 ) - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[2], 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[0], TestBeam4pElement.analytical_solution_torsion(nodes[4].X, 1, 70000,2.5*5**3/3)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[2], 0.0 ) - -E_MOD = 70000.0 -NU = 0.0 -WIDTH = 2.5 -HEIGHT = 5.0 -LENGTH = 4.0 -I_N_ = WIDTH * HEIGHT ** 3 / 12.0 -I_V_ = HEIGHT * WIDTH ** 3 / 12.0 -I_T_ = WIDTH * HEIGHT ** 3 / 3.0 -G_MOD = E_MOD / (2.0 * (1.0 + NU)) -DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) - -class TestBeam4pElementNonlinear(KratosUnittest.TestCase): - - @staticmethod - def build_cantilever(n_cp=5, degree=4): - - model = KM.Model() - mp = model.CreateModelPart('IgaModelPart') - for var in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, - KM.REACTION_MOMENT, SMA.POINT_LOAD): - mp.AddNodalSolutionStepVariable(var) - - props = mp.GetProperties()[0] - props.SetValue(IGA.CROSS_AREA, WIDTH * HEIGHT) - props.SetValue(IGA.HEIGHT, HEIGHT) - props.SetValue(IGA.WIDTH, WIDTH) - props.SetValue(IGA.I_T, I_T_) - props.SetValue(IGA.I_N, I_N_) - props.SetValue(IGA.I_V, I_V_) - props.SetValue(KM.YOUNG_MODULUS, E_MOD) - props.SetValue(KM.POISSON_RATIO, NU) - props.SetValue(KM.DENSITY, 7856) - props.SetValue(IGA.LOCAL_AXIS_ORIENTATION, - np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], - [0.75, 0, 0, 1], [1, 0, 0, 1]])) - props.SetValue(KM.CONSTITUTIVE_LAW, IGA.BernoulliBeamElasticConstitutiveLaw()) - - nodes = KM.NodesVector() - for i in range(n_cp): - nodes.append(mp.CreateNewNode(i + 1, LENGTH * i / (n_cp - 1), 0.0, 0.0)) - - kv = ([0.0] * degree - + [float(i) / (n_cp - degree) for i in range(1, n_cp - degree)] - + [1.0] * degree) - knots = KM.Vector(len(kv)) - for i, k in enumerate(kv): - knots[i] = k - - curve = KM.NurbsCurveGeometry3D(nodes, degree, knots) - curve.SetId(2) - mp.AddGeometry(curve) - - from KratosMultiphysics.modeler_factory import KratosModelerFactory - modeler_parameters = KM.Parameters(r'''[{ - "modeler_name": "RefinementModeler", - "Parameters": { - "echo_level": 0, - "refinements_file_name": "modeler_tests/curve_h_refinements.iga.json" - } - }]''') - refinement_modeler = KratosModelerFactory().ConstructListOfModelers( - model, modeler_parameters)[0] - refinement_modeler.PrepareGeometryModel() - - curve = mp.GetGeometry(2) - # vtk_curve = KM.BrepCurve(curve) - # vtk_curve.SetId(3) - # mp.AddGeometry(vtk_curve) - nodes = KM.NodesVector() - for node in mp.Nodes: - nodes.append(node) - - qpg = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(qpg, 3) - for eid in range(len(qpg)): - mp.CreateNewElement('NonLinearBernoulliBeamElement3D', eid + 1, qpg[eid], props) - - IGA.ComputeBeamVectorsProcess(mp, curve).ExecuteInitialize() - - for dof, reaction in zip(DOFS, (KM.REACTION_X, KM.REACTION_Y, - KM.REACTION_Z, KM.REACTION_MOMENT_X)): - KM.VariableUtils().AddDof(dof, reaction, mp) - - for var in DOFS: - nodes[0].Fix(var) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - mp.SetBufferSize(1) - mp.CloneTimeStep(1) - for element in mp.Elements: - element.Initialize(mp.ProcessInfo) - return model, mp, nodes - - @staticmethod - def free_dofs(nodes): - fixed = {4 * i + j - for i in range(len(nodes)) - for j, var in enumerate(DOFS) if nodes[i].IsFixed(var)} - return [i for i in range(4 * len(nodes)) if i not in fixed] - - @staticmethod - def element_dof_index(element): - idx = [] - for node in element.GetGeometry(): - base = 4 * (node.Id - 1) - idx += [base, base + 1, base + 2, base + 3] - return np.array(idx) - - @classmethod - def apply_state(cls, nodes, u): - for i in range(len(nodes)): - nodes[i].SetSolutionStepValue( - KM.DISPLACEMENT, KM.Array3([u[4 * i], u[4 * i + 1], u[4 * i + 2]])) - nodes[i].SetSolutionStepValue(KM.ROTATION_X, float(u[4 * i + 3])) - - - @staticmethod - def write_vtk_output(model, mp, output_file_name="beam_deformation"): - from KratosMultiphysics.IgaApplication.iga_vtk_output_process import IgaVTKOutputProcess - - settings = KM.Parameters(r'''{ - "model_part_name": "IgaModelPart", - "output_file_name": "beam_deformation", - "brep_curve_ids": [3], - "nodal_solution_step_data_variables": ["DISPLACEMENT", "ROTATION"], - "output_refinement_curve": [10], - "output_control_type": "step", - "output_frequency": 1 - }''') - settings["output_file_name"].SetString(output_file_name) - - output_process = IgaVTKOutputProcess(model, settings) - output_process.ExecuteInitialize() - output_process.ExecuteBeforeSolutionLoop() - mp.ProcessInfo[KM.TIME] = 1.0 - if output_process.IsOutputStep(): - output_process.PrintOutput() - - @classmethod - def assemble(cls, mp, nodes, u, build_level=0): - - cls.apply_state(nodes, u) - mp.ProcessInfo[IGA.BUILD_LEVEL] = build_level - ndof = 4 * len(nodes) - K = np.zeros((ndof, ndof)) - R = np.zeros(ndof) - for element in mp.Elements: - lhs, rhs = KM.Matrix(), KM.Vector() - element.CalculateLocalSystem(lhs, rhs, mp.ProcessInfo) - idx = cls.element_dof_index(element) - K[np.ix_(idx, idx)] += np.array(lhs, copy=True) - R[idx] += np.array(rhs, copy=True) - return K, R - - @classmethod - def newton(cls, mp, nodes, f_ext, n_steps=8, tol=1e-10, max_it=40): - - free = cls.free_dofs(nodes) - u = np.zeros(4 * len(nodes)) - norms = [] - for step in range(1, n_steps + 1): - f = f_ext * step / n_steps - scale = max(1.0, np.linalg.norm(f[free])) - norms = [] - for _ in range(max_it): - K, R = cls.assemble(mp, nodes, u) - residual = R + f - norm = np.linalg.norm(residual[free]) - norms.append(norm) - if norm < tol * scale: - break - u[free] += np.linalg.solve(K[np.ix_(free, free)], residual[free]) - return u, norms - - def testTangentMatchesFiniteDifferences(self): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - ndof = 4 * n_cp - - u0 = np.zeros(ndof) - for i in range(n_cp): - x = nodes[i].X0 - u0[4 * i] = 0.004 * x - u0[4 * i + 1] = 0.010 * x ** 2 - u0[4 * i + 2] = -0.006 * x ** 2 - u0[4 * i + 3] = 0.003 * x - - K, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=0) - - K_mat, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=1) - - K_geo, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=2) - - h = 1e-7 - K_fd = np.zeros_like(K) - for j in range(ndof): - up = u0.copy(); up[j] += h - um = u0.copy(); um[j] -= h - _, rp = TestBeam4pElementNonlinear.assemble(mp, nodes, up) - _, rm = TestBeam4pElementNonlinear.assemble(mp, nodes, um) - K_fd[:, j] = -(rp - rm) / (2.0 * h) - - # error diagonistics block - #--------------- - K_reconstructed = K_mat + K_geo - - diff = K - K_fd - reconstruction_diff = K - K_reconstructed - - max_index = np.unravel_index( - np.argmax(np.abs(diff)), - diff.shape) - - i, j = max_index - - print("\n--- Tangent diagnostics ---") - print("||K|| =", np.linalg.norm(K)) - print("||K_mat|| =", np.linalg.norm(K_mat)) - print("||K_geo|| =", np.linalg.norm(K_geo)) - print("||K_fd|| =", np.linalg.norm(K_fd)) - - print( - "||K - (K_mat + K_geo)|| =", - np.linalg.norm(reconstruction_diff) - ) - - print( - "relative total error =", - np.abs(diff).max() / np.abs(K).max() - ) - - print("largest mismatch at (row, col) =", max_index) - print("K =", K[i, j]) - print("K_fd =", K_fd[i, j]) - print("diff =", diff[i, j]) - print("K_mat =", K_mat[i, j]) - print("K_geo =", K_geo[i, j]) - - K_geo_required = K_fd - K_mat - geo_diff = K_geo - K_geo_required - - print( - "relative geometric-part error =", - np.abs(geo_diff).max() / - max(np.abs(K_geo_required).max(), 1e-16) - ) - - geo_index = np.unravel_index( - np.argmax(np.abs(geo_diff)), - geo_diff.shape) - - print("largest geometric mismatch =", geo_index) - print("K_geo =", K_geo[geo_index]) - print("K_geo_required =", K_geo_required[geo_index]) - print("geo diff =", geo_diff[geo_index]) - - #--------------------------end - - error = np.abs(diff).max() / np.abs(K).max() - - self.assertLess( - error, - 1e-5, - 'tangent stiffness is not the derivative of the internal ' - 'force (relative error %.3e) -- a missing or wrong ' - 'geometric-stiffness term' % error) - - error = np.abs(K - K_fd).max() / np.abs(K).max() - self.assertLess(error, 1e-5, - 'tangent stiffness is not the derivative of the internal ' - 'force (relative error %.3e) -- a missing or wrong ' - 'geometric-stiffness term' % error) - - def testQuadraticNewtonConvergence(self): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - - _, norms = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=4) - - self.assertGreaterEqual(len(norms), 3) - self.assertLess(norms[-1], 1e-6, 'Newton did not converge') - - self.assertLess(norms[-1], norms[-2] ** 1.5, - 'convergence is not quadratic: %s' - % ' '.join('%.2e' % n for n in norms)) - - def testLargeDeflectionElastica(self): - EI = E_MOD * I_N_ - alpha = 0.5 - load = alpha * EI / LENGTH ** 2 - ux_exact, uy_exact = -0.0636758499, -0.6485743026 - - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=8) - # TestBeam4pElementNonlinear.write_vtk_output(model, mp) - - uy = u[4 * (n_cp - 1) + 1] - ux = u[4 * (n_cp - 1)] - - self.assertLess(abs(uy), abs(-load * LENGTH ** 3 / (3 * EI)) * 1.02) - self.assertLess(abs(uy - uy_exact) / abs(uy_exact), 0.06) - self.assertLess(abs(ux - ux_exact) / abs(ux_exact), 0.15) - - @classmethod - def buckling_loads(cls, mp, nodes, load_vector, p_ref): - n_cp = len(nodes) - f_ext = np.zeros(4 * n_cp) - for j, value in enumerate(load_vector): - f_ext[4 * (n_cp - 1) + j] = value - - u, _ = cls.newton(mp, nodes, f_ext, n_steps=1) - - cls.apply_state(nodes, u) - k_mat, _ = cls.assemble(mp, nodes, u, build_level=1) - k_geo, _ = cls.assemble(mp, nodes, u, build_level=2) - - free = cls.free_dofs(nodes) - A = k_mat[np.ix_(free, free)] - B = k_geo[np.ix_(free, free)] - - mu = np.linalg.eigvals(-np.linalg.solve(A, B)) - mu = mu[np.abs(mu.imag) < 1e-8 * (1.0 + np.abs(mu.real))].real - lam = np.sort(1.0 / mu[np.abs(mu) > 1e-12]) - return np.sort(lam[lam > 1e-8]) * p_ref - - def testEulerBucklingWeakAxis(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [-p_ref, 0.0, 0.0], p_ref) - euler = np.pi ** 2 * E_MOD * I_V_ / (4.0 * LENGTH ** 2) - self.assertAlmostEqual(loads[0] / euler, 1.0, delta=0.005) - - def testEulerBucklingStrongAxis(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [-p_ref, 0.0, 0.0], p_ref) - euler = np.pi ** 2 * E_MOD * I_N_ / (4.0 * LENGTH ** 2) - self.assertAlmostEqual(loads[1] / euler, 1.0, delta=0.005) - - def testLateralTorsionalBuckling(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [0.0, -p_ref, 0.0], p_ref) - timoshenko = 4.013 * np.sqrt(E_MOD * I_V_ * G_MOD * I_T_) / LENGTH ** 2 - - self.assertAlmostEqual(loads[0] / timoshenko, 1.0, delta=0.05) - - @KratosUnittest.expectedFailure - def testLinearBendingIsMeshIndependent(self): - EI = E_MOD * I_N_ - load = 1e-4 * EI / LENGTH ** 2 - reference = -load * LENGTH ** 3 / (3.0 * EI) - for n_cp in (5, 7, 9, 13): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever(n_cp) - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=1) - uy = u[4 * (n_cp - 1) + 1] - self.assertLess(abs(uy - reference) / abs(reference), 1e-6, - 'n_cp=%d (%d knot spans) is off by %.3e' - % (n_cp, mp.NumberOfElements() // 5, - abs(uy - reference) / abs(reference))) - -if __name__ == "__main__": - KratosUnittest.main() \ No newline at end of file From 2dbb027a5c380e87a0cabcf5c48054ee9e494500 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 15:53:32 +0100 Subject: [PATCH 16/32] revert changes in nurbs curve --- kratos/geometries/nurbs_curve_geometry.h | 106 ----------------------- 1 file changed, 106 deletions(-) diff --git a/kratos/geometries/nurbs_curve_geometry.h b/kratos/geometries/nurbs_curve_geometry.h index 590e26348b2f..2f021f18451c 100644 --- a/kratos/geometries/nurbs_curve_geometry.h +++ b/kratos/geometries/nurbs_curve_geometry.h @@ -895,112 +895,6 @@ class NurbsCurveGeometry : public Geometry& rControlPointIndices, - Vector& rShapeFunctionsValues, - const IndexType DerivativeOrder = 0, - DenseVector* pShapeFunctionDerivatives = nullptr - ) const - { - const double u = rCoordinates[0]; - - KRATOS_WARNING_IF( - "ShapeFunctionsValuesAndCPIndices", - DerivativeOrder > mPolynomialDegree) - << "Requested derivative order (" << DerivativeOrder - << ") exceeds the polynomial degree (" << mPolynomialDegree - << "). Higher derivatives may be zero or undefined." - << std::endl; - - NurbsCurveShapeFunction shape_function_container( - mPolynomialDegree, - DerivativeOrder + 1); - - if (IsRational()) { - shape_function_container.ComputeNurbsShapeFunctionValues( - mKnots, - mWeights, - u); - } else { - shape_function_container.ComputeBSplineShapeFunctionValues( - mKnots, - u); - } - - const SizeType number_of_nonzero_control_points = - shape_function_container.NumberOfNonzeroControlPoints(); - - const auto control_point_indices = - shape_function_container.GetNonzeroControlPointIndices(); - - rControlPointIndices.resize(control_point_indices.size()); - - for (IndexType i = 0; i < control_point_indices.size(); ++i) { - rControlPointIndices[i] = - this->pGetPoint(control_point_indices[i])->Id(); - } - - if (rShapeFunctionsValues.size() != - number_of_nonzero_control_points) { - rShapeFunctionsValues.resize( - number_of_nonzero_control_points, - false); - } - - for (IndexType i = 0; - i < number_of_nonzero_control_points; - ++i) { - rShapeFunctionsValues[i] = - shape_function_container(i, 0); - } - - if (pShapeFunctionDerivatives == nullptr || - DerivativeOrder == 0) { - return; - } - - pShapeFunctionDerivatives->resize(DerivativeOrder); - - for (IndexType derivative_order = 0; - derivative_order < DerivativeOrder; - ++derivative_order) { - - Matrix& r_derivatives = - (*pShapeFunctionDerivatives)[derivative_order]; - - r_derivatives.resize( - number_of_nonzero_control_points, - 1, - false); - - const IndexType container_derivative_index = - derivative_order + 1; - - for (IndexType i = 0; - i < number_of_nonzero_control_points; - ++i) { - r_derivatives(i, 0) = - shape_function_container( - i, - container_derivative_index); - } - } - } - - void SetInternals( - const PointsArrayType& rThisPoints, - const SizeType PolynomialDegree, - const Vector& rKnots, - const Vector& rWeights) - { - this->Points() = rThisPoints; - mPolynomialDegree = PolynomialDegree; - mKnots = rKnots; - mWeights = rWeights; - } - ///@} private: From d36399b59b1fc2c36bbbb51488a723de41bef2d9 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 16:09:40 +0100 Subject: [PATCH 17/32] solve bug in the constitutive law --- ...ernoulli_beam_elastic_constitutive_law.cpp | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp index b0d601158c33..c4ed2192f35b 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -114,25 +114,26 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti r_stress_vector[0] = E * A * r_strain_vector[0]; // N = E*A*ε (normal force) r_stress_vector[1] = E * I_v * r_strain_vector[1]; // M_y = E*I_y*κ_y (bending about y-axis) r_stress_vector[2] = E * I_n * r_strain_vector[2]; // M_z = E*I_z*κ_z (bending about z-axis) - r_stress_vector[3] = G * I_t * r_strain_vector[3]; // T = G*I_t*γ_t1 (torsion) - r_stress_vector[4] = G * I_t * r_strain_vector[4]; // T = G*I_t*γ_t2 (torsion) + // The torsional energy is split between the two shear components κ32 and κ23 (equal in magnitude), + // so each one carries half of the torsional stiffness, consistent with the constitutive matrix below. + r_stress_vector[3] = 0.5 * G * I_t * r_strain_vector[3]; // T = G*I_t*γ_t1 (torsion) + r_stress_vector[4] = 0.5 * G * I_t * r_strain_vector[4]; // T = G*I_t*γ_t2 (torsion) AddInitialStressVectorContribution(r_stress_vector); + } - - if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR)) { - auto &r_constitutive_matrix = rValues.GetConstitutiveMatrix(); - if (r_constitutive_matrix.size1() != strain_size || r_constitutive_matrix.size2() != strain_size) - r_constitutive_matrix.resize(strain_size, strain_size, false); - r_constitutive_matrix.clear(); - - // 5x5 diagonal constitutive matrix with beam cross-section properties - r_constitutive_matrix(0,0) = E * A; // Normal stiffness - r_constitutive_matrix(1,1) = E * I_v; // Bending stiffness about y-axis - r_constitutive_matrix(2,2) = E * I_n; // Bending stiffness about z-axis - r_constitutive_matrix(3,3) = 0.5 * G * I_t; // Torsional stiffness - r_constitutive_matrix(4,4) = 0.5 * G * I_t; // Torsional stiffness - } + if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_CONSTITUTIVE_TENSOR)) { + auto &r_constitutive_matrix = rValues.GetConstitutiveMatrix(); + if (r_constitutive_matrix.size1() != strain_size || r_constitutive_matrix.size2() != strain_size) + r_constitutive_matrix.resize(strain_size, strain_size, false); + r_constitutive_matrix.clear(); + + // 5x5 diagonal constitutive matrix with beam cross-section properties + r_constitutive_matrix(0,0) = E * A; // Normal stiffness + r_constitutive_matrix(1,1) = E * I_v; // Bending stiffness about y-axis + r_constitutive_matrix(2,2) = E * I_n; // Bending stiffness about z-axis + r_constitutive_matrix(3,3) = 0.5 * G * I_t; // Torsional stiffness + r_constitutive_matrix(4,4) = 0.5 * G * I_t; // Torsional stiffness } } From c0fe2505f9149dfa73c5ff5e807f57daec051ef8 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 16:10:16 +0100 Subject: [PATCH 18/32] clean the tests and rewrite it --- .../beam_quadrant_refinements.iga.json | 13 + ...etric_non_linear_bernoulli_beam_element.py | 1064 +++++++---------- 2 files changed, 417 insertions(+), 660 deletions(-) create mode 100644 applications/IgaApplication/tests/modeler_tests/beam_quadrant_refinements.iga.json diff --git a/applications/IgaApplication/tests/modeler_tests/beam_quadrant_refinements.iga.json b/applications/IgaApplication/tests/modeler_tests/beam_quadrant_refinements.iga.json new file mode 100644 index 000000000000..78806804e683 --- /dev/null +++ b/applications/IgaApplication/tests/modeler_tests/beam_quadrant_refinements.iga.json @@ -0,0 +1,13 @@ +{ + "refinements": [ + { + "brep_ids": [ 2 ], + "geometry_type": "NurbsCurve", + "model_part_name": "IgaModelPart", + "parameters": { + "increase_degree": 2, + "insert_nb_per_span": 15 + } + } + ] +} diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index b141d1d1551c..cd2d000a4a1d 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -1,769 +1,513 @@ +import numpy as np + import KratosMultiphysics as KM import KratosMultiphysics.IgaApplication as IGA import KratosMultiphysics.StructuralMechanicsApplication as SMA -import KratosMultiphysics.python_linear_solver_factory as linear_solver_factory - import KratosMultiphysics.KratosUnittest as KratosUnittest -import numpy as np +from KratosMultiphysics import python_linear_solver_factory -class TestBeam4pElement(KratosUnittest.TestCase): +# Straight cantilever along the local tangent t, with the cross section dimension WIDTH along the +# normal n and HEIGHT along v = t x n. I_V is the moment of inertia for deflections along n and +# I_N the one for deflections along v. Torsion constant as in Bauer et al. (2016), Table 1. +E_MOD = 70000.0 +NU = 0.0 +G_MOD = E_MOD / (2.0 * (1.0 + NU)) +WIDTH = 2.5 +HEIGHT = 5.0 +LENGTH = 4.0 +AREA = WIDTH * HEIGHT +I_V_ = HEIGHT * WIDTH ** 3 / 12.0 +I_N_ = WIDTH * HEIGHT ** 3 / 12.0 +I_T_ = HEIGHT * WIDTH ** 3 / 3.0 - def analytical_solution_bending(x, F, E, I, L): - return F / (6 * E * I) * (3 * L * x**2 - x**3) +DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) +REACTIONS = (KM.REACTION_X, KM.REACTION_Y, KM.REACTION_Z, KM.REACTION_MOMENT_X) - def analytical_solution_torsion(x, M, E, It, nu = 0): - G = 1 / (2 * (1 + nu)) * E - return M / (G * It) * x - def analytical_solution_normalforce(x, F, E, A): - return (F / (E * A)) * x +def create_model_part(model): + model_part = model.CreateModelPart("IgaModelPart") + for variable in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, KM.REACTION_MOMENT, SMA.POINT_LOAD): + model_part.AddNodalSolutionStepVariable(variable) + return model_part - def solve_linear_examples(last_node_force, last_node_moment): - model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - w = 2.5 - h = 5 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, w*h) - beam_properties.SetValue(IGA.HEIGHT, h) - beam_properties.SetValue(IGA.WIDTH, w) - beam_properties.SetValue(IGA.I_T, w*h**3/3) - beam_properties.SetValue(IGA.I_N, w * h**3 / 12) - beam_properties.SetValue(IGA.I_V, h * w**3 / 12) - beam_properties.SetValue(KM.YOUNG_MODULUS , 70000) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 7856) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) - control_points = [[0.0, 0.0, 0.0],[1.0, 0.0, 0.0],[2.0, 0.0, 0.0],[3.0, 0.0, 0.0],[4.0, 0.0, 0.0]] - knotvector = [0,0,0,0,1,1,1,1] - nodes = KM.NodesVector() - for i, ctrlpt in enumerate(control_points, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) +def create_properties(model_part, properties_id, normal, young_modulus=E_MOD, poisson_ratio=NU, + area=AREA, i_n=I_N_, i_v=I_V_, i_t=I_T_): + properties = model_part.GetProperties()[properties_id] + properties.SetValue(IGA.CROSS_AREA, area) + properties.SetValue(IGA.I_N, i_n) + properties.SetValue(IGA.I_V, i_v) + properties.SetValue(IGA.I_T, i_t) + properties.SetValue(KM.YOUNG_MODULUS, young_modulus) + properties.SetValue(KM.POISSON_RATIO, poisson_ratio) + properties.SetValue(KM.DENSITY, 1.0) + properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0.0, *normal], [1.0, *normal]], dtype=float)) + properties.SetValue(KM.CONSTITUTIVE_LAW, IGA.BernoulliBeamElasticConstitutiveLaw()) + return properties - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) +def create_straight_curve(model_part, start, direction, n_cp=5, degree=4, first_node_id=1): + """Straight curve with the control points at the Greville abscissae, i.e. with a linear parametrization.""" + knots = [0.0] * degree + [i / (n_cp - degree) for i in range(1, n_cp - degree)] + [1.0] * degree + full_knots = [0.0] + knots + [1.0] - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + nodes = KM.NodesVector() + for i in range(n_cp): + greville_abscissa = sum(full_knots[i + 1:i + 1 + degree]) / degree + position = np.array(start, dtype=float) + LENGTH * greville_abscissa * np.array(direction, dtype=float) + nodes.append(model_part.CreateNewNode(first_node_id + i, *position)) - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 + return KM.NurbsCurveGeometry3D(nodes, degree, KM.Vector(knots)) - IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) - - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - prop = model_part.GetProperties()[2] - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[len(control_points)-1].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, last_node_force) - moment_condition = model_part.CreateNewCondition('PointMomentCondition3D1N', 2, [nodes[len(control_points)-1].Id], prop) - moment_condition.SetValue(SMA.POINT_MOMENT, last_node_moment ) +def refine_curve(model, refinements_file_name): + modeler_parameters = KM.Parameters(r'''{ + "echo_level": 0, + "refinements_file_name": "" + }''') + modeler_parameters["refinements_file_name"].SetString(refinements_file_name) + KM.CreateModeler("RefinementModeler", model, modeler_parameters).PrepareGeometryModel() - model_part.SetBufferSize(1) - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() +def create_elements(model_part, curve, properties, first_element_id=1): + quadrature_point_geometries = KM.GeometriesVector() + curve.CreateQuadraturePointGeometries(quadrature_point_geometries, 3) + for i in range(len(quadrature_point_geometries)): + model_part.CreateNewElement("NonLinearBernoulliBeamElement3D", first_element_id + i, quadrature_point_geometries[i], properties) - linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( - r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) - relative_tolerance = 1e-7 - absolute_tolerance = 1e-7 +def add_dofs(model_part): + for dof, reaction in zip(DOFS, REACTIONS): + KM.VariableUtils().AddDof(dof, reaction, model_part) - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - maximum_iterations = 1 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = False +def clamp(nodes, axial_component): + """Clamps an axis-aligned beam: all dofs of the first control point and the transverse displacements of the second one.""" + for dof in DOFS: + nodes[0].Fix(dof) + for component, dof in enumerate(DOFS[:3]): + if component != axial_component: + nodes[1].Fix(dof) - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - solver.SetEchoLevel(0) - model_part.CloneTimeStep(1) - solver.Solve() +def add_point_load(model_part, condition_id, node, force): + condition = model_part.CreateNewCondition("PointLoadCondition3D1N", condition_id, [node.Id], model_part.GetProperties()[100]) + condition.SetValue(SMA.POINT_LOAD, KM.Array3([float(f) for f in force])) - return nodes, curve - def solve_nonlinear_example1(): - load = -15 +def add_point_moment(model_part, condition_id, node, moment): + condition = model_part.CreateNewCondition("PointMomentCondition3D1N", condition_id, [node.Id], model_part.GetProperties()[100]) + condition.SetValue(SMA.POINT_MOMENT, KM.Array3([float(m) for m in moment])) - control_points = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] - knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] - model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - w = 0.1 - h = 0.1 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, w*h) - beam_properties.SetValue(IGA.HEIGHT, h) - beam_properties.SetValue(IGA.WIDTH, w) - beam_properties.SetValue(IGA.I_T, w*h**3/3) - beam_properties.SetValue(IGA.I_V, w * h**3 / 12) - beam_properties.SetValue(IGA.I_N, h * w**3 / 12) - beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 1) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) +def solve_linear(model_part): + """Solves with a single Newton iteration from the undeformed state, i.e. the linearized problem.""" + model_part.SetBufferSize(1) + model_part.CloneTimeStep(1.0) - nodes = KM.NodesVector() - for i, ctrlpt in enumerate(control_points, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) - last_node = node - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot + linear_solver = python_linear_solver_factory.ConstructSolver( + KM.Parameters(r'{"solver_type": "skyline_lu_factorization"}')) + strategy = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + KM.ResidualBasedIncrementalUpdateStaticScheme(), + linear_solver, + KM.ResidualCriteria(1e-10, 1e-12), + 1, # maximum iterations + False, # compute reactions + False, # reform dofs at each iteration + False) # move mesh + strategy.SetEchoLevel(0) + strategy.Check() + strategy.Solve() - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) +def cantilever_tip_deflection(force, moment_of_inertia): + return force * LENGTH ** 3 / (3.0 * E_MOD * moment_of_inertia) - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 - IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() +class BeamTestCase(KratosUnittest.TestCase): - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) + def assertRelativelyEqual(self, value, reference, tolerance): + self.assertLess(abs(value - reference), tolerance * abs(reference), + "%.12e != %.12e (relative tolerance %.1e)" % (value, reference, tolerance)) - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - prop = model_part.GetProperties()[2] +class TestBeam4pElement(BeamTestCase): + """Linear response of the NonLinearBernoulliBeamElement3D compared to beam theory.""" - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, load])) + @staticmethod + def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0)): + """Cantilever along +X, clamped at x = 0 and loaded at the tip. Returns the tip node.""" + model = KM.Model() + model_part = create_model_part(model) + properties = create_properties(model_part, 1, normal) - model_part.SetBufferSize(1) - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() - linear_solver = linear_solver_factory.ConstructSolver( - KM.Parameters(r'{"solver_type": "LinearSolversApplication.sparse_lu"}')) - - relative_tolerance = 1e-8 - absolute_tolerance = 1e-7 - - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - - maximum_iterations = 10 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = True - - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - - solver.SetEchoLevel(1) - model_part.CloneTimeStep(1) - solver.Solve() - - return last_node - - def solve_nonlinear_example2(): - k = 0.6 - load = k * 25000 - control_points = [[0.0, 0.0, 0.0], [-0.60412500000000002, 0.0, 0.19230000000000003], [-1.1560208333333331, -0.047874999999999987, 0.36798749999999997], [-2.1115562499999996, -0.19984583333333331, 0.67512760416666673], [-2.9186499999999995, -0.41159583333333322, 0.94091666666666662], [-3.5380499999999997, -0.62918489583333348, 1.1495924479166666], [-4.139524999999999, -0.88037447916666678, 1.3563434895833333], [-4.7245499999999998, -1.1637291666666667, 1.5627458333333333], [-5.287725, -1.4909666666666668, 1.7699208333333334], [-5.8283447916666677, -1.8611583333333335, 1.9781567708333334], [-6.3503989583333347, -2.2607291666666667, 2.1869088541666666], [-6.849591666666667, -2.6874000000000002, 2.3957541666666664], [-7.313341666666668, -3.1501874999999999, 2.6043916666666669], [-7.740093229166666, -3.6477776041666661, 2.8127442708333334], [-8.1393161458333321, -4.1685255208333327, 3.0209588541666665], [-8.5090833333333329, -4.7094541666666672, 3.2291499999999997], [-8.8360708333333342, -5.2762541666666669, 3.4373999999999993], [-9.1194135416666668, -5.8673156249999998, 3.6457296874999994], [-9.370705208333332, -6.4737281250000009, 3.8540984374999989], [-9.5884125000000004, -7.0920291666666673, 4.0624749999999992], [-9.7578750000000021, -7.7242041666666674, 4.2708374999999998], [-9.8785942708333359, -8.3684583333333329, 4.4791796874999994], [-9.9642338541666682, -9.0192166666666651, 4.687510937499999], [-10.014333333333333, -9.672762500000001, 4.8958375000000007], [-10.014308333333332, -10.327237500000003, 5.1041625000000002], [-9.9641640625000001, -10.980783333333333, 5.3124880208333334], [-9.8784953124999983, -11.631541666666667, 5.5208151041666671], [-9.7577833333333324, -12.275795833333333, 5.7291458333333329], [-9.5883958333333332, -12.907970833333334, 5.9374833333333346], [-9.3708125000000013, -13.526271874999999, 6.1458270833333337], [-9.1196250000000028, -14.132684375, 6.3541729166666672], [-8.8362708333333337, -14.723745833333334, 6.5625166666666663], [-8.5090333333333348, -15.290545833333333, 6.7708541666666662], [-8.1388416666666679, -15.831474479166666, 6.9791848958333329], [-7.7392708333333342, -16.352222395833333, 7.1875119791666666], [-7.3126000000000007, -16.849812499999999, 7.3958375000000007], [-6.8498125000000014, -17.3126, 7.6041624999999993], [-6.3522223958333344, -17.739270833333332, 7.8124880208333334], [-5.8314744791666673, -18.138841666666668, 8.0208151041666653], [-5.2905458333333346, -18.509033333333335, 8.2291458333333338], [-4.723745833333334, -18.83627083333333, 8.4374833333333346], [-4.1326843750000011, -19.119625520833328, 8.6458270833333337], [-3.3746687500000014, -19.433612499999995, 8.9062593749999976], [-2.3873527777777794, -19.752688888888891, 9.2361347222222214], [-1.3089500000000003, -19.942550000000001, 9.5833500000000011], [0.0, -20.057449999999999, 10.0], [1.3089499999999998, -19.942550000000001, 10.416649999999999], [2.6030333333333333, -19.714716666666664, 10.833308333333331], [3.83765, -19.264949999999999, 11.249999999999996], [5.0286833333333343, -18.709958333333333, 11.666691666666667], [6.1048499999999999, -17.956, 12.083350000000003], [7.1116750000000009, -17.111674999999998, 12.5], [7.9559999999999995, -16.104850000000003, 12.916649999999999], [8.7099583333333346, -15.028683333333333, 13.333300000000001], [9.2649499999999989, -13.837650000000002, 13.74995], [9.7147083333333342, -12.603033333333332, 14.166608333333336], [9.942499999999999, -11.308949999999999, 14.583300000000001], [10.057383333333334, -10.0, 14.999991666666666], [9.9426000000000005, -8.6910500000000006, 15.416649999999999], [9.7148250000000012, -7.3969666666666676, 15.833324999999999], [9.2647499999999976, -6.16235, 16.250099999999996], [8.7096583333333335, -4.9713166666666657, 16.666799999999999], [7.9567999999999994, -3.8951499999999992, 17.083100000000002], [7.1127666666666656, -2.8883249999999996, 17.499650000000003], [6.1017999999999999, -2.044, 17.917599999999997], [5.0245499999999996, -1.2900416666666668, 18.334583333333327], [3.8491000000000009, -0.73504999999999987, 18.746299999999998], [2.6186499999999997, -0.28528333333333333, 19.161662499999998], [1.2664, -0.057450000000000001, 19.596875000000001], [0.60412500000000002, 0.0, 19.807700000000001], [0.0, 0.0, 20.0]] - knotvector = [0.0, 0.0, 0.0, 0.041666666666666664, 0.083333333333333287, 0.10416666666666664, 0.125, 0.14583333333333331, 0.16666666666666666, 0.1875, 0.20833333333333331, 0.22916666666666666, 0.25, 0.27083333333333331, 0.29166666666666663, 0.3125, 0.33333333333333331, 0.35416666666666663, 0.375, 0.39583333333333331, 0.41666666666666663, 0.4375, 0.45833333333333331, 0.47916666666666663, 0.5, 0.52083333333333337, 0.54166666666666674, 0.5625, 0.58333333333333337, 0.60416666666666674, 0.625, 0.64583333333333337, 0.66666666666666674, 0.6875, 0.70833333333333337, 0.72916666666666674, 0.75, 0.77083333333333337, 0.79166666666666674, 0.8125, 0.83333333333333337, 0.85416666666666674, 0.875, 0.89583333333333326, 0.91666666666666663, 0.95833333333333337, 1.0, 1.0, 1.0, 13.0, 14.0, 14.0, 15.0, 15.0, 16.0, 16.0, 17.0, 17.0, 18.0, 18.0, 19.0, 19.0, 20.0, 20.0, 21.0, 21.0, 22.0, 22.0, 23.0, 23.0, 24.0, 24.0, 24.0, 24.0] + curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) + create_elements(model_part, curve, properties) + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) + + nodes = [model_part.GetNode(i) for i in range(1, 6)] + clamp(nodes, 0) + add_point_load(model_part, 1, nodes[-1], force) + if any(moment): + # PointMomentCondition3D1N assembles all three moment components, but the beam only has the + # rotation about its axis (ROTATION_X for this beam along +X). The other two are suppressed. + for dof, reaction in ((KM.ROTATION_Y, KM.REACTION_MOMENT_Y), (KM.ROTATION_Z, KM.REACTION_MOMENT_Z)): + nodes[-1].AddDof(dof, reaction) + nodes[-1].Fix(dof) + add_point_moment(model_part, 2, nodes[-1], moment) + + solve_linear(model_part) + return nodes[-1] + + def test_constitutive_law_stress_matches_tangent(self): + # Strains are [axial, bending n, bending v, torsion 1, torsion 2]. The stresses returned by the + # law must be the ones of its constitutive matrix, including the two torsional components. + model = KM.Model() + model_part = create_model_part(model) + properties = create_properties(model_part, 1, (0.0, 0.0, 1.0)) + geometry = KM.Line3D2(model_part.CreateNewNode(1, 0.0, 0.0, 0.0), model_part.CreateNewNode(2, LENGTH, 0.0, 0.0)) + + options = KM.Flags() + options.Set(KM.ConstitutiveLaw.USE_ELEMENT_PROVIDED_STRAIN, True) + options.Set(KM.ConstitutiveLaw.COMPUTE_STRESS, True) + options.Set(KM.ConstitutiveLaw.COMPUTE_CONSTITUTIVE_TENSOR, True) + + strain = KM.Vector([1e-3, 2e-3, -3e-3, 4e-3, -4e-3]) + stress = KM.Vector(5) + constitutive_matrix = KM.Matrix(5, 5) + parameters = KM.ConstitutiveLawParameters() + parameters.SetOptions(options) + parameters.SetStrainVector(strain) + parameters.SetStressVector(stress) + parameters.SetConstitutiveMatrix(constitutive_matrix) + parameters.SetMaterialProperties(properties) + parameters.SetElementGeometry(geometry) + parameters.SetProcessInfo(model_part.ProcessInfo) + + constitutive_law = properties[KM.CONSTITUTIVE_LAW].Clone() + constitutive_law.CalculateMaterialResponsePK2(parameters) + + stiffnesses = [E_MOD * AREA, E_MOD * I_V_, E_MOD * I_N_, 0.5 * G_MOD * I_T_, 0.5 * G_MOD * I_T_] + expected_stress = np.array(constitutive_matrix) @ np.array(strain) + for i, stiffness in enumerate(stiffnesses): + self.assertRelativelyEqual(constitutive_matrix[i, i], stiffness, 1e-12) + self.assertRelativelyEqual(stress[i], expected_stress[i], 1e-12) + + def test_axial_force(self): + tip = self.solve_cantilever((1.0, 0.0, 0.0)) + displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) + reference = LENGTH / (E_MOD * AREA) + + self.assertRelativelyEqual(displacement[0], reference, 1e-8) + self.assertLess(abs(displacement[1]), 1e-8 * reference) + self.assertLess(abs(displacement[2]), 1e-8 * reference) + + def test_bending_along_binormal(self): + tip = self.solve_cantilever((0.0, -1.0, 0.0)) + displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) + reference = cantilever_tip_deflection(-1.0, I_N_) + + self.assertRelativelyEqual(displacement[1], reference, 1e-8) + self.assertLess(abs(displacement[0]), 1e-8 * abs(reference)) + self.assertLess(abs(displacement[2]), 1e-8 * abs(reference)) + + def test_bending_along_normal(self): + tip = self.solve_cantilever((0.0, 0.0, -1.0)) + displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) + reference = cantilever_tip_deflection(-1.0, I_V_) + + self.assertRelativelyEqual(displacement[2], reference, 1e-8) + self.assertLess(abs(displacement[0]), 1e-8 * abs(reference)) + self.assertLess(abs(displacement[1]), 1e-8 * abs(reference)) + + def test_torsion(self): + tip = self.solve_cantilever((0.0, 0.0, 0.0), moment=(1.0, 0.0, 0.0)) + reference = LENGTH / (G_MOD * I_T_) + + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.ROTATION_X), reference, 1e-8) + self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y)), 1e-8 * reference) + self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z)), 1e-8 * reference) + + def test_rotated_cross_section(self): + # Rotating the cross section by 90 degrees about the beam axis (normal along +Y instead of +Z) + # swaps the bending stiffness of the two transverse directions. + tip = self.solve_cantilever((0.0, -1.0, 0.0), normal=(0.0, 1.0, 0.0)) + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y), cantilever_tip_deflection(-1.0, I_V_), 1e-8) + + tip = self.solve_cantilever((0.0, 0.0, -1.0), normal=(0.0, 1.0, 0.0)) + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z), cantilever_tip_deflection(-1.0, I_N_), 1e-8) + + def test_several_beams_in_one_model_part(self): + # Three cantilevers with different directions and cross-section orientations share one model part. + # A single ComputeBeamVectorsProcess call must give every beam the initial frame of its own curve. + model = KM.Model() + model_part = create_model_part(model) + + beams = [ + # start, direction, normal, axial component, tip force, expected tip deflection + ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, -1.0, 0.0), cantilever_tip_deflection(-1.0, I_N_)), + ((0.0, 10.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, 0.0, 1.0), cantilever_tip_deflection(1.0, I_V_)), + ((10.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), 2, (1.0, 0.0, 0.0), cantilever_tip_deflection(1.0, I_V_)), + ] + + tips = [] + for i, (start, direction, normal, axial_component, force, _) in enumerate(beams): + properties = create_properties(model_part, i + 1, normal) + curve = create_straight_curve(model_part, start, direction, first_node_id=10 * i + 1) + curve.SetId(i + 1) + model_part.AddGeometry(curve) # keeps the parent curve of the quadrature points alive + create_elements(model_part, curve, properties, first_element_id=100 * i + 1) + nodes = [model_part.GetNode(10 * i + j) for j in range(1, 6)] + tips.append((nodes, axial_component, force)) + + IGA.ComputeBeamVectorsProcess(model_part).ExecuteInitialize() + add_dofs(model_part) + + for i, (nodes, axial_component, force) in enumerate(tips): + clamp(nodes, axial_component) + add_point_load(model_part, i + 1, nodes[-1], force) + + solve_linear(model_part) + + for (nodes, _, force), beam in zip(tips, beams): + loaded_component = int(np.argmax(np.abs(force))) + deflection = nodes[-1].GetSolutionStepValue(KM.DISPLACEMENT)[loaded_component] + self.assertRelativelyEqual(deflection, beam[5], 1e-8) + + def test_curved_quadrant_bending_torsion(self): + # Bending-torsion interaction of a clamped quarter circle loaded out of plane at the tip, + # Bauer et al. (2016), Section 5.2, analytical solution Eqs. (81) and (82). + young_modulus, poisson_ratio, radius, force = 1.999e8, 0.25, 1.0, 1.0 + height, width = 0.1, 0.01 + shear_modulus = young_modulus / (2.0 * (1.0 + poisson_ratio)) + i_out_of_plane = height ** 3 * width / 12.0 + i_torsion = height * width ** 3 / 3.0 model = KM.Model() - model_part = model.CreateModelPart('Model') - - model_part.AddNodalSolutionStepVariable(KM.DISPLACEMENT) - model_part.AddNodalSolutionStepVariable(KM.ROTATION) - model_part.AddNodalSolutionStepVariable(KM.REACTION) - model_part.AddNodalSolutionStepVariable(KM.REACTION_MOMENT) - model_part.AddNodalSolutionStepVariable(SMA.POINT_LOAD) - - r = 0.5*0.1 - beam_properties = model_part.GetProperties()[0] - beam_properties.SetValue(IGA.CROSS_AREA, np.pi * r**2) - beam_properties.SetValue(IGA.HEIGHT, 2*r) - beam_properties.SetValue(IGA.WIDTH, 2*r) - beam_properties.SetValue(IGA.I_T, np.pi * r**4/2) - beam_properties.SetValue(IGA.I_V, np.pi * r**4/4) - beam_properties.SetValue(IGA.I_N, np.pi * r**4/4) - beam_properties.SetValue(KM.YOUNG_MODULUS , 1e+10) - beam_properties.SetValue(KM.POISSON_RATIO , 0) - beam_properties.SetValue(KM.DENSITY , 0) - beam_properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], [0.75, 0, 0, 1], [1, 0, 0, 1]])) - beam_properties.SetValue(KM.CONSTITUTIVE_LAW,IGA.BernoulliBeamElasticConstitutiveLaw()) + model_part = create_model_part(model) + properties = create_properties( + model_part, 1, (0.0, 0.0, 1.0), + young_modulus=young_modulus, poisson_ratio=poisson_ratio, area=height * width, + i_n=height * width ** 3 / 12.0, i_v=i_out_of_plane, i_t=i_torsion) + # Exact quarter circle of degree 2 from (R, 0, 0) to (0, R, 0), refined to degree 4 with 16 knot spans nodes = KM.NodesVector() - for i, ctrlpt in enumerate(control_points, 1): - node = model_part.CreateNewNode(i, *ctrlpt) - nodes.append(node) - last_node = node - knots = KM.Vector(len(knotvector)) - for i, knot in enumerate(knotvector): - knots[i] = knot - - curve = KM.NurbsCurveGeometry3D(nodes, 4, knots) - - quadrature_point_geometries = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(quadrature_point_geometries,3) + for i, point in enumerate(((radius, 0.0, 0.0), (radius, radius, 0.0), (0.0, radius, 0.0)), 1): + nodes.append(model_part.CreateNewNode(i, *point)) + curve = KM.NurbsCurveGeometry3D(nodes, 2, KM.Vector([0.0, 0.0, 1.0, 1.0]), KM.Vector([1.0, np.sqrt(0.5), 1.0])) + curve.SetId(2) + model_part.AddGeometry(curve) - element_id = 1 - for i in range(0, len(quadrature_point_geometries)): - model_part.CreateNewElement('NonLinearBernoulliBeamElement3D', element_id, quadrature_point_geometries[i], beam_properties) - element_id += 1 + refine_curve(model, "modeler_tests/beam_quadrant_refinements.iga.json") + curve = model_part.GetGeometry(2) + create_elements(model_part, curve, properties) IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_X, KM.REACTION_X, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Y, KM.REACTION_Y, model_part) - KM.VariableUtils().AddDof(KM.DISPLACEMENT_Z, KM.REACTION_Z, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_X, KM.REACTION_MOMENT_X, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Y, KM.REACTION_MOMENT_Y, model_part) - KM.VariableUtils().AddDof(KM.ROTATION_Z, KM.REACTION_MOMENT_Z, model_part) - - nodes[0].Fix(KM.DISPLACEMENT_X) - nodes[0].Fix(KM.DISPLACEMENT_Y) - nodes[0].Fix(KM.DISPLACEMENT_Z) - nodes[0].Fix(KM.ROTATION_X) - nodes[1].Fix(KM.DISPLACEMENT_X) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) - - prop = model_part.GetProperties()[2] - force_condition= model_part.CreateNewCondition('PointLoadCondition3D1N', 1, [nodes[2].Id], prop) - force_condition.SetValue(SMA.POINT_LOAD, KM.Array3([0, 0, -load])) - - model_part.SetBufferSize(1) - - time_scheme = KM.ResidualBasedIncrementalUpdateStaticScheme() - - linear_solver = linear_solver_factory.ConstructSolver(KM.Parameters( - r'{"solver_type": "skyline_lu_factorization"}')) - - relative_tolerance = 1e-7 - absolute_tolerance = 1e-7 - - conv_criteria = KM.ResidualCriteria(relative_tolerance, absolute_tolerance) - conv_criteria.SetEchoLevel(0) - - maximum_iterations = 3 - compute_reactions = False - reform_dofs_at_each_iteration = False - move_mesh_flag = True - - solver = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, - time_scheme, - linear_solver, - conv_criteria, - maximum_iterations, - compute_reactions, - reform_dofs_at_each_iteration, - move_mesh_flag - ) - - solver.SetEchoLevel(1) - model_part.CloneTimeStep(1) - solver.Solve() - - return last_node - - def testClampedFXLinear(self): - last_node_force = KM.Array3([1, 0, 0]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], TestBeam4pElement.analytical_solution_normalforce(nodes[4].X, 1, 70000, 2.5*5)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0 ) - - def testClampedFYLinear(self): - last_node_force = KM.Array3([0, -1, 0]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) - - self.assertAlmostEqual(nodes[1].X, 1.0 ) - self.assertAlmostEqual(nodes[1].Y, 0.0 ) - self.assertAlmostEqual(nodes[1].Z, 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], TestBeam4pElement.analytical_solution_bending(nodes[4].X, -1, 70000,5**3*2.5/12,4)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], 0.0) + nodes = sorted(model_part.Nodes, key=lambda node: node.Id) + clamp(nodes, 1) + add_point_load(model_part, 1, nodes[-1], (0.0, 0.0, force)) - def testClampedFZLinear(self): - last_node_force = KM.Array3([0, 0, -1]) - last_node_moment = KM.Array3([0, 0, 0]) - nodes , _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) + solve_linear(model_part) - self.assertAlmostEqual(nodes[0].X, 0.0 ) - self.assertAlmostEqual(nodes[0].Y, 0.0 ) - self.assertAlmostEqual(nodes[0].Z, 0.0 ) + tip_displacement_reference = (force * radius ** 3 * np.pi / (4.0 * young_modulus * i_out_of_plane) + + force * radius ** 3 / (shear_modulus * i_torsion) * (3.0 * np.pi / 4.0 - 2.0)) + tip_rotation_reference = (-force * radius ** 2 * np.pi / (4.0 * young_modulus * i_out_of_plane) + + force * radius ** 2 / (shear_modulus * i_torsion) * (1.0 - np.pi / 4.0)) - self.assertAlmostEqual(nodes[1].X, 1.0 ) - self.assertAlmostEqual(nodes[1].Y, 0.0 ) - self.assertAlmostEqual(nodes[1].Z, 0.0 ) + self.assertRelativelyEqual(nodes[-1].GetSolutionStepValue(KM.DISPLACEMENT_Z), tip_displacement_reference, 1e-6) + self.assertRelativelyEqual(nodes[-1].GetSolutionStepValue(KM.ROTATION_X), tip_rotation_reference, 1e-6) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[0], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.DISPLACEMENT))[2], TestBeam4pElement.analytical_solution_bending(nodes[4].X,-1, 70000,2.5**3*5/12,4)) - def testClampedMXLinear(self): - last_node_force = KM.Array3([0, 0, 0]) - last_node_moment = KM.Array3([1, 0, 0]) - nodes, _ = TestBeam4pElement.solve_linear_examples(last_node_force, last_node_moment) - - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[0], 0.0 ) - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[1], 0.0 ) - self.assertAlmostEqual(nodes[0].GetSolutionStepValue(KM.ROTATION)[2], 0.0 ) - - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[0], TestBeam4pElement.analytical_solution_torsion(nodes[4].X, 1, 70000,2.5*5**3/3)) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[1], 0.0 ) - self.assertAlmostEqual(np.array(nodes[4].GetSolutionStepValue(KM.ROTATION))[2], 0.0 ) - -E_MOD = 70000.0 -NU = 0.0 -WIDTH = 2.5 -HEIGHT = 5.0 -LENGTH = 4.0 -I_N_ = WIDTH * HEIGHT ** 3 / 12.0 -I_V_ = HEIGHT * WIDTH ** 3 / 12.0 -I_T_ = WIDTH * HEIGHT ** 3 / 3.0 -G_MOD = E_MOD / (2.0 * (1.0 + NU)) -DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) - -class TestBeam4pElementNonlinear(KratosUnittest.TestCase): +class TestBeam4pElementNonlinear(BeamTestCase): + """Geometrically nonlinear response of the NonLinearBernoulliBeamElement3D.""" @staticmethod def build_cantilever(n_cp=5, degree=4): - + """Cantilever along +X, refined with curve_h_refinements.iga.json. Returns (model, model_part, nodes).""" model = KM.Model() - mp = model.CreateModelPart('IgaModelPart') - for var in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, - KM.REACTION_MOMENT, SMA.POINT_LOAD): - mp.AddNodalSolutionStepVariable(var) - - props = mp.GetProperties()[0] - props.SetValue(IGA.CROSS_AREA, WIDTH * HEIGHT) - props.SetValue(IGA.HEIGHT, HEIGHT) - props.SetValue(IGA.WIDTH, WIDTH) - props.SetValue(IGA.I_T, I_T_) - props.SetValue(IGA.I_N, I_N_) - props.SetValue(IGA.I_V, I_V_) - props.SetValue(KM.YOUNG_MODULUS, E_MOD) - props.SetValue(KM.POISSON_RATIO, NU) - props.SetValue(KM.DENSITY, 7856) - props.SetValue(IGA.LOCAL_AXIS_ORIENTATION, - np.array([[0, 0, 0, 1], [0.25, 0, 0, 1], [0.5, 0, 0, 1], - [0.75, 0, 0, 1], [1, 0, 0, 1]])) - props.SetValue(KM.CONSTITUTIVE_LAW, IGA.BernoulliBeamElasticConstitutiveLaw()) - - nodes = KM.NodesVector() - for i in range(n_cp): - nodes.append(mp.CreateNewNode(i + 1, LENGTH * i / (n_cp - 1), 0.0, 0.0)) - - kv = ([0.0] * degree - + [float(i) / (n_cp - degree) for i in range(1, n_cp - degree)] - + [1.0] * degree) - knots = KM.Vector(len(kv)) - for i, k in enumerate(kv): - knots[i] = k + model_part = create_model_part(model) + properties = create_properties(model_part, 1, (0.0, 0.0, 1.0)) - curve = KM.NurbsCurveGeometry3D(nodes, degree, knots) + curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0), n_cp, degree) curve.SetId(2) - mp.AddGeometry(curve) - - from KratosMultiphysics.modeler_factory import KratosModelerFactory - modeler_parameters = KM.Parameters(r'''[{ - "modeler_name": "RefinementModeler", - "Parameters": { - "echo_level": 0, - "refinements_file_name": "modeler_tests/curve_h_refinements.iga.json" - } - }]''') - refinement_modeler = KratosModelerFactory().ConstructListOfModelers( - model, modeler_parameters)[0] - refinement_modeler.PrepareGeometryModel() - - curve = mp.GetGeometry(2) - # vtk_curve = KM.BrepCurve(curve) - # vtk_curve.SetId(3) - # mp.AddGeometry(vtk_curve) - nodes = KM.NodesVector() - for node in mp.Nodes: - nodes.append(node) + model_part.AddGeometry(curve) - qpg = KM.GeometriesVector() - curve.CreateQuadraturePointGeometries(qpg, 3) - for eid in range(len(qpg)): - mp.CreateNewElement('NonLinearBernoulliBeamElement3D', eid + 1, qpg[eid], props) + refine_curve(model, "modeler_tests/curve_h_refinements.iga.json") - IGA.ComputeBeamVectorsProcess(mp, curve).ExecuteInitialize() - - for dof, reaction in zip(DOFS, (KM.REACTION_X, KM.REACTION_Y, - KM.REACTION_Z, KM.REACTION_MOMENT_X)): - KM.VariableUtils().AddDof(dof, reaction, mp) + curve = model_part.GetGeometry(2) + create_elements(model_part, curve, properties) + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) - for var in DOFS: - nodes[0].Fix(var) - nodes[1].Fix(KM.DISPLACEMENT_Y) - nodes[1].Fix(KM.DISPLACEMENT_Z) + nodes = sorted(model_part.Nodes, key=lambda node: node.Id) + clamp(nodes, 0) - mp.SetBufferSize(1) - mp.CloneTimeStep(1) - for element in mp.Elements: - element.Initialize(mp.ProcessInfo) - return model, mp, nodes + model_part.SetBufferSize(1) + model_part.CloneTimeStep(1.0) + for element in model_part.Elements: + element.Initialize(model_part.ProcessInfo) + return model, model_part, nodes @staticmethod def free_dofs(nodes): - fixed = {4 * i + j - for i in range(len(nodes)) - for j, var in enumerate(DOFS) if nodes[i].IsFixed(var)} + fixed = {4 * i + j for i, node in enumerate(nodes) for j, dof in enumerate(DOFS) if node.IsFixed(dof)} return [i for i in range(4 * len(nodes)) if i not in fixed] @staticmethod - def element_dof_index(element): - idx = [] - for node in element.GetGeometry(): - base = 4 * (node.Id - 1) - idx += [base, base + 1, base + 2, base + 3] - return np.array(idx) - - @classmethod - def apply_state(cls, nodes, u): - for i in range(len(nodes)): - nodes[i].SetSolutionStepValue( - KM.DISPLACEMENT, KM.Array3([u[4 * i], u[4 * i + 1], u[4 * i + 2]])) - nodes[i].SetSolutionStepValue(KM.ROTATION_X, float(u[4 * i + 3])) - + def element_dof_indices(element): + # The refinement modeler numbers the control points consecutively from 1. + return np.array([4 * (node.Id - 1) + j for node in element.GetGeometry() for j in range(4)]) @staticmethod - def write_vtk_output(model, mp, output_file_name="beam_deformation"): - from KratosMultiphysics.IgaApplication.iga_vtk_output_process import IgaVTKOutputProcess - - settings = KM.Parameters(r'''{ - "model_part_name": "IgaModelPart", - "output_file_name": "beam_deformation", - "brep_curve_ids": [3], - "nodal_solution_step_data_variables": ["DISPLACEMENT", "ROTATION"], - "output_refinement_curve": [10], - "output_control_type": "step", - "output_frequency": 1 - }''') - settings["output_file_name"].SetString(output_file_name) - - output_process = IgaVTKOutputProcess(model, settings) - output_process.ExecuteInitialize() - output_process.ExecuteBeforeSolutionLoop() - mp.ProcessInfo[KM.TIME] = 1.0 - if output_process.IsOutputStep(): - output_process.PrintOutput() + def apply_state(nodes, u): + for i, node in enumerate(nodes): + node.SetSolutionStepValue(KM.DISPLACEMENT, KM.Array3([float(v) for v in u[4 * i:4 * i + 3]])) + node.SetSolutionStepValue(KM.ROTATION_X, float(u[4 * i + 3])) @classmethod - def assemble(cls, mp, nodes, u, build_level=0): - + def assemble(cls, model_part, nodes, u, build_level=0): + """Global tangent and residual at the state u. BUILD_LEVEL 1/2 restricts the tangent to its material/geometric part.""" cls.apply_state(nodes, u) - mp.ProcessInfo[IGA.BUILD_LEVEL] = build_level - ndof = 4 * len(nodes) - K = np.zeros((ndof, ndof)) - R = np.zeros(ndof) - for element in mp.Elements: + model_part.ProcessInfo[IGA.BUILD_LEVEL] = build_level + n_dofs = 4 * len(nodes) + K = np.zeros((n_dofs, n_dofs)) + R = np.zeros(n_dofs) + for element in model_part.Elements: lhs, rhs = KM.Matrix(), KM.Vector() - element.CalculateLocalSystem(lhs, rhs, mp.ProcessInfo) - idx = cls.element_dof_index(element) - K[np.ix_(idx, idx)] += np.array(lhs, copy=True) - R[idx] += np.array(rhs, copy=True) + element.CalculateLocalSystem(lhs, rhs, model_part.ProcessInfo) + indices = cls.element_dof_indices(element) + K[np.ix_(indices, indices)] += np.array(lhs) + R[indices] += np.array(rhs) return K, R @classmethod - def newton(cls, mp, nodes, f_ext, n_steps=8, tol=1e-10, max_it=40): - + def newton(cls, model_part, nodes, f_ext, n_steps, tolerance=1e-10, max_iterations=40): + """Load-controlled Newton-Raphson. Returns the solution and the residual norms of the last load step.""" free = cls.free_dofs(nodes) u = np.zeros(4 * len(nodes)) - norms = [] for step in range(1, n_steps + 1): f = f_ext * step / n_steps scale = max(1.0, np.linalg.norm(f[free])) norms = [] - for _ in range(max_it): - K, R = cls.assemble(mp, nodes, u) + for _ in range(max_iterations): + K, R = cls.assemble(model_part, nodes, u) residual = R + f - norm = np.linalg.norm(residual[free]) - norms.append(norm) - if norm < tol * scale: + norms.append(np.linalg.norm(residual[free])) + if norms[-1] < tolerance * scale: break u[free] += np.linalg.solve(K[np.ix_(free, free)], residual[free]) return u, norms - def testTangentMatchesFiniteDifferences(self): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - ndof = 4 * n_cp + @classmethod + def buckling_loads(cls, model_part, nodes, tip_load, reference_load): + """Linearized buckling loads (K_mat + lambda * K_geo) after a pre-load of the given tip load.""" + f_ext = np.zeros(4 * len(nodes)) + f_ext[4 * (len(nodes) - 1):4 * (len(nodes) - 1) + 3] = tip_load + u, _ = cls.newton(model_part, nodes, f_ext, n_steps=1) + + free = cls.free_dofs(nodes) + K_mat, _ = cls.assemble(model_part, nodes, u, build_level=1) + K_geo, _ = cls.assemble(model_part, nodes, u, build_level=2) - u0 = np.zeros(ndof) - for i in range(n_cp): - x = nodes[i].X0 - u0[4 * i] = 0.004 * x - u0[4 * i + 1] = 0.010 * x ** 2 - u0[4 * i + 2] = -0.006 * x ** 2 - u0[4 * i + 3] = 0.003 * x + mu = np.linalg.eigvals(-np.linalg.solve(K_mat[np.ix_(free, free)], K_geo[np.ix_(free, free)])) + mu = mu[np.abs(mu.imag) < 1e-8 * (1.0 + np.abs(mu.real))].real + load_factors = 1.0 / mu[np.abs(mu) > 1e-12] + return np.sort(load_factors[load_factors > 1e-8]) * reference_load - K, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=0) + def test_tangent_matches_finite_differences(self): + _, model_part, nodes = self.build_cantilever() + n_dofs = 4 * len(nodes) - K_mat, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=1) + u0 = np.zeros(n_dofs) + for i, node in enumerate(nodes): + x = node.X0 + u0[4 * i:4 * i + 4] = (0.004 * x, 0.010 * x ** 2, -0.006 * x ** 2, 0.003 * x) - K_geo, _ = TestBeam4pElementNonlinear.assemble( - mp, nodes, u0, build_level=2) + K, _ = self.assemble(model_part, nodes, u0) + K_mat, _ = self.assemble(model_part, nodes, u0, build_level=1) + K_geo, _ = self.assemble(model_part, nodes, u0, build_level=2) h = 1e-7 K_fd = np.zeros_like(K) - for j in range(ndof): - up = u0.copy(); up[j] += h - um = u0.copy(); um[j] -= h - _, rp = TestBeam4pElementNonlinear.assemble(mp, nodes, up) - _, rm = TestBeam4pElementNonlinear.assemble(mp, nodes, um) - K_fd[:, j] = -(rp - rm) / (2.0 * h) - - # error diagonistics block - #--------------- - K_reconstructed = K_mat + K_geo - - diff = K - K_fd - reconstruction_diff = K - K_reconstructed - - max_index = np.unravel_index( - np.argmax(np.abs(diff)), - diff.shape) - - i, j = max_index - - print("\n--- Tangent diagnostics ---") - print("||K|| =", np.linalg.norm(K)) - print("||K_mat|| =", np.linalg.norm(K_mat)) - print("||K_geo|| =", np.linalg.norm(K_geo)) - print("||K_fd|| =", np.linalg.norm(K_fd)) - - print( - "||K - (K_mat + K_geo)|| =", - np.linalg.norm(reconstruction_diff) - ) - - print( - "relative total error =", - np.abs(diff).max() / np.abs(K).max() - ) - - print("largest mismatch at (row, col) =", max_index) - print("K =", K[i, j]) - print("K_fd =", K_fd[i, j]) - print("diff =", diff[i, j]) - print("K_mat =", K_mat[i, j]) - print("K_geo =", K_geo[i, j]) - - K_geo_required = K_fd - K_mat - geo_diff = K_geo - K_geo_required - - print( - "relative geometric-part error =", - np.abs(geo_diff).max() / - max(np.abs(K_geo_required).max(), 1e-16) - ) - - geo_index = np.unravel_index( - np.argmax(np.abs(geo_diff)), - geo_diff.shape) - - print("largest geometric mismatch =", geo_index) - print("K_geo =", K_geo[geo_index]) - print("K_geo_required =", K_geo_required[geo_index]) - print("geo diff =", geo_diff[geo_index]) - - #--------------------------end - - error = np.abs(diff).max() / np.abs(K).max() - - self.assertLess( - error, - 1e-5, - 'tangent stiffness is not the derivative of the internal ' - 'force (relative error %.3e) -- a missing or wrong ' - 'geometric-stiffness term' % error) - - error = np.abs(K - K_fd).max() / np.abs(K).max() - self.assertLess(error, 1e-5, - 'tangent stiffness is not the derivative of the internal ' - 'force (relative error %.3e) -- a missing or wrong ' - 'geometric-stiffness term' % error) - - def testQuadraticNewtonConvergence(self): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - - _, norms = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=4) + for j in range(n_dofs): + u_plus = u0.copy() + u_plus[j] += h + u_minus = u0.copy() + u_minus[j] -= h + _, R_plus = self.assemble(model_part, nodes, u_plus) + _, R_minus = self.assemble(model_part, nodes, u_minus) + K_fd[:, j] = -(R_plus - R_minus) / (2.0 * h) + + scale = np.abs(K).max() + self.assertLess(np.abs(K - K_fd).max() / scale, 1e-6, + "the tangent stiffness is not the derivative of the internal forces") + self.assertLess(np.abs(K - (K_mat + K_geo)).max() / scale, 1e-12, + "the material and geometric parts do not add up to the tangent stiffness") + + def test_quadratic_newton_convergence(self): + _, model_part, nodes = self.build_cantilever() + f_ext = np.zeros(4 * len(nodes)) + f_ext[4 * (len(nodes) - 1) + 1] = -0.5 * E_MOD * I_N_ / LENGTH ** 2 + + _, norms = self.newton(model_part, nodes, f_ext, n_steps=4) + relative_norms = np.array(norms) / norms[0] self.assertGreaterEqual(len(norms), 3) - self.assertLess(norms[-1], 1e-6, 'Newton did not converge') - - self.assertLess(norms[-1], norms[-2] ** 1.5, - 'convergence is not quadratic: %s' - % ' '.join('%.2e' % n for n in norms)) - - def testLargeDeflectionElastica(self): - EI = E_MOD * I_N_ - alpha = 0.5 - load = alpha * EI / LENGTH ** 2 + self.assertLess(relative_norms[-1], 1e-10, "Newton did not converge") + self.assertLess(relative_norms[-2], relative_norms[-3] ** 1.8, + "convergence is not quadratic: %s" % " ".join("%.2e" % n for n in relative_norms)) + + def test_large_deflection_elastica(self): + # Cantilever with a tip load perpendicular to the undeformed axis, P L^2 / EI = 0.5. + # Reference: inextensible elastica (shooting method). The linear solution would be uy = -0.6667, ux = 0. + # The cantilever is stocky, so the axial stiffness is increased to match the inextensibility of the reference. ux_exact, uy_exact = -0.0636758499, -0.6485743026 + load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - n_cp = len(nodes) - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=8) - # TestBeam4pElementNonlinear.write_vtk_output(model, mp) - - uy = u[4 * (n_cp - 1) + 1] - ux = u[4 * (n_cp - 1)] - - self.assertLess(abs(uy), abs(-load * LENGTH ** 3 / (3 * EI)) * 1.02) - self.assertLess(abs(uy - uy_exact) / abs(uy_exact), 0.06) - self.assertLess(abs(ux - ux_exact) / abs(ux_exact), 0.15) - - @classmethod - def buckling_loads(cls, mp, nodes, load_vector, p_ref): - n_cp = len(nodes) - f_ext = np.zeros(4 * n_cp) - for j, value in enumerate(load_vector): - f_ext[4 * (n_cp - 1) + j] = value - - u, _ = cls.newton(mp, nodes, f_ext, n_steps=1) + _, model_part, nodes = self.build_cantilever() + model_part.GetProperties()[1].SetValue(IGA.CROSS_AREA, 1e4 * AREA) + f_ext = np.zeros(4 * len(nodes)) + f_ext[4 * (len(nodes) - 1) + 1] = -load + u, _ = self.newton(model_part, nodes, f_ext, n_steps=8) - cls.apply_state(nodes, u) - k_mat, _ = cls.assemble(mp, nodes, u, build_level=1) - k_geo, _ = cls.assemble(mp, nodes, u, build_level=2) + self.assertRelativelyEqual(u[4 * (len(nodes) - 1) + 1], uy_exact, 5e-4) + self.assertRelativelyEqual(u[4 * (len(nodes) - 1)], ux_exact, 5e-4) - free = cls.free_dofs(nodes) - A = k_mat[np.ix_(free, free)] - B = k_geo[np.ix_(free, free)] - - mu = np.linalg.eigvals(-np.linalg.solve(A, B)) - mu = mu[np.abs(mu.imag) < 1e-8 * (1.0 + np.abs(mu.real))].real - lam = np.sort(1.0 / mu[np.abs(mu) > 1e-12]) - return np.sort(lam[lam > 1e-8]) * p_ref - - def testEulerBucklingWeakAxis(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + def test_euler_buckling_weak_axis(self): + _, model_part, nodes = self.build_cantilever() + loads = self.buckling_loads(model_part, nodes, (-1000.0, 0.0, 0.0), 1000.0) euler = np.pi ** 2 * E_MOD * I_V_ / (4.0 * LENGTH ** 2) - self.assertAlmostEqual(loads[0] / euler, 1.0, delta=0.005) + self.assertRelativelyEqual(loads[0], euler, 5e-3) - def testEulerBucklingStrongAxis(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [-p_ref, 0.0, 0.0], p_ref) + def test_euler_buckling_strong_axis(self): + # The second mode is the first strong-axis mode, since the second weak-axis mode is at 9 times the first one. + _, model_part, nodes = self.build_cantilever() + loads = self.buckling_loads(model_part, nodes, (-1000.0, 0.0, 0.0), 1000.0) euler = np.pi ** 2 * E_MOD * I_N_ / (4.0 * LENGTH ** 2) - self.assertAlmostEqual(loads[1] / euler, 1.0, delta=0.005) + self.assertRelativelyEqual(loads[1], euler, 5e-3) - def testLateralTorsionalBuckling(self): - p_ref = 1000.0 - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever() - loads = TestBeam4pElementNonlinear.buckling_loads( - mp, nodes, [0.0, -p_ref, 0.0], p_ref) + def test_lateral_torsional_buckling(self): + # Cantilever with a tip load at the centroid, Timoshenko & Gere: P_cr = 4.013 sqrt(E I_weak G I_T) / L^2 + _, model_part, nodes = self.build_cantilever() + loads = self.buckling_loads(model_part, nodes, (0.0, -1000.0, 0.0), 1000.0) timoshenko = 4.013 * np.sqrt(E_MOD * I_V_ * G_MOD * I_T_) / LENGTH ** 2 + self.assertRelativelyEqual(loads[0], timoshenko, 5e-2) - self.assertAlmostEqual(loads[0] / timoshenko, 1.0, delta=0.05) - - @KratosUnittest.expectedFailure - def testLinearBendingIsMeshIndependent(self): - EI = E_MOD * I_N_ - load = 1e-4 * EI / LENGTH ** 2 - reference = -load * LENGTH ** 3 / (3.0 * EI) + def test_linear_bending_is_mesh_independent(self): + # The exact cubic deflection is in the spline space of every mesh, since the curve is linearly parametrized. + load = 1e-4 * E_MOD * I_N_ / LENGTH ** 2 + reference = cantilever_tip_deflection(-load, I_N_) for n_cp in (5, 7, 9, 13): - model, mp, nodes = TestBeam4pElementNonlinear.build_cantilever(n_cp) - f_ext = np.zeros(4 * n_cp) - f_ext[4 * (n_cp - 1) + 1] = -load - u, _ = TestBeam4pElementNonlinear.newton(mp, nodes, f_ext, n_steps=1) - uy = u[4 * (n_cp - 1) + 1] - self.assertLess(abs(uy - reference) / abs(reference), 1e-6, - 'n_cp=%d (%d knot spans) is off by %.3e' - % (n_cp, mp.NumberOfElements() // 5, - abs(uy - reference) / abs(reference))) + _, model_part, nodes = self.build_cantilever(n_cp) + f_ext = np.zeros(4 * len(nodes)) + f_ext[4 * (len(nodes) - 1) + 1] = -load + u, _ = self.newton(model_part, nodes, f_ext, n_steps=1) + self.assertRelativelyEqual(u[4 * (len(nodes) - 1) + 1], reference, 1e-6) + if __name__ == "__main__": - KratosUnittest.main() \ No newline at end of file + KratosUnittest.main() From ea5b54aa6e720f48c389d01fac8bd4b8b6911fc2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 16:12:31 +0100 Subject: [PATCH 19/32] [IGA] Compute the initial beam frame per curve in ComputeBeamVectorsProcess - T_0/N_0 were written to the shared Properties of every element in the model part, and the model-part-only constructor used the parent curve of the first element for all of them. With several beams in one model part, each beam got another beam's frame. For a beam opposite to the first one (T0.T = -1), Lambda(T0,T) divides by zero and the solution is NaN. - Each element now gets the frame of its own parent curve (GetGeometryParent(0)), cached per curve and stored on the element. If a curve is given to the constructor, only its elements are processed. - The tangent was evaluated at local coordinate 0 instead of the start of the curve's parameter domain. It is now evaluated at DomainInterval().GetT0(). --- .../compute_beam_vectors_process.cpp | 52 +++++++++++++------ .../compute_beam_vectors_process.h | 9 +++- 2 files changed, 45 insertions(+), 16 deletions(-) diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp index e3d2e216e495..c04d86e3de6f 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -29,7 +29,7 @@ ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( ModelPart& rModelPart) : Process() , mrThisModelPart(rModelPart) - , mpParentCurve(&(rModelPart.ElementsBegin()->GetGeometry().GetGeometryParent(0))) + , mpParentCurve(nullptr) { } @@ -61,10 +61,11 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( array_1d V = ZeroVector(3); array_1d up = ZeroVector(3); - // Evaluate at the start of the beam (parameter = 0) + // Evaluate at the start of the beam array_1d local_coordinates = ZeroVector(3); + local_coordinates[0] = rCurve.DomainInterval().GetT0(); std::vector> global_space_derivatives; - + rCurve.GlobalSpaceDerivatives(global_space_derivatives, local_coordinates, 1); @@ -92,8 +93,9 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( array_1d V = ZeroVector(3); array_1d up = ZeroVector(3); - // Evaluate at the start of the beam (parameter = 0) + // Evaluate at the start of the beam array_1d local_coordinates = ZeroVector(3); + local_coordinates[0] = rCurve.DomainInterval().GetT0(); std::vector> global_space_derivatives; rCurve.GlobalSpaceDerivatives(global_space_derivatives, local_coordinates, 1); @@ -118,31 +120,51 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( } -void ComputeBeamVectorsProcess::ExecuteInitialize() +void ComputeBeamVectorsProcess::ComputeT0AndN0( + const Geometry& rParentCurve, + array_1d& rT0, + array_1d& rN0) { - const auto* curve_on_surface = dynamic_cast, PointerVector>*>(mpParentCurve); - auto* nurbs_curve = dynamic_cast>*>(mpParentCurve); - const auto* brep_curve = dynamic_cast, PointerVector>*>(mpParentCurve); + const auto* curve_on_surface = dynamic_cast, PointerVector>*>(&rParentCurve); + auto* nurbs_curve = dynamic_cast>*>(&rParentCurve); + const auto* brep_curve = dynamic_cast, PointerVector>*>(&rParentCurve); if (brep_curve != nullptr) { nurbs_curve = dynamic_cast>*>( &brep_curve->GetGeometryPart(Geometry::BACKGROUND_GEOMETRY_INDEX)); } - array_1d T; - array_1d N; - if (curve_on_surface != nullptr) { - ComputeT0AndN0(*curve_on_surface, T, N); + ComputeT0AndN0(*curve_on_surface, rT0, rN0); } else if (nurbs_curve != nullptr) { - ComputeT0AndN0(*nurbs_curve, T, N); + ComputeT0AndN0(*nurbs_curve, rT0, rN0); } else { KRATOS_ERROR << "Unknown geometry type in ComputeBeamVectorsProcess"; } +} + +void ComputeBeamVectorsProcess::ExecuteInitialize() +{ + // Each beam element gets the initial frame of its own parent curve, so that several beams can share a model part. + std::unordered_map*, std::pair, array_1d>> frames; for (auto& r_element : mrThisModelPart.Elements()) { - r_element.GetProperties().SetValue(T_0, T); - r_element.GetProperties().SetValue(N_0, N); + const Geometry* p_parent_curve = &r_element.GetGeometry().GetGeometryParent(0); + + if (mpParentCurve != nullptr && p_parent_curve != mpParentCurve) { + continue; + } + + auto it_frame = frames.find(p_parent_curve); + if (it_frame == frames.end()) { + array_1d T; + array_1d N; + ComputeT0AndN0(*p_parent_curve, T, N); + it_frame = frames.emplace(p_parent_curve, std::make_pair(T, N)).first; + } + + r_element.SetValue(T_0, Vector(it_frame->second.first)); + r_element.SetValue(N_0, Vector(it_frame->second.second)); } } diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h index e68de5ae5ade..fd95f7d823b4 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h @@ -27,6 +27,7 @@ #include "iga_application_variables.h" #include "utilities/math_utils.h" #include +#include namespace Kratos @@ -107,9 +108,15 @@ class KRATOS_API(IGA_APPLICATION) ComputeBeamVectorsProcess } private: + /// Computes T0 and N0 for a NurbsCurve, NurbsCurveOnSurface or BrepCurve parent geometry. + void ComputeT0AndN0( + const Geometry& rParentCurve, + array_1d& rT0, + array_1d& rN0); + ///@name Member Variables ///@{ - ModelPart& mrThisModelPart; + ModelPart& mrThisModelPart; const Geometry* mpParentCurve; ///@} }; // Class ComputeBeamVectorsProcess From 20c3ec5e32e32e5670cca2670e7d3ca1744662b4 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 16:12:41 +0100 Subject: [PATCH 20/32] [IGA] Fix cross-section orientation and torsional stress of the Bernoulli beam - NonLinearBernoulliBeamElement3D: LOCAL_AXIS_ORIENTATION was ignored for straight beams. CalculateDeltaPhi measured the twist Psi as the angle between Lambda(T0,T)*n_requested and n_requested instead of between Lambda(T0,T)*N0 and n_requested (Bauer et al. 2016, Eq. 15). For a straight beam Lambda = I, so Psi was always 0 and the cross section always followed the default N0. N0/V0 are now computed before the twist angle, which depends on them. - Read T_0/N_0 from the element data, falling back to the properties. Check() now requires them instead of dividing by zero when missing. - BernoulliBeamElasticConstitutiveLaw: the torsional stresses were G*I_T*kappa while the tangent was 0.5*G*I_T, so the stress was twice the energetically consistent value. The tangent is now also computed when only COMPUTE_CONSTITUTIVE_TENSOR is requested. - The element now uses the stress returned by the constitutive law instead of recomputing D*strain, which hid the law's bug and discarded initial strain/stress contributions. - Remove the K_geo(0,5) debug accumulators and std::cout output from CalculateAll. --- .../non_linear_bernoulli_beam_element_3D.cpp | 244 +++++------------- .../non_linear_bernoulli_beam_element_3D.h | 6 + 2 files changed, 74 insertions(+), 176 deletions(-) diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index 07590d582cbf..c83610cf0657 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -207,13 +207,6 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector stress_torsion_1 = ZeroVector(5); Vector stress_torsion_2 = ZeroVector(5); - // Temporary diagnostics for geometric stiffness entry (0, 5) - double debug_geo_axial = 0.0; - double debug_geo_bending_1 = 0.0; - double debug_geo_bending_2 = 0.0; - double debug_geo_torsion_1 = 0.0; - double debug_geo_torsion_2 = 0.0; - for ( IndexType point_number = 0; point_number < r_integration_points.size(); @@ -335,37 +328,6 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } if (calculate_geometric_stiffness) { - // Temporary diagnostic contributions for K_geo(0, 5) - debug_geo_axial += - inverse_a4 * - integration_weight * - g_axial(0, 5) * - constitutive_variables.StressVector[0]; - - debug_geo_bending_1 += - inverse_a4 * - integration_weight * - g_bending_1(0, 5) * - constitutive_variables.StressVector[1]; - - debug_geo_bending_2 += - inverse_a4 * - integration_weight * - g_bending_2(0, 5) * - constitutive_variables.StressVector[2]; - - debug_geo_torsion_1 += - inverse_a2 * - integration_weight * - g_torsion_1(0, 5) * - constitutive_variables.StressVector[3]; - - debug_geo_torsion_2 += - inverse_a2 * - integration_weight * - g_torsion_2(0, 5) * - constitutive_variables.StressVector[4]; - // Geometrical stiffness rLeftHandSideMatrix += inverse_a4 * @@ -454,50 +416,6 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } - if ( - CalculateStiffnessMatrixFlag && - calculate_geometric_stiffness && - build_level == 2) - { - std::cout - << "\n--- Geometric contribution (0,5) ---" - << std::endl; - - std::cout - << "axial = " - << debug_geo_axial - << std::endl; - - std::cout - << "bending 1 = " - << debug_geo_bending_1 - << std::endl; - - std::cout - << "bending 2 = " - << debug_geo_bending_2 - << std::endl; - - std::cout - << "torsion 1 = " - << debug_geo_torsion_1 - << std::endl; - - std::cout - << "torsion 2 = " - << debug_geo_torsion_2 - << std::endl; - - std::cout - << "sum = " - << debug_geo_axial + - debug_geo_bending_1 + - debug_geo_bending_2 + - debug_geo_torsion_1 + - debug_geo_torsion_2 - << std::endl; - } - KRATOS_CATCH("") } @@ -538,27 +456,27 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( << "\"LOCAL_AXIS_ORIENTATION\" not provided for element #" << Id() << std::endl; - if (GetProperties().Has(T_0)) { - const Vector3d& r_reference_tangent = - GetProperties()[T_0]; + KRATOS_ERROR_IF(!Has(T_0) && !GetProperties().Has(T_0)) + << "\"T_0\" not provided for element #" << Id() + << ". Run the ComputeBeamVectorsProcess first." << std::endl; - KRATOS_ERROR_IF( - norm_2(r_reference_tangent) <= numerical_limit) - << "\"T_0\" reference director vector must have " - << "non-zero magnitude for element #" - << Id() << std::endl; - } + KRATOS_ERROR_IF(!Has(N_0) && !GetProperties().Has(N_0)) + << "\"N_0\" not provided for element #" << Id() + << ". Run the ComputeBeamVectorsProcess first." << std::endl; - if (GetProperties().Has(N_0)) { - const Vector3d& r_reference_normal = - GetProperties()[N_0]; + const Vector3d initial_tangent = Has(T_0) + ? GetValue(T_0) + : GetProperties()[T_0]; - KRATOS_ERROR_IF( - norm_2(r_reference_normal) <= numerical_limit) - << "\"N_0\" reference director vector must have " - << "non-zero magnitude for element #" - << Id() << std::endl; - } + KRATOS_ERROR_IF(norm_2(initial_tangent) <= numerical_limit) + << "\"T_0\" reference director vector must have " + << "non-zero magnitude for element #" + << Id() << std::endl; + + KRATOS_ERROR_IF(norm_2(GetInitialNormal()) <= numerical_limit) + << "\"N_0\" reference director vector must have " + << "non-zero magnitude for element #" + << Id() << std::endl; return 0; @@ -617,12 +535,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( ->CalculateMaterialResponse( rConstitutiveLawParameters, StressMeasure); - - noalias(rConstitutiveVariables.StressVector) = - prod( - trans(rConstitutiveVariables.ConstitutiveMatrix), - rConstitutiveVariables.StrainVector); - } + } void NonLinearBernoulliBeamElement3D::ComputeReferenceTwistAngleAndDerivative( @@ -705,70 +618,73 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const KinematicVariables& rKinematicVariables, const Vector3d& rNormal) { - const Vector3d initial_tangent = GetProperties()[T_0]; - const Vector3d reference_base_vector = rKinematicVariables.R1; - - const Vector3d current_reference_tangent = - reference_base_vector / norm_2(reference_base_vector); - - const Vector3d normalized_initial_tangent = - initial_tangent / norm_2(initial_tangent); - - Vector3d normal = rNormal; - - const double tangent_normal_projection = - inner_prod(current_reference_tangent, normal); - - // Project the normal onto the plane normal to the reference tangent. - normal -= tangent_normal_projection * current_reference_tangent; - normal /= norm_2(normal); + const Vector3d reference_tangent = + rKinematicVariables.R1 / norm_2(rKinematicVariables.R1); - const Vector3d reference_principal_axis = normal; + // Project the requested normal onto the plane normal to the reference tangent. + Vector3d requested_axis = + rNormal - inner_prod(reference_tangent, rNormal) * reference_tangent; + requested_axis /= norm_2(requested_axis); + // Untwisted cross-section axis Lambda(T0, T) * N0, i.e. Eq. (15) with Psi = 0. Matrix3d lambda_matrix; ComputeLambdaMatrix( - normalized_initial_tangent, - current_reference_tangent, + GetInitialTangent(), + reference_tangent, lambda_matrix); - const Vector3d rotated_reference_axis = - prod(lambda_matrix, reference_principal_axis); + const Vector3d untwisted_axis = + prod(lambda_matrix, rKinematicVariables.N0); - const Vector3d orientation_reference = - MathUtils::CrossProduct(reference_base_vector, rotated_reference_axis); + // Signed angle about the reference tangent which rotates the untwisted axis onto the requested one. + const double cos_phi = inner_prod(untwisted_axis, requested_axis); + const double sin_phi = inner_prod( + MathUtils::CrossProduct(untwisted_axis, requested_axis), + reference_tangent); - const double axis_dot_product = - inner_prod(rotated_reference_axis, normal); + double phi = std::atan2(sin_phi, cos_phi); - const double orientation_dot_product = - inner_prod(normal, orientation_reference); - - double cos_theta = - axis_dot_product / - (norm_2(rotated_reference_axis) * norm_2(normal)); - - if (std::abs(1.0 - std::abs(cos_theta)) < 1e-9) { - cos_theta = MathUtils::Sign(cos_theta); + if (phi < 0.0) { + phi += 2.0 * Globals::Pi; } - double phi = std::acos(cos_theta); + return phi; + } - const double pi = 4.0 * std::atan(1.0); + NonLinearBernoulliBeamElement3D::Vector3d NonLinearBernoulliBeamElement3D::GetInitialTangent() const + { + const Vector3d initial_tangent = Has(T_0) + ? GetValue(T_0) + : GetProperties()[T_0]; - if (orientation_dot_product < -1e-12) { - phi = 2.0 * pi - phi; - } + return initial_tangent / norm_2(initial_tangent); + } - return phi; + NonLinearBernoulliBeamElement3D::Vector3d NonLinearBernoulliBeamElement3D::GetInitialNormal() const + { + const Vector3d initial_normal = Has(N_0) + ? GetValue(N_0) + : GetProperties()[N_0]; + + return initial_normal; } - void NonLinearBernoulliBeamElement3D::ComputeReferenceCrossSectionGeometry( KinematicVariables& rKinematicVariables) { const Vector3d reference_first_base_vector = rKinematicVariables.R1; const Vector3d reference_second_base_vector = rKinematicVariables.R2; - const Vector3d initial_reference_tangent = GetProperties()[T_0]; + const Vector3d initial_reference_tangent = GetInitialTangent(); + + // Initial cross-section axes N0 and V0, orthonormal to T0. Needed by the twist angle computation below. + rKinematicVariables.N0 = GetInitialNormal(); + rKinematicVariables.N0 -= + inner_prod(initial_reference_tangent, rKinematicVariables.N0) + * initial_reference_tangent; + rKinematicVariables.N0 /= norm_2(rKinematicVariables.N0); + rKinematicVariables.V0 = MathUtils::CrossProduct( + initial_reference_tangent, + rKinematicVariables.N0); ComputeReferenceTwistAngleAndDerivative( rKinematicVariables, @@ -822,30 +738,6 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( reference_rodrigues_matrix_derivative); rKinematicVariables.n.clear(); - rKinematicVariables.N0 = GetProperties()[N_0]; - - const double initial_reference_tangent_norm = - norm_2(initial_reference_tangent); - - const Vector3d normalized_initial_reference_tangent = - initial_reference_tangent / initial_reference_tangent_norm; - - rKinematicVariables.N0 -= - inner_prod( - normalized_initial_reference_tangent, - rKinematicVariables.N0) - * normalized_initial_reference_tangent; - - rKinematicVariables.V0 = - MathUtils::CrossProduct( - normalized_initial_reference_tangent, - rKinematicVariables.N0); - - rKinematicVariables.N0 /= - norm_2(rKinematicVariables.N0); - - rKinematicVariables.V0 /= - norm_2(rKinematicVariables.V0); Vector3d transformed_reference_normal; transformed_reference_normal.clear(); @@ -923,7 +815,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const Vector3d current_second_base_vector = rKinematicVariables.r2; const Vector3d reference_first_base_vector = rKinematicVariables.R1; const Vector3d reference_second_base_vector = rKinematicVariables.R2; - const Vector3d initial_reference_tangent = GetProperties()[T_0]; + const Vector3d initial_reference_tangent = GetInitialTangent(); rKinematicVariables.n.clear(); rKinematicVariables.v.clear(); @@ -1179,7 +1071,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( double current_twist_angle_derivative = rKinematicVariables.phi_der; double reference_twist_angle = rKinematicVariables.Phi; double reference_twist_angle_derivative = rKinematicVariables.Phi_der; - Vector3d initial_reference_tangent = GetProperties()[T_0]; + Vector3d initial_reference_tangent = GetInitialTangent(); // Compute curvature and torsion variations Vector axial_variation(mNumberOfDofs); @@ -1508,7 +1400,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( double current_twist_angle_derivative = rKinematicVariables.phi_der; double reference_twist_angle = rKinematicVariables.Phi; double reference_twist_angle_derivative = rKinematicVariables.Phi_der; - Vector3d initial_reference_tangent = GetProperties()[T_0]; + Vector3d initial_reference_tangent = GetInitialTangent(); // Compute curvature and torsion variations Matrix axial_second_variation(mNumberOfDofs, mNumberOfDofs); diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h index 22a5308214cd..8c2027f43c17 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -439,6 +439,12 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D const KinematicVariables& rKinematicVariables, const Vector3d& rNormal); + /// Normalized initial tangent T_0, taken from the element data if set, otherwise from the properties. + Vector3d GetInitialTangent() const; + + /// Initial normal N_0, taken from the element data if set, otherwise from the properties. + Vector3d GetInitialNormal() const; + void ComputeReferenceCrossSectionGeometry( KinematicVariables& rKinematicVariables); From 3955b5910fae9c779df0b4697f129c36e3aa4769 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 16:20:35 +0100 Subject: [PATCH 21/32] [IGA] Format beam element files Remove trailing whitespace and add the missing final newlines in the files added or modified by the beam implementation. Whitespace-only changes. Co-Authored-By: Claude Opus 5.5 --- ...ernoulli_beam_elastic_constitutive_law.cpp | 14 +- .../bernoulli_beam_elastic_constitutive_law.h | 2 +- .../custom_elements/beam_base_element_3D.cpp | 382 +++++++++--------- .../custom_elements/beam_base_element_3D.h | 2 +- .../non_linear_bernoulli_beam_element_3D.cpp | 58 +-- .../non_linear_bernoulli_beam_element_3D.h | 6 +- .../compute_beam_vectors_process.cpp | 20 +- .../compute_beam_vectors_process.h | 8 +- ...add_custom_constitutive_laws_to_python.cpp | 2 +- .../add_custom_constitutive_laws_to_python.h | 2 +- .../add_custom_utilities_to_python.cpp | 2 +- .../custom_python/iga_python_application.cpp | 2 +- .../IgaApplication/iga_application.cpp | 2 +- applications/IgaApplication/iga_application.h | 2 +- .../iga_application_variables.cpp | 2 +- .../iga_application_variables.h | 2 +- .../compute_beam_vectors_process.py | 2 +- 17 files changed, 255 insertions(+), 255 deletions(-) diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp index c4ed2192f35b..092bba96ef7c 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -40,8 +40,8 @@ BernoulliBeamElasticConstitutiveLaw::~BernoulliBeamElasticConstitutiveLaw() void BernoulliBeamElasticConstitutiveLaw::GetLawFeatures(Features& rFeatures) { - rFeatures.mStrainSize = 5; - rFeatures.mSpaceDimension = 3; + rFeatures.mStrainSize = 5; + rFeatures.mSpaceDimension = 3; } int BernoulliBeamElasticConstitutiveLaw::Check( @@ -55,19 +55,19 @@ int BernoulliBeamElasticConstitutiveLaw::Check( KRATOS_ERROR_IF_NOT(rMaterialProperties[YOUNG_MODULUS] > 0.0) << "The YOUNG_MODULUS value is lower than 0.0" << std::endl; KRATOS_ERROR_IF (rMaterialProperties[POISSON_RATIO] < 0.0) << "The POISSON_RATIO value is lower than 0.0" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[POISSON_RATIO] < 0.5) << "The POISSON_RATIO cannot be greater than or equal 0.5." << std::endl; - + // Check for IGA beam cross-section properties KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(CROSS_AREA)) << "CROSS_AREA is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_V)) << "I_V is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_N)) << "I_N is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_T)) << "I_T is not defined in the properties" << std::endl; - + // Validate property values KRATOS_ERROR_IF_NOT(rMaterialProperties[CROSS_AREA] > 0.0) << "CROSS_AREA must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I_V] > 0.0) << "I_V must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I_N] > 0.0) << "I_N must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I_T] > 0.0) << "I_T must be positive" << std::endl; - + return 0; } @@ -98,7 +98,7 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti const double E = r_material_properties[YOUNG_MODULUS]; const double nu = r_material_properties[POISSON_RATIO]; const double G = E / (2.0 * (1.0 + nu)); - + // Retrieve beam cross-section properties const double A = r_material_properties[CROSS_AREA]; const double I_v = r_material_properties[I_V]; @@ -137,4 +137,4 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti } } -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h index a945e5699823..276299eb0f7a 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h @@ -155,4 +155,4 @@ class KRATOS_API(IGA_APPLICATION) BernoulliBeamElasticConstitutiveLaw : public C } }; // Class BernoulliBeamElasticConstitutiveLaw -} // namespace Kratos. \ No newline at end of file +} // namespace Kratos. diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index c7e8a9f02c55..f8ba967da4fc 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -956,7 +956,7 @@ namespace Kratos } } - + void BeamBaseElement3D::ComputeTangentSecondDerivativeVariation( const Vector& rShapeFunctionDerivatives, const Vector& rShapeFunctionSecondDerivatives, @@ -1241,9 +1241,9 @@ namespace Kratos } } - - void BeamBaseElement3D::ComputeRodriguesMatrix(const array_1d& rAxis, + + void BeamBaseElement3D::ComputeRodriguesMatrix(const array_1d& rAxis, const double Phi, Matrix3d& rRodriguesMatrix) { rRodriguesMatrix.clear(); @@ -1656,22 +1656,22 @@ namespace Kratos double sin_phi; sin_phi = sin(Phi); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - + for (size_t s = 0;s < NumberOfDofs;s++) { - - + + if (t == u) { rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * cos_phi - phi_derivative_variation(s) * phi_variation(r) * cos_phi + sin_phi * PhiDerivative * phi_variation[r] * phi_variation[s]; } - + { for (int k = 0; k < 3; k++) { @@ -1688,8 +1688,8 @@ namespace Kratos + phi_variation[s] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] ; - - rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); + + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); } } @@ -1716,7 +1716,7 @@ namespace Kratos const SizeType DofsPerNode, Matrix& rRodriguesMatrixSecondDerivativeVariation) { - + rRodriguesMatrixSecondDerivativeVariation.resize(3 * NumberOfDofs, 3); rRodriguesMatrixSecondDerivativeVariation.clear(); @@ -1740,14 +1740,14 @@ namespace Kratos levi_civita[1][0][2] = -1; levi_civita[2][1][0] = -1; - for (size_t t = 0; t < 3; t++) + for (size_t t = 0; t < 3; t++) { for (size_t u = 0; u < 3; u++) { for (size_t r = 0; r < NumberOfDofs; r++) { - size_t xyz = r % DofsPerNode; - size_t i= r / DofsPerNode; + size_t xyz = r % DofsPerNode; + size_t i= r / DofsPerNode; if (t == u) { if (xyz > 2) @@ -1762,7 +1762,7 @@ namespace Kratos if (xyz > 2) rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (rShapeFunctionSecondDerivatives[i] * cos(Phi) - PhiSecondDerivative * rShapeFunctions[i] * sin(Phi) - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * sin(Phi) - pow(PhiDerivative, 2) * rShapeFunctions[i] * cos(Phi)) * levi_civita[t][k][u] * rAxis[k] + 2 * (cos(Phi) * rShapeFunctionDerivatives[i] - sin(Phi) * rShapeFunctions[i] * PhiDerivative) * levi_civita[t][k][u] * rAxisDerivative[k] + cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxisSecondDerivative[k]; else - rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + 2 * PhiDerivative * cos(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisSecondDerivativeVariation[k * NumberOfDofs + r]; + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + 2 * PhiDerivative * cos(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisSecondDerivativeVariation[k * NumberOfDofs + r]; } } } @@ -1789,13 +1789,13 @@ namespace Kratos Matrix& rRodriguesMatrixSecondVariation, Matrix& rRodriguesMatrixDerivativeSecondVariation) { - + rRodriguesMatrixVariation.clear(); - + rRodriguesMatrixDerivativeVariation.clear(); - + rRodriguesMatrixSecondVariation.clear(); - + rRodriguesMatrixDerivativeSecondVariation.clear(); int levi_civita[3][3][3]; @@ -1836,14 +1836,14 @@ namespace Kratos double sin_phi; sin_phi = sin(Phi); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; - size_t i= r / DofsPerNode; + size_t xyz_r = r % DofsPerNode; + size_t i= r / DofsPerNode; if (t == u) { if (xyz_r > 2) @@ -1862,26 +1862,26 @@ namespace Kratos else { rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += sin(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; - rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += cos(Phi) * PhiDerivative * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += cos(Phi) * PhiDerivative * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r]; } } for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyz_s = s % DofsPerNode; - + size_t xyz_s = s % DofsPerNode; + if (t == u) { rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -cos(Phi) * phi_variation[r] * phi_variation[s]; rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * cos_phi - phi_derivative_variation(s) * phi_variation(r) * cos_phi + sin_phi * PhiDerivative * phi_variation[r] * phi_variation[s]; } - + { for (int k = 0; k < 3; k++) { if (xyz_r > 2 || xyz_s > 2) rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -sin(Phi) * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + phi_variation[r] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + phi_variation[s] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; else - rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin(Phi) * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s); + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin(Phi) * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s); rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * sin_phi * levi_civita[t][k][u] * rAxis[k] - phi_derivative_variation(s) * phi_variation(r) * sin_phi * levi_civita[t][k][u] * rAxis[k] @@ -1896,8 +1896,8 @@ namespace Kratos + phi_variation[s] * cos_phi * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] ; - - rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); + + rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin_phi * levi_civita[t][k][u] * rAxisDerivativeSecondVariation(k * NumberOfDofs + r, s); } } } @@ -1920,7 +1920,7 @@ namespace Kratos rRodriguesMatrixSecondDerivative.clear(); Matrix3d identity_matrix; - identity_matrix.clear(); + identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1; } for (int i = 0; i < 3; i++) { rRodriguesMatrixSecondDerivative(i, i) = -PhiSecondDerivative * sin(Phi) - pow(PhiDerivative, 2) * cos(Phi); } @@ -1931,14 +1931,14 @@ namespace Kratos void BeamBaseElement3D::ComputeLambdaMatrix(const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, Matrix3d& rLambdaMatrix) { - rLambdaMatrix.clear(); + rLambdaMatrix.clear(); Matrix3d lambda_matrix_auxiliary; - lambda_matrix_auxiliary.clear(); + lambda_matrix_auxiliary.clear(); double scaling_factor; Matrix3d identity_matrix; identity_matrix.resize(3, 3, false); - identity_matrix.clear(); + identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } array_1d reference_cross_current; CrossProduct(reference_cross_current, rReferenceTangent, rCurrentTangent); @@ -1979,12 +1979,12 @@ namespace Kratos const array_1d& rCurrentTangentDerivative, Matrix3d& rLambdaMatrixDerivative) { - rLambdaMatrixDerivative.clear(); + rLambdaMatrixDerivative.clear(); double scaling_factor; Matrix3d identity_matrix; - identity_matrix.clear(); + identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); @@ -2015,12 +2015,12 @@ namespace Kratos const array_1d& rCurrentTangentSecondDerivative, Matrix3d& rLambdaMatrixSecondDerivative) { - rLambdaMatrixSecondDerivative.clear(); + rLambdaMatrixSecondDerivative.clear(); double scaling_factor; Matrix3d identity_matrix; - identity_matrix.clear(); + identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); @@ -2064,14 +2064,14 @@ namespace Kratos const SizeType DofsPerNode, Matrix& rLambdaMatrixVariation) { - + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); - + rLambdaMatrixVariation.clear(); Matrix3d identity_matrix; - identity_matrix.clear(); + identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1.; } int levi_civita[3][3][3]; @@ -2105,11 +2105,11 @@ namespace Kratos reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; for (size_t u = 0;u < 3;u++) { for (size_t k = 0;k < 3;k++) @@ -2129,10 +2129,10 @@ namespace Kratos for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; - + size_t xyz = r % DofsPerNode; + if (xyz > 2) tangent_dot_product_variation(r) = 0; @@ -2141,14 +2141,14 @@ namespace Kratos } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; - + size_t xyz = r % DofsPerNode; + if (t == u) { if (xyz > 2) @@ -2158,7 +2158,7 @@ namespace Kratos } for (int k = 0; k < 3; k++) { - rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; } rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); @@ -2175,10 +2175,10 @@ namespace Kratos const SizeType NumberOfDofs, const SizeType DofsPerNode, Matrix& rLambdaMatrixSecondVariation) - { - - - rLambdaMatrixSecondVariation.clear(); + { + + + rLambdaMatrixSecondVariation.clear(); double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); @@ -2222,9 +2222,9 @@ namespace Kratos for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) tangent_dot_product_variation(r) = 0; @@ -2239,12 +2239,12 @@ namespace Kratos for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - for (size_t s = 0;s < NumberOfDofs;s++) + for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzr = r % DofsPerNode; - size_t xyzs = s % DofsPerNode; + size_t xyzr = r % DofsPerNode; + size_t xyzs = s % DofsPerNode; if (xyzr > 2 || xyzs > 2) tangent_dot_product_second_variation(r, s) += 0; @@ -2256,11 +2256,11 @@ namespace Kratos - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t u = 0;u < 3;u++) { for (size_t k = 0;k < 3;k++) @@ -2274,16 +2274,16 @@ namespace Kratos } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { - for (size_t u = 0;u < 3;u++) + for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyz_s = s % DofsPerNode; + size_t xyz_s = s % DofsPerNode; for (size_t k = 0;k < 3;k++) { if (xyz_r > 2 || xyz_s > 2) @@ -2296,16 +2296,16 @@ namespace Kratos } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyzr = r % DofsPerNode; + size_t xyzr = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzs = s % DofsPerNode; + size_t xyzs = s % DofsPerNode; if (xyzr > 2 || xyzs > 2) rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) = 0; else { @@ -2314,7 +2314,7 @@ namespace Kratos else { for (int k = 0; k < 3; k++) - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); } rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) @@ -2339,8 +2339,8 @@ namespace Kratos const SizeType DofsPerNode, Matrix& rLambdaMatrixDerivativeVariation) { - - rLambdaMatrixDerivativeVariation.clear(); + + rLambdaMatrixDerivativeVariation.clear(); double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); @@ -2392,7 +2392,7 @@ namespace Kratos tangent_cross_product_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t r = 0;r < NumberOfDofs;r++) { @@ -2430,9 +2430,9 @@ namespace Kratos for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) { @@ -2442,7 +2442,7 @@ namespace Kratos } else { - + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; tangent_dot_product_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; @@ -2451,13 +2451,13 @@ namespace Kratos } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 0; @@ -2470,7 +2470,7 @@ namespace Kratos { { for (int k = 0; k < 3; k++) - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; } } @@ -2501,10 +2501,10 @@ namespace Kratos const SizeType DofsPerNode, Matrix& rLambdaMatrixSecondDerivativeVariation) { - + rLambdaMatrixSecondDerivativeVariation.resize(3 * NumberOfDofs, 3); - rLambdaMatrixSecondDerivativeVariation.clear(); - + rLambdaMatrixSecondDerivativeVariation.clear(); + double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); double reference_derivative_dot_current = inner_prod(rReferenceTangentDerivative, rCurrentTangent); @@ -2513,7 +2513,7 @@ namespace Kratos double reference_dot_current_second_derivative = inner_prod(rReferenceTangent, rCurrentTangentSecondDerivative); double tangent_dot_product_derivative = reference_derivative_dot_current + reference_dot_current_derivative; double tangent_dot_product_second_derivative = reference_second_derivative_dot_current + 2 * tangent_derivative_dot_product + reference_dot_current_second_derivative; - + int levi_civita[3][3][3]; for (int i = 0; i < 3; i++) { @@ -2525,32 +2525,32 @@ namespace Kratos } } } - + levi_civita[0][1][2] = 1; levi_civita[2][0][1] = 1; levi_civita[1][2][0] = 1; - + levi_civita[0][2][1] = -1; levi_civita[1][0][2] = -1; levi_civita[2][1][0] = -1; - - Vector reference_cross_current_variation; - Vector reference_cross_current_derivative_variation; - Vector reference_derivative_cross_current_variation; - Vector reference_second_derivative_cross_current_variation; - Vector reference_derivative_cross_current_derivative_variation; - Vector reference_cross_current_second_derivative_variation; - Vector reference_cross_current; - Vector reference_cross_current_derivative; - Vector reference_derivative_cross_current; - Vector reference_cross_current_second_derivative; - Vector reference_second_derivative_cross_current; - Vector reference_derivative_cross_current_derivative; - Vector tangent_cross_product_derivative; - Vector tangent_cross_product_second_derivative; - Vector tangent_cross_product_derivative_variation; - Vector tangent_cross_product_second_derivative_variation; - + + Vector reference_cross_current_variation; + Vector reference_cross_current_derivative_variation; + Vector reference_derivative_cross_current_variation; + Vector reference_second_derivative_cross_current_variation; + Vector reference_derivative_cross_current_derivative_variation; + Vector reference_cross_current_second_derivative_variation; + Vector reference_cross_current; + Vector reference_cross_current_derivative; + Vector reference_derivative_cross_current; + Vector reference_cross_current_second_derivative; + Vector reference_second_derivative_cross_current; + Vector reference_derivative_cross_current_derivative; + Vector tangent_cross_product_derivative; + Vector tangent_cross_product_second_derivative; + Vector tangent_cross_product_derivative_variation; + Vector tangent_cross_product_second_derivative_variation; + reference_cross_current_variation.resize(NumberOfDofs * 3); reference_cross_current_derivative_variation.resize(NumberOfDofs * 3); reference_derivative_cross_current_variation.resize(NumberOfDofs * 3); @@ -2567,7 +2567,7 @@ namespace Kratos reference_cross_current_second_derivative.resize(3); tangent_cross_product_derivative.resize(3); tangent_cross_product_second_derivative.resize(3); - + reference_cross_current_variation.clear(); reference_cross_current_derivative_variation.clear(); reference_derivative_cross_current_variation.clear(); @@ -2584,7 +2584,7 @@ namespace Kratos tangent_cross_product_second_derivative.clear(); tangent_cross_product_derivative_variation.clear(); tangent_cross_product_second_derivative_variation.clear(); - + reference_cross_current = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangent); reference_cross_current_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentDerivative); reference_derivative_cross_current = MathUtils::CrossProduct(rReferenceTangentDerivative, rCurrentTangent); @@ -2593,8 +2593,8 @@ namespace Kratos reference_cross_current_second_derivative = MathUtils::CrossProduct(rReferenceTangent, rCurrentTangentSecondDerivative); tangent_cross_product_derivative = reference_cross_current_derivative + reference_derivative_cross_current; tangent_cross_product_second_derivative = 2 * reference_derivative_cross_current_derivative + reference_second_derivative_cross_current + reference_cross_current_second_derivative; - - for (size_t t = 0; t < 3; t++) + + for (size_t t = 0; t < 3; t++) { for (size_t r = 0; r < NumberOfDofs; r++) { @@ -2627,7 +2627,7 @@ namespace Kratos } tangent_cross_product_derivative_variation = reference_cross_current_derivative_variation + reference_derivative_cross_current_variation; tangent_cross_product_second_derivative_variation = 2 * reference_derivative_cross_current_derivative_variation + reference_second_derivative_cross_current_variation + reference_cross_current_second_derivative_variation; - + Vector tangent_dot_product_variation; tangent_dot_product_variation.resize(NumberOfDofs); tangent_dot_product_variation.clear(); @@ -2646,13 +2646,13 @@ namespace Kratos Vector reference_dot_current_second_derivative_variation; reference_dot_current_second_derivative_variation.resize(NumberOfDofs); reference_dot_current_second_derivative_variation.clear(); - + for (size_t t = 0; t < 3; t++) { - for (size_t r = 0; r < NumberOfDofs; r++) + for (size_t r = 0; r < NumberOfDofs; r++) { - size_t xyz = r % DofsPerNode; - + size_t xyz = r % DofsPerNode; + if (xyz > 2) { tangent_dot_product_variation(r) += 0; @@ -2664,7 +2664,7 @@ namespace Kratos } else { - + tangent_dot_product_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; reference_dot_current_derivative_variation(r) += rCurrentTangentDerivativeVariation[t * NumberOfDofs + r] * rReferenceTangent[t]; reference_derivative_dot_current_variation(r) += rCurrentTangentVariation[t * NumberOfDofs + r] * rReferenceTangentDerivative[t]; @@ -2680,36 +2680,36 @@ namespace Kratos Vector tangent_dot_product_second_derivative_variation; tangent_dot_product_second_derivative_variation.resize(NumberOfDofs); tangent_dot_product_second_derivative_variation.clear(); - + tangent_dot_product_derivative_variation = reference_derivative_dot_current_variation + reference_dot_current_derivative_variation; tangent_dot_product_second_derivative_variation = reference_second_derivative_dot_current_variation + 2 * tangent_derivative_dot_product_variation + reference_dot_current_second_derivative_variation; - + double inverse_one_plus_tangent_dot_squared = 1.0 / pow(1.0 + tangent_dot_product, 2); double inverse_one_plus_tangent_dot_cubed = 1.0 / pow(1.0 + tangent_dot_product, 3); double inverse_one_plus_tangent_dot_fourth = 1.0 / pow(1.0 + tangent_dot_product, 4); - - for (size_t t = 0; t < 3; t++) + + for (size_t t = 0; t < 3; t++) { for (size_t u = 0; u < 3; u++) { for (size_t r = 0; r < NumberOfDofs; r++) { - size_t xyz = r % DofsPerNode; - + size_t xyz = r % DofsPerNode; + if (xyz > 2) rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 0; else { if (t == u) rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += tangent_dot_product_second_derivative_variation(r); - + else { { for (int k = 0; k < 3; k++) - rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * tangent_cross_product_second_derivative_variation[r + k * NumberOfDofs]; + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * tangent_cross_product_second_derivative_variation[r + k * NumberOfDofs]; } - + } rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative_variation(r) * inverse_one_plus_tangent_dot_squared + 2 * (tangent_dot_product_variation(r) * tangent_dot_product_second_derivative + 2 * tangent_dot_product_derivative_variation[r] * tangent_dot_product_derivative) * inverse_one_plus_tangent_dot_cubed - 6 * (pow(tangent_dot_product_derivative, 2) * tangent_dot_product_variation[r]) * inverse_one_plus_tangent_dot_fourth) * reference_cross_current[t] * reference_cross_current[u]; rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative * inverse_one_plus_tangent_dot_squared + 2 * pow(tangent_dot_product_derivative, 2) * inverse_one_plus_tangent_dot_cubed) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); @@ -2718,11 +2718,11 @@ namespace Kratos rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation(r) * inverse_one_plus_tangent_dot_squared * (tangent_cross_product_second_derivative[t] * reference_cross_current[u] + 2 * tangent_cross_product_derivative[t] * tangent_cross_product_derivative[u] + reference_cross_current[t] * tangent_cross_product_second_derivative[u]); rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * (tangent_cross_product_second_derivative_variation[t * NumberOfDofs + r] * reference_cross_current[u] + tangent_cross_product_second_derivative[t] * reference_cross_current_variation[u * NumberOfDofs + r] + 2 * tangent_cross_product_derivative_variation[t * NumberOfDofs + r] * tangent_cross_product_derivative[u] + 2 * tangent_cross_product_derivative[t] * tangent_cross_product_derivative_variation[u * NumberOfDofs + r] + reference_cross_current_variation[t * NumberOfDofs + r] * tangent_cross_product_second_derivative[u] + reference_cross_current[t] * tangent_cross_product_second_derivative_variation[u * NumberOfDofs + r]); } - + } } } - + } void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( @@ -2738,8 +2738,8 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( const SizeType DofsPerNode, Matrix& rLambdaMatrixDerivativeSecondVariation) { - - rLambdaMatrixDerivativeSecondVariation.clear(); + + rLambdaMatrixDerivativeSecondVariation.clear(); double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); @@ -2803,9 +2803,9 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) { @@ -2834,14 +2834,14 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyzr = r % DofsPerNode; - - for (size_t s = 0;s < NumberOfDofs;s++) + size_t xyzr = r % DofsPerNode; + + for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzs = s % DofsPerNode; - + size_t xyzs = s % DofsPerNode; + if (xyzr > 2 || xyzs > 2) { @@ -2857,11 +2857,11 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t u = 0;u < 3;u++) { if (xyz_r > 2) @@ -2891,16 +2891,16 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( reference_derivative_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); reference_derivative_cross_current_second_variation.clear(); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { - for (size_t u = 0;u < 3;u++) + for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyz_s = s % DofsPerNode; + size_t xyz_s = s % DofsPerNode; if (xyz_r < 3 || xyz_s < 3) { for (size_t k = 0;k < 3;k++) @@ -2915,17 +2915,17 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { - for (size_t u = 0;u < 3;u++) + for (size_t u = 0;u < 3;u++) { for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyz_s = s % DofsPerNode; + size_t xyz_s = s % DofsPerNode; for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; if (t == u) { if (xyz_r > 2 || xyz_s > 2) @@ -2941,23 +2941,23 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( else { for (int k = 0; k < 3; k++) - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); } } } } } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyzr = r % DofsPerNode; + size_t xyzr = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzs = s % DofsPerNode; + size_t xyzs = s % DofsPerNode; if (xyzr > 2 || xyzs > 2) rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 0; else @@ -2966,11 +2966,11 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + - reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); } } } @@ -2994,16 +2994,16 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( Matrix& rLambdaMatrixSecondVariation, Matrix& rLambdaMatrixDerivativeSecondVariation) { - - - rLambdaMatrixVariation.clear(); - - rLambdaMatrixDerivativeVariation.clear(); - - rLambdaMatrixSecondVariation.clear(); - - rLambdaMatrixDerivativeSecondVariation.clear(); + + + rLambdaMatrixVariation.clear(); + + rLambdaMatrixDerivativeVariation.clear(); + + rLambdaMatrixSecondVariation.clear(); + + rLambdaMatrixDerivativeSecondVariation.clear(); double tangent_dot_product = inner_prod(rReferenceTangent, rCurrentTangent); double reference_dot_current_derivative = inner_prod(rReferenceTangent, rCurrentTangentDerivative); @@ -3067,9 +3067,9 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) { @@ -3098,14 +3098,14 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( for (size_t t = 0;t < 3;t++) { - for (size_t r = 0;r < NumberOfDofs;r++) + for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyzr = r % DofsPerNode; - - for (size_t s = 0;s < NumberOfDofs;s++) + size_t xyzr = r % DofsPerNode; + + for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzs = s % DofsPerNode; - + size_t xyzs = s % DofsPerNode; + if (xyzr > 2 || xyzs > 2) { @@ -3121,11 +3121,11 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t u = 0;u < 3;u++) { if (xyz_r > 2) @@ -3155,16 +3155,16 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( reference_derivative_cross_current_second_variation.resize(3 * NumberOfDofs, NumberOfDofs); reference_derivative_cross_current_second_variation.clear(); - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { - for (size_t u = 0;u < 3;u++) + for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz_r = r % DofsPerNode; + size_t xyz_r = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyz_s = s % DofsPerNode; + size_t xyz_s = s % DofsPerNode; if (xyz_r < 3 || xyz_s < 3) { for (size_t k = 0;k < 3;k++) @@ -3179,18 +3179,18 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyz = r % DofsPerNode; + size_t xyz = r % DofsPerNode; if (xyz > 2) { - - + + } else { @@ -3204,13 +3204,13 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( for (int k = 0; k < 3; k++) { rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_derivative_variation[r + k * NumberOfDofs] + levi_civita[t][k][u] * reference_derivative_cross_current_variation[r + k * NumberOfDofs]; } } - + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); - + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); @@ -3220,20 +3220,20 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - for (size_t t = 0;t < 3;t++) + for (size_t t = 0;t < 3;t++) { for (size_t u = 0;u < 3;u++) { for (size_t r = 0;r < NumberOfDofs;r++) { - size_t xyzr = r % DofsPerNode; + size_t xyzr = r % DofsPerNode; for (size_t s = 0;s < NumberOfDofs;s++) { - size_t xyzs = s % DofsPerNode; + size_t xyzs = s % DofsPerNode; if (xyzr > 2 || xyzs > 2) { - - + + } else { @@ -3246,26 +3246,26 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( { for (int k = 0; k < 3; k++) { - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_derivative_second_variation(k * NumberOfDofs + r, s) + levi_civita[t][k][u] * reference_derivative_cross_current_second_variation(k * NumberOfDofs + r, s); } } - + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) - tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + s, r)); - + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + - reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); } } @@ -3277,4 +3277,4 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.h b/applications/IgaApplication/custom_elements/beam_base_element_3D.h index c39c96fb5e28..1f31e9c19aca 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.h +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.h @@ -473,4 +473,4 @@ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D }; // Class BeamBaseElement3D -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index c83610cf0657..a9ac4206594c 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -59,7 +59,7 @@ namespace Kratos mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); KRATOS_CATCH("") - + } @@ -176,7 +176,7 @@ namespace Kratos ComputeCurrentCrossSectionGeometry( rKinematicVariables); } - + void NonLinearBernoulliBeamElement3D::CalculateAll( MatrixType& rLeftHandSideMatrix, @@ -419,7 +419,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( KRATOS_CATCH("") } - + int NonLinearBernoulliBeamElement3D::Check( const ProcessInfo& rCurrentProcessInfo) const { @@ -559,18 +559,18 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( lower_parameter_coordinate = local_axis_orientation(0, 0); upper_parameter_coordinate = local_axis_orientation(number_of_orientation_points - 1, 0); - + // Extract normal vector components for start and end Vector3d lower_normal; lower_normal[0] = local_axis_orientation(0, 1); lower_normal[1] = local_axis_orientation(0, 2); lower_normal[2] = local_axis_orientation(0, 3); - + Vector3d upper_normal; upper_normal[0] = local_axis_orientation(number_of_orientation_points - 1, 1); upper_normal[1] = local_axis_orientation(number_of_orientation_points - 1, 2); upper_normal[2] = local_axis_orientation(number_of_orientation_points - 1, 3); - + // Convert normal vectors to rotation angles (phi) for backward compatibility lower_twist_angle = CalculateDeltaPhi(rKinematicVariables, lower_normal); upper_twist_angle = CalculateDeltaPhi(rKinematicVariables, upper_normal); @@ -1059,7 +1059,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); - + // Extract kinematic variables Vector3d current_first_base_vector = rKinematicVariables.r1; Vector3d current_second_base_vector = rKinematicVariables.r2; @@ -1088,8 +1088,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( //compute axial_variation for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) { - size_t dof_component = dof_index % mDofsPerNode; - size_t control_point_index = dof_index / mDofsPerNode; + size_t dof_component = dof_index % mDofsPerNode; + size_t control_point_index = dof_index / mDofsPerNode; if (dof_component > 2) axial_variation[dof_index] = 0; else @@ -1323,9 +1323,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector current_first_base_vector_variation; current_first_base_vector_variation.resize(3 * mNumberOfDofs); current_first_base_vector_variation.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) + for (size_t row_component = 0; row_component < 3; row_component++) { - for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) + for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) { size_t dof_component = dof_index % mDofsPerNode; size_t control_point_index = dof_index / mDofsPerNode; @@ -1348,7 +1348,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } - + // Initialize B matrices rBAxial.resize(5, mNumberOfDofs); rBBending1.resize(5, mNumberOfDofs); @@ -1366,7 +1366,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( noalias(row(rBBending2, 2)) = binormal_curvature_variation; // Bending about v-axis noalias(row(rBTorsion1, 3)) = normal_torsion_variation; // Torsion n in row 1 (shear stress) noalias(row(rBTorsion2, 4)) = binormal_torsion_variation; // Torsion v in row 2 (shear stress) - + KRATOS_CATCH("") } @@ -1388,7 +1388,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector shape_functions = row(r_geometry.ShapeFunctionsValues(GetIntegrationMethod()), IntegrationPointIndex); Vector shape_function_derivatives = column(r_geometry.ShapeFunctionDerivatives(1, IntegrationPointIndex, GetIntegrationMethod()), 0); Vector shape_function_second_derivatives = column(r_geometry.ShapeFunctionDerivatives(2, IntegrationPointIndex, GetIntegrationMethod()), 0); - + // Extract kinematic variables Vector3d current_first_base_vector = rKinematicVariables.r1; Vector3d current_second_base_vector = rKinematicVariables.r2; @@ -1415,10 +1415,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( binormal_torsion_second_variation.clear(); //compute axial_variation - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) + for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) { - size_t dof_component = dof_index % mDofsPerNode; - size_t control_point_index = dof_index / mDofsPerNode; + size_t dof_component = dof_index % mDofsPerNode; + size_t control_point_index = dof_index / mDofsPerNode; if (dof_component > 2) for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) axial_second_variation(dof_index, second_dof_index) = 0.0; @@ -1426,8 +1426,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) { - size_t second_dof_component = second_dof_index % mDofsPerNode; - int second_control_point_index = second_dof_index / mDofsPerNode; + size_t second_dof_component = second_dof_index % mDofsPerNode; + int second_control_point_index = second_dof_index / mDofsPerNode; if (second_dof_component > 2) axial_second_variation(dof_index, second_dof_index) = 0; else @@ -1438,7 +1438,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } } - + //compute normal_curvature_second_variation, binormal_curvature_second_variation, normal_torsion_second_variation, binormal_torsion_second_variation Vector3d current_tangent; current_tangent.clear(); @@ -1569,7 +1569,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( cross_section_transformation_derivative.clear(); cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; - + mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); mSMatrixLambdaVariationRodriguesLambda.clear(); @@ -1632,8 +1632,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } - - + + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda @@ -1879,11 +1879,11 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( noalias(rGAxial) = axial_second_variation; noalias(rGBending1) = normal_curvature_second_variation; - noalias(rGBending2) = binormal_curvature_second_variation; - noalias(rGTorsion1) = normal_torsion_second_variation; - noalias(rGTorsion2) = binormal_torsion_second_variation; - + noalias(rGBending2) = binormal_curvature_second_variation; + noalias(rGTorsion1) = normal_torsion_second_variation; + noalias(rGTorsion2) = binormal_torsion_second_variation; + KRATOS_CATCH("") - + } -} \ No newline at end of file +} diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h index 8c2027f43c17..86013d0cffb2 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -252,7 +252,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D ConstitutiveVariables& rConstitutiveVariables, ConstitutiveLaw::Parameters& rConstitutiveLawParameters, const ConstitutiveLaw::StressMeasure StressMeasure); - + void ComputeBMatrices( const IndexType IntegrationPointIndex, const KinematicVariables& rKinematicVariables, @@ -270,7 +270,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D Matrix& rGBending2, Matrix& rGTorsion1, Matrix& rGTorsion2); - + void ComputeGAxial( const IndexType IntegrationPointIndex, Matrix& rGAxial, @@ -472,4 +472,4 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D ///@} -} // Namespace Kratos \ No newline at end of file +} // Namespace Kratos diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp index c04d86e3de6f..a78ca3c7223d 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -19,12 +19,12 @@ #include "includes/define.h" #include "iga_application_variables.h" #include "custom_elements/non_linear_bernoulli_beam_element_3D.h" -#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/beam_base_element_3D.h" namespace Kratos { -//for normal beam +//for normal beam ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( ModelPart& rModelPart) : Process() @@ -33,7 +33,7 @@ ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( { } -//for normal beam +//for normal beam ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( ModelPart& rModelPart, const NurbsCurveGeometry<3, PointerVector>& rParentCurve) @@ -43,7 +43,7 @@ ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( { } -//for embedded beam +//for embedded beam ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( ModelPart& rModelPart, const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rParentCurve) @@ -60,7 +60,7 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( { array_1d V = ZeroVector(3); array_1d up = ZeroVector(3); - + // Evaluate at the start of the beam array_1d local_coordinates = ZeroVector(3); local_coordinates[0] = rCurve.DomainInterval().GetT0(); @@ -82,7 +82,7 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( MathUtils::CrossProduct(V, rT0, up); V /= norm_2(V); MathUtils::CrossProduct(rN0, V, rT0); - rN0 /= norm_2(rN0); + rN0 /= norm_2(rN0); } void ComputeBeamVectorsProcess::ComputeT0AndN0( @@ -92,7 +92,7 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( { array_1d V = ZeroVector(3); array_1d up = ZeroVector(3); - + // Evaluate at the start of the beam array_1d local_coordinates = ZeroVector(3); local_coordinates[0] = rCurve.DomainInterval().GetT0(); @@ -114,9 +114,9 @@ void ComputeBeamVectorsProcess::ComputeT0AndN0( array_1d G2 = global_space_derivatives[2]; MathUtils::CrossProduct(rN0, G1, G2); //surface normal = G1 × G2 rN0 /= norm_2(rN0); - + MathUtils::CrossProduct(V, rT0, rN0); - V /= norm_2(V); + V /= norm_2(V); } @@ -169,4 +169,4 @@ void ComputeBeamVectorsProcess::ExecuteInitialize() } -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h index fd95f7d823b4..69b875e795f2 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h @@ -58,10 +58,10 @@ class KRATOS_API(IGA_APPLICATION) ComputeBeamVectorsProcess ComputeBeamVectorsProcess(ModelPart& rModelPart); - ComputeBeamVectorsProcess(ModelPart& rModelPart, + ComputeBeamVectorsProcess(ModelPart& rModelPart, const NurbsCurveGeometry<3, PointerVector>& rParentCurve); - ComputeBeamVectorsProcess(ModelPart& rModelPart, + ComputeBeamVectorsProcess(ModelPart& rModelPart, const NurbsCurveOnSurfaceGeometry<3, PointerVector, PointerVector>& rParentCurve); ~ComputeBeamVectorsProcess() = default; @@ -117,9 +117,9 @@ class KRATOS_API(IGA_APPLICATION) ComputeBeamVectorsProcess ///@name Member Variables ///@{ ModelPart& mrThisModelPart; - const Geometry* mpParentCurve; + const Geometry* mpParentCurve; ///@} }; // Class ComputeBeamVectorsProcess } // namespace Kratos. -#endif // KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED defined \ No newline at end of file +#endif // KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED defined diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp index fe75015cd93a..22f3f5d0fd67 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp @@ -28,4 +28,4 @@ void AddCustomConstitutiveLawsToPython(pybind11::module& m) ; } -} // namespace Kratos::Python. \ No newline at end of file +} // namespace Kratos::Python. diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h index d89760c8cc7e..cf14791bce42 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h @@ -24,4 +24,4 @@ void AddCustomConstitutiveLawsToPython(pybind11::module& m); } // namespace Kratos::Python -#endif // KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED \ No newline at end of file +#endif // KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED diff --git a/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp index 31cac4e4e2a7..57f925fe56b9 100644 --- a/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_utilities_to_python.cpp @@ -92,7 +92,7 @@ void AddCustomUtilitiesToPython( shape_function_values); }); - + m.def( "GetNurbsCurveKnots", [](Geometry& rGeometry) { diff --git a/applications/IgaApplication/custom_python/iga_python_application.cpp b/applications/IgaApplication/custom_python/iga_python_application.cpp index e32fe5475f9f..61afb6d9133e 100644 --- a/applications/IgaApplication/custom_python/iga_python_application.cpp +++ b/applications/IgaApplication/custom_python/iga_python_application.cpp @@ -128,4 +128,4 @@ PYBIND11_MODULE(KratosIgaApplication, m) } // namespace Python } // namespace Kratos -#endif // defined(KRATOS_PYTHON) \ No newline at end of file +#endif // defined(KRATOS_PYTHON) diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index d4515bfe8ae9..84ab71986f22 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -255,4 +255,4 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(BREP_ID) } -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index cfb9fa91da7f..bfc7b51298ad 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -208,4 +208,4 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio ///@} -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index f141dd1851f1..373d1387627a 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -123,4 +123,4 @@ KRATOS_CREATE_VARIABLE(std::vector, INTERPOLATION_NODES_ID) KRATOS_CREATE_VARIABLE(int, BREP_ID) -} // namespace Kratos \ No newline at end of file +} // namespace Kratos diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index dd7d4019519d..68ee700793a3 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -137,4 +137,4 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, int, BREP_ID) } // namespace Kratos -#endif // !defined(KRATOS_IGA_APPLICATION_VARIABLES_H_INCLUDED) \ No newline at end of file +#endif // !defined(KRATOS_IGA_APPLICATION_VARIABLES_H_INCLUDED) diff --git a/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py b/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py index c3d00f10d0e5..d3d4d526568a 100644 --- a/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py +++ b/applications/IgaApplication/python_scripts/compute_beam_vectors_process.py @@ -29,4 +29,4 @@ def __init__(self, model, params): self.process = IGA.ComputeBeamVectorsProcess(self.model_part_beam) def ExecuteInitialize(self): - self.process.ExecuteInitialize() \ No newline at end of file + self.process.ExecuteInitialize() From 7f5069a1969959789c2fea49b6ee8648eb3b6f7a Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 20:07:11 +0100 Subject: [PATCH 22/32] [IGA] Address review of the Bernoulli beam element - Use the core I22/I33 instead of the IGA I_N/I_V (I22 about the normal n, I33 about v = t x n). Remove the unused IGA HEIGHT, WIDTH and VON_MISES_STRESS, which duplicate variables of other applications. - Add body forces (VOLUME_ACCELERATION, dead load) to the residual, with a self-weight test. - Assemble the internal forces from the single non-zero row of each B matrix instead of building temporary 5-vectors. - Turn the 28 scratch member matrices into locals of ComputeBMatrices and ComputeGMatrices. They were recomputed at every integration point anyway. - Document the formulation and reference paper in the element header, and explain the structure and data layout of ComputeGMatrices. - Use std:: math functions, IGA headers and authors in the constitutive law and its Python bindings. Co-Authored-By: Claude Opus 5.5 --- ...ernoulli_beam_elastic_constitutive_law.cpp | 34 +- .../bernoulli_beam_elastic_constitutive_law.h | 14 +- .../custom_elements/beam_base_element_3D.cpp | 188 +++---- .../non_linear_bernoulli_beam_element_3D.cpp | 490 ++++++++++-------- .../non_linear_bernoulli_beam_element_3D.h | 50 +- ...add_custom_constitutive_laws_to_python.cpp | 13 +- .../add_custom_constitutive_laws_to_python.h | 13 +- .../custom_python/iga_python_application.cpp | 7 +- .../IgaApplication/iga_application.cpp | 7 +- .../iga_application_variables.cpp | 5 - .../iga_application_variables.h | 5 - ...etric_non_linear_bernoulli_beam_element.py | 67 ++- 12 files changed, 467 insertions(+), 426 deletions(-) diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp index 092bba96ef7c..16e46000e38e 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -1,10 +1,13 @@ -// KRATOS ___| | | | -// \___ \ __| __| | | __| __| | | __| _` | | -// | | | | | ( | | | | ( | | -// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application // // License: BSD License -// license: IgaApplication/license.txt +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio // // System includes @@ -58,14 +61,14 @@ int BernoulliBeamElasticConstitutiveLaw::Check( // Check for IGA beam cross-section properties KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(CROSS_AREA)) << "CROSS_AREA is not defined in the properties" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_V)) << "I_V is not defined in the properties" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_N)) << "I_N is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I33)) << "I33 is not defined in the properties" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I22)) << "I22 is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_T)) << "I_T is not defined in the properties" << std::endl; // Validate property values KRATOS_ERROR_IF_NOT(rMaterialProperties[CROSS_AREA] > 0.0) << "CROSS_AREA must be positive" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties[I_V] > 0.0) << "I_V must be positive" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties[I_N] > 0.0) << "I_N must be positive" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[I33] > 0.0) << "I33 must be positive" << std::endl; + KRATOS_ERROR_IF_NOT(rMaterialProperties[I22] > 0.0) << "I22 must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I_T] > 0.0) << "I_T must be positive" << std::endl; return 0; @@ -101,8 +104,9 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti // Retrieve beam cross-section properties const double A = r_material_properties[CROSS_AREA]; - const double I_v = r_material_properties[I_V]; - const double I_n = r_material_properties[I_N]; + // Moments of inertia about the local cross-section axes 2 (normal n) and 3 (v = t x n) + const double I_22 = r_material_properties[I22]; + const double I_33 = r_material_properties[I33]; const double I_t = r_material_properties[I_T]; if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_STRESS)) { @@ -112,8 +116,8 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti // Compute stresses according to 5x5 diagonal constitutive matrix with beam properties r_stress_vector[0] = E * A * r_strain_vector[0]; // N = E*A*ε (normal force) - r_stress_vector[1] = E * I_v * r_strain_vector[1]; // M_y = E*I_y*κ_y (bending about y-axis) - r_stress_vector[2] = E * I_n * r_strain_vector[2]; // M_z = E*I_z*κ_z (bending about z-axis) + r_stress_vector[1] = E * I_33 * r_strain_vector[1]; // M_3 = E*I_33*κ_21 (curvature along n, bending about v) + r_stress_vector[2] = E * I_22 * r_strain_vector[2]; // M_2 = E*I_22*κ_31 (curvature along v, bending about n) // The torsional energy is split between the two shear components κ32 and κ23 (equal in magnitude), // so each one carries half of the torsional stiffness, consistent with the constitutive matrix below. r_stress_vector[3] = 0.5 * G * I_t * r_strain_vector[3]; // T = G*I_t*γ_t1 (torsion) @@ -130,8 +134,8 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti // 5x5 diagonal constitutive matrix with beam cross-section properties r_constitutive_matrix(0,0) = E * A; // Normal stiffness - r_constitutive_matrix(1,1) = E * I_v; // Bending stiffness about y-axis - r_constitutive_matrix(2,2) = E * I_n; // Bending stiffness about z-axis + r_constitutive_matrix(1,1) = E * I_33; // Bending stiffness about v + r_constitutive_matrix(2,2) = E * I_22; // Bending stiffness about n r_constitutive_matrix(3,3) = 0.5 * G * I_t; // Torsional stiffness r_constitutive_matrix(4,4) = 0.5 * G * I_t; // Torsional stiffness } diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h index 276299eb0f7a..5aa2eecea288 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h @@ -1,11 +1,13 @@ -// KRATOS ___| | | | -// \___ \ __| __| | | __| __| | | __| _` | | -// | | | | | ( | | | | ( | | -// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application // // License: BSD License -// license: IgaApplication/license.txt - +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio // #pragma once diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index f8ba967da4fc..618e4da1b722 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -255,7 +255,7 @@ namespace Kratos norm_2(rFirstBaseVector); const double first_base_vector_norm_cubed = - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); Vector first_base_vector_variation; first_base_vector_variation.resize( @@ -343,10 +343,10 @@ namespace Kratos norm_2(rFirstBaseVector); const double first_base_vector_norm_cubed = - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); const double first_base_vector_norm_fifth = - pow(first_base_vector_norm, 5); + std::pow(first_base_vector_norm, 5); Vector first_base_vector_variation; first_base_vector_variation.resize( @@ -618,7 +618,7 @@ namespace Kratos - rSecondBaseVector[component] * first_base_vector_dot_first_variation[dof_index] / - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); rTangentDerivativeVariation[ component * mNumberOfDofs + dof_index] += @@ -626,7 +626,7 @@ namespace Kratos first_base_vector_dot_first_variation[dof_index] * first_second_base_vector_product * rFirstBaseVector[component] / - pow(first_base_vector_norm, 5) + std::pow(first_base_vector_norm, 5) - ( first_base_vector_variation[ @@ -640,7 +640,7 @@ namespace Kratos ) * rFirstBaseVector[component] ) / - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); } } } @@ -666,13 +666,13 @@ namespace Kratos norm_2(rFirstBaseVector); const double first_base_vector_norm_cubed = - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); const double first_base_vector_norm_fifth = - pow(first_base_vector_norm, 5); + std::pow(first_base_vector_norm, 5); const double first_base_vector_norm_seventh = - pow(first_base_vector_norm, 7); + std::pow(first_base_vector_norm, 7); Vector first_base_vector_variation = ZeroVector(3 * mNumberOfDofs); @@ -1114,7 +1114,7 @@ namespace Kratos - rThirdBaseVector[component] * first_base_vector_dot_first_variation[dof_index] / - pow(first_base_vector_norm, 3); + std::pow(first_base_vector_norm, 3); rTangentSecondDerivativeVariation[ component * mNumberOfDofs + dof_index] += @@ -1126,13 +1126,13 @@ namespace Kratos rSecondBaseVector[component] * first_second_product_variation[dof_index] ) / - pow(first_base_vector_norm, 3) + std::pow(first_base_vector_norm, 3) + 3.0 * rSecondBaseVector[component] * first_second_base_vector_product * first_base_vector_dot_first_variation[dof_index] / - pow(first_base_vector_norm, 5); + std::pow(first_base_vector_norm, 5); rTangentSecondDerivativeVariation[ component * mNumberOfDofs + dof_index] += @@ -1151,7 +1151,7 @@ namespace Kratos rFirstBaseVector[component] * first_second_product_derivative_variation[dof_index] ) / - pow(first_base_vector_norm, 3) + std::pow(first_base_vector_norm, 3) + 3.0 * ( @@ -1162,7 +1162,7 @@ namespace Kratos first_second_base_vector_product_derivative ) * first_base_vector_dot_first_variation[dof_index] / - pow(first_base_vector_norm, 5); + std::pow(first_base_vector_norm, 5); rTangentSecondDerivativeVariation[ component * mNumberOfDofs + dof_index] += @@ -1170,20 +1170,20 @@ namespace Kratos ( first_base_vector_variation[ component * mNumberOfDofs + dof_index] * - pow(first_second_base_vector_product, 2) + std::pow(first_second_base_vector_product, 2) + rFirstBaseVector[component] * 2.0 * first_second_base_vector_product * first_second_product_variation[dof_index] ) / - pow(first_base_vector_norm, 5) + std::pow(first_base_vector_norm, 5) - 15.0 * rFirstBaseVector[component] * - pow(first_second_base_vector_product, 2) * + std::pow(first_second_base_vector_product, 2) * first_base_vector_dot_first_variation[dof_index] / - pow(first_base_vector_norm, 7); + std::pow(first_base_vector_norm, 7); } } } @@ -1257,14 +1257,14 @@ namespace Kratos } for (SizeType i = 0; i < 3; ++i) { - rRodriguesMatrix(i, i) = cos(Phi); + rRodriguesMatrix(i, i) = std::cos(Phi); } rRodriguesMatrix += CrossProductVectorMatrix( rAxis, identity_matrix) * - sin(Phi); + std::sin(Phi); } void BeamBaseElement3D::ComputeRodriguesMatrixDerivative( @@ -1286,21 +1286,21 @@ namespace Kratos for (SizeType i = 0; i < 3; ++i) { rRodriguesMatrixDerivative(i, i) = - -PhiDerivative * sin(Phi); + -PhiDerivative * std::sin(Phi); } rRodriguesMatrixDerivative += CrossProductVectorMatrix( rAxis, identity_matrix) * - cos(Phi) * + std::cos(Phi) * PhiDerivative; rRodriguesMatrixDerivative += CrossProductVectorMatrix( rAxisDerivative, identity_matrix) * - sin(Phi); + std::sin(Phi); } void BeamBaseElement3D::ComputeRodriguesMatrixVariation( @@ -1338,7 +1338,7 @@ namespace Kratos rRodriguesMatrixVariation( row_component * NumberOfDofs + dof_index, column_component) += - -sin(Phi) * + -std::sin(Phi) * rShapeFunctions[control_point_index]; } } else if (dof_component > 2) { @@ -1346,7 +1346,7 @@ namespace Kratos rRodriguesMatrixVariation( row_component * NumberOfDofs + dof_index, column_component) += - cos(Phi) * + std::cos(Phi) * rShapeFunctions[control_point_index] * levi_civita[row_component][k][column_component] * rAxis[k]; @@ -1357,7 +1357,7 @@ namespace Kratos rRodriguesMatrixVariation( row_component * NumberOfDofs + dof_index, column_component) += - sin(Phi) * + std::sin(Phi) * levi_civita[row_component][k][column_component] * rAxisVariation[ k * NumberOfDofs + dof_index]; @@ -1431,7 +1431,7 @@ namespace Kratos row_component * NumberOfDofs + dof_index, column_component * NumberOfDofs + second_dof_index) += - -cos(Phi) * + -std::cos(Phi) * phi_variation[dof_index] * phi_variation[second_dof_index]; } @@ -1445,21 +1445,21 @@ namespace Kratos row_component * NumberOfDofs + dof_index, column_component * NumberOfDofs + second_dof_index) += - -sin(Phi) * + -std::sin(Phi) * phi_variation[dof_index] * phi_variation[second_dof_index] * levi_civita[row_component][k][column_component] * rAxis[k] + phi_variation[dof_index] * - cos(Phi) * + std::cos(Phi) * levi_civita[row_component][k][column_component] * rAxisVariation[ k * NumberOfDofs + second_dof_index] + phi_variation[second_dof_index] * - cos(Phi) * + std::cos(Phi) * levi_civita[row_component][k][column_component] * rAxisVariation[ k * NumberOfDofs + @@ -1469,7 +1469,7 @@ namespace Kratos row_component * NumberOfDofs + dof_index, column_component * NumberOfDofs + second_dof_index) += - sin(Phi) * + std::sin(Phi) * levi_civita[row_component][k][column_component] * rAxisSecondVariation( k * NumberOfDofs + dof_index, @@ -1551,9 +1551,9 @@ namespace Kratos row_component * NumberOfDofs + dof_index, column_component) += -phi_derivative_variation(dof_index) * - sin(Phi) + std::sin(Phi) - - cos(Phi) * + std::cos(Phi) * PhiDerivative * rShapeFunctions[control_point_index]; } @@ -1565,16 +1565,16 @@ namespace Kratos column_component) += ( phi_derivative_variation(dof_index) * - cos(Phi) + std::cos(Phi) - PhiDerivative * rShapeFunctions[control_point_index] * - sin(Phi) + std::sin(Phi) ) * levi_civita[row_component][k][column_component] * rAxis[k] + - cos(Phi) * + std::cos(Phi) * phi_variation(dof_index) * levi_civita[row_component][k][column_component] * rAxisDerivative[k]; @@ -1582,13 +1582,13 @@ namespace Kratos rRodriguesMatrixDerivativeVariation( row_component * NumberOfDofs + dof_index, column_component) += - cos(Phi) * + std::cos(Phi) * PhiDerivative * levi_civita[row_component][k][column_component] * rAxisVariation[ k * NumberOfDofs + dof_index] + - sin(Phi) * + std::sin(Phi) * levi_civita[row_component][k][column_component] * rAxisDerivativeVariation[ k * NumberOfDofs + dof_index]; @@ -1652,9 +1652,9 @@ namespace Kratos } double cos_phi; - cos_phi = cos(Phi); + cos_phi = std::cos(Phi); double sin_phi; - sin_phi = sin(Phi); + sin_phi = std::sin(Phi); for (size_t t = 0;t < 3;t++) { @@ -1751,7 +1751,7 @@ namespace Kratos if (t == u) { if (xyz > 2) - rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -rShapeFunctionSecondDerivatives[i] * sin(Phi) - cos(Phi) * PhiSecondDerivative * rShapeFunctions[i] - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * cos(Phi) + sin(Phi) * pow(PhiDerivative, 2) * rShapeFunctions[i]; + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -rShapeFunctionSecondDerivatives[i] * std::sin(Phi) - std::cos(Phi) * PhiSecondDerivative * rShapeFunctions[i] - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * std::cos(Phi) + std::sin(Phi) * std::pow(PhiDerivative, 2) * rShapeFunctions[i]; else rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += 0; } @@ -1760,9 +1760,9 @@ namespace Kratos for (int k = 0; k < 3; k++) { if (xyz > 2) - rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (rShapeFunctionSecondDerivatives[i] * cos(Phi) - PhiSecondDerivative * rShapeFunctions[i] * sin(Phi) - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * sin(Phi) - pow(PhiDerivative, 2) * rShapeFunctions[i] * cos(Phi)) * levi_civita[t][k][u] * rAxis[k] + 2 * (cos(Phi) * rShapeFunctionDerivatives[i] - sin(Phi) * rShapeFunctions[i] * PhiDerivative) * levi_civita[t][k][u] * rAxisDerivative[k] + cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxisSecondDerivative[k]; + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (rShapeFunctionSecondDerivatives[i] * std::cos(Phi) - PhiSecondDerivative * rShapeFunctions[i] * std::sin(Phi) - 2 * rShapeFunctionDerivatives[i] * PhiDerivative * std::sin(Phi) - std::pow(PhiDerivative, 2) * rShapeFunctions[i] * std::cos(Phi)) * levi_civita[t][k][u] * rAxis[k] + 2 * (std::cos(Phi) * rShapeFunctionDerivatives[i] - std::sin(Phi) * rShapeFunctions[i] * PhiDerivative) * levi_civita[t][k][u] * rAxisDerivative[k] + std::cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxisSecondDerivative[k]; else - rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + 2 * PhiDerivative * cos(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisSecondDerivativeVariation[k * NumberOfDofs + r]; + rRodriguesMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (std::cos(Phi) * PhiSecondDerivative - std::pow(PhiDerivative, 2) * std::sin(Phi)) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + 2 * PhiDerivative * std::cos(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r] + std::sin(Phi) * levi_civita[t][k][u] * rAxisSecondDerivativeVariation[k * NumberOfDofs + r]; } } } @@ -1832,9 +1832,9 @@ namespace Kratos } double cos_phi; - cos_phi = cos(Phi); + cos_phi = std::cos(Phi); double sin_phi; - sin_phi = sin(Phi); + sin_phi = std::sin(Phi); for (size_t t = 0;t < 3;t++) { @@ -1848,21 +1848,21 @@ namespace Kratos { if (xyz_r > 2) { - rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += -sin(Phi) * rShapeFunctions[i]; - rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -phi_derivative_variation(r) * sin(Phi) - cos(Phi) * PhiDerivative * rShapeFunctions[i]; + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += -std::sin(Phi) * rShapeFunctions[i]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -phi_derivative_variation(r) * std::sin(Phi) - std::cos(Phi) * PhiDerivative * rShapeFunctions[i]; } } for (int k = 0; k < 3; k++) { if (xyz_r > 2) { - rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxis[k]; - rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (phi_derivative_variation(r) * cos(Phi) - PhiDerivative * rShapeFunctions[i] * sin(Phi)) * levi_civita[t][k][u] * rAxis[k] + cos(Phi) * phi_variation(r) * levi_civita[t][k][u] * rAxisDerivative[k]; + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += std::cos(Phi) * rShapeFunctions[i] * levi_civita[t][k][u] * rAxis[k]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (phi_derivative_variation(r) * std::cos(Phi) - PhiDerivative * rShapeFunctions[i] * std::sin(Phi)) * levi_civita[t][k][u] * rAxis[k] + std::cos(Phi) * phi_variation(r) * levi_civita[t][k][u] * rAxisDerivative[k]; } else { - rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += sin(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; - rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += cos(Phi) * PhiDerivative * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + sin(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r]; + rRodriguesMatrixVariation(t * NumberOfDofs + r, u) += std::sin(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; + rRodriguesMatrixDerivativeVariation(t * NumberOfDofs + r, u) += std::cos(Phi) * PhiDerivative * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r] + std::sin(Phi) * levi_civita[t][k][u] * rAxisDerivativeVariation[k * NumberOfDofs + r]; } } for (size_t s = 0;s < NumberOfDofs;s++) @@ -1871,7 +1871,7 @@ namespace Kratos if (t == u) { - rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -cos(Phi) * phi_variation[r] * phi_variation[s]; + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -std::cos(Phi) * phi_variation[r] * phi_variation[s]; rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * cos_phi - phi_derivative_variation(s) * phi_variation(r) * cos_phi + sin_phi * PhiDerivative * phi_variation[r] * phi_variation[s]; } @@ -1879,9 +1879,9 @@ namespace Kratos for (int k = 0; k < 3; k++) { if (xyz_r > 2 || xyz_s > 2) - rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -sin(Phi) * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + phi_variation[r] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + phi_variation[s] * cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -std::sin(Phi) * phi_variation[r] * phi_variation[s] * levi_civita[t][k][u] * rAxis[k] + phi_variation[r] * std::cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + s] + phi_variation[s] * std::cos(Phi) * levi_civita[t][k][u] * rAxisVariation[k * NumberOfDofs + r]; else - rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += sin(Phi) * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s); + rRodriguesMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += std::sin(Phi) * levi_civita[t][k][u] * rAxisSecondVariation(k * NumberOfDofs + r, s); rRodriguesMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -phi_derivative_variation(r) * phi_variation(s) * sin_phi * levi_civita[t][k][u] * rAxis[k] - phi_derivative_variation(s) * phi_variation(r) * sin_phi * levi_civita[t][k][u] * rAxis[k] @@ -1923,10 +1923,10 @@ namespace Kratos identity_matrix.clear(); for (int i = 0; i < 3; i++) { identity_matrix(i, i) = 1; } - for (int i = 0; i < 3; i++) { rRodriguesMatrixSecondDerivative(i, i) = -PhiSecondDerivative * sin(Phi) - pow(PhiDerivative, 2) * cos(Phi); } - rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxis, identity_matrix) * (cos(Phi) * PhiSecondDerivative - pow(PhiDerivative, 2) * sin(Phi)); - rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisDerivative, identity_matrix) * 2 * PhiDerivative * cos(Phi); - rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisSecondDerivative, identity_matrix) * sin(Phi); + for (int i = 0; i < 3; i++) { rRodriguesMatrixSecondDerivative(i, i) = -PhiSecondDerivative * std::sin(Phi) - std::pow(PhiDerivative, 2) * std::cos(Phi); } + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxis, identity_matrix) * (std::cos(Phi) * PhiSecondDerivative - std::pow(PhiDerivative, 2) * std::sin(Phi)); + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisDerivative, identity_matrix) * 2 * PhiDerivative * std::cos(Phi); + rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisSecondDerivative, identity_matrix) * std::sin(Phi); } void BeamBaseElement3D::ComputeLambdaMatrix(const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, Matrix3d& rLambdaMatrix) @@ -1997,7 +1997,7 @@ namespace Kratos for (int i = 0; i < 3; i++) { rLambdaMatrixDerivative(i, i) = reference_dot_current_derivative + reference_derivative_dot_current; } rLambdaMatrixDerivative += CrossProductVectorMatrix(tangent_cross_product_derivative, identity_matrix); - scaling_factor = -(reference_dot_current_derivative + reference_derivative_dot_current) / pow((1.0 + tangent_dot_product), 2); + scaling_factor = -(reference_dot_current_derivative + reference_derivative_dot_current) / std::pow((1.0 + tangent_dot_product), 2); rLambdaMatrixDerivative += outer_prod(reference_cross_current, reference_cross_current) * scaling_factor; scaling_factor = 1.0 / (1.0 + tangent_dot_product); rLambdaMatrixDerivative += outer_prod(tangent_cross_product_derivative, reference_cross_current) * scaling_factor; @@ -2043,9 +2043,9 @@ namespace Kratos for (int i = 0; i < 3; i++) { rLambdaMatrixSecondDerivative(i, i) = tangent_dot_product_second_derivative; } rLambdaMatrixSecondDerivative += CrossProductVectorMatrix(tangent_cross_product_second_derivative, identity_matrix); - scaling_factor = 2 * pow(tangent_dot_product_derivative, 2) / pow((1.0 + tangent_dot_product), 3) - tangent_dot_product_second_derivative / pow((1.0 + tangent_dot_product), 2); + scaling_factor = 2 * std::pow(tangent_dot_product_derivative, 2) / std::pow((1.0 + tangent_dot_product), 3) - tangent_dot_product_second_derivative / std::pow((1.0 + tangent_dot_product), 2); rLambdaMatrixSecondDerivative += outer_prod(reference_cross_current, reference_cross_current) * scaling_factor; - scaling_factor = -tangent_dot_product_derivative / pow((1.0 + tangent_dot_product), 2) * 2; + scaling_factor = -tangent_dot_product_derivative / std::pow((1.0 + tangent_dot_product), 2) * 2; rLambdaMatrixSecondDerivative += outer_prod(tangent_cross_product_derivative, reference_cross_current) * scaling_factor; rLambdaMatrixSecondDerivative += outer_prod(reference_cross_current, tangent_cross_product_derivative) * scaling_factor; scaling_factor = 1.0 / (1.0 + tangent_dot_product); @@ -2160,7 +2160,7 @@ namespace Kratos { rLambdaMatrixVariation(t * NumberOfDofs + r, u) += levi_civita[t][k][u] * reference_cross_current_variation[r + k * NumberOfDofs]; } - rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); } } @@ -2316,9 +2316,9 @@ namespace Kratos for (int k = 0; k < 3; k++) rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += levi_civita[t][k][u] * reference_cross_current_second_variation(k * NumberOfDofs + r, s); } - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) - - tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / std::pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + - tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + s, r)); } @@ -2474,9 +2474,9 @@ namespace Kratos } } - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / pow(1.0 + tangent_dot_product, 2) * ((tangent_cross_product_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (tangent_cross_product_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / std::pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / std::pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / std::pow(1.0 + tangent_dot_product, 2) * ((tangent_cross_product_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (tangent_cross_product_derivative[u] + reference_derivative_cross_current[u])); rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_variation[t * NumberOfDofs + r] + reference_derivative_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + (reference_cross_current_variation[t * NumberOfDofs + r]) * (tangent_cross_product_derivative[u] + reference_derivative_cross_current[u]) + (tangent_cross_product_derivative[t] + reference_derivative_cross_current[t]) * (reference_cross_current_variation[u * NumberOfDofs + r]) + reference_cross_current[t] * (reference_cross_current_derivative_variation[u * NumberOfDofs + r] + reference_derivative_cross_current_variation[u * NumberOfDofs + r])); } @@ -2684,9 +2684,9 @@ namespace Kratos tangent_dot_product_derivative_variation = reference_derivative_dot_current_variation + reference_dot_current_derivative_variation; tangent_dot_product_second_derivative_variation = reference_second_derivative_dot_current_variation + 2 * tangent_derivative_dot_product_variation + reference_dot_current_second_derivative_variation; - double inverse_one_plus_tangent_dot_squared = 1.0 / pow(1.0 + tangent_dot_product, 2); - double inverse_one_plus_tangent_dot_cubed = 1.0 / pow(1.0 + tangent_dot_product, 3); - double inverse_one_plus_tangent_dot_fourth = 1.0 / pow(1.0 + tangent_dot_product, 4); + double inverse_one_plus_tangent_dot_squared = 1.0 / std::pow(1.0 + tangent_dot_product, 2); + double inverse_one_plus_tangent_dot_cubed = 1.0 / std::pow(1.0 + tangent_dot_product, 3); + double inverse_one_plus_tangent_dot_fourth = 1.0 / std::pow(1.0 + tangent_dot_product, 4); for (size_t t = 0; t < 3; t++) { @@ -2711,8 +2711,8 @@ namespace Kratos } } - rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative_variation(r) * inverse_one_plus_tangent_dot_squared + 2 * (tangent_dot_product_variation(r) * tangent_dot_product_second_derivative + 2 * tangent_dot_product_derivative_variation[r] * tangent_dot_product_derivative) * inverse_one_plus_tangent_dot_cubed - 6 * (pow(tangent_dot_product_derivative, 2) * tangent_dot_product_variation[r]) * inverse_one_plus_tangent_dot_fourth) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative * inverse_one_plus_tangent_dot_squared + 2 * pow(tangent_dot_product_derivative, 2) * inverse_one_plus_tangent_dot_cubed) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative_variation(r) * inverse_one_plus_tangent_dot_squared + 2 * (tangent_dot_product_variation(r) * tangent_dot_product_second_derivative + 2 * tangent_dot_product_derivative_variation[r] * tangent_dot_product_derivative) * inverse_one_plus_tangent_dot_cubed - 6 * (std::pow(tangent_dot_product_derivative, 2) * tangent_dot_product_variation[r]) * inverse_one_plus_tangent_dot_fourth) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (-tangent_dot_product_second_derivative * inverse_one_plus_tangent_dot_squared + 2 * std::pow(tangent_dot_product_derivative, 2) * inverse_one_plus_tangent_dot_cubed) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += (4 * tangent_dot_product_derivative * tangent_dot_product_variation[r] * inverse_one_plus_tangent_dot_cubed - 2 * tangent_dot_product_derivative_variation[r] * inverse_one_plus_tangent_dot_squared) * (tangent_cross_product_derivative[t] * reference_cross_current[u] + reference_cross_current[t] * tangent_cross_product_derivative[u]); rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -2 * tangent_dot_product_derivative * inverse_one_plus_tangent_dot_squared * (tangent_cross_product_derivative_variation[t * NumberOfDofs + r] * reference_cross_current[u] + tangent_cross_product_derivative[t] * reference_cross_current_variation[u * NumberOfDofs + r] + reference_cross_current_variation[t * NumberOfDofs + r] * tangent_cross_product_derivative[u] + reference_cross_current[t] * tangent_cross_product_derivative_variation[u * NumberOfDofs + r]); rLambdaMatrixSecondDerivativeVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation(r) * inverse_one_plus_tangent_dot_squared * (tangent_cross_product_second_derivative[t] * reference_cross_current[u] + 2 * tangent_cross_product_derivative[t] * tangent_cross_product_derivative[u] + reference_cross_current[t] * tangent_cross_product_second_derivative[u]); @@ -2962,14 +2962,14 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 0; else { - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) - + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / std::pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / std::pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / std::pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / std::pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / std::pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / std::pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); } } @@ -3208,12 +3208,12 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); + rLambdaMatrixVariation(t * NumberOfDofs + r, u) += -tangent_dot_product_variation[r] / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current[t] * reference_cross_current[u]); rLambdaMatrixVariation(t * NumberOfDofs + r, u) += +1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); - rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += (2 * (tangent_dot_product_variation(r)) * (reference_dot_current_derivative + reference_derivative_dot_current) / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / std::pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(reference_dot_current_derivative + reference_derivative_dot_current) / std::pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_variation[u * NumberOfDofs + r])); + rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += -(tangent_dot_product_variation(r)) / std::pow(1.0 + tangent_dot_product, 2) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); rLambdaMatrixDerivativeVariation(t * NumberOfDofs + r, u) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_variation[t * NumberOfDofs + r] + reference_derivative_cross_current_variation[t * NumberOfDofs + r]) * reference_cross_current[u] + (reference_cross_current_variation[t * NumberOfDofs + r]) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * (reference_cross_current_variation[u * NumberOfDofs + r]) + reference_cross_current[t] * (reference_cross_current_derivative_variation[u * NumberOfDofs + r] + reference_derivative_cross_current_variation[u * NumberOfDofs + r])); } } @@ -3251,20 +3251,20 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) - - tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3) - tangent_dot_product_second_variation(r, s) / std::pow(1.0 + tangent_dot_product, 2)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_variation(r) / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + - tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); rLambdaMatrixSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + s, r)); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) - + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * (tangent_dot_product_variation(r) * (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) + tangent_dot_product_derivative * tangent_dot_product_second_variation(r, s)) / std::pow(1.0 + tangent_dot_product, 3) - 6 * tangent_dot_product_derivative * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 4) - (tangent_dot_product_derivative_second_variation(r, s) + reference_derivative_dot_current_second_variation(r, s)) / std::pow(1.0 + tangent_dot_product, 2) + 2 * (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3)) * reference_cross_current[t] * reference_cross_current[u]; + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (2 * tangent_dot_product_variation(r) * tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(r) + reference_derivative_dot_current_variation(r)) / std::pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + s] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + s]) + + (2 * tangent_dot_product_variation(s) * tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 3) - (tangent_dot_product_derivative_variation(s) + reference_derivative_dot_current_variation(s)) / std::pow(1.0 + tangent_dot_product, 2)) * (reference_cross_current_variation[t * NumberOfDofs + r] * reference_cross_current[u] + reference_cross_current[t] * reference_cross_current_variation[u * NumberOfDofs + r]); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += -tangent_dot_product_derivative / std::pow(1.0 + tangent_dot_product, 2) * (reference_cross_current_second_variation(t * NumberOfDofs + r, s) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + s) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * reference_cross_current_second_variation(u * NumberOfDofs + r, s)); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); - rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_second_variation(r, s) / std::pow(1.0 + tangent_dot_product, 2) + 2 * tangent_dot_product_variation(r) * tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 3)) * ((reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current[u] + reference_cross_current[t] * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u])); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(r) / std::pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s))); + rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += (-tangent_dot_product_variation(s) / std::pow(1.0 + tangent_dot_product, 2)) * ((reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current[u] + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative(u) + reference_derivative_cross_current(u)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current[t] * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r))); rLambdaMatrixDerivativeSecondVariation(t * NumberOfDofs + r, u * NumberOfDofs + s) += 1.0 / (1.0 + tangent_dot_product) * ((reference_cross_current_derivative_second_variation(t * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(t * NumberOfDofs + r, s)) * reference_cross_current[u] + reference_cross_current_second_variation(t * NumberOfDofs + r, s) * (reference_cross_current_derivative[u] + reference_derivative_cross_current[u]) + (reference_cross_current_derivative_variation(t * NumberOfDofs + s) + reference_derivative_cross_current_variation(t * NumberOfDofs + s)) * reference_cross_current_variation(u * NumberOfDofs + r) + reference_cross_current_variation(t * NumberOfDofs + s) * (reference_cross_current_derivative_variation(u * NumberOfDofs + r) + reference_derivative_cross_current_variation(u * NumberOfDofs + r)) + (reference_cross_current_derivative_variation(t * NumberOfDofs + r) + reference_derivative_cross_current_variation(t * NumberOfDofs + r)) * reference_cross_current_variation(u * NumberOfDofs + s) + reference_cross_current_variation(t * NumberOfDofs + r) * (reference_cross_current_derivative_variation(u * NumberOfDofs + s) + reference_derivative_cross_current_variation(u * NumberOfDofs + s)) + (reference_cross_current_derivative[t] + reference_derivative_cross_current[t]) * reference_cross_current_second_variation(u * NumberOfDofs + r, s) + reference_cross_current[t] * (reference_cross_current_derivative_second_variation(u * NumberOfDofs + r, s) + reference_derivative_cross_current_second_variation(u * NumberOfDofs + r, s))); } diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index a9ac4206594c..e70d986e2633 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -30,34 +30,6 @@ namespace Kratos mDofsPerNode = 4; mNumberOfDofs = this->GetGeometry().size() * mDofsPerNode; - mSMatrixRodriguesVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaRodriguesLambdaVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesDerivativeVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.resize(mNumberOfDofs * 3, 3); - mSMatrixRodriguesSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixRodriguesDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaDerivativeSecondVariation.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); - mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.resize(mNumberOfDofs * 3, mNumberOfDofs * 3); KRATOS_CATCH("") } @@ -150,20 +122,20 @@ namespace Kratos rKinematicVariables.r1, rKinematicVariables.r2); - rKinematicVariables.B = sqrt( + rKinematicVariables.B = std::sqrt( inner_prod( rKinematicVariables.R2, rKinematicVariables.R2) - - pow( + - std::pow( reference_base_vector_product / rKinematicVariables.A, 2)); - rKinematicVariables.b = sqrt( + rKinematicVariables.b = std::sqrt( inner_prod( rKinematicVariables.r2, rKinematicVariables.r2) - - pow( + - std::pow( current_base_vector_product / rKinematicVariables.a, 2)); @@ -201,11 +173,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const bool calculate_geometric_stiffness = build_level != 1; - Vector stress_axial = ZeroVector(5); - Vector stress_bending_1 = ZeroVector(5); - Vector stress_bending_2 = ZeroVector(5); - Vector stress_torsion_1 = ZeroVector(5); - Vector stress_torsion_2 = ZeroVector(5); + // Body forces (e.g. self weight) are applied if the nodes provide a VOLUME_ACCELERATION + const bool has_body_forces = + r_geometry[0].SolutionStepsDataHas(VOLUME_ACCELERATION); for ( IndexType point_number = 0; @@ -362,57 +332,39 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } if (CalculateResidualVectorFlag == true) { - // Map stress components to different behaviors - stress_axial[0] = - constitutive_variables.StressVector[0]; - - stress_bending_1[1] = - constitutive_variables.StressVector[1]; - - stress_bending_2[2] = - constitutive_variables.StressVector[2]; - - stress_torsion_1[3] = - constitutive_variables.StressVector[3]; - - stress_torsion_2[4] = - constitutive_variables.StressVector[4]; - - // Assemble internal forces - rRightHandSideVector -= - inverse_a4 * - integration_weight * - prod( - trans(b_axial), - stress_axial); - - rRightHandSideVector -= - inverse_a4 * - integration_weight * - prod( - trans(b_bending_1), - stress_bending_1); - - rRightHandSideVector -= - inverse_a4 * - integration_weight * - prod( - trans(b_bending_2), - stress_bending_2); - - rRightHandSideVector -= - inverse_a2 * - integration_weight * - prod( - trans(b_torsion_1), - stress_torsion_1); - - rRightHandSideVector -= - inverse_a2 * - integration_weight * - prod( - trans(b_torsion_2), - stress_torsion_2); + // Internal forces. Each B matrix has a single non-zero row, the one of its generalized strain. + const Vector& r_stress_vector = constitutive_variables.StressVector; + + noalias(rRightHandSideVector) -= + inverse_a4 * integration_weight * r_stress_vector[0] * row(b_axial, 0); + noalias(rRightHandSideVector) -= + inverse_a4 * integration_weight * r_stress_vector[1] * row(b_bending_1, 1); + noalias(rRightHandSideVector) -= + inverse_a4 * integration_weight * r_stress_vector[2] * row(b_bending_2, 2); + noalias(rRightHandSideVector) -= + inverse_a2 * integration_weight * r_stress_vector[3] * row(b_torsion_1, 3); + noalias(rRightHandSideVector) -= + inverse_a2 * integration_weight * r_stress_vector[4] * row(b_torsion_2, 4); + + // External body forces (dead load): f_i = int N_i * rho * A * b dL, Bauer et al. (2016) Eq. (3) + if (has_body_forces) { + const Matrix& r_shape_functions = r_geometry.ShapeFunctionsValues(); + const double mass_per_length = + GetProperties()[DENSITY] * GetProperties()[CROSS_AREA]; + + array_1d body_force = ZeroVector(3); + for (IndexType i = 0; i < r_geometry.size(); ++i) { + body_force += r_shape_functions(point_number, i) + * r_geometry[i].FastGetSolutionStepValue(VOLUME_ACCELERATION); + } + + for (IndexType i = 0; i < r_geometry.size(); ++i) { + for (IndexType j = 0; j < 3; ++j) { + rRightHandSideVector[i * mDofsPerNode + j] += + r_shape_functions(point_number, i) * mass_per_length * body_force[j] * integration_weight; + } + } + } } } @@ -438,16 +390,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( << Id() << std::endl; KRATOS_ERROR_IF( - !GetProperties().Has(I_N) || - GetProperties()[I_N] <= numerical_limit) - << "Please provide a reasonable value for \"I_N\" " + !GetProperties().Has(I22) || + GetProperties()[I22] <= numerical_limit) + << "Please provide a reasonable value for \"I22\" " << "(bending moment of inertia about N axis) for element #" << Id() << std::endl; KRATOS_ERROR_IF( - !GetProperties().Has(I_V) || - GetProperties()[I_V] <= numerical_limit) - << "Please provide a reasonable value for \"I_V\" " + !GetProperties().Has(I33) || + GetProperties()[I33] <= numerical_limit) + << "Please provide a reasonable value for \"I33\" " << "(bending moment of inertia about V axis) for element #" << Id() << std::endl; @@ -707,7 +659,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const Vector3d reference_tangent_derivative = reference_second_base_vector / reference_first_base_vector_norm - inner_prod(reference_first_base_vector, reference_second_base_vector) - / pow(reference_first_base_vector_norm, 3) + / std::pow(reference_first_base_vector_norm, 3) * reference_first_base_vector; Vector3d initial_reference_tangent_derivative; @@ -841,7 +793,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const Vector3d current_tangent_derivative = current_second_base_vector / current_first_base_vector_norm - inner_prod(current_first_base_vector, current_second_base_vector) - / pow(current_first_base_vector_norm, 3) + / std::pow(current_first_base_vector_norm, 3) * current_first_base_vector; const Vector3d reference_tangent = @@ -850,7 +802,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const Vector3d reference_tangent_derivative = reference_second_base_vector / reference_first_base_vector_norm - inner_prod(reference_first_base_vector, reference_second_base_vector) - / pow(reference_first_base_vector_norm, 3) + / std::pow(reference_first_base_vector_norm, 3) * reference_first_base_vector; Vector3d initial_reference_tangent_derivative; @@ -1053,6 +1005,29 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix& rBTorsion2) { KRATOS_TRY + + // Scratch matrices, laid out as (3 * number of dofs) x 3 or (3 * number of dofs) x (3 * number of dofs) + Matrix lambda_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_derivative_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_rodrigues_lambda_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + const auto& r_geometry = GetGeometry(); // Get shape functions and derivatives at integration point @@ -1118,23 +1093,23 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d reference_rodrigues_matrix_derivative; current_tangent = current_first_base_vector / norm_2(current_first_base_vector); - current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; + current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / std::pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); - reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; + reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / std::pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); - ComputeLambdaMatrixVariation(reference_tangent, current_tangent, current_tangent_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation); - ComputeLambdaMatrixDerivativeVariation(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaDerivativeVariation); + ComputeLambdaMatrixVariation(reference_tangent, current_tangent, current_tangent_variation, mNumberOfDofs, mDofsPerNode, lambda_variation_matrix); + ComputeLambdaMatrixDerivativeVariation(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, mNumberOfDofs, mDofsPerNode, lambda_derivative_variation_matrix); ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); - ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); - ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); + ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, rodrigues_variation_matrix); + ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, rodrigues_derivative_variation_matrix); ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); @@ -1218,10 +1193,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( cross_section_transformation_derivative.clear(); cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; - mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); - mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); - mSMatrixLambdaVariationRodriguesLambda.clear(); - mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); + lambda_variation_rodrigues_lambda_derivative_matrix.clear(); + lambda_variation_rodrigues_derivative_lambda_matrix.clear(); + lambda_variation_rodrigues_lambda_matrix.clear(); + lambda_derivative_variation_rodrigues_lambda_matrix.clear(); for (size_t row_component = 0; row_component < 3; row_component++) { @@ -1231,10 +1206,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) { - mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); } } } @@ -1244,18 +1219,18 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); - current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; + current_lambda_reference_rodrigues_lambda_product_derivative_variation = lambda_variation_rodrigues_lambda_derivative_matrix + lambda_variation_rodrigues_derivative_lambda_matrix + lambda_derivative_variation_rodrigues_lambda_matrix; - mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); - mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); - mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); - mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); - mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); - mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); - mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); - mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); - mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); - mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); + rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix.clear(); + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix.clear(); + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix.clear(); + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix.clear(); + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix.clear(); + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix.clear(); + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix.clear(); + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix.clear(); + rodrigues_lambda_variation_rodrigues_lambda_matrix.clear(); + rodrigues_variation_lambda_rodrigues_lambda_matrix.clear(); for (size_t row_component = 0; row_component < 3; row_component++) { @@ -1265,27 +1240,27 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) { - mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); } } } } - mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); - mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix.clear(); + rodrigues_lambda_rodrigues_lambda_variation_matrix.clear(); - mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda - + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; - mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix = rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix + + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix; + rodrigues_lambda_rodrigues_lambda_variation_matrix = rodrigues_variation_lambda_rodrigues_lambda_matrix + rodrigues_lambda_variation_rodrigues_lambda_matrix; Vector3d normal_vector; normal_vector.clear(); @@ -1314,8 +1289,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (int product_index = 0; product_index < 3; product_index++) { - normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); - binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); + normal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); + binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); } } } @@ -1340,10 +1315,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) { - normal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; - binormal_curvature_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; - normal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index); - binormal_torsion_variation(dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index); + normal_curvature_variation(dof_index) += rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; + binormal_curvature_variation(dof_index) += rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * current_first_base_vector[row_component] + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * current_first_base_vector_variation[row_component * mNumberOfDofs + dof_index]; + normal_torsion_variation(dof_index) += rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index); + binormal_torsion_variation(dof_index) += rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector(row_component) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index); } } } @@ -1371,6 +1346,19 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } + /** + * Second variations of the generalized strains with respect to the dofs (Bauer et al. 2016, Eq. 70 and Appendix A). + * + * The current cross-section axes are a_alpha = T * A0_alpha with the frame transformation + * T = R_t(psi) * Lambda(T, t) * P, where P = R_T(Psi) * Lambda(T0, T) only depends on the reference + * configuration. Their derivative along the curve is a_alpha,1 = T,1 * A0_alpha. The second variations of + * T and T,1 follow from the product rule and are assembled term by term below. + * + * Layout of the variation containers (n = number of element dofs): + * - 3x3 matrix M, first variation: (3 n) x 3 with M,r(i, j) stored at (i * n + r, j) + * - 3x3 matrix M, second variation: (3 n) x (3 n) with M,rs(i, j) stored at (i * n + r, j * n + s) + * - 3-vector v, first variation: 3 n with v,r(i) stored at (i * n + r) + */ void NonLinearBernoulliBeamElement3D::ComputeGMatrices( const IndexType IntegrationPointIndex, const KinematicVariables& rKinematicVariables, @@ -1382,6 +1370,37 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { KRATOS_TRY + // Scratch matrices, laid out as (3 * number of dofs) x 3 or (3 * number of dofs) x (3 * number of dofs) + Matrix lambda_derivative_second_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_derivative_second_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_derivative_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_second_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_second_variation_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_second_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_second_variation_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix lambda_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix lambda_variation_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_second_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix rodrigues_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_rodrigues_lambda_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_second_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3 * mNumberOfDofs); + Matrix rodrigues_variation_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_lambda_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + Matrix rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix = ZeroMatrix(3 * mNumberOfDofs, 3); + + const auto& r_geometry = GetGeometry(); // Get shape functions and derivatives at integration point @@ -1464,31 +1483,36 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d reference_rodrigues_matrix_derivative; current_tangent = current_first_base_vector / norm_2(current_first_base_vector); - current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; + current_tangent_derivative = current_second_base_vector / norm_2(current_first_base_vector) - inner_prod(current_first_base_vector, current_second_base_vector) / std::pow(norm_2(current_first_base_vector), 3) * current_first_base_vector; reference_tangent = reference_first_base_vector / norm_2(reference_first_base_vector); - reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; + reference_tangent_derivative = reference_second_base_vector / norm_2(reference_first_base_vector) - inner_prod(reference_first_base_vector, reference_second_base_vector) / std::pow(norm_2(reference_first_base_vector), 3) * reference_first_base_vector; + // 1. Current tangent t = a1 / |a1|, its derivative t,1 and their first and second variations ComputeTangentVariation(shape_function_derivatives, current_first_base_vector, current_tangent_variation); ComputeTangentDerivativeVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_variation); ComputeTangentSecondVariation(shape_function_derivatives, current_first_base_vector, current_tangent_second_variation); ComputeTangentDerivativeSecondVariation(shape_function_derivatives, shape_function_second_derivatives, current_first_base_vector, current_second_base_vector, current_tangent_derivative_second_variation); + // 2. Mapping matrices (Eq. 23): Lambda(T, t) depends on the dofs (Eq. A.13-A.19), Lambda(T0, T) does not ComputeLambdaMatrix(reference_tangent, current_tangent, current_lambda_matrix); ComputeLambdaMatrixDerivative(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_derivative, current_lambda_matrix_derivative); ComputeLambdaMatrix(initial_reference_tangent, reference_tangent, reference_lambda_matrix); ComputeLambdaMatrixDerivative(initial_reference_tangent, reference_tangent, initial_reference_tangent_derivative, reference_tangent_derivative, reference_lambda_matrix_derivative); - ComputeLambdaMatrixVariations(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, mNumberOfDofs, mDofsPerNode, mSMatrixLambdaVariation, mSMatrixLambdaDerivativeVariation, mSMatrixLambdaSecondVariation, mSMatrixLambdaDerivativeSecondVariation); + ComputeLambdaMatrixVariations(reference_tangent, current_tangent, reference_tangent_derivative, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, mNumberOfDofs, mDofsPerNode, lambda_variation_matrix, lambda_derivative_variation_matrix, lambda_second_variation_matrix, lambda_derivative_second_variation_matrix); + // 3. Rotation matrices (Eq. 26): R_t(psi) depends on the dofs (Eq. A.5-A.11), R_T(Psi) does not ComputeRodriguesMatrix(current_tangent, current_twist_angle, current_rodrigues_matrix); ComputeRodriguesMatrixDerivative(current_tangent, current_tangent_derivative, current_twist_angle, current_twist_angle_derivative, current_rodrigues_matrix_derivative); - ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesVariation); - ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeVariation); - ComputeRodriguesMatrixSecondVariation(current_tangent, current_tangent_variation, current_tangent_second_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesSecondVariation); - ComputeRodriguesMatrixDerivativeSecondVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, mSMatrixRodriguesDerivativeSecondVariation); + ComputeRodriguesMatrixVariation(current_tangent, current_tangent_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, rodrigues_variation_matrix); + ComputeRodriguesMatrixDerivativeVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, rodrigues_derivative_variation_matrix); + ComputeRodriguesMatrixSecondVariation(current_tangent, current_tangent_variation, current_tangent_second_variation, shape_functions, current_twist_angle, mNumberOfDofs, mDofsPerNode, rodrigues_second_variation_matrix); + ComputeRodriguesMatrixDerivativeSecondVariation(current_tangent, current_tangent_variation, current_tangent_derivative, current_tangent_derivative_variation, current_tangent_second_variation, current_tangent_derivative_second_variation, shape_functions, shape_function_derivatives, current_twist_angle, current_twist_angle_derivative, mNumberOfDofs, mDofsPerNode, rodrigues_derivative_second_variation_matrix); ComputeRodriguesMatrix(reference_tangent, reference_twist_angle, reference_rodrigues_matrix); ComputeRodriguesMatrixDerivative(reference_tangent, reference_tangent_derivative, reference_twist_angle, reference_twist_angle_derivative, reference_rodrigues_matrix_derivative); + // 4. Products of R_t, Lambda(T, t) and P and of their derivatives and variations + Matrix3d reference_rodrigues_lambda_derivative_product; reference_rodrigues_lambda_derivative_product.clear(); Matrix3d reference_rodrigues_derivative_lambda_product; @@ -1570,10 +1594,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term + current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term + current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term + current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term; - mSMatrixLambdaVariationRodriguesLambdaDerivative.clear(); - mSMatrixLambdaVariationRodriguesDerivativeLambda.clear(); - mSMatrixLambdaVariationRodriguesLambda.clear(); - mSMatrixLambdaDerivativeVariationRodriguesLambda.clear(); + lambda_variation_rodrigues_lambda_derivative_matrix.clear(); + lambda_variation_rodrigues_derivative_lambda_matrix.clear(); + lambda_variation_rodrigues_lambda_matrix.clear(); + lambda_derivative_variation_rodrigues_lambda_matrix.clear(); for (size_t row_component = 0;row_component < 3;row_component++) { @@ -1583,10 +1607,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) { - mSMatrixLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - mSMatrixLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - mSMatrixLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); } } } @@ -1596,18 +1620,18 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); - current_lambda_reference_rodrigues_lambda_product_derivative_variation = mSMatrixLambdaVariationRodriguesLambdaDerivative + mSMatrixLambdaVariationRodriguesDerivativeLambda + mSMatrixLambdaDerivativeVariationRodriguesLambda; + current_lambda_reference_rodrigues_lambda_product_derivative_variation = lambda_variation_rodrigues_lambda_derivative_matrix + lambda_variation_rodrigues_derivative_lambda_matrix + lambda_derivative_variation_rodrigues_lambda_matrix; - mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative.clear(); - mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda.clear(); - mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda.clear(); - mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda.clear(); - mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda.clear(); - mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda.clear(); - mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda.clear(); - mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative.clear(); - mSMatrixRodriguesLambdaVariationRodriguesLambda.clear(); - mSMatrixRodriguesVariationLambdaRodriguesLambda.clear(); + rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix.clear(); + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix.clear(); + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix.clear(); + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix.clear(); + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix.clear(); + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix.clear(); + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix.clear(); + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix.clear(); + rodrigues_lambda_variation_rodrigues_lambda_matrix.clear(); + rodrigues_variation_lambda_rodrigues_lambda_matrix.clear(); for (size_t row_component = 0;row_component < 3;row_component++) { @@ -1617,16 +1641,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) { - mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesLambdaVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component); - mSMatrixRodriguesVariationLambdaRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); + rodrigues_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); } } } @@ -1634,16 +1658,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( - mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation.clear(); - mSMatrixRodriguesLambdaRodriguesLambdaVariation.clear(); - mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation = mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative + mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda + mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda + mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda - + mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative + mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda + mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda + mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; - mSMatrixRodriguesLambdaRodriguesLambdaVariation = mSMatrixRodriguesVariationLambdaRodriguesLambda + mSMatrixRodriguesLambdaVariationRodriguesLambda; + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix.clear(); + rodrigues_lambda_rodrigues_lambda_variation_matrix.clear(); + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix = rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix + rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix + rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix + rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix + + rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix + rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix + rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix + rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix; + rodrigues_lambda_rodrigues_lambda_variation_matrix = rodrigues_variation_lambda_rodrigues_lambda_matrix + rodrigues_lambda_variation_rodrigues_lambda_matrix; - mSMatrixLambdaSecondVariationRodriguesLambda.clear(); - mSMatrixLambdaDerivativeSecondVariationRodriguesLambda.clear(); - mSMatrixLambdaSecondVariationRodriguesDerivativeLambda.clear(); - mSMatrixLambdaSecondVariationRodriguesLambdaDerivative.clear(); + lambda_second_variation_rodrigues_lambda_matrix.clear(); + lambda_derivative_second_variation_rodrigues_lambda_matrix.clear(); + lambda_second_variation_rodrigues_derivative_lambda_matrix.clear(); + lambda_second_variation_rodrigues_lambda_derivative_matrix.clear(); for (size_t row_component = 0;row_component < 3;row_component++) { @@ -1655,16 +1679,18 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) { - mSMatrixLambdaSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); - mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixLambdaSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); + lambda_second_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_derivative_second_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_derivative_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); + lambda_second_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); + lambda_second_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); } } } } } + // 5. Second variation of T,1 = (R_t Lambda P),1: all product-rule terms of R_t, Lambda and P with two + // variations distributed over R_t and Lambda (P is independent of the dofs), Eq. (A.2) and (A.4) Matrix current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term; current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term.clear(); @@ -1723,21 +1749,21 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) { - current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaDerivativeSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaDerivativeVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesDerivativeLambda(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambdaDerivative(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesDerivativeSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * mSMatrixLambdaSecondVariationRodriguesLambda(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesVariation(row_component * mNumberOfDofs + dof_index, product_index) * mSMatrixLambdaVariationRodriguesLambda(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += mSMatrixRodriguesSecondVariation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_derivative_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); } } } @@ -1775,12 +1801,13 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (int product_index = 0;product_index < 3;product_index++) { - normal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); - binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += mSMatrixRodriguesLambdaRodriguesLambdaVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); + normal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); + binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); } } } + // 6. Second variation of T = R_t Lambda P, needed for the second variation of the axes a_alpha Matrix cross_section_transformation_second_variation; cross_section_transformation_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); cross_section_transformation_second_variation.clear(); @@ -1793,11 +1820,28 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) { - cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) - + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) - + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) - + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + cross_section_transformation_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); + cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += + current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + second_dof_index, column_component * mNumberOfDofs + dof_index) + + current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) + + current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); } } } @@ -1825,6 +1869,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } + // 7. Second variations of the generalized strains, Eq. (70): + // bending b_alpha = a_alpha,1 . a1 and torsion t_alpha = a_beta,1 . a_alpha for (size_t row_component = 0;row_component < 3;row_component++) { for (size_t product_index = 0;product_index < 3;product_index++) @@ -1844,21 +1890,21 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( : 0.0; normal_curvature_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * current_first_base_vector(row_component) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_second_dof - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_dof; + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_second_dof + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * first_base_vector_variation_dof; binormal_curvature_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * current_first_base_vector(row_component) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_second_dof - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_dof; + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_second_dof + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * first_base_vector_variation_dof; normal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_binormal(product_index) * normal_vector(row_component) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index) + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + second_dof_index) + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_binormal(product_index) * normal_vector_variation(row_component * mNumberOfDofs + dof_index) + cross_section_transformation_derivative(row_component, product_index) * reference_binormal(product_index) * normal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); binormal_torsion_second_variation(dof_index, second_dof_index) += cross_section_transformation_derivative_second_variation(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_normal(product_index) * binormal_vector(row_component) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + second_dof_index) - + mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index) + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + second_dof_index) + + rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix(row_component * mNumberOfDofs + second_dof_index, product_index) * reference_normal(product_index) * binormal_vector_variation(row_component * mNumberOfDofs + dof_index) + cross_section_transformation_derivative(row_component, product_index) * reference_normal(product_index) * binormal_vector_second_variation(row_component * mNumberOfDofs + dof_index, second_dof_index); } } diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h index 86013d0cffb2..20a40c610d78 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -34,7 +34,23 @@ namespace Kratos /** * @class NonLinearBernoulliBeamElement3D - * @brief Three-dimensional Bernoulli beam element. + * @brief Geometrically nonlinear isogeometric spatial Bernoulli beam with torsion. + * @details Total Lagrangian formulation derived from the 3D continuum with Green-Lagrange strains and + * second Piola-Kirchhoff stresses. The cross section remains orthogonal to the center line (Bernoulli) + * and warping is neglected. Each control point has four dofs: DISPLACEMENT_X/Y/Z and the rotation + * about the center line (ROTATION_X). + * + * The cross-section frame is A_alpha = R_T(Psi) Lambda(T0, T) A0_alpha in the reference configuration and + * a_alpha = R_t(psi) Lambda(T, t) A_alpha in the current one, where Lambda maps one tangent onto the other + * and R rotates about the tangent. The generalized strains are the axial strain, the two bending curvatures + * and the two torsional curvatures. + * + * Reference: + * A.M. Bauer, M. Breitenberger, B. Philipp, R. Wuechner, K.-U. Bletzinger, + * "Nonlinear isogeometric spatial Bernoulli beam", + * Computer Methods in Applied Mechanics and Engineering 303 (2016) 101-127. + * https://doi.org/10.1016/j.cma.2015.12.027 + * Equation numbers in the comments of this element refer to this paper. */ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D : public BeamBaseElement3D @@ -43,38 +59,6 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D using Vector3d = array_1d; using Matrix3d = BoundedMatrix; - Matrix mSMatrixRodriguesVariation; - Matrix mSMatrixLambdaVariation; - Matrix mSMatrixLambdaVariationRodriguesLambda; - Matrix mSMatrixRodriguesLambdaVariationRodriguesLambda; - Matrix mSMatrixRodriguesVariationLambdaRodriguesLambda; - Matrix mSMatrixRodriguesLambdaRodriguesLambdaVariation; - - Matrix mSMatrixRodriguesDerivativeVariation; - Matrix mSMatrixLambdaDerivativeVariation; - Matrix mSMatrixLambdaDerivativeVariationRodriguesLambda; - Matrix mSMatrixLambdaVariationRodriguesDerivativeLambda; - Matrix mSMatrixLambdaVariationRodriguesLambdaDerivative; - - Matrix mSMatrixRodriguesDerivativeLambdaVariationRodriguesLambda; - Matrix mSMatrixRodriguesLambdaDerivativeVariationRodriguesLambda; - Matrix mSMatrixRodriguesLambdaVariationRodriguesDerivativeLambda; - Matrix mSMatrixRodriguesLambdaVariationRodriguesLambdaDerivative; - - Matrix mSMatrixRodriguesDerivativeVariationLambdaRodriguesLambda; - Matrix mSMatrixRodriguesVariationLambdaDerivativeRodriguesLambda; - Matrix mSMatrixRodriguesVariationLambdaRodriguesDerivativeLambda; - Matrix mSMatrixRodriguesVariationLambdaRodriguesLambdaDerivative; - Matrix mSMatrixRodriguesLambdaRodriguesLambdaDerivativeVariation; - - Matrix mSMatrixRodriguesSecondVariation; - Matrix mSMatrixLambdaSecondVariation; - Matrix mSMatrixLambdaSecondVariationRodriguesLambda; - Matrix mSMatrixRodriguesDerivativeSecondVariation; - Matrix mSMatrixLambdaDerivativeSecondVariation; - Matrix mSMatrixLambdaDerivativeSecondVariationRodriguesLambda; - Matrix mSMatrixLambdaSecondVariationRodriguesDerivativeLambda; - Matrix mSMatrixLambdaSecondVariationRodriguesLambdaDerivative; struct KinematicVariables { diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp index 22f3f5d0fd67..d2ff1008dc32 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp @@ -1,10 +1,13 @@ -// KRATOS ___| | | | -// \___ \ __| __| | | __| __| | | __| _` | | -// | | | | | ( | | | | ( | | -// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application // // License: BSD License -// license: IgaApplication/license.txt +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio // // System includes diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h index cf14791bce42..9e4f26380990 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h @@ -1,10 +1,13 @@ -// KRATOS ___| | | | -// \___ \ __| __| | | __| __| | | __| _` | | -// | | | | | ( | | | | ( | | -// _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application // // License: BSD License -// license: IgaApplication/license.txt +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio // #if !defined(KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED ) diff --git a/applications/IgaApplication/custom_python/iga_python_application.cpp b/applications/IgaApplication/custom_python/iga_python_application.cpp index 61afb6d9133e..29c197090330 100644 --- a/applications/IgaApplication/custom_python/iga_python_application.cpp +++ b/applications/IgaApplication/custom_python/iga_python_application.cpp @@ -67,16 +67,13 @@ PYBIND11_MODULE(KratosIgaApplication, m) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_AXIS_ORIENTATION) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, T_0) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, N_0) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_V) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_N) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I22) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I33) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_T) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, HEIGHT) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, WIDTH) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_N) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_n) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_V) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_v) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, VON_MISES_STRESS) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 84ab71986f22..98270b109bdc 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -226,12 +226,9 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(T_0) KRATOS_REGISTER_VARIABLE(N_0) KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) - KRATOS_REGISTER_VARIABLE(I_V) - KRATOS_REGISTER_VARIABLE(I_N) + KRATOS_REGISTER_VARIABLE(I22) + KRATOS_REGISTER_VARIABLE(I33) KRATOS_REGISTER_VARIABLE(I_T) - KRATOS_REGISTER_VARIABLE(HEIGHT) - KRATOS_REGISTER_VARIABLE(WIDTH) - KRATOS_REGISTER_VARIABLE(VON_MISES_STRESS) KRATOS_REGISTER_VARIABLE(ROTATIONAL_DOF_ACTIVE) diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index 373d1387627a..d979db32a1cb 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -46,16 +46,11 @@ KRATOS_CREATE_VARIABLE(double, RAYLEIGH_BETA) KRATOS_CREATE_VARIABLE(Vector, T_0) KRATOS_CREATE_VARIABLE(Vector, N_0) KRATOS_CREATE_VARIABLE(Matrix, LOCAL_AXIS_ORIENTATION) -KRATOS_CREATE_VARIABLE(double, I_V) -KRATOS_CREATE_VARIABLE(double, I_N) KRATOS_CREATE_VARIABLE(double, I_T) -KRATOS_CREATE_VARIABLE(double, HEIGHT) -KRATOS_CREATE_VARIABLE(double, WIDTH) KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_N) KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_n) KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_V) KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_v) -KRATOS_CREATE_VARIABLE(double, VON_MISES_STRESS) KRATOS_CREATE_VARIABLE(bool, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index 68ee700793a3..e5107c797338 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -55,16 +55,11 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, RAYLEIGH_BETA) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, T_0) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, N_0) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Matrix, LOCAL_AXIS_ORIENTATION) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_V) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_N) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_T) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, HEIGHT) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, WIDTH) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_N) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_n) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_V) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_v) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, VON_MISES_STRESS) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index cd2d000a4a1d..c3ba2cac4ef3 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -7,8 +7,8 @@ from KratosMultiphysics import python_linear_solver_factory # Straight cantilever along the local tangent t, with the cross section dimension WIDTH along the -# normal n and HEIGHT along v = t x n. I_V is the moment of inertia for deflections along n and -# I_N the one for deflections along v. Torsion constant as in Bauer et al. (2016), Table 1. +# normal n and HEIGHT along v = t x n. I33 is the moment of inertia about v (deflections along n) and +# I22 the one about n (deflections along v). Torsion constant as in Bauer et al. (2016), Table 1. E_MOD = 70000.0 NU = 0.0 G_MOD = E_MOD / (2.0 * (1.0 + NU)) @@ -16,27 +16,29 @@ HEIGHT = 5.0 LENGTH = 4.0 AREA = WIDTH * HEIGHT -I_V_ = HEIGHT * WIDTH ** 3 / 12.0 -I_N_ = WIDTH * HEIGHT ** 3 / 12.0 +I33_ = HEIGHT * WIDTH ** 3 / 12.0 +I22_ = WIDTH * HEIGHT ** 3 / 12.0 I_T_ = HEIGHT * WIDTH ** 3 / 3.0 DOFS = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X) REACTIONS = (KM.REACTION_X, KM.REACTION_Y, KM.REACTION_Z, KM.REACTION_MOMENT_X) -def create_model_part(model): +def create_model_part(model, body_forces=False): model_part = model.CreateModelPart("IgaModelPart") for variable in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, KM.REACTION_MOMENT, SMA.POINT_LOAD): model_part.AddNodalSolutionStepVariable(variable) + if body_forces: + model_part.AddNodalSolutionStepVariable(KM.VOLUME_ACCELERATION) return model_part def create_properties(model_part, properties_id, normal, young_modulus=E_MOD, poisson_ratio=NU, - area=AREA, i_n=I_N_, i_v=I_V_, i_t=I_T_): + area=AREA, i22=I22_, i33=I33_, i_t=I_T_): properties = model_part.GetProperties()[properties_id] properties.SetValue(IGA.CROSS_AREA, area) - properties.SetValue(IGA.I_N, i_n) - properties.SetValue(IGA.I_V, i_v) + properties.SetValue(IGA.I22, i22) + properties.SetValue(IGA.I33, i33) properties.SetValue(IGA.I_T, i_t) properties.SetValue(KM.YOUNG_MODULUS, young_modulus) properties.SetValue(KM.POISSON_RATIO, poisson_ratio) @@ -136,10 +138,10 @@ class TestBeam4pElement(BeamTestCase): """Linear response of the NonLinearBernoulliBeamElement3D compared to beam theory.""" @staticmethod - def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0)): + def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0), volume_acceleration=None): """Cantilever along +X, clamped at x = 0 and loaded at the tip. Returns the tip node.""" model = KM.Model() - model_part = create_model_part(model) + model_part = create_model_part(model, body_forces=volume_acceleration is not None) properties = create_properties(model_part, 1, normal) curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) @@ -149,6 +151,9 @@ def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0)): nodes = [model_part.GetNode(i) for i in range(1, 6)] clamp(nodes, 0) + if volume_acceleration is not None: + for node in nodes: + node.SetSolutionStepValue(KM.VOLUME_ACCELERATION, KM.Array3([float(a) for a in volume_acceleration])) add_point_load(model_part, 1, nodes[-1], force) if any(moment): # PointMomentCondition3D1N assembles all three moment components, but the beam only has the @@ -189,7 +194,7 @@ def test_constitutive_law_stress_matches_tangent(self): constitutive_law = properties[KM.CONSTITUTIVE_LAW].Clone() constitutive_law.CalculateMaterialResponsePK2(parameters) - stiffnesses = [E_MOD * AREA, E_MOD * I_V_, E_MOD * I_N_, 0.5 * G_MOD * I_T_, 0.5 * G_MOD * I_T_] + stiffnesses = [E_MOD * AREA, E_MOD * I33_, E_MOD * I22_, 0.5 * G_MOD * I_T_, 0.5 * G_MOD * I_T_] expected_stress = np.array(constitutive_matrix) @ np.array(strain) for i, stiffness in enumerate(stiffnesses): self.assertRelativelyEqual(constitutive_matrix[i, i], stiffness, 1e-12) @@ -207,7 +212,7 @@ def test_axial_force(self): def test_bending_along_binormal(self): tip = self.solve_cantilever((0.0, -1.0, 0.0)) displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) - reference = cantilever_tip_deflection(-1.0, I_N_) + reference = cantilever_tip_deflection(-1.0, I22_) self.assertRelativelyEqual(displacement[1], reference, 1e-8) self.assertLess(abs(displacement[0]), 1e-8 * abs(reference)) @@ -216,7 +221,7 @@ def test_bending_along_binormal(self): def test_bending_along_normal(self): tip = self.solve_cantilever((0.0, 0.0, -1.0)) displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) - reference = cantilever_tip_deflection(-1.0, I_V_) + reference = cantilever_tip_deflection(-1.0, I33_) self.assertRelativelyEqual(displacement[2], reference, 1e-8) self.assertLess(abs(displacement[0]), 1e-8 * abs(reference)) @@ -230,14 +235,24 @@ def test_torsion(self): self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y)), 1e-8 * reference) self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z)), 1e-8 * reference) + def test_self_weight(self): + # Uniform line load q = rho * A * g from the body forces: tip deflection q L^4 / (8 E I) + gravity = 9.81 + tip = self.solve_cantilever((0.0, 0.0, 0.0), volume_acceleration=(0.0, -gravity, 0.0)) + line_load = -1.0 * AREA * gravity # DENSITY = 1 + reference = line_load * LENGTH ** 4 / (8.0 * E_MOD * I22_) + + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y), reference, 1e-8) + self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z)), 1e-8 * abs(reference)) + def test_rotated_cross_section(self): # Rotating the cross section by 90 degrees about the beam axis (normal along +Y instead of +Z) # swaps the bending stiffness of the two transverse directions. tip = self.solve_cantilever((0.0, -1.0, 0.0), normal=(0.0, 1.0, 0.0)) - self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y), cantilever_tip_deflection(-1.0, I_V_), 1e-8) + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y), cantilever_tip_deflection(-1.0, I33_), 1e-8) tip = self.solve_cantilever((0.0, 0.0, -1.0), normal=(0.0, 1.0, 0.0)) - self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z), cantilever_tip_deflection(-1.0, I_N_), 1e-8) + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z), cantilever_tip_deflection(-1.0, I22_), 1e-8) def test_several_beams_in_one_model_part(self): # Three cantilevers with different directions and cross-section orientations share one model part. @@ -247,9 +262,9 @@ def test_several_beams_in_one_model_part(self): beams = [ # start, direction, normal, axial component, tip force, expected tip deflection - ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, -1.0, 0.0), cantilever_tip_deflection(-1.0, I_N_)), - ((0.0, 10.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, 0.0, 1.0), cantilever_tip_deflection(1.0, I_V_)), - ((10.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), 2, (1.0, 0.0, 0.0), cantilever_tip_deflection(1.0, I_V_)), + ((0.0, 0.0, 0.0), (1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, -1.0, 0.0), cantilever_tip_deflection(-1.0, I22_)), + ((0.0, 10.0, 0.0), (-1.0, 0.0, 0.0), (0.0, 0.0, 1.0), 0, (0.0, 0.0, 1.0), cantilever_tip_deflection(1.0, I33_)), + ((10.0, 0.0, 0.0), (0.0, 0.0, 1.0), (1.0, 0.0, 0.0), 2, (1.0, 0.0, 0.0), cantilever_tip_deflection(1.0, I33_)), ] tips = [] @@ -290,7 +305,7 @@ def test_curved_quadrant_bending_torsion(self): properties = create_properties( model_part, 1, (0.0, 0.0, 1.0), young_modulus=young_modulus, poisson_ratio=poisson_ratio, area=height * width, - i_n=height * width ** 3 / 12.0, i_v=i_out_of_plane, i_t=i_torsion) + i22=height * width ** 3 / 12.0, i33=i_out_of_plane, i_t=i_torsion) # Exact quarter circle of degree 2 from (R, 0, 0) to (0, R, 0), refined to degree 4 with 16 knot spans nodes = KM.NodesVector() @@ -451,7 +466,7 @@ def test_tangent_matches_finite_differences(self): def test_quadratic_newton_convergence(self): _, model_part, nodes = self.build_cantilever() f_ext = np.zeros(4 * len(nodes)) - f_ext[4 * (len(nodes) - 1) + 1] = -0.5 * E_MOD * I_N_ / LENGTH ** 2 + f_ext[4 * (len(nodes) - 1) + 1] = -0.5 * E_MOD * I22_ / LENGTH ** 2 _, norms = self.newton(model_part, nodes, f_ext, n_steps=4) relative_norms = np.array(norms) / norms[0] @@ -466,7 +481,7 @@ def test_large_deflection_elastica(self): # Reference: inextensible elastica (shooting method). The linear solution would be uy = -0.6667, ux = 0. # The cantilever is stocky, so the axial stiffness is increased to match the inextensibility of the reference. ux_exact, uy_exact = -0.0636758499, -0.6485743026 - load = 0.5 * E_MOD * I_N_ / LENGTH ** 2 + load = 0.5 * E_MOD * I22_ / LENGTH ** 2 _, model_part, nodes = self.build_cantilever() model_part.GetProperties()[1].SetValue(IGA.CROSS_AREA, 1e4 * AREA) @@ -480,27 +495,27 @@ def test_large_deflection_elastica(self): def test_euler_buckling_weak_axis(self): _, model_part, nodes = self.build_cantilever() loads = self.buckling_loads(model_part, nodes, (-1000.0, 0.0, 0.0), 1000.0) - euler = np.pi ** 2 * E_MOD * I_V_ / (4.0 * LENGTH ** 2) + euler = np.pi ** 2 * E_MOD * I33_ / (4.0 * LENGTH ** 2) self.assertRelativelyEqual(loads[0], euler, 5e-3) def test_euler_buckling_strong_axis(self): # The second mode is the first strong-axis mode, since the second weak-axis mode is at 9 times the first one. _, model_part, nodes = self.build_cantilever() loads = self.buckling_loads(model_part, nodes, (-1000.0, 0.0, 0.0), 1000.0) - euler = np.pi ** 2 * E_MOD * I_N_ / (4.0 * LENGTH ** 2) + euler = np.pi ** 2 * E_MOD * I22_ / (4.0 * LENGTH ** 2) self.assertRelativelyEqual(loads[1], euler, 5e-3) def test_lateral_torsional_buckling(self): # Cantilever with a tip load at the centroid, Timoshenko & Gere: P_cr = 4.013 sqrt(E I_weak G I_T) / L^2 _, model_part, nodes = self.build_cantilever() loads = self.buckling_loads(model_part, nodes, (0.0, -1000.0, 0.0), 1000.0) - timoshenko = 4.013 * np.sqrt(E_MOD * I_V_ * G_MOD * I_T_) / LENGTH ** 2 + timoshenko = 4.013 * np.sqrt(E_MOD * I33_ * G_MOD * I_T_) / LENGTH ** 2 self.assertRelativelyEqual(loads[0], timoshenko, 5e-2) def test_linear_bending_is_mesh_independent(self): # The exact cubic deflection is in the spline space of every mesh, since the curve is linearly parametrized. - load = 1e-4 * E_MOD * I_N_ / LENGTH ** 2 - reference = cantilever_tip_deflection(-load, I_N_) + load = 1e-4 * E_MOD * I22_ / LENGTH ** 2 + reference = cantilever_tip_deflection(-load, I22_) for n_cp in (5, 7, 9, 13): _, model_part, nodes = self.build_cantilever(n_cp) f_ext = np.zeros(4 * len(nodes)) From a6f45f7d9c49931076f68687b91cfcc9ab58ce8b Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 19 Nov 2026 20:08:13 +0100 Subject: [PATCH 23/32] [IGA] Add Alicia Knauer to the beam authors Co-Authored-By: Claude Opus 5.5 --- .../bernoulli_beam_elastic_constitutive_law.cpp | 3 ++- .../bernoulli_beam_elastic_constitutive_law.h | 3 ++- .../custom_elements/non_linear_bernoulli_beam_element_3D.cpp | 3 ++- .../custom_processes/compute_beam_vectors_process.cpp | 3 +++ .../custom_processes/compute_beam_vectors_process.h | 3 +++ .../custom_python/add_custom_constitutive_laws_to_python.cpp | 3 ++- .../custom_python/add_custom_constitutive_laws_to_python.h | 3 ++- 7 files changed, 16 insertions(+), 5 deletions(-) diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp index 16e46000e38e..098a07e74a1d 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // // System includes diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h index 5aa2eecea288..37e01ecd5e6b 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // #pragma once diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index e70d986e2633..a2a1d2a8467c 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // // System includes diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp index a78ca3c7223d..cb690858ea5e 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -7,6 +7,9 @@ // License: BSD License // Kratos default license: kratos/license.txt // +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// // System includes #include diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h index 69b875e795f2..92ee18bc7b25 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h @@ -7,6 +7,9 @@ // License: BSD License // Kratos default license: kratos/license.txt // +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// #if !defined(KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED ) #define KRATOS_COMPUTE_BEAM_VECTORS_PROCESS_H_INCLUDED diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp index d2ff1008dc32..96a597d1f747 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // // System includes diff --git a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h index 9e4f26380990..a5eb46ca072d 100644 --- a/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h @@ -7,7 +7,8 @@ // License: BSD License // Kratos default license: kratos/license.txt // -// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, Ricky Aristio +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer // #if !defined(KRATOS_ADD_CUSTOM_CONSTITUTIVE_LAWS_TO_PYTHON_H_INCLUDED ) From d4fc37c440ac2ea141d3cdc1be28925fe164694c Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 20 Nov 2026 10:09:16 +0100 Subject: [PATCH 24/32] [IGA] Add dynamics to the Bernoulli beam and address Max's review - NonLinearBernoulliBeamElement3D: consistent mass matrix (rho A for the displacements, rho (I22 + I33) for the rotation about the center line), GetFirstDerivativesVector (VELOCITY, ANGULAR_VELOCITY_X) and GetSecondDerivativesVector (ACCELERATION, ANGULAR_ACCELERATION_X). - BeamBaseElement3D: Rayleigh damping alpha * M + beta * K, sized from the element's equation ids so that it can be reused by other beam elements. - Check the shape of LOCAL_AXIS_ORIENTATION ([parameter, nx, ny, nz], at least two rows), strictly increasing parameters and non-zero normals. - Compute the second variations only when the geometric stiffness is assembled. - Remove the declared but never defined ComputeB*/ComputeG* functions. - Tests: mass matrix, Rayleigh damping, derivatives vectors, natural frequencies against beam theory, free vibration in bending and torsion with the BDF scheme, LOCAL_AXIS_ORIENTATION checks. Co-Authored-By: Claude Opus 5.5 --- .../custom_elements/beam_base_element_3D.cpp | 43 +++++ .../custom_elements/beam_base_element_3D.h | 10 + .../non_linear_bernoulli_beam_element_3D.cpp | 181 ++++++++++++++++-- .../non_linear_bernoulli_beam_element_3D.h | 54 ++---- .../IgaApplication/iga_application.cpp | 1 + ...etric_non_linear_bernoulli_beam_element.py | 174 ++++++++++++++++- 6 files changed, 411 insertions(+), 52 deletions(-) diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index 618e4da1b722..c885bb8e8877 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -165,6 +165,49 @@ namespace Kratos } } + void BeamBaseElement3D::CalculateDampingMatrix( + MatrixType& rDampingMatrix, + const ProcessInfo& rCurrentProcessInfo) + { + KRATOS_TRY + + const auto get_rayleigh_coefficient = [&](const Variable& rVariable) -> double { + if (GetProperties().Has(rVariable)) { + return GetProperties()[rVariable]; + } + if (rCurrentProcessInfo.Has(rVariable)) { + return rCurrentProcessInfo[rVariable]; + } + return 0.0; + }; + + const double alpha = get_rayleigh_coefficient(RAYLEIGH_ALPHA); + const double beta = get_rayleigh_coefficient(RAYLEIGH_BETA); + + EquationIdVectorType equation_ids; + EquationIdVector(equation_ids, rCurrentProcessInfo); + const SizeType number_of_dofs = equation_ids.size(); + + if (rDampingMatrix.size1() != number_of_dofs || rDampingMatrix.size2() != number_of_dofs) { + rDampingMatrix.resize(number_of_dofs, number_of_dofs, false); + } + noalias(rDampingMatrix) = ZeroMatrix(number_of_dofs, number_of_dofs); + + if (beta != 0.0) { + MatrixType stiffness_matrix; + CalculateLeftHandSide(stiffness_matrix, rCurrentProcessInfo); + noalias(rDampingMatrix) += beta * stiffness_matrix; + } + + if (alpha != 0.0) { + MatrixType mass_matrix; + CalculateMassMatrix(mass_matrix, rCurrentProcessInfo); + noalias(rDampingMatrix) += alpha * mass_matrix; + } + + KRATOS_CATCH("") + } + int BeamBaseElement3D::Check( const ProcessInfo& rCurrentProcessInfo) const { diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.h b/applications/IgaApplication/custom_elements/beam_base_element_3D.h index 1f31e9c19aca..f66e6be646e8 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.h +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.h @@ -111,6 +111,16 @@ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D Vector& rValues, int Step = 0) const override; + ///@} + ///@name Dynamics + ///@{ + + /// Rayleigh damping C = alpha * M + beta * K, with RAYLEIGH_ALPHA/RAYLEIGH_BETA from the properties or the process info. + /// Uses the mass and stiffness matrices of the derived element. + void CalculateDampingMatrix( + MatrixType& rDampingMatrix, + const ProcessInfo& rCurrentProcessInfo) override; + ///@} ///@name Material ///@{ diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index a2a1d2a8467c..609eae4a44a5 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -35,6 +35,127 @@ namespace Kratos } + void NonLinearBernoulliBeamElement3D::GetFirstDerivativesVector( + Vector& rValues, + const int Step) const + { + const auto& r_geometry = GetGeometry(); + const IndexType number_of_nodes = r_geometry.size(); + + if (rValues.size() != number_of_nodes * 4) { + rValues.resize(number_of_nodes * 4, false); + } + + for (IndexType i = 0; i < number_of_nodes; ++i) { + const IndexType index = i * 4; + + const auto& r_velocity = + r_geometry[i].FastGetSolutionStepValue( + VELOCITY, + Step); + + rValues[index] = r_velocity[0]; + rValues[index + 1] = r_velocity[1]; + rValues[index + 2] = r_velocity[2]; + rValues[index + 3] = + r_geometry[i].FastGetSolutionStepValue( + ANGULAR_VELOCITY_X, + Step); + } + } + + void NonLinearBernoulliBeamElement3D::GetSecondDerivativesVector( + Vector& rValues, + const int Step) const + { + const auto& r_geometry = GetGeometry(); + const IndexType number_of_nodes = r_geometry.size(); + + if (rValues.size() != number_of_nodes * 4) { + rValues.resize(number_of_nodes * 4, false); + } + + for (IndexType i = 0; i < number_of_nodes; ++i) { + const IndexType index = i * 4; + + const auto& r_acceleration = + r_geometry[i].FastGetSolutionStepValue( + ACCELERATION, + Step); + + rValues[index] = r_acceleration[0]; + rValues[index + 1] = r_acceleration[1]; + rValues[index + 2] = r_acceleration[2]; + rValues[index + 3] = + r_geometry[i].FastGetSolutionStepValue( + ANGULAR_ACCELERATION_X, + Step); + } + } + + void NonLinearBernoulliBeamElement3D::CalculateMassMatrix( + MatrixType& rMassMatrix, + const ProcessInfo& rCurrentProcessInfo) + { + KRATOS_TRY + + const auto& r_geometry = GetGeometry(); + const SizeType number_of_nodes = r_geometry.size(); + const SizeType number_of_dofs = number_of_nodes * 4; + + if (rMassMatrix.size1() != number_of_dofs || rMassMatrix.size2() != number_of_dofs) { + rMassMatrix.resize(number_of_dofs, number_of_dofs, false); + } + noalias(rMassMatrix) = ZeroMatrix(number_of_dofs, number_of_dofs); + + const auto& r_properties = GetProperties(); + const double density = r_properties[DENSITY]; + const double mass_per_length = density * r_properties[CROSS_AREA]; + + // Polar mass moment of inertia per unit length, for the rotation about the center line + const double rotational_inertia_per_length = + density * (r_properties[I22] + r_properties[I33]); + + const auto& r_integration_points = r_geometry.IntegrationPoints(); + const Matrix& r_shape_functions = r_geometry.ShapeFunctionsValues(); + + for (IndexType point_number = 0; point_number < r_integration_points.size(); ++point_number) { + const Matrix& r_shape_function_derivatives = + r_geometry.ShapeFunctionDerivatives(1, point_number); + + // Reference base vector A1, so that dL = |A1| dxi + array_1d reference_base_vector = ZeroVector(3); + for (IndexType i = 0; i < number_of_nodes; ++i) { + reference_base_vector += + r_shape_function_derivatives(i, 0) * + r_geometry[i].GetInitialPosition().Coordinates(); + } + + const double integration_weight = + r_integration_points[point_number].Weight() * + norm_2(reference_base_vector); + + for (IndexType i = 0; i < number_of_nodes; ++i) { + for (IndexType j = 0; j < number_of_nodes; ++j) { + const double shape_function_product = + r_shape_functions(point_number, i) * + r_shape_functions(point_number, j) * + integration_weight; + + for (IndexType k = 0; k < 3; ++k) { + rMassMatrix(i * 4 + k, j * 4 + k) += + shape_function_product * mass_per_length; + } + + rMassMatrix(i * 4 + 3, j * 4 + 3) += + shape_function_product * rotational_inertia_per_length; + } + } + } + + KRATOS_CATCH("") + } + void NonLinearBernoulliBeamElement3D::CalculateKinematics( @@ -221,21 +342,6 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( b_torsion_1, b_torsion_2); - Matrix g_axial; - Matrix g_bending_1; - Matrix g_bending_2; - Matrix g_torsion_1; - Matrix g_torsion_2; - - ComputeGMatrices( - point_number, - kinematic_variables, - g_axial, - g_bending_1, - g_bending_2, - g_torsion_1, - g_torsion_2); - // Assemble stiffness with cross-sectional scaling const double integration_weight = r_integration_points[point_number].Weight() * @@ -299,6 +405,22 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } if (calculate_geometric_stiffness) { + // The second variations are only needed for the geometric stiffness + Matrix g_axial; + Matrix g_bending_1; + Matrix g_bending_2; + Matrix g_torsion_1; + Matrix g_torsion_2; + + ComputeGMatrices( + point_number, + kinematic_variables, + g_axial, + g_bending_1, + g_bending_2, + g_torsion_1, + g_torsion_2); + // Geometrical stiffness rLeftHandSideMatrix += inverse_a4 * @@ -409,6 +531,35 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( << "\"LOCAL_AXIS_ORIENTATION\" not provided for element #" << Id() << std::endl; + // Each row is [parameter, nx, ny, nz]: the cross-section normal at that curve parameter. + // The twist is interpolated between consecutive rows, so at least two rows with + // strictly increasing parameters and non-zero normals are required. + const Matrix& r_local_axis_orientation = GetProperties()[LOCAL_AXIS_ORIENTATION]; + + KRATOS_ERROR_IF(r_local_axis_orientation.size2() != 4) + << "\"LOCAL_AXIS_ORIENTATION\" must have 4 columns [parameter, nx, ny, nz], but has " + << r_local_axis_orientation.size2() << " for element #" << Id() << std::endl; + + KRATOS_ERROR_IF(r_local_axis_orientation.size1() < 2) + << "\"LOCAL_AXIS_ORIENTATION\" must have at least 2 rows, but has " + << r_local_axis_orientation.size1() << " for element #" << Id() << std::endl; + + for (IndexType i = 0; i < r_local_axis_orientation.size1(); ++i) { + KRATOS_ERROR_IF(i > 0 && r_local_axis_orientation(i, 0) <= r_local_axis_orientation(i - 1, 0)) + << "\"LOCAL_AXIS_ORIENTATION\" parameters must be strictly increasing, but row " << i + << " has parameter " << r_local_axis_orientation(i, 0) << " after " + << r_local_axis_orientation(i - 1, 0) << " for element #" << Id() << std::endl; + + const double normal_norm = std::sqrt( + r_local_axis_orientation(i, 1) * r_local_axis_orientation(i, 1) + + r_local_axis_orientation(i, 2) * r_local_axis_orientation(i, 2) + + r_local_axis_orientation(i, 3) * r_local_axis_orientation(i, 3)); + + KRATOS_ERROR_IF(normal_norm <= numerical_limit) + << "\"LOCAL_AXIS_ORIENTATION\" row " << i + << " has a zero normal vector for element #" << Id() << std::endl; + } + KRATOS_ERROR_IF(!Has(T_0) && !GetProperties().Has(T_0)) << "\"T_0\" not provided for element #" << Id() << ". Run the ComputeBeamVectorsProcess first." << std::endl; diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h index 20a40c610d78..13dbfd16c8f0 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -226,6 +226,26 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D void Initialize( const ProcessInfo& rCurrentProcessInfo) override; + /// Velocities [VELOCITY_X, VELOCITY_Y, VELOCITY_Z, ANGULAR_VELOCITY_X] per control point. + void GetFirstDerivativesVector( + Vector& rValues, + int Step = 0) const override; + + /// Accelerations [ACCELERATION_X, ACCELERATION_Y, ACCELERATION_Z, ANGULAR_ACCELERATION_X] per control point. + void GetSecondDerivativesVector( + Vector& rValues, + int Step = 0) const override; + + /** + * @brief Consistent mass matrix in the reference configuration. + * @details M_ij = int N_i N_j rho A dL for the displacements and int N_i N_j rho (I22 + I33) dL + * for the rotation about the center line (polar mass moment of inertia per unit length). + */ + void CalculateMassMatrix( + MatrixType& rMassMatrix, + const ProcessInfo& rCurrentProcessInfo) override; + + void CalculateKinematics( const IndexType IntegrationPointIndex, KinematicVariables& rKinematicVariables); @@ -255,40 +275,6 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D Matrix& rGTorsion1, Matrix& rGTorsion2); - void ComputeGAxial( - const IndexType IntegrationPointIndex, - Matrix& rGAxial, - KinematicVariables& rKinematicVariables) const; - - void ComputeGBending( - const IndexType IntegrationPointIndex, - Matrix& rGBending1, - Matrix& rGBending2, - KinematicVariables& rKinematicVariables) const; - - void ComputeGTorsion( - const IndexType IntegrationPointIndex, - Matrix& rGTorsion1, - Matrix& rGTorsion2, - KinematicVariables& rKinematicVariables) const; - - void ComputeBAxial( - const IndexType IntegrationPointIndex, - Matrix& rBAxial, - KinematicVariables& rKinematicVariables) const; - - void ComputeBBending( - const IndexType IntegrationPointIndex, - Matrix& rBBending1, - Matrix& rBBending2, - KinematicVariables& rKinematicVariables) const; - - void ComputeBTorsion( - const IndexType IntegrationPointIndex, - Matrix& rBTorsion1, - Matrix& rBTorsion2, - KinematicVariables& rKinematicVariables) const; - ///@} ///@name Input and Output ///@{ diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 98270b109bdc..0617044e0485 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -226,6 +226,7 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(T_0) KRATOS_REGISTER_VARIABLE(N_0) KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) + // I22 and I33 are core variables, but the core does not register them KRATOS_REGISTER_VARIABLE(I22) KRATOS_REGISTER_VARIABLE(I33) KRATOS_REGISTER_VARIABLE(I_T) diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index c3ba2cac4ef3..cd26ea7dbb0f 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -24,12 +24,15 @@ REACTIONS = (KM.REACTION_X, KM.REACTION_Y, KM.REACTION_Z, KM.REACTION_MOMENT_X) -def create_model_part(model, body_forces=False): +def create_model_part(model, body_forces=False, dynamic=False): model_part = model.CreateModelPart("IgaModelPart") for variable in (KM.DISPLACEMENT, KM.ROTATION, KM.REACTION, KM.REACTION_MOMENT, SMA.POINT_LOAD): model_part.AddNodalSolutionStepVariable(variable) if body_forces: model_part.AddNodalSolutionStepVariable(KM.VOLUME_ACCELERATION) + if dynamic: + for variable in (KM.VELOCITY, KM.ACCELERATION, KM.ANGULAR_VELOCITY, KM.ANGULAR_ACCELERATION): + model_part.AddNodalSolutionStepVariable(variable) return model_part @@ -200,6 +203,35 @@ def test_constitutive_law_stress_matches_tangent(self): self.assertRelativelyEqual(constitutive_matrix[i, i], stiffness, 1e-12) self.assertRelativelyEqual(stress[i], expected_stress[i], 1e-12) + def test_local_axis_orientation_checks(self): + model = KM.Model() + model_part = create_model_part(model) + properties = create_properties(model_part, 1, (0.0, 0.0, 1.0)) + curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) + create_elements(model_part, curve, properties) + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) + clamp([model_part.GetNode(i) for i in range(1, 6)], 0) + + # Element::Check is not exposed to Python, so it is called through the strategy + strategy = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, + KM.ResidualBasedIncrementalUpdateStaticScheme(), + python_linear_solver_factory.ConstructSolver(KM.Parameters(r'{"solver_type": "skyline_lu_factorization"}')), + KM.ResidualCriteria(1e-10, 1e-12), 1, False, False, False) + strategy.Check() + + invalid_orientations = { + "must have 4 columns": [[0.0, 0.0, 1.0], [1.0, 0.0, 1.0]], + "must have at least 2 rows": [[0.0, 0.0, 0.0, 1.0]], + "strictly increasing": [[0.0, 0.0, 0.0, 1.0], [0.5, 0.0, 0.0, 1.0], [0.5, 0.0, 0.0, 1.0]], + "zero normal vector": [[0.0, 0.0, 0.0, 1.0], [1.0, 0.0, 0.0, 0.0]], + } + for message, orientation in invalid_orientations.items(): + properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array(orientation, dtype=float)) + with self.assertRaisesRegex(RuntimeError, message): + strategy.Check() + def test_axial_force(self): tip = self.solve_cantilever((1.0, 0.0, 0.0)) displacement = tip.GetSolutionStepValue(KM.DISPLACEMENT) @@ -341,10 +373,10 @@ class TestBeam4pElementNonlinear(BeamTestCase): """Geometrically nonlinear response of the NonLinearBernoulliBeamElement3D.""" @staticmethod - def build_cantilever(n_cp=5, degree=4): + def build_cantilever(n_cp=5, degree=4, dynamic=False): """Cantilever along +X, refined with curve_h_refinements.iga.json. Returns (model, model_part, nodes).""" model = KM.Model() - model_part = create_model_part(model) + model_part = create_model_part(model, dynamic=dynamic) properties = create_properties(model_part, 1, (0.0, 0.0, 1.0)) curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0), n_cp, degree) @@ -399,6 +431,27 @@ def assemble(cls, model_part, nodes, u, build_level=0): R[indices] += np.array(rhs) return K, R + @classmethod + def assemble_mass(cls, model_part, nodes): + n_dofs = 4 * len(nodes) + M = np.zeros((n_dofs, n_dofs)) + for element in model_part.Elements: + mass_matrix = KM.Matrix() + element.CalculateMassMatrix(mass_matrix, model_part.ProcessInfo) + indices = cls.element_dof_indices(element) + M[np.ix_(indices, indices)] += np.array(mass_matrix) + return M + + @classmethod + def eigen_modes(cls, model_part, nodes): + """Natural circular frequencies and mode shapes (on the free dofs) of the undeformed cantilever.""" + free = cls.free_dofs(nodes) + K, _ = cls.assemble(model_part, nodes, np.zeros(4 * len(nodes))) + M = cls.assemble_mass(model_part, nodes) + eigenvalues, eigenvectors = np.linalg.eig(np.linalg.solve(M[np.ix_(free, free)], K[np.ix_(free, free)])) + order = np.argsort(eigenvalues.real) + return np.sqrt(eigenvalues.real[order]), eigenvectors.real[:, order], free + @classmethod def newton(cls, model_part, nodes, f_ext, n_steps, tolerance=1e-10, max_iterations=40): """Load-controlled Newton-Raphson. Returns the solution and the residual norms of the last load step.""" @@ -512,6 +565,121 @@ def test_lateral_torsional_buckling(self): timoshenko = 4.013 * np.sqrt(E_MOD * I33_ * G_MOD * I_T_) / LENGTH ** 2 self.assertRelativelyEqual(loads[0], timoshenko, 5e-2) + def test_consistent_mass_matrix(self): + _, model_part, nodes = self.build_cantilever() + M = self.assemble_mass(model_part, nodes) + + # The B-splines are a partition of unity, so each block sums up to the total (rotational) mass + self.assertRelativelyEqual(M[0::4, 0::4].sum(), AREA * LENGTH, 1e-12) + self.assertRelativelyEqual(M[1::4, 1::4].sum(), AREA * LENGTH, 1e-12) + self.assertRelativelyEqual(M[2::4, 2::4].sum(), AREA * LENGTH, 1e-12) + self.assertRelativelyEqual(M[3::4, 3::4].sum(), (I22_ + I33_) * LENGTH, 1e-12) + self.assertLess(np.abs(M - M.T).max(), 1e-12 * np.abs(M).max()) + self.assertGreater(np.linalg.eigvalsh(M).min(), 0.0) + + def test_rayleigh_damping_matrix(self): + _, model_part, _ = self.build_cantilever() + alpha, beta = 0.3, 2e-4 + model_part.GetProperties()[1].SetValue(IGA.RAYLEIGH_ALPHA, alpha) + model_part.GetProperties()[1].SetValue(IGA.RAYLEIGH_BETA, beta) + + for element in model_part.Elements: + damping, mass, stiffness = KM.Matrix(), KM.Matrix(), KM.Matrix() + element.CalculateDampingMatrix(damping, model_part.ProcessInfo) + element.CalculateMassMatrix(mass, model_part.ProcessInfo) + element.CalculateLeftHandSide(stiffness, model_part.ProcessInfo) + expected = alpha * np.array(mass) + beta * np.array(stiffness) + self.assertLess(np.abs(np.array(damping) - expected).max(), 1e-12 * np.abs(expected).max()) + + def test_derivatives_vectors(self): + _, model_part, nodes = self.build_cantilever(dynamic=True) + for i, node in enumerate(nodes): + node.SetSolutionStepValue(KM.VELOCITY, KM.Array3([i + 0.1, i + 0.2, i + 0.3])) + node.SetSolutionStepValue(KM.ANGULAR_VELOCITY_X, i + 0.4) + node.SetSolutionStepValue(KM.ACCELERATION, KM.Array3([i + 0.5, i + 0.6, i + 0.7])) + node.SetSolutionStepValue(KM.ANGULAR_ACCELERATION_X, i + 0.8) + + for element in model_part.Elements: + velocities, accelerations = KM.Vector(), KM.Vector() + element.GetFirstDerivativesVector(velocities, 0) + element.GetSecondDerivativesVector(accelerations, 0) + for k, node in enumerate(element.GetGeometry()): + i = node.Id - 1 + self.assertVectorAlmostEqual(velocities[4 * k:4 * k + 4], [i + 0.1, i + 0.2, i + 0.3, i + 0.4]) + self.assertVectorAlmostEqual(accelerations[4 * k:4 * k + 4], [i + 0.5, i + 0.6, i + 0.7, i + 0.8]) + + def test_natural_frequencies(self): + # Clamped-free beam: bending (beta_1 L)^2 sqrt(EI / (rho A L^4)), torsion and axial pi / (2 L) sqrt(...) + _, model_part, nodes = self.build_cantilever() + omegas, _, _ = self.eigen_modes(model_part, nodes) + beta_1 = 1.875104068711961 + references = [ + beta_1 ** 2 * np.sqrt(E_MOD * I33_ / (AREA * LENGTH ** 4)), + beta_1 ** 2 * np.sqrt(E_MOD * I22_ / (AREA * LENGTH ** 4)), + np.pi / (2.0 * LENGTH) * np.sqrt(G_MOD * I_T_ / (I22_ + I33_)), + np.pi / (2.0 * LENGTH) * np.sqrt(E_MOD), + ] + for reference in references: + self.assertRelativelyEqual(omegas[np.argmin(np.abs(omegas - reference))], reference, 1e-5) + + def run_free_vibration(self, reference_omega, tip_dof, steps_per_period=200): + """Releases the cantilever at rest in the mode closest to reference_omega and integrates one period with BDF2. + Returns the tip value of tip_dof over time, normalized by its initial value.""" + _, model_part, nodes = self.build_cantilever(dynamic=True) + omegas, modes, free = self.eigen_modes(model_part, nodes) + self.apply_state(nodes, np.zeros(4 * len(nodes))) + + shape = np.zeros(4 * len(nodes)) + shape[free] = modes[:, np.argmin(np.abs(omegas - reference_omega))] + tip_index = 4 * (len(nodes) - 1) + tip_dof + shape *= 1e-6 / shape[tip_index] # small amplitude, linear regime + + model_part.ProcessInfo[KM.DOMAIN_SIZE] = 3 + model_part.SetBufferSize(3) + for i, node in enumerate(nodes): + for step in range(3): + node.SetSolutionStepValue(KM.DISPLACEMENT, step, KM.Array3([float(v) for v in shape[4 * i:4 * i + 3]])) + node.SetSolutionStepValue(KM.ROTATION_X, step, float(shape[4 * i + 3])) + + # The BDF scheme also integrates the rotation about the beam axis (ROTATION_X) + scheme = KM.ResidualBasedBDFCustomScheme(2, KM.Parameters(r'''{ + "domain_size": 3, + "integration_order": 2, + "solution_variables": ["DISPLACEMENT", "ROTATION_X"] + }''')) + linear_solver = python_linear_solver_factory.ConstructSolver( + KM.Parameters(r'{"solver_type": "skyline_lu_factorization"}')) + strategy = KM.ResidualBasedNewtonRaphsonStrategy( + model_part, scheme, linear_solver, KM.ResidualCriteria(1e-10, 1e-14), 10, False, False, False) + strategy.SetEchoLevel(0) + strategy.Check() + + tip_variable = (KM.DISPLACEMENT_X, KM.DISPLACEMENT_Y, KM.DISPLACEMENT_Z, KM.ROTATION_X)[tip_dof] + dt = 2.0 * np.pi / reference_omega / steps_per_period + start_time = model_part.ProcessInfo[KM.TIME] + values = [] + for step in range(1, steps_per_period + 1): + model_part.CloneTimeStep(start_time + step * dt) + strategy.Solve() + values.append(nodes[-1].GetSolutionStepValue(tip_variable) / shape[tip_index]) + return np.array(values), dt + + def assertFreeVibrationPeriod(self, reference_omega, tip_dof): + values, dt = self.run_free_vibration(reference_omega, tip_dof) + # First zero crossing at a quarter of the period, and no loss of amplitude after half a period + i = np.where((values[:-1] > 0.0) & (values[1:] <= 0.0))[0][0] + crossing_time = dt * (i + 1) + dt * values[i] / (values[i] - values[i + 1]) + quarter_period = 0.5 * np.pi / reference_omega + self.assertRelativelyEqual(crossing_time, quarter_period, 1e-3) + self.assertRelativelyEqual(values.min(), -1.0, 1e-2) + + def test_free_vibration_bending(self): + beta_1 = 1.875104068711961 + self.assertFreeVibrationPeriod(beta_1 ** 2 * np.sqrt(E_MOD * I33_ / (AREA * LENGTH ** 4)), tip_dof=2) + + def test_free_vibration_torsion(self): + self.assertFreeVibrationPeriod(np.pi / (2.0 * LENGTH) * np.sqrt(G_MOD * I_T_ / (I22_ + I33_)), tip_dof=3) + def test_linear_bending_is_mesh_independent(self): # The exact cubic deflection is in the spline space of every mesh, since the curve is linearly parametrized. load = 1e-4 * E_MOD * I22_ / LENGTH ** 2 From df01fd7c059e63448e2ece504b3b5b6a0a0727d9 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 20 Nov 2026 14:26:47 +0100 Subject: [PATCH 25/32] [IGA] Speed up the beam dynamics and elastica tests The free vibration tests used an absolute residual tolerance of 1e-14, below the round-off level of the residual, so every time step ran into the maximum of 10 Newton iterations and the IGA tests exceeded the 15 minute CI limit in the FullDebug and Custom builds. The vibration is linear, so a tolerance of 1e-6/1e-9 converges in one iteration per step with the same accuracy. Only half a period is integrated, which is all the checks need. The elastica Newton loop hit its 40 iteration cap in some load steps for the same reason; its tolerance is relaxed to 1e-8, still well below the 5e-4 accuracy that is checked. Co-Authored-By: Claude Opus 5.5 --- ...isogeometric_non_linear_bernoulli_beam_element.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index cd26ea7dbb0f..51d597894f80 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -540,7 +540,8 @@ def test_large_deflection_elastica(self): model_part.GetProperties()[1].SetValue(IGA.CROSS_AREA, 1e4 * AREA) f_ext = np.zeros(4 * len(nodes)) f_ext[4 * (len(nodes) - 1) + 1] = -load - u, _ = self.newton(model_part, nodes, f_ext, n_steps=8) + # The very stiff axial response limits the attainable residual, hence the 1e-8 tolerance + u, _ = self.newton(model_part, nodes, f_ext, n_steps=8, tolerance=1e-8) self.assertRelativelyEqual(u[4 * (len(nodes) - 1) + 1], uy_exact, 5e-4) self.assertRelativelyEqual(u[4 * (len(nodes) - 1)], ux_exact, 5e-4) @@ -623,7 +624,7 @@ def test_natural_frequencies(self): self.assertRelativelyEqual(omegas[np.argmin(np.abs(omegas - reference))], reference, 1e-5) def run_free_vibration(self, reference_omega, tip_dof, steps_per_period=200): - """Releases the cantilever at rest in the mode closest to reference_omega and integrates one period with BDF2. + """Releases the cantilever at rest in the mode closest to reference_omega and integrates half a period with BDF2. Returns the tip value of tip_dof over time, normalized by its initial value.""" _, model_part, nodes = self.build_cantilever(dynamic=True) omegas, modes, free = self.eigen_modes(model_part, nodes) @@ -649,8 +650,9 @@ def run_free_vibration(self, reference_omega, tip_dof, steps_per_period=200): }''')) linear_solver = python_linear_solver_factory.ConstructSolver( KM.Parameters(r'{"solver_type": "skyline_lu_factorization"}')) + # The vibration is linear (small amplitude), so a single Newton iteration per step converges strategy = KM.ResidualBasedNewtonRaphsonStrategy( - model_part, scheme, linear_solver, KM.ResidualCriteria(1e-10, 1e-14), 10, False, False, False) + model_part, scheme, linear_solver, KM.ResidualCriteria(1e-6, 1e-9), 10, False, False, False) strategy.SetEchoLevel(0) strategy.Check() @@ -658,7 +660,7 @@ def run_free_vibration(self, reference_omega, tip_dof, steps_per_period=200): dt = 2.0 * np.pi / reference_omega / steps_per_period start_time = model_part.ProcessInfo[KM.TIME] values = [] - for step in range(1, steps_per_period + 1): + for step in range(1, steps_per_period // 2 + 1): model_part.CloneTimeStep(start_time + step * dt) strategy.Solve() values.append(nodes[-1].GetSolutionStepValue(tip_variable) / shape[tip_index]) @@ -666,7 +668,7 @@ def run_free_vibration(self, reference_omega, tip_dof, steps_per_period=200): def assertFreeVibrationPeriod(self, reference_omega, tip_dof): values, dt = self.run_free_vibration(reference_omega, tip_dof) - # First zero crossing at a quarter of the period, and no loss of amplitude after half a period + # First zero crossing at a quarter of the period, and no loss of amplitude at half the period i = np.where((values[:-1] > 0.0) & (values[1:] <= 0.0))[0][0] crossing_time = dt * (i + 1) + dt * values[i] / (values[i] - values[i + 1]) quarter_period = 0.5 * np.pi / reference_omega From 253063f5a46d3ac5030628a74fd761684f04a71d Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Fri, 20 Nov 2026 14:47:59 +0100 Subject: [PATCH 26/32] [IGA] Remove unused beam variables LOCAL_CS_N, LOCAL_CS_n, LOCAL_CS_V, LOCAL_CS_v and ROTATIONAL_DOF_ACTIVE were defined and registered but never used. Co-Authored-By: Claude Opus 5.5 --- .../IgaApplication/custom_python/iga_python_application.cpp | 5 ----- applications/IgaApplication/iga_application.cpp | 5 ----- applications/IgaApplication/iga_application_variables.cpp | 5 ----- applications/IgaApplication/iga_application_variables.h | 5 ----- 4 files changed, 20 deletions(-) diff --git a/applications/IgaApplication/custom_python/iga_python_application.cpp b/applications/IgaApplication/custom_python/iga_python_application.cpp index 29c197090330..671665365b4f 100644 --- a/applications/IgaApplication/custom_python/iga_python_application.cpp +++ b/applications/IgaApplication/custom_python/iga_python_application.cpp @@ -70,11 +70,6 @@ PYBIND11_MODULE(KratosIgaApplication, m) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I22) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I33) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_T) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_N) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_n) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_V) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, LOCAL_CS_v) - KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DIRECTOR_COMPUTED) diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index 0617044e0485..4386e56c1882 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -219,10 +219,6 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(BUILD_LEVEL) // Beam variables - KRATOS_REGISTER_VARIABLE(LOCAL_CS_N) - KRATOS_REGISTER_VARIABLE(LOCAL_CS_n) - KRATOS_REGISTER_VARIABLE(LOCAL_CS_V) - KRATOS_REGISTER_VARIABLE(LOCAL_CS_v) KRATOS_REGISTER_VARIABLE(T_0) KRATOS_REGISTER_VARIABLE(N_0) KRATOS_REGISTER_VARIABLE(LOCAL_AXIS_ORIENTATION) @@ -230,7 +226,6 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(I22) KRATOS_REGISTER_VARIABLE(I33) KRATOS_REGISTER_VARIABLE(I_T) - KRATOS_REGISTER_VARIABLE(ROTATIONAL_DOF_ACTIVE) // SBM Variables diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index d979db32a1cb..b981efe08837 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -47,11 +47,6 @@ KRATOS_CREATE_VARIABLE(Vector, T_0) KRATOS_CREATE_VARIABLE(Vector, N_0) KRATOS_CREATE_VARIABLE(Matrix, LOCAL_AXIS_ORIENTATION) KRATOS_CREATE_VARIABLE(double, I_T) -KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_N) -KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_n) -KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_V) -KRATOS_CREATE_VARIABLE(Vector, LOCAL_CS_v) -KRATOS_CREATE_VARIABLE(bool, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables KRATOS_CREATE_VARIABLE(bool, DIRECTOR_COMPUTED) diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index e5107c797338..56468cb346d7 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -56,11 +56,6 @@ KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, T_0) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, N_0) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Matrix, LOCAL_AXIS_ORIENTATION) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, double, I_T) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_N) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_n) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_V) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, LOCAL_CS_v) -KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, ROTATIONAL_DOF_ACTIVE) // 5p Director Shell Variables KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, DIRECTOR_COMPUTED) From 24a6250a202a98977d57c139c5eeb00264e3baf8 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 23 Nov 2026 10:04:28 +0100 Subject: [PATCH 27/32] [IGA] Make the beam torsional constant optional - I_T defaults to the polar moment I22 + I33 when it is not provided, with a one-time warning since this is only exact for circular cross sections. Tested with a cantilever under torque without I_T. - Use the boolean flags directly instead of comparing them with true/false. Co-Authored-By: Claude Opus 5.5 --- ...ernoulli_beam_elastic_constitutive_law.cpp | 33 +++++++++++++++++-- .../custom_elements/beam_base_element_3D.cpp | 12 +++---- .../non_linear_bernoulli_beam_element_3D.cpp | 7 ++-- ...etric_non_linear_bernoulli_beam_element.py | 14 ++++++-- 4 files changed, 51 insertions(+), 15 deletions(-) diff --git a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp index 098a07e74a1d..68a4f111a12c 100644 --- a/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -12,6 +12,7 @@ // // System includes +#include // External includes @@ -22,6 +23,33 @@ namespace Kratos { +namespace +{ + +/** + * @brief Torsional constant I_T, defaulting to the polar moment I22 + I33 when it is not provided. + * @details The default is exact for circular (solid or hollow) cross sections only; for other + * sections it overestimates the torsional stiffness, hence the warning. + */ +double GetTorsionalInertia(const Properties& rMaterialProperties) +{ + if (rMaterialProperties.Has(I_T)) { + return rMaterialProperties[I_T]; + } + + static std::once_flag warning_flag; + std::call_once(warning_flag, [](){ + KRATOS_WARNING("BernoulliBeamElasticConstitutiveLaw") + << "I_T is not defined in the properties, using I22 + I33 instead. " + << "This is only exact for circular cross sections." << std::endl; + }); + + return rMaterialProperties[I22] + rMaterialProperties[I33]; +} + +} // namespace + + BernoulliBeamElasticConstitutiveLaw::BernoulliBeamElasticConstitutiveLaw() : ConstitutiveLaw() { @@ -64,13 +92,12 @@ int BernoulliBeamElasticConstitutiveLaw::Check( KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(CROSS_AREA)) << "CROSS_AREA is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I33)) << "I33 is not defined in the properties" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I22)) << "I22 is not defined in the properties" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties.Has(I_T)) << "I_T is not defined in the properties" << std::endl; // Validate property values KRATOS_ERROR_IF_NOT(rMaterialProperties[CROSS_AREA] > 0.0) << "CROSS_AREA must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I33] > 0.0) << "I33 must be positive" << std::endl; KRATOS_ERROR_IF_NOT(rMaterialProperties[I22] > 0.0) << "I22 must be positive" << std::endl; - KRATOS_ERROR_IF_NOT(rMaterialProperties[I_T] > 0.0) << "I_T must be positive" << std::endl; + KRATOS_ERROR_IF(rMaterialProperties.Has(I_T) && rMaterialProperties[I_T] <= 0.0) << "I_T must be positive" << std::endl; return 0; } @@ -108,7 +135,7 @@ void BernoulliBeamElasticConstitutiveLaw::CalculateMaterialResponseCauchy(Consti // Moments of inertia about the local cross-section axes 2 (normal n) and 3 (v = t x n) const double I_22 = r_material_properties[I22]; const double I_33 = r_material_properties[I33]; - const double I_t = r_material_properties[I_T]; + const double I_t = GetTorsionalInertia(r_material_properties); if (r_cl_law_options.Is(ConstitutiveLaw::COMPUTE_STRESS)) { auto &r_stress_vector = rValues.GetStressVector(); diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp index c885bb8e8877..56ebb13fa8cf 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp @@ -219,22 +219,22 @@ namespace Kratos const auto& r_geometry = GetGeometry(); for (IndexType i = 0; i < r_geometry.size(); ++i) { - if (r_geometry[i].SolutionStepsDataHas(DISPLACEMENT) == false) { + if (!r_geometry[i].SolutionStepsDataHas(DISPLACEMENT)) { KRATOS_ERROR << "missing variable DISPLACEMENT on node " << r_geometry[i].Id() << std::endl; } - if (r_geometry[i].SolutionStepsDataHas(ROTATION_X) == false) { + if (!r_geometry[i].SolutionStepsDataHas(ROTATION_X)) { KRATOS_ERROR << "missing variable ROTATION_X on node " << r_geometry[i].Id() << std::endl; } if ( - r_geometry[i].HasDofFor(DISPLACEMENT_X) == false || - r_geometry[i].HasDofFor(DISPLACEMENT_Y) == false || - r_geometry[i].HasDofFor(DISPLACEMENT_Z) == false) + !r_geometry[i].HasDofFor(DISPLACEMENT_X) || + !r_geometry[i].HasDofFor(DISPLACEMENT_Y) || + !r_geometry[i].HasDofFor(DISPLACEMENT_Z)) { KRATOS_ERROR << "missing one of the dofs for the variable " @@ -242,7 +242,7 @@ namespace Kratos << r_geometry[i].Id() << std::endl; } - if (r_geometry[i].HasDofFor(ROTATION_X) == false) { + if (!r_geometry[i].HasDofFor(ROTATION_X)) { KRATOS_ERROR << "missing dof for the variable ROTATION_X on node " << r_geometry[i].Id() << std::endl; diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index 609eae4a44a5..2f71edcec590 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -355,7 +355,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const double inverse_a4 = inverse_a2 * inverse_a2; - if (CalculateStiffnessMatrixFlag == true) { + if (CalculateStiffnessMatrixFlag) { if (calculate_material_stiffness) { // Material stiffness rLeftHandSideMatrix += @@ -454,7 +454,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( } } - if (CalculateResidualVectorFlag == true) { + if (CalculateResidualVectorFlag) { // Internal forces. Each B matrix has a single non-zero row, the one of its generalized strain. const Vector& r_stress_vector = constitutive_variables.StressVector; @@ -505,8 +505,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( const double numerical_limit = std::numeric_limits::epsilon(); + // I_T is optional: the constitutive law uses I22 + I33 if it is not provided KRATOS_ERROR_IF( - !GetProperties().Has(I_T) || + GetProperties().Has(I_T) && GetProperties()[I_T] <= numerical_limit) << "Please provide a reasonable value for \"I_T\" " << "(torsional moment of inertia) for element #" diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index 51d597894f80..f5103b504f8a 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -42,7 +42,8 @@ def create_properties(model_part, properties_id, normal, young_modulus=E_MOD, po properties.SetValue(IGA.CROSS_AREA, area) properties.SetValue(IGA.I22, i22) properties.SetValue(IGA.I33, i33) - properties.SetValue(IGA.I_T, i_t) + if i_t is not None: # I_T is optional, I22 + I33 is used otherwise + properties.SetValue(IGA.I_T, i_t) properties.SetValue(KM.YOUNG_MODULUS, young_modulus) properties.SetValue(KM.POISSON_RATIO, poisson_ratio) properties.SetValue(KM.DENSITY, 1.0) @@ -141,11 +142,11 @@ class TestBeam4pElement(BeamTestCase): """Linear response of the NonLinearBernoulliBeamElement3D compared to beam theory.""" @staticmethod - def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0), volume_acceleration=None): + def solve_cantilever(force, moment=(0.0, 0.0, 0.0), normal=(0.0, 0.0, 1.0), volume_acceleration=None, i_t=I_T_): """Cantilever along +X, clamped at x = 0 and loaded at the tip. Returns the tip node.""" model = KM.Model() model_part = create_model_part(model, body_forces=volume_acceleration is not None) - properties = create_properties(model_part, 1, normal) + properties = create_properties(model_part, 1, normal, i_t=i_t) curve = create_straight_curve(model_part, (0.0, 0.0, 0.0), (1.0, 0.0, 0.0)) create_elements(model_part, curve, properties) @@ -267,6 +268,13 @@ def test_torsion(self): self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Y)), 1e-8 * reference) self.assertLess(abs(tip.GetSolutionStepValue(KM.DISPLACEMENT_Z)), 1e-8 * reference) + def test_torsion_without_torsional_constant(self): + # Without I_T the polar moment I22 + I33 is used as torsional constant + tip = self.solve_cantilever((0.0, 0.0, 0.0), moment=(1.0, 0.0, 0.0), i_t=None) + reference = LENGTH / (G_MOD * (I22_ + I33_)) + + self.assertRelativelyEqual(tip.GetSolutionStepValue(KM.ROTATION_X), reference, 1e-8) + def test_self_weight(self): # Uniform line load q = rho * A * g from the body forces: tip deflection q L^4 / (8 E I) gravity = 9.81 From 93f82cbf085bbdc19aa1107d088a7a33f1bec040 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 23 Nov 2026 10:14:23 +0100 Subject: [PATCH 28/32] [IGA] Replace the hand-written product loops of the Bernoulli beam The products of 3x3 matrices and of the variation containers were written as nested loops of up to five levels. They are now prod() calls, plus four documented helpers for the products that are not plain matrix products because of the storage layout of the variations: 24 of the loop nests are replaced and the element goes from 129 to 55 for-loops. The refactor only reorders the same algebra. The stiffness (full, material and geometric), residual and mass of a straight, a curved and a curved and twisted beam at undeformed and deformed states match the previous implementation to 4e-18 relative to their physical scale. A new finite-difference tangent test on a curved and twisted beam at a deformed state exercises the reference curvature, mapping and twist terms that vanish for the straight beam. Co-Authored-By: Claude Opus 5.5 --- .../non_linear_bernoulli_beam_element_3D.cpp | 560 +++++++----------- .../beam_curved_refinements.iga.json | 13 + ...etric_non_linear_bernoulli_beam_element.py | 66 +++ 3 files changed, 278 insertions(+), 361 deletions(-) create mode 100644 applications/IgaApplication/tests/modeler_tests/beam_curved_refinements.iga.json diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index 2f71edcec590..8f0740fa41c6 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -23,6 +23,104 @@ namespace Kratos { + +namespace +{ + +/* + * Products with the variation containers of a 3x3 matrix M with respect to the n element dofs: + * - first variation: (3 n) x 3 matrix with M,r(i, j) at (i * n + r, j) + * - second variation: (3 n) x (3 n) matrix with M,rs(i, j) at (i * n + r, j * n + s) + * A product of a first variation with a constant 3x3 matrix from the right is a plain prod(), the + * other products below are not, because of this layout. + */ + +/// rResult += A * V,r for all dofs r, with V,r a first variation +template +void AddMatrixTimesVariation( + Matrix& rResult, + const TMatrixType& rMatrix, + const Matrix& rVariation, + const std::size_t NumberOfDofs) +{ + for (std::size_t i = 0; i < 3; ++i) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t r = 0; r < NumberOfDofs; ++r) { + rResult(i * NumberOfDofs + r, j) += rMatrix(i, k) * rVariation(k * NumberOfDofs + r, j); + } + } + } + } +} + +/// rResult += W,rs * A for all dofs r, s, with W,rs a second variation +template +void AddSecondVariationTimesMatrix( + Matrix& rResult, + const Matrix& rSecondVariation, + const TMatrixType& rMatrix, + const std::size_t NumberOfDofs) +{ + for (std::size_t i = 0; i < 3; ++i) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t r = 0; r < NumberOfDofs; ++r) { + for (std::size_t s = 0; s < NumberOfDofs; ++s) { + rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += + rSecondVariation(i * NumberOfDofs + r, k * NumberOfDofs + s) * rMatrix(k, j); + } + } + } + } + } +} + +/// rResult += A * W,rs for all dofs r, s, with W,rs a second variation +template +void AddMatrixTimesSecondVariation( + Matrix& rResult, + const TMatrixType& rMatrix, + const Matrix& rSecondVariation, + const std::size_t NumberOfDofs) +{ + for (std::size_t i = 0; i < 3; ++i) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t r = 0; r < NumberOfDofs; ++r) { + for (std::size_t s = 0; s < NumberOfDofs; ++s) { + rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += + rMatrix(i, k) * rSecondVariation(k * NumberOfDofs + r, j * NumberOfDofs + s); + } + } + } + } + } +} + +/// rResult += V,r * W,s for all dofs r, s: the mixed second variation of the product of two matrices V and W +void AddVariationTimesVariation( + Matrix& rResult, + const Matrix& rFirstVariation, + const Matrix& rSecondVariation, + const std::size_t NumberOfDofs) +{ + for (std::size_t i = 0; i < 3; ++i) { + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + for (std::size_t r = 0; r < NumberOfDofs; ++r) { + for (std::size_t s = 0; s < NumberOfDofs; ++s) { + rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += + rFirstVariation(i * NumberOfDofs + r, k) * rSecondVariation(k * NumberOfDofs + s, j); + } + } + } + } + } +} + +} // namespace + void NonLinearBernoulliBeamElement3D::Initialize(const ProcessInfo& rCurrentProcessInfo) { KRATOS_TRY @@ -847,21 +945,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector3d transformed_reference_normal; transformed_reference_normal.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - transformed_reference_normal[i] += - reference_lambda_matrix(i, j) - * rKinematicVariables.N0[j]; - } - } + noalias(transformed_reference_normal) += prod(reference_lambda_matrix, rKinematicVariables.N0); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - rKinematicVariables.n(i) += - reference_rodrigues_matrix(i, j) - * transformed_reference_normal[j]; - } - } + noalias(rKinematicVariables.n) += prod(reference_rodrigues_matrix, transformed_reference_normal); rKinematicVariables.n /= norm_2(rKinematicVariables.n); @@ -869,36 +955,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( rKinematicVariables.v = MathUtils::CrossProduct(reference_tangent, rKinematicVariables.n); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - for (IndexType k = 0; k < 3; ++k) { - cross_section_transformation_derivative(i, j) += - reference_rodrigues_matrix_derivative(i, k) - * reference_lambda_matrix(k, j); - - cross_section_transformation_derivative(i, j) += - reference_rodrigues_matrix(i, k) - * reference_lambda_matrix_derivative(k, j); - } - } - } + noalias(cross_section_transformation_derivative) += prod(reference_rodrigues_matrix_derivative, reference_lambda_matrix); + noalias(cross_section_transformation_derivative) += prod(reference_rodrigues_matrix, reference_lambda_matrix_derivative); Vector3d a21_vector; Vector3d a31_vector; a21_vector.clear(); a31_vector.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - a21_vector[i] += - cross_section_transformation_derivative(i, j) - * rKinematicVariables.N0[j]; - - a31_vector[i] += - cross_section_transformation_derivative(i, j) - * rKinematicVariables.V0[j]; - } - } + noalias(a21_vector) += prod(cross_section_transformation_derivative, rKinematicVariables.N0); + noalias(a31_vector) += prod(cross_section_transformation_derivative, rKinematicVariables.V0); rKinematicVariables.B_n = inner_prod(a21_vector, reference_first_base_vector); @@ -1016,23 +1082,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( reference_rodrigues_lambda_derivative_product.clear(); reference_rodrigues_derivative_lambda_product.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - for (IndexType k = 0; k < 3; ++k) { - reference_rodrigues_lambda_product(i, j) += - reference_rodrigues_matrix(i, k) - * reference_lambda_matrix(k, j); - - reference_rodrigues_lambda_derivative_product(i, j) += - reference_rodrigues_matrix(i, k) - * reference_lambda_matrix_derivative(k, j); - - reference_rodrigues_derivative_lambda_product(i, j) += - reference_rodrigues_matrix_derivative(i, k) - * reference_lambda_matrix(k, j); - } - } - } + noalias(reference_rodrigues_lambda_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix); + noalias(reference_rodrigues_lambda_derivative_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix_derivative); + noalias(reference_rodrigues_derivative_lambda_product) += prod(reference_rodrigues_matrix_derivative, reference_lambda_matrix); Matrix3d current_lambda_reference_rodrigues_lambda_product; Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; @@ -1043,27 +1095,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( current_lambda_reference_rodrigues_derivative_lambda_product.clear(); current_lambda_derivative_reference_rodrigues_lambda_product.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - for (IndexType k = 0; k < 3; ++k) { - current_lambda_reference_rodrigues_lambda_product(i, j) += - current_lambda_matrix(i, k) - * reference_rodrigues_lambda_product(k, j); - - current_lambda_reference_rodrigues_lambda_derivative_product(i, j) += - current_lambda_matrix(i, k) - * reference_rodrigues_lambda_derivative_product(k, j); - - current_lambda_reference_rodrigues_derivative_lambda_product(i, j) += - current_lambda_matrix(i, k) - * reference_rodrigues_derivative_lambda_product(k, j); - - current_lambda_derivative_reference_rodrigues_lambda_product(i, j) += - current_lambda_matrix_derivative(i, k) - * reference_rodrigues_lambda_product(k, j); - } - } - } + noalias(current_lambda_reference_rodrigues_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_product); + noalias(current_lambda_reference_rodrigues_lambda_derivative_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_derivative_product); + noalias(current_lambda_reference_rodrigues_derivative_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_derivative_lambda_product); + noalias(current_lambda_derivative_reference_rodrigues_lambda_product) += prod(current_lambda_matrix_derivative, reference_rodrigues_lambda_product); Matrix3d current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term; Matrix3d current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term; @@ -1077,31 +1112,11 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term.clear(); cross_section_transformation.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - for (IndexType k = 0; k < 3; ++k) { - current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(i, j) += - current_rodrigues_matrix(i, k) - * current_lambda_reference_rodrigues_lambda_derivative_product(k, j); - - current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(i, j) += - current_rodrigues_matrix(i, k) - * current_lambda_reference_rodrigues_derivative_lambda_product(k, j); - - current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(i, j) += - current_rodrigues_matrix(i, k) - * current_lambda_derivative_reference_rodrigues_lambda_product(k, j); - - current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(i, j) += - current_rodrigues_matrix_derivative(i, k) - * current_lambda_reference_rodrigues_lambda_product(k, j); - - cross_section_transformation(i, j) += - current_rodrigues_matrix(i, k) - * current_lambda_reference_rodrigues_lambda_product(k, j); - } - } - } + noalias(current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_derivative_product); + noalias(current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_derivative_lambda_product); + noalias(current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix, current_lambda_derivative_reference_rodrigues_lambda_product); + noalias(current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix_derivative, current_lambda_reference_rodrigues_lambda_product); + noalias(cross_section_transformation) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_product); const Matrix3d cross_section_transformation_derivative = current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term @@ -1114,25 +1129,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( a21_vector.clear(); a31_vector.clear(); - for (IndexType i = 0; i < 3; ++i) { - for (IndexType j = 0; j < 3; ++j) { - a21_vector[i] += - cross_section_transformation_derivative(i, j) - * rKinematicVariables.N0[j]; - - a31_vector[i] += - cross_section_transformation_derivative(i, j) - * rKinematicVariables.V0[j]; - - rKinematicVariables.n[i] += - cross_section_transformation(i, j) - * rKinematicVariables.N0[j]; - - rKinematicVariables.v[i] += - cross_section_transformation(i, j) - * rKinematicVariables.V0[j]; - } - } + noalias(a21_vector) += prod(cross_section_transformation_derivative, rKinematicVariables.N0); + noalias(a31_vector) += prod(cross_section_transformation_derivative, rKinematicVariables.V0); + noalias(rKinematicVariables.n) += prod(cross_section_transformation, rKinematicVariables.N0); + noalias(rKinematicVariables.v) += prod(cross_section_transformation, rKinematicVariables.V0); rKinematicVariables.b_n = inner_prod(a21_vector, current_first_base_vector); @@ -1275,18 +1275,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d reference_rodrigues_lambda_product_derivative; reference_rodrigues_lambda_product_derivative.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int column_component = 0; column_component < 3; column_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); - reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); - reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); - } - } - } + noalias(reference_rodrigues_lambda_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix); + noalias(reference_rodrigues_lambda_derivative_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix_derivative); + noalias(reference_rodrigues_derivative_lambda_product) += prod(reference_rodrigues_matrix_derivative, reference_lambda_matrix); reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; @@ -1300,19 +1291,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; current_lambda_reference_rodrigues_lambda_product_derivative.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int column_component = 0; column_component < 3; column_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - } - } - } + noalias(current_lambda_reference_rodrigues_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_product); + noalias(current_lambda_reference_rodrigues_lambda_derivative_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_derivative_product); + noalias(current_lambda_reference_rodrigues_derivative_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_derivative_lambda_product); + noalias(current_lambda_derivative_reference_rodrigues_lambda_product) += prod(current_lambda_matrix_derivative, reference_rodrigues_lambda_product); current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; @@ -1327,20 +1309,11 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d cross_section_transformation; cross_section_transformation.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int column_component = 0; column_component < 3; column_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - } - } - } + noalias(current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_derivative_product); + noalias(current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_derivative_lambda_product); + noalias(current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix, current_lambda_derivative_reference_rodrigues_lambda_product); + noalias(current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix_derivative, current_lambda_reference_rodrigues_lambda_product); + noalias(cross_section_transformation) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_product); Matrix3d cross_section_transformation_derivative; cross_section_transformation_derivative.clear(); @@ -1351,22 +1324,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( lambda_variation_rodrigues_lambda_matrix.clear(); lambda_derivative_variation_rodrigues_lambda_matrix.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int column_component = 0; column_component < 3; column_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) - { - lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - } - } - } - } + noalias(lambda_variation_rodrigues_lambda_matrix) += prod(lambda_variation_matrix, reference_rodrigues_lambda_product); + noalias(lambda_variation_rodrigues_lambda_derivative_matrix) += prod(lambda_variation_matrix, reference_rodrigues_lambda_derivative_product); + noalias(lambda_variation_rodrigues_derivative_lambda_matrix) += prod(lambda_variation_matrix, reference_rodrigues_derivative_lambda_product); + noalias(lambda_derivative_variation_rodrigues_lambda_matrix) += prod(lambda_derivative_variation_matrix, reference_rodrigues_lambda_product); Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); @@ -1385,28 +1346,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( rodrigues_lambda_variation_rodrigues_lambda_matrix.clear(); rodrigues_variation_lambda_rodrigues_lambda_matrix.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int column_component = 0; column_component < 3; column_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) - { - rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - } - } - } - } + noalias(rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_lambda_derivative_product); + noalias(rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_derivative_lambda_product); + noalias(rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_derivative_reference_rodrigues_lambda_product); + noalias(rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix) += prod(rodrigues_derivative_variation_matrix, current_lambda_reference_rodrigues_lambda_product); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_lambda_derivative_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_derivative_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix, current_rodrigues_matrix, lambda_derivative_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix, current_rodrigues_matrix_derivative, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_lambda_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + noalias(rodrigues_variation_lambda_rodrigues_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_lambda_product); rodrigues_lambda_rodrigues_lambda_derivative_variation_matrix.clear(); rodrigues_lambda_rodrigues_lambda_variation_matrix.clear(); @@ -1420,14 +1369,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector3d binormal_vector; binormal_vector.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); - binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); - } - } + noalias(normal_vector) += prod(cross_section_transformation, reference_normal); + noalias(binormal_vector) += prod(cross_section_transformation, reference_binormal); Vector normal_vector_variation; normal_vector_variation.resize(3 * mNumberOfDofs); @@ -1436,17 +1379,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( binormal_vector_variation.resize(3 * mNumberOfDofs); binormal_vector_variation.clear(); - for (size_t row_component = 0; row_component < 3; row_component++) - { - for (size_t dof_index = 0; dof_index < mNumberOfDofs; dof_index++) - { - for (int product_index = 0; product_index < 3; product_index++) - { - normal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); - binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); - } - } - } + noalias(normal_vector_variation) += prod(rodrigues_lambda_rodrigues_lambda_variation_matrix, reference_normal); + noalias(binormal_vector_variation) += prod(rodrigues_lambda_rodrigues_lambda_variation_matrix, reference_binormal); Vector current_first_base_vector_variation; current_first_base_vector_variation.resize(3 * mNumberOfDofs); @@ -1675,18 +1609,9 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d reference_rodrigues_lambda_product_derivative; reference_rodrigues_lambda_product_derivative.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - reference_rodrigues_lambda_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix(product_index, column_component); - reference_rodrigues_lambda_derivative_product(row_component, column_component) += reference_rodrigues_matrix(row_component, product_index) * reference_lambda_matrix_derivative(product_index, column_component); - reference_rodrigues_derivative_lambda_product(row_component, column_component) += reference_rodrigues_matrix_derivative(row_component, product_index) * reference_lambda_matrix(product_index, column_component); - } - } - } + noalias(reference_rodrigues_lambda_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix); + noalias(reference_rodrigues_lambda_derivative_product) += prod(reference_rodrigues_matrix, reference_lambda_matrix_derivative); + noalias(reference_rodrigues_derivative_lambda_product) += prod(reference_rodrigues_matrix_derivative, reference_lambda_matrix); reference_rodrigues_lambda_product_derivative = reference_rodrigues_lambda_derivative_product + reference_rodrigues_derivative_lambda_product; Matrix3d current_lambda_reference_rodrigues_lambda_derivative_product; @@ -1700,19 +1625,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d current_lambda_reference_rodrigues_lambda_product_derivative; current_lambda_reference_rodrigues_lambda_product_derivative.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - current_lambda_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - current_lambda_reference_rodrigues_lambda_derivative_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_lambda_reference_rodrigues_derivative_lambda_product(row_component, column_component) += current_lambda_matrix(row_component, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_lambda_derivative_reference_rodrigues_lambda_product(row_component, column_component) += current_lambda_matrix_derivative(row_component, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - } - } - } + noalias(current_lambda_reference_rodrigues_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_product); + noalias(current_lambda_reference_rodrigues_lambda_derivative_product) += prod(current_lambda_matrix, reference_rodrigues_lambda_derivative_product); + noalias(current_lambda_reference_rodrigues_derivative_lambda_product) += prod(current_lambda_matrix, reference_rodrigues_derivative_lambda_product); + noalias(current_lambda_derivative_reference_rodrigues_lambda_product) += prod(current_lambda_matrix_derivative, reference_rodrigues_lambda_product); current_lambda_reference_rodrigues_lambda_product_derivative = current_lambda_reference_rodrigues_lambda_derivative_product + current_lambda_reference_rodrigues_derivative_lambda_product + current_lambda_derivative_reference_rodrigues_lambda_product; @@ -1727,20 +1643,11 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Matrix3d cross_section_transformation; cross_section_transformation.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term(row_component, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - cross_section_transformation(row_component, column_component) += current_rodrigues_matrix(row_component, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - } - } - } + noalias(current_rodrigues_current_lambda_reference_rodrigues_lambda_derivative_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_derivative_product); + noalias(current_rodrigues_current_lambda_reference_rodrigues_derivative_lambda_term) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_derivative_lambda_product); + noalias(current_rodrigues_current_lambda_derivative_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix, current_lambda_derivative_reference_rodrigues_lambda_product); + noalias(current_rodrigues_derivative_current_lambda_reference_rodrigues_lambda_term) += prod(current_rodrigues_matrix_derivative, current_lambda_reference_rodrigues_lambda_product); + noalias(cross_section_transformation) += prod(current_rodrigues_matrix, current_lambda_reference_rodrigues_lambda_product); Matrix3d cross_section_transformation_derivative; cross_section_transformation_derivative.clear(); @@ -1752,22 +1659,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( lambda_variation_rodrigues_lambda_matrix.clear(); lambda_derivative_variation_rodrigues_lambda_matrix.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) - { - lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += lambda_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_rodrigues_lambda_product(product_index, column_component); - } - } - } - } + noalias(lambda_variation_rodrigues_lambda_matrix) += prod(lambda_variation_matrix, reference_rodrigues_lambda_product); + noalias(lambda_variation_rodrigues_lambda_derivative_matrix) += prod(lambda_variation_matrix, reference_rodrigues_lambda_derivative_product); + noalias(lambda_variation_rodrigues_derivative_lambda_matrix) += prod(lambda_variation_matrix, reference_rodrigues_derivative_lambda_product); + noalias(lambda_derivative_variation_rodrigues_lambda_matrix) += prod(lambda_derivative_variation_matrix, reference_rodrigues_lambda_product); Matrix current_lambda_reference_rodrigues_lambda_product_derivative_variation; current_lambda_reference_rodrigues_lambda_product_derivative_variation.resize(3 * mNumberOfDofs, 3); @@ -1786,28 +1681,16 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( rodrigues_lambda_variation_rodrigues_lambda_matrix.clear(); rodrigues_variation_lambda_rodrigues_lambda_matrix.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) - { - rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_lambda_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += current_rodrigues_matrix(row_component, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component); - rodrigues_variation_lambda_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - } - } - } - } + noalias(rodrigues_variation_lambda_rodrigues_lambda_derivative_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_lambda_derivative_product); + noalias(rodrigues_variation_lambda_rodrigues_derivative_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_derivative_lambda_product); + noalias(rodrigues_variation_lambda_derivative_rodrigues_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_derivative_reference_rodrigues_lambda_product); + noalias(rodrigues_derivative_variation_lambda_rodrigues_lambda_matrix) += prod(rodrigues_derivative_variation_matrix, current_lambda_reference_rodrigues_lambda_product); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_lambda_derivative_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_lambda_derivative_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_derivative_lambda_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_derivative_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_derivative_variation_rodrigues_lambda_matrix, current_rodrigues_matrix, lambda_derivative_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_derivative_lambda_variation_rodrigues_lambda_matrix, current_rodrigues_matrix_derivative, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesVariation(rodrigues_lambda_variation_rodrigues_lambda_matrix, current_rodrigues_matrix, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + noalias(rodrigues_variation_lambda_rodrigues_lambda_matrix) += prod(rodrigues_variation_matrix, current_lambda_reference_rodrigues_lambda_product); @@ -1822,25 +1705,10 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( lambda_second_variation_rodrigues_derivative_lambda_matrix.clear(); lambda_second_variation_rodrigues_lambda_derivative_matrix.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) - { - for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) - { - lambda_second_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); - lambda_derivative_second_variation_rodrigues_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_derivative_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_product(product_index, column_component); - lambda_second_variation_rodrigues_derivative_lambda_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_derivative_lambda_product(product_index, column_component); - lambda_second_variation_rodrigues_lambda_derivative_matrix(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += lambda_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * reference_rodrigues_lambda_derivative_product(product_index, column_component); - } - } - } - } - } + AddSecondVariationTimesMatrix(lambda_second_variation_rodrigues_lambda_matrix, lambda_second_variation_matrix, reference_rodrigues_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(lambda_derivative_second_variation_rodrigues_lambda_matrix, lambda_derivative_second_variation_matrix, reference_rodrigues_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(lambda_second_variation_rodrigues_derivative_lambda_matrix, lambda_second_variation_matrix, reference_rodrigues_derivative_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(lambda_second_variation_rodrigues_lambda_derivative_matrix, lambda_second_variation_matrix, reference_rodrigues_lambda_derivative_product, mNumberOfDofs); // 5. Second variation of T,1 = (R_t Lambda P),1: all product-rule terms of R_t, Lambda and P with two // variations distributed over R_t and Lambda (P is independent of the dofs), Eq. (A.2) and (A.4) @@ -1892,36 +1760,21 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int column_component = 0;column_component < 3;column_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) - { - for (size_t second_dof_index = 0;second_dof_index < mNumberOfDofs;second_dof_index++) - { - current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix_derivative(row_component, product_index) * lambda_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_derivative_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_derivative_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_derivative_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_derivative_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_derivative_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_derivative_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_derivative_reference_rodrigues_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_derivative_lambda_product(product_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_derivative_product(product_index, column_component); - current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += current_rodrigues_matrix(row_component, product_index) * lambda_second_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index); - current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * lambda_variation_rodrigues_lambda_matrix(product_index * mNumberOfDofs + second_dof_index, column_component); - current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term(row_component * mNumberOfDofs + dof_index, column_component * mNumberOfDofs + second_dof_index) += rodrigues_second_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index * mNumberOfDofs + second_dof_index) * current_lambda_reference_rodrigues_lambda_product(product_index, column_component); - } - } - } - } - } + AddMatrixTimesSecondVariation(current_rodrigues_derivative_lambda_second_variation_reference_rodrigues_lambda_term, current_rodrigues_matrix_derivative, lambda_second_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesSecondVariation(current_rodrigues_lambda_derivative_second_variation_reference_rodrigues_lambda_term, current_rodrigues_matrix, lambda_derivative_second_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddMatrixTimesSecondVariation(current_rodrigues_lambda_second_variation_reference_rodrigues_derivative_lambda_term, current_rodrigues_matrix, lambda_second_variation_rodrigues_derivative_lambda_matrix, mNumberOfDofs); + AddMatrixTimesSecondVariation(current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_derivative_term, current_rodrigues_matrix, lambda_second_variation_rodrigues_lambda_derivative_matrix, mNumberOfDofs); + AddVariationTimesVariation(current_rodrigues_derivative_variation_lambda_variation_reference_rodrigues_lambda_term, rodrigues_derivative_variation_matrix, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddVariationTimesVariation(current_rodrigues_variation_lambda_derivative_variation_reference_rodrigues_lambda_term, rodrigues_variation_matrix, lambda_derivative_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddVariationTimesVariation(current_rodrigues_variation_lambda_variation_reference_rodrigues_derivative_lambda_term, rodrigues_variation_matrix, lambda_variation_rodrigues_derivative_lambda_matrix, mNumberOfDofs); + AddVariationTimesVariation(current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_derivative_term, rodrigues_variation_matrix, lambda_variation_rodrigues_lambda_derivative_matrix, mNumberOfDofs); + AddSecondVariationTimesMatrix(current_rodrigues_derivative_second_variation_lambda_reference_rodrigues_lambda_term, rodrigues_derivative_second_variation_matrix, current_lambda_reference_rodrigues_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(current_rodrigues_second_variation_lambda_derivative_reference_rodrigues_lambda_term, rodrigues_second_variation_matrix, current_lambda_derivative_reference_rodrigues_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(current_rodrigues_second_variation_lambda_reference_rodrigues_derivative_lambda_term, rodrigues_second_variation_matrix, current_lambda_reference_rodrigues_derivative_lambda_product, mNumberOfDofs); + AddSecondVariationTimesMatrix(current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_derivative_term, rodrigues_second_variation_matrix, current_lambda_reference_rodrigues_lambda_derivative_product, mNumberOfDofs); + AddMatrixTimesSecondVariation(current_rodrigues_lambda_second_variation_reference_rodrigues_lambda_term, current_rodrigues_matrix, lambda_second_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddVariationTimesVariation(current_rodrigues_variation_lambda_variation_reference_rodrigues_lambda_term, rodrigues_variation_matrix, lambda_variation_rodrigues_lambda_matrix, mNumberOfDofs); + AddSecondVariationTimesMatrix(current_rodrigues_second_variation_lambda_reference_rodrigues_lambda_term, rodrigues_second_variation_matrix, current_lambda_reference_rodrigues_lambda_product, mNumberOfDofs); Matrix cross_section_transformation_derivative_second_variation; cross_section_transformation_derivative_second_variation.resize(3 * mNumberOfDofs, 3 * mNumberOfDofs); @@ -1932,14 +1785,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( Vector3d binormal_vector; binormal_vector.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - normal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_normal(product_index); - binormal_vector(row_component) += cross_section_transformation(row_component, product_index) * reference_binormal(product_index); - } - } + noalias(normal_vector) += prod(cross_section_transformation, reference_normal); + noalias(binormal_vector) += prod(cross_section_transformation, reference_binormal); Vector normal_vector_variation; normal_vector_variation.resize(3 * mNumberOfDofs); @@ -1948,17 +1795,8 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( binormal_vector_variation.resize(3 * mNumberOfDofs); binormal_vector_variation.clear(); - for (size_t row_component = 0;row_component < 3;row_component++) - { - for (size_t dof_index = 0;dof_index < mNumberOfDofs;dof_index++) - { - for (int product_index = 0;product_index < 3;product_index++) - { - normal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_normal(product_index); - binormal_vector_variation(row_component * mNumberOfDofs + dof_index) += rodrigues_lambda_rodrigues_lambda_variation_matrix(row_component * mNumberOfDofs + dof_index, product_index) * reference_binormal(product_index); - } - } - } + noalias(normal_vector_variation) += prod(rodrigues_lambda_rodrigues_lambda_variation_matrix, reference_normal); + noalias(binormal_vector_variation) += prod(rodrigues_lambda_rodrigues_lambda_variation_matrix, reference_binormal); // 6. Second variation of T = R_t Lambda P, needed for the second variation of the axes a_alpha Matrix cross_section_transformation_second_variation; diff --git a/applications/IgaApplication/tests/modeler_tests/beam_curved_refinements.iga.json b/applications/IgaApplication/tests/modeler_tests/beam_curved_refinements.iga.json new file mode 100644 index 000000000000..af64259133f8 --- /dev/null +++ b/applications/IgaApplication/tests/modeler_tests/beam_curved_refinements.iga.json @@ -0,0 +1,13 @@ +{ + "refinements": [ + { + "brep_ids": [ 2 ], + "geometry_type": "NurbsCurve", + "model_part_name": "IgaModelPart", + "parameters": { + "increase_degree": 1, + "insert_nb_per_span": 2 + } + } + ] +} diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index f5103b504f8a..4cfbc7a5495b 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -407,6 +407,39 @@ def build_cantilever(n_cp=5, degree=4, dynamic=False): element.Initialize(model_part.ProcessInfo) return model, model_part, nodes + @staticmethod + def build_curved_beam(twisted): + """Quarter circle of radius 1 (degree 3, 3 knot spans), clamped at its start. If twisted, the cross section + rotates along the curve, so that the reference twist and its derivative are non-zero.""" + model = KM.Model() + model_part = create_model_part(model) + properties = create_properties(model_part, 1, (0.0, 0.0, 1.0)) + if twisted: + properties.SetValue(IGA.LOCAL_AXIS_ORIENTATION, np.array( + [[0.0, 0.0, 0.0, 1.0], [0.5, 1.0, 1.0, 1.0], [1.0, 0.0, 1.0, 1.0]], dtype=float)) + + nodes = KM.NodesVector() + for i, point in enumerate(((1.0, 0.0, 0.0), (1.0, 1.0, 0.0), (0.0, 1.0, 0.0)), 1): + nodes.append(model_part.CreateNewNode(i, *point)) + curve = KM.NurbsCurveGeometry3D(nodes, 2, KM.Vector([0.0, 0.0, 1.0, 1.0]), KM.Vector([1.0, np.sqrt(0.5), 1.0])) + curve.SetId(2) + model_part.AddGeometry(curve) + refine_curve(model, "modeler_tests/beam_curved_refinements.iga.json") + + curve = model_part.GetGeometry(2) + create_elements(model_part, curve, properties) + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) + + nodes = sorted(model_part.Nodes, key=lambda node: node.Id) + clamp(nodes, 1) + + model_part.SetBufferSize(1) + model_part.CloneTimeStep(1.0) + for element in model_part.Elements: + element.Initialize(model_part.ProcessInfo) + return model, model_part, nodes + @staticmethod def free_dofs(nodes): fixed = {4 * i + j for i, node in enumerate(nodes) for j, dof in enumerate(DOFS) if node.IsFixed(dof)} @@ -524,6 +557,39 @@ def test_tangent_matches_finite_differences(self): self.assertLess(np.abs(K - (K_mat + K_geo)).max() / scale, 1e-12, "the material and geometric parts do not add up to the tangent stiffness") + def assertTangentMatchesFiniteDifferences(self, model_part, nodes, u0): + K, _ = self.assemble(model_part, nodes, u0) + K_mat, _ = self.assemble(model_part, nodes, u0, build_level=1) + K_geo, _ = self.assemble(model_part, nodes, u0, build_level=2) + + h = 1e-7 + K_fd = np.zeros_like(K) + for j in range(K.shape[0]): + u_plus = u0.copy() + u_plus[j] += h + u_minus = u0.copy() + u_minus[j] -= h + _, R_plus = self.assemble(model_part, nodes, u_plus) + _, R_minus = self.assemble(model_part, nodes, u_minus) + K_fd[:, j] = -(R_plus - R_minus) / (2.0 * h) + + scale = np.abs(K).max() + self.assertLess(np.abs(K - K_fd).max() / scale, 1e-6, + "the tangent stiffness is not the derivative of the internal forces") + self.assertLess(np.abs(K - (K_mat + K_geo)).max() / scale, 1e-12, + "the material and geometric parts do not add up to the tangent stiffness") + self.assertGreater(np.abs(K_geo).max() / scale, 1e-4, "the geometric stiffness is not exercised") + + def test_tangent_matches_finite_differences_curved_twisted(self): + # Curved and twisted reference configuration at a deformed state: all terms of the formulation are non-zero + _, model_part, nodes = self.build_curved_beam(twisted=True) + rng = np.random.default_rng(42) + u0 = np.zeros(4 * len(nodes)) + for i in range(len(nodes)): + u0[4 * i:4 * i + 3] = 0.02 * rng.standard_normal(3) + u0[4 * i + 3] = 0.1 * rng.standard_normal() + self.assertTangentMatchesFiniteDifferences(model_part, nodes, u0) + def test_quadratic_newton_convergence(self): _, model_part, nodes = self.build_cantilever() f_ext = np.zeros(4 * len(nodes)) From 3f0cb5cd67ef9853b2c13345d5f4b5361ae8ca46 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Mon, 23 Nov 2026 10:19:16 +0100 Subject: [PATCH 29/32] [IGA] Write the beam variation products block-wise The helpers for products with variation containers looped over all dofs explicitly, with up to five nested loops. They now operate on n x n (or n x 3) blocks with uBLAS, so the only remaining loops run over the 3x3 block indices and read like the formulas, e.g. W_ij += A(i, k) * W_kj. Stiffness, residual and mass still match the original implementation to 4e-18 relative to their physical scale. Co-Authored-By: Claude Opus 5.5 --- .../non_linear_bernoulli_beam_element_3D.cpp | 77 ++++++++++--------- 1 file changed, 41 insertions(+), 36 deletions(-) diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index 8f0740fa41c6..fbaa79ce80c3 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -29,13 +29,27 @@ namespace /* * Products with the variation containers of a 3x3 matrix M with respect to the n element dofs: - * - first variation: (3 n) x 3 matrix with M,r(i, j) at (i * n + r, j) - * - second variation: (3 n) x (3 n) matrix with M,rs(i, j) at (i * n + r, j * n + s) - * A product of a first variation with a constant 3x3 matrix from the right is a plain prod(), the - * other products below are not, because of this layout. + * - first variation: (3 n) x 3 matrix. Its row block i, rows i * n ... (i + 1) * n, holds M,r(i, :) for all r. + * - second variation: (3 n) x (3 n) matrix of n x n blocks. Block (i, j) holds M,rs(i, j) for all r, s. + * A product of a first variation with a constant 3x3 matrix from the right is a plain prod(). The products + * below are not, because of this layout, and are written block-wise. */ -/// rResult += A * V,r for all dofs r, with V,r a first variation +/// Row block i of a first variation: the n x 3 matrix M,r(i, :) for all dofs r +template +auto RowBlock(TMatrixType& rVariation, const std::size_t i, const std::size_t NumberOfDofs) +{ + return subrange(rVariation, i * NumberOfDofs, (i + 1) * NumberOfDofs, 0, 3); +} + +/// Block (i, j) of a second variation: the n x n matrix M,rs(i, j) for all dofs r, s +template +auto Block(TMatrixType& rSecondVariation, const std::size_t i, const std::size_t j, const std::size_t NumberOfDofs) +{ + return subrange(rSecondVariation, i * NumberOfDofs, (i + 1) * NumberOfDofs, j * NumberOfDofs, (j + 1) * NumberOfDofs); +} + +/// rResult += A * V,r for all dofs r: row block i of the result is sum_k A(i, k) * (row block k of V) template void AddMatrixTimesVariation( Matrix& rResult, @@ -44,17 +58,14 @@ void AddMatrixTimesVariation( const std::size_t NumberOfDofs) { for (std::size_t i = 0; i < 3; ++i) { - for (std::size_t j = 0; j < 3; ++j) { - for (std::size_t k = 0; k < 3; ++k) { - for (std::size_t r = 0; r < NumberOfDofs; ++r) { - rResult(i * NumberOfDofs + r, j) += rMatrix(i, k) * rVariation(k * NumberOfDofs + r, j); - } - } + auto result_block = RowBlock(rResult, i, NumberOfDofs); + for (std::size_t k = 0; k < 3; ++k) { + noalias(result_block) += rMatrix(i, k) * RowBlock(rVariation, k, NumberOfDofs); } } } -/// rResult += W,rs * A for all dofs r, s, with W,rs a second variation +/// rResult += W,rs * A for all dofs r, s: block (i, j) of the result is sum_k W_ik * A(k, j) template void AddSecondVariationTimesMatrix( Matrix& rResult, @@ -64,19 +75,15 @@ void AddSecondVariationTimesMatrix( { for (std::size_t i = 0; i < 3; ++i) { for (std::size_t j = 0; j < 3; ++j) { + auto result_block = Block(rResult, i, j, NumberOfDofs); for (std::size_t k = 0; k < 3; ++k) { - for (std::size_t r = 0; r < NumberOfDofs; ++r) { - for (std::size_t s = 0; s < NumberOfDofs; ++s) { - rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += - rSecondVariation(i * NumberOfDofs + r, k * NumberOfDofs + s) * rMatrix(k, j); - } - } + noalias(result_block) += rMatrix(k, j) * Block(rSecondVariation, i, k, NumberOfDofs); } } } } -/// rResult += A * W,rs for all dofs r, s, with W,rs a second variation +/// rResult += A * W,rs for all dofs r, s: block (i, j) of the result is sum_k A(i, k) * W_kj template void AddMatrixTimesSecondVariation( Matrix& rResult, @@ -86,35 +93,33 @@ void AddMatrixTimesSecondVariation( { for (std::size_t i = 0; i < 3; ++i) { for (std::size_t j = 0; j < 3; ++j) { + auto result_block = Block(rResult, i, j, NumberOfDofs); for (std::size_t k = 0; k < 3; ++k) { - for (std::size_t r = 0; r < NumberOfDofs; ++r) { - for (std::size_t s = 0; s < NumberOfDofs; ++s) { - rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += - rMatrix(i, k) * rSecondVariation(k * NumberOfDofs + r, j * NumberOfDofs + s); - } - } + noalias(result_block) += rMatrix(i, k) * Block(rSecondVariation, k, j, NumberOfDofs); } } } } -/// rResult += V,r * W,s for all dofs r, s: the mixed second variation of the product of two matrices V and W +/** + * rResult += V,r * W,s for all dofs r, s: the mixed second variation of the product of two matrices V and W. + * Block (i, j) of the result is sum_k V,r(i, k) W,s(k, j) = A_i * B_j^T, with A_i the row block i of V and + * B_j the n x 3 matrix with B_j(s, k) = W,s(k, j). + */ void AddVariationTimesVariation( Matrix& rResult, const Matrix& rFirstVariation, const Matrix& rSecondVariation, const std::size_t NumberOfDofs) { - for (std::size_t i = 0; i < 3; ++i) { - for (std::size_t j = 0; j < 3; ++j) { - for (std::size_t k = 0; k < 3; ++k) { - for (std::size_t r = 0; r < NumberOfDofs; ++r) { - for (std::size_t s = 0; s < NumberOfDofs; ++s) { - rResult(i * NumberOfDofs + r, j * NumberOfDofs + s) += - rFirstVariation(i * NumberOfDofs + r, k) * rSecondVariation(k * NumberOfDofs + s, j); - } - } - } + Matrix second_factor(NumberOfDofs, 3); + for (std::size_t j = 0; j < 3; ++j) { + for (std::size_t k = 0; k < 3; ++k) { + noalias(column(second_factor, k)) = subrange(column(rSecondVariation, j), k * NumberOfDofs, (k + 1) * NumberOfDofs); + } + for (std::size_t i = 0; i < 3; ++i) { + auto result_block = Block(rResult, i, j, NumberOfDofs); + noalias(result_block) += prod(RowBlock(rFirstVariation, i, NumberOfDofs), trans(second_factor)); } } } From f4af69d3d0a83155f4de6b6accde27738b3ba086 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 26 Nov 2026 13:56:04 +0100 Subject: [PATCH 30/32] Move VTK HDF attribute changes to a separate PR Co-Authored-By: Claude Opus 5.5 --- .../python_scripts/iga_vtk_output_process.py | 18 ++---------------- 1 file changed, 2 insertions(+), 16 deletions(-) diff --git a/applications/IgaApplication/python_scripts/iga_vtk_output_process.py b/applications/IgaApplication/python_scripts/iga_vtk_output_process.py index 4d9299bc5904..0a9f13c4a602 100644 --- a/applications/IgaApplication/python_scripts/iga_vtk_output_process.py +++ b/applications/IgaApplication/python_scripts/iga_vtk_output_process.py @@ -115,22 +115,8 @@ def PrintOutput(self): # Create or retrieve root group if "VTKHDF" not in file: root = file.create_group("VTKHDF") - - root.attrs["Version"] = np.array( - VERSION, - dtype=np.int64 - ) - - ascii_type = h5.string_dtype( - encoding="ascii", - length=len(GLOBAL_TYPE) - ) - - root.attrs.create( - "Type", - GLOBAL_TYPE.encode("ascii"), - dtype=ascii_type - ) + root.attrs["Version"] = VERSION + root.attrs["Type"] = GLOBAL_TYPE else: root = file["VTKHDF"] From 9e1d3b713dfe6825e3e99fb5a57075b81e7086bc Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 26 Nov 2026 13:56:58 +0100 Subject: [PATCH 31/32] clarifications in the tests --- ..._isogeometric_non_linear_bernoulli_beam_element.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py index 4cfbc7a5495b..348457b520b3 100644 --- a/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -605,8 +605,15 @@ def test_quadratic_newton_convergence(self): def test_large_deflection_elastica(self): # Cantilever with a tip load perpendicular to the undeformed axis, P L^2 / EI = 0.5. - # Reference: inextensible elastica (shooting method). The linear solution would be uy = -0.6667, ux = 0. - # The cantilever is stocky, so the axial stiffness is increased to match the inextensibility of the reference. + # Reference: inextensible elastica EI theta'' + P cos(theta) = 0, theta(0) = 0, theta'(L) = 0, solved in closed + # form with elliptic integrals (Bisshopp & Drucker 1945, Q. Appl. Math. 3; Mattiasson 1981, IJNME 17). + # With alpha = P L^2 / EI, k = sqrt((1 + sin(theta_0)) / 2) and sin(phi_1) = 1 / (k sqrt(2)): + # sqrt(alpha) = K(k) - F(phi_1, k) -> tip rotation theta_0 = 0.24453 + # ux / L = sqrt(2 sin(theta_0) / alpha) - 1 -> ux = -0.0636758499 + # uy / L = -(1 - 2 / sqrt(alpha) * (E(k) - E(phi_1, k))) -> uy = -0.6485743026 + # K, F and E are the complete/incomplete elliptic integrals of the first and second kind. + # The linear solution would be uy = -0.6667, ux = 0. + # The cantilever is thick, so the axial stiffness is increased to match the inextensibility of the reference. ux_exact, uy_exact = -0.0636758499, -0.6485743026 load = 0.5 * E_MOD * I22_ / LENGTH ** 2 From a32b4ce25a67896d5bdbc2b62ae460707d2a2bf2 Mon Sep 17 00:00:00 2001 From: Juan Ignacio Camarotti Date: Thu, 26 Nov 2026 14:09:39 +0100 Subject: [PATCH 32/32] change beam base element name --- ...cpp => bernoulli_beam_base_element_3D.cpp} | 62 +++++++++---------- ..._3D.h => bernoulli_beam_base_element_3D.h} | 27 ++++---- .../non_linear_bernoulli_beam_element_3D.cpp | 2 +- .../non_linear_bernoulli_beam_element_3D.h | 16 ++--- .../compute_beam_vectors_process.cpp | 2 +- applications/IgaApplication/iga_application.h | 2 +- 6 files changed, 58 insertions(+), 53 deletions(-) rename applications/IgaApplication/custom_elements/{beam_base_element_3D.cpp => bernoulli_beam_base_element_3D.cpp} (98%) rename applications/IgaApplication/custom_elements/{beam_base_element_3D.h => bernoulli_beam_base_element_3D.h} (94%) diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp similarity index 98% rename from applications/IgaApplication/custom_elements/beam_base_element_3D.cpp rename to applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp index 56ebb13fa8cf..833b75c5d670 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp @@ -21,12 +21,12 @@ #include "utilities/math_utils.h" // Application includes -#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/bernoulli_beam_base_element_3D.h" namespace Kratos { - void BeamBaseElement3D::EquationIdVector( + void BernoulliBeamBaseElement3D::EquationIdVector( EquationIdVectorType& rResult, const ProcessInfo& rCurrentProcessInfo) const { @@ -70,7 +70,7 @@ namespace Kratos } - void BeamBaseElement3D::GetDofList( + void BernoulliBeamBaseElement3D::GetDofList( DofsVectorType& rElementalDofList, const ProcessInfo& rCurrentProcessInfo) const { @@ -100,7 +100,7 @@ namespace Kratos } - void BeamBaseElement3D::InitializeMaterial() + void BernoulliBeamBaseElement3D::InitializeMaterial() { KRATOS_TRY @@ -134,7 +134,7 @@ namespace Kratos } - void BeamBaseElement3D::GetValuesVector( + void BernoulliBeamBaseElement3D::GetValuesVector( Vector& rValues, const int Step) const { @@ -165,7 +165,7 @@ namespace Kratos } } - void BeamBaseElement3D::CalculateDampingMatrix( + void BernoulliBeamBaseElement3D::CalculateDampingMatrix( MatrixType& rDampingMatrix, const ProcessInfo& rCurrentProcessInfo) { @@ -208,7 +208,7 @@ namespace Kratos KRATOS_CATCH("") } - int BeamBaseElement3D::Check( + int BernoulliBeamBaseElement3D::Check( const ProcessInfo& rCurrentProcessInfo) const { KRATOS_TRY @@ -286,7 +286,7 @@ namespace Kratos // Beam kinematics // --------------------------------------------------------------------- - void BeamBaseElement3D::ComputeTangentVariation( + void BernoulliBeamBaseElement3D::ComputeTangentVariation( const Vector& rShapeFunctionDerivatives, const array_1d& rFirstBaseVector, Vector& rTangentVariation) const @@ -371,7 +371,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeTangentSecondVariation( + void BernoulliBeamBaseElement3D::ComputeTangentSecondVariation( const Vector& rShapeFunctionDerivatives, const array_1d& rFirstBaseVector, Matrix& rTangentSecondVariation) const @@ -550,7 +550,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeTangentDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeTangentDerivativeVariation( const Vector& rShapeFunctionDerivatives, const Vector& rShapeFunctionSecondDerivatives, const array_1d& rFirstBaseVector, @@ -689,7 +689,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeTangentDerivativeSecondVariation( + void BernoulliBeamBaseElement3D::ComputeTangentDerivativeSecondVariation( const Vector& rShapeFunctionDerivatives, const Vector& rShapeFunctionSecondDerivatives, const array_1d& rFirstBaseVector, @@ -1000,7 +1000,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeTangentSecondDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeTangentSecondDerivativeVariation( const Vector& rShapeFunctionDerivatives, const Vector& rShapeFunctionSecondDerivatives, const Vector& rShapeFunctionThirdDerivatives, @@ -1234,7 +1234,7 @@ namespace Kratos // Beam rotation helpers // --------------------------------------------------------------------- // These helpers are local to this translation unit and are not part of - // the BeamBaseElement3D interface. + // the BernoulliBeamBaseElement3D interface. namespace { @@ -1286,7 +1286,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeRodriguesMatrix(const array_1d& rAxis, + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrix(const array_1d& rAxis, const double Phi, Matrix3d& rRodriguesMatrix) { rRodriguesMatrix.clear(); @@ -1310,7 +1310,7 @@ namespace Kratos std::sin(Phi); } - void BeamBaseElement3D::ComputeRodriguesMatrixDerivative( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixDerivative( const array_1d& rAxis, const array_1d& rAxisDerivative, const double Phi, @@ -1346,7 +1346,7 @@ namespace Kratos std::sin(Phi); } - void BeamBaseElement3D::ComputeRodriguesMatrixVariation( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixVariation( const array_1d& rAxis, const Vector& rAxisVariation, const Vector& rShapeFunctions, @@ -1411,7 +1411,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeRodriguesMatrixSecondVariation( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixSecondVariation( const array_1d& rAxis, const Vector& rAxisVariation, const Matrix& rAxisSecondVariation, @@ -1526,7 +1526,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeRodriguesMatrixDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixDerivativeVariation( const array_1d& rAxis, const Vector& rAxisVariation, const array_1d& rAxisDerivative, @@ -1643,7 +1643,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeRodriguesMatrixDerivativeSecondVariation( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixDerivativeSecondVariation( const array_1d& rAxis, const Vector& rAxisVariation, const array_1d& rAxisDerivative, @@ -1742,7 +1742,7 @@ namespace Kratos } } - void BeamBaseElement3D::ComputeRodriguesMatrixSecondDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixSecondDerivativeVariation( const array_1d& rAxis, const Vector& rAxisVariation, const array_1d& rAxisDerivative, @@ -1814,7 +1814,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeRodriguesMatrixVariations( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixVariations( const array_1d& rAxis, const array_1d& rAxisVariation, const array_1d& rAxisDerivative, @@ -1951,7 +1951,7 @@ namespace Kratos - void BeamBaseElement3D::ComputeRodriguesMatrixSecondDerivative( + void BernoulliBeamBaseElement3D::ComputeRodriguesMatrixSecondDerivative( const array_1d& rAxis, const array_1d& rAxisDerivative, const array_1d& rAxisSecondDerivative, @@ -1972,7 +1972,7 @@ namespace Kratos rRodriguesMatrixSecondDerivative += CrossProductVectorMatrix(rAxisSecondDerivative, identity_matrix) * std::sin(Phi); } - void BeamBaseElement3D::ComputeLambdaMatrix(const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, Matrix3d& rLambdaMatrix) + void BernoulliBeamBaseElement3D::ComputeLambdaMatrix(const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, Matrix3d& rLambdaMatrix) { rLambdaMatrix.clear(); Matrix3d lambda_matrix_auxiliary; @@ -2015,7 +2015,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeLambdaMatrixDerivative( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixDerivative( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, @@ -2049,7 +2049,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeLambdaMatrixSecondDerivative( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixSecondDerivative( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, @@ -2099,7 +2099,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeLambdaMatrixVariation( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixVariation( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const Vector& rCurrentTangentVariation, @@ -2210,7 +2210,7 @@ namespace Kratos } } - void BeamBaseElement3D::ComputeLambdaMatrixSecondVariation( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixSecondVariation( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const Vector& rCurrentTangentVariation, @@ -2371,7 +2371,7 @@ namespace Kratos } } - void BeamBaseElement3D::ComputeLambdaMatrixDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixDerivativeVariation( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, @@ -2530,7 +2530,7 @@ namespace Kratos } - void BeamBaseElement3D::ComputeLambdaMatrixSecondDerivativeVariation( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixSecondDerivativeVariation( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, @@ -2768,7 +2768,7 @@ namespace Kratos } -void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( +void BernoulliBeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, @@ -3021,7 +3021,7 @@ void BeamBaseElement3D::ComputeLambdaMatrixDerivativeSecondVariation( } } - void BeamBaseElement3D::ComputeLambdaMatrixVariations( + void BernoulliBeamBaseElement3D::ComputeLambdaMatrixVariations( const array_1d& rReferenceTangent, const array_1d& rCurrentTangent, const array_1d& rReferenceTangentDerivative, diff --git a/applications/IgaApplication/custom_elements/beam_base_element_3D.h b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h similarity index 94% rename from applications/IgaApplication/custom_elements/beam_base_element_3D.h rename to applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h index f66e6be646e8..c6b212a1c04d 100644 --- a/applications/IgaApplication/custom_elements/beam_base_element_3D.h +++ b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h @@ -30,14 +30,19 @@ namespace Kratos { /** - * @class BeamBaseElement3D - * @brief Base class for three-dimensional IGA beam elements. + * @class BernoulliBeamBaseElement3D + * @brief Base class for three-dimensional IGA Bernoulli beam elements. * - * This class provides functionality shared by three-dimensional beam - * formulations, including degree-of-freedom handling, constitutive-law + * This class provides functionality shared by three-dimensional Bernoulli + * beam formulations, including degree-of-freedom handling, constitutive-law * initialization, beam kinematics, and rotation-related operations. + * + * The kinematics are rotation-free: the cross-section orientation follows from + * the tangent of the displaced centreline plus a twist angle, giving 4 DOFs per + * node (DISPLACEMENT_X/Y/Z and ROTATION_X). Formulations with independent + * rotations, such as Timoshenko beams, are not covered and need their own base. */ -class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D +class KRATOS_API(IGA_APPLICATION) BernoulliBeamBaseElement3D : public Element { public: @@ -53,20 +58,20 @@ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D using IndexType = typename BaseType::IndexType; using Matrix3d = BoundedMatrix; - KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BeamBaseElement3D); + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BernoulliBeamBaseElement3D); ///@} ///@name Life Cycle ///@{ - BeamBaseElement3D( + BernoulliBeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry) : Element(NewId, pGeometry) { } - BeamBaseElement3D( + BernoulliBeamBaseElement3D( IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) @@ -74,12 +79,12 @@ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D { } - BeamBaseElement3D() + BernoulliBeamBaseElement3D() : Element() { } - ~BeamBaseElement3D() override = default; + ~BernoulliBeamBaseElement3D() override = default; ///@} ///@name Element Creation @@ -481,6 +486,6 @@ class KRATOS_API(IGA_APPLICATION) BeamBaseElement3D ///@} -}; // Class BeamBaseElement3D +}; // Class BernoulliBeamBaseElement3D } // namespace Kratos diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp index fbaa79ce80c3..c255d1ea962b 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -603,7 +603,7 @@ void NonLinearBernoulliBeamElement3D::CalculateAll( { KRATOS_TRY - BeamBaseElement3D::Check(rCurrentProcessInfo); + BernoulliBeamBaseElement3D::Check(rCurrentProcessInfo); const double numerical_limit = std::numeric_limits::epsilon(); diff --git a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h index 13dbfd16c8f0..4819a7de17b2 100644 --- a/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -24,7 +24,7 @@ // Application includes #include "iga_application_variables.h" -#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/bernoulli_beam_base_element_3D.h" namespace Kratos { @@ -53,7 +53,7 @@ namespace Kratos * Equation numbers in the comments of this element refer to this paper. */ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D - : public BeamBaseElement3D + : public BernoulliBeamBaseElement3D { protected: @@ -157,7 +157,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION( NonLinearBernoulliBeamElement3D); - using BaseType = BeamBaseElement3D; + using BaseType = BernoulliBeamBaseElement3D; using SizeType = typename BaseType::SizeType; using IndexType = typename BaseType::IndexType; using GeometryType = typename BaseType::GeometryType; @@ -169,7 +169,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D NonLinearBernoulliBeamElement3D( IndexType NewId, GeometryType::Pointer pGeometry) - : BeamBaseElement3D( + : BernoulliBeamBaseElement3D( NewId, pGeometry) { @@ -179,7 +179,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D IndexType NewId, GeometryType::Pointer pGeometry, PropertiesType::Pointer pProperties) - : BeamBaseElement3D( + : BernoulliBeamBaseElement3D( NewId, pGeometry, pProperties) @@ -187,7 +187,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D } NonLinearBernoulliBeamElement3D() - : BeamBaseElement3D() + : BernoulliBeamBaseElement3D() { } @@ -428,7 +428,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D { KRATOS_SERIALIZE_SAVE_BASE_CLASS( rSerializer, - BeamBaseElement3D); + BernoulliBeamBaseElement3D); } void load( @@ -436,7 +436,7 @@ class KRATOS_API(IGA_APPLICATION) NonLinearBernoulliBeamElement3D { KRATOS_SERIALIZE_LOAD_BASE_CLASS( rSerializer, - BeamBaseElement3D); + BernoulliBeamBaseElement3D); } }; diff --git a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp index cb690858ea5e..01f3a5fae702 100644 --- a/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -22,7 +22,7 @@ #include "includes/define.h" #include "iga_application_variables.h" #include "custom_elements/non_linear_bernoulli_beam_element_3D.h" -#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/bernoulli_beam_base_element_3D.h" namespace Kratos { diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index bfc7b51298ad..e74a71e6426f 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -19,7 +19,7 @@ //elements #include "custom_elements/truss_element.h" #include "custom_elements/truss_embedded_edge_element.h" -#include "custom_elements/beam_base_element_3D.h" +#include "custom_elements/bernoulli_beam_base_element_3D.h" #include "custom_elements/non_linear_bernoulli_beam_element_3D.h" #include "custom_elements/beam_thin_element_2D.h" #include "custom_elements/beam_thick_element_2D.h"