DiagonalPreconditioner.cc 1.76 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
#include "DiagonalPreconditioner.h"
#include "FiniteElemSpace.h"
#include "DOFAdmin.h"
#include "DOFVector.h"
#include "DOFMatrix.h"
#include "DOFIterator.h"

namespace AMDiS {

  void DiagonalPreconditioner::precon(DOFVector<double>* x)
  {
    FUNCNAME("DiagonalPreconditioner::precon()");

14
15
    TEST_EXIT_DBG(matrix[row])("no matrix\n");
    TEST_EXIT_DBG(x)("no solution vector\n");
Thomas Witkowski's avatar
Thomas Witkowski committed
16
 
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
    DOFMatrix::Iterator rowIterator((*matrix[row]), USED_DOFS);
    DOFVector<double>::Iterator vecIterator(x, USED_DOFS);

    if (bound) {
      ERROR_EXIT("not up to date\n");
      DOFVector<BoundaryType>::Iterator bIterator(const_cast<DOFVector<BoundaryType>*>(bound), USED_DOFS);
      for (vecIterator.reset(), rowIterator.reset(), bIterator.reset();
	   !vecIterator.end(); ++vecIterator, ++bIterator, ++rowIterator) {
	// only non-dirichlet nodes will be preconditioned
	if ((*bIterator) <= 0 && rowIterator->size() != 0) {
	  (*vecIterator) /= (*rowIterator)[0].entry;
	}
      }
    } else {
      for (vecIterator.reset(), rowIterator.reset(); 
	   !vecIterator.end(); 
33
34
35
36
37
	   ++vecIterator, ++rowIterator) {
	if (rowIterator->size() != 0) {
	  (*vecIterator) /= (*rowIterator)[0].entry;
	}
      }    
38
39
40
    }
  }
    
41
42
43
  void DiagonalPreconditionerStd::precon(::std::vector<double>* x)
  {
    FUNCNAME("DiagonalPreconditionerStd::precon()");
44
	
45
46
47
48
49
50
51
    TEST_EXIT_DBG(x)("no solution vector\n");
    TEST_EXIT_DBG(x->size() == matrix->size())("solution vector and matrix have different size\n");
    
    ::std::vector<double>::iterator vecIt;
    ::std::vector< ::std::vector<MatEntry> >::iterator matrixIt;
      
    for (vecIt = x->begin(), matrixIt = matrix->begin(); 
52
	 vecIt < x->end(); 
53
54
55
56
	 ++vecIt, ++matrixIt) {
      if (matrixIt->size() != 0) {
	(*vecIt) /= (*matrixIt)[0].entry;
      }
57
    }
58
  }  
59
}