Reference documentation for deal.II version 9.1.0-pre
local_results.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 2018 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.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #ifndef dealii_mesh_worker_local_results_h
18 #define dealii_mesh_worker_local_results_h
19 
20 #include <deal.II/base/config.h>
21 
22 #include <deal.II/base/geometry_info.h>
23 
24 #include <deal.II/lac/block_vector.h>
25 #include <deal.II/lac/matrix_block.h>
26 
27 #include <deal.II/meshworker/vector_selector.h>
28 
29 #include <functional>
30 
31 DEAL_II_NAMESPACE_OPEN
32 
33 class BlockIndices;
34 
178 namespace MeshWorker
179 {
210  template <typename number>
212  {
213  public:
220  unsigned int
221  n_values() const;
222 
229  unsigned int
230  n_vectors() const;
231 
235  unsigned int
236  n_matrices() const;
237 
241  unsigned int
242  n_quadrature_points() const;
243 
247  unsigned int
248  n_quadrature_values() const;
249 
253  number &
254  value(unsigned int i);
255 
259  number
260  value(unsigned int i) const;
261 
266  vector(unsigned int i);
267 
271  const BlockVector<number> &
272  vector(unsigned int i) const;
273 
280  matrix(unsigned int i, bool external = false);
281 
288  matrix(unsigned int i, bool external = false) const;
289 
297 
301  number &
302  quadrature_value(unsigned int k, unsigned int i);
303 
307  number
308  quadrature_value(unsigned int k, unsigned int i) const;
309 
315  void
316  initialize_numbers(const unsigned int n);
317 
323  void
324  initialize_vectors(const unsigned int n);
325 
333  void
334  initialize_matrices(unsigned int n, bool both);
335 
343  template <typename MatrixType>
344  void
346  bool both);
347 
355  template <typename MatrixType>
356  void
358  bool both);
359 
364  void
365  initialize_quadrature(unsigned int np, unsigned int nv);
366 
372  void
373  reinit(const BlockIndices &local_sizes);
374 
375  template <class StreamType>
376  void
377  print_debug(StreamType &os) const;
378 
382  std::size_t
383  memory_consumption() const;
384 
385  private:
389  std::vector<number> J;
390 
395  std::vector<BlockVector<number>> R;
396 
401  std::vector<MatrixBlock<FullMatrix<number>>> M1;
402 
409  std::vector<MatrixBlock<FullMatrix<number>>> M2;
410 
415  };
416 
417  //----------------------------------------------------------------------//
418 
419  template <typename number>
420  inline void
422  {
423  J.resize(n);
424  }
425 
426 
427  template <typename number>
428  inline void
430  {
431  R.resize(n);
432  }
433 
434 
435  template <typename number>
436  template <typename MatrixType>
437  inline void
439  const MatrixBlockVector<MatrixType> &matrices,
440  bool both)
441  {
442  M1.resize(matrices.size());
443  if (both)
444  M2.resize(matrices.size());
445  for (unsigned int i = 0; i < matrices.size(); ++i)
446  {
447  const unsigned int row = matrices.block(i).row;
448  const unsigned int col = matrices.block(i).column;
449 
450  M1[i].row = row;
451  M1[i].column = col;
452  if (both)
453  {
454  M2[i].row = row;
455  M2[i].column = col;
456  }
457  }
458  }
459 
460 
461  template <typename number>
462  template <typename MatrixType>
463  inline void
465  const MGMatrixBlockVector<MatrixType> &matrices,
466  bool both)
467  {
468  M1.resize(matrices.size());
469  if (both)
470  M2.resize(matrices.size());
471  for (unsigned int i = 0; i < matrices.size(); ++i)
472  {
473  const MGLevelObject<MatrixBlock<MatrixType>> &o = matrices.block(i);
474  const unsigned int row = o[o.min_level()].row;
475  const unsigned int col = o[o.min_level()].column;
476 
477  M1[i].row = row;
478  M1[i].column = col;
479  if (both)
480  {
481  M2[i].row = row;
482  M2[i].column = col;
483  }
484  }
485  }
486 
487 
488  template <typename number>
489  inline void
491  const bool both)
492  {
493  M1.resize(n);
494  if (both)
495  M2.resize(n);
496  for (unsigned int i = 0; i < n; ++i)
497  {
498  M1[i].row = 0;
499  M1[i].column = 0;
500  if (both)
501  {
502  M2[i].row = 0;
503  M2[i].column = 0;
504  }
505  }
506  }
507 
508 
509  template <typename number>
510  inline void
511  LocalResults<number>::initialize_quadrature(unsigned int np, unsigned int nv)
512  {
513  quadrature_data.reinit(np, nv);
514  }
515 
516 
517  template <typename number>
518  inline unsigned int
520  {
521  return J.size();
522  }
523 
524 
525  template <typename number>
526  inline unsigned int
528  {
529  return R.size();
530  }
531 
532 
533  template <typename number>
534  inline unsigned int
536  {
537  return M1.size();
538  }
539 
540 
541  template <typename number>
542  inline unsigned int
544  {
545  return quadrature_data.n_rows();
546  }
547 
548 
549  template <typename number>
550  inline unsigned int
552  {
553  return quadrature_data.n_cols();
554  }
555 
556 
557  template <typename number>
558  inline number &
560  {
561  AssertIndexRange(i, J.size());
562  return J[i];
563  }
564 
565 
566  template <typename number>
567  inline BlockVector<number> &
569  {
570  AssertIndexRange(i, R.size());
571  return R[i];
572  }
573 
574 
575  template <typename number>
577  LocalResults<number>::matrix(unsigned int i, bool external)
578  {
579  if (external)
580  {
581  AssertIndexRange(i, M2.size());
582  return M2[i];
583  }
584  AssertIndexRange(i, M1.size());
585  return M1[i];
586  }
587 
588 
589  template <typename number>
590  inline number &
591  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i)
592  {
593  return quadrature_data(k, i);
594  }
595 
596 
597  template <typename number>
598  inline Table<2, number> &
600  {
601  return quadrature_data;
602  }
603 
604 
605  template <typename number>
606  inline number
607  LocalResults<number>::value(unsigned int i) const
608  {
609  AssertIndexRange(i, J.size());
610  return J[i];
611  }
612 
613 
614  template <typename number>
615  inline const BlockVector<number> &
616  LocalResults<number>::vector(unsigned int i) const
617  {
618  AssertIndexRange(i, R.size());
619  return R[i];
620  }
621 
622 
623  template <typename number>
624  inline const MatrixBlock<FullMatrix<number>> &
625  LocalResults<number>::matrix(unsigned int i, bool external) const
626  {
627  if (external)
628  {
629  AssertIndexRange(i, M2.size());
630  return M2[i];
631  }
632  AssertIndexRange(i, M1.size());
633  return M1[i];
634  }
635 
636 
637  template <typename number>
638  inline number
639  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i) const
640  {
641  return quadrature_data(k, i);
642  }
643 
644 
645  template <typename number>
646  template <class StreamType>
647  void
648  LocalResults<number>::print_debug(StreamType &os) const
649  {
650  os << "J: " << J.size() << std::endl;
651  os << "R: " << R.size() << std::endl;
652  for (unsigned int i = 0; i < R.size(); ++i)
653  {
654  os << " " << R[i].n_blocks() << " -";
655  for (unsigned int j = 0; j < R[i].n_blocks(); ++j)
656  os << ' ' << R[i].block(j).size();
657  os << std::endl;
658  }
659  os << "M: " << M1.size() << " face " << M2.size() << std::endl;
660  for (unsigned int i = 0; i < M1.size(); ++i)
661  {
662  os << " " << M1[i].row << "," << M1[i].column << " "
663  << M1[i].matrix.m() << 'x' << M1[i].matrix.n();
664  if (i < M2.size())
665  os << " face " << M2[i].row << "," << M2[i].column << " "
666  << M2[i].matrix.m() << 'x' << M2[i].matrix.n();
667  os << std::endl;
668  }
669  }
670 
671 } // namespace MeshWorker
672 
673 
674 DEAL_II_NAMESPACE_CLOSE
675 
676 #endif
const value_type & block(size_type i) const
Definition: matrix_block.h:957
std::vector< BlockVector< number > > R
void initialize_quadrature(unsigned int np, unsigned int nv)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1407
MatrixBlock< FullMatrix< number > > & matrix(unsigned int i, bool external=false)
std::size_t memory_consumption() const
Definition: mesh_worker.cc:46
void initialize_vectors(const unsigned int n)
size_type column
Definition: matrix_block.h:303
number & value(unsigned int i)
number & quadrature_value(unsigned int k, unsigned int i)
Table< 2, number > quadrature_data
void initialize_matrices(unsigned int n, bool both)
unsigned int n_matrices() const
unsigned int n_quadrature_values() const
void reinit(const TableIndices< N > &new_size, const bool omit_default_initialization=false)
std::vector< number > J
std::vector< MatrixBlock< FullMatrix< number > > > M2
Table< 2, number > & quadrature_values()
unsigned int n_vectors() const
unsigned int n_quadrature_points() const
const value_type & block(size_type i) const
Definition: matrix_block.h:890
void reinit(const BlockIndices &local_sizes)
Definition: mesh_worker.cc:28
unsigned int size() const
Definition: matrix_block.h:925
unsigned int min_level() const
std::vector< MatrixBlock< FullMatrix< number > > > M1
BlockVector< number > & vector(unsigned int i)
unsigned int n_values() const
void initialize_numbers(const unsigned int n)
unsigned int size() const
Number of stored data objects.
Definition: any_data.h:223
size_type row
Definition: matrix_block.h:298