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_constitutive/bernoulli_beam_elastic_constitutive_law.cpp b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp new file mode 100644 index 000000000000..68a4f111a12c --- /dev/null +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.cpp @@ -0,0 +1,172 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +// System includes +#include + +// External includes + +// Project includes +#include "bernoulli_beam_elastic_constitutive_law.h" +#include "iga_application_variables.h" + +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() +{ +} + +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(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; + + // 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(rMaterialProperties.Has(I_T) && 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]; + // 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 = GetTorsionalInertia(r_material_properties); + + 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_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) + 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_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 + } +} + +} // 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 new file mode 100644 index 000000000000..37e01ecd5e6b --- /dev/null +++ b/applications/IgaApplication/custom_constitutive/bernoulli_beam_elastic_constitutive_law.h @@ -0,0 +1,161 @@ +// 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 + +// 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. diff --git a/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp new file mode 100644 index 000000000000..833b75c5d670 --- /dev/null +++ b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.cpp @@ -0,0 +1,3323 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// 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/bernoulli_beam_base_element_3D.h" + +namespace Kratos +{ + + void BernoulliBeamBaseElement3D::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 BernoulliBeamBaseElement3D::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 BernoulliBeamBaseElement3D::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 BernoulliBeamBaseElement3D::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; + } + } + + void BernoulliBeamBaseElement3D::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 BernoulliBeamBaseElement3D::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)) { + KRATOS_ERROR + << "missing variable DISPLACEMENT on node " + << r_geometry[i].Id() << std::endl; + } + + 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) || + !r_geometry[i].HasDofFor(DISPLACEMENT_Y) || + !r_geometry[i].HasDofFor(DISPLACEMENT_Z)) + { + 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)) { + 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 BernoulliBeamBaseElement3D::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 = + std::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 BernoulliBeamBaseElement3D::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 = + std::pow(first_base_vector_norm, 3); + + const double first_base_vector_norm_fifth = + std::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 BernoulliBeamBaseElement3D::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] / + std::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] / + std::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] + ) / + std::pow(first_base_vector_norm, 3); + } + } + } + + + void BernoulliBeamBaseElement3D::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 = + std::pow(first_base_vector_norm, 3); + + const double first_base_vector_norm_fifth = + std::pow(first_base_vector_norm, 5); + + const double first_base_vector_norm_seventh = + std::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 % mDofsPerNode; + + const size_t second_dof_component = + second_dof_index % mDofsPerNode; + + 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 BernoulliBeamBaseElement3D::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] / + std::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] + ) / + std::pow(first_base_vector_norm, 3) + + + 3.0 * + rSecondBaseVector[component] * + first_second_base_vector_product * + first_base_vector_dot_first_variation[dof_index] / + std::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] + ) / + std::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] / + std::pow(first_base_vector_norm, 5); + + rTangentSecondDerivativeVariation[ + component * mNumberOfDofs + dof_index] += + 3.0 * + ( + first_base_vector_variation[ + component * mNumberOfDofs + dof_index] * + std::pow(first_second_base_vector_product, 2) + + + rFirstBaseVector[component] * + 2.0 * + first_second_base_vector_product * + first_second_product_variation[dof_index] + ) / + std::pow(first_base_vector_norm, 5) + - + 15.0 * + rFirstBaseVector[component] * + std::pow(first_second_base_vector_product, 2) * + first_base_vector_dot_first_variation[dof_index] / + std::pow(first_base_vector_norm, 7); + } + } + } + // --------------------------------------------------------------------- + // Beam rotation helpers + // --------------------------------------------------------------------- + // These helpers are local to this translation unit and are not part of + // the BernoulliBeamBaseElement3D 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 BernoulliBeamBaseElement3D::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) = std::cos(Phi); + } + + rRodriguesMatrix += + CrossProductVectorMatrix( + rAxis, + identity_matrix) * + std::sin(Phi); + } + + void BernoulliBeamBaseElement3D::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 * std::sin(Phi); + } + + rRodriguesMatrixDerivative += + CrossProductVectorMatrix( + rAxis, + identity_matrix) * + std::cos(Phi) * + PhiDerivative; + + rRodriguesMatrixDerivative += + CrossProductVectorMatrix( + rAxisDerivative, + identity_matrix) * + std::sin(Phi); + } + + void BernoulliBeamBaseElement3D::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) += + -std::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) += + std::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) += + std::sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + dof_index]; + } + } + } + } + } + + + void BernoulliBeamBaseElement3D::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) += + -std::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) += + -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] * + std::cos(Phi) * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + + second_dof_index] + + + phi_variation[second_dof_index] * + std::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) += + std::sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisSecondVariation( + k * NumberOfDofs + dof_index, + second_dof_index); + } + } + } + } + } + } + } + + + void BernoulliBeamBaseElement3D::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) * + std::sin(Phi) + - + std::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) * + std::cos(Phi) + - + PhiDerivative * + rShapeFunctions[control_point_index] * + std::sin(Phi) + ) * + levi_civita[row_component][k][column_component] * + rAxis[k] + + + std::cos(Phi) * + phi_variation(dof_index) * + levi_civita[row_component][k][column_component] * + rAxisDerivative[k]; + } else { + rRodriguesMatrixDerivativeVariation( + row_component * NumberOfDofs + dof_index, + column_component) += + std::cos(Phi) * + PhiDerivative * + levi_civita[row_component][k][column_component] * + rAxisVariation[ + k * NumberOfDofs + dof_index] + + + std::sin(Phi) * + levi_civita[row_component][k][column_component] * + rAxisDerivativeVariation[ + k * NumberOfDofs + dof_index]; + } + } + } + } + } + } + + + void BernoulliBeamBaseElement3D::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 = std::cos(Phi); + double sin_phi; + sin_phi = std::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 BernoulliBeamBaseElement3D::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] * 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; + } + + { + for (int k = 0; k < 3; k++) + { + if (xyz > 2) + 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) += (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]; + } + } + } + } + } + + } + + void BernoulliBeamBaseElement3D::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 = std::cos(Phi); + double sin_phi; + sin_phi = std::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) += -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) += 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) += 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++) + { + size_t xyz_s = s % DofsPerNode; + + if (t == u) + { + 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]; + } + + { + for (int k = 0; k < 3; k++) + { + if (xyz_r > 2 || xyz_s > 2) + 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) += 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] + + 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 BernoulliBeamBaseElement3D::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 * 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 BernoulliBeamBaseElement3D::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 BernoulliBeamBaseElement3D::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) / 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; + rLambdaMatrixDerivative += outer_prod(reference_cross_current, tangent_cross_product_derivative) * scaling_factor; + + } + + + void BernoulliBeamBaseElement3D::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 * 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 / 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); + 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 BernoulliBeamBaseElement3D::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] / 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]); + } + } + } + } + + void BernoulliBeamBaseElement3D::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) / 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)); + } + } + } + } + } + } + + void BernoulliBeamBaseElement3D::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) / 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])); + } + + } + } + } + + } + + + void BernoulliBeamBaseElement3D::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 / 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++) + { + 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 * (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]); + 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 BernoulliBeamBaseElement3D::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)) / 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) / 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))); + } + } + } + } + } + } + + void BernoulliBeamBaseElement3D::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] / 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) / 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])); + } + } + } + } + + 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) / 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)) / 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) / 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))); + + } + } + } + } + } + + } + + + +} // namespace Kratos diff --git a/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h new file mode 100644 index 000000000000..c6b212a1c04d --- /dev/null +++ b/applications/IgaApplication/custom_elements/bernoulli_beam_base_element_3D.h @@ -0,0 +1,491 @@ +// 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 + +// External includes + +// 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 +{ + +/** + * @class BernoulliBeamBaseElement3D + * @brief Base class for three-dimensional IGA Bernoulli beam elements. + * + * 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) BernoulliBeamBaseElement3D + : public Element +{ +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; + + KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(BernoulliBeamBaseElement3D); + + ///@} + ///@name Life Cycle + ///@{ + + BernoulliBeamBaseElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry) + : Element(NewId, pGeometry) + { + } + + BernoulliBeamBaseElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) + : Element(NewId, pGeometry, pProperties) + { + } + + BernoulliBeamBaseElement3D() + : Element() + { + } + + ~BernoulliBeamBaseElement3D() override = default; + + ///@} + ///@name Element Creation + ///@{ + + Element::Pointer Create( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) const override = 0; + + Element::Pointer Create( + IndexType NewId, + const NodesArrayType& rThisNodes, + PropertiesType::Pointer pProperties) const override = 0; + + ///@} + ///@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 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 + ///@{ + + void InitializeMaterial(); + + ///@} + ///@name Element Calculations + ///@{ + + void CalculateLocalSystem( + MatrixType& rLeftHandSideMatrix, + VectorType& rRightHandSideVector, + const ProcessInfo& rCurrentProcessInfo) override = 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 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; + + /** + * @brief Computes the first variation of the beam tangent. + */ + void ComputeTangentVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Vector& rTangentVariation) const; + + /** + * @brief Computes the second variation of the beam tangent. + */ + void ComputeTangentSecondVariation( + const Vector& rShapeFunctionDerivatives, + const array_1d& rFirstBaseVector, + Matrix& rTangentSecondVariation) const; + + /** + * @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; + + /** + * @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; + + /** + * @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; + + /** + * @brief Computes the Rodrigues rotation matrix. + */ + static void ComputeRodriguesMatrix( + const array_1d& rAxis, + const double Phi, + Matrix3d& rRodriguesMatrix); + + /** + * @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); + + /** + * @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; + + ///@} + +private: + + ///@name Serialization + ///@{ + + friend class Serializer; + + 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 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 new file mode 100644 index 000000000000..c255d1ea962b --- /dev/null +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.cpp @@ -0,0 +1,1931 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +// 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 +{ + +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. 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. + */ + +/// 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, + const TMatrixType& rMatrix, + const Matrix& rVariation, + const std::size_t NumberOfDofs) +{ + for (std::size_t i = 0; i < 3; ++i) { + 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: block (i, j) of the result is sum_k W_ik * A(k, j) +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) { + auto result_block = Block(rResult, i, j, NumberOfDofs); + for (std::size_t k = 0; k < 3; ++k) { + noalias(result_block) += rMatrix(k, j) * Block(rSecondVariation, i, k, NumberOfDofs); + } + } + } +} + +/// 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, + 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) { + auto result_block = Block(rResult, i, j, NumberOfDofs); + for (std::size_t k = 0; k < 3; ++k) { + 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. + * 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) +{ + 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)); + } + } +} + +} // namespace + + void NonLinearBernoulliBeamElement3D::Initialize(const ProcessInfo& rCurrentProcessInfo) + { + KRATOS_TRY + InitializeMaterial(); + + + mDofsPerNode = 4; + mNumberOfDofs = this->GetGeometry().size() * mDofsPerNode; + KRATOS_CATCH("") + + } + + 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( + 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 = std::sqrt( + inner_prod( + rKinematicVariables.R2, + rKinematicVariables.R2) + - std::pow( + reference_base_vector_product / + rKinematicVariables.A, + 2)); + + rKinematicVariables.b = std::sqrt( + inner_prod( + rKinematicVariables.r2, + rKinematicVariables.r2) + - std::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(); + + 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; + + // 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; + 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); + + // 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) { + if (calculate_material_stiffness) { + // 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))); + } + + 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 * + 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) { + // 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; + } + } + } + } + } + + KRATOS_CATCH("") +} + + + int NonLinearBernoulliBeamElement3D::Check( + const ProcessInfo& rCurrentProcessInfo) const + { + KRATOS_TRY + + BernoulliBeamBaseElement3D::Check(rCurrentProcessInfo); + + 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()[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(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(I33) || + GetProperties()[I33] <= numerical_limit) + << "Please provide a reasonable value for \"I33\" " + << "(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; + + // 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; + + KRATOS_ERROR_IF(!Has(N_0) && !GetProperties().Has(N_0)) + << "\"N_0\" not provided for element #" << Id() + << ". Run the ComputeBeamVectorsProcess first." << std::endl; + + const Vector3d initial_tangent = Has(T_0) + ? GetValue(T_0) + : GetProperties()[T_0]; + + 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; + + 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); + } + + + 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 reference_tangent = + rKinematicVariables.R1 / norm_2(rKinematicVariables.R1); + + // 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( + GetInitialTangent(), + reference_tangent, + lambda_matrix); + + const Vector3d untwisted_axis = + prod(lambda_matrix, rKinematicVariables.N0); + + // 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); + + double phi = std::atan2(sin_phi, cos_phi); + + if (phi < 0.0) { + phi += 2.0 * Globals::Pi; + } + + return phi; + } + + NonLinearBernoulliBeamElement3D::Vector3d NonLinearBernoulliBeamElement3D::GetInitialTangent() const + { + const Vector3d initial_tangent = Has(T_0) + ? GetValue(T_0) + : GetProperties()[T_0]; + + return initial_tangent / norm_2(initial_tangent); + } + + 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 = 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, + 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) + / std::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(); + + Vector3d transformed_reference_normal; + transformed_reference_normal.clear(); + + noalias(transformed_reference_normal) += prod(reference_lambda_matrix, rKinematicVariables.N0); + + noalias(rKinematicVariables.n) += prod(reference_rodrigues_matrix, transformed_reference_normal); + + rKinematicVariables.n /= + norm_2(rKinematicVariables.n); + + rKinematicVariables.v = + MathUtils::CrossProduct(reference_tangent, rKinematicVariables.n); + + 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(); + + 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); + + 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 = GetInitialTangent(); + + 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) + / std::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) + / std::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(); + + 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; + 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(); + + 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; + 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(); + + 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 + + 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(); + + 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); + + 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 + + // 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 + 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 = GetInitialTangent(); + + // 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) / 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) / 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, 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, 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); + + 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(); + + 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; + 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(); + + 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; + + 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(); + + 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(); + 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; + + 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(); + + 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); + current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); + + 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; + + 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(); + + 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(); + + 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(); + Vector3d binormal_vector; + binormal_vector.clear(); + + 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); + normal_vector_variation.clear(); + Vector binormal_vector_variation; + binormal_vector_variation.resize(3 * mNumberOfDofs); + binormal_vector_variation.clear(); + + 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); + 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) += 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); + } + } + } + + + // 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("") + } + + + /** + * 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, + Matrix& rGAxial, + Matrix& rGBending1, + Matrix& rGBending2, + Matrix& rGTorsion1, + Matrix& rGTorsion2) + { + 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 + 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 = GetInitialTangent(); + + // 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) / 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) / 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, 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, 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; + 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(); + + 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; + 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(); + + 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; + + 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(); + + 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(); + 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; + + + 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(); + + 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); + current_lambda_reference_rodrigues_lambda_product_derivative_variation.clear(); + + 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; + + 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(); + + 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(); + 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; + + 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(); + + 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) + 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(); + + 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); + cross_section_transformation_derivative_second_variation.clear(); + + Vector3d normal_vector; + normal_vector.clear(); + Vector3d binormal_vector; + binormal_vector.clear(); + + 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); + normal_vector_variation.clear(); + Vector binormal_vector_variation; + binormal_vector_variation.resize(3 * mNumberOfDofs); + binormal_vector_variation.clear(); + + 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; + 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); + } + } + } + } + + // 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++) + { + 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++) + { + 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) + + 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) + + 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) + + 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) + + 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); + } + } + } + } + + // 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(rGTorsion2) = binormal_torsion_second_variation; + + KRATOS_CATCH("") + + } +} 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..4819a7de17b2 --- /dev/null +++ b/applications/IgaApplication/custom_elements/non_linear_bernoulli_beam_element_3D.h @@ -0,0 +1,445 @@ +// 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/bernoulli_beam_base_element_3D.h" + +namespace Kratos +{ + +///@name Kratos Classes +///@{ + +/** + * @class NonLinearBernoulliBeamElement3D + * @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 BernoulliBeamBaseElement3D +{ +protected: + + using Vector3d = array_1d; + using Matrix3d = BoundedMatrix; + + 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 = BernoulliBeamBaseElement3D; + using SizeType = typename BaseType::SizeType; + using IndexType = typename BaseType::IndexType; + using GeometryType = typename BaseType::GeometryType; + + ///@} + ///@name Life Cycle + ///@{ + + NonLinearBernoulliBeamElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry) + : BernoulliBeamBaseElement3D( + NewId, + pGeometry) + { + } + + NonLinearBernoulliBeamElement3D( + IndexType NewId, + GeometryType::Pointer pGeometry, + PropertiesType::Pointer pProperties) + : BernoulliBeamBaseElement3D( + NewId, + pGeometry, + pProperties) + { + } + + NonLinearBernoulliBeamElement3D() + : BernoulliBeamBaseElement3D() + { + } + + ~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; + + /// 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); + + 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); + + ///@} + ///@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); + + /// 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); + + void ComputeCurrentCrossSectionGeometry( + KinematicVariables& rKinematicVariables); + + friend class Serializer; + + void save( + Serializer& rSerializer) const override + { + KRATOS_SERIALIZE_SAVE_BASE_CLASS( + rSerializer, + BernoulliBeamBaseElement3D); + } + + void load( + Serializer& rSerializer) override + { + KRATOS_SERIALIZE_LOAD_BASE_CLASS( + rSerializer, + BernoulliBeamBaseElement3D); + } +}; + +///@} + +} // 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..01f3a5fae702 --- /dev/null +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.cpp @@ -0,0 +1,175 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ \. +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +// 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/bernoulli_beam_base_element_3D.h" + +namespace Kratos +{ + +//for normal beam +ComputeBeamVectorsProcess::ComputeBeamVectorsProcess( + ModelPart& rModelPart) + : Process() + , mrThisModelPart(rModelPart) + , mpParentCurve(nullptr) +{ +} + +//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 + 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); + + + // 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 + 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); + + // 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::ComputeT0AndN0( + const Geometry& rParentCurve, + array_1d& rT0, + array_1d& rN0) +{ + 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)); + } + + if (curve_on_surface != nullptr) { + ComputeT0AndN0(*curve_on_surface, rT0, rN0); + } else if (nurbs_curve != nullptr) { + 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()) { + 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)); + } +} + + +} // namespace Kratos 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..92ee18bc7b25 --- /dev/null +++ b/applications/IgaApplication/custom_processes/compute_beam_vectors_process.h @@ -0,0 +1,128 @@ +// | / | +// ' / __| _` | __| _ \ __| +// . \ | ( | | ( |\__ \. +// _|\_\_| \__,_|\__|\___/ ____/ +// Multi-Physics +// +// 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 + +// 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 +#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: + /// 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; + const Geometry* mpParentCurve; + ///@} +}; // Class ComputeBeamVectorsProcess +} // namespace Kratos. + +#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 new file mode 100644 index 000000000000..96a597d1f747 --- /dev/null +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.cpp @@ -0,0 +1,35 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +// 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. 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..a5eb46ca072d --- /dev/null +++ b/applications/IgaApplication/custom_python/add_custom_constitutive_laws_to_python.h @@ -0,0 +1,31 @@ +// KRATOS _____________ +// / _/ ____/ | +// / // / __/ /| | +// _/ // /_/ / ___ | +// /___/\____/_/ |_| Application +// +// License: BSD License +// Kratos default license: kratos/license.txt +// +// Main authors: Max Friedrichs Dachale, Juan Ignacio Camarotti, +// Ricky Aristio, Alicia Knauer +// + +#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 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 4c96cecfcd2f..57f925fe56b9 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" #include "custom_utilities/compute_interface_traction_shell_3p.h" @@ -48,6 +49,77 @@ void AddCustomUtilitiesToPython( 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(); + }); + pybind11::class_< ComputeInterfaceTractionShell3pUtility >(m, "ComputeInterfaceTractionShell3pUtility") .def_static( "ComputeAndSetInterfaceTraction", diff --git a/applications/IgaApplication/custom_python/iga_python_application.cpp b/applications/IgaApplication/custom_python/iga_python_application.cpp index bce24fba8277..671665365b4f 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,14 @@ 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, I22) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I33) + KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, I_T) + // 5p Director Shell Variables KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DIRECTOR_COMPUTED) KRATOS_REGISTER_IN_PYTHON_VARIABLE(m, DIRECTOR) @@ -105,6 +114,7 @@ PYBIND11_MODULE(KratosIgaApplication, m) AddCustomProcessesToPython(m); AddCustomStrategiesToPython(m); AddCustomSolversToPython(m); + AddCustomConstitutiveLawsToPython(m); } } // namespace Python diff --git a/applications/IgaApplication/iga_application.cpp b/applications/IgaApplication/iga_application.cpp index baae891ab5e7..4386e56c1882 100644 --- a/applications/IgaApplication/iga_application.cpp +++ b/applications/IgaApplication/iga_application.cpp @@ -20,6 +20,8 @@ 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( @@ -80,6 +82,7 @@ KratosIgaApplication::KratosIgaApplication() new Geometry(Condition::GeometryType::PointsArrayType(1)))) , mLoadSolidCondition(0, Condition::GeometryType::Pointer( new Geometry(Condition::GeometryType::PointsArrayType(1)))) + , mBernoulliBeamElasticConstitutiveLaw() { } @@ -96,6 +99,7 @@ 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("IgaMembraneElement", mIgaMembraneElement) @@ -140,9 +144,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) @@ -211,7 +218,17 @@ KRATOS_INFO("") << " KRATOS _____ _____\n" KRATOS_REGISTER_VARIABLE(EIGENVALUE_NITSCHE_STABILIZATION_VECTOR) KRATOS_REGISTER_VARIABLE(BUILD_LEVEL) - // SBM Variables + // Beam variables + 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) + + + // SBM Variables KRATOS_REGISTER_VARIABLE(INTEGRATION_POINTS) KRATOS_REGISTER_VARIABLE(INTEGRATION_WEIGHTS) KRATOS_REGISTER_VARIABLE(BOUNDARY_CONDITION_TYPE) diff --git a/applications/IgaApplication/iga_application.h b/applications/IgaApplication/iga_application.h index 3971128c2590..e74a71e6426f 100644 --- a/applications/IgaApplication/iga_application.h +++ b/applications/IgaApplication/iga_application.h @@ -19,6 +19,8 @@ //elements #include "custom_elements/truss_element.h" #include "custom_elements/truss_embedded_edge_element.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" #include "custom_elements/iga_membrane_element.h" @@ -64,6 +66,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 @@ -138,6 +143,7 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio const TrussElement mTrussElement; const TrussEmbeddedEdgeElement mTrussEmbeddedEdgeElement; + const NonLinearBernoulliBeamElement3D mNonLinearBernoulliBeamElement3D; const BeamThinElement2D mBeamThinElement2D; const BeamThickElement2D mBeamThickElement2D; const IgaMembraneElement mIgaMembraneElement; @@ -183,6 +189,9 @@ class KRATOS_API(IGA_APPLICATION) KratosIgaApplication : public KratosApplicatio const NurbsGeometryModelerGapSbm mNurbsGeometryModelerGapSbm; const ImportNurbsSbmModeler mImportNurbsSbmModeler; + // Constitutive Laws + const BernoulliBeamElasticConstitutiveLaw mBernoulliBeamElasticConstitutiveLaw; + ///@} ///@name Private methods ///@{ diff --git a/applications/IgaApplication/iga_application_variables.cpp b/applications/IgaApplication/iga_application_variables.cpp index 54f9eafeddb5..b981efe08837 100644 --- a/applications/IgaApplication/iga_application_variables.cpp +++ b/applications/IgaApplication/iga_application_variables.cpp @@ -42,6 +42,12 @@ 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_T) + // 5p Director Shell Variables KRATOS_CREATE_VARIABLE(bool, DIRECTOR_COMPUTED) KRATOS_CREATE_VARIABLE(Vector, DIRECTOR) diff --git a/applications/IgaApplication/iga_application_variables.h b/applications/IgaApplication/iga_application_variables.h index 5f19cd6bf71f..56468cb346d7 100644 --- a/applications/IgaApplication/iga_application_variables.h +++ b/applications/IgaApplication/iga_application_variables.h @@ -51,6 +51,12 @@ 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_T) + // 5p Director Shell Variables KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, bool, DIRECTOR_COMPUTED) KRATOS_DEFINE_APPLICATION_VARIABLE(IGA_APPLICATION, Vector, DIRECTOR) 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..d3d4d526568a --- /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() 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/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_IgaApplication.py b/applications/IgaApplication/tests/test_IgaApplication.py index 8e5e2affe6af..a561b5999e7d 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 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 @@ -92,6 +94,8 @@ def AssembleTestSuites(): TTrussElementTests, # Beam Elements tests TBeamIGAElementTests, + TTestBeam4pElement, + TTestBeam4pElementNonlinear, # Structural Elements tests TSolidIGAElementTests, # Sbm Elements tests 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..348457b520b3 --- /dev/null +++ b/applications/IgaApplication/tests/test_isogeometric_non_linear_bernoulli_beam_element.py @@ -0,0 +1,779 @@ +import numpy as np + +import KratosMultiphysics as KM +import KratosMultiphysics.IgaApplication as IGA +import KratosMultiphysics.StructuralMechanicsApplication as SMA +import KratosMultiphysics.KratosUnittest as KratosUnittest +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. 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)) +WIDTH = 2.5 +HEIGHT = 5.0 +LENGTH = 4.0 +AREA = WIDTH * HEIGHT +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, 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 + + +def create_properties(model_part, properties_id, normal, young_modulus=E_MOD, poisson_ratio=NU, + 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.I22, i22) + properties.SetValue(IGA.I33, i33) + 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) + 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 + + +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] + + 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)) + + return KM.NurbsCurveGeometry3D(nodes, degree, KM.Vector(knots)) + + +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() + + +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) + + +def add_dofs(model_part): + for dof, reaction in zip(DOFS, REACTIONS): + KM.VariableUtils().AddDof(dof, reaction, model_part) + + +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) + + +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])) + + +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])) + + +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) + + 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() + + +def cantilever_tip_deflection(force, moment_of_inertia): + return force * LENGTH ** 3 / (3.0 * E_MOD * moment_of_inertia) + + +class BeamTestCase(KratosUnittest.TestCase): + + def assertRelativelyEqual(self, value, reference, tolerance): + self.assertLess(abs(value - reference), tolerance * abs(reference), + "%.12e != %.12e (relative tolerance %.1e)" % (value, reference, tolerance)) + + +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, 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, 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) + IGA.ComputeBeamVectorsProcess(model_part, curve).ExecuteInitialize() + add_dofs(model_part) + + 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 + # 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 * 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) + 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) + 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, I22_) + + 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, I33_) + + 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_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 + 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, 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, 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. + # 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, 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 = [] + 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 = 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, + 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() + 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) + + 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) + + 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)) + + solve_linear(model_part) + + 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.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) + + +class TestBeam4pElementNonlinear(BeamTestCase): + """Geometrically nonlinear response of the NonLinearBernoulliBeamElement3D.""" + + @staticmethod + 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, 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) + curve.SetId(2) + model_part.AddGeometry(curve) + + refine_curve(model, "modeler_tests/curve_h_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, 0) + + 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 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)} + return [i for i in range(4 * len(nodes)) if i not in fixed] + + @staticmethod + 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 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, 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) + 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, 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 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.""" + free = cls.free_dofs(nodes) + u = np.zeros(4 * len(nodes)) + 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_iterations): + K, R = cls.assemble(model_part, nodes, u) + residual = R + f + 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 + + @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) + + 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 + + def test_tangent_matches_finite_differences(self): + _, model_part, nodes = self.build_cantilever() + n_dofs = 4 * len(nodes) + + 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, _ = 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(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 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)) + 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] + + self.assertGreaterEqual(len(norms), 3) + 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 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 + + _, 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 + # 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) + + 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 * 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 * 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 * 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 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) + 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"}')) + # 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-6, 1e-9), 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 // 2 + 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 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 + 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 + 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)) + 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()