Commit 5f727ce4 authored by Dmitry Bagaev's avatar Dmitry Bagaev
Browse files

Some code improvements and cleanup

1) SetParameter for each InnerSolver
2) Utils.h hided
parent 948d7eb1
......@@ -266,7 +266,6 @@ set(INMOST_INSTALL_HEADERS Source/Headers/inmost.h
Source/Headers/inmost_solver_interface.h
Source/Headers/inmost_sparse.h
Source/Headers/inmost_xml.h
Source/Headers/inmost_utils.h
Source/Headers/inmost_variable.h
Source/Headers/container.hpp)
......@@ -299,7 +298,6 @@ set_property(TARGET inmost PROPERTY PUBLIC_HEADER
"${PROJECT_SOURCE_DIR}/Source/Headers/inmost_sparse.h"
"${PROJECT_SOURCE_DIR}/Source/Headers/inmost_variable.h"
"${PROJECT_SOURCE_DIR}/Source/Headers/inmost_xml.h"
"${PROJECT_SOURCE_DIR}/Source/Headers/inmost_utils.h"
"${PROJECT_SOURCE_DIR}/Source/Headers/container.hpp")
install(FILES
......
......@@ -20,7 +20,6 @@ set(HEADER
${CMAKE_CURRENT_SOURCE_DIR}/inmost_sparse.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_nonlinear.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_xml.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_utils.h
${CMAKE_CURRENT_SOURCE_DIR}/container.hpp
PARENT_SCOPE
)
\ No newline at end of file
......@@ -11,6 +11,5 @@
#include "inmost_variable.h"
#include "inmost_nonlinear.h"
#include "inmost_xml.h"
#include "inmost_utils.h"
#endif // INMOST_H_INCLUDED
......@@ -5,21 +5,6 @@
#include "inmost_common.h"
#include "inmost_sparse.h"
#define DEFAULT_ADDITIVE_SCHWARTZ_OVERLAP 1
#define DEFAULT_ABSOLUTE_TOLERANCE 1.0e-5
#define DEFAULT_RELATIVE_TOLERANCE 1.0e-12
#define DEFAULT_DIVERGENCE_TOLERANCE 1.0e+100
#define DEFAULT_MAXIMUM_ITERATIONS 2500
#define DEFAULT_SOLVER_GMRES_SUBSTEPS 2
#define DEFAULT_PRECONDITIONER_DROP_TOLERANCE 0.005
#define DEFAULT_PRECONDITIONER_REUSE_TOLERANCE 0.00005
#define DEFAULT_PRECONDITIONER_FILL_LEVEL 3
#define DEFAULT_PRECONDITIONER_DDPQ_TOLERANCE 0.75
#define DEFAULT_PRECONDITIONER_REORDER_NONZEROS 1
#define DEFAULT_PRECONDITIONER_RESCALE_ITERS 6
#define DEFAULT_PRECONDITIONER_CONDITION_ESTIMATION 1
#define DEFAULT_PRECONDITIONER_ADAPT_DDPQ_TOLERANCE 1
#if defined(USE_SOLVER)
namespace INMOST
{
......@@ -33,7 +18,6 @@ namespace INMOST
static std::vector<SolverParameters> parameters;
static int *argc;
static char ***argv;
static const char *database;
static bool is_initialized;
static bool is_finalized;
......
......@@ -50,7 +50,6 @@ namespace INMOST {
int *Solver::argc = NULL;
char ***Solver::argv = NULL;
const char *Solver::database = NULL;
bool Solver::is_initialized = false;
bool Solver::is_finalized = false;
std::vector<SolverParameters> Solver::parameters = std::vector<SolverParameters>();
......@@ -119,7 +118,6 @@ namespace INMOST {
void Solver::Initialize(int *argc, char ***argv, const char *database) {
Solver::argc = argc;
Solver::argv = argv;
Solver::database = database;
Solver::is_initialized = true;
Solver::is_finalized = false;
#if defined(USE_MPI)
......
......@@ -4,20 +4,9 @@ namespace INMOST {
SolverInner::SolverInner() {
maximum_iterations = 2500;
rescale_iterations = 6;
condition_estimation = 1;
adapt_ddpq_tolerance = 1;
schwartz_overlap = 1;
gmres_substeps = 2;
reorder_nnz = 1;
atol = 1.0e-5;
rtol = 1.0e-12;
dtol = 1.0e+100;
drop_tolerance = 0.005;
reuse_tolerance = 0.00005;
ddpq_tolerance = 0.75;
fill_level = 3;
}
SolverInner::SolverInner(const SolverInterface *other) : SolverInterface(other) {
......@@ -85,19 +74,9 @@ namespace INMOST {
std::string SolverInner::GetParameter(std::string name) const {
if (name == "maximum_iterations") return to_string(maximum_iterations);
else if (name == "rescale_iterations") return to_string(rescale_iterations);
else if (name == "condition_estimation") return to_string(condition_estimation);
else if (name == "adapt_ddpq_tolerance") return to_string(adapt_ddpq_tolerance);
else if (name == "schwartz_overlap") return to_string(schwartz_overlap);
else if (name == "gmres_substeps") return to_string(gmres_substeps);
else if (name == "reorder_nonzeros") return to_string(reorder_nnz);
else if (name == "absolute_tolerance") return to_string(atol);
else if (name == "relative_tolerance") return to_string(rtol);
else if (name == "divergence_tolerance") return to_string(dtol);
else if (name == "drop_tolerance") return to_string(drop_tolerance);
else if (name == "reuse_tolerance") return to_string(reuse_tolerance);
else if (name == "ddpq_tolerance") return to_string(ddpq_tolerance);
else if (name == "fill_level") return to_string(fill_level);
else {
std::cout << "Parameter " << name << " is unknown" << std::endl;
return "";
......@@ -107,19 +86,9 @@ namespace INMOST {
void SolverInner::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "maximum_iterations") maximum_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "rescale_iterations") rescale_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "condition_estimation") condition_estimation = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "adapt_ddpq_tolerance") adapt_ddpq_tolerance = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "schwartz_overlap") schwartz_overlap = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "gmres_substeps") gmres_substeps = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "reorder_nonzeros") reorder_nnz = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "absolute_tolerance") atol = atof(val);
else if (name == "relative_tolerance") rtol = atof(val);
else if (name == "divergence_tolerance") dtol = atof(val);
else if (name == "drop_tolerance") drop_tolerance = atof(val);
else if (name == "reuse_tolerance") reuse_tolerance = atof(val);
else if (name == "ddpq_tolerance") ddpq_tolerance = atof(val);
else if (name == "fill_level") fill_level = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else std::cout << "Parameter " << name << " is unknown" << std::endl;
}
......
......@@ -2,7 +2,7 @@
#define INMOST_SOLVERINNER_H
#include "inmost_solver_interface.h"
#include "inmost_utils.h"
#include "Source/Utils/Utils.h"
#include "solver_prototypes.hpp"
#include "solver_bcgsl.hpp"
......@@ -15,8 +15,8 @@ namespace INMOST {
KSOLVER *solver;
Solver::OrderInfo info;
INMOST_DATA_ENUM_TYPE maximum_iterations, rescale_iterations, condition_estimation, adapt_ddpq_tolerance, schwartz_overlap, gmres_substeps, reorder_nnz, fill_level;
INMOST_DATA_REAL_TYPE atol, rtol, dtol, ddpq_tolerance, drop_tolerance, reuse_tolerance;
INMOST_DATA_ENUM_TYPE maximum_iterations;
INMOST_DATA_REAL_TYPE atol, rtol, dtol;
public:
SolverInner();
......
......@@ -6,6 +6,15 @@ namespace INMOST {
Method *preconditioner = new ILUC_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
rescale_iterations = 6;
condition_estimation = 1;
adapt_ddpq_tolerance = 1;
schwartz_overlap = 1;
gmres_substeps = 2;
reorder_nnz = 1;
drop_tolerance = 0.005;
reuse_tolerance = 0.00005;
ddpq_tolerance = 0.75;
}
SolverDDPQILUC2::SolverDDPQILUC2(const SolverInterface *other) {
......@@ -38,6 +47,20 @@ namespace INMOST {
}
}
void SolverDDPQILUC2::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "rescale_iterations") rescale_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "condition_estimation") condition_estimation = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "adapt_ddpq_tolerance") adapt_ddpq_tolerance = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "schwartz_overlap") schwartz_overlap = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "gmres_substeps") gmres_substeps = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "reorder_nonzeros") reorder_nnz = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "drop_tolerance") drop_tolerance = atof(val);
else if (name == "reuse_tolerance") reuse_tolerance = atof(val);
else if (name == "ddpq_tolerance") ddpq_tolerance = atof(val);
else SolverInner::SetParameter(name, value);
}
const std::string SolverDDPQILUC2::SolverName() const {
return "inner_ddpqiluc2";
}
......
......@@ -9,6 +9,9 @@
namespace INMOST {
class SolverDDPQILUC2 : public SolverInner {
INMOST_DATA_ENUM_TYPE rescale_iterations, condition_estimation, adapt_ddpq_tolerance, schwartz_overlap, gmres_substeps, reorder_nnz;
INMOST_DATA_REAL_TYPE ddpq_tolerance, drop_tolerance, reuse_tolerance;
public:
public:
SolverDDPQILUC2();
......@@ -16,6 +19,8 @@ namespace INMOST {
virtual void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner);
virtual void SetParameter(std::string name, std::string value);
virtual const std::string SolverName() const;
virtual ~SolverDDPQILUC2();
......
......@@ -6,6 +6,13 @@ namespace INMOST {
Method *preconditioner = new ILU2_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
rescale_iterations = 6;
schwartz_overlap = 1;
gmres_substeps = 2;
reorder_nnz = 1;
drop_tolerance = 0.005;
reuse_tolerance = 0.00005;
fill_level = 3;
}
SolverILU2::SolverILU2(const SolverInterface *other) {
......@@ -35,6 +42,18 @@ namespace INMOST {
}
}
void SolverILU2::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "rescale_iterations") rescale_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "schwartz_overlap") schwartz_overlap = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "gmres_substeps") gmres_substeps = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "reorder_nonzeros") reorder_nnz = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "fill_level") fill_level = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "drop_tolerance") drop_tolerance = atof(val);
else if (name == "reuse_tolerance") reuse_tolerance = atof(val);
else SolverInner::SetParameter(name, value);
}
const std::string SolverILU2::SolverName() const {
return "inner_ilu2";
}
......
......@@ -8,6 +8,8 @@
namespace INMOST {
class SolverILU2 : public SolverInner {
INMOST_DATA_ENUM_TYPE rescale_iterations, schwartz_overlap, gmres_substeps, reorder_nnz, fill_level;
INMOST_DATA_REAL_TYPE drop_tolerance, reuse_tolerance;
public:
SolverILU2();
......@@ -15,6 +17,8 @@ namespace INMOST {
virtual void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner);
virtual void SetParameter(std::string name, std::string value);
virtual const std::string SolverName() const;
virtual ~SolverILU2();
......
......@@ -6,6 +6,14 @@ namespace INMOST {
Method *preconditioner = new MTILU2_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
rescale_iterations = 6;
schwartz_overlap = 1;
gmres_substeps = 2;
reorder_nnz = 1;
drop_tolerance = 0.005;
reuse_tolerance = 0.00005;
fill_level = 3;
}
SolverMPTILU2::SolverMPTILU2(const SolverInterface *other) {
......@@ -34,6 +42,21 @@ namespace INMOST {
}
}
void SolverMPTILU2::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "rescale_iterations") rescale_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "schwartz_overlap") schwartz_overlap = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "gmres_substeps") gmres_substeps = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "reorder_nonzeros") reorder_nnz = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "absolute_tolerance") atol = atof(val);
else if (name == "relative_tolerance") rtol = atof(val);
else if (name == "divergence_tolerance") dtol = atof(val);
else if (name == "drop_tolerance") drop_tolerance = atof(val);
else if (name == "reuse_tolerance") reuse_tolerance = atof(val);
else if (name == "fill_level") fill_level = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else SolverInner::SetParameter(name, value);
}
const std::string SolverMPTILU2::SolverName() const {
return "inner_mptilu2";
}
......
......@@ -9,6 +9,8 @@
namespace INMOST {
class SolverMPTILU2 : public SolverInner {
INMOST_DATA_ENUM_TYPE rescale_iterations, schwartz_overlap, gmres_substeps, reorder_nnz, fill_level;
INMOST_DATA_REAL_TYPE drop_tolerance, reuse_tolerance;
public:
SolverMPTILU2();
......@@ -16,6 +18,8 @@ namespace INMOST {
virtual void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner);
virtual void SetParameter(std::string name, std::string value);
virtual const std::string SolverName() const;
virtual ~SolverMPTILU2();
......
......@@ -6,6 +6,15 @@ namespace INMOST {
Method *preconditioner = new MTILUC_preconditioner(info);
solver = new KSOLVER(preconditioner, info);
matrix = NULL;
rescale_iterations = 6;
condition_estimation = 1;
schwartz_overlap = 1;
gmres_substeps = 2;
reorder_nnz = 1;
drop_tolerance = 0.005;
reuse_tolerance = 0.00005;
fill_level = 3;
}
SolverMPTILUC::SolverMPTILUC(const SolverInterface *other) {
......@@ -35,14 +44,17 @@ namespace INMOST {
}
}
bool SolverMPTILUC::Solve(Sparse::Vector &RHS, Sparse::Vector &SOL) {
solver->EnumParameter("maxits") = maximum_iterations;
solver->RealParameter("rtol") = rtol;
solver->RealParameter("atol") = atol;
solver->RealParameter("divtol") = dtol;
bool solve = solver->Solve(RHS, SOL);
return solve;
void SolverMPTILUC::SetParameter(std::string name, std::string value) {
const char *val = value.c_str();
if (name == "rescale_iterations") rescale_iterations = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "condition_estimation") condition_estimation = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "schwartz_overlap") schwartz_overlap = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "gmres_substeps") gmres_substeps = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "reorder_nonzeros") reorder_nnz = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "fill_level") fill_level = static_cast<INMOST_DATA_ENUM_TYPE>(atoi(val));
else if (name == "drop_tolerance") drop_tolerance = atof(val);
else if (name == "reuse_tolerance") reuse_tolerance = atof(val);
else SolverInner::SetParameter(name, value);
}
const std::string SolverMPTILUC::SolverName() const {
......
......@@ -8,6 +8,8 @@
namespace INMOST {
class SolverMPTILUC : public SolverInner {
INMOST_DATA_ENUM_TYPE rescale_iterations, condition_estimation, schwartz_overlap, gmres_substeps, reorder_nnz, fill_level;
INMOST_DATA_REAL_TYPE drop_tolerance, reuse_tolerance;
public:
SolverMPTILUC();
......@@ -15,7 +17,7 @@ namespace INMOST {
virtual void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner);
virtual bool Solve(Sparse::Vector &RHS, Sparse::Vector &SOL);
virtual void SetParameter(std::string name, std::string value);
virtual const std::string SolverName() const;
......
......@@ -4,6 +4,7 @@
#include "inmost.h"
#include "petsc.h"
#include "solver_petsc.h"
#include "Source/Utils/Utils.h"
namespace INMOST {
......
......@@ -7,6 +7,7 @@
#include <inmost.h>
#include "Source/Utils/Utils.h"
#if defined(USE_MPI)
......
......@@ -6,5 +6,6 @@ set(SOURCE
set(HEADER
${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/Utils.h
PARENT_SCOPE
)
\ No newline at end of file
#include "inmost_utils.h"
#include "Utils.h"
namespace INMOST {
......
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