void VanDerPolOscillator::evalModel( const InArgs& inArgs, 
				     const OutArgs& outArgs ) const
{
  // compute f(x)
  Teuchos::RCP<const Epetra_Vector> x = inArgs.get_x();
  Teuchos::RCP<Epetra_Vector> f = outArgs.get_f();
  if ( (x != Teuchos::null) && (f != Teuchos::null) ) {
    evalVField((*x)[0],(*x)[1],(*f)[0],(*f)[1]);
  }

  // compute f([x])
  Teuchos::RCP<const Teuchos::Polynomial<Epetra_Vector> > x_poly = 
    inArgs.get_x_poly();
  Teuchos::RCP<Teuchos::Polynomial<Epetra_Vector> > f_poly = 
    outArgs.get_f_poly();
  if ( (x_poly != Teuchos::null) && (f_poly != Teuchos::null) ) {
    unsigned int d = x_poly->degree();
    Sacado::Tay::Taylor<double> x1(d,0.0);
    Sacado::Tay::Taylor<double> x2(d,0.0);
    Sacado::Tay::Taylor<double> f1(d,0.0);
    Sacado::Tay::Taylor<double> f2(d,0.0);

    for (unsigned int i=0; i<=d; i++) {
      x1.fastAccessCoeff(i) = (*(x_poly->getCoefficient(i)))[0];
      x2.fastAccessCoeff(i) = (*(x_poly->getCoefficient(i)))[1];
    }

    evalVField(x1,x2,f1,f2);

    for (unsigned int i=0; i<=d; i++) {
      (*(f_poly->getCoefficient(i)))[0] = f1.coeff(i);
      (*(f_poly->getCoefficient(i)))[1] = f2.coeff(i);
    }
  }

  // compute W
  Teuchos::RCP<Epetra_Operator> W = outArgs.get_W();
  if (W != Teuchos::null) {
    const double alpha = inArgs.get_alpha();
    const double beta = inArgs.get_beta();
    Epetra_CrsMatrix &crsW = Teuchos::dyn_cast<Epetra_CrsMatrix>(*W);
    const int dim = 2;
    double values_1[2];
    double values_2[2];
    int indices[] = {0,1};

    Sacado::Fad::DFad<double> x1(dim,0,(*x)[0]);
    Sacado::Fad::DFad<double> x2(dim,1,(*x)[1]);
    Sacado::Fad::DFad<double> f1;
    Sacado::Fad::DFad<double> f2;

    evalVField(x1,x2,f1,f2);

    values_1[0] = alpha * f1.fastAccessDx(0) - beta;
    values_1[1] = alpha * f1.fastAccessDx(1);
    values_2[0] = alpha * f2.fastAccessDx(0);
    values_2[0] = alpha * f2.fastAccessDx(1) - beta;
   
    crsW.ReplaceGlobalValues(0,dim,values_1,indices);
    crsW.ReplaceGlobalValues(1,dim,values_2,indices);
  }
}