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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef SACADO_PARAMETERVECTORBASE_HPP
11 #define SACADO_PARAMETERVECTORBASE_HPP
12 
13 #include <vector>
14 
15 #include "Teuchos_Array.hpp"
16 
18 
19 namespace Sacado {
20 
26  template <typename FamilyType, typename BaseValueType>
28 
29  public:
30 
32  struct Entry {
33 
36 
38  BaseValueType baseValue;
39 
41  Entry(const Teuchos::RCP<FamilyType>& f, BaseValueType bv) :
42  family(f), baseValue(bv) {}
43 
44  };
45 
46  protected:
47 
50 
51  public:
52 
54  typedef typename EntryVector::iterator iterator;
55 
58 
61 
64  params(source.params) {}
65 
67  virtual ~ParameterVectorBase() {}
68 
71  params = source.params; return *this; }
72 
74  void addParam(const Teuchos::RCP<FamilyType>& family,
75  BaseValueType baseValue) {
76  params.push_back(Entry(family, baseValue));
77  }
78 
80  unsigned int size() const { return params.size(); }
81 
83  Entry& operator[] (int i) { return params[i]; }
84 
86  const Entry& operator[] (int i) const { return params[i]; }
87 
89  iterator begin() { return params.begin(); }
90 
92  const_iterator begin() const { return params.begin(); }
93 
95  iterator end() { return params.end(); }
96 
98  const_iterator end() const { return params.end(); }
99 
101  void
103  ParameterVectorBase& analytic,
104  ParameterVectorBase& other,
105  std::vector<int>& index_ad,
106  std::vector<int>& index_analytic,
107  std::vector<int>& index_other) {
108  index_ad.resize(0);
109  index_analytic.resize(0);
110  index_other.resize(0);
111 
112  typename EntryVector::iterator it;
113  int i;
114  for (it = params.begin(), i=0; it != params.end(); ++it, ++i) {
115  if ((*it).family->supportsAD()) {
116  ad.params.push_back(*it);
117  index_ad.push_back(i);
118  }
119  else if ((*it).family->supportsAnalytic()) {
120  analytic.params.push_back(*it);
121  index_analytic.push_back(i);
122  }
123  else {
124  other.params.push_back(*it);
125  index_other.push_back(i);
126  }
127  }
128  }
129 
130  protected:
131 
134  };
135 }
136 
137 #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.