Reference documentation for deal.II version Git d9b14c2d54 2019-09-14 18:13:29 -0600
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
matrix_tools.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 2019 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 
22 #include <deal.II/base/exceptions.h>
23 #include <deal.II/base/function.h>
24 #include <deal.II/base/thread_management.h>
25 
26 #include <deal.II/dofs/deprecated_function_map.h>
27 
28 #include <deal.II/lac/affine_constraints.h>
29 
30 #include <map>
31 
32 #ifdef DEAL_II_WITH_PETSC
33 # include <petscsys.h>
34 #endif
35 
36 DEAL_II_NAMESPACE_OPEN
37 
38 
39 // forward declarations
40 #ifndef DOXYGEN
41 template <int dim>
42 class Quadrature;
43 
44 
45 template <typename number>
46 class Vector;
47 template <typename number>
48 class FullMatrix;
49 template <typename number>
50 class SparseMatrix;
51 
52 template <typename number>
53 class BlockSparseMatrix;
54 template <typename Number>
55 class BlockVector;
56 
57 template <int dim, int spacedim>
58 class Mapping;
59 template <int dim, int spacedim>
60 class DoFHandler;
61 
62 namespace hp
63 {
64  template <int>
65  class QCollection;
66  template <int, int>
67  class MappingCollection;
68  template <int, int>
69  class DoFHandler;
70 } // namespace hp
71 
72 
73 # ifdef DEAL_II_WITH_PETSC
74 namespace PETScWrappers
75 {
76  class MatrixBase;
77  class VectorBase;
78  namespace MPI
79  {
80  class BlockSparseMatrix;
81  class BlockVector;
82  } // namespace MPI
83 } // namespace PETScWrappers
84 # endif
85 
86 # ifdef DEAL_II_WITH_TRILINOS
87 namespace TrilinosWrappers
88 {
89  class SparseMatrix;
90  class BlockSparseMatrix;
91  namespace MPI
92  {
93  class Vector;
94  class BlockVector;
95  } // namespace MPI
96 } // namespace TrilinosWrappers
97 # endif
98 #endif
99 
100 
234 namespace MatrixCreator
235 {
255  template <int dim, int spacedim, typename number>
256  void
258  const Mapping<dim, spacedim> & mapping,
259  const DoFHandler<dim, spacedim> & dof,
260  const Quadrature<dim> & q,
261  SparseMatrix<number> & matrix,
262  const Function<spacedim, number> *const a = nullptr,
264 
269  template <int dim, int spacedim, typename number>
270  void
271  create_mass_matrix(
272  const DoFHandler<dim, spacedim> & dof,
273  const Quadrature<dim> & q,
274  SparseMatrix<number> & matrix,
275  const Function<spacedim, number> *const a = nullptr,
277 
297  template <int dim, int spacedim, typename number>
298  void
299  create_mass_matrix(
300  const Mapping<dim, spacedim> & mapping,
301  const DoFHandler<dim, spacedim> & dof,
302  const Quadrature<dim> & q,
303  SparseMatrix<number> & matrix,
304  const Function<spacedim, number> & rhs,
305  Vector<number> & rhs_vector,
306  const Function<spacedim, number> *const a = nullptr,
308 
313  template <int dim, int spacedim, typename number>
314  void
315  create_mass_matrix(
316  const DoFHandler<dim, spacedim> & dof,
317  const Quadrature<dim> & q,
318  SparseMatrix<number> & matrix,
319  const Function<spacedim, number> & rhs,
320  Vector<number> & rhs_vector,
321  const Function<spacedim, number> *const a = nullptr,
323 
327  template <int dim, int spacedim, typename number>
328  void
329  create_mass_matrix(
331  const hp::DoFHandler<dim, spacedim> & dof,
332  const hp::QCollection<dim> & q,
333  SparseMatrix<number> & matrix,
334  const Function<spacedim, number> *const a = nullptr,
336 
340  template <int dim, int spacedim, typename number>
341  void
342  create_mass_matrix(
343  const hp::DoFHandler<dim, spacedim> & dof,
344  const hp::QCollection<dim> & q,
345  SparseMatrix<number> & matrix,
346  const Function<spacedim, number> *const a = nullptr,
348 
352  template <int dim, int spacedim, typename number>
353  void
354  create_mass_matrix(
356  const hp::DoFHandler<dim, spacedim> & dof,
357  const hp::QCollection<dim> & q,
358  SparseMatrix<number> & matrix,
359  const Function<spacedim, number> & rhs,
360  Vector<number> & rhs_vector,
361  const Function<spacedim, number> *const a = nullptr,
363 
367  template <int dim, int spacedim, typename number>
368  void
369  create_mass_matrix(
370  const hp::DoFHandler<dim, spacedim> & dof,
371  const hp::QCollection<dim> & q,
372  SparseMatrix<number> & matrix,
373  const Function<spacedim, number> & rhs,
374  Vector<number> & rhs_vector,
375  const Function<spacedim, number> *const a = nullptr,
377 
378 
404  template <int dim, int spacedim, typename number>
405  void
407  const Mapping<dim, spacedim> & mapping,
408  const DoFHandler<dim, spacedim> &dof,
409  const Quadrature<dim - 1> & q,
410  SparseMatrix<number> & matrix,
411  const std::map<types::boundary_id, const Function<spacedim, number> *>
412  & boundary_functions,
413  Vector<number> & rhs_vector,
414  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
415  const Function<spacedim, number> *const weight = 0,
416  std::vector<unsigned int> component_mapping = {});
417 
418 
423  template <int dim, int spacedim, typename number>
424  void
426  const DoFHandler<dim, spacedim> &dof,
427  const Quadrature<dim - 1> & q,
428  SparseMatrix<number> & matrix,
429  const std::map<types::boundary_id, const Function<spacedim, number> *>
430  & boundary_functions,
431  Vector<number> & rhs_vector,
432  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
433  const Function<spacedim, number> *const a = nullptr,
434  std::vector<unsigned int> component_mapping = {});
435 
439  template <int dim, int spacedim, typename number>
440  void
443  const hp::DoFHandler<dim, spacedim> & dof,
444  const hp::QCollection<dim - 1> & q,
445  SparseMatrix<number> & matrix,
446  const std::map<types::boundary_id, const Function<spacedim, number> *>
447  & boundary_functions,
448  Vector<number> & rhs_vector,
449  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
450  const Function<spacedim, number> *const a = nullptr,
451  std::vector<unsigned int> component_mapping = {});
452 
456  template <int dim, int spacedim, typename number>
457  void
460  const hp::QCollection<dim - 1> & q,
461  SparseMatrix<number> & matrix,
462  const std::map<types::boundary_id, const Function<spacedim, number> *>
463  & boundary_functions,
464  Vector<number> & rhs_vector,
465  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
466  const Function<spacedim, number> *const a = nullptr,
467  std::vector<unsigned int> component_mapping = {});
468 
488  template <int dim, int spacedim>
489  void
491  const Mapping<dim, spacedim> & mapping,
492  const DoFHandler<dim, spacedim> &dof,
493  const Quadrature<dim> & q,
494  SparseMatrix<double> & matrix,
495  const Function<spacedim> *const a = nullptr,
497 
502  template <int dim, int spacedim>
503  void
504  create_laplace_matrix(
505  const DoFHandler<dim, spacedim> &dof,
506  const Quadrature<dim> & q,
507  SparseMatrix<double> & matrix,
508  const Function<spacedim> *const a = nullptr,
510 
529  template <int dim, int spacedim>
530  void
531  create_laplace_matrix(
532  const Mapping<dim, spacedim> & mapping,
533  const DoFHandler<dim, spacedim> &dof,
534  const Quadrature<dim> & q,
535  SparseMatrix<double> & matrix,
536  const Function<spacedim> & rhs,
537  Vector<double> & rhs_vector,
538  const Function<spacedim> *const a = nullptr,
540 
545  template <int dim, int spacedim>
546  void
547  create_laplace_matrix(
548  const DoFHandler<dim, spacedim> &dof,
549  const Quadrature<dim> & q,
550  SparseMatrix<double> & matrix,
551  const Function<spacedim> & rhs,
552  Vector<double> & rhs_vector,
553  const Function<spacedim> *const a = nullptr,
555 
560  template <int dim, int spacedim>
561  void
562  create_laplace_matrix(
564  const hp::DoFHandler<dim, spacedim> & dof,
565  const hp::QCollection<dim> & q,
566  SparseMatrix<double> & matrix,
567  const Function<spacedim> *const a = nullptr,
569 
574  template <int dim, int spacedim>
575  void
576  create_laplace_matrix(
578  const hp::QCollection<dim> & q,
579  SparseMatrix<double> & matrix,
580  const Function<spacedim> *const a = nullptr,
582 
587  template <int dim, int spacedim>
588  void
589  create_laplace_matrix(
591  const hp::DoFHandler<dim, spacedim> & dof,
592  const hp::QCollection<dim> & q,
593  SparseMatrix<double> & matrix,
594  const Function<spacedim> & rhs,
595  Vector<double> & rhs_vector,
596  const Function<spacedim> *const a = nullptr,
598 
603  template <int dim, int spacedim>
604  void
605  create_laplace_matrix(
607  const hp::QCollection<dim> & q,
608  SparseMatrix<double> & matrix,
609  const Function<spacedim> & rhs,
610  Vector<double> & rhs_vector,
611  const Function<spacedim> *const a = nullptr,
613 
618  "You are providing either a right hand side function or a "
619  "coefficient with a number of vector components that is "
620  "inconsistent with the rest of the arguments. If you do "
621  "provide a coefficient or right hand side function, then "
622  "it either needs to have as many components as the finite "
623  "element in use, or only a single vector component. In "
624  "the latter case, the same value will be taken for "
625  "each vector component of the finite element.");
626 } // namespace MatrixCreator
627 
628 
629 
822 namespace MatrixTools
823 {
829  using namespace MatrixCreator;
830 
835  template <typename number>
836  void
838  const std::map<types::global_dof_index, number> &boundary_values,
839  SparseMatrix<number> & matrix,
840  Vector<number> & solution,
841  Vector<number> & right_hand_side,
842  const bool eliminate_columns = true);
843 
849  template <typename number>
850  void
851  apply_boundary_values(
852  const std::map<types::global_dof_index, number> &boundary_values,
853  BlockSparseMatrix<number> & matrix,
854  BlockVector<number> & solution,
855  BlockVector<number> & right_hand_side,
856  const bool eliminate_columns = true);
857 
858 #ifdef DEAL_II_WITH_PETSC
859 
894  void
895  apply_boundary_values(
896  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
897  PETScWrappers::MatrixBase & matrix,
898  PETScWrappers::VectorBase & solution,
899  PETScWrappers::VectorBase & right_hand_side,
900  const bool eliminate_columns = true);
901 
905  void
906  apply_boundary_values(
907  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
910  PETScWrappers::MPI::BlockVector & right_hand_side,
911  const bool eliminate_columns = true);
912 
913 #endif
914 
915 #ifdef DEAL_II_WITH_TRILINOS
916 
949  void
950  apply_boundary_values(
951  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
954  TrilinosWrappers::MPI::Vector & right_hand_side,
955  const bool eliminate_columns = true);
956 
961  void
962  apply_boundary_values(
963  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
966  TrilinosWrappers::MPI::BlockVector & right_hand_side,
967  const bool eliminate_columns = true);
968 #endif
969 
988  template <typename number>
989  void
991  const std::map<types::global_dof_index, number> &boundary_values,
992  const std::vector<types::global_dof_index> & local_dof_indices,
993  FullMatrix<number> & local_matrix,
994  Vector<number> & local_rhs,
995  const bool eliminate_columns);
996 
1001  "You are providing a matrix whose subdivision into "
1002  "blocks in either row or column direction does not use "
1003  "the same blocks sizes as the solution vector or "
1004  "right hand side vectors, respectively.");
1005 } // namespace MatrixTools
1006 
1007 
1008 
1009 DEAL_II_NAMESPACE_CLOSE
1010 
1011 #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 apply_boundary_values(const std::map< types::global_dof_index, number > &boundary_values, SparseMatrix< number > &matrix, Vector< number > &solution, Vector< number > &right_hand_side, const bool eliminate_columns=true)
Definition: matrix_tools.cc:81
void create_laplace_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, SparseMatrix< double > &matrix, const Function< spacedim > *const a=nullptr, const AffineConstraints< double > &constraints=AffineConstraints< double >())
void create_boundary_mass_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< 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 weight=0, std::vector< unsigned int > component_mapping={})
LinearAlgebra::distributed::Vector< Number > Vector
Abstract base class for mapping classes.
Definition: mapping.h:301
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:496
void create_mass_matrix(const Mapping< dim, spacedim > &mapping, const DoFHandler< dim, spacedim > &dof, const Quadrature< dim > &q, SparseMatrix< number > &matrix, const Function< spacedim, number > *const a=nullptr, const AffineConstraints< number > &constraints=AffineConstraints< number >())
static ::ExceptionBase & ExcComponentMismatch()
Definition: hp.h:117
static ::ExceptionBase & ExcBlocksDontMatch()
unsigned int boundary_id
Definition: types.h:125