Reference documentation for deal.II version Git e8f99f7e31 2020-07-08 12:50:43 +0200
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
matrix_tools.h
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2020 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 #ifndef dealii_matrix_tools_h
17 #define dealii_matrix_tools_h
18 
19 
20 #include <deal.II/base/config.h>
21 
23 #include <deal.II/base/function.h>
24 
26 
27 #include <map>
28 
29 #ifdef DEAL_II_WITH_PETSC
30 # include <petscsys.h>
31 #endif
32 
34 
35 
36 // forward declarations
37 #ifndef DOXYGEN
38 template <int dim>
39 class Quadrature;
40 
41 
42 template <typename number>
43 class Vector;
44 template <typename number>
45 class FullMatrix;
46 template <typename number>
47 class SparseMatrix;
48 
49 template <typename number>
50 class BlockSparseMatrix;
51 template <typename Number>
52 class BlockVector;
53 
54 template <int dim, int spacedim>
55 class Mapping;
56 template <int dim, int spacedim>
57 class DoFHandler;
58 
59 namespace hp
60 {
61  template <int>
62  class QCollection;
63  template <int, int>
64  class MappingCollection;
65  template <int, int>
66  class DoFHandler;
67 } // namespace hp
68 
69 
70 # ifdef DEAL_II_WITH_PETSC
71 namespace PETScWrappers
72 {
73  class MatrixBase;
74  class VectorBase;
75  namespace MPI
76  {
77  class BlockSparseMatrix;
78  class BlockVector;
79  } // namespace MPI
80 } // namespace PETScWrappers
81 # endif
82 
83 # ifdef DEAL_II_WITH_TRILINOS
84 namespace TrilinosWrappers
85 {
86  class SparseMatrix;
87  class BlockSparseMatrix;
88  namespace MPI
89  {
90  class Vector;
91  class BlockVector;
92  } // namespace MPI
93 } // namespace TrilinosWrappers
94 # endif
95 #endif
96 
97 
230 namespace MatrixCreator
231 {
251  template <int dim, int spacedim, typename number>
252  void
254  const Mapping<dim, spacedim> & mapping,
255  const DoFHandler<dim, spacedim> & dof,
256  const Quadrature<dim> & q,
258  const Function<spacedim, number> *const a = nullptr,
260 
265  template <int dim, int spacedim, typename number>
266  void
268  const DoFHandler<dim, spacedim> & dof,
269  const Quadrature<dim> & q,
270  SparseMatrix<number> & matrix,
271  const Function<spacedim, number> *const a = nullptr,
273 
293  template <int dim, int spacedim, typename number>
294  void
296  const Mapping<dim, spacedim> & mapping,
297  const DoFHandler<dim, spacedim> & dof,
298  const Quadrature<dim> & q,
299  SparseMatrix<number> & matrix,
300  const Function<spacedim, number> & rhs,
301  Vector<number> & rhs_vector,
302  const Function<spacedim, number> *const a = nullptr,
304 
309  template <int dim, int spacedim, typename number>
310  void
312  const DoFHandler<dim, spacedim> & dof,
313  const Quadrature<dim> & q,
314  SparseMatrix<number> & matrix,
315  const Function<spacedim, number> & rhs,
316  Vector<number> & rhs_vector,
317  const Function<spacedim, number> *const a = nullptr,
319 
323  template <int dim, int spacedim, typename number>
324  void
327  const DoFHandler<dim, spacedim> & dof,
328  const hp::QCollection<dim> & q,
329  SparseMatrix<number> & matrix,
330  const Function<spacedim, number> *const a = nullptr,
332 
336  template <int dim, int spacedim, typename number>
337  void
339  const DoFHandler<dim, spacedim> & dof,
340  const hp::QCollection<dim> & q,
341  SparseMatrix<number> & matrix,
342  const Function<spacedim, number> *const a = nullptr,
344 
348  template <int dim, int spacedim, typename number>
349  void
352  const DoFHandler<dim, spacedim> & dof,
353  const hp::QCollection<dim> & q,
354  SparseMatrix<number> & matrix,
355  const Function<spacedim, number> & rhs,
356  Vector<number> & rhs_vector,
357  const Function<spacedim, number> *const a = nullptr,
359 
363  template <int dim, int spacedim, typename number>
364  void
366  const DoFHandler<dim, spacedim> & dof,
367  const hp::QCollection<dim> & q,
368  SparseMatrix<number> & matrix,
369  const Function<spacedim, number> & rhs,
370  Vector<number> & rhs_vector,
371  const Function<spacedim, number> *const a = nullptr,
373 
374 
400  template <int dim, int spacedim, typename number>
401  void
403  const Mapping<dim, spacedim> & mapping,
404  const DoFHandler<dim, spacedim> &dof,
405  const Quadrature<dim - 1> & q,
406  SparseMatrix<number> & matrix,
407  const std::map<types::boundary_id, const Function<spacedim, number> *>
408  & boundary_functions,
409  Vector<number> & rhs_vector,
410  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
411  const Function<spacedim, number> *const weight = 0,
412  std::vector<unsigned int> component_mapping = {});
413 
414 
419  template <int dim, int spacedim, typename number>
420  void
422  const DoFHandler<dim, spacedim> &dof,
423  const Quadrature<dim - 1> & q,
424  SparseMatrix<number> & matrix,
425  const std::map<types::boundary_id, const Function<spacedim, number> *>
426  & boundary_functions,
427  Vector<number> & rhs_vector,
428  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
429  const Function<spacedim, number> *const a = nullptr,
430  std::vector<unsigned int> component_mapping = {});
431 
435  template <int dim, int spacedim, typename number>
436  void
439  const DoFHandler<dim, spacedim> & dof,
440  const hp::QCollection<dim - 1> & q,
441  SparseMatrix<number> & matrix,
442  const std::map<types::boundary_id, const Function<spacedim, number> *>
443  & boundary_functions,
444  Vector<number> & rhs_vector,
445  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
446  const Function<spacedim, number> *const a = nullptr,
447  std::vector<unsigned int> component_mapping = {});
448 
452  template <int dim, int spacedim, typename number>
453  void
455  const DoFHandler<dim, spacedim> &dof,
456  const hp::QCollection<dim - 1> & q,
457  SparseMatrix<number> & matrix,
458  const std::map<types::boundary_id, const Function<spacedim, number> *>
459  & boundary_functions,
460  Vector<number> & rhs_vector,
461  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
462  const Function<spacedim, number> *const a = nullptr,
463  std::vector<unsigned int> component_mapping = {});
464 
484  template <int dim, int spacedim>
485  void
487  const Mapping<dim, spacedim> & mapping,
488  const DoFHandler<dim, spacedim> &dof,
489  const Quadrature<dim> & q,
490  SparseMatrix<double> & matrix,
491  const Function<spacedim> *const a = nullptr,
493 
498  template <int dim, int spacedim>
499  void
501  const DoFHandler<dim, spacedim> &dof,
502  const Quadrature<dim> & q,
503  SparseMatrix<double> & matrix,
504  const Function<spacedim> *const a = nullptr,
506 
525  template <int dim, int spacedim>
526  void
528  const Mapping<dim, spacedim> & mapping,
529  const DoFHandler<dim, spacedim> &dof,
530  const Quadrature<dim> & q,
531  SparseMatrix<double> & matrix,
532  const Function<spacedim> & rhs,
533  Vector<double> & rhs_vector,
534  const Function<spacedim> *const a = nullptr,
536 
541  template <int dim, int spacedim>
542  void
544  const DoFHandler<dim, spacedim> &dof,
545  const Quadrature<dim> & q,
546  SparseMatrix<double> & matrix,
547  const Function<spacedim> & rhs,
548  Vector<double> & rhs_vector,
549  const Function<spacedim> *const a = nullptr,
551 
556  template <int dim, int spacedim>
557  void
560  const DoFHandler<dim, spacedim> & dof,
561  const hp::QCollection<dim> & q,
562  SparseMatrix<double> & matrix,
563  const Function<spacedim> *const a = nullptr,
565 
570  template <int dim, int spacedim>
571  void
573  const DoFHandler<dim, spacedim> &dof,
574  const hp::QCollection<dim> & q,
575  SparseMatrix<double> & matrix,
576  const Function<spacedim> *const a = nullptr,
578 
583  template <int dim, int spacedim>
584  void
587  const DoFHandler<dim, spacedim> & dof,
588  const hp::QCollection<dim> & q,
589  SparseMatrix<double> & matrix,
590  const Function<spacedim> & rhs,
591  Vector<double> & rhs_vector,
592  const Function<spacedim> *const a = nullptr,
594 
599  template <int dim, int spacedim>
600  void
602  const DoFHandler<dim, spacedim> &dof,
603  const hp::QCollection<dim> & q,
604  SparseMatrix<double> & matrix,
605  const Function<spacedim> & rhs,
606  Vector<double> & rhs_vector,
607  const Function<spacedim> *const a = nullptr,
609 
614  "You are providing either a right hand side function or a "
615  "coefficient with a number of vector components that is "
616  "inconsistent with the rest of the arguments. If you do "
617  "provide a coefficient or right hand side function, then "
618  "it either needs to have as many components as the finite "
619  "element in use, or only a single vector component. In "
620  "the latter case, the same value will be taken for "
621  "each vector component of the finite element.");
622 } // namespace MatrixCreator
623 
624 
625 
817 namespace MatrixTools
818 {
824  using namespace MatrixCreator;
825 
830  template <typename number>
831  void
833  const std::map<types::global_dof_index, number> &boundary_values,
835  Vector<number> & solution,
836  Vector<number> & right_hand_side,
837  const bool eliminate_columns = true);
838 
844  template <typename number>
845  void
847  const std::map<types::global_dof_index, number> &boundary_values,
848  BlockSparseMatrix<number> & matrix,
849  BlockVector<number> & solution,
850  BlockVector<number> & right_hand_side,
851  const bool eliminate_columns = true);
852 
853 #ifdef DEAL_II_WITH_PETSC
854 
889  void
891  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
892  PETScWrappers::MatrixBase & matrix,
893  PETScWrappers::VectorBase & solution,
894  PETScWrappers::VectorBase & right_hand_side,
895  const bool eliminate_columns = true);
896 
900  void
902  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
905  PETScWrappers::MPI::BlockVector & right_hand_side,
906  const bool eliminate_columns = true);
907 
908 #endif
909 
910 #ifdef DEAL_II_WITH_TRILINOS
911 
944  void
946  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
949  TrilinosWrappers::MPI::Vector & right_hand_side,
950  const bool eliminate_columns = true);
951 
956  void
958  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
961  TrilinosWrappers::MPI::BlockVector & right_hand_side,
962  const bool eliminate_columns = true);
963 #endif
964 
983  template <typename number>
984  void
986  const std::map<types::global_dof_index, number> &boundary_values,
987  const std::vector<types::global_dof_index> & local_dof_indices,
988  FullMatrix<number> & local_matrix,
989  Vector<number> & local_rhs,
990  const bool eliminate_columns);
991 
996  "You are providing a matrix whose subdivision into "
997  "blocks in either row or column direction does not use "
998  "the same blocks sizes as the solution vector or "
999  "right hand side vectors, respectively.");
1000 } // namespace MatrixTools
1001 
1002 
1003 
1005 
1006 #endif
void local_apply_boundary_values(const std::map< types::global_dof_index, number > &boundary_values, const std::vector< types::global_dof_index > &local_dof_indices, FullMatrix< number > &local_matrix, Vector< number > &local_rhs, const bool eliminate_columns)
void create_laplace_matrix(const DoFHandler< dim, spacedim > &dof, const hp::QCollection< dim > &q, SparseMatrix< double > &matrix, const Function< spacedim > &rhs, Vector< double > &rhs_vector, const Function< spacedim > *const a=nullptr, const AffineConstraints< double > &constraints=AffineConstraints< double >())
Contents is actually a matrix.
void create_mass_matrix(const DoFHandler< dim, spacedim > &dof, const hp::QCollection< dim > &q, SparseMatrix< number > &matrix, const Function< spacedim, number > &rhs, Vector< number > &rhs_vector, const Function< spacedim, number > *const a=nullptr, const AffineConstraints< number > &constraints=AffineConstraints< number >())
Abstract base class for mapping classes.
Definition: mapping.h:301
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:363
void apply_boundary_values(const std::map< types::global_dof_index, TrilinosScalar > &boundary_values, TrilinosWrappers::BlockSparseMatrix &matrix, TrilinosWrappers::MPI::BlockVector &solution, TrilinosWrappers::MPI::BlockVector &right_hand_side, const bool eliminate_columns=true)
static ::ExceptionBase & ExcComponentMismatch()
Definition: hp.h:117
static ::ExceptionBase & ExcBlocksDontMatch()
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:362
void create_boundary_mass_matrix(const DoFHandler< dim, spacedim > &dof, const hp::QCollection< dim - 1 > &q, SparseMatrix< number > &matrix, const std::map< types::boundary_id, const Function< spacedim, number > *> &boundary_functions, Vector< number > &rhs_vector, std::vector< types::global_dof_index > &dof_to_boundary_mapping, const Function< spacedim, number > *const a=nullptr, std::vector< unsigned int > component_mapping={})