Exemplo n.º 1
0
int 
IncrementalIntegrator::doMv(const Vector &v, Vector &res) {

  int n = v.Size();
  if (isDiagonal == true) {
    for (int i=0; i<n; i++)
      res[i] = diagMass[i]*v[i];
    return 0;
  }

  res.Zero();

  // loop over the FE_Elements
  FE_Element *elePtr;
  FE_EleIter &theEles = theAnalysisModel->getFEs();    
  while((elePtr = theEles()) != 0) {
    const Vector &b = elePtr->getM_Force(v, 1.0);
    res.Assemble(b, elePtr->getID(), 1.0);
  }

  // loop over the DOF_Groups
  DOF_Group *dofPtr;
  DOF_GrpIter &theDofs = theAnalysisModel->getDOFs();
  while ((dofPtr = theDofs()) != 0) {
    const Vector &a = dofPtr->getM_Force(v, 1.0);      
    res.Assemble(a, dofPtr->getID(), 1.0);
  }
  return 0;
}
Exemplo n.º 2
0
void TwoLayerSW::AssembleGFirstOrder( Vec* G ) {
    Vector*		rhs;
    RHSOp**		ops		= new RHSOp*[1];
    GLayerVector2*	gCurrRHS	= NULL;

    CreateVector( velTop, G );

    gCurrRHS = new GLayerVector2( "g-curr", velTop->mesh, -dt, etaInt, velTop, velBot,
                                  params->H1, params->H2, params->nu, params->g, params->tau, params->k );
    ops[0] = gCurrRHS;
    rhs = new Vector( "G", velTop, *G, ops, 1 );
    rhs->Assemble();

    delete rhs;
}
Exemplo n.º 3
0
void TwoLayerSW::AssembleGSecondOrder( Field* velTopPrev, Field* velBotPrev, Field* etaIntPrev, Vec* G ) {
    Vector*		rhs;
    RHSOp**		ops		= new RHSOp*[2];
    GLayerVector2*	gCurrRHS;
    GLayerVector2*	gPrevRHS;

    CreateVector( velTop, G );

    gCurrRHS = new GLayerVector2( "g-curr", velTop->mesh, -2.0*dt, etaInt, velTop, velBot,
                                  params->H1, params->H2, params->nu, params->g, params->tau, params->k );
    gPrevRHS = new GLayerVector2( "g-prev", velTop->mesh, dt, etaIntPrev, velTopPrev, velBotPrev,
                                  params->H1, params->H2, params->nu, params->g, params->tau, params->k );
    ops[0] = gCurrRHS;
    ops[1] = gPrevRHS;
    rhs = new Vector( "G", velTop, *G, ops, 2 );
    rhs->Assemble();

    delete rhs;
}
Exemplo n.º 4
0
void TwoLayerSW::SolveSecondOrder( Field* velTopPrev, Field* velBotPrev, Field* etaIntPrev ) {
    Advector*		velTopAdv	= new Advector( velTop, velTop, velTopPrev, velTopPrev );
    Advector*		velBotAdv	= new Advector( velBot, velBot, velBotPrev, velBotPrev );
    /* interfacial pressure rhs ops */
    FieldRHS*		eta1RHS;
    FieldRHS*		eta2RHS;
    DivHeightVelRHS*	dEtaVel1CurrRHS;
    DivHeightVelRHS*	dEtaVel2CurrRHS;
    DivHeightVelRHS*	dEtaVel1PrevRHS;
    DivHeightVelRHS*	dEtaVel2PrevRHS;
    PhiRHS*			u1RHS;
    PhiRHS*			u2RHS;
    /* momentum eqn rhs ops */
    FieldRHS*		velRHS;
    GradFieldRHS*		gPresRHS;
    WindStress2RHS*		windRHS;
    GradFieldRHS*		gEtaRHS;
    RHSOp**			ops;
    Vector*			sol;
    Vector*			rhs;
    Vec			f;
    Vec			x;
    KSP			ksp;
    MatNullSpace		null;
    Field*			etaIntTemp	= new Field( "etaIntTemp", etaInt->mesh, 1, etaInt->bcs );
    Field*			velTopNew	= new Field( "vel-top-new", velTop->mesh, 2, velTop->bcs );
    Field*			velBotNew	= new Field( "vel-bot-new", velBot->mesh, 2, velBot->bcs );

    etaIntTemp->Copy( etaInt );
    for( int i = 0; i < velTop->mesh->nVertsTotal; i++ ) {
        velTopNew->vals[i][0] = 2.0*velTop->vals[i][0] - velTopPrev->vals[i][0];
        velTopNew->vals[i][1] = 2.0*velTop->vals[i][1] - velTopPrev->vals[i][1];
        velBotNew->vals[i][0] = 2.0*velBot->vals[i][0] - velBotPrev->vals[i][0];
        velBotNew->vals[i][1] = 2.0*velBot->vals[i][1] - velBotPrev->vals[i][1];
    }

    //SolvePressureSecondOrder( velTopPrev, velBotPrev, etaIntPrev );

    CreateVector( etaInt, &f );
    CreateVector( etaInt, &x );

    velTopAdv->Advect( dt );
    velBotAdv->Advect( dt );

    sol = new Vector( "e-sol", etaInt, x, NULL, 0 );

    eta1RHS         = new FieldRHS( "eta-curr-rhs", etaInt->mesh, +2.0, etaInt );
    eta2RHS         = new FieldRHS( "eta-prev-rhs", etaInt->mesh, -0.5, etaIntPrev );
    dEtaVel1CurrRHS = new DivHeightVelRHS( "d-eta-vel-1-curr-rhs", etaInt->mesh, -1.0*dt, etaInt, velTop );
    dEtaVel1PrevRHS = new DivHeightVelRHS( "d-eta-vel-1-prev-rhs", etaInt->mesh, +0.5*dt, etaIntPrev, velTopPrev );
    dEtaVel2CurrRHS = new DivHeightVelRHS( "d-eta-vel-2-curr-rhs", etaInt->mesh, -1.0*dt, etaInt, velBot );
    dEtaVel2PrevRHS = new DivHeightVelRHS( "d-eta-vel-2-prev-rhs", etaInt->mesh, +0.5*dt, etaIntPrev, velBotPrev );
    u1RHS           = new PhiRHS( "u1-rhs", etaInt->mesh, 1.5, velTopNew, +1.0, dt, params->H1, params->tau, params->k,
                                  params->nu, params->p, params->f, params->beta, presSurf, etaInt, velTopAdv->fieldSL );
    u2RHS           = new PhiRHS( "u2-rhs", etaInt->mesh, 1.5, velBotNew, -1.0, dt, params->H2, 0.0, 0.0,
                                  params->nu, params->p, params->f, params->beta, presSurf, etaInt, velBotAdv->fieldSL );
    ops = new RHSOp*[8];
    ops[0] = eta1RHS;
    ops[1] = eta2RHS;
    ops[2] = dEtaVel1CurrRHS;
    ops[3] = dEtaVel1PrevRHS;
    ops[4] = dEtaVel2CurrRHS;
    ops[5] = dEtaVel2PrevRHS;
    ops[6] = u1RHS;
    ops[7] = u2RHS;
    rhs = new Vector( "e-rhs", etaInt, f, ops, 8 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, PI, PI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "eta-int_" );
    KSPSetFromOptions( ksp );
    if( enull ) {
        MatNullSpaceCreate( MPI_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, &null );
        KSPSetNullSpace( ksp, null );
    }
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    if( enull ) {
        MatNullSpaceDestroy( null );
    }
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    /* update the upper layer velocity field */
    CreateVector( velTop, &x );
    CreateVector( velTop, &f );

    velRHS   = new FieldRHS( "vel-1-rhs", velTop->mesh, 1.0, velTopAdv->fieldSL );
    gPresRHS = new GradFieldRHS( "g-pres-rhs", velTop->mesh, -dt*params->p, presSurf );
    windRHS  = new WindStress2RHS( "wind-rhs", velTop->mesh, dt*params->tau, etaIntTemp, params->k, params->H1 );
    ops = new RHSOp*[3];
    ops[0] = velRHS;
    ops[1] = gPresRHS;
    ops[2] = windRHS;
    rhs = new Vector( "u1-rhs", velTop, f, ops, 3 );
    sol = new Vector( "u1-sol", velTop, x, NULL, 0 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, VI, VI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "vel-top_" );
    KSPSetFromOptions( ksp );
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    /* update the lower layer velocity field */
    CreateVector( velBot, &x );
    CreateVector( velBot, &f );

    velRHS   = new FieldRHS( "vel-2-rhs", velBot->mesh, 1.0, velBotAdv->fieldSL );
    gPresRHS = new GradFieldRHS( "g-pres-rhs", velBot->mesh, -dt*params->p, presSurf );
    gEtaRHS  = new GradFieldRHS( "g-eta-rhs", velBot->mesh, -dt*params->g, etaInt );
    ops = new RHSOp*[3];
    ops[0] = velRHS;
    ops[1] = gPresRHS;
    ops[2] = gEtaRHS;
    rhs = new Vector( "u2-rhs", velBot, f, ops, 3 );
    sol = new Vector( "u2-sol", velBot, x, NULL, 0 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, VI, VI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "vel-bot_" );
    KSPSetFromOptions( ksp );
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    delete velTopAdv;
    delete velBotAdv;
    delete etaIntTemp;
    delete velTopNew;
    delete velBotNew;
}
Exemplo n.º 5
0
void TwoLayerSW::SolveFirstOrder() {
    Advector*		velTopAdv	= new Advector( velTop, velTop );
    Advector*		velBotAdv	= new Advector( velBot, velBot );
    /* interfacial pressure rhs */
    FieldRHS*		etaRHS;
    DivHeightVelRHS*	dEtaVel1RHS;
    DivHeightVelRHS*	dEtaVel2RHS;
    PhiRHS*			u1RHS;
    PhiRHS*			u2RHS;
    /* momentum eqn rhs */
    FieldRHS*		velRHS;
    GradFieldRHS*		gPresRHS;
    WindStress2RHS*		windRHS;
    GradFieldRHS*		gEtaRHS;
    RHSOp**			ops;
    Vector*			sol;
    Vector*			rhs;
    Vec			f;
    Vec			x;
    KSP			ksp;
    MatNullSpace		null;

    //SolvePressureFirstOrder();

    CreateVector( etaInt, &f );
    CreateVector( etaInt, &x );

    velTopAdv->Advect( dt );
    velBotAdv->Advect( dt );

    sol = new Vector( "e-sol", etaInt, x, NULL, 0 );

    etaRHS      = new FieldRHS( "eta-rhs", etaInt->mesh, 1.0, etaInt );
    dEtaVel1RHS = new DivHeightVelRHS( "div-eta-vel-1-rhs", etaInt->mesh, -0.5*dt, etaInt, velTop );
    dEtaVel2RHS = new DivHeightVelRHS( "div-eta-vel-2-rhs", etaInt->mesh, -0.5*dt, etaInt, velBot );
    u1RHS       = new PhiRHS( "u1-rhs", etaInt->mesh, 1.0, velTop, +1.0, dt, params->H1, params->tau, params->k,
                              params->nu, params->p, params->f, params->beta, presSurf, etaInt, velTopAdv->fieldSL );
    u2RHS       = new PhiRHS( "u2-rhs", etaInt->mesh, 1.0, velBot, -1.0, dt, params->H2, 0.0, 0.0,
                              params->nu, params->p, params->f, params->beta, presSurf, etaInt, velBotAdv->fieldSL );
    ops = new RHSOp*[5];
    ops[0] = etaRHS;
    ops[1] = dEtaVel1RHS;
    ops[2] = dEtaVel2RHS;
    ops[3] = u1RHS;
    ops[4] = u2RHS;
    rhs = new Vector( "e-rhs", etaInt, f, ops, 5 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, PI, PI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "eta-int_" );
    KSPSetFromOptions( ksp );
    if( enull ) {
        MatNullSpaceCreate( MPI_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, &null );
        KSPSetNullSpace( ksp, null );
    }
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    if( enull ) {
        MatNullSpaceDestroy( null );
    }
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    /* update the upper layer velocity field */
    CreateVector( velTop, &x );
    CreateVector( velTop, &f );

    velRHS   = new FieldRHS( "vel-1-rhs", velTop->mesh, 1.0, velTopAdv->fieldSL );
    gPresRHS = new GradFieldRHS( "g-pres-rhs", velTop->mesh, -dt*params->p, presSurf );
    windRHS  = new WindStress2RHS( "wind-rhs", velTop->mesh, dt*params->tau, etaInt, params->k, params->H1 );
    ops = new RHSOp*[3];
    ops[0] = velRHS;
    ops[1] = gPresRHS;
    ops[2] = windRHS;
    rhs = new Vector( "u1-rhs", velTop, f, ops, 3 );
    sol = new Vector( "u1-sol", velTop, x, NULL, 0 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, VI, VI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "vel-top_" );
    KSPSetFromOptions( ksp );
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    /* update the lower layer velocity field */
    CreateVector( velBot, &x );
    CreateVector( velBot, &f );

    velRHS   = new FieldRHS( "vel-2-rhs", velBot->mesh, 1.0, velBotAdv->fieldSL );
    gPresRHS = new GradFieldRHS( "g-pres-rhs", velBot->mesh, -dt*params->p, presSurf );
    gEtaRHS  = new GradFieldRHS( "g-eta-rhs", velBot->mesh, -dt*params->g, etaInt );
    ops = new RHSOp*[3];
    ops[0] = velRHS;
    ops[1] = gPresRHS;
    ops[2] = gEtaRHS;
    rhs = new Vector( "u2-rhs", velBot, f, ops, 3 );
    sol = new Vector( "u2-sol", velBot, x, NULL, 0 );
    rhs->Assemble();

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, VI, VI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "vel-bot_" );
    KSPSetFromOptions( ksp );
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    KSPDestroy( ksp );

    delete sol;
    delete rhs;
    VecDestroy( f );
    VecDestroy( x );

    delete velTopAdv;
    delete velBotAdv;
}
Exemplo n.º 6
0
void TwoLayerSW::SolvePressureSecondOrder( Field* velTopPrev, Field* velBotPrev, Field* etaIntPrev ) {
    Field*		velBarCurr	= new Field( "vel-bar-curr", velTop->mesh, 2, velTop->bcs );
    Field*		velBarPrev	= new Field( "vel-bar-prev", velTop->mesh, 2, velTop->bcs );
    Field*		velHat		= new Field( "vel-hat", velTop->mesh, 2, velTop->bcs );
    Field*		deltaPres	= new Field( "delta-pres", presSurf->mesh, 1, presSurf->bcs );
    FieldRHS*	velCurrRHS;
    FieldRHS*	velPrevRHS;
    GradFieldRHS*	gPresRHS;
    DivVelRHS*	divVelRHS;
    RHSOp**		ops;
    Vector*		rhs;
    Vector*		sol;
    Vec		x;
    Vec		f;
    Vec		G;
    KSP		ksp;
    MatNullSpace	null;

    CalcVelBar( velTop, velBot, etaInt, velBarCurr );
    CalcVelBar( velTopPrev, velBotPrev, etaIntPrev, velBarPrev );

    CreateVector( velBarCurr, &f );
    CreateVector( velBarCurr, &x );

    velCurrRHS = new FieldRHS( "vel-rhs", velHat->mesh, +2.0, velBarCurr );
    velPrevRHS = new FieldRHS( "vel-rhs", velHat->mesh, -0.5, velBarPrev );
    gPresRHS = new GradFieldRHS( "grad-pres-rhs", velHat->mesh, -dt*params->p, presSurf );
    ops = new RHSOp*[3];
    ops[0] = velCurrRHS;
    ops[1] = velPrevRHS;
    ops[2] = gPresRHS;
    rhs = new Vector( "rhs", velHat, f, ops, 3 );
    sol = new Vector( "sol", velHat, x, NULL, 0 );
    rhs->Assemble();

    AssembleGSecondOrder( velTopPrev, velBotPrev, etaIntPrev, &G );
    VecAXPY( f, 1.0, G );

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, UI, UI, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "vel-bar_" );
    KSPSetFromOptions( ksp );
    KSPSolve( ksp, f, x );
    sol->UpdateField();
    KSPDestroy( ksp );

    VecDestroy( f );
    VecDestroy( x );
    VecDestroy( G );
    delete rhs;
    delete sol;
    delete velBarCurr;
    delete velBarPrev;

    CreateVector( presSurf, &f );
    CreateVector( presSurf, &x );

    divVelRHS = new DivVelRHS( "div-vel", presSurf->mesh, 1.0, velHat );
    ops = new RHSOp*[1];
    ops[0] = divVelRHS;
    rhs = new Vector( "rhs", deltaPres, f, ops, 1 );
    rhs->Assemble();

    sol = new Vector( "sol", deltaPres, x, NULL, 0 );

    KSPCreate( MPI_COMM_WORLD, &ksp );
    KSPSetOperators( ksp, PS, PS, SAME_NONZERO_PATTERN );
    KSPSetOptionsPrefix( ksp, "pres-surf_" );
    KSPSetFromOptions( ksp );
    if( pnull ) {
        MatNullSpaceCreate( MPI_COMM_WORLD, PETSC_TRUE, 0, PETSC_NULL, &null );
        KSPSetNullSpace( ksp, null );
    }
    KSPSolve( ksp, f, x );
    if( pnull ) {
        MatNullSpaceDestroy( null );
    }
    KSPDestroy( ksp );
    sol->UpdateField();

    for( int i = 0; i < presSurf->mesh->nVertsTotal; i++ ) {
        presSurf->vals[i][0] += deltaPres->vals[i][0];
    }

    VecDestroy( f );
    VecDestroy( x );
    delete rhs;
    delete sol;
    delete velHat;
    delete deltaPres;
}
Exemplo n.º 7
0
int 
BeamColumnJoint3d::getResponse(int responseID, Information &eleInfo)
{
	static Vector delta(13);
	static Vector def(4);
	static Vector U(16);
	static Vector Utemp(12);
	double bsFa, bsFb, bsFc, bsFd;
	double bsFac, bsFbd, isFac, isFbd; 

	switch (responseID) {
	case 1:       
		if(eleInfo.theVector!=0)
		{
			(*(eleInfo.theVector))(0) =  UeprCommit(0);
			(*(eleInfo.theVector))(1) =  UeprCommit(1);
			(*(eleInfo.theVector))(2) =  UeprCommit(2);
			(*(eleInfo.theVector))(3) =  UeprCommit(3);
			(*(eleInfo.theVector))(4) =  UeprCommit(4);
			(*(eleInfo.theVector))(5) =  UeprCommit(5);
			(*(eleInfo.theVector))(6) =  UeprCommit(6);
			(*(eleInfo.theVector))(7) =  UeprCommit(7);
			(*(eleInfo.theVector))(8) =  UeprCommit(8);
			(*(eleInfo.theVector))(9) =  UeprCommit(9);
			(*(eleInfo.theVector))(10) = UeprCommit(10);
			(*(eleInfo.theVector))(11) = UeprCommit(11);
			(*(eleInfo.theVector))(12) = UeprCommit(12);
			(*(eleInfo.theVector))(13) = UeprCommit(13);
			(*(eleInfo.theVector))(14) = UeprCommit(14);
			(*(eleInfo.theVector))(15) = UeprCommit(15);
			(*(eleInfo.theVector))(16) = UeprCommit(16);
			(*(eleInfo.theVector))(17) = UeprCommit(17);
			(*(eleInfo.theVector))(18) = UeprCommit(18);
			(*(eleInfo.theVector))(19) = UeprCommit(19);
			(*(eleInfo.theVector))(20) = UeprCommit(20);
			(*(eleInfo.theVector))(21) = UeprCommit(21);
			(*(eleInfo.theVector))(22) = UeprCommit(22);
			(*(eleInfo.theVector))(23) = UeprCommit(23);
		}
		return 0;

	case 2:
		if (eleInfo.theVector !=0) {
			(*(eleInfo.theVector))(0) = UeprIntCommit(0);
			(*(eleInfo.theVector))(1) = UeprIntCommit(1);
			(*(eleInfo.theVector))(2) = UeprIntCommit(2);
			(*(eleInfo.theVector))(3) = UeprIntCommit(3);
		}
		return 0;

	case 3:

		// modified 01.04.03  -------- determine which plane the joint lies
		Utemp.addMatrixVector(0.0,Transf,UeprCommit,1.0);
		U.Assemble(Utemp,0,1.0);
		U.Assemble(UeprIntCommit,12,1.0);

		delta.addMatrixVector(0.0,BCJoint,U,1.0);
		
		bsFa = fabs(delta(0) - delta(1))/elemWidth;
		bsFc = fabs(delta(7) - delta(6))/elemWidth;
		bsFac = bsFa + bsFc;
		bsFb = fabs(delta(4) - delta(3))/elemHeight;
		bsFd = fabs(delta(10) - delta(9))/elemHeight;
		bsFbd = bsFb + bsFd;

		def(0) = bsFac + bsFbd; // contribution of bar slip deformation
		
		
		isFac = (delta(2) + delta(8))/elemHeight;
		isFbd = (delta(5) + delta(11))/elemWidth;

		def(1) = isFac + isFbd;  // contribution due to interface shear spring

		def(2) = delta(12);  // contribution due to shear panel

		def(3) = def(0) + def(1) + def(2);  // total joint deformation


		return eleInfo.setVector(def);
	default:
		return -1;
	}
}