Reference documentation for deal.II version Git f44593662d 2019-12-06 10:50:57 -0500
\(\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 
25 #include <deal.II/dofs/deprecated_function_map.h>
26 
27 #include <deal.II/lac/affine_constraints.h>
28 
29 #include <map>
30 
31 #ifdef DEAL_II_WITH_PETSC
32 # include <petscsys.h>
33 #endif
34 
35 DEAL_II_NAMESPACE_OPEN
36 
37 
38 // forward declarations
39 #ifndef DOXYGEN
40 template <int dim>
41 class Quadrature;
42 
43 
44 template <typename number>
45 class Vector;
46 template <typename number>
47 class FullMatrix;
48 template <typename number>
49 class SparseMatrix;
50 
51 template <typename number>
52 class BlockSparseMatrix;
53 template <typename Number>
54 class BlockVector;
55 
56 template <int dim, int spacedim>
57 class Mapping;
58 template <int dim, int spacedim>
59 class DoFHandler;
60 
61 namespace hp
62 {
63  template <int>
64  class QCollection;
65  template <int, int>
66  class MappingCollection;
67  template <int, int>
68  class DoFHandler;
69 } // namespace hp
70 
71 
72 # ifdef DEAL_II_WITH_PETSC
73 namespace PETScWrappers
74 {
75  class MatrixBase;
76  class VectorBase;
77  namespace MPI
78  {
79  class BlockSparseMatrix;
80  class BlockVector;
81  } // namespace MPI
82 } // namespace PETScWrappers
83 # endif
84 
85 # ifdef DEAL_II_WITH_TRILINOS
86 namespace TrilinosWrappers
87 {
88  class SparseMatrix;
89  class BlockSparseMatrix;
90  namespace MPI
91  {
92  class Vector;
93  class BlockVector;
94  } // namespace MPI
95 } // namespace TrilinosWrappers
96 # endif
97 #endif
98 
99 
233 namespace MatrixCreator
234 {
254  template <int dim, int spacedim, typename number>
255  void
257  const Mapping<dim, spacedim> & mapping,
258  const DoFHandler<dim, spacedim> & dof,
259  const Quadrature<dim> & q,
260  SparseMatrix<number> & matrix,
261  const Function<spacedim, number> *const a = nullptr,
263 
268  template <int dim, int spacedim, typename number>
269  void
270  create_mass_matrix(
271  const DoFHandler<dim, spacedim> & dof,
272  const Quadrature<dim> & q,
273  SparseMatrix<number> & matrix,
274  const Function<spacedim, number> *const a = nullptr,
276 
296  template <int dim, int spacedim, typename number>
297  void
298  create_mass_matrix(
299  const Mapping<dim, spacedim> & mapping,
300  const DoFHandler<dim, spacedim> & dof,
301  const Quadrature<dim> & q,
302  SparseMatrix<number> & matrix,
303  const Function<spacedim, number> & rhs,
304  Vector<number> & rhs_vector,
305  const Function<spacedim, number> *const a = nullptr,
307 
312  template <int dim, int spacedim, typename number>
313  void
314  create_mass_matrix(
315  const DoFHandler<dim, spacedim> & dof,
316  const Quadrature<dim> & q,
317  SparseMatrix<number> & matrix,
318  const Function<spacedim, number> & rhs,
319  Vector<number> & rhs_vector,
320  const Function<spacedim, number> *const a = nullptr,
322 
326  template <int dim, int spacedim, typename number>
327  void
328  create_mass_matrix(
330  const hp::DoFHandler<dim, spacedim> & dof,
331  const hp::QCollection<dim> & q,
332  SparseMatrix<number> & matrix,
333  const Function<spacedim, number> *const a = nullptr,
335 
339  template <int dim, int spacedim, typename number>
340  void
341  create_mass_matrix(
342  const hp::DoFHandler<dim, spacedim> & dof,
343  const hp::QCollection<dim> & q,
344  SparseMatrix<number> & matrix,
345  const Function<spacedim, number> *const a = nullptr,
347 
351  template <int dim, int spacedim, typename number>
352  void
353  create_mass_matrix(
355  const hp::DoFHandler<dim, spacedim> & dof,
356  const hp::QCollection<dim> & q,
357  SparseMatrix<number> & matrix,
358  const Function<spacedim, number> & rhs,
359  Vector<number> & rhs_vector,
360  const Function<spacedim, number> *const a = nullptr,
362 
366  template <int dim, int spacedim, typename number>
367  void
368  create_mass_matrix(
369  const hp::DoFHandler<dim, spacedim> & dof,
370  const hp::QCollection<dim> & q,
371  SparseMatrix<number> & matrix,
372  const Function<spacedim, number> & rhs,
373  Vector<number> & rhs_vector,
374  const Function<spacedim, number> *const a = nullptr,
376 
377 
403  template <int dim, int spacedim, typename number>
404  void
406  const Mapping<dim, spacedim> & mapping,
407  const DoFHandler<dim, spacedim> &dof,
408  const Quadrature<dim - 1> & q,
409  SparseMatrix<number> & matrix,
410  const std::map<types::boundary_id, const Function<spacedim, number> *>
411  & boundary_functions,
412  Vector<number> & rhs_vector,
413  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
414  const Function<spacedim, number> *const weight = 0,
415  std::vector<unsigned int> component_mapping = {});
416 
417 
422  template <int dim, int spacedim, typename number>
423  void
425  const DoFHandler<dim, spacedim> &dof,
426  const Quadrature<dim - 1> & q,
427  SparseMatrix<number> & matrix,
428  const std::map<types::boundary_id, const Function<spacedim, number> *>
429  & boundary_functions,
430  Vector<number> & rhs_vector,
431  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
432  const Function<spacedim, number> *const a = nullptr,
433  std::vector<unsigned int> component_mapping = {});
434 
438  template <int dim, int spacedim, typename number>
439  void
442  const hp::DoFHandler<dim, spacedim> & dof,
443  const hp::QCollection<dim - 1> & q,
444  SparseMatrix<number> & matrix,
445  const std::map<types::boundary_id, const Function<spacedim, number> *>
446  & boundary_functions,
447  Vector<number> & rhs_vector,
448  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
449  const Function<spacedim, number> *const a = nullptr,
450  std::vector<unsigned int> component_mapping = {});
451 
455  template <int dim, int spacedim, typename number>
456  void
459  const hp::QCollection<dim - 1> & q,
460  SparseMatrix<number> & matrix,
461  const std::map<types::boundary_id, const Function<spacedim, number> *>
462  & boundary_functions,
463  Vector<number> & rhs_vector,
464  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
465  const Function<spacedim, number> *const a = nullptr,
466  std::vector<unsigned int> component_mapping = {});
467 
487  template <int dim, int spacedim>
488  void
490  const Mapping<dim, spacedim> & mapping,
491  const DoFHandler<dim, spacedim> &dof,
492  const Quadrature<dim> & q,
493  SparseMatrix<double> & matrix,
494  const Function<spacedim> *const a = nullptr,
496 
501  template <int dim, int spacedim>
502  void
503  create_laplace_matrix(
504  const DoFHandler<dim, spacedim> &dof,
505  const Quadrature<dim> & q,
506  SparseMatrix<double> & matrix,
507  const Function<spacedim> *const a = nullptr,
509 
528  template <int dim, int spacedim>
529  void
530  create_laplace_matrix(
531  const Mapping<dim, spacedim> & mapping,
532  const DoFHandler<dim, spacedim> &dof,
533  const Quadrature<dim> & q,
534  SparseMatrix<double> & matrix,
535  const Function<spacedim> & rhs,
536  Vector<double> & rhs_vector,
537  const Function<spacedim> *const a = nullptr,
539 
544  template <int dim, int spacedim>
545  void
546  create_laplace_matrix(
547  const DoFHandler<dim, spacedim> &dof,
548  const Quadrature<dim> & q,
549  SparseMatrix<double> & matrix,
550  const Function<spacedim> & rhs,
551  Vector<double> & rhs_vector,
552  const Function<spacedim> *const a = nullptr,
554 
559  template <int dim, int spacedim>
560  void
561  create_laplace_matrix(
563  const hp::DoFHandler<dim, spacedim> & dof,
564  const hp::QCollection<dim> & q,
565  SparseMatrix<double> & matrix,
566  const Function<spacedim> *const a = nullptr,
568 
573  template <int dim, int spacedim>
574  void
575  create_laplace_matrix(
577  const hp::QCollection<dim> & q,
578  SparseMatrix<double> & matrix,
579  const Function<spacedim> *const a = nullptr,
581 
586  template <int dim, int spacedim>
587  void
588  create_laplace_matrix(
590  const hp::DoFHandler<dim, spacedim> & dof,
591  const hp::QCollection<dim> & q,
592  SparseMatrix<double> & matrix,
593  const Function<spacedim> & rhs,
594  Vector<double> & rhs_vector,
595  const Function<spacedim> *const a = nullptr,
597 
602  template <int dim, int spacedim>
603  void
604  create_laplace_matrix(
606  const hp::QCollection<dim> & q,
607  SparseMatrix<double> & matrix,
608  const Function<spacedim> & rhs,
609  Vector<double> & rhs_vector,
610  const Function<spacedim> *const a = nullptr,
612 
617  "You are providing either a right hand side function or a "
618  "coefficient with a number of vector components that is "
619  "inconsistent with the rest of the arguments. If you do "
620  "provide a coefficient or right hand side function, then "
621  "it either needs to have as many components as the finite "
622  "element in use, or only a single vector component. In "
623  "the latter case, the same value will be taken for "
624  "each vector component of the finite element.");
625 } // namespace MatrixCreator
626 
627 
628 
821 namespace MatrixTools
822 {
828  using namespace MatrixCreator;
829 
834  template <typename number>
835  void
837  const std::map<types::global_dof_index, number> &boundary_values,
838  SparseMatrix<number> & matrix,
839  Vector<number> & solution,
840  Vector<number> & right_hand_side,
841  const bool eliminate_columns = true);
842 
848  template <typename number>
849  void
850  apply_boundary_values(
851  const std::map<types::global_dof_index, number> &boundary_values,
852  BlockSparseMatrix<number> & matrix,
853  BlockVector<number> & solution,
854  BlockVector<number> & right_hand_side,
855  const bool eliminate_columns = true);
856 
857 #ifdef DEAL_II_WITH_PETSC
858 
893  void
894  apply_boundary_values(
895  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
896  PETScWrappers::MatrixBase & matrix,
897  PETScWrappers::VectorBase & solution,
898  PETScWrappers::VectorBase & right_hand_side,
899  const bool eliminate_columns = true);
900 
904  void
905  apply_boundary_values(
906  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
909  PETScWrappers::MPI::BlockVector & right_hand_side,
910  const bool eliminate_columns = true);
911 
912 #endif
913 
914 #ifdef DEAL_II_WITH_TRILINOS
915 
948  void
949  apply_boundary_values(
950  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
953  TrilinosWrappers::MPI::Vector & right_hand_side,
954  const bool eliminate_columns = true);
955 
960  void
961  apply_boundary_values(
962  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
965  TrilinosWrappers::MPI::BlockVector & right_hand_side,
966  const bool eliminate_columns = true);
967 #endif
968 
987  template <typename number>
988  void
990  const std::map<types::global_dof_index, number> &boundary_values,
991  const std::vector<types::global_dof_index> & local_dof_indices,
992  FullMatrix<number> & local_matrix,
993  Vector<number> & local_rhs,
994  const bool eliminate_columns);
995 
1000  "You are providing a matrix whose subdivision into "
1001  "blocks in either row or column direction does not use "
1002  "the same blocks sizes as the solution vector or "
1003  "right hand side vectors, respectively.");
1004 } // namespace MatrixTools
1005 
1006 
1007 
1008 DEAL_II_NAMESPACE_CLOSE
1009 
1010 #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:302
#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