00001 #include "GLpApp_AdvDiffReactOptModelCreator.hpp"
00002 #include "MoochoPack_MoochoThyraSolver.hpp"
00003 #include "Thyra_EpetraModelEvaluator.hpp"
00004 #include "Thyra_DefaultSpmdMultiVectorFileIO.hpp"
00005 #include "Stratimikos_DefaultLinearSolverBuilder.hpp"
00006 #include "Teuchos_GlobalMPISession.hpp"
00007 #include "Teuchos_CommandLineProcessor.hpp"
00008 #include "Teuchos_StandardCatchMacros.hpp"
00009 #include "Teuchos_VerboseObject.hpp"
00010 #include "Teuchos_XMLParameterListHelpers.hpp"
00011 #ifdef HAVE_MPI
00012 # include "Epetra_MpiComm.h"
00013 #else
00014 # include "Epetra_SerialComm.h"
00015 #endif
00016
00017 namespace {
00018
00019 typedef AbstractLinAlgPack::value_type Scalar;
00020
00021 }
00022
00023 int main( int argc, char* argv[] )
00024 {
00025 using Teuchos::rcp;
00026 using Teuchos::RCP;
00027 using Teuchos::OSTab;
00028 using MoochoPack::MoochoSolver;
00029 using MoochoPack::MoochoThyraSolver;
00030 using Teuchos::CommandLineProcessor;
00031
00032 Teuchos::GlobalMPISession mpiSession(&argc,&argv);
00033
00034 const int numProcs = mpiSession.getNProc();
00035
00036 Teuchos::Time timer("");
00037
00038 bool dummySuccess = true;
00039
00040 Teuchos::RCP<Teuchos::FancyOStream>
00041 out = Teuchos::VerboseObjectBase::getDefaultOStream();
00042
00043 try {
00044
00045
00046 GLpApp::AdvDiffReactOptModelCreator advDiffReacModelCreator;
00047 Stratimikos::DefaultLinearSolverBuilder lowsfCreator;
00048 MoochoThyraSolver solver;
00049
00050
00051
00052
00053
00054 std::string matchingVecFile = "";
00055
00056 bool showMoochoThyraParams = false;
00057 bool showMoochoThyraParamsWithDoc = true;
00058 bool showMoochoThyraParamsXML = false;
00059
00060 CommandLineProcessor clp;
00061 clp.throwExceptions(false);
00062 clp.addOutputSetupOptions(true);
00063
00064 advDiffReacModelCreator.setupCLP(&clp);
00065 lowsfCreator.setupCLP(&clp);
00066 solver.setupCLP(&clp);
00067
00068 clp.setOption(
00069 "q-vec-file", &matchingVecFile
00070 ,"Base file name to read the objective state matching "
00071 "vector q (i.e. ||x-q||_M in the objective)."
00072 );
00073
00074 clp.setOption(
00075 "only-print-moocho-thyra-solver-params", "no-print-moocho-thyra-solver-params"
00076 ,&showMoochoThyraParams
00077 ,"Only print the parameters accepted by MoochoPack::MoochoThyraSolver and stop."
00078 );
00079 clp.setOption(
00080 "show-doc", "hide-doc", &showMoochoThyraParamsWithDoc
00081 ,"Show MoochoPack::MocohoThyraSolver parameters with documentation or not."
00082 );
00083 clp.setOption(
00084 "xml-format", "readable-format", &showMoochoThyraParamsXML
00085 ,"Show MoochoPack::MoochoThyraSolver parameters in XML or human-readable format."
00086 );
00087
00088 CommandLineProcessor::EParseCommandLineReturn
00089 parse_return = clp.parse(argc,argv,&std::cerr);
00090
00091 if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00092 return parse_return;
00093
00094 lowsfCreator.readParameters( !showMoochoThyraParams ? out.get() : NULL );
00095 solver.readParameters( !showMoochoThyraParams ? out.get() : NULL );
00096
00097 if(showMoochoThyraParams) {
00098 typedef Teuchos::ParameterList::PrintOptions PLPrintOptions;
00099 if(showMoochoThyraParamsXML)
00100 Teuchos::writeParameterListToXmlOStream(
00101 *solver.getValidParameters()
00102 ,*out
00103 );
00104 else
00105 solver.getValidParameters()->print(
00106 *out,PLPrintOptions().indent(2).showTypes(true).showDoc(showMoochoThyraParamsWithDoc)
00107 );
00108 return 0;
00109 }
00110
00111
00112
00113
00114
00115 Teuchos::RCP<Teuchos::FancyOStream>
00116 journalOut = Teuchos::rcp(
00117 new Teuchos::FancyOStream(
00118 solver.getSolver().generate_output_file("MoochoJournal")
00119 ," "
00120 )
00121 );
00122 journalOut->copyAllOutputOptions(*out);
00123
00124 *out
00125 << "\n***"
00126 << "\n*** NLPThyraEpetraAdvDiffReactOptMain, Global numProcs = "<<numProcs
00127 << "\n***\n";
00128
00129 #ifdef HAVE_MPI
00130 MPI_Comm mpiComm = MPI_COMM_WORLD;
00131 #endif
00132
00133 Teuchos::RCP<Epetra_Comm> comm = Teuchos::null;
00134 #ifdef HAVE_MPI
00135 comm = Teuchos::rcp(new Epetra_MpiComm(mpiComm));
00136 #else
00137 comm = Teuchos::rcp(new Epetra_SerialComm());
00138 #endif
00139
00140
00141
00142
00143
00144 *out << "\nCreate the GLpApp::AdvDiffReactOptModel wrapper object ...\n";
00145
00146 Teuchos::RCP<GLpApp::AdvDiffReactOptModel>
00147 epetraModel = advDiffReacModelCreator.createModel(comm);
00148 epetraModel->setOStream(journalOut);
00149
00150 *out << "\nCreate the Thyra::LinearOpWithSolveFactory object ...\n";
00151
00152 Teuchos::RCP<Thyra::LinearOpWithSolveFactoryBase<Scalar> >
00153 lowsFactory = lowsfCreator.createLinearSolveStrategy("");
00154
00156
00157 *out << "\nCreate the Thyra::EpetraModelEvaluator wrapper object ...\n";
00158
00159 Teuchos::RCP<Thyra::EpetraModelEvaluator>
00160 epetraThyraModel = rcp(new Thyra::EpetraModelEvaluator());
00161 epetraThyraModel->setOStream(journalOut);
00162 epetraThyraModel->initialize(epetraModel,lowsFactory);
00163
00164 *out
00165 << "\nnx = " << epetraThyraModel->get_x_space()->dim()
00166 << "\nnp = " << epetraThyraModel->get_p_space(0)->dim() << "\n";
00167
00168 if(matchingVecFile != "") {
00169 *out << "\nReading the matching vector \'q\' from the file(s) with base name \""<<matchingVecFile<<"\" ...\n";
00170 Thyra::DefaultSpmdMultiVectorFileIO<Scalar> fileIO;
00171 epetraModel->set_q(
00172 Thyra::get_Epetra_Vector(
00173 *epetraModel->get_x_map()
00174 ,readVectorFromFile(fileIO,matchingVecFile,*epetraThyraModel->get_x_space())
00175 )
00176 );
00177 }
00178
00179
00180
00181
00182
00183
00184 solver.getSolver().set_journal_out(journalOut);
00185
00186
00187 solver.setModel(epetraThyraModel);
00188
00189
00190 solver.readInitialGuess(out.get());
00191
00192
00193 const MoochoSolver::ESolutionStatus solution_status = solver.solve();
00194
00195
00196 solver.writeFinalSolution(out.get());
00197
00198
00199 lowsfCreator.writeParamsFile(*lowsFactory);
00200 solver.writeParamsFile();
00201
00202
00203
00204
00205
00206 if(solution_status == MoochoSolver::SOLVE_RETURN_SOLVED)
00207 *out << "\nEnd Result: TEST PASSED\n";
00208 else
00209 *out << "\nEnd Result: TEST FAILED\n";
00210
00211 return solution_status;
00212
00213 }
00214 TEUCHOS_STANDARD_CATCH_STATEMENTS(true,*out,dummySuccess)
00215
00216 return MoochoSolver::SOLVE_RETURN_EXCEPTION;
00217
00218 }