MatrixVector2Test.cpp 2.18 KB
Newer Older
1
2
//======================================================================================================================
//
3
//  This file is part of waLBerla. waLBerla is free software: you can
4
//  redistribute it and/or modify it under the terms of the GNU General Public
5
//  License as published by the Free Software Foundation, either version 3 of
6
//  the License, or (at your option) any later version.
7
8
9
10
//
//  waLBerla is distributed in the hope that it will be useful, but WITHOUT
//  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
//  FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
11
//  for more details.
12
//
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//  You should have received a copy of the GNU General Public License along
//  with waLBerla (see COPYING.txt). If not, see <http://www.gnu.org/licenses/>.
//
//! \file MatrixVector2Test.cpp
//! \ingroup core
//! \author Martin Bauer <martin.bauer@fau.de>
//
//======================================================================================================================

#include "core/debug/TestSubsystem.h"
#include "core/math/Matrix2.h"
#include "core/math/Vector2.h"

#include <iostream>

using namespace walberla;
using walberla::uint8_t;

void matrix2Test()
{
33
34
   Matrix2< real_t > m1(2, 1, -1, 5);
   Matrix2< real_t > m2(4, 2, -2, 1);
35

36
37
   WALBERLA_CHECK_EQUAL(m1 * m2 * m2.getInverse(), m1);
   WALBERLA_CHECK_EQUAL(m1 * m1.getInverse() * m2, m2);
38

39
   Vector2< real_t > v1(5, 7);
40

41
   WALBERLA_CHECK_EQUAL(m2 * v1, Vector2< real_t >(34, -3));
42

43
44
45
46
47
   const real_t s = real_c(5);

   WALBERLA_CHECK_EQUAL(s * m1, Matrix2< real_t >(10, 5, -5, 25));
   WALBERLA_CHECK_EQUAL(m1 * s, Matrix2< real_t >(10, 5, -5, 25));
}
48
49
50

void vector2Test()
{
51
52
53
   Vector2< real_t > v1(1, 2);
   Vector2< real_t > v2(3, 4);
   Vector2< uint_t > v3(4, 3);
54
55

   auto sum = v1 + v2;
56
   WALBERLA_CHECK_EQUAL(sum, Vector2< real_t >(4, 6));
57
58

   auto product = v1 * v2;
59
   WALBERLA_CHECK_FLOAT_EQUAL(product, 1.0 * 3 + 2.0 * 4);
60

61
62
   WALBERLA_CHECK_FLOAT_EQUAL(v2.length(), 5.0);
   WALBERLA_CHECK_FLOAT_EQUAL(v2.sqrLength(), 25.0);
63

64
65
   WALBERLA_CHECK_EQUAL(v3.indexOfMin(), 1);
   WALBERLA_CHECK_EQUAL(v3.indexOfMax(), 0);
66
67
68
69
70
71
72
73
74
}

int main()
{
   vector2Test();
   matrix2Test();

   return 0;
}