| Line | |
|---|
| 1 | /**
|
|---|
| 2 | * @file solver.hpp
|
|---|
| 3 | * @author Julian Iseringhausen <isering@ins.uni-bonn.de>
|
|---|
| 4 | * @date Mon Apr 18 13:11:14 2011
|
|---|
| 5 | *
|
|---|
| 6 | * @brief VMG::Solver
|
|---|
| 7 | *
|
|---|
| 8 | */
|
|---|
| 9 |
|
|---|
| 10 | #ifndef SOLVER_HPP_
|
|---|
| 11 | #define SOLVER_HPP_
|
|---|
| 12 |
|
|---|
| 13 | #include "base/discretization.hpp"
|
|---|
| 14 | #include "base/object.hpp"
|
|---|
| 15 | #include "base/stencil.hpp"
|
|---|
| 16 | #include "comm/comm.hpp"
|
|---|
| 17 | #include "grid/grid.hpp"
|
|---|
| 18 | #include "mg.hpp"
|
|---|
| 19 |
|
|---|
| 20 | namespace VMGTests
|
|---|
| 21 | {
|
|---|
| 22 | class SolverTestSuite;
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | namespace VMG
|
|---|
| 26 | {
|
|---|
| 27 |
|
|---|
| 28 | class Solver : public Object
|
|---|
| 29 | {
|
|---|
| 30 | public:
|
|---|
| 31 | friend class VMGTests::SolverTestSuite;
|
|---|
| 32 |
|
|---|
| 33 | Solver()
|
|---|
| 34 | {
|
|---|
| 35 | max_size = 0;
|
|---|
| 36 | vec_size = 0;
|
|---|
| 37 | b = NULL;
|
|---|
| 38 | x = NULL;
|
|---|
| 39 | A = NULL;
|
|---|
| 40 | }
|
|---|
| 41 |
|
|---|
| 42 | virtual ~Solver()
|
|---|
| 43 | {
|
|---|
| 44 | delete [] b;
|
|---|
| 45 | delete [] x;
|
|---|
| 46 | for (int i=0; i<max_size; i++)
|
|---|
| 47 | delete [] A[i];
|
|---|
| 48 | delete [] A;
|
|---|
| 49 | }
|
|---|
| 50 |
|
|---|
| 51 | void Run(Grid& sol, Grid& rhs)
|
|---|
| 52 | {
|
|---|
| 53 | #ifdef DEBUG
|
|---|
| 54 | sol.IsConsistent();
|
|---|
| 55 | rhs.IsConsistent();
|
|---|
| 56 | sol.IsCompatible(rhs);
|
|---|
| 57 | #endif
|
|---|
| 58 |
|
|---|
| 59 | Grid *rhsGlobal = MG::GetComm()->CommMergeGrids(rhs);
|
|---|
| 60 |
|
|---|
| 61 | this->Realloc(*rhsGlobal);
|
|---|
| 62 | this->AssembleMatrix(*rhsGlobal);
|
|---|
| 63 | this->Compute();
|
|---|
| 64 | this->ExportSol(sol, rhs);
|
|---|
| 65 | }
|
|---|
| 66 |
|
|---|
| 67 | private:
|
|---|
| 68 |
|
|---|
| 69 | virtual void Compute() = 0; ///< Solves the system of equations
|
|---|
| 70 | virtual void AssembleMatrix(const Grid& rhs) = 0; ///< Assembles all matrices and vectors.
|
|---|
| 71 | virtual void ExportSol(Grid& sol, Grid& rhs) = 0; ///< Exports the solution back to a given mesh.
|
|---|
| 72 |
|
|---|
| 73 | vmg_float **A, *b, *x;
|
|---|
| 74 | int max_size, vec_size;
|
|---|
| 75 |
|
|---|
| 76 | protected:
|
|---|
| 77 | void Realloc(int n);
|
|---|
| 78 | void Realloc(Grid& x);
|
|---|
| 79 |
|
|---|
| 80 | vmg_float& Mat(int i, int j)
|
|---|
| 81 | {
|
|---|
| 82 | return A[i][j];
|
|---|
| 83 | }
|
|---|
| 84 |
|
|---|
| 85 | vmg_float& Rhs(int i)
|
|---|
| 86 | {
|
|---|
| 87 | return b[i];
|
|---|
| 88 | }
|
|---|
| 89 |
|
|---|
| 90 | vmg_float& Sol(int i)
|
|---|
| 91 | {
|
|---|
| 92 | return x[i];
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | const int& Size() const {return vec_size;}
|
|---|
| 96 | const int& MemSize() const {return max_size;}
|
|---|
| 97 | };
|
|---|
| 98 |
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | #endif
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.