qoi_set.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2014 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 
41 class QoISet
42 {
43 public:
44  class iterator
45  {
46  public:
47  iterator(unsigned int i, const std::vector<bool>& v) : _i(i), _vecbool(v)
48  {
49  while (_i < _vecbool.size() && !_vecbool[_i])
50  _i++;
51  }
52 
53  unsigned int operator*() const { return _i; }
54 
56  {
57  do {
58  _i++;
59  } while (_i < _vecbool.size() && !_vecbool[_i]);
60  return *this;
61  }
62 
64  iterator it = *this;
65  ++(*this);
66  return it;
67  }
68 
69  bool operator==(const iterator &other) const {
70  libmesh_assert_equal_to (&_vecbool, &other._vecbool);
71  return _i == other._i;
72  }
73 
74  bool operator!=(const iterator &other) const {
75  libmesh_assert_equal_to (&_vecbool, &other._vecbool);
76  return _i != other._i;
77  }
78 
79  private:
80 
81  unsigned int _i;
82 
83  const std::vector<bool>& _vecbool;
84  };
85 
93  QoISet() : _indices(), _weights() {}
94 
99  explicit
100  QoISet(const System &sys);
101 
106  explicit
107  QoISet(const std::vector<bool> &indices) :
108  _indices(indices), _weights() {}
109 
114  explicit
115  QoISet(const std::vector<unsigned int> &indices);
116 
120  void clear() { _indices.clear(); _weights.clear(); }
121 
126  unsigned int size(const System& sys) const;
127 
131  void add_indices(const std::vector<unsigned int> &indices);
132 
136  void add_index(unsigned int);
137 
141  void remove_indices(const std::vector<unsigned int> &indices);
142 
146  void remove_index(unsigned int);
147 
151  void set_weight(unsigned int, Real);
152 
156  Real weight(unsigned int) const;
157 
161  bool has_index(unsigned int) const;
162 
166  iterator begin() const { return iterator(0, _indices); }
167 
168 private:
172  std::vector<bool> _indices;
173 
177  std::vector<Real> _weights;
178 };
179 
180 
181 
182 // ------------------------------------------------------------
183 // QoISet inline methods
184 
185 
186 
187 inline
188 QoISet::QoISet(const std::vector<unsigned int> &indices) :
189  _indices(), _weights()
190 {
191  this->add_indices(indices);
192 }
193 
194 
195 
196 inline
197 void QoISet::add_index(unsigned int i)
198 {
199  if (i >= _indices.size())
200  _indices.resize(i+1, true);
201  _indices[i] = true;
202 }
203 
204 
205 
206 inline
207 void QoISet::remove_index(unsigned int i)
208 {
209  if (i >= _indices.size())
210  _indices.resize(i+1, true);
211  _indices[i] = false;
212 }
213 
214 
215 
216 inline
217 bool QoISet::has_index(unsigned int i) const
218 {
219  return (_indices.size() <= i || _indices[i]);
220 }
221 
222 
223 
224 inline
225 void QoISet::set_weight(unsigned int i, Real w)
226 {
227  if (_weights.size() <= i)
228  _weights.resize(i+1, 1.0);
229 
230  _weights[i] = w;
231 }
232 
233 
234 
235 inline
236 Real QoISet::weight(unsigned int i) const
237 {
238  if (_weights.size() <= i)
239  return 1.0;
240  return _weights[i];
241 }
242 
243 } // namespace libMesh
244 
245 #endif // LIBMESH_QOI_SET_H

Site Created By: libMesh Developers
Last modified: February 07 2014 16:57:06 UTC

Hosted By:
SourceForge.net Logo