|
Sacado Package Browser (Single Doxygen Collection) Version of the Day
|
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 #include "Sacado_ConfigDefs.h" 00033 00034 template <typename ValueT> 00035 inline Sacado::Fad::SimpleFad<ValueT>& 00036 Sacado::Fad::SimpleFad<ValueT>:: 00037 operator += (const Sacado::Fad::SimpleFad<ValueT>& x) 00038 { 00039 int xsz = x.size(), sz = this->size(); 00040 00041 #ifdef SACADO_DEBUG 00042 if ((xsz != sz) && (xsz != 0) && (sz != 0)) 00043 throw "Fad Error: Attempt to assign with incompatible sizes"; 00044 #endif 00045 00046 if (xsz) { 00047 if (sz) { 00048 if (x.hasFastAccess()) 00049 for (int i=0; i<sz; ++i) 00050 this->fastAccessDx(i) += x.fastAccessDx(i); 00051 else 00052 for (int i=0; i<sz; ++i) 00053 this->fastAccessDx(i) += x.dx(i); 00054 } 00055 else { 00056 this->resize(xsz); 00057 if (x.hasFastAccess()) 00058 for (int i=0; i<xsz; ++i) 00059 this->fastAccessDx(i) = x.fastAccessDx(i); 00060 else 00061 for (int i=0; i<xsz; ++i) 00062 this->fastAccessDx(i) = x.dx(i); 00063 } 00064 } 00065 00066 this->val() += x.val(); 00067 00068 return *this; 00069 } 00070 00071 template <typename ValueT> 00072 inline Sacado::Fad::SimpleFad<ValueT>& 00073 Sacado::Fad::SimpleFad<ValueT>:: 00074 operator -= (const Sacado::Fad::SimpleFad<ValueT>& x) 00075 { 00076 int xsz = x.size(), sz = this->size(); 00077 00078 #ifdef SACADO_DEBUG 00079 if ((xsz != sz) && (xsz != 0) && (sz != 0)) 00080 throw "Fad Error: Attempt to assign with incompatible sizes"; 00081 #endif 00082 00083 if (xsz) { 00084 if (sz) { 00085 if (x.hasFastAccess()) 00086 for(int i=0; i<sz; ++i) 00087 this->fastAccessDx(i) -= x.fastAccessDx(i); 00088 else 00089 for (int i=0; i<sz; ++i) 00090 this->fastAccessDx(i) -= x.dx(i); 00091 } 00092 else { 00093 this->resize(xsz); 00094 if (x.hasFastAccess()) 00095 for(int i=0; i<xsz; ++i) 00096 this->fastAccessDx(i) = -x.fastAccessDx(i); 00097 else 00098 for (int i=0; i<xsz; ++i) 00099 this->fastAccessDx(i) = -x.dx(i); 00100 } 00101 } 00102 00103 this->val() -= x.val(); 00104 00105 00106 return *this; 00107 } 00108 00109 template <typename ValueT> 00110 inline Sacado::Fad::SimpleFad<ValueT>& 00111 Sacado::Fad::SimpleFad<ValueT>:: 00112 operator *= (const Sacado::Fad::SimpleFad<ValueT>& x) 00113 { 00114 int xsz = x.size(), sz = this->size(); 00115 ValueT xval = x.val(); 00116 00117 #ifdef SACADO_DEBUG 00118 if ((xsz != sz) && (xsz != 0) && (sz != 0)) 00119 throw "Fad Error: Attempt to assign with incompatible sizes"; 00120 #endif 00121 00122 if (xsz) { 00123 if (sz) { 00124 if (x.hasFastAccess()) 00125 for(int i=0; i<sz; ++i) 00126 this->fastAccessDx(i) = this->val() * x.fastAccessDx(i) + this->fastAccessDx(i) * xval; 00127 else 00128 for (int i=0; i<sz; ++i) 00129 this->fastAccessDx(i) = this->val() * x.dx(i) + this->fastAccessDx(i) * xval; 00130 } 00131 else { 00132 this->resize(xsz); 00133 if (x.hasFastAccess()) 00134 for(int i=0; i<xsz; ++i) 00135 this->fastAccessDx(i) = this->val() * x.fastAccessDx(i); 00136 else 00137 for (int i=0; i<xsz; ++i) 00138 this->fastAccessDx(i) = this->val() * x.dx(i); 00139 } 00140 } 00141 else { 00142 if (sz) { 00143 for (int i=0; i<sz; ++i) 00144 this->fastAccessDx(i) *= xval; 00145 } 00146 } 00147 00148 this->val() *= xval; 00149 00150 return *this; 00151 } 00152 00153 template <typename ValueT> 00154 inline Sacado::Fad::SimpleFad<ValueT>& 00155 Sacado::Fad::SimpleFad<ValueT>:: 00156 operator /= (const Sacado::Fad::SimpleFad<ValueT>& x) 00157 { 00158 int xsz = x.size(), sz = this->size(); 00159 ValueT xval = x.val(); 00160 00161 #ifdef SACADO_DEBUG 00162 if ((xsz != sz) && (xsz != 0) && (sz != 0)) 00163 throw "Fad Error: Attempt to assign with incompatible sizes"; 00164 #endif 00165 00166 if (xsz) { 00167 if (sz) { 00168 if (x.hasFastAccess()) 00169 for(int i=0; i<sz; ++i) 00170 this->fastAccessDx(i) = ( this->fastAccessDx(i)*xval - this->val()*x.fastAccessDx(i) )/ (xval*xval); 00171 else 00172 for (int i=0; i<sz; ++i) 00173 this->fastAccessDx(i) = ( this->fastAccessDx(i)*xval - this->val()*x.dx(i) )/ (xval*xval); 00174 } 00175 else { 00176 this->resize(xsz); 00177 if (x.hasFastAccess()) 00178 for(int i=0; i<xsz; ++i) 00179 this->fastAccessDx(i) = - this->val()*x.fastAccessDx(i) / (xval*xval); 00180 else 00181 for (int i=0; i<xsz; ++i) 00182 this->fastAccessDx(i) = -this->val() * x.dx(i) / (xval*xval); 00183 } 00184 } 00185 else { 00186 if (sz) { 00187 for (int i=0; i<sz; ++i) 00188 this->fastAccessDx(i) /= xval; 00189 } 00190 } 00191 00192 this->val() /= xval; 00193 00194 return *this; 00195 } 00196
1.7.4