libMesh
parameter_vector.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 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 
28 // C++ Includes
29 #include <vector>
30 #include <memory>
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(std::size_t s);
98 
106  void push_back(std::unique_ptr<ParameterAccessor<Number>> new_accessor);
107 
112  void deep_resize(std::size_t s);
113 
117  const ParameterAccessor<Number> & operator[](std::size_t i) const;
118 
125  ParameterAccessor<Number> & operator[](std::size_t 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 (auto & param : _params)
174  delete param;
175 
176  _params.clear();
177  _my_data.clear();
178 }
179 
180 
181 
182 inline
183 void ParameterVector::push_back(std::unique_ptr<ParameterAccessor<Number>> new_accessor)
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
libMesh::ParameterVector::size
std::size_t size() const
Definition: parameter_vector.h:90
libMesh::Number
Real Number
Definition: libmesh_common.h:195
libMesh::ParameterAccessor
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
Definition: parameter_accessor.h:55
libMesh::ParameterVector::operator+=
ParameterVector & operator+=(const ParameterVector &a)
Addition operator.
Definition: parameter_vector.C:118
libMesh::ParameterVector::ParameterVector
ParameterVector()
Default constructor: "no parameters".
Definition: parameter_vector.h:50
libMesh::ParameterVector::push_back
void push_back(std::unique_ptr< ParameterAccessor< Number >> new_accessor)
Adds an additional parameter accessor to the end of the vector.
Definition: parameter_vector.h:183
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ParameterVector::_my_data
std::vector< Number > _my_data
Parameters which I own; e.g.
Definition: parameter_vector.h:147
libMesh::ParameterVector::value_copy
void value_copy(ParameterVector &target) const
Value copy method: the target, which should already have as many parameters as I do,...
Definition: parameter_vector.C:63
libMesh::ParameterVector::deep_resize
void deep_resize(std::size_t s)
Sets the number of parameters to be used.
Definition: parameter_vector.C:95
libMesh::libmesh_assert
libmesh_assert(ctx)
libMesh::ParameterVector::_params
std::vector< ParameterAccessor< Number > * > _params
Pointers to parameters which may exist elsewhere.
Definition: parameter_vector.h:142
libMesh::ParameterVector::resize
void resize(std::size_t s)
Sets the number of parameters to be used.
Definition: parameter_vector.C:74
libMesh::ParameterVector::operator[]
const ParameterAccessor< Number > & operator[](std::size_t i) const
Definition: parameter_vector.h:194
libMesh::ParameterVector
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
Definition: parameter_vector.h:44
libMesh::ParameterVector::shallow_copy
void shallow_copy(ParameterVector &target) const
Shallow copy constructor: the target will now point to all the parameter values I'm pointing to.
Definition: parameter_vector.C:54
libMesh::ParameterVector::clear
void clear()
Resets to "no parameters".
Definition: parameter_vector.h:170
libMesh::ParameterVector::~ParameterVector
~ParameterVector()
Destructor - deletes ParameterAccessor objects.
Definition: parameter_vector.h:162
libMesh::ParameterVector::deep_copy
void deep_copy(ParameterVector &target) const
Deep copy constructor: the target will now own new copies of all the parameter values I'm pointing to...
Definition: parameter_vector.C:38
libMesh::ParameterVector::_is_shallow_copy
bool _is_shallow_copy
Am I a shallow copy? If so then I shouldn't be deleting my ParameterAccessors.
Definition: parameter_vector.h:153
libMesh::ParameterVector::operator*=
ParameterVector & operator*=(const Number a)
Multiplication operator; acts individually on each parameter.
Definition: parameter_vector.C:108