LibraryFactory.cpp

00001 /*--------------------------------------------------------------------*/
00002 /*    Copyright 2005 Sandia Corporation.                              */
00003 /*    Under the terms of Contract DE-AC04-94AL85000, there is a       */
00004 /*    non-exclusive license for use of this work by or on behalf      */
00005 /*    of the U.S. Government.  Export of this program may require     */
00006 /*    a license from the United States Government.                    */
00007 /*--------------------------------------------------------------------*/
00008 
00009 #include <fei_macros.hpp>
00010 
00011 #include <fei_mpi.h>
00012 
00013 #include <test_utils/LibraryFactory.hpp>
00014 
00015 #include <fei_LibraryWrapper.hpp>
00016 
00017 #include <snl_fei_Factory.hpp>
00018 
00019 #include <fei_Factory_Trilinos.hpp>
00020 #ifdef HAVE_FEI_AZTECOO
00021 #include <fei_Aztec_LinSysCore.hpp>
00022 #endif
00023 
00024 #ifdef HAVE_FEI_FETI
00025 #include <FETI_DP_FiniteElementData.h>
00026 #endif
00027 
00028 //----------------------------------------------------------------------------
00029 fei::SharedPtr<LibraryWrapper>
00030 fei::create_LibraryWrapper(MPI_Comm comm,
00031              const char* libraryName)
00032 {
00033   std::string libname(libraryName);
00034 
00035   fei::SharedPtr<LinearSystemCore> lsc;
00036   fei::SharedPtr<FiniteElementData> fedata;
00037   fei::SharedPtr<LibraryWrapper> wrapper;
00038 
00039   if (libname == "Aztec") {
00040 #ifdef HAVE_FEI_AZTECOO
00041     lsc.reset(new fei_trilinos::Aztec_LinSysCore(comm));
00042 #else
00043     std::string msg("Aztec not available.");
00044     throw std::runtime_error(msg);
00045 #endif
00046   }
00047 
00048   if (libname == "FETI") {
00049 #ifdef HAVE_FEI_FETI
00050     fedata.reset(new FETI_DP_FiniteElementData(comm));
00051 #endif
00052   }
00053 
00054   if (lsc.get() == NULL && fedata.get() == NULL) {
00055     //libraryName not found
00056     std::string msg("create_LibraryWrapper: ");
00057     msg += libraryName;
00058     msg += " not a valid name.";
00059     throw std::runtime_error(msg);
00060   }
00061 
00062   if (lsc.get() != NULL) {
00063     wrapper.reset(new LibraryWrapper(lsc));
00064     return(wrapper);
00065   }
00066 
00067   if (fedata.get() != NULL) {
00068     wrapper.reset(new LibraryWrapper(fedata));
00069     return(wrapper);
00070   }
00071 
00072   return(wrapper);
00073 }
00074 
00075 //----------------------------------------------------------------------------
00076 fei::SharedPtr<fei::Factory>
00077 fei::create_fei_Factory(MPI_Comm comm,
00078           const char* libraryName)
00079 {
00080   std::string libname(libraryName);
00081 
00082   if (libname.find("Trilinos") != std::string::npos) {
00083     fei::SharedPtr<fei::Factory> factory(new Factory_Trilinos(comm));
00084 
00085     if (libname.find("Amesos") != std::string::npos) {
00086       fei::ParameterSet paramset;
00087       paramset.add(fei::Param("Trilinos_Solver", "Amesos"));
00088       factory->parameters(paramset);
00089     }
00090     else if (libname.find("Aztec") != std::string::npos) {
00091 
00092       //if libname contains "AztecOO" we'll return the Trilinos factory
00093       //but if libname only contains "Aztec" then we want to skip on down
00094       //and return an snl_fei::Factory with a Aztec LibraryWrapper...
00095 
00096       if (libname.find("AztecOO") != std::string::npos) {
00097         return(factory);
00098       }
00099     }
00100     else {
00101       //This else handles the case where libname contains "Trilinos", but
00102       //doesn't contain "Aztec" or "Amesos"...
00103       return(factory);
00104     }
00105   }
00106 
00107   fei::SharedPtr<LibraryWrapper> wrapper;
00108   try {
00109     wrapper = fei::create_LibraryWrapper(comm, libraryName);
00110   }
00111   catch (std::runtime_error& exc) {
00112     std::string msg("create_fei_Factory: ");
00113     msg += exc.what();
00114     throw std::runtime_error(msg);
00115   }
00116 
00117   if (wrapper.get() != NULL) {
00118     fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm, wrapper));
00119     return(factory);
00120   }
00121 
00122   fei::SharedPtr<fei::Factory> empty;
00123   return(empty);
00124 }
00125 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Friends
Generated on Wed Apr 13 10:08:24 2011 for FEI by  doxygen 1.6.3