FixVec.hh 3.18 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
//
// Software License for AMDiS
//
// Copyright (c) 2010 Dresden University of Technology 
// All rights reserved.
// Authors: Simon Vey, Thomas Witkowski et al.
//
// This file is part of AMDiS
//
// See also license.opensource.txt in the distribution.


13
14
namespace AMDiS {

15
16
17
18
19
20
21
22
  template<typename T>
  void DimVec<T>::multMatrixVec(DimMat<T> &m, DimVec<T> &v)
  {
    T *mIt, *thisIt;
    for (thisIt = this->begin(), mIt = m.begin();
	 thisIt != this->end();
	 thisIt++) {
      *thisIt = 0;
Thomas Witkowski's avatar
Thomas Witkowski committed
23
      for (T* vIt = v.begin(); vIt != v.end(); vIt++, mIt++)
24
25
26
27
	*thisIt += *vIt * *mIt;
    }
  }

28
29
30
  template<typename T, GeoIndex d>
  double absteukl(const FixVec<T,d>& a,const FixVec<T,d>& b)
  {
31
    double erg = 0.0;
32

Thomas Witkowski's avatar
Thomas Witkowski committed
33
    for (int i = 0; i < a.getSize() ; i++)
34
      erg = erg + ((a[i] - b[i]) * (a[i] - b[i]));
35
36
37
38
39
40
41
42

    return sqrt(erg);
  }

  template<typename T>
  void WorldVector<T>::multMatrixVec(WorldMatrix<T> &m, WorldVector<T> &v) 
  {
    FUNCNAME("WorldVector<T>::multMatrix()");
43
44
    TEST_EXIT_DBG(m.getNumRows() == this->getSize())("invalide size\n");
    TEST_EXIT_DBG(v.getSize() == this->getSize())("invalide size\n");
45
46
47
48

    T *mIt, *thisIt;
    for (thisIt = this->begin(), mIt = m.begin();
	 thisIt != this->end(); 
49
50
51
	 thisIt++) {
      *thisIt = 0;
      
Thomas Witkowski's avatar
Thomas Witkowski committed
52
53
      for (T* vIt = v.begin(); vIt != v.end(); vIt++, mIt++) 
	*thisIt += *vIt * *mIt;      
54
    }
55
56
57
58
59
60
61
62
63
  }

  template<typename T>
  bool WorldMatrix<T>::isDiagMatrix() const
  {
    for (int i = 0; i < this->getSize(); i++)
      for (int j = i + 1; j < this->getSize(); j++)
	if (abs((*this)[i][j]) > DBL_TOL || abs((*this)[j][i]) > DBL_TOL) 
	  return(false);
64

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
    return(true);
  }

  template<typename T>
  bool WorldMatrix<T>::isSymmetric() const
  {
    for (int i = 0; i < this->getSize(); i++)
      for (int j = i + 1; j < this->getSize(); j++)
	if (abs((*this)[i][j] - (*this)[j][i]) > DBL_TOL) 
	  return false;

    return true;
  }
 
  template<typename T>
  void WorldMatrix<T>::setDiag(T value)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
82
    for (int i = 0; i < this->rows; i++)
83
84
85
86
87
88
89
90
      this->valArray[i * this->cols + i] = value;
  }

  template<typename T>
  void WorldMatrix<T>::vecProduct(const WorldVector<T>& v1, const WorldVector<T>& v2)
  {
    FUNCNAME("WorldMatrix<T>::vecProduct()");

91
92
    TEST_EXIT_DBG(v1.getSize() == v2.getSize())("invalid size 1\n");
    TEST_EXIT_DBG(v1.getSize() == this->getSize())("invalid size 2\n");
93
94
95

    T *thisIt = this->begin();

Thomas Witkowski's avatar
Thomas Witkowski committed
96
97
    for (T* v1It = v1.begin(); v1It != v1.end(); v1It++)
      for (T* v2It = v2.begin(); v2It != v2.end(); v2It++, thisIt++)
98
99
100
101
102
103
	*thisIt = *v1It * *v2It;
  }
  
  template<typename T>
  const WorldMatrix<T>& operator*=(WorldMatrix<T>& m, T scal)
  {
Thomas Witkowski's avatar
Thomas Witkowski committed
104
    for (T* mIt = m.begin(); mIt != m.end(); mIt++)
105
106
107
108
109
110
111
112
113
114
115
      *mIt *= scal;

    return m;
  }

  template<typename T>
  const WorldMatrix<T>& operator-=(WorldMatrix<T>& m1, const WorldMatrix<T>& m2)
  {
    T *m1It, *m2It;
    for (m1It = m1.begin(), m2It = m2.begin();
	 m1It != m1.end(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
116
	 m1It++, m2It++)
117
      *m1It -= *m2It;
118
119
120
121
122
123
124
125
126
127

    return m1;
  }

  template<typename T>
  const WorldMatrix<T>& operator+=(WorldMatrix<T>& m1, const WorldMatrix<T>& m2)
  {
    T* m1It, *m2It;
    for (m1It = m1.begin(), m2It = m2.begin();
	 m1It != m1.end(); 
Thomas Witkowski's avatar
Thomas Witkowski committed
128
	 m1It++, m2It++)
129
      *m1It += *m2It;
130
131
132
133

    return m1;
  }
}