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 (std::size_t s)
 
void push_back (std::unique_ptr< ParameterAccessor< Number >> new_accessor)
 
void deep_resize (std::size_t s)
 
const ParameterAccessor< Number > & operator[] (std::size_t i) const
 
ParameterAccessor< Number > & operator[] (std::size_t 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 45 of file parameter_vector.h.

Constructor & Destructor Documentation

◆ ParameterVector() [1/2]

libMesh::ParameterVector::ParameterVector ( )
inline

Default constructor: "no parameters"

Definition at line 51 of file parameter_vector.h.

◆ ParameterVector() [2/2]

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

◆ ~ParameterVector()

libMesh::ParameterVector::~ParameterVector ( )
inline

Destructor - deletes ParameterAccessor objects

Definition at line 163 of file parameter_vector.h.

References clear().

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

Member Function Documentation

◆ clear()

void libMesh::ParameterVector::clear ( )
inline

Resets to "no parameters"

Definition at line 171 of file parameter_vector.h.

References _is_shallow_copy, _my_data, and _params.

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

172 {
173  if (!_is_shallow_copy)
174  for (auto & param : _params)
175  delete param;
176 
177  _params.clear();
178  _my_data.clear();
179 }
std::vector< ParameterAccessor< Number > * > _params
std::vector< Number > _my_data

◆ deep_copy()

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 libMesh::ImplicitSystem::qoi_parameter_hessian_vector_product(), libMesh::ImplicitSystem::weighted_sensitivity_adjoint_solve(), and libMesh::ImplicitSystem::weighted_sensitivity_solve().

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

◆ deep_resize()

void libMesh::ParameterVector::deep_resize ( std::size_t  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 95 of file parameter_vector.C.

References _is_shallow_copy, _my_data, and _params.

96 {
97  libmesh_assert(!_is_shallow_copy);
98 
99  this->_params.resize(s);
100  this->_my_data.resize(s);
101  for (std::size_t i=0; i != s; ++i)
102  this->_params[i] =
103  new ParameterPointer<Number>(&this->_my_data[i]);
104 }
std::vector< ParameterAccessor< Number > * > _params
std::vector< Number > _my_data

◆ operator*=()

ParameterVector & libMesh::ParameterVector::operator*= ( const Number  a)

Multiplication operator; acts individually on each parameter.

Definition at line 108 of file parameter_vector.C.

References _params.

109 {
110  const std::size_t Np = this->_params.size();
111  for (std::size_t i=0; i != Np; ++i)
112  *(*this)[i] *= a;
113  return *this;
114 }
std::vector< ParameterAccessor< Number > * > _params

◆ operator+=()

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 118 of file parameter_vector.C.

References _params.

119 {
120  const std::size_t Np = this->_params.size();
121  libmesh_assert_equal_to (a._params.size(), Np);
122  for (std::size_t i=0; i != Np; ++i)
123  *(*this)[i] += *a[i];
124  return *this;
125 }
std::vector< ParameterAccessor< Number > * > _params

◆ operator[]() [1/2]

const ParameterAccessor< Number > & libMesh::ParameterVector::operator[] ( std::size_t  i) const
inline
Returns
A smart-pointer to a parameter value

Definition at line 195 of file parameter_vector.h.

References _params.

196 {
197  libmesh_assert_greater (_params.size(), i);
198 
199  return *_params[i];
200 }
std::vector< ParameterAccessor< Number > * > _params

◆ operator[]() [2/2]

ParameterAccessor< Number > & libMesh::ParameterVector::operator[] ( std::size_t  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 205 of file parameter_vector.h.

References _params.

206 {
207  libmesh_assert_greater (_params.size(), i);
208 
209  return *_params[i];
210 }
std::vector< ParameterAccessor< Number > * > _params

◆ push_back()

void libMesh::ParameterVector::push_back ( std::unique_ptr< 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 std::unique_ptr to reflect that fact in the API.

Definition at line 184 of file parameter_vector.h.

References _is_shallow_copy, and _params.

185 {
186  // Can't append stuff we are responsible for if we're already a shallow copy.
187  libmesh_assert(!_is_shallow_copy);
188  libmesh_assert(new_accessor.get());
189  _params.push_back(new_accessor.release());
190 }
std::vector< ParameterAccessor< Number > * > _params

◆ resize()

void libMesh::ParameterVector::resize ( std::size_t  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 74 of file parameter_vector.C.

References _is_shallow_copy, and _params.

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

◆ shallow_copy()

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 54 of file parameter_vector.C.

References _is_shallow_copy, _my_data, and _params.

55 {
56  target._my_data.clear();
57  target._params = this->_params;
58  target._is_shallow_copy = true;
59 }
std::vector< ParameterAccessor< Number > * > _params

◆ size()

◆ value_copy()

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 63 of file parameter_vector.C.

References _params.

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

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

Member Data Documentation

◆ _is_shallow_copy

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 154 of file parameter_vector.h.

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

◆ _my_data

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

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

Definition at line 148 of file parameter_vector.h.

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

◆ _params

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

Pointers to parameters which may exist elsewhere

Definition at line 143 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: