00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012 #ifndef __deal2__tria_accessor_h
00013 #define __deal2__tria_accessor_h
00014
00015
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/exceptions.h>
00018 #include <deal.II/base/geometry_info.h>
00019 #include <deal.II/base/point.h>
00020 #include <deal.II/grid/tria_iterator_base.h>
00021 #include <deal.II/grid/tria_iterator_selector.h>
00022
00023
00024 namespace std
00025 {
00026 template<class T1, class T2>
00027 struct pair;
00028 }
00029
00030 DEAL_II_NAMESPACE_OPEN
00031
00032 template <int dim, int spacedim> class Triangulation;
00033 template <typename Accessor> class TriaRawIterator;
00034 template <typename Accessor> class TriaIterator;
00035 template <typename Accessor> class TriaActiveIterator;
00036
00037 template <int dim, int spacedim> class Boundary;
00038
00039
00040 namespace internal
00041 {
00042 namespace Triangulation
00043 {
00044 template <int dim> class TriaObject;
00045 template <typename G> class TriaObjects;
00046 struct Implementation;
00047 }
00048
00049 namespace TriaAccessor
00050 {
00051 struct Implementation;
00052
00062 template <int structdim, int dim> struct PresentLevelType
00063 {
00064 struct type
00065 {
00069 type ()
00070 {}
00071
00077 type (const int level)
00078 {
00079 Assert (level == 0, ExcInternalError());
00080 }
00081
00087 operator int () const
00088 {
00089 return 0;
00090 }
00091
00092 void operator ++ () const
00093 {
00094 Assert (false, ExcInternalError());
00095 }
00096
00097 void operator -- () const
00098 {
00099 Assert (false, ExcInternalError());
00100 }
00101 };
00102 };
00103
00104
00114 template <int dim> struct PresentLevelType<dim,dim>
00115 {
00116 typedef int type;
00117 };
00118
00119 }
00120 }
00121 template <int structdim, int dim, int spacedim> class TriaAccessor;
00122 template <int dim, int spacedim> class TriaAccessor<0, dim, spacedim>;
00123 template <int spacedim> class TriaAccessor<0, 1, spacedim>;
00124
00125
00126
00127
00128
00129
00130
00134 namespace TriaAccessorExceptions
00135 {
00136
00140 DeclException0 (ExcCellNotUsed);
00152 DeclException0 (ExcCellNotActive);
00159 DeclException0 (ExcCellHasNoChildren);
00167 DeclException0 (ExcCellHasNoParent);
00168
00172 DeclException0 (ExcUnusedCellAsChild);
00173
00177 DeclException1 (ExcCantSetChildren,
00178 int,
00179 << "You can only set the child index if the cell has no "
00180 << "children, or clear it. The given "
00181 << "index was " << arg1 << " (-1 means: clear children)");
00182
00186 DeclException0 (ExcUnusedCellAsNeighbor);
00187
00191 DeclException0 (ExcUncaughtCase);
00192
00196 DeclException0 (ExcDereferenceInvalidObject);
00197
00201 DeclException0 (ExcCantCompareIterators);
00202
00206 DeclException0 (ExcNeighborIsCoarser);
00207
00211 DeclException0 (ExcNeighborIsNotCoarser);
00223 DeclException0 (ExcFacesHaveNoLevel);
00224
00228 DeclException1 (ExcSetOnlyEvenChildren,
00229 int,
00230 << "You can only set the child index of an even numbered child."
00231 << "The number of the child given was " << arg1 << ".");
00232 }
00233
00234
00260 template <int structdim, int dim, int spacedim=dim>
00261 class TriaAccessorBase
00262 {
00263 public:
00275 static const unsigned int space_dimension = spacedim;
00276
00286 static const unsigned int dimension = dim;
00287
00298 static const unsigned int structure_dimension = structdim;
00299
00300 protected:
00310 typedef void AccessorData;
00311
00317 TriaAccessorBase (const Triangulation<dim,spacedim> *parent = 0,
00318 const int level = -1,
00319 const int index = -1,
00320 const AccessorData * = 0);
00321
00326 TriaAccessorBase (const TriaAccessorBase &);
00327
00339 void copy_from (const TriaAccessorBase &);
00340
00345 TriaAccessorBase & operator = (const TriaAccessorBase &);
00346
00347 protected:
00365 void operator = (const TriaAccessorBase *);
00366
00370 bool operator == (const TriaAccessorBase &) const;
00371
00375 bool operator != (const TriaAccessorBase &) const;
00376
00395 void operator ++ ();
00396
00410 void operator -- ();
00420 internal::Triangulation::TriaObjects<internal::Triangulation::TriaObject<structdim> > &
00421 objects () const;
00422
00423 public:
00431 typedef void * LocalData;
00432
00445 int level () const;
00446
00470 int index () const;
00471
00480 IteratorState::IteratorStates state () const;
00481
00488 const Triangulation<dim,spacedim> & get_triangulation () const;
00489
00493 protected:
00499 typename internal::TriaAccessor::PresentLevelType<structdim,dim>::type present_level;
00500
00507 int present_index;
00508
00513 const Triangulation<dim,spacedim> *tria;
00514
00515 private:
00516
00517 template <typename Accessor> friend class TriaRawIterator;
00518 template <typename Accessor> friend class TriaIterator;
00519 template <typename Accessor> friend class TriaActiveIterator;
00520 };
00521
00522
00523
00546 template <int structdim, int dim, int spacedim=dim>
00547 class InvalidAccessor : public TriaAccessorBase<structdim,dim,spacedim>
00548 {
00549 public:
00554 typedef typename TriaAccessorBase<structdim,dim,spacedim>::AccessorData AccessorData;
00555
00569 InvalidAccessor (const Triangulation<dim,spacedim> *parent = 0,
00570 const int level = -1,
00571 const int index = -1,
00572 const AccessorData *local_data = 0);
00573
00587 InvalidAccessor (const InvalidAccessor &);
00588
00596 template <typename OtherAccessor>
00597 InvalidAccessor (const OtherAccessor &);
00598
00602 void copy_from (const InvalidAccessor &);
00603
00607 bool operator == (const InvalidAccessor &) const;
00608 bool operator != (const InvalidAccessor &) const;
00609
00614 void operator ++ () const;
00615 void operator -- () const;
00616
00622 bool used () const;
00623
00629 bool has_children () const;
00630 };
00631
00632
00633
00650 template <int structdim, int dim, int spacedim>
00651 class TriaAccessor : public TriaAccessorBase<structdim, dim, spacedim>
00652 {
00653 public:
00658 typedef
00659 typename TriaAccessorBase<structdim,dim,spacedim>::AccessorData
00660 AccessorData;
00661
00665 TriaAccessor (const Triangulation<dim,spacedim> *parent = 0,
00666 const int level = -1,
00667 const int index = -1,
00668 const AccessorData *local_data = 0);
00669
00691 template <int structdim2, int dim2, int spacedim2>
00692 TriaAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &);
00693
00700 template <int structdim2, int dim2, int spacedim2>
00701 TriaAccessor (const TriaAccessor<structdim2,dim2,spacedim2> &);
00702
00716 bool used () const;
00717
00727 int parent_index () const;
00728
00729
00753 unsigned int vertex_index (const unsigned int i) const;
00754
00759 Point<spacedim> & vertex (const unsigned int i) const;
00760
00765 typename internal::Triangulation::Iterators<dim,spacedim>::line_iterator
00766 line (const unsigned int i) const;
00767
00777 unsigned int line_index (const unsigned int i) const;
00778
00783 typename internal::Triangulation::Iterators<dim,spacedim>::quad_iterator
00784 quad (const unsigned int i) const;
00785
00795 unsigned int quad_index (const unsigned int i) const;
00829 bool face_orientation (const unsigned int face) const;
00830
00845 bool face_flip (const unsigned int face) const;
00846
00861 bool face_rotation (const unsigned int face) const;
00862
00880 bool line_orientation (const unsigned int line) const;
00896 bool has_children () const;
00897
00904 unsigned int n_children() const;
00905
00930 unsigned int number_of_children () const;
00931
00953 unsigned int max_refinement_depth () const;
00954
00959 TriaIterator<TriaAccessor<structdim,dim,spacedim> >
00960 child (const unsigned int i) const;
00961
00976 TriaIterator<TriaAccessor<structdim,dim,spacedim> >
00977 isotropic_child (const unsigned int i) const;
00978
00983 RefinementCase<structdim> refinement_case () const;
00984
00995 int child_index (const unsigned int i) const;
00996
01004 int isotropic_child_index (const unsigned int i) const;
01025 types::boundary_id_t boundary_indicator () const;
01026
01069 void set_boundary_indicator (const types::boundary_id_t) const;
01070
01087 void set_all_boundary_indicators (const types::boundary_id_t) const;
01088
01100 bool at_boundary () const;
01101
01112 const Boundary<dim,spacedim> & get_boundary () const;
01113
01128 bool user_flag_set () const;
01129
01133 void set_user_flag () const;
01134
01138 void clear_user_flag () const;
01139
01144 void recursively_set_user_flag () const;
01145
01150 void recursively_clear_user_flag () const;
01151
01156 void clear_user_data () const;
01157
01170 void set_user_pointer (void *p) const;
01171
01176 void clear_user_pointer () const;
01177
01198 void * user_pointer () const;
01199
01235 void recursively_set_user_pointer (void *p) const;
01236
01245 void recursively_clear_user_pointer () const;
01246
01259 void set_user_index (const unsigned int p) const;
01260
01264 void clear_user_index () const;
01265
01278 unsigned int user_index () const;
01279
01306 void recursively_set_user_index (const unsigned int p) const;
01307
01316 void recursively_clear_user_index () const;
01338 double diameter () const;
01339
01355 double extent_in_direction (const unsigned int axis) const;
01356
01361 double minimum_vertex_distance () const;
01362
01375 Point<spacedim> center () const;
01376
01380 Point<spacedim> barycenter () const;
01381
01390 double measure () const;
01391
01418 bool
01419 is_translation_of (const TriaIterator<TriaAccessor<structdim,dim,spacedim> > &o) const;
01420
01426 private:
01433 void set (const internal::Triangulation::TriaObject<structdim> &o) const;
01434
01445 void set_line_orientation (const unsigned int line,
01446 const bool orientation) const;
01447
01467 void set_face_orientation (const unsigned int face,
01468 const bool orientation) const;
01469
01480 void set_face_flip (const unsigned int face,
01481 const bool flip) const;
01482
01493 void set_face_rotation (const unsigned int face,
01494 const bool rotation) const;
01495
01501 void set_used_flag () const;
01502
01508 void clear_used_flag () const;
01509
01525 void set_refinement_case (const RefinementCase<structdim> &ref_case) const;
01526
01538 void clear_refinement_case () const;
01539
01543 void set_parent (const unsigned int parent_index);
01544
01558 void set_children (const unsigned int i, const int index) const;
01559
01566 void clear_children () const;
01567
01568 private:
01586 void operator = (const TriaAccessor &);
01587
01588 template <int, int> friend class Triangulation;
01589
01590 friend struct internal::Triangulation::Implementation;
01591 friend struct internal::TriaAccessor::Implementation;
01592 };
01593
01594
01595
01596
01597
01598
01605 template<int dim, int spacedim>
01606 class TriaAccessor<0, dim, spacedim>
01607 {
01608 private:
01614 TriaAccessor ();
01615 };
01616
01617
01618
01628 template <int spacedim>
01629 class TriaAccessor<0, 1, spacedim>
01630 {
01631 public:
01643 static const unsigned int space_dimension = spacedim;
01644
01654 static const unsigned int dimension = 1;
01655
01666 static const unsigned int structure_dimension = 0;
01667
01671 typedef void AccessorData;
01672
01679 enum VertexKind
01680 {
01681 left_vertex,
01682 interior_vertex,
01683 right_vertex
01684 };
01685
01706 TriaAccessor (const Triangulation<1,spacedim> * tria,
01707 const VertexKind vertex_kind,
01708 const unsigned int vertex_index);
01709
01719 TriaAccessor (const Triangulation<1,spacedim> * = 0,
01720 const int = 0,
01721 const int = 0,
01722 const AccessorData * = 0);
01723
01729 template <int structdim2, int dim2, int spacedim2>
01730 TriaAccessor (const TriaAccessor<structdim2,dim2,spacedim2> &);
01731
01737 template <int structdim2, int dim2, int spacedim2>
01738 TriaAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &);
01739
01751 void copy_from (const TriaAccessor &);
01752
01762 static IteratorState::IteratorStates state ();
01763
01769 static int level ();
01770
01776 int index () const;
01777
01792 void operator ++ () const;
01793
01802 void operator -- () const;
01806 bool operator == (const TriaAccessor &) const;
01807
01811 bool operator != (const TriaAccessor &) const;
01812
01821 static int parent_index ();
01822
01847 unsigned int vertex_index (const unsigned int i = 0) const;
01848
01857 Point<spacedim> & vertex (const unsigned int i = 0) const;
01858
01865 Point<spacedim> center () const;
01866
01872 typename internal::Triangulation::Iterators<1,spacedim>::line_iterator
01873 static line (const unsigned int);
01874
01884 static unsigned int line_index (const unsigned int i);
01885
01890 static
01891 typename internal::Triangulation::Iterators<1,spacedim>::quad_iterator
01892 quad (const unsigned int i);
01893
01903 static unsigned int quad_index (const unsigned int i);
01904
01916 bool at_boundary () const;
01917
01932 types::boundary_id_t boundary_indicator () const;
01933
01944 static bool face_orientation (const unsigned int face);
01945
01949 static bool face_flip (const unsigned int face);
01950
01954 static bool face_rotation (const unsigned int face);
01955
01959 static bool line_orientation (const unsigned int line);
01960
01976 static bool has_children ();
01977
01983 static unsigned int n_children();
01984
01990 static unsigned int number_of_children ();
01991
01997 static unsigned int max_refinement_depth ();
01998
02002 static
02003 TriaIterator<TriaAccessor<0,1,spacedim> >
02004 child (const unsigned int);
02005
02009 static
02010 TriaIterator<TriaAccessor<0,1,spacedim> >
02011 isotropic_child (const unsigned int);
02012
02016 static
02017 RefinementCase<0> refinement_case ();
02018
02022 static
02023 int child_index (const unsigned int i);
02024
02028 static
02029 int isotropic_child_index (const unsigned int i);
02030
02057 void
02058 set_boundary_indicator (const types::boundary_id_t);
02059
02066 void
02067 set_all_boundary_indicators (const types::boundary_id_t);
02068
02073 bool used () const;
02074
02075 protected:
02080 const Triangulation<1,spacedim> * tria;
02081
02089 VertexKind vertex_kind;
02090
02096 unsigned int global_vertex_index;
02097 };
02098
02099
02100
02101
02118 template <int dim, int spacedim=dim>
02119 class CellAccessor : public TriaAccessor<dim,dim,spacedim>
02120 {
02121 public:
02126 typedef typename TriaAccessor<dim,dim,spacedim>::AccessorData AccessorData;
02127
02132 typedef Triangulation<dim, spacedim> Container;
02133
02144 CellAccessor (const Triangulation<dim,spacedim> *parent = 0,
02145 const int level = -1,
02146 const int index = -1,
02147 const AccessorData *local_data = 0);
02148
02152 CellAccessor (const CellAccessor &cell_accessor);
02153
02175 template <int structdim2, int dim2, int spacedim2>
02176 CellAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &);
02177
02184 template <int structdim2, int dim2, int spacedim2>
02185 CellAccessor (const TriaAccessor<structdim2,dim2,spacedim2> &);
02186
02204 TriaIterator<CellAccessor<dim, spacedim> >
02205 child (const unsigned int i) const;
02206
02215 TriaIterator<TriaAccessor<dim-1,dim,spacedim> >
02216 face (const unsigned int i) const;
02217
02228 unsigned int
02229 face_index (const unsigned int i) const;
02230
02322 TriaIterator<CellAccessor<dim, spacedim> >
02323 neighbor_child_on_subface (const unsigned int face_no,
02324 const unsigned int subface_no) const;
02325
02337 TriaIterator<CellAccessor<dim, spacedim> >
02338 neighbor (const unsigned int i) const;
02339
02346 int neighbor_index (const unsigned int i) const;
02347
02354 int neighbor_level (const unsigned int i) const;
02355
02377 unsigned int neighbor_of_neighbor (const unsigned int neighbor) const;
02378
02400 bool neighbor_is_coarser (const unsigned int neighbor) const;
02401
02420 std::pair<unsigned int, unsigned int>
02421 neighbor_of_coarser_neighbor (const unsigned int neighbor) const;
02422
02432 unsigned int neighbor_face_no (const unsigned int neighbor) const;
02433
02453 bool at_boundary (const unsigned int i) const;
02454
02473 bool at_boundary () const;
02474
02488 bool has_boundary_lines () const;
02506 RefinementCase<dim> refine_flag_set () const;
02507
02514 void set_refine_flag (const RefinementCase<dim> ref_case = RefinementCase<dim>::isotropic_refinement) const;
02515
02519 void clear_refine_flag () const;
02520
02532 bool flag_for_face_refinement (const unsigned int face_no,
02533 const RefinementCase<dim-1> &face_refinement_case=RefinementCase<dim-1>::isotropic_refinement) const;
02534
02543 bool flag_for_line_refinement (const unsigned int line_no) const;
02544
02559 internal::SubfaceCase<dim> subface_case(const unsigned int face_no) const;
02560
02565 bool coarsen_flag_set () const;
02566
02573 void set_coarsen_flag () const;
02574
02578 void clear_coarsen_flag () const;
02602 types::material_id_t material_id () const;
02603
02616 void set_material_id (const types::material_id_t new_material_id) const;
02617
02628 void recursively_set_material_id (const types::material_id_t new_material_id) const;
02652 types::subdomain_id_t subdomain_id () const;
02653
02666 void set_subdomain_id (const types::subdomain_id_t new_subdomain_id) const;
02667
02682 void recursively_set_subdomain_id (const types::subdomain_id_t new_subdomain_id) const;
02701 bool direction_flag () const;
02702
02703
02704
02709 TriaIterator<CellAccessor<dim,spacedim> >
02710 parent () const;
02711
02731 bool active () const;
02732
02748 bool is_locally_owned () const;
02749
02777 bool is_ghost () const;
02778
02815 bool is_artificial () const;
02816
02840 bool point_inside (const Point<spacedim> &p) const;
02841
02855 void set_neighbor (const unsigned int i,
02856 const TriaIterator<CellAccessor<dim, spacedim> > &pointer) const;
02857
02866 DeclException0 (ExcRefineCellNotActive);
02870 DeclException0 (ExcCellFlaggedForRefinement);
02874 DeclException0 (ExcCellFlaggedForCoarsening);
02875
02876 protected:
02910 unsigned int neighbor_of_neighbor_internal (const unsigned int neighbor) const;
02911
02918 template<int dim_,int spacedim_ >
02919 bool point_inside_codim(const Point<spacedim_> &p) const;
02920
02921
02922
02923 private:
02931 void set_direction_flag (const bool new_direction_flag) const;
02952 void operator = (const CellAccessor<dim, spacedim> &);
02953
02954 template <int, int> friend class Triangulation;
02955
02956 friend struct internal::Triangulation::Implementation;
02957 };
02958
02959
02960
02961
02962
02963
02964
02965 template <int structdim, int dim, int spacedim>
02966 template <typename OtherAccessor>
02967 InvalidAccessor<structdim, dim, spacedim>::
02968 InvalidAccessor (const OtherAccessor &)
02969 {
02970 Assert (false,
02971 ExcMessage ("You are attempting an illegal conversion between "
02972 "iterator/accessor types. The constructor you call "
02973 "only exists to make certain template constructs "
02974 "easier to write as dimension independent code but "
02975 "the conversion is not valid in the current context."));
02976 }
02977
02978
02979
02980 template <int structdim, int dim, int spacedim>
02981 template <int structdim2, int dim2, int spacedim2>
02982 TriaAccessor<structdim,dim,spacedim>::
02983 TriaAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &)
02984 {
02985 Assert (false,
02986 ExcMessage ("You are attempting an illegal conversion between "
02987 "iterator/accessor types. The constructor you call "
02988 "only exists to make certain template constructs "
02989 "easier to write as dimension independent code but "
02990 "the conversion is not valid in the current context."));
02991 }
02992
02993
02994
02995 template <int dim, int spacedim>
02996 template <int structdim2, int dim2, int spacedim2>
02997 CellAccessor<dim,spacedim>::
02998 CellAccessor (const InvalidAccessor<structdim2,dim2,spacedim2> &)
02999 {
03000 Assert (false,
03001 ExcMessage ("You are attempting an illegal conversion between "
03002 "iterator/accessor types. The constructor you call "
03003 "only exists to make certain template constructs "
03004 "easier to write as dimension independent code but "
03005 "the conversion is not valid in the current context."));
03006 }
03007
03008
03009
03010 template <int structdim, int dim, int spacedim>
03011 template <int structdim2, int dim2, int spacedim2>
03012 TriaAccessor<structdim,dim,spacedim>::
03013 TriaAccessor (const TriaAccessor<structdim2,dim2,spacedim2> &)
03014 {
03015 Assert (false,
03016 ExcMessage ("You are attempting an illegal conversion between "
03017 "iterator/accessor types. The constructor you call "
03018 "only exists to make certain template constructs "
03019 "easier to write as dimension independent code but "
03020 "the conversion is not valid in the current context."));
03021 }
03022
03023
03024
03025 template <int dim, int spacedim>
03026 template <int structdim2, int dim2, int spacedim2>
03027 CellAccessor<dim,spacedim>::
03028 CellAccessor (const TriaAccessor<structdim2,dim2,spacedim2> &)
03029 {
03030 Assert (false,
03031 ExcMessage ("You are attempting an illegal conversion between "
03032 "iterator/accessor types. The constructor you call "
03033 "only exists to make certain template constructs "
03034 "easier to write as dimension independent code but "
03035 "the conversion is not valid in the current context."));
03036 }
03037
03038
03039 #ifndef DOXYGEN
03040
03041 template <> bool CellAccessor<1,1>::point_inside (const Point<1> &) const;
03042 template <> bool CellAccessor<2,2>::point_inside (const Point<2> &) const;
03043 template <> bool CellAccessor<3,3>::point_inside (const Point<3> &) const;
03044 template <> bool CellAccessor<1,2>::point_inside (const Point<2> &) const;
03045 template <> bool CellAccessor<1,3>::point_inside (const Point<3> &) const;
03046 template <> bool CellAccessor<2,3>::point_inside (const Point<3> &) const;
03047
03048
03049 #endif // DOXYGEN
03050
03051 DEAL_II_NAMESPACE_CLOSE
03052
03053
03054 # include "tria_accessor.templates.h"
03055
03056 #endif
03057