Exemple #1
0
void   XC::Twenty_Node_Brick::formInertiaTerms( int tangFlag ) const
{
        static double xsj ;  // determinant jacaobian matrix
        int i, j, k, m;
        double Nrho;

        //zero mass
        mass.Zero( ) ;

        //compute basis vectors and local nodal coordinates
        computeBasis( ) ;
        //gauss loop to compute and save shape functions
        for( i = 0; i < nintu; i++ ) {
                // compute Jacobian and global shape functions
                Jacobian3d(i, xsj, 0);
                //volume element to also be saved
                dvolu[i] = wu[i] * xsj ;
        } // end for i

        // Compute consistent mass matrix
        for(i = 0; i < nenu; i++) {
                for(j = 0; j < nenu; j++) {
                        for(m = 0; m < nintu; m++) {
                                Nrho = dvolu[m]*mixtureRho(m)*shgu[3][i][m]*shgu[3][j][m];
                                for( k = 0; k < 3; k++) {
                                        mass(i*3+k,j*3+k) += Nrho;
                                }
                        }
                }
        }

}
Exemple #2
0
// TODO: Don't do the if here, have children do what they need to do
scalar Constraint::computeLambda( const VectorXs& q, const VectorXs& v ) const
{
  MatrixXXsc basis;
  computeBasis( q, v, basis );
  assert( basis.rows() == basis.cols() );
  assert( basis.cols() == 2 || basis.cols() == 3 );
  const VectorXs rel_vel = computeRelativeVelocity( q, v );
  assert( rel_vel.size() == basis.rows() );
  if( basis.cols() == 3 )
  {
    const Vector2s tangent_vel( rel_vel.dot( basis.col( 1 ) ), rel_vel.dot( basis.col( 2 ) ) );
    return tangent_vel.norm();
  }
  else if( basis.cols() == 2 )
  {
    return fabs( rel_vel.dot( basis.col( 1 ) ) );
  }
  std::cerr << "Unhandled case in Constraint::computeLambda" << std::endl;
  std::exit( EXIT_FAILURE );
}
Exemple #3
0
// TODO: Unspecialize from 3D
void Constraint::computeNormalAndRelVelAlignedTangent( const VectorXs& q, const VectorXs& v, VectorXs& n, VectorXs& t, VectorXs& tangent_rel_vel ) const
{
  MatrixXXsc basis;
  computeBasis( q, v, basis );
  assert( basis.rows() == basis.cols() ); assert( basis.rows() == 3 );
  n = basis.col( 0 );
  t = basis.col( 1 );

  // Compute the relative velocity
  tangent_rel_vel = computeRelativeVelocity( q, v );
  // Project out normal component of relative velocity
  tangent_rel_vel = tangent_rel_vel - tangent_rel_vel.dot( n ) * n;

  #ifndef NDEBUG
  // Relative velocity and tangent should be parallel
  assert( Eigen::Map<Vector3s>( tangent_rel_vel.data() ).cross( Eigen::Map<Vector3s>( t.data() ) ).lpNorm<Eigen::Infinity>() <= 1.0e-6 );
  // If tangent relative velocity is non-negligble, tangent should oppose
  if( tangent_rel_vel.norm() > 1.0e-9 )
  {
    assert( fabs( tangent_rel_vel.normalized().dot( t ) + 1.0 ) <= 1.0e-6 );
  }
  #endif
}
Exemple #4
0
//set domain
void  ShellMITC9::setDomain( Domain *theDomain ) 
{
  int i,j ;
  static Vector eig(3) ;
  static Matrix ddMembrane(3,3) ;

  //node pointers
  for ( i = 0; i < 9; i++ ) {
     nodePointers[i] = theDomain->getNode( connectedExternalNodes(i) ) ;
     
     if (nodePointers[i] == 0) {
       opserr << "ShellMITC9::setDomain - no node " << connectedExternalNodes(i);
       opserr << " exists in the model\n";
     }
  }

  //compute drilling stiffness penalty parameter
  const Matrix &dd = materialPointers[0]->getInitialTangent( ) ;

  //assemble ddMembrane ;
  for ( i = 0; i < 3; i++ ) {
      for ( j = 0; j < 3; j++ ){
         ddMembrane(i,j) = dd(i,j) ;
	  } //end for j
  } //end for i 

  //eigenvalues of ddMembrane
  eig = LovelyEig( ddMembrane ) ;
  
  //set ktt 
  //Ktt = dd(2,2) ;  //shear modulus 
  Ktt = min( eig(2), min( eig(0), eig(1) ) ) ;
  //basis vectors and local coordinates
  computeBasis( ) ;

  this->DomainComponent::setDomain(theDomain);
}
const Matrix&  TwentyEightNodeBrickUP::getStiff( int flag )

{

	if (flag != 0 && flag != 1) {

		opserr << "FATAL TwentyEightNodeBrickUP::getStiff() - illegal use\n";

		exit(-1);

	}



	if (flag == 0 && Ki != 0)

		return *Ki;



	int i, j ;



	static double xsj ;  // determinant jacaobian matrix

	double volume = 0.;

	//-------------------------------------------------------

	int j3, j3m1, j3m2, ik, ib, jk, jb;

	static Matrix B(6,nenu*3);

	static Matrix BTDB(nenu*3,nenu*3);

	static Matrix D(6, 6);

	B.Zero();

	BTDB.Zero();

	stiff.Zero();



	//compute basis vectors and local nodal coordinates

	computeBasis( ) ;



	for( i = 0; i < nintu; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 0);

		//volume element to also be saved

		dvolu[i] = wu[i] * xsj ;

		volume += dvolu[i];

	} // end for i

    //printf("volume = %f\n", volume);



//	for( i = 0; i < nintu; i++ ) {

//		for(int j = 0; j < nenu; j++ ) {

//			printf("%5d %5d %15.6e %15.6e %15.6e %15.6e\n", i,j,

//				shgu[0][j][i], shgu[1][j][i], shgu[2][j][i], shgu[3][j][i]);

//		}

//	}

//	exit(-1);



	// Loop over the integration points

	for (i = 0; i < nintu; i++) {



		// Get the material tangent

		if( flag == 0 )

			D = materialPointers[i]->getInitialTangent();

		else

			D = materialPointers[i]->getTangent();

		//const Matrix &D = materialPointers[i]->getTangent();





		for (j=0; j<nenu; j++) {



			j3   = 3*j+2;

			j3m1 = j3 - 1;

			j3m2 = j3 - 2;



			B(0,j3m2) = shgu[0][j][i];

			B(0,j3m1) = 0.;

			B(0,j3  ) = 0.;



			B(1,j3m2) = 0.;

			B(1,j3m1) = shgu[1][j][i];

			B(1,j3  ) = 0.;



			B(2,j3m2) = 0.;

			B(2,j3m1) = 0.;

			B(2,j3  ) = shgu[2][j][i];



			B(3,j3m2) = shgu[1][j][i];

			B(3,j3m1) = shgu[0][j][i];

			B(3,j3  ) = 0.;



			B(4,j3m2) = 0.;

			B(4,j3m1) = shgu[2][j][i];

			B(4,j3  ) = shgu[1][j][i];



			B(5,j3m2) = shgu[2][j][i];

			B(5,j3m1) = 0.;

			B(5,j3  ) = shgu[0][j][i];



		}



		// Perform numerical integration

		//K = K + (B^ D * B) * intWt(i) * detJ;

		BTDB.addMatrixTripleProduct(1.0, B, D, dvolu[i]);

	}



	for (i = 0; i < nenu; i++) {

		if (i<nenp)

			ik = i*4;

		else

			ik = nenp*4 + (i-nenp)*3;

		ib = i*3;



		for (j = 0; j < nenu; j++) {

			if (j<nenp)

				jk = j*4;

			else

				jk = nenp*4 + (j-nenp)*3;

			jb = j*3;

			for( int i1 = 0; i1 < 3; i1++)

				for(int j1 = 0; j1 < 3; j1++) {

					stiff(ik+i1, jk+j1) = BTDB(ib+i1,jb+j1);

				}

		}

	}

	if( flag == 1) {

		return stiff;

	}

	Ki = new Matrix(stiff);

	if (Ki == 0) {

		opserr << "FATAL TwentyEightNodeBrickUP::getStiff() -";

		opserr << "ran out of memory\n";

		exit(-1);

	}



	return *Ki;

}
void   TwentyEightNodeBrickUP::formInertiaTerms( int tangFlag )

{

	static double xsj ;  // determinant jacaobian matrix

	int i, j, k, ik, m, jk;

	double Nrho;



	//zero mass

	mass.Zero( ) ;



	//compute basis vectors and local nodal coordinates

	computeBasis( ) ;

	//gauss loop to compute and save shape functions

	for( i = 0; i < nintu; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 0);

		//volume element to also be saved

		dvolu[i] = wu[i] * xsj ;

	} // end for i

	for( i = 0; i < nintp; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 1);

		//volume element to also be saved

		dvolp[i] = wp[i] * xsj ;

	} // end for i



	// Compute consistent mass matrix

	for (i = 0; i < nenu; i++) {

		if (i<nenp)

			ik = i*4;

		else

			ik = nenp*4 + (i-nenp)*3;



		for (j = 0; j < nenu; j++) {

			if (j<nenp)

				jk = j*4;

			else

				jk = nenp*4 + (j-nenp)*3;



			for (m = 0; m < nintu; m++) {

				Nrho = dvolu[m]*mixtureRho(m)*shgu[3][i][m]*shgu[3][j][m];

				for( k = 0; k < 3; k++) {

					mass(ik+k,jk+k) += Nrho;

				}

			}

		}

	}



	// Compute compressibility matrix

	double oneOverKc = 1./kc;

	for (i = 0; i < nenp; i++) {

		ik = i*4+3;



		for (j = 0; j < nenp; j++) {

			jk = j*4+3;



			for (m = 0; m < nintp; m++) {

				mass(ik,jk) += -dvolp[m]*oneOverKc*shgp[3][i][m]*shgp[3][j][m];

			}

		}

	}

}
const Vector&  TwentyEightNodeBrickUP::getResistingForce( )

{

	int i, j, jk, k, k1;

	double xsj;

	static Matrix B(6, 3);

	double volume = 0.;



//	printf("calling getResistingForce()\n");

	resid.Zero();



	//compute basis vectors and local nodal coordinates

	computeBasis( ) ;

	//gauss loop to compute and save shape functions

	for( i = 0; i < nintu; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 0);

		//volume element to also be saved

		dvolu[i] = wu[i] * xsj ;

		volume += dvolu[i];

	} // end for i

	//printf("volume = %f\n", volume);

	volume = 0.;

	for( i = 0; i < nintp; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 1);

		//volume element to also be saved

		dvolp[i] = wp[i] * xsj ;

		volume += dvolp[i];

	} // end for i

	//printf("volume = %f\n", volume);



	// Loop over the integration points

	for (i = 0; i < nintu; i++) {



		// Get material stress response

		const Vector &sigma = materialPointers[i]->getStress();



		// Perform numerical integration on internal force

		//P = P + (B^ sigma) * intWt(i)*intWt(j) * detJ;

		//P.addMatrixTransposeVector(1.0, B, sigma, intWt(i)*intWt(j)*detJ);

		for (j = 0; j < nenu; j++) {

			if (j<nenp)

				jk = j*4;

			else

				jk = nenp*4 + (j-nenp)*3;



			B(0,0) = shgu[0][j][i];

			B(0,1) = 0.;

			B(0,2) = 0.;

			B(1,0) = 0.;

			B(1,1) = shgu[1][j][i];

			B(1,2) = 0.;

			B(2,0) = 0.;

			B(2,1) = 0.;

			B(2,2) = shgu[2][j][i];

			B(3,0) = shgu[1][j][i];

			B(3,1) = shgu[0][j][i];

			B(3,2) = 0.;

			B(4,0) = 0.;

			B(4,1) = shgu[2][j][i];

			B(4,2) = shgu[1][j][i];

			B(5,0) = shgu[2][j][i];

			B(5,1) = 0.;

			B(5,2) = shgu[0][j][i];





			for(k = 0; k < 3; k++) {

				for(k1 = 0; k1 < 6; k1++)

					resid(jk+k) += dvolu[i]*(B(k1,k)*sigma(k1));

			}

			// Subtract equiv. body forces from the nodes

			//P = P - (N^ b) * intWt(i)*intWt(j) * detJ;

			//P.addMatrixTransposeVector(1.0, N, b, -intWt(i)*intWt(j)*detJ);

			double r = mixtureRho(i);

			if (applyLoad == 0) {
				resid(jk) -= dvolu[i]*(shgu[3][j][i]*r*b[0]);
				resid(jk+1) -= dvolu[i]*(shgu[3][j][i]*r*b[1]);
				resid(jk+2) -= dvolu[i]*(shgu[3][j][i]*r*b[2]);
			} else {
				resid(jk) -= dvolu[i]*(shgu[3][j][i]*r*appliedB[0]);
				resid(jk+1) -= dvolu[i]*(shgu[3][j][i]*r*appliedB[1]);
				resid(jk+2) -= dvolu[i]*(shgu[3][j][i]*r*appliedB[2]);
			}

		}

	}



	// Subtract fluid body force

	for (j = 0; j < nenp; j++) {

		jk = j*4+3;

		for (i = 0; i < nintp; i++) {
			
			if (applyLoad == 0) {
				resid(jk) += dvolp[i]*rho*(perm[0]*b[0]*shgp[0][j][i] +
							 perm[1]*b[1]*shgp[1][j][i] + perm[2]*b[2]*shgp[2][j][i]);
			} else {
				resid(jk) += dvolp[i]*rho*(perm[0]*appliedB[0]*shgp[0][j][i] +
							 perm[1]*appliedB[1]*shgp[1][j][i] + perm[2]*appliedB[2]*shgp[2][j][i]);
			}

		}

	}



	// Subtract other external nodal loads ... P_res = P_int - P_ext

//	opserr<<"resid before:"<<resid<<endln;



	if (load != 0)

		resid -= *load;



//	opserr<<"resid "<<resid<<endln;



	return resid ;

}
void TwentyEightNodeBrickUP::formDampingTerms( int tangFlag )

{

	static double xsj ;  // determinant jacaobian matrix

	int i, j, k, m, ik, jk;

	double volume = 0.;

	//zero damp

	damp.Zero( ) ;



	if (betaK != 0.0)

		damp.addMatrix(1.0, this->getTangentStiff(), betaK);

	if (betaK0 != 0.0)

		damp.addMatrix(1.0, this->getInitialStiff(), betaK0);

	if (betaKc != 0.0)

		damp.addMatrix(1.0, *Kc, betaKc);



	if (alphaM != 0.0) {

		this->getMass();

		for( i = 0; i < nenu; i++ ) {

			if( i < nenp)

				ik = i*4;

			else

				ik = nenp*4 + (i - nenp) * 3;

			for( j = 0; j < nenu; j++) {

				if( j < nenp)

					jk = j * 4;

				else

					jk = nenp * 4 + (j-nenp) * 3;

				for( k = 0; k < 3; k++)

					damp(ik + k, jk + k) += mass(ik + k, jk + k) * alphaM;

			}

		}

	}



	//compute basis vectors and local nodal coordinates

	computeBasis( ) ;

	//gauss loop to compute and save shape functions

	for( i = 0; i < nintp; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 1);

		//volume element to also be saved

		dvolp[i] = wp[i] * xsj ;

		volume += dvolp[i];

	} // end for i

	//printf("volume = %f\n", volume);



	volume = 0.;

	for( i = 0; i < nintp; i++ ) {

		// compute Jacobian and global shape functions

		Jacobian3d(i, xsj, 2);

		//volume element to also be saved

		dvolq[i] = wp[i] * xsj ;

		volume += dvolq[i];

	} // end for i

	//printf("volume = %f\n", volume);



	// Compute coupling matrix

	for( i = 0; i < nenu; i++ ) {

		if( i < nenp)

			ik = i * 4;

		else

			ik = nenp * 4 + (i-nenp)*3;

		for( j = 0; j < nenp; j++) {

			jk = j * 4 + 3;

			for( m = 0; m < nintp; m++) {

				for( k = 0; k < 3; k++) {

					damp(ik+k,jk) += -dvolq[m]*shgq[k][i][m]*shgp[3][j][m];

				}

			}

			for( k = 0; k < 3; k++ ) {

				damp(jk, ik+k) = damp(ik+k, jk);

			}

		}

	}

	// Compute permeability matrix

	for( i = 0; i < nenp; i++ ) {

		ik = i*4 + 3;

		for( j = 0; j < nenp; j++ ) {

			jk = j * 4 + 3;

			for( m = 0; m < nintp; m++ ) {

				damp(ik,jk) += - dvolp[m]*(perm[0]*shgp[0][i][m]*shgp[0][j][m] +

					perm[1]*shgp[1][i][m]*shgp[1][j][m]+

					perm[2]*shgp[2][i][m]*shgp[2][j][m]);

			}

		}

	}

}
Exemple #9
0
void  
NineNodeMixedQuad::formResidAndTangent( int tang_flag ) 
{

  //strains ordered : eps11, eps22, eps33, 2*eps12 
  //volumtric strains projected onto {1, \xi, \eta} natural coordinates

  static const int ndm = 2 ;

  static const int ndf = 2 ; 

  static const int nstress = 4 ;
 
  static const int numberNodes = 9 ;

  static const int numberGauss = 9 ;

  static const int nShape = 3 ;

  static const int nMixed = 3 ;

  int i, j, k, p, q, r, s ;
  int jj, kk ;

  int success ;
  
  static double volume ;

  static double xsj ;  // determinant jacaobian matrix 

  static double dvol[numberGauss] ; //volume element

  static double gaussPoint[ndm] ;

  static double natCoorArray[ndm][numberGauss] ;

  static Vector strain(nstress) ;  //strain

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static double Shape[nShape][numberNodes][numberGauss] ; //all the shape functions

  static double shpBar[nShape][numberNodes][nMixed] ; //mean value of shape functions

  static double rightHandSide[nShape][numberNodes][nMixed] ;

  static Vector residJ(ndf) ; //nodeJ residual 

  static Matrix stiffJK(ndf,ndf) ; //nodeJK stiffness 

  static Vector stress(nstress) ;  //stress

  static Matrix dd(nstress,nstress) ;  //material tangent

  static double interp[nMixed] ;

  static Matrix Proj(3,3) ;   //projection matrix 
  static Matrix ProjInv(3,3) ;

  static Matrix Iden(3,3) ;
  Iden(0,0) = 1.0 ;
  Iden(1,1) = 1.0 ;
  Iden(2,2) = 1.0 ;

  //---------B-matrices------------------------------------

    static Matrix BJ(nstress,ndf) ;      // B matrix node J

    static Matrix BJtran(ndf,nstress) ;

    static Matrix BK(nstress,ndf) ;      // B matrix node k

    static Matrix BJtranD(ndf,nstress) ;

  //-------------------------------------------------------

  
  //zero stiffness and residual 
  stiff.Zero( ) ;
  resid.Zero( ) ;

  //node coordinates
  computeBasis() ;

  //zero mean shape functions
  for ( p=0; p<nShape; p++ ) {
    for ( q=0; q<numberNodes; q++ ) {

      for (r=0; r<nMixed; r++ ) {
	shpBar[p][q][r] = 0.0 ;
	rightHandSide[p][q][r] = 0.0 ;
      }

    }//end for q
  } // end for p


  //zero volume
  volume = 0.0 ;

  //zero projection matrix  
  Proj.Zero( ) ;
  ProjInv.Zero( ) ;


  //gauss loop to compute and save shape functions 
  int count = 0 ;

  for ( i = 0; i < 3; i++ ) {
    for ( j = 0; j < 3; j++ ) {

        gaussPoint[0] = sg[i] ;        
	gaussPoint[1] = sg[j] ;        


	//save gauss point locations
	natCoorArray[0][count] = gaussPoint[0] ;
	natCoorArray[1][count] = gaussPoint[1] ;


	//get shape functions    
	shape2dNine( gaussPoint, xl, shp, xsj ) ;


	//save shape functions
	for ( p=0; p<nShape; p++ ) {
	  for ( q=0; q<numberNodes; q++ )
	    Shape[p][q][count] = shp[p][q] ;
	} // end for p

	
	//volume element to also be saved
	dvol[count] = ( wg[i]*wg[j] ) * xsj ;  


        //add to projection matrix
	interp[0] = 1.0 ;
	interp[1] = gaussPoint[0] ;
	interp[2] = gaussPoint[1] ;
	
	for ( r=0; r<nMixed; r++ ) {
	  for ( s=0; s<nMixed; s++ ) 
	    Proj(r,s) += ( interp[r]*interp[s] * dvol[count] ) ;
	}//end for r

	volume += dvol[count] ;
	
	
	//add to mean shape functions
	for ( p=0; p<nShape; p++ ) {
	  for ( q=0; q<numberNodes; q++ ) {

	    for ( s=0; s<nMixed; s++ ) 
	      rightHandSide[p][q][s] += ( shp[p][q] * interp[s] * dvol[count] ) ;

	  }//end for q 
	} // end for p


	//increment gauss point counter
	count++ ;

    } //end for j
  } // end for i 
  


  //invert projection matrix
  //int Solve(const Matrix &M, Matrix &res) const;
  Proj.Solve( Iden, ProjInv ) ;
  
  //mean value of shape functions
  for ( p=0; p<nShape; p++ ) {
    for ( q=0; q<numberNodes; q++ ) {

      for (r=0; r<nMixed; r++ ) {
	for (s=0; s<nMixed; s++ ) 
	  shpBar[p][q][r] += ( ProjInv(r,s) * rightHandSide[p][q][s] ) ;
      }//end for r

    }//end for q
  }//end for p


  //gauss loop 
  for ( i=0; i<numberGauss; i++ ) {
    
    //extract gauss point location
    gaussPoint[0] = natCoorArray[0][i] ;
    gaussPoint[1] = natCoorArray[1][i] ;

    //extract shape functions from saved array
    for ( p=0; p<nShape; p++ ) {
       for ( q=0; q<numberNodes; q++ )
	  shp[p][q]  = Shape[p][q][i] ;
    } // end for p


    //zero the strains
    strain.Zero( ) ;

    // j-node loop to compute strain 
    for ( j=0; j<numberNodes; j++ )  {

      //compute B matrix 

      BJ = computeBbar( j, gaussPoint, shp, shpBar ) ;
      
      //nodal displacements 
      const Vector &ul = nodePointers[j]->getTrialDisp( ) ;

      //compute the strain
      //strain += (BJ*ul) ; 
      strain.addMatrixVector(1.0,  BJ,ul,1.0 ) ;

    } // end for j
  


    //send the strain to the material 
    success = materialPointers[i]->setTrialStrain( strain ) ;

    //compute the stress
    stress = materialPointers[i]->getStress( ) ;


    //multiply by volume element
    stress  *= dvol[i] ;

    if ( tang_flag == 1 ) {
      dd = materialPointers[i]->getTangent( ) ;
      dd *= dvol[i] ;
    } //end if tang_flag


    //residual and tangent calculations node loops

    jj = 0 ;
    for ( j=0; j<numberNodes; j++ ) {

      BJ = computeBbar( j, gaussPoint, shp, shpBar ) ;
   
      //transpose 
      //BJtran = transpose( nstress, ndf, BJ ) ;
      for (p=0; p<ndf; p++) {
	for (q=0; q<nstress; q++) 
	  BJtran(p,q) = BJ(q,p) ;
      }//end for p


      //residual
      //residJ = BJtran * stress ;
      residJ.addMatrixVector(0.0,  BJtran,stress,1.0);

      //residual 
      for ( p=0; p<ndf; p++ )
        resid( jj + p ) += residJ(p)  ;


      if ( tang_flag == 1 ) {

	//BJtranD = BJtran * dd ;
	BJtranD.addMatrixProduct(0.0,  BJtran,dd,1.0);

         kk = 0 ;
         for ( k=0; k<numberNodes; k++ ) {

            BK = computeBbar( k, gaussPoint, shp, shpBar ) ;
  
 
            //stiffJK =  BJtranD * BK  ;
	    stiffJK.addMatrixProduct(0.0,  BJtranD,BK,1.0) ;

            for ( p=0; p<ndf; p++ )  {
               for ( q=0; q<ndf; q++ )
                  stiff( jj+p, kk+q ) += stiffJK( p, q ) ;
            } //end for p

            kk += ndf ;
	 }//end for k loop

      }//end if tang_flag 

      jj += ndf ;
    }//end for j loop


  }//end for i gauss loop 

  
  return ;
}
Exemple #10
0
MatrixXXsc Constraint::computeFrictionBasis( const VectorXs& q, const VectorXs& v ) const
{
  MatrixXXsc basis;
  computeBasis( q, v, basis );
  return basis.block( 0, 1, basis.rows(), basis.cols() - 1 );
}
Exemple #11
0
//get residual
const XC::Vector &XC::Twenty_Node_Brick::getResistingForce(void) const
  {
        int i, j, k, k1;
        double xsj;
        static XC::Matrix B(6, 3);
        double volume = 0.;

//        printf("calling getResistingForce()\n");
        resid.Zero();

        //compute basis vectors and local nodal coordinates
        computeBasis( ) ;
        //gauss loop to compute and save shape functions
        for( i = 0; i < nintu; i++ ) {
                // compute Jacobian and global shape functions
                Jacobian3d(i, xsj, 0);
                //volume element to also be saved
                dvolu[i] = wu[i] * xsj ;
                volume += dvolu[i];
        } // end for i
        //printf("volume = %f\n", volume);

        // Loop over the integration points
        for(i = 0; i < nintu; i++) {

                // Get material stress response
                const XC::Vector &sigma = physicalProperties[i]->getStress();

                // Perform numerical integration on internal force
                //P = P + (B^ sigma) * intWt(i)*intWt(j) * detJ;
                //P.addMatrixTransposeVector(1.0, B, sigma, intWt(i)*intWt(j)*detJ);
                for(j = 0; j < nenu; j++) {

                        B(0,0) = shgu[0][j][i];
                        B(0,1) = 0.;
                        B(0,2) = 0.;
                        B(1,0) = 0.;
                        B(1,1) = shgu[1][j][i];
                        B(1,2) = 0.;
                        B(2,0) = 0.;
                        B(2,1) = 0.;
                        B(2,2) = shgu[2][j][i];
                        B(3,0) = shgu[1][j][i];
                        B(3,1) = shgu[0][j][i];
                        B(3,2) = 0.;
                        B(4,0) = 0.;
                        B(4,1) = shgu[2][j][i];
                        B(4,2) = shgu[1][j][i];
                        B(5,0) = shgu[2][j][i];
                        B(5,1) = 0.;
                        B(5,2) = shgu[0][j][i];


                        for(k = 0; k < 3; k++) {
                                for(k1 = 0; k1 < 6; k1++)
                                        resid(j*3+k) += dvolu[i]*(B(k1,k)*sigma(k1));
                        }
                        // Subtract equiv. body forces from the nodes
                        //P = P - (N^ b) * intWt(i)*intWt(j) * detJ;
                        //P.addMatrixTransposeVector(1.0, N, b, -intWt(i)*intWt(j)*detJ);
                        double r = mixtureRho(i);
                        resid(j*3) -= dvolu[i]*(shgu[3][j][i]*r*bf[0]);
                        resid(j*3+1) -= dvolu[i]*(shgu[3][j][i]*r*bf[1]);
                        resid(j*3+2) -= dvolu[i]*(shgu[3][j][i]*r*bf[2]);
                }
        }

        // Subtract other external nodal loads ... P_res = P_int - P_ext
//        std::cerr<<"resid before:"<<resid<<std::endl;

        if(!load.isEmpty())
          resid-= load;

//        std::cerr<<"resid "<<resid<<std::endl;

    if(isDead())
      resid*=dead_srf;
    return resid ;
  }
Exemple #12
0
//*********************************************************************
//form residual and tangent
void  BbarBrick::formResidAndTangent( int tang_flag )
{

  //strains ordered : eps11, eps22, eps33, 2*eps12, 2*eps23, 2*eps31

  static const int ndm = 3 ;

  static const int ndf = 3 ;

  static const int nstress = 6 ;

  static const int numberNodes = 8 ;

  static const int numberGauss = 8 ;

  static const int nShape = 4 ;

  int i, j, k, p, q ;
  int jj, kk ;

  int success ;

  static double volume ;

  static double xsj ;  // determinant jacaobian matrix

  static double dvol[numberGauss] ; //volume element

  static double gaussPoint[ndm] ;

  static Vector strain(nstress) ;  //strain

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static double Shape[nShape][numberNodes][numberGauss] ; //all the shape functions

  static double shpBar[nShape][numberNodes] ;  //mean value of shape functions

  static Vector residJ(ndf) ; //nodeJ residual

  static Matrix stiffJK(ndf,ndf) ; //nodeJK stiffness

  static Vector stress(nstress) ;  //stress

  static Matrix dd(nstress,nstress) ;  //material tangent


  //---------B-matrices------------------------------------

    static Matrix BJ(nstress,ndf) ;      // B matrix node J

    static Matrix BJtran(ndf,nstress) ;

    static Matrix BK(nstress,ndf) ;      // B matrix node k

    static Matrix BJtranD(ndf,nstress) ;

  //-------------------------------------------------------


  //zero stiffness and residual
  stiff.Zero( ) ;
  resid.Zero( ) ;

  //compute basis vectors and local nodal coordinates
  computeBasis( ) ;


  //zero mean shape functions
  for ( p = 0; p < nShape; p++ ) {
    for ( q = 0; q < numberNodes; q++ )
      shpBar[p][q] = 0.0 ;
  } // end for p

  //zero volume
  volume = 0.0 ;


  //gauss loop to compute and save shape functions
  int count = 0 ;

  for ( i = 0; i < 2; i++ ) {
    for ( j = 0; j < 2; j++ ) {
      for ( k = 0; k < 2; k++ ) {

        gaussPoint[0] = sg[i] ;
	gaussPoint[1] = sg[j] ;
	gaussPoint[2] = sg[k] ;

	//get shape functions
	shp3d( gaussPoint, xsj, shp, xl ) ;

	//save shape functions
	for ( p = 0; p < nShape; p++ ) {
	  for ( q = 0; q < numberNodes; q++ )
	    Shape[p][q][count] = shp[p][q] ;
	} // end for p

	//volume element to also be saved
	dvol[count] = wg[count] * xsj ;

        //add to volume
	volume += dvol[count] ;

	//add to mean shape functions
	for ( p = 0; p < nShape; p++ ) {
	  for ( q = 0; q < numberNodes; q++ )
	    shpBar[p][q] += ( dvol[count] * shp[p][q] ) ;
	} // end for p

	count++ ;

      } //end for k
    } //end for j
  } // end for i


  //mean value of shape functions
  for ( p = 0; p < nShape; p++ ) {
    for ( q = 0; q < numberNodes; q++ )
      shpBar[p][q] /= volume ;
  } // end for p


  //gauss loop
  for ( i = 0; i < numberGauss; i++ ) {

    //extract shape functions from saved array
    for ( p = 0; p < nShape; p++ ) {
       for ( q = 0; q < numberNodes; q++ )
	  shp[p][q]  = Shape[p][q][i] ;
    } // end for p


    //zero the strains
    strain.Zero( ) ;


    // j-node loop to compute strain
    for ( j = 0; j < numberNodes; j++ )  {

      //compute B matrix

      BJ = computeBbar( j, shp, shpBar ) ;

      //nodal displacements
      const Vector &ul = nodePointers[j]->getTrialDisp( ) ;

      //compute the strain
      //strain += (BJ*ul) ;
      strain.addMatrixVector(1.0,  BJ,ul,1.0 ) ;

    } // end for j



    //send the strain to the material
    success = materialPointers[i]->setTrialStrain( strain ) ;

    //compute the stress
    stress = materialPointers[i]->getStress( ) ;


    //multiply by volume element
    stress  *= dvol[i] ;

    if ( tang_flag == 1 ) {
      dd = materialPointers[i]->getTangent( ) ;
      dd *= dvol[i] ;
    } //end if tang_flag


    //residual and tangent calculations node loops

    jj = 0 ;
    for ( j = 0; j < numberNodes; j++ ) {

      BJ = computeBbar( j, shp, shpBar ) ;

      //transpose
      //BJtran = transpose( nstress, ndf, BJ ) ;
      for (p=0; p<ndf; p++) {
	for (q=0; q<nstress; q++)
	  BJtran(p,q) = BJ(q,p) ;
      }//end for p


      //residual
      //residJ = BJtran * stress ;
      residJ.addMatrixVector(0.0,  BJtran,stress,1.0);

      //residual
      for ( p = 0; p < ndf; p++ ) {
        resid( jj + p ) += residJ(p)  ;
		if (applyLoad == 0) {
	    	resid( jj + p ) -= dvol[i]*b[p]*shp[3][j];
		} else {
			resid( jj + p ) -= dvol[i]*appliedB[p]*shp[3][j];
		}
      }

      if ( tang_flag == 1 ) {

	//BJtranD = BJtran * dd ;
	BJtranD.addMatrixProduct(0.0,  BJtran,dd,1.0);

         kk = 0 ;
         for ( k = 0; k < numberNodes; k++ ) {

            BK = computeBbar( k, shp, shpBar ) ;


            //stiffJK =  BJtranD * BK  ;
	    stiffJK.addMatrixProduct(0.0,  BJtranD,BK,1.0) ;

            for ( p = 0; p < ndf; p++ )  {
               for ( q = 0; q < ndf; q++ )
                  stiff( jj+p, kk+q ) += stiffJK( p, q ) ;
            } //end for p

            kk += ndf ;
          } // end for k loop

      } // end if tang_flag

      jj += ndf ;
    } // end for j loop


  } //end for i gauss loop


  return ;
}
Exemple #13
0
void   BbarBrick::formInertiaTerms( int tangFlag )
{

  static const int ndm = 3 ;

  static const int ndf = 3 ;

  static const int numberNodes = 8 ;

  static const int numberGauss = 8 ;

  static const int nShape = 4 ;

  static const int massIndex = nShape - 1 ;

  double xsj ;  // determinant jacaobian matrix

  double dvol[numberGauss] ; //volume element

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static double Shape[nShape][numberNodes][numberGauss] ; //all the shape functions

  static double gaussPoint[ndm] ;

  static Vector momentum(ndf) ;

  int i, j, k, p, q ;
  int jj, kk ;

  double temp, rho, massJK ;


  //zero mass
  mass.Zero( ) ;

  //compute basis vectors and local nodal coordinates
  computeBasis( ) ;

  //gauss loop to compute and save shape functions

  int count = 0 ;

  for ( i = 0; i < 2; i++ ) {
    for ( j = 0; j < 2; j++ ) {
      for ( k = 0; k < 2; k++ ) {

        gaussPoint[0] = sg[i] ;
	gaussPoint[1] = sg[j] ;
	gaussPoint[2] = sg[k] ;

	//get shape functions
	shp3d( gaussPoint, xsj, shp, xl ) ;

	//save shape functions
	for ( p = 0; p < nShape; p++ ) {
	  for ( q = 0; q < numberNodes; q++ )
	    Shape[p][q][count] = shp[p][q] ;
	} // end for p

	//volume element to also be saved
	dvol[count] = wg[count] * xsj ;

	count++ ;

      } //end for k
    } //end for j
  } // end for i



  //gauss loop
  for ( i = 0; i < numberGauss; i++ ) {

    //extract shape functions from saved array
    for ( p = 0; p < nShape; p++ ) {
       for ( q = 0; q < numberNodes; q++ )
	  shp[p][q]  = Shape[p][q][i] ;
    } // end for p


    //node loop to compute acceleration
    momentum.Zero( ) ;
    for ( j = 0; j < numberNodes; j++ )
      //momentum += shp[massIndex][j] * ( nodePointers[j]->getTrialAccel()  ) ;
      momentum.addVector( 1.0,
			  nodePointers[j]->getTrialAccel(),
			  shp[massIndex][j] ) ;


    //density
    rho = materialPointers[i]->getRho() ;

    //multiply acceleration by density to form momentum
    momentum *= rho ;


    //residual and tangent calculations node loops
    jj = 0 ;
    for ( j = 0; j < numberNodes; j++ ) {

      temp = shp[massIndex][j] * dvol[i] ;

      for ( p = 0; p < ndf; p++ )
        resid( jj+p ) += ( temp * momentum(p) )  ;


      if ( tangFlag == 1 ) {

	 //multiply by density
	 temp *= rho ;

	 //node-node mass
         kk = 0 ;
         for ( k = 0; k < numberNodes; k++ ) {

	    massJK = temp * shp[massIndex][k] ;

            for ( p = 0; p < ndf; p++ )
	      mass( jj+p, kk+p ) += massJK ;

            kk += ndf ;
          } // end for k loop

      } // end if tang_flag

      jj += ndf ;
    } // end for j loop


  } //end for i gauss loop

}
Exemple #14
0
//return stiffness matrix
const Matrix&  BbarBrick::getInitialStiff( )
{
  if (Ki != 0)
    return *Ki;

  //strains ordered : eps11, eps22, eps33, 2*eps12, 2*eps23, 2*eps31

  static const int ndm = 3 ;

  static const int ndf = 3 ;

  static const int nstress = 6 ;

  static const int numberNodes = 8 ;

  static const int numberGauss = 8 ;

  static const int nShape = 4 ;

  int i, j, k, p, q ;
  int jj, kk ;

  static double volume ;

  static double xsj ;  // determinant jacaobian matrix

  static double dvol[numberGauss] ; //volume element

  static double gaussPoint[ndm] ;

  static Vector strain(nstress) ;  //strain

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static double Shape[nShape][numberNodes][numberGauss] ; //all the shape functions

  static double shpBar[nShape][numberNodes] ;  //mean value of shape functions

  static Matrix stiffJK(ndf,ndf) ; //nodeJK stiffness

  static Matrix dd(nstress,nstress) ;  //material tangent


  //---------B-matrices------------------------------------

    static Matrix BJ(nstress,ndf) ;      // B matrix node J

    static Matrix BJtran(ndf,nstress) ;

    static Matrix BK(nstress,ndf) ;      // B matrix node k

    static Matrix BJtranD(ndf,nstress) ;

  //-------------------------------------------------------


  //zero stiffness and residual
  stiff.Zero( ) ;


  //compute basis vectors and local nodal coordinates
  computeBasis( ) ;

  //zero mean shape functions
  for ( p = 0; p < nShape; p++ ) {
    for ( q = 0; q < numberNodes; q++ )
      shpBar[p][q] = 0.0 ;
  } // end for p

  //zero volume
  volume = 0.0 ;


  //gauss loop to compute and save shape functions
  int count = 0 ;

  for ( i = 0; i < 2; i++ ) {
    for ( j = 0; j < 2; j++ ) {
      for ( k = 0; k < 2; k++ ) {

        gaussPoint[0] = sg[i] ;
	gaussPoint[1] = sg[j] ;
	gaussPoint[2] = sg[k] ;

	//get shape functions
	shp3d( gaussPoint, xsj, shp, xl ) ;

	//save shape functions
	for ( p = 0; p < nShape; p++ ) {
	  for ( q = 0; q < numberNodes; q++ )
	    Shape[p][q][count] = shp[p][q] ;
	} // end for p

	//volume element to also be saved
	dvol[count] = wg[count] * xsj ;

        //add to volume
	volume += dvol[count] ;

	//add to mean shape functions
	for ( p = 0; p < nShape; p++ ) {
	  for ( q = 0; q < numberNodes; q++ )
	    shpBar[p][q] += ( dvol[count] * shp[p][q] ) ;
	} // end for p

	count++ ;

      } //end for k
    } //end for j
  } // end for i


  //mean value of shape functions
  for ( p = 0; p < nShape; p++ ) {
    for ( q = 0; q < numberNodes; q++ )
      shpBar[p][q] /= volume ;
  } // end for p


  //gauss loop
  for ( i = 0; i < numberGauss; i++ ) {

    //extract shape functions from saved array
    for ( p = 0; p < nShape; p++ ) {
       for ( q = 0; q < numberNodes; q++ )
	  shp[p][q]  = Shape[p][q][i] ;
    } // end for p

    dd = materialPointers[i]->getInitialTangent( ) ;
    dd *= dvol[i] ;

    //residual and tangent calculations node loops

    jj = 0 ;
    for ( j = 0; j < numberNodes; j++ ) {

      BJ = computeBbar( j, shp, shpBar ) ;

      //transpose
      //BJtran = transpose( nstress, ndf, BJ ) ;
      for (p=0; p<ndf; p++) {
	for (q=0; q<nstress; q++)
	  BJtran(p,q) = BJ(q,p) ;
      }//end for p

      //BJtranD = BJtran * dd ;
      BJtranD.addMatrixProduct(0.0,  BJtran,dd,1.0);

      kk = 0 ;
      for ( k = 0; k < numberNodes; k++ ) {

	BK = computeBbar( k, shp, shpBar ) ;

	//stiffJK =  BJtranD * BK  ;
	stiffJK.addMatrixProduct(0.0,  BJtranD,BK,1.0) ;

	for ( p = 0; p < ndf; p++ )  {
	  for ( q = 0; q < ndf; q++ )
	    stiff( jj+p, kk+q ) += stiffJK( p, q ) ;
	} //end for p

	kk += ndf ;
      } // end for k loop

      jj += ndf ;

    } // end for j loop
  } //end for i gauss loop

  Ki = new Matrix(stiff);

  return stiff ;
}
Exemple #15
0
int
XC::Twenty_Node_Brick::update()
{
        int i, j;
        static double u[3][20];
        static double xsj;
        static XC::Matrix B(6, 3);
        double volume = 0.;

        for(i = 0; i < nenu; i++) {
             const XC::Vector &disp = theNodes[i]->getTrialDisp();
             u[0][i] = disp(0);
             u[1][i] = disp(1);
             u[2][i] = disp(2);
    }

        static XC::Vector eps(6);

        int ret = 0;

        //compute basis vectors and local nodal coordinates
        computeBasis( ) ;

        for( i = 0; i < nintu; i++ ) {
                // compute Jacobian and global shape functions
                Jacobian3d(i, xsj, 0);
                //volume element to also be saved
                dvolu[i] = wu[i] * xsj ;
                volume += dvolu[i];
        } // end for i
    //printf("volume = %f\n", volume);

        // Loop over the integration points
        for(i = 0; i < nintu; i++) {

                // Interpolate strains
                //eps = B*u;
                //eps.addMatrixVector(0.0, B, u, 1.0);
                eps.Zero();
                for( j = 0; j < nenu; j++) {


                        B(0,0) = shgu[0][j][i];
                        B(0,1) = 0.;
                        B(0,2) = 0.;
                        B(1,0) = 0.;
                        B(1,1) = shgu[1][j][i];
                        B(1,2) = 0.;
                        B(2,0) = 0.;
                        B(2,1) = 0.;
                        B(2,2) = shgu[2][j][i];
                        B(3,0) = shgu[1][j][i];
                        B(3,1) = shgu[0][j][i];
                        B(3,2) = 0.;
                        B(4,0) = 0.;
                        B(4,1) = shgu[2][j][i];
                        B(4,2) = shgu[1][j][i];
                        B(5,0) = shgu[2][j][i];
                        B(5,1) = 0.;
                        B(5,2) = shgu[0][j][i];

                        //BJ = computeB( j, shp ) ;

                        //nodal displacements
                        const XC::Vector &ul = theNodes[j]->getTrialDisp( ) ;
                        Vector ul3(3);
                        ul3(0) = ul(0);
                        ul3(1) = ul(1);
                        ul3(2) = ul(2);
                        //compute the strain
                        //strain += (BJ*ul) ;
                        eps.addMatrixVector(1.0,B,ul3,1.0 ) ;

                        /* for( k = 0; k < 6; k++) {
                        for( k1 = 0; k1 < 3; k1++) {
                        eps[k] += BJ(k, k1)*u[k1][j];
                        }
                }        */


                }

                // Set the material strain
                ret += physicalProperties[i]->setTrialStrain(eps);
        }

        return ret;
}
Exemple #16
0
// compute stiffness matrix
const XC::Matrix&  XC::Twenty_Node_Brick::getStiff(int flag) const
{
        if(flag != 0 && flag != 1) {
                std::cerr << "FATAL XC::Twenty_Node_Brick::getStiff() - illegal use\n";
                exit(-1);
        }

        if(flag == 0 && Ki != 0)
                return *Ki;

        int i, j ;

        static double xsj ;  // determinant jacaobian matrix
        double volume = 0.;
        //-------------------------------------------------------
        int j3, j3m1, j3m2;
        static XC::Matrix B(6,nenu*3);
        static XC::Matrix BTDB(nenu*3,nenu*3);
        static XC::Matrix D(6, 6);
        B.Zero();
        BTDB.Zero();
        stiff.Zero();
//                FILE *fp;
//                fp = fopen("stiff.dat","w");

        //compute basis vectors and local nodal coordinates
        computeBasis( ) ;

        for( i = 0; i < nintu; i++ ) {
                // compute Jacobian and global shape functions
                Jacobian3d(i, xsj, 0);
                //volume element to also be saved
                dvolu[i] = wu[i] * xsj ;
                volume += dvolu[i];
        } // end for i
    //printf("volume = %f\n", volume);

//        for( i = 0; i < nintu; i++ ) {
//                for(int j = 0; j < nenu; j++ ) {
//                        printf("%5d %5d %15.6e %15.6e %15.6e %15.6e\n", i,j,
//                                shgu[0][j][i], shgu[1][j][i], shgu[2][j][i], shgu[3][j][i]);
//                }
//        }
//        exit(-1);

        // Loop over the integration points
        for(i = 0; i < nintu; i++) {

                // Get the material tangent
                if( flag == 0 )
                        D = physicalProperties[i]->getInitialTangent();
                else
                        D = physicalProperties[i]->getTangent();
                //const Matrix &D = physicalProperties[i]->getTangent();


                for(j=0; j<nenu; j++) {

                        j3   = 3*j+2;
                        j3m1 = j3 - 1;
                        j3m2 = j3 - 2;

                        B(0,j3m2) = shgu[0][j][i];
                        B(0,j3m1) = 0.;
                        B(0,j3  ) = 0.;

                        B(1,j3m2) = 0.;
                        B(1,j3m1) = shgu[1][j][i];
                        B(1,j3  ) = 0.;

                        B(2,j3m2) = 0.;
                        B(2,j3m1) = 0.;
                        B(2,j3  ) = shgu[2][j][i];

                        B(3,j3m2) = shgu[1][j][i];
                        B(3,j3m1) = shgu[0][j][i];
                        B(3,j3  ) = 0.;

                        B(4,j3m2) = 0.;
                        B(4,j3m1) = shgu[2][j][i];
                        B(4,j3  ) = shgu[1][j][i];

                        B(5,j3m2) = shgu[2][j][i];
                        B(5,j3m1) = 0.;
                        B(5,j3  ) = shgu[0][j][i];

                }

                // Perform numerical integration
                //K = K + (B^ D * B) * intWt(i) * detJ;
                BTDB.addMatrixTripleProduct(1.0, B, D, dvolu[i]);
        }
    for( i = 0; i < 60; i++)
                for( j = 0; j < 60; j++)
                        stiff(i,j) = BTDB(i,j);

        if( flag == 1) {
                return stiff;
        }
        Ki = new Matrix(stiff);
        if(Ki == 0) {
                std::cerr << "FATAL XC::Twenty_Node_Brick::getStiff() -";
                std::cerr << "ran out of memory\n";
                exit(-1);
        }

        return *Ki;
}
Exemple #17
0
//return secant matrix 
const Matrix& 
NineNodeMixedQuad::getInitialStiff( ) 
{
  if (Ki != 0)
    return *Ki;

  static const int ndm = 2 ;

  static const int ndf = 2 ; 

  static const int nstress = 4 ;
 
  static const int numberNodes = 9 ;

  static const int numberGauss = 9 ;

  static const int nShape = 3 ;

  static const int nMixed = 3 ;

  int i, j, k, p, q, r, s ;
  int jj, kk ;

  static double volume ;

  static double xsj ;  // determinant jacaobian matrix 

  static double dvol[numberGauss] ; //volume element

  static double gaussPoint[ndm] ;

  static double natCoorArray[ndm][numberGauss] ;

  static Vector strain(nstress) ;  //strain

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static double Shape[nShape][numberNodes][numberGauss] ; //all the shape functions

  static double shpBar[nShape][numberNodes][nMixed] ; //mean value of shape functions

  static double rightHandSide[nShape][numberNodes][nMixed] ;

  static Vector residJ(ndf) ; //nodeJ residual 

  static Matrix stiffJK(ndf,ndf) ; //nodeJK stiffness 

  static Vector stress(nstress) ;  //stress

  static Matrix dd(nstress,nstress) ;  //material tangent

  static double interp[nMixed] ;

  static Matrix Proj(3,3) ;   //projection matrix 
  static Matrix ProjInv(3,3) ;

  static Matrix Iden(3,3) ;
  Iden(0,0) = 1.0 ;
  Iden(1,1) = 1.0 ;
  Iden(2,2) = 1.0 ;

  //---------B-matrices------------------------------------

    static Matrix BJ(nstress,ndf) ;      // B matrix node J

    static Matrix BJtran(ndf,nstress) ;

    static Matrix BK(nstress,ndf) ;      // B matrix node k

    static Matrix BJtranD(ndf,nstress) ;

  //-------------------------------------------------------

  
  //zero stiffness and residual 
  stiff.Zero( ) ;

  //node coordinates
  computeBasis() ;

  //zero mean shape functions
  for ( p=0; p<nShape; p++ ) {
    for ( q=0; q<numberNodes; q++ ) {

      for (r=0; r<nMixed; r++ ) {
	shpBar[p][q][r] = 0.0 ;
	rightHandSide[p][q][r] = 0.0 ;
      }

    }//end for q
  } // end for p


  //zero volume
  volume = 0.0 ;

  //zero projection matrix  
  Proj.Zero( ) ;
  ProjInv.Zero( ) ;

  //gauss loop to compute and save shape functions 
  int count = 0 ;

  for ( i = 0; i < 3; i++ ) {
    for ( j = 0; j < 3; j++ ) {

        gaussPoint[0] = sg[i] ;        
	gaussPoint[1] = sg[j] ;        


	//save gauss point locations
	natCoorArray[0][count] = gaussPoint[0] ;
	natCoorArray[1][count] = gaussPoint[1] ;


	//get shape functions    
	shape2dNine( gaussPoint, xl, shp, xsj ) ;


	//save shape functions
	for ( p=0; p<nShape; p++ ) {
	  for ( q=0; q<numberNodes; q++ )
	    Shape[p][q][count] = shp[p][q] ;
	} // end for p

	
	//volume element to also be saved
	dvol[count] = ( wg[i]*wg[j] ) * xsj ;  


        //add to projection matrix
	interp[0] = 1.0 ;
	interp[1] = gaussPoint[0] ;
	interp[2] = gaussPoint[1] ;
	
	for ( r=0; r<nMixed; r++ ) {
	  for ( s=0; s<nMixed; s++ ) 
	    Proj(r,s) += ( interp[r]*interp[s] * dvol[count] ) ;
	}//end for r

	volume += dvol[count] ;
	
	
	//add to mean shape functions
	for ( p=0; p<nShape; p++ ) {
	  for ( q=0; q<numberNodes; q++ ) {

	    for ( s=0; s<nMixed; s++ ) 
	      rightHandSide[p][q][s] += ( shp[p][q] * interp[s] * dvol[count] ) ;

	  }//end for q 
	} // end for p


	//increment gauss point counter
	count++ ;

    } //end for j
  } // end for i 
  


  //invert projection matrix
  //int Solve(const Matrix &M, Matrix &res) const;
  Proj.Solve( Iden, ProjInv ) ;
  
  //mean value of shape functions
  for ( p=0; p<nShape; p++ ) {
    for ( q=0; q<numberNodes; q++ ) {

      for (r=0; r<nMixed; r++ ) {
	for (s=0; s<nMixed; s++ ) 
	  shpBar[p][q][r] += ( ProjInv(r,s) * rightHandSide[p][q][s] ) ;
      }//end for r

    }//end for q
  }//end for p


  //gauss loop 
  for ( i=0; i<numberGauss; i++ ) {
    
    //extract gauss point location
    gaussPoint[0] = natCoorArray[0][i] ;
    gaussPoint[1] = natCoorArray[1][i] ;

    //extract shape functions from saved array
    for ( p=0; p<nShape; p++ ) {
       for ( q=0; q<numberNodes; q++ )
	  shp[p][q]  = Shape[p][q][i] ;
    } // end for p

    dd = materialPointers[i]->getInitialTangent( ) ;
    dd *= dvol[i] ;


    //residual and tangent calculations node loops

    jj = 0 ;
    for ( j=0; j<numberNodes; j++ ) {

      BJ = computeBbar( j, gaussPoint, shp, shpBar ) ;
   
      //transpose 
      //BJtran = transpose( nstress, ndf, BJ ) ;
      for (p=0; p<ndf; p++) {
	for (q=0; q<nstress; q++) 
	  BJtran(p,q) = BJ(q,p) ;
      }//end for p


      //BJtranD = BJtran * dd ;
      BJtranD.addMatrixProduct(0.0,  BJtran,dd,1.0);

      kk = 0 ;
      for ( k=0; k<numberNodes; k++ ) {
	
	BK = computeBbar( k, gaussPoint, shp, shpBar ) ;
  
	
	//stiffJK =  BJtranD * BK  ;
	stiffJK.addMatrixProduct(0.0,  BJtranD,BK,1.0) ;

	for ( p=0; p<ndf; p++ )  {
	  for ( q=0; q<ndf; q++ )
	    stiff( jj+p, kk+q ) += stiffJK( p, q ) ;
	} //end for p
	
	kk += ndf ;
      }//end for k loop

      jj += ndf ;
    }//end for j loop
  }//end for i gauss loop 

  Ki = new Matrix(stiff);

  return stiff;
}
Exemple #18
0
void   
NineNodeMixedQuad::formInertiaTerms( int tangFlag ) 
{

  static const int ndm = 2 ;

  static const int ndf = 2 ; 

  static const int numberNodes = 9 ;

  //  static const int numberGauss = 9 ;

  static const int nShape = 3 ;

  static const int massIndex = nShape - 1 ;

  double xsj ;  // determinant jacaobian matrix 

  double dvol ; //volume element

  static double shp[nShape][numberNodes] ;  //shape functions at a gauss point

  static Vector momentum(ndf) ;

  static Matrix sx(ndm,ndm) ;

  static double GaussPoint[2] ;

  int j, k, p, q, r ;
  int jj, kk ;

  double temp, rho, massJK ;


  //zero mass 
  mass.Zero( ) ;

  //node coordinates
  computeBasis() ;

  //gauss loop 
  int count = 0 ;
  for ( p=0; p<3; p++ ) {
    for ( q=0; q<3; q++ ) {
 
    GaussPoint[0] = sg[p] ;
    GaussPoint[1] = sg[q] ;

    //get shape functions    
    shape2dNine( GaussPoint, xl, shp, xsj ) ;

    //volume element
    dvol = ( wg[p] * wg[q] ) * xsj ;

    //node loop to compute acceleration
    momentum.Zero( ) ;
    for ( j = 0; j < numberNodes; j++ ) 
      //momentum += shp[massIndex][j] * ( nodePointers[j]->getTrialAccel()  ) ; 
      momentum.addVector( 1.0,
			  nodePointers[j]->getTrialAccel(),
			  shp[massIndex][j] ) ;


    //density
    rho = materialPointers[count]->getRho() ;

    //multiply acceleration by density to form momentum
    momentum *= rho ;


    //residual and tangent calculations node loops
    for ( jj=0, j=0; j<numberNodes; j++, jj+=ndf ) {

      temp = shp[massIndex][j] * dvol ;

      for ( r=0; r<ndf; r++ )
        resid( jj+r ) += ( temp * momentum(r) )  ;

      
      if ( tangFlag == 1 ) {

	 //multiply by density
	 temp *= rho ;

	 //node-node mass
         for ( kk=0, k=0; k<numberNodes; k++, kk+=ndf ) {

	    massJK = temp * shp[massIndex][k] ;

            for ( r=0; r<ndf; r++ )  
	      mass( jj+r, kk+r ) += massJK ;
            
          } // end for k loop

      } // end if tang_flag 

    } // end for j loop

    
    count++ ;
    }//end for q gauss loop
  } //end for p gauss loop 

}
void DrawWireCapsule(const NxCapsule& capsule, const NxVec3& color)
{
	NxReal r = capsule.radius;
	NxVec3 dir = capsule.p0 - capsule.p1;
	NxReal h = dir.magnitude();
	NxMat34 pose;
	pose.t = (capsule.p0 + capsule.p1)*0.5f;

	if(h!=0.0f)
	{
		dir/=h;
		NxVec3 right, up;
		computeBasis(dir, right, up);
		pose.M.setColumn(0, right);
		pose.M.setColumn(1, dir);
		pose.M.setColumn(2, up);
	}
	else
	{
		pose.M.id();
	}

//	NxMat34 pose = capsule->getGlobalPose();
//	const NxReal & r = capsule->isCapsule()->getRadius();
//	const NxReal & h = capsule->isCapsule()->getHeight();



	NxSegment SG;
	pose.M.getColumn(1, SG.p1);
	SG.p1 *= 0.5f*h;
	SG.p0 = -SG.p1;
	SG.p0 += pose.t;
	SG.p1 += pose.t;

	NxVec3 c0;	pose.M.getColumn(0, c0);
	NxVec3 c1;	pose.M.getColumn(1, c1);
	NxVec3 c2;	pose.M.getColumn(2, c2);
	DrawLine(SG.p0 + c0*r, SG.p1 + c0*r, color);
	DrawLine(SG.p0 - c0*r, SG.p1 - c0*r, color);
	DrawLine(SG.p0 + c2*r, SG.p1 + c2*r, color);
	DrawLine(SG.p0 - c2*r, SG.p1 - c2*r, color);

	pose.M.setColumn(0, -c1);
	pose.M.setColumn(1, -c0);
	pose.M.setColumn(2, c2);
	pose.t = SG.p0;
	DrawCircle(20, pose, color, r, true);	//halfcircle -- flipped

	pose.M.setColumn(0, c1);
	pose.M.setColumn(1, -c0);
	pose.M.setColumn(2, c2);
	pose.t = SG.p1;
	DrawCircle(20, pose, color, r, true);

	pose.M.setColumn(0, -c1);
	pose.M.setColumn(1, c2);
	pose.M.setColumn(2, c0);
	pose.t = SG.p0;
	DrawCircle(20, pose, color, r, true);//halfcircle -- good

	pose.M.setColumn(0, c1);
	pose.M.setColumn(1, c2);
	pose.M.setColumn(2, c0);
	pose.t = SG.p1;
	DrawCircle(20, pose, color, r, true);

	pose.M.setColumn(0, c2);
	pose.M.setColumn(1, c0);
	pose.M.setColumn(2, c1);
	pose.t = SG.p0;
	DrawCircle(20, pose, color, r);	//full circle
	pose.t = SG.p1;
	DrawCircle(20, pose, color, r);
}