00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef IFPACK_DYNAMIC_FACTORY_H
00031 #define IFPACK_DYNAMIC_FACTORY_H
00032
00033 #include <ostream>
00034 #include <string>
00035 #include <map>
00036 #include <algorithm>
00037
00038 #include "Ifpack_ConfigDefs.h"
00039 #include "Ifpack_Preconditioner.h"
00040 #include "Teuchos_iostream_helpers.hpp"
00041 #include "Ifpack_AdditiveSchwarz.h"
00042
00043
00044 #ifdef HAVE_HYPRE
00045 #include "Ifpack_Hypre.h"
00046 #endif
00047
00048
00050
00057 class Ifpack_DynamicFactory {
00058 public:
00059
00060 typedef Ifpack_Preconditioner* (*builderFunction)(Epetra_RowMatrix*, int, bool, bool);
00061
00076 Ifpack_Preconditioner* Create(const string PrecType,
00077 Epetra_RowMatrix* Matrix,
00078 const int overlap = 0,
00079 bool overrideSerialDefault = false);
00080
00081
00087 static bool Initialize();
00088
00097 static int RegisterPreconditioner(const std::string PrecName,
00098 builderFunction PrecBuilder);
00099
00100
00104 static void Print(std::ostream& os = std::cout);
00105
00106
00107 template <typename PrecType, bool StandAlone>
00108 static Ifpack_Preconditioner* buildPreconditioner(Epetra_RowMatrix* Matrix,
00109 int Overlap,
00110 bool Serial,
00111 bool OverrideSerialDefault);
00112
00113 private:
00114 static std::map<std::string, builderFunction> PreconditionerMap_;
00115 static int NumPreconditioners_;
00116 static bool Initialized_;
00117 };
00118
00119
00120 template <typename PrecType, bool StandAlone>
00121 Ifpack_Preconditioner*
00122 Ifpack_DynamicFactory::buildPreconditioner(Epetra_RowMatrix* Matrix,
00123 int Overlap,
00124 bool Serial,
00125 bool OverrideSerialDefault)
00126 {
00127 if (StandAlone || (Serial && !OverrideSerialDefault)) {
00128 return new PrecType(Matrix);
00129 } else {
00130 return new Ifpack_AdditiveSchwarz<PrecType>(Matrix, Overlap);
00131 }
00132 }
00133
00134 #endif // IFPACK_DYNAMIC_FACTORY_H