Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ParameterVectorBase.hpp
Go to the documentation of this file.
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Sacado Package
5 // Copyright (2006) Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
9 //
10 // This library is free software; you can redistribute it and/or modify
11 // it under the terms of the GNU Lesser General Public License as
12 // published by the Free Software Foundation; either version 2.1 of the
13 // License, or (at your option) any later version.
14 //
15 // This library is distributed in the hope that it will be useful, but
16 // 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 St, Fifth Floor, Boston, MA 02110-1301
23 // USA
24 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25 // (etphipp@sandia.gov).
26 //
27 // ***********************************************************************
28 // @HEADER
29 
30 #ifndef SACADO_PARAMETERVECTORBASE_HPP
31 #define SACADO_PARAMETERVECTORBASE_HPP
32 
33 #include <vector>
34 
35 #include "Teuchos_Array.hpp"
36 
38 
39 namespace Sacado {
40 
46  template <typename FamilyType, typename BaseValueType>
48 
49  public:
50 
52  struct Entry {
53 
56 
58  BaseValueType baseValue;
59 
61  Entry(const Teuchos::RCP<FamilyType>& f, BaseValueType bv) :
62  family(f), baseValue(bv) {}
63 
64  };
65 
66  protected:
67 
70 
71  public:
72 
74  typedef typename EntryVector::iterator iterator;
75 
78 
81 
84  params(source.params) {}
85 
87  virtual ~ParameterVectorBase() {}
88 
91  params = source.params; return *this; }
92 
94  void addParam(const Teuchos::RCP<FamilyType>& family,
95  BaseValueType baseValue) {
96  params.push_back(Entry(family, baseValue));
97  }
98 
100  unsigned int size() const { return params.size(); }
101 
103  Entry& operator[] (int i) { return params[i]; }
104 
106  const Entry& operator[] (int i) const { return params[i]; }
107 
109  iterator begin() { return params.begin(); }
110 
112  const_iterator begin() const { return params.begin(); }
113 
115  iterator end() { return params.end(); }
116 
118  const_iterator end() const { return params.end(); }
119 
121  void
123  ParameterVectorBase& analytic,
124  ParameterVectorBase& other,
125  std::vector<int>& index_ad,
126  std::vector<int>& index_analytic,
127  std::vector<int>& index_other) {
128  index_ad.resize(0);
129  index_analytic.resize(0);
130  index_other.resize(0);
131 
132  typename EntryVector::iterator it;
133  int i;
134  for (it = params.begin(), i=0; it != params.end(); ++it, ++i) {
135  if ((*it).family->supportsAD()) {
136  ad.params.push_back(*it);
137  index_ad.push_back(i);
138  }
139  else if ((*it).family->supportsAnalytic()) {
140  analytic.params.push_back(*it);
141  index_analytic.push_back(i);
142  }
143  else {
144  other.params.push_back(*it);
145  index_other.push_back(i);
146  }
147  }
148  }
149 
150  protected:
151 
154  };
155 }
156 
157 #endif
iterator begin()
Iterator pointing at beginning of vector.
ParameterVectorBase(const ParameterVectorBase &source)
Copy constructor.
void filterParameters(ParameterVectorBase &ad, ParameterVectorBase &analytic, ParameterVectorBase &other, std::vector< int > &index_ad, std::vector< int > &index_analytic, std::vector< int > &index_other)
Filter vector into types.
BaseValueType baseValue
Base value of parameter family.
ParameterVectorBase()
Default constructor.
EntryVector::iterator iterator
Iterator typename.
EntryVector::const_iterator const_iterator
Const iterator typename.
Teuchos::RCP< FamilyType > family
Pointer to family.
void addParam(const Teuchos::RCP< FamilyType > &family, BaseValueType baseValue)
Add entry.
Container for parameter entries.
Entry & operator[](int i)
Element access.
EntryVector params
Parameter vector.
unsigned int size() const
Return number of parameters in vector.
ParameterVectorBase & operator=(const ParameterVectorBase &source)
Assignment.
Teuchos::Array< Entry > EntryVector
Vector of all parameter families.
iterator end()
std::vector< Entry >::const_iterator const_iterator
void push_back(const value_type &x)
A class to store the active parameters in a code in an ordered fashion, along with their &quot;base&quot; value...
size_type size() const
iterator end()
Iterator pointing at end of vector.
const_iterator end() const
Iterator pointing at end of vector.
std::vector< Entry >::iterator iterator
iterator begin()
Entry(const Teuchos::RCP< FamilyType > &f, BaseValueType bv)
Constructor.
const_iterator begin() const
Iterator pointing at beginning of vector.