void TRBDF2SolverNewtonFunction::evalF(RealVector& Z, RealVector& F){

	Bool refining = (ref.all() == false);

	if(refining == false){
		Integer n = Z.size();
		RealVector Y(n);
		Y.fill(0.0);
		F.fill(0.0);

		Y = ya + d * Z;

		RealVector f  = fun->evalF(tnp,Y);

		F = Z  - dt * f;
	}
	else{

		Integer n = ref.cast<Real>().size();
		RealVector Y(n);
		Y.fill(0.0);
		F.fill(0.0);

		RealVector Z_long = VectorUtility::vectorProlong(Z,ref);

		Y = ya + d * Z_long;

		RealVector f  = fun->evalF(tnp,Y,ref);

		F = Z  - dt * f;
	}
}
void TRBDF2SolverNewtonFunction::evalFJ(RealVector& Z, RealVector& F, RealMatrixSparse& J){

	Bool refining = (ref.all() == false);

	if(refining == false){

		Integer n = Z.size();
		RealVector Y(n);
		Y.fill(0.0);
		F.fill(0.0);

		RealMatrixSparse DZ_DZ(n,n);  //Identity matrix
		DZ_DZ.setIdentity();

		Y = ya + d * Z;

		RealVector f  = fun->evalF(tnp,Y);
		RealMatrixSparse Df_DY = fun->evaldFdY(tnp,Y);


		F = Z     - dt *     f;
		J = DZ_DZ - dt * d * Df_DY;    //J = DF_DZ

	}
	else{

		Real d = (2 - sqrt(2))/2;

		Integer n = ref.cast<Real>().size();
		RealVector Y(n);
		Y.fill(0);
		F.fill(0);

		Integer elem_ref = ref.sum();
		RealMatrixSparse DZ_DZ;
		DZ_DZ.resize(elem_ref,elem_ref);
		DZ_DZ.setIdentity();


		RealVector Z_long = VectorUtility::vectorProlong(Z,ref);

		Y = ya + d * Z_long;

		RealVector f  = fun->evalF(tnp,Y,ref);
		RealMatrixSparse Df_DY = fun->evaldFdY(tnp,Y,ref);

		F = Z     - dt *     f;
		J = DZ_DZ - dt * d * Df_DY;  //J = DF_DZ
	}
}
예제 #3
0
///////////////////////////////////////////////////////////////////////////////
//
/// Changes the variable of a polynomial represented in P and stores the
/// result in Q so that \f$P(x) = Q(x')\f$ where
///
/// \f$x = \alpha x' + (1 - \alpha)\f$
//
///////////////////////////////////////////////////////////////////////////////
void AntisymmetricExpFit::change_variable(RealVector &P, const Real &alpha, RealVector &Q) {
  const int M = P.size(); 	// degree of P + 1
  const int SMAX = 96;		// maximum degree of Q
  int m;			// index into P
  int r;			// index into Q
  Real beta = 1.0-alpha;	// offset
  Real lgb;			// log of alpha^r beta^(m-r) (m choose r) 
  Q.resize(SMAX);
  Q.fill(0.0);

  for(r = 0; r<SMAX; ++r) {
    lgb = r*log(alpha);
    for(m = r; m<M; ++m) {
      Q(r) += exp(lgb)*P(m);
      lgb += log(beta) + log((m+1.0)/(m+1.0-r));
    }
  }
}