Loading [MathJax]/extensions/tex2jax.js
libMesh
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Pages
parameter_vector.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2025 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:
50  ParameterVector() = default;
51 
55  explicit
56  ParameterVector(const std::vector<Number *> & params);
57 
61  ~ParameterVector() = default;
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<std::unique_ptr<ParameterAccessor<Number>>> _params;
143 
147  std::vector<Number> _my_data;
148 
149 #ifndef NDEBUG
150 
153  bool _is_shallow_copy = false;
154 #endif
155 };
156 
157 
158 
159 // ------------------------------------------------------------
160 // ParameterVector inline methods
161 
162 
163 inline
164 void
166 {
167  _params.clear();
168  _my_data.clear();
169 }
170 
171 
172 
173 inline
174 void ParameterVector::push_back(std::unique_ptr<ParameterAccessor<Number>> new_accessor)
175 {
176  // Can't append stuff we are responsible for if we're already a shallow copy.
178  libmesh_assert(new_accessor.get());
179  _params.push_back(std::move(new_accessor));
180 }
181 
182 
183 
184 inline
186 {
187  libmesh_assert_greater (_params.size(), i);
188 
189  return *_params[i];
190 }
191 
192 
193 
194 inline
196 {
197  libmesh_assert_greater (_params.size(), i);
198 
199  return *_params[i];
200 }
201 
202 } // namespace libMesh
203 
204 #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)
Sets the number of parameters to be used.
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...
void deep_resize(std::size_t s)
Sets the number of parameters to be used.
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
~ParameterVector()=default
Destructor - deletes ParameterAccessor objects.
The libMesh namespace provides an interface to certain functionality in the library.
ParameterVector & operator*=(const Number a)
Multiplication operator; acts individually on each parameter.
bool _is_shallow_copy
Am I a shallow copy? If so then resizing me would be a bug.
libmesh_assert(ctx)
void clear()
Resets to "no parameters".
void push_back(std::unique_ptr< ParameterAccessor< Number >> new_accessor)
Adds an additional parameter accessor to the end of the vector.
ParameterVector()=default
Default constructor: "no parameters".
std::vector< std::unique_ptr< ParameterAccessor< Number > > > _params
Pointers to parameters which may exist elsewhere.
std::vector< Number > _my_data
Parameters which I own; e.g.
ParameterVector & operator+=(const ParameterVector &a)
Addition operator.
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.
void shallow_copy(ParameterVector &target) const
Shallow copy constructor: the target will now point to all the parameter values I&#39;m pointing to...
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...