Reference documentation for deal.II version 9.0.0
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 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/geometry_info.h>
22 #include <deal.II/lac/matrix_block.h>
23 #include <deal.II/lac/block_vector.h>
24 #include <deal.II/meshworker/vector_selector.h>
25 
26 #include <functional>
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 class BlockIndices;
31 
175 namespace MeshWorker
176 {
207  template <typename number>
209  {
210  public:
217  unsigned int n_values () const;
218 
225  unsigned int n_vectors () const;
226 
230  unsigned int n_matrices () const;
231 
235  unsigned int n_quadrature_points() const;
236 
240  unsigned int n_quadrature_values() const;
241 
245  number &value(unsigned int i);
246 
250  number value(unsigned int i) const;
251 
255  BlockVector<number> &vector(unsigned int i);
256 
260  const BlockVector<number> &vector(unsigned int i) const;
261 
267  MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false);
268 
274  const MatrixBlock<FullMatrix<number> > &matrix(unsigned int i, bool external = false) const;
275 
282 
286  number &quadrature_value(unsigned int k, unsigned int i);
287 
291  number quadrature_value(unsigned int k, unsigned int i) const;
292 
298  void initialize_numbers(const unsigned int n);
299 
305  void initialize_vectors(const unsigned int n);
306 
314  void initialize_matrices(unsigned int n, bool both);
315 
323  template <typename MatrixType>
325  bool both);
326 
334  template <typename MatrixType>
336  bool both);
337 
342  void initialize_quadrature(unsigned int np, unsigned int nv);
343 
349  void reinit(const BlockIndices &local_sizes);
350 
351  template <class StreamType>
352  void print_debug(StreamType &os) const;
353 
357  std::size_t memory_consumption () const;
358 
359  private:
363  std::vector<number> J;
364 
369  std::vector<BlockVector<number> > R;
370 
375  std::vector<MatrixBlock<FullMatrix<number> > > M1;
376 
383  std::vector<MatrixBlock<FullMatrix<number> > > M2;
384 
389  };
390 
391 //----------------------------------------------------------------------//
392 
393  template <typename number>
394  inline void
396  {
397  J.resize(n);
398  }
399 
400 
401  template <typename number>
402  inline void
404  {
405  R.resize(n);
406  }
407 
408 
409  template <typename number>
410  template <typename MatrixType>
411  inline void
414  bool both)
415  {
416  M1.resize(matrices.size());
417  if (both)
418  M2.resize(matrices.size());
419  for (unsigned int i=0; i<matrices.size(); ++i)
420  {
421  const unsigned int row = matrices.block(i).row;
422  const unsigned int col = matrices.block(i).column;
423 
424  M1[i].row = row;
425  M1[i].column = col;
426  if (both)
427  {
428  M2[i].row = row;
429  M2[i].column = col;
430  }
431  }
432  }
433 
434 
435  template <typename number>
436  template <typename MatrixType>
437  inline void
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 MGLevelObject<MatrixBlock<MatrixType> > &o = matrices.block(i);
448  const unsigned int row = o[o.min_level()].row;
449  const unsigned int col = o[o.min_level()].column;
450 
451  M1[i].row = row;
452  M1[i].column = col;
453  if (both)
454  {
455  M2[i].row = row;
456  M2[i].column = col;
457  }
458  }
459  }
460 
461 
462  template <typename number>
463  inline void
465  const bool both)
466  {
467  M1.resize(n);
468  if (both)
469  M2.resize(n);
470  for (unsigned int i=0; i<n; ++i)
471  {
472  M1[i].row = 0;
473  M1[i].column = 0;
474  if (both)
475  {
476  M2[i].row = 0;
477  M2[i].column = 0;
478  }
479  }
480  }
481 
482 
483  template <typename number>
484  inline void
485  LocalResults<number>::initialize_quadrature(unsigned int np, unsigned int nv)
486  {
487  quadrature_data.reinit(np, nv);
488  }
489 
490 
491  template <typename number>
492  inline
493  unsigned int
495  {
496  return J.size();
497  }
498 
499 
500  template <typename number>
501  inline
502  unsigned int
504  {
505  return R.size();
506  }
507 
508 
509  template <typename number>
510  inline
511  unsigned int
513  {
514  return M1.size();
515  }
516 
517 
518  template <typename number>
519  inline
520  unsigned int
522  {
523  return quadrature_data.n_rows();
524  }
525 
526 
527  template <typename number>
528  inline
529  unsigned int
531  {
532  return quadrature_data.n_cols();
533  }
534 
535 
536  template <typename number>
537  inline
538  number &
540  {
541  AssertIndexRange(i,J.size());
542  return J[i];
543  }
544 
545 
546  template <typename number>
547  inline
550  {
551  AssertIndexRange(i,R.size());
552  return R[i];
553  }
554 
555 
556  template <typename number>
557  inline
559  LocalResults<number>::matrix(unsigned int i, bool external)
560  {
561  if (external)
562  {
563  AssertIndexRange(i,M2.size());
564  return M2[i];
565  }
566  AssertIndexRange(i,M1.size());
567  return M1[i];
568  }
569 
570 
571  template <typename number>
572  inline
573  number &
574  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i)
575  {
576  return quadrature_data(k,i);
577  }
578 
579 
580  template <typename number>
581  inline
584  {
585  return quadrature_data;
586  }
587 
588 
589  template <typename number>
590  inline
591  number
592  LocalResults<number>::value(unsigned int i) const
593  {
594  AssertIndexRange(i,J.size());
595  return J[i];
596  }
597 
598 
599  template <typename number>
600  inline
601  const BlockVector<number> &
602  LocalResults<number>::vector(unsigned int i) const
603  {
604  AssertIndexRange(i,R.size());
605  return R[i];
606  }
607 
608 
609  template <typename number>
610  inline
612  LocalResults<number>::matrix(unsigned int i, bool external) const
613  {
614  if (external)
615  {
616  AssertIndexRange(i,M2.size());
617  return M2[i];
618  }
619  AssertIndexRange(i,M1.size());
620  return M1[i];
621  }
622 
623 
624  template <typename number>
625  inline
626  number
627  LocalResults<number>::quadrature_value(unsigned int k, unsigned int i) const
628  {
629  return quadrature_data(k,i);
630  }
631 
632 
633  template <typename number>
634  template <class StreamType>
635  void
636  LocalResults<number>::print_debug(StreamType &os) const
637  {
638  os << "J: " << J.size() << std::endl;
639  os << "R: " << R.size() << std::endl;
640  for (unsigned int i=0; i<R.size(); ++i)
641  {
642  os << " " << R[i].n_blocks() << " -";
643  for (unsigned int j=0; j<R[i].n_blocks(); ++j)
644  os << ' ' << R[i].block(j).size();
645  os << std::endl;
646  }
647  os << "M: " << M1.size() << " face " << M2.size() << std::endl;
648  for (unsigned int i=0; i<M1.size(); ++i)
649  {
650  os << " " << M1[i].row << "," << M1[i].column
651  << " " << M1[i].matrix.m() << 'x' << M1[i].matrix.n();
652  if (i < M2.size())
653  os << " face " << M2[i].row << "," << M2[i].column
654  << " " << M2[i].matrix.m() << 'x' << M2[i].matrix.n();
655  os << std::endl;
656  }
657  }
658 
659 }
660 
661 
662 DEAL_II_NAMESPACE_CLOSE
663 
664 #endif
unsigned int n_matrices() const
const value_type & block(size_type i) const
Definition: matrix_block.h:862
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:1284
const value_type & block(size_type i) const
Definition: matrix_block.h:931
MatrixBlock< FullMatrix< number > > & matrix(unsigned int i, bool external=false)
void initialize_vectors(const unsigned int n)
size_type column
Definition: matrix_block.h:287
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
std::vector< number > J
std::vector< MatrixBlock< FullMatrix< number > > > M2
Table< 2, number > & quadrature_values()
unsigned int n_values() const
MatrixType matrix
Definition: matrix_block.h:292
unsigned int size() const
Definition: matrix_block.h:899
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:282
unsigned int n_quadrature_points() const
unsigned int size() const
Number of stored data objects.
Definition: any_data.h:199