libMesh
Loading...
Searching...
No Matches
parameter_vector.h
Go to the documentation of this file.
1// The libMesh Finite Element Library.
2// Copyright (C) 2002-2026 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
32namespace libMesh
33{
34
35
45{
46public:
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
138private:
142 std::vector<std::unique_ptr<ParameterAccessor<Number>>> _params;
143
147 std::vector<Number> _my_data;
148
149#ifndef NDEBUG
153 bool _is_shallow_copy = false;
154#endif
155};
156
157
158
159// ------------------------------------------------------------
160// ParameterVector inline methods
161
162
163inline
164void
166{
167 _params.clear();
168 _my_data.clear();
169}
170
171
172
173inline
174void 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
184inline
186{
187 libmesh_assert_greater (_params.size(), i);
188
189 return *_params[i];
190}
191
192
193
194inline
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
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
Data structure for specifying which Parameters should be independent variables in a parameter sensiti...
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...
void clear()
Resets to "no parameters".
ParameterVector()=default
Default constructor: "no parameters".
void deep_resize(std::size_t s)
Sets the number of parameters to be used.
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,...
ParameterVector & operator*=(const Number a)
Multiplication operator; acts individually on each parameter.
void shallow_copy(ParameterVector &target) const
Shallow copy constructor: the target will now point to all the parameter values I'm pointing to.
std::vector< Number > _my_data
Parameters which I own; e.g.
std::vector< std::unique_ptr< ParameterAccessor< Number > > > _params
Pointers to parameters which may exist elsewhere.
const ParameterAccessor< Number > & operator[](std::size_t i) const
void resize(std::size_t s)
Sets the number of parameters to be used.
~ParameterVector()=default
Destructor - deletes ParameterAccessor objects.
bool _is_shallow_copy
Am I a shallow copy? If so then resizing me would be a bug.
void push_back(std::unique_ptr< ParameterAccessor< Number > > new_accessor)
Adds an additional parameter accessor to the end of the vector.
std::size_t size() const
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)