Reference documentation for deal.II version 8.1.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Groups Pages
tria_objects.h
1 // ---------------------------------------------------------------------
2 // @f$Id: tria_objects.h 31932 2013-12-08 02:15:54Z heister @f$
3 //
4 // Copyright (C) 2006 - 2013 by the deal.II authors
5 //
6 // This file is part of the deal.II library.
7 //
8 // The deal.II library is free software; you can use it, redistribute
9 // it, and/or modify it under the terms of the GNU Lesser General
10 // Public License as published by the Free Software Foundation; either
11 // version 2.1 of the License, or (at your option) any later version.
12 // The full text of the license can be found in the file LICENSE at
13 // the top level of the deal.II distribution.
14 //
15 // ---------------------------------------------------------------------
16 
17 #ifndef __deal2__tria_objects_h
18 #define __deal2__tria_objects_h
19 
20 #include <deal.II/base/config.h>
22 #include <deal.II/base/geometry_info.h>
23 #include <deal.II/grid/tria_object.h>
24 
25 #include <vector>
26 
27 DEAL_II_NAMESPACE_OPEN
28 
29 //TODO: This should all be cleaned up. Currently, only a single
30 //function in the library makes use of the odd specializations, and
31 //this function is Triangulation::execute_refinement() in 3D. I
32 //assume, that the other refinement functions would profit from using
33 //next_free_single_object() and next_free_pair_object, but they seem
34 //to get around it.
35 
36 //TODO: The TriaObjects class contains a std::vector<G>. This is only an
37 //efficient storage scheme if G is relatively well packed, i.e. it's not a
38 //bool and then an integer and then a double, etc. Verify that this is
39 //actually the case.
40 
41 template <int dim, int spacedim> class Triangulation;
42 template <class Accessor> class TriaRawIterator;
43 template <int, int, int> class TriaAccessor;
44 
45 namespace internal
46 {
47  namespace Triangulation
48  {
49 
62  template <typename G>
64  {
65  public:
69  TriaObjects();
70 
76  std::vector<G> cells;
77 
95  std::vector<int> children;
96 
108  std::vector<RefinementCase<G::dimension> > refinement_cases;
109 
122  std::vector<bool> used;
123 
135  std::vector<bool> user_flags;
136 
137 
147  {
148  union
149  {
150  types::boundary_id boundary_id;
151  types::material_id material_id;
152  };
153 
154 
159 
164  static
165  std::size_t memory_consumption ();
166 
174  template <class Archive>
175  void serialize(Archive &ar,
176  const unsigned int version);
177  };
178 
203  std::vector<BoundaryOrMaterialId> boundary_or_material_id;
204 
225  void reserve_space (const unsigned int new_objs_in_pairs,
226  const unsigned int new_objs_single = 0);
227 
249  template <int dim, int spacedim>
251  next_free_single_object (const ::Triangulation<dim,spacedim> &tria);
252 
274  template <int dim, int spacedim>
276  next_free_pair_object (const ::Triangulation<dim,spacedim> &tria);
277 
285  template <int dim, int spacedim>
286  typename ::Triangulation<dim,spacedim>::raw_hex_iterator
287  next_free_hex (const ::Triangulation<dim,spacedim> &tria,
288  const unsigned int level);
289 
293  void clear();
294 
323  bool face_orientation(const unsigned int cell, const unsigned int face) const;
324 
325 
329  void *&user_pointer(const unsigned int i);
330 
334  const void *user_pointer(const unsigned int i) const;
335 
339  unsigned int &user_index(const unsigned int i);
340 
344  unsigned int user_index(const unsigned int i) const;
345 
349  void clear_user_data(const unsigned int i);
350 
357  void clear_user_data();
358 
362  void clear_user_flags();
363 
372  void monitor_memory (const unsigned int true_dimension) const;
373 
379  std::size_t memory_consumption () const;
380 
385  template <class Archive>
386  void serialize(Archive &ar,
387  const unsigned int version);
388 
392  DeclException3 (ExcMemoryWasted,
393  char *, int, int,
394  << "The container " << arg1 << " contains "
395  << arg2 << " elements, but it`s capacity is "
396  << arg3 << ".");
401  DeclException2 (ExcMemoryInexact,
402  int, int,
403  << "The containers have sizes " << arg1 << " and "
404  << arg2 << ", which is not as expected.");
405 
409  DeclException2 (ExcWrongIterator,
410  char *, char *,
411  << "You asked for the next free " << arg1 << "_iterator, "
412  "but you can only ask for " << arg2 <<"_iterators.");
413 
425  DeclException0 (ExcPointerIndexClash);
426 
427  protected:
431  unsigned int next_free_single;
432 
436  unsigned int next_free_pair;
437 
442 
447  struct UserData
448  {
449  union
450  {
453  void *p;
456  unsigned int i;
457  };
458 
463  {
464  p = 0;
465  }
466 
472  template <class Archive>
473  void serialize (Archive &ar, const unsigned int version);
474  };
475 
482  {
489  };
490 
491 
498  std::vector<UserData> user_data;
499 
511  };
512 
518  class TriaObjectsHex : public TriaObjects<TriaObject<3> >
519  {
520  public:
534  bool face_orientation(const unsigned int cell, const unsigned int face) const;
535 
536 
582  std::vector<bool> face_orientations;
583 
587  std::vector<bool> face_flips;
588 
592  std::vector<bool> face_rotations;
593 
603  void reserve_space (const unsigned int new_objs);
604 
608  void clear();
609 
618  void monitor_memory (const unsigned int true_dimension) const;
619 
625  std::size_t memory_consumption () const;
626 
631  template <class Archive>
632  void serialize(Archive &ar,
633  const unsigned int version);
634  };
635 
636 
643  class TriaObjectsQuad3D: public TriaObjects<TriaObject<2> >
644  {
645  public:
659  bool face_orientation(const unsigned int cell, const unsigned int face) const;
660 
661 
669  std::vector<bool> line_orientations;
670 
686  void reserve_space (const unsigned int new_quads_in_pairs,
687  const unsigned int new_quads_single = 0);
688 
692  void clear();
693 
702  void monitor_memory (const unsigned int true_dimension) const;
703 
709  std::size_t memory_consumption () const;
710 
715  template <class Archive>
716  void serialize(Archive &ar,
717  const unsigned int version);
718  };
719 
720 //----------------------------------------------------------------------//
721 
722 
723  template <typename G>
724  inline
726  {
727  material_id = numbers::invalid_material_id;
728  }
729 
730 
731 
732  template <typename G>
733  std::size_t
735  {
736  return sizeof(BoundaryOrMaterialId);
737  }
738 
739 
740 
741  template <typename G>
742  template <class Archive>
743  void
745  const unsigned int version)
746  {
747  // serialize this
748  // structure by
749  // writing and
750  // reading the larger
751  // of the two values,
752  // in order to make
753  // sure we get all
754  // bits
755  if (sizeof(material_id) > sizeof(boundary_id))
756  ar &material_id;
757  else
758  ar &boundary_id;
759  }
760 
761 
762  template<typename G>
763  inline
764  bool
766  face_orientation(const unsigned int, const unsigned int) const
767  {
768  return true;
769  }
770 
771 
772  template<typename G>
773  inline
774  void *&
775  TriaObjects<G>::user_pointer (const unsigned int i)
776  {
778  ExcPointerIndexClash());
780 
781  Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
782  return user_data[i].p;
783  }
784 
785 
786  template<typename G>
787  inline
788  const void *
789  TriaObjects<G>::user_pointer (const unsigned int i) const
790  {
792  ExcPointerIndexClash());
794 
795  Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
796  return user_data[i].p;
797  }
798 
799 
800  template<typename G>
801  inline
802  unsigned int &
803  TriaObjects<G>::user_index (const unsigned int i)
804  {
806  ExcPointerIndexClash());
808 
809  Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
810  return user_data[i].i;
811  }
812 
813 
814  template<typename G>
815  inline
816  void
817  TriaObjects<G>::clear_user_data (const unsigned int i)
818  {
819  Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
820  user_data[i].i = 0;
821  }
822 
823 
824  template <typename G>
825  inline
827  :
830  {}
831 
832 
833  template<typename G>
834  inline
835  unsigned int TriaObjects<G>::user_index (const unsigned int i) const
836  {
837  Assert(user_data_type == data_unknown || user_data_type == data_index,
838  ExcPointerIndexClash());
839  user_data_type = data_index;
840 
841  Assert(i<user_data.size(), ExcIndexRange(i,0,user_data.size()));
842  return user_data[i].i;
843  }
844 
845 
846  template<typename G>
847  inline
849  {
850  user_data_type = data_unknown;
851  for (unsigned int i=0; i<user_data.size(); ++i)
852  user_data[i].p = 0;
853  }
854 
855 
856  template<typename G>
857  inline
859  {
860  user_flags.assign(user_flags.size(),false);
861  }
862 
863 
864  template<typename G>
865  template <class Archive>
866  void
868  const unsigned int)
869  {
870  // serialize this as an integer
871  ar &i;
872  }
873 
874 
875 
876  template <typename G>
877  template <class Archive>
878  void TriaObjects<G>::serialize(Archive &ar,
879  const unsigned int)
880  {
881  ar &cells &children;
882  ar &refinement_cases;
883  ar &used;
884  ar &user_flags;
888  }
889 
890 
891  template <class Archive>
892  void TriaObjectsHex::serialize(Archive &ar,
893  const unsigned int version)
894  {
895  this->TriaObjects<TriaObject<3> >::serialize (ar, version);
896 
897  ar &face_orientations &face_flips &face_rotations;
898  }
899 
900 
901  template <class Archive>
903  const unsigned int version)
904  {
905  this->TriaObjects<TriaObject<2> >::serialize (ar, version);
906 
907  ar &line_orientations;
908  }
909 
910 
911 //----------------------------------------------------------------------//
912 
913  inline
914  bool
915  TriaObjectsHex::face_orientation(const unsigned int cell,
916  const unsigned int face) const
917  {
918  Assert (cell < face_orientations.size() / GeometryInfo<3>::faces_per_cell,
919  ExcIndexRange(0, cell, face_orientations.size() / GeometryInfo<3>::faces_per_cell));
922 
923  return face_orientations[cell * GeometryInfo<3>::faces_per_cell
924  + face];
925  }
926 
927 //----------------------------------------------------------------------//
928 
929  inline
930  bool
931  TriaObjectsQuad3D::face_orientation(const unsigned int cell, const unsigned int face) const
932  {
933  return line_orientations[cell * GeometryInfo<2>::faces_per_cell
934  + face];
935  }
936 
937 
938 
939 // declaration of explicit specializations
940 
941  template<>
942  void
943  TriaObjects<TriaObject<2> >::monitor_memory (const unsigned int) const;
944 
945  }
946 }
947 
948 
949 
950 DEAL_II_NAMESPACE_CLOSE
951 
952 #endif
bool face_orientation(const unsigned int cell, const unsigned int face) const
Definition: tria_objects.h:931
std::vector< UserData > user_data
Definition: tria_objects.h:498
DeclException3(ExcMemoryWasted, char *, int, int,<< "The container "<< arg1<< " contains "<< arg2<< " elements, but it`s capacity is "<< arg3<< ".")
DeclException0(ExcPointerIndexClash)
unsigned char material_id
Definition: types.h:142
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:744
void reserve_space(const unsigned int new_quads_in_pairs, const unsigned int new_quads_single=0)
bool face_orientation(const unsigned int cell, const unsigned int face) const
Definition: tria_objects.h:915
bool face_orientation(const unsigned int cell, const unsigned int face) const
Definition: tria_objects.h:766
void monitor_memory(const unsigned int true_dimension) const
unsigned int & user_index(const unsigned int i)
Definition: tria_objects.h:803
DeclException2(ExcMemoryInexact, int, int,<< "The containers have sizes "<< arg1<< " and "<< arg2<< ", which is not as expected.")
std::size_t memory_consumption() const
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:878
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:867
#define Assert(cond, exc)
Definition: exceptions.h:299
void *& user_pointer(const unsigned int i)
Definition: tria_objects.h:775
std::vector< RefinementCase< G::dimension > > refinement_cases
Definition: tria_objects.h:108
::ExceptionBase & ExcIndexRange(int arg1, int arg2, int arg3)
void reserve_space(const unsigned int new_objs)
std::vector< BoundaryOrMaterialId > boundary_or_material_id
Definition: tria_objects.h:203
::TriaRawIterator<::TriaAccessor< G::dimension, dim, spacedim > > next_free_single_object(const ::Triangulation< dim, spacedim > &tria)
typename::Triangulation< dim, spacedim >::raw_hex_iterator next_free_hex(const ::Triangulation< dim, spacedim > &tria, const unsigned int level)
unsigned char boundary_id
Definition: types.h:128
::TriaRawIterator<::TriaAccessor< G::dimension, dim, spacedim > > next_free_pair_object(const ::Triangulation< dim, spacedim > &tria)
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:902
void serialize(Archive &ar, const unsigned int version)
Definition: tria_objects.h:892
void reserve_space(const unsigned int new_objs_in_pairs, const unsigned int new_objs_single=0)
const types::material_id invalid_material_id
Definition: types.h:226
void monitor_memory(const unsigned int true_dimension) const
void monitor_memory(const unsigned int true_dimension) const