Sacado Package Browser (Single Doxygen Collection) Version of the Day
Sacado_ParameterVectorBase.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_PARAMETERVECTORBASE_HPP
00033 #define SACADO_PARAMETERVECTORBASE_HPP
00034 
00035 #include <vector>
00036 
00037 #include "Teuchos_Array.hpp"
00038 
00039 #include "Sacado_ParameterFamilyBase.hpp"
00040 
00041 namespace Sacado {
00042 
00048   template <typename FamilyType, typename BaseValueType>
00049   class ParameterVectorBase  {
00050 
00051   public:
00052 
00054     struct Entry {
00055 
00057       Teuchos::RCP<FamilyType> family;
00058 
00060       BaseValueType baseValue;
00061 
00063       Entry(const Teuchos::RCP<FamilyType>& f, BaseValueType bv) :
00064         family(f), baseValue(bv) {}
00065 
00066     };
00067 
00068   protected:
00069 
00071     typedef Teuchos::Array<Entry> EntryVector;
00072 
00073   public:
00074 
00076     typedef typename EntryVector::iterator iterator;
00077 
00079     typedef typename EntryVector::const_iterator const_iterator;
00080   
00082     ParameterVectorBase() {}
00083 
00085     ParameterVectorBase(const ParameterVectorBase& source) : 
00086       params(source.params) {}
00087 
00089     virtual ~ParameterVectorBase() {}
00090 
00092     ParameterVectorBase& operator = (const ParameterVectorBase& source) {
00093       params = source.params; return *this; }
00094 
00096     void addParam(const Teuchos::RCP<FamilyType>& family,
00097                   BaseValueType baseValue) { 
00098       params.push_back(Entry(family, baseValue));
00099     }
00100 
00102     unsigned int size() const { return params.size(); }
00103 
00105     Entry& operator[] (int i) { return params[i]; }
00106 
00108     const Entry& operator[] (int i) const { return params[i]; }
00109 
00111     iterator begin() { return params.begin(); }
00112 
00114     const_iterator begin() const { return params.begin(); }
00115 
00117     iterator end() { return params.end(); }
00118 
00120     const_iterator end() const { return params.end(); }
00121 
00123     void
00124     filterParameters(ParameterVectorBase& ad,
00125                      ParameterVectorBase& analytic,
00126                      ParameterVectorBase& other,
00127                      std::vector<int>& index_ad,
00128                      std::vector<int>& index_analytic,
00129                      std::vector<int>& index_other) {
00130       index_ad.resize(0);
00131       index_analytic.resize(0);
00132       index_other.resize(0);
00133       
00134       typename EntryVector::iterator it;
00135       int i;
00136       for (it = params.begin(), i=0; it != params.end(); ++it, ++i) {
00137         if ((*it).family->supportsAD()) {
00138           ad.params.push_back(*it);
00139           index_ad.push_back(i);
00140         }
00141         else if ((*it).family->supportsAnalytic()) {
00142           analytic.params.push_back(*it);
00143           index_analytic.push_back(i);
00144         }
00145         else {
00146           other.params.push_back(*it);
00147           index_other.push_back(i);
00148         }
00149       }
00150     }
00151 
00152   protected:
00153 
00155     EntryVector params;
00156   };
00157 }
00158 
00159 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines