FEI  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
LibraryFactory.cpp
1 /*--------------------------------------------------------------------*/
2 /* Copyright 2005 Sandia Corporation. */
3 /* Under the terms of Contract DE-AC04-94AL85000, there is a */
4 /* non-exclusive license for use of this work by or on behalf */
5 /* of the U.S. Government. Export of this program may require */
6 /* a license from the United States Government. */
7 /*--------------------------------------------------------------------*/
8 
9 #include <fei_macros.hpp>
10 
11 #include <fei_mpi.h>
12 
13 #include <test_utils/LibraryFactory.hpp>
14 
15 #include <fei_LibraryWrapper.hpp>
16 
17 #include <snl_fei_Factory.hpp>
18 
19 #include <fei_Factory_Trilinos.hpp>
20 #ifdef HAVE_FEI_AZTECOO
21 #include <fei_Aztec_LinSysCore.hpp>
22 #endif
23 
24 #ifdef HAVE_FEI_FETI
25 #include <FETI_DP_FiniteElementData.h>
26 #endif
27 
28 //----------------------------------------------------------------------------
30 fei::create_LibraryWrapper(MPI_Comm comm,
31  const char* libraryName)
32 {
33  std::string libname(libraryName);
34 
38 
39  if (libname == "Aztec") {
40 #ifdef HAVE_FEI_AZTECOO
41  lsc.reset(new fei_trilinos::Aztec_LinSysCore(comm));
42 #else
43  std::string msg("Aztec not available.");
44  throw std::runtime_error(msg);
45 #endif
46  }
47 
48  if (libname == "FETI") {
49 #ifdef HAVE_FEI_FETI
50  fedata.reset(new FETI_DP_FiniteElementData(comm));
51 #endif
52  }
53 
54  if (lsc.get() == NULL && fedata.get() == NULL) {
55  //libraryName not found
56  std::string msg("create_LibraryWrapper: ");
57  msg += libraryName;
58  msg += " not a valid name.";
59  throw std::runtime_error(msg);
60  }
61 
62  if (lsc.get() != NULL) {
63  wrapper.reset(new LibraryWrapper(lsc));
64  return(wrapper);
65  }
66 
67  if (fedata.get() != NULL) {
68  wrapper.reset(new LibraryWrapper(fedata));
69  return(wrapper);
70  }
71 
72  return(wrapper);
73 }
74 
75 //----------------------------------------------------------------------------
77 fei::create_fei_Factory(MPI_Comm comm,
78  const char* libraryName)
79 {
80  std::string libname(libraryName);
81 
82  if (libname.find("Trilinos") != std::string::npos) {
83  fei::SharedPtr<fei::Factory> factory(new Factory_Trilinos(comm));
84 
85  if (libname.find("Amesos") != std::string::npos) {
86  fei::ParameterSet paramset;
87  paramset.add(fei::Param("Trilinos_Solver", "Amesos"));
88  factory->parameters(paramset);
89  }
90  else if (libname.find("Aztec") != std::string::npos) {
91 
92  //if libname contains "AztecOO" we'll return the Trilinos factory
93  //but if libname only contains "Aztec" then we want to skip on down
94  //and return an snl_fei::Factory with a Aztec LibraryWrapper...
95 
96  if (libname.find("AztecOO") != std::string::npos) {
97  return(factory);
98  }
99  }
100  else {
101  //This else handles the case where libname contains "Trilinos", but
102  //doesn't contain "Aztec" or "Amesos"...
103  return(factory);
104  }
105  }
106 
108  try {
109  wrapper = fei::create_LibraryWrapper(comm, libraryName);
110  }
111  catch (std::runtime_error& exc) {
112  std::string msg("create_fei_Factory: ");
113  msg += exc.what();
114  throw std::runtime_error(msg);
115  }
116 
117  if (wrapper.get() != NULL) {
118  fei::SharedPtr<fei::Factory> factory(new snl_fei::Factory(comm, wrapper));
119  return(factory);
120  }
121 
123  return(empty);
124 }
125 
fei::SharedPtr< fei::Factory > create_fei_Factory(MPI_Comm comm, const char *libraryName)
void reset(T *p=0)
void add(const Param &param, bool maintain_unique_keys=true)
T * get() const
fei::SharedPtr< LibraryWrapper > create_LibraryWrapper(MPI_Comm comm, const char *libraryName)