//! From ParameterListAcceptor void CubeTetMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList) { paramList->validateParametersAndSetDefaults(*getValidParameters(),0); setMyParamList(paramList); x0_ = paramList->get<double>("X0"); y0_ = paramList->get<double>("Y0"); z0_ = paramList->get<double>("Z0"); xf_ = paramList->get<double>("Xf"); yf_ = paramList->get<double>("Yf"); zf_ = paramList->get<double>("Zf"); xBlocks_ = paramList->get<int>("X Blocks"); yBlocks_ = paramList->get<int>("Y Blocks"); zBlocks_ = paramList->get<int>("Z Blocks"); xProcs_ = paramList->get<int>("X Procs"); yProcs_ = paramList->get<int>("Y Procs"); zProcs_ = paramList->get<int>("Z Procs"); nXElems_ = paramList->get<int>("X Elements"); nYElems_ = paramList->get<int>("Y Elements"); nZElems_ = paramList->get<int>("Z Elements"); // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); }
bool NOX::LineSearch::SafeguardedStep:: reset(const Teuchos::RCP<NOX::GlobalData>& gd, Teuchos::ParameterList& params) { globalDataPtr_ = gd; print_.reset(gd->getUtils()); paramsPtr_ = ¶ms; Teuchos::ParameterList& p = params.sublist("Safeguarded Step"); p.validateParametersAndSetDefaults(*getValidParameters()); userLimits_ = p.get<Teuchos::RCP<NOX::Abstract::Vector> >("Update Limit Vector"); lowerStepBound_ = p.get<double>("Step Size Lower Bound"); upperStepBound_ = p.get<double>("Step Size Upper Bound"); useCounter_ = p.get<bool>("Use Counters"); TEUCHOS_TEST_FOR_EXCEPTION(is_null(userLimits_), std::runtime_error, "Error: The line search NOX::LineSearch::SafeguardedStep requires the user to supply the \"Update Limit Vector\" parameter of type NOX::Abstract::Vector for in the parameter list."); if (is_null(invLimits_)) invLimits_ = userLimits_->clone(NOX::ShapeCopy); if (is_null(scaledUpdate_)) scaledUpdate_ = userLimits_->clone(NOX::ShapeCopy); // Set up counter if (useCounter_) counter_.reset(); return true; }
//! From ParameterListAcceptor void SculptMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList) { paramList->validateParametersAndSetDefaults(*getValidParameters(),0); setMyParamList(paramList); xInterval_ = paramList->get<int>("xInterval"); yInterval_ = paramList->get<int>("yInterval"); zInterval_ = paramList->get<int>("zInterval"); xMin_ = paramList->get<double>("xMin"); yMin_ = paramList->get<double>("yMin"); zMin_ = paramList->get<double>("zMin"); xMax_ = paramList->get<double>("xMax"); yMax_ = paramList->get<double>("yMax"); zMax_ = paramList->get<double>("zMax"); stlFileDir_ = paramList->get<std::string>("stlFileDir"); stlFileName_ = paramList->get<std::string>("stlFileName"); // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); }
//! From ParameterListAcceptor void CustomMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> ¶mList) { paramList->validateParametersAndSetDefaults(*getValidParameters(),0); setMyParamList(paramList); Dimension_ = paramList->get<int>("Dimension"); NumBlocks_ = paramList->get<int>("NumBlocks"); NumNodesPerProc_ = paramList->get<int>("NumNodesPerProc"); Nodes_ = paramList->get<int*>("Nodes"); Coords_ = paramList->get<double*>("Coords"); NumElementsPerProc_ = paramList->get<int>("NumElementsPerProc"); BlockIDs_ = paramList->get<int*>("BlockIDs"); Element2Nodes_ = paramList->get<int*>("Element2Nodes"); OffsetToGlobalElementIDs_ = paramList->get<int>("OffsetToGlobalElementIDs"); // solution fields from tramonto ChargeDensity_ = paramList->get<double*>("ChargeDensity"); ElectricPotential_ = paramList->get<double*>("ElectricPotential"); // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); }
void CubeTetMeshFactory::initializeWithDefaults() { // get valid parameters RCP<Teuchos::ParameterList> validParams = rcp(new Teuchos::ParameterList(*getValidParameters())); // set that parameter list setParameterList(validParams); }
//! From ParameterListAcceptor void LineMeshFactory::setParameterList(const Teuchos::RCP<Teuchos::ParameterList> & paramList) { paramList->validateParametersAndSetDefaults(*getValidParameters(),0); setMyParamList(paramList); x0_ = paramList->get<double>("X0"); xf_ = paramList->get<double>("Xf"); xBlocks_ = paramList->get<int>("X Blocks"); nXElems_ = paramList->get<int>("X Elements"); // read in periodic boundary conditions parsePeriodicBCList(Teuchos::rcpFromRef(paramList->sublist("Periodic BCs")),periodicBCVec_); }
void Ifpack2PreconditionerFactory<MatrixType>::initializePrec( const Teuchos::RCP<const LinearOpSourceBase<scalar_type> > &fwdOpSrc, PreconditionerBase<scalar_type> *prec, const ESupportSolveUse /* supportSolveUse */ ) const { // Check precondition TEUCHOS_ASSERT(Teuchos::nonnull(fwdOpSrc)); TEUCHOS_ASSERT(this->isCompatible(*fwdOpSrc)); TEUCHOS_ASSERT(prec); Teuchos::Time totalTimer(""), timer(""); totalTimer.start(true); const Teuchos::RCP<Teuchos::FancyOStream> out = this->getOStream(); const Teuchos::EVerbosityLevel verbLevel = this->getVerbLevel(); Teuchos::OSTab tab(out); if (Teuchos::nonnull(out) && Teuchos::includesVerbLevel(verbLevel, Teuchos::VERB_MEDIUM)) { *out << "\nEntering Thyra::Ifpack2PreconditionerFactory::initializePrec(...) ...\n"; } // Retrieve wrapped concrete Tpetra matrix from FwdOp const Teuchos::RCP<const LinearOpBase<scalar_type> > fwdOp = fwdOpSrc->getOp(); TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(fwdOp)); typedef typename MatrixType::local_ordinal_type local_ordinal_type; typedef typename MatrixType::global_ordinal_type global_ordinal_type; typedef typename MatrixType::node_type node_type; typedef Thyra::TpetraLinearOp<scalar_type, local_ordinal_type, global_ordinal_type, node_type> ThyraTpetraLinOp; const Teuchos::RCP<const ThyraTpetraLinOp> thyraTpetraFwdOp = Teuchos::rcp_dynamic_cast<const ThyraTpetraLinOp>(fwdOp); TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(thyraTpetraFwdOp)); typedef Tpetra::Operator<scalar_type, local_ordinal_type, global_ordinal_type, node_type> TpetraLinOp; const Teuchos::RCP<const TpetraLinOp> tpetraFwdOp = thyraTpetraFwdOp->getConstTpetraOperator(); TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpetraFwdOp)); const Teuchos::RCP<const MatrixType> tpetraFwdMatrix = Teuchos::rcp_dynamic_cast<const MatrixType>(tpetraFwdOp); TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(tpetraFwdMatrix)); // Retrieve concrete preconditioner object const Teuchos::Ptr<DefaultPreconditioner<scalar_type> > defaultPrec = Teuchos::ptr(dynamic_cast<DefaultPreconditioner<scalar_type> *>(prec)); TEUCHOS_TEST_FOR_EXCEPT(Teuchos::is_null(defaultPrec)); // Process parameter list Teuchos::RCP<const Teuchos::ParameterList> constParamList = paramList_; if (constParamList.is_null ()) { constParamList = getValidParameters (); } const std::string preconditionerType = Teuchos::getParameter<std::string>(*constParamList, "Prec Type"); const Teuchos::RCP<const Teuchos::ParameterList> packageParamList = Teuchos::sublist(constParamList, "Ifpack2 Settings"); // precTypeUpper is the upper-case version of preconditionerType. std::string precTypeUpper (preconditionerType); if (precTypeUpper.size () > 0) { std::locale locale; for (size_t k = 0; k < precTypeUpper.size (); ++k) { precTypeUpper[k] = std::toupper<char> (precTypeUpper[k], locale); } } // mfh 09 Nov 2013: If the Ifpack2 list doesn't already have the // "schwarz: overlap level" parameter, then override it with the // value of "Overlap". This avoids use of the newly deprecated // three-argument version of Ifpack2::Factory::create() that takes // the overlap as an integer. if (constParamList->isType<int> ("Overlap") && ! packageParamList.is_null () && ! packageParamList->isType<int> ("schwarz: overlap level") && precTypeUpper == "SCHWARZ") { const int overlap = constParamList->get<int> ("Overlap"); Teuchos::RCP<Teuchos::ParameterList> nonconstPackageParamList = Teuchos::sublist (paramList_, "Ifpack2 Settings"); nonconstPackageParamList->set ("schwarz: overlap level", overlap); } // Create the initial preconditioner if (Teuchos::nonnull(out) && Teuchos::includesVerbLevel(verbLevel, Teuchos::VERB_LOW)) { *out << "\nCreating a new Ifpack2::Preconditioner object...\n"; } timer.start(true); typedef Ifpack2::Preconditioner<scalar_type, local_ordinal_type, global_ordinal_type, node_type> Ifpack2Prec; typedef Tpetra::RowMatrix<scalar_type, local_ordinal_type, global_ordinal_type, node_type> row_matrix_type; const Teuchos::RCP<Ifpack2Prec> concretePrecOp = Ifpack2::Factory::create<row_matrix_type> (preconditionerType, tpetraFwdMatrix); timer.stop(); if (Teuchos::nonnull(out) && Teuchos::includesVerbLevel(verbLevel, Teuchos::VERB_LOW)) { Teuchos::OSTab(out).o() << "> Creation time = " << timer.totalElapsedTime() << " sec\n"; } // Initialize and compute the initial preconditioner concretePrecOp->setParameters(*packageParamList); concretePrecOp->initialize(); concretePrecOp->compute(); // Wrap concrete preconditioner const Teuchos::RCP<LinearOpBase<scalar_type> > thyraPrecOp = Thyra::createLinearOp(Teuchos::RCP<TpetraLinOp>(concretePrecOp)); defaultPrec->initializeUnspecified(thyraPrecOp); totalTimer.stop(); if (Teuchos::nonnull(out) && Teuchos::includesVerbLevel(verbLevel, Teuchos::VERB_LOW)) { *out << "\nTotal time in Thyra::Ifpack2PreconditionerFactory::initializePrec(...) = " << totalTimer.totalElapsedTime() << " sec\n"; } if (Teuchos::nonnull(out) && Teuchos::includesVerbLevel(verbLevel, Teuchos::VERB_MEDIUM)) { *out << "\nLeaving Thyra::Ifpack2PreconditionerFactory::initializePrec(...) ...\n"; } }
ReturnType TFQMRSolMgr<ScalarType,MV,OP>::solve() { // Set the current parameters if they were not set before. // NOTE: This may occur if the user generated the solver manager with the default constructor and // then didn't set any parameters using setParameters(). if (!isSet_) { setParameters(Teuchos::parameterList(*getValidParameters())); } Teuchos::BLAS<int,ScalarType> blas; Teuchos::LAPACK<int,ScalarType> lapack; TEST_FOR_EXCEPTION(problem_ == Teuchos::null,TFQMRSolMgrLinearProblemFailure, "Belos::TFQMRSolMgr::solve(): Linear problem is not a valid object."); TEST_FOR_EXCEPTION(!problem_->isProblemSet(),TFQMRSolMgrLinearProblemFailure, "Belos::TFQMRSolMgr::solve(): Linear problem is not ready, setProblem() has not been called."); if (!isSTSet_) { TEST_FOR_EXCEPTION( checkStatusTest(),TFQMRSolMgrLinearProblemFailure, "Belos::TFQMRSolMgr::solve(): Linear problem and requested status tests are incompatible."); } // Create indices for the linear systems to be solved. int startPtr = 0; int numRHS2Solve = MVT::GetNumberVecs( *(problem_->getRHS()) ); int numCurrRHS = blockSize_; std::vector<int> currIdx, currIdx2; // The index set is generated that informs the linear problem that some linear systems are augmented. currIdx.resize( blockSize_ ); currIdx2.resize( blockSize_ ); for (int i=0; i<numCurrRHS; ++i) { currIdx[i] = startPtr+i; currIdx2[i]=i; } // Inform the linear problem of the current linear system to solve. problem_->setLSIndex( currIdx ); ////////////////////////////////////////////////////////////////////////////////////// // Parameter list Teuchos::ParameterList plist; plist.set("Block Size",blockSize_); // Reset the status test. outputTest_->reset(); // Assume convergence is achieved, then let any failed convergence set this to false. bool isConverged = true; ////////////////////////////////////////////////////////////////////////////////////// // TFQMR solver Teuchos::RCP<TFQMRIter<ScalarType,MV,OP> > tfqmr_iter = Teuchos::rcp( new TFQMRIter<ScalarType,MV,OP>(problem_,printer_,outputTest_,plist) ); // Enter solve() iterations { Teuchos::TimeMonitor slvtimer(*timerSolve_); while ( numRHS2Solve > 0 ) { // // Reset the active / converged vectors from this block std::vector<int> convRHSIdx; std::vector<int> currRHSIdx( currIdx ); currRHSIdx.resize(numCurrRHS); // Reset the number of iterations. tfqmr_iter->resetNumIters(); // Reset the number of calls that the status test output knows about. outputTest_->resetNumCalls(); // Get the current residual for this block of linear systems. Teuchos::RCP<MV> R_0 = MVT::CloneViewNonConst( *(Teuchos::rcp_const_cast<MV>(problem_->getInitPrecResVec())), currIdx ); // Set the new state and initialize the solver. TFQMRIterState<ScalarType,MV> newstate; newstate.R = R_0; tfqmr_iter->initializeTFQMR(newstate); while(1) { // tell tfqmr_iter to iterate try { tfqmr_iter->iterate(); //////////////////////////////////////////////////////////////////////////////////// // // check convergence first // //////////////////////////////////////////////////////////////////////////////////// if ( convTest_->getStatus() == Passed ) { // We have convergence of the linear system. break; // break from while(1){tfqmr_iter->iterate()} } //////////////////////////////////////////////////////////////////////////////////// // // check for maximum iterations // //////////////////////////////////////////////////////////////////////////////////// else if ( maxIterTest_->getStatus() == Passed ) { // we don't have convergence isConverged = false; break; // break from while(1){tfqmr_iter->iterate()} } //////////////////////////////////////////////////////////////////////////////////// // // we returned from iterate(), but none of our status tests Passed. // something is wrong, and it is probably our fault. // //////////////////////////////////////////////////////////////////////////////////// else { TEST_FOR_EXCEPTION(true,std::logic_error, "Belos::TFQMRSolMgr::solve(): Invalid return from TFQMRIter::iterate()."); } } catch (const std::exception &e) { printer_->stream(Errors) << "Error! Caught std::exception in TFQMRIter::iterate() at iteration " << tfqmr_iter->getNumIters() << std::endl << e.what() << std::endl; throw; } } // Inform the linear problem that we are finished with this block linear system. problem_->setCurrLS(); // Update indices for the linear systems to be solved. startPtr += numCurrRHS; numRHS2Solve -= numCurrRHS; if ( numRHS2Solve > 0 ) { numCurrRHS = blockSize_; currIdx.resize( blockSize_ ); currIdx2.resize( blockSize_ ); for (int i=0; i<numCurrRHS; ++i) { currIdx[i] = startPtr+i; currIdx2[i] = i; } // Set the next indices. problem_->setLSIndex( currIdx ); // Set the new blocksize for the solver. tfqmr_iter->setBlockSize( blockSize_ ); } else { currIdx.resize( numRHS2Solve ); } }// while ( numRHS2Solve > 0 ) } // print final summary sTest_->print( printer_->stream(FinalSummary) ); // print timing information Teuchos::TimeMonitor::summarize( printer_->stream(TimingDetails) ); // get iteration information for this solve numIters_ = maxIterTest_->getNumIters(); if (!isConverged) { return Unconverged; // return from TFQMRSolMgr::solve() } return Converged; // return from TFQMRSolMgr::solve() }
void TFQMRSolMgr<ScalarType,MV,OP>::setParameters( const Teuchos::RCP<Teuchos::ParameterList> ¶ms ) { // Create the internal parameter list if ones doesn't already exist. if (params_ == Teuchos::null) { params_ = Teuchos::rcp( new Teuchos::ParameterList(*getValidParameters()) ); } else { params->validateParameters(*getValidParameters()); } // Check for maximum number of iterations if (params->isParameter("Maximum Iterations")) { maxIters_ = params->get("Maximum Iterations",maxIters_default_); // Update parameter in our list and in status test. params_->set("Maximum Iterations", maxIters_); if (maxIterTest_!=Teuchos::null) maxIterTest_->setMaxIters( maxIters_ ); } // Check for blocksize if (params->isParameter("Block Size")) { blockSize_ = params->get("Block Size",1); TEST_FOR_EXCEPTION(blockSize_ != 1, std::invalid_argument, "Belos::TFQMRSolMgr: \"Block Size\" must be 1."); // Update parameter in our list. params_->set("Block Size", blockSize_); } // Check to see if the timer label changed. if (params->isParameter("Timer Label")) { std::string tempLabel = params->get("Timer Label", label_default_); // Update parameter in our list and solver timer if (tempLabel != label_) { label_ = tempLabel; params_->set("Timer Label", label_); std::string solveLabel = label_ + ": TFQMRSolMgr total solve time"; timerSolve_ = Teuchos::TimeMonitor::getNewTimer(solveLabel); } } // Check for a change in verbosity level if (params->isParameter("Verbosity")) { if (Teuchos::isParameterType<int>(*params,"Verbosity")) { verbosity_ = params->get("Verbosity", verbosity_default_); } else { verbosity_ = (int)Teuchos::getParameter<Belos::MsgType>(*params,"Verbosity"); } // Update parameter in our list. params_->set("Verbosity", verbosity_); if (printer_ != Teuchos::null) printer_->setVerbosity(verbosity_); } // Check for a change in output style if (params->isParameter("Output Style")) { if (Teuchos::isParameterType<int>(*params,"Output Style")) { outputStyle_ = params->get("Output Style", outputStyle_default_); } else { outputStyle_ = (int)Teuchos::getParameter<Belos::OutputType>(*params,"Output Style"); } // Reconstruct the convergence test if the explicit residual test is not being used. params_->set("Output Style", outputStyle_); isSTSet_ = false; } // output stream if (params->isParameter("Output Stream")) { outputStream_ = Teuchos::getParameter<Teuchos::RCP<std::ostream> >(*params,"Output Stream"); // Update parameter in our list. params_->set("Output Stream", outputStream_); if (printer_ != Teuchos::null) printer_->setOStream( outputStream_ ); } // frequency level if (verbosity_ & Belos::StatusTestDetails) { if (params->isParameter("Output Frequency")) { outputFreq_ = params->get("Output Frequency", outputFreq_default_); } // Update parameter in out list and output status test. params_->set("Output Frequency", outputFreq_); if (outputTest_ != Teuchos::null) outputTest_->setOutputFrequency( outputFreq_ ); } // Create output manager if we need to. if (printer_ == Teuchos::null) { printer_ = Teuchos::rcp( new OutputManager<ScalarType>(verbosity_, outputStream_) ); } // Check for convergence tolerance if (params->isParameter("Convergence Tolerance")) { convtol_ = params->get("Convergence Tolerance",convtol_default_); // Update parameter in our list and residual tests. params_->set("Convergence Tolerance", convtol_); if (impConvTest_ != Teuchos::null) impConvTest_->setTolerance( convtol_ ); if (expConvTest_ != Teuchos::null) expConvTest_->setTolerance( convtol_ ); } // Check for a change in scaling, if so we need to build new residual tests. if (params->isParameter("Implicit Residual Scaling")) { std::string tempImpResScale = Teuchos::getParameter<std::string>( *params, "Implicit Residual Scaling" ); // Only update the scaling if it's different. if (impResScale_ != tempImpResScale) { Belos::ScaleType impResScaleType = convertStringToScaleType( tempImpResScale ); impResScale_ = tempImpResScale; // Update parameter in our list and residual tests params_->set("Implicit Residual Scaling", impResScale_); if (impConvTest_ != Teuchos::null) { try { impConvTest_->defineScaleForm( impResScaleType, Belos::TwoNorm ); } catch (std::exception& e) { // Make sure the convergence test gets constructed again. isSTSet_ = false; } } } } if (params->isParameter("Explicit Residual Scaling")) { std::string tempExpResScale = Teuchos::getParameter<std::string>( *params, "Explicit Residual Scaling" ); // Only update the scaling if it's different. if (expResScale_ != tempExpResScale) { Belos::ScaleType expResScaleType = convertStringToScaleType( tempExpResScale ); expResScale_ = tempExpResScale; // Update parameter in our list and residual tests params_->set("Explicit Residual Scaling", expResScale_); if (expConvTest_ != Teuchos::null) { try { expConvTest_->defineScaleForm( expResScaleType, Belos::TwoNorm ); } catch (std::exception& e) { // Make sure the convergence test gets constructed again. isSTSet_ = false; } } } } if (params->isParameter("Explicit Residual Test")) { expResTest_ = Teuchos::getParameter<bool>( *params,"Explicit Residual Test" ); // Reconstruct the convergence test if the explicit residual test is not being used. params_->set("Explicit Residual Test", expResTest_); if (expConvTest_ == Teuchos::null) { isSTSet_ = false; } } // Create the timer if we need to. if (timerSolve_ == Teuchos::null) { std::string solveLabel = label_ + ": TFQMRSolMgr total solve time"; timerSolve_ = Teuchos::TimeMonitor::getNewTimer(solveLabel); } // Inform the solver manager that the current parameters were set. isSet_ = true; }