00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__dof_tools_h
00013 #define __deal2__dof_tools_h
00014
00015
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018 #include <deal.II/base/table.h>
00019 #include <deal.II/base/index_set.h>
00020 #include <deal.II/base/point.h>
00021 #include <deal.II/lac/constraint_matrix.h>
00022 #include <deal.II/lac/sparsity_pattern.h>
00023 #include <deal.II/dofs/function_map.h>
00024 #include <deal.II/dofs/dof_handler.h>
00025 #include <deal.II/fe/fe.h>
00026 #include <deal.II/hp/mapping_collection.h>
00027
00028 #include <vector>
00029 #include <set>
00030 #include <map>
00031
00032 DEAL_II_NAMESPACE_OPEN
00033
00034 template<int dim, class T> class Table;
00035 class SparsityPattern;
00036 template <typename number> class Vector;
00037 template <int dim> class Function;
00038 template <int dim, int spacedim> class FiniteElement;
00039 template <int dim, int spacedim> class DoFHandler;
00040 namespace hp
00041 {
00042 template <int dim, int spacedim> class DoFHandler;
00043 template <int dim, int spacedim> class MappingCollection;
00044 }
00045 template <int dim, int spacedim> class MGDoFHandler;
00046 class ConstraintMatrix;
00047 template <class GridClass> class InterGridMap;
00048 template <int dim, int spacedim> class Mapping;
00049
00050
00051
00052
00178 namespace DoFTools
00179 {
00198 enum Coupling
00199 {
00204 none,
00208 always,
00217 nonzero
00218 };
00219
00230 template <int dim, int spacedim>
00231 unsigned int
00232 max_dofs_per_cell (const DoFHandler<dim,spacedim> &dh);
00233
00240 template <int dim, int spacedim>
00241 unsigned int
00242 max_dofs_per_cell (const hp::DoFHandler<dim,spacedim> &dh);
00243
00244
00256 template <int dim, int spacedim>
00257 unsigned int
00258 max_dofs_per_face (const DoFHandler<dim,spacedim> &dh);
00259
00271 template <int dim, int spacedim>
00272 unsigned int
00273 max_dofs_per_face (const hp::DoFHandler<dim,spacedim> &dh);
00274
00286 template <int dim, int spacedim>
00287 unsigned int
00288 max_dofs_per_vertex (const DoFHandler<dim,spacedim> &dh);
00289
00301 template <int dim, int spacedim>
00302 unsigned int
00303 max_dofs_per_vertex (const hp::DoFHandler<dim,spacedim> &dh);
00304
00317 template <int dim, int spacedim>
00318 unsigned int
00319 n_components (const DoFHandler<dim,spacedim> &dh);
00320
00333 template <int dim, int spacedim>
00334 unsigned int
00335 n_components (const hp::DoFHandler<dim,spacedim> &dh);
00336
00349 template <int dim, int spacedim>
00350 bool
00351 fe_is_primitive (const DoFHandler<dim,spacedim> &dh);
00352
00365 template <int dim, int spacedim>
00366 bool
00367 fe_is_primitive (const hp::DoFHandler<dim,spacedim> &dh);
00368
00493 template <class DH, class SparsityPattern>
00494 void
00495 make_sparsity_pattern (const DH &dof,
00496 SparsityPattern &sparsity_pattern,
00497 const ConstraintMatrix &constraints = ConstraintMatrix(),
00498 const bool keep_constrained_dofs = true,
00499 const types::subdomain_id_t subdomain_id = types::invalid_subdomain_id);
00500
00652 template <class DH, class SparsityPattern>
00653 void
00654 make_sparsity_pattern (const DH &dof,
00655 const Table<2, Coupling> &coupling,
00656 SparsityPattern &sparsity_pattern,
00657 const ConstraintMatrix &constraints = ConstraintMatrix(),
00658 const bool keep_constrained_dofs = true,
00659 const types::subdomain_id_t subdomain_id = types::invalid_subdomain_id);
00660
00673 template <class DH, class SparsityPattern>
00674 void
00675 make_sparsity_pattern (const DH &dof,
00676 const std::vector<std::vector<bool> > &mask,
00677 SparsityPattern &sparsity_pattern);
00678
00712 template <class DH, class SparsityPattern>
00713 void
00714 make_sparsity_pattern (const DH &dof_row,
00715 const DH &dof_col,
00716 SparsityPattern &sparsity);
00717
00735 template <class DH, class SparsityPattern>
00736 void
00737 make_boundary_sparsity_pattern (const DH &dof,
00738 const std::vector<unsigned int> &dof_to_boundary_mapping,
00739 SparsityPattern &sparsity_pattern);
00740
00771 template <class DH, class SparsityPattern>
00772 void
00773 make_boundary_sparsity_pattern (const DH &dof,
00774 const typename FunctionMap<DH::space_dimension>::type &boundary_indicators,
00775 const std::vector<unsigned int> &dof_to_boundary_mapping,
00776 SparsityPattern &sparsity);
00777
00794 template<class DH, class SparsityPattern>
00795 void
00796 make_flux_sparsity_pattern (const DH &dof_handler,
00797 SparsityPattern &sparsity_pattern);
00798
00810 template<class DH, class SparsityPattern>
00811 void
00812 make_flux_sparsity_pattern (const DH &dof_handler,
00813 SparsityPattern &sparsity_pattern,
00814 const ConstraintMatrix &constraints,
00815 const bool keep_constrained_dofs = true,
00816 const types::subdomain_id_t subdomain_id = numbers::invalid_unsigned_int);
00817
00838 template <class DH, class SparsityPattern>
00839 void
00840 make_flux_sparsity_pattern (const DH &dof,
00841 SparsityPattern &sparsity,
00842 const Table<2,Coupling> &int_mask,
00843 const Table<2,Coupling> &flux_mask);
00844
00846
00923 template <class DH>
00924 void
00925 make_hanging_node_constraints (const DH &dof_handler,
00926 ConstraintMatrix &constraints);
00928
00929
01002 template<typename FaceIterator>
01003 void
01004 make_periodicity_constraints (const FaceIterator &face_1,
01005 const typename identity<FaceIterator>::type &face_2,
01006 ::ConstraintMatrix &constraint_matrix,
01007 const std::vector<bool> &component_mask = std::vector<bool>());
01008
01009
01080 template<typename DH>
01081 void
01082 make_periodicity_constraints (const DH &dof_handler,
01083 const types::boundary_id_t boundary_component,
01084 const int direction,
01085 ::ConstraintMatrix &constraint_matrix,
01086 const std::vector<bool> &component_mask = std::vector<bool>());
01087
01088
01100 template<typename DH>
01101 void
01102 make_periodicity_constraints (const DH &dof_handler,
01103 const types::boundary_id_t boundary_component,
01104 const int direction,
01105 ::Tensor<1,DH::space_dimension>
01106 &offset,
01107 ::ConstraintMatrix &constraint_matrix,
01108 const std::vector<bool> &component_mask = std::vector<bool>());
01110
01111
01166 template <class DH, typename Number>
01167 void
01168 distribute_cell_to_dof_vector (const DH &dof_handler,
01169 const Vector<Number> &cell_data,
01170 Vector<double> &dof_data,
01171 const unsigned int component = 0);
01172
01224 template <int dim, int spacedim>
01225 void
01226 extract_dofs (const DoFHandler<dim,spacedim> &dof_handler,
01227 const std::vector<bool> &select,
01228 std::vector<bool> &selected_dofs,
01229 const bool blocks = false);
01230
01235 template <int dim, int spacedim>
01236 void
01237 extract_dofs (const hp::DoFHandler<dim,spacedim> &dof_handler,
01238 const std::vector<bool> &select,
01239 std::vector<bool> &selected_dofs,
01240 const bool blocks = false);
01241
01247 template <int dim, int spacedim>
01248 void
01249 extract_level_dofs (const unsigned int level,
01250 const MGDoFHandler<dim,spacedim> &dof,
01251 const std::vector<bool> &select,
01252 std::vector<bool> &selected_dofs,
01253 const bool blocks = false);
01254
01333 template <class DH>
01334 void
01335 extract_boundary_dofs (const DH &dof_handler,
01336 const std::vector<bool> &component_select,
01337 std::vector<bool> &selected_dofs,
01338 const std::set<types::boundary_id_t> &boundary_indicators = std::set<types::boundary_id_t>());
01339
01368 template <class DH>
01369 void
01370 extract_boundary_dofs (const DH &dof_handler,
01371 const std::vector<bool> &component_select,
01372 IndexSet &selected_dofs,
01373 const std::set<types::boundary_id_t> &boundary_indicators = std::set<types::boundary_id_t>());
01374
01405 template <class DH>
01406 void
01407 extract_dofs_with_support_on_boundary (const DH &dof_handler,
01408 const std::vector<bool> &component_select,
01409 std::vector<bool> &selected_dofs,
01410 const std::set<types::boundary_id_t> &boundary_indicators = std::set<types::boundary_id_t>());
01411
01429 template <int dim, int spacedim>
01430 void
01431 extract_hanging_node_dofs (const DoFHandler<dim,spacedim> &dof_handler,
01432 std::vector<bool> &selected_dofs);
01434
01457 template <class DH>
01458 void
01459 extract_subdomain_dofs (const DH &dof_handler,
01460 const types::subdomain_id_t subdomain_id,
01461 std::vector<bool> &selected_dofs);
01462
01463
01475 template <class DH>
01476 void
01477 extract_locally_owned_dofs (const DH & dof_handler,
01478 IndexSet & dof_set);
01479
01480
01509 template <class DH>
01510 void
01511 extract_locally_active_dofs (const DH & dof_handler,
01512 IndexSet & dof_set);
01513
01530 template <class DH>
01531 void
01532 extract_locally_relevant_dofs (const DH & dof_handler,
01533 IndexSet & dof_set);
01534
01588 template <class DH>
01589 void
01590 get_subdomain_association (const DH &dof_handler,
01591 std::vector<types::subdomain_id_t> &subdomain);
01592
01632 template <class DH>
01633 unsigned int
01634 count_dofs_with_subdomain_association (const DH &dof_handler,
01635 const types::subdomain_id_t subdomain);
01636
01669 template <class DH>
01670 void
01671 count_dofs_with_subdomain_association (const DH &dof_handler,
01672 const types::subdomain_id_t subdomain,
01673 std::vector<unsigned int> &n_dofs_on_subdomain);
01674
01711 template <class DH>
01712 IndexSet
01713 dof_indices_with_subdomain_association (const DH &dof_handler,
01714 const types::subdomain_id_t subdomain);
01715
01716
01740 template <class DH, class Sparsity>
01741 void make_cell_patches(Sparsity& block_list,
01742 const DH& dof_handler,
01743 const unsigned int level,
01744 const std::vector<bool>& selected_dofs = std::vector<bool>(),
01745 unsigned int offset = 0);
01746
01805 template <class DH>
01806 void make_vertex_patches(SparsityPattern& block_list,
01807 const DH& dof_handler,
01808 const unsigned int level,
01809 const bool interior_dofs_only,
01810 const bool boundary_patches = false,
01811 const bool level_boundary_patches = false,
01812 const bool single_cell_patches = false);
01813
01871 template <class DH>
01872 void make_child_patches(SparsityPattern& block_list,
01873 const DH& dof_handler,
01874 const unsigned int level,
01875 const bool interior_dofs_only,
01876 const bool boundary_dofs = false);
01877
01904 template <class DH>
01905 void make_single_patch(SparsityPattern& block_list,
01906 const DH& dof_handler,
01907 const unsigned int level,
01908 const bool interior_dofs_only = false);
01909
01911
01956 template <class DH>
01957 void
01958 extract_constant_modes (const DH &dof_handler,
01959 const std::vector<bool> &component_select,
01960 std::vector<std::vector<bool> > &constant_modes);
01961
01977 template <class DH>
01978 void
01979 get_active_fe_indices (const DH &dof_handler,
01980 std::vector<unsigned int> &active_fe_indices);
01981
02059 template <class DH>
02060 void
02061 count_dofs_per_component (const DH & dof_handler,
02062 std::vector<unsigned int>& dofs_per_component,
02063 const bool vector_valued_once = false,
02064 std::vector<unsigned int> target_component
02065 = std::vector<unsigned int>());
02066
02098 template <class DH>
02099 void
02100 count_dofs_per_block (const DH &dof,
02101 std::vector<unsigned int> &dofs_per_block,
02102 std::vector<unsigned int> target_block
02103 = std::vector<unsigned int>());
02104
02113 template <int dim, int spacedim>
02114 void
02115 count_dofs_per_component (const DoFHandler<dim,spacedim>& dof_handler,
02116 std::vector<unsigned int>& dofs_per_component,
02117 std::vector<unsigned int> target_component);
02118
02333 template <int dim, int spacedim>
02334 void
02335 compute_intergrid_constraints (const DoFHandler<dim,spacedim> &coarse_grid,
02336 const unsigned int coarse_component,
02337 const DoFHandler<dim,spacedim> &fine_grid,
02338 const unsigned int fine_component,
02339 const InterGridMap<DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
02340 ConstraintMatrix &constraints);
02341
02342
02366 template <int dim, int spacedim>
02367 void
02368 compute_intergrid_transfer_representation (const DoFHandler<dim,spacedim> &coarse_grid,
02369 const unsigned int coarse_component,
02370 const DoFHandler<dim,spacedim> &fine_grid,
02371 const unsigned int fine_component,
02372 const InterGridMap<DoFHandler<dim,spacedim> > &coarse_to_fine_grid_map,
02373 std::vector<std::map<unsigned int, float> > &transfer_representation);
02374
02402 template <class DH>
02403 void
02404 map_dof_to_boundary_indices (const DH &dof_handler,
02405 std::vector<unsigned int> &mapping);
02406
02418 template <class DH>
02419 void
02420 map_dof_to_boundary_indices (const DH &dof_handler,
02421 const std::set<types::boundary_id_t> &boundary_indicators,
02422 std::vector<unsigned int> &mapping);
02423
02451 template <int dim, int spacedim>
02452 void
02453 map_dofs_to_support_points (const Mapping<dim,spacedim> &mapping,
02454 const DoFHandler<dim,spacedim> &dof_handler,
02455 std::vector<Point<spacedim> > &support_points);
02456
02460 template <int dim, int spacedim>
02461 void
02462 map_dofs_to_support_points (const ::hp::MappingCollection<dim,spacedim> &mapping,
02463 const hp::DoFHandler<dim,spacedim> &dof_handler,
02464 std::vector<Point<spacedim> > &support_points);
02465
02492 template <int dim, int spacedim>
02493 void
02494 map_dofs_to_support_points (const Mapping<dim,spacedim> &mapping,
02495 const DoFHandler<dim,spacedim> &dof_handler,
02496 std::map<unsigned int, Point<spacedim> > &support_points);
02497
02501 template <int dim, int spacedim>
02502 void
02503 map_dofs_to_support_points (const ::hp::MappingCollection<dim,spacedim> &mapping,
02504 const hp::DoFHandler<dim,spacedim> &dof_handler,
02505 std::map<unsigned int, Point<spacedim> > &support_points);
02506
02534 template <class DH, class Comp>
02535 void
02536 map_support_points_to_dofs (const Mapping<DH::dimension, DH::space_dimension> &mapping,
02537 const DH &dof_handler,
02538 std::map<Point<DH::space_dimension>, unsigned int, Comp> &point_to_index_map);
02539
02555 template <int dim, int spacedim>
02556 void
02557 convert_couplings_to_blocks (const hp::DoFHandler<dim,spacedim>& dof_handler,
02558 const Table<2, Coupling>& table_by_component,
02559 std::vector<Table<2,Coupling> >& tables_by_block);
02560
02586 template <int dim, int spacedim, template <int, int> class DH>
02587 void
02588 make_zero_boundary_constraints (const DH<dim,spacedim> &dof,
02589 ConstraintMatrix &zero_boundary_constraints,
02590 const std::vector<bool> &component_mask_=std::vector<bool>());
02591
02607 template <int dim, int spacedim>
02608 void
02609 convert_couplings_to_blocks (const DoFHandler<dim,spacedim>& dof_handler,
02610 const Table<2, Coupling>& table_by_component,
02611 std::vector<Table<2,Coupling> >& tables_by_block);
02612
02621 template <int dim, int spacedim>
02622 Table<2,Coupling>
02623 dof_couplings_from_component_couplings (const FiniteElement<dim,spacedim> &fe,
02624 const Table<2,Coupling> &component_couplings);
02625
02635 template <int dim, int spacedim>
02636 std::vector<Table<2,Coupling> >
02637 dof_couplings_from_component_couplings (const hp::FECollection<dim,spacedim> &fe,
02638 const Table<2,Coupling> &component_couplings);
02643 DeclException0 (ExcFiniteElementsDontMatch);
02648 DeclException0 (ExcGridNotCoarser);
02653 DeclException0 (ExcGridsDontMatch);
02658 DeclException0 (ExcNoFESelected);
02663 DeclException0 (ExcInvalidBoundaryIndicator);
02664 }
02665
02666
02667
02668
02669
02670 #ifndef DOXYGEN
02671
02672 namespace DoFTools
02673 {
02679 inline
02680 Coupling operator |= (Coupling& c1,
02681 const Coupling c2)
02682 {
02683 if (c2 == always)
02684 c1 = always;
02685 else if (c1 != always && c2 == nonzero)
02686 return c1 = nonzero;
02687 return c1;
02688 }
02689
02690
02696 inline
02697 Coupling operator | (const Coupling c1,
02698 const Coupling c2)
02699 {
02700 if (c1 == always || c2 == always)
02701 return always;
02702 if (c1 == nonzero || c2 == nonzero)
02703 return nonzero;
02704 return none;
02705 }
02706
02707
02708
02709
02710 template <int dim, int spacedim>
02711 inline
02712 unsigned int
02713 max_dofs_per_cell (const DoFHandler<dim,spacedim> &dh)
02714 {
02715 return dh.get_fe().dofs_per_cell;
02716 }
02717
02718
02719 template <int dim, int spacedim>
02720 inline
02721 unsigned int
02722 max_dofs_per_face (const DoFHandler<dim,spacedim> &dh)
02723 {
02724 return dh.get_fe().dofs_per_face;
02725 }
02726
02727
02728 template <int dim, int spacedim>
02729 inline
02730 unsigned int
02731 max_dofs_per_vertex (const DoFHandler<dim,spacedim> &dh)
02732 {
02733 return dh.get_fe().dofs_per_vertex;
02734 }
02735
02736
02737 template <int dim, int spacedim>
02738 inline
02739 unsigned int
02740 n_components (const DoFHandler<dim,spacedim> &dh)
02741 {
02742 return dh.get_fe().n_components();
02743 }
02744
02745
02746
02747 template <int dim, int spacedim>
02748 inline
02749 bool
02750 fe_is_primitive (const DoFHandler<dim,spacedim> &dh)
02751 {
02752 return dh.get_fe().is_primitive();
02753 }
02754
02755
02756 template <int dim, int spacedim>
02757 inline
02758 unsigned int
02759 max_dofs_per_cell (const hp::DoFHandler<dim,spacedim> &dh)
02760 {
02761 return dh.get_fe().max_dofs_per_cell ();
02762 }
02763
02764
02765 template <int dim, int spacedim>
02766 inline
02767 unsigned int
02768 max_dofs_per_face (const hp::DoFHandler<dim,spacedim> &dh)
02769 {
02770 return dh.get_fe().max_dofs_per_face ();
02771 }
02772
02773
02774 template <int dim, int spacedim>
02775 inline
02776 unsigned int
02777 max_dofs_per_vertex (const hp::DoFHandler<dim,spacedim> &dh)
02778 {
02779 return dh.get_fe().max_dofs_per_vertex ();
02780 }
02781
02782
02783 template <int dim, int spacedim>
02784 inline
02785 unsigned int
02786 n_components (const hp::DoFHandler<dim,spacedim> &dh)
02787 {
02788 return dh.get_fe()[0].n_components();
02789 }
02790
02791
02792 template <int dim, int spacedim>
02793 inline
02794 bool
02795 fe_is_primitive (const hp::DoFHandler<dim,spacedim> &dh)
02796 {
02797 return dh.get_fe()[0].is_primitive();
02798 }
02799
02800
02801 template <class DH, class SparsityPattern>
02802 inline
02803 void
02804 make_sparsity_pattern (const DH &dof,
02805 const std::vector<std::vector<bool> > &mask,
02806 SparsityPattern &sparsity_pattern)
02807 {
02808 const unsigned int ncomp = dof.get_fe().n_components();
02809
02810 Assert (mask.size() == ncomp,
02811 ExcDimensionMismatch(mask.size(), ncomp));
02812 for (unsigned int i=0; i<mask.size(); ++i)
02813 Assert (mask[i].size() == ncomp,
02814 ExcDimensionMismatch(mask[i].size(), ncomp));
02815
02816 Table<2,DoFTools::Coupling> couplings(ncomp, ncomp);
02817 for (unsigned int i=0;i<ncomp;++i)
02818 for (unsigned int j=0;j<ncomp;++j)
02819 if (mask[i][j])
02820 couplings(i,j) = always;
02821 else
02822 couplings(i,j) = none;
02823
02824
02825 make_sparsity_pattern(dof, couplings, sparsity_pattern);
02826 }
02827
02828
02829 template <class DH, class Comp>
02830 void
02831 map_support_points_to_dofs (
02832 const Mapping<DH::dimension,DH::space_dimension> &mapping,
02833 const DH &dof_handler,
02834 std::map<Point<DH::space_dimension>, unsigned int, Comp> &point_to_index_map)
02835 {
02836
02837
02838
02839 std::vector<Point<DH::space_dimension> > support_points (dof_handler.n_dofs());
02840 map_dofs_to_support_points (mapping, dof_handler, support_points);
02841
02842
02843
02844 point_to_index_map.clear ();
02845 for (unsigned int i=0; i<dof_handler.n_dofs(); ++i)
02846 point_to_index_map[support_points[i]] = i;
02847 }
02848 }
02849
02850 #endif
02851
02852 DEAL_II_NAMESPACE_CLOSE
02853
02854 #endif
02855