Ejemplo n.º 1
0
// ************************************************************************
// ************************************************************************
Teuchos::RCP<NOX::StatusTest::Generic> NOX::StatusTest::Factory::
buildFiniteValueTest(Teuchos::ParameterList& p, const NOX::Utils& u) const
{
  std::string vector_type_string = p.get("Vector Type","F Vector");
  std::string norm_type_string = p.get("Norm Type", "Two Norm");

  NOX::StatusTest::FiniteValue::VectorType vector_type = 
    NOX::StatusTest::FiniteValue::FVector;
  NOX::Abstract::Vector::NormType norm_type = NOX::Abstract::Vector::TwoNorm;

  if (vector_type_string == "F Vector")
    vector_type = NOX::StatusTest::FiniteValue::FVector;
  else if (vector_type_string == "Solution Vector")
    vector_type = NOX::StatusTest::FiniteValue::SolutionVector;
  else {
    std::string msg = "\"Vector Type\" must be either \"F Vector\" or \"Solution Vector\"!";
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
  }
  
  if (norm_type_string == "Two Norm")
    norm_type = NOX::Abstract::Vector::TwoNorm;
  else if (vector_type_string == "One Norm")
    norm_type = NOX::Abstract::Vector::OneNorm;
  else if (vector_type_string == "Max Norm")
    norm_type = NOX::Abstract::Vector::MaxNorm;
  else {
    std::string msg = "\"Norm Type\" must be either \"Two Norm\", \"One Norm\", or \"Max Norm\"!";
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
  }
  
  RCP<NOX::StatusTest::FiniteValue> status_test = 
    rcp(new NOX::StatusTest::FiniteValue(vector_type, norm_type));

  return status_test;
}
Ejemplo n.º 2
0
Teuchos::Array<bool> parseResponseParameters(Teuchos::ParameterList &params, int responseCount)
{
  const std::string selectionType = params.get("Response Selection", "All");
  const int userIndex = parseResponseIndex(params);
  const Teuchos::Array<int> userList = params.get("Response List", Teuchos::Array<int>());
  return createResponseTable(responseCount, selectionType, userIndex, userList);
}
void
OverlappingPartitioner<GraphType>::
setParameters (Teuchos::ParameterList& List)
{
  NumLocalParts_    = List.get("partitioner: local parts", NumLocalParts_);
  OverlappingLevel_ = List.get("partitioner: overlap", OverlappingLevel_);
  verbose_          = List.get("partitioner: print level", verbose_);

  if (NumLocalParts_ < 0) {
    NumLocalParts_ = Graph_->getNodeNumRows() / (-NumLocalParts_);
  }
  if (NumLocalParts_ == 0) {
    NumLocalParts_ = 1;
  }
  
  // Sanity checking
  TEUCHOS_TEST_FOR_EXCEPTION(
    NumLocalParts_ < 0 || 
    Teuchos::as<size_t> (NumLocalParts_) > Graph_->getNodeNumRows(),
    std::runtime_error, 
    "Ifpack2::OverlappingPartitioner::setParameters: "
    "Invalid NumLocalParts_ = " << NumLocalParts_ << ".");
  TEUCHOS_TEST_FOR_EXCEPTION(
    OverlappingLevel_ < 0, std::runtime_error,
    "Ifpack2::OverlappingPartitioner::setParameters: "
    "Invalid OverlappingLevel_ = " << OverlappingLevel_ << ".");

  setPartitionParameters(List);
}
Ejemplo n.º 4
0
Stokhos::ParallelData::
ParallelData(
  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& basis,
  const Teuchos::RCP<const Stokhos::Sparse3Tensor<int,double> >& Cijk,
  const Teuchos::RCP<const Epetra_Comm>& globalComm,
  Teuchos::ParameterList& params)
{
  int num_global_stoch_blocks = basis->size();

  int num_spatial_procs = params.get("Number of Spatial Processors", -1);

  // Build multi-comm
  globalMultiComm = 
    Stokhos::buildMultiComm(*globalComm, num_global_stoch_blocks,
			    num_spatial_procs);

  // Get stochastic and spatial comm's
  stoch_comm = Stokhos::getStochasticComm(globalMultiComm);
  spatial_comm = Stokhos::getSpatialComm(globalMultiComm);

  if (Cijk != Teuchos::null) {
    // Build Epetra Cijk
    epetraCijk = 
      Teuchos::rcp(new Stokhos::EpetraSparse3Tensor(basis, Cijk, 
						    globalMultiComm));
    
    // Rebalance graphs
    bool use_isorropia = params.get("Rebalance Stochastic Graph", false);
    if (use_isorropia)
    epetraCijk->rebalance(params.sublist("Isorropia"));
    
    // Transform to local indices
    epetraCijk->transformToLocal();
  }
}
Ejemplo n.º 5
0
//==========================================================================
int Ifpack_ICT::SetParameters(Teuchos::ParameterList& List)
{

  try
  {
    LevelOfFill_ = List.get("fact: ict level-of-fill",LevelOfFill_);
    Athresh_ = List.get("fact: absolute threshold", Athresh_);
    Rthresh_ = List.get("fact: relative threshold", Rthresh_);
    Relax_ = List.get("fact: relax value", Relax_);
    DropTolerance_ = List.get("fact: drop tolerance", DropTolerance_);

    // set label
    Label_ = "ICT (fill=" + Ifpack_toString(LevelOfFill())
      + ", athr=" + Ifpack_toString(AbsoluteThreshold()) 
      + ", rthr=" + Ifpack_toString(RelativeThreshold())
      + ", relax=" + Ifpack_toString(RelaxValue())
      + ", droptol=" + Ifpack_toString(DropTolerance())
      + ")";

    return(0);
  }
  catch (...)
  {
    cerr << "Caught an exception while parsing the parameter list" << endl;
    cerr << "This typically means that a parameter was set with the" << endl;
    cerr << "wrong type (for example, int instead of double). " << endl;
    cerr << "please check the documentation for the type required by each parameer." << endl;
    IFPACK_CHK_ERR(-1);
  }
}
Ejemplo n.º 6
0
// ************************************************************************
// ************************************************************************
Teuchos::RCP<NOX::StatusTest::Generic> NOX::StatusTest::Factory::
buildNormFTest(Teuchos::ParameterList& p, const NOX::Utils& u) const
{
  double tolerance = p.get("Tolerance", 1.0e-8);
  
  // Norm Type
  std::string norm_type_string = p.get("Norm Type", "Two Norm");
  NOX::Abstract::Vector::NormType norm_type = NOX::Abstract::Vector::TwoNorm;
  if (norm_type_string == "Two Norm")
    norm_type = NOX::Abstract::Vector::TwoNorm;
  else if (norm_type_string == "One Norm")
    norm_type = NOX::Abstract::Vector::OneNorm;
  else if (norm_type_string == "Max Norm")
    norm_type = NOX::Abstract::Vector::MaxNorm;
  else {
    std::string msg = "\"Norm Type\" must be either \"Two Norm\", \"One Norm\", or \"Max Norm\"!";
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
  }
  
  // Scale Type
  std::string scale_type_string = p.get("Scale Type", "Unscaled");
  NOX::StatusTest::NormF::ScaleType scale_type = 
    NOX::StatusTest::NormF::Unscaled;
  if (scale_type_string == "Unscaled")
    scale_type = NOX::StatusTest::NormF::Unscaled;
  else if (scale_type_string == "Scaled")
    scale_type = NOX::StatusTest::NormF::Scaled;
  else {
    std::string msg = "\"Scale Type\" must be either \"Unscaled\" or \"Scaled\"!";
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, msg);
  }

  // Relative or absoltue tolerance (relative requires f_0)
  bool use_relative_tolerance = false;
  Teuchos::RCP<NOX::Abstract::Group> group;
  if (isParameterType< RCP<NOX::Abstract::Group> >(p, "Initial Guess")) {
    group = get< RCP<NOX::Abstract::Group> >(p, "Initial Guess");
    use_relative_tolerance = true;
  }

  RCP<NOX::StatusTest::NormF> status_test;

  if (use_relative_tolerance)
    status_test = rcp(new NOX::StatusTest::NormF(*group,
						 tolerance,
						 norm_type,
						 scale_type,
						 &u));
  else
    status_test = rcp(new NOX::StatusTest::NormF(tolerance,
						 norm_type,
						 scale_type,
						 &u));
    
  
  return status_test;
}
Ejemplo n.º 7
0
// ======================================================================
void Krylov(const Operator& A, const MultiVector& LHS,
            const MultiVector& RHS, const BaseOperator& Prec,
            Teuchos::ParameterList& List)
{
#ifndef HAVE_ML_AZTECOO
      std::cerr << "Please configure ML with --enable-aztecoo to use" << std::endl;
      std::cerr << "MLAPI Krylov solvers" << std::endl;
      exit(EXIT_FAILURE);
#else
  if (LHS.GetNumVectors() != 1)
    ML_THROW("FIXME: only one vector is currently supported", -1);

  Epetra_LinearProblem Problem;

  const Epetra_RowMatrix& A_Epetra = *(A.GetRowMatrix());

  Epetra_Vector LHS_Epetra(View,A_Epetra.OperatorDomainMap(),
                           (double*)&(LHS(0)));
  Epetra_Vector RHS_Epetra(View,A_Epetra.OperatorRangeMap(),
                           (double*)&(RHS(0)));

  // FIXME: this works only for Epetra-based operators
  Problem.SetOperator((const_cast<Epetra_RowMatrix*>(&A_Epetra)));
  Problem.SetLHS(&LHS_Epetra);
  Problem.SetRHS(&RHS_Epetra);

  AztecOO solver(Problem);

  EpetraBaseOperator Prec_Epetra(A_Epetra.OperatorDomainMap(),Prec);
  solver.SetPrecOperator(&Prec_Epetra);

  // get options from List
  int    NumIters = List.get("krylov: max iterations", 1550);
  double Tol      = List.get("krylov: tolerance", 1e-9);
  std::string type     = List.get("krylov: type", "gmres");
  int    output   = List.get("krylov: output level", GetPrintLevel());

  // set options in `solver'
  if (type == "cg")
    solver.SetAztecOption(AZ_solver, AZ_cg);
  else if (type == "cg_condnum")
    solver.SetAztecOption(AZ_solver, AZ_cg_condnum);
  else if (type == "gmres")
    solver.SetAztecOption(AZ_solver, AZ_gmres);
  else if (type == "gmres_condnum")
    solver.SetAztecOption(AZ_solver, AZ_gmres_condnum);
  else if (type == "fixed point")
    solver.SetAztecOption(AZ_solver, AZ_fixed_pt);
  else
    ML_THROW("krylov: type has incorrect value (" +
             type + ")", -1);

  solver.SetAztecOption(AZ_output, output);
  solver.Iterate(NumIters, Tol);
#endif

}
Stokhos::KL::OneDExponentialCovarianceFunction<value_type>::
OneDExponentialCovarianceFunction(int M, 
				  const value_type& a, 
				  const value_type& b, 
				  const value_type& L_,
				  const std::string& dim_name,
				  Teuchos::ParameterList& solverParams) :
  L(L_),
  eig_pair(M)
{
  // Get parameters with default values
  magnitude_type eps = solverParams.get("Bound Perturbation Size", 1e-6);
  magnitude_type tol = solverParams.get("Nonlinear Solver Tolerance", 1e-10);
  int max_it = solverParams.get("Maximum Nonlinear Solver Iterations", 100);

  value_type aa, alpha, omega, lambda;
  int i=0;
  double pi = 4.0*std::atan(1.0);
  int idx = 0;
  
  aa = (b-a)/2.0;
  while (i < M-1) {
    alpha = aa/L;
    omega = bisection(EigFuncCos(alpha), idx*pi, idx*pi+pi/2.0-eps, 
		      tol, max_it) / aa;
    lambda = 2.0*L/(L*L*omega*omega + 1.0);
    eig_pair[i].eig_val = lambda;
    eig_pair[i].eig_func = Teuchos::rcp(new 
      ExponentialOneDEigenFunction<value_type>(
	ExponentialOneDEigenFunction<value_type>::COS, a, b, omega, dim_name)
      );
    i++;

    omega = bisection(EigFuncSin(alpha), idx*pi+pi/2.0+eps, (idx+1)*pi,
		      tol, max_it) / aa;
    lambda = 2.0*L/(L*L*omega*omega + 1.0);
    eig_pair[i].eig_val = lambda;
    eig_pair[i].eig_func = Teuchos::rcp(new
      ExponentialOneDEigenFunction<value_type>(
	ExponentialOneDEigenFunction<value_type>::SIN, a, b, omega, dim_name)
      );
    i++;

    idx++;
  }
  if (i < M) {
    omega = bisection(EigFuncCos(alpha), idx*pi, idx*pi+pi/2.0-eps, 
		      tol, max_it) / aa;
    lambda = 2.0*L/(L*L*omega*omega + 1.0);
    eig_pair[i].eig_val = lambda;
    eig_pair[i].eig_func = Teuchos::rcp(new
      ExponentialOneDEigenFunction<value_type>(
	ExponentialOneDEigenFunction<value_type>::COS, a, b, omega, dim_name)
      );
  }
}
void ConstitutiveModelParameters<EvalT, Traits>::
parseParameters(const std::string &n,
    Teuchos::ParameterList &p,
    Teuchos::RCP<ParamLib> paramLib)
{
  Teuchos::ParameterList pl =
    p.get<Teuchos::ParameterList*>("Material Parameters")->sublist(n);
  std::string type_name(n + " Type");
  std::string type = pl.get(type_name, "Constant");
  if (type == "Constant") {
    is_constant_map_.insert(std::make_pair(n, true));
    constant_value_map_.insert(std::make_pair(n, pl.get("Value", 1.0)));
    new Sacado::ParameterRegistration<EvalT, SPL_Traits>(n, this, paramLib);
    if (have_temperature_) {
      if (pl.get<std::string>("Temperature Dependence Type", "Linear")
          == "Linear") {
        temp_type_map_.insert(std::make_pair(n,"Linear"));
        dparam_dtemp_map_.insert
        (std::make_pair(n,
          pl.get<RealType>("Linear Temperature Coefficient", 0.0)));
        ref_temp_map_.insert
        (std::make_pair(n, pl.get<RealType>("Reference Temperature", -1)));
      } else if (pl.get<std::string>("Temperature Dependence Type", "Linear")
          == "Arrhenius") {
        temp_type_map_.insert(std::make_pair(n,"Arrhenius"));
        pre_exp_map_.insert(
            std::make_pair(n, pl.get<RealType>("Pre Exponential", 0.0)));
        exp_param_map_.insert(
            std::make_pair(n, pl.get<RealType>("Exponential Parameter", 0.0)));
      }
    }
  } else if (type == "Truncated KL Expansion") {
    is_constant_map_.insert(std::make_pair(n, false));
    PHX::MDField<MeshScalarT, Cell, QuadPoint, Dim>
      fx(p.get<std::string>("QP Coordinate Vector Name"), dl_->qp_vector);
    coord_vec_ = fx;
    this->addDependentField(coord_vec_);

    exp_rf_kl_map_.
        insert(
        std::make_pair(n,
            Teuchos::rcp(
                new Stokhos::KL::ExponentialRandomField<MeshScalarT>(pl))));
    int num_KL = exp_rf_kl_map_[n]->stochasticDimension();

    // Add KL random variables as Sacado-ized parameters
    rv_map_.insert(std::make_pair(n, Teuchos::Array<ScalarT>(num_KL)));
    for (int i(0); i < num_KL; ++i) {
      std::string ss = Albany::strint(n + " KL Random Variable", i);
      new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib);
      rv_map_[n][i] = pl.get(ss, 0.0);
    }
  }
}
Ejemplo n.º 10
0
// ************************************************************************
// ************************************************************************
Teuchos::RCP<NOX::StatusTest::Generic> NOX::StatusTest::Factory::
buildStagnationTest(Teuchos::ParameterList& p, const NOX::Utils& u) const
{
  double tolerance = p.get("Tolerance", 1.0e+12);
  int iterations = p.get("Consecutive Iterations", 1);
  
  RCP<NOX::StatusTest::Stagnation> status_test = 
    rcp(new NOX::StatusTest::Stagnation(iterations, tolerance));
  
  return status_test;
}
//==============================================================================
int Ifpack_PointRelaxation::SetParameters(Teuchos::ParameterList& List)
{
  using std::cout;
  using std::endl;

  std::string PT;
  if (PrecType_ == IFPACK_JACOBI)
    PT = "Jacobi";
  else if (PrecType_ == IFPACK_GS)
    PT = "Gauss-Seidel";
  else if (PrecType_ == IFPACK_SGS)
    PT = "symmetric Gauss-Seidel";

  PT = List.get("relaxation: type", PT);

  if (PT == "Jacobi")
    PrecType_ = IFPACK_JACOBI;
  else if (PT == "Gauss-Seidel")
    PrecType_ = IFPACK_GS;
  else if (PT == "symmetric Gauss-Seidel")
    PrecType_ = IFPACK_SGS;
  else {
    IFPACK_CHK_ERR(-2);
  }

  NumSweeps_            = List.get("relaxation: sweeps",NumSweeps_);
  DampingFactor_        = List.get("relaxation: damping factor",
                                   DampingFactor_);
  MinDiagonalValue_     = List.get("relaxation: min diagonal value",
                                   MinDiagonalValue_);
  ZeroStartingSolution_ = List.get("relaxation: zero starting solution",
                                   ZeroStartingSolution_);

  DoBackwardGS_         = List.get("relaxation: backward mode",DoBackwardGS_);

  DoL1Method_           = List.get("relaxation: use l1",DoL1Method_);

  L1Eta_                = List.get("relaxation: l1 eta",L1Eta_);


  // This (partial) reordering would require a very different implementation of Jacobi than we have no, so we're not
  // going to do it.
  NumLocalSmoothingIndices_= List.get("relaxation: number of local smoothing indices",NumLocalSmoothingIndices_);
  LocalSmoothingIndices_   = List.get("relaxation: local smoothing indices",LocalSmoothingIndices_);
  if(PrecType_ == IFPACK_JACOBI && LocalSmoothingIndices_) {
    NumLocalSmoothingIndices_=NumMyRows_;
    LocalSmoothingIndices_=0;
    if(!Comm().MyPID()) cout<<"Ifpack_PointRelaxation: WARNING: Reordered/Local Smoothing not implemented for Jacobi.  Defaulting to regular Jacobi"<<endl;
  }

  SetLabel();

  return(0);
}
void
LinePartitioner<GraphType,Scalar>::
setPartitionParameters(Teuchos::ParameterList& List) {
  threshold_ = List.get("partitioner: line detection threshold",threshold_);
  TEUCHOS_TEST_FOR_EXCEPTION(threshold_ < Teuchos::ScalarTraits<MT>::zero() || threshold_ > Teuchos::ScalarTraits<MT>::one(),
                             std::runtime_error,"Ifpack2::LinePartitioner: threshold not valid");

  NumEqns_   = List.get("partitioner: PDE equations",NumEqns_);
  TEUCHOS_TEST_FOR_EXCEPTION(NumEqns_<1,std::runtime_error,"Ifpack2::LinePartitioner: NumEqns not valid");

  coord_   = List.get("partitioner: coordinates",coord_);
  TEUCHOS_TEST_FOR_EXCEPTION(coord_.is_null(),std::runtime_error,"Ifpack2::LinePartitioner: coordinates not defined");
}
Ejemplo n.º 13
0
//==========================================================================
int Ifpack2_ILU::SetParameters(Teuchos::ParameterList& List)
{
  RelaxValue_ = List.get("fact: relax value", RelaxValue_);
  Athresh_ = List.get("fact: absolute threshold", Athresh_);
  Rthresh_ = List.get("fact: relative threshold", Rthresh_);
  LevelOfFill_ = List.get("fact: level-of-fill", LevelOfFill_);

  // set label
  sprintf(Label_, "TIFPACK ILU (fill=%d, relax=%f, athr=%f, rthr=%f)",
	  LevelOfFill(), RelaxValue(), AbsoluteThreshold(), 
	  RelativeThreshold());
  return(0);
}
Ejemplo n.º 14
0
//==========================================================================
int Ifpack_IC::SetParameters(Teuchos::ParameterList& List)
{

  // Lfil_ = List.get("fact: level-of-fill",Lfil_); // Confusing parameter since Ifpack_IC can only do ICT not IC(k)
  Lfil_ = List.get("fact: ict level-of-fill", Lfil_); // Lfil_ is now the fill ratio as in ICT (1.0 means same #nonzeros as A)
  Athresh_ = List.get("fact: absolute threshold", Athresh_);
  Rthresh_ = List.get("fact: relative threshold", Rthresh_);
  Droptol_ = List.get("fact: drop tolerance", Droptol_);

  // set label
  sprintf(Label_, "IFPACK IC (fill=%f, drop=%f)",
	  Lfil_, Droptol_);
  return(0);
}
Ejemplo n.º 15
0
// ************************************************************************
// ************************************************************************
Teuchos::RCP<NOX::StatusTest::Generic> NOX::StatusTest::Factory::
buildRelativeNormFTest(Teuchos::ParameterList& p, const NOX::Utils& u) const
{
  double tolerance = p.get("Tolerance", 1.0e-8);
  bool scale_by_length = p.get("Scale Norms by Length", false);

  RCP<NOX::StatusTest::RelativeNormF> status_test;

  status_test = rcp(new NOX::StatusTest::RelativeNormF(tolerance, 
						       scale_by_length,
						       &u));
  
  return status_test;
}
 void KrylovFactory(Teuchos::ParameterList &parlist) {
   EKrylov ekv  = StringToEKrylov(parlist.get("Krylov Method","Conjugate Residuals"));  
   Real absTol  = parlist.get("Absolute Krylov Tolerance", 1.e-4);
   Real relTol  = parlist.get("Relative Krylov Tolerance", 1.e-2);
   int maxit    = parlist.get("Maximum Number of Krylov Iterations", 20);
   bool inexact = parlist.get("Use Inexact Hessian-Times-A-Vector",false);
   switch(ekv) {
     case KRYLOV_CR:
       krylov_ = Teuchos::rcp( new ConjugateResiduals<Real>(absTol,relTol,maxit,inexact) ); break;
     case KRYLOV_CG:
     default:
       krylov_ = Teuchos::rcp( new ConjugateGradients<Real>(absTol,relTol,maxit,inexact) ); break;
   }
 }
 TruncatedExponential(Teuchos::ParameterList &parlist) {
   Teuchos::ParameterList TElist
     = parlist.sublist("SOL").sublist("Distribution").sublist("Truncated Exponential");
   a_ = TElist.get("Lower Bound",0.);
   b_ = TElist.get("Upper Bound",1.);
   Real tmp = a_;
   a_ = std::min(a_,b_);
   b_ = std::max(b_,tmp);
   scale_ = TElist.get("Scale",1.);
   scale_ = (scale_ > 0.) ? scale_ : 1.;
   expa_  = std::exp(-scale_*a_);
   expb_  = std::exp(-scale_*b_);
   diff_  = expa_ - expb_;
   coeff_ = scale_/diff_;
 }
Ejemplo n.º 18
0
Teuchos::Array< Teuchos::RCP<Albany::AbstractResponseFunction> >
Albany::ResponseFactory::
createResponseFunctions(Teuchos::ParameterList& responseList) const
{
  using Teuchos::RCP;
  using Teuchos::rcp;
  using Teuchos::ParameterList;
  using Teuchos::Array;

  // First check for the old response specification
  if (responseList.isType<int>("Number")) {
    int num_aggregate_responses = responseList.get<int>("Number");
    if (num_aggregate_responses > 0) {
      Array<RCP<AbstractResponseFunction> > responses;
      createResponseFunction("Aggregated", responseList, responses);
      return responses;
    }
  }

  int num_response_vecs = responseList.get("Number of Response Vectors", 0);
  Array<RCP<AbstractResponseFunction> > responses;

  for (int i=0; i<num_response_vecs; i++) {
    std::string sublist_name = Albany::strint("Response Vector",i);
    ParameterList& response_params =
      responseList.sublist(sublist_name);
    std::string response_name = response_params.get<std::string>("Name");
    createResponseFunction(response_name, response_params, responses);
  }

  return responses;
}
Ejemplo n.º 19
0
NOX::Epetra::LinearSystemAmesos::
LinearSystemAmesos(
  Teuchos::ParameterList& printingParams, 
  Teuchos::ParameterList& linearSolverParams, 
  const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq, 
  const Teuchos::RCP<NOX::Epetra::Interface::Jacobian>& iJac, 
  const Teuchos::RCP<Epetra_Operator>& J,
  const NOX::Epetra::Vector& cloneVector,
  const Teuchos::RCP<NOX::Epetra::Scaling> s):
  amesosProblem(Teuchos::null),
  amesosSolver(Teuchos::null),
  factory(),
  isValidFactorization(false),
  jacInterfacePtr(iJac),
  jacPtr(J),
  leftHandSide(Teuchos::rcp(new Epetra_Vector(cloneVector.getEpetraVector()))),
  rightHandSide(Teuchos::rcp(new Epetra_Vector(cloneVector.getEpetraVector()))),
  scaling(s),
  timer(cloneVector.getEpetraVector().Comm()),
  utils(printingParams)
{
  amesosProblem = Teuchos::rcp(new Epetra_LinearProblem(
				      dynamic_cast<Epetra_CrsMatrix *>(jacPtr.get()),
				      leftHandSide.get(),
				      rightHandSide.get()));

  Amesos_BaseSolver * tmp = factory.Create(linearSolverParams.get("Amesos Solver","Amesos_Klu"), 
      *amesosProblem);
  TEUCHOS_TEST_FOR_EXCEPTION ( tmp == 0, Teuchos::Exceptions::InvalidParameterValue, 
      "Invalid Amesos Solver: " << linearSolverParams.get<string>("Amesos Solver"));
  amesosSolver = Teuchos::rcp(tmp);

  amesosSolver->SetParameters(linearSolverParams);
}
Ejemplo n.º 20
0
inline bool Monotone::check_for_existance(Teuchos::ParameterList &source_list)
{ 
  std::string g("Monotone");
  bool exists = source_list.getEntryPtr("Type");
  if (exists) exists = g==source_list.get("Type",g);
  return exists;
}
NOX::Abstract::Group::ReturnType 
LOCA::SingularJacobianSolve::Manager::reset(Teuchos::ParameterList& params) 
{
  std::string newmethod = params.get("Method", "Default");

  if (method != newmethod) {
    delete singularSolverPtr;

    method = newmethod;

    if (method == "Default")
      singularSolverPtr = new LOCA::SingularJacobianSolve::Default(params);
    else if (method == "Nic")
      singularSolverPtr = new LOCA::SingularJacobianSolve::Nic(params);
    else if (method == "Nic-Day")
      singularSolverPtr = new LOCA::SingularJacobianSolve::NicDay(params);
    else if (method == "Iterative Refinement")
      singularSolverPtr = new LOCA::SingularJacobianSolve::ItRef(params);
    else {
      LOCA::ErrorCheck::throwError(
			      "LOCA::SingularJacobianSolve::Manager::reset()",
			      "Invalid choice for singular solve method.");
      return NOX::Abstract::Group::Failed;
    }
  }

  return NOX::Abstract::Group::Ok;
}
Ejemplo n.º 22
0
void
Permittivity<EvalT, Traits>::
init_KL_RF(std::string &type, Teuchos::ParameterList& sublist, Teuchos::ParameterList& p){

    is_constant = false;

    if (type == "Truncated KL Expansion")
      randField = UNIFORM;
    else if (type == "Log Normal RF")
      randField = LOGNORMAL;

    Teuchos::RCP<PHX::DataLayout> scalar_dl =
      p.get< Teuchos::RCP<PHX::DataLayout> >("QP Scalar Data Layout");
    Teuchos::RCP<PHX::DataLayout> vector_dl =
      p.get< Teuchos::RCP<PHX::DataLayout> >("QP Vector Data Layout");
    PHX::MDField<MeshScalarT,Cell,QuadPoint,Dim>
      fx(p.get<std::string>("QP Coordinate Vector Name"), vector_dl);
    coordVec = fx;
    this->addDependentField(coordVec);

    exp_rf_kl =
      Teuchos::rcp(new Stokhos::KL::ExponentialRandomField<MeshScalarT>(sublist));
    int num_KL = exp_rf_kl->stochasticDimension();

    // Add KL random variables as Sacado-ized parameters
    rv.resize(num_KL);
    Teuchos::RCP<ParamLib> paramLib =
      p.get< Teuchos::RCP<ParamLib> >("Parameter Library", Teuchos::null);
    for (int i=0; i<num_KL; i++) {
      std::string ss = Albany::strint("Permittivity KL Random Variable",i);
      new Sacado::ParameterRegistration<EvalT, SPL_Traits>(ss, this, paramLib);
      rv[i] = sublist.get(ss, 0.0);
    }

} // (type == "Truncated KL Expansion" || type == "Log Normal RF")
Ejemplo n.º 23
0
//==============================================================================
int Ifpack2_Amesos::SetParameters(Teuchos::ParameterList& List_in)
{

  List_ = List_in;
  Label_ = List_in.get("amesos: solver type", Label_);
  return(0);
}
Ejemplo n.º 24
0
NOX::Epetra::LinearSystemMPBD::
LinearSystemMPBD(
  Teuchos::ParameterList& printingParams, 
  Teuchos::ParameterList& linearSolverParams, 
  const Teuchos::RCP<NOX::Epetra::LinearSystem>& block_solver_,
  const Teuchos::RCP<NOX::Epetra::Interface::Required>& iReq, 
  const Teuchos::RCP<NOX::Epetra::Interface::Jacobian>& iJac,
  const Teuchos::RCP<Epetra_Operator>& J,
  const Teuchos::RCP<const Epetra_Map>& base_map_,
  const Teuchos::RCP<NOX::Epetra::Scaling> s):
  block_solver(block_solver_),
  jacInterfacePtr(iJac),
  base_map(base_map_),
  scaling(s),
  utils(printingParams)
{
  mp_op = Teuchos::rcp_dynamic_cast<Stokhos::BlockDiagonalOperator>(J, true);
  block_ops = mp_op->getMPOps();
  num_mp_blocks = block_ops->size();

  std::string prec_strategy = linearSolverParams.get("Preconditioner Strategy",
						     "Standard");
  if (prec_strategy == "Standard")
    precStrategy = STANDARD;
  else if (prec_strategy == "Mean")
    precStrategy = MEAN;
  else if (prec_strategy == "On the fly")
    precStrategy = ON_THE_FLY;
  else
    TEUCHOS_TEST_FOR_EXCEPTION(true, std::logic_error, 
		       "Invalid preconditioner strategy " << prec_strategy);

  if (precStrategy == STANDARD)
    precs.resize(num_mp_blocks);
}
Ejemplo n.º 25
0
inline bool Gaussian<EvalT>::check_for_existance(Teuchos::ParameterList &source_list)
{
  std::string g("Gaussian");
  bool exists = source_list.getEntryPtr("Type");
  if (exists) exists = g==source_list.get("Type",g);
  return exists;
}
Ejemplo n.º 26
0
Stokhos::ParallelData::
ParallelData(
  const Teuchos::RCP<const Stokhos::OrthogPolyBasis<int,double> >& basis,
  const Teuchos::RCP<const Stokhos::Sparse3Tensor<int,double> >& Cijk,
  const Teuchos::RCP<const EpetraExt::MultiComm>& globalMultiComm_,
  Teuchos::ParameterList& params) :
  globalMultiComm(globalMultiComm_)
{
  // Get stochastic and spatial comm's
  stoch_comm = Stokhos::getStochasticComm(globalMultiComm);
  spatial_comm = Stokhos::getSpatialComm(globalMultiComm);

  if (Cijk != Teuchos::null) {
    // Build Epetra Cijk
    epetraCijk = 
      Teuchos::rcp(new Stokhos::EpetraSparse3Tensor(basis, Cijk, 
						    globalMultiComm));

    // Rebalance graphs
    bool use_isorropia = params.get("Rebalance Stochastic Graph", false);
    if (use_isorropia)
      epetraCijk->rebalance(params.sublist("Isorropia"));
    
    // Transform to local indices
    epetraCijk->transformToLocal();
  }
}
Ejemplo n.º 27
0
// protected
NOX::Abstract::Group::ReturnType NOX::Thyra::Group::
applyJacobianInverseMultiVector(Teuchos::ParameterList& p, 
				const ::Thyra::MultiVectorBase<double>& input, 
				::Thyra::MultiVectorBase<double>& result) const
{
  this->updateLOWS();

  // Create solve criteria
  ::Thyra::SolveCriteria<double> solveCriteria;
  solveCriteria.requestedTol = p.get("Tolerance", 1.0e-6);

  std::string numer_measure = p.get("Solve Measure Numerator",
				    "Norm Residual");
  std::string denom_measure = p.get("Solve Measure Denominator",
				    "Norm Initial Residual");
  solveCriteria.solveMeasureType = 
    ::Thyra::SolveMeasureType(getThyraNormType(numer_measure),
			      getThyraNormType(denom_measure));

  // Initialize result to zero to remove possible NaNs
  ::Thyra::assign(Teuchos::ptrFromRef(result), 0.0);

  this->scaleResidualAndJacobian();

  ::Thyra::SolveStatus<double> solve_status;
  {
    NOX_FUNC_TIME_MONITOR("NOX Total Linear Solve");

    solve_status = ::Thyra::solve(*shared_jacobian_->getObject(), 
				  ::Thyra::NOTRANS, input, 
				  Teuchos::ptrFromRef(result), 
				  Teuchos::constPtr(solveCriteria));
  }

  this->unscaleResidualAndJacobian();

  // ToDo: Get the output statistics and achieved tolerance to pass
  // back ...
  
  if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_CONVERGED)
    return NOX::Abstract::Group::Ok;
  else if (solve_status.solveStatus == ::Thyra::SOLVE_STATUS_UNCONVERGED)
    return NOX::Abstract::Group::NotConverged;
  
  return NOX::Abstract::Group::Failed;
}
Ejemplo n.º 28
0
  //! Sets all the parameters for the partitioner (none for linear partioning).
  int SetPartitionParameters(Teuchos::ParameterList& List)
  {
    Map_ = List.get("partitioner: map",Map_);
    if (Map_ == 0)
      IFPACK2_CHK_ERR(-1);

    return(0);
  }
Ejemplo n.º 29
0
// ====================================================================== 
// FIXME: Add List
void Eigs(const Operator& A, int NumEigenvalues, 
          MultiVector& ER, MultiVector& EI)
{

  if (A.GetDomainSpace() != A.GetRangeSpace())
    ML_THROW("Input Operator is not square", -1);

  double time;

  time = GetClock();

  int length = NumEigenvalues;
  double tol = 1e-3;
  int restarts = 1;
  int output = 10;
  bool PrintStatus = true;

  // 1.- set parameters for Anasazi
  Teuchos::ParameterList AnasaziList;
  // MatVec should be either "A" or "ML^{-1}A"
  AnasaziList.set("eigen-analysis: matrix operation", "A");
  AnasaziList.set("eigen-analysis: use diagonal scaling", false);
  AnasaziList.set("eigen-analysis: symmetric problem", false);
  AnasaziList.set("eigen-analysis: length", length);
  AnasaziList.set("eigen-analysis: block-size",1);
  AnasaziList.set("eigen-analysis: tolerance", tol);
  AnasaziList.set("eigen-analysis: restart", restarts);
  AnasaziList.set("eigen-analysis: output", output);
  AnasaziList.get("eigen-analysis: print current status",PrintStatus);

  // data to hold real and imag for eigenvalues and eigenvectors
  Space ESpace(-1, NumEigenvalues);
  ER.Reshape(ESpace);
  EI.Reshape(ESpace);

  // this is the starting value -- random
  Epetra_MultiVector EigenVectors(A.GetRowMatrix()->OperatorDomainMap(),
                                  NumEigenvalues);
  EigenVectors.Random();
#ifdef HAVE_ML_ANASAxI
  //int NumRealEigenvectors, NumImagEigenvectors;
#endif

  AnasaziList.set("eigen-analysis: action", "LM");

#ifdef HAVE_ML_ANASAxI
  ML_THROW("fixme...", -1);
  /* FIXME
  ML_Anasazi::Interface(A.GetRowMatrix(),EigenVectors,ER.GetValues(),
			EI.GetValues(), AnasaziList, 0, 0,
			&NumRealEigenvectors, &NumImagEigenvectors, 0);
                        */
#else
  ML_THROW("Anasazi is no longer supported", -1);
#endif

  return;
}
Ejemplo n.º 30
0
  // Constructor
  LineSearch( Teuchos::ParameterList &parlist ) : eps_(0.0) {
    // Enumerations
    edesc_ = StringToEDescent(parlist.get("Descent Type","Quasi-Newton Method"));
    econd_ = StringToECurvatureCondition( parlist.get("Linesearch Curvature Condition","Strong Wolfe Conditions"));
    // Linesearc Parameters
    maxit_     = parlist.get("Maximum Number of Function Evaluations",            20);
    c1_        = parlist.get("Sufficient Decrease Parameter",                     1.e-4);
    c2_        = parlist.get("Curvature Conditions Parameter",                    0.9);
    c3_        = parlist.get("Curvature Conditions Parameter: Generalized Wolfe", 0.6);
    alpha0_    = parlist.get("Initial Linesearch Parameter",1.0);
    useralpha_ = parlist.get("User Defined Linesearch Parameter",false);

    if ( c1_ < 0.0 ) {
      c1_ = 1.e-4;
    }
    if ( c2_ < 0.0 ) {
      c2_ = 0.9;
    }
    if ( c3_ < 0.0 ) {
      c3_ = 0.9;
    }
    if ( c2_ <= c1_ ) {
      c1_ = 1.e-4;
      c2_ = 0.9;
    }
    if ( edesc_ == DESCENT_NONLINEARCG ) {
      c2_ = 0.4;
      c3_ = std::min(1.0-c2_,c3_);
    }
  }