Sacado_Fad_VectorImp.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 #include "Sacado_DynamicArrayTraits.hpp"
00033 
00034 template <typename OrdinalType, typename ValueType>
00035 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00036 Vector(OrdinalType vec_size, OrdinalType deriv_sz, 
00037        VectorDerivOrientation orient) :
00038   deriv_size_(deriv_sz), orient_(orient), stride_(1), vec_(vec_size)
00039 {
00040   ValueType* x = NULL;
00041   ValueType* dx_ = NULL;
00042   if (vec_size > 0) {
00043     x = ds_array<ValueType>::get_and_fill(vec_size);
00044     if (deriv_size_ > 0)
00045       dx_ = ds_array<ValueType>::get_and_fill(vec_size*deriv_size_);
00046   }
00047   if (orient_ == Row) {
00048     stride_ = vec_size;
00049     for (OrdinalType i=0; i<vec_size; i++)
00050       vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
00051   }
00052   else {
00053     stride_ = 1;
00054     for (OrdinalType i=0; i<vec_size; i++)
00055       vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
00056   }
00057 }
00058 
00059 template <typename OrdinalType, typename ValueType>
00060 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00061 Vector(const Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >& fv) :
00062   deriv_size_(fv.deriv_size_), orient_(fv.orient_), stride_(fv.stride_), 
00063   vec_(fv.size())
00064 {
00065   OrdinalType vec_size = fv.size();
00066   ValueType* x = NULL;
00067   ValueType* dx_ = NULL;
00068   if (vec_size > 0) {
00069     x = ds_array<ValueType>::get_and_fill(vec_size);
00070     if (deriv_size_ > 0)
00071       dx_ = ds_array<ValueType>::get_and_fill(vec_size*deriv_size_);
00072   }
00073   if (orient_=Row) {
00074     for (OrdinalType i=0; i<vec_size; i++) {
00075       vec_[i].setMemory(deriv_size_, x+i, dx_+i, stride_);
00076       vec_[i] = fv.vec_[i];
00077     }
00078   }
00079   else {
00080     for (OrdinalType i=0; i<vec_size; i++) {
00081       vec_[i].setMemory(deriv_size_, x+i, dx_+i*deriv_size_, stride_);
00082       vec_[i] = fv.vec_[i];
00083     }
00084   }
00085 }
00086 
00087 template <typename OrdinalType, typename ValueType>
00088 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00089 ~Vector()
00090 {
00091   // Here we must destroy the value and derivative arrays
00092   if (vec_.size() > 0) {
00093     ValueType *v = vals();
00094     ds_array<ValueType>::destroy_and_release(v, vec_.size());
00095     if (deriv_size_ > 0) {
00096       v = dx();
00097       ds_array<ValueType>::destroy_and_release(v, vec_.size()*deriv_size_);
00098     }
00099   }
00100 }
00101 
00102 template <typename OrdinalType, typename ValueType>
00103 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >&
00104 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00105 operator=(const Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >& fv) 
00106 { 
00107   vec_ = fv.vec_; 
00108   return *this; 
00109 }
00110 
00111 template <typename OrdinalType, typename ValueType>
00112 ValueType* 
00113 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00114 vals() 
00115 { 
00116   if (vec_.size() == 0)
00117     return NULL;
00118   return &(vec_[0].val()); 
00119 }
00120 
00121 template <typename OrdinalType, typename ValueType>
00122 const ValueType* 
00123 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00124 vals() const 
00125 { 
00126   if (vec_.size() == 0)
00127     return NULL;
00128   return &(vec_[0].val()); 
00129 }
00130 
00131 template <typename OrdinalType, typename ValueType>
00132 ValueType* 
00133 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00134 dx() 
00135 { 
00136   if (vec_.size() == 0 || deriv_size_ == 0)
00137     return NULL;
00138   return &(vec_[0].fastAccessDx(0)); 
00139 }
00140 
00141 template <typename OrdinalType, typename ValueType>
00142 const ValueType* 
00143 Sacado::Fad::Vector< OrdinalType, Sacado::Fad::DVFad<ValueType> >::
00144 dx() const 
00145 { 
00146   if (vec_.size() == 0 || deriv_size_ == 0)
00147     return NULL;
00148   return &(vec_[0].fastAccessDx(0)); 
00149 }

Generated on Wed May 12 21:39:34 2010 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.4.7