libMesh::CouplingAccessor Class Reference

#include <coupling_matrix.h>

Inheritance diagram for libMesh::CouplingAccessor:

Public Member Functions

 CouplingAccessor (std::size_t loc_in, CouplingMatrix &mat_in)
 
template<typename T >
CouplingAccessoroperator= (T new_value)
 
CouplingAccessoroperator= (bool new_value)
 
 operator bool () const
 

Protected Attributes

std::size_t _location
 
const CouplingMatrix_mat
 

Private Attributes

CouplingMatrix_my_mat
 

Detailed Description

This accessor class allows simple setting of CouplingMatrix values.

Definition at line 190 of file coupling_matrix.h.

Constructor & Destructor Documentation

libMesh::CouplingAccessor::CouplingAccessor ( std::size_t  loc_in,
CouplingMatrix mat_in 
)
inline

Definition at line 193 of file coupling_matrix.h.

194  :
195  ConstCouplingAccessor(loc_in, mat_in), _my_mat(mat_in) {}
ConstCouplingAccessor(std::size_t loc_in, const CouplingMatrix &mat_in)

Member Function Documentation

libMesh::ConstCouplingAccessor::operator bool ( ) const
inlineinherited

Definition at line 144 of file coupling_matrix.h.

References std::max(), and libMesh::MeshTools::Subdivision::next.

144  {
145  const std::size_t max_size = std::numeric_limits<std::size_t>::max();
146 
147  // Find the range that might contain i,j
148  // lower_bound isn't *quite* what we want
149  CouplingMatrix::rc_type::const_iterator lb = std::upper_bound
150  (_mat._ranges.begin(), _mat._ranges.end(),
151  std::make_pair(_location, max_size));
152  if (lb!=_mat._ranges.begin())
153  --lb;
154  else
155  lb=_mat._ranges.end();
156 
157  // If no range might contain i,j then it's 0
158  if (lb == _mat._ranges.end())
159  return false;
160 
161  const std::size_t lastloc = lb->second;
162 
163 #ifdef DEBUG
164  const std::size_t firstloc = lb->first;
165  libmesh_assert_less_equal(firstloc, lastloc);
166  libmesh_assert_less_equal(firstloc, _location);
167 
168  CouplingMatrix::rc_type::const_iterator next = lb;
169  next++;
170  if (next != _mat._ranges.end())
171  {
172  // Ranges should be sorted and should not touch
173  libmesh_assert_greater(next->first, lastloc+1);
174  }
175 #endif
176 
177  return (lastloc >= _location);
178  }
long double max(long double a, double b)
static const unsigned int next[3]
const CouplingMatrix & _mat
template<typename T >
CouplingAccessor& libMesh::CouplingAccessor::operator= ( new_value)
inline

Definition at line 198 of file coupling_matrix.h.

199  {
200  // For backwards compatibility we take integer arguments,
201  // but coupling matrix entries are really all zero or one.
202  const bool as_bool = new_value;
203  libmesh_assert_equal_to(new_value, as_bool);
204 
205  *this = as_bool;
206  return *this;
207  }
CouplingAccessor& libMesh::CouplingAccessor::operator= ( bool  new_value)
inline

Definition at line 209 of file coupling_matrix.h.

References std::max(), and libMesh::MeshTools::Subdivision::next.

210  {
211  const std::size_t max_size = std::numeric_limits<std::size_t>::max();
212 
213  // Find the range that might contain i,j
214  // lower_bound isn't *quite* what we want
215  CouplingMatrix::rc_type::iterator lb =
216  std::upper_bound (_my_mat._ranges.begin(), _my_mat._ranges.end(),
217  std::make_pair(_location, max_size));
218  if (lb!=_my_mat._ranges.begin())
219  --lb;
220  else
221  lb=_my_mat._ranges.end();
222 
223  // If no range might contain i,j then we might need to make a new
224  // one.
225  if (lb == _my_mat._ranges.end())
226  {
227  if (new_value == true)
228  _my_mat._ranges.insert(_my_mat._ranges.begin(),
229  std::make_pair(_location, _location));
230  }
231  else
232  {
233  const std::size_t firstloc = lb->first;
234  const std::size_t lastloc = lb->second;
235  libmesh_assert_less_equal(firstloc, lastloc);
236  libmesh_assert_less_equal(firstloc, _location);
237 
238 #ifdef DEBUG
239  CouplingMatrix::rc_type::const_iterator next = lb;
240  next++;
241  if (next != _my_mat._ranges.end())
242  {
243  // Ranges should be sorted and should not touch
244  libmesh_assert_greater(next->first, lastloc+1);
245  }
246 #endif
247 
248  // If we're in this range, we might need to shorten or remove
249  // or split it
250  if (new_value == false)
251  {
252  if (_location == firstloc)
253  {
254  if (_location == lastloc)
255  {
256  _my_mat._ranges.erase(lb);
257  }
258  else
259  {
260  libmesh_assert_less (lb->first, lastloc);
261  lb->first++;
262  }
263  }
264  else if (_location == lastloc)
265  {
266  libmesh_assert_less (firstloc, lb->second);
267 
268  lb->second--;
269  }
270  else if (_location < lastloc)
271  {
272  libmesh_assert_less_equal(_location+1, lastloc);
273 
274  lb->first = _location+1;
275 
276  libmesh_assert_less_equal(firstloc, _location-1);
277 
278  _my_mat._ranges.insert
279  (lb, std::make_pair(firstloc, _location-1));
280  }
281  }
282 
283  // If we're not in this range, we might need to extend it or
284  // join it with its neighbor or add a new one.
285  else // new_value == true
286  {
287  CouplingMatrix::rc_type::iterator next = lb;
288  next++;
289  const std::size_t nextloc =
290  (next == _my_mat._ranges.end()) ?
292  next->first;
293 
294  // Ranges should be sorted and should not touch
295  libmesh_assert_greater(nextloc, lastloc+1);
296 
297  if (_location > lastloc)
298  {
299  if (_location == lastloc + 1)
300  {
301  if (_location == nextloc - 1)
302  {
303  next->first = firstloc;
304  _my_mat._ranges.erase(lb);
305  }
306  else
307  lb->second++;
308  }
309  else
310  {
311  if (_location == nextloc - 1)
312  next->first--;
313  else
314  _my_mat._ranges.insert
315  (next, std::make_pair(_location, _location));
316  }
317  }
318  }
319  }
320 
321  return *this;
322  }
long double max(long double a, double b)
static const unsigned int next[3]

Member Data Documentation

std::size_t libMesh::ConstCouplingAccessor::_location
protectedinherited

Definition at line 182 of file coupling_matrix.h.

const CouplingMatrix& libMesh::ConstCouplingAccessor::_mat
protectedinherited

Definition at line 183 of file coupling_matrix.h.

CouplingMatrix& libMesh::CouplingAccessor::_my_mat
private

Definition at line 326 of file coupling_matrix.h.


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