Reference documentation for deal.II version 8.4.2
local_results.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2006 - 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__mesh_worker_local_results_h
18 #define dealii__mesh_worker_local_results_h
19 
20 #include <deal.II/base/config.h>
21 #include <deal.II/base/std_cxx11/function.h>
22 #include <deal.II/base/geometry_info.h>
23 #include <deal.II/lac/matrix_block.h>
24 #include <deal.II/lac/block_vector.h>
25 #include <deal.II/meshworker/vector_selector.h>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 class BlockIndices;
30 template<int,int> class DoFHandler;
31 
32 
176 namespace MeshWorker
177 {
208  template <typename number>
210  {
211  public:
218  unsigned int n_values () const;
219 
226  unsigned int n_vectors () const;
227 
231  unsigned int n_matrices () const;
232 
236  unsigned int n_quadrature_points() const;
237 
241  unsigned int n_quadrature_values() const;
242 
246  number &value(unsigned int i);
247 
251  number value(unsigned int i) const;
252 
256  BlockVector<number> &vector(unsigned int i);
257 
261  const BlockVector<number> &vector(unsigned int i) const;
262 
268  MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false);
269 
275  const MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false) const;
276 
283 
287  number &quadrature_value(unsigned int k, unsigned int i);
288 
292  number quadrature_value(unsigned int k, unsigned int i) const;
293 
299  void initialize_numbers(const unsigned int n);
300 
306  void initialize_vectors(const unsigned int n);
307 
315  void initialize_matrices(unsigned int n, bool both);
316 
324  template <typename MatrixType>
326  bool both);
327 
335  template <typename MatrixType>
337  bool both);
338 
343  void initialize_quadrature(unsigned int np, unsigned int nv);
344 
350  void reinit(const BlockIndices &local_sizes);
351 
352  template <class StreamType>
353  void print_debug(StreamType &os) const;
354 
358  std::size_t memory_consumption () const;
359 
360  private:
366  const unsigned int row,
367  const unsigned int col);
368 
372  std::vector<number> J;
373 
378  std::vector<BlockVector<number> > R;
379 
384  std::vector<MatrixBlock<FullMatrix<number> > > M1;
385 
392  std::vector<MatrixBlock<FullMatrix<number> > > M2;
393 
398  };
399 
400 //----------------------------------------------------------------------//
401 
402  template <typename number>
403  inline void
405  {
406  J.resize(n);
407  }
408 
409 
410  template <typename number>
411  inline void
413  {
414  R.resize(n);
415  }
416 
417 
418  template <typename number>
419  template <typename MatrixType>
420  inline void
423  bool both)
424  {
425  M1.resize(matrices.size());
426  if (both)
427  M2.resize(matrices.size());
428  for (unsigned int i=0; i<matrices.size(); ++i)
429  {
430  const unsigned int row = matrices.block(i).row;
431  const unsigned int col = matrices.block(i).column;
432 
433  M1[i].row = row;
434  M1[i].column = col;
435  if (both)
436  {
437  M2[i].row = row;
438  M2[i].column = col;
439  }
440  }
441  }
442 
443 
444  template <typename number>
445  template <typename MatrixType>
446  inline void
449  bool both)
450  {
451  M1.resize(matrices.size());
452  if (both)
453  M2.resize(matrices.size());
454  for (unsigned int i=0; i<matrices.size(); ++i)
455  {
456  const MGLevelObject<MatrixBlock<MatrixType> > &o = matrices.block(i);
457  const unsigned int row = o[o.min_level()].row;
458  const unsigned int col = o[o.min_level()].column;
459 
460  M1[i].row = row;
461  M1[i].column = col;
462  if (both)
463  {
464  M2[i].row = row;
465  M2[i].column = col;
466  }
467  }
468  }
469 
470 
471  template <typename number>
472  inline void
474  const bool both)
475  {
476  M1.resize(n);
477  if (both)
478  M2.resize(n);
479  for (unsigned int i=0; i<n; ++i)
480  {
481  M1[i].row = 0;
482  M1[i].column = 0;
483  if (both)
484  {
485  M2[i].row = 0;
486  M2[i].column = 0;
487  }
488  }
489  }
490 
491 
492  template <typename number>
493  inline void
494  LocalResults<number>::initialize_quadrature(unsigned int np, unsigned int nv)
495  {
496  quadrature_data.reinit(np, nv);
497  }
498 
499 
500  template <typename number>
501  inline
502  unsigned int
504  {
505  return J.size();
506  }
507 
508 
509  template <typename number>
510  inline
511  unsigned int
513  {
514  return R.size();
515  }
516 
517 
518  template <typename number>
519  inline
520  unsigned int
522  {
523  return M1.size();
524  }
525 
526 
527  template <typename number>
528  inline
529  unsigned int
531  {
532  return quadrature_data.n_rows();
533  }
534 
535 
536  template <typename number>
537  inline
538  unsigned int
540  {
541  return quadrature_data.n_cols();
542  }
543 
544 
545  template <typename number>
546  inline
547  number &
549  {
550  AssertIndexRange(i,J.size());
551  return J[i];
552  }
553 
554 
555  template <typename number>
556  inline
559  {
560  AssertIndexRange(i,R.size());
561  return R[i];
562  }
563 
564 
565  template <typename number>
566  inline
568  LocalResults<number>::matrix(unsigned int i, bool external)
569  {
570  if (external)
571  {
572  AssertIndexRange(i,M2.size());
573  return M2[i];
574  }
575  AssertIndexRange(i,M1.size());
576  return M1[i];
577  }
578 
579 
580  template <typename number>
581  inline
582  number &
583  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i)
584  {
585  return quadrature_data(k,i);
586  }
587 
588 
589  template <typename number>
590  inline
593  {
594  return quadrature_data;
595  }
596 
597 
598  template <typename number>
599  inline
600  number
601  LocalResults<number>::value(unsigned int i) const
602  {
603  AssertIndexRange(i,J.size());
604  return J[i];
605  }
606 
607 
608  template <typename number>
609  inline
610  const BlockVector<number> &
611  LocalResults<number>::vector(unsigned int i) const
612  {
613  AssertIndexRange(i,R.size());
614  return R[i];
615  }
616 
617 
618  template <typename number>
619  inline
621  LocalResults<number>::matrix(unsigned int i, bool external) const
622  {
623  if (external)
624  {
625  AssertIndexRange(i,M2.size());
626  return M2[i];
627  }
628  AssertIndexRange(i,M1.size());
629  return M1[i];
630  }
631 
632 
633  template <typename number>
634  inline
635  number
636  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i) const
637  {
638  return quadrature_data(k,i);
639  }
640 
641 
642  template <typename number>
643  template <class StreamType>
644  void
645  LocalResults<number>::print_debug(StreamType &os) const
646  {
647  os << "J: " << J.size() << std::endl;
648  os << "R: " << R.size() << std::endl;
649  for (unsigned int i=0; i<R.size(); ++i)
650  {
651  os << " " << R[i].n_blocks() << " -";
652  for (unsigned int j=0; j<R[i].n_blocks(); ++j)
653  os << ' ' << R[i].block(j).size();
654  os << std::endl;
655  }
656  os << "M: " << M1.size() << " face " << M2.size() << std::endl;
657  for (unsigned int i=0; i<M1.size(); ++i)
658  {
659  os << " " << M1[i].row << "," << M1[i].column
660  << " " << M1[i].matrix.m() << 'x' << M1[i].matrix.n();
661  if (i < M2.size())
662  os << " face " << M2[i].row << "," << M2[i].column
663  << " " << M2[i].matrix.m() << 'x' << M2[i].matrix.n();
664  os << std::endl;
665  }
666  }
667 
668 }
669 
670 
671 DEAL_II_NAMESPACE_CLOSE
672 
673 #endif
unsigned int n_matrices() const
const value_type & block(size_type i) const
Definition: matrix_block.h:861
unsigned int n_quadrature_values() const
std::vector< BlockVector< number > > R
void initialize_quadrature(unsigned int np, unsigned int nv)
#define AssertIndexRange(index, range)
Definition: exceptions.h:1081
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
Definition: block_indices.h:54
const value_type & block(size_type i) const
Definition: matrix_block.h:930
MatrixBlock< FullMatrix< number > > & matrix(unsigned int i, bool external=false)
void initialize_vectors(const unsigned int n)
size_type column
Definition: matrix_block.h:286
number & value(unsigned int i)
number & quadrature_value(unsigned int k, unsigned int i)
Table< 2, number > quadrature_data
unsigned int min_level() const
void initialize_matrices(unsigned int n, bool both)
unsigned int n_vectors() 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_values() const
void initialize_local(MatrixBlock< FullMatrix< number > > &M, const unsigned int row, const unsigned int col)
unsigned int size() const
Definition: matrix_block.h:898
unsigned int size() const
Number of stored data objects.
Definition: any_data.h:204
void reinit(const BlockIndices &local_sizes)
Definition: mesh_worker.cc:27
std::size_t memory_consumption() const
Definition: mesh_worker.cc:45
std::vector< MatrixBlock< FullMatrix< number > > > M1
BlockVector< number > & vector(unsigned int i)
void initialize_numbers(const unsigned int n)
size_type row
Definition: matrix_block.h:281
unsigned int n_quadrature_points() const