Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_Fad_SimpleFad.hpp
Go to the documentation of this file.
00001 // $Id$ 
00002 // $Source$ 
00003 // @HEADER
00004 // ***********************************************************************
00005 // 
00006 //                           Sacado Package
00007 //                 Copyright (2006) Sandia Corporation
00008 // 
00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
00010 // the U.S. Government retains certain rights in this software.
00011 // 
00012 // This library is free software; you can redistribute it and/or modify
00013 // it under the terms of the GNU Lesser General Public License as
00014 // published by the Free Software Foundation; either version 2.1 of the
00015 // License, or (at your option) any later version.
00016 //  
00017 // This library is distributed in the hope that it will be useful, but
00018 // WITHOUT ANY WARRANTY; without even the implied warranty of
00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00020 // Lesser General Public License for more details.
00021 //  
00022 // You should have received a copy of the GNU Lesser General Public
00023 // License along with this library; if not, write to the Free Software
00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
00025 // USA
00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
00027 // (etphipp@sandia.gov).
00028 // 
00029 // ***********************************************************************
00030 // @HEADER
00031 
00032 #ifndef SACADO_FAD_SIMPLEFAD_HPP
00033 #define SACADO_FAD_SIMPLEFAD_HPP
00034 
00035 #include "Sacado_Fad_SimpleFadTraits.hpp"
00036 #include "Sacado_Fad_DynamicStorage.hpp"
00037 #include "Sacado_dummy_arg.hpp"
00038 
00039 namespace Sacado {
00040 
00041   namespace Fad {
00042 
00053     template <typename ValueT>
00054     class SimpleFad : public GeneralFad<ValueT,DynamicStorage<ValueT> >  {
00055 
00056     public:
00057 
00059       typedef ValueT value_type;
00060 
00062       typedef typename ScalarType<ValueT>::type ScalarT;
00063 
00065       template <typename T> 
00066       struct apply {
00067   typedef SimpleFad<T> type;
00068       };
00069 
00074 
00076 
00079       SimpleFad() : 
00080   GeneralFad< ValueT,DynamicStorage<ValueT> >() {}
00081 
00083 
00086       SimpleFad(const ValueT& x) : 
00087   GeneralFad< ValueT,DynamicStorage<ValueT> >(x) {}
00088 
00090 
00094       SimpleFad(const typename dummy<ValueT,ScalarT>::type& x) : 
00095   GeneralFad< ValueT,DynamicStorage<ValueT> >(ValueT(x)) {}
00096 
00098 
00101       SimpleFad(const int sz, const ValueT& x) : 
00102   GeneralFad< ValueT,DynamicStorage<ValueT> >(sz,x) {}
00103 
00105 
00110       SimpleFad(const int sz, const int i, const ValueT & x) : 
00111   GeneralFad< ValueT,DynamicStorage<ValueT> >(sz,i,x) {}
00112 
00114       SimpleFad(const SimpleFad& x) : 
00115   GeneralFad< ValueT,DynamicStorage<ValueT> >(x) {}
00116 
00118       SimpleFad(const SimpleFad& x, const ValueT& v, const ValueT& partial) :
00119   GeneralFad< ValueT,DynamicStorage<ValueT> >(x.size(), v) {
00120   for (int i=0; i<this->size(); i++)
00121     this->fastAccessDx(i) = x.fastAccessDx(i)*partial;
00122       }
00123 
00125 
00127       ~SimpleFad() {}
00128 
00130       bool isEqualTo(const SimpleFad& x) const {
00131   typedef IsEqual<value_type> IE;
00132   if (x.size() != this->size()) return false;
00133   bool eq = IE::eval(x.val(), this->val());
00134   for (int i=0; i<this->size(); i++)
00135     eq = eq && IE::eval(x.dx(i), this->dx(i));
00136   return eq;
00137       }
00138 
00140       SimpleFad& operator=(const ValueT& v) {
00141   GeneralFad< ValueT,DynamicStorage<ValueT> >::operator=(v);
00142   return *this;
00143       }
00144 
00146 
00149       SimpleFad& operator=(const typename dummy<ValueT,ScalarT>::type& v) {
00150   GeneralFad< ValueT,DynamicStorage<ValueT> >::operator=(ValueT(v));
00151   return *this;
00152       }
00153 
00155       SimpleFad& operator=(const SimpleFad& x) {
00156   GeneralFad< ValueT,DynamicStorage<ValueT> >::operator=(static_cast<const GeneralFad< ValueT,DynamicStorage<ValueT> >&>(x));
00157   return *this;
00158       }
00159 
00161       SimpleFad& operator += (const SimpleFad& x);
00162 
00164       SimpleFad& operator -= (const SimpleFad& x);
00165   
00167       SimpleFad& operator *= (const SimpleFad& x);
00168 
00170       SimpleFad& operator /= (const SimpleFad& x);
00171   
00172     }; // class SimpleFad<ValueT>
00173 
00174   } // namespace Fad
00175 
00176 } // namespace Sacado
00177 
00178 // Include method definitions
00179 #include "Sacado_Fad_SimpleFadImp.hpp"
00180 
00181 // Include elementary operation overloads
00182 #include "Sacado_Fad_SimpleFadOps.hpp"
00183 
00184 #endif // SACADO_FAD_SIMPLEFAD_HPP
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines