/usr/include/deal.II/matrix_free/dof_info.h is in libdeal.ii-dev 8.4.2-2+b1.
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 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 | // ---------------------------------------------------------------------
//
// Copyright (C) 2011 - 2015 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE at
// the top level of the deal.II distribution.
//
// ---------------------------------------------------------------------
#ifndef dealii__matrix_free_dof_info_h
#define dealii__matrix_free_dof_info_h
#include <deal.II/base/exceptions.h>
#include <deal.II/base/vectorization.h>
#include <deal.II/base/partitioner.h>
#include <deal.II/lac/constraint_matrix.h>
#include <deal.II/lac/dynamic_sparsity_pattern.h>
#include <deal.II/dofs/dof_handler.h>
#include <deal.II/matrix_free/helper_functions.h>
#include <deal.II/base/std_cxx11/array.h>
#include <memory>
DEAL_II_NAMESPACE_OPEN
namespace internal
{
namespace MatrixFreeFunctions
{
/**
* The class that stores the indices of the degrees of freedom for all the
* cells. Essentially, this is a smart number cache in the style of a
* DoFHandler that also embeds the description of constraints directly on
* the cell level without the need to refer to the external
* ConstraintMatrix.
*
* This class only stores index relations. The weights for hanging node
* constraints are stored in a different field. This is because a
* different field allows for the same compressed weight data on different
* DoFHandlers for vector-valued problems. There, the indices might be
* constrained differently on different components (e.g. Dirichlet
* conditions only on selected components), whereas the weights from
* hanging nodes are the same and need to be stored only once. The
* combination will be handled in the MatrixFree class.
*
* @author Katharina Kormann and Martin Kronbichler, 2010, 2011
*/
struct DoFInfo
{
/**
* Default empty constructor.
*/
DoFInfo ();
/**
* Copy constructor.
*/
DoFInfo (const DoFInfo &dof_info);
/**
* Clears all data fields in this class.
*/
void clear ();
/**
* Returns a pointer to the first index in the DoF row @p row.
*/
const unsigned int *begin_indices (const unsigned int row) const;
/**
* Returns a pointer to the one past the last DoF index in the row @p
* row.
*/
const unsigned int *end_indices (const unsigned int row) const;
/**
* Returns the number of entries in the indices field for the given row.
*/
unsigned int row_length_indices (const unsigned int row) const;
/**
* Returns a pointer to the first constraint indicator in the row @p
* row.
*/
const std::pair<unsigned short,unsigned short> *
begin_indicators (const unsigned int row) const;
/**
* Returns a pointer to the one past the last constraint indicator in
* the row @p row.
*/
const std::pair<unsigned short,unsigned short> *
end_indicators (const unsigned int row) const;
/**
* Returns the number of entries in the constraint indicator field for
* the given row.
*/
unsigned int row_length_indicators (const unsigned int row) const;
/**
* Returns a pointer to the first index in the DoF row @p row for plain
* indices (i.e., the entries where constraints are not embedded).
*/
const unsigned int *begin_indices_plain (const unsigned int row) const;
/**
* Returns a pointer to the one past the last DoF index in the row @p
* row (i.e., the entries where constraints are not embedded).
*/
const unsigned int *end_indices_plain (const unsigned int row) const;
/**
* Returns the FE index for a given finite element degree. If not in hp
* mode, this function always returns index 0. If an index is not found
* in hp mode, it returns max_fe_degree, i.e., one index past the last
* valid one.
*/
unsigned int fe_index_from_degree (const unsigned int fe_degree) const;
/**
* Returns the FE index for a given finite element degree. If not in hp
* mode or if the index is not found, this function always returns index
* 0. Hence, this function does not check whether the given degree is
* actually present.
*/
unsigned int
fe_index_from_dofs_per_cell (const unsigned int dofs_per_cell) const;
/**
* This internal method takes the local indices on a cell and fills them
* into this class. It resolves the constraints and distributes the
* results. Ghost indices, i.e., indices that are located on another
* processor, get a temporary number by this function, and will later be
* assigned the correct index after all the ghost indices have been
* collected by the call to @p assign_ghosts.
*/
void read_dof_indices (const std::vector<types::global_dof_index> &local_indices,
const std::vector<unsigned int> &lexicographic_inv,
const ConstraintMatrix &constraints,
const unsigned int cell_number,
ConstraintValues<double> &constraint_values,
bool &cell_at_boundary);
/**
* This method assigns the correct indices to ghost indices from the
* temporary numbering employed by the @p read_dof_indices function. The
* numbers are localized with respect to the MPI process, and ghosts
* start at the end of the locally owned range. This way, we get direct
* access to all vector entries.
*/
void assign_ghosts(const std::vector<unsigned int> &boundary_cells);
/**
* Reorganizes cells for serial (non-thread-parallelized) such that
* boundary cells are places in the middle. This way, computations and
* communication can be overlapped. Should only be called by one DoFInfo
* object when used on a system of several DoFHandlers.
*/
void compute_renumber_serial (const std::vector<unsigned int> &boundary_cells,
const SizeInfo &size_info,
std::vector<unsigned int> &renumbering);
/**
* Reorganizes cells in the hp case without parallelism such that all
* cells with the same FE index are placed consecutively. Should only be
* called by one DoFInfo object when used on a system of several
* DoFHandlers.
*/
void compute_renumber_hp_serial (SizeInfo &size_info,
std::vector<unsigned int> &renumbering,
std::vector<unsigned int> &irregular_cells);
/**
* Computes the initial renumbering of cells such that all cells with
* ghosts are put first. This is the first step before building the
* thread graph and used to overlap computations and communication.
*/
void compute_renumber_parallel (const std::vector<unsigned int> &boundary_cells,
SizeInfo &size_info,
std::vector<unsigned int> &renumbering);
/**
* This method reorders the way cells are gone through based on a given
* renumbering of the cells. It also takes @p vectorization_length cells
* together and interprets them as one cell only, as is needed for
* vectorization.
*/
void reorder_cells (const SizeInfo &size_info,
const std::vector<unsigned int> &renumbering,
const std::vector<unsigned int> &constraint_pool_row_index,
const std::vector<unsigned int> &irregular_cells,
const unsigned int vectorization_length);
/**
* This helper function determines a block size if the user decided not
* to force a block size through MatrixFree::AdditionalData. This is
* computed based on the number of hardware threads on the system and
* the number of macro cells that we should work on.
*/
void guess_block_size (const SizeInfo &size_info,
TaskInfo &task_info);
/**
* This method goes through all cells that have been filled into @p
* dof_indices and finds out which cells can be worked on independently
* and which ones are neighboring and need to be done at different times
* when used in parallel.
*
* The strategy is based on a two-level approach. The outer level is
* subdivided into partitions similar to the type of neighbors in
* Cuthill-McKee, and the inner level is subdivided via colors (for
* chunks within the same color, can work independently). One task is
* represented by a chunk of cells. The cell chunks are formed before
* subdivision into partitions and colors.
*/
void
make_thread_graph_partition_color (SizeInfo &size_info,
TaskInfo &task_info,
std::vector<unsigned int> &renumbering,
std::vector<unsigned int> &irregular_cells,
const bool hp_bool);
/**
* This function goes through all cells that have been filled into @p
* dof_indices and finds out which cells can be worked on independently
* and which ones are neighboring and need to be done at different times
* when used in parallel.
*
* The strategy is based on a two-level approach. The outer level is
* subdivided into partitions similar to the type of neighbors in
* Cuthill-McKee, and the inner level is again subdivided into Cuthill-
* McKee-like partitions (partitions whose level differs by more than 2
* can be worked on independently). One task is represented by a chunk
* of cells. The cell chunks are formed after subdivision into the two
* levels of partitions.
*/
void
make_thread_graph_partition_partition (SizeInfo &size_info,
TaskInfo &task_info,
std::vector<unsigned int> &renumbering,
std::vector<unsigned int> &irregular_cells,
const bool hp_bool);
/**
* This function computes the connectivity of the currently stored
* indices and fills the structure into a sparsity pattern. The
* parameter block_size can be used to specify whether several cells
* should be treated as one.
*/
void
make_connectivity_graph (const SizeInfo &size_info,
const TaskInfo &task_info,
const std::vector<unsigned int> &renumbering,
const std::vector<unsigned int> &irregular_cells,
const bool do_blocking,
DynamicSparsityPattern &connectivity) const;
/**
* Renumbers the degrees of freedom to give good access for this class.
*/
void renumber_dofs (std::vector<types::global_dof_index> &renumbering);
/**
* Returns the memory consumption in bytes of this class.
*/
std::size_t memory_consumption() const;
/**
* Prints a detailed summary of memory consumption in the different
* structures of this class to the given output stream.
*/
template <typename StreamType>
void print_memory_consumption(StreamType &out,
const SizeInfo &size_info) const;
/**
* Prints a representation of the indices in the class to the given
* output stream.
*/
template <typename Number>
void print (const std::vector<Number> &constraint_pool_data,
const std::vector<unsigned int> &constraint_pool_row_index,
std::ostream &out) const;
/**
* Stores the rowstart indices of the compressed row storage in the @p
* dof_indices and @p constraint_indicator fields. These two fields are
* always accessed together, so it is simpler to keep just one variable
* for them. This also obviates keeping two rowstart vectors in synch.
*
* In addition, the third field stores whether a particular cell has a
* certain structure in the indices, like indices for vector-valued
* problems or for cells where not all vector components are filled.
*/
std::vector<std_cxx11::array<unsigned int, 3> > row_starts;
/**
* Stores the indices of the degrees of freedom for each cell. These
* indices are computed in MPI-local index space, i.e., each processor
* stores the locally owned indices as numbers between <tt>0</tt> and
* <tt>n_locally_owned_dofs-1</tt> and ghost indices in the range
* <tt>n_locally_owned_dofs</tt> to
* <tt>n_locally_owned_dofs+n_ghost_dofs</tt>. The translation between
* this MPI-local index space and the global numbering of degrees of
* freedom is stored in the @p vector_partitioner data structure. This
* array also includes the indirect contributions from constraints,
* which are described by the @p constraint_indicator field. Because of
* variable lengths of rows, this would be a vector of a vector.
* However, we use one contiguous memory region and store the rowstart
* in the variable @p row_starts.
*/
std::vector<unsigned int> dof_indices;
/**
* This variable describes the position of constraints in terms of the
* local numbering of degrees of freedom on a cell. The first number
* stores the distance from one constrained degree of freedom to the
* next. This allows to identify the position of constrained DoFs as we
* loop through the local degrees of freedom of the cell when reading
* from or writing to a vector. The second number stores the index of
* the constraint weights, stored in the variable constraint_pool_data.
*/
std::vector<std::pair<unsigned short,unsigned short> > constraint_indicator;
/**
* This stores the parallel partitioning that can be used to set up
* vectors. The partitioner includes the description of the local range
* in the vector, and also includes how the ghosts look like. This
* enables initialization of vectors based on the DoFInfo field.
*/
std_cxx11::shared_ptr<const Utilities::MPI::Partitioner> vector_partitioner;
/**
* This stores a (sorted) list of all locally owned degrees of freedom
* that are constrained.
*/
std::vector<unsigned int> constrained_dofs;
/**
* Stores the rowstart indices of the compressed row storage in the @p
* plain_dof_indices fields.
*/
std::vector<unsigned int> row_starts_plain_indices;
/**
* Stores the indices of the degrees of freedom for each cell. This
* array does not include the indirect contributions from constraints,
* which are included in @p dof_indices. Because of variable lengths of
* rows, this would be a vector of a vector. However, we use one
* contiguous memory region and store the rowstart in the variable @p
* row_starts_plain_indices.
*/
std::vector<unsigned int> plain_dof_indices;
/**
* Stores the dimension of the underlying DoFHandler. Since the indices
* are not templated, this is the variable that makes the dimension
* accessible in the (rare) cases it is needed inside this class.
*/
unsigned int dimension;
/**
* Stores the number of components in the DoFHandler where the indices
* have been read from.
*/
unsigned int n_components;
/**
* Stores the number of degrees of freedom per cell.
*/
std::vector<unsigned int> dofs_per_cell;
/**
* Stores the number of degrees of freedom per face.
*/
std::vector<unsigned int> dofs_per_face;
/**
* Informs on whether plain indices are cached.
*/
bool store_plain_indices;
/**
* Stores the index of the active finite element in the hp case.
*/
std::vector<unsigned int> cell_active_fe_index;
/**
* Stores the maximum degree of different finite elements for the hp
* case.
*/
unsigned int max_fe_index;
/**
* This variable stores the dofs per cell and the finite element degree
* associated for all fe indices in the underlying element for easier
* access to data in the hp case.
*/
std::vector<std::pair<unsigned int,unsigned int> > fe_index_conversion;
/**
* Temporarily stores the numbers of ghosts during setup. Cleared when
* calling @p assign_ghosts. Then, all information is collected by the
* partitioner.
*/
std::vector<types::global_dof_index> ghost_dofs;
};
/*----------------------- Inline functions ----------------------------------*/
#ifndef DOXYGEN
inline
const unsigned int *
DoFInfo::begin_indices (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
const unsigned int index = row_starts[row][0];
AssertIndexRange(index, dof_indices.size()+1);
return dof_indices.empty() ? 0 : &dof_indices[0] + index;
}
inline
const unsigned int *
DoFInfo::end_indices (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
const unsigned int index = row_starts[row+1][0];
AssertIndexRange(index, dof_indices.size()+1);
return dof_indices.empty() ? 0 : &dof_indices[0] + index;
}
inline
unsigned int
DoFInfo::row_length_indices (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
return (row_starts[row+1][0] - row_starts[row][0]);
}
inline
const std::pair<unsigned short,unsigned short> *
DoFInfo::begin_indicators (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
const unsigned int index = row_starts[row][1];
AssertIndexRange (index, constraint_indicator.size()+1);
return constraint_indicator.empty() ? 0 : &constraint_indicator[0] + index;
}
inline
const std::pair<unsigned short,unsigned short> *
DoFInfo::end_indicators (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
const unsigned int index = row_starts[row+1][1];
AssertIndexRange (index, constraint_indicator.size()+1);
return constraint_indicator.empty() ? 0 : &constraint_indicator[0] + index;
}
inline
unsigned int
DoFInfo::row_length_indicators (const unsigned int row) const
{
AssertIndexRange (row, row_starts.size()-1);
return (row_starts[row+1][1] - row_starts[row][1]);
}
inline
const unsigned int *
DoFInfo::begin_indices_plain (const unsigned int row) const
{
// if we have no constraints, should take the data from dof_indices
if (row_length_indicators(row) == 0)
{
Assert (row_starts_plain_indices[row]==numbers::invalid_unsigned_int,
ExcInternalError());
return begin_indices(row);
}
else
{
AssertDimension (row_starts.size(), row_starts_plain_indices.size());
const unsigned int index = row_starts_plain_indices[row];
AssertIndexRange(index, plain_dof_indices.size()+1);
return plain_dof_indices.empty() ? 0 : &plain_dof_indices[0] + index;
}
}
inline
const unsigned int *
DoFInfo::end_indices_plain (const unsigned int row) const
{
return begin_indices_plain(row) +
dofs_per_cell[(cell_active_fe_index.size()==0)?
0:cell_active_fe_index[row]];
}
inline
unsigned int
DoFInfo::fe_index_from_degree (const unsigned int fe_degree) const
{
const unsigned int n_indices = fe_index_conversion.size();
for (unsigned int i=0; i<n_indices; ++i)
if (fe_index_conversion[i].first == fe_degree)
return i;
return n_indices;
}
inline
unsigned int
DoFInfo::fe_index_from_dofs_per_cell (const unsigned int dofs_per_cell) const
{
for (unsigned int i=0; i<fe_index_conversion.size(); ++i)
if (fe_index_conversion[i].second == dofs_per_cell)
return i;
return 0;
}
} // end of namespace MatrixFreeFunctions
} // end of namespace internal
#endif // ifndef DOXYGEN
DEAL_II_NAMESPACE_CLOSE
#endif
|