libMesh::ParameterVector Class Reference

Specifies parameters for parameter sensitivity calculations. More...

#include <parameter_vector.h>

Public Member Functions

 ParameterVector ()
 
 ParameterVector (const std::vector< Number * > &params)
 
 ~ParameterVector ()
 
void deep_copy (ParameterVector &target) const
 
void shallow_copy (ParameterVector &target) const
 
void value_copy (ParameterVector &target) const
 
void clear ()
 
std::size_t size () const
 
void resize (unsigned int s)
 
void push_back (UniquePtr< ParameterAccessor< Number > > new_accessor)
 
void deep_resize (unsigned int s)
 
const ParameterAccessor< Number > & operator[] (unsigned int i) const
 
ParameterAccessor< Number > & operator[] (unsigned int i)
 
ParameterVectoroperator*= (const Number a)
 
ParameterVectoroperator+= (const ParameterVector &a)
 

Private Attributes

std::vector< ParameterAccessor< Number > * > _params
 
std::vector< Number_my_data
 
bool _is_shallow_copy
 

Detailed Description

Specifies parameters for parameter sensitivity calculations.

Data structure for specifying which Parameters should be independent variables in a parameter sensitivity calculation.

Author
Roy Stogner
Date
2009

Definition at line 44 of file parameter_vector.h.

Constructor & Destructor Documentation

libMesh::ParameterVector::ParameterVector ( )
inline

Default constructor: "no parameters"

Definition at line 50 of file parameter_vector.h.

References clear(), deep_copy(), shallow_copy(), value_copy(), and ~ParameterVector().

libMesh::ParameterVector::ParameterVector ( const std::vector< Number * > &  params)
explicit

Constructor-from-vector-of-Number*: each points to a parameter

Definition at line 27 of file parameter_vector.C.

References _params.

28  : _is_shallow_copy(false)
29 {
30  _params.reserve(params.size());
31 
32  for (std::size_t i=0; i != params.size(); ++i)
33  _params.push_back(new ParameterPointer<Number>(params[i]));
34 }
std::vector< ParameterAccessor< Number > * > _params
libMesh::ParameterVector::~ParameterVector ( )
inline

Destructor - deletes ParameterAccessor objects

Definition at line 162 of file parameter_vector.h.

References clear().

Referenced by ParameterVector().

163 {
164  this->clear();
165 }

Member Function Documentation

void libMesh::ParameterVector::clear ( )
inline

Resets to "no parameters"

Definition at line 170 of file parameter_vector.h.

References _is_shallow_copy, _my_data, and _params.

Referenced by deep_copy(), ParameterVector(), and ~ParameterVector().

171 {
172  if (!_is_shallow_copy)
173  for (std::size_t i=0; i != _params.size(); ++i)
174  delete _params[i];
175 
176  _params.clear();
177  _my_data.clear();
178 }
std::vector< ParameterAccessor< Number > * > _params
std::vector< Number > _my_data
void libMesh::ParameterVector::deep_copy ( ParameterVector target) const

Deep copy constructor: the target will now own new copies of all the parameter values I'm pointing to

Definition at line 38 of file parameter_vector.C.

References _my_data, _params, and clear().

Referenced by ParameterVector(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

39 {
40  const unsigned int Np = cast_int<unsigned int>
41  (this->_params.size());
42  target.clear();
43  target._params.resize(Np);
44  target._my_data.resize(Np);
45  for (unsigned int i=0; i != Np; ++i)
46  {
47  target._params[i] =
48  new ParameterPointer<Number>(&target._my_data[i]);
49  target._my_data[i] = *(*this)[i];
50  }
51 }
std::vector< ParameterAccessor< Number > * > _params
void libMesh::ParameterVector::deep_resize ( unsigned int  s)

Sets the number of parameters to be used. This method is for resizing a ParameterVector that owns its own parameter values

Definition at line 97 of file parameter_vector.C.

References _is_shallow_copy, _my_data, _params, and libMesh::libmesh_assert().

Referenced by size().

98 {
100 
101  this->_params.resize(s);
102  this->_my_data.resize(s);
103  for (unsigned int i=0; i != s; ++i)
104  this->_params[i] =
105  new ParameterPointer<Number>(&this->_my_data[i]);
106 }
std::vector< ParameterAccessor< Number > * > _params
libmesh_assert(j)
std::vector< Number > _my_data
ParameterVector & libMesh::ParameterVector::operator*= ( const Number  a)

Multiplication operator; acts individually on each parameter.

Definition at line 110 of file parameter_vector.C.

References _params.

Referenced by size().

111 {
112  const unsigned int Np = cast_int<unsigned int>
113  (this->_params.size());
114  for (unsigned int i=0; i != Np; ++i)
115  *(*this)[i] *= a;
116  return *this;
117 }
std::vector< ParameterAccessor< Number > * > _params
ParameterVector & libMesh::ParameterVector::operator+= ( const ParameterVector a)

Addition operator. The parameter vector to be added in must have the same number of values.

Definition at line 121 of file parameter_vector.C.

References _params.

Referenced by size().

122 {
123  const unsigned int Np = cast_int<unsigned int>
124  (this->_params.size());
125  libmesh_assert_equal_to (a._params.size(), Np);
126  for (unsigned int i=0; i != Np; ++i)
127  *(*this)[i] += *a[i];
128  return *this;
129 }
std::vector< ParameterAccessor< Number > * > _params
const ParameterAccessor< Number > & libMesh::ParameterVector::operator[] ( unsigned int  i) const
inline

Returns a smart-pointer to a parameter value

Definition at line 194 of file parameter_vector.h.

References _params.

Referenced by size().

195 {
196  libmesh_assert_greater (_params.size(), i);
197 
198  return *_params[i];
199 }
std::vector< ParameterAccessor< Number > * > _params
ParameterAccessor< Number > & libMesh::ParameterVector::operator[] ( unsigned int  i)
inline

Returns a reference to a smart-pointer to a parameter value, suitable for repointing it to a different address. This method is deprecated and may not work with more sophisticated ParameterAccessor subclasses.

Definition at line 204 of file parameter_vector.h.

References _params.

205 {
206  libmesh_assert_greater (_params.size(), i);
207 
208  return *_params[i];
209 }
std::vector< ParameterAccessor< Number > * > _params
void libMesh::ParameterVector::push_back ( UniquePtr< ParameterAccessor< Number > >  new_accessor)
inline

Adds an additional parameter accessor to the end of the vector.

We will free this accessor when we are finished with it; we request that it be passed to us as a UniquePtr to reflect that fact in the API.

Definition at line 183 of file parameter_vector.h.

References _is_shallow_copy, _params, and libMesh::libmesh_assert().

Referenced by size().

184 {
185  // Can't append stuff we are responsible for if we're already a shallow copy.
187  libmesh_assert(new_accessor.get());
188  _params.push_back(new_accessor.release());
189 }
std::vector< ParameterAccessor< Number > * > _params
libmesh_assert(j)
void libMesh::ParameterVector::resize ( unsigned int  s)

Sets the number of parameters to be used. If the new size is larger than the old, empty ParameterPointer accessors fill the new entries.

Definition at line 76 of file parameter_vector.C.

References _is_shallow_copy, _params, libMesh::libmesh_assert(), and libmesh_nullptr.

Referenced by size().

77 {
79 
80  const std::size_t old_size = this->_params.size();
81 
82  // If we're shrinking the vector, we don't want to leak memory.
83  // Note that we're using < in these for loops, not !=
84  // We don't know a priori if we're shrinking or growing
85  for (unsigned int i=s; i < old_size; ++i)
86  delete _params[i];
87 
88  this->_params.resize(s);
89 
90  for (unsigned int i=old_size; i < s; ++i)
91  this->_params[i] =
92  new ParameterPointer<Number>(libmesh_nullptr);
93 }
std::vector< ParameterAccessor< Number > * > _params
const class libmesh_nullptr_t libmesh_nullptr
libmesh_assert(j)
void libMesh::ParameterVector::shallow_copy ( ParameterVector target) const

Shallow copy constructor: the target will now point to all the parameter values I'm pointing to

Definition at line 55 of file parameter_vector.C.

References _is_shallow_copy, _my_data, and _params.

Referenced by ParameterVector().

56 {
57  target._my_data.clear();
58  target._params = this->_params;
59  target._is_shallow_copy = true;
60 }
std::vector< ParameterAccessor< Number > * > _params
void libMesh::ParameterVector::value_copy ( ParameterVector target) const

Value copy method: the target, which should already have as many parameters as I do, will now have those parameters set to my values.

Definition at line 64 of file parameter_vector.C.

References _params.

Referenced by ParameterVector(), libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

65 {
66  const unsigned int Np = cast_int<unsigned int>
67  (this->_params.size());
68  libmesh_assert_equal_to (target._params.size(), Np);
69 
70  for (unsigned int i=0; i != Np; ++i)
71  *target[i] = *(*this)[i];
72 }
std::vector< ParameterAccessor< Number > * > _params

Member Data Documentation

bool libMesh::ParameterVector::_is_shallow_copy
private

Am I a shallow copy? If so then I shouldn't be deleting my ParameterAccessors.

Definition at line 153 of file parameter_vector.h.

Referenced by clear(), deep_resize(), push_back(), resize(), and shallow_copy().

std::vector<Number> libMesh::ParameterVector::_my_data
private

Parameters which I own; e.g. as the result of a deep copy

Definition at line 147 of file parameter_vector.h.

Referenced by clear(), deep_copy(), deep_resize(), and shallow_copy().

std::vector<ParameterAccessor<Number> *> libMesh::ParameterVector::_params
private

Pointers to parameters which may exist elsewhere

Definition at line 142 of file parameter_vector.h.

Referenced by clear(), deep_copy(), deep_resize(), operator*=(), operator+=(), operator[](), ParameterVector(), push_back(), resize(), shallow_copy(), size(), and value_copy().


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