libMesh
Loading...
Searching...
No Matches
parameter_accessor.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_ACCESSOR_H
21#define LIBMESH_PARAMETER_ACCESSOR_H
22
23
24// Local Includes
25#include "libmesh/libmesh_common.h"
26#include "libmesh/compare_types.h" // remove_const
27
28// C++ includes
29#include <memory>
30
31namespace libMesh
32{
33
34// Forward declarations
35template <typename T>
36class ParameterProxy;
37
38template <typename T>
39class ConstParameterProxy;
40
41
54template <typename T=Number>
56{
57public:
62 virtual ~ParameterAccessor() = default;
63
67 virtual void set (const T & new_value) = 0;
68
72 virtual const T & get () const = 0;
73
81
83
89 virtual std::unique_ptr<ParameterAccessor<T>> clone() const = 0;
90};
91
92template <typename T=Number>
94{
95public:
100 : _accessor(accessor) {}
101
105 ParameterProxy (const ParameterProxy<T> & accessor) = default;
106
110 ParameterProxy & operator = (const T & new_value) { _accessor.set(new_value); return *this; }
111
115 ParameterProxy & operator = (const ParameterProxy<T> & new_value) { _accessor.set(new_value._accessor.get()); return *this; }
116
120 ParameterProxy & operator = (const ConstParameterProxy<T> & new_value) { _accessor.set(new_value.get()); return *this; }
121
125 ParameterProxy & operator += (const T & value_increment) { _accessor.set(_accessor.get() + value_increment); return *this; }
126
130 ParameterProxy & operator -= (const T & value_decrement) { _accessor.set(_accessor.get() - value_decrement); return *this; }
131
135 ParameterProxy & operator *= (const T & value_multiplier) { _accessor.set(_accessor.get() * value_multiplier); return *this; }
136
140 ParameterProxy & operator /= (const T & value_divisor) { _accessor.set(_accessor.get() / value_divisor); return *this; }
141
145 operator T () const { return _accessor.get(); }
146
150 T get() const { return _accessor.get(); }
151
152#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
153 operator boost::multiprecision::backends::float128_backend () const { return _accessor.get().backend(); }
154#endif
155
156private:
158};
159
160
161template <typename T=Number>
163{
164public:
169 : _accessor(accessor) {}
170
174 operator T () const { return _accessor.get(); }
175
179 T get() const { return _accessor.get(); }
180
181#ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
182 operator boost::multiprecision::backends::float128_backend () const { return _accessor.get().backend(); }
183#endif
184
185private:
187};
188
189
190} // namespace libMesh
191
192#endif // LIBMESH_PARAMETER_ACCESSOR_H
const ParameterAccessor< T > & _accessor
ConstParameterProxy(const ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?
T get() const
Getter: get the value of the parameter we access.
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
virtual const T & get() const =0
Getter: get the value of the parameter we access.
virtual void set(const T &new_value)=0
Setter: change the value of the parameter we access.
ParameterProxy< T > operator*()
Proxy: for backward compatibility, we allow codes to treat a ParameterAccessor as if it were a simple...
virtual std::unique_ptr< ParameterAccessor< T > > clone() const =0
virtual ~ParameterAccessor()=default
Virtual destructor - we'll be deleting subclasses from pointers-to-ParameterAccessor.
ParameterProxy(const ParameterProxy< T > &accessor)=default
Default Copy Constructor works.
ParameterProxy & operator=(const T &new_value)
Setter: change the value of the parameter we access.
ParameterProxy & operator/=(const T &value_divisor)
Setter: change the value of the parameter we access.
ParameterProxy & operator-=(const T &value_decrement)
Setter: change the value of the parameter we access.
ParameterProxy & operator+=(const T &value_increment)
Setter: change the value of the parameter we access.
ParameterProxy & operator*=(const T &value_multiplier)
Setter: change the value of the parameter we access.
ParameterProxy(ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?
ParameterAccessor< T > & _accessor
T get() const
Getter: get the value of the parameter we access.
The libMesh namespace provides an interface to certain functionality in the library.