$extrastylesheet
00001 // The libMesh Finite Element Library. 00002 // Copyright (C) 2002-2014 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner 00003 00004 // This library is free software; you can redistribute it and/or 00005 // modify it under the terms of the GNU Lesser General Public 00006 // License as published by the Free Software Foundation; either 00007 // version 2.1 of the License, or (at your option) any later version. 00008 00009 // This library is distributed in the hope that it will be useful, 00010 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 // Lesser General Public License for more details. 00013 00014 // You should have received a copy of the GNU Lesser General Public 00015 // License along with this library; if not, write to the Free Software 00016 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 00018 00019 00020 #ifndef LIBMESH_QOI_SET_H 00021 #define LIBMESH_QOI_SET_H 00022 00023 00024 // Local Includes ----------------------------------- 00025 #include "libmesh/libmesh_common.h" 00026 00027 // C++ Includes ----------------------------------- 00028 #include <vector> 00029 00030 namespace libMesh 00031 { 00032 00033 // Forward Declarations ----------------------------- 00034 class System; 00035 00041 class QoISet 00042 { 00043 public: 00044 class iterator 00045 { 00046 public: 00047 iterator(unsigned int i, const std::vector<bool>& v) : _i(i), _vecbool(v) 00048 { 00049 while (_i < _vecbool.size() && !_vecbool[_i]) 00050 _i++; 00051 } 00052 00053 unsigned int operator*() const { return _i; } 00054 00055 iterator& operator++() 00056 { 00057 do { 00058 _i++; 00059 } while (_i < _vecbool.size() && !_vecbool[_i]); 00060 return *this; 00061 } 00062 00063 iterator operator++(int) { 00064 iterator it = *this; 00065 ++(*this); 00066 return it; 00067 } 00068 00069 bool operator==(const iterator &other) const { 00070 libmesh_assert_equal_to (&_vecbool, &other._vecbool); 00071 return _i == other._i; 00072 } 00073 00074 bool operator!=(const iterator &other) const { 00075 libmesh_assert_equal_to (&_vecbool, &other._vecbool); 00076 return _i != other._i; 00077 } 00078 00079 private: 00080 00081 unsigned int _i; 00082 00083 const std::vector<bool>& _vecbool; 00084 }; 00085 00093 QoISet() : _indices(), _weights() {} 00094 00099 explicit 00100 QoISet(const System &sys); 00101 00106 explicit 00107 QoISet(const std::vector<bool> &indices) : 00108 _indices(indices), _weights() {} 00109 00114 explicit 00115 QoISet(const std::vector<unsigned int> &indices); 00116 00120 void clear() { _indices.clear(); _weights.clear(); } 00121 00126 unsigned int size(const System& sys) const; 00127 00131 void add_indices(const std::vector<unsigned int> &indices); 00132 00136 void add_index(unsigned int); 00137 00141 void remove_indices(const std::vector<unsigned int> &indices); 00142 00146 void remove_index(unsigned int); 00147 00151 void set_weight(unsigned int, Real); 00152 00156 Real weight(unsigned int) const; 00157 00161 bool has_index(unsigned int) const; 00162 00166 iterator begin() const { return iterator(0, _indices); } 00167 00168 private: 00172 std::vector<bool> _indices; 00173 00177 std::vector<Real> _weights; 00178 }; 00179 00180 00181 00182 // ------------------------------------------------------------ 00183 // QoISet inline methods 00184 00185 00186 00187 inline 00188 QoISet::QoISet(const std::vector<unsigned int> &indices) : 00189 _indices(), _weights() 00190 { 00191 this->add_indices(indices); 00192 } 00193 00194 00195 00196 inline 00197 void QoISet::add_index(unsigned int i) 00198 { 00199 if (i >= _indices.size()) 00200 _indices.resize(i+1, true); 00201 _indices[i] = true; 00202 } 00203 00204 00205 00206 inline 00207 void QoISet::remove_index(unsigned int i) 00208 { 00209 if (i >= _indices.size()) 00210 _indices.resize(i+1, true); 00211 _indices[i] = false; 00212 } 00213 00214 00215 00216 inline 00217 bool QoISet::has_index(unsigned int i) const 00218 { 00219 return (_indices.size() <= i || _indices[i]); 00220 } 00221 00222 00223 00224 inline 00225 void QoISet::set_weight(unsigned int i, Real w) 00226 { 00227 if (_weights.size() <= i) 00228 _weights.resize(i+1, 1.0); 00229 00230 _weights[i] = w; 00231 } 00232 00233 00234 00235 inline 00236 Real QoISet::weight(unsigned int i) const 00237 { 00238 if (_weights.size() <= i) 00239 return 1.0; 00240 return _weights[i]; 00241 } 00242 00243 } // namespace libMesh 00244 00245 #endif // LIBMESH_QOI_SET_H