libMesh
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
libMesh::ParameterVector Class Reference

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

#include <parameter_vector.h>

Public Member Functions

 ParameterVector ()=default
 Default constructor: "no parameters".
 
 ParameterVector (const std::vector< Number * > &params)
 Constructor-from-vector-of-Number*: each points to a parameter.
 
 ~ParameterVector ()=default
 Destructor - deletes ParameterAccessor objects.
 
void deep_copy (ParameterVector &target) const
 Deep copy constructor: the target will now own new copies of all the parameter values I'm pointing to.
 
void shallow_copy (ParameterVector &target) const
 Shallow copy constructor: the target will now point to all the parameter values I'm pointing to.
 
void 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.
 
void clear ()
 Resets to "no parameters".
 
std::size_t size () const
 
void resize (std::size_t s)
 Sets the number of parameters to be used.
 
void push_back (std::unique_ptr< ParameterAccessor< Number > > new_accessor)
 Adds an additional parameter accessor to the end of the vector.
 
void deep_resize (std::size_t s)
 Sets the number of parameters to be used.
 
const ParameterAccessor< Number > & operator[] (std::size_t i) const
 
ParameterAccessor< Number > & operator[] (std::size_t i)
 
ParameterVectoroperator*= (const Number a)
 Multiplication operator; acts individually on each parameter.
 
ParameterVectoroperator+= (const ParameterVector &a)
 Addition operator.
 

Private Attributes

std::vector< std::unique_ptr< ParameterAccessor< Number > > > _params
 Pointers to parameters which may exist elsewhere.
 
std::vector< Number_my_data
 Parameters which I own; e.g.
 
bool _is_shallow_copy = false
 Am I a shallow copy? If so then resizing me would be a bug.
 

Detailed Description

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

Author
Roy Stogner
Date
2009

Specifies parameters for parameter sensitivity calculations.

Definition at line 44 of file parameter_vector.h.

Constructor & Destructor Documentation

◆ ParameterVector() [1/2]

libMesh::ParameterVector::ParameterVector ( )
default

Default constructor: "no parameters".

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

31 : _is_shallow_copy(false)
32#endif
33{
34 _params.reserve(params.size());
35
36 for (auto p : params)
37 _params.push_back(std::make_unique<ParameterPointer<Number>>(p));
38}
39
40
41
43{
44 const std::size_t Np = this->_params.size();
45 target.clear();
46 target._params.resize(Np);
47 target._my_data.resize(Np);
48#ifndef NDEBUG
49 target._is_shallow_copy = false;
50#endif
51 for (std::size_t i=0; i != Np; ++i)
52 {
53 target._params[i] =
54 std::make_unique<ParameterPointer<Number>>
55 (&target._my_data[i]);
56 target._my_data[i] = *(*this)[i];
57 }
58}
59
60
61
63{
64 target._my_data.clear();
65 target._params.resize(this->_params.size());
66 for (auto i : index_range(this->_params))
67 target._params[i] = this->_params[i]->clone();
68#ifndef NDEBUG
69 target._is_shallow_copy = true;
70#endif
71}
72
73
74
76{
77 const std::size_t Np = this->_params.size();
78 libmesh_assert_equal_to (target._params.size(), Np);
79
80 for (std::size_t i=0; i != Np; ++i)
81 *target[i] = *(*this)[i];
82}
83
84
85
86void ParameterVector::resize(std::size_t s)
87{
89
90 this->_params.resize(s);
91
92 // We used to make nullptr ParameterPointers here, but that was just
93 // to keep our destructor happy; users couldn't reseat them so
94 // shouldn't have code depending on them
95}
void deep_copy(ParameterVector &target) const
Deep copy constructor: the target will now own new copies of all the parameter values I'm pointing to...
ParameterVector()=default
Default constructor: "no parameters".
void value_copy(ParameterVector &target) const
Value copy method: the target, which should already have as many parameters as I do,...
void shallow_copy(ParameterVector &target) const
Shallow copy constructor: the target will now point to all the parameter values I'm pointing to.
std::vector< std::unique_ptr< ParameterAccessor< Number > > > _params
Pointers to parameters which may exist elsewhere.
void resize(std::size_t s)
Sets the number of parameters to be used.
bool _is_shallow_copy
Am I a shallow copy? If so then resizing me would be a bug.
void push_back(std::unique_ptr< ParameterAccessor< Number > > new_accessor)
Adds an additional parameter accessor to the end of the vector.
auto index_range(const T &sizable)
Helper function that returns an IntRange<std::size_t> representing all the indices of the passed-in v...
Definition int_range.h:153
libmesh_assert(ctx)

◆ ~ParameterVector()

libMesh::ParameterVector::~ParameterVector ( )
default

Destructor - deletes ParameterAccessor objects.

Member Function Documentation

◆ clear()

void libMesh::ParameterVector::clear ( )
inline

Resets to "no parameters".

Definition at line 165 of file parameter_vector.h.

166{
167 _params.clear();
168 _my_data.clear();
169}
std::vector< Number > _my_data
Parameters which I own; e.g.

References _my_data, and _params.

Referenced by LaplaceSystem::get_parameter_vector().

◆ 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.

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

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

100{
102
103 this->_params.resize(s);
104 this->_my_data.resize(s);
105 for (std::size_t i=0; i != s; ++i)
106 this->_params[i] =
107 std::make_unique<ParameterPointer<Number>>(&this->_my_data[i]);
108}

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

◆ operator*=()

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

Multiplication operator; acts individually on each parameter.

Definition at line 112 of file parameter_vector.C.

113{
114 const std::size_t Np = this->_params.size();
115 for (std::size_t i=0; i != Np; ++i)
116 *(*this)[i] *= a;
117 return *this;
118}

References _params, and size().

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

123{
124 const std::size_t Np = this->_params.size();
125 libmesh_assert_equal_to (a._params.size(), Np);
126 for (std::size_t i=0; i != Np; ++i)
127 *(*this)[i] += *a[i];
128 return *this;
129}

References _params, and size().

◆ operator[]() [1/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 195 of file parameter_vector.h.

196{
197 libmesh_assert_greater (_params.size(), i);
198
199 return *_params[i];
200}

References _params.

◆ operator[]() [2/2]

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

Definition at line 185 of file parameter_vector.h.

186{
187 libmesh_assert_greater (_params.size(), i);
188
189 return *_params[i];
190}

References _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 174 of file parameter_vector.h.

175{
176 // Can't append stuff we are responsible for if we're already a shallow copy.
178 libmesh_assert(new_accessor.get());
179 _params.push_back(std::move(new_accessor));
180}

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

Referenced by LaplaceSystem::get_parameter_vector(), CoupledSystem::get_parameter_vector(), and HeatSystem::get_parameter_vector().

◆ 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.

◆ 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.

◆ size()

std::size_t libMesh::ParameterVector::size ( ) const
inline

◆ 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.

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

Member Data Documentation

◆ _is_shallow_copy

bool libMesh::ParameterVector::_is_shallow_copy = false
private

Am I a shallow copy? If so then resizing me would be a bug.

Definition at line 153 of file parameter_vector.h.

Referenced by deep_resize(), and push_back().

◆ _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 147 of file parameter_vector.h.

Referenced by clear(), and deep_resize().

◆ _params

std::vector<std::unique_ptr<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_resize(), operator*=(), operator+=(), operator[](), operator[](), push_back(), and size().


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