1 #include "Epetra_ConfigDefs.h" 4 #include "Epetra_MpiComm.h" 6 #include "Epetra_SerialComm.h" 12 #include "Teuchos_CommandLineProcessor.hpp" 13 #include "Teuchos_StandardCatchMacros.hpp" 14 #include "Teuchos_ParameterList.hpp" 15 #include "Teuchos_XMLParameterListCoreHelpers.hpp" 16 #include "Stratimikos_DefaultLinearSolverBuilder.hpp" 18 int main(
int argc,
char *argv[]){
20 std::string xmlInFileName =
"";
21 std::string extraXmlFile =
"";
22 std::string xmlOutFileName =
"paramList.out";
24 Teuchos::CommandLineProcessor clp(
false);
25 clp.setOption(
"xml-in-file",&xmlInFileName,
"The XML file to read into a parameter list");
26 clp.setOption(
"xml-out-file",&xmlOutFileName,
"The XML file to write the final parameter list to");
28 "This example program shows how to read in a parameter list from an" 29 " XML file (given by --xml-in-file=xmlInFileName)." 30 " The final parameter list is then written back to an XML file." 31 " (given by --xml-out-file=xmlOutFileName)." 32 "This program also shows how to use Stratikimos for a" 33 " sequence of two linear systems." 35 Teuchos::CommandLineProcessor::EParseCommandLineReturn
36 parse_return = clp.parse(argc,argv);
37 if( parse_return != Teuchos::CommandLineProcessor::PARSE_SUCCESSFUL ) {
38 std::cout <<
"\nEnd Result: TEST FAILED" << std::endl;
43 MPI_Init(&argc, &argv);
44 Epetra_MpiComm Comm(MPI_COMM_WORLD);
46 Epetra_SerialComm Comm;
49 Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::rcp(
new Teuchos::ParameterList);
50 if(xmlInFileName.length()) {
51 Teuchos::updateParametersFromXmlFile(xmlInFileName, inoutArg(*paramList));
54 Teuchos::RCP<Teuchos::ParameterList> solverBuilderSL = Teuchos::sublist(paramList,
"Linear Solver Builder",
true);
56 Teuchos::RCP<laplace> Laplace = Teuchos::rcp(
new laplace(Comm,paramList->sublist(
"Mesh")));
58 Teuchos::RCP<Epetra_FECrsMatrix> matrix = Teuchos::rcp(
new Epetra_FECrsMatrix(Copy,*Laplace->FEGraph));
59 Teuchos::RCP<Epetra_Vector> lhs = Teuchos::rcp(
new Epetra_Vector(*Laplace->StandardMap));
60 Teuchos::RCP<Epetra_FEVector> rhs = Teuchos::rcp(
new Epetra_FEVector(*Laplace->StandardMap));
61 Teuchos::RCP<Epetra_MultiVector> rhsv = rhs;
63 Stratimikos::DefaultLinearSolverBuilder linearSolverBuilder;
64 linearSolverBuilder.setParameterList(solverBuilderSL);
66 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<double> > lowsFactory =
67 linearSolverBuilder.createLinearSolveStrategy(
"");
68 Teuchos::RCP<Thyra::LinearOpWithSolveBase<double> > lows = lowsFactory->createOp();
70 Thyra::SolveStatus<double> status;
72 Teuchos::RCP<const Thyra::LinearOpBase<double>> A = Thyra::epetraLinearOp(matrix);
73 Teuchos::RCP<Thyra::VectorBase<double>> x = Thyra::create_Vector(lhs,A->domain());
74 Teuchos::RCP<const Thyra::MultiVectorBase<double>> b = Thyra::create_MultiVector(rhsv,A->range());
78 bc_indx[0] = 2; bc_indx[1] = 3;
79 bc_val[0] = 0.0; bc_val[1] = 1.0;
81 for (
unsigned iter=0; iter<5; ++iter){
82 Laplace->assembling_OAZ(*matrix, *rhs, &bc_indx[0], &bc_val[0]);
86 Thyra::initializeOp<double>(*lowsFactory, A, lows.ptr());
87 status = Thyra::solve<double>(*lows, Thyra::NOTRANS, *b, x.ptr());
88 if (status.solveStatus){
90 std::cout <<
"STRATIMIKOS FAILED TO CONVERGE.\n";
91 std::cout << status.message <<
"\n";
94 std::string name =
"belos_test_" + std::to_string(iter) +
".mtx";
95 int error = Laplace->print_solution(*lhs,name);
int main(int argc, char *argv[])