Commit 96f0d91c authored by Dmitry Bagaev's avatar Dmitry Bagaev

New SolverMaster

parent 5f727ce4
......@@ -31,7 +31,7 @@ namespace INMOST {
public:
SolverInterface() {};
SolverInterface(const SolverInterface *other) {};
virtual SolverInterface *Copy(const SolverInterface *other) = 0;
virtual void Assign(const SolverInterface *other) = 0;
......
......@@ -2,38 +2,74 @@
namespace INMOST {
std::map<std::string, SolverBaseFactory *> SolverMaster::solvers = std::map<std::string, SolverBaseFactory *>();
SolverInterface *SolverMaster::getSolver(std::string name) {
solvers_map_iterator_t iterator = SolverMaster::solvers.find(name);
if (iterator != SolverMaster::solvers.end()) {
return iterator->second->create();
} else {
throw INMOST::SolverNotFound;
}
}
SolverInterface *SolverMaster::copySolver(const SolverInterface *other) {
solvers_map_iterator_t iterator = SolverMaster::solvers.find(other->SolverName());
if (iterator != SolverMaster::solvers.end()) {
return iterator->second->copy(other);
} else {
throw INMOST::SolverNotFound;
}
if (name == "inner_ilu2") return new SolverILU2();
if (name == "inner_ddpqiluc2") return new SolverDDPQILUC2();
if (name == "inner_mptiluc") return new SolverMPTILUC();
if (name == "inner_mptilu2") return new SolverMPTILU2();
#if defined(USE_SOLVER_PETSC)
if (name == "petsc") return new SolverPETSc();
#endif
#if defined(USE_SOLVER_TRILINOS) && defined(USE_MPI)
if (name == "trilinos_aztec") return new SolverTrilinosAztec();
if (name == "trilinos_belos") return new SolverTrilinosBelos();
if (name == "trilinos_ml") return new SolverTrilinosML();
if (name == "trilinos_ifpack") return new SolverTrilinosIfpack();
#endif
#if defined(USE_SOLVER_ANI)
if (name == "ani") return new SolverANI();
#endif
#if defined(USE_SOLVER_SUPERLU)
if (name == "superlu") return new SolverSUPERLU();
#endif
#if defined(HAVE_SOLVER_K3BIILU2)
if (name == "k3biilu2") return new SolverK3BIILU2();
#endif
#if defined(HAVE_SOLVER_FCBIILU2)
if (name == "fcbiilu2") return new SolverFCBIILU2();
#endif
throw INMOST::SolverNotFound;
}
std::vector<std::string> SolverMaster::getAvailableSolvers() {
std::vector<std::string> s;
for (solvers_map_iterator_t bi = SolverMaster::solvers.begin(); bi != SolverMaster::solvers.end(); bi++) {
s.push_back(bi->first);
}
s.push_back("inner_ilu2");
s.push_back("inner_ddpqiluc2");
s.push_back("inner_mptiluc");
s.push_back("inner_mptilu2");
#if defined(USE_SOLVER_PETSC)
s.push_back("petsc");
#endif
#if defined(USE_SOLVER_TRILINOS) && defined(USE_MPI)
s.push_back("trilinos_aztec");
s.push_back("trilinos_belos");
s.push_back("trilinos_ml");
s.push_back("trilinos_ifpack");
#endif
#if defined(USE_SOLVER_ANI)
s.push_back("ani");
#endif
#if defined(USE_SOLVER_SUPERLU)
s.push_back("superlu");
#endif
#if defined(HAVE_SOLVER_K3BIILU2)
s.push_back("k3biilu2");
#endif
#if defined(HAVE_SOLVER_FCBIILU2)
s.push_back("fcbiilu2");
#endif
return s;
}
bool SolverMaster::isSolverAvailable(std::string name) {
return SolverMaster::solvers.find(name) != SolverMaster::solvers.end();
try {
SolverInterface *s = SolverMaster::getSolver(name);
delete s;
return true;
} catch (...) {
return false;
}
}
}
......@@ -4,39 +4,57 @@
#include <inmost_solver.h>
#include <inmost_solver_interface.h>
namespace INMOST {
#include "SolverMaster.h"
#include "solver_inner/solver_ilu2/SolverILU2.h"
#include "solver_inner/solver_ddpqiluc2/SolverDDPQILUC2.h"
#include "solver_inner/solver_mptiluc/SolverMPTILUC.h"
#include "solver_inner/solver_mptilu2/SolverMPTILU2.h"
struct SolverBaseFactory {
virtual SolverInterface *create() = 0;
#if defined(USE_SOLVER_PETSC)
virtual SolverInterface *copy(const SolverInterface *other) = 0;
#include "solver_petsc/SolverPETSc.h"
virtual ~SolverBaseFactory() {};
};
#endif
template<class C>
struct SolverCreateFactory : SolverBaseFactory {
SolverInterface *create() {
return new C();
};
#if defined(USE_SOLVER_TRILINOS) && defined(USE_MPI)
SolverInterface *copy(const SolverInterface *other) {
return new C(other);
};
};
#include "solver_trilinos/SolverTrilinos.h"
#include "solver_trilinos/solver_aztec/SolverTrilinosAztec.h"
#include "solver_trilinos/solver_belos/SolverTrilinosBelos.h"
#include "solver_trilinos/solver_ml/SolverTrilinosML.h"
#include "solver_trilinos/solver_ifpack/SolverTrilinosIfpack.h"
class SolverMaster {
private:
static std::map<std::string, SolverBaseFactory *> solvers;
#endif
template<class T>
static void registerSolver(std::string name) {
solvers.insert(std::make_pair(name, new SolverCreateFactory<T>));
};
#if defined(USE_SOLVER_ANI)
static SolverInterface *getSolver(std::string name);
#include "solver_ani/SolverANI.h"
#endif
#if defined(USE_SOLVER_SUPERLU)
#include "solver_superlu/SolverSUPERLU.h"
#endif
#if defined(HAVE_SOLVER_K3BIILU2)
static SolverInterface *copySolver(const SolverInterface *other);
#include "solver_k3biilu2/SolverK3BIILU2.h"
#endif
#if defined(HAVE_SOLVER_FCBIILU2)
#include "solver_fcbiilu2/SolverFCBIILU2.h"
#endif
namespace INMOST {
class SolverMaster {
private:
static SolverInterface *getSolver(std::string name);
static std::vector<std::string> getAvailableSolvers();
......@@ -52,8 +70,6 @@ namespace INMOST {
friend std::vector<std::string> Solver::getAvailableSolvers();
};
typedef std::map<std::string, SolverBaseFactory *>::iterator solvers_map_iterator_t;
}
#endif //INMOST_SOLVER_MASTER
#include <inmost.h>
#include "SolverMaster.h"
#include "solver_inner/solver_ilu2/SolverILU2.h"
#include "solver_inner/solver_ddpqiluc2/SolverDDPQILUC2.h"
#include "solver_inner/solver_mptiluc/SolverMPTILUC.h"
#include "solver_inner/solver_mptilu2/SolverMPTILU2.h"
#if defined(USE_SOLVER_PETSC)
#include "solver_petsc/SolverPETSc.h"
#endif
#if defined(USE_SOLVER_TRILINOS) && defined(USE_MPI)
#include "solver_trilinos/SolverTrilinos.h"
#include "solver_trilinos/solver_aztec/SolverTrilinosAztec.h"
#include "solver_trilinos/solver_belos/SolverTrilinosBelos.h"
#include "solver_trilinos/solver_ml/SolverTrilinosML.h"
#include "solver_trilinos/solver_ifpack/SolverTrilinosIfpack.h"
#endif
#if defined(USE_SOLVER_ANI)
#include "solver_ani/SolverANI.h"
#endif
#if defined(USE_SOLVER_SUPERLU)
#include "solver_superlu/SolverSUPERLU.h"
#endif
#if defined(HAVE_SOLVER_K3BIILU2)
#include "solver_k3biilu2/SolverK3BIILU2.h"
#endif
#if defined(HAVE_SOLVER_FCBIILU2)
#include "Source/Utils/Utils.h"
#include "solver_fcbiilu2/SolverFCBIILU2.h"
#endif
namespace INMOST {
......@@ -56,7 +13,7 @@ namespace INMOST {
Solver::Solver(std::string solverName, std::string prefix, INMOST_MPI_Comm _comm) {
std::string lowerName = string_to_lower(solverName);
this->solver = SolverMaster::getSolver(lowerName);
this->solver = SolverMaster::getSolver(solverName);
this->prefix = string_to_lower(prefix);
solver->SetCommunicator(_comm);
//TODO find easiest way
......@@ -78,7 +35,8 @@ namespace INMOST {
}
Solver::Solver(const Solver &other) {
this->solver = SolverMaster::copySolver(other.solver);
this->solver = SolverMaster::getSolver(other.solver->SolverName());
this->solver->Copy(other.solver);
this->prefix = other.prefix;
solver->SetCommunicator(other.solver->GetCommunicator());
//TODO find easiest way
......@@ -132,45 +90,8 @@ namespace INMOST {
}
}
}
#endif
//Register all available solvers
SolverMaster::registerSolver<SolverILU2>("inner_ilu2");
SolverMaster::registerSolver<SolverDDPQILUC2>("inner_ddpqiluc2");
SolverMaster::registerSolver<SolverMPTILUC>("inner_mptiluc");
SolverMaster::registerSolver<SolverMPTILU2>("inner_mptilu2");
#if defined(USE_SOLVER_PETSC)
SolverMaster::registerSolver<SolverPETSc>("petsc");
#endif
#if defined(USE_SOLVER_TRILINOS) && defined(USE_MPI)
SolverMaster::registerSolver<SolverTrilinosAztec>("trilinos_aztec");
SolverMaster::registerSolver<SolverTrilinosBelos>("trilinos_belos");
SolverMaster::registerSolver<SolverTrilinosML>("trilinos_ml");
SolverMaster::registerSolver<SolverTrilinosIfpack>("trilinos_ifpack");
#endif
#if defined(USE_SOLVER_ANI)
SolverMaster::registerSolver<SolverANI>("ani");
#endif
#if defined(USE_SOLVER_SUPERLU)
SolverMaster::registerSolver<SolverSUPERLU>("superlu");
#endif
#if defined(HAVE_SOLVER_K3BIILU2)
SolverMaster::registerSolver<SolverK3BIILU2>("k3biilu2");
#endif
#if defined(HAVE_SOLVER_FCBIILU2)
SolverMaster::registerSolver<SolverFCBIILU2>("fcbiilu2");
#endif
Solver::parseXMLDatabase(database);
//Debug
// for (auto p = parameters.begin(); p < parameters.end(); p++) {
// std::cout << "============================================================================" << std::endl;
// std::cout << (*p).solverName << ":" << (*p).solverPrefix << ":" << (*p).internalFile << std::endl;
// for (auto pp = (*p).parameters.begin(); pp < (*p).parameters.end(); pp++) {
// std::cout << (*pp).first << " = " << (*pp).second << std::endl;
// }
// std::cout << "============================================================================" << std::endl;
// }
Sparse::CreateRowEntryType();
}
......
......@@ -6,7 +6,7 @@ namespace INMOST {
};
SolverANI::SolverANI(const SolverInterface *other) {
SolverInterface *SolverANI::Copy(const SolverInterface *other) {
throw INMOST::SolverUnsupportedOperation; //later
};
......
......@@ -15,7 +15,7 @@ namespace INMOST {
public:
SolverANI();
SolverANI(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -6,13 +6,14 @@ namespace INMOST {
}
SolverFCBIILU2::SolverFCBIILU2(const SolverInterface *other) {
SolverInterface *SolverFCBIILU2::Copy(const SolverInterface *other) {
const SolverFCBIILU2 *fcother = static_cast<const SolverFCBIILU2 *>(other);
SolverCopyDataFcbiilu2(&solver_data, fcother->solver_data, communicator);
if (fcother->matrix_data != NULL) {
MatrixCopyDataFcbiilu2(&matrix_data, fcother->matrix_data);
SolverSetMatrixFcbiilu2(solver_data, matrix_data, false, false);
}
return this;
}
void SolverFCBIILU2::Assign(const SolverInterface *other) {
......
......@@ -14,7 +14,7 @@ namespace INMOST {
public:
SolverFCBIILU2();
SolverFCBIILU2(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -9,7 +9,7 @@ namespace INMOST {
dtol = 1.0e+100;
}
SolverInner::SolverInner(const SolverInterface *other) : SolverInterface(other) {
SolverInterface *SolverInner::Copy(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
......
......@@ -20,7 +20,7 @@ namespace INMOST {
public:
SolverInner();
SolverInner(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -6,13 +6,14 @@ namespace INMOST {
}
SolverK3BIILU2::SolverK3BIILU2(const SolverInterface *other) {
SolverInterface *SolverK3BIILU2::Copy(const SolverInterface *other) {
const SolverK3BIILU2 *k3other = static_cast<const SolverK3BIILU2 *>(other);
SolverCopyDataK3biilu2(&solver_data, k3other->solver_data, k3other->communicator);
if (k3other->matrix_data != NULL) {
MatrixCopyDataK3biilu2(&matrix_data, k3other->matrix_data);
SolverSetMatrixK3biilu2(solver_data, matrix_data, false, false);
}
return this;
}
void SolverK3BIILU2::Assign(const SolverInterface *other) {
......
......@@ -14,7 +14,7 @@ namespace INMOST {
public:
SolverK3BIILU2();
SolverK3BIILU2(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -18,7 +18,7 @@ namespace INMOST {
fill_level = 3;
}
SolverPETSc::SolverPETSc(const SolverInterface *other) {
SolverInterface *SolverPETSc::Copy(const SolverInterface *other) {
petscSolversCount++;
const SolverPETSc *solver = static_cast<const SolverPETSc *>(other);
this->ksp = NULL;
......@@ -29,6 +29,7 @@ namespace INMOST {
MatrixCopyDataPetsc(&matrix, solver->matrix);
SolverSetMatrixPetsc(ksp, matrix, false, false);
}
return this;
}
void SolverPETSc::Assign(const SolverInterface *other) {
......
......@@ -25,7 +25,7 @@ namespace INMOST {
public:
SolverPETSc();
SolverPETSc(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -10,7 +10,7 @@ namespace INMOST {
a_size = 0;
}
SolverSUPERLU::SolverSUPERLU(const SolverInterface *other) {
SolverInterface *SolverSUPERLU::Copy(const SolverInterface *other) {
throw INMOST::SolverUnsupportedOperation;
}
......
......@@ -18,7 +18,7 @@ namespace INMOST {
public:
SolverSUPERLU();
SolverSUPERLU(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
......@@ -14,7 +14,7 @@ namespace INMOST {
matrix = NULL;
}
SolverTrilinos::SolverTrilinos(const SolverInterface *other): SolverInterface(other) {
SolverInterface *SolverTrilinos::Copy(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
......@@ -66,7 +66,7 @@ namespace INMOST {
for (k = imbeg; k < imend; ++k) {
temporary[k - imbeg] = A[k].Size();
}
matrix = new Epetra_CrsMatrix(Copy, Map, temporary, true);
matrix = new Epetra_CrsMatrix(Epetra_DataAccess::Copy, Map, temporary, true);
delete[] temporary;
refill = false;
}
......
......@@ -51,7 +51,7 @@ namespace INMOST {
public:
SolverTrilinos();
SolverTrilinos(const SolverInterface *other);
virtual SolverInterface *Copy(const SolverInterface *other);
virtual void Assign(const SolverInterface *other);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment