libMesh
Public Member Functions | Protected Attributes | Private Attributes | List of all members
libMesh::CouplingAccessor Class Reference

This accessor class allows simple setting of CouplingMatrix values. More...

#include <coupling_matrix.h>

Inheritance diagram for libMesh::CouplingAccessor:
[legend]

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 191 of file coupling_matrix.h.

Constructor & Destructor Documentation

◆ CouplingAccessor()

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

Definition at line 194 of file coupling_matrix.h.

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

Member Function Documentation

◆ operator bool()

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

Definition at line 144 of file coupling_matrix.h.

References libMesh::ConstCouplingAccessor::_location, libMesh::ConstCouplingAccessor::_mat, libMesh::CouplingMatrix::_ranges, and libMesh::MeshTools::Subdivision::next.

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

◆ operator=() [1/2]

template<typename T >
CouplingAccessor& libMesh::CouplingAccessor::operator= ( new_value)
inline

Definition at line 199 of file coupling_matrix.h.

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

◆ operator=() [2/2]

CouplingAccessor& libMesh::CouplingAccessor::operator= ( bool  new_value)
inline

Definition at line 210 of file coupling_matrix.h.

References libMesh::ConstCouplingAccessor::_location, _my_mat, libMesh::CouplingMatrix::_ranges, and libMesh::MeshTools::Subdivision::next.

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

Member Data Documentation

◆ _location

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

◆ _mat

const CouplingMatrix& libMesh::ConstCouplingAccessor::_mat
protectedinherited

◆ _my_mat

CouplingMatrix& libMesh::CouplingAccessor::_my_mat
private

Definition at line 327 of file coupling_matrix.h.

Referenced by operator=().


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