parameter_vector.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 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"
27 #include "libmesh/auto_ptr.h" // deprecated
28 
29 // C++ Includes
30 #include <vector>
31 #include <memory>
32 
33 namespace libMesh
34 {
35 
36 
46 {
47 public:
52 
56  explicit
57  ParameterVector(const std::vector<Number *> & params);
58 
63 
68  void deep_copy(ParameterVector & target) const;
69 
74  void shallow_copy(ParameterVector & target) const;
75 
81  void value_copy(ParameterVector & target) const;
82 
86  void clear();
87 
91  std::size_t size() const { return _params.size(); }
92 
98  void resize(std::size_t s);
99 
107  void push_back(std::unique_ptr<ParameterAccessor<Number>> new_accessor);
108 
113  void deep_resize(std::size_t s);
114 
118  const ParameterAccessor<Number> & operator[](std::size_t i) const;
119 
126  ParameterAccessor<Number> & operator[](std::size_t i);
127 
132 
138 
139 private:
143  std::vector<ParameterAccessor<Number> *> _params;
144 
148  std::vector<Number> _my_data;
149 
155 };
156 
157 
158 
159 // ------------------------------------------------------------
160 // ParameterVector inline methods
161 
162 inline
164 {
165  this->clear();
166 }
167 
168 
169 inline
170 void
172 {
173  if (!_is_shallow_copy)
174  for (auto & param : _params)
175  delete param;
176 
177  _params.clear();
178  _my_data.clear();
179 }
180 
181 
182 
183 inline
184 void ParameterVector::push_back(std::unique_ptr<ParameterAccessor<Number>> new_accessor)
185 {
186  // Can't append stuff we are responsible for if we're already a shallow copy.
187  libmesh_assert(!_is_shallow_copy);
188  libmesh_assert(new_accessor.get());
189  _params.push_back(new_accessor.release());
190 }
191 
192 
193 
194 inline
196 {
197  libmesh_assert_greater (_params.size(), i);
198 
199  return *_params[i];
200 }
201 
202 
203 
204 inline
206 {
207  libmesh_assert_greater (_params.size(), i);
208 
209  return *_params[i];
210 }
211 
212 } // namespace libMesh
213 
214 #endif // LIBMESH_PARAMETER_VECTOR_H
std::size_t size() const
const ParameterAccessor< Number > & operator[](std::size_t i) const
void resize(std::size_t s)
void deep_copy(ParameterVector &target) const
void deep_resize(std::size_t s)
Specifies parameters for parameter sensitivity calculations.
std::vector< ParameterAccessor< Number > * > _params
ParameterVector & operator*=(const Number a)
void push_back(std::unique_ptr< ParameterAccessor< Number >> new_accessor)
std::vector< Number > _my_data
ParameterVector & operator+=(const ParameterVector &a)
void value_copy(ParameterVector &target) const
void shallow_copy(ParameterVector &target) const
Base class for reading/writing sensitivity parameters.