Пример #1
0
int
BeamContact2Dp::revertToStart()
{
	if (mIniContact == 0) {
		inContact          = true;
		was_inContact      = true;
		in_bounds          = true;
	} else {
		inContact          = false;
		was_inContact      = false;
		in_bounds          = true;
	}

	// reset applicable member variables 
	mDcrd_a = mIcrd_a;
	mDcrd_b = mIcrd_b;
	mDcrd_s = mIcrd_s;
	mDisp_a_n.Zero();
	mDisp_b_n.Zero();

	mLength = (mDcrd_b - mDcrd_a).Norm();

	ma_1 = (mDcrd_b - mDcrd_a)/mLength;
	mb_1 = ma_1;

	mXi = ((mDcrd_b - mDcrd_s)^(mDcrd_b - mDcrd_a))/mLength;
	mXi = Project(mXi);

	in_bounds = ((mXi > 0.000) && (mXi < 1.000));
	inContact = (was_inContact && in_bounds);

	UpdateBase(mXi);
	ComputeB();

	return theMaterial->revertToStart();
}
Пример #2
0
int main(int argc, char **argv)
{
  PetscErrorCode      info;               /* used to check for functions returning nonzeros */
  Vec                 x;                  /* variables vector */
  Vec                 xl,xu;              /* lower and upper bound on variables */
  PetscBool           flg;              /* A return variable when checking for user options */
  SNESConvergedReason reason;
  AppCtx              user;               /* user-defined work context */
  SNES                snes;
  Vec                 r;
  PetscReal           zero=0.0,thnd=1000;


  /* Initialize PETSC */
  PetscInitialize(&argc, &argv,(char*)0,help);

#if defined(PETSC_USE_COMPLEX)
  SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"This example does not work for scalar type complex\n");
#endif

  /* Set the default values for the problem parameters */
  user.nx = 50; user.ny = 50; user.ecc = 0.1; user.b = 10.0;

  /* Check for any command line arguments that override defaults */
  info = PetscOptionsGetReal(NULL,"-ecc",&user.ecc,&flg);CHKERRQ(info);
  info = PetscOptionsGetReal(NULL,"-b",&user.b,&flg);CHKERRQ(info);

  /*
     A two dimensional distributed array will help define this problem,
     which derives from an elliptic PDE on two dimensional domain.  From
     the distributed array, Create the vectors.
  */
  info = DMDACreate2d(PETSC_COMM_WORLD, DMDA_BOUNDARY_NONE, DMDA_BOUNDARY_NONE,DMDA_STENCIL_STAR,-50,-50,PETSC_DECIDE,PETSC_DECIDE,1,1,NULL,NULL,&user.da);CHKERRQ(info);
  info = DMDAGetInfo(user.da,PETSC_IGNORE,&user.nx,&user.ny,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE,PETSC_IGNORE);CHKERRQ(info);

  PetscPrintf(PETSC_COMM_WORLD,"\n---- Journal Bearing Problem -----\n");
  PetscPrintf(PETSC_COMM_WORLD,"mx: %d,  my: %d,  ecc: %4.3f, b:%3.1f \n",
              user.nx,user.ny,user.ecc,user.b);
  /*
     Extract global and local vectors from DA; the vector user.B is
     used solely as work space for the evaluation of the function,
     gradient, and Hessian.  Duplicate for remaining vectors that are
     the same types.
  */
  info = DMCreateGlobalVector(user.da,&x);CHKERRQ(info); /* Solution */
  info = VecDuplicate(x,&user.B);CHKERRQ(info); /* Linear objective */
  info = VecDuplicate(x,&r);CHKERRQ(info);

  /*  Create matrix user.A to store quadratic, Create a local ordering scheme. */
  info = DMCreateMatrix(user.da,MATAIJ,&user.A);CHKERRQ(info);

  /* User defined function -- compute linear term of quadratic */
  info = ComputeB(&user);CHKERRQ(info);

  /* Create nonlinear solver context */
  info = SNESCreate(PETSC_COMM_WORLD,&snes);CHKERRQ(info);

  /*  Set function evaluation and Jacobian evaluation  routines */
  info = SNESSetFunction(snes,r,FormGradient,&user);CHKERRQ(info);
  info = SNESSetJacobian(snes,user.A,user.A,FormHessian,&user);CHKERRQ(info);

  /* Set the initial solution guess */
  info = VecSet(x, zero);CHKERRQ(info);

  info = SNESSetFromOptions(snes);CHKERRQ(info);

  /* Set variable bounds */
  info = VecDuplicate(x,&xl);CHKERRQ(info);
  info = VecDuplicate(x,&xu);CHKERRQ(info);
  info = VecSet(xl,zero);CHKERRQ(info);
  info = VecSet(xu,thnd);CHKERRQ(info);
  info = SNESVISetVariableBounds(snes,xl,xu);CHKERRQ(info);

  /* Solve the application */
  info = SNESSolve(snes,NULL,x);CHKERRQ(info);

  info = SNESGetConvergedReason(snes,&reason);CHKERRQ(info);
  if (reason <= 0) SETERRQ(PETSC_COMM_WORLD,PETSC_ERR_SUP,"The SNESVI solver did not converge, adjust some parameters, or check the function evaluation routines\n");

  /* Free memory */
  info = VecDestroy(&x);CHKERRQ(info);
  info = VecDestroy(&xl);CHKERRQ(info);
  info = VecDestroy(&xu);CHKERRQ(info);
  info = VecDestroy(&r);CHKERRQ(info);
  info = MatDestroy(&user.A);CHKERRQ(info);
  info = VecDestroy(&user.B);CHKERRQ(info);
  info = DMDestroy(&user.da);CHKERRQ(info);
  info = SNESDestroy(&snes);CHKERRQ(info);

  info = PetscFinalize();

  return 0;
}
Пример #3
0
void
BeamContact2Dp::setDomain(Domain *theDomain)
{
	Vector x_c(BC2D_NUM_DIM);
	
	mEye1.Zero();
	mEye1(0,0) = 1.0;
	mEye1(1,1) = 1.0;

	mEyeS.Zero();
	mEyeS(0,1) = -1.0;
	mEyeS(1,0) = 1.0;

	theNodes[0] = theDomain->getNode(mExternalNodes(0));
	theNodes[1] = theDomain->getNode(mExternalNodes(1));
	theNodes[2] = theDomain->getNode(mExternalNodes(2));

	for (int i = 0; i < 3; i++) {
        if (theNodes[i] == 0)
            return;  // don't go any further - otherwise segmentation fault
    }

	// initialize coordinate vectors
	mIcrd_a = theNodes[0]->getCrds();
	mIcrd_b = theNodes[1]->getCrds();
	mIcrd_s = theNodes[2]->getCrds();
	mDcrd_a = mIcrd_a;
	mDcrd_b = mIcrd_b;
	mDcrd_s = mIcrd_s;
	mDisp_a_n.Zero();
	mDisp_b_n.Zero();

    // length of beam element
	mLength = (mDcrd_b - mDcrd_a).Norm();

	// initialize tangent vectors at beam nodes
	ma_1 = (mDcrd_b - mDcrd_a)/mLength;
	mb_1 = ma_1;

	// perform projection of slave node to beam centerline
	mXi = ((mDcrd_b - mDcrd_s)^(mDcrd_b - mDcrd_a))/mLength;  // initial assumption
	mXi = Project(mXi);                                       // actual location

	// update contact state based on projection
	in_bounds = ((mXi > 0.000) && (mXi < 1.000));
	inContact = (was_inContact && in_bounds);

	// centerline projection coordinate
	x_c = mDcrd_a*mShape(0) + ma_1*mLength*mShape(1) + mDcrd_b*mShape(2) + mb_1*mLength*mShape(3);

	// update surface tangent vector, g_xi
	UpdateBase(mXi);

	// adjust cohesion force
	theMaterial->ScaleCohesion(mLength);
	theMaterial->ScaleTensileStrength(mLength);

	// compute vectors Bn and Bs
	ComputeB();

	// call the base class method
	this->DomainComponent::setDomain(theDomain);
}