/usr/include/deal.II/lac/block_indices.h is in libdeal.ii-dev 6.3.1-1.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 | //---------------------------------------------------------------------------
// $Id: block_indices.h 20967 2010-04-09 05:06:05Z bangerth $
// Version: $Name$
//
// Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2010 by the deal.II authors
//
// This file is subject to QPL and may not be distributed
// without copyright and license information. Please refer
// to the file deal.II/doc/license.html for the text and
// further information on this license.
//
//---------------------------------------------------------------------------
#ifndef __deal2__block_indices_h
#define __deal2__block_indices_h
#include <base/config.h>
#include <base/subscriptor.h>
#include <base/exceptions.h>
#include <vector>
DEAL_II_NAMESPACE_OPEN
/**
* Class that manages the conversion of global indices into a block vector or
* matrix to the local indices within this block. This is required, for
* example, when you address a global element in a block vector and want to
* know which element within which block this is. It is also useful if a
* matrix is composed of several blocks, where you have to translate global
* row and column indices to local ones.
*
* @ingroup data
* @see @ref GlossBlockLA "Block (linear algebra)"
* @author Wolfgang Bangerth, Guido Kanschat, 2000, 2007
*/
class BlockIndices : public Subscriptor
{
public:
/**
* Default
* constructor. Initialize for
* @p n_blocks blocks and set
* all block sizes to zero.
*/
BlockIndices (const unsigned int n_blocks = 0);
/**
* Constructor. Initialize the
* number of entries in each
* block @p i as <tt>n[i]</tt>. The
* number of blocks will be the
* size of the vector
*/
BlockIndices (const std::vector<unsigned int> &n);
/**
* Reinitialize the number of
* blocks and assign each block
* the same number of elements.
*/
void reinit (const unsigned int n_blocks,
const unsigned int n_elements_per_block);
/**
* Reinitialize the number of
* indices within each block from
* the given argument. The number
* of blocks will be adjusted to
* the size of @p n and the size
* of block @p i is set to
* <tt>n[i]</tt>.
*/
inline void reinit (const std::vector<unsigned int> &n);
/**
* Return the block and the
* index within that block
* for the global index @p i. The
* first element of the pair is
* the block, the second the
* index within it.
*/
std::pair<unsigned int,unsigned int>
global_to_local (const unsigned int i) const;
/**
* Return the global index of
* @p index in block @p block.
*/
unsigned int local_to_global (const unsigned int block,
const unsigned int index) const;
/**
* Number of blocks in index field.
*/
unsigned int size () const;
/**
* Return the total number of
* indices accumulated over all
* blocks, that is, the dimension
* of the vector space of the
* block vector.
*/
inline unsigned int total_size () const;
/**
* The size of the @p ith block.
*/
unsigned int block_size (const unsigned int i) const;
/**
* The start index of the ith block.
*/
unsigned int block_start (const unsigned int i) const;
/**
* Copy operator.
*/
BlockIndices & operator = (const BlockIndices &b);
/**
* Compare whether two objects
* are the same, i.e. whether the
* starting indices of all blocks
* are equal.
*/
bool operator == (const BlockIndices &b) const;
/**
* Swap the contents of these two
* objects.
*/
void swap (BlockIndices &b);
/**
* Determine an estimate for the
* memory consumption (in bytes)
* of this object.
*/
unsigned int memory_consumption () const;
private:
/**
* Number of blocks. While this
* value could be obtained
* through
* <tt>start_indices.size()-1</tt>,
* we cache this value for faster
* access.
*/
unsigned int n_blocks;
/**
* Global starting index of each
* vector. The last and redundant
* value is the total number of
* entries.
*/
std::vector<unsigned int> start_indices;
};
/* ---------------------- template and inline functions ------------------- */
inline
BlockIndices::BlockIndices (const unsigned int n_blocks)
:
n_blocks(n_blocks),
start_indices(n_blocks+1)
{
for (unsigned int i=0; i<=n_blocks; ++i)
start_indices[i] = 0;
}
inline
BlockIndices::BlockIndices (const std::vector<unsigned int> &n)
:
n_blocks(n.size()),
start_indices(n.size()+1)
{
reinit (n);
}
inline
void
BlockIndices::reinit (const unsigned int n_blocks,
const unsigned int n_elements_per_block)
{
const std::vector<unsigned int> v(n_blocks, n_elements_per_block);
reinit (v);
}
inline
void
BlockIndices::reinit (const std::vector<unsigned int> &n)
{
if (start_indices.size() != n.size()+1)
{
n_blocks = n.size();
start_indices.resize(n_blocks+1);
}
start_indices[0] = 0;
for (unsigned int i=1; i<=n_blocks; ++i)
start_indices[i] = start_indices[i-1] + n[i-1];
}
inline
std::pair<unsigned int,unsigned int>
BlockIndices::global_to_local (const unsigned int i) const
{
Assert (i<total_size(), ExcIndexRange(i, 0, total_size()));
int block = n_blocks-1;
while (i < start_indices[block])
--block;
return std::make_pair<unsigned int>(block, i-start_indices[block]);
}
inline
unsigned int
BlockIndices::local_to_global (const unsigned int block,
const unsigned int index) const
{
Assert (block < n_blocks, ExcIndexRange(block, 0, n_blocks));
Assert (index < start_indices[block+1]-start_indices[block],
ExcIndexRange (index, 0, start_indices[block+1]-start_indices[block]));
return start_indices[block]+index;
}
inline
unsigned int
BlockIndices::size () const
{
return n_blocks;
}
inline
unsigned int
BlockIndices::total_size () const
{
return start_indices[n_blocks];
}
inline
unsigned int
BlockIndices::block_size (const unsigned int block) const
{
Assert (block < n_blocks, ExcIndexRange(block, 0, n_blocks));
return start_indices[block+1]-start_indices[block];
}
inline
unsigned int
BlockIndices::block_start (const unsigned int block) const
{
Assert (block < n_blocks, ExcIndexRange(block, 0, n_blocks));
return start_indices[block];
}
inline
BlockIndices &
BlockIndices::operator = (const BlockIndices &b)
{
start_indices = b.start_indices;
n_blocks = b.n_blocks;
return *this;
}
inline
bool
BlockIndices::operator == (const BlockIndices &b) const
{
if (n_blocks != b.n_blocks)
return false;
for (unsigned int i=0; i<=n_blocks; ++i)
if (start_indices[i] != b.start_indices[i])
return false;
return true;
}
inline
void
BlockIndices::swap (BlockIndices &b)
{
Assert (n_blocks == b.n_blocks,
ExcDimensionMismatch(n_blocks, b.n_blocks));
for (unsigned int i=0; i<=n_blocks; ++i)
std::swap (start_indices[i], b.start_indices[i]);
}
inline
unsigned int
BlockIndices::memory_consumption () const
{
return (sizeof(*this) +
start_indices.size() * sizeof(start_indices[0]));
}
/* ----------------- global functions ---------------------------- */
/**
* Global function @p swap which overloads the default implementation
* of the C++ standard library which uses a temporary object. The
* function simply exchanges the data of the two objects.
*
* @relates BlockIndices
* @author Wolfgang Bangerth, 2000
*/
inline
void swap (BlockIndices &u, BlockIndices &v)
{
u.swap (v);
}
DEAL_II_NAMESPACE_CLOSE
#endif
|