MOOCHO (Single Doxygen Collection) Version of the Day
AbstractLinAlgPack_exampleNLPDiagSetup.cpp
Go to the documentation of this file.
00001 /*
00002 // @HEADER
00003 // ***********************************************************************
00004 // 
00005 // Moocho: Multi-functional Object-Oriented arCHitecture for Optimization
00006 //                  Copyright (2003) Sandia Corporation
00007 // 
00008 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
00009 // license for use of this work by or on behalf of the U.S. Government.
00010 // 
00011 // Redistribution and use in source and binary forms, with or without
00012 // modification, are permitted provided that the following conditions are
00013 // met:
00014 //
00015 // 1. Redistributions of source code must retain the above copyright
00016 // notice, this list of conditions and the following disclaimer.
00017 //
00018 // 2. Redistributions in binary form must reproduce the above copyright
00019 // notice, this list of conditions and the following disclaimer in the
00020 // documentation and/or other materials provided with the distribution.
00021 //
00022 // 3. Neither the name of the Corporation nor the names of the
00023 // contributors may be used to endorse or promote products derived from
00024 // this software without specific prior written permission.
00025 //
00026 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00027 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00028 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00029 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00030 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00031 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00032 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00033 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00034 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00035 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00036 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00037 //
00038 // Questions? Contact Roscoe A. Bartlett (rabartl@sandia.gov) 
00039 // 
00040 // ***********************************************************************
00041 // @HEADER
00042 */
00043 
00044 // ////////////////////////////////////////////////////////////////////
00045 // AbstractLinAlgPack_exampleNLPDiagSetup.hpp
00046 
00047 #include <assert.h>
00048 
00049 #include <fstream>
00050 #include <fstream>
00051 #include <iostream>
00052 #include <iomanip>
00053 
00054 #include "AbstractLinAlgPack_exampleNLPDiagSetup.hpp"
00055 #include "AbstractLinAlgPack_VectorSpaceSerial.hpp"
00056 #include "OptionsFromStreamPack_OptionsFromStream.hpp"
00057 #include "Teuchos_CommandLineProcessor.hpp"
00058 
00059 #ifdef USE_EPETRA_THYRA
00060 
00061 #include "TSFCoreSerialVectorSpaceStd.hpp"
00062 #include "AbstractLinAlgPack_VectorSpaceTSFCore.hpp"
00063 #include "TSFCoreEpetraVectorSpace.hpp"
00064 #include "Epetra_Map.h"
00065 #ifdef HAVE_MPI
00066 #include "Epetra_MpiComm.h"
00067 #else
00068 #include "Epetra_SerialComm.h"
00069 #endif
00070 
00071 #endif // USE_EPETRA_THYRA
00072 
00074 int AbstractLinAlgPack::exampleNLPDiagSetup(
00075   int argc, char* argv[], MPI_Comm comm
00076   ,Teuchos::RCP<const VectorSpace>   *vec_space
00077   ,int *n, value_type *xo, bool *has_bounds, bool *dep_bounded
00078   )
00079 {
00080 
00081   using std::endl;
00082   using std::setw;
00083   namespace mmp = MemMngPack;
00084   using Teuchos::RCP;
00085   typedef AbstractLinAlgPack::size_type size_type;
00086   typedef AbstractLinAlgPack::value_type value_type;
00087 
00088   using AbstractLinAlgPack::VectorSpace;
00089   using AbstractLinAlgPack::Vector;
00090   using AbstractLinAlgPack::VectorMutable;
00091 
00092   using Teuchos::CommandLineProcessor;
00093 
00094   // Get an idea of what processors we have.
00095   int num_proc, proc_rank;
00096   MPI_Comm_size( comm, &num_proc );
00097   MPI_Comm_rank( comm, &proc_rank );
00098 
00099   // Get the size of the problem to solve
00100   *n = 4;
00101   // Get the starting point
00102   *xo = 0.1;
00103   // Determine if the NLP has bounds or not.
00104   *has_bounds = false;
00105   // Make the dependent or independent variables bounded.
00106   *dep_bounded = true;
00107 #ifdef USE_EPETRA_THYRA
00108   // Serial or parallel?
00109   bool in_parallel = false;
00110   // Use TSF?
00111   bool use_tsf = false;
00112 #endif // USE_EPETRA_THYRA
00113 
00114   CommandLineProcessor  command_line_processor;
00115   
00116   command_line_processor.setOption( "n",  n,   "Global number of dependent (and independent) variables" );
00117   command_line_processor.setOption( "xo", xo,  "Initial guess of the solution" );
00118   command_line_processor.setOption(
00119     "has-bounds", "no-has-bounds", has_bounds
00120     ,"Determine if the NLP has bounds or not" );
00121   command_line_processor.setOption(
00122     "dep-bounded", "indep-bounded", dep_bounded
00123     ,"Determine if the dependent or independent variables are bounded" );
00124 #ifdef USE_EPETRA_THYRA
00125   command_line_processor.setOption(
00126     "in-parallel", "in-serial", &in_parallel
00127     ,"Determine if computations are performed in parallel or not" );
00128   command_line_processor.setOption(
00129     "use-tsf", "no-use-tsf", &use_tsf
00130     ,"Determine whether to use TSF vectors or not" );
00131 #endif // USE_EPETRA_THYRA
00132   
00133   CommandLineProcessor::EParseCommandLineReturn
00134     parse_return = command_line_processor.parse(argc,argv,&std::cerr);
00135   
00136   if( parse_return != CommandLineProcessor::PARSE_SUCCESSFUL )
00137     return parse_return;
00138 
00139   // Create the vector space object to use.
00140 
00141 #ifdef USE_EPETRA_THYRA
00142 
00143   using AbstractLinAlgPack::VectorSpaceTSFCore;
00144 
00145   if(in_parallel) {
00146     //
00147     // Use parallel vectors!
00148     //
00149     Teuchos::RCP<Epetra_Comm> comm;
00150 #ifdef HAVE_MPI
00151     comm = Teuchos::rcp(new Epetra_MpiComm(MPI_COMM_WORLD));
00152 #else
00153     comm = Teuchos::rcp(new Epetra_SerialComm());
00154 #endif
00155     Teuchos::RCP<Epetra_Map> map = Teuchos::rcp(new Epetra_Map(*n,0,*comm));
00156     Teuchos::set_extra_data(comm, "comm", Teuchos::outArg(map));
00157     *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::EpetraVectorSpace(map))));
00158   }
00159   else {
00160     //
00161     // Use serial vectors
00162     //
00163     if( use_tsf ) {
00164       *vec_space = Teuchos::rcp(new VectorSpaceTSFCore(Teuchos::rcp(new TSFCore::SerialVectorSpaceStd<value_type>(*n))));
00165     }
00166     else {
00167       *vec_space = Teuchos::rcp(new AbstractLinAlgPack::VectorSpaceSerial(*n));
00168     }
00169   }
00170 
00171 #else // USE_EPETRA_THYRA
00172 
00173   *vec_space = Teuchos::rcp(new AbstractLinAlgPack::VectorSpaceSerial(*n));
00174 
00175 #endif // USE_EPETRA_THYRA
00176   
00177   return 0;
00178 }
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines