qoi_set.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2018 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_QOI_SET_H
21 #define LIBMESH_QOI_SET_H
22 
23 
24 // Local Includes
25 #include "libmesh/libmesh_common.h"
26 
27 // C++ Includes
28 #include <vector>
29 
30 namespace libMesh
31 {
32 
33 // Forward Declarations
34 class System;
35 
45 class QoISet
46 {
47 public:
48  class iterator
49  {
50  public:
51  iterator(std::size_t i, const std::vector<bool> & v) : _i(i), _vecbool(v)
52  {
53  while (_i < _vecbool.size() && !_vecbool[_i])
54  _i++;
55  }
56 
57  std::size_t operator*() const { return _i; }
58 
60  {
61  do {
62  _i++;
63  } while (_i < _vecbool.size() && !_vecbool[_i]);
64  return *this;
65  }
66 
68  iterator it = *this;
69  ++(*this);
70  return it;
71  }
72 
73  bool operator==(const iterator & other) const {
74  libmesh_assert_equal_to (&_vecbool, &other._vecbool);
75  return _i == other._i;
76  }
77 
78  bool operator!=(const iterator & other) const {
79  libmesh_assert_equal_to (&_vecbool, &other._vecbool);
80  return _i != other._i;
81  }
82 
83  private:
84 
85  std::size_t _i;
86 
87  const std::vector<bool> & _vecbool;
88  };
89 
97  QoISet() : _indices(), _weights() {}
98 
103  explicit
104  QoISet(const System & sys);
105 
110  explicit
111  QoISet(const std::vector<bool> & indices) :
112  _indices(indices), _weights() {}
113 
118  explicit
119  QoISet(const std::vector<unsigned int> & indices);
120 
124  void clear() { _indices.clear(); _weights.clear(); }
125 
130  std::size_t size(const System & sys) const;
131 
135  void add_indices(const std::vector<unsigned int> & indices);
136 
140  void add_index(std::size_t);
141 
145  void remove_indices(const std::vector<unsigned int> & indices);
146 
150  void remove_index(std::size_t);
151 
155  void set_weight(std::size_t, Real);
156 
160  Real weight(std::size_t) const;
161 
165  bool has_index(std::size_t) const;
166 
170  iterator begin() const { return iterator(0, _indices); }
171 
172 private:
176  std::vector<bool> _indices;
177 
181  std::vector<Real> _weights;
182 };
183 
184 
185 
186 // ------------------------------------------------------------
187 // QoISet inline methods
188 
189 
190 
191 inline
192 QoISet::QoISet(const std::vector<unsigned int> & indices) :
193  _indices(), _weights()
194 {
195  this->add_indices(indices);
196 }
197 
198 
199 
200 inline
201 void QoISet::add_index(std::size_t i)
202 {
203  if (i >= _indices.size())
204  _indices.resize(i+1, true);
205  _indices[i] = true;
206 }
207 
208 
209 
210 inline
211 void QoISet::remove_index(std::size_t i)
212 {
213  if (i >= _indices.size())
214  _indices.resize(i+1, true);
215  _indices[i] = false;
216 }
217 
218 
219 
220 inline
221 bool QoISet::has_index(std::size_t i) const
222 {
223  return (_indices.size() <= i || _indices[i]);
224 }
225 
226 
227 
228 inline
229 void QoISet::set_weight(std::size_t i, Real w)
230 {
231  if (_weights.size() <= i)
232  _weights.resize(i+1, 1.0);
233 
234  _weights[i] = w;
235 }
236 
237 
238 
239 inline
240 Real QoISet::weight(std::size_t i) const
241 {
242  if (_weights.size() <= i)
243  return 1.0;
244  return _weights[i];
245 }
246 
247 } // namespace libMesh
248 
249 #endif // LIBMESH_QOI_SET_H
void add_index(std::size_t)
Definition: qoi_set.h:201
void set_weight(std::size_t, Real)
Definition: qoi_set.h:229
const std::vector< bool > & _vecbool
Definition: qoi_set.h:87
iterator begin() const
Definition: qoi_set.h:170
Used to specify quantities of interest in a simulation.
Definition: qoi_set.h:45
bool operator==(const iterator &other) const
Definition: qoi_set.h:73
std::vector< bool > _indices
Definition: qoi_set.h:176
iterator & operator++()
Definition: qoi_set.h:59
bool has_index(std::size_t) const
Definition: qoi_set.h:221
std::size_t operator*() const
Definition: qoi_set.h:57
Manages consistently variables, degrees of freedom, and coefficient vectors.
Definition: system.h:92
std::size_t size(const System &sys) const
Definition: qoi_set.C:35
Real weight(std::size_t) const
Definition: qoi_set.h:240
std::vector< Real > _weights
Definition: qoi_set.h:181
QoISet(const std::vector< bool > &indices)
Definition: qoi_set.h:111
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void remove_index(std::size_t)
Definition: qoi_set.h:211
void add_indices(const std::vector< unsigned int > &indices)
Definition: qoi_set.C:46
iterator operator++(int)
Definition: qoi_set.h:67
iterator(std::size_t i, const std::vector< bool > &v)
Definition: qoi_set.h:51
bool operator!=(const iterator &other) const
Definition: qoi_set.h:78
void remove_indices(const std::vector< unsigned int > &indices)
Definition: qoi_set.C:61
void clear()
Definition: qoi_set.h:124