libMesh
Loading...
Searching...
No Matches
parameter_multiaccessor.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_MULTIACCESSOR_H
21#define LIBMESH_PARAMETER_MULTIACCESSOR_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
59 _accessors(1, param_accessor.clone()) {}
60
61 /*
62 * Destructor
63 */
65
69 virtual void set (const T & new_value) override
70 {
71 libmesh_assert(!_accessors.empty());
72#ifndef NDEBUG
73 // Compare other values to the last one we'll change
74 const T & val = _accessors.back()->get();
75#endif
76 for (auto & accessor : _accessors)
77 {
78 // If you're already using inconsistent parameters we can't
79 // help you.
80 libmesh_assert_equal_to(accessor->get(), val);
81 accessor->set(new_value);
82 }
83 }
84
88 virtual const T & get () const override
89 {
90 libmesh_assert(!_accessors.empty());
91 const T & val = _accessors[0]->get();
92#ifndef NDEBUG
93 // If you're already using inconsistent parameters we can't help
94 // you.
95 for (const auto & accessor : _accessors)
96 libmesh_assert_equal_to(accessor->get(), val);
97#endif
98 return val;
99 }
100
104 virtual std::unique_ptr<ParameterAccessor<T>> clone() const override
105 {
106 auto pmp = std::make_unique<ParameterMultiAccessor<T>>();
107 for (auto & accessor : _accessors)
108 pmp->_accessors.push_back(accessor->clone());
109
110 return pmp;
111 }
112
113
114 void push_back (const ParameterAccessor<T> & new_accessor)
115 {
116 _accessors.push_back(new_accessor.clone());
117 }
118
124 std::size_t size() const { return _accessors.size(); }
125
126private:
127 std::vector<std::unique_ptr<ParameterAccessor<T>>> _accessors;
128};
129
130} // namespace libMesh
131
132#endif // LIBMESH_PARAMETER_MULTIACCESSOR_H
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
virtual std::unique_ptr< ParameterAccessor< T > > clone() const =0
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
virtual const T & get() const override
Getter: get the value of the parameter we access.
void push_back(const ParameterAccessor< T > &new_accessor)
virtual void set(const T &new_value) override
Setter: change the value of the parameter we access.
virtual std::unique_ptr< ParameterAccessor< T > > clone() const override
ParameterMultiAccessor(const ParameterAccessor< T > &param_accessor)
Constructor: take the first sub-accessor for the parameter.
std::vector< std::unique_ptr< ParameterAccessor< T > > > _accessors
ParameterMultiAccessor()=default
Constructor: no parameters attached yet.
The libMesh namespace provides an interface to certain functionality in the library.
libmesh_assert(ctx)