libMesh
Classes | Public Member Functions | Private Attributes | List of all members
libMesh::QoISet Class Reference

Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a parameter sensitivity calculation. More...

#include <qoi_set.h>

Classes

class  iterator
 

Public Member Functions

 QoISet ()
 Empty constructor: "calculate all QoIs in the System". More...
 
 QoISet (const System &sys)
 Default constructor: "calculate all QoIs in the System", "give every QoI weight 1.0". More...
 
 QoISet (std::vector< bool > indices)
 Constructor-from-vector-of-bool: "calculate the QoIs for which \p indices[q] is true". More...
 
 QoISet (const std::vector< unsigned int > &indices)
 Constructor-from-vector: "calculate the listed QoIs", "give every QoI weight 1.0". More...
 
void clear ()
 Resets to "calculate all QoIs, give every QoI weight 1.0". More...
 
std::size_t size (const System &sys) const
 
void add_indices (const std::vector< unsigned int > &indices)
 Add this indices to the set to be calculated. More...
 
void add_index (std::size_t)
 Add this index to the set to be calculated. More...
 
void remove_indices (const std::vector< unsigned int > &indices)
 Remove these indices from the set to be calculated. More...
 
void remove_index (std::size_t)
 Remove this index from the set to be calculated. More...
 
void set_weight (std::size_t, Real)
 Set the weight for this index. More...
 
Real weight (std::size_t) const
 Get the weight for this index (default 1.0) More...
 
bool has_index (std::size_t) const
 Return whether or not this index is in the set to be calculated. More...
 
iterator begin () const
 Return an iterator pointing to the first index in the set. More...
 

Private Attributes

std::vector< bool > _indices
 Interpret _indices.empty() to mean "calculate all indices". More...
 
std::vector< Real_weights
 Interpret _weights.size() <= i to mean "weight i = 1.0". More...
 

Detailed Description

Data structure for specifying which Quantities of Interest should be calculated in an adjoint or a parameter sensitivity calculation.

Author
Roy Stogner
Date
2009 Used to specify quantities of interest in a simulation.

Definition at line 45 of file qoi_set.h.

Constructor & Destructor Documentation

◆ QoISet() [1/4]

libMesh::QoISet::QoISet ( )
inline

Empty constructor: "calculate all QoIs in the System".

No further changes to this special QoISet should be made; it doesn't even know how many QoIs your system has, it just knows to instruct a function to use all of them.

Definition at line 100 of file qoi_set.h.

100 : _indices(), _weights() {}
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184

◆ QoISet() [2/4]

libMesh::QoISet::QoISet ( const System sys)
explicit

Default constructor: "calculate all QoIs in the System", "give every QoI weight 1.0".

Definition at line 31 of file qoi_set.C.

31 : _indices(sys.n_qois(), true) {}
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ QoISet() [3/4]

libMesh::QoISet::QoISet ( std::vector< bool >  indices)
inlineexplicit

Constructor-from-vector-of-bool: "calculate the QoIs for which \p indices[q] is true".

Definition at line 114 of file qoi_set.h.

114  :
115  _indices(std::move(indices)), _weights() {}
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184

◆ QoISet() [4/4]

libMesh::QoISet::QoISet ( const std::vector< unsigned int > &  indices)
inlineexplicit

Constructor-from-vector: "calculate the listed QoIs", "give every QoI weight 1.0".

Definition at line 195 of file qoi_set.h.

References add_indices().

195  :
196  _indices(), _weights()
197 {
198  this->add_indices(indices);
199 }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184
void add_indices(const std::vector< unsigned int > &indices)
Add this indices to the set to be calculated.
Definition: qoi_set.C:46

Member Function Documentation

◆ add_index()

void libMesh::QoISet::add_index ( std::size_t  i)
inline

Add this index to the set to be calculated.

Definition at line 204 of file qoi_set.h.

References _indices.

205 {
206  if (i >= _indices.size())
207  _indices.resize(i+1, true);
208  _indices[i] = true;
209 }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ add_indices()

void libMesh::QoISet::add_indices ( const std::vector< unsigned int > &  indices)

Add this indices to the set to be calculated.

Definition at line 46 of file qoi_set.C.

References _indices.

Referenced by main(), and QoISet().

47 {
48  unsigned int max_size = 0;
49  for (const auto & i : indices)
50  max_size = std::max(max_size, i + 1);
51 
52  _indices.resize(max_size);
53 
54  for (const auto & i : indices)
55  _indices[i] = true;
56 }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ begin()

iterator libMesh::QoISet::begin ( ) const
inline

Return an iterator pointing to the first index in the set.

Definition at line 173 of file qoi_set.h.

References _indices.

173 { return iterator(0, _indices); }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ clear()

void libMesh::QoISet::clear ( )
inline

Resets to "calculate all QoIs, give every QoI weight 1.0".

Definition at line 127 of file qoi_set.h.

References _indices, and _weights.

127 { _indices.clear(); _weights.clear(); }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184

◆ has_index()

bool libMesh::QoISet::has_index ( std::size_t  i) const
inline

◆ remove_index()

void libMesh::QoISet::remove_index ( std::size_t  i)
inline

Remove this index from the set to be calculated.

Definition at line 214 of file qoi_set.h.

References _indices.

215 {
216  if (i >= _indices.size())
217  _indices.resize(i+1, true);
218  _indices[i] = false;
219 }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ remove_indices()

void libMesh::QoISet::remove_indices ( const std::vector< unsigned int > &  indices)
inline

Remove these indices from the set to be calculated.

Definition at line 61 of file qoi_set.C.

References _indices.

62 {
63  for (const auto & i : indices)
64  _indices[i] = false;
65 }
std::vector< bool > _indices
Interpret _indices.empty() to mean "calculate all indices".
Definition: qoi_set.h:179

◆ set_weight()

void libMesh::QoISet::set_weight ( std::size_t  i,
Real  w 
)
inline

Set the weight for this index.

Definition at line 232 of file qoi_set.h.

References _weights.

Referenced by main().

233 {
234  if (_weights.size() <= i)
235  _weights.resize(i+1, 1.0);
236 
237  _weights[i] = w;
238 }
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184

◆ size()

std::size_t libMesh::QoISet::size ( const System sys) const
Returns
The number of QoIs that would be computed for the System sys

Definition at line 35 of file qoi_set.C.

References has_index(), libMesh::make_range(), and libMesh::System::n_qois().

Referenced by libMesh::TwostepTimeSolver::integrate_adjoint_sensitivity(), libMesh::UnsteadySolver::integrate_adjoint_sensitivity(), and libMesh::System::qoi_parameter_sensitivity().

36 {
37  std::size_t qoi_count = 0;
38  for (auto i : make_range(sys.n_qois()))
39  if (this->has_index(i))
40  qoi_count++;
41  return qoi_count;
42 }
bool has_index(std::size_t) const
Return whether or not this index is in the set to be calculated.
Definition: qoi_set.h:224
IntRange< T > make_range(T beg, T end)
The 2-parameter make_range() helper function returns an IntRange<T> when both input parameters are of...
Definition: int_range.h:140

◆ weight()

Real libMesh::QoISet::weight ( std::size_t  i) const
inline

Get the weight for this index (default 1.0)

Definition at line 243 of file qoi_set.h.

References _weights.

Referenced by libMesh::AdjointRefinementEstimator::estimate_error(), and libMesh::AdjointResidualErrorEstimator::estimate_error().

244 {
245  if (_weights.size() <= i)
246  return 1.0;
247  return _weights[i];
248 }
std::vector< Real > _weights
Interpret _weights.size() <= i to mean "weight i = 1.0".
Definition: qoi_set.h:184

Member Data Documentation

◆ _indices

std::vector<bool> libMesh::QoISet::_indices
private

Interpret _indices.empty() to mean "calculate all indices".

Definition at line 179 of file qoi_set.h.

Referenced by add_index(), add_indices(), begin(), clear(), has_index(), remove_index(), and remove_indices().

◆ _weights

std::vector<Real> libMesh::QoISet::_weights
private

Interpret _weights.size() <= i to mean "weight i = 1.0".

Definition at line 184 of file qoi_set.h.

Referenced by clear(), set_weight(), and weight().


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