bool ElasticityForce::evalForce (ElmMats& elmat, const Vec3& th, const FiniteElement& fe) const { // Integrate the nodal force vector Vector& ES = elmat.b.front(); size_t nsd = fe.dNdX.cols(); for (size_t a = 1; a <= fe.N.size(); a++) for (size_t d = 1; d <= nsd; d++) ES(nsd*(a-1)+d) += th[d-1]*fe.N(a)*fe.detJxW; return true; }
bool Elasticity::evalBou (LocalIntegral& elmInt, const FiniteElement& fe, const Vec3& X, const Vec3& normal) const { if (!tracFld && !fluxFld) { std::cerr <<" *** Elasticity::evalBou: No tractions."<< std::endl; return false; } else if (!eS) { std::cerr <<" *** Elasticity::evalBou: No load vector."<< std::endl; return false; } // Axi-symmetric integration point volume; 2*pi*r*|J|*w const double detJW = axiSymmetry ? 2.0*M_PI*X.x*fe.detJxW : fe.detJxW; // Evaluate the surface traction Vec3 T = this->getTraction(X,normal); // Store traction value for visualization if (fe.iGP < tracVal.size() && !T.isZero()) { tracVal[fe.iGP].first = X; tracVal[fe.iGP].second += T; } // Pull-back traction to reference configuration if (!this->pullBackTraction(T)) return false; // Integrate the force vector Vector& ES = static_cast<ElmMats&>(elmInt).b[eS-1]; for (size_t a = 1; a <= fe.N.size(); a++) for (unsigned short int i = 1; i <= nsd; i++) ES(nsd*(a-1)+i) += T[i-1]*fe.N(a)*detJW; return true; }
bool ElasticBase::evalPoint (LocalIntegral& elmInt, const FiniteElement& fe, const Vec3& pval) { if (!eS) { std::cerr <<" *** ElasticBase::evalPoint: No load vector."<< std::endl; return false; } Vector& ES = static_cast<ElmMats&>(elmInt).b[eS-1]; for (size_t a = 1; a <= fe.N.size(); a++) for (unsigned short int i = 1; i <= npv && i <= 3; i++) ES(npv*(a-1)+i) += pval(i)*fe.N(a)*fe.detJxW; if (eS == 1) { RealArray& sumLoad = static_cast<ElmMats&>(elmInt).c; for (size_t i = 0; i < sumLoad.size() && i < 3; i++) sumLoad[i] += pval[i]*fe.detJxW; } return true; }
bool ElasticCable::evalInt (LocalIntegral& elmInt, const FiniteElement& fe, const Vec3& X) const { size_t a, aa, b, bb; unsigned char i, j, k, l, o; const size_t nen = fe.N.size(); // Set up reference configuration Vec3 dX(fe.G.getColumn(1)); Vec3 ddX(fe.G.getColumn(2)); #if INT_DEBUG > 1 std::cout <<"ElasticCable: X = "<< X <<" dX = "<< dX <<" ddX = "<< ddX <<"\n"; #endif // Compute current configuration ElmMats& elMat = static_cast<ElmMats&>(elmInt); const Vector& eV = elMat.vec.front(); // Current displacement vector Vec3 x(X); Vec3 dx(dX); Vec3 ddx(ddX); for (i = 0; i < 3; i++) { x[i] += eV.dot(fe.N,i,3); dx[i] += eV.dot(fe.dNdX,i,3); ddx[i] += eV.dot(fe.d2NdX2,i,3); } #if INT_DEBUG > 1 std::cout <<"ElasticCable: x = "<< x <<" dx = "<< dx <<" ddx = "<< ddx <<"\n"; #endif // Compute local coordinate systems of the reference and current configuration Vec3 B_unit, N_unit; double B_len, N_len; if (!evalLocalAxes(dX,ddX,B_unit,N_unit,B_len,N_len)) return false; #if INT_DEBUG > 1 std::cout <<"ElasticCable: B_unit = "<< B_unit <<" N_unit = "<< N_unit <<"\n"; #endif Vec3 b_unit, n_unit; double b_len, n_len; if (!evalLocalAxes(dx,ddx,b_unit,n_unit,b_len,n_len)) return false; Vec3 bin = b_unit * b_len; double b_len2 = b_len * b_len; Vec3 n = n_unit * n_len; double n_len2 = n_len * n_len; #if INT_DEBUG > 1 std::cout <<"ElasticCable: b = "<< bin <<" b_unit = "<< b_unit <<"\n n = "<< n <<" n_unit = "<< n_unit << std::endl; #endif // Calculate derivative of b_unit std::vector<Matrix> db(nen,Matrix(3,3)), db_unit(nen,Matrix(3,3)); std::vector<Vec3> db_normal(nen); for (i = 1; i <= 3; i++) for (k = 1; k <= 3; k++) for (l = 1; l <= 3; l++) { double eps_kli = 0.5*(k-l)*(l-i)*(i-k); double eps_kil = 0.5*(k-i)*(i-l)*(l-k); for (a = 1; a <= nen; a++) db[a-1](k,i) += (eps_kil*fe.dNdX(a,1)*ddx[l-1] + eps_kli*dx[l-1]*fe.d2NdX2(a,1,1)); } for (i = 1; i <= 3; i++) for (a = 0; a < nen; a++) for (k = 1; k <= 3; k++) db_normal[a][i-1] += b_unit[k-1]*db[a](k,i); for (i = 1; i <= 3; i++) for (k = 1; k <= 3; k++) for (a = 0; a < nen; a++) db_unit[a](k,i) += (db[a](k,i) - b_unit[k-1]*db_normal[a][i-1])/b_len; #if INT_DEBUG > 2 std::cout <<"ElasticCable: db_unit:\n"; for (a = 0; a < nen; a++) std::cout <<"node "<< a+1 << db_unit[a]; #endif // Calculate second derivative of b_unit std::vector< std::vector<Matrix3D> > ddb(nen), ddb_unit(nen); std::vector< std::vector<Matrix> > ddb_normal(nen); for (a = 0; a < nen; a++) { ddb[a].resize(nen,Matrix3D(3,3,3)); ddb_unit[a].resize(nen,Matrix3D(3,3,3)); ddb_normal[a].resize(nen,Matrix(3,3)); } for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (k = 1; k <= 3; k++) { double eps_kij = 0.5*(k-i)*(i-j)*(j-k); double eps_kji = 0.5*(k-j)*(j-i)*(i-k); for (a = 1; a <= nen; a++) for (b = 1; b <= nen; b++) ddb[a-1][b-1](k,i,j) = (eps_kji*fe.d2NdX2(a,1,1)*fe.dNdX(b,1) + eps_kij*fe.d2NdX2(b,1,1)*fe.dNdX(a,1)); } #if INT_DEBUG > 3 std::cout <<"ElasticCable: ddb:\n"; for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) std::cout <<"nodes "<< a+1 <<","<< b+1 << ddb[a][b]; #endif for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) for (k = 1; k <= 3; k++) ddb_normal[a][b](i,j) += (ddb[a][b](k,i,j)*bin[k-1] + db[a](k,i)*db[b](k,j) - bin[k-1]*db[a](k,i)*bin[k-1]*db[b](k,j) / b_len2) / b_len; #if INT_DEBUG > 3 std::cout <<"ElasticCable: ddb_normal:\n"; for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) std::cout <<"nodes "<< a+1 <<","<< b+1 << ddb_normal[a][b]; #endif for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) for (k = 1; k <= 3; k++) ddb_unit[a][b](k,i,j) = (ddb[a][b](k,i,j)/b_len - db[a](k,i)*db_normal[b][j-1]/b_len2 - db[b](k,j)*db_normal[a][i-1]/b_len2 - bin[k-1]*(ddb_normal[a][b](i,j) - db_normal[a][i-1]* db_normal[b][j-1]*2.0 / b_len) / b_len2); #if INT_DEBUG > 2 std::cout <<"ElasticCable: ddb_unit:\n"; for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) std::cout <<"nodes "<< a+1 <<","<< b+1 << ddb_unit[a][b]; #endif // Calculate derivative of n_unit std::vector<Matrix> dn(nen,Matrix(3,3)), dn_unit(nen,Matrix(3,3)); std::vector<Vec3> dn_normal(nen); for (i = 1; i <= 3; i++) for (k = 1; k <= 3; k++) for (l = 1; l <= 3; l++) { double eps_kli = 0.5*(k-l)*(l-i)*(i-k); for (a = 0; a < nen; a++) { dn[a](k,i) += eps_kli*b_unit[l-1]*fe.dNdX(1+a,1); for (o = 1; o <= 3; o++) { double eps_kol = 0.5*(k-o)*(o-l)*(l-k); dn[a](k,i) += eps_kol*db_unit[a](o,i)*dx[l-1]; } } } for (i = 1; i <= 3; i++) for (a = 0; a < nen; a++) for (k = 1; k <= 3; k++) dn_normal[a][i-1] += n_unit[k-1]*dn[a](k,i); for (i = 1; i <= 3; i++) for (k = 1; k <= 3; k++) for (a = 0; a < nen; a++) dn_unit[a](k,i) += (dn[a](k,i) - n_unit[k-1]*dn_normal[a][i-1])/n_len; #if INT_DEBUG > 2 std::cout <<"\nElasticCable: dn_unit:\n"; for (a = 0; a < nen; a++) std::cout <<"node "<< a+1 << dn_unit[a]; #endif // Calculate second derivative of n_unit std::vector< std::vector<Matrix3D> > ddn(nen), ddn_unit(nen); std::vector< std::vector<Matrix> > ddn_normal(nen); for (a = 0; a < nen; a++) { ddn[a].resize(nen,Matrix3D(3,3,3)); ddn_unit[a].resize(nen,Matrix3D(3,3,3)); ddn_normal[a].resize(nen,Matrix(3,3)); } for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) for (k = 1; k <= 3; k++) for (o = 1; o <= 3; o++) { double eps_koj = 0.5*(k-o)*(o-j)*(j-k); double eps_koi = 0.5*(k-o)*(o-i)*(i-k); ddn[a][b](k,i,j) += (eps_koj*db_unit[a](o,i)*fe.dNdX(1+b,1) + eps_koi*db_unit[b](o,j)*fe.dNdX(1+a,1)); for (l = 1; l <= 3; l++) { double eps_kol = 0.5*(k-o)*(o-l)*(l-k); ddn[a][b](k,i,j) += eps_kol*ddb_unit[a][b](o,i,j)*dx[l-1]; } } for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) for (k = 1; k <= 3; k++) ddn_normal[a][b](i,j) += (ddn[a][b](k,i,j)*n[k-1] + dn[a](k,i)*dn[b](k,j) - n[k-1]*dn[a](k,i)* n[k-1]*dn[b](k,j)/n_len2) / n_len; for (i = 1; i <= 3; i++) for (j = 1; j <= 3; j++) for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) for (k = 1; k <= 3; k++) ddn_unit[a][b](k,i,j) = (ddn[a][b](k,i,j)/n_len - dn[a](k,i)*dn_normal[b][j-1]/n_len2 - dn[b](k,j)*dn_normal[a][i-1]/n_len2 - n[k-1]*(ddn_normal[a][b](i,j) - dn_normal[a][i-1]* dn_normal[b][j-1]*2.0 / n_len) / n_len2); #if INT_DEBUG > 2 std::cout <<"ElasticCable: ddn_unit:\n"; for (a = 0; a < nen; a++) for (b = 0; b < nen; b++) std::cout <<"nodes "<< a+1 <<","<< b+1 << ddn_unit[a][b]; #endif // Axial strain double eps = 0.5*(dx*dx - dX*dX); // Derivative of the axial strain Vector deps(3*nen); for (a = aa = 1; a <= nen; a++) for (i = 1; i <= 3; i++, aa++) deps(aa) = fe.dNdX(a,1)*dx[i-1]; // Second derivative of the axial strain Matrix ddeps(3*nen,3*nen); for (a = 1; a <= nen; a++) for (b = 1; b <= nen; b++) for (i = 1; i <= 3; i++) ddeps(3*(a-1)+i,3*(b-1)+i) = fe.dNdX(a,1)*fe.dNdX(b,1); // Curvature double kappa = (ddx*n_unit - ddX*N_unit); // Derivative of the curvature Vector dkappa(3*nen); for (a = aa = 1; a <= nen; a++) for (i = 1; i <= 3; i++, aa++) { dkappa(aa) = fe.d2NdX2(a,1,1)*n_unit[i-1]; for (k = 1; k <= 3; k++) dkappa(aa) += ddx[k-1]*dn_unit[a-1](k,i); } // Second derivative of the curvature Matrix ddkappa(3*nen,3*nen); for (a = 0, aa = 1; a < nen; a++) for (i = 1; i <= 3; i++, aa++) for (b = 0, bb = 1; b < nen; b++) for (j = 1; j <= 3; j++, bb++) { ddkappa(aa,bb) = (fe.d2NdX2(1+a,1,1)*dn_unit[b](i,j) + fe.d2NdX2(1+b,1,1)*dn_unit[a](j,i)); for (k = 1; k <= 3; k++) ddkappa(aa,bb) += ddx[k-1]*ddn_unit[a][b](k,i,j); } #if INT_DEBUG > 1 std::cout <<"ElasticCable: eps = "<< eps <<" kappa = "<< kappa <<"\ndeps:"<< deps <<"dkappa:"<< dkappa <<"ddeps:"<< ddeps <<"ddkappa:"<< ddkappa; #endif // Norm of initial contravariant basis (G^1) double normG1contr2 = 1.0 / (dX.x*dX.x + dX.y*dX.y + dX.z*dX.z); double normG1contr4JW = normG1contr2 * normG1contr2 * fe.detJxW; double EAxJW = EA * normG1contr4JW; // volume-weighted axial stiffness double EIxJW = EI * normG1contr4JW; // volume-weighted bending stiffness if (iS) { // Integrate the internal forces (note the negative sign here) elMat.b[iS-1].add(deps,-eps*EAxJW); elMat.b[iS-1].add(dkappa,-kappa*EIxJW); } if (eKm) { // Integrate the material stiffness matrix elMat.A[eKm-1].outer_product(deps,deps*EAxJW,true); elMat.A[eKm-1].outer_product(dkappa,dkappa*EIxJW,true); } if (eKg) { // Integrate the geometric stiffness matrix elMat.A[eKg-1].add(ddeps,eps*EAxJW); elMat.A[eKg-1].add(ddkappa,kappa*EIxJW); } if (lineMass > 0.0) { double dMass = lineMass*fe.detJxW; if (eM) { // Integrate the mass matrix Matrix& M = elMat.A[eM-1]; for (a = 1; a <= nen; a++) for (b = 1; b <= nen; b++) for (i = 1; i <= 3; i++) M(3*(a-1)+i,3*(b-1)+i) += fe.N(a)*fe.N(b)*dMass; } if (eS && !gravity.isZero()) { // Integrate the external (gravitation) forces Vector& S = elMat.b[eS-1]; for (a = 1; a <= nen; a++) for (i = 1; i <= 3; i++) S(3*(a-1)+i) += fe.N(a)*gravity[i-1]*dMass; } } return true; }