45 #include "MoochoPack_MoochoThyraSolver.hpp"
46 #include "Thyra_EpetraModelEvaluator.hpp"
47 #include "Thyra_DefaultSpmdMultiVectorFileIO.hpp"
48 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
49 #include "Teuchos_GlobalMPISession.hpp"
50 #include "Teuchos_CommandLineProcessor.hpp"
51 #include "Teuchos_StandardCatchMacros.hpp"
52 #include "Teuchos_VerboseObject.hpp"
53 #include "Teuchos_XMLParameterListHelpers.hpp"
55 # include "Epetra_MpiComm.h"
57 # include "Epetra_SerialComm.h"
61 typedef AbstractLinAlgPack::value_type Scalar;
65 int main(
int argc,
char* argv[] )
76 const int numProcs = mpiSession.getNProc();
80 bool dummySuccess =
true;
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);
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 )
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
172 MPI_Comm mpiComm = MPI_COMM_WORLD;
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";
199 *out <<
"\nCreate the Thyra::EpetraModelEvaluator wrapper object ...\n";
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";
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());
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
basic_OSTab< char > OSTab
void setupCLP(Teuchos::CommandLineProcessor *clp)
void readParameters(std::ostream *out)
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
RCP< Thyra::LinearOpWithSolveFactoryBase< double > > createLinearSolveStrategy(const std::string &linearSolveStrategyName) const
static RCP< FancyOStream > getDefaultOStream()
RCP< Epetra_Vector > get_Epetra_Vector(const Epetra_Map &map, const RCP< VectorBase< double > > &v)
void initialize(const RCP< const EpetraExt::ModelEvaluator > &epetraModel, const RCP< LinearOpWithSolveFactoryBase< double > > &W_factory)
void writeParamsFile(const Thyra::LinearOpWithSolveFactoryBase< double > &lowsFactory, const std::string &outputXmlFileName="") const
RCP< const VectorSpaceBase< double > > get_x_space() const
void setupCLP(Teuchos::CommandLineProcessor *clp)
RCP< const VectorSpaceBase< double > > get_p_space(int l) const
void set_q(Teuchos::RCP< const Epetra_Vector > const &q)
void copyAllOutputOptions(const basic_FancyOStream< CharT, Traits > &oStream)
#define TEUCHOS_STANDARD_CATCH_STATEMENTS(VERBOSE, ERR_STREAM, SUCCESS_FLAG)
Teuchos::RCP< AdvDiffReactOptModel > createModel(const Teuchos::RCP< const Epetra_Comm > &comm, std::ostream *out=NULL) const