Example #1
0
const Matrix &
CorotTruss::getInitialStiff(void)
{
    static Matrix kl(3,3);

    // Material stiffness
    kl.Zero();
    kl(0,0) = A * theMaterial->getInitialTangent() / Lo;

    // Compute R'*kl*R
    static Matrix kg(3,3);
    kg.addMatrixTripleProduct(0.0, R, kl, 1.0);

    Matrix &K = *theMatrix;
    K.Zero();

    // Copy stiffness into appropriate blocks in element stiffness
    int numDOF2 = numDOF/2;
    for (int i = 0; i < numDIM; i++) {
        for (int j = 0; j < numDIM; j++) {
            K(i,j)                 =  kg(i,j);
            K(i,j+numDOF2)         = -kg(i,j);
            K(i+numDOF2,j)         = -kg(i,j);
            K(i+numDOF2,j+numDOF2) =  kg(i,j);
        }
    }

    return *theMatrix;
}
const Matrix& ElastomericBearingBoucWen2d::getDamp()
{
    // zero the matrix
    theMatrix.Zero();
    
    // call base class to setup Rayleigh damping
    double factThis = 0.0;
    if (addRayleigh == 1)  {
        theMatrix = this->Element::getDamp();
        factThis = 1.0;
    }
    
    // now add damping tangent from materials
    static Matrix cb(3,3);
    cb.Zero();
    cb(0,0) = theMaterials[0]->getDampTangent();
    cb(2,2) = theMaterials[1]->getDampTangent();
    
    // transform from basic to local system
    static Matrix cl(6,6);
    cl.addMatrixTripleProduct(0.0, Tlb, cb, 1.0);
    
    // transform from local to global system and add to cg
    theMatrix.addMatrixTripleProduct(factThis, Tgl, cl, 1.0);
    
    return theMatrix;
}
Example #3
0
//! @brief Return initial stiffness matrix.
const XC::Matrix &XC::CorotTruss::getInitialStiff(void) const
  {
    static Matrix kl(3,3);

    if(A<1e-8)
      std::clog << getClassName() << "::" << __FUNCTION__
	        << "; WARNING area of element: " << getTag()
	        << " is extremely small: " << A << std::endl;
    // Material stiffness
    kl.Zero();
    kl(0,0)= A*theMaterial->getInitialTangent() / Lo;

    // Compute R'*kl*R
    static Matrix kg(3,3);
    kg.addMatrixTripleProduct(0.0, R, kl, 1.0);

    Matrix &K = *theMatrix;
    K.Zero();

    // Copy stiffness into appropriate blocks in element stiffness
    int numDOF2 = numDOF/2;
    for(int i = 0; i < getNumDIM(); i++)
      {
        for(int j = 0; j < getNumDIM(); j++)
	  {
            K(i,j)                 =  kg(i,j);
            K(i,j+numDOF2)         = -kg(i,j);
            K(i+numDOF2,j)         = -kg(i,j);
            K(i+numDOF2,j+numDOF2) =  kg(i,j);
          }
      }
    if(isDead())
      (*theMatrix)*=dead_srf;
    return *theMatrix;
  }
void
PFEMElement2DBubble::getdK(Matrix& dk) const
{
    double J2 = J/2.*thickness;
    // double lambda = -2*mu/3.0;

    dk.resize(6,6);
    dk.Zero();

    double dNdx[3], dNdy[3];
    for(int a=0; a<3; a++) {
        dNdx[a] = dJ(2*a)/J;
        dNdy[a] = dJ(2*a+1)/J;
    }
    
    // other matrices
    for(int a=0; a<3; a++) {
        for(int b=0; b<3; b++) {
            dk(2*a, 2*b) += J2*(2*dNdx[a]*dNdx[b] + dNdy[a]*dNdy[b]); // K1
            dk(2*a, 2*b+1) += J2*dNdy[a]*dNdx[b]; // K1
            dk(2*a+1, 2*b) += J2*dNdx[a]*dNdy[b]; // K1
            dk(2*a+1, 2*b+1) += J2*(2*dNdy[a]*dNdy[b] + dNdx[a]*dNdx[b]); // K1

            // K(2*a, 2*b) += lambda*J2*dNdx[a]*dNdx[b]; // K2
            // K(2*a, 2*b+1) += lambda*J2*dNdx[a]*dNdy[b]; // K2
            // K(2*a+1, 2*b) += lambda*J2*dNdy[a]*dNdx[b]; // K2
            // K(2*a+1, 2*b+1) += lambda*J2*dNdy[a]*dNdy[b]; // K2
        }
    }
}
void 
PFEMElement2DBubble::getdF(Matrix& df) const {

    df.resize(6,6);
    df.Zero();

    for(int a=0; a<3; a++) {
        for(int b=0; b<6; b++) {
            df(2*a,b) = bx*dJ(b);
            df(2*a+1,b) = by*dJ(b);
        }
    }

    df *= rho*thickness/6.0;

    // velocity
    if(mu > 0) {
        Vector v(6);
        for(int a=0; a<3; a++) {
            const Vector& vel = nodes[2*a]->getTrialVel();
            v(2*a) = vel(0);
            v(2*a+1) = vel(1);
        }
        Matrix dk(6,6);
        getdK(v,dk);
        df -= dk;
    }
}
Example #6
0
const Matrix&
Timoshenko2d::getInitialBasicStiff()
{
  static Matrix kb(3,3);

  // Zero for integration
  kb.Zero();
  
  double L = crdTransf->getInitialLength();
  const Vector &v = crdTransf->getBasicTrialDisp();
  double oneOverL = 1.0/L;
  
  double pts[maxNumSections];
  beamInt->getSectionLocations(numSections, L, pts);
  double wts[maxNumSections];
  beamInt->getSectionWeights(numSections, L, wts);

  // Loop over the integration points
  for (int i = 0; i<numSections; i++) {
    int order = theSections[i]->getOrder();
    const ID &code = theSections[i]->getType();
  
    // Get the section tangent stiffness and stress resultant
    const Matrix &ks = theSections[i]->getInitialTangent();
    
	// Perform numerical integration
	bd[i] = this->getBd(i, v, L);
    kb.addMatrixTripleProduct(1.0, bd[i], ks, L*wts[i]);
  }
  return kb;
}
void ColoredPolygon::DrawBinded()
{
    _trianglesBinded = _triangles;
    Matrix tmp;
    for (uint i = 0; i < _trianglesBinded.GetVB().Size(); ++i)
    {
        bool needMul = false;
        tmp.Zero();
        if (_dots[i].p[0].bone)
        {
            tmp.Add(_dots[i].p[0].bone->GetAnimVertMatrix(), _dots[i].p[0].mass);
            needMul = true;
        }
        if (_dots[i].p[1].bone)
        {
            tmp.Add(_dots[i].p[1].bone->GetAnimVertMatrix(), _dots[i].p[1].mass);
        }
        if (needMul)
            tmp.Mul(_trianglesBinded.GetVB().VertXY(i));
    }

    Render::PushColorAndMul(_color);
    _trianglesBinded.Render();
    Render::PopColor();
}
Example #8
0
const Matrix &
Element::getDampSensitivity(int gradIndex) 
{
  if (index  == -1) {
    this->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
  }

  // now compute the damping matrix
  Matrix *theMatrix = theMatrices[index]; 
  theMatrix->Zero();
  if (alphaM != 0.0) {
    theMatrix->addMatrix(0.0, this->getMassSensitivity(gradIndex), alphaM);
  }
  if (betaK != 0.0) {
	theMatrix->addMatrix(1.0, this->getTangentStiff(), 0.0); // Don't use this and DDM      
	//opserr << "Rayleigh damping with non-zero betaCurrentTangent is not compatible with DDM sensitivity analysis" << endln;
  }
  if (betaK0 != 0.0) {
    theMatrix->addMatrix(1.0, this->getInitialStiffSensitivity(gradIndex), betaK0);      
  }
  if (betaKc != 0.0) {
    theMatrix->addMatrix(1.0, *Kc, 0.0);      // Don't use this and DDM   
    //opserr << "Rayleigh damping with non-zero betaCommittedTangent is not compatible with DDM sensitivity analysis" << endln;
  }

  // return the computed matrix
  return *theMatrix;
}
Example #9
0
int loadMatrix(Matrix& a, String& fileName) {
  a.Zero();

  IFILE ifile(fileName.c_str(), "r");
  String line;
  StringArray array;
  int lineNo = 0;
  while (!ifeof(ifile)) {
    line.ReadLine(ifile);
    lineNo++;
    if (line.Length() == 0) continue;
    array.Clear();
    array.AddTokens(line);
    if (a.cols != 0 && a.cols != array.Length() && line.Length() > 0) {
      fprintf(stderr, "Wrong column size at line %d!\n", lineNo);
      array.Print();
      line.Write(stdout);
      return -1;
    } else {
      a.GrowTo(a.rows, array.Length());
    }
    if (a.rows < lineNo) {
      a.GrowTo(a.rows + 1, a.cols);
    }
    for (int i = 0; i < array.Length(); i++) {
      a[lineNo - 1][i] = atol(array[i]);
    }
  }

  // a.Print(stdout);
  return 0;
};
Example #10
0
int EEBeamColumn2d::setInitialStiff(const Matrix &kbinit)
{
    if (kbinit.noRows() != 3 || kbinit.noCols() != 3)  {
        opserr << "EEBeamColumn2d::setInitialStiff() - "
               << "matrix size is incorrect for element: "
               << this->getTag() << endln;
        return -1;
    }
    kbInit = kbinit;

    // transform stiffness from basic sys B to basic sys A
    static Matrix kbAInit(3,3);
    kbAInit.Zero();
    kbAInit(0,0) = kbInit(0,0);
    kbAInit(1,1) = L*L*kbInit(1,1) + L*(kbInit(1,2)+kbInit(2,1)) + kbInit(2,2);
    kbAInit(1,2) = -L*kbInit(1,2) - kbInit(2,2);
    kbAInit(2,1) = -L*kbInit(2,1) - kbInit(2,2);
    kbAInit(2,2) = kbInit(2,2);

    // transform stiffness from the basic to the global system
    theInitStiff.Zero();
    theInitStiff = theCoordTransf->getInitialGlobalStiffMatrix(kbAInit);

    return 0;
}
Example #11
0
const Matrix& ActuatorCorot::getInitialStiff(void)
{
    // zero the matrix
    theMatrix->Zero();
    
    // local stiffness matrix
    static Matrix kl(3,3);
    
    // material stiffness portion
    kl.Zero();
    kl(0,0) = EA/L;
    
    // compute R'*kl*R
    static Matrix kg(3,3);
    kg.addMatrixTripleProduct(0.0, R, kl, 1.0);
    
    // copy stiffness into appropriate blocks in element stiffness
    int numDOF2 = numDOF/2;
    for (int i=0; i<numDIM; i++)  {
        for (int j=0; j<numDIM; j++)  {
            (*theMatrix)(i,j) = kg(i,j);
            (*theMatrix)(i,j+numDOF2) = -kg(i,j);
            (*theMatrix)(i+numDOF2,j) = -kg(i,j);
            (*theMatrix)(i+numDOF2,j+numDOF2) = kg(i,j);
        }
    }
    
    return *theMatrix;
}
Example #12
0
const Matrix &
FiberSection2d::getInitialTangentSensitivity(int gradIndex)
{
  static Matrix dksdh(2,2);
  
  dksdh.Zero();

  double y, A, dydh, dAdh;
  double tangent = 0.0;
  double dtangentdh = 0.0;

  static double fiberLocs[10000];
  static double fiberArea[10000];

  if (sectionIntegr != 0) {
    sectionIntegr->getFiberLocations(numFibers, fiberLocs);
    sectionIntegr->getFiberWeights(numFibers, fiberArea);
  }  
  else {
    for (int i = 0; i < numFibers; i++) {
      fiberLocs[i] = matData[2*i];
      fiberArea[i] = matData[2*i+1];
    }
  }

  static double locsDeriv[10000];
  static double areaDeriv[10000];

  if (sectionIntegr != 0) {
    sectionIntegr->getLocationsDeriv(numFibers, locsDeriv);  
    sectionIntegr->getWeightsDeriv(numFibers, areaDeriv);
  }
  else {
    for (int i = 0; i < numFibers; i++) {
      locsDeriv[i] = 0.0;
      areaDeriv[i] = 0.0;
    }
  }
  
  for (int i = 0; i < numFibers; i++) {
    y = fiberLocs[i] - yBar;
    A = fiberArea[i];
    dydh = locsDeriv[i];
    dAdh = areaDeriv[i];
    
    tangent = theMaterials[i]->getInitialTangent();
    dtangentdh = theMaterials[i]->getInitialTangentSensitivity(gradIndex);

    dksdh(0,0) += dtangentdh*A + tangent*dAdh;

    dksdh(0,1) += -y*(dtangentdh*A+tangent*dAdh) - dydh*(tangent*A);

    dksdh(1,1) += 2*(y*dydh*tangent*A) + y*y*(dtangentdh*A+tangent*dAdh);
  }

  dksdh(1,0) = dksdh(0,1);

  return dksdh;
}
Example #13
0
const Matrix &
FiberSection3d::getSectionTangentSensitivity(int gradIndex)
{
  static Matrix something(3,3);
  
  something.Zero();
  
  return something;
}
void BeamColumnJoint3d::matDiag(Vector k,Matrix &dfd)
{
	dfd.Zero();
	// takes in a vector and converts it to a diagonal matrix (could have been placed as a method in matrix class)
	for (int ja=0; ja<13; ja++)
	{
		dfd(ja,ja) = k(ja);
	}

}
Example #15
0
int
FindCurvatures::gramSchmidt(const Vector &first, Matrix &R)
{
    // simple GS orthogonalization of input (row) vector first
    int n = first.Size();
    R.resize(n,n);
    R.Zero();
    Matrix R0(R);
    Matrix temp(R);
    
    for (int i = 0; i < n; i++) {
        R0(i,i) = 1;
        R0(n-1,i) = first(i);
        R(n-1,i) = first(i);
    }
    
    // computation of the rows of R
    for (int k = n-2; k >= 0; k--) {
        temp.Zero();
        for (int j = k+1; j < n; j++) {
            double numer = 0;
            double denom = 0;
            for (int i = 0; i < n; i++) {
                numer += R(j,i)*R0(k,i);
                denom += R(j,i)*R(j,i);
            }
            
            for (int i = 0; i < n; i++)
                temp(j,i) = numer/denom * R(j,i);
        }
        
        // sum columns
        for (int j = 0; j < n; j++) {
            double sum_j = 0;
            for (int i = 0; i < n; i++)
                sum_j += temp(i,j);
        
            R(k,j) = R0(k,j) - sum_j;
        }
    }
    
    // normalization of each rows
    for (int k = 0; k < n; k++) {
        double sum = 0;
        for (int j = 0; j < n; j++)
            sum += R(k,j)*R(k,j);
        
        for (int j = 0; j < n; j++)
            R(k,j) = R(k,j)/sqrt(sum);

    }
    
    return 0;
}
Example #16
0
const Matrix &
Element::getMassSensitivity(int gradIndex)
{
  if (index == -1) {
    this->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
  }

  Matrix *theMatrix = theMatrices[index];
  theMatrix->Zero();

  return *theMatrix;
}
Example #17
0
void
PDeltaCrdTransf2d::compTransfMatrixLocalGlobal(Matrix &Tlg) 
{
    // setup transformation matrix from global to local coordinates
    Tlg.Zero();
    
    Tlg(0,0) = Tlg(3,3) =  cosTheta;
    Tlg(0,1) = Tlg(3,4) =  sinTheta;
    Tlg(1,0) = Tlg(4,3) = -sinTheta;
    Tlg(1,1) = Tlg(4,4) =  cosTheta;
    Tlg(2,2) = Tlg(5,5) =  1.0;
}
Example #18
0
const Matrix &
Element::getMass(void)
{
  if (index  == -1) {
    this->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
  }

  // zero the matrix & return it
  Matrix *theMatrix = theMatrices[index]; 
  theMatrix->Zero();
  return *theMatrix;
}
Example #19
0
const Matrix &
Element::getGeometricTangentStiff()
{
    if (index == -1) {
	this->setRayleighDampingFactors(alphaM, betaK, betaK0, betaKc);
    }
    
    Matrix *theMatrix = theMatrices[index];
    theMatrix->Zero();
    
    return *theMatrix;
}
void 
PFEMElement2DBubble::getdFbub(Matrix& dfb) const {

    dfb.resize(2,6);
    dfb.Zero();

    for(int b=0; b<6; b++) {
        dfb(0,b) = bx*dJ(b);
        dfb(1,b) = by*dJ(b);
    }

    dfb *= rho*thickness*27.0/120.0;
}
void 
PFEMElement2DBubble::getdinvMbub(const Vector& vb, Matrix& dmb) const {

    dmb.resize(2,6);
    dmb.Zero(); 

    for(int a=0; a<2; a++) {
        for(int b=0; b<6; b++) {
            dmb(a,b) = vb(a)*dJ(b);
        }
    }
    dmb *= -5040.0*ops_Dt/(1863.0*thickness*rho*J*J);
}
// geometric sensitivity
void
PFEMElement2DBubble::getdM(const Vector& vdot, Matrix& dm) const
{
    dm.resize(6,6);
    dm.Zero();

    for(int a=0; a<6; a++) {
        for(int b=0; b<6; b++) {
            dm(a,b) = vdot(a)*dJ(b);
        }
    }
    dm *= (1.0/6.0+3.0/40.0)*rho*thickness;
}
Example #23
0
//! fill the generators of SU(n)
template <int n> vector<Matrix<complex<double>,n,n>> get_generators()
{
  vector<Matrix<complex<double>,n,n>> out;
  
  //real generators
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      {
	Matrix<complex<double>,n,n> gen;
	gen.Zero();
	gen(i,j)=gen(j,i)=1;
	out.push_back(gen);
      }
  
  //diagonal generators
  for(int i=1;i<n;i++)
    {
      Matrix<complex<double>,n,n> gen;
      gen.Zero();
      double norm=1/sqrt(i*(i+1)/2);
      for(int j=0;j<i;j++) gen(j,j)=norm;
      gen(i,i)=-i*norm;
      out.push_back(gen);
    }
  
  //imag generators
  for(int i=0;i<n;i++)
    for(int j=i+1;j<n;j++)
      {
	Matrix<complex<double>,n,n> gen;
	gen.Zero();
	gen(i,j)=+I;
	gen(j,i)=-I;
	out.push_back(gen);
      }
  
  return out;
}
Example #24
0
//==========================================================================
// Class:			Matrix
// Function:		InitializeSVDMatrices
//
// Description:		Part of SVD algorithm.  Initializes the matrices (sets sizes)
//					and copies this matrix to U.
//
// Input Arguments:
//		U	= Matrix&
//		V	= Matrix&
//		W	= Matrix&
//
// Output Arguments:
//		None
//
// Return Value:
//		None
//
//==========================================================================
void Matrix::InitializeSVDMatrices(Matrix &U, Matrix &V, Matrix &W) const
{
	U.Resize(rows, columns);
	W.Resize(columns, columns);
	W.Zero();
	V.Resize(columns, columns);

	unsigned int i, j;
	for (i = 0; i < U.rows; i++)
	{
		for (j = 0; j < V.rows; j++)
			U.elements[i][j] = elements[i][j];
	}
}
void 
PFEMElement2DBubble::getdGbt(const Vector& vb, Matrix& dgbt) const {

    dgbt.resize(3,6);
    dgbt.Zero();

    for(int a=0; a<3; a++) {
        for(int b=0; b<6; b++) {
            for(int i=0; i<vb.Size(); i++) {
                dgbt(a,b) += C(2*a+i,b)*vb(i);
            }
        }
    }
    dgbt *= -27.0*thickness/120.0;
}
Example #26
0
// ---------------- add by guquan ------------------------------
// ---------------- c=a*b, c(i,j,k,l)=a(i,j)*b(k,l)-------------
void tensorProduct(Matrix & c, const Vector & a, const Vector & b)
{
  if (b.Size() !=6 || a.Size() !=6 || c.noCols() !=6|| c.noRows() !=6) {
    opserr << "FATAL:operator && (Vector &, Matrix &): vector or Matrix size not equal 6" << endln;
    exit(-1);
  }
	
  c.Zero();
  for(int j=0;j<6;j++){
	  for (int i=0; i<6; i++){
		c(i,j) = a[i]*b[j];
	  }
  }
  return;
}
void 
PFEMElement2DBubble::getdGb(const Vector& p, Matrix& dgb) const {

    dgb.resize(2,6);
    dgb.Zero();

    for(int a=0; a<2; a++) {
        for(int b=0; b<6; b++) {
            for(int i=0; i<3; i++) {
                dgb(a,b) += C(2*i+a,b)*p(i);
            }
        }
    }

    dgb *= -27.0*thickness/120.0;
}
void 
PFEMElement2DBubble::getdK(const Vector& v, Matrix& dk) const
{
    dk.resize(6,6);
    getK(dk);
    dk *= -1.0/J;

    Vector kv = dk*v;

    dk.Zero();
    for(int a=0; a<6; a++) {
        for(int b=0; b<6; b++) {
            dk(a,b) = kv(a)*dJ(b);
        }
    }
}
void bimanual_ds::initialize_Gains(Matrix & M, double Gain)
{
	M.Zero();
	M(0,3)=1;
	M(1,4)=1;
	M(2,5)=1;
	M(0,3)=1;
	double Scaler_V=1;
	double Scaler_Z=1;
	M(3,0)=-1*Gain*Gain;
	M(4,1)=-1*Scaler_V*Scaler_V*Gain*Gain;
	M(5,2)=-1*Scaler_Z*Scaler_Z*Gain*Gain;

	M(3,3)=-2*Gain;
	M(4,4)=-2*Scaler_V*Gain;
	M(5,5)=-2*Scaler_Z*Gain;
}
Example #30
0
// ---------------- add by guquan ------------------------------
// ---------------- c=a:b, c(i,j,k,l)=a(i,j,m,n)*b(m,n,k,l)-------------
void doubledotMatrixProduct (Matrix & c, const Matrix & a, const Matrix & b)
{
  if (c.noCols() !=6 ||c.noRows() !=6 || a.noCols() !=6 ||a.noRows() !=6 || b.noCols() !=6|| b.noRows() !=6) {
    opserr << "FATAL: doubledotproduct(Matrix &, Matrix &): Matrix size not equal 6" << endln;
    exit(-1);
  }
	
  c.Zero();
  for(int i=0;i<6;i++){
	for(int j=0;j<6;j++){
	  for (int l=0; l<3; l++){
		c(i,j) += a(i,l)*b(l,j) + 2*a(i,l+3)*b(l+3,j);
	  }
	}
  }
  return;
}