LifeV
TestFunction.hpp
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  * @file
29  * @brief File containing the Vector Container Test
30  *
31  * @date 29-09-2009
32  * @author Cristiano Malossi <cristiano.malossi@epfl.ch>
33  *
34  * @maintainer Cristiano Malossi <cristiano.malossi@epfl.ch>
35  */
36 
37 
38 #include <iomanip>
39 #include <string>
40 
41 
42 
43 // LifeV includes
44 #include <lifev/core/LifeV.hpp>
45 #include <lifev/core/array/VectorContainer.hpp>
46 
47 using namespace LifeV;
48 
49 template < class VectorType >
50 UInt
51 TestFunction ( std::shared_ptr<VectorType> A1, std::shared_ptr<VectorType> B1,
52  std::shared_ptr<VectorType> A2, std::shared_ptr<VectorType> B2,
53  std::shared_ptr<VectorType> A3, std::shared_ptr<VectorType> B3,
54  std::shared_ptr<VectorType> A4, std::shared_ptr<VectorType> B4 )
55 {
56  //CONTAINER OF BASE VECTORS
57  typedef VectorContainer< VectorType > ContainerOfBaseVectors;
58  typedef std::shared_ptr<ContainerOfBaseVectors> ContainerOfBaseVectors_ptr;
59 
60  ContainerOfBaseVectors_ptr V1, V2, V3, V4;
61  Real scalar = 1.0;
62 
63  V1.reset ( new ContainerOfBaseVectors() );
64  V1->push_back ( A1 );
65  V1->push_back ( B1 );
66  std::cout << "V1" << std::endl;
67  V1->showMe();
68 
69  V2.reset ( new ContainerOfBaseVectors() );
70  V2->push_back ( A2 );
71  V2->push_back ( B2 );
72  std::cout << "V2" << std::endl;
73  V2->showMe();
74 
75  V3.reset ( new ContainerOfBaseVectors() );
76  V3->push_back ( A3 );
77  V3->push_back ( B3 );
78  std::cout << "V3" << std::endl;
79  V3->showMe();
80 
81  V4.reset ( new ContainerOfBaseVectors() );
82  V4->push_back ( A4 );
83  V4->push_back ( B4 );
84  std::cout << "V4" << std::endl;
85  V4->showMe();
86 
87  // Test operator= (initialize a vector as a copy of another vector)
88  ContainerOfBaseVectors_ptr VV1, VV2, VV3;
89  VV1.reset ( new ContainerOfBaseVectors() );
90  *VV1 = *V1;
91  std::cout << "VV1 = V1" << std::endl;
92  VV1->showMe();
93 
94  // Test operator= (for initialize the vector with a scalar - cannot be done for an empty vector!)
95  *VV1 = scalar;
96  std::cout << "VV1 = 1.0" << std::endl;
97  VV1->showMe();
98 
99  // Test operator+=
100  *VV1 += *V1;
101  std::cout << "VV1 += V1" << std::endl;
102  VV1->showMe();
103 
104  // Test operator-
105  *VV1 = *VV1 - *V2;
106  std::cout << "VV1 = VV1 - V2" << std::endl;
107  VV1->showMe();
108 
109  // Test operator*= (multiplication: scalar * vector)
110  scalar = 1.23456789;
111  *VV1 = *V1;
112  *VV1 = scalar * *V1;
113  std::cout << "VV1 = 1.23456789 * V1" << std::endl;
114  VV1->showMe();
115 
116  // Test operator* (scalar product multiplication)
117  scalar = VV1->dot ( *V1 );
118  std::cout << "scalarProduct = VV1.Dot(V1) = " << scalar << std::endl << std::endl;
119 
120  // Concatenate two vector of vectors
121  VV1->push_back ( *V1 );
122  VV1->push_back ( *V2 );
123  std::cout << "VV1->push_back( V1 ); VV1->push_back( V2 )" << std::endl;
124  VV1->showMe();
125 
126  VV2.reset ( new ContainerOfBaseVectors() );
127  VV2->push_back ( *V3 );
128  VV2->push_back ( *V4 );
129  VV2->push_back ( *V3 );
130  std::cout << "VV2->push_back( V3 ); VV2->push_back( V4 ); VV2->push_back( V3 )" << std::endl;
131  VV2->showMe();
132 
133  // Element by element Multiplication
134  std::cout << "VV2 *= VV1" << std::endl;
135  *VV2 *= *VV1;
136  VV2->showMe();
137  std::cout << "VV1 =" << std::endl;
138  VV1->showMe();
139 
140  // Element by element Division
141  std::cout << "VV2 /= VV1" << std::endl;
142  *VV2 /= *VV1;
143  VV2->showMe();
144  std::cout << "VV1 =" << std::endl;
145  VV1->showMe();
146 
147  // Element by element Multiplication (NaN is interpreted as a zero)
148  std::cout << "VV2 && VV1" << std::endl;
149  (*VV2 && *VV1).showMe();
150 
151  // Element by element Comparison ==
152  std::cout << "VV1 == 0" << std::endl;
153  VV3.reset ( new ContainerOfBaseVectors() );
154  *VV3 = ( *VV1 == 0.0 );
155  VV3->showMe();
156 
157  // Element by element Comparison >=
158  std::cout << "VV1 >= 2.2" << std::endl;
159  *VV3 = ( *VV1 >= 2.2 );
160  VV3->showMe();
161 
162  // Abs
163  std::cout << "VV2 *= -1" << std::endl;
164  scalar = -1.0;
165  *VV2 *= scalar;
166  VV2->showMe();
167 
168  std::cout << "VV2->abs( *VV3 )" << std::endl;
169  VV2->abs ( *VV3 );
170  std::cout << "VV2:" << std::endl;
171  VV2->showMe();
172  std::cout << "VV3:" << std::endl;
173  VV3->showMe();
174 
175 
176 
177 
178 
179 
180 
181  // Replace a vector
182  UInt pos = 2;
183  (*VV1) ( pos ) = B1;
184  std::cout << "VV1( 2 ) = B1" << std::endl;
185  VV1->showMe();
186 
187  // Compute the weight norm2 of the vector
188  VV1->weightNorm2();
189  std::cout << "WeightNorm2(VV1) = " << VV1->weightNorm2() << std::endl << std::endl;
190 
191  // operator!
192  std::cout << "!VV1 " << std::endl;
193  (! (*VV1) ).showMe();
194 
195  std::cout << "!VV3 " << std::endl;
196  (! (*VV3) ).showMe();
197 
198  return EXIT_SUCCESS;
199 }
void updateInverseJacobian(const UInt &iQuadPt)
uint32_type UInt
generic unsigned integer (used mainly for addressing)
Definition: LifeV.hpp:191
UInt TestFunction(std::shared_ptr< VectorType > A1, std::shared_ptr< VectorType > B1, std::shared_ptr< VectorType > A2, std::shared_ptr< VectorType > B2, std::shared_ptr< VectorType > A3, std::shared_ptr< VectorType > B3, std::shared_ptr< VectorType > A4, std::shared_ptr< VectorType > B4)