libMesh
Loading...
Searching...
No Matches
parameter_multipointer.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_MULTIPOINTER_H
21#define LIBMESH_PARAMETER_MULTIPOINTER_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
31namespace libMesh
32{
33
46template <typename T=Number>
48{
49public:
54
58 ParameterMultiPointer(T * param_ptr) : _ptrs(1, param_ptr) {}
59
63 virtual void set (const T & new_value) override
64 {
65 libmesh_assert(!_ptrs.empty());
66#ifndef NDEBUG
67 // Compare other values to the last one we'll change
68 const T & val = *_ptrs.back();
69#endif
70 for (auto & ptr : _ptrs)
71 {
72 // If you're already using inconsistent parameters we can't
73 // help you.
74 libmesh_assert_equal_to(*ptr, val);
75 *ptr = new_value;
76 }
77 }
78
82 virtual const T & get () const override
83 {
84 libmesh_assert(!_ptrs.empty());
85 T & val = *_ptrs[0];
86#ifndef NDEBUG
87 // If you're already using inconsistent parameters we can't help
88 // you.
89 for (auto ptr : _ptrs)
90 libmesh_assert_equal_to(*ptr, val);
91#endif
92 return val;
93 }
94
98 virtual std::unique_ptr<ParameterAccessor<T>> clone() const override
99 {
100 auto pmp = std::make_unique<ParameterMultiPointer<T>>();
101 pmp->_ptrs = _ptrs;
102 return pmp;
103 }
104
105 void push_back (T * new_ptr) { _ptrs.push_back(new_ptr); }
106
111 std::size_t size() const { return _ptrs.size(); }
112
113private:
114 std::vector<T *> _ptrs;
115};
116
117} // namespace libMesh
118
119#endif // LIBMESH_PARAMETER_MULTIPOINTER_H
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
ParameterMultiPointer(T *param_ptr)
Constructor: take the first raw pointer to the parameter.
virtual std::unique_ptr< ParameterAccessor< T > > clone() const override
virtual void set(const T &new_value) override
Setter: change the value of the parameter we access.
virtual const T & get() const override
Getter: get the value of the parameter we access.
ParameterMultiPointer()
Constructor: no parameters attached yet.
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)