libMesh::ParameterMultiPointer< T > Class Template Reference

Stores multiple user-provided pointers. More...

#include <parameter_multipointer.h>

Inheritance diagram for libMesh::ParameterMultiPointer< T >:

Public Member Functions

 ParameterMultiPointer ()
 
 ParameterMultiPointer (T *param_ptr)
 
virtual ParameterAccessor< T > & operator= (T *) libmesh_override
 
virtual void set (const T &new_value) libmesh_override
 
virtual const T & get () const libmesh_override
 
virtual std::unique_ptr< ParameterAccessor< T > > clone () const libmesh_override
 
void push_back (T *new_ptr)
 
std::size_t size () const
 
ParameterProxy< T > operator* ()
 
ConstParameterProxy< T > operator* () const
 

Private Attributes

std::vector< T * > _ptrs
 

Detailed Description

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

Stores multiple user-provided pointers.

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

Definition at line 47 of file parameter_multipointer.h.

Constructor & Destructor Documentation

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

Constructor: no parameters attached yet

Definition at line 53 of file parameter_multipointer.h.

53 {}
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

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

Implements libMesh::ParameterAccessor< T >.

Definition at line 110 of file parameter_multipointer.h.

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

111  {
112  ParameterMultiPointer * pmp = new ParameterMultiPointer<T>();
113  pmp->_ptrs = _ptrs;
114 
115  return std::unique_ptr<ParameterAccessor<T>>(pmp);
116  }
template<typename T = Number>
virtual const T& libMesh::ParameterMultiPointer< T >::get ( ) const
inlinevirtual

Getter: get the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 94 of file parameter_multipointer.h.

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

95  {
96  libmesh_assert(!_ptrs.empty());
97  T & val = *_ptrs[0];
98 #ifndef NDEBUG
99  // If you're already using inconsistent parameters we can't help
100  // you.
101  for (std::size_t i=1; i < _ptrs.size(); ++i)
102  libmesh_assert_equal_to(*_ptrs[i], val);
103 #endif
104  return val;
105  }
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); }
template<typename T = Number>
ConstParameterProxy<T> libMesh::ParameterAccessor< T >::operator* ( ) const
inlineinherited

Definition at line 93 of file parameter_accessor.h.

References libMesh::ParameterAccessor< T >::clone().

93 { return ConstParameterProxy<T>(*this); }
template<typename T = Number>
virtual ParameterAccessor<T>& libMesh::ParameterMultiPointer< T >::operator= ( T *  )
inlinevirtual

A simple reseater won't work with a multipointer

Reimplemented from libMesh::ParameterAccessor< T >.

Definition at line 65 of file parameter_multipointer.h.

66  {
67  libmesh_error();
68  return *this;
69  }
template<typename T = Number>
void libMesh::ParameterMultiPointer< T >::push_back ( T *  new_ptr)
inline

Definition at line 118 of file parameter_multipointer.h.

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

118 { _ptrs.push_back(new_ptr); }
template<typename T = Number>
virtual void libMesh::ParameterMultiPointer< T >::set ( const T &  new_value)
inlinevirtual

Setter: change the value of the parameter we access.

Implements libMesh::ParameterAccessor< T >.

Definition at line 75 of file parameter_multipointer.h.

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

76  {
77  libmesh_assert(!_ptrs.empty());
78 #ifndef NDEBUG
79  // Compare other values to the last one we'll change
80  const T & val = *_ptrs.back();
81 #endif
82  for (std::size_t i=0; i != _ptrs.size(); ++i)
83  {
84  // If you're already using inconsistent parameters we can't
85  // help you.
86  libmesh_assert_equal_to(*_ptrs[i], val);
87  *_ptrs[i] = new_value;
88  }
89  }
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 124 of file parameter_multipointer.h.

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

124 { return _ptrs.size(); }

Member Data Documentation


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