void
Albany::SamplingBasedScalarResponseFunction::
evaluateSGResponse(
  const double curr_time,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdotdot,
  const Stokhos::EpetraVectorOrthogPoly& sg_x,
  const Teuchos::Array<ParamVec>& p,
  const Teuchos::Array<int>& sg_p_index,
  const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
  Stokhos::EpetraVectorOrthogPoly& sg_g)
{
  RCP<const Epetra_BlockMap> x_map = sg_x.coefficientMap();
  RCP<Epetra_Vector> xdot;
  if (sg_xdot != NULL)
    xdot = rcp(new Epetra_Vector(*x_map));
  RCP<Epetra_Vector> xdotdot;
  if (sg_xdotdot != NULL)
    xdotdot = rcp(new Epetra_Vector(*x_map));
  Epetra_Vector x(*x_map);
  Teuchos::Array<ParamVec> pp = p;
  
  RCP<const Epetra_BlockMap> g_map = sg_g.coefficientMap();
  Epetra_Vector g(*g_map);

  // Get quadrature data
  const Teuchos::Array<double>& norms = basis->norm_squared();
  const Teuchos::Array< Teuchos::Array<double> >& points = 
    quad->getQuadPoints();
  const Teuchos::Array<double>& weights = quad->getQuadWeights();
  const Teuchos::Array< Teuchos::Array<double> >& vals = 
    quad->getBasisAtQuadPoints();
  int nqp = points.size();

  // Compute sg_g via quadrature
  sg_g.init(0.0);
  SGConverter c(this, commT);
  for (int qp=0; qp<nqp; qp++) {

    // Evaluate sg_x, sg_xdot at quadrature point
    sg_x.evaluate(vals[qp], x);
    if (sg_xdot != NULL)
      sg_xdot->evaluate(vals[qp], *xdot);
    if (sg_xdotdot != NULL)
      sg_xdotdot->evaluate(vals[qp], *xdotdot);

    // Evaluate parameters at quadrature point
    for (int i=0; i<sg_p_index.size(); i++) {
      int ii = sg_p_index[i];
      for (unsigned int j=0; j<pp[ii].size(); j++)
	pp[ii][j].baseValue = sg_p_vals[ii][j].evaluate(points[qp], vals[qp]);
    }

    // Compute response at quadrature point
    c.evaluateResponse(curr_time, xdot.get(), xdotdot.get(), x, pp, g);

    // Add result into integral
    sg_g.sumIntoAllTerms(weights[qp], vals[qp], norms, g);
  }
}
bool
Albany::KLResponseFunction::
computeKL(const Stokhos::EpetraVectorOrthogPoly& sg_u,
    const int NumKL,
    Teuchos::Array<double>& evals,
    Teuchos::RCP<Epetra_MultiVector>& evecs)
{
  Teuchos::RCP<const EpetraExt::BlockVector> X_ov = sg_u.getBlockVector();
    //App_sg->get_sg_model()->import_solution( *(sg_u->getBlockVector()) );
  //Teuchos::RCP<const EpetraExt::BlockVector> cX_ov = X_ov;

  // pceKL is object with member functions that explicitly call anasazi
  Stokhos::PCEAnasaziKL pceKL(X_ov, *(sg_u.basis()), NumKL);

  // Set parameters for anasazi
  Teuchos::ParameterList& anasazi_params =
    responseParams.sublist("Anasazi");
  Teuchos::ParameterList default_params = pceKL.getDefaultParams();
  anasazi_params.setParametersNotAlreadySet(default_params);

  // Self explanatory
  bool result = pceKL.computeKL(anasazi_params);

  // Retrieve evals/evectors into return argument slots...
  evals = pceKL.getEigenvalues();
  evecs = pceKL.getEigenvectors();

  return result;
}
void
Albany::SolutionAverageResponseFunction::
evaluateSGGradient(
  const double current_time,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
  const Stokhos::EpetraVectorOrthogPoly& sg_x,
  const Teuchos::Array<ParamVec>& p,
  const Teuchos::Array<int>& sg_p_index,
  const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
  ParamVec* deriv_p,
  Stokhos::EpetraVectorOrthogPoly* sg_g,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dx,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dxdot,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dp)
{
  // Evaluate response g
  if (sg_g != NULL)
    for (int i=0; i<sg_x.size(); i++)
      sg_x[i].MeanValue(&(*sg_g)[i][0]);

  // Evaluate dg/dx
  if (sg_dg_dx != NULL)
    (*sg_dg_dx)[0].PutScalar(1.0 / sg_x[0].GlobalLength());

  // Evaluate dg/dxdot
  if (sg_dg_dxdot != NULL)
    sg_dg_dxdot->init(0.0);

  // Evaluate dg/dp
  if (sg_dg_dp != NULL)
    sg_dg_dp->init(0.0);
}
Ejemplo n.º 4
0
/** Copy from an adaptive vector to a set of blocked vectors
  */
void Stokhos::AdaptivityManager::copyFromAdaptiveVector(const Epetra_Vector & x,Stokhos::EpetraVectorOrthogPoly & x_sg) const
{
   int numBlocks = x_sg.size();
   Teuchos::RCP<EpetraExt::BlockVector> x_sg_bv = x_sg.getBlockVector();

   // zero out determinstic vectors
   for(int blk=0;blk<numBlocks;blk++)
      x_sg_bv->GetBlock(blk)->PutScalar(0.0);

   // copy from adapted vector to deterministic
   for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
      int P_i = getRowStochasticBasisSize(i); 
      int localId = rowMap_->LID(getGlobalRowId(i,0));

      for(int j=0;j<P_i;j++,localId++) {
         int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
         x_sg_bv->GetBlock(blk)->operator[](i) = x[localId];
      }
   }
}
void
Albany::SolutionAverageResponseFunction::
evaluateSGResponse(
  const double current_time,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
  const Stokhos::EpetraVectorOrthogPoly& sg_x,
  const Teuchos::Array<ParamVec>& p,
  const Teuchos::Array<int>& sg_p_index,
  const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
  Stokhos::EpetraVectorOrthogPoly& sg_g)
{
  for (int i=0; i<sg_x.size(); i++)
    sg_x[i].MeanValue(&sg_g[i][0]);
}
Ejemplo n.º 6
0
/** Copy to an adaptive vector from a set of blocked vectors
  */
void Stokhos::AdaptivityManager::copyToAdaptiveVector(const Stokhos::EpetraVectorOrthogPoly & x_sg,Epetra_Vector & x) const
{
   Teuchos::RCP<const EpetraExt::BlockVector> x_sg_bv = x_sg.getBlockVector();

   // copy from adapted vector to deterministic
   for(std::size_t i=0;i<sg_basis_row_dof_.size();i++) {
      int P_i = getRowStochasticBasisSize(i); 
      int localId = rowMap_->LID(getGlobalRowId(i,0));

      for(int j=0;j<P_i;j++,localId++) {
         int blk = sg_master_basis_->index(sg_basis_row_dof_[i]->term(j));
         x[localId] = x_sg_bv->GetBlock(blk)->operator[](i);
      }
   }
}
void
Albany::SolutionResponseFunction::
evaluateSGResponse(const double curr_time,
		   const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
		   const Stokhos::EpetraVectorOrthogPoly* sg_xdotdot,
		   const Stokhos::EpetraVectorOrthogPoly& sg_x,
		   const Teuchos::Array<ParamVec>& p,
		   const Teuchos::Array<int>& sg_p_index,
		   const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
		   Stokhos::EpetraVectorOrthogPoly& sg_g)
{
  // Note that by doing the culling this way, instead of importing into
  // sg_g directly using a product importer, it doesn't really matter that
  // the product maps between sg_x and sg_g aren't consistent
  for (int i=0; i<sg_g.size(); i++)
    cullSolution(sg_x[i], sg_g[i]);
}
void
Albany::SolutionAverageResponseFunction::
evaluateSGTangent(
  const double alpha, 
  const double beta, 
  const double omega, 
  const double current_time,
  bool sum_derivs,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdotdot,
  const Stokhos::EpetraVectorOrthogPoly& sg_x,
  const Teuchos::Array<ParamVec>& p,
  const Teuchos::Array<int>& sg_p_index,
  const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
  ParamVec* deriv_p,
  const Epetra_MultiVector* Vx,
  const Epetra_MultiVector* Vxdot,
  const Epetra_MultiVector* Vxdotdot,
  const Epetra_MultiVector* Vp,
  Stokhos::EpetraVectorOrthogPoly* sg_g,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_JV,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_gp)
{
  // Evaluate response g
  if (sg_g != NULL)
    for (int i=0; i<sg_x.size(); i++)
      sg_x[i].MeanValue(&(*sg_g)[i][0]);

  // Evaluate tangent of g = dg/dx*Vx + dg/dxdot*Vxdot + dg/dp*Vp
  // If Vx == NULL, Vx is the identity
  if (sg_JV != NULL) {
    sg_JV->init(0.0);
    if (Vx != NULL)
      for (int j=0; j<Vx->NumVectors(); j++)
	(*Vx)(j)->MeanValue(&(*sg_JV)[0][j][0]);
    else
      (*sg_JV)[0].PutScalar(alpha/sg_x[0].GlobalLength());
  }
  if (sg_gp != NULL)
    sg_gp->init(0.0);
}
void
Albany::SamplingBasedScalarResponseFunction::
evaluateSGGradient(
  const double current_time,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdot,
  const Stokhos::EpetraVectorOrthogPoly* sg_xdotdot,
  const Stokhos::EpetraVectorOrthogPoly& sg_x,
  const Teuchos::Array<ParamVec>& p,
  const Teuchos::Array<int>& sg_p_index,
  const Teuchos::Array< Teuchos::Array<SGType> >& sg_p_vals,
  ParamVec* deriv_p,
  Stokhos::EpetraVectorOrthogPoly* sg_g,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dx,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dxdot,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dxdotdot,
  Stokhos::EpetraMultiVectorOrthogPoly* sg_dg_dp)
{
  RCP<const Epetra_BlockMap> x_map = sg_x.coefficientMap();
  RCP<Epetra_Vector> xdot;
  if (sg_xdot != NULL)
    xdot = rcp(new Epetra_Vector(*x_map));
  RCP<Epetra_Vector> xdotdot;
  if (sg_xdotdot != NULL)
    xdotdot = rcp(new Epetra_Vector(*x_map));
  Epetra_Vector x(*x_map);
  Teuchos::Array<ParamVec> pp = p;

  RCP<Epetra_Vector> g;
  if (sg_g != NULL) {
    sg_g->init(0.0);
    g = rcp(new Epetra_Vector(*(sg_g->coefficientMap())));
  }

  RCP<Epetra_MultiVector> dg_dx;
  if (sg_dg_dx != NULL) {
    sg_dg_dx->init(0.0);
    dg_dx = rcp(new Epetra_MultiVector(*(sg_dg_dx->coefficientMap()), 
				       sg_dg_dx->numVectors()));
  }

  RCP<Epetra_MultiVector> dg_dxdot;
  if (sg_dg_dxdot != NULL) {
    sg_dg_dxdot->init(0.0);
    dg_dxdot = rcp(new Epetra_MultiVector(*(sg_dg_dxdot->coefficientMap()), 
					  sg_dg_dxdot->numVectors()));
  }

  RCP<Epetra_MultiVector> dg_dxdotdot;
  if (sg_dg_dxdotdot != NULL) {
    sg_dg_dxdotdot->init(0.0);
    dg_dxdotdot = rcp(new Epetra_MultiVector(*(sg_dg_dxdotdot->coefficientMap()), 
					  sg_dg_dxdotdot->numVectors()));
  }

  RCP<Epetra_MultiVector> dg_dp;
  if (sg_dg_dp != NULL) {
    sg_dg_dp->init(0.0);
    dg_dp = rcp(new Epetra_MultiVector(*(sg_dg_dp->coefficientMap()), 
				       sg_dg_dp->numVectors()));
  }

  // Get quadrature data
  const Teuchos::Array<double>& norms = basis->norm_squared();
  const Teuchos::Array< Teuchos::Array<double> >& points = 
    quad->getQuadPoints();
  const Teuchos::Array<double>& weights = quad->getQuadWeights();
  const Teuchos::Array< Teuchos::Array<double> >& vals = 
    quad->getBasisAtQuadPoints();
  int nqp = points.size();

  // Compute sg_g via quadrature
  for (int qp=0; qp<nqp; qp++) {

    // Evaluate sg_x, sg_xdot at quadrature point
    sg_x.evaluate(vals[qp], x);
    if (sg_xdot != NULL)
      sg_xdot->evaluate(vals[qp], *xdot);
    if (sg_xdotdot != NULL)
      sg_xdotdot->evaluate(vals[qp], *xdotdot);

    // Evaluate parameters at quadrature point
    for (int i=0; i<sg_p_index.size(); i++) {
      int ii = sg_p_index[i];
      for (unsigned int j=0; j<pp[ii].size(); j++) {
	pp[ii][j].baseValue = sg_p_vals[ii][j].evaluate(points[qp], vals[qp]);
	if (deriv_p != NULL) {
	  for (unsigned int k=0; k<deriv_p->size(); k++)
	    if ((*deriv_p)[k].family->getName() == pp[ii][j].family->getName())
	      (*deriv_p)[k].baseValue = pp[ii][j].baseValue;
	}
      }
    }

    // Compute response at quadrature point
    evaluateGradient(current_time, xdot.get(), xdotdot.get(), x, pp, deriv_p,
		     g.get(), dg_dx.get(), dg_dxdot.get(), dg_dxdotdot.get(), dg_dp.get());

    // Add result into integral
    if (sg_g != NULL)
      sg_g->sumIntoAllTerms(weights[qp], vals[qp], norms, *g);
    if (sg_dg_dx != NULL)
      sg_dg_dx->sumIntoAllTerms(weights[qp], vals[qp], norms, *dg_dx);
    if (sg_dg_dxdot != NULL)
      sg_dg_dxdot->sumIntoAllTerms(weights[qp], vals[qp], norms, *dg_dxdot);
    if (sg_dg_dxdotdot != NULL)
      sg_dg_dxdotdot->sumIntoAllTerms(weights[qp], vals[qp], norms, *dg_dxdotdot);
    if (sg_dg_dp != NULL)
      sg_dg_dp->sumIntoAllTerms(weights[qp], vals[qp], norms, *dg_dp);
  }
}