TEUCHOS_UNIT_TEST(tStratimikosFactory, test_RelatedFunctions) { using Teuchos::RCP; using Teuchos::ParameterList; // build global (or serial communicator) #ifdef HAVE_MPI Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // build epetra operator RCP<Epetra_Operator> eA = buildStridedSystem(comm,5); RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA); { // build stratimikos factory, adding Teko's version Stratimikos::DefaultLinearSolverBuilder stratFactory; Teko::addTekoToStratimikosBuilder(stratFactory); TEST_THROW(Teko::addTekoToStratimikosBuilder(stratFactory),std::logic_error); Teko::addTekoToStratimikosBuilder(stratFactory,"Teko-2"); TEST_NOTHROW(stratFactory.getValidParameters()->sublist("Preconditioner Types").sublist("Teko")); TEST_NOTHROW(stratFactory.getValidParameters()->sublist("Preconditioner Types").sublist("Teko-2")); } { Teuchos::RCP<Teko::RequestHandler> rh = Teuchos::rcp(new Teko::RequestHandler); // build stratimikos factory, adding Teko's version Stratimikos::DefaultLinearSolverBuilder stratFactory; Teko::addTekoToStratimikosBuilder(stratFactory,rh); TEST_THROW(Teko::addTekoToStratimikosBuilder(stratFactory,rh),std::logic_error); Teko::addTekoToStratimikosBuilder(stratFactory,rh,"Teko-2"); TEST_NOTHROW(stratFactory.getValidParameters()->sublist("Preconditioner Types").sublist("Teko")); TEST_NOTHROW(stratFactory.getValidParameters()->sublist("Preconditioner Types").sublist("Teko-2")); RCP<ParameterList> params = Teuchos::rcp(new ParameterList(*stratFactory.getValidParameters())); ParameterList & tekoList = params->sublist("Preconditioner Types").sublist("Teko"); tekoList.set("Write Block Operator", false); tekoList.set("Test Block Operator", false); tekoList.set("Strided Blocking","1 1"); tekoList.set("Inverse Type","BGS"); ParameterList & ifl = tekoList.sublist("Inverse Factory Library"); ifl.sublist("BGS").set("Type","Block Gauss-Seidel"); ifl.sublist("BGS").set("Inverse Type","Amesos"); stratFactory.setParameterList(params); RCP<Teko::StratimikosFactory> precFactory = Teuchos::rcp_dynamic_cast<Teko::StratimikosFactory>(stratFactory.createPreconditioningStrategy("Teko-2")); TEST_EQUALITY(precFactory->getRequestHandler(),rh); } }
void addMueLuToStratimikosBuilder(Stratimikos::DefaultLinearSolverBuilder & builder, const std::string & stratName) { TEUCHOS_TEST_FOR_EXCEPTION(builder.getValidParameters()->sublist("Preconditioner Types").isParameter(stratName),std::logic_error, "MueLu::addMueLuToStratimikosBuilder cannot add \"" + stratName +"\" because it is already included in builder!"); // use default constructor to add Teko::StratimikosFactory builder.setPreconditioningStrategyFactory(Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Thyra::MueLuPreconditionerFactory>(), stratName); }
void addTekoToStratimikosBuilder(Stratimikos::DefaultLinearSolverBuilder & builder, const Teuchos::RCP<Teko::RequestHandler> & rh, const std::string & stratName) { TEUCHOS_TEST_FOR_EXCEPTION(builder.getValidParameters()->sublist("Preconditioner Types").isParameter(stratName),std::logic_error, "Teko::addTekoToStratimikosBuilder cannot add \"" + stratName +"\" because it is already included in builder!"); // build an instance of a Teuchos::AbsractFactory<Thyra::PFB> so request handler is passed onto // the resulting StratimikosFactory Teuchos::RCP<TekoFactoryBuilder> tekoFactoryBuilder = Teuchos::rcp(new TekoFactoryBuilder(rh)); builder.setPreconditioningStrategyFactory(tekoFactoryBuilder,stratName); }
TEUCHOS_UNIT_TEST(tStratimikosFactory, test_Defaults) { using Teuchos::RCP; using Teuchos::ParameterList; // build global (or serial communicator) #ifdef HAVE_MPI Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // build epetra operator RCP<Epetra_Operator> eA = buildSystem(comm,5); RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA); // build stratimikos factory, adding Teko's version Stratimikos::DefaultLinearSolverBuilder stratFactory; stratFactory.setPreconditioningStrategyFactory( Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Teko::StratimikosFactory>(), "Teko"); RCP<const ParameterList> validParams = stratFactory.getValidParameters(); stratFactory.setParameterList(Teuchos::rcp(new Teuchos::ParameterList(*validParams))); // print out Teko's parameter list and fail if it doesn't exist! TEST_NOTHROW(validParams->sublist("Preconditioner Types").sublist("Teko").print(out, ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true))); // build teko preconditioner factory RCP<Thyra::PreconditionerFactoryBase<double> > precFactory = stratFactory.createPreconditioningStrategy("Teko"); // make sure factory is built TEST_ASSERT(precFactory!=Teuchos::null); // build preconditioner RCP<Thyra::PreconditionerBase<double> > prec = Thyra::prec<double>(*precFactory,tA); TEST_ASSERT(prec!=Teuchos::null); // build an operator to test against RCP<const Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromStratimikos(); RCP<const Teko::InverseFactory> invFact = invLib->getInverseFactory("Amesos"); Teko::LinearOp testOp = Teko::buildInverse(*invFact,tA); Teko::LinearOp precOp = prec->getUnspecifiedPrecOp(); TEST_ASSERT(precOp!=Teuchos::null); Thyra::LinearOpTester<double> tester; tester.show_all_tests(true); tester.set_all_error_tol(0); TEST_ASSERT(tester.compare(*precOp,*testOp,Teuchos::ptrFromRef(out))); }
TEUCHOS_UNIT_TEST(tStratimikosFactory, test_MultipleCalls) { using Teuchos::RCP; using Teuchos::ParameterList; // build global (or serial communicator) #ifdef HAVE_MPI Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // build epetra operator RCP<Epetra_Operator> eA = buildStridedSystem(comm,5); RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA); Stratimikos::DefaultLinearSolverBuilder stratFactory; RCP<ParameterList> params = Teuchos::rcp(new ParameterList(*stratFactory.getValidParameters())); ParameterList & tekoList = params->sublist("Preconditioner Types").sublist("Teko"); tekoList.set("Write Block Operator", false); tekoList.set("Test Block Operator", false); tekoList.set("Strided Blocking","1 1"); tekoList.set("Inverse Type","BGS"); ParameterList & ifl = tekoList.sublist("Inverse Factory Library"); ifl.sublist("BGS").set("Type","Block Gauss-Seidel"); ifl.sublist("BGS").set("Inverse Type","Amesos"); Teko::addTekoToStratimikosBuilder(stratFactory,"Teko"); stratFactory.setParameterList(params); RCP<Thyra::PreconditionerFactoryBase<double> > precFactory = stratFactory.createPreconditioningStrategy("Teko"); // build teko preconditioner factory RCP<Thyra::PreconditionerBase<double> > prec_a = Thyra::prec<double>(*precFactory,tA); Teko::LinearOp precOp_a = prec_a->getUnspecifiedPrecOp(); TEST_ASSERT(precOp_a!=Teuchos::null); // try to do it again RCP<Thyra::PreconditionerBase<double> > prec_b = Thyra::prec<double>(*precFactory,tA); Teko::LinearOp precOp_b = prec_b->getUnspecifiedPrecOp(); TEST_ASSERT(precOp_b!=Teuchos::null); }
/** \brief Build an inverse library from Stratimikos * * Build an inverse library from Stratimkos. The labels * will just be the names in Stratimikos. * * \param[in] strat Stratimikos object to use * * \returns A pointer to the inverse library created. */ Teuchos::RCP<InverseLibrary> InverseLibrary::buildFromStratimikos(const Stratimikos::DefaultLinearSolverBuilder & strat) { RCP<InverseLibrary> invLib = rcp(new InverseLibrary()); // get default inveres in Stratimikos RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList(*strat.getValidParameters())); Teuchos::ParameterList lst(pl->sublist("Linear Solver Types")); Teuchos::ParameterList pft(pl->sublist("Preconditioner Types")); Teuchos::ParameterList::ConstIterator itr; Teuchos::ParameterList * temp = 0; // loop over all entries in solver list for(itr=lst.begin();itr!=lst.end();++itr) { // get current entry std::string label = itr->first; Teuchos::ParameterList & list = itr->second.getValue(temp); list.set("Type",label); // add to library invLib->addInverse(label,list); } // loop over all entries in preconditioner list for(itr=pft.begin();itr!=pft.end();++itr) { // get current entry std::string label = itr->first; Teuchos::ParameterList & list = itr->second.getValue(temp); list.set("Type",label); // add to library invLib->addInverse(label,list); } return invLib; }
TEUCHOS_UNIT_TEST(explicit_model_evaluator, basic) { using Teuchos::RCP; PHX::KokkosDeviceSession session; bool parameter_on = true; Teuchos::RCP<panzer::FieldManagerBuilder> fmb; Teuchos::RCP<panzer::ResponseLibrary<panzer::Traits> > rLibrary; Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > lof; Teuchos::RCP<panzer::GlobalData> gd; buildAssemblyPieces(parameter_on,fmb,rLibrary,gd,lof); // Test a transient me { typedef Thyra::ModelEvaluatorBase MEB; typedef Thyra::ModelEvaluatorBase::InArgs<double> InArgs; typedef Thyra::ModelEvaluatorBase::OutArgs<double> OutArgs; typedef Thyra::VectorBase<double> VectorType; typedef Thyra::LinearOpBase<double> OperatorType; typedef panzer::ModelEvaluator<double> PME; typedef panzer::ExplicitModelEvaluator<double> ExpPME; std::vector<Teuchos::RCP<Teuchos::Array<std::string> > > p_names; std::vector<Teuchos::RCP<Teuchos::Array<double> > > p_values; bool build_transient_support = true; Stratimikos::DefaultLinearSolverBuilder builder; Teuchos::RCP<Teuchos::ParameterList> validList = Teuchos::rcp(new Teuchos::ParameterList(*builder.getValidParameters())); builder.setParameterList(validList); RCP<const Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = builder.createLinearSolveStrategy("Amesos"); RCP<PME> me = Teuchos::rcp(new PME(fmb,rLibrary,lof,p_names,p_values,lowsFactory,gd,build_transient_support,0.0)); RCP<ExpPME> exp_me = Teuchos::rcp(new ExpPME(me,true,false)); // constant mass, use lumped RCP<VectorType> exp_f, f; // explicit evaluation { // set the nominal values InArgs nom_vals = exp_me->getNominalValues(); TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_x)); TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_x_dot)); // this is supported for stabilization purposes TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_alpha)); // alpha and beta support needed for outputting responses TEST_ASSERT(nom_vals.supports(MEB::IN_ARG_beta)); // create in args InArgs in_args = exp_me->createInArgs(); TEST_ASSERT(in_args.supports(MEB::IN_ARG_x)); TEST_ASSERT(in_args.supports(MEB::IN_ARG_x_dot)); // this is supported for stabilization purposes TEST_ASSERT(in_args.supports(MEB::IN_ARG_alpha)); // alpha and beta support needed for outputting responses TEST_ASSERT(in_args.supports(MEB::IN_ARG_beta)); InArgs nomValues = exp_me->getNominalValues(); RCP<VectorType> x = Thyra::createMember(*exp_me->get_x_space()); RCP<VectorType> x_dot = Thyra::createMember(*exp_me->get_x_space()); Thyra::assign(x_dot.ptr(),0.0); Thyra::assign(x.ptr(),5.0); in_args.set_x(x); in_args.set_x_dot(x_dot); // create out args OutArgs out_args = exp_me->createOutArgs(); TEST_ASSERT(out_args.supports(MEB::OUT_ARG_f)); TEST_ASSERT(!out_args.supports(MEB::OUT_ARG_W_op)); TEST_ASSERT(!out_args.supports(MEB::OUT_ARG_W)); exp_f = Thyra::createMember(*exp_me->get_f_space()); out_args.set_f(exp_f); exp_me->evalModel(in_args, out_args); } // implicit evaluation RCP<OperatorType> mass = me->create_W_op(); { // create in args InArgs in_args = me->createInArgs(); InArgs nomValues = me->getNominalValues(); RCP<VectorType> x = Thyra::createMember(*me->get_x_space()); RCP<VectorType> x_dot = Thyra::createMember(*me->get_x_space()); Thyra::assign(x_dot.ptr(),0.0); Thyra::assign(x.ptr(),5.0); in_args.set_x(x); in_args.set_x_dot(x_dot); // create out args OutArgs out_args = me->createOutArgs(); f = Thyra::createMember(*me->get_f_space()); out_args.set_f(f); me->evalModel(in_args, out_args); in_args.set_x(x); in_args.set_x_dot(x_dot); in_args.set_alpha(1.0); in_args.set_beta(0.0); out_args.set_f(Teuchos::null); out_args.set_W_op(mass); me->setOneTimeDirichletBeta(1.0); me->evalModel(in_args, out_args); } Teuchos::RCP<Thyra::VectorBase<double> > mass_exp_f = Thyra::createMember(*exp_me->get_f_space()); Thyra::apply(*mass,Thyra::NOTRANS,*exp_f,mass_exp_f.ptr()); out << "f_i = \n" << Teuchos::describe(*f,Teuchos::VERB_EXTREME) << std::endl; out << "f_e = \n" << Teuchos::describe(*mass_exp_f,Teuchos::VERB_EXTREME) << std::endl; // it should be that exp_f = -f b/c x_dot=0 in the evaluation Thyra::Vp_StV(mass_exp_f.ptr(),1.0,*f); out << "Error = " << Thyra::norm_2(*mass_exp_f) << std::endl; TEST_ASSERT(Thyra::norm_2(*mass_exp_f)<=1e-16); } }
// calls MPI_Init and MPI_Finalize int main(int argc,char * argv[]) { using Teuchos::RCP; using panzer::StrPureBasisPair; using panzer::StrPureBasisComp; PHX::InitializeKokkosDevice(); Teuchos::GlobalMPISession mpiSession(&argc,&argv); Teuchos::FancyOStream out(Teuchos::rcpFromRef(std::cout)); out.setOutputToRootOnly(0); out.setShowProcRank(true); // variable declarations //////////////////////////////////////////////////// // factory definitions Teuchos::RCP<user_app::MyFactory> eqset_factory = Teuchos::rcp(new user_app::MyFactory); panzer_stk::SquareQuadMeshFactory mesh_factory; user_app::BCFactory bc_factory; // other declarations const std::size_t workset_size = 20; Teuchos::RCP<panzer::FieldManagerBuilder> fmb = Teuchos::rcp(new panzer::FieldManagerBuilder); RCP<panzer_stk::STK_Interface> mesh; // construction of uncommitted (no elements) mesh //////////////////////////////////////////////////////// // set mesh factory parameters RCP<Teuchos::ParameterList> pl = rcp(new Teuchos::ParameterList); pl->set("X Blocks",2); pl->set("Y Blocks",1); pl->set("X Elements",10); pl->set("Y Elements",10); mesh_factory.setParameterList(pl); mesh = mesh_factory.buildUncommitedMesh(MPI_COMM_WORLD); // construct input physics and physics block //////////////////////////////////////////////////////// out << "BUILD PHYSICS" << std::endl; Teuchos::RCP<Teuchos::ParameterList> ipb = Teuchos::parameterList("Physics Blocks"); std::vector<panzer::BC> bcs; std::vector<Teuchos::RCP<panzer::PhysicsBlock> > physicsBlocks; { std::map<std::string,std::string> block_ids_to_physics_ids; std::map<std::string,Teuchos::RCP<const shards::CellTopology> > block_ids_to_cell_topo; testInitialzation(ipb, bcs); block_ids_to_physics_ids["eblock-0_0"] = "test physics"; block_ids_to_physics_ids["eblock-1_0"] = "test physics"; block_ids_to_cell_topo["eblock-0_0"] = mesh->getCellTopology("eblock-0_0"); block_ids_to_cell_topo["eblock-1_0"] = mesh->getCellTopology("eblock-1_0"); Teuchos::RCP<panzer::GlobalData> gd = panzer::createGlobalData(); int default_integration_order = 1; // build physicsBlocks map panzer::buildPhysicsBlocks(block_ids_to_physics_ids, block_ids_to_cell_topo, ipb, default_integration_order, workset_size, eqset_factory, gd, true, physicsBlocks); } // finish building mesh, set required field variables and mesh bulk data //////////////////////////////////////////////////////////////////////// { std::vector<Teuchos::RCP<panzer::PhysicsBlock> >::const_iterator physIter; for(physIter=physicsBlocks.begin();physIter!=physicsBlocks.end();++physIter) { Teuchos::RCP<const panzer::PhysicsBlock> pb = *physIter; const std::vector<StrPureBasisPair> & blockFields = pb->getProvidedDOFs(); // insert all fields into a set std::set<StrPureBasisPair,StrPureBasisComp> fieldNames; fieldNames.insert(blockFields.begin(),blockFields.end()); // add basis to DOF manager: block specific std::set<StrPureBasisPair,StrPureBasisComp>::const_iterator fieldItr; for (fieldItr=fieldNames.begin();fieldItr!=fieldNames.end();++fieldItr) { mesh->addSolutionField(fieldItr->first,pb->elementBlockID()); } } mesh_factory.completeMeshConstruction(*mesh,MPI_COMM_WORLD); } // build worksets //////////////////////////////////////////////////////// // build worksets out << "BUILD WORKSETS" << std::endl; Teuchos::RCP<panzer_stk::WorksetFactory> wkstFactory = Teuchos::rcp(new panzer_stk::WorksetFactory(mesh)); // build STK workset factory Teuchos::RCP<panzer::WorksetContainer> wkstContainer // attach it to a workset container (uses lazy evaluation) = Teuchos::rcp(new panzer::WorksetContainer(wkstFactory,physicsBlocks,workset_size)); std::vector<std::string> elementBlockNames; mesh->getElementBlockNames(elementBlockNames); std::map<std::string,Teuchos::RCP<std::vector<panzer::Workset> > > volume_worksets; panzer::getVolumeWorksetsFromContainer(*wkstContainer,elementBlockNames,volume_worksets); out << "block count = " << volume_worksets.size() << std::endl; out << "workset count = " << volume_worksets["eblock-0_0"]->size() << std::endl; // build DOF Manager ///////////////////////////////////////////////////////////// out << "BUILD CONN MANAGER" << std::endl; // build the connection manager const Teuchos::RCP<panzer::ConnManager<int,int> > conn_manager = Teuchos::rcp(new panzer_stk::STKConnManager<int>(mesh)); panzer::DOFManagerFactory<int,int> globalIndexerFactory; RCP<panzer::UniqueGlobalIndexer<int,int> > dofManager = globalIndexerFactory.buildUniqueGlobalIndexer(Teuchos::opaqueWrapper(MPI_COMM_WORLD),physicsBlocks,conn_manager); // construct some linear algebra object, build object to pass to evaluators Teuchos::RCP<const Teuchos::MpiComm<int> > tComm = Teuchos::rcp(new Teuchos::MpiComm<int>(MPI_COMM_WORLD)); Teuchos::RCP<panzer::EpetraLinearObjFactory<panzer::Traits,int> > eLinObjFactory = Teuchos::rcp(new panzer::EpetraLinearObjFactory<panzer::Traits,int>(tComm.getConst(),dofManager)); Teuchos::RCP<panzer::LinearObjFactory<panzer::Traits> > linObjFactory = eLinObjFactory; // setup field manager build ///////////////////////////////////////////////////////////// out << "SETUP FMB" << std::endl; // Add in the application specific closure model factory panzer::ClosureModelFactory_TemplateManager<panzer::Traits> cm_factory; user_app::MyModelFactory_TemplateBuilder cm_builder; cm_factory.buildObjects(cm_builder); Teuchos::ParameterList closure_models("Closure Models"); closure_models.sublist("solid").sublist("SOURCE_TEMPERATURE").set<double>("Value",1.0); closure_models.sublist("solid").sublist("DENSITY").set<double>("Value",1.0); closure_models.sublist("solid").sublist("HEAT_CAPACITY").set<double>("Value",1.0); closure_models.sublist("ion solid").sublist("SOURCE_ION_TEMPERATURE").set<double>("Value",1.0); closure_models.sublist("ion solid").sublist("ION_DENSITY").set<double>("Value",1.0); closure_models.sublist("ion solid").sublist("ION_HEAT_CAPACITY").set<double>("Value",1.0); Teuchos::ParameterList user_data("User Data"); fmb->setWorksetContainer(wkstContainer); fmb->setupVolumeFieldManagers(physicsBlocks,cm_factory,closure_models,*linObjFactory,user_data); fmb->setupBCFieldManagers(bcs,physicsBlocks,*eqset_factory,cm_factory,bc_factory,closure_models,*linObjFactory,user_data); // setup assembly engine ///////////////////////////////////////////////////////////// // build assembly engine panzer::AssemblyEngine_TemplateManager<panzer::Traits> ae_tm; panzer::AssemblyEngine_TemplateBuilder builder(fmb,linObjFactory); ae_tm.buildObjects(builder); // setup linear algebra and solve ///////////////////////////////////////////////////////////// // build ghosted variables out << "BUILD LA" << std::endl; RCP<panzer::EpetraLinearObjContainer> ghostCont = Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(linObjFactory->buildGhostedLinearObjContainer()); RCP<panzer::EpetraLinearObjContainer> container = Teuchos::rcp_dynamic_cast<panzer::EpetraLinearObjContainer>(linObjFactory->buildLinearObjContainer()); eLinObjFactory->initializeContainer(panzer::EpetraLinearObjContainer::X | panzer::EpetraLinearObjContainer::DxDt | panzer::EpetraLinearObjContainer::F | panzer::EpetraLinearObjContainer::Mat,*container); eLinObjFactory->initializeGhostedContainer(panzer::EpetraLinearObjContainer::X | panzer::EpetraLinearObjContainer::DxDt | panzer::EpetraLinearObjContainer::F | panzer::EpetraLinearObjContainer::Mat,*ghostCont); panzer::AssemblyEngineInArgs input(ghostCont,container); input.alpha = 0; input.beta = 1; // evaluate physics out << "EVALUTE" << std::endl; ae_tm.getAsObject<panzer::Traits::Residual>()->evaluate(input); ae_tm.getAsObject<panzer::Traits::Jacobian>()->evaluate(input); out << "RAN SUCCESSFULLY!" << std::endl; out << "SOLVE" << std::endl; // notice that this should be called by the assembly driver! // linObjFactory->ghostToGlobalContainer(*ghostCont,*container); Teuchos::RCP<const Thyra::LinearOpBase<double> > th_A = Thyra::epetraLinearOp(container->get_A()); Teuchos::RCP<const Thyra::VectorSpaceBase<double> > range = th_A->range(); Teuchos::RCP<const Thyra::VectorSpaceBase<double> > domain = th_A->domain(); Teuchos::RCP<Thyra::VectorBase<double> > th_x = Thyra::create_Vector(container->get_x(),domain); Teuchos::RCP<Thyra::VectorBase<double> > th_f = Thyra::create_Vector(container->get_f(),range); // solve with amesos Stratimikos::DefaultLinearSolverBuilder solverBuilder; Teuchos::RCP<Teuchos::ParameterList> validList = Teuchos::rcp(new Teuchos::ParameterList(*solverBuilder.getValidParameters())); solverBuilder.setParameterList(validList); RCP<Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory = solverBuilder.createLinearSolveStrategy("Amesos"); RCP<Thyra::LinearOpWithSolveBase<double> > lows = Thyra::linearOpWithSolve(*lowsFactory, th_A.getConst()); Thyra::solve<double>(*lows, Thyra::NOTRANS, *th_f, th_x.ptr()); if(false) { EpetraExt::RowMatrixToMatrixMarketFile("a_op.mm",*container->get_A()); EpetraExt::VectorToMatrixMarketFile("x_vec.mm",*container->get_x()); EpetraExt::VectorToMatrixMarketFile("b_vec.mm",*container->get_f()); } out << "WRITE" << std::endl; // redistribute solution vector linObjFactory->globalToGhostContainer(*container,*ghostCont,panzer::EpetraLinearObjContainer::X | panzer::EpetraLinearObjContainer::DxDt); panzer_stk::write_solution_data(*dofManager,*mesh,*ghostCont->get_x()); mesh->writeToExodus("output.exo"); PHX::FinalizeKokkosDevice(); return 0; }
int main(int argc, char* argv[]) { bool success = false; bool verbose = false; try { std::ofstream out; out.open("stratimikos.xml", std::ofstream::out); Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder; // // We will print to standard out, and that output will be valid XML // describing the validated ParameterList. For the purposes of // generating nicely-formatted HTML documentation for this // ParameterList, we also need to include an XSL header line. This // bool will control whether we include this header line, which can // be controlled at the command line. // bool xsl_header_flag = true; // // Set up the command line processor. All versions of this // executable should support the add-xsl-header/suppress-xsl-header // command line options. If you want a single executable to support // multiple ParameterLists, you could put additional options here to // control which ParameterList to output. // CommandLineProcessor clp(false); //don't throw exceptions clp.recogniseAllOptions(true); clp.setOption("add-xsl-header", "suppress-xsl-header", &xsl_header_flag, "XSL header flag"); // // Parse the command line and quit if not successful // CommandLineProcessor::EParseCommandLineReturn parse_return = clp.parse(argc, argv); if(parse_return != CommandLineProcessor::PARSE_SUCCESSFUL) return parse_return; // // Print the XSL header line if requested // if (xsl_header_flag ) out << "<?xml-stylesheet type=\"text/xsl\" " << "href=\"../common/paramList/paramList.xsl\"?>\n"; // // Obtain the validated ParameterList and write it to the fancy // output stream. If you wanted to support multiple ParameterLists, // this is where the logic would go to choose between them. Note // that Domi has a function that returns the valid ParameterList, // but that a more common use case will be to construct a class // (that supports the construct-then-init paradigm) with a default // constructor and then call its getValidParameters() method. // Teuchos::writeParameterListToXmlOStream(*linearSolverBuilder.getValidParameters(), out); success = true; } TEUCHOS_STANDARD_CATCH_STATEMENTS(verbose, std::cerr, success); return ( success ? EXIT_SUCCESS : EXIT_FAILURE ); }
TEUCHOS_UNIT_TEST(tStratimikosFactory, test_multi_use) { using Teuchos::RCP; using Teuchos::ParameterList; // build global (or serial communicator) #ifdef HAVE_MPI Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // build epetra operator RCP<Epetra_Operator> eA = buildSystem(comm,5); RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA); // build stratimikos factory, adding Teko's version Stratimikos::DefaultLinearSolverBuilder stratFactory; stratFactory.setPreconditioningStrategyFactory( Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Teko::StratimikosFactory>(), "Teko"); RCP<const ParameterList> validParams = stratFactory.getValidParameters(); stratFactory.setParameterList(Teuchos::rcp(new Teuchos::ParameterList(*validParams))); // print out Teko's parameter list and fail if it doesn't exist! TEST_NOTHROW(validParams->sublist("Preconditioner Types").sublist("Teko").print(out, ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true))); // build teko preconditioner factory RCP<Thyra::PreconditionerFactoryBase<double> > precFactory = stratFactory.createPreconditioningStrategy("Teko"); // make sure factory is built TEST_ASSERT(precFactory!=Teuchos::null); // try using a different preconditioner each time RCP<Thyra::PreconditionerBase<double> > prec; for(int i=0;i<2;i++) { prec = precFactory->createPrec(); RCP<const Thyra::LinearOpSourceBase<double> > losb = rcp(new Thyra::DefaultLinearOpSource<double>(tA)); precFactory->initializePrec(losb,prec.get()); RCP<Teko::StratimikosFactory> stratFact = rcp_dynamic_cast<Teko::StratimikosFactory>(precFactory); const std::vector<int> & decomp = stratFact->getDecomposition(); TEST_EQUALITY(decomp.size(),1); TEST_EQUALITY(decomp[0],1); } // try using a single preconditioner multiple times prec = precFactory->createPrec(); for(int i=0;i<2;i++) { RCP<const Thyra::LinearOpSourceBase<double> > losb = rcp(new Thyra::DefaultLinearOpSource<double>(tA)); precFactory->initializePrec(losb,prec.get()); RCP<Teko::StratimikosFactory> stratFact = rcp_dynamic_cast<Teko::StratimikosFactory>(precFactory); const std::vector<int> & decomp = stratFact->getDecomposition(); TEST_EQUALITY(decomp.size(),1); TEST_EQUALITY(decomp[0],1); } }
TEUCHOS_UNIT_TEST(tStratimikosFactory, test_BlockGaussSeidel) { using Teuchos::RCP; using Teuchos::ParameterList; // build global (or serial communicator) #ifdef HAVE_MPI Epetra_MpiComm comm(MPI_COMM_WORLD); #else Epetra_SerialComm comm; #endif // build epetra operator RCP<Epetra_Operator> eA = buildStridedSystem(comm,5); RCP<Thyra::LinearOpBase<double> > tA = Thyra::nonconstEpetraLinearOp(eA); // build stratimikos factory, adding Teko's version Stratimikos::DefaultLinearSolverBuilder stratFactory; stratFactory.setPreconditioningStrategyFactory( Teuchos::abstractFactoryStd<Thyra::PreconditionerFactoryBase<double>,Teko::StratimikosFactory>(), "Teko"); RCP<ParameterList> params = Teuchos::rcp(new ParameterList(*stratFactory.getValidParameters())); ParameterList & tekoList = params->sublist("Preconditioner Types").sublist("Teko"); tekoList.set("Write Block Operator", false); tekoList.set("Test Block Operator", false); tekoList.set("Strided Blocking","1 1"); tekoList.set("Inverse Type","BGS"); ParameterList & ifl = tekoList.sublist("Inverse Factory Library"); ifl.sublist("BGS").set("Type","Block Gauss-Seidel"); ifl.sublist("BGS").set("Inverse Type","Amesos"); // RCP<Thyra::PreconditionerFactoryBase<double> > precFactory // = stratFactory.createPreconditioningStrategy("Teko"); // build operator to test against Teko::LinearOp testOp; { Teuchos::ParameterList iflCopy(ifl); RCP<Epetra_Operator> strided_eA = Teuchos::rcp(new Teko::Epetra::StridedEpetraOperator(2,eA)); RCP<Teko::InverseLibrary> invLib = Teko::InverseLibrary::buildFromParameterList(iflCopy); RCP<const Teko::InverseFactory> invFact = invLib->getInverseFactory("BGS"); RCP<Teko::Epetra::InverseFactoryOperator> invFactOp = Teuchos::rcp(new Teko::Epetra::InverseFactoryOperator(invFact)); invFactOp->buildInverseOperator(strided_eA); testOp = Thyra::epetraLinearOp(invFactOp,Thyra::NOTRANS,Thyra::EPETRA_OP_APPLY_APPLY_INVERSE); } stratFactory.setParameterList(params); RCP<Thyra::PreconditionerFactoryBase<double> > precFactory = stratFactory.createPreconditioningStrategy("Teko"); // build teko preconditioner factory RCP<Thyra::PreconditionerBase<double> > prec = Thyra::prec<double>(*precFactory,tA); Teko::LinearOp precOp = prec->getUnspecifiedPrecOp(); TEST_ASSERT(precOp!=Teuchos::null); Thyra::LinearOpTester<double> tester; tester.show_all_tests(true); tester.set_all_error_tol(0); TEST_ASSERT(tester.compare(*precOp,*testOp,Teuchos::ptrFromRef(out))); }