libMesh
parameter_accessor.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2024 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 
31 namespace libMesh
32 {
33 
34 // Forward declarations
35 template <typename T>
37 
38 template <typename T>
40 
41 
54 template <typename T=Number>
56 {
57 public:
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 
92 template <typename T=Number>
93 class ParameterProxy
94 {
95 public:
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.get()); }
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 
147 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
148  operator boost::multiprecision::backends::float128_backend () const { return _accessor.get().backend(); }
149 #endif
150 
151 private:
153 };
154 
155 
156 template <typename T=Number>
158 {
159 public:
164  : _accessor(accessor) {}
165 
169  operator T () const { return _accessor.get(); }
170 
174  T get() const { return _accessor.get(); }
175 
176 #ifdef LIBMESH_DEFAULT_QUADRUPLE_PRECISION
177  operator boost::multiprecision::backends::float128_backend () const { return _accessor.get().backend(); }
178 #endif
179 
180 private:
182 };
183 
184 
185 } // namespace libMesh
186 
187 #endif // LIBMESH_PARAMETER_ACCESSOR_H
T get() const
Getter: get the value of the parameter we access.
ParameterProxy & operator*=(const T &value_multiplier)
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...
ParameterProxy & operator+=(const T &value_increment)
Setter: change the value of the parameter we access.
virtual ~ParameterAccessor()=default
Virtual destructor - we&#39;ll be deleting subclasses from pointers-to-ParameterAccessor.
The libMesh namespace provides an interface to certain functionality in the library.
ConstParameterProxy(const ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?
const ParameterAccessor< T > & _accessor
ParameterProxy & operator-=(const T &value_decrement)
Setter: change the value of the parameter we access.
ParameterAccessor< T > & _accessor
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.
virtual std::unique_ptr< ParameterAccessor< T > > clone() const =0
Accessor object allowing reading and modification of the independent variables in a parameter sensiti...
ParameterProxy(ParameterAccessor< T > &accessor)
Constructor: which parameter are we a proxy for?