コード例 #1
0
ファイル: rottec.C プロジェクト: HerculesCE/ParaView
main(int argc, char *argv[])
{
  register int i,j;
  double x[3],mv[3],cp,sp,c;
  char file[BUFSIZ],buf[BUFSIZ];
  int   n,n1,n2;
  FILE *fp,*fp_new;

  if(argc != 5){
    fprintf(stdout,"Usage:  rottec +xrot +yrot +zrot file \n");
    exit(-1);
  }

  sprintf(file,"%s",argv[argc-1]);

  mv[0] = atof(argv[argc-4]);
  mv[1] = atof(argv[argc-3]);
  mv[2] = atof(argv[argc-2]);

  if(!(fp = fopen(file,"r"))){
    fprintf(stdout,"File %s does not exist\n",file);
    exit(-1);
  }

  fp_new = stdout;

  fp_new = stdout;

  fgets(buf,BUFSIZ,fp);
  fputs(buf,fp_new);

  while(fgets(buf,BUFSIZ,fp)){
    fputs(buf,fp_new);
    sscanf(buf,"ZONE I=%d, J=%d",&n1,&n2);
    for(i =0 ; i < n1*n2; ++i){
      fscanf(fp,"%lf%lf%lf ",x,x+1,x+2);

      cp = cos(mv[0]*M_PI/180.0);
      sp = sin(mv[0]*M_PI/180.0);
      drot(1,x+1,1,x+2,1,cp,sp);
      cp = cos(mv[1]*M_PI/180.0);
      sp = sin(mv[1]*M_PI/180.0);
      drot(1,x+2,1,x,1,cp,sp);
      cp = cos(mv[2]*M_PI/180.0);
      sp = sin(mv[2]*M_PI/180.0);
      drot(1,x,1,x+1,1,cp,sp);
      fprintf(fp_new,"%lf  %lf  %lf ",x[0],x[1],x[2]);
      fgets(buf,BUFSIZ,fp);
      fputs(buf,fp_new);
    }
  }

  fclose(fp);
  fclose(fp_new);

  return 0;
}
コード例 #2
0
ファイル: linalg_dense.c プロジェクト: jackd/FVMPor
void mtx_givens( Tmtx_ptr A, int k, double *rhs )
{
	int i, pos, lwork, one=1, lda;
	int info;
	double a, b, c, s;  
	double *work, *tau;
	char L = 'L', T = 'T'; 
	
	lda = A->nrows;
	lwork = 64*(k+1);
	work = (double*)calloc( lwork, sizeof(double) );
	tau  = (double*)calloc( k+10, sizeof(double) );
	

	//mtx_QR( A );
	//dormqr_( &L, &T, &A->nrows, &one, &A->ncols, A->dat, &lda, A->tau, rhs, &lda, work, &lwork, &info );
	//return;

	
	/* 
	 *  eliminate upper block if it exists, use Householder reflections 
	 */
	if( k )
	{
		int kplus1 = k+1;
		
		pos = A->ncols-k;
		
		// find QR decomp of block, storing in the block 
		dgeqrf_( &kplus1, &k, A->dat, &lda, tau, work, &lwork, &info );
		// adjust the other columns in the first k+1 rows
		dormqr_( &L, &T, &kplus1, &pos, &k, A->dat, &lda, tau, A->dat+lda*k, &lda, work, &lwork, &info );
		// adjust the first k+1 elements of b
		dormqr_( &L, &T, &kplus1, &one, &k, A->dat, &lda, tau, rhs, &lda, work, &lwork, &info );
	}
	
	/*  eliminate sub-diagonal elements in remaining columns using Given's rotations */
	for( i=k, pos=k*lda; i<A->ncols; i++, pos+=lda )
	{
		a = A->dat[pos+i];
		b = A->dat[pos+i+1];
		drotg( &a, &b, &c, &s );
		drot( A->ncols-i, &A->dat[pos+i], lda, &A->dat[pos+i+1], lda, c, s );
		drot( 1, rhs+i, lda, rhs+i+1, lda, c, s );
	}
	
	free( tau );
	free( work );
}
コード例 #3
0
ファイル: Utility_check.c プロジェクト: adrielb/DCell
END_TEST

START_TEST( using_MKL_DROT )
{
  int i;
  PetscErrorCode ierr;
  
  double *x, *y, c = 0.9, s = 0.1;
  int incx = 1, incy = 1, n = 5;
  
  PetscMalloc( n*sizeof(double), &x);
  PetscMalloc( n*sizeof(double), &y);
  
  for( i = 0; i < n; ++i)
  {
    x[i] = i;
    y[i] = one;
  }
  
  for( i = 0; i < n; ++i)
  {
    printf("{%f, %f},\n",  x[i],  y[i]);
  }
  
  drot(&n, x, &incx, y, &incy, &c, &s);
  
  for( i = 0; i < n; ++i)
  {
    printf("{%f, %f},\n",  x[i],  y[i]);
  }
  
  PetscFree( x );
  PetscFree( y );
}
コード例 #4
0
ファイル: Puppeteer.cpp プロジェクト: LudoSapiens/Dev
//------------------------------------------------------------------------------
//!
RCP<SkeletalAnimation>
Puppeteer::cycle( SkeletalAnimation* animation, float fraction )
{
   DBG_BLOCK( os_pup, "Puppeteer::cycle(" << animation << ", " << fraction << ")" );
   RCP<SkeletalAnimation> anim = animation->clone();
   anim->makeRelative();

   fraction      = CGM::clamp( fraction, 0.0f, 1.0f );
   uint offset   = uint((anim->numPoses()-1)*fraction);
   uint numPoses = anim->numPoses()-offset;

   // Compute delta transformations.
   SkeletalPose* sp = anim->pose(0);
   SkeletalPose* ep = anim->pose( anim->numPoses()-1 );
   Reff dref = sp->referential() * ep->referential().getInversed();

   SkeletalPose::BoneContainer& b0 = sp->bones();
   SkeletalPose::BoneContainer& b1 = ep->bones();

   Vector<Quatf> drot( b0.size() );

   for( uint i = 0; i < b0.size(); ++i )
   {
      drot[i] = b0[i] * b1[i].getInversed();
   }

   // Compute poses.
   for( uint p = 0; p < numPoses; ++p )
   {
      SkeletalPose* p0 = anim->pose( offset+p );
      SkeletalPose::BoneContainer& b0 = p0->bones();

      float t = float(p) / float(numPoses-1);

      //Reff ref = p0->referential().slerp( dref*p0->referential(), t );
      Reff ref = p0->referential().nlerp( dref*p0->referential(), t );
      p0->referential( ref );
      for( uint i = 0; i < b0.size(); ++i )
      {
         //b0[i] = b0[i].slerp( drot[i]*b0[i], t );
         b0[i] = b0[i].nlerp( drot[i]*b0[i], t );
      }
   }

   anim->cyclic( true );  // We are now cyclic.

   return anim;
}
コード例 #5
0
ファイル: abaqususermaterial.C プロジェクト: aishugang/oofem
void AbaqusUserMaterial :: giveFirstPKStressVector_3d(FloatArray &answer, GaussPoint *gp,
                                                      const FloatArray &vF, TimeStep *tStep)
{
    AbaqusUserMaterialStatus *ms = static_cast< AbaqusUserMaterialStatus * >( this->giveStatus(gp) );
    /* User-defined material name, left justified. Some internal material models are given names starting with
     * the “ABQ_” character string. To avoid conflict, you should not use “ABQ_” as the leading string for
     * CMNAME. */
    //char cmname[80];

    // Sizes of the tensors.
    int ndi = 3;
    int nshr = 3;

    int ntens = ndi + nshr;
    FloatArray stress(9); // PK1
    FloatArray strainIncrement;

    // compute Green-Lagrange strain
    FloatArray strain;
    FloatArray vS;
    FloatMatrix F, E;
    F.beMatrixForm(vF);
    E.beTProductOf(F, F);
    E.at(1, 1) -= 1.0;
    E.at(2, 2) -= 1.0;
    E.at(3, 3) -= 1.0;
    E.times(0.5);
    strain.beSymVectorFormOfStrain(E);

    strainIncrement.beDifferenceOf(strain, ms->giveStrainVector());
    FloatArray state = ms->giveStateVector();
    FloatMatrix jacobian(9, 9); // dPdF
    int numProperties = this->properties.giveSize();

    // Temperature and increment
    double temp = 0.0, dtemp = 0.0;

    // Times and increment
    double dtime = tStep->giveTimeIncrement();
    ///@todo Check this. I'm just guessing. Maybe intrinsic time instead?
    double time [ 2 ] = {
        tStep->giveTargetTime() - dtime, tStep->giveTargetTime()
    };
    double pnewdt = 1.0; ///@todo Right default value? umat routines may change this (although we ignore it)

    /* Specific elastic strain energy, plastic dissipation, and “creep” dissipation, respectively. These are passed
     * in as the values at the start of the increment and should be updated to the corresponding specific energy
     * values at the end of the increment. They have no effect on the solution, except that they are used for
     * energy output. */
    double sse, spd, scd;

    // Outputs only in a fully coupled thermal-stress analysis:
    double rpl = 0.0; // Volumetric heat generation per unit time at the end of the increment caused by mechanical working of the material.
    FloatArray ddsddt(ntens); // Variation of the stress increments with respect to the temperature.
    FloatArray drplde(ntens); // Variation of RPL with respect to the strain increments.
    double drpldt = 0.0; // Variation of RPL with respect to the temperature.

    /* An array containing the coordinates of this point. These are the current coordinates if geometric
     * nonlinearity is accounted for during the step (see “Procedures: overview,” Section 6.1.1); otherwise,
     * the array contains the original coordinates of the point */
    FloatArray coords;
    gp->giveElement()->computeGlobalCoordinates( coords, gp->giveNaturalCoordinates() ); ///@todo Large deformations?

    /* Rotation increment matrix. This matrix represents the increment of rigid body rotation of the basis
     * system in which the components of stress (STRESS) and strain (STRAN) are stored. It is provided so
     * that vector- or tensor-valued state variables can be rotated appropriately in this subroutine: stress and
     * strain components are already rotated by this amount before UMAT is called. This matrix is passed in
     * as a unit matrix for small-displacement analysis and for large-displacement analysis if the basis system
     * for the material point rotates with the material (as in a shell element or when a local orientation is used).*/
    FloatMatrix drot(3, 3);
    drot.beUnitMatrix();

    /* Characteristic element length, which is a typical length of a line across an element for a first-order
     * element; it is half of the same typical length for a second-order element. For beams and trusses it is a
     * characteristic length along the element axis. For membranes and shells it is a characteristic length in
     * the reference surface. For axisymmetric elements it is a characteristic length in the
     * plane only.
     * For cohesive elements it is equal to the constitutive thickness.*/
    double celent = 0.0; /// @todo Include the characteristic element length

    /* Array containing the deformation gradient at the beginning of the increment. See the discussion
     * regarding the availability of the deformation gradient for various element types. */
    FloatMatrix dfgrd0(3, 3);
    /* Array containing the deformation gradient at the end of the increment. The components of this array
     * are set to zero if nonlinear geometric effects are not included in the step definition associated with
     * this increment. See the discussion regarding the availability of the deformation gradient for various
     * element types. */
    FloatMatrix dfgrd1(3, 3);

    dfgrd0.beMatrixForm( ms->giveFVector() );
    dfgrd1.beMatrixForm(vF);

    int noel = gp->giveElement()->giveNumber(); // Element number.
    int npt = 0; // Integration point number.

    // We intentionally ignore the layer number since that is handled by the layered cross-section in OOFEM.
    int layer = 0; // Layer number (for composite shells and layered solids)..
    int kspt = 0; // Section point number within the current layer.
    int kstep = tStep->giveMetaStepNumber(); // Step number.
    int kinc = 0; // Increment number.

    ///@todo No idea about these parameters
    double predef;
    double dpred;

    // Change to Abaqus's component order
    stress.changeComponentOrder();
    strain.changeComponentOrder();
    strainIncrement.changeComponentOrder();

    OOFEM_LOG_DEBUG("AbaqusUserMaterial :: giveRealStressVector - Calling subroutine");
    this->umat(stress.givePointer(), // STRESS
               state.givePointer(), // STATEV
               jacobian.givePointer(), // DDSDDE
               & sse, // SSE
               & spd, // SPD
               & scd, // SCD
               & rpl, // RPL
               ddsddt.givePointer(), // DDSDDT
               drplde.givePointer(), // DRPLDE
               & drpldt, // DRPLDT
               strain.givePointer(), // STRAN
               strainIncrement.givePointer(), // DSTRAN
               time, // TIME
               & dtime, // DTIME
               & temp, // TEMP
               & dtemp, // DTEMP
               & predef, // PREDEF
               & dpred, // DPRED
               this->cmname, // CMNAME
               & ndi, // NDI
               & nshr, // NSHR
               & ntens, // NTENS
               & numState, // NSTATV
               properties.givePointer(), // PROPS
               & numProperties, // NPROPS
               coords.givePointer(), // COORDS
               drot.givePointer(), // DROT
               & pnewdt, // PNEWDT
               & celent, // CELENT
               dfgrd0.givePointer(), // DFGRD0
               dfgrd1.givePointer(), // DFGRD1
               & noel, // NOEL
               & npt, // NPT
               & layer, // LAYER
               & kspt, // KSPT
               & kstep, // KSTEP
               & kinc); // KINC


    // Change to OOFEM's component order
    stress.changeComponentOrder();
    strain.changeComponentOrder();
    strainIncrement.changeComponentOrder();
    jacobian.changeComponentOrder();


    if ( mStressInterpretation == 0 ) {
        FloatMatrix P, cauchyStress;
        P.beMatrixForm(stress);

        FloatArray vP;
        vP.beVectorForm(P);

        cauchyStress.beProductTOf(P, F);
        cauchyStress.times( 1.0 / F.giveDeterminant() );

        FloatArray vCauchyStress;
        vCauchyStress.beSymVectorForm(cauchyStress);

        ms->letTempStrainVectorBe(strain);
        ms->letTempStressVectorBe(vCauchyStress);
        ms->letTempStateVectorBe(state);
        ms->letTempTangentBe(jacobian);
        ms->letTempPVectorBe(vP);
        ms->letTempFVectorBe(vF);

        answer = vP;
    } else   {
        FloatArray vP;
        FloatMatrix P, sigma, F_inv;
        F_inv.beInverseOf(F);

        sigma.beMatrixForm(stress);
        P.beProductOf(F, sigma);
        vP.beVectorForm(P);
        answer = vP;

        // Convert from sigma to S
        FloatMatrix S;
        S.beProductOf(F_inv, P);
        vS.beSymVectorForm(S);

        // @todo Should convert from dsigmadE to dSdE here
        // L2=detF*matmul( matmul ( inv(op_a_V9(F,F), cm-op_a_V9(ident,Tau)-op_b_V9(Tau,ident) ), inv(op_a_V9(Ft,Ft)))

        ms->letTempStrainVectorBe(strain);
        ms->letTempStressVectorBe(vS);
        ms->letTempStateVectorBe(state);
        ms->letTempTangentBe(jacobian);
        ms->letTempPVectorBe(vP);
        ms->letTempFVectorBe(vF);
    }

    OOFEM_LOG_DEBUG("AbaqusUserMaterial :: giveRealStressVector_3d - Calling subroutine was successful");
}
コード例 #6
0
void AbaqusUserMaterial :: giveRealStressVector(FloatArray &answer, MatResponseForm form, GaussPoint *gp,
                                                const FloatArray &reducedStrain, TimeStep *tStep)
{
    AbaqusUserMaterialStatus *ms = static_cast< AbaqusUserMaterialStatus * >( this->giveStatus(gp) );
    /* User-defined material name, left justified. Some internal material models are given names starting with
     * the “ABQ_” character string. To avoid conflict, you should not use “ABQ_” as the leading string for
     * CMNAME. */
    //char cmname[80];

    MaterialMode mMode = gp->giveMaterialMode();
    // Sizes of the tensors.
    int ndi;
    int nshr;
    ///@todo Check how to deal with large deformations.
    ///@todo Check order of entries in the Voigt notation (which order does Abaqus use? convert to that).
    if ( mMode == _3dMat ) {
        ndi = 3;
        nshr = 3;
    } else if ( mMode == _PlaneStress ) {
        ndi = 2;
        nshr = 1;
    } else if ( mMode == _PlaneStrain ) {
        ndi = 3;
        nshr = 1;
    } /*else if ( mMode == _3dMat_F ) {
       * ndi = 3;
       * nshr = 6;
       * } */
    else if ( mMode == _1dMat ) {
        ndi = 1;
        nshr = 0;
    } else {
        ndi = nshr = 0;
        OOFEM_ERROR2( "AbaqusUserMaterial :: giveRealStressVector : unsupported material mode (%s)", __MaterialModeToString(mMode) );
    }

    int ntens = ndi + nshr;
    FloatArray stress(ntens);
    FloatArray strain = ms->giveStrainVector();
    FloatArray strainIncrement;
    strainIncrement.beDifferenceOf(reducedStrain, strain);
    FloatArray state = ms->giveStateVector();
    FloatMatrix jacobian(ntens, ntens);
    int numProperties = this->properties.giveSize();

    // Temperature and increment
    double temp = 0.0, dtemp = 0.0;

    // Times and increment
    double dtime = tStep->giveTimeIncrement();
    ///@todo Check this. I'm just guessing. Maybe intrinsic time instead?
    double time [ 2 ] = {
        tStep->giveTargetTime() - dtime, tStep->giveTargetTime()
    };
    double pnewdt = 1.0; ///@todo Right default value? umat routines may change this (although we ignore it)

    /* Specific elastic strain energy, plastic dissipation, and “creep” dissipation, respectively. These are passed
     * in as the values at the start of the increment and should be updated to the corresponding specific energy
     * values at the end of the increment. They have no effect on the solution, except that they are used for
     * energy output. */
    double sse, spd, scd;

    // Outputs only in a fully coupled thermal-stress analysis:
    double rpl = 0.0; // Volumetric heat generation per unit time at the end of the increment caused by mechanical working of the material.
    FloatArray ddsddt(ntens); // Variation of the stress increments with respect to the temperature.
    FloatArray drplde(ntens); // Variation of RPL with respect to the strain increments.
    double drpldt = 0.0; // Variation of RPL with respect to the temperature.

    /* An array containing the coordinates of this point. These are the current coordinates if geometric
     * nonlinearity is accounted for during the step (see “Procedures: overview,” Section 6.1.1); otherwise,
     * the array contains the original coordinates of the point */
    FloatArray coords;
    gp->giveElement()->computeGlobalCoordinates( coords, * gp->giveCoordinates() ); ///@todo Large deformations?

    /* Rotation increment matrix. This matrix represents the increment of rigid body rotation of the basis
     * system in which the components of stress (STRESS) and strain (STRAN) are stored. It is provided so
     * that vector- or tensor-valued state variables can be rotated appropriately in this subroutine: stress and
     * strain components are already rotated by this amount before UMAT is called. This matrix is passed in
     * as a unit matrix for small-displacement analysis and for large-displacement analysis if the basis system
     * for the material point rotates with the material (as in a shell element or when a local orientation is used).*/
    FloatMatrix drot(3, 3);
    drot.beUnitMatrix();

    /* Characteristic element length, which is a typical length of a line across an element for a first-order
     * element; it is half of the same typical length for a second-order element. For beams and trusses it is a
     * characteristic length along the element axis. For membranes and shells it is a characteristic length in
     * the reference surface. For axisymmetric elements it is a characteristic length in the
     * plane only.
     * For cohesive elements it is equal to the constitutive thickness.*/
    double celent = 0.0; /// @todo Include the characteristic element length

    /* Array containing the deformation gradient at the beginning of the increment. See the discussion
     * regarding the availability of the deformation gradient for various element types. */
    FloatMatrix dfgrd0(3, 3);
    /* Array containing the deformation gradient at the end of the increment. The components of this array
     * are set to zero if nonlinear geometric effects are not included in the step definition associated with
     * this increment. See the discussion regarding the availability of the deformation gradient for various
     * element types. */
    FloatMatrix dfgrd1(3, 3);

    int noel = gp->giveElement()->giveNumber(); // Element number.
    int npt = 0; // Integration point number.

    int layer = 0; // Layer number (for composite shells and layered solids)..
    int kspt = 0.0; // Section point number within the current layer.
    int kstep = 0; // Step number.
    int kinc = 0; // Increment number.

    ///@todo No idea about these parameters
    double predef;
    double dpred;

    OOFEM_LOG_DEBUG("AbaqusUserMaterial :: giveRealStressVector - Calling subroutine");
    this->umat(stress.givePointer(), // STRESS
               state.givePointer(), // STATEV
               jacobian.givePointer(), // DDSDDE
               & sse, // SSE
               & spd, // SPD
               & scd, // SCD
               & rpl, // RPL
               ddsddt.givePointer(), // DDSDDT
               drplde.givePointer(), // DRPLDE
               & drpldt, // DRPLDT
               strain.givePointer(), // STRAN
               strainIncrement.givePointer(), // DSTRAN
               time, // TIME
               & dtime, // DTIME
               & temp, // TEMP
               & dtemp, // DTEMP
               & predef, // PREDEF
               & dpred, // DPRED
               this->cmname, // CMNAME
               & ndi, // NDI
               & nshr, // NSHR
               & ntens, // NTENS
               & numState, // NSTATV
               properties.givePointer(), // PROPS
               & numProperties, // NPROPS
               coords.givePointer(), // COORDS
               drot.givePointer(), // DROT
               & pnewdt, // PNEWDT
               & celent, // CELENT
               dfgrd0.givePointer(), // DFGRD0
               dfgrd1.givePointer(), // DFGRD1
               & noel, // NOEL
               & npt, // NPT
               & layer, // LAYER
               & kspt, // KSPT
               & kstep, // KSTEP
               & kinc); // KINC

    ms->letTempStrainVectorBe(reducedStrain);
    ms->letTempStressVectorBe(stress);
    ms->letTempStateVectorBe(state);
    ms->letTempTangentBe(jacobian);
    answer = stress;

    OOFEM_LOG_DEBUG("AbaqusUserMaterial :: giveRealStressVector - Calling subroutine was successful");
}