LifeV
RNMTemplate.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 implementation of the templated method/classes of RNM.hpp
30 
31  @contributor Matteo Astorino <matteo.astorino@epfl.ch>
32  @mantainer Matteo Astorino <matteo.astorino@epfl.ch>
33 
34  */
35 #ifndef RNM_tpl_
36 #define RNM_tpl_
37 
38 #include <lifev/core/array/RNM.hpp>
39 
40 namespace LifeV
41 {
42 
43 // version du 22 nov 1999
44 // Voila une debut de class vecteur + matrice
45 // les class avec termine avec un _ ne travail que sur
46 // un pointeur existant => pas de new et delete de pointeur
47 // la class correspondant sans de _ genere les pointeurs
48 //
49 // avec ses classes on peut prendre une ligne
50 // ou une colonne d'une matrice
51 // -----------------------
52 
53 
54 template <class R>
55 void MatMul ( KNM_<R>& ab, KNM_<R>& a, KNM_<R>& b )
56 {
57  // attention ne marche que si les adresses ne sont pas les memes
58  int N = a.shapei.n;
59  int M = a.shapej.n;
60  K_assert ( a.shapej.n == a.shapei.n );
61  K_assert ( a.shapei.n == ab.shapei.n );
62  K_assert ( b.shapej.n == ab.shapej.n );
63  K_assert ( b.v != ab.v );
64  K_assert ( a.v != ab.v );
65  KN_<R> ai = a ( 0 );
66  for ( int i = 1; i < N; i++, ++ai )
67  {
68  KN_<R> bj = b[ 0 ];
69  for ( int j = 1; j < M; j++, ++bj )
70  {
71  ab ( i, j ) = ( ai , bj ) ;
72  }
73  }
74 }
75 
76 
77 
78 inline std::ostream& operator<< ( std::ostream& f, const ShapeOfArray& s )
79 {
80  f << s.n ;
81  if ( s.step != 1 )
82  {
83  f << ":" << s.step ;
84  }
85  if ( s.step * s.n != s.next )
86  {
87  f << " n: " << std::setw ( 3 ) << s.next ;
88  }
89  f << ",";
90  return f;
91 }
92 
93 template <class R>
94 std::ostream& operator<< ( std::ostream& f, const KN_<const_R>& v )
95 {
96  //f << " KN_ : " << (ShapeOfArray) v << " " << (const_R *) v << " :\n\t" ;
97  f << v.N() << "\t:\t" ;
98  for ( int i = 0; i < v.N(); i++ )
99  {
100  std::cout << std::setw ( 3 ) << v[ i ] << ( ( i % 10 ) == 9 ? "\n\t" : "\t" );
101  }
102  return f;
103 }
104 
105 template <class R>
106 std::ostream& operator<< ( std::ostream& f, const KNM_<const_R>& v )
107 {
108  //f << " KNM_ "<<v.N()<<"x"<<v.M()<< ": " << (ShapeOfArray) v
109  //<< " i " << v.shapei
110  // << " j " << v.shapej
111  // << " " << &v(0,0) << " :\n\t";
112  f << v.N() << 'x' << v.M() /*<< " n" << v.next<<" :"<< v.shapei.next << "," << v.shapej.next */ << "\t:\n\t" ;
113  for ( int i = 0; i < v.N(); i++ )
114  {
115  for ( int j = 0; j < v.M(); j++ )
116  {
117  std::cout << " " << std::setw ( 3 ) << v ( i, j );
118  }
119  std::cout << "\n\t";
120  }
121  return f;
122 
123 }
124 
125 template <class R>
126 std::ostream& operator<< ( std::ostream& f, const KNMK_<const_R>& v )
127 {
128  //f << " KNM_" <<v.N()<<"x"<<v.M()<<"x"<<v.K()<< " : " << (ShapeOfArray) v
129  // << " i " << v.shapei
130  // << " j " << v.shapej
131  // << " k " << v.shapek << std::endl;
132  // << " " << (void *) & v(0,0,0) << "\n\t" ;
133  f << v.N() << 'x' << v.M() << 'x' << v.K() << "\t:\n\t" ;
134  for ( int i = 0; i < v.shapei.n; i++ )
135  {
136  for ( int j = 0; j < v.shapej.n; j++ )
137  {
138  for ( int k = 0; k < v.shapek.n; k++ )
139  {
140  std::cout << " " << std::setw ( 3 ) << v ( i, j, k );
141  }
142  std::cout << "\n\t";
143  }
144  std::cout << "\n\t";
145  }
146  return f;
147 
148 }
149 
150 template <class R>
151 R KN_<R>::operator, ( const KN_<const_R>& u ) const
152 {
153  K_assert ( u.n == n );
154  double s = 0;
155  R* l ( v );
156  R* r ( u.v );
157  for ( int i = 0; i < n; i++, l += step, r += u.step )
158  {
159  s += *l * *r;
160  }
161  return s;
162 }
163 
164 
165 template <class R>
166 R KN_<R>::KNMmin() const
167 {
168  R minv = v[ index ( 0 ) ];
169  for ( int i = 1; i < n; i++ )
170  {
171  minv = minv < v[ index ( i ) ] ? minv : v[ index ( i ) ];
172  }
173  return minv;
174 }
175 template <class R>
176 R KN_<R>::KNMmax() const
177 {
178  R maxv = v[ index ( 0 ) ];
179  for ( int i = 1; i < n; i++ )
180  {
181  maxv = maxv > v[ index ( i ) ] ? maxv : v[ index ( i ) ];
182  }
183  return maxv;
184 }
185 
186 template <class R>
187 R KN_<R>::sum() const
188 {
189  R s = v[ index ( 0 ) ];
190  for ( int i = 1; i < n; i++ )
191  {
192  s += v[ index ( i ) ];
193  }
194  return s;
195 }
196 template <class R>
197 KN_<R>& KN_<R>::map ( R ( *f ) ( R ) )
198 {
199  for ( int i = 0; i < n; i++ )
200  {
201  R& x ( v[ index ( i ) ] );
202  x = f ( x );
203  }
204  return *this;
205 }
206 
207 }
208 ///////////////// definition des operateurs d'affectation /////////////////////////
209 #define oper =
210 #include <lifev/core/array/RNMOperator.hpp>
211 #include <lifev/core/array/RNMOperatorConstant.hpp>
212 #define oper +=
213 #include <lifev/core/array/RNMOperator.hpp>
214 #include <lifev/core/array/RNMOperatorConstant.hpp>
215 #define oper -=
216 #include <lifev/core/array/RNMOperator.hpp>
217 #include <lifev/core/array/RNMOperatorConstant.hpp>
218 #define oper *=
219 #include <lifev/core/array/RNMOperatorConstant.hpp>
220 #define oper /=
221 #include <lifev/core/array/RNMOperatorConstant.hpp>
222 
223 #endif
R KNMmin() const
void updateInverseJacobian(const UInt &iQuadPt)
R * v
Definition: RNM.hpp:275
const int next
Definition: RNM.hpp:182
const int n
Definition: RNM.hpp:180
const int step
Definition: RNM.hpp:181
int index(int k) const
Definition: RNM.hpp:219
KN_ & map(R(*)(R))
R KNMmax() const
R operator,(const KN_< R > &v) const
#define K_assert(i)
Definition: RNM.hpp:59
void MatMul(KNM_< R > &ab, KNM_< R > &a, KNM_< R > &b)
Definition: RNMTemplate.hpp:55
#define const_R
Definition: RNM.hpp:48
R sum() const