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 }
//************************************************************************************ //************************************************************************************ void ThermalFace2D::CalculateAll(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo, bool CalculateStiffnessMatrixFlag, bool CalculateResidualVectorFlag) { KRATOS_TRY unsigned int number_of_nodes = GetGeometry().size(); //resizing as needed the LHS unsigned int MatSize=number_of_nodes; ConvectionDiffusionSettings::Pointer my_settings = rCurrentProcessInfo.GetValue(CONVECTION_DIFFUSION_SETTINGS); const Variable<double>& rUnknownVar = my_settings->GetUnknownVariable(); const Variable<double>& rSurfaceSourceVar = my_settings->GetSurfaceSourceVariable(); //calculate lenght double x21 = GetGeometry()[1].X() - GetGeometry()[0].X(); double y21 = GetGeometry()[1].Y() - GetGeometry()[0].Y(); double lenght = x21*x21 + y21*y21; lenght = sqrt(lenght); const Properties& ConstProp = GetProperties(); const double& ambient_temperature = ConstProp[AMBIENT_TEMPERATURE]; double StefenBoltzmann = 5.67e-8; double emissivity = ConstProp[EMISSIVITY]; double convection_coefficient = ConstProp[CONVECTION_COEFFICIENT]; const double& T0 = GetGeometry()[0].FastGetSolutionStepValue(rUnknownVar); const double& T1 = GetGeometry()[1].FastGetSolutionStepValue(rUnknownVar); const double& q0 =GetGeometry()[0].FastGetSolutionStepValue(rSurfaceSourceVar); const double& q1 =GetGeometry()[1].FastGetSolutionStepValue(rSurfaceSourceVar); if (CalculateStiffnessMatrixFlag == true) //calculation of the matrix is required { if(rLeftHandSideMatrix.size1() != MatSize ) rLeftHandSideMatrix.resize(MatSize,MatSize,false); noalias(rLeftHandSideMatrix) = ZeroMatrix(MatSize,MatSize); rLeftHandSideMatrix(0,0) = ( convection_coefficient + emissivity*StefenBoltzmann*4.0*pow(T0,3) )* 0.5 * lenght; rLeftHandSideMatrix(1,1) = ( convection_coefficient + emissivity*StefenBoltzmann*4.0*pow(T1,3) )* 0.5 * lenght; } //resizing as needed the RHS double aux = pow(ambient_temperature,4); if (CalculateResidualVectorFlag == true) //calculation of the matrix is required { if(rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize(MatSize,false); rRightHandSideVector[0] = q0 - emissivity*StefenBoltzmann*(pow(T0,4) - aux) - convection_coefficient * ( T0 - ambient_temperature); rRightHandSideVector[1] = q1 - emissivity*StefenBoltzmann*(pow(T1,4) - aux) - convection_coefficient * ( T1 - ambient_temperature); rRightHandSideVector *= 0.5*lenght; } KRATOS_CATCH("") }
/** * calculates this contact element's local contributions */ void SlaveContactFace3DNewmark::CalculateLocalSystem( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { rRightHandSideVector.resize(0,false); rLeftHandSideMatrix(0,0); }
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( "" ) }
/** * calculates only the RHS vector (certainly to be removed due to contact algorithm) */ void MasterContactPoint2D::CalculateRightHandSide( VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { unsigned int ndof = GetGeometry().size()*2; if( rRightHandSideVector.size() != ndof ) rRightHandSideVector.resize(ndof,false); rRightHandSideVector = ZeroVector(ndof); }
void SolidFace3D::CalculateRightHandSide(VectorType& rRightHandSideVector, ProcessInfo& r_process_info) { const unsigned int number_of_nodes = GetGeometry().size(); unsigned int MatSize = number_of_nodes * 3; if (rRightHandSideVector.size() != MatSize) { rRightHandSideVector.resize(MatSize, false); } rRightHandSideVector = ZeroVector(MatSize); std::vector<SphericParticle*>& rNeighbours = this->mNeighbourSphericParticles; for (unsigned int i=0; i<rNeighbours.size(); i++) { if(rNeighbours[i]->Is(BLOCKED)) continue; //Inlet Generator Spheres are ignored when integrating forces. std::vector<DEMWall*>& rRFnei = rNeighbours[i]->mNeighbourRigidFaces; for (unsigned int i_nei = 0; i_nei < rRFnei.size(); i_nei++) { int Contact_Type = rNeighbours[i]->mContactConditionContactTypes[i_nei]; if ( ( rRFnei[i_nei]->Id() == this->Id() ) && (Contact_Type > 0 ) ) { array_1d<double, 4> weights_vector = rNeighbours[i]->mContactConditionWeights[i_nei]; double weight = 0.0; double ContactForce[3] = {0.0}; const array_1d<double, 3>& neighbour_rigid_faces_contact_force = rNeighbours[i]->mNeighbourRigidFacesTotalContactForce[i_nei]; ContactForce[0] = neighbour_rigid_faces_contact_force[0]; ContactForce[1] = neighbour_rigid_faces_contact_force[1]; ContactForce[2] = neighbour_rigid_faces_contact_force[2]; for (unsigned int k=0; k< number_of_nodes; k++) { weight = weights_vector[k]; unsigned int w = k * 3; rRightHandSideVector[w + 0] += -ContactForce[0] * weight; rRightHandSideVector[w + 1] += -ContactForce[1] * weight; rRightHandSideVector[w + 2] += -ContactForce[2] * weight; } }//if the condition neighbour of my sphere neighbour is myself. }//Loop spheres neighbours (condition) }//Loop condition neighbours (spheres) }//CalculateRightHandSide
inline void StackContextBase<TSuperClass>::setSlotVariable(const VariableSlotID slot, const UnitType &newValue, VectorType &container) const { if(slot < container.size()) container.replace(slot, newValue); else { container.resize(slot + 1); container.replace(slot, newValue); } }
/** * calculates this contact element's local contributions */ void MasterContactPoint2D::CalculateLocalSystem( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { unsigned int ndof = GetGeometry().size()*2; if( rRightHandSideVector.size() != ndof ) rRightHandSideVector.resize(ndof,false); rRightHandSideVector = ZeroVector(ndof); if( rLeftHandSideMatrix.size1() != ndof ) rLeftHandSideMatrix(ndof,ndof); rLeftHandSideMatrix = ZeroMatrix(ndof,ndof); }
void AbsoluteEulerAngleDecoder::Encode(array_view<const DirectX::Quaternion> rots, VectorType & x) { int n = rots.size(); Eigen::Vector4f qs; XMVECTOR q; qs.setZero(); x.resize(n * 3); for (int i = 0; i < n; i++) { q = XMLoad(rots[i]); q = XMQuaternionEulerAngleYawPitchRoll(q); // Decompsoe in to euler angle XMStoreFloat4(qs.data(), q); x.segment<3>(i * 3) = qs.head<3>(); } }
void PeriodicConditionLM2D2N::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { if(rLeftHandSideMatrix.size1() != 6 || rLeftHandSideMatrix.size2() != 6) rLeftHandSideMatrix.resize(6, 6,false); noalias(rLeftHandSideMatrix) = ZeroMatrix(6, 6); if(rRightHandSideVector.size() != 6) rRightHandSideVector.resize(6, false); noalias( rRightHandSideVector ) = ZeroVector(6); // Nodal IDs = [slave ID, master ID] GeometryType& geom = GetGeometry(); // get current values and form the system matrix Vector currentValues(6); currentValues(0) = geom[0].FastGetSolutionStepValue(DISPLACEMENT_X); currentValues(1) = geom[0].FastGetSolutionStepValue(DISPLACEMENT_Y); currentValues(2) = geom[1].FastGetSolutionStepValue(DISPLACEMENT_X); currentValues(3) = geom[1].FastGetSolutionStepValue(DISPLACEMENT_Y); currentValues(4) = geom[0].FastGetSolutionStepValue(DISPLACEMENT_LAGRANGE_X); currentValues(5) = geom[0].FastGetSolutionStepValue(DISPLACEMENT_LAGRANGE_Y); //KRATOS_WATCH(currentValues); rLeftHandSideMatrix(4,0) = 1.0; rLeftHandSideMatrix(4,2) = -1.0; rLeftHandSideMatrix(0,4) = 1.0; rLeftHandSideMatrix(2,4) = -1.0; rLeftHandSideMatrix(5,1) = 1.0; rLeftHandSideMatrix(5,3) = -1.0; rLeftHandSideMatrix(1,5) = 1.0; rLeftHandSideMatrix(3,5) = -1.0; // form residual noalias(rRightHandSideVector) -= prod( rLeftHandSideMatrix, currentValues ); }
//************************************************************************************ //************************************************************************************ void Monolithic2DNeumann::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { if(rLeftHandSideMatrix.size1() != 4) { rLeftHandSideMatrix.resize(4,4,false); rRightHandSideVector.resize(4,false); } noalias(rLeftHandSideMatrix) = ZeroMatrix(4,4); //calculate normal to element.(normal follows the cross rule) array_1d<double,2> An,edge; edge[0] = GetGeometry()[1].X() - GetGeometry()[0].X(); edge[1] = GetGeometry()[1].Y() - GetGeometry()[0].Y(); double norm = edge[0]*edge[0] + edge[1]*edge[1]; norm = pow(norm,0.5); An[0] = -edge[1]; An[1] = edge[0]; //An /= norm; this is then simplified by length of element in integration so is not divided. double mean_ex_p = 0.0; for(unsigned int i = 0; i<2 ; i++) mean_ex_p += 0.5*GetGeometry()[i].FastGetSolutionStepValue(EXTERNAL_PRESSURE); double p0 = GetGeometry()[0].FastGetSolutionStepValue(EXTERNAL_PRESSURE); rRightHandSideVector[0] = -0.5*An[0]*p0; rRightHandSideVector[1] = -0.5*An[1]*p0; double p1 = GetGeometry()[1].FastGetSolutionStepValue(EXTERNAL_PRESSURE); rRightHandSideVector[2] = -0.5*An[0]*p1; rRightHandSideVector[3] = -0.5*An[1]*p1; // if(mean_ex_p !=GetGeometry()[0].FastGetSolutionStepValue(EXTERNAL_PRESSURE)) // mean_ex_p = 0.0; //KRATOS_WATCH(mean_ex_p); /* for(unsigned int ii = 0; ii< 2; ++ii) { int id = (2 + 1)*(ii); rRightHandSideVector[id] = mean_ex_p * An[0]* 0.5; rRightHandSideVector[id + 1] = mean_ex_p * An[1]* 0.5; rRightHandSideVector[id + 2] = 0.0; //KRATOS_WATCH(An); }*/ // KRATOS_WATCH(An); //KRATOS_WATCH(p0); //KRATOS_WATCH(p1); //KRATOS_WATCH("TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT"); // KRATOS_WATCH(rRightHandSideVector); }
void resize(VectorType & vec, size_t new_size) { vec.resize(new_size); }
//*********************************************************************************** //*********************************************************************************** void LineForce::CalculateRightHandSide( VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo ) { KRATOS_TRY const unsigned int number_of_nodes = GetGeometry().size(); const unsigned int dim = GetGeometry().WorkingSpaceDimension(); unsigned int MatSize = number_of_nodes * dim; //resizing as needed the RHS if ( rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize( MatSize, false ); rRightHandSideVector = ZeroVector( MatSize ); //resetting RHS //reading integration points and local gradients const GeometryType::IntegrationPointsArrayType& integration_points = GetGeometry().IntegrationPoints(); // DN_DeContainer is the array of shape function gradients at each integration points const GeometryType::ShapeFunctionsGradientsType& DN_DeContainer = GetGeometry().ShapeFunctionsLocalGradients(); // Ncontainer is the array of shape function values at each integration points const Matrix& Ncontainer = GetGeometry().ShapeFunctionsValues(); //loop over integration points Vector Load( dim ); Vector LoadOnNode( dim ); for ( unsigned int PointNumber = 0; PointNumber < integration_points.size(); ++PointNumber ) { noalias( Load ) = ZeroVector( dim ); for ( unsigned int n = 0; n < GetGeometry().size(); n++ ) { noalias( LoadOnNode ) = ( GetGeometry()[n] ).GetSolutionStepValue( FACE_LOAD ); for ( unsigned int i = 0; i < dim; i++ ) { Load( i ) += LoadOnNode( i ) * Ncontainer( PointNumber, n ); } } double IntegrationWeight = GetGeometry().IntegrationPoints()[PointNumber].Weight(); // if(dim == 2) IntegrationWeight *= GetProperties()[THICKNESS]; // TODO: check Vector t = ZeroVector( dim );//tangential vector for ( unsigned int n = 0; n < GetGeometry().size(); ++n ) { t[0] += GetGeometry().GetPoint( n ).X0() * DN_DeContainer[PointNumber]( n, 0 ); t[1] += GetGeometry().GetPoint( n ).Y0() * DN_DeContainer[PointNumber]( n, 0 ); if(dim == 3) t[2] += GetGeometry().GetPoint( n ).Z0() * DN_DeContainer[PointNumber]( n, 0 ); } // calculating length double dL = norm_2(t); // RIGHT HAND SIDE VECTOR for ( unsigned int prim = 0; prim < GetGeometry().size(); ++prim ) for ( unsigned int i = 0; i < dim; ++i ) rRightHandSideVector( prim * dim + i ) += Ncontainer( PointNumber, prim ) * Load( i ) * IntegrationWeight * dL; } KRATOS_CATCH( "" ) }
//************************************************************************************ //************************************************************************************ void Electrostatic2D::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { KRATOS_TRY const unsigned int number_of_points = GetGeometry().size(); if(rLeftHandSideMatrix.size1() != number_of_points) rLeftHandSideMatrix.resize(number_of_points,number_of_points,false); if(rRightHandSideVector.size() != number_of_points) rRightHandSideVector.resize(number_of_points,false); //getting data for the given geometry double Area; GeometryUtils::CalculateGeometryData(GetGeometry(), msDN_DX, msN, Area); //reading properties and conditions array_1d<double,3> permittivity = GetProperties()[ELECTRICAL_PERMITTIVITY]; msD(0,0)=permittivity[0]; msD(1,1)=permittivity[1]; msD(1,0)=0.0; msD(0,1)=0.0; //point_sources[0] = GetGeometry()[0].FastGetSolutionStepValue(ELECTROSTATIC_POINT_CHARGE); //point_sources[1] = GetGeometry()[1].FastGetSolutionStepValue(ELECTROSTATIC_POINT_CHARGE); //point_sources[2] = GetGeometry()[2].FastGetSolutionStepValue(ELECTROSTATIC_POINT_CHARGE); //double surface_sources = (this)->GetValue(ELECTROSTATIC_SURFACE_CHARGE); surface_sources[0] = (this)->GetValue(ELECTROSTATIC_SURFACE_CHARGE); surface_sources[1] = (this)->GetValue(ELECTROSTATIC_SURFACE_CHARGE); surface_sources[2] = (this)->GetValue(ELECTROSTATIC_SURFACE_CHARGE); //surface_sources[0] = GetGeometry()[0].FastGetSolutionStepValue(ELECTROSTATIC_SURFACE_CHARGE); //surface_sources[1] = GetGeometry()[1].FastGetSolutionStepValue(ELECTROSTATIC_SURFACE_CHARGE); //surface_sources[2] = GetGeometry()[2].FastGetSolutionStepValue(ELECTROSTATIC_SURFACE_CHARGE); // main loop const GeometryType::IntegrationPointsArrayType& integration_points = GetGeometry().IntegrationPoints(); noalias(rLeftHandSideMatrix) = prod(msDN_DX,Matrix(prod(msD,trans(msDN_DX)))); /* for(unsigned int k = 1; k<integration_points.size(); k++) //integration points { double w_detj = integration_points[k].Weight()*mDetJo[k]; */ rLeftHandSideMatrix *= Area; // } //Point charge contribution //noalias(rRightHandSideVector) = point_sources; //noalias(rRightHandSideVector) = point_sources/3.0; //+surface_sources*Area/3.0; noalias(rRightHandSideVector) = surface_sources*Area/3.0; //subtracting the dirichlet term // RHS -= LHS*ELECTROSTATIC_POTENTIALs for(unsigned int iii = 0; iii<number_of_points; iii++) ms_temp[iii] = GetGeometry()[iii].FastGetSolutionStepValue(ELECTROSTATIC_POTENTIAL); noalias(rRightHandSideVector) -= prod(rLeftHandSideMatrix,ms_temp); //multiplying by area, rho and density //rRightHandSideVector *= (Area * permittivity); //rLeftHandSideMatrix *= (Area * permittivity); KRATOS_CATCH(""); }
//---------------------- //----- PRIVATE ------ //---------------------- //*********************************************************************************** void FaceHeatConvection::CalculateAll( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, const ProcessInfo& rCurrentProcessInfo, bool CalculateStiffnessMatrixFlag, bool CalculateResidualVectorFlag ) { KRATOS_TRY const unsigned int number_of_nodes = GetGeometry().size(); unsigned int MatSize = number_of_nodes; //resizing as needed the LHS if ( CalculateStiffnessMatrixFlag == true ) //calculation of the matrix is required { if ( rLeftHandSideMatrix.size1() != MatSize ) rLeftHandSideMatrix.resize( MatSize, MatSize, false ); noalias( rLeftHandSideMatrix ) = ZeroMatrix( MatSize, MatSize ); //resetting LHS } //resizing as needed the RHS if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { if ( rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize( MatSize ); rRightHandSideVector = ZeroVector( MatSize ); //resetting RHS } //reading integration points and local gradients const GeometryType::IntegrationPointsArrayType& integration_points = GetGeometry().IntegrationPoints(); const GeometryType::ShapeFunctionsGradientsType& DN_DeContainer = GetGeometry().ShapeFunctionsLocalGradients(); const Matrix& Ncontainer = GetGeometry().ShapeFunctionsValues(); //calculating actual jacobian GeometryType::JacobiansType J; J = GetGeometry().Jacobian( J ); //auxiliary terms for ( unsigned int PointNumber = 0; PointNumber < integration_points.size(); PointNumber++ ) { double convection_coefficient = 0.0; double T_ambient = 0.0; double T = 0.0; for ( unsigned int n = 0; n < GetGeometry().size(); n++ ) { convection_coefficient += ( GetGeometry()[n] ).GetSolutionStepValue( CONVECTION_COEFFICIENT ) * Ncontainer( PointNumber, n ); T_ambient += ( GetGeometry()[n] ).GetSolutionStepValue( AMBIENT_TEMPERATURE ) * Ncontainer( PointNumber, n ); T += ( GetGeometry()[n] ).GetSolutionStepValue( TEMPERATURE ) * Ncontainer( PointNumber, n ); } // if ( PointNumber == 1 ) // std::cout << "CONDITION ### HeatConvection: h= " << convection_coefficient << ",\t T_ambient= " << T_ambient << ",\t T_surface= " << T << std::endl; double IntegrationWeight = GetGeometry().IntegrationPoints()[PointNumber].Weight(); Vector t1 = ZeroVector( 3 );//first tangential vector Vector t2 = ZeroVector( 3 );//second tangential vector for ( unsigned int n = 0; n < number_of_nodes; n++ ) { t1[0] += GetGeometry().GetPoint( n ).X0() * DN_DeContainer[PointNumber]( n, 0 ); t1[1] += GetGeometry().GetPoint( n ).Y0() * DN_DeContainer[PointNumber]( n, 0 ); t1[2] += GetGeometry().GetPoint( n ).Z0() * DN_DeContainer[PointNumber]( n, 0 ); t2[0] += GetGeometry().GetPoint( n ).X0() * DN_DeContainer[PointNumber]( n, 1 ); t2[1] += GetGeometry().GetPoint( n ).Y0() * DN_DeContainer[PointNumber]( n, 1 ); t2[2] += GetGeometry().GetPoint( n ).Z0() * DN_DeContainer[PointNumber]( n, 1 ); } //calculating normal Vector v3 = ZeroVector( 3 ); v3[0] = t1[1] * t2[2] - t1[2] * t2[1]; v3[1] = t1[2] * t2[0] - t1[0] * t2[2]; v3[2] = t1[0] * t2[1] - t1[1] * t2[0]; double dA = sqrt( v3[0] * v3[0] + v3[1] * v3[1] + v3[2] * v3[2] ); if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { for ( unsigned int n = 0; n < number_of_nodes; n++ ) rRightHandSideVector( n ) -= Ncontainer( PointNumber, n ) * convection_coefficient * ( T - T_ambient ) * IntegrationWeight * dA; // W/(m^2*°C) = kg*s^-3*°C°^-1 } if ( CalculateStiffnessMatrixFlag == true ) //calculation of the matrix is required { for ( unsigned int n = 0; n < number_of_nodes; n++ ) rLeftHandSideMatrix( n, n ) += Ncontainer( PointNumber, n ) * convection_coefficient * Ncontainer( PointNumber, n ) * IntegrationWeight * dA; // W/(m^2*°C) = kg*s^-3*°C°^-1 } } KRATOS_CATCH( "" ) }
//************************************************************************************ //************************************************************************************ //calculation by component of the fractional step velocity corresponding to the first stage void NDFluid2DCrankNicolson::Stage1(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo, unsigned int ComponentIndex) { KRATOS_TRY; const unsigned int number_of_points = 3; if(rLeftHandSideMatrix.size1() != number_of_points) rLeftHandSideMatrix.resize(number_of_points,number_of_points,false); //false says not to preserve existing storage!! if(rRightHandSideVector.size() != number_of_points) rRightHandSideVector.resize(number_of_points,false); //false says not to preserve existing storage!! //getting data for the given geometry double Area; GeometryUtils::CalculateGeometryData(GetGeometry(),msDN_DX,msN,Area); //getting the velocity vector on the nodes //getting the velocity on the nodes const array_1d<double,3>& fv0 = GetGeometry()[0].FastGetSolutionStepValue(FRACT_VEL,0); const array_1d<double,3>& fv0_old = GetGeometry()[0].FastGetSolutionStepValue(VELOCITY,1); const array_1d<double,3>& w0 = GetGeometry()[0].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& w0_old = GetGeometry()[0].FastGetSolutionStepValue(MESH_VELOCITY,1); const array_1d<double,3>& proj0 = GetGeometry()[0].FastGetSolutionStepValue(CONV_PROJ); const array_1d<double,3>& proj0_old = GetGeometry()[0].FastGetSolutionStepValue(CONV_PROJ,1); double p0old = GetGeometry()[0].FastGetSolutionStepValue(PRESSURE_OLD_IT); const double nu0 = GetGeometry()[0].FastGetSolutionStepValue(VISCOSITY); const double rho0 = GetGeometry()[0].FastGetSolutionStepValue(DENSITY); const double fcomp0 = GetGeometry()[0].FastGetSolutionStepValue(BODY_FORCE)[ComponentIndex]; const double eps0 = GetGeometry()[0].FastGetSolutionStepValue(POROSITY); const double dp0 = GetGeometry()[0].FastGetSolutionStepValue(DIAMETER); const array_1d<double,3>& fv1 = GetGeometry()[1].FastGetSolutionStepValue(FRACT_VEL); const array_1d<double,3>& fv1_old = GetGeometry()[1].FastGetSolutionStepValue(VELOCITY,1); const array_1d<double,3>& w1 = GetGeometry()[1].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& w1_old = GetGeometry()[1].FastGetSolutionStepValue(MESH_VELOCITY,1); const array_1d<double,3>& proj1 = GetGeometry()[1].FastGetSolutionStepValue(CONV_PROJ); double p1old = GetGeometry()[1].FastGetSolutionStepValue(PRESSURE_OLD_IT); const array_1d<double,3>& proj1_old = GetGeometry()[1].FastGetSolutionStepValue(CONV_PROJ,1); const double nu1 = GetGeometry()[1].FastGetSolutionStepValue(VISCOSITY); const double rho1 = GetGeometry()[1].FastGetSolutionStepValue(DENSITY); const double fcomp1 = GetGeometry()[1].FastGetSolutionStepValue(BODY_FORCE)[ComponentIndex]; const double eps1 = GetGeometry()[1].FastGetSolutionStepValue(POROSITY); const double dp1 = GetGeometry()[1].FastGetSolutionStepValue(DIAMETER); const array_1d<double,3>& fv2 = GetGeometry()[2].FastGetSolutionStepValue(FRACT_VEL); const array_1d<double,3>& fv2_old = GetGeometry()[2].FastGetSolutionStepValue(VELOCITY,1); const array_1d<double,3>& w2 = GetGeometry()[2].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& w2_old = GetGeometry()[2].FastGetSolutionStepValue(MESH_VELOCITY,1); const array_1d<double,3>& proj2 = GetGeometry()[2].FastGetSolutionStepValue(CONV_PROJ); const array_1d<double,3>& proj2_old = GetGeometry()[2].FastGetSolutionStepValue(CONV_PROJ,1); double p2old = GetGeometry()[2].FastGetSolutionStepValue(PRESSURE_OLD_IT); const double nu2 = GetGeometry()[2].FastGetSolutionStepValue(VISCOSITY); const double rho2 = GetGeometry()[2].FastGetSolutionStepValue(DENSITY); const double fcomp2 = GetGeometry()[2].FastGetSolutionStepValue(BODY_FORCE)[ComponentIndex]; const double eps2 = GetGeometry()[2].FastGetSolutionStepValue(POROSITY); const double dp2 = GetGeometry()[2].FastGetSolutionStepValue(DIAMETER); // // vel_gauss = sum( N[i]*(vel[i]-mesh_vel[i]), i=0, number_of_points) (note that the fractional step vel is used) ms_vel_gauss[0] = msN[0]*(fv0[0]-w0[0]) + msN[1]*(fv1[0]-w1[0]) + msN[2]*(fv2[0]-w2[0]); ms_vel_gauss[1] = msN[0]*(fv0[1]-w0[1]) + msN[1]*(fv1[1]-w1[1]) + msN[2]*(fv2[1]-w2[1]); //vel_gauss = sum( N[i]*(vel[i]-mesh_vel[i]), i=0, number_of_points) (note that the fractional step vel is used) ms_vel_gauss_old[0] = msN[0]*(fv0_old[0]-w0_old[0]) + msN[1]*(fv1_old[0]-w1_old[0]) + msN[2]*(fv2_old[0]-w2_old[0]); ms_vel_gauss_old[1] = msN[0]*(fv0_old[1]-w0_old[1]) + msN[1]*(fv1_old[1]-w1_old[1]) + msN[2]*(fv2_old[1]-w2_old[1]); //ms_vel_gauss = v at (n+1)/2; ms_vel_gauss[0] += ms_vel_gauss_old[0]; ms_vel_gauss[0] *= 0.5; ms_vel_gauss[1] += ms_vel_gauss_old[1]; ms_vel_gauss[1] *= 0.5; //calculating viscosity double nu = 0.333333333333333333333333*(nu0 + nu1 + nu2 ); double density = 0.3333333333333333333333*(rho0 + rho1 + rho2 ); //DIAMETER of the element double dp = 0.3333333333333333333333*(dp0 + dp1 + dp2); //POROSITY of the element: average value of the porosity double eps = 0.3333333333333333333333*(eps0 + eps1 + eps2 ); //1/PERMEABILITY of the element: average value of the porosity double kinv = 0.0; //Calculate the elemental Kinv in function of the nodal K of each element. //Version 1: we can calculate the elemental kinv from the nodal kinv; //THERE IS AN ERROR: IN THE INTERPHASE ELEMENTS A WATER NODE HAS TO BE ''MORE IMPORTANT'' THAN A POROUS ONE!!! // if(kinv0 != 0.0 || kinv1 != 0.0 || kinv2 != 0.0) //if it is a fluid element // { double k0 = 0.0; // double k1 = 0.0; // double k2 = 0.0; // if(kinv0 != 0.0) // k0 = 1.0/kinv0; // if(kinv1 != 0.0) // k1 = 1.0/kinv1; // if(kinv2 != 0.0) // k2 = 1.0/kinv2; // kinv = 3.0/(k0 + k1 + k2 ); // } // //Calculate kinv = 1/ k(eps_elem); // if(rLeftHandSideMatrix.size1() != number_of_points) // rLeftHandSideMatrix.resize(number_of_points,number_of_points,false); //Version 2:we can calculate the elemental kinv from the already calculate elemental eps; if( (eps0 != 1) | (eps1 != 1) | (eps2 != 1) ) kinv = 150*(1-eps)*(1-eps)/(eps*eps*eps*dp*dp); //getting the BDF2 coefficients (not fixed to allow variable time step) //the coefficients INCLUDE the time step //const Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS]; //Getting delta time value for the restriction over tau. double Dt = rCurrentProcessInfo[DELTA_TIME]; array_1d<double,2> BDFcoeffs = ZeroVector(2); BDFcoeffs[0]= 1.0 / Dt; //coeff for step n+1; BDFcoeffs[1]= -1.0 / Dt; //coeff for step n; //calculating parameter tau (saved internally to each element) double c1 = 4.00; double c2 = 2.00; double h = sqrt(2.00*Area); double norm_u = ms_vel_gauss[0]*ms_vel_gauss[0] + ms_vel_gauss[1]*ms_vel_gauss[1]; norm_u = sqrt(norm_u); //norm_u calculated at (n+1)/2;// double tau = 1.00 / ( c1*nu/(h*h) + c2*norm_u/h ); // ***************************************** //CALCULATION OF THE LHS //CONVECTIVE CONTRIBUTION TO THE STIFFNESS MATRIX noalias(ms_u_DN) = prod(msDN_DX , ms_vel_gauss); noalias(rLeftHandSideMatrix) = 0.5 * outer_prod(msN,ms_u_DN)/(eps*eps); //CONVECTION STABILIZING CONTRIBUTION (Suu) noalias(rLeftHandSideMatrix) += 0.5 * tau/(eps*eps) * outer_prod(ms_u_DN,ms_u_DN); //VISCOUS CONTRIBUTION TO THE STIFFNESS MATRIX // rLeftHandSideMatrix += Laplacian * nu; noalias(rLeftHandSideMatrix) += 0.5 * nu/eps * prod(msDN_DX,trans(msDN_DX)); //INERTIA CONTRIBUTION // rLeftHandSideMatrix += M/Dt noalias(rLeftHandSideMatrix) += BDFcoeffs[0] * msMassFactors/eps; //DARCY linear CONTRIBUTION // rLeftHandSideMatrix -= nu/permeability (using the cinematic viscosity it is already divided for density: then we are going to multiplicate for density again); noalias(rLeftHandSideMatrix) -= 0.5 * nu*msMassFactors*kinv; //DARCY non linear CONTRIBUTION (brinkmann) //rLeftHandSideMatrix -= 1.75*|u(n+1/2)|/[(150*k)^0.5*eps^(3/2)] noalias(rLeftHandSideMatrix) -= 0.5 * msMassFactors*norm_u*1.75*sqrt(kinv)/12.2474487/sqrt(eps*eps*eps); //multiplication by the area rLeftHandSideMatrix *= (Area * density); // ***************************************** //CALCULATION OF THE RHS //external forces (component) double force_component = 0.3333333333333333*(fcomp0 + fcomp1 + fcomp2); // KRATOS_WATCH(force_component); // KRATOS_WATCH(p0old); // KRATOS_WATCH(p1old); // KRATOS_WATCH(p2old); //adding pressure gradient (integrated by parts) noalias(rRightHandSideVector) = (force_component )*msN; //3PG------------- //p_avg turn out to be p0_avg p1_avg and p2_avg //3PG------------- double p_avg = msN[0]*p0old + msN[1]*p1old + msN[2]*p2old; p_avg /= density; // KRATOS_WATCH(p_avg); rRightHandSideVector[0] += msDN_DX(0,ComponentIndex)*p_avg; rRightHandSideVector[1] += msDN_DX(1,ComponentIndex)*p_avg; rRightHandSideVector[2] += msDN_DX(2,ComponentIndex)*p_avg; // KRATOS_WATCH(rRightHandSideVector); //adding the inertia terms // RHS += M*vhistory //calculating the historical velocity noalias(ms_temp_vec_np) = ZeroVector(3); for(int iii = 0; iii<3; iii++) { const array_1d<double,3>& v = (GetGeometry()[iii].FastGetSolutionStepValue(VELOCITY,1) ); ms_temp_vec_np[iii] = BDFcoeffs[1]*v[ComponentIndex]; } noalias(rRightHandSideVector) -= prod(msMassFactors,ms_temp_vec_np)/eps ; // KRATOS_WATCH(prod(msMassFactors,ms_temp_vec_np)/eps); //3PG------------- //proj_component calculated on the 3 gauss points //3PG------------- //RHS += Suy * proj[component] double proj_component = msN[0]*proj0[ComponentIndex] + msN[1]*proj1[ComponentIndex] + msN[2]*proj2[ComponentIndex]; double proj_old_component = msN[0]*proj0_old[ComponentIndex] + msN[1]*proj1_old[ComponentIndex] + msN[2]*proj2_old[ComponentIndex]; proj_component += proj_old_component; proj_component *= 0.5; //proj_component calculate in t_n+1/2; noalias(rRightHandSideVector) += (tau*proj_component)/(eps*eps)*ms_u_DN; //multiplying by area rRightHandSideVector *= (Area * density); ms_temp_vec_np[0] = fv0_old[ComponentIndex]; ms_temp_vec_np[1] = fv1_old[ComponentIndex]; ms_temp_vec_np[2] = fv2_old[ComponentIndex]; //there is a part of the lhs which is already included; for(int iii = 0; iii<3; iii++) { ms_temp_vec_np[iii] *= BDFcoeffs[0]; } noalias(rRightHandSideVector) += (Area * density)*prod(msMassFactors,ms_temp_vec_np)/eps ; // KRATOS_WATCH((Area * density)*prod(msMassFactors,ms_temp_vec_np)/eps); //suubtracting the dirichlet term // RHS -= LHS*FracVel ms_temp_vec_np[0] = fv0[ComponentIndex] + fv0_old[ComponentIndex]; ms_temp_vec_np[1] = fv1[ComponentIndex] + fv1_old[ComponentIndex]; ms_temp_vec_np[2] = fv2[ComponentIndex] + fv2_old[ComponentIndex]; noalias(rRightHandSideVector) -= prod(rLeftHandSideMatrix,ms_temp_vec_np); // KRATOS_WATCH(prod(rLeftHandSideMatrix,ms_temp_vec_np)); // // KRATOS_WATCH(fv0); // KRATOS_WATCH(fv1); // KRATOS_WATCH(fv2); // KRATOS_WATCH(fv0_old); // KRATOS_WATCH(fv1_old); // KRATOS_WATCH(fv2_old); // KRATOS_WATCH(rRightHandSideVector); KRATOS_CATCH(""); }
void TwoStepPeriodicCondition<TDim>::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { rLeftHandSideMatrix.resize(0,0,false); rRightHandSideVector.resize(0,false); }
/** * calculates only the RHS vector (certainly to be removed due to contact algorithm) */ void SlaveContactFace3DNewmark::CalculateRightHandSide( VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { rRightHandSideVector.resize(0,false); }
//************************************************************************************ //************************************************************************************ //calculation by component of the fractional step velocity corresponding to the first stage void NDFluid2DCrankNicolson::Stage2(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { KRATOS_TRY; unsigned int number_of_points = 3; if(rLeftHandSideMatrix.size1() != number_of_points) rLeftHandSideMatrix.resize(number_of_points,number_of_points,false); if(rRightHandSideVector.size() != number_of_points) rRightHandSideVector.resize(number_of_points,false); //getting data for the given geometry double Area; GeometryUtils::CalculateGeometryData(GetGeometry(),msDN_DX,msN,Area); const array_1d<double,3>& fv0 = GetGeometry()[0].FastGetSolutionStepValue(FRACT_VEL); const array_1d<double,3>& w0 = GetGeometry()[0].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& proj0 = GetGeometry()[0].FastGetSolutionStepValue(PRESS_PROJ); double p0 = GetGeometry()[0].FastGetSolutionStepValue(PRESSURE); double p0old = GetGeometry()[0].FastGetSolutionStepValue(PRESSURE_OLD_IT); const double nu0 = GetGeometry()[0].FastGetSolutionStepValue(VISCOSITY); const double rho0 = GetGeometry()[0].FastGetSolutionStepValue(DENSITY); const double eps0 = GetGeometry()[0].FastGetSolutionStepValue(POROSITY); const array_1d<double,3>& fv1 = GetGeometry()[1].FastGetSolutionStepValue(FRACT_VEL); const array_1d<double,3>& w1 = GetGeometry()[1].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& proj1 = GetGeometry()[1].FastGetSolutionStepValue(PRESS_PROJ); double p1 = GetGeometry()[1].FastGetSolutionStepValue(PRESSURE); double p1old = GetGeometry()[1].FastGetSolutionStepValue(PRESSURE_OLD_IT); const double nu1 = GetGeometry()[1].FastGetSolutionStepValue(VISCOSITY); const double rho1 = GetGeometry()[1].FastGetSolutionStepValue(DENSITY); const double eps1 = GetGeometry()[1].FastGetSolutionStepValue(POROSITY); const array_1d<double,3>& fv2 = GetGeometry()[2].FastGetSolutionStepValue(FRACT_VEL); const array_1d<double,3>& w2 = GetGeometry()[2].FastGetSolutionStepValue(MESH_VELOCITY); const array_1d<double,3>& proj2 = GetGeometry()[2].FastGetSolutionStepValue(PRESS_PROJ); double p2 = GetGeometry()[2].FastGetSolutionStepValue(PRESSURE); double p2old = GetGeometry()[2].FastGetSolutionStepValue(PRESSURE_OLD_IT); const double nu2 = GetGeometry()[2].FastGetSolutionStepValue(VISCOSITY); const double rho2 = GetGeometry()[2].FastGetSolutionStepValue(DENSITY); const double eps2 = GetGeometry()[2].FastGetSolutionStepValue(POROSITY); //3PG------------- //ms_vel_gauss //3PG------------- // vel_gauss = sum( N[i]*(vel[i]-mesh_vel[i]), i=0, number_of_points) (note that the fractional step vel is used) ms_vel_gauss[0] = msN[0]*(fv0[0]-w0[0]) + msN[1]*(fv1[0]-w1[0]) + msN[2]*(fv2[0]-w2[0]); ms_vel_gauss[1] = msN[0]*(fv0[1]-w0[1]) + msN[1]*(fv1[1]-w1[1]) + msN[2]*(fv2[1]-w2[1]); //calculating convective auxiliary vector //3PG------------- //ms_u_DN //3PG------------- noalias(ms_u_DN) = prod(msDN_DX , ms_vel_gauss); //calculating average density and viscosity double nu = 0.33333333333333*(nu0 + nu1 + nu2 ); double density = 0.33333333333333*(rho0 + rho1 + rho2 ); //DIAMETER of the element //double dp = 0.33333333333333*(d0+d1+d2) //POROSITY of the element: average value of the porosity double eps = 0.3333333333333333333333*(eps0 + eps1 + eps2 ); //Getting delta time value for the restriction over tau. double Dt = rCurrentProcessInfo[DELTA_TIME]; //calculating parameter tau (saved internally to each element) double h = sqrt(2.00*Area); double norm_u = ms_vel_gauss[0]*ms_vel_gauss[0] + ms_vel_gauss[1]*ms_vel_gauss[1]; norm_u = sqrt(norm_u); double tau = 1.00 / ( 4.00*nu/(h*h) + 2.00*norm_u/h ); //tau = min{tau; Dt} if(tau > Dt) { tau = Dt; } //getting the BDF2 coefficients (not fixed to allow variable time step) //the coefficients INCLUDE the time step const Vector& BDFcoeffs = rCurrentProcessInfo[BDF_COEFFICIENTS]; //CALCULATION OF THE LEFT HAND SIDE //laplacian term L = Dt * gradN *eps * trans(gradN); //stabilization term Spp = tau * gradN * eps * trans(gradN); noalias(rLeftHandSideMatrix) = ((1.00/BDFcoeffs[0] + tau)/density*eps) * prod(msDN_DX,trans(msDN_DX)); //calculation of the RHS // RHS = -G*vfrac double Gaux; Gaux = msDN_DX(0,0)*fv0[0] + msDN_DX(0,1)*fv0[1]; Gaux += msDN_DX(1,0)*fv1[0] + msDN_DX(1,1)*fv1[1]; Gaux += msDN_DX(2,0)*fv2[0] + msDN_DX(2,1)*fv2[1]; rRightHandSideVector[0] = - Gaux * msN[0]; rRightHandSideVector[1] = - Gaux * msN[1]; rRightHandSideVector[2] = - Gaux * msN[2]; //attention!! changing the meaning of ms_vel_gauss //Inserting the influence of POROSITY! // RHS += Sz * proj*eps //contrib of Spy*proj ms_vel_gauss[0] = msN[0]*proj0[0] + msN[1]*proj1[0] + msN[2]*proj2[0]; ms_vel_gauss[1] = msN[0]*proj0[1] + msN[1]*proj1[1] + msN[2]*proj2[1]; ms_vel_gauss *= tau*eps; noalias(rRightHandSideVector) += prod(msDN_DX , ms_vel_gauss); //dirichlet contribution ms_temp_vec_np[0] = p0; ms_temp_vec_np[1] = p1; ms_temp_vec_np[2] = p2; noalias(rRightHandSideVector) -= prod(rLeftHandSideMatrix,ms_temp_vec_np); // RHS += dt * L *eps* pold ms_temp_vec_np[0] = p0old; ms_temp_vec_np[1] = p1old; ms_temp_vec_np[2] = p2old; noalias(ms_vel_gauss) = prod(trans(msDN_DX),ms_temp_vec_np); noalias(rRightHandSideVector) += (1.00/BDFcoeffs[0]/density*eps) * prod(msDN_DX,ms_vel_gauss); //multiplicating by the area rLeftHandSideMatrix *= Area; rRightHandSideVector *= Area; //adding contributions to nodal areas following the corresponding lumping term double nodal_contrib = 0.333333333333333333333333333 * Area*density; GetGeometry()[0].FastGetSolutionStepValue(NODAL_MASS) += nodal_contrib; GetGeometry()[1].FastGetSolutionStepValue(NODAL_MASS) += nodal_contrib; GetGeometry()[2].FastGetSolutionStepValue(NODAL_MASS) += nodal_contrib; KRATOS_CATCH(""); }
void resize_vector(VectorType & vec, unsigned int size) { vec.resize(size); }
//*********************************************************************************** //*********************************************************************************** void FaceForce3D::CalculateAll( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, const ProcessInfo& rCurrentProcessInfo, bool CalculateStiffnessMatrixFlag, bool CalculateResidualVectorFlag ) { KRATOS_TRY const unsigned int number_of_nodes = GetGeometry().size(); unsigned int MatSize = number_of_nodes * 3; const unsigned int dim = 3; //resizing as needed the LHS if ( CalculateStiffnessMatrixFlag == true ) //calculation of the matrix is required { if ( rLeftHandSideMatrix.size1() != MatSize ) rLeftHandSideMatrix.resize( MatSize, MatSize, false ); noalias( rLeftHandSideMatrix ) = ZeroMatrix( MatSize, MatSize ); //resetting LHS } //resizing as needed the RHS if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { if ( rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize( MatSize, false ); rRightHandSideVector = ZeroVector( MatSize ); //resetting RHS } //reading integration points and local gradients const GeometryType::IntegrationPointsArrayType& integration_points = GetGeometry().IntegrationPoints(); const GeometryType::ShapeFunctionsGradientsType& DN_DeContainer = GetGeometry().ShapeFunctionsLocalGradients(); const Matrix& Ncontainer = GetGeometry().ShapeFunctionsValues(); //calculating actual jacobian GeometryType::JacobiansType J; J = GetGeometry().Jacobian( J ); //auxiliary terms array_1d<double, 3> BodyForce; //this should be used once the implementation of the Jacobian is correct in all geometries // array_1d<double,3> ge; // array_1d<double,3> gn; // array_1d<double,3> v3; //loop over integration points for ( unsigned int PointNumber = 0; PointNumber < integration_points.size(); PointNumber++ ) { Vector Load( 3 ); noalias( Load ) = ZeroVector( 3 ); Vector temp( 3 ); for ( unsigned int n = 0; n < GetGeometry().size(); n++ ) { noalias( temp ) = ( GetGeometry()[n] ).GetSolutionStepValue( FACE_LOAD ); for ( unsigned int i = 0; i < 3; i++ ) { Load( i ) += temp( i ) * Ncontainer( PointNumber, n ); } } double IntegrationWeight = GetGeometry().IntegrationPoints()[PointNumber].Weight(); //to be replaced by the formulation in Face3D Vector t1 = ZeroVector( 3 );//first tangential vector Vector t2 = ZeroVector( 3 );//second tangential vector for ( unsigned int n = 0; n < GetGeometry().size(); n++ ) { t1[0] += GetGeometry().GetPoint( n ).X0() * DN_DeContainer[PointNumber]( n, 0 ); t1[1] += GetGeometry().GetPoint( n ).Y0() * DN_DeContainer[PointNumber]( n, 0 ); t1[2] += GetGeometry().GetPoint( n ).Z0() * DN_DeContainer[PointNumber]( n, 0 ); t2[0] += GetGeometry().GetPoint( n ).X0() * DN_DeContainer[PointNumber]( n, 1 ); t2[1] += GetGeometry().GetPoint( n ).Y0() * DN_DeContainer[PointNumber]( n, 1 ); t2[2] += GetGeometry().GetPoint( n ).Z0() * DN_DeContainer[PointNumber]( n, 1 ); } //calculating normal Vector v3 = ZeroVector( 3 ); v3[0] = t1[1] * t2[2] - t1[2] * t2[1]; v3[1] = t1[2] * t2[0] - t1[0] * t2[2]; v3[2] = t1[0] * t2[1] - t1[1] * t2[0]; double dA = sqrt( v3[0] * v3[0] + v3[1] * v3[1] + v3[2] * v3[2] ); // RIGHT HAND SIDE VECTOR if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { for ( unsigned int prim = 0; prim < GetGeometry().size(); prim++ ) for ( unsigned int i = 0; i < 3; i++ ) rRightHandSideVector( prim*dim + i ) += Ncontainer( PointNumber, prim ) * Load( i ) * IntegrationWeight * dA; } } KRATOS_CATCH( "" ) }
//************************************************************************************ //************************************************************************************ void UpdatedLagrangianFluid3Dinc::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, 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)); double K = 0.25* (GetGeometry()[0].FastGetSolutionStepValue(BULK_MODULUS)+ GetGeometry()[1].FastGetSolutionStepValue(BULK_MODULUS) + GetGeometry()[2].FastGetSolutionStepValue(BULK_MODULUS)+ GetGeometry()[3].FastGetSolutionStepValue(BULK_MODULUS)); K *= density; //unsigned int dim = 3; unsigned int number_of_nodes = 4; if(rLeftHandSideMatrix.size1() != 12) rLeftHandSideMatrix.resize(12,12,false); if(rRightHandSideVector.size() != 12) rRightHandSideVector.resize(12,false); //calculate current area double current_volume; GeometryUtils::CalculateGeometryData(GetGeometry(), msDN_Dx, msN, current_volume); //writing the body force const array_1d<double,3>& body_force = 0.25*(GetGeometry()[0].FastGetSolutionStepValue(BODY_FORCE)+ GetGeometry()[1].FastGetSolutionStepValue(BODY_FORCE) + GetGeometry()[2].FastGetSolutionStepValue(BODY_FORCE) + GetGeometry()[3].FastGetSolutionStepValue(BODY_FORCE)); for(unsigned int i = 0; i<number_of_nodes; i++) { rRightHandSideVector[i*3] = body_force[0]* density * mA0 * 0.25; rRightHandSideVector[i*3+1] = body_force[1] * density * mA0 * 0.25; rRightHandSideVector[i*3+2] = body_force[2] * density * mA0 * 0.25; } /* //VISCOUS CONTRIBUTION TO THE STIFFNESS MATRIX // rLeftHandSideMatrix += Laplacian * nu; //filling matrix B for (unsigned int i=0;i<number_of_nodes;i++) { unsigned int index = dim*i; msB(0,index+0)=msDN_Dx(i,0); msB(0,index+1)= 0.0; msB(1,index+0)=0.0; msB(1,index+1)= msDN_Dx(i,1); msB(2,index+0)= msDN_Dx(i,1); msB(2,index+1)= msDN_Dx(i,0); } //constitutive tensor ms_constitutive_matrix(0,0) = K; ms_constitutive_matrix(0,1) = K ; ms_constitutive_matrix(0,2) = 0.0; ms_constitutive_matrix(1,0) = K; ms_constitutive_matrix(1,1) = K; ms_constitutive_matrix(1,2) = 0.0; ms_constitutive_matrix(2,0) = 0.0; ms_constitutive_matrix(2,1) = 0.0; ms_constitutive_matrix(2,2) = 0.0; //calculating viscous contributions ms_temp = prod( ms_constitutive_matrix , msB); noalias(rLeftHandSideMatrix) = prod( trans(msB) , ms_temp); rLeftHandSideMatrix *= -current_area; */ noalias(rLeftHandSideMatrix) = ZeroMatrix(12,12); //get the nodal pressure double p0 = GetGeometry()[0].FastGetSolutionStepValue(PRESSURE); double p1 = GetGeometry()[1].FastGetSolutionStepValue(PRESSURE); double p2 = GetGeometry()[2].FastGetSolutionStepValue(PRESSURE); double p3 = GetGeometry()[3].FastGetSolutionStepValue(PRESSURE); //adding pressure gradient double pavg = p0 + p1 + p2 + p3; //calculate old pressure over the element pavg *= 0.25 * current_volume; rRightHandSideVector[0] += msDN_Dx(0,0)*pavg; rRightHandSideVector[1] += msDN_Dx(0,1)*pavg; rRightHandSideVector[2] += msDN_Dx(0,2)*pavg; rRightHandSideVector[3] += msDN_Dx(1,0)*pavg; rRightHandSideVector[4] += msDN_Dx(1,1)*pavg; rRightHandSideVector[5] += msDN_Dx(1,2)*pavg; rRightHandSideVector[6] += msDN_Dx(2,0)*pavg; rRightHandSideVector[7] += msDN_Dx(2,1)*pavg; rRightHandSideVector[8] += msDN_Dx(2,2)*pavg; rRightHandSideVector[9] += msDN_Dx(3,0)*pavg; rRightHandSideVector[10] += msDN_Dx(3,1)*pavg; rRightHandSideVector[11] += msDN_Dx(3,2)*pavg; KRATOS_CATCH("") }
//************************************************************************************ //************************************************************************************ void UpdatedLagrangianFluid3Dinc::CalculateRightHandSide(VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { const double& density = 0.25*(GetGeometry()[0].FastGetSolutionStepValue(DENSITY)+ GetGeometry()[1].FastGetSolutionStepValue(DENSITY) + GetGeometry()[2].FastGetSolutionStepValue(DENSITY)+ GetGeometry()[3].FastGetSolutionStepValue(DENSITY)); double K = 0.25*(GetGeometry()[0].FastGetSolutionStepValue(BULK_MODULUS)+ GetGeometry()[1].FastGetSolutionStepValue(BULK_MODULUS) + GetGeometry()[2].FastGetSolutionStepValue(BULK_MODULUS)+ GetGeometry()[3].FastGetSolutionStepValue(BULK_MODULUS)); K *= density; // KRATOS_THROW_ERROR(std::logic_error,"not goooood",""); if(rRightHandSideVector.size() != 12) rRightHandSideVector.resize(12,false); unsigned int number_of_nodes = GetGeometry().size(); //calculate current area double current_volume; GeometryUtils::CalculateGeometryData(GetGeometry(), msDN_Dx, msN, current_volume); //writing the body force const array_1d<double,3>& body_force = 0.25*(GetGeometry()[0].FastGetSolutionStepValue(BODY_FORCE)+ GetGeometry()[1].FastGetSolutionStepValue(BODY_FORCE) + GetGeometry()[2].FastGetSolutionStepValue(BODY_FORCE)+ GetGeometry()[3].FastGetSolutionStepValue(BODY_FORCE)); for(unsigned int i = 0; i<number_of_nodes; i++) { rRightHandSideVector[i*3] = body_force[0]* density * mA0 * 0.25; rRightHandSideVector[i*3+1] = body_force[1] * density * mA0 * 0.25; rRightHandSideVector[i*3+2] = body_force[2] * density * mA0 * 0.25; } //get the nodal pressure double p0 = GetGeometry()[0].FastGetSolutionStepValue(PRESSURE); double p1 = GetGeometry()[1].FastGetSolutionStepValue(PRESSURE); double p2 = GetGeometry()[2].FastGetSolutionStepValue(PRESSURE); double p3 = GetGeometry()[3].FastGetSolutionStepValue(PRESSURE); //adding pressure gradient double pavg = p0 + p1 + p2 + p3; //calculate old pressure over the element pavg *= 0.25 * current_volume; rRightHandSideVector[0] += msDN_Dx(0,0)*pavg; rRightHandSideVector[1] += msDN_Dx(0,1)*pavg; rRightHandSideVector[2] += msDN_Dx(0,2)*pavg; rRightHandSideVector[3] += msDN_Dx(1,0)*pavg; rRightHandSideVector[4] += msDN_Dx(1,1)*pavg; rRightHandSideVector[5] += msDN_Dx(1,2)*pavg; rRightHandSideVector[6] += msDN_Dx(2,0)*pavg; rRightHandSideVector[7] += msDN_Dx(2,1)*pavg; rRightHandSideVector[8] += msDN_Dx(2,2)*pavg; rRightHandSideVector[9] += msDN_Dx(3,0)*pavg; rRightHandSideVector[10] += msDN_Dx(3,1)*pavg; rRightHandSideVector[11] += msDN_Dx(3,2)*pavg; }
void TotalLagrangian::CalculateAll( MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo, bool CalculateStiffnessMatrixFlag, bool CalculateResidualVectorFlag ) { KRATOS_TRY const unsigned int number_of_nodes = GetGeometry().size(); const unsigned int dim = GetGeometry().WorkingSpaceDimension(); unsigned int StrainSize; if ( dim == 2 ) StrainSize = 3; else StrainSize = 6; Matrix B( StrainSize, number_of_nodes * dim ); Matrix F( dim, dim ); Matrix D( StrainSize, StrainSize ); Matrix C( dim, dim ); Vector StrainVector( StrainSize ); Vector StressVector( StrainSize ); Matrix DN_DX( number_of_nodes, dim ); //resizing as needed the LHS unsigned int MatSize = number_of_nodes * dim; if ( CalculateStiffnessMatrixFlag == true ) //calculation of the matrix is required { if ( rLeftHandSideMatrix.size1() != MatSize ) rLeftHandSideMatrix.resize( MatSize, MatSize, false ); noalias( rLeftHandSideMatrix ) = ZeroMatrix( MatSize, MatSize ); //resetting LHS } //resizing as needed the RHS if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { if ( rRightHandSideVector.size() != MatSize ) rRightHandSideVector.resize( MatSize, false ); rRightHandSideVector = ZeroVector( MatSize ); //resetting RHS } //reading integration points and local gradients const GeometryType::IntegrationPointsArrayType& integration_points = GetGeometry().IntegrationPoints( mThisIntegrationMethod ); const GeometryType::ShapeFunctionsGradientsType& DN_De = GetGeometry().ShapeFunctionsLocalGradients( mThisIntegrationMethod ); const Matrix& Ncontainer = GetGeometry().ShapeFunctionsValues( mThisIntegrationMethod ); //calculating actual jacobian GeometryType::JacobiansType J; GetGeometry().Jacobian( J ); //KRATOS_WATCH(J) //auxiliary terms Vector BodyForce; for ( unsigned int PointNumber = 0; PointNumber < integration_points.size(); PointNumber++ ) { //Calculating the cartesian derivatives (it is avoided storing them to minimize storage) noalias( DN_DX ) = prod( DN_De[PointNumber], mInvJ0[PointNumber] ); //deformation gradient noalias( F ) = prod( J[PointNumber], mInvJ0[PointNumber] ); //strain calculation noalias( C ) = prod( trans( F ), F ); CalculateStrain( C, StrainVector ); Comprobate_State_Vector( StrainVector ); mConstitutiveLawVector[PointNumber]->CalculateMaterialResponse( StrainVector, F, StressVector, D, rCurrentProcessInfo, GetProperties(), GetGeometry(), row( Ncontainer, PointNumber ), true, CalculateStiffnessMatrixFlag, true ); //calculating operator B CalculateB( B, F, DN_DX, StrainVector.size() ); //calculating weights for integration on the reference configuration double IntToReferenceWeight = integration_points[PointNumber].Weight() * mDetJ0[PointNumber]; if ( dim == 2 ) IntToReferenceWeight *= GetProperties()[THICKNESS]; if ( CalculateStiffnessMatrixFlag == true ) //calculation of the matrix is required { //contributions to stiffness matrix calculated on the reference config noalias( rLeftHandSideMatrix ) += prod( trans( B ), ( IntToReferenceWeight ) * Matrix( prod( D, B ) ) ); //to be optimized to remove the temporary CalculateAndAddKg( rLeftHandSideMatrix, DN_DX, StressVector, IntToReferenceWeight ); } if ( CalculateResidualVectorFlag == true ) //calculation of the matrix is required { //contribution to external forces BodyForce = GetProperties()[BODY_FORCE]; // operation performed: rRightHandSideVector += ExtForce*IntToReferenceWeight CalculateAndAdd_ExtForceContribution( row( Ncontainer, PointNumber ), rCurrentProcessInfo, BodyForce, rRightHandSideVector, IntToReferenceWeight ); // operation performed: rRightHandSideVector -= IntForce*IntToReferenceWeight noalias( rRightHandSideVector ) -= IntToReferenceWeight * prod( trans( B ), StressVector ); } } KRATOS_CATCH( "" ) }
void assemble(MeshType & mesh, MatrixType & system_matrix, VectorType & load_vector) { typedef typename viennagrid::result_of::cell<MeshType>::type CellType; typedef typename viennagrid::result_of::vertex<MeshType>::type VertexType; typedef typename viennagrid::result_of::line<MeshType>::type EdgeType; typedef typename viennagrid::result_of::vertex_range<MeshType>::type VertexContainer; typedef typename viennagrid::result_of::iterator<VertexContainer>::type VertexIterator; typedef typename viennagrid::result_of::coboundary_range<MeshType, viennagrid::vertex_tag, viennagrid::line_tag>::type EdgeOnVertexContainer; typedef typename viennagrid::result_of::iterator<EdgeOnVertexContainer>::type EdgeOnVertexIterator; std::size_t current_dof = 0; // // Compute Voronoi info // typedef typename viennagrid::result_of::const_cell_handle<MeshType>::type ConstCellHandleType; std::deque<double> interface_areas; std::deque< typename viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > interface_contributions; std::deque<double> vertex_box_volumes; std::deque< typename viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > vertex_box_volume_contributions; std::deque<double> edge_box_volumes; std::deque< typename viennagrid::result_of::voronoi_cell_contribution<ConstCellHandleType>::type > edge_box_volume_contributions; // Write Voronoi info to default ViennaData keys: viennagrid::apply_voronoi<CellType>( mesh, viennagrid::make_accessor<EdgeType>(interface_areas), viennagrid::make_accessor<EdgeType>(interface_contributions), viennagrid::make_accessor<VertexType>(vertex_box_volumes), viennagrid::make_accessor<VertexType>(vertex_box_volume_contributions), viennagrid::make_accessor<EdgeType>(edge_box_volumes), viennagrid::make_accessor<EdgeType>(edge_box_volume_contributions) ); typename viennagrid::result_of::accessor< std::deque<double>, EdgeType >::type interface_area_accessor( interface_areas ); typename viennagrid::result_of::accessor< std::deque<double>, EdgeType >::type edge_box_volume_accessor( edge_box_volumes ); std::deque<long> dof_container; typename viennagrid::result_of::accessor< std::deque<long>, VertexType >::type dof_accessor( dof_container ); // // Iterate over all vertices in the mesh and enumerate degrees of freedom (aka. unknown indices) // VertexContainer vertices = viennagrid::elements<viennagrid::vertex_tag>(mesh); for (VertexIterator vit = vertices.begin(); vit != vertices.end(); ++vit) { //boundary condition: Assuming homogeneous Dirichlet boundary conditions at x=0 and x=1 //if ( (vit->point()[0] == 0) || (vit->point()[0] == 1) ) if ( (viennagrid::point(mesh, *vit)[0] == 0) || (viennagrid::point(mesh, *vit)[0] == 1) ) dof_accessor(*vit) = -1; else { dof_accessor(*vit) = current_dof; ++current_dof; } } std::cout << "Assigned degrees of freedom: " << current_dof << std::endl; //resize global system matrix and load vector to the number of unknowns: system_matrix.resize(current_dof, current_dof); load_vector.resize(current_dof); // // Poisson equation assembly: div( grad(psi) ) = 1 // for (VertexIterator vhit = vertices.begin(); vhit != vertices.end(); ++vhit) { VertexType & vertex = *vhit; long row_index = dof_accessor(vertex); //std::cout << vertex << " " << row_index << std::endl; if (row_index < 0) //this is a Dirichlet boundary condition continue; //EdgeOnVertexContainer edges = viennagrid::ncells<1>(*vit, mesh); EdgeOnVertexContainer edges = viennagrid::coboundary_elements<viennagrid::vertex_tag, viennagrid::line_tag>(mesh, vhit.handle()); for (EdgeOnVertexIterator eovit = edges.begin(); eovit != edges.end(); ++eovit) { VertexType const * other_vertex_ptr = &(viennagrid::elements<viennagrid::vertex_tag>(*eovit)[0]); if (other_vertex_ptr == &(vertex)) //one of the two vertices of the edge is different from *vit other_vertex_ptr = &(viennagrid::elements<viennagrid::vertex_tag>(*eovit)[1]); long col_index = dof_accessor(*other_vertex_ptr); double edge_len = viennagrid::volume(*eovit); double interface_area = interface_area_accessor(*eovit); //std::cout << " " << *other_vertex_ptr << std::endl; //std::cout << " " << col_index << " " << edge_len << " " << interface_area << std::endl; if (col_index >= 0) system_matrix(row_index, col_index) = - interface_area / edge_len; system_matrix(row_index, row_index) += interface_area / edge_len; //std::cout << " " << system_matrix(row_index, col_index) << " " << system_matrix(row_index, row_index) << std::endl; //std::cout << std::endl; //Note: volume stored on edges consists of volumes of both adjacent boxes. load_vector[row_index] += edge_box_volume_accessor(*eovit) / 2.0; } //for edges } //for vertices } //assemble()
//************************************************************************************ //************************************************************************************ void MeshlessLagrangeCouplingCondition::CalculateLocalSystem(MatrixType& rLeftHandSideMatrix, VectorType& rRightHandSideVector, ProcessInfo& rCurrentProcessInfo) { KRATOS_TRY const unsigned int number_of_points = GetGeometry().size(); //system equation contains of [(3 displacments)*number_of_points + (3 Lagrange Multipliers)*number_of_points] //LHS if (rLeftHandSideMatrix.size1() != number_of_points * 6) rLeftHandSideMatrix.resize(number_of_points * 6, number_of_points * 6, false); noalias(rLeftHandSideMatrix) = ZeroMatrix(number_of_points * 6, number_of_points * 6); //resetting LHS //RHS if (rRightHandSideVector.size() != number_of_points * 6) rRightHandSideVector.resize(number_of_points * 6, false); rRightHandSideVector = ZeroVector(number_of_points * 6); //resetting RHS const double& Weighting = this->GetValue(INTEGRATION_WEIGHT); const Vector& localTrimTangents = this->GetValue(TANGENTS); const Vector& ShapeFunctionsN = this->GetValue(SHAPE_FUNCTION_VALUES); const Matrix& DN_DeMaster = this->GetValue(SHAPE_FUNCTION_LOCAL_DERIVATIVES_MASTER); //For ROTATIONAL SUPPORT Vector Phi_r = ZeroVector(number_of_points * 3); Vector Phi_r_Lambda = ZeroVector(number_of_points * 3); Matrix Phi_rs = ZeroMatrix(number_of_points * 3, number_of_points * 3); array_1d<double, 2> Diff_Phi; Diff_Phi.clear(); CaculateRotationalShapeFunctions(Phi_r, Phi_r_Lambda, Phi_rs, Diff_Phi); //SHAPE_FUNCTION_VALUES has first the shape functions of the displacements, // then the shape functions of the Lagrange Multipliers for (unsigned int i = number_of_points; i < 2*number_of_points; i++) //loop over Lagrange Multipliers { for (unsigned int j = 0; j < number_of_points; j++) // lopp over shape functions of displacements { double NN = ShapeFunctionsN[j] * ShapeFunctionsN[i]; //lambda in X rLeftHandSideMatrix(i * 3, 3 * j) = NN + Phi_r_Lambda((i - number_of_points) * 3 ) * Phi_r(j * 3);//Phi_r_Lambda((i - number_of_points)*3)*Phi_r(j*3); ShapeFunctionsN[i] * Phi_r(j * 3);// //lambda in Y rLeftHandSideMatrix(i * 3 + 1, 3 * j + 1) = NN + Phi_r_Lambda((i - number_of_points) * 3+1) * Phi_r(j * 3+1); //lambda in Z; rLeftHandSideMatrix(i * 3 + 2, 3 * j + 2) = NN + Phi_r_Lambda((i - number_of_points) * 3+2) * Phi_r(j * 3+2); //lambda in X rLeftHandSideMatrix(3 * j, i * 3) = NN + Phi_r_Lambda((i - number_of_points) * 3 ) * Phi_r(j * 3); //lambda in Y rLeftHandSideMatrix(3 * j + 1, i * 3 + 1) = NN + Phi_r_Lambda((i - number_of_points) * 3+1) * Phi_r(j * 3+1); //lambda in Z; rLeftHandSideMatrix(3 * j + 2, i * 3 + 2) = NN + Phi_r_Lambda((i - number_of_points) * 3+2) * Phi_r(j * 3+2); } } Vector TDisplacementsLambda = ZeroVector(number_of_points * 6); for (unsigned int i = 0; i < number_of_points; i++) { const array_1d<double, 3> disp = GetGeometry()[i].FastGetSolutionStepValue(DISPLACEMENT); int index = 3 * i; TDisplacementsLambda[index] = disp[0]; TDisplacementsLambda[index + 1] = disp[1]; TDisplacementsLambda[index + 2] = disp[2]; } for (unsigned int i = 0; i < number_of_points; i++) { const array_1d<double, 3> LagrangeMultiplier = GetGeometry()[i].FastGetSolutionStepValue(VECTOR_LAGRANGE_MULTIPLIER); int index = 3 * i + 3 * number_of_points; TDisplacementsLambda[index] = LagrangeMultiplier[0]; TDisplacementsLambda[index + 1] = LagrangeMultiplier[1]; TDisplacementsLambda[index + 2] = LagrangeMultiplier[2]; } array_1d<double,2> aux; aux[0] = localTrimTangents[0]; aux[1] = localTrimTangents[1]; double JGeometrictoParameter; MappingGeometricToParameterMasterElement(DN_DeMaster, aux, JGeometrictoParameter); rLeftHandSideMatrix *= (Weighting * JGeometrictoParameter); noalias(rRightHandSideVector) -= prod(rLeftHandSideMatrix, TDisplacementsLambda); KRATOS_CATCH("") } // MeshlessLagrangeCouplingCondition::MeshlessLagrangeCouplingCondition