Commit efb0bb4a authored by Dmitry Bagaev's avatar Dmitry Bagaev
Browse files

CLion code style reformat

parent 9705cf97
set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp
)
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp
)
set(HEADER
${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h
)
${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h
)
add_subdirectory(solver_inner)
if(USE_SOLVER_PETSC)
add_subdirectory(solver_petsc)
endif()
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp" )
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILUC2)
set(HAVE_SOLVER_MPTILUC2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp)
else()
set(HAVE_SOLVER_MPTILUC2 FALSE PARENT_SCOPE)
endif()
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp" )
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILU2)
set(HAVE_SOLVER_MPTILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.cpp)
else()
set(HAVE_SOLVER_MPTILU2 FALSE PARENT_SCOPE)
endif()
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp" )
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_FCBIILU2)
set(HAVE_SOLVER_FCBIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp)
else()
set(HAVE_SOLVER_FCBIILU2 FALSE)
endif()
if (USE_SOLVER_PETSC)
add_subdirectory(solver_petsc)
endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILUC2)
set(HAVE_SOLVER_MPTILUC2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.hpp)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtiluc2.cpp)
else ()
set(HAVE_SOLVER_MPTILUC2 FALSE PARENT_SCOPE)
endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILU2)
set(HAVE_SOLVER_MPTILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.hpp)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_mtilu2.cpp)
else ()
set(HAVE_SOLVER_MPTILU2 FALSE PARENT_SCOPE)
endif ()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp" AND EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_FCBIILU2)
set(HAVE_SOLVER_FCBIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_fcbiilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/fcbiilu2.cpp)
else ()
set(HAVE_SOLVER_FCBIILU2 FALSE)
endif ()
if (USE_MPI)
if( EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp" )
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2)
set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp)
else()
set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE)
endif()
endif()
if (EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.h" AND EXISTS
"${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp")
set(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_K3BIILU2)
set(HAVE_SOLVER_K3BIILU2 TRUE PARENT_SCOPE)
list(APPEND HEADER ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.h ${CMAKE_CURRENT_SOURCE_DIR}/k3d.h)
list(APPEND SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/solver_k3biilu2.cpp ${CMAKE_CURRENT_SOURCE_DIR}/k3d.cpp)
else ()
set(HAVE_SOLVER_K3BIILU2 FALSE PARENT_SCOPE)
endif ()
endif ()
set(HEADER ${HEADER} PARENT_SCOPE)
......
......@@ -41,6 +41,5 @@ namespace INMOST {
}
}
......@@ -6,17 +6,20 @@
namespace INMOST {
struct SolverBaseFactory {
virtual SolverInterface* create() = 0;
virtual SolverInterface* copy(const SolverInterface* other) = 0;
virtual SolverInterface *create() = 0;
virtual SolverInterface *copy(const SolverInterface *other) = 0;
virtual ~SolverBaseFactory() {};
};
template <class C> struct SolverCreateFactory : SolverBaseFactory {
template<class C>
struct SolverCreateFactory : SolverBaseFactory {
SolverInterface *create() {
return new C;
};
SolverInterface *copy(const SolverInterface* other) {
SolverInterface *copy(const SolverInterface *other) {
return new C(other);
};
};
......@@ -25,12 +28,17 @@ namespace INMOST {
private:
static std::map<std::string, SolverBaseFactory *> solvers;
public:
template<class T> static void registerSolver(std::string name) {
template<class T>
static void registerSolver(std::string name) {
solvers.insert(std::make_pair(name, new SolverCreateFactory<T>));
};
static SolverInterface *getSolver(std::string name);
static SolverInterface *copySolver(const SolverInterface *other);
static std::vector<std::string> getAvailableSolvers();
static bool isSolverAvailable(std::string name);
};
......
This diff is collapsed.
This diff is collapsed.
......@@ -2,144 +2,144 @@
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;
Method *prec = new ILU2_preconditioner(info);
solver = new BCGS_solver(prec, info);
matrix = NULL;
}
SolverILU2::SolverILU2(const SolverInterface* other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
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;
Method *prec = new ILU2_preconditioner(info);
solver = new BCGS_solver(prec, info);
matrix = NULL;
}
SolverILU2::SolverILU2(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
void SolverILU2::Assign(const SolverInterface *other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
void SolverILU2::Initialize(int *argc, char ***argv, const char *parameters_file, std::string prefix) {
}
void SolverILU2::SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) {
Sparse::Matrix *m = new Sparse::Matrix(A);
info.PrepareMatrix(*m, additive_schwartz_overlap);
solver->ReplaceMAT(*m);
if (matrix != NULL) {
delete matrix;
}
matrix = m;
void SolverILU2::Assign(const SolverInterface* other) {
//You should not really want to copy solver's information
throw INMOST::SolverUnsupportedOperation;
}
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);
void SolverILU2::Initialize(int *argc, char ***argv, const char *parameters_file, std::string prefix) {
}
void SolverILU2::SetMatrix(Sparse::Matrix & A, bool ModifiedPattern, bool OldPreconditioner) {
Sparse::Matrix *m = new Sparse::Matrix(A);
info.PrepareMatrix(*m, additive_schwartz_overlap);
solver->ReplaceMAT(*m);
if (matrix != NULL) {
delete matrix;
}
matrix = m;
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);
if (!solver->isInitialized()) {
solver->Initialize();
}
}
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;
return solver->Solve(RHS,SOL);
if (!solver->isInitialized()) {
solver->Initialize();
}
bool SolverILU2::Clear() {
info.Clear();
if (matrix != NULL) {
delete matrix;
matrix = NULL;
}
if (solver != NULL) {
delete solver;
solver = NULL;
}
return true;
}
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;
return solver->Solve(RHS, SOL);
}
bool SolverILU2::Clear() {
info.Clear();
if (matrix != NULL) {
delete matrix;
matrix = NULL;
}
bool SolverILU2::isMatrixSet() {
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 std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
if (solver != NULL) {
delete solver;
solver = NULL;
}
const INMOST_DATA_ENUM_TYPE SolverILU2::Iterations() const {
return solver->GetIterations();
}
const INMOST_DATA_REAL_TYPE SolverILU2::Residual() const {
return solver->GetResidual();
}
const std::string SolverILU2::ReturnReason() const {
return solver->GetReason();
}
const std::string SolverILU2::SolverName() const {
return "inner_ilu2";
}
void SolverILU2::Finalize() {
}
SolverILU2::~SolverILU2() {
Clear();
return true;
}
bool SolverILU2::isMatrixSet() {
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 std::cout << "Parameter " << property << " of integral type is unknown" << std::endl;
}
const INMOST_DATA_ENUM_TYPE SolverILU2::Iterations() const {
return solver->GetIterations();
}
const INMOST_DATA_REAL_TYPE SolverILU2::Residual() const {
return solver->GetResidual();
}
const std::string SolverILU2::ReturnReason() const {
return solver->GetReason();
}
const std::string SolverILU2::SolverName() const {
return "inner_ilu2";
}
void SolverILU2::Finalize() {
}
SolverILU2::~SolverILU2() {
Clear();
}
}
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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