// ================================================ ====== ==== ==== == = int ML_Epetra::RefMaxwellPreconditioner::SetEdgeSmoother(Teuchos::ParameterList &List){ std::string smoother=List.get("smoother: type","Chebyshev"); int smoother_sweeps=List.get("smoother: sweeps",2); int output=List.get("ML output",0); if(smoother == "Hiptmair"){ /* Smoother info output */ int NumGlobalRows=SM_Matrix_->NumGlobalRows(); int NumGlobalNNZ=SM_Matrix_->NumGlobalNonzeros(); if(verbose_ && !Comm_->MyPID()) { int edge_sweeps=List.get("subsmoother: edge sweeps",2); int node_sweeps=List.get("subsmoother: node sweeps",2); char msg[80]; sprintf(msg,"%s","RefMaxwell (level 0) :"); printf("%s # global rows = %d, # estim. global nnz = %d\n",msg,NumGlobalRows,NumGlobalNNZ); printf("%s %s %d (e=%d/n=%d)\n",msg,smoother.c_str(),smoother_sweeps,edge_sweeps,node_sweeps); } /* Setup Teuchos Lists - Hiptmair */ int edge_sweeps=List.get("subsmoother: edge sweeps",2); int node_sweeps=List.get("subsmoother: node sweeps",2); Teuchos::ParameterList PreList; PreList.setName("refmaxwell: edge presmoother"); PreList.set("coarse: type",smoother); PreList.set("coarse: sweeps",1); PreList.set("coarse: edge sweeps",smoother_sweeps*edge_sweeps); PreList.set("coarse: node sweeps",smoother_sweeps*node_sweeps); PreList.set("coarse: subsmoother type",List.get("subsmoother: type","symmetric Gauss-Seidel")); PreList.set("coarse: Chebyshev alpha",List.get("subsmoother: Chebyshev alpha",30.0)); PreList.set("coarse: MLS alpha",List.get("subsmoother: MLS alpha",30.0)); PreList.set("coarse: damping factor",List.get("subsmoother: SGS damping factor",1.0)); PreList.set("smoother: Hiptmair efficient symmetric",true); PreList.set("PDE equations",1); PreList.set("max levels",1); Teuchos::ParameterList PostList(PreList); PostList.setName("refmaxwell: edge postsmoother"); PreList.set("coarse: pre or post","pre"); PreList.set("smoother: pre or post","pre"); PreList.set("zero starting solution", true); PreList.set("ML label","(1,1) block fine pre-smoother"); PreList.set("ML output",output); PostList.set("coarse: pre or post","post"); PostList.set("smoother: pre or post","post"); PostList.set("zero starting solution", false); PostList.set("ML label","(1,1) block fine post-smoother"); PostList.set("ML output",output); if(HasOnlyDirichletNodes){ if(PreList.get("coarse: type","dummy") == "Hiptmair"){ smoother=PreList.get("coarse: subsmoother type","symmetric Gauss-Seidel"); PreList.set("coarse: type",smoother); PostList.set("coarse: type",smoother); }/*end if*/ #ifdef HAVE_ML_IFPACK IfSmoother=ML_Gen_Smoother_Ifpack_Epetra(const_cast<Epetra_CrsMatrix*>(&*SM_Matrix_),0,List_,"RefMaxwell (level 0): ",verbose_); #else PreEdgeSmoother = new MultiLevelPreconditioner(*SM_Matrix_,PreList); PostEdgeSmoother = new MultiLevelPreconditioner(*SM_Matrix_,PostList); #endif }/*end if*/ else{ PreEdgeSmoother = new MultiLevelPreconditioner(*SM_Matrix_,*D0_Matrix_,*TMT_Matrix_,PreList,true,true); PostEdgeSmoother = new MultiLevelPreconditioner(*SM_Matrix_,*D0_Matrix_,*TMT_Matrix_,PostList,true,true); }/*end if*/ }/*end if*/ #ifdef HAVE_ML_IFPACK else { IfSmoother=ML_Gen_Smoother_Ifpack_Epetra(const_cast<Epetra_CrsMatrix*>(&*SM_Matrix_),0,List_,"RefMaxwell (level 0): ",verbose_); }/*end else*/ #endif return 0; }/*end SetEdgeSmoother*/
int main(int argc, char *argv[]) { Teuchos::GlobalMPISession mpiSession(&argc, &argv); // This little trick lets us print to std::cout only if a (dummy) command-line argument is provided. int iprint = argc - 1; Teuchos::RCP<std::ostream> outStream; Teuchos::oblackholestream bhs; // outputs nothing if (iprint > 0) outStream = Teuchos::rcp(&std::cout, false); else outStream = Teuchos::rcp(&bhs, false); int errorFlag = 0; // *** Example body. try { int dim = 10; Teuchos::ParameterList parlist; std::string jsonFileName("parameters.json"); parlist.setName("Imported from " + jsonFileName); // Load json parameters into a Teuchos::ParameterList ROL::JSON_Parameters(jsonFileName,parlist); Teuchos::RCP<ROL::Step<RealT> > step; ROL::stepFactory<RealT>(parlist,step); // Define Status Test RealT gtol = parlist.get("Gradient Tolerance",1e-12); RealT stol = parlist.get("Step Tolerance",1e-14); int maxit = parlist.get("Maximum Number of Iterations",100); ROL::StatusTest<RealT> status(gtol, stol, maxit); ROL::DefaultAlgorithm<RealT> algo(*step,status,false); Teuchos::RCP<std::vector<RealT> > x_rcp = Teuchos::rcp(new std::vector<RealT> (dim, 1.0) ); Teuchos::RCP<std::vector<RealT> > k_rcp = Teuchos::rcp(new std::vector<RealT> (dim, 0.0) ); ROL::StdVector<RealT> x(x_rcp); Teuchos::RCP<ROL::Vector<RealT> > k = Teuchos::rcp(new ROL::StdVector<RealT>(k_rcp) ); for(int i=0;i<dim;++i) { (*k_rcp)[i] = i+1.0; } ROL::ZOO::Objective_Zakharov<RealT> obj(k); // Run Algorithm std::vector<std::string> output = algo.run(x, obj, false); for ( unsigned i = 0; i < output.size(); i++ ) { std::cout << output[i]; } // Get True Solution Teuchos::RCP<std::vector<RealT> > xtrue_rcp = Teuchos::rcp( new std::vector<RealT> (dim, 0.0) ); ROL::StdVector<RealT> xtrue(xtrue_rcp); // Compute Error x.axpy(-1.0, xtrue); RealT abserr = x.norm(); *outStream << std::scientific << "\n Absolute Error: " << abserr; if ( abserr > sqrt(ROL::ROL_EPSILON) ) { errorFlag += 1; } // Make an XML file containing the supplied parameters Teuchos::writeParameterListToXmlFile(parlist,"parameters.xml"); } catch (std::logic_error err) { *outStream << err.what() << "\n"; errorFlag = -1000; }; // end try if (errorFlag != 0) std::cout << "End Result: TEST FAILED\n"; else std::cout << "End Result: TEST PASSED\n"; return 0; }