LifeV
test_vectorsmall.cpp
Go to the documentation of this file.
1 //@HEADER
2 /*
3 *******************************************************************************
4 
5  Copyright (C) 2004, 2005, 2007 EPFL, Politecnico di Milano, INRIA
6  Copyright (C) 2010 EPFL, Politecnico di Milano, Emory University
7 
8  This file is part of LifeV.
9 
10  LifeV is free software; you can redistribute it and/or modify
11  it under the terms of the GNU Lesser General Public License as published by
12  the Free Software Foundation, either version 3 of the License, or
13  (at your option) any later version.
14 
15  LifeV is distributed in the hope that it will be useful,
16  but WITHOUT ANY WARRANTY; without even the implied warranty of
17  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18  Lesser General Public License for more details.
19 
20  You should have received a copy of the GNU Lesser General Public License
21  along with LifeV. If not, see <http://www.gnu.org/licenses/>.
22 
23 *******************************************************************************
24 */
25 //@HEADER
26 
27 /* ========================================================
28 
29 Simple VectorSmall class test
30 
31 */
32 
33 
34 /**
35  @file test_vectorsmall.cpp
36  @author A. Cervone <ant.cervone@gmail.com>
37  @date 2011-06-15
38 */
39 
40 
41 // ===================================================
42 //! Includes
43 // ===================================================
44 
45 #include <lifev/core/LifeV.hpp>
46 #include <lifev/core/array/VectorSmall.hpp>
47 
48 using namespace LifeV;
49 
50 // ===================================================
51 //! Main
52 // ===================================================
53 int main()
54 {
55  // test for dim = 3
56  Vector3D v1 ( 1., 1., 2. ), v2 ( 0., 1., 0. ), v3;
57 
58  std::cout << v1 << std::endl << std::endl;
59  std::cout << v2 << std::endl << std::endl;
60  std::cout << v3 << std::endl << std::endl;
61  std::cout << v1[ 0 ] << std::endl << std::endl;
62  v1 [ 0 ] = 0.;
63  std::cout << v1[ 0 ] << std::endl << std::endl;
64  std::cout << v1 ( 0 ) << std::endl << std::endl;
65  v1 ( 0 ) = 1.;
66  std::cout << v1 ( 0 ) << std::endl << std::endl;
67  std::cout << v1 + v2 << std::endl << std::endl;
68  std::cout << v1 - v2 << std::endl << std::endl;
69  std::cout << 2. * v1 << std::endl << std::endl;
70  std::cout << v1 / 2. << std::endl << std::endl;
71  std::cout << v1.dot ( v2 ) << std::endl << std::endl;
72  std::cout << v1.cross ( v2 ) << std::endl << std::endl;
73  std::cout << v1.normalized() << std::endl << std::endl;
74  v1.normalize();
75  std::cout << v1 << std::endl << std::endl;
76 
77  std::vector<Real> v4 ( 3, 1. );
78  std::cout << castToVector3D ( v4 ) << std::endl << std::endl;
79  KN<Real> v5 ( 3, 2. );
80  std::cout << castToVector3D ( v5 ) << std::endl << std::endl;
81 
82 
83  // test for dim = 5
84  VectorSmall<5> a, b;
85  for ( UInt i = 0; i < 5; i++ )
86  {
87  a[ i ] = i;
88  b ( i ) = 4 - i;
89  }
90 
91  std::cout << a << std::endl << std::endl;
92  std::cout << b << std::endl << std::endl;
93  std::cout << a + b << std::endl << std::endl;
94  std::cout << a - b << std::endl << std::endl;
95  std::cout << 0.5 * a << std::endl << std::endl;
96  std::cout << b / 2. << std::endl << std::endl;
97  std::cout << a.dot (b) << std::endl << std::endl;
98  std::cout << a.normalized() << std::endl << std::endl;
99  b.normalize();
100  std::cout << b << std::endl << std::endl;
101 
102  std::vector<Real> c ( 5, 1. );
103  std::cout << castToVectorSmall<5> ( c ) << std::endl << std::endl;
104  KN<Real> d ( 5, 2. );
105  std::cout << castToVectorSmall<5> ( d ) << std::endl << std::endl;
106 
107  VectorSmall<10> v6 = VectorSmall<10>::Constant ( 3. );
108  std::cout << v6 << std::endl << std::endl;
109  v6 = VectorSmall<10>::Zero();
110  std::cout << v6 << std::endl << std::endl;
111 
112  return 0;
113 }
void updateInverseJacobian(const UInt &iQuadPt)
void normalize()
Normalize vector.
Real & operator[](UInt const &i)
Operator [].
double Real
Generic real data.
Definition: LifeV.hpp:175
VectorSmall< 3 > Vector3D
VectorSmall(Real const &x, Real const &y, Real const &z)
Full constructor with all components explicitly initialized.
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
Real & operator()(UInt const &i)
Operator ()