NodeCentricRepMatrix.cpp 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. #include "NodeCentricRepMatrix.h"
  2. using namespace OBJREC;
  3. using namespace std;
  4. /** Member-Methodes **/
  5. NodeCentricRepMatrix::NodeCentricRepMatrix ( const uint m, const uint n, const uint e ) : std::valarray<double> ( m * n * e ) {
  6. this->m = m;
  7. this->n = n;
  8. this->e = e;
  9. }
  10. NodeCentricRepMatrix::NodeCentricRepMatrix ( const NodeCentricRepMatrix& matrix ) : std::valarray<double> ( matrix ) {
  11. this->m = matrix.getM();
  12. this->n = matrix.getN();
  13. this->e = matrix.getE();
  14. }
  15. NodeCentricRepMatrix::~NodeCentricRepMatrix() {}
  16. double NodeCentricRepMatrix::at ( uint m, uint n, uint e ) const {
  17. checkRange ( m, n, e );
  18. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  19. }
  20. double& NodeCentricRepMatrix::at ( uint m, uint n, uint e ) {
  21. checkRange ( m, n, e );
  22. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  23. }
  24. double NodeCentricRepMatrix::atQuick ( uint m, uint n, uint e ) const
  25. {
  26. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  27. }
  28. double& NodeCentricRepMatrix::atQuick ( uint m, uint n, uint e )
  29. {
  30. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  31. }
  32. void NodeCentricRepMatrix::checkRange ( uint m, uint n, uint e ) const {
  33. if ( m >= ( *this ).m || n >= ( *this ).n || e >= ( *this ).e )
  34. throw range_error ( "NodeCentricRepMatrix: You try to access an element outside the matrix!" );
  35. }
  36. NodeCentricRepMatrix& NodeCentricRepMatrix::operator= ( const NodeCentricRepMatrix & matrix ) {
  37. // Selbstkopie verhindern
  38. if ( this == &matrix ) return ( *this );
  39. if ( ( *this ).getM() != matrix.getM() ||
  40. ( *this ).getN() != matrix.getN() ||
  41. ( *this ).getE() != matrix.getE() ) {
  42. throw range_error ( "NodeCentricRepMatrix: Assigment not possible. Matrix-dim does not match." );
  43. }
  44. for ( uint i = 0; i < ( *this ).getN(); i++ ) {
  45. for ( uint j = 0; j < ( *this ).getM(); j++ ) {
  46. for ( uint e = 0; e < ( *this ).getE(); e++ ) {
  47. ( *this ) ( j, i, e ) = matrix ( j, i, e );
  48. }
  49. }
  50. }
  51. return ( *this );
  52. }
  53. NodeCentricRepMatrix& NodeCentricRepMatrix::operator-= ( NodeCentricRepMatrix const & rhs )
  54. {
  55. if ( ( *this ).getM() != rhs.getM() ||
  56. ( *this ).getN() != rhs.getN() ||
  57. ( *this ).getE() != rhs.getE() )
  58. {
  59. throw range_error ( "NodeCentricRepMatrix: Minus not possible. Matrix-dim does not match." );
  60. }
  61. #pragma omp parallel for
  62. for ( uint i = 0; i < ( *this ).getN(); i++ )
  63. {
  64. for ( uint j = 0; j < ( *this ).getM(); j++ )
  65. {
  66. for ( uint e = 0; e < ( *this ).getE(); e++ )
  67. {
  68. ( *this ) ( j, i, e ) -= rhs ( j, i, e );
  69. }
  70. }
  71. }
  72. return ( *this );
  73. }
  74. NodeCentricRepMatrix NodeCentricRepMatrix::operator- ( NodeCentricRepMatrix const& rhs )
  75. {
  76. NodeCentricRepMatrix tmp ( ( *this ) );
  77. tmp -= rhs;
  78. return tmp;
  79. }
  80. double NodeCentricRepMatrix::operator() ( const uint m, const uint n, const uint e ) const
  81. {
  82. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  83. }
  84. double& NodeCentricRepMatrix::operator() ( const uint m, const uint n, const uint e )
  85. {
  86. return valarray<double>::operator[] ( m * ( ( *this ).n * ( *this ).e ) + n * ( *this ).e + e );
  87. }
  88. bool NodeCentricRepMatrix::changes ( const NodeCentricRepMatrix& matrix, double epsilon ) const {
  89. if ( ( *this ).getM() != matrix.getM() ||
  90. ( *this ).getN() != matrix.getN() ||
  91. ( *this ).getE() != matrix.getE() ) {
  92. throw range_error ( "NodeCentricRepMatrix: Calculate difference not possible. Matrix-dim does not match." );
  93. }
  94. bool retValue = false;
  95. //#pragma omp parallel for
  96. for ( uint i = 0; i < ( *this ).getN(); i++ ) {
  97. for ( uint j = 0; j < ( *this ).getM(); j++ ) {
  98. for ( uint e = 0; e < ( *this ).getE(); e++ ) {
  99. if ( abs ( ( *this ) ( j, i, e ) - matrix ( j, i, e ) ) > epsilon )
  100. {
  101. return true;
  102. }
  103. }
  104. }
  105. }
  106. return retValue;
  107. }