Reference documentation for deal.II version Git 180c135554 2021-06-23 17:42:41 -0400
\(\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 } // namespace hp
66 
67 
68 # ifdef DEAL_II_WITH_PETSC
69 namespace PETScWrappers
70 {
71  class MatrixBase;
72  class VectorBase;
73  namespace MPI
74  {
75  class BlockSparseMatrix;
76  class BlockVector;
77  } // namespace MPI
78 } // namespace PETScWrappers
79 # endif
80 
81 # ifdef DEAL_II_WITH_TRILINOS
82 namespace TrilinosWrappers
83 {
84  class SparseMatrix;
85  class BlockSparseMatrix;
86  namespace MPI
87  {
88  class Vector;
89  class BlockVector;
90  } // namespace MPI
91 } // namespace TrilinosWrappers
92 # endif
93 #endif
94 
95 
228 namespace MatrixCreator
229 {
249  template <int dim, int spacedim, typename number>
250  void
252  const Mapping<dim, spacedim> & mapping,
253  const DoFHandler<dim, spacedim> & dof,
254  const Quadrature<dim> & q,
256  const Function<spacedim, number> *const a = nullptr,
258 
263  template <int dim, int spacedim, typename number>
264  void
266  const DoFHandler<dim, spacedim> & dof,
267  const Quadrature<dim> & q,
268  SparseMatrix<number> & matrix,
269  const Function<spacedim, number> *const a = nullptr,
271 
291  template <int dim, int spacedim, typename number>
292  void
294  const Mapping<dim, spacedim> & mapping,
295  const DoFHandler<dim, spacedim> & dof,
296  const Quadrature<dim> & q,
297  SparseMatrix<number> & matrix,
298  const Function<spacedim, number> & rhs,
299  Vector<number> & rhs_vector,
300  const Function<spacedim, number> *const a = nullptr,
302 
307  template <int dim, int spacedim, typename number>
308  void
310  const DoFHandler<dim, spacedim> & dof,
311  const Quadrature<dim> & q,
312  SparseMatrix<number> & matrix,
313  const Function<spacedim, number> & rhs,
314  Vector<number> & rhs_vector,
315  const Function<spacedim, number> *const a = nullptr,
317 
321  template <int dim, int spacedim, typename number>
322  void
325  const DoFHandler<dim, spacedim> & dof,
326  const hp::QCollection<dim> & q,
327  SparseMatrix<number> & matrix,
328  const Function<spacedim, number> *const a = nullptr,
330 
334  template <int dim, int spacedim, typename number>
335  void
337  const DoFHandler<dim, spacedim> & dof,
338  const hp::QCollection<dim> & q,
339  SparseMatrix<number> & matrix,
340  const Function<spacedim, number> *const a = nullptr,
342 
346  template <int dim, int spacedim, typename number>
347  void
350  const DoFHandler<dim, spacedim> & dof,
351  const hp::QCollection<dim> & q,
352  SparseMatrix<number> & matrix,
353  const Function<spacedim, number> & rhs,
354  Vector<number> & rhs_vector,
355  const Function<spacedim, number> *const a = nullptr,
357 
361  template <int dim, int spacedim, typename number>
362  void
364  const DoFHandler<dim, spacedim> & dof,
365  const hp::QCollection<dim> & q,
366  SparseMatrix<number> & matrix,
367  const Function<spacedim, number> & rhs,
368  Vector<number> & rhs_vector,
369  const Function<spacedim, number> *const a = nullptr,
371 
372 
398  template <int dim, int spacedim, typename number>
399  void
401  const Mapping<dim, spacedim> & mapping,
402  const DoFHandler<dim, spacedim> &dof,
403  const Quadrature<dim - 1> & q,
404  SparseMatrix<number> & matrix,
405  const std::map<types::boundary_id, const Function<spacedim, number> *>
406  & boundary_functions,
407  Vector<number> & rhs_vector,
408  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
409  const Function<spacedim, number> *const weight = 0,
410  std::vector<unsigned int> component_mapping = {});
411 
412 
417  template <int dim, int spacedim, typename number>
418  void
420  const DoFHandler<dim, spacedim> &dof,
421  const Quadrature<dim - 1> & q,
422  SparseMatrix<number> & matrix,
423  const std::map<types::boundary_id, const Function<spacedim, number> *>
424  & boundary_functions,
425  Vector<number> & rhs_vector,
426  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
427  const Function<spacedim, number> *const a = nullptr,
428  std::vector<unsigned int> component_mapping = {});
429 
433  template <int dim, int spacedim, typename number>
434  void
437  const DoFHandler<dim, spacedim> & dof,
438  const hp::QCollection<dim - 1> & q,
439  SparseMatrix<number> & matrix,
440  const std::map<types::boundary_id, const Function<spacedim, number> *>
441  & boundary_functions,
442  Vector<number> & rhs_vector,
443  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
444  const Function<spacedim, number> *const a = nullptr,
445  std::vector<unsigned int> component_mapping = {});
446 
450  template <int dim, int spacedim, typename number>
451  void
453  const DoFHandler<dim, spacedim> &dof,
454  const hp::QCollection<dim - 1> & q,
455  SparseMatrix<number> & matrix,
456  const std::map<types::boundary_id, const Function<spacedim, number> *>
457  & boundary_functions,
458  Vector<number> & rhs_vector,
459  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
460  const Function<spacedim, number> *const a = nullptr,
461  std::vector<unsigned int> component_mapping = {});
462 
482  template <int dim, int spacedim>
483  void
485  const Mapping<dim, spacedim> & mapping,
486  const DoFHandler<dim, spacedim> &dof,
487  const Quadrature<dim> & q,
488  SparseMatrix<double> & matrix,
489  const Function<spacedim> *const a = nullptr,
491 
496  template <int dim, int spacedim>
497  void
499  const DoFHandler<dim, spacedim> &dof,
500  const Quadrature<dim> & q,
501  SparseMatrix<double> & matrix,
502  const Function<spacedim> *const a = nullptr,
504 
523  template <int dim, int spacedim>
524  void
526  const Mapping<dim, spacedim> & mapping,
527  const DoFHandler<dim, spacedim> &dof,
528  const Quadrature<dim> & q,
529  SparseMatrix<double> & matrix,
530  const Function<spacedim> & rhs,
531  Vector<double> & rhs_vector,
532  const Function<spacedim> *const a = nullptr,
534 
539  template <int dim, int spacedim>
540  void
542  const DoFHandler<dim, spacedim> &dof,
543  const Quadrature<dim> & q,
544  SparseMatrix<double> & matrix,
545  const Function<spacedim> & rhs,
546  Vector<double> & rhs_vector,
547  const Function<spacedim> *const a = nullptr,
549 
553  template <int dim, int spacedim>
554  void
557  const DoFHandler<dim, spacedim> & dof,
558  const hp::QCollection<dim> & q,
559  SparseMatrix<double> & matrix,
560  const Function<spacedim> *const a = nullptr,
562 
566  template <int dim, int spacedim>
567  void
569  const DoFHandler<dim, spacedim> &dof,
570  const hp::QCollection<dim> & q,
571  SparseMatrix<double> & matrix,
572  const Function<spacedim> *const a = nullptr,
574 
578  template <int dim, int spacedim>
579  void
582  const DoFHandler<dim, spacedim> & dof,
583  const hp::QCollection<dim> & q,
584  SparseMatrix<double> & matrix,
585  const Function<spacedim> & rhs,
586  Vector<double> & rhs_vector,
587  const Function<spacedim> *const a = nullptr,
589 
593  template <int dim, int spacedim>
594  void
596  const DoFHandler<dim, spacedim> &dof,
597  const hp::QCollection<dim> & q,
598  SparseMatrix<double> & matrix,
599  const Function<spacedim> & rhs,
600  Vector<double> & rhs_vector,
601  const Function<spacedim> *const a = nullptr,
603 
608  "You are providing either a right hand side function or a "
609  "coefficient with a number of vector components that is "
610  "inconsistent with the rest of the arguments. If you do "
611  "provide a coefficient or right hand side function, then "
612  "it either needs to have as many components as the finite "
613  "element in use, or only a single vector component. In "
614  "the latter case, the same value will be taken for "
615  "each vector component of the finite element.");
616 } // namespace MatrixCreator
617 
618 
619 
827 namespace MatrixTools
828 {
834  using namespace MatrixCreator;
835 
840  template <typename number>
841  void
843  const std::map<types::global_dof_index, number> &boundary_values,
845  Vector<number> & solution,
846  Vector<number> & right_hand_side,
847  const bool eliminate_columns = true);
848 
854  template <typename number>
855  void
857  const std::map<types::global_dof_index, number> &boundary_values,
858  BlockSparseMatrix<number> & matrix,
859  BlockVector<number> & solution,
860  BlockVector<number> & right_hand_side,
861  const bool eliminate_columns = true);
862 
863 #ifdef DEAL_II_WITH_PETSC
864 
899  void
901  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
902  PETScWrappers::MatrixBase & matrix,
903  PETScWrappers::VectorBase & solution,
904  PETScWrappers::VectorBase & right_hand_side,
905  const bool eliminate_columns = true);
906 
910  void
912  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
915  PETScWrappers::MPI::BlockVector & right_hand_side,
916  const bool eliminate_columns = true);
917 
918 #endif
919 
920 #ifdef DEAL_II_WITH_TRILINOS
921 
954  void
956  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
959  TrilinosWrappers::MPI::Vector & right_hand_side,
960  const bool eliminate_columns = true);
961 
966  void
968  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
971  TrilinosWrappers::MPI::BlockVector & right_hand_side,
972  const bool eliminate_columns = true);
973 #endif
974 
993  template <typename number>
994  void
996  const std::map<types::global_dof_index, number> &boundary_values,
997  const std::vector<types::global_dof_index> & local_dof_indices,
998  FullMatrix<number> & local_matrix,
999  Vector<number> & local_rhs,
1000  const bool eliminate_columns);
1001 
1006  "You are providing a matrix whose subdivision into "
1007  "blocks in either row or column direction does not use "
1008  "the same blocks sizes as the solution vector or "
1009  "right hand side vectors, respectively.");
1010 } // namespace MatrixTools
1011 
1012 
1013 
1015 
1016 #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:303
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:493
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:399
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:398
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={})