Commit 9705cf97 authored by Dmitry Bagaev's avatar Dmitry Bagaev

InnerILU2 added

parent b551ac9f
#Actually Solver class in refactoring state right now
#All examples will be refactored too after the main stage
if(USE_MESH) if(USE_MESH)
#add_subdirectory(DrawGrid) #add_subdirectory(DrawGrid)
add_subdirectory(OldDrawGrid) #add_subdirectory(OldDrawGrid)
add_subdirectory(GridGen) #add_subdirectory(GridGen)
endif(USE_MESH) endif(USE_MESH)
if(USE_SOLVER) if(USE_SOLVER)
add_subdirectory(DrawMatrix) #add_subdirectory(DrawMatrix)
add_subdirectory(MatSolve) add_subdirectory(MatSolve)
endif(USE_SOLVER) endif(USE_SOLVER)
if(USE_SOLVER AND USE_MESH) if(USE_SOLVER AND USE_MESH)
add_subdirectory(FVDiscr) #add_subdirectory(FVDiscr)
add_subdirectory(Solver) #add_subdirectory(Solver)
endif(USE_SOLVER AND USE_MESH) endif(USE_SOLVER AND USE_MESH)
if(USE_AUTODIFF AND USE_SOLVER AND USE_MESH) if(USE_AUTODIFF AND USE_SOLVER AND USE_MESH)
add_subdirectory(ADFVDiscr) #add_subdirectory(ADFVDiscr)
add_subdirectory(ADMFD) #add_subdirectory(ADMFD)
endif(USE_AUTODIFF AND USE_SOLVER AND USE_MESH) endif(USE_AUTODIFF AND USE_SOLVER AND USE_MESH)
#add_subdirectory(OctreeCutcell) #add_subdirectory(OctreeCutcell)
\ No newline at end of file
...@@ -5,7 +5,6 @@ ...@@ -5,7 +5,6 @@
#include <cstdio> #include <cstdio>
#include "inmost.h" #include "inmost.h"
#include "Source/Solver/refactoring/Solver2.h"
#include "inner_parser.h" #include "inner_parser.h"
using namespace INMOST; using namespace INMOST;
...@@ -33,7 +32,7 @@ int main(int argc, char ** argv) { ...@@ -33,7 +32,7 @@ int main(int argc, char ** argv) {
std::string vectorBFileName = ""; std::string vectorBFileName = "";
std::string vectorXFileName = ""; std::string vectorXFileName = "";
std::string parametersFileName = ""; std::string parametersFileName = "";
int solverType = 0; std::string solverName = "";
bool matrixFound = false; bool matrixFound = false;
bool vectorBFound = false; bool vectorBFound = false;
...@@ -57,21 +56,7 @@ int main(int argc, char ** argv) { ...@@ -57,21 +56,7 @@ int main(int argc, char ** argv) {
std::cout << "-b, --bvector <RHS vector file name>" << std::endl; std::cout << "-b, --bvector <RHS vector file name>" << std::endl;
std::cout << "-x, --xvector <X vector file name>" << std::endl; std::cout << "-x, --xvector <X vector file name>" << std::endl;
std::cout << "-p, --parameters <Solver parameters file name>" << std::endl; std::cout << "-p, --parameters <Solver parameters file name>" << std::endl;
std::cout << "-t, --type <Solver type index>" << std::endl; std::cout << "-t, --type <Solver type name>" << std::endl;
std::cout << " 0: INNER_ILU2 " << std::endl;
std::cout << " 1: INNER_DDPQILUC " << std::endl;
std::cout << " 2: INNER_MPTILUC " << std::endl;
std::cout << " 3: INNER_MPTILU2 " << std::endl;
std::cout << " 4: Trilinos_Aztec " << std::endl;
std::cout << " 5: Trilinos_Belos " << std::endl;
std::cout << " 6: Trilinos_ML " << std::endl;
std::cout << " 7: Trilinos_Ifpack " << std::endl;
std::cout << " 8: PETSc " << std::endl;
std::cout << " 9: ANI " << std::endl;
std::cout << " 10: FCBIILU2 " << std::endl;
std::cout << " 11: K3BIILU2 " << std::endl;
std::cout << " 12: SUPERLU " << std::endl << std::endl;
std::cout << "-h, --help - print this message." << std::endl;
} }
#if defined(USE_MPI) #if defined(USE_MPI)
MPI_Finalize(); MPI_Finalize();
...@@ -133,7 +118,7 @@ int main(int argc, char ** argv) { ...@@ -133,7 +118,7 @@ int main(int argc, char ** argv) {
std::cout << "Solver type index found: " << argv[i + 1] << std::endl; std::cout << "Solver type index found: " << argv[i + 1] << std::endl;
} }
typeFound = true; typeFound = true;
solverType = atoi(argv[i + 1]); solverName = std::string(argv[i + 1]);
i++; i++;
continue; continue;
} }
...@@ -163,39 +148,13 @@ int main(int argc, char ** argv) { ...@@ -163,39 +148,13 @@ int main(int argc, char ** argv) {
} }
} }
Solver::Type type;
switch (solverType) {
case 0: type = Solver::INNER_ILU2; break;
case 1: type = Solver::INNER_DDPQILUC; break;
case 2: type = Solver::INNER_MPTILUC; break;
case 3: type = Solver::INNER_MPTILU2; break;
case 4: type = Solver::Trilinos_Aztec; break;
case 5: type = Solver::Trilinos_Belos; break;
case 6: type = Solver::Trilinos_ML; break;
case 7: type = Solver::Trilinos_Ifpack; break;
case 8: type = Solver::PETSc; break;
case 9: type = Solver::ANI; break;
case 10: type = Solver::FCBIILU2; break;
case 11: type = Solver::K3BIILU2; break;
case 12: type = Solver::SUPERLU; break;
default:
if (processRank == 0) {
std::cout << "Invalid solver type index: " << solverType << " , using INNER_ILU2 instead." <<
std::endl;
}
type = Solver::INNER_ILU2;
break;
}
// Initialize the linear solver in accordance with args // Initialize the linear solver in accordance with args
Solver2::Initialize(&argc, &argv, parametersFound ? parametersFileName.c_str() : NULL); Solver::Initialize(&argc, &argv, parametersFound ? parametersFileName.c_str() : NULL);
Solver2 solver = Solver2("petsc"); Solver solver = Solver(solverName);
Solver2 solver2 = solver;
//solver2.Finalize(); //solver2.Finalize();
if (processRank == 0) { if (processRank == 0) {
std::cout << "Solving with " << Solver::TypeName(type) << std::endl; std::cout << "Solving with " << solverName << std::endl;
} }
Sparse::Matrix mat("A"); // Declare the matrix of the linear system to be solved Sparse::Matrix mat("A"); // Declare the matrix of the linear system to be solved
...@@ -267,18 +226,18 @@ int main(int argc, char ** argv) { ...@@ -267,18 +226,18 @@ int main(int argc, char ** argv) {
tempTimer = Timer(); tempTimer = Timer();
solver2.SetMatrix(mat); solver.SetMatrix(mat);
//s.SetMatrix(mat); // Compute the preconditioner for the original matrix //s.SetMatrix(mat); // Compute the preconditioner for the original matrix
BARRIER BARRIER
if (processRank == 0) std::cout << "preconditioner time: " << Timer() - tempTimer << std::endl; if (processRank == 0) std::cout << "preconditioner time: " << Timer() - tempTimer << std::endl;
tempTimer = Timer(); tempTimer = Timer();
success = solver2.Solve(b, x); // Solve the linear system with the previously computted preconditioner success = solver.Solve(b, x); // Solve the linear system with the previously computted preconditioner
BARRIER BARRIER
solvingTimer = Timer() - solvingTimer; solvingTimer = Timer() - solvingTimer;
if (processRank == 0) std::cout << "iterations time: " << Timer() - tempTimer << std::endl; if (processRank == 0) std::cout << "iterations time: " << Timer() - tempTimer << std::endl;
iters = solver2.Iterations(); // Get the number of iterations performed iters = solver.Iterations(); // Get the number of iterations performed
resid = solver2.Residual(); // Get the final residual achieved resid = solver.Residual(); // Get the final residual achieved
reason = solver2.ReturnReason(); // Get the convergence reason reason = solver.ReturnReason(); // Get the convergence reason
//x.Save("output.sol"); // Save the solution if required //x.Save("output.sol"); // Save the solution if required
// Compute the true residual // Compute the true residual
...@@ -309,7 +268,7 @@ int main(int argc, char ** argv) { ...@@ -309,7 +268,7 @@ int main(int argc, char ** argv) {
std::cout << "||Ax-b||=" << sqrt(recv[0]) << " ||b||=" << sqrt(recv[1]) << " ||Ax-b||/||b||=" << std::cout << "||Ax-b||=" << sqrt(recv[0]) << " ||b||=" << sqrt(recv[1]) << " ||Ax-b||/||b||=" <<
sqrt(recv[0] / (recv[1] + 1.0e-100)) << std::endl; sqrt(recv[0] / (recv[1] + 1.0e-100)) << std::endl;
std::cout << "norms: " << Timer() - tempTimer << std::endl; std::cout << "norms: " << Timer() - tempTimer << std::endl;
std::cout << processorsCount << " processors for Solver::type=" << type; std::cout << processorsCount << " processors for Solver " << solverName;
if (success) { if (success) {
std::cout << " solved in " << solvingTimer << " secs"; std::cout << " solved in " << solvingTimer << " secs";
std::cout << " with " << iters << " iterations to " << resid << " norm"; std::cout << " with " << iters << " iterations to " << resid << " norm";
...@@ -362,6 +321,6 @@ int main(int argc, char ** argv) { ...@@ -362,6 +321,6 @@ int main(int argc, char ** argv) {
} }
} }
BARRIER BARRIER
Solver2::Finalize(); // Finalize solver and close MPI activity Solver::Finalize(); // Finalize solver and close MPI activity
return 0; return 0;
} }
...@@ -12,6 +12,7 @@ set(HEADER ...@@ -12,6 +12,7 @@ set(HEADER
${CMAKE_CURRENT_SOURCE_DIR}/inmost_dense.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_dense.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_mesh.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_mesh.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_solver.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_solver.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_solver_interface.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_partitioner.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_partitioner.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_autodiff.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_autodiff.h
${CMAKE_CURRENT_SOURCE_DIR}/inmost_expression.h ${CMAKE_CURRENT_SOURCE_DIR}/inmost_expression.h
......
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
#include "inmost_mesh.h" #include "inmost_mesh.h"
#include "inmost_dense.h" #include "inmost_dense.h"
#include "inmost_solver.h" #include "inmost_solver.h"
#include "inmost_solver_interface.h"
#include "inmost_partitioner.h" #include "inmost_partitioner.h"
#include "inmost_variable.h" #include "inmost_variable.h"
#include "inmost_nonlinear.h" #include "inmost_nonlinear.h"
......
...@@ -222,6 +222,7 @@ namespace INMOST ...@@ -222,6 +222,7 @@ namespace INMOST
PrepareMatrixFirst, PrepareMatrixFirst,
CannotReusePreconditionerOfDifferentSize, CannotReusePreconditionerOfDifferentSize,
SolverNotFound, SolverNotFound,
SolverUnsupportedOperation,
/// The list of errors may occur in the Partitioner. /// The list of errors may occur in the Partitioner.
ErrorInPartitioner = 500, ErrorInPartitioner = 500,
......
This diff is collapsed.
#ifndef INMOST_SOLVERINTERFACE_H
#define INMOST_SOLVERINTERFACE_H
#include <string>
#include "inmost_sparse.h"
namespace INMOST {
#if defined(USE_SOLVER)
class SolverInterface {
protected:
INMOST_MPI_Comm communicator;
public:
SolverInterface() {};
SolverInterface(const SolverInterface* other) {};
virtual void Assign(const SolverInterface* other) = 0;
virtual void Initialize(int *argc, char ***argv, const char *parameters_file, std::string prefix) = 0;
virtual void SetMatrix(Sparse::Matrix & A, bool ModifiedPattern, bool OldPreconditioner) = 0;
virtual bool Solve(INMOST::Sparse::Vector & RHS, INMOST::Sparse::Vector & SOL) = 0;
virtual bool Clear() = 0;
virtual bool isMatrixSet() = 0;
virtual INMOST_DATA_REAL_TYPE GetPropertyReal(std::string property) const = 0;
virtual INMOST_DATA_ENUM_TYPE GetPropertyEnum(std::string property) const = 0;
virtual void SetPropertyReal(std::string property, INMOST_DATA_REAL_TYPE value) = 0;
virtual void SetPropertyEnum(std::string property, INMOST_DATA_ENUM_TYPE value) = 0;
virtual const INMOST_DATA_ENUM_TYPE Iterations() const = 0;
virtual const INMOST_DATA_REAL_TYPE Residual() const = 0;
virtual const std::string ReturnReason() const = 0;
virtual const std::string SolverName() const = 0;
virtual void Finalize() = 0;
virtual ~SolverInterface() {};
void SetCommunicator(INMOST_MPI_Comm _communicator) {
communicator = _communicator;
}
INMOST_MPI_Comm GetCommunicator() {
return communicator;
}
};
}
#endif
#endif //INMOST_SOLVERINTERFACE_H
This diff is collapsed.
add_subdirectory(refactoring)
set(SOURCE set(SOURCE
${SOURCE} ${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/solver.cpp ${CMAKE_CURRENT_SOURCE_DIR}/Solver.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp
${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp ${CMAKE_CURRENT_SOURCE_DIR}/sparse.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_ani.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_ddpqiluc2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_petsc.cpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_superlu.cpp
) )
set(HEADER set(HEADER
${HEADER} ${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/solver_prototypes.hpp ${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h
${CMAKE_CURRENT_SOURCE_DIR}/solver_petsc.h
${CMAKE_CURRENT_SOURCE_DIR}/solver_superlu.h
${CMAKE_CURRENT_SOURCE_DIR}/solver_ilu2.hpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_ddpqiluc2.hpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_bcgsl.hpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_ani.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" ) 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(SOLVER_DEFINITIONS ${SOLVER_DEFINITIONS} -DHAVE_SOLVER_MPTILUC2)
......
...@@ -2,8 +2,9 @@ ...@@ -2,8 +2,9 @@
// Created by Dmitri Bagaev on 28.09.16. // Created by Dmitri Bagaev on 28.09.16.
// //
#include "inmost.h"
#include "SolverFactory.h" #include "SolverFactory.h"
#include "SolverInterface.h"
namespace INMOST { namespace INMOST {
......
//
// Created by Dmitri Bagaev on 28.09.16.
//
#ifndef INMOST_SOLVERFACTORY_H #ifndef INMOST_SOLVERFACTORY_H
#define INMOST_SOLVERFACTORY_H #define INMOST_SOLVERFACTORY_H
#include "SolverInterface.h" #include <inmost.h>
namespace INMOST { namespace INMOST {
......
This diff is collapsed.
This diff is collapsed.
if(USE_SOLVER_PETSC)
add_subdirectory(solver_petsc)
endif()
set(HEADER
${HEADER}
${CMAKE_CURRENT_SOURCE_DIR}/SolverInterface.h
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.h
${CMAKE_CURRENT_SOURCE_DIR}/Solver2.h)
set(SOURCE
${SOURCE}
${CMAKE_CURRENT_SOURCE_DIR}/Solver2.cpp
${CMAKE_CURRENT_SOURCE_DIR}/SolverFactory.cpp)
set(HEADER ${HEADER} PARENT_SCOPE)
set(SOURCE ${SOURCE} PARENT_SCOPE)
\ No newline at end of file
This diff is collapsed.
//
// Created by Dmitri Bagaev on 22.09.16.
//
#ifndef INMOST_SOLVERCONTAINER_H
#define INMOST_SOLVERCONTAINER_H
#include <string>
#include "SolverInterface.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
namespace INMOST {
class Solver2 {
private:
static int *argc;
static char ***argv;
static const char *database;
static bool is_initialized;
static bool is_finalized;
//Actual solver using for solving system
SolverInterface *solver;
std::string prefix;
public:
Solver2(std::string solverName, std::string prefix = "", INMOST_MPI_Comm _comm = INMOST_MPI_COMM_WORLD);
Solver2(const Solver2& other);
Solver2& operator =(const Solver2& other);
std::string SolverName() const;
std::string SolverPrefix() const;
static void Initialize(int *argc, char ***argv, const char *database);
static bool isInitialized();
static bool isFinalized();
static void Finalize();
void SetMatrix(Sparse::Matrix & A, bool ModifiedPattern = true, bool OldPreconditioner = false);
bool Solve(INMOST::Sparse::Vector & RHS, INMOST::Sparse::Vector & SOL);
const INMOST_DATA_ENUM_TYPE Iterations() const;
const INMOST_DATA_REAL_TYPE Residual() const;
const std::string ReturnReason() const;
~Solver2();
static std::string parseDatabase(std::string solverName);
};
}
#endif //INMOST_SOLVERCONTAINER_H
This diff is collapsed.
This diff is collapsed.
set(HEADER ${HEADER} ${CMAKE_CURRENT_SOURCE_DIR}/solver_prototypes.hpp
${CMAKE_CURRENT_SOURCE_DIR}/solver_bcgsl.hpp)
add_subdirectory(solver_ilu2)
set(SOURCE ${SOURCE} PARENT_SCOPE)
set(HEADER ${HEADER} PARENT_SCOPE)
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
This diff is collapsed.
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