46 #include "Thyra_EpetraModelEvaluator.hpp"
47 #include "Thyra_DefaultSpmdMultiVectorFileIO.hpp"
48 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
65 int main(
int argc,
char* argv[] )
76 const int numProcs = mpiSession.
getNProc();
80 bool dummySuccess =
true;
83 out = Teuchos::VerboseObjectBase::getDefaultOStream();
89 Stratimikos::DefaultLinearSolverBuilder lowsfCreator;
90 MoochoThyraSolver solver;
96 std::string matchingVecFile =
"";
98 bool showMoochoThyraParams =
false;
99 bool showMoochoThyraParamsWithDoc =
true;
100 bool showMoochoThyraParamsXML =
false;
102 CommandLineProcessor clp;
103 clp.throwExceptions(
false);
104 clp.addOutputSetupOptions(
true);
106 advDiffReacModelCreator.
setupCLP(&clp);
107 lowsfCreator.setupCLP(&clp);
108 solver.setupCLP(&clp);
111 "q-vec-file", &matchingVecFile
112 ,
"Base file name to read the objective state matching "
113 "vector q (i.e. ||x-q||_M in the objective)."
117 "only-print-moocho-thyra-solver-params",
"no-print-moocho-thyra-solver-params"
118 ,&showMoochoThyraParams
119 ,
"Only print the parameters accepted by MoochoPack::MoochoThyraSolver and stop."
122 "show-doc",
"hide-doc", &showMoochoThyraParamsWithDoc
123 ,
"Show MoochoPack::MocohoThyraSolver parameters with documentation or not."
126 "xml-format",
"readable-format", &showMoochoThyraParamsXML
127 ,
"Show MoochoPack::MoochoThyraSolver parameters in XML or human-readable format."
130 CommandLineProcessor::EParseCommandLineReturn
131 parse_return = clp.parse(argc,argv,&std::cerr);
133 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
136 lowsfCreator.readParameters( !showMoochoThyraParams ? out.
get() : NULL );
137 solver.readParameters( !showMoochoThyraParams ? out.
get() : NULL );
139 if(showMoochoThyraParams) {
141 if(showMoochoThyraParamsXML)
142 Teuchos::writeParameterListToXmlOStream(
143 *solver.getValidParameters()
147 solver.getValidParameters()->print(
148 *out,PLPrintOptions().indent(2).showTypes(
true).showDoc(showMoochoThyraParamsWithDoc)
160 solver.getSolver().generate_output_file(
"MoochoJournal")
168 <<
"\n*** NLPThyraEpetraAdvDiffReactOptMain, Global numProcs = "<<numProcs
186 *out <<
"\nCreate the GLpApp::AdvDiffReactOptModel wrapper object ...\n";
189 epetraModel = advDiffReacModelCreator.
createModel(comm);
190 epetraModel->setOStream(journalOut);
192 *out <<
"\nCreate the Thyra::LinearOpWithSolveFactory object ...\n";
195 lowsFactory = lowsfCreator.createLinearSolveStrategy(
"");
199 *out <<
"\nCreate the Thyra::EpetraModelEvaluator wrapper object ...\n";
202 epetraThyraModel =
rcp(
new Thyra::EpetraModelEvaluator());
203 epetraThyraModel->setOStream(journalOut);
204 epetraThyraModel->initialize(epetraModel,lowsFactory);
207 <<
"\nnx = " << epetraThyraModel->get_x_space()->dim()
208 <<
"\nnp = " << epetraThyraModel->get_p_space(0)->dim() <<
"\n";
210 if(matchingVecFile !=
"") {
211 *out <<
"\nReading the matching vector \'q\' from the file(s) with base name \""<<matchingVecFile<<
"\" ...\n";
212 Thyra::DefaultSpmdMultiVectorFileIO<Scalar> fileIO;
214 Thyra::get_Epetra_Vector(
216 ,readVectorFromFile(fileIO,matchingVecFile,*epetraThyraModel->get_x_space())
226 solver.getSolver().set_journal_out(journalOut);
229 solver.setModel(epetraThyraModel);
232 solver.readInitialGuess(out.
get());
235 const MoochoSolver::ESolutionStatus solution_status = solver.solve();
238 solver.writeFinalSolution(out.
get());
241 lowsfCreator.writeParamsFile(*lowsFactory);
242 solver.writeParamsFile();
248 if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
249 *out <<
"\nEnd Result: TEST PASSED\n";
251 *out <<
"\nEnd Result: TEST FAILED\n";
253 return solution_status;
258 return MoochoSolver::SOLVE_RETURN_EXCEPTION;
Teuchos::RCP< const Epetra_Map > get_x_map() const
RTOp_value_type value_type
MOOCHO NLP Solver class for models represented through Thyra::ModelEvaluator.
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
int main(int argc, char *argv[])
void setupCLP(Teuchos::CommandLineProcessor *clp)
ParameterList::PrintOptions PLPrintOptions
Universal interface to a MOOCHO solver.
void set_q(Teuchos::RCP< const Epetra_Vector > const &q)
void copyAllOutputOptions(const basic_FancyOStream< CharT, Traits > &oStream)
Teuchos::RCP< AdvDiffReactOptModel > createModel(const Teuchos::RCP< const Epetra_Comm > &comm, std::ostream *out=NULL) const