libMesh
parameter_vector.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_PARAMETER_VECTOR_H
21 #define LIBMESH_PARAMETER_VECTOR_H
22 
23 
24 // Local Includes
25 #include "libmesh/libmesh_common.h"
26 #include "libmesh/parameter_accessor.h"
27 #include "libmesh/auto_ptr.h"
28 
29 // C++ Includes
30 #include <vector>
31 
32 namespace libMesh
33 {
34 
35 
45 {
46 public:
51 
55  explicit
56  ParameterVector(const std::vector<Number *> & params);
57 
62 
67  void deep_copy(ParameterVector & target) const;
68 
73  void shallow_copy(ParameterVector & target) const;
74 
80  void value_copy(ParameterVector & target) const;
81 
85  void clear();
86 
90  std::size_t size() const { return _params.size(); }
91 
97  void resize(unsigned int s);
98 
106  void push_back(UniquePtr<ParameterAccessor<Number>> new_accessor);
107 
112  void deep_resize(unsigned int s);
113 
117  const ParameterAccessor<Number> & operator[](unsigned int i) const;
118 
125  ParameterAccessor<Number> & operator[](unsigned int i);
126 
131 
137 
138 private:
142  std::vector<ParameterAccessor<Number> *> _params;
143 
147  std::vector<Number> _my_data;
148 
154 };
155 
156 
157 
158 // ------------------------------------------------------------
159 // ParameterVector inline methods
160 
161 inline
163 {
164  this->clear();
165 }
166 
167 
168 inline
169 void
171 {
172  if (!_is_shallow_copy)
173  for (std::size_t i=0; i != _params.size(); ++i)
174  delete _params[i];
175 
176  _params.clear();
177  _my_data.clear();
178 }
179 
180 
181 
182 inline
184 {
185  // Can't append stuff we are responsible for if we're already a shallow copy.
187  libmesh_assert(new_accessor.get());
188  _params.push_back(new_accessor.release());
189 }
190 
191 
192 
193 inline
195 {
196  libmesh_assert_greater (_params.size(), i);
197 
198  return *_params[i];
199 }
200 
201 
202 
203 inline
205 {
206  libmesh_assert_greater (_params.size(), i);
207 
208  return *_params[i];
209 }
210 
211 } // namespace libMesh
212 
213 #endif // LIBMESH_PARAMETER_VECTOR_H
void push_back(UniquePtr< ParameterAccessor< Number >> new_accessor)
Adds an additional parameter accessor to the end of the vector.
void resize(unsigned int s)
Sets the number of parameters to be used.
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
void value_copy(ParameterVector &target) const
Value copy method: the target, which should already have as many parameters as I do, will now have those parameters set to my values.
std::vector< ParameterAccessor< Number > * > _params
Pointers to parameters which may exist elsewhere.
The libMesh namespace provides an interface to certain functionality in the library.
ParameterVector & operator*=(const Number a)
Multiplication operator; acts individually on each parameter.
libmesh_assert(j)
std::unique_ptr< T > UniquePtr
Definition: auto_ptr.h:46
bool _is_shallow_copy
Am I a shallow copy? If so then I shouldn&#39;t be deleting my ParameterAccessors.
void deep_resize(unsigned int s)
Sets the number of parameters to be used.
void shallow_copy(ParameterVector &target) const
Shallow copy constructor: the target will now point to all the parameter values I&#39;m pointing to...
~ParameterVector()
Destructor - deletes ParameterAccessor objects.
void clear()
Resets to "no parameters".
std::size_t size() const
void deep_copy(ParameterVector &target) const
Deep copy constructor: the target will now own new copies of all the parameter values I&#39;m pointing to...
ParameterVector()
Default constructor: "no parameters".
const ParameterAccessor< Number > & operator[](unsigned int i) const
std::vector< Number > _my_data
Parameters which I own; e.g.
ParameterVector & operator+=(const ParameterVector &a)
Addition operator.
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...