00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__dof_handler_h
00013 #define __deal2__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/smartpointer.h>
00020 #include <deal.II/base/index_set.h>
00021 #include <deal.II/dofs/block_info.h>
00022 #include <deal.II/dofs/dof_iterator_selector.h>
00023 #include <deal.II/dofs/number_cache.h>
00024 #include <deal.II/dofs/function_map.h>
00025 #include <deal.II/dofs/dof_handler_policy.h>
00026
00027 #include <boost/serialization/split_member.hpp>
00028
00029 #include <vector>
00030 #include <map>
00031 #include <set>
00032
00033 DEAL_II_NAMESPACE_OPEN
00034
00035 namespace internal
00036 {
00037 namespace DoFHandler
00038 {
00039 template <int dim> class DoFLevel;
00040 template <int dim> class DoFFaces;
00041
00042 struct Implementation;
00043 }
00044
00045 namespace DoFAccessor
00046 {
00047 struct Implementation;
00048 }
00049
00050 namespace DoFCellAccessor
00051 {
00052 struct Implementation;
00053 }
00054 }
00055
00056
00171 template <int dim, int spacedim=dim>
00172 class DoFHandler : public Subscriptor
00173 {
00174 typedef internal::DoFHandler::Iterators<DoFHandler<dim,spacedim> > IteratorSelector;
00175 public:
00176 typedef typename IteratorSelector::CellAccessor cell_accessor;
00177 typedef typename IteratorSelector::FaceAccessor face_accessor;
00178
00179 typedef typename IteratorSelector::raw_line_iterator raw_line_iterator;
00180 typedef typename IteratorSelector::line_iterator line_iterator;
00181 typedef typename IteratorSelector::active_line_iterator active_line_iterator;
00182
00183 typedef typename IteratorSelector::raw_quad_iterator raw_quad_iterator;
00184 typedef typename IteratorSelector::quad_iterator quad_iterator;
00185 typedef typename IteratorSelector::active_quad_iterator active_quad_iterator;
00186
00187 typedef typename IteratorSelector::raw_hex_iterator raw_hex_iterator;
00188 typedef typename IteratorSelector::hex_iterator hex_iterator;
00189 typedef typename IteratorSelector::active_hex_iterator active_hex_iterator;
00190
00191 typedef typename IteratorSelector::raw_cell_iterator raw_cell_iterator;
00192 typedef typename IteratorSelector::cell_iterator cell_iterator;
00193 typedef typename IteratorSelector::active_cell_iterator active_cell_iterator;
00194
00195 typedef typename IteratorSelector::raw_face_iterator raw_face_iterator;
00196 typedef typename IteratorSelector::face_iterator face_iterator;
00197 typedef typename IteratorSelector::active_face_iterator active_face_iterator;
00198
00203 typedef typename ::FunctionMap<spacedim>::type FunctionMap;
00204
00209 static const unsigned int dimension = dim;
00210
00215 static const unsigned int space_dimension = spacedim;
00216
00232 static const unsigned int invalid_dof_index = numbers::invalid_unsigned_int;
00233
00254 static const unsigned int default_fe_index = 0;
00255
00264 DoFHandler ();
00265
00270 DoFHandler ( const Triangulation<dim,spacedim> &tria);
00271
00275 virtual ~DoFHandler ();
00276
00284 void initialize(const Triangulation<dim,spacedim>& tria,
00285 const FiniteElement<dim,spacedim>& fe);
00286
00320 virtual void distribute_dofs (const FiniteElement<dim,spacedim> &fe,
00321 const unsigned int offset = 0);
00322
00334 void initialize_local_block_info();
00335
00342 virtual void clear ();
00343
00412 void renumber_dofs (const std::vector<unsigned int> &new_numbers);
00413
00466 unsigned int max_couplings_between_dofs () const;
00467
00483 unsigned int max_couplings_between_boundary_dofs () const;
00484
00498 raw_cell_iterator begin_raw (const unsigned int level = 0) const;
00499
00507 cell_iterator begin (const unsigned int level = 0) const;
00508
00516 active_cell_iterator begin_active(const unsigned int level = 0) const;
00517
00527 raw_cell_iterator end () const;
00528
00535 cell_iterator end (const unsigned int level) const;
00536
00543 raw_cell_iterator end_raw (const unsigned int level) const;
00544
00551 active_cell_iterator end_active (const unsigned int level) const;
00552
00560 raw_cell_iterator last_raw () const;
00561
00569 raw_cell_iterator last_raw (const unsigned int level) const;
00570
00578 cell_iterator last () const;
00579
00587 cell_iterator last (const unsigned int level) const;
00588
00596 active_cell_iterator last_active () const;
00597
00605 active_cell_iterator last_active (const unsigned int level) const;
00607
00608
00609
00623 raw_face_iterator begin_raw_face () const;
00624
00632 face_iterator begin_face () const;
00633
00641 active_face_iterator begin_active_face() const;
00642
00652 raw_face_iterator end_face () const;
00653
00660 raw_face_iterator end_raw_face () const;
00661
00668 active_face_iterator end_active_face () const;
00669
00677 raw_face_iterator last_raw_face () const;
00678
00686 face_iterator last_face () const;
00687
00695 face_iterator last_face (const unsigned int level) const;
00696
00704 active_face_iterator last_active_face () const;
00705
00707
00708
00709
00710
00721 raw_line_iterator begin_raw_line (const unsigned int level = 0) const;
00722
00727 line_iterator begin_line (const unsigned int level = 0) const;
00728
00733 active_line_iterator begin_active_line(const unsigned int level = 0) const;
00734
00741 raw_line_iterator end_line () const;
00742
00749 line_iterator end_line (const unsigned int level) const;
00750
00757 raw_line_iterator end_raw_line (const unsigned int level) const;
00758
00765 active_line_iterator end_active_line (const unsigned int level) const;
00766
00767
00772 raw_line_iterator last_raw_line () const;
00773
00779 raw_line_iterator last_raw_line (const unsigned int level) const;
00780
00785 line_iterator last_line () const;
00786
00791 line_iterator last_line (const unsigned int level) const;
00792
00797 active_line_iterator last_active_line () const;
00798
00803 active_line_iterator last_active_line (const unsigned int level) const;
00806
00807
00810
00818 raw_quad_iterator begin_raw_quad (const unsigned int level = 0) const;
00819
00824 quad_iterator begin_quad (const unsigned int level = 0) const;
00825
00830 active_quad_iterator begin_active_quad(const unsigned int level = 0) const;
00831
00838 raw_quad_iterator end_quad () const;
00839
00846 quad_iterator end_quad (const unsigned int level) const;
00847
00854 raw_quad_iterator end_raw_quad (const unsigned int level) const;
00855
00862 active_quad_iterator end_active_quad (const unsigned int level) const;
00863
00864
00869 raw_quad_iterator last_raw_quad () const;
00870
00876 raw_quad_iterator last_raw_quad (const unsigned int level) const;
00877
00882 quad_iterator last_quad () const;
00883
00888 quad_iterator last_quad (const unsigned int level) const;
00889
00894 active_quad_iterator last_active_quad () const;
00895
00900 active_quad_iterator last_active_quad (const unsigned int level) const;
00903
00904
00907
00915 raw_hex_iterator
00916 begin_raw_hex (const unsigned int level = 0) const;
00917
00922 hex_iterator
00923 begin_hex (const unsigned int level = 0) const;
00924
00929 active_hex_iterator
00930 begin_active_hex(const unsigned int level = 0) const;
00931
00938 raw_hex_iterator
00939 end_hex () const;
00940
00947 hex_iterator end_hex (const unsigned int level) const;
00948
00955 raw_hex_iterator end_raw_hex (const unsigned int level) const;
00956
00963 active_hex_iterator end_active_hex (const unsigned int level) const;
00964
00969 raw_hex_iterator
00970 last_raw_hex () const;
00971
00977 raw_hex_iterator
00978 last_raw_hex (const unsigned int level) const;
00979
00984 hex_iterator
00985 last_hex () const;
00986
00991 hex_iterator
00992 last_hex (const unsigned int level) const;
00993
00998 active_hex_iterator
00999 last_active_hex () const;
01000
01005 active_hex_iterator
01006 last_active_hex (const unsigned int level) const;
01009
01010
01011
01043 unsigned int n_dofs () const;
01044
01049 unsigned int n_boundary_dofs () const;
01050
01064 unsigned int
01065 n_boundary_dofs (const FunctionMap &boundary_indicators) const;
01066
01075 unsigned int
01076 n_boundary_dofs (const std::set<types::boundary_id_t> &boundary_indicators) const;
01077
01104 const BlockInfo& block_info() const;
01105
01106
01137 unsigned int n_locally_owned_dofs() const;
01138
01147 const IndexSet & locally_owned_dofs() const;
01148
01149
01166 const std::vector<IndexSet> &
01167 locally_owned_dofs_per_processor () const;
01168
01195 const std::vector<unsigned int> &
01196 n_locally_owned_dofs_per_processor () const;
01197
01203 const FiniteElement<dim,spacedim> & get_fe () const;
01204
01210 const Triangulation<dim,spacedim> & get_tria () const;
01211
01224 virtual std::size_t memory_consumption () const;
01225
01231 template <class Archive>
01232 void save (Archive & ar, const unsigned int version) const;
01233
01239 template <class Archive>
01240 void load (Archive & ar, const unsigned int version);
01241
01242 BOOST_SERIALIZATION_SPLIT_MEMBER()
01243
01244
01252 DeclException0 (ExcRenumberingIncomplete);
01257 DeclException0 (ExcGridsDoNotMatch);
01262 DeclException0 (ExcInvalidBoundaryIndicator);
01267 DeclException1 (ExcNewNumbersNotConsecutive,
01268 int,
01269 << "The given list of new dof indices is not consecutive: "
01270 << "the index " << arg1 << " does not exist.");
01275 DeclException1 (ExcInvalidLevel,
01276 int,
01277 << "The given level " << arg1
01278 << " is not in the valid range!");
01283 DeclException0 (ExcFacesHaveNoLevel);
01289 DeclException1 (ExcEmptyLevel,
01290 int,
01291 << "You tried to do something on level " << arg1
01292 << ", but this level is empty.");
01293
01294
01295 protected:
01300 BlockInfo block_info_object;
01301
01307 std::vector<unsigned int> vertex_dofs;
01308
01309
01310
01315 SmartPointer<const Triangulation<dim,spacedim>,DoFHandler<dim,spacedim> >
01316 tria;
01317
01330 SmartPointer<const FiniteElement<dim,spacedim>,DoFHandler<dim,spacedim> >
01331 selected_fe;
01332
01338 std_cxx1x::shared_ptr<internal::DoFHandler::Policy::PolicyBase<dim,spacedim> > policy;
01339
01351 internal::DoFHandler::NumberCache number_cache;
01352
01353 private:
01354
01364 DoFHandler (const DoFHandler &);
01365
01375 DoFHandler & operator = (const DoFHandler &);
01376
01380 void clear_space ();
01381
01389 std::vector<internal::DoFHandler::DoFLevel<dim>*> levels;
01390
01399 internal::DoFHandler::DoFFaces<dim> *faces;
01400
01404 template <int, class> friend class DoFAccessor;
01405 template <class> friend class DoFCellAccessor;
01406 friend struct internal::DoFAccessor::Implementation;
01407 friend struct internal::DoFCellAccessor::Implementation;
01408
01409 friend struct internal::DoFHandler::Implementation;
01410 friend struct internal::DoFHandler::Policy::Implementation;
01411 };
01412
01413
01414
01415
01416
01417
01418 #ifndef DOXYGEN
01419
01420 template <> unsigned int DoFHandler<1>::n_boundary_dofs () const;
01421 template <> unsigned int DoFHandler<1>::n_boundary_dofs (const FunctionMap &) const;
01422 template <> unsigned int DoFHandler<1>::n_boundary_dofs (const std::set<types::boundary_id_t> &) const;
01423
01424
01425
01426
01427
01428 template <int dim, int spacedim>
01429 inline
01430 unsigned int
01431 DoFHandler<dim,spacedim>::n_dofs () const
01432 {
01433 return number_cache.n_global_dofs;
01434 }
01435
01436
01437 template <int dim, int spacedim>
01438 unsigned int
01439 DoFHandler<dim, spacedim>::n_locally_owned_dofs() const
01440 {
01441 return number_cache.n_locally_owned_dofs;
01442 }
01443
01444
01445 template <int dim, int spacedim>
01446 const IndexSet &
01447 DoFHandler<dim, spacedim>::locally_owned_dofs() const
01448 {
01449 return number_cache.locally_owned_dofs;
01450 }
01451
01452
01453 template <int dim, int spacedim>
01454 const std::vector<unsigned int> &
01455 DoFHandler<dim, spacedim>::n_locally_owned_dofs_per_processor() const
01456 {
01457 return number_cache.n_locally_owned_dofs_per_processor;
01458 }
01459
01460
01461 template <int dim, int spacedim>
01462 const std::vector<IndexSet> &
01463 DoFHandler<dim, spacedim>::locally_owned_dofs_per_processor () const
01464 {
01465 return number_cache.locally_owned_dofs_per_processor;
01466 }
01467
01468
01469
01470 template <int dim, int spacedim>
01471 inline
01472 const FiniteElement<dim,spacedim> &
01473 DoFHandler<dim,spacedim>::get_fe () const
01474 {
01475 Assert(selected_fe!=0, ExcNotInitialized());
01476 return *selected_fe;
01477 }
01478
01479
01480 template <int dim, int spacedim>
01481 inline
01482 const Triangulation<dim,spacedim> &
01483 DoFHandler<dim,spacedim>::get_tria () const
01484 {
01485 Assert(tria != 0, ExcNotInitialized());
01486 return *tria;
01487 }
01488
01489
01490 template <int dim, int spacedim>
01491 inline
01492 const BlockInfo&
01493 DoFHandler<dim,spacedim>::block_info () const
01494 {
01495 return block_info_object;
01496 }
01497
01498
01499 template <int dim, int spacedim>
01500 template <class Archive>
01501 void DoFHandler<dim,spacedim>::save (Archive & ar,
01502 const unsigned int) const
01503 {
01504 ar & block_info_object;
01505 ar & vertex_dofs;
01506 ar & number_cache;
01507 ar & levels;
01508 ar & faces;
01509
01510
01511
01512
01513 unsigned int n_cells = tria->n_cells();
01514 std::string fe_name = selected_fe->get_name();
01515 std::string policy_name = typeid(*policy).name();
01516
01517 ar & n_cells & fe_name & policy_name;
01518 }
01519
01520
01521 template <int dim, int spacedim>
01522 template <class Archive>
01523 void DoFHandler<dim,spacedim>::load (Archive & ar,
01524 const unsigned int)
01525 {
01526 ar & block_info_object;
01527 ar & vertex_dofs;
01528 ar & number_cache;
01529
01530
01531
01532
01533
01534 for (unsigned int i=0; i<levels.size(); ++i)
01535 delete levels[i];
01536 levels.resize (0);
01537 delete faces;
01538 faces = 0;
01539
01540 ar & levels;
01541 ar & faces;
01542
01543
01544 unsigned int n_cells;
01545 std::string fe_name;
01546 std::string policy_name;
01547
01548 ar & n_cells & fe_name & policy_name;
01549
01550 AssertThrow (n_cells == tria->n_cells(),
01551 ExcMessage ("The object being loaded into does not match the triangulation "
01552 "that has been stored previously."));
01553 AssertThrow (fe_name == selected_fe->get_name(),
01554 ExcMessage ("The finite element associated with this DoFHandler does not match "
01555 "the one that was associated with the DoFHandler previously stored."));
01556 AssertThrow (policy_name == typeid(*policy).name(),
01557 ExcMessage ("The policy associated with this DoFHandler does not match "
01558 "the one that was associated with the DoFHandler previously stored."));
01559 }
01560
01561
01562 #endif // DOXYGEN
01563
01564 DEAL_II_NAMESPACE_CLOSE
01565
01566
01567 #endif
01568
01569