Commit e2c01644 authored by Dmitry Bagaev's avatar Dmitry Bagaev

Some improvements to SolverInterface, SolverParameters added

parent 7f1cedd4
......@@ -33,7 +33,7 @@ int main(int argc, char **argv) {
std::string vectorBFileName = "";
std::string vectorXFileName = "";
std::string parametersFileName = "";
std::string solverName = "";
std::string solverName = "inner_ilu2";
bool matrixFound = false;
bool vectorBFound = false;
......@@ -60,8 +60,8 @@ int main(int argc, char **argv) {
std::cout << "-t, --type <Solver type name>" << std::endl;
std::cout << " Available solvers:" << std::endl;
Solver::Initialize(NULL, NULL, NULL);
std::vector<std::string> availableSolvers = SolverFactory::getAvailableSolvers();
for (auto it = availableSolvers.begin(); it != availableSolvers.end(); it++) {
std::vector<std::string> availableSolvers = SolverMaster::getAvailableSolvers();
for (solvers_names_iterator_t it = availableSolvers.begin(); it != availableSolvers.end(); it++) {
std::cout << " " << *it << std::endl;
}
Solver::Finalize();
......@@ -158,7 +158,7 @@ int main(int argc, char **argv) {
// Initialize the linear solver in accordance with args
Solver::Initialize(&argc, &argv, parametersFound ? parametersFileName.c_str() : NULL);
if (!SolverFactory::isSolverAvailable(solverName)) {
if (!SolverMaster::isSolverAvailable(solverName)) {
if (processRank == 0) {
std::cout << "Solver " << solverName << " is not available" << std::endl;
}
......@@ -166,7 +166,7 @@ int main(int argc, char **argv) {
exit(1);
}
Solver solver = Solver(solverName);
Solver solver = Solver(solverName, "test");
if (processRank == 0) {
std::cout << "Solving with " << solverName << std::endl;
......@@ -200,7 +200,6 @@ int main(int argc, char **argv) {
bool success;
double resid, realresid = 0;
std::string reason;
//Solver s(type); // Declare the linear solver by specified type
if (parametersFound) {
char *fileName = findInnerOptions(parametersFileName.c_str());
......@@ -210,9 +209,9 @@ int main(int argc, char **argv) {
for (unsigned ii = 0; ii < options->options.size(); ii++) {
InnerOption *option = options->options[ii];
if (option->type == ENUM) {
solver.SetPropertyEnum(option->name, (unsigned int) atoi(option->value.c_str()));
solver.SetParameterEnum(option->name, (unsigned int) atoi(option->value.c_str()));
} else {
solver.SetPropertyReal(option->name, atof(option->value.c_str()));
solver.SetParameterReal(option->name, atof(option->value.c_str()));
};
}
delete options;
......
......@@ -223,6 +223,7 @@ namespace INMOST
CannotReusePreconditionerOfDifferentSize,
SolverNotFound,
SolverUnsupportedOperation,
SolverUnknownParameter,
/// The list of errors may occur in the Partitioner.
ErrorInPartitioner = 500,
......
......@@ -245,13 +245,13 @@ namespace INMOST {
/// Clear all internal data of the current solver including matrix, preconditioner etc.
bool Clear();
INMOST_DATA_REAL_TYPE GetPropertyReal(std::string property) const;
INMOST_DATA_REAL_TYPE GetParameterReal(std::string property) const;
INMOST_DATA_ENUM_TYPE GetPropertyEnum(std::string property) const;
INMOST_DATA_ENUM_TYPE GetParameterEnum(std::string property) const;
void SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value);
void SetParameterReal(std::string property, INMOST_DATA_REAL_TYPE value);
void SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value);
void SetParameterEnum(std::string property, INMOST_DATA_ENUM_TYPE value);
/// Return the number of iterations performed by the last solution.
/// @see Sparse::Solve
......
......@@ -22,7 +22,7 @@ namespace INMOST {
};
};
class SolverFactory {
class SolverMaster {
private:
static std::map<std::string, SolverBaseFactory *> solvers;
public:
......@@ -40,6 +40,9 @@ namespace INMOST {
static bool isSolverAvailable(std::string name);
};
typedef std::map<std::string, SolverBaseFactory *>::iterator solvers_map_iterator_t;
typedef std::vector<std::string>::iterator solvers_names_iterator_t;
}
#endif //INMOST_SOLVER_FACTORY
......@@ -8,9 +8,24 @@ namespace INMOST {
#if defined(USE_SOLVER)
class SolverParameters {
private:
std::map<std::string, INMOST_DATA_ENUM_TYPE> enums;
std::map<std::string, INMOST_DATA_REAL_TYPE> reals;
public:
SolverParameters();
void SetDefaults();
void SetParameterReal(std::string name, INMOST_DATA_REAL_TYPE value);
void SetParameterEnum(std::string name, INMOST_DATA_ENUM_TYPE value);
const INMOST_DATA_REAL_TYPE GetParameterReal(std::string name) const;
const INMOST_DATA_ENUM_TYPE GetParameterEnum(std::string name) const;
};
class SolverInterface {
protected:
INMOST_MPI_Comm communicator;
SolverParameters parameters;
public:
SolverInterface() {};
......@@ -28,13 +43,21 @@ namespace INMOST {
virtual bool isMatrixSet() = 0;
virtual INMOST_DATA_REAL_TYPE GetPropertyReal(std::string property) const = 0;
virtual INMOST_DATA_REAL_TYPE GetParameterReal(std::string name) const {
return parameters.GetParameterReal(name);
};
virtual INMOST_DATA_ENUM_TYPE GetPropertyEnum(std::string property) const = 0;
virtual INMOST_DATA_ENUM_TYPE GetParameterEnum(std::string name) const {
return parameters.GetParameterEnum(name);
};
virtual void SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) = 0;
virtual void SetParameterReal(std::string name, INMOST_DATA_REAL_TYPE value) {
parameters.SetParameterReal(name, value);
};
virtual void SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) = 0;
virtual void SetParameterEnum(std::string name, INMOST_DATA_ENUM_TYPE value) {
parameters.SetParameterEnum(name, value);
};
virtual const INMOST_DATA_ENUM_TYPE Iterations() const = 0;
......
......@@ -2,7 +2,8 @@ set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/OrderInfo.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverMaster.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverParameters.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp
)
......
//
// Created by Dmitri Bagaev on 28.09.16.
//
#include "inmost.h"
namespace INMOST {
std::map<std::string, SolverBaseFactory *> SolverFactory::solvers = std::map<std::string, SolverBaseFactory *>();
std::map<std::string, SolverBaseFactory *> SolverMaster::solvers = std::map<std::string, SolverBaseFactory *>();
SolverInterface *SolverFactory::getSolver(std::string name) {
auto iterator = SolverFactory::solvers.find(name);
if (iterator != SolverFactory::solvers.end()) {
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 *SolverFactory::copySolver(const SolverInterface *other) {
auto iterator = SolverFactory::solvers.find(other->SolverName());
if (iterator != SolverFactory::solvers.end()) {
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;
}
}
std::vector<std::string> SolverFactory::getAvailableSolvers() {
std::vector<std::string> SolverMaster::getAvailableSolvers() {
std::vector<std::string> s;
for (auto bi = SolverFactory::solvers.begin(); bi != SolverFactory::solvers.end(); bi++) {
for (solvers_map_iterator_t bi = SolverMaster::solvers.begin(); bi != SolverMaster::solvers.end(); bi++) {
s.push_back(bi->first);
}
return s;
}
bool SolverFactory::isSolverAvailable(std::string name) {
return SolverFactory::solvers.find(name) != SolverFactory::solvers.end();
bool SolverMaster::isSolverAvailable(std::string name) {
return SolverMaster::solvers.find(name) != SolverMaster::solvers.end();
}
......
#include "inmost_solver.h"
#include "inmost_solver_interface.h"
namespace INMOST {
typedef std::map<std::string, INMOST_DATA_REAL_TYPE>::const_iterator parameters_map_real_iterator_t;
typedef std::map<std::string, INMOST_DATA_ENUM_TYPE>::const_iterator parameters_map_enum_iterator_t;
SolverParameters::SolverParameters() {
this->SetDefaults();
}
void SolverParameters::SetDefaults() {
this->SetParameterEnum("additive_schwartz_overlap", DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP);
this->SetParameterEnum("maximum_iterations", DEFAULT_MAXIMUM_ITERATIONS);
this->SetParameterEnum("reorder_nonzero", DEFAULT_PRECONDITIONER_REORDER_NONZEROS);
this->SetParameterEnum("rescale_iterations", DEFAULT_PRECONDITIONER_RESCALE_ITERS);
this->SetParameterEnum("condition_estimation", DEFAULT_PRECONDITIONER_CONDITION_ESTIMATION);
this->SetParameterEnum("adapt_ddpq_tolerance", DEFAULT_PRECONDITIONER_ADAPT_DDPQ_TOLERANCE);
this->SetParameterEnum("gmres_substeps", DEFAULT_SOLVER_GMRES_SUBSTEPS);
this->SetParameterReal("absolute_tolerance", DEFAULT_ABSOLUTE_TOLERANCE);
this->SetParameterReal("relative_tolerance", DEFAULT_RELATIVE_TOLERANCE);
this->SetParameterReal("divergence_tolerance", DEFAULT_DIVERGENCE_TOLERANCE);
this->SetParameterReal("drop_tolerance", DEFAULT_PRECONDITIONER_DROP_TOLERANCE);
this->SetParameterReal("reuse_tolerance", DEFAULT_PRECONDITIONER_REUSE_TOLERANCE);
this->SetParameterReal("ddpq_tolerance", DEFAULT_PRECONDITIONER_DDPQ_TOLERANCE);
this->SetParameterReal("fill_level", DEFAULT_PRECONDITIONER_FILL_LEVEL);
}
void SolverParameters::SetParameterReal(std::string name, INMOST_DATA_REAL_TYPE value) {
reals[name] = value;
}
void SolverParameters::SetParameterEnum(std::string name, INMOST_DATA_ENUM_TYPE value) {
enums[name] = value;
}
const INMOST_DATA_REAL_TYPE SolverParameters::GetParameterReal(std::string name) const {
parameters_map_real_iterator_t value = reals.find(name);
if (value != reals.cend()) {
return value->second;
} else {
throw INMOST::SolverUnknownParameter;
}
}
const INMOST_DATA_ENUM_TYPE SolverParameters::GetParameterEnum(std::string name) const {
parameters_map_enum_iterator_t value = enums.find(name);
if (value != enums.cend()) {
return value->second;
} else {
throw INMOST::SolverUnknownParameter;
}
}
}
......@@ -26,7 +26,7 @@ namespace INMOST {
bool Solver::is_finalized = false;
Solver::Solver(std::string solverName, std::string prefix, INMOST_MPI_Comm _comm) {
this->solver = SolverFactory::getSolver(solverName);
this->solver = SolverMaster::getSolver(solverName);
this->prefix = prefix;
solver->SetCommunicator(_comm);
......@@ -35,7 +35,7 @@ namespace INMOST {
}
Solver::Solver(const Solver &other) {
this->solver = SolverFactory::copySolver(other.solver);
this->solver = SolverMaster::copySolver(other.solver);
this->prefix = other.prefix;
solver->SetCommunicator(other.solver->GetCommunicator());
......@@ -80,18 +80,18 @@ namespace INMOST {
}
#endif
//Register all available solvers
SolverFactory::registerSolver<SolverILU2>("inner_ilu2");
SolverFactory::registerSolver<SolverDDPQILUC2>("inner_ddpqiluc2");
SolverFactory::registerSolver<SolverMPTILUC>("inner_mptiluc");
SolverFactory::registerSolver<SolverMPTILU2>("inner_mptilu2");
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)
SolverFactory::registerSolver<SolverPETSc>("petsc");
SolverMaster::registerSolver<SolverPETSc>("petsc");
#endif
#if defined(USE_SOLVER_TRILINOS)
SolverFactory::registerSolver<SolverTrilinosAztec>("trilinos_aztec");
SolverFactory::registerSolver<SolverTrilinosBelos>("trilinos_belos");
SolverFactory::registerSolver<SolverTrilinosML>("trilinos_ml");
SolverFactory::registerSolver<SolverTrilinosIfpack>("trilinos_ifpack");
SolverMaster::registerSolver<SolverTrilinosAztec>("trilinos_aztec");
SolverMaster::registerSolver<SolverTrilinosBelos>("trilinos_belos");
SolverMaster::registerSolver<SolverTrilinosML>("trilinos_ml");
SolverMaster::registerSolver<SolverTrilinosIfpack>("trilinos_ifpack");
#endif
Sparse::CreateRowEntryType();
}
......@@ -143,20 +143,20 @@ namespace INMOST {
return solver->Clear();
}
INMOST_DATA_REAL_TYPE Solver::GetPropertyReal(std::string property) const {
return solver->GetPropertyReal(property);
INMOST_DATA_REAL_TYPE Solver::GetParameterReal(std::string property) const {
return solver->GetParameterReal(property);
}
INMOST_DATA_ENUM_TYPE Solver::GetPropertyEnum(std::string property) const {
return solver->GetPropertyEnum(property);
INMOST_DATA_ENUM_TYPE Solver::GetParameterEnum(std::string property) const {
return solver->GetParameterEnum(property);
}
void Solver::SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) {
solver->SetPropertyReal(property, value);
void Solver::SetParameterReal(std::string property, INMOST_DATA_REAL_TYPE value) {
solver->SetParameterReal(property, value);
}
void Solver::SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
solver->SetPropertyEnum(property, value);
void Solver::SetParameterEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
solver->SetParameterEnum(property, value);
}
const INMOST_DATA_ENUM_TYPE Solver::Iterations() const {
......
......@@ -6,20 +6,6 @@ namespace INMOST {
Method *preconditioner = new ILUC_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
additive_schwartz_overlap = DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP;
maximum_iterations = DEFAULT_MAXIMUM_ITERATIONS;
absolute_tolerance = DEFAULT_ABSOLUTE_TOLERANCE;
relative_tolerance = DEFAULT_RELATIVE_TOLERANCE;
divergence_tolerance = DEFAULT_DIVERGENCE_TOLERANCE;
preconditioner_drop_tolerance = DEFAULT_PRECONDITIONER_DROP_TOLERANCE;
preconditioner_reuse_tolerance = DEFAULT_PRECONDITIONER_REUSE_TOLERANCE;
preconditioner_rescale_iterations = DEFAULT_PRECONDITIONER_RESCALE_ITERS;
preconditioner_ddpq_tolerance = DEFAULT_PRECONDITIONER_DDPQ_TOLERANCE;
preconditioner_reorder_nonzero = DEFAULT_PRECONDITIONER_REORDER_NONZEROS;
preconditioner_condition_estimation = DEFAULT_PRECONDITIONER_CONDITION_ESTIMATION;
preconditioner_adapt_ddpq_tolerance = DEFAULT_PRECONDITIONER_ADAPT_DDPQ_TOLERANCE;
solver_gmres_substeps = DEFAULT_SOLVER_GMRES_SUBSTEPS;
}
SolverDDPQILUC2::SolverDDPQILUC2(const SolverInterface *other) {
......@@ -41,19 +27,19 @@ namespace INMOST {
delete matrix;
}
matrix = new Sparse::Matrix(A);
info.PrepareMatrix(*matrix, additive_schwartz_overlap);
info.PrepareMatrix(*matrix, parameters.GetParameterEnum("additive_schwartz_overlap"));
solver->ReplaceMAT(*matrix);
solver->RealParameter(":tau") = preconditioner_drop_tolerance;
solver->RealParameter(":tau2") = preconditioner_reuse_tolerance;
solver->EnumParameter(":scale_iters") = preconditioner_rescale_iterations;
solver->RealParameter(":ddpq_tau") = preconditioner_ddpq_tolerance;
solver->EnumParameter(":reorder_nnz") = preconditioner_reorder_nonzero;
solver->EnumParameter(":estimator") = preconditioner_condition_estimation;
solver->EnumParameter(":ddpq_tau_adapt") = preconditioner_adapt_ddpq_tolerance;
solver->RealParameter(":tau") = parameters.GetParameterReal("drop_tolerance");
solver->RealParameter(":tau2") = parameters.GetParameterReal("reuse_tolerance");
solver->EnumParameter(":scale_iters") = parameters.GetParameterEnum("rescale_iterations");
solver->RealParameter(":ddpq_tau") = parameters.GetParameterReal("ddpq_tolerance");
solver->EnumParameter(":reorder_nnz") = parameters.GetParameterEnum("reorder_nonzero");
solver->EnumParameter(":estimator") = parameters.GetParameterEnum("condition_estimation");
solver->EnumParameter(":ddpq_tau_adapt") = parameters.GetParameterEnum("adapt_ddpq_tolerance");
if (sizeof(KSOLVER) == sizeof(BCGSL_solver)) {
solver->EnumParameter("levels") = solver_gmres_substeps;
solver->EnumParameter("levels") = parameters.GetParameterEnum("gmres_substeps");
}
if (!solver->isInitialized()) {
......@@ -62,10 +48,10 @@ namespace INMOST {
}
bool SolverDDPQILUC2::Solve(Sparse::Vector &RHS, Sparse::Vector &SOL) {
solver->EnumParameter("maxits") = maximum_iterations;
solver->RealParameter("rtol") = relative_tolerance;
solver->RealParameter("atol") = absolute_tolerance;
solver->RealParameter("divtol") = divergence_tolerance;
solver->EnumParameter("maxits") = parameters.GetParameterEnum("maximum_iterations");
solver->RealParameter("rtol") = parameters.GetParameterReal("relative_tolerance");
solver->RealParameter("atol") = parameters.GetParameterReal("absolute_tolerance");
solver->RealParameter("divtol") = parameters.GetParameterReal("divergence_tolerance");
return solver->Solve(RHS, SOL);
}
......@@ -87,48 +73,6 @@ namespace INMOST {
return matrix != NULL;
}
INMOST_DATA_REAL_TYPE SolverDDPQILUC2::GetPropertyReal(std::string property) const {
return solver->RealParameter(property);
}
INMOST_DATA_ENUM_TYPE SolverDDPQILUC2::GetPropertyEnum(std::string property) const {
return solver->EnumParameter(property);
}
void SolverDDPQILUC2::SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) {
if (property == "absolute_tolerance")
absolute_tolerance = value;
else if (property == "relative_tolerance")
relative_tolerance = value;
else if (property == "divergence_tolerance")
divergence_tolerance = value;
else if (property == "drop_tolerance")
preconditioner_drop_tolerance = value;
else if (property == "reuse_tolerance")
preconditioner_reuse_tolerance = value;
else if (property == "ddpq_tolerance")
preconditioner_ddpq_tolerance = value;
else std::cout << "Parameter " << property << " of real type is unknown" << std::endl;
}
void SolverDDPQILUC2::SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
if (property == "maximum_iterations")
maximum_iterations = value;
else if (property == "rescale_iterations")
preconditioner_rescale_iterations = value;
else if (property == "condition_estimation")
preconditioner_condition_estimation = value;
else if (property == "adapt_ddpq_tolerance")
preconditioner_adapt_ddpq_tolerance = value;
else if (property == "schwartz_overlap")
additive_schwartz_overlap = value;
else if (property == "gmres_substeps")
solver_gmres_substeps = value;
else if (property == "reorder_nonzeros")
preconditioner_reorder_nonzero = value;
else std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverDDPQILUC2::Iterations() const {
return solver->GetIterations();
}
......
......@@ -13,23 +13,6 @@ namespace INMOST {
Sparse::Matrix *matrix;
KSOLVER *solver;
Solver::OrderInfo info;
INMOST_DATA_ENUM_TYPE additive_schwartz_overlap;
INMOST_DATA_ENUM_TYPE maximum_iterations;
INMOST_DATA_REAL_TYPE absolute_tolerance;
INMOST_DATA_REAL_TYPE relative_tolerance;
INMOST_DATA_REAL_TYPE divergence_tolerance;
INMOST_DATA_REAL_TYPE preconditioner_drop_tolerance;
INMOST_DATA_REAL_TYPE preconditioner_reuse_tolerance;
INMOST_DATA_ENUM_TYPE preconditioner_rescale_iterations;
INMOST_DATA_REAL_TYPE preconditioner_ddpq_tolerance;
INMOST_DATA_ENUM_TYPE preconditioner_reorder_nonzero;
INMOST_DATA_ENUM_TYPE preconditioner_condition_estimation;
INMOST_DATA_ENUM_TYPE preconditioner_adapt_ddpq_tolerance;
INMOST_DATA_ENUM_TYPE solver_gmres_substeps;
public:
SolverDDPQILUC2();
......@@ -47,14 +30,6 @@ namespace INMOST {
virtual bool isMatrixSet();
virtual INMOST_DATA_REAL_TYPE GetPropertyReal(std::string property) const;
virtual INMOST_DATA_ENUM_TYPE GetPropertyEnum(std::string property) const;
virtual void SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value);
virtual void SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value);
virtual const INMOST_DATA_ENUM_TYPE Iterations() const;
virtual const INMOST_DATA_REAL_TYPE Residual() const;
......
......@@ -3,18 +3,6 @@
namespace INMOST {
SolverILU2::SolverILU2() {
additive_schwartz_overlap = DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP;
maximum_iterations = DEFAULT_MAXIMUM_ITERATIONS;
absolute_tolerance = DEFAULT_ABSOLUTE_TOLERANCE;
relative_tolerance = DEFAULT_RELATIVE_TOLERANCE;
divergence_tolerance = DEFAULT_DIVERGENCE_TOLERANCE;
preconditioner_drop_tolerance = DEFAULT_PRECONDITIONER_DROP_TOLERANCE;
preconditioner_reuse_tolerance = DEFAULT_PRECONDITIONER_REUSE_TOLERANCE;
preconditioner_rescale_iterations = DEFAULT_PRECONDITIONER_RESCALE_ITERS;
preconditioner_fill_level = DEFAULT_PRECONDITIONER_FILL_LEVEL;
solver_gmres_substeps = DEFAULT_SOLVER_GMRES_SUBSTEPS;
Method *preconditioner = new ILU2_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
......@@ -39,16 +27,16 @@ namespace INMOST {
delete matrix;
}
matrix = new Sparse::Matrix(A);
info.PrepareMatrix(*matrix, additive_schwartz_overlap);
info.PrepareMatrix(*matrix, parameters.GetParameterEnum("additive_schwartz_overlap"));
solver->ReplaceMAT(*matrix);
solver->RealParameter(":tau") = preconditioner_drop_tolerance;
solver->RealParameter(":tau2") = preconditioner_reuse_tolerance;
solver->EnumParameter(":scale_iters") = preconditioner_rescale_iterations;
solver->EnumParameter(":fill") = static_cast<INMOST_DATA_ENUM_TYPE>(preconditioner_fill_level);
solver->RealParameter(":tau") = parameters.GetParameterReal("drop_tolerance");
solver->RealParameter(":tau2") = parameters.GetParameterReal("reuse_tolerance");
solver->EnumParameter(":scale_iters") = parameters.GetParameterEnum("rescale_iterations");
solver->EnumParameter(":fill") = static_cast<INMOST_DATA_ENUM_TYPE>(parameters.GetParameterReal("fill_level"));
if (sizeof(KSOLVER) == sizeof(BCGSL_solver)) {
solver->EnumParameter("levels") = solver_gmres_substeps;
solver->EnumParameter("levels") = parameters.GetParameterEnum("gmres_substeps");
}
if (!solver->isInitialized()) {
......@@ -57,10 +45,10 @@ namespace INMOST {
}
bool SolverILU2::Solve(Sparse::Vector &RHS, Sparse::Vector &SOL) {
solver->EnumParameter("maxits") = maximum_iterations;
solver->RealParameter("rtol") = relative_tolerance;
solver->RealParameter("atol") = absolute_tolerance;
solver->RealParameter("divtol") = divergence_tolerance;
solver->EnumParameter("maxits") = parameters.GetParameterEnum("maximum_iterations");
solver->RealParameter("rtol") = parameters.GetParameterReal("relative_tolerance");
solver->RealParameter("atol") = parameters.GetParameterReal("absolute_tolerance");
solver->RealParameter("divtol") = parameters.GetParameterReal("divergence_tolerance");
return solver->Solve(RHS, SOL);
}
......@@ -82,48 +70,6 @@ namespace INMOST {
return matrix != NULL;
}
INMOST_DATA_REAL_TYPE SolverILU2::GetPropertyReal(std::string property) const {
return solver->RealParameter(property);
}
INMOST_DATA_ENUM_TYPE SolverILU2::GetPropertyEnum(std::string property) const {
return solver->EnumParameter(property);
}
void SolverILU2::SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
//like solver->RealParameter(property) = value;
if (property == "absolute_tolerance") {
absolute_tolerance = value;
} else if (property == "relative_tolerance") {
relative_tolerance = value;
} else if (property == "divergence_tolerance") {
divergence_tolerance = value;
} else if (property == "drop_tolerance") {
preconditioner_drop_tolerance = value;
} else if (property == "reuse_tolerance") {
preconditioner_reuse_tolerance = value;
} else if (property == "fill_level") {
preconditioner_fill_level = value;
} else {
std::cout << "Parameter " << property << " of real type is unknown" << std::endl;
}
}
void SolverILU2::SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) {
//Maybe we should use explicit names?, like maxits ..etc
//like solver->EnumParameter(property) = value;
if (property == "maximum_iterations") {
maximum_iterations = value;
} else if (property == "rescale_iterations") {
preconditioner_rescale_iterations = value;
} else if (property == "schwartz_overlap") {
additive_schwartz_overlap = value;
} else if (property == "gmres_substeps") {
solver_gmres_substeps = value;
} else std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverILU2::Iterations() const {
return solver->GetIterations();
}
......
......@@ -12,19 +12,6 @@ namespace INMOST {
Sparse::Matrix *matrix;
BCGS_solver *solver;
Solver::OrderInfo info;
INMOST_DATA_ENUM_TYPE additive_schwartz_overlap;
INMOST_DATA_ENUM_TYPE maximum_iterations;
INMOST_DATA_REAL_TYPE absolute_tolerance;
INMOST_DATA_REAL_TYPE relative_tolerance;
INMOST_DATA_REAL_TYPE divergence_tolerance;
INMOST_DATA_REAL_TYPE preconditioner_drop_tolerance;
INMOST_DATA_REAL_TYPE preconditioner_reuse_tolerance;
INMOST_DATA_REAL_TYPE preconditioner_fill_level;
INMOST_DATA_ENUM_TYPE preconditioner_rescale_iterations;
INMOST_DATA_ENUM_TYPE solver_gmres_substeps;
public:
SolverILU2();
......@@ -42,14 +29,6 @@ namespace INMOST {
virtual bool isMatrixSet();
virtual INMOST_DATA_REAL_TYPE GetPropertyReal(std::string property) const;
virtual INMOST_DATA_ENUM_TYPE GetPropertyEnum(std::string property) const;
virtual void SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value);
virtual void SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value);
virtual const INMOST_DATA_ENUM_TYPE Iterations() const;
virtual const INMOST_DATA_REAL_TYPE Residual() const;
......
......@@ -6,16 +6,6 @@ namespace INMOST {
Method *preconditioner = new MTILU2_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
additive_schwartz_overlap = DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP;
maximum_iterations = DEFAULT_MAXIMUM_ITERATIONS;
absolute_tolerance = DEFAULT_ABSOLUTE_TOLERANCE;
relative_tolerance = DEFAULT_RELATIVE_TOLERANCE;
divergence_tolerance = DEFAULT_DIVERGENCE_TOLERANCE;
preconditioner_drop_tolerance = DEFAULT_PRECONDITIONER_DROP_TOLERANCE;
preconditioner_reuse_tolerance = DEFAULT_PRECONDITIONER_REUSE_TOLERANCE;
preconditioner_rescale_iterations = DEFAULT_PRECONDITIONER_RESCALE_ITERS;
solver_gmres_substeps = DEFAULT_SOLVER_GMRES_SUBSTEPS;
}
SolverMPTILU2::SolverMPTILU2(const SolverInterface *other) {
......@@ -37,15 +27,15 @@ namespace INMOST {
delete matrix;
}
matrix = new Sparse::Matrix(A);
info.PrepareMatrix(*matrix, additive_schwartz_overlap);
info.PrepareMatrix(*matrix, parameters.GetParameterEnum("additive_schwartz_overlap"));
solver->ReplaceMAT(*matrix);
solver->RealParameter(":tau") = preconditioner_drop_tolerance;
solver->RealParameter(":tau2") = preconditioner_reuse_tolerance;