libMesh::ParameterMultiAccessor< T > Class Template Reference

Stores a user-provided pointer to a parameter. More...

#include <parameter_multiaccessor.h>

Inheritance diagram for libMesh::ParameterMultiAccessor< T >:

Public Member Functions

 ParameterMultiAccessor ()
 
 ParameterMultiAccessor (const ParameterAccessor< T > &param_accessor)
 
 ~ParameterMultiAccessor ()
 
virtual ParameterAccessor< T > & operator= (T *) override
 
virtual void set (const T &new_value) override
 
virtual const T & get () const override
 
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* ()
 
ConstParameterProxy< T > operator* () const
 

Private Attributes

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

Detailed Description

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

Stores a user-provided pointer to a parameter.

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

Definition at line 47 of file parameter_multiaccessor.h.

Constructor & Destructor Documentation

◆ ParameterMultiAccessor() [1/2]

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

Constructor: no parameters attached yet

Definition at line 53 of file parameter_multiaccessor.h.

53 {}

◆ 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< ParameterAccessor< T > * > _accessors

◆ ~ParameterMultiAccessor()

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

Definition at line 64 of file parameter_multiaccessor.h.

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

64  {
65  for (auto & accessor : _accessors)
66  delete accessor;
67  }
std::vector< ParameterAccessor< T > * > _accessors

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 119 of file parameter_multiaccessor.h.

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

120  {
121  ParameterMultiAccessor * pmp = new ParameterMultiAccessor<T>();
122  for (auto & accessor : _accessors)
123  pmp->_accessors.push_back(accessor->clone().release());
124 
125  return std::unique_ptr<ParameterAccessor<T>>(pmp);
126  }
std::vector< ParameterAccessor< 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 103 of file parameter_multiaccessor.h.

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

104  {
105  libmesh_assert(!_accessors.empty());
106  const T & val = _accessors[0]->get();
107 #ifndef NDEBUG
108  // If you're already using inconsistent parameters we can't help
109  // you.
110  for (std::size_t i=1; i < _accessors.size(); ++i)
111  libmesh_assert_equal_to(_accessors[i]->get(), val);
112 #endif
113  return val;
114  }
std::vector< ParameterAccessor< T > * > _accessors

◆ 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 91 of file parameter_accessor.h.

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

◆ operator*() [2/2]

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

Definition at line 93 of file parameter_accessor.h.

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

◆ operator=()

template<typename T = Number>
virtual ParameterAccessor<T>& libMesh::ParameterMultiAccessor< T >::operator= ( T *  )
inlineoverridevirtual

A simple reseater won't work with a multi-accessor

Reimplemented from libMesh::ParameterAccessor< T >.

Definition at line 74 of file parameter_multiaccessor.h.

75  {
76  libmesh_error();
77  return *this;
78  }

◆ push_back()

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

Definition at line 129 of file parameter_multiaccessor.h.

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

129  {
130  _accessors.push_back(new_accessor.clone().release());
131  }
std::vector< ParameterAccessor< T > * > _accessors

◆ 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 84 of file parameter_multiaccessor.h.

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

85  {
86  libmesh_assert(!_accessors.empty());
87 #ifndef NDEBUG
88  // Compare other values to the last one we'll change
89  const T & val = _accessors.back()->get();
90 #endif
91  for (auto & accessor : _accessors)
92  {
93  // If you're already using inconsistent parameters we can't
94  // help you.
95  libmesh_assert_equal_to(accessor->get(), val);
96  accessor->set(new_value);
97  }
98  }
std::vector< ParameterAccessor< T > * > _accessors

◆ 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 138 of file parameter_multiaccessor.h.

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

138 { return _accessors.size(); }
std::vector< ParameterAccessor< T > * > _accessors

Member Data Documentation

◆ _accessors


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