Reference documentation for deal.II version 8.4.2
dof_info.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2011 - 2015 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE at
12 // the top level of the deal.II distribution.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #ifndef dealii__matrix_free_dof_info_h
18 #define dealii__matrix_free_dof_info_h
19 
20 
21 #include <deal.II/base/exceptions.h>
22 #include <deal.II/base/vectorization.h>
23 #include <deal.II/base/partitioner.h>
24 #include <deal.II/lac/constraint_matrix.h>
25 #include <deal.II/lac/dynamic_sparsity_pattern.h>
26 #include <deal.II/dofs/dof_handler.h>
27 #include <deal.II/matrix_free/helper_functions.h>
28 
29 #include <deal.II/base/std_cxx11/array.h>
30 
31 #include <memory>
32 
33 
34 DEAL_II_NAMESPACE_OPEN
35 
36 namespace internal
37 {
38  namespace MatrixFreeFunctions
39  {
58  struct DoFInfo
59  {
63  DoFInfo ();
64 
68  DoFInfo (const DoFInfo &dof_info);
69 
73  void clear ();
74 
75 
79  const unsigned int *begin_indices (const unsigned int row) const;
80 
85  const unsigned int *end_indices (const unsigned int row) const;
86 
90  unsigned int row_length_indices (const unsigned int row) const;
91 
96  const std::pair<unsigned short,unsigned short> *
97  begin_indicators (const unsigned int row) const;
98 
103  const std::pair<unsigned short,unsigned short> *
104  end_indicators (const unsigned int row) const;
105 
110  unsigned int row_length_indicators (const unsigned int row) const;
111 
116  const unsigned int *begin_indices_plain (const unsigned int row) const;
117 
122  const unsigned int *end_indices_plain (const unsigned int row) const;
123 
130  unsigned int fe_index_from_degree (const unsigned int fe_degree) const;
131 
132 
139  unsigned int
140  fe_index_from_dofs_per_cell (const unsigned int dofs_per_cell) const;
141 
150  void read_dof_indices (const std::vector<types::global_dof_index> &local_indices,
151  const std::vector<unsigned int> &lexicographic_inv,
152  const ConstraintMatrix &constraints,
153  const unsigned int cell_number,
154  ConstraintValues<double> &constraint_values,
155  bool &cell_at_boundary);
156 
164  void assign_ghosts(const std::vector<unsigned int> &boundary_cells);
165 
172  void compute_renumber_serial (const std::vector<unsigned int> &boundary_cells,
173  const SizeInfo &size_info,
174  std::vector<unsigned int> &renumbering);
175 
182  void compute_renumber_hp_serial (SizeInfo &size_info,
183  std::vector<unsigned int> &renumbering,
184  std::vector<unsigned int> &irregular_cells);
185 
191  void compute_renumber_parallel (const std::vector<unsigned int> &boundary_cells,
192  SizeInfo &size_info,
193  std::vector<unsigned int> &renumbering);
194 
201  void reorder_cells (const SizeInfo &size_info,
202  const std::vector<unsigned int> &renumbering,
203  const std::vector<unsigned int> &constraint_pool_row_index,
204  const std::vector<unsigned int> &irregular_cells,
205  const unsigned int vectorization_length);
206 
213  void guess_block_size (const SizeInfo &size_info,
214  TaskInfo &task_info);
215 
229  void
230  make_thread_graph_partition_color (SizeInfo &size_info,
231  TaskInfo &task_info,
232  std::vector<unsigned int> &renumbering,
233  std::vector<unsigned int> &irregular_cells,
234  const bool hp_bool);
235 
250  void
251  make_thread_graph_partition_partition (SizeInfo &size_info,
252  TaskInfo &task_info,
253  std::vector<unsigned int> &renumbering,
254  std::vector<unsigned int> &irregular_cells,
255  const bool hp_bool);
256 
263  void
264  make_connectivity_graph (const SizeInfo &size_info,
265  const TaskInfo &task_info,
266  const std::vector<unsigned int> &renumbering,
267  const std::vector<unsigned int> &irregular_cells,
268  const bool do_blocking,
269  DynamicSparsityPattern &connectivity) const;
270 
274  void renumber_dofs (std::vector<types::global_dof_index> &renumbering);
275 
279  std::size_t memory_consumption() const;
280 
285  template <typename StreamType>
286  void print_memory_consumption(StreamType &out,
287  const SizeInfo &size_info) const;
288 
293  template <typename Number>
294  void print (const std::vector<Number> &constraint_pool_data,
295  const std::vector<unsigned int> &constraint_pool_row_index,
296  std::ostream &out) const;
297 
308  std::vector<std_cxx11::array<unsigned int, 3> > row_starts;
309 
325  std::vector<unsigned int> dof_indices;
326 
336  std::vector<std::pair<unsigned short,unsigned short> > constraint_indicator;
337 
344  std_cxx11::shared_ptr<const Utilities::MPI::Partitioner> vector_partitioner;
345 
350  std::vector<unsigned int> constrained_dofs;
351 
356  std::vector<unsigned int> row_starts_plain_indices;
357 
366  std::vector<unsigned int> plain_dof_indices;
367 
373  unsigned int dimension;
374 
379  unsigned int n_components;
380 
384  std::vector<unsigned int> dofs_per_cell;
385 
389  std::vector<unsigned int> dofs_per_face;
390 
394  bool store_plain_indices;
395 
399  std::vector<unsigned int> cell_active_fe_index;
400 
405  unsigned int max_fe_index;
406 
412  std::vector<std::pair<unsigned int,unsigned int> > fe_index_conversion;
413 
419  std::vector<types::global_dof_index> ghost_dofs;
420  };
421 
422 
423  /*----------------------- Inline functions ----------------------------------*/
424 
425 #ifndef DOXYGEN
426 
427  inline
428  const unsigned int *
429  DoFInfo::begin_indices (const unsigned int row) const
430  {
431  AssertIndexRange (row, row_starts.size()-1);
432  const unsigned int index = row_starts[row][0];
433  AssertIndexRange(index, dof_indices.size()+1);
434  return dof_indices.empty() ? 0 : &dof_indices[0] + index;
435  }
436 
437 
438 
439  inline
440  const unsigned int *
441  DoFInfo::end_indices (const unsigned int row) const
442  {
443  AssertIndexRange (row, row_starts.size()-1);
444  const unsigned int index = row_starts[row+1][0];
445  AssertIndexRange(index, dof_indices.size()+1);
446  return dof_indices.empty() ? 0 : &dof_indices[0] + index;
447  }
448 
449 
450 
451  inline
452  unsigned int
453  DoFInfo::row_length_indices (const unsigned int row) const
454  {
455  AssertIndexRange (row, row_starts.size()-1);
456  return (row_starts[row+1][0] - row_starts[row][0]);
457  }
458 
459 
460 
461  inline
462  const std::pair<unsigned short,unsigned short> *
463  DoFInfo::begin_indicators (const unsigned int row) const
464  {
465  AssertIndexRange (row, row_starts.size()-1);
466  const unsigned int index = row_starts[row][1];
467  AssertIndexRange (index, constraint_indicator.size()+1);
468  return constraint_indicator.empty() ? 0 : &constraint_indicator[0] + index;
469  }
470 
471 
472 
473  inline
474  const std::pair<unsigned short,unsigned short> *
475  DoFInfo::end_indicators (const unsigned int row) const
476  {
477  AssertIndexRange (row, row_starts.size()-1);
478  const unsigned int index = row_starts[row+1][1];
479  AssertIndexRange (index, constraint_indicator.size()+1);
480  return constraint_indicator.empty() ? 0 : &constraint_indicator[0] + index;
481  }
482 
483 
484 
485  inline
486  unsigned int
487  DoFInfo::row_length_indicators (const unsigned int row) const
488  {
489  AssertIndexRange (row, row_starts.size()-1);
490  return (row_starts[row+1][1] - row_starts[row][1]);
491  }
492 
493 
494 
495  inline
496  const unsigned int *
497  DoFInfo::begin_indices_plain (const unsigned int row) const
498  {
499  // if we have no constraints, should take the data from dof_indices
500  if (row_length_indicators(row) == 0)
501  {
502  Assert (row_starts_plain_indices[row]==numbers::invalid_unsigned_int,
503  ExcInternalError());
504  return begin_indices(row);
505  }
506  else
507  {
508  AssertDimension (row_starts.size(), row_starts_plain_indices.size());
509  const unsigned int index = row_starts_plain_indices[row];
510  AssertIndexRange(index, plain_dof_indices.size()+1);
511  return plain_dof_indices.empty() ? 0 : &plain_dof_indices[0] + index;
512  }
513  }
514 
515 
516 
517  inline
518  const unsigned int *
519  DoFInfo::end_indices_plain (const unsigned int row) const
520  {
521  return begin_indices_plain(row) +
522  dofs_per_cell[(cell_active_fe_index.size()==0)?
523  0:cell_active_fe_index[row]];
524  }
525 
526 
527 
528  inline
529  unsigned int
530  DoFInfo::fe_index_from_degree (const unsigned int fe_degree) const
531  {
532  const unsigned int n_indices = fe_index_conversion.size();
533  for (unsigned int i=0; i<n_indices; ++i)
534  if (fe_index_conversion[i].first == fe_degree)
535  return i;
536  return n_indices;
537  }
538 
539 
540 
541  inline
542  unsigned int
543  DoFInfo::fe_index_from_dofs_per_cell (const unsigned int dofs_per_cell) const
544  {
545  for (unsigned int i=0; i<fe_index_conversion.size(); ++i)
546  if (fe_index_conversion[i].second == dofs_per_cell)
547  return i;
548  return 0;
549  }
550 
551  } // end of namespace MatrixFreeFunctions
552 } // end of namespace internal
553 
554 #endif // ifndef DOXYGEN
555 
556 DEAL_II_NAMESPACE_CLOSE
557 
558 #endif
static const unsigned int invalid_unsigned_int
Definition: types.h:164
#define AssertDimension(dim1, dim2)
Definition: exceptions.h:1052
#define AssertIndexRange(index, range)
Definition: exceptions.h:1081
#define Assert(cond, exc)
Definition: exceptions.h:294
std_cxx11::enable_if< std_cxx11::is_fundamental< T >::value, std::size_t >::type memory_consumption(const T &t)