Logo  0.95.0-final
Finite Element Embedded Library and Language in C++
Feel++ Feel++ on Github Feel++ community
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
adtypeorder0.hpp
Go to the documentation of this file.
1 /* -*- mode: c++; coding: utf-8; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; show-trailing-whitespace: t -*- vim:fenc=utf-8:ft=tcl:et:sw=4:ts=4:sts=4
2 
3  This file is part of the Feel library
4 
5  Author(s): Christophe Prud'homme <christophe.prudhomme@feelpp.org>
6  Date: 2008-02-14
7 
8  Copyright (C) 2008 Université Joseph Fourier (Grenoble I)
9 
10  This library is free software; you can redistribute it and/or
11  modify it under the terms of the GNU Lesser General Public
12  License as published by the Free Software Foundation; either
13  version 3.0 of the License, or (at your option) any later version.
14 
15  This library 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
21  License along with this library; if not, write to the Free Software
22  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
23 */
29 #ifndef __ADTypeOrder0_H
30 #define __ADTypeOrder0_H 1
31 
32 namespace Feel
33 {
51 template<typename T, int Nvar, int Var>
52 class ADType<T, Nvar, 0, Var>
53 {
54 public:
55 
56  enum { nvar = Nvar };
57  enum { order = 1 };
58 
59  typedef ADVariable<Var> variable_type;
60 
61  typedef ADType<T, Nvar, 0, Var> This;
62 
63  typedef T value_type;
64 
65  template<typename NumT, int NumVar, int Order, int VarNum> friend class ADType;
66 
67  operator T()
68  {
69  return M_val;
70  }
71 
72  ADType ( T __v = 0 )
73  :
74  M_val ( __v )
75  {
76  }
77 
78  template<int VarNum>
79  ADType( ADType<T,Nvar,0,VarNum> const& sad )
80  :
81  M_val( sad.M_val )
82  {
83  }
84 
85  template<typename ExprT>
86  ADType ( const ADExpr<ExprT>& expr )
87  :
88  M_val( 0 )
89  {
90  *this = expr;
91  }
93 
97  value_type value() const
98  {
99  return M_val;
100  }
101 
102 
104 
108  value_type& value()
109  {
110  return M_val;
111  }
112 
114 
118 
119  This& operator=( T const& );
120  This& operator=( This const& );
121  template <class ExprT> This& operator=( const ADExpr<ExprT>& expr );
122 
124  ADExpr< ADUnaryPlus< This > > operator+ () const
125  {
126  typedef ADUnaryPlus<This> expr_t;
127  return ADExpr<expr_t> ( expr_t ( *this ) );
128  }
129 
131  ADExpr< ADUnaryMinus< This > > operator- () const
132  {
133  typedef ADUnaryMinus<This> expr_t;
134  return ADExpr<expr_t> ( expr_t ( *this ) );
135  }
136 
137 #define AD_UNARY_OP( op ) \
138  This& operator op ( value_type val ) \
139  { \
140  M_val op val; \
141  return *this; \
142  }
143  AD_UNARY_OP( += );
144  AD_UNARY_OP( -= );
145  AD_UNARY_OP( *= );
146  AD_UNARY_OP( /= );
147 
148 #undef AD_UNARY_OP
149 
150  This& operator += ( This const& sad )
151  {
152  M_val += sad.M_val;
153  return *this;
154  }
155  This& operator -= ( This const& sad )
156  {
157  M_val -= sad.M_val;
158  return *this;
159  }
160 
161 
162  This& operator *= ( This const& sad )
163  {
164  M_val *= sad.M_val;
165  return *this;
166  }
167 
168  This& operator /= ( This const& sad )
169  {
170  M_val /= sad.M_val;
171  return *this;
172  }
173 
174  template<typename Expr>
175  This& operator += ( ADExpr<Expr> const& sad )
176  {
177  *this = *this + sad;
178  return *this;
179  }
180 
181  template<typename Expr>
182  This& operator -= ( ADExpr<Expr> const& sad )
183  {
184  *this = *this - sad;
185  return *this;
186  }
187 
188  template<typename Expr>
189  This& operator *= ( ADExpr<Expr> const& sad )
190  {
191  *this = *this * sad;
192  return *this;
193  }
194 
195  template<typename Expr>
196  This& operator /= ( ADExpr<Expr> const& sad )
197  {
198  *this = *this / sad;
199  return *this;
200  }
202 private:
203 
204  value_type M_val;
205 
206 };
207 template<typename T,int Nvar, int Var>
208 ADType<T, Nvar, 0, Var>&
209 ADType<T, Nvar, 0, Var>::operator=( value_type const& val )
210 {
211  M_val = val;
212  return *this;
213 }
214 
215 template<typename T,int Nvar, int Var>
216 ADType<T, Nvar, 0, Var>&
217 ADType<T, Nvar, 0, Var>::operator=( This const& sad )
218 {
219  M_val = sad.M_val;
220  return *this;
221 }
222 template<typename T,int Nvar, int Var>
223 template <class ExprT>
224 ADType<T,Nvar, 0, Var> &
225 ADType<T,Nvar, 0, Var>::operator=( const ADExpr<ExprT>& expr )
226 {
227  M_val = expr.value();
228  return *this;
229 }
230 
231 
232 }
233 //------------------------------- AD ostream operator ------------------------------------------
234 template <class T, int Nvar, int Var>
235 std::ostream&
236 operator << ( std::ostream& os, const Feel::ADType<T, Nvar, 0, Var>& a )
237 {
238  os.setf( std::ios::fixed,std::ios::floatfield );
239  os.width( 12 );
240  os << "value = " << a.value() << " \n";
241  return os;
242 }
243 
244 #endif

Generated on Fri Oct 25 2013 14:24:03 for Feel++ by doxygen 1.8.4