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

Constructor & Destructor Documentation

◆ CouplingAccessor()

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

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

◆ operator bool()

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

Definition at line 144 of file coupling_matrix.h.

References libMesh::ConstCouplingAccessor::_location, libMesh::ConstCouplingAccessor::_mat, libMesh::CouplingMatrix::_ranges, 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]
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)

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  }

◆ operator=() [2/2]

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

Definition at line 209 of file coupling_matrix.h.

References libMesh::ConstCouplingAccessor::_location, _my_mat, libMesh::CouplingMatrix::_ranges, 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  {
240  CouplingMatrix::rc_type::const_iterator next = lb;
241  next++;
242  if (next != _my_mat._ranges.end())
243  {
244  // Ranges should be sorted and should not touch
245  libmesh_assert_greater(next->first, lastloc+1);
246  }
247  }
248 #endif
249 
250  // If we're in this range, we might need to shorten or remove
251  // or split it
252  if (new_value == false)
253  {
254  if (_location == firstloc)
255  {
256  if (_location == lastloc)
257  {
258  _my_mat._ranges.erase(lb);
259  }
260  else
261  {
262  libmesh_assert_less (lb->first, lastloc);
263  lb->first++;
264  }
265  }
266  else if (_location == lastloc)
267  {
268  libmesh_assert_less (firstloc, lb->second);
269 
270  lb->second--;
271  }
272  else if (_location < lastloc)
273  {
274  libmesh_assert_less_equal(_location+1, lastloc);
275 
276  lb->first = _location+1;
277 
278  libmesh_assert_less_equal(firstloc, _location-1);
279 
280  _my_mat._ranges.insert
281  (lb, std::make_pair(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()) ?
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
316  _my_mat._ranges.insert
317  (next, std::make_pair(_location, _location));
318  }
319  }
320  }
321  }
322 
323  return *this;
324  }
long double max(long double a, double b)
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 328 of file coupling_matrix.h.

Referenced by operator=().


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