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 ParameterAccessor< T > & operator= (T *) libmesh_override
 A simple reseater won't work with a multipointer. More...
 
virtual void set (const T &new_value) libmesh_override
 Setter: change the value of the parameter we access. More...
 
virtual const T & get () const libmesh_override
 Getter: get the value of the parameter we access. More...
 
virtual UniquePtr< ParameterAccessor< T > > clone () const libmesh_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

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

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)

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 UniquePtr<ParameterAccessor<T> > libMesh::ParameterMultiPointer< T >::clone ( ) const
virtual
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 UniquePtr<ParameterAccessor<T>>(pmp);
116  }
ParameterMultiPointer()
Constructor: no parameters attached yet.
template<typename T = Number>
virtual const T& libMesh::ParameterMultiPointer< T >::get ( ) const
virtual

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, and libMesh::libmesh_assert().

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  }
libmesh_assert(j)
template<typename T = Number>
ParameterProxy<T> libMesh::ParameterAccessor< T >::operator* ( )
inherited

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

88 { return ParameterProxy<T>(*this); }
template<typename T = Number>
ConstParameterProxy<T> libMesh::ParameterAccessor< T >::operator* ( ) const
inherited

Definition at line 90 of file parameter_accessor.h.

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

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

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)

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)
virtual

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, and libMesh::libmesh_assert().

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  }
libmesh_assert(j)
template<typename T = Number>
std::size_t libMesh::ParameterMultiPointer< T >::size ( ) const
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

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

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