FEI Version of the Day
LibraryFactory.cpp
00001 /*
00002 // @HEADER
00003 // ************************************************************************
00004 //             FEI: Finite Element Interface to Linear Solvers
00005 //                  Copyright (2005) Sandia Corporation.
00006 //
00007 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, the
00008 // U.S. Government retains certain rights in this software.
00009 //
00010 // Redistribution and use in source and binary forms, with or without
00011 // modification, are permitted provided that the following conditions are
00012 // met:
00013 //
00014 // 1. Redistributions of source code must retain the above copyright
00015 // notice, this list of conditions and the following disclaimer.
00016 //
00017 // 2. Redistributions in binary form must reproduce the above copyright
00018 // notice, this list of conditions and the following disclaimer in the
00019 // documentation and/or other materials provided with the distribution.
00020 //
00021 // 3. Neither the name of the Corporation nor the names of the
00022 // contributors may be used to endorse or promote products derived from
00023 // this software without specific prior written permission.
00024 //
00025 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
00026 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00027 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
00028 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
00029 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00030 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00031 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
00032 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00033 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
00034 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
00035 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00036 //
00037 // Questions? Contact Alan Williams (william@sandia.gov) 
00038 //
00039 // ************************************************************************
00040 // @HEADER
00041 */
00042 
00043 
00044 #include <fei_macros.hpp>
00045 
00046 #include <fei_mpi.h>
00047 
00048 #include <test_utils/LibraryFactory.hpp>
00049 
00050 #include <fei_LibraryWrapper.hpp>
00051 
00052 #include <snl_fei_Factory.hpp>
00053 
00054 #include <fei_Factory_Trilinos.hpp>
00055 #ifdef HAVE_FEI_AZTECOO
00056 #include <fei_Aztec_LinSysCore.hpp>
00057 #endif
00058 
00059 #ifdef HAVE_FEI_FETI
00060 #include <FETI_DP_FiniteElementData.h>
00061 #endif
00062 
00063 //----------------------------------------------------------------------------
00064 fei::SharedPtr<LibraryWrapper>
00065 fei::create_LibraryWrapper(MPI_Comm comm,
00066              const char* libraryName)
00067 {
00068   std::string libname(libraryName);
00069 
00070   fei::SharedPtr<LinearSystemCore> lsc;
00071   fei::SharedPtr<FiniteElementData> fedata;
00072   fei::SharedPtr<LibraryWrapper> wrapper;
00073 
00074   if (libname == "Aztec") {
00075 #ifdef HAVE_FEI_AZTECOO
00076     lsc.reset(new fei_trilinos::Aztec_LinSysCore(comm));
00077 #else
00078     std::string msg("Aztec not available.");
00079     throw std::runtime_error(msg);
00080 #endif
00081   }
00082 
00083   if (libname == "FETI") {
00084 #ifdef HAVE_FEI_FETI
00085     fedata.reset(new FETI_DP_FiniteElementData(comm));
00086 #endif
00087   }
00088 
00089   if (lsc.get() == NULL && fedata.get() == NULL) {
00090     //libraryName not found
00091     std::string msg("create_LibraryWrapper: ");
00092     msg += libraryName;
00093     msg += " not a valid name.";
00094     throw std::runtime_error(msg);
00095   }
00096 
00097   if (lsc.get() != NULL) {
00098     wrapper.reset(new LibraryWrapper(lsc));
00099     return(wrapper);
00100   }
00101 
00102   if (fedata.get() != NULL) {
00103     wrapper.reset(new LibraryWrapper(fedata));
00104     return(wrapper);
00105   }
00106 
00107   return(wrapper);
00108 }
00109 
00110 //----------------------------------------------------------------------------
00111 fei::SharedPtr<fei::Factory>
00112 fei::create_fei_Factory(MPI_Comm comm,
00113           const char* libraryName)
00114 {
00115   std::string libname(libraryName);
00116 
00117   if (libname.find("Trilinos") != std::string::npos) {
00118     fei::SharedPtr<fei::Factory> factory(new Factory_Trilinos(comm));
00119 
00120     if (libname.find("Amesos") != std::string::npos) {
00121       fei::ParameterSet paramset;
00122       paramset.add(fei::Param("Trilinos_Solver", "Amesos"));
00123       factory->parameters(paramset);
00124     }
00125     else if (libname.find("Aztec") != std::string::npos) {
00126 
00127       //if libname contains "AztecOO" we'll return the Trilinos factory
00128       //but if libname only contains "Aztec" then we want to skip on down
00129       //and return an snl_fei::Factory with a Aztec LibraryWrapper...
00130 
00131       if (libname.find("AztecOO") != std::string::npos) {
00132         return(factory);
00133       }
00134     }
00135     else {
00136       //This else handles the case where libname contains "Trilinos", but
00137       //doesn't contain "Aztec" or "Amesos"...
00138       return(factory);
00139     }
00140   }
00141 
00142   fei::SharedPtr<LibraryWrapper> wrapper;
00143   try {
00144     wrapper = fei::create_LibraryWrapper(comm, libraryName);
00145   }
00146   catch (std::runtime_error& exc) {
00147     std::string msg("create_fei_Factory: ");
00148     msg += exc.what();
00149     throw std::runtime_error(msg);
00150   }
00151 
00152   if (wrapper.get() != NULL) {
00153     fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm, wrapper));
00154     return(factory);
00155   }
00156 
00157   fei::SharedPtr<fei::Factory> empty;
00158   return(empty);
00159 }
00160 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends