include/deal.II/hp/dof_handler.h

00001 //----------------------------------------------------------------------
00002 //    @f$Id: dof_handler.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012 by the deal.II authors
00005 //
00006 //    This file is subject to QPL and may not be  distributed
00007 //    without copyright and license information. Please refer
00008 //    to the file deal.II/doc/license.html for the  text  and
00009 //    further information on this license.
00010 //
00011 //----------------------------------------------------------------------
00012 #ifndef __deal2__hp_dof_handler_h
00013 #define __deal2__hp_dof_handler_h
00014 
00015 
00016 
00017 #include <deal.II/base/config.h>
00018 #include <deal.II/base/exceptions.h>
00019 #include <deal.II/base/template_constraints.h>
00020 #include <deal.II/base/smartpointer.h>
00021 #include <deal.II/dofs/function_map.h>
00022 #include <deal.II/dofs/dof_iterator_selector.h>
00023 #include <deal.II/dofs/number_cache.h>
00024 #include <deal.II/hp/fe_collection.h>
00025 
00026 #include <vector>
00027 #include <map>
00028 #include <set>
00029 
00030 DEAL_II_NAMESPACE_OPEN
00031 
00032 namespace internal
00033 {
00034   namespace hp
00035   {
00036     template <int> class DoFLevel;
00037     template <int> class DoFFaces;
00038     template <int> class DoFObjects;
00039 
00040     namespace DoFHandler
00041     {
00042       struct Implementation;
00043     }
00044   }
00045 }
00046 
00047 namespace internal
00048 {
00049   namespace DoFAccessor
00050   {
00051     struct Implementation;
00052   }
00053 
00054   namespace DoFCellAccessor
00055   {
00056     struct Implementation;
00057   }
00058 }
00059 
00060 
00061 
00062 namespace hp
00063 {
00064 
00075   template <int dim, int spacedim=dim>
00076   class DoFHandler : public Subscriptor
00077   {
00078       typedef internal::DoFHandler::Iterators<DoFHandler<dim,spacedim> > IteratorSelector;
00079     public:
00080       typedef typename IteratorSelector::CellAccessor         cell_accessor;
00081       typedef typename IteratorSelector::FaceAccessor         face_accessor;
00082 
00083       typedef typename IteratorSelector::raw_line_iterator raw_line_iterator;
00084       typedef typename IteratorSelector::line_iterator line_iterator;
00085       typedef typename IteratorSelector::active_line_iterator active_line_iterator;
00086 
00087       typedef typename IteratorSelector::raw_quad_iterator raw_quad_iterator;
00088       typedef typename IteratorSelector::quad_iterator quad_iterator;
00089       typedef typename IteratorSelector::active_quad_iterator active_quad_iterator;
00090 
00091       typedef typename IteratorSelector::raw_hex_iterator raw_hex_iterator;
00092       typedef typename IteratorSelector::hex_iterator hex_iterator;
00093       typedef typename IteratorSelector::active_hex_iterator active_hex_iterator;
00094 
00095       typedef typename IteratorSelector::raw_cell_iterator raw_cell_iterator;
00096       typedef typename IteratorSelector::cell_iterator cell_iterator;
00097       typedef typename IteratorSelector::active_cell_iterator active_cell_iterator;
00098 
00099       typedef typename IteratorSelector::raw_face_iterator raw_face_iterator;
00100       typedef typename IteratorSelector::face_iterator face_iterator;
00101       typedef typename IteratorSelector::active_face_iterator active_face_iterator;
00102 
00107       typedef typename FunctionMap<spacedim>::type FunctionMap;
00108 
00113       static const unsigned int dimension = dim;
00114 
00119       static const unsigned int space_dimension = spacedim;
00120 
00136       static const unsigned int invalid_dof_index = numbers::invalid_unsigned_int;
00137 
00160       static const unsigned int default_fe_index = numbers::invalid_unsigned_int;
00161 
00162 
00167       DoFHandler (const Triangulation<dim,spacedim> &tria);
00168 
00172       virtual ~DoFHandler ();
00173 
00193       virtual void distribute_dofs (const hp::FECollection<dim,spacedim> &fe);
00194 
00201       void set_active_fe_indices (const std::vector<unsigned int>& active_fe_indices);
00202 
00210       void get_active_fe_indices (std::vector<unsigned int>& active_fe_indices) const;
00211 
00218       virtual void clear ();
00219 
00251       void renumber_dofs (const std::vector<unsigned int> &new_numbers);
00252 
00279       unsigned int max_couplings_between_dofs () const;
00280 
00290       unsigned int max_couplings_between_boundary_dofs () const;
00291 
00305       raw_cell_iterator    begin_raw   (const unsigned int level = 0) const;
00306 
00314       cell_iterator        begin       (const unsigned int level = 0) const;
00315 
00323       active_cell_iterator begin_active(const unsigned int level = 0) const;
00324 
00334       raw_cell_iterator    end () const;
00335 
00342       cell_iterator        end (const unsigned int level) const;
00343 
00350       raw_cell_iterator    end_raw (const unsigned int level) const;
00351 
00358       active_cell_iterator end_active (const unsigned int level) const;
00359 
00367       raw_cell_iterator    last_raw () const;
00368 
00376       raw_cell_iterator    last_raw (const unsigned int level) const;
00377 
00385       cell_iterator        last () const;
00386 
00394       cell_iterator        last (const unsigned int level) const;
00395 
00403       active_cell_iterator last_active () const;
00404 
00412       active_cell_iterator last_active (const unsigned int level) const;
00414 
00415                                        /*---------------------------------------*/
00416 
00428       raw_face_iterator    begin_raw_face   () const;
00429 
00436       face_iterator        begin_face       () const;
00437 
00444       active_face_iterator begin_active_face() const;
00445 
00455       raw_face_iterator    end_face () const;
00456 
00461       raw_face_iterator    end_raw_face () const;
00462 
00467       active_face_iterator end_active_face () const;
00468 
00476       raw_face_iterator    last_raw_face () const;
00477 
00485       face_iterator        last_face () const;
00486 
00494       active_face_iterator last_active_face () const;
00495 
00497 
00498 
00499                                        /*---------------------------------------*/
00500 
00511       raw_line_iterator    begin_raw_line   (const unsigned int level = 0) const;
00512 
00517       line_iterator        begin_line       (const unsigned int level = 0) const;
00518 
00523       active_line_iterator begin_active_line(const unsigned int level = 0) const;
00524 
00531       raw_line_iterator    end_line () const;
00532 
00539       line_iterator        end_line (const unsigned int level) const;
00540 
00547       raw_line_iterator    end_raw_line (const unsigned int level) const;
00548 
00555       active_line_iterator end_active_line (const unsigned int level) const;
00556 
00557 
00562       raw_line_iterator    last_raw_line () const;
00563 
00569       raw_line_iterator    last_raw_line (const unsigned int level) const;
00570 
00575       line_iterator        last_line () const;
00576 
00581       line_iterator        last_line (const unsigned int level) const;
00582 
00587       active_line_iterator last_active_line () const;
00588 
00593       active_line_iterator last_active_line (const unsigned int level) const;
00596                                        /*---------------------------------------*/
00597 
00600 
00608       raw_quad_iterator    begin_raw_quad   (const unsigned int level = 0) const;
00609 
00614       quad_iterator        begin_quad       (const unsigned int level = 0) const;
00615 
00620       active_quad_iterator begin_active_quad(const unsigned int level = 0) const;
00621 
00628       raw_quad_iterator    end_quad () const;
00629 
00636       quad_iterator        end_quad (const unsigned int level) const;
00637 
00644       raw_quad_iterator    end_raw_quad (const unsigned int level) const;
00645 
00652       active_quad_iterator end_active_quad (const unsigned int level) const;
00653 
00654 
00659       raw_quad_iterator    last_raw_quad () const;
00660 
00666       raw_quad_iterator    last_raw_quad (const unsigned int level) const;
00667 
00672       quad_iterator        last_quad () const;
00673 
00678       quad_iterator        last_quad (const unsigned int level) const;
00679 
00684       active_quad_iterator last_active_quad () const;
00685 
00690       active_quad_iterator last_active_quad (const unsigned int level) const;
00693                                        /*---------------------------------------*/
00694 
00697 
00705       raw_hex_iterator
00706       begin_raw_hex   (const unsigned int level = 0) const;
00707 
00712       hex_iterator
00713       begin_hex       (const unsigned int level = 0) const;
00714 
00719       active_hex_iterator
00720       begin_active_hex(const unsigned int level = 0) const;
00721 
00728       raw_hex_iterator
00729       end_hex () const;
00730 
00737       hex_iterator        end_hex (const unsigned int level) const;
00738 
00745       raw_hex_iterator    end_raw_hex (const unsigned int level) const;
00746 
00753       active_hex_iterator end_active_hex (const unsigned int level) const;
00754 
00759       raw_hex_iterator
00760       last_raw_hex () const;
00761 
00767       raw_hex_iterator
00768       last_raw_hex (const unsigned int level) const;
00769 
00774       hex_iterator
00775       last_hex () const;
00776 
00781       hex_iterator
00782       last_hex (const unsigned int level) const;
00783 
00788       active_hex_iterator
00789       last_active_hex () const;
00790 
00795       active_hex_iterator
00796       last_active_hex (const unsigned int level) const;
00799                                        /*---------------------------------------*/
00800 
00801 
00833       unsigned int n_dofs () const;
00834 
00839       unsigned int n_boundary_dofs () const;
00840 
00854       unsigned int
00855       n_boundary_dofs (const FunctionMap &boundary_indicators) const;
00856 
00865       unsigned int
00866       n_boundary_dofs (const std::set<types::boundary_id_t> &boundary_indicators) const;
00867 
00898       unsigned int n_locally_owned_dofs() const;
00899 
00908       const IndexSet & locally_owned_dofs() const;
00909 
00910 
00927       const std::vector<IndexSet> &
00928       locally_owned_dofs_per_processor () const;
00929 
00956       const std::vector<unsigned int> &
00957       n_locally_owned_dofs_per_processor () const;
00958 
00965       const hp::FECollection<dim,spacedim> & get_fe () const;
00966 
00971       const Triangulation<dim,spacedim> & get_tria () const;
00972 
00985       virtual std::size_t memory_consumption () const;
00986 
00990       DeclException0 (ExcInvalidTriangulation);
00994       DeclException0 (ExcNoFESelected);
00998       DeclException0 (ExcRenumberingIncomplete);
01002       DeclException0 (ExcGridsDoNotMatch);
01006       DeclException0 (ExcInvalidBoundaryIndicator);
01010       DeclException1 (ExcMatrixHasWrongSize,
01011                       int,
01012                       << "The matrix has the wrong dimension " << arg1);
01016       DeclException0 (ExcFunctionNotUseful);
01020       DeclException1 (ExcNewNumbersNotConsecutive,
01021                       int,
01022                       << "The given list of new dof indices is not consecutive: "
01023                       << "the index " << arg1 << " does not exist.");
01027       DeclException2 (ExcInvalidFEIndex,
01028                       int, int,
01029                       << "The mesh contains a cell with an active_fe_index of "
01030                       << arg1 << ", but the finite element collection only has "
01031                       << arg2 << " elements");
01035       DeclException1 (ExcInvalidLevel,
01036                       int,
01037                       << "The given level " << arg1
01038                       << " is not in the valid range!");
01042       DeclException0 (ExcFacesHaveNoLevel);
01047       DeclException1 (ExcEmptyLevel,
01048                       int,
01049                       << "You tried to do something on level " << arg1
01050                       << ", but this level is empty.");
01051 
01052     protected:
01053 
01058       SmartPointer<const Triangulation<dim,spacedim>,DoFHandler<dim,spacedim> > tria;
01059 
01075       SmartPointer<const hp::FECollection<dim,spacedim>,hp::DoFHandler<dim,spacedim> > finite_elements;
01076 
01077     private:
01078 
01088       DoFHandler (const DoFHandler &);
01089 
01099       DoFHandler & operator = (const DoFHandler &);
01100 
01104       void clear_space ();
01105 
01123       void create_active_fe_table ();
01124 
01135       void pre_refinement_action ();
01136       void post_refinement_action ();
01137 
01138 
01145       void
01146       compute_vertex_dof_identities (std::vector<unsigned int> &new_dof_indices) const;
01147 
01154       void
01155       compute_line_dof_identities (std::vector<unsigned int> &new_dof_indices) const;
01156 
01163       void
01164       compute_quad_dof_identities (std::vector<unsigned int> &new_dof_indices) const;
01165 
01191       void renumber_dofs_internal (const std::vector<unsigned int> &new_numbers,
01192                                    internal::int2type<0>);
01193 
01194       void renumber_dofs_internal (const std::vector<unsigned int> &new_numbers,
01195                                    internal::int2type<1>);
01196 
01197       void renumber_dofs_internal (const std::vector<unsigned int> &new_numbers,
01198                                    internal::int2type<2>);
01199 
01200       void renumber_dofs_internal (const std::vector<unsigned int> &new_numbers,
01201                                    internal::int2type<3>);
01202 
01210       std::vector<internal::hp::DoFLevel<dim>*>    levels;
01218       internal::hp::DoFFaces<dim> * faces;
01219 
01231       internal::DoFHandler::NumberCache number_cache;
01232 
01256       std::vector<unsigned int>      vertex_dofs;
01257 
01279       std::vector<unsigned int>      vertex_dofs_offsets;
01280 
01290       std::vector<std::vector<bool> *> has_children;
01291 
01297       std::vector<boost::signals2::connection> tria_listeners;
01298 
01302       template <int, class> friend class ::DoFAccessor;
01303       template <class> friend class ::DoFCellAccessor;
01304       friend struct internal::DoFAccessor::Implementation;
01305       friend struct internal::DoFCellAccessor::Implementation;
01306 
01314       template <int> friend class internal::hp::DoFLevel;
01315       template <int> friend class internal::hp::DoFObjects;
01316       friend struct internal::hp::DoFHandler::Implementation;
01317   };
01318 
01319 
01320 
01321 #ifndef DOXYGEN
01322 
01323 
01324 /* ----------------------- Inline functions ---------------------------------- */
01325 
01326   template <int dim, int spacedim>
01327   inline
01328   unsigned int
01329   DoFHandler<dim,spacedim>::n_dofs () const
01330   {
01331     return number_cache.n_global_dofs;
01332   }
01333 
01334 
01335   template <int dim, int spacedim>
01336   unsigned int
01337   DoFHandler<dim, spacedim>::n_locally_owned_dofs() const
01338   {
01339     return number_cache.n_locally_owned_dofs;
01340   }
01341 
01342 
01343   template <int dim, int spacedim>
01344   const IndexSet &
01345   DoFHandler<dim, spacedim>::locally_owned_dofs() const
01346   {
01347     return number_cache.locally_owned_dofs;
01348   }
01349 
01350 
01351   template <int dim, int spacedim>
01352   const std::vector<unsigned int> &
01353   DoFHandler<dim, spacedim>::n_locally_owned_dofs_per_processor() const
01354   {
01355     return number_cache.n_locally_owned_dofs_per_processor;
01356   }
01357 
01358 
01359   template <int dim, int spacedim>
01360   const std::vector<IndexSet> &
01361   DoFHandler<dim, spacedim>::locally_owned_dofs_per_processor () const
01362   {
01363     return number_cache.locally_owned_dofs_per_processor;
01364   }
01365 
01366 
01367 
01368   template<int dim, int spacedim>
01369   inline
01370   const hp::FECollection<dim,spacedim> &
01371   DoFHandler<dim,spacedim>::get_fe () const
01372   {
01373     Assert (finite_elements != 0,
01374             ExcMessage ("No finite element collection is associated with "
01375                         "this DoFHandler"));
01376     return *finite_elements;
01377   }
01378 
01379 
01380   template<int dim, int spacedim>
01381   inline
01382   const Triangulation<dim,spacedim> &
01383   DoFHandler<dim,spacedim>::get_tria () const
01384   {
01385     return *tria;
01386   }
01387 
01388 
01389 
01390 
01391 #endif
01392 
01393 }
01394 
01395 DEAL_II_NAMESPACE_CLOSE
01396 
01397 #endif
01398 
01399 
01400 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

deal.II documentation generated on Tue May 22 2012 12:06:07 by doxygen 1.7.3