libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
libMesh::ParameterMultiAccessor< T > Class Template Reference

Accessor object allowing reading and modification of the independent variables in a parameter sensitivity calculation. More...

#include <parameter_multiaccessor.h>

Inheritance diagram for libMesh::ParameterMultiAccessor< T >:
[legend]

Public Member Functions

 ParameterMultiAccessor ()=default
 Constructor: no parameters attached yet.
 
 ParameterMultiAccessor (const ParameterAccessor< T > &param_accessor)
 Constructor: take the first sub-accessor for the parameter.
 
 ~ParameterMultiAccessor ()=default
 
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.
 
virtual std::unique_ptr< ParameterAccessor< T > > clone () const override
 
void push_back (const ParameterAccessor< T > &new_accessor)
 
std::size_t size () const
 
ParameterProxy< T > operator* ()
 Proxy: for backward compatibility, we allow codes to treat a ParameterAccessor as if it were a simple pointer-to-value.
 
ConstParameterProxy< T > operator* () const
 

Private Attributes

std::vector< std::unique_ptr< ParameterAccessor< T > > > _accessors
 

Detailed Description

template<typename T = Number>
class libMesh::ParameterMultiAccessor< T >

Accessor object allowing reading and modification of the independent variables in a parameter sensitivity calculation.

This is the "default" ParameterAccessor subclass: it simply stores a user-provided pointer to the parameter, and modifies the value at that location in memory.

Author
Roy Stogner
Date
2015

Stores a user-provided pointer to a parameter.

Definition at line 47 of file parameter_multiaccessor.h.

Constructor & Destructor Documentation

◆ ParameterMultiAccessor() [1/2]

template<typename T = Number>
libMesh::ParameterMultiAccessor< T >::ParameterMultiAccessor ( )
default

Constructor: no parameters attached yet.

◆ ParameterMultiAccessor() [2/2]

template<typename T = Number>
libMesh::ParameterMultiAccessor< T >::ParameterMultiAccessor ( const ParameterAccessor< T > &  param_accessor)
inline

Constructor: take the first sub-accessor for the parameter.

Definition at line 58 of file parameter_multiaccessor.h.

58 :
59 _accessors(1, param_accessor.clone()) {}
std::vector< std::unique_ptr< ParameterAccessor< T > > > _accessors

◆ ~ParameterMultiAccessor()

template<typename T = Number>
libMesh::ParameterMultiAccessor< T >::~ParameterMultiAccessor ( )
default

Member Function Documentation

◆ clone()

template<typename T = Number>
virtual std::unique_ptr< ParameterAccessor< T > > libMesh::ParameterMultiAccessor< T >::clone ( ) const
inlineoverridevirtual
Returns
A new copy of the accessor.

Implements libMesh::ParameterAccessor< T >.

Definition at line 104 of file parameter_multiaccessor.h.

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 }
void push_back(const ParameterAccessor< T > &new_accessor)
virtual std::unique_ptr< ParameterAccessor< T > > clone() const override

References libMesh::ParameterMultiAccessor< T >::_accessors.

◆ get()

template<typename T = Number>
virtual const T & libMesh::ParameterMultiAccessor< T >::get ( ) const
inlineoverridevirtual

Getter: get the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 88 of file parameter_multiaccessor.h.

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 }
virtual const T & get() const override
Getter: get the value of the parameter we access.
libmesh_assert(ctx)

References libMesh::ParameterMultiAccessor< T >::_accessors, and libMesh::libmesh_assert().

◆ operator*() [1/2]

template<typename T = Number>
ParameterProxy< T > libMesh::ParameterAccessor< T >::operator* ( )
inlineinherited

Proxy: for backward compatibility, we allow codes to treat a ParameterAccessor as if it were a simple pointer-to-value.

We can't safely allow "Number * n = parameter_vector[p]" to compile, but we can allow "*parameter_vector[p] += deltap" to work.

Definition at line 80 of file parameter_accessor.h.

80{ return ParameterProxy<T>(*this); }

◆ operator*() [2/2]

template<typename T = Number>
ConstParameterProxy< T > libMesh::ParameterAccessor< T >::operator* ( ) const
inlineinherited

Definition at line 82 of file parameter_accessor.h.

82{ return ConstParameterProxy<T>(*this); }

◆ push_back()

template<typename T = Number>
void libMesh::ParameterMultiAccessor< T >::push_back ( const ParameterAccessor< T > &  new_accessor)
inline

Definition at line 114 of file parameter_multiaccessor.h.

115 {
116 _accessors.push_back(new_accessor.clone());
117 }

References libMesh::ParameterMultiAccessor< T >::_accessors, and libMesh::ParameterAccessor< T >::clone().

◆ set()

template<typename T = Number>
virtual void libMesh::ParameterMultiAccessor< T >::set ( const T &  new_value)
inlineoverridevirtual

Setter: change the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 69 of file parameter_multiaccessor.h.

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 }

References libMesh::ParameterMultiAccessor< T >::_accessors, and libMesh::libmesh_assert().

◆ size()

template<typename T = Number>
std::size_t libMesh::ParameterMultiAccessor< T >::size ( ) const
inline
Returns
The number of sub-accessors associated with this parameter. Useful for testing if the multi-accessor is empty/invalid.

Definition at line 124 of file parameter_multiaccessor.h.

124{ return _accessors.size(); }

References libMesh::ParameterMultiAccessor< T >::_accessors.

Member Data Documentation

◆ _accessors

template<typename T = Number>
std::vector<std::unique_ptr<ParameterAccessor<T> > > libMesh::ParameterMultiAccessor< T >::_accessors
private

The documentation for this class was generated from the following file: