Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
local_results.h
1 // ---------------------------------------------------------------------
2 // @f$Id: local_results.h 30040 2013-07-18 17:06:48Z maier @f$
3 //
4 // Copyright (C) 2006 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 
18 #ifndef __deal2__mesh_worker_local_results_h
19 #define __deal2__mesh_worker_local_results_h
20 
21 #include <deal.II/base/config.h>
22 #include <deal.II/base/std_cxx1x/function.h>
23 #include <deal.II/base/geometry_info.h>
24 #include <deal.II/lac/matrix_block.h>
25 #include <deal.II/lac/block_vector.h>
26 #include <deal.II/meshworker/vector_selector.h>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 class BlockIndices;
31 template<int,int> class DoFHandler;
32 template<int,int> class MGDoFHandler;
33 
182 namespace MeshWorker
183 {
216  template <typename number>
218  {
219  public:
227  unsigned int n_values () const;
228 
237  unsigned int n_vectors () const;
238 
242  unsigned int n_matrices () const;
243 
248  unsigned int n_quadrature_points() const;
249 
255  unsigned int n_quadrature_values() const;
256 
261  number &value(unsigned int i);
262 
267  number value(unsigned int i) const;
268 
272  BlockVector<number> &vector(unsigned int i);
273 
277  const BlockVector<number> &vector(unsigned int i) const;
278 
288  MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false);
289 
299  const MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false) const;
300 
311 
315  number &quadrature_value(unsigned int k, unsigned int i);
316 
320  number quadrature_value(unsigned int k, unsigned int i) const;
321 
327  void initialize_numbers(const unsigned int n);
328 
334  void initialize_vectors(const unsigned int n);
335 
343  void initialize_matrices(unsigned int n, bool both);
344 
352  template <class MATRIX>
353  void initialize_matrices(const MatrixBlockVector<MATRIX> &matrices,
354  bool both);
355 
370  template <class MATRIX>
372  bool both);
373 
378  void initialize_quadrature(unsigned int np, unsigned int nv);
379 
386  void reinit(const BlockIndices &local_sizes);
387 
388  template <class STREAM>
389  void print_debug(STREAM &os) const;
390 
394  std::size_t memory_consumption () const;
395 
396  private:
402  const unsigned int row,
403  const unsigned int col);
404 
408  std::vector<number> J;
409 
414  std::vector<BlockVector<number> > R;
415 
420  std::vector<MatrixBlock<FullMatrix<number> > > M1;
421 
428  std::vector<MatrixBlock<FullMatrix<number> > > M2;
429 
434  };
435 
436 //----------------------------------------------------------------------//
437 
438  template <typename number>
439  inline void
441  {
442  J.resize(n);
443  }
444 
445 
446  template <typename number>
447  inline void
449  {
450  R.resize(n);
451  }
452 
453 
454  template <typename number>
455  template <class MATRIX>
456  inline void
458  const MatrixBlockVector<MATRIX> &matrices,
459  bool both)
460  {
461  M1.resize(matrices.size());
462  if (both)
463  M2.resize(matrices.size());
464  for (unsigned int i=0; i<matrices.size(); ++i)
465  {
466  const unsigned int row = matrices.block(i).row;
467  const unsigned int col = matrices.block(i).column;
468 
469  M1[i].row = row;
470  M1[i].column = col;
471  if (both)
472  {
473  M2[i].row = row;
474  M2[i].column = col;
475  }
476  }
477  }
478 
479 
480  template <typename number>
481  template <class MATRIX>
482  inline void
484  const MGMatrixBlockVector<MATRIX> &matrices,
485  bool both)
486  {
487  M1.resize(matrices.size());
488  if (both)
489  M2.resize(matrices.size());
490  for (unsigned int i=0; i<matrices.size(); ++i)
491  {
492  const MGLevelObject<MatrixBlock<MATRIX> > &o = matrices.block(i);
493  const unsigned int row = o[o.min_level()].row;
494  const unsigned int col = o[o.min_level()].column;
495 
496  M1[i].row = row;
497  M1[i].column = col;
498  if (both)
499  {
500  M2[i].row = row;
501  M2[i].column = col;
502  }
503  }
504  }
505 
506 
507  template <typename number>
508  inline void
510  const bool both)
511  {
512  M1.resize(n);
513  if (both)
514  M2.resize(n);
515  for (unsigned int i=0; i<n; ++i)
516  {
517  M1[i].row = 0;
518  M1[i].column = 0;
519  if (both)
520  {
521  M2[i].row = 0;
522  M2[i].column = 0;
523  }
524  }
525  }
526 
527 
528  template <typename number>
529  inline void
530  LocalResults<number>::initialize_quadrature(unsigned int np, unsigned int nv)
531  {
532  quadrature_data.reinit(np, nv);
533  }
534 
535 
536  template <typename number>
537  inline
538  unsigned int
540  {
541  return J.size();
542  }
543 
544 
545  template <typename number>
546  inline
547  unsigned int
549  {
550  return R.size();
551  }
552 
553 
554  template <typename number>
555  inline
556  unsigned int
558  {
559  return M1.size();
560  }
561 
562 
563  template <typename number>
564  inline
565  unsigned int
567  {
568  return quadrature_data.n_rows();
569  }
570 
571 
572  template <typename number>
573  inline
574  unsigned int
576  {
577  return quadrature_data.n_cols();
578  }
579 
580 
581  template <typename number>
582  inline
583  number &
585  {
586  AssertIndexRange(i,J.size());
587  return J[i];
588  }
589 
590 
591  template <typename number>
592  inline
595  {
596  AssertIndexRange(i,R.size());
597  return R[i];
598  }
599 
600 
601  template <typename number>
602  inline
604  LocalResults<number>::matrix(unsigned int i, bool external)
605  {
606  if (external)
607  {
608  AssertIndexRange(i,M2.size());
609  return M2[i];
610  }
611  AssertIndexRange(i,M1.size());
612  return M1[i];
613  }
614 
615 
616  template <typename number>
617  inline
618  number &
619  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i)
620  {
621  return quadrature_data(k,i);
622  }
623 
624 
625  template <typename number>
626  inline
629  {
630  return quadrature_data;
631  }
632 
633 
634  template <typename number>
635  inline
636  number
637  LocalResults<number>::value(unsigned int i) const
638  {
639  AssertIndexRange(i,J.size());
640  return J[i];
641  }
642 
643 
644  template <typename number>
645  inline
646  const BlockVector<number> &
647  LocalResults<number>::vector(unsigned int i) const
648  {
649  AssertIndexRange(i,R.size());
650  return R[i];
651  }
652 
653 
654  template <typename number>
655  inline
657  LocalResults<number>::matrix(unsigned int i, bool external) const
658  {
659  if (external)
660  {
661  AssertIndexRange(i,M2.size());
662  return M2[i];
663  }
664  AssertIndexRange(i,M1.size());
665  return M1[i];
666  }
667 
668 
669  template <typename number>
670  inline
671  number
672  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i) const
673  {
674  return quadrature_data(k,i);
675  }
676 
677 
678  template <typename number>
679  template <class STREAM>
680  void
681  LocalResults<number>::print_debug(STREAM &os) const
682  {
683  os << "J: " << J.size() << std::endl;
684  os << "R: " << R.size() << std::endl;
685  for (unsigned int i=0; i<R.size(); ++i)
686  {
687  os << " " << R[i].n_blocks() << " -";
688  for (unsigned int j=0; j<R[i].n_blocks(); ++j)
689  os << ' ' << R[i].block(j).size();
690  os << std::endl;
691  }
692  os << "M: " << M1.size() << " face " << M2.size() << std::endl;
693  for (unsigned int i=0; i<M1.size(); ++i)
694  {
695  os << " " << M1[i].row << "," << M1[i].column
696  << " " << M1[i].matrix.m() << 'x' << M1[i].matrix.n();
697  if (i < M2.size())
698  os << " face " << M2[i].row << "," << M2[i].column
699  << " " << M2[i].matrix.m() << 'x' << M2[i].matrix.n();
700  os << std::endl;
701  }
702  }
703 
704 }
705 
706 
707 DEAL_II_NAMESPACE_CLOSE
708 
709 #endif
unsigned int size() const
std::vector< BlockVector< number > > R
void initialize_quadrature(unsigned int np, unsigned int nv)
#define AssertIndexRange(index, range)
Definition: exceptions.h:888
Auxiliary class aiding in the handling of block structures like in BlockVector or FESystem...
Definition: block_indices.h:55
const value_type & block(size_type i) const
Definition: matrix_block.h:981
MatrixBlock< FullMatrix< number > > & matrix(unsigned int i, bool external=false)
std::size_t memory_consumption() const
void initialize_vectors(const unsigned int n)
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
unsigned int size() const
Number of stored data objects.
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
void initialize_local(MatrixBlock< FullMatrix< number > > &M, const unsigned int row, const unsigned int col)
size_type row
Definition: matrix_block.h:359
void reinit(const BlockIndices &local_sizes)
const value_type & block(size_type i) const
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)
MATRIX matrix
Definition: matrix_block.h:371
size_type column
Definition: matrix_block.h:366