libMesh
Public Member Functions | Private Attributes | List of all members
libMesh::ParameterMultiPointer< T > Class Template Reference

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

#include <parameter_multipointer.h>

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

Public Member Functions

 ParameterMultiPointer ()
 Constructor: no parameters attached yet. More...
 
 ParameterMultiPointer (T *param_ptr)
 Constructor: take the first raw pointer to the parameter. More...
 
virtual void set (const T &new_value) override
 Setter: change the value of the parameter we access. More...
 
virtual const T & get () const override
 Getter: get the value of the parameter we access. More...
 
virtual std::unique_ptr< ParameterAccessor< T > > clone () const override
 
void push_back (T *new_ptr)
 
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. More...
 
ConstParameterProxy< T > operator* () const
 

Private Attributes

std::vector< T * > _ptrs
 

Detailed Description

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

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

This is a slightly flexible ParameterAccessor subclass: it stores all user-provided pointers to copies of the parameter, and modifies the value at each location in memory.

Author
Roy Stogner
Date
2015 Stores multiple user-provided pointers.

Definition at line 47 of file parameter_multipointer.h.

Constructor & Destructor Documentation

◆ ParameterMultiPointer() [1/2]

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

Constructor: no parameters attached yet.

Definition at line 53 of file parameter_multipointer.h.

53 {}

◆ ParameterMultiPointer() [2/2]

template<typename T = Number>
libMesh::ParameterMultiPointer< T >::ParameterMultiPointer ( T *  param_ptr)
inline

Constructor: take the first raw pointer to the parameter.

Definition at line 58 of file parameter_multipointer.h.

58 : _ptrs(1, param_ptr) {}

Member Function Documentation

◆ clone()

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

Implements libMesh::ParameterAccessor< T >.

Definition at line 98 of file parameter_multipointer.h.

References libMesh::ParameterMultiPointer< T >::_ptrs.

99  {
100  auto pmp = std::make_unique<ParameterMultiPointer<T>>();
101  pmp->_ptrs = _ptrs;
102  return pmp;
103  }

◆ get()

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

Getter: get the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 82 of file parameter_multipointer.h.

References libMesh::ParameterMultiPointer< T >::_ptrs, and libMesh::libmesh_assert().

83  {
84  libmesh_assert(!_ptrs.empty());
85  T & val = *_ptrs[0];
86 #ifndef NDEBUG
87  // If you're already using inconsistent parameters we can't help
88  // you.
89  for (auto ptr : _ptrs)
90  libmesh_assert_equal_to(*ptr, val);
91 #endif
92  return val;
93  }
libmesh_assert(ctx)

◆ 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::ParameterMultiPointer< T >::push_back ( T *  new_ptr)
inline

Definition at line 105 of file parameter_multipointer.h.

References libMesh::ParameterMultiPointer< T >::_ptrs.

105 { _ptrs.push_back(new_ptr); }

◆ set()

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

Setter: change the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 63 of file parameter_multipointer.h.

References libMesh::ParameterMultiPointer< T >::_ptrs, and libMesh::libmesh_assert().

64  {
65  libmesh_assert(!_ptrs.empty());
66 #ifndef NDEBUG
67  // Compare other values to the last one we'll change
68  const T & val = *_ptrs.back();
69 #endif
70  for (auto & ptr : _ptrs)
71  {
72  // If you're already using inconsistent parameters we can't
73  // help you.
74  libmesh_assert_equal_to(*ptr, val);
75  *ptr = new_value;
76  }
77  }
libmesh_assert(ctx)

◆ size()

template<typename T = Number>
std::size_t libMesh::ParameterMultiPointer< T >::size ( ) const
inline
Returns
The number of data associated with this parameter. Useful for testing if the multipointer is empty/invalid.

Definition at line 111 of file parameter_multipointer.h.

References libMesh::ParameterMultiPointer< T >::_ptrs.

111 { return _ptrs.size(); }

Member Data Documentation

◆ _ptrs

template<typename T = Number>
std::vector<T *> libMesh::ParameterMultiPointer< T >::_ptrs
private

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