SolverInterface.h 2.35 KB
Newer Older
Dmitry Bagaev's avatar
Dmitry Bagaev committed
1 2
#ifndef INMOST_SOLVER_INTERFACE_H
#define INMOST_SOLVER_INTERFACE_H
Dmitry Bagaev's avatar
Dmitry Bagaev committed
3

4
#include "inmost_sparse.h"
Dmitry Bagaev's avatar
Dmitry Bagaev committed
5
#include <string>
Dmitry Bagaev's avatar
Dmitry Bagaev committed
6
#include <sstream>
7

Dmitry Bagaev's avatar
Dmitry Bagaev committed
8

Kirill Terekhov's avatar
Kirill Terekhov committed
9
#define SILENCE_SET_PARAMETER
Dmitry Bagaev's avatar
Dmitry Bagaev committed
10
#if defined(USE_SOLVER)
11
namespace INMOST {
Dmitry Bagaev's avatar
Dmitry Bagaev committed
12

13
    class SolverInterface;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
14 15
    class SolverParameters {
    public:
Dmitry Bagaev's avatar
Dmitry Bagaev committed
16 17 18
        std::string solverName;
        std::string solverPrefix;
        std::string internalFile;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
19 20 21 22 23 24 25

        std::vector<std::pair<std::string, std::string> > parameters;

        SolverParameters(std::string solverName, std::string solverPrefix, std::string internalFile);
        SolverParameters(const SolverParameters &other);

        ~SolverParameters();
26 27

        static void SetInnerParametersFromFile(const std::string &file, SolverInterface *solver);
Dmitry Bagaev's avatar
Dmitry Bagaev committed
28 29 30 31
    };

    typedef std::vector<std::pair<std::string, std::string> >::iterator parameters_iterator_t;

Dmitry Bagaev's avatar
Dmitry Bagaev committed
32 33 34 35
    class SolverInterface {
    protected:
        INMOST_MPI_Comm communicator;
    public:
Dmitry Bagaev's avatar
Dmitry Bagaev committed
36
        SolverInterface() {};
Dmitry Bagaev's avatar
Dmitry Bagaev committed
37

Dmitry Bagaev's avatar
Dmitry Bagaev committed
38
        virtual SolverInterface *Copy(const SolverInterface *other) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
39 40

        virtual void Assign(const SolverInterface *other) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
41

Dmitry Bagaev's avatar
Dmitry Bagaev committed
42
        virtual void Setup(int *argc, char ***argv, SolverParameters &p) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
43 44 45 46 47

        virtual void SetMatrix(Sparse::Matrix &A, bool ModifiedPattern, bool OldPreconditioner) = 0;

        virtual bool Solve(INMOST::Sparse::Vector &RHS, INMOST::Sparse::Vector &SOL) = 0;

Dmitry Bagaev's avatar
Dmitry Bagaev committed
48 49 50 51
        virtual bool Clear() = 0;

        virtual bool isMatrixSet() = 0;

Dmitry Bagaev's avatar
Dmitry Bagaev committed
52
        virtual std::string GetParameter(std::string name) const = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
53

Dmitry Bagaev's avatar
Dmitry Bagaev committed
54
        virtual void SetParameter(std::string name, std::string value) = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
55

56
        virtual INMOST_DATA_ENUM_TYPE Iterations() const = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
57

58
        virtual INMOST_DATA_REAL_TYPE Residual() const = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
59

Dmitry Bagaev's avatar
Dmitry Bagaev committed
60 61 62 63 64
        virtual const std::string ReturnReason() const = 0;

        virtual const std::string SolverName() const = 0;

        virtual void Finalize() = 0;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
65

Dmitry Bagaev's avatar
2prev  
Dmitry Bagaev committed
66
        virtual INMOST_DATA_REAL_TYPE Condest(INMOST_DATA_REAL_TYPE tol, INMOST_DATA_ENUM_TYPE maxiter) {
Dmitry Bagaev's avatar
Dmitry Bagaev committed
67
            throw INMOST::SolverUnsupportedOperation;
68
            (void) tol; (void) maxiter;
Dmitry Bagaev's avatar
Dmitry Bagaev committed
69 70
        };

Dmitry Bagaev's avatar
Dmitry Bagaev committed
71 72 73 74 75 76 77 78 79
        virtual ~SolverInterface() {};

        void SetCommunicator(INMOST_MPI_Comm _communicator) {
            communicator = _communicator;
        }

        INMOST_MPI_Comm GetCommunicator() {
            return communicator;
        }
Dmitry Bagaev's avatar
Dmitry Bagaev committed
80

Dmitry Bagaev's avatar
Dmitry Bagaev committed
81 82 83
    };

}
84
#endif //USE_SOLVER
Dmitry Bagaev's avatar
Dmitry Bagaev committed
85 86


Dmitry Bagaev's avatar
Dmitry Bagaev committed
87
#endif //INMOST_SOLVER_INTERFACE_H