Reference documentation for deal.II version 9.1.0-pre
matrix_tools.h
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 1998 - 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.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 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 
98 
232 namespace MatrixCreator
233 {
253  template <int dim, int spacedim, typename number>
254  void
256  const Mapping<dim, spacedim> & mapping,
257  const DoFHandler<dim, spacedim> & dof,
258  const Quadrature<dim> & q,
259  SparseMatrix<number> & matrix,
260  const Function<spacedim, number> *const a = nullptr,
262 
267  template <int dim, int spacedim, typename number>
268  void
269  create_mass_matrix(
270  const DoFHandler<dim, spacedim> & dof,
271  const Quadrature<dim> & q,
272  SparseMatrix<number> & matrix,
273  const Function<spacedim, number> *const a = nullptr,
275 
295  template <int dim, int spacedim, typename number>
296  void
297  create_mass_matrix(
298  const Mapping<dim, spacedim> & mapping,
299  const DoFHandler<dim, spacedim> & dof,
300  const Quadrature<dim> & q,
301  SparseMatrix<number> & matrix,
302  const Function<spacedim, number> & rhs,
303  Vector<number> & rhs_vector,
304  const Function<spacedim, number> *const a = nullptr,
306 
311  template <int dim, int spacedim, typename number>
312  void
313  create_mass_matrix(
314  const DoFHandler<dim, spacedim> & dof,
315  const Quadrature<dim> & q,
316  SparseMatrix<number> & matrix,
317  const Function<spacedim, number> & rhs,
318  Vector<number> & rhs_vector,
319  const Function<spacedim, number> *const a = nullptr,
321 
325  template <int dim, int spacedim, typename number>
326  void
327  create_mass_matrix(
329  const hp::DoFHandler<dim, spacedim> & dof,
330  const hp::QCollection<dim> & q,
331  SparseMatrix<number> & matrix,
332  const Function<spacedim, number> *const a = nullptr,
334 
338  template <int dim, int spacedim, typename number>
339  void
340  create_mass_matrix(
341  const hp::DoFHandler<dim, spacedim> & dof,
342  const hp::QCollection<dim> & q,
343  SparseMatrix<number> & matrix,
344  const Function<spacedim, number> *const a = nullptr,
346 
350  template <int dim, int spacedim, typename number>
351  void
352  create_mass_matrix(
354  const hp::DoFHandler<dim, spacedim> & dof,
355  const hp::QCollection<dim> & q,
356  SparseMatrix<number> & matrix,
357  const Function<spacedim, number> & rhs,
358  Vector<number> & rhs_vector,
359  const Function<spacedim, number> *const a = nullptr,
361 
365  template <int dim, int spacedim, typename number>
366  void
367  create_mass_matrix(
368  const hp::DoFHandler<dim, spacedim> & dof,
369  const hp::QCollection<dim> & q,
370  SparseMatrix<number> & matrix,
371  const Function<spacedim, number> & rhs,
372  Vector<number> & rhs_vector,
373  const Function<spacedim, number> *const a = nullptr,
375 
376 
402  template <int dim, int spacedim, typename number>
403  void
405  const Mapping<dim, spacedim> & mapping,
406  const DoFHandler<dim, spacedim> &dof,
407  const Quadrature<dim - 1> & q,
408  SparseMatrix<number> & matrix,
409  const std::map<types::boundary_id, const Function<spacedim, number> *>
410  & boundary_functions,
411  Vector<number> & rhs_vector,
412  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
413  const Function<spacedim, number> *const weight = 0,
414  std::vector<unsigned int> component_mapping = std::vector<unsigned int>());
415 
416 
421  template <int dim, int spacedim, typename number>
422  void
423  create_boundary_mass_matrix(
424  const DoFHandler<dim, spacedim> &dof,
425  const Quadrature<dim - 1> & q,
426  SparseMatrix<number> & matrix,
427  const std::map<types::boundary_id, const Function<spacedim, number> *>
428  & boundary_functions,
429  Vector<number> & rhs_vector,
430  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
431  const Function<spacedim, number> *const a = nullptr,
432  std::vector<unsigned int> component_mapping = std::vector<unsigned int>());
433 
437  template <int dim, int spacedim, typename number>
438  void
439  create_boundary_mass_matrix(
441  const hp::DoFHandler<dim, spacedim> & dof,
442  const hp::QCollection<dim - 1> & q,
443  SparseMatrix<number> & matrix,
444  const std::map<types::boundary_id, const Function<spacedim, number> *>
445  & boundary_functions,
446  Vector<number> & rhs_vector,
447  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
448  const Function<spacedim, number> *const a = nullptr,
449  std::vector<unsigned int> component_mapping = std::vector<unsigned int>());
450 
454  template <int dim, int spacedim, typename number>
455  void
456  create_boundary_mass_matrix(
458  const hp::QCollection<dim - 1> & q,
459  SparseMatrix<number> & matrix,
460  const std::map<types::boundary_id, const Function<spacedim, number> *>
461  & boundary_functions,
462  Vector<number> & rhs_vector,
463  std::vector<types::global_dof_index> & dof_to_boundary_mapping,
464  const Function<spacedim, number> *const a = nullptr,
465  std::vector<unsigned int> component_mapping = std::vector<unsigned int>());
466 
486  template <int dim, int spacedim>
487  void
489  const Mapping<dim, spacedim> & mapping,
490  const DoFHandler<dim, spacedim> &dof,
491  const Quadrature<dim> & q,
492  SparseMatrix<double> & matrix,
493  const Function<spacedim> *const a = nullptr,
495 
500  template <int dim, int spacedim>
501  void
502  create_laplace_matrix(
503  const DoFHandler<dim, spacedim> &dof,
504  const Quadrature<dim> & q,
505  SparseMatrix<double> & matrix,
506  const Function<spacedim> *const a = nullptr,
508 
527  template <int dim, int spacedim>
528  void
529  create_laplace_matrix(
530  const Mapping<dim, spacedim> & mapping,
531  const DoFHandler<dim, spacedim> &dof,
532  const Quadrature<dim> & q,
533  SparseMatrix<double> & matrix,
534  const Function<spacedim> & rhs,
535  Vector<double> & rhs_vector,
536  const Function<spacedim> *const a = nullptr,
538 
543  template <int dim, int spacedim>
544  void
545  create_laplace_matrix(
546  const DoFHandler<dim, spacedim> &dof,
547  const Quadrature<dim> & q,
548  SparseMatrix<double> & matrix,
549  const Function<spacedim> & rhs,
550  Vector<double> & rhs_vector,
551  const Function<spacedim> *const a = nullptr,
553 
558  template <int dim, int spacedim>
559  void
560  create_laplace_matrix(
562  const hp::DoFHandler<dim, spacedim> & dof,
563  const hp::QCollection<dim> & q,
564  SparseMatrix<double> & matrix,
565  const Function<spacedim> *const a = nullptr,
567 
572  template <int dim, int spacedim>
573  void
574  create_laplace_matrix(
576  const hp::QCollection<dim> & q,
577  SparseMatrix<double> & matrix,
578  const Function<spacedim> *const a = nullptr,
580 
585  template <int dim, int spacedim>
586  void
587  create_laplace_matrix(
589  const hp::DoFHandler<dim, spacedim> & dof,
590  const hp::QCollection<dim> & q,
591  SparseMatrix<double> & matrix,
592  const Function<spacedim> & rhs,
593  Vector<double> & rhs_vector,
594  const Function<spacedim> *const a = nullptr,
596 
601  template <int dim, int spacedim>
602  void
603  create_laplace_matrix(
605  const hp::QCollection<dim> & q,
606  SparseMatrix<double> & matrix,
607  const Function<spacedim> & rhs,
608  Vector<double> & rhs_vector,
609  const Function<spacedim> *const a = nullptr,
611 
616  "You are providing either a right hand side function or a "
617  "coefficient with a number of vector components that is "
618  "inconsistent with the rest of the arguments. If you do "
619  "provide a coefficient or right hand side function, then "
620  "it either needs to have as many components as the finite "
621  "element in use, or only a single vector component. In "
622  "the latter case, the same value will be taken for "
623  "each vector component of the finite element.");
624 } // namespace MatrixCreator
625 
626 
627 
819 namespace MatrixTools
820 {
826  using namespace MatrixCreator;
827 
832  template <typename number>
833  void
835  const std::map<types::global_dof_index, number> &boundary_values,
836  SparseMatrix<number> & matrix,
837  Vector<number> & solution,
838  Vector<number> & right_hand_side,
839  const bool eliminate_columns = true);
840 
846  template <typename number>
847  void
848  apply_boundary_values(
849  const std::map<types::global_dof_index, number> &boundary_values,
850  BlockSparseMatrix<number> & matrix,
851  BlockVector<number> & solution,
852  BlockVector<number> & right_hand_side,
853  const bool eliminate_columns = true);
854 
855 #ifdef DEAL_II_WITH_PETSC
856 
891  void
892  apply_boundary_values(
893  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
894  PETScWrappers::MatrixBase & matrix,
895  PETScWrappers::VectorBase & solution,
896  PETScWrappers::VectorBase & right_hand_side,
897  const bool eliminate_columns = true);
898 
902  void
903  apply_boundary_values(
904  const std::map<types::global_dof_index, PetscScalar> &boundary_values,
907  PETScWrappers::MPI::BlockVector & right_hand_side,
908  const bool eliminate_columns = true);
909 
910 #endif
911 
912 #ifdef DEAL_II_WITH_TRILINOS
913 
946  void
947  apply_boundary_values(
948  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
951  TrilinosWrappers::MPI::Vector & right_hand_side,
952  const bool eliminate_columns = true);
953 
958  void
959  apply_boundary_values(
960  const std::map<types::global_dof_index, TrilinosScalar> &boundary_values,
963  TrilinosWrappers::MPI::BlockVector & right_hand_side,
964  const bool eliminate_columns = true);
965 #endif
966 
985  template <typename number>
986  void
988  const std::map<types::global_dof_index, number> &boundary_values,
989  const std::vector<types::global_dof_index> & local_dof_indices,
990  FullMatrix<number> & local_matrix,
991  Vector<number> & local_rhs,
992  const bool eliminate_columns);
993 
998  "You are providing a matrix whose subdivision into "
999  "blocks in either row or column direction does not use "
1000  "the same blocks sizes as the solution vector or "
1001  "right hand side vectors, respectively.");
1002 } // namespace MatrixTools
1003 
1004 
1005 
1006 DEAL_II_NAMESPACE_CLOSE
1007 
1008 #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=std::vector< unsigned int >())
Abstract base class for mapping classes.
Definition: dof_tools.h:57
#define DeclExceptionMsg(Exception, defaulttext)
Definition: exceptions.h:397
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:102
static::ExceptionBase & ExcBlocksDontMatch()
unsigned int boundary_id
Definition: types.h:111