当前位置: 首页>>代码示例>>C++>>正文


C++ InArgs::get_alpha方法代码示例

本文整理汇总了C++中InArgs::get_alpha方法的典型用法代码示例。如果您正苦于以下问题:C++ InArgs::get_alpha方法的具体用法?C++ InArgs::get_alpha怎么用?C++ InArgs::get_alpha使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在InArgs的用法示例。


在下文中一共展示了InArgs::get_alpha方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1:

void ExampleApplication1Dfem::evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const
{
  Teuchos::RCP<const Epetra_Vector> x = inArgs.get_x();
  Teuchos::RCP<const Epetra_Vector> xdot = inArgs.get_x_dot();
#ifdef EXAMPLEAPPLICATION_DEBUG
  std::cout << "ExampleApplication1Dfem::evalModel ---------------------------{" << std::endl;
  std::cout << "x = " << std::endl;
  x->Print(std::cout);
  std::cout << "xdot = " << std::endl;
  xdot->Print(std::cout);
#endif // EXAMPLEAPPLICATION_DEBUG
  Teuchos::RCP<Epetra_Vector> f;
  if( (f = outArgs.get_f()).get() ) 
  {
    NOX::Epetra::Interface::Required::FillType flag = NOX::Epetra::Interface::Required::Residual;
    problemInterfacePtr_->evaluate(flag,&*x,&*xdot,0.0,0.0,&*f,NULL);
#ifdef EXAMPLEAPPLICATION_DEBUG
    std::cout << "f = " << std::endl;
    f->Print(std::cout);
#endif // EXAMPLEAPPLICATION_DEBUG
  }
  Teuchos::RCP<Epetra_Operator> W;
  if( (W = outArgs.get_W()).get() ) 
  {
    const double alpha = inArgs.get_alpha();
    const double beta = inArgs.get_beta();
    NOX::Epetra::Interface::Required::FillType flag = NOX::Epetra::Interface::Required::Jac;
//    Epetra_CrsMatrix& jacobian = problemInterfacePtr_->getJacobian();
    Epetra_CrsMatrix& jac = Teuchos::dyn_cast<Epetra_CrsMatrix>(*W);
    problemInterfacePtr_->evaluate(flag,&*x,&*xdot,alpha,beta,NULL,&jac);
#ifdef EXAMPLEAPPLICATION_DEBUG
    std::cout << "jac = " << std::endl;
    jac.Print(std::cout);
#endif // EXAMPLEAPPLICATION_DEBUG
  }
#ifdef EXAMPLEAPPLICATION_DEBUG
  std::cout << "ExampleApplication1Dfem::evalModel ---------------------------}" << std::endl;
#endif // EXAMPLEAPPLICATION_DEBUG
}
开发者ID:haripandey,项目名称:trilinos,代码行数:39,代码来源:ExampleApplication1Dfem.cpp

示例2: evalModel

void ExampleApplication::evalModel( const InArgs& inArgs, const OutArgs& outArgs ) const
{
  const Epetra_Vector &x = *(inArgs.get_x());
  const double t = inArgs.get_t();
  const Epetra_Vector &lambda = *lambda_ptr_;
#ifdef EXAMPLEAPPLICATION_DEBUG
      std::cout << "----------------------------------------------------------------------" << std::endl;
      std::cout << "ExampleApplication::evalModel x = " << std::endl;
      x.Print(std::cout);
      std::cout << "ExampleApplication::evalModel lambda = " << std::endl;
      lambda.Print(std::cout);
#endif
  int localNumElements = x.MyLength();
  if(implicit_) 
  {
    const Epetra_Vector &x_dot = *inArgs.get_x_dot();
    if(outArgs.get_f().get()) 
    {
      Epetra_Vector &f = *outArgs.get_f();
      for (int i=0 ; i<localNumElements ; ++i)
      {
        f[i] = x_dot[i] - lambda[i]*x[i] - evalR(t,lambda[i],coeff_s_);
      }
#ifdef EXAMPLEAPPLICATION_DEBUG
      std::cout << "ExampleApplication::evalModel (implicit) x_dot = " << std::endl;
      x_dot.Print(std::cout);
      std::cout << "ExampleApplication::evalModel (implicit) f = " << std::endl;
      f.Print(std::cout);
#endif
    }
    Teuchos::RCP<Epetra_Operator> W;
    if( (W = outArgs.get_W()).get() ) {
      const double alpha = inArgs.get_alpha();
      const double beta = inArgs.get_beta();
      Epetra_CrsMatrix &crsW = Teuchos::dyn_cast<Epetra_CrsMatrix>(*W);
      double values[1];
      int indices[1];
      const int IB = epetra_map_ptr_->IndexBase();
      for( int i = 0; i < localNumElements; ++i ) 
      {
        values[0] = alpha - beta*lambda[i];
        indices[0] = i + IB;  // global column
        crsW.ReplaceGlobalValues(i + IB              // GlobalRow
                                 ,1                  // NumEntries
                                 ,values             // Values
                                 ,indices            // Indices
                                          );
      }
#ifdef EXAMPLEAPPLICATION_DEBUG
      std::cout << "ExampleApplication::evalModel (implicit) alpha, beta = " << std::endl;
      std::cout << "alpha = " << alpha << std::endl;
      std::cout << "beta = "  << beta  << std::endl;
      std::cout << "ExampleApplication::evalModel (implicit) W = " << std::endl;
      crsW.Print(std::cout);
#endif
    }
  }
  else 
  {
    Epetra_Vector &f = *outArgs.get_f();
    for (int i=0 ; i<localNumElements ; ++i)
    {
      f[i] = lambda[i]*x[i]+evalR(t,lambda[i],coeff_s_);
    }
#ifdef EXAMPLEAPPLICATION_DEBUG
    std::cout << "ExampleApplication::evalModel (explicit) f = " << std::endl;
    f.Print(std::cout);
#endif
  }
#ifdef EXAMPLEAPPLICATION_DEBUG
  std::cout << "----------------------------------------------------------------------" << std::endl;
#endif
}
开发者ID:haripandey,项目名称:trilinos,代码行数:73,代码来源:ExampleApplication.cpp

示例3: evalModel

void MockModelEval_A::evalModel( const InArgs& inArgs,
                              const OutArgs& outArgs ) const
{

  // Parse InArgs
  RCP<const Epetra_Vector> p_in = inArgs.get_p(0);
  if (!p_in.get()) cout << "ERROR: MockModelEval_A requires p as inargs" << endl;
  //int numParameters = p_in->GlobalLength();

  RCP<const Epetra_Vector> x_in = inArgs.get_x();
  if (!x_in.get()) cout << "ERROR: MockModelEval_A requires x as inargs" << endl;
  int vecLength = x_in->GlobalLength();
  int myVecLength = x_in->MyLength();

  // Parse OutArgs

  RCP<Epetra_Vector> f_out = outArgs.get_f(); 
  RCP<Epetra_Vector> g_out = outArgs.get_g(0); 
  Teuchos::RCP<Epetra_Operator> W_out = outArgs.get_W();
  Teuchos::RCP<Epetra_MultiVector> dfdp_out;
  if (outArgs.Np() > 0)
    dfdp_out = outArgs.get_DfDp(0).getMultiVector();
  RCP<Epetra_MultiVector> dgdp_out;
  dgdp_out = outArgs.get_DgDp(0,0).getMultiVector();
  RCP<Epetra_MultiVector> dgdx_out;
  dgdx_out = outArgs.get_DgDx(0).getMultiVector();

  if (f_out != Teuchos::null) {
    for (int i=0; i<myVecLength; i++) {
      int gid = x_in->Map().GID(i);
      if (gid==0) // x_0^2 = p_0
       (*f_out)[i] = (*x_in)[i] * (*x_in)[i] -  (*p_in)[i];
      else // x^2 = (i+p_1)^2
       (*f_out)[i] = (*x_in)[i] * (*x_in)[i] - (gid + (*p_in)[1])*(gid + (*p_in)[1]);
    }
  }
  if (W_out != Teuchos::null) {
    Teuchos::RCP<Epetra_CrsMatrix> W_out_crs =
      Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out, true);
    W_out_crs->PutScalar(0.0);

    double diag=0.0;
    for (int i=0; i<myVecLength; i++) {
      diag = 2.0 * (*x_in)[i];
      W_out_crs->ReplaceMyValues(i, 1, &diag, &i);
    }
  }

  if (dfdp_out != Teuchos::null) {
    dfdp_out->PutScalar(0.0);
    for (int i=0; i<myVecLength; i++) {
      int gid = x_in->Map().GID(i);
      if   (gid==0) (*dfdp_out)[0][i] = -1.0;
      else          (*dfdp_out)[1][i] =  -2.0* (gid + (*p_in)[1]);
    }
  }

  // ObjFn = 0.5*(Sum(x)-Sum(p)-12)^2 + 0.5*(p0-1)^2:  min at 1,3

  double term1, term2;
  x_in->MeanValue(&term1); 
  term1 =  vecLength * term1 - ((*p_in)[0] + (*p_in)[1]) - 12.0;
  term2 = (*p_in)[0] - 1.0;
  
  if (!is_null(g_out)) {
    (*g_out)[0] = 0.5*term1*term1 + 0.5*term2*term2;
  }

  if (dgdx_out != Teuchos::null) {
     dgdx_out->PutScalar(term1);
   }
  if (dgdp_out != Teuchos::null) {
     dgdp_out->PutScalar(0.0);
     (*dgdp_out)[0][0] = -term1 + term2;
     (*dgdp_out)[0][1] = -term1;
   }

  // Modify for time dependent (implicit timeintegration or eigensolves
  // Check if time dependent
  RCP<const Epetra_Vector> x_dot = inArgs.get_x_dot();

  if (x_dot.get()) {
    double alpha =  inArgs.get_alpha();
    double beta  =  inArgs.get_beta();
    if (alpha==0.0 && beta==0.0) {
      cout << "MockModelEval Warning: alpha=beta=0 -- setting beta=1" << endl;
      beta = 1.0;
    }

    if (f_out != Teuchos::null) {
      for (int i=0; i<myVecLength; i++) {
         (*f_out)[i] = -alpha*(*x_dot)[i] + beta * (*f_out)[i];
      }
    }
    if (dfdp_out != Teuchos::null) {
      dfdp_out->Scale(beta);
    }
    if (W_out != Teuchos::null) {
      Teuchos::RCP<Epetra_CrsMatrix> W_out_crs =
        Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out, true);
//.........这里部分代码省略.........
开发者ID:haripandey,项目名称:trilinos,代码行数:101,代码来源:MockModelEval_A.cpp

示例4: Timer

void
Albany::ModelEvaluator::evalModel(const InArgs& inArgs,
                                 const OutArgs& outArgs) const
{
  Teuchos::TimeMonitor Timer(*timer); //start timer
  //
  // Get the input arguments
  //
  Teuchos::RCP<const Epetra_Vector> x = inArgs.get_x();
  Teuchos::RCP<const Epetra_Vector> x_dot;
  Teuchos::RCP<const Epetra_Vector> x_dotdot;
  double alpha     = 0.0;
  double omega     = 0.0;
  double beta      = 1.0;
  double curr_time = 0.0;
  x_dot = inArgs.get_x_dot();
  x_dotdot = inArgs.get_x_dotdot();
  if (x_dot != Teuchos::null || x_dotdot != Teuchos::null) {
    alpha = inArgs.get_alpha();
    omega = inArgs.get_omega();
    beta = inArgs.get_beta();
    curr_time  = inArgs.get_t();
  }
  for (int i=0; i<num_param_vecs; i++) {
    Teuchos::RCP<const Epetra_Vector> p = inArgs.get_p(i);
    if (p != Teuchos::null) {
      for (unsigned int j=0; j<sacado_param_vec[i].size(); j++)
        sacado_param_vec[i][j].baseValue = (*p)[j];
    }
  }
  for (int i=0; i<num_dist_param_vecs; i++) {
    Teuchos::RCP<const Epetra_Vector> p = inArgs.get_p(i+num_param_vecs);
    if (p != Teuchos::null) {
      *(distParamLib->get(dist_param_names[i])->vector()) = *p;
    }
  }

  //
  // Get the output arguments
  //
  EpetraExt::ModelEvaluator::Evaluation<Epetra_Vector> f_out = outArgs.get_f();
  Teuchos::RCP<Epetra_Operator> W_out = outArgs.get_W();

  // Cast W to a CrsMatrix, throw an exception if this fails
  Teuchos::RCP<Epetra_CrsMatrix> W_out_crs;

  if (W_out != Teuchos::null)
    W_out_crs = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out, true);

int test_var = 0;
if(test_var != 0){
std::cout << "The current solution length is: " << x->MyLength() << std::endl;
x->Print(std::cout);

}

  // Get preconditioner operator, if requested
  Teuchos::RCP<Epetra_Operator> WPrec_out;
  if (outArgs.supports(OUT_ARG_WPrec)) WPrec_out = outArgs.get_WPrec();

  //
  // Compute the functions
  //
  bool f_already_computed = false;

  // W matrix
  if (W_out != Teuchos::null) {
    app->computeGlobalJacobian(alpha, beta, omega, curr_time, x_dot.get(), x_dotdot.get(),*x,
                               sacado_param_vec, f_out.get(), *W_out_crs);
    f_already_computed=true;
if(test_var != 0){
//std::cout << "The current rhs length is: " << f_out->MyLength() << std::endl;
//f_out->Print(std::cout);
std::cout << "The current Jacobian length is: " << W_out_crs->NumGlobalRows() << std::endl;
W_out_crs->Print(std::cout);
}
  }

  if (WPrec_out != Teuchos::null) {
    app->computeGlobalJacobian(alpha, beta, omega, curr_time, x_dot.get(), x_dotdot.get(), *x,
                               sacado_param_vec, f_out.get(), *Extra_W_crs);
    f_already_computed=true;
if(test_var != 0){
//std::cout << "The current rhs length is: " << f_out->MyLength() << std::endl;
//f_out->Print(std::cout);
std::cout << "The current preconditioner length is: " << Extra_W_crs->NumGlobalRows() << std::endl;
Extra_W_crs->Print(std::cout);
}

    app->computeGlobalPreconditioner(Extra_W_crs, WPrec_out);
  }

  // scalar df/dp
  for (int i=0; i<num_param_vecs; i++) {
    Teuchos::RCP<Epetra_MultiVector> dfdp_out =
      outArgs.get_DfDp(i).getMultiVector();
    if (dfdp_out != Teuchos::null) {
      Teuchos::Array<int> p_indexes =
        outArgs.get_DfDp(i).getDerivativeMultiVector().getParamIndexes();
      Teuchos::RCP<ParamVec> p_vec;
//.........这里部分代码省略.........
开发者ID:adam727,项目名称:Albany,代码行数:101,代码来源:Albany_ModelEvaluator.cpp

示例5: Timer

void
Albany::ModelEvaluator::evalModel(const InArgs& inArgs,
                                 const OutArgs& outArgs) const
{
  Teuchos::TimeMonitor Timer(*timer); //start timer
  //
  // Get the input arguments
  //
  Teuchos::RCP<const Epetra_Vector> x = inArgs.get_x();
  Teuchos::RCP<const Epetra_Vector> x_dot;
  Teuchos::RCP<const Epetra_Vector> x_dotdot;

  //create comm and node objects for Epetra -> Tpetra conversions
  Teuchos::RCP<const Teuchos::Comm<int> > commT = app->getComm();
  Teuchos::RCP<Epetra_Comm> comm = Albany::createEpetraCommFromTeuchosComm(commT);
  //Create Tpetra copy of x, call it xT
  Teuchos::RCP<const Tpetra_Vector> xT;
  if (x != Teuchos::null)
    xT  = Petra::EpetraVector_To_TpetraVectorConst(*x, commT);

  double alpha     = 0.0;
  double omega     = 0.0;
  double beta      = 1.0;
  double curr_time = 0.0;

  if(num_time_deriv > 0)
    x_dot = inArgs.get_x_dot();
  if(num_time_deriv > 1)
    x_dotdot = inArgs.get_x_dotdot();

  //Declare and create Tpetra copy of x_dot, call it x_dotT
  Teuchos::RCP<const Tpetra_Vector> x_dotT;
  if (Teuchos::nonnull(x_dot))
    x_dotT = Petra::EpetraVector_To_TpetraVectorConst(*x_dot, commT);

  //Declare and create Tpetra copy of x_dotdot, call it x_dotdotT
  Teuchos::RCP<const Tpetra_Vector> x_dotdotT;
  if (Teuchos::nonnull(x_dotdot))
    x_dotdotT = Petra::EpetraVector_To_TpetraVectorConst(*x_dotdot, commT);

  if (Teuchos::nonnull(x_dot)){
    alpha = inArgs.get_alpha();
    beta = inArgs.get_beta();
    curr_time  = inArgs.get_t();
  }
  if (Teuchos::nonnull(x_dotdot)) {
    omega = inArgs.get_omega();
  }

  for (int i=0; i<num_param_vecs; i++) {
    Teuchos::RCP<const Epetra_Vector> p = inArgs.get_p(i);
    if (p != Teuchos::null) {
      for (unsigned int j=0; j<sacado_param_vec[i].size(); j++) {
        sacado_param_vec[i][j].baseValue = (*p)[j];
      }
    }
  }
  for (int i=0; i<num_dist_param_vecs; i++) {
    Teuchos::RCP<const Epetra_Vector> p = inArgs.get_p(i+num_param_vecs);
    //create Tpetra copy of p
    Teuchos::RCP<const Tpetra_Vector> pT;
    if (p != Teuchos::null) {
      pT = Petra::EpetraVector_To_TpetraVectorConst(*p, commT);
      //*(distParamLib->get(dist_param_names[i])->vector()) = *p;
      *(distParamLib->get(dist_param_names[i])->vector()) = *pT;
    }
  }

  //
  // Get the output arguments
  //
  EpetraExt::ModelEvaluator::Evaluation<Epetra_Vector> f_out = outArgs.get_f();
  Teuchos::RCP<Epetra_Operator> W_out = outArgs.get_W();

  // Cast W to a CrsMatrix, throw an exception if this fails
  Teuchos::RCP<Epetra_CrsMatrix> W_out_crs;
#ifdef WRITE_MASS_MATRIX_TO_MM_FILE
  //IK, 7/15/14: adding object to hold mass matrix to be written to matrix market file
  Teuchos::RCP<Epetra_CrsMatrix> Mass;
  //IK, 7/15/14: needed for writing mass matrix out to matrix market file
  EpetraExt::ModelEvaluator::Evaluation<Epetra_Vector> ftmp = outArgs.get_f();
#endif

  if (W_out != Teuchos::null) {
    W_out_crs = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out, true);
#ifdef WRITE_MASS_MATRIX_TO_MM_FILE
    //IK, 7/15/14: adding object to hold mass matrix to be written to matrix market file
    Mass = Teuchos::rcp_dynamic_cast<Epetra_CrsMatrix>(W_out, true);
#endif
  }


int test_var = 0;
if(test_var != 0){
std::cout << "The current solution length is: " << x->MyLength() << std::endl;
x->Print(std::cout);

}

  // Get preconditioner operator, if requested
//.........这里部分代码省略.........
开发者ID:ImmutableLtd,项目名称:Albany,代码行数:101,代码来源:Albany_ModelEvaluator.cpp

示例6: if

void 
Stokhos::SGQuadModelEvaluator::
evalModel(const InArgs& inArgs, const OutArgs& outArgs) const
{
  // Create underlying inargs
  InArgs me_inargs = me->createInArgs();
  if (me_inargs.supports(IN_ARG_x))
    me_inargs.set_x(inArgs.get_x());
  if (me_inargs.supports(IN_ARG_x_dot))
    me_inargs.set_x_dot(inArgs.get_x_dot());
  if (me_inargs.supports(IN_ARG_alpha))
    me_inargs.set_alpha(inArgs.get_alpha());
  if (me_inargs.supports(IN_ARG_beta))
    me_inargs.set_beta(inArgs.get_beta());
  if (me_inargs.supports(IN_ARG_t))
    me_inargs.set_t(inArgs.get_t());
  for (int i=0; i<num_p; i++)
    me_inargs.set_p(i, inArgs.get_p(i));

  // Create underlying outargs
  OutArgs me_outargs = me->createOutArgs();
  if (me_outargs.supports(OUT_ARG_f))
    me_outargs.set_f(outArgs.get_f());
  if (me_outargs.supports(OUT_ARG_W))
    me_outargs.set_W(outArgs.get_W());
  for (int j=0; j<num_p; j++)
    if (!outArgs.supports(OUT_ARG_DfDp, j).none())
      me_outargs.set_DfDp(j, outArgs.get_DfDp(j));
  for (int i=0; i<num_g; i++) {
    me_outargs.set_g(i, outArgs.get_g(i));
    if (!outArgs.supports(OUT_ARG_DgDx, i).none())
	me_outargs.set_DgDx(i, outArgs.get_DgDx(i));
    if (!outArgs.supports(OUT_ARG_DgDx_dot, i).none())
	me_outargs.set_DgDx(i, outArgs.get_DgDx_dot(i));
    for (int j=0; j<num_p; j++)
      if (!outArgs.supports(OUT_ARG_DgDp, i, j).none())
	me_outargs.set_DgDp(i, j, outArgs.get_DgDp(i,j));
  }

  bool do_quad = false;
  InArgs::sg_const_vector_t x_sg;
  InArgs::sg_const_vector_t x_dot_sg;
  Teuchos::Array<InArgs::sg_const_vector_t> p_sg(num_p);
  OutArgs::sg_vector_t f_sg;
  OutArgs::sg_operator_t W_sg;
  Teuchos::Array<SGDerivative> dfdp_sg(num_p);
  Teuchos::Array<OutArgs::sg_vector_t> g_sg(num_g);
  Teuchos::Array<SGDerivative> dgdx_sg(num_g);
  Teuchos::Array<SGDerivative> dgdx_dot_sg(num_g);
  Teuchos::Array< Teuchos::Array<SGDerivative> > dgdp_sg(num_g);
  TEUCHOS_TEST_FOR_EXCEPTION(inArgs.get_sg_basis() == Teuchos::null, 
		     std::logic_error,
		     "Error!  Stokhos::SGQuadModelEvaluator::evalModel():  " <<
		     "SG basis inArg cannot be null!");
  TEUCHOS_TEST_FOR_EXCEPTION(inArgs.get_sg_quadrature() == Teuchos::null, 
		     std::logic_error,
		     "Error!  Stokhos::SGQuadModelEvaluator::evalModel():  " <<
		     "SG quadrature inArg cannot be null!");
  Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> > basis = 
    inArgs.get_sg_basis();
  Teuchos::RCP< const Stokhos::Quadrature<int,double> > quad = 
    inArgs.get_sg_quadrature();
  if (inArgs.supports(IN_ARG_x_sg)) {
    x_sg = inArgs.get_x_sg();
    if (x_sg != Teuchos::null) {
      do_quad = true;
    }
  }
  if (inArgs.supports(IN_ARG_x_dot_sg)) {
    x_dot_sg = inArgs.get_x_dot_sg();
    if (x_dot_sg != Teuchos::null) {
      do_quad = true;
    }
  }
  for (int i=0; i<num_p; i++) {
    p_sg[i] = inArgs.get_p_sg(i);
    if (p_sg[i] != Teuchos::null) {
      do_quad = true;
    }
  }
  if (outArgs.supports(OUT_ARG_f_sg)) {
    f_sg = outArgs.get_f_sg();
    if (f_sg != Teuchos::null)
      f_sg->init(0.0);
  }
  if (outArgs.supports(OUT_ARG_W_sg)) {
    W_sg = outArgs.get_W_sg();
    if (W_sg != Teuchos::null)
      W_sg->init(0.0);
  }
  for (int i=0; i<num_p; i++) {
    if (!outArgs.supports(OUT_ARG_DfDp_sg, i).none()) {
      dfdp_sg[i] = outArgs.get_DfDp_sg(i);
      if (dfdp_sg[i].getMultiVector() != Teuchos::null)
	dfdp_sg[i].getMultiVector()->init(0.0);
      else if (dfdp_sg[i].getLinearOp() != Teuchos::null)
	dfdp_sg[i].getLinearOp()->init(0.0);
    }
  }
      
//.........这里部分代码省略.........
开发者ID:00liujj,项目名称:trilinos,代码行数:101,代码来源:Stokhos_SGQuadModelEvaluator.cpp

示例7: evalModel

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);
  }
}
开发者ID:haripandey,项目名称:trilinos,代码行数:62,代码来源:VanDerPolOscillator.cpp


注:本文中的InArgs::get_alpha方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。