00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__tria_objects_h
00013 #define __deal2__tria_objects_h
00014
00015 #include <deal.II/base/config.h>
00016 #include <deal.II/base/exceptions.h>
00017 #include <deal.II/base/geometry_info.h>
00018 #include <deal.II/grid/tria_object.h>
00019
00020 #include <vector>
00021
00022 DEAL_II_NAMESPACE_OPEN
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 template <int dim, int spacedim> class Triangulation;
00038
00039
00040 namespace internal
00041 {
00042 namespace Triangulation
00043 {
00044
00057 template <typename G>
00058 class TriaObjects
00059 {
00060 public:
00064 TriaObjects();
00065
00071 std::vector<G> cells;
00089 std::vector<int> children;
00090
00102 std::vector<RefinementCase<G::dimension> > refinement_cases;
00103
00116 std::vector<bool> used;
00117
00129 std::vector<bool> user_flags;
00130
00152 std::vector<unsigned char> material_id;
00153
00174 void reserve_space (const unsigned int new_objs_in_pairs,
00175 const unsigned int new_objs_single = 0);
00176
00185 template <int dim, int spacedim>
00186 typename ::Triangulation<dim,spacedim>::raw_line_iterator
00187 next_free_single_line (const ::Triangulation<dim,spacedim> &tria);
00188
00196 template <int dim, int spacedim>
00197 typename ::Triangulation<dim,spacedim>::raw_line_iterator
00198 next_free_pair_line (const ::Triangulation<dim,spacedim> &tria);
00199
00208 template <int dim, int spacedim>
00209 typename ::Triangulation<dim,spacedim>::raw_quad_iterator
00210 next_free_single_quad (const ::Triangulation<dim,spacedim> &tria);
00211
00219 template <int dim, int spacedim>
00220 typename ::Triangulation<dim,spacedim>::raw_quad_iterator
00221 next_free_pair_quad (const ::Triangulation<dim,spacedim> &tria);
00222
00230 template <int dim, int spacedim>
00231 typename ::Triangulation<dim,spacedim>::raw_hex_iterator
00232 next_free_hex (const ::Triangulation<dim,spacedim> &tria,
00233 const unsigned int level);
00234
00238 void clear();
00239
00268 bool face_orientation(const unsigned int cell, const unsigned int face) const;
00269
00270
00274 void*& user_pointer(const unsigned int i);
00275
00279 const void* user_pointer(const unsigned int i) const;
00280
00284 unsigned int& user_index(const unsigned int i);
00285
00289 unsigned int user_index(const unsigned int i) const;
00290
00294 void clear_user_data(const unsigned int i);
00295
00302 void clear_user_data();
00303
00307 void clear_user_flags();
00308
00317 void monitor_memory (const unsigned int true_dimension) const;
00318
00324 std::size_t memory_consumption () const;
00325
00330 template <class Archive>
00331 void serialize(Archive & ar,
00332 const unsigned int version);
00333
00337 DeclException3 (ExcMemoryWasted,
00338 char*, int, int,
00339 << "The container " << arg1 << " contains "
00340 << arg2 << " elements, but it`s capacity is "
00341 << arg3 << ".");
00346 DeclException2 (ExcMemoryInexact,
00347 int, int,
00348 << "The containers have sizes " << arg1 << " and "
00349 << arg2 << ", which is not as expected.");
00350
00354 DeclException2 (ExcWrongIterator,
00355 char*, char*,
00356 << "You asked for the next free " << arg1 << "_iterator, "
00357 "but you can only ask for " << arg2 <<"_iterators.");
00358
00370 DeclException0 (ExcPointerIndexClash);
00371
00372 protected:
00376 unsigned int next_free_single;
00377
00381 unsigned int next_free_pair;
00382
00386 bool reverse_order_next_free_single;
00387
00392 struct UserData
00393 {
00394 union Data
00395 {
00398 void* p;
00401 unsigned int i;
00403 };
00404 Data data;
00405
00409 UserData()
00410 {
00411 data.p = 0;
00412 }
00413
00419 template <class Archive>
00420 void serialize (Archive & ar, const unsigned int version);
00421 };
00422
00428 enum UserDataType
00429 {
00431 data_unknown,
00433 data_pointer,
00435 data_index
00436 };
00437
00438
00445 std::vector<UserData> user_data;
00456 mutable UserDataType user_data_type;
00457 };
00458
00465 class TriaObjectsHex : public TriaObjects<TriaObject<3> >
00466 {
00467 public:
00481 bool face_orientation(const unsigned int cell, const unsigned int face) const;
00482
00483
00529 std::vector<bool> face_orientations;
00533 std::vector<bool> face_flips;
00537 std::vector<bool> face_rotations;
00538
00548 void reserve_space (const unsigned int new_objs);
00549
00553 void clear();
00554
00563 void monitor_memory (const unsigned int true_dimension) const;
00564
00570 std::size_t memory_consumption () const;
00571
00576 template <class Archive>
00577 void serialize(Archive & ar,
00578 const unsigned int version);
00579 };
00580
00581
00589 class TriaObjectsQuad3D: public TriaObjects<TriaObject<2> >
00590 {
00591 public:
00605 bool face_orientation(const unsigned int cell, const unsigned int face) const;
00606
00607
00615 std::vector<bool> line_orientations;
00616
00632 void reserve_space (const unsigned int new_quads_in_pairs,
00633 const unsigned int new_quads_single = 0);
00634
00638 void clear();
00639
00648 void monitor_memory (const unsigned int true_dimension) const;
00649
00655 std::size_t memory_consumption () const;
00656
00661 template <class Archive>
00662 void serialize(Archive & ar,
00663 const unsigned int version);
00664 };
00665
00666
00667
00668 template<typename G>
00669 inline
00670 bool
00671 TriaObjects<G>::
00672 face_orientation(const unsigned int, const unsigned int) const
00673 {
00674 return true;
00675 }
00676
00677
00678 template<typename G>
00679 inline
00680 void*&
00681 TriaObjects<G>::user_pointer (const unsigned int i)
00682 {
00683 #ifdef DEBUG
00684 Assert(user_data_type == data_unknown || user_data_type == data_pointer,
00685 ExcPointerIndexClash());
00686 user_data_type = data_pointer;
00687 #endif
00688 Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
00689 return user_data[i].data.p;
00690 }
00691
00692
00693 template<typename G>
00694 inline
00695 const void*
00696 TriaObjects<G>::user_pointer (const unsigned int i) const
00697 {
00698 #ifdef DEBUG
00699 Assert(user_data_type == data_unknown || user_data_type == data_pointer,
00700 ExcPointerIndexClash());
00701 user_data_type = data_pointer;
00702 #endif
00703 Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
00704 return user_data[i].data.p;
00705 }
00706
00707
00708 template<typename G>
00709 inline
00710 unsigned int&
00711 TriaObjects<G>::user_index (const unsigned int i)
00712 {
00713 #ifdef DEBUG
00714 Assert(user_data_type == data_unknown || user_data_type == data_index,
00715 ExcPointerIndexClash());
00716 user_data_type = data_index;
00717 #endif
00718 Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
00719 return user_data[i].data.i;
00720 }
00721
00722
00723 template<typename G>
00724 inline
00725 void
00726 TriaObjects<G>::clear_user_data (const unsigned int i)
00727 {
00728 Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
00729 user_data[i].data.i = 0;
00730 }
00731
00732
00733 template <typename G>
00734 inline
00735 TriaObjects<G>::TriaObjects()
00736 :
00737 reverse_order_next_free_single (false),
00738 user_data_type(data_unknown)
00739 {}
00740
00741
00742 template<typename G>
00743 inline
00744 unsigned int TriaObjects<G>::user_index (const unsigned int i) const
00745 {
00746 #ifdef DEBUG
00747 Assert(user_data_type == data_unknown || user_data_type == data_index,
00748 ExcPointerIndexClash());
00749 user_data_type = data_index;
00750 #endif
00751 Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
00752 return user_data[i].data.i;
00753 }
00754
00755
00756 template<typename G>
00757 inline
00758 void TriaObjects<G>::clear_user_data ()
00759 {
00760 user_data_type = data_unknown;
00761 for (unsigned int i=0;i<user_data.size();++i)
00762 user_data[i].data.p = 0;
00763 }
00764
00765
00766 template<typename G>
00767 inline
00768 void TriaObjects<G>::clear_user_flags ()
00769 {
00770 user_flags.assign(user_flags.size(),false);
00771 }
00772
00773
00774 template<typename G>
00775 template <class Archive>
00776 void
00777 TriaObjects<G>::UserData::serialize (Archive & ar,
00778 const unsigned int)
00779 {
00780
00781 ar & data.i;
00782 }
00783
00784
00785
00786 template <typename G>
00787 template <class Archive>
00788 void TriaObjects<G>::serialize(Archive & ar,
00789 const unsigned int)
00790 {
00791 ar & cells & children;
00792 ar & refinement_cases;
00793 ar & used;
00794 ar & user_flags;
00795 ar & material_id;
00796 ar & next_free_single & next_free_pair & reverse_order_next_free_single;
00797 ar & user_data & user_data_type;
00798 }
00799
00800
00801 template <class Archive>
00802 void TriaObjectsHex::serialize(Archive & ar,
00803 const unsigned int version)
00804 {
00805 this->TriaObjects<TriaObject<3> >::serialize (ar, version);
00806
00807 ar & face_orientations & face_flips & face_rotations;
00808 }
00809
00810
00811 template <class Archive>
00812 void TriaObjectsQuad3D::serialize(Archive & ar,
00813 const unsigned int version)
00814 {
00815 this->TriaObjects<TriaObject<2> >::serialize (ar, version);
00816
00817 ar & line_orientations;
00818 }
00819
00820
00821
00822
00823 inline
00824 bool
00825 TriaObjectsHex::face_orientation(const unsigned int cell,
00826 const unsigned int face) const
00827 {
00828 Assert (cell < face_orientations.size() / GeometryInfo<3>::faces_per_cell,
00829 ExcIndexRange(0, cell, face_orientations.size() / GeometryInfo<3>::faces_per_cell));
00830 Assert (face < GeometryInfo<3>::faces_per_cell,
00831 ExcIndexRange(0, face, GeometryInfo<3>::faces_per_cell));
00832
00833 return face_orientations[cell * GeometryInfo<3>::faces_per_cell
00834 + face];
00835 }
00836
00837
00838
00839 inline
00840 bool
00841 TriaObjectsQuad3D::face_orientation(const unsigned int cell, const unsigned int face) const
00842 {
00843 return line_orientations[cell * GeometryInfo<2>::faces_per_cell
00844 + face];
00845 }
00846
00847
00848
00849
00850
00851 template<>
00852 void
00853 TriaObjects<TriaObject<1> >::reserve_space (const unsigned int new_lines_in_pairs,
00854 const unsigned int new_lines_single);
00855
00856 template<>
00857 void
00858 TriaObjects<TriaObject<2> >::reserve_space (const unsigned int new_quads_in_pairs,
00859 const unsigned int new_quads_single);
00860
00861 template<>
00862 void
00863 TriaObjects<TriaObject<2> >::monitor_memory (const unsigned int) const;
00864
00865 }
00866 }
00867
00868
00869
00870 DEAL_II_NAMESPACE_CLOSE
00871
00872 #endif
00873