AbstractLinAlgPack_exampleNLPDiagSetup.cpp

Go to the documentation of this file.
00001 // ////////////////////////////////////////////////////////////////////
00002 // AbstractLinAlgPack_exampleNLPDiagSetup.hpp
00003 
00004 #include <assert.h>
00005 
00006 #include <fstream>
00007 #include <fstream>
00008 #include <iostream>
00009 #include <iomanip>
00010 
00011 #include "AbstractLinAlgPack_exampleNLPDiagSetup.hpp"
00012 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp"
00013 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
00014 #include "Teuchos_CommandLineProcessor.hpp"
00015 
00016 #ifdef USE_EPETRA_THYRA
00017 
00018 #include "TSFCoreSerialVectorSpaceStd.hpp"
00019 #include "AbstractLinAlgPack_VectorSpaceTSFCore.hpp"
00020 #include "TSFCoreEpetraVectorSpace.hpp"
00021 #include "Epetra_Map.h"
00022 #ifdef HAVE_MPI
00023 #include "Epetra_MpiComm.h"
00024 #else
00025 #include "Epetra_SerialComm.h"
00026 #endif
00027 
00028 #endif // USE_EPETRA_THYRA
00029 
00031 int AbstractLinAlgPack::exampleNLPDiagSetup(
00032   int argc, char* argv[], MPI_Comm comm
00033   ,Teuchos::RCP<const VectorSpace>   *vec_space
00034   ,int *n, value_type *xo, bool *has_bounds, bool *dep_bounded
00035   )
00036 {
00037 
00038   using std::endl;
00039   using std::setw;
00040   namespace mmp = MemMngPack;
00041   using Teuchos::RCP;
00042   typedef AbstractLinAlgPack::size_type size_type;
00043   typedef AbstractLinAlgPack::value_type value_type;
00044 
00045   using AbstractLinAlgPack::VectorSpace;
00046   using AbstractLinAlgPack::Vector;
00047   using AbstractLinAlgPack::VectorMutable;
00048 
00049   using Teuchos::CommandLineProcessor;
00050 
00051   // Get an idea of what processors we have.
00052   int num_proc, proc_rank;
00053   MPI_Comm_size( comm, &num_proc );
00054   MPI_Comm_rank( comm, &proc_rank );
00055 
00056   // Get the size of the problem to solve
00057   *n = 4;
00058   // Get the starting point
00059   *xo = 0.1;
00060   // Determine if the NLP has bounds or not.
00061   *has_bounds = false;
00062   // Make the dependent or independent variables bounded.
00063   *dep_bounded = true;
00064 #ifdef USE_EPETRA_THYRA
00065   // Serial or parallel?
00066   bool in_parallel = false;
00067   // Use TSF?
00068   bool use_tsf = false;
00069 #endif // USE_EPETRA_THYRA
00070 
00071   CommandLineProcessor  command_line_processor;
00072   
00073   command_line_processor.setOption( "n",  n,   "Global number of dependent (and independent) variables" );
00074   command_line_processor.setOption( "xo", xo,  "Initial guess of the solution" );
00075   command_line_processor.setOption(
00076     "has-bounds", "no-has-bounds", has_bounds
00077     ,"Determine if the NLP has bounds or not" );
00078   command_line_processor.setOption(
00079     "dep-bounded", "indep-bounded", dep_bounded
00080     ,"Determine if the dependent or independent variables are bounded" );
00081 #ifdef USE_EPETRA_THYRA
00082   command_line_processor.setOption(
00083     "in-parallel", "in-serial", &in_parallel
00084     ,"Determine if computations are performed in parallel or not" );
00085   command_line_processor.setOption(
00086     "use-tsf", "no-use-tsf", &use_tsf
00087     ,"Determine whether to use TSF vectors or not" );
00088 #endif // USE_EPETRA_THYRA
00089   
00090   CommandLineProcessor::EParseCommandLineReturn
00091     parse_return = command_line_processor.parse(argc,argv,&std::cerr);
00092   
00093   if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00094     return parse_return;
00095 
00096   // Create the vector space object to use.
00097 
00098 #ifdef USE_EPETRA_THYRA
00099 
00100   using AbstractLinAlgPack::VectorSpaceTSFCore;
00101 
00102   if(in_parallel) {
00103     //
00104     // Use parallel vectors!
00105     //
00106     Teuchos::RCP<Epetra_Comm> comm;
00107 #ifdef HAVE_MPI
00108     comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
00109 #else
00110     comm = Teuchos::rcp(new Epetra_SerialComm());
00111 #endif
00112     Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(new Epetra_Map(*n,0,*comm));
00113     Teuchos::set_extra_data(comm, "comm", Teuchos::outArg(map));
00114     *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::EpetraVectorSpace(map))));
00115   }
00116   else {
00117     //
00118     // Use serial vectors
00119     //
00120     if( use_tsf ) {
00121       *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::SerialVectorSpaceStd<value_type>(*n))));
00122     }
00123     else {
00124       *vec_space = Teuchos::rcp(new AbstractLinAlgPack::VectorSpaceSerial(*n));
00125     }
00126   }
00127 
00128 #else // USE_EPETRA_THYRA
00129 
00130   *vec_space = Teuchos::rcp(new AbstractLinAlgPack::VectorSpaceSerial(*n));
00131 
00132 #endif // USE_EPETRA_THYRA
00133   
00134   return 0;
00135 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:10:56 2011 for MOOCHO (Single Doxygen Collection) by  doxygen 1.6.3