FixVec.hh 2.85 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
/******************************************************************************
 *
 * AMDiS - Adaptive multidimensional simulations
 *
 * Copyright (C) 2013 Dresden University of Technology. All Rights Reserved.
 * Web: https://fusionforge.zih.tu-dresden.de/projects/amdis
 *
 * Authors: 
 * Simon Vey, Thomas Witkowski, Andreas Naumann, Simon Praetorius, et al.
 *
 * This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
 * WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
 *
 *
 * This file is part of AMDiS
 *
 * See also license.opensource.txt in the distribution.
 * 
 ******************************************************************************/
20 21


22 23
namespace AMDiS {

24 25 26 27 28 29 30 31
  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
32
      for (T* vIt = v.begin(); vIt != v.end(); vIt++, mIt++)
33 34 35 36
	*thisIt += *vIt * *mIt;
    }
  }

37
  template<typename T>
38
  void WorldVector<T>::multMatrixVec(const WorldMatrix<T> &m, const WorldVector<T> &v)
39
  {
40
    FUNCNAME_DBG("WorldVector<T>::multMatrix()");
41 42
    TEST_EXIT_DBG(m.getNumRows() == this->getSize())("invalide size\n");
    TEST_EXIT_DBG(v.getSize() == this->getSize())("invalide size\n");
43

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

  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);
63

64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
    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
81
    for (int i = 0; i < this->rows; i++)
82 83 84 85 86 87
      this->valArray[i * this->cols + i] = value;
  }

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

Praetorius, Simon's avatar
Praetorius, Simon committed
90 91
    TEST_EXIT_DBG(v1.getSize() == v2.getSize())("size(v1) != size(v2), %d != %d\n", v1.getSize(), v2.getSize());
    TEST_EXIT_DBG(v1.getSize() == this->getNumRows())("size(v1) != num_rows(this), %d != %d\n", v1.getSize(), this->getNumRows());
92 93 94

    T *thisIt = this->begin();

95 96
    for (T const* v1It = v1.begin(); v1It != v1.end(); v1It++)
      for (T const* v2It = v2.begin(); v2It != v2.end(); v2It++, thisIt++)
97 98 99 100
	*thisIt = *v1It * *v2It;
  }
  
}