Eigen::Matrix<typename DerivedA::Scalar, matGradMultMatNumRows(DerivedA::RowsAtCompileTime, DerivedB::ColsAtCompileTime), DerivedDA::ColsAtCompileTime> matGradMultMat( const Eigen::MatrixBase<DerivedA>& A, const Eigen::MatrixBase<DerivedB>& B, const Eigen::MatrixBase<DerivedDA>& dA, const Eigen::MatrixBase<DerivedDB>& dB) { assert(dA.cols() == dB.cols()); const int nq = dA.cols(); const int nq_at_compile_time = DerivedDA::ColsAtCompileTime; Eigen::Matrix<typename DerivedA::Scalar, matGradMultMatNumRows(DerivedA::RowsAtCompileTime, DerivedB::ColsAtCompileTime), DerivedDA::ColsAtCompileTime> ret(A.rows() * B.cols(), nq); for (int col = 0; col < B.cols(); col++) { auto block = ret.template block<DerivedA::RowsAtCompileTime, nq_at_compile_time>(col * A.rows(), 0, A.rows(), nq); // A * dB part: block.noalias() = A * dB.template block<DerivedA::ColsAtCompileTime, nq_at_compile_time>(col * A.cols(), 0, A.cols(), nq); for (int row = 0; row < B.rows(); row++) { // B * dA part: block.noalias() += B(row, col) * dA.template block<DerivedA::RowsAtCompileTime, nq_at_compile_time>(row * A.rows(), 0, A.rows(), nq); } } return ret; // much slower and requires eigen/unsupported: // return Eigen::kroneckerProduct(Eigen::MatrixXd::Identity(B.cols(), B.cols()), A) * dB + Eigen::kroneckerProduct(B.transpose(), Eigen::MatrixXd::Identity(A.rows(), A.rows())) * dA; }
//********************************************************************** void Isotropic3D::CalculateCauchyStresses( Vector& rCauchy_StressVector, const Matrix& rF, const Vector& rPK2_StressVector, const Vector& rGreenLagrangeStrainVector ) { Matrix S = MathUtils<double>::StressVectorToTensor( rPK2_StressVector ); double J = MathUtils<double>::Det3( rF ); boost::numeric::ublas::bounded_matrix<double, 3, 3> mstemp; boost::numeric::ublas::bounded_matrix<double, 3, 3> msaux; noalias( mstemp ) = prod( rF, S ); noalias( msaux ) = prod( mstemp, trans( rF ) ); msaux *= J; if ( rCauchy_StressVector.size() != 6 ) rCauchy_StressVector.resize( 6 ); rCauchy_StressVector[0] = msaux( 0, 0 ); rCauchy_StressVector[1] = msaux( 1, 1 ); rCauchy_StressVector[2] = msaux( 2, 2 ); rCauchy_StressVector[3] = msaux( 0, 1 ); rCauchy_StressVector[4] = msaux( 0, 2 ); rCauchy_StressVector[5] = msaux( 1, 2 ); }
void BeamElement::CalculateLocalNodalStress(Vector& Stress) { Matrix Rotation; Matrix LocalMatrix; array_1d<double, 12 > CurrentDisplacement; array_1d<double, 12 > LocalDisplacement; Vector LocalBody = ZeroVector(12); Vector GlobalBody = ZeroVector(12); Rotation.resize(12,12, false); Stress.resize(12, false); CurrentDisplacement(0) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_X); CurrentDisplacement(1) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_Y); CurrentDisplacement(2) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_Z); CurrentDisplacement(3) = GetGeometry()[0].GetSolutionStepValue(ROTATION_X); CurrentDisplacement(4) = GetGeometry()[0].GetSolutionStepValue(ROTATION_Y); CurrentDisplacement(5) = GetGeometry()[0].GetSolutionStepValue(ROTATION_Z); CurrentDisplacement(6) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_X); CurrentDisplacement(7) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_Y); CurrentDisplacement(8) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_Z); CurrentDisplacement(9) = GetGeometry()[1].GetSolutionStepValue(ROTATION_X); CurrentDisplacement(10) = GetGeometry()[1].GetSolutionStepValue(ROTATION_Y); CurrentDisplacement(11) = GetGeometry()[1].GetSolutionStepValue(ROTATION_Z); CalculateTransformationMatrix(Rotation); CalculateLocalMatrix(LocalMatrix); noalias(LocalDisplacement) = prod(Matrix(trans(Rotation)), CurrentDisplacement); CalculateBodyForce(Rotation, LocalBody, GlobalBody); noalias(Stress) = -LocalBody + prod(LocalMatrix, LocalDisplacement); // noalias(Stress) = -LocalBody + prod(Matrix(prod(Rotation,LocalMatrix)), LocalDisplacement); return; }
Vector& ConvDiffInterface2DLaw::GetValue(const Variable<Vector>& rThisVariable, Vector& rValue) { if (rThisVariable == INITIAL_TEMP_GRAD) { if (rValue.size() != m_init_gradT.size()) rValue.resize(m_init_gradT.size()); noalias(rValue) = m_init_gradT; } if (rThisVariable == FLUX_RVE) { if (rValue.size() != mStressVector.size()) rValue.resize(mStressVector.size()); noalias(rValue) = mStressVector; } if (rThisVariable == HEAT_FLUX_RVE) { //For Output if (rValue.size() != 3) rValue.resize(3); rValue(0) = mStressVector(0); // 1.0e6;//[W/mm^2] rValue(1) = mStressVector(1); // 1.0e6; rValue(2) = 0.0; } if (rThisVariable == GAP_INTERFACE) { if (rValue.size() != m_gap_interface.size()) rValue.resize(m_gap_interface.size()); noalias(rValue) = m_gap_interface; } return rValue; }
void ExplicitSolverStrategy::ClearFEMForces() { KRATOS_TRY ModelPart& fem_model_part = GetFemModelPart(); NodesArrayType& pNodes = fem_model_part.Nodes(); vector<unsigned int> node_partition; OpenMPUtils::CreatePartition(mNumberOfThreads, pNodes.size(), node_partition); #pragma omp parallel for for (int k = 0; k < mNumberOfThreads; k++) { typename NodesArrayType::iterator i_begin = pNodes.ptr_begin() + node_partition[k]; typename NodesArrayType::iterator i_end = pNodes.ptr_begin() + node_partition[k + 1]; for (ModelPart::NodeIterator i = i_begin; i != i_end; ++i) { array_1d<double, 3>& node_rhs = i->FastGetSolutionStepValue(CONTACT_FORCES); array_1d<double, 3>& node_rhs_elas = i->FastGetSolutionStepValue(ELASTIC_FORCES); array_1d<double, 3>& node_rhs_tang = i->FastGetSolutionStepValue(TANGENTIAL_ELASTIC_FORCES); double& node_pressure = i->GetSolutionStepValue(DEM_PRESSURE); double& node_area = i->GetSolutionStepValue(DEM_NODAL_AREA); double& shear_stress = i->FastGetSolutionStepValue(SHEAR_STRESS); noalias(node_rhs) = ZeroVector(3); noalias(node_rhs_elas) = ZeroVector(3); noalias(node_rhs_tang) = ZeroVector(3); node_pressure = 0.0; node_area = 0.0; shear_stress = 0.0; } } KRATOS_CATCH("") }
void Isotropic_Rankine_Yield_Function::GetValue(Matrix& Result) { m_inv_DeltaF.resize(3,3, false); noalias(m_inv_DeltaF) = ZeroMatrix(3,3); switch(mState) { case Plane_Stress: { KRATOS_THROW_ERROR(std::logic_error, "PLANE STRESS NOT IMPLEMENTED" , ""); break; } case Plane_Strain: { m_inv_DeltaF(0,0) = Result(0,0); m_inv_DeltaF(0,1) = Result(0,1); m_inv_DeltaF(1,0) = Result(1,0); m_inv_DeltaF(1,1) = Result(1,1); m_inv_DeltaF(2,2) = 1.00; break; } case Tri_D: { noalias(m_inv_DeltaF) = Result; break; } } }
void InfiniteDomainCondition<TDim,TNumNodes>::CalculateRHS( VectorType& rRightHandSideVector, const ProcessInfo& CurrentProcessInfo ) { KRATOS_TRY //const PropertiesType& Prop = this->GetProperties(); const GeometryType& Geom = this->GetGeometry(); const unsigned int element_size = TNumNodes; const GeometryType::IntegrationPointsArrayType& integration_points = Geom.IntegrationPoints( mThisIntegrationMethod ); const unsigned int NumGPoints = integration_points.size(); const unsigned int LocalDim = Geom.LocalSpaceDimension(); //Resetting the RHS if ( rRightHandSideVector.size() != element_size ) rRightHandSideVector.resize( element_size, false ); noalias( rRightHandSideVector ) = ZeroVector( element_size ); boost::numeric::ublas::bounded_matrix<double,TNumNodes,TNumNodes> DampingMatrix; //Defining the shape functions, the jacobian and the shape functions local gradients Containers array_1d<double,TNumNodes> Np; const Matrix& NContainer = Geom.ShapeFunctionsValues( mThisIntegrationMethod ); GeometryType::JacobiansType JContainer(NumGPoints); for(unsigned int i = 0; i<NumGPoints; i++) (JContainer[i]).resize(TDim,LocalDim,false); Geom.Jacobian( JContainer, mThisIntegrationMethod ); double IntegrationCoefficient; // Definition of the speed in the fluid //~ const double BulkModulus = Prop[BULK_MODULUS_FLUID]; //~ const double Water_density = Prop[DENSITY_WATER]; const double BulkModulus = 2.21e9; const double Water_density = 1000.0; const double inv_c_speed = 1.0 /sqrt(BulkModulus/Water_density); //Nodal Variables array_1d<double,TNumNodes> DtPressureVector; for(unsigned int i=0; i<TNumNodes; i++) { DtPressureVector[i] = Geom[i].FastGetSolutionStepValue(Dt_PRESSURE); } for ( unsigned int igauss = 0; igauss < NumGPoints; igauss++ ) { noalias(Np) = row(NContainer,igauss); //calculating weighting coefficient for integration this->CalculateIntegrationCoefficient( IntegrationCoefficient, JContainer[igauss], integration_points[igauss].Weight() ); // Mass matrix contribution noalias(DampingMatrix) = (inv_c_speed)*outer_prod(Np,Np)*IntegrationCoefficient; noalias(rRightHandSideVector) += -1.0*prod(DampingMatrix,DtPressureVector); } KRATOS_CATCH( "" ) }
void Cluster3D::CustomInitialize(ProcessInfo& r_process_info) { const double cl = GetGeometry()[0].FastGetSolutionStepValue(CHARACTERISTIC_LENGTH); const ClusterInformation& cl_info = GetProperties()[CLUSTER_INFORMATION]; //std::string& name = cl_info.mName; const double reference_size = cl_info.mSize; const double reference_volume = cl_info.mVolume; const std::vector<double>& reference_list_of_radii = cl_info.mListOfRadii; const std::vector<array_1d<double,3> >& reference_list_of_coordinates = cl_info.mListOfCoordinates; const array_1d<double,3>& reference_inertias = cl_info.mInertias; const unsigned int number_of_spheres = reference_list_of_radii.size(); mListOfRadii.resize(number_of_spheres); mListOfCoordinates.resize(number_of_spheres); mListOfSphericParticles.resize(number_of_spheres); const double scaling_factor = cl / reference_size; for(int i=0; i<(int)number_of_spheres; i++){ mListOfRadii[i] = scaling_factor * reference_list_of_radii[i]; mListOfCoordinates[i][0] = scaling_factor * reference_list_of_coordinates[i][0]; mListOfCoordinates[i][1] = scaling_factor * reference_list_of_coordinates[i][1]; mListOfCoordinates[i][2] = scaling_factor * reference_list_of_coordinates[i][2]; } const double particle_density = this->SlowGetDensity(); const double cluster_volume = reference_volume * scaling_factor*scaling_factor*scaling_factor; const double cluster_mass = particle_density * cluster_volume; GetGeometry()[0].FastGetSolutionStepValue(NODAL_MASS) = cluster_mass; GetGeometry()[0].FastGetSolutionStepValue(CLUSTER_VOLUME) = cluster_volume; GetGeometry()[0].FastGetSolutionStepValue(PARTICLE_MATERIAL) = this->SlowGetParticleMaterial(); const double squared_scaling_factor_times_density = scaling_factor * scaling_factor * particle_density; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[0] = reference_inertias[0] * cluster_volume * squared_scaling_factor_times_density; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[1] = reference_inertias[1] * cluster_volume * squared_scaling_factor_times_density; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[2] = reference_inertias[2] * cluster_volume * squared_scaling_factor_times_density; array_1d<double, 3> base_principal_moments_of_inertia = GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA); Quaternion<double>& Orientation = GetGeometry()[0].FastGetSolutionStepValue(ORIENTATION); Orientation.normalize(); array_1d<double, 3> angular_velocity = GetGeometry()[0].FastGetSolutionStepValue(ANGULAR_VELOCITY); array_1d<double, 3> angular_momentum; double LocalTensor[3][3]; double GlobalTensor[3][3]; GeometryFunctions::ConstructLocalTensor(base_principal_moments_of_inertia, LocalTensor); GeometryFunctions::QuaternionTensorLocal2Global(Orientation, LocalTensor, GlobalTensor); GeometryFunctions::ProductMatrix3X3Vector3X1(GlobalTensor, angular_velocity, angular_momentum); noalias(this->GetGeometry()[0].FastGetSolutionStepValue(ANGULAR_MOMENTUM)) = angular_momentum; array_1d<double, 3> local_angular_velocity; GeometryFunctions::QuaternionVectorGlobal2Local(Orientation, angular_velocity, local_angular_velocity); noalias(this->GetGeometry()[0].FastGetSolutionStepValue(LOCAL_ANGULAR_VELOCITY)) = local_angular_velocity; }
void Isotropic_Rankine_Yield_Function::FinalizeSolutionStep() { mpastic_damage_old = mpastic_damage_current; mFt = mcurrent_Ft; mrankine_accumulated_plastic_strain_old = mrankine_accumulated_plastic_strain_current; noalias(mPrincipalPlasticStrain_old) = mPrincipalPlasticStrain_current; noalias(mplastic_strain_old) = mplastic_strain; noalias(mElastic_strain_old) = mElastic_strain; }
void PlaneStressJ2::FinalizeSolutionStep(const Properties& props, const GeometryType& geom, const Vector& ShapeFunctionsValues, const ProcessInfo& CurrentProcessInfo) { malpha_old = malpha_current; noalias(mOldPlasticStrain) = mCurrentPlasticStrain; noalias(mbeta_old) = mbeta_n1; }
/** * TO BE TESTED!!! */ void Isotropic3D::CalculateStress( const Vector& StrainVector, Matrix& AlgorithmicTangent, Vector& StressVector ) { if ( StressVector.size() != 6 ) { StressVector.resize( 6 ); } noalias( StressVector ) = prod( AlgorithmicTangent, StrainVector ) - mPrestressFactor * mPrestress; noalias(mCurrentStress) = StressVector; }
void Isotropic_Rankine_Yield_Function::UpdateMaterial() { mpastic_damage_current = mpastic_damage_old; mcurrent_Ft = mFt; mrankine_accumulated_plastic_strain_current = mrankine_accumulated_plastic_strain_old; noalias(mPrincipalPlasticStrain_current) = mPrincipalPlasticStrain_old; noalias(mplastic_strain) = mplastic_strain_old; noalias(mElastic_strain) = mElastic_strain_old; }
void CapsuleCluster3D::CustomInitialize(ProcessInfo& r_process_info) { int number_of_spheres = 5; mListOfRadii.resize(number_of_spheres); mListOfCoordinates.resize(number_of_spheres); mListOfSphericParticles.resize(number_of_spheres); double cl = GetGeometry()[0].FastGetSolutionStepValue(CHARACTERISTIC_LENGTH); mListOfRadii[0]= 0.35 * cl; mListOfRadii[1]= 0.35 * cl; mListOfRadii[2]= 0.35 * cl; mListOfRadii[3]= 0.35 * cl; mListOfRadii[4]= 0.35 * cl; mListOfCoordinates[0][0] = 0.0000 * cl; mListOfCoordinates[0][1] = 0.0; mListOfCoordinates[0][2] = 0.0; mListOfCoordinates[1][0] = 0.2325 * cl; mListOfCoordinates[1][1] = 0.0; mListOfCoordinates[1][2] = 0.0; mListOfCoordinates[2][0] = 0.4650 * cl; mListOfCoordinates[2][1] = 0.0; mListOfCoordinates[2][2] = 0.0; mListOfCoordinates[3][0] = 0.6975 * cl; mListOfCoordinates[3][1] = 0.0; mListOfCoordinates[3][2] = 0.0; mListOfCoordinates[4][0] = 0.9300 * cl; mListOfCoordinates[4][1] = 0.0; mListOfCoordinates[4][2] = 0.0; double particle_density = this->SlowGetDensity(); double cluster_volume = 4.0 * KRATOS_M_PI_3 * 0.35 * 0.35 * 0.35 * cl * cl * cl + KRATOS_M_PI * 0.35 * 0.35 * 0.93 * cl * cl * cl; double cluster_mass = particle_density * cluster_volume; GetGeometry()[0].FastGetSolutionStepValue(NODAL_MASS) = cluster_mass; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[0] = 0.5 * cluster_mass * 0.35 * 0.35 * cl * cl; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[1] = 0.08333333333 * cluster_mass * (3.0 * 0.35 * 0.35 + 4.0 * 1.0 * 1.0) * cl * cl; GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA)[2] = 0.08333333333 * cluster_mass * (3.0 * 0.35 * 0.35 + 4.0 * 1.0 * 1.0) * cl * cl; array_1d<double, 3> base_principal_moments_of_inertia = GetGeometry()[0].FastGetSolutionStepValue(PRINCIPAL_MOMENTS_OF_INERTIA); GetGeometry()[0].FastGetSolutionStepValue(NODAL_MASS) = cluster_mass; GetGeometry()[0].FastGetSolutionStepValue(CLUSTER_VOLUME) = cluster_volume; GetGeometry()[0].FastGetSolutionStepValue(PARTICLE_MATERIAL) = this->SlowGetParticleMaterial(); Quaternion<double>& Orientation = GetGeometry()[0].FastGetSolutionStepValue(ORIENTATION); Orientation.normalize(); array_1d<double, 3> angular_velocity = GetGeometry()[0].FastGetSolutionStepValue(ANGULAR_VELOCITY); array_1d<double, 3> angular_momentum; double LocalTensor[3][3]; double GlobalTensor[3][3]; GeometryFunctions::ConstructLocalTensor(base_principal_moments_of_inertia, LocalTensor); GeometryFunctions::QuaternionTensorLocal2Global(Orientation, LocalTensor, GlobalTensor); GeometryFunctions::ProductMatrix3X3Vector3X1(GlobalTensor, angular_velocity, angular_momentum); noalias(this->GetGeometry()[0].FastGetSolutionStepValue(ANGULAR_MOMENTUM)) = angular_momentum; array_1d<double, 3> local_angular_velocity; GeometryFunctions::QuaternionVectorGlobal2Local(Orientation, angular_velocity, local_angular_velocity); noalias(this->GetGeometry()[0].FastGetSolutionStepValue(LOCAL_ANGULAR_VELOCITY)) = local_angular_velocity; }
/** * TO BE TESTED!!! */ PlaneStressJ2::PlaneStressJ2() : ConstitutiveLaw() { noalias(mOldPlasticStrain) = ZeroVector(3); noalias(mbeta_old) = ZeroVector(3); malpha_old = 0.0; malpha_current = 0.0; noalias(mCurrentPlasticStrain) = ZeroVector(3); noalias(mbeta_n1) = ZeroVector(3); }
void ConvDiffAnisotropic2DLaw::SetValue(const Variable<Vector >& rVariable, const Vector& rValue, const ProcessInfo& rCurrentProcessInfo) { if (rVariable == INITIAL_TEMP_GRAD) { if (rValue.size() == m_init_gradT.size()) noalias(m_init_gradT) = rValue; } if (rVariable == FLUX_RVE) { if (rValue.size() == mStressVector.size()) noalias(mStressVector) = rValue; } }
void Isotropic_Rankine_Yield_Function::GetValue(const Variable<Vector>& rVariable, Vector& Result) { const int size = mplastic_strain.size(); if(rVariable==ALMANSI_PLASTIC_STRAIN) { Result.resize(size); noalias(Result) = mplastic_strain; } if(rVariable==ALMANSI_ELASTIC_STRAIN) { Result.resize(size); noalias(Result) = mElastic_strain ; } }
void ConvDiffInterface2DLaw::SetValue(const Variable<Vector >& rVariable, const Vector& rValue, const ProcessInfo& rCurrentProcessInfo) { if (rVariable == FLUX_RVE) { if (rValue.size() == mStressVector.size()) noalias(mStressVector) = rValue; } if (rVariable == GAP_INTERFACE) { if (rValue.size() == m_gap_interface.size()) noalias(m_gap_interface) = rValue; } }
void InfiniteDomainCondition<TDim,TNumNodes>::CalculateLHS( MatrixType& rLeftHandSideMatrix, const ProcessInfo& CurrentProcessInfo ) { KRATOS_TRY //const PropertiesType& Prop = this->GetProperties(); const GeometryType& Geom = this->GetGeometry(); const unsigned int element_size = TNumNodes; const GeometryType::IntegrationPointsArrayType& integration_points = Geom.IntegrationPoints( mThisIntegrationMethod ); const unsigned int NumGPoints = integration_points.size(); const unsigned int LocalDim = Geom.LocalSpaceDimension(); //Resetting the LHS if ( rLeftHandSideMatrix.size1() != element_size ) rLeftHandSideMatrix.resize( element_size, element_size, false ); noalias( rLeftHandSideMatrix ) = ZeroMatrix( element_size, element_size ); //Defining the shape functions, the jacobian and the shape functions local gradients Containers array_1d<double,TNumNodes> Np; const Matrix& NContainer = Geom.ShapeFunctionsValues( mThisIntegrationMethod ); GeometryType::JacobiansType JContainer(NumGPoints); for(unsigned int i = 0; i<NumGPoints; i++) (JContainer[i]).resize(TDim,LocalDim,false); Geom.Jacobian( JContainer, mThisIntegrationMethod ); double IntegrationCoefficient; // Definition of the speed in the fluid //~ const double BulkModulus = Prop[BULK_MODULUS_FLUID]; //~ const double Water_density = Prop[DENSITY_WATER]; const double BulkModulus = 2.21e9; const double Water_density = 1000.0; const double inv_c_speed = 1.0 /sqrt(BulkModulus/Water_density); for ( unsigned int igauss = 0; igauss < NumGPoints; igauss++ ) { noalias(Np) = row(NContainer,igauss); //calculating weighting coefficient for integration this->CalculateIntegrationCoefficient( IntegrationCoefficient, JContainer[igauss], integration_points[igauss].Weight() ); // Mass matrix contribution noalias(rLeftHandSideMatrix) += CurrentProcessInfo[VELOCITY_PRESSURE_COEFFICIENT]*(inv_c_speed)*outer_prod(Np,Np)*IntegrationCoefficient; } KRATOS_CATCH( "" ) }
void Tresca_Yield_Function::ReturnMapping(const Vector& StressVector, const Vector& StrainVector, Vector& delta_lamda, array_1d<double,3>& Result) { double p_trial = 0.00; Matrix Sigma_Tensor = ZeroMatrix(3,3); State_Tensor(StressVector, Sigma_Tensor); p_trial = (Sigma_Tensor(0,0) + Sigma_Tensor(1,1) + Sigma_Tensor(2,2))/3.00 ; array_1d<double,3> Trial_Stress_Vector = ZeroVector(3); array_1d<double,3> Aux_Trial_Stress_Vector = ZeroVector(3); CalculatePrincipalStressVector(StressVector, Trial_Stress_Vector); Trial_Stress_Vector[0] = Trial_Stress_Vector[0] - p_trial; Trial_Stress_Vector[1] = Trial_Stress_Vector[1] - p_trial; Trial_Stress_Vector[2] = Trial_Stress_Vector[2] - p_trial; noalias(Aux_Trial_Stress_Vector) = Trial_Stress_Vector; ///* return to main plane One_Vector_Return_Mapping_To_Main_Plane(StressVector, delta_lamda, Trial_Stress_Vector); ///*check validty bool check = false; check = CheckValidity(Trial_Stress_Vector); if( check==false) { ///*return to corner noalias(Trial_Stress_Vector) = Aux_Trial_Stress_Vector; double proof = Trial_Stress_Vector[0] + Trial_Stress_Vector[2] - 2.00 * Trial_Stress_Vector[1]; if(proof > 0.00 ) { mCases = right; } else { mCases = left; } Two_Vector_Return_Mapping_To_Corner(StressVector,delta_lamda, Trial_Stress_Vector); } Result[0] = Trial_Stress_Vector[0] + p_trial; Result[1] = Trial_Stress_Vector[1] + p_trial; Result[2] = Trial_Stress_Vector[2] + p_trial; }
//************************************************************************************ //************************************************************************************ void BeamPointPressureCondition::InitializeNonLinearIteration(ProcessInfo& CurrentProcessInfo) { array_1d<double, 3 > node_to_center_vector; node_to_center_vector[0] = node_to_center_vector[1] = node_to_center_vector[2] = 0.0; mForce[0] = mForce[1] = mForce[2] = 0.0; //Calculate all normals for(unsigned int i=0; i<mNodesList.size(); i++){ node_to_center_vector[0] = GetGeometry()[0].X() - mNodesList[i]->X(); node_to_center_vector[1] = GetGeometry()[0].Y() - mNodesList[i]->Y(); node_to_center_vector[2] = GetGeometry()[0].Z() - mNodesList[i]->Z(); double modulus = sqrt( node_to_center_vector[0]*node_to_center_vector[0] + node_to_center_vector[1]*node_to_center_vector[1] + node_to_center_vector[2]*node_to_center_vector[2] ); array_1d<double, 3 > unitary_vector; noalias(unitary_vector) = node_to_center_vector / modulus; //Multiply normal times the pressure and the nodal area unitary_vector *= mNodesList[i]->FastGetSolutionStepValue(PRESSURE) * mNodesList[i]->FastGetSolutionStepValue(NODAL_AREA); //Add up forces coming from all perimetral nodes mForce += unitary_vector; } }
lslboost::numeric::ublas::vector<T> solve( const lslboost::numeric::ublas::matrix<T>& A_, const lslboost::numeric::ublas::vector<T>& b_) { //BOOST_ASSERT(A_.size() == b_.size()); lslboost::numeric::ublas::matrix<T> A(A_); lslboost::numeric::ublas::vector<T> b(b_); lslboost::numeric::ublas::permutation_matrix<> piv(b.size()); lu_factorize(A, piv); lu_substitute(A, piv, b); // // iterate to reduce error: // lslboost::numeric::ublas::vector<T> delta(b.size()); for(unsigned i = 0; i < 1; ++i) { noalias(delta) = prod(A_, b); delta -= b_; lu_substitute(A, piv, delta); b -= delta; T max_error = 0; for(unsigned i = 0; i < delta.size(); ++i) { T err = fabs(delta[i] / b[i]); if(err > max_error) max_error = err; } //std::cout << "Max change in LU error correction: " << max_error << std::endl; } return b; }
Matrix DruckerPrager::InverseC(Matrix& InvC) { if (InvC.size1() != 6 || InvC.size2() != 6) InvC.resize(6, 6); noalias(InvC) = ZeroMatrix(6, 6); double lambda = mNU * mE / ((1 + mNU) * (1 - 2 * mNU)); double mu = mE / (2 * (1 + mNU)); double a = (4 * mu * mu + 4 * mu * lambda) / (8 * mu * mu * mu + 12 * mu * mu * lambda); double b = -(2 * mu * lambda) / (8 * mu * mu * mu + 12 * mu * mu * lambda); InvC(0, 0) = a; InvC(0, 1) = b; InvC(0, 2) = b; InvC(1, 0) = b; InvC(1, 1) = a; InvC(1, 2) = b; InvC(2, 0) = b; InvC(2, 1) = b; InvC(2, 2) = a; InvC(3, 3) = 1 / (2 * mu); InvC(4, 4) = 1 / (2 * mu); InvC(5, 5) = 1 / (2 * mu); return InvC; }
void trsm_impl( matrix_expression<MatA, cpu_tag> const& A, matrix_expression<MatB, cpu_tag>& B, boost::mpl::true_, column_major ) { SIZE_CHECK(A().size1() == A().size2()); SIZE_CHECK(A().size2() == B().size1()); typedef typename MatA::value_type value_type; std::size_t size1 = B().size1(); std::size_t size2 = B().size2(); for (std::size_t i = 0; i < size1; ++ i) { std::size_t n = size1-i-1; auto columnTriangular = column(A(),n); if(!Unit){ RANGE_CHECK(A()(n, n) != value_type());//matrix is singular row(B(),n) /= A()(n, n); } for (std::size_t l = 0; l < size2; ++ l) { if (B()(n, l) != value_type/*zero*/()) { auto columnMatrix = column(B(),l); noalias(subrange(columnMatrix,0,n)) -= B()(n,l) * subrange(columnTriangular,0,n); } } } }
void UpdatedLagrangianFluid3Dinc::CalculateMassMatrix(MatrixType& rMassMatrix, ProcessInfo& rCurrentProcessInfo) { KRATOS_TRY const double& density = 0.25*(GetGeometry()[0].FastGetSolutionStepValue(DENSITY)+ GetGeometry()[1].FastGetSolutionStepValue(DENSITY) + GetGeometry()[2].FastGetSolutionStepValue(DENSITY)+ GetGeometry()[3].FastGetSolutionStepValue(DENSITY)); //lumped unsigned int dimension = GetGeometry().WorkingSpaceDimension(); unsigned int NumberOfNodes = GetGeometry().size(); unsigned int MatSize = dimension * NumberOfNodes; if(rMassMatrix.size1() != MatSize) rMassMatrix.resize(MatSize,MatSize,false); noalias(rMassMatrix) = ZeroMatrix(MatSize,MatSize); double nodal_mass = mA0 * density * 0.25; for(unsigned int i=0; i<NumberOfNodes; i++) { for(unsigned int j=0; j<dimension; j++) { unsigned int index = i*dimension + j; rMassMatrix(index,index) = nodal_mass; } } KRATOS_CATCH("") }
double vecvscalaradd(size_t N, size_t iterations = 1) { boost::numeric::ublas::vector<double> a(N), b(N); double c = 3; vinit(b.size(), b); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); noalias(a) = b + boost::numeric::ublas::scalar_vector<double>(N, c); auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); /* // check to see if nothing happened during rum to invalidate the times if(tmin*(1.0 + deviation*0.01) < tavg){ std::cerr << "uBLAS kernel 'vecscalaradd': Time deviation too large!!!" << std::endl; } */ return tavg; }
Vector& ScalarDamageInterface2DLaw::GetValue(const Variable<Vector>& rThisVariable, Vector& rValue) { if (rThisVariable == INITIAL_STRAIN) { if (rValue.size() != m_initial_strain.size()) rValue.resize(m_initial_strain.size()); noalias(rValue) = m_initial_strain; } if(rThisVariable == YIELD_SURFACE_DATA_2D_X || rThisVariable == YIELD_SURFACE_DATA_2D_Y) { int ijob = rThisVariable == YIELD_SURFACE_DATA_2D_X ? 1 : 2; double Ft = 1.0; double C0 = 2.0; double Fs = std::tan(M_PI / 180 * 30.0); SizeType nn = 10; if(rValue.size() != nn) rValue.resize(nn, false); double Ft_d = (1.0 - mD1)*Ft; double C0_d = (1.0 - mD2)*C0; double x = Ft_d; double x_incr = (4.0*Ft+Ft_d) / (double)(nn-1); rValue(0) = ijob == 1 ? x : 0.0; for(SizeType i = 1; i < nn; i++) { double y = -x*Fs+C0_d; rValue(i) = ijob == 1 ? x : y; x -= x_incr; } } return rValue; }
//************************************************************************************ //************************************************************************************ void BeamElement::CalculateRHS(Vector& rRightHandSideVector) { Matrix Rotation; Matrix GlobalMatrix; Vector LocalBody; array_1d<double, 12 > CurrentDisplacement; Rotation.resize(12,12, false); rRightHandSideVector = ZeroVector(12); LocalBody = ZeroVector(12); CalculateTransformationMatrix(Rotation); CalculateBodyForce(Rotation, LocalBody, rRightHandSideVector); CurrentDisplacement(0) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_X); CurrentDisplacement(1) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_Y); CurrentDisplacement(2) = GetGeometry()[0].GetSolutionStepValue(DISPLACEMENT_Z); CurrentDisplacement(3) = GetGeometry()[0].GetSolutionStepValue(ROTATION_X); CurrentDisplacement(4) = GetGeometry()[0].GetSolutionStepValue(ROTATION_Y); CurrentDisplacement(5) = GetGeometry()[0].GetSolutionStepValue(ROTATION_Z); CurrentDisplacement(6) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_X); CurrentDisplacement(7) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_Y); CurrentDisplacement(8) = GetGeometry()[1].GetSolutionStepValue(DISPLACEMENT_Z); CurrentDisplacement(9) = GetGeometry()[1].GetSolutionStepValue(ROTATION_X); CurrentDisplacement(10) = GetGeometry()[1].GetSolutionStepValue(ROTATION_Y); CurrentDisplacement(11) = GetGeometry()[1].GetSolutionStepValue(ROTATION_Z); CalculateLHS(GlobalMatrix); noalias(rRightHandSideVector) -= prod(GlobalMatrix, CurrentDisplacement); return; }
double vecscalarmult(size_t N, size_t iterations = 1) { boost::numeric::ublas::vector<value_type> a(N), b(N); value_type c = 3; vinit(a.size(), a); std::vector<double> times; for(size_t i = 0; i < iterations; ++i){ auto start = std::chrono::steady_clock::now(); noalias(a) = b * c; auto end = std::chrono::steady_clock::now(); auto diff = end - start; times.push_back(std::chrono::duration<double, std::milli> (diff).count()); //save time in ms for each iteration } double tmin = *(std::min_element(times.begin(), times.end())); double tavg = average_time(times); // check to see if nothing happened during run to invalidate the times if(variance(tavg, times) > max_variance){ std::cerr << "boost kernel 'vecscalarmult': Time deviation too large! \n"; } return tavg; }
void BeamPointPressureCondition::InitializeSystemMatrices( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector) { rLeftHandSideMatrix.resize( 6, 6, false ); noalias( rLeftHandSideMatrix ) = ZeroMatrix( 6, 6 ); //resetting LHS rRightHandSideVector.resize( 6, false ); rRightHandSideVector = ZeroVector( 6 ); //resetting RHS }
Vector& Isotropic3D::GetValue( const Variable<Vector>& rThisVariable, Vector& rValue ) { if ( rThisVariable == INSITU_STRESS || rThisVariable == PRESTRESS ) { const unsigned int size = mPrestress.size(); if(rValue.size() != size) rValue.resize(size, false ); noalias(rValue) = mPrestressFactor * mPrestress; return rValue; } if ( rThisVariable == STRESSES ) { const unsigned int size = mCurrentStress.size(); rValue.resize(size, false ); rValue = mCurrentStress; return rValue; } if ( rThisVariable == PLASTIC_STRAIN_VECTOR ) { rValue = ZeroVector( 6 ); return( rValue ); } if ( rThisVariable == INTERNAL_VARIABLES ) { rValue = ZeroVector( 1 ); return( rValue ); } KRATOS_THROW_ERROR( std::logic_error, "Vector Variable case not considered", "" ); }