include/deal.II/distributed/tria.h

00001 //---------------------------------------------------------------------------
00002 //    @f$Id: tria.h 25345 2012-03-31 08:37:04Z bangerth @f$
00003 //
00004 //    Copyright (C) 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__distributed_tria_h
00013 #define __deal2__distributed_tria_h
00014 
00015 
00016 #include <deal.II/base/config.h>
00017 #include <deal.II/base/subscriptor.h>
00018 #include <deal.II/base/smartpointer.h>
00019 #include <deal.II/base/template_constraints.h>
00020 #include <deal.II/grid/tria.h>
00021 
00022 #include <deal.II/base/std_cxx1x/function.h>
00023 
00024 #include <vector>
00025 #include <list>
00026 #include <utility>
00027 
00028 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
00029 #  include <mpi.h>
00030 #endif
00031 
00032 #ifdef DEAL_II_USE_P4EST
00033 #include <p4est_connectivity.h>
00034 #include <p4est.h>
00035 #include <p4est_ghost.h>
00036 
00037 #include <p8est_connectivity.h>
00038 #include <p8est.h>
00039 #include <p8est_ghost.h>
00040 #endif
00041 
00042 
00043 DEAL_II_NAMESPACE_OPEN
00044 
00045 template <int, int> class Triangulation;
00046 
00047 #ifdef DEAL_II_USE_P4EST
00048 
00049 namespace internal
00050 {
00051   namespace DoFHandler
00052   {
00053     namespace Policy
00054     {
00055       template <int, int> class ParallelDistributed;
00056     }
00057   }
00058 }
00059 
00060 
00061 namespace internal
00062 {
00063   namespace p4est
00064   {
00082     template <int> struct types;
00083 
00084     template <>
00085     struct types<2>
00086     {
00087         typedef p4est_connectivity_t connectivity;
00088         typedef p4est_t              forest;
00089         typedef p4est_tree_t         tree;
00090         typedef p4est_quadrant_t     quadrant;
00091         typedef p4est_topidx_t       topidx;
00092         typedef p4est_locidx_t       locidx;
00093         typedef p4est_balance_type_t balance_type;
00094         typedef p4est_ghost_t        ghost;
00095     };
00096 
00097     template <>
00098     struct types<3>
00099     {
00100         typedef p8est_connectivity_t connectivity;
00101         typedef p8est_t              forest;
00102         typedef p8est_tree_t         tree;
00103         typedef p8est_quadrant_t     quadrant;
00104         typedef p4est_topidx_t       topidx;
00105         typedef p4est_locidx_t       locidx;
00106         typedef p8est_balance_type_t balance_type;
00107         typedef p8est_ghost_t        ghost;
00108     };
00109 
00110 
00117     template <int dim>
00118     void
00119     init_quadrant_children
00120     (const typename types<dim>::quadrant & p4est_cell,
00121      typename types<dim>::quadrant (&p4est_children)[GeometryInfo<dim>::max_children_per_cell]);
00122 
00123 
00127     template <int dim>
00128     void
00129     init_coarse_quadrant(typename types<dim>::quadrant & quad);
00130 
00131 
00132 
00136     template <int dim>
00137     bool
00138     quadrant_is_equal (const typename types<dim>::quadrant & q1,
00139                        const typename types<dim>::quadrant & q2);
00140 
00141                                      //TODO: remove these functions from
00142                                      //public interface somehow? [TH]
00143 
00147     template <int dim>
00148     bool
00149     quadrant_is_ancestor (const typename types<dim>::quadrant & q1,
00150                           const typename types<dim>::quadrant & q2);
00151   }
00152 }
00153 
00154 
00155 
00156 namespace parallel
00157 {
00158   namespace distributed
00159   {
00160 
00161 
00180     template <int dim, int spacedim = dim>
00181     class Triangulation : public ::Triangulation<dim,spacedim>
00182     {
00183       public:
00189         typedef typename ::Triangulation<dim,spacedim>::active_cell_iterator active_cell_iterator;
00190         typedef typename ::Triangulation<dim,spacedim>::cell_iterator        cell_iterator;
00191         typedef typename ::Triangulation<dim,spacedim>::raw_cell_iterator    raw_cell_iterator;
00192 
00209         enum Settings
00210         {
00211           default_setting = 0x0,
00212           mesh_reconstruction_after_repartitioning = 0x1
00213         };
00214 
00215 
00216 
00267         Triangulation (MPI_Comm mpi_communicator,
00268                        const typename ::Triangulation<dim,spacedim>::MeshSmoothing
00269                        smooth_grid = (::Triangulation<dim,spacedim>::none),
00270                        const Settings settings = default_setting);
00271 
00275         virtual ~Triangulation ();
00276 
00286         virtual void clear ();
00287 
00293         virtual void copy_triangulation (const ::Triangulation<dim, spacedim> &old_tria);
00294 
00313         virtual void create_triangulation (const std::vector<Point<spacedim> >    &vertices,
00314                                            const std::vector<CellData<dim> > &cells,
00315                                            const SubCellData                 &subcelldata);
00316 
00345         virtual void execute_coarsening_and_refinement ();
00346 
00359         types::subdomain_id_t locally_owned_subdomain () const;
00360 
00396         unsigned int n_locally_owned_active_cells () const;
00397 
00407         unsigned int n_global_active_cells () const;
00408 
00420         const std::vector<unsigned int> &
00421         n_locally_owned_active_cells_per_processor () const;
00422 
00428         MPI_Comm get_communicator () const;
00429 
00434         virtual std::size_t memory_consumption () const;
00435 
00445         virtual std::size_t memory_consumption_p4est () const;
00446 
00457         void write_mesh_vtk (const char *file_basename) const;
00458 
00466         unsigned int get_checksum () const;
00467 
00474         void save(const char* filename) const;
00475 
00481         void load(const char* filename);
00482 
00495         enum CellStatus
00496         {
00497               CELL_PERSIST, CELL_REFINE, CELL_COARSEN, CELL_INVALID
00498         };
00499 
00528         unsigned int
00529         register_data_attach (const std::size_t size,
00530                               const std_cxx1x::function<void (const cell_iterator &,
00531                                                               const CellStatus,
00532                                                               void*)> & pack_callback);
00533 
00540         void
00541         notify_ready_to_unpack (const unsigned int offset,
00542                                 const std_cxx1x::function<void (const cell_iterator &,
00543                                                                 const CellStatus,
00544                                                                 const void*)> & unpack_callback);
00545 
00553         const std::vector<unsigned int> &
00554         get_p4est_tree_to_coarse_cell_permutation() const;
00555 
00556   private:
00566         MPI_Comm mpi_communicator;
00567 
00571         Settings settings;
00572 
00578         types::subdomain_id_t my_subdomain;
00579 
00584         bool triangulation_has_content;
00585 
00591         struct NumberCache
00592         {
00593             std::vector<unsigned int> n_locally_owned_active_cells;
00594             unsigned int              n_global_active_cells;
00595         };
00596 
00597         NumberCache number_cache;
00598 
00607         typename ::internal::p4est::types<dim>::connectivity *connectivity;
00608 
00614         typename ::internal::p4est::types<dim>::forest *parallel_forest;
00615 
00636         bool refinement_in_progress;
00637 
00638 
00644         unsigned int attached_data_size;
00645 
00651         unsigned int n_attached_datas;
00652 
00657         unsigned int n_attached_deserialize;
00658 
00659         typedef  std_cxx1x::function<
00660           void(typename Triangulation<dim,spacedim>::cell_iterator, CellStatus, void*)
00661           > pack_callback_t;
00662 
00663         typedef std::pair<unsigned int, pack_callback_t> callback_pair_t;
00664 
00665         typedef std::list<callback_pair_t> callback_list_t;
00666 
00672         callback_list_t attached_data_pack_callbacks;
00673 
00674 
00695         std::vector<unsigned int> coarse_cell_to_p4est_tree_permutation;
00696         std::vector<unsigned int> p4est_tree_to_coarse_cell_permutation;
00697 
00703         typename ::internal::p4est::types<dim>::tree *
00704         init_tree(const int dealii_coarse_cell_index) const;
00705 
00711         void setup_coarse_cell_to_p4est_tree_permutation ();
00712 
00721         void copy_new_triangulation_to_p4est (::internal::int2type<2>);
00722         void copy_new_triangulation_to_p4est (::internal::int2type<3>);
00723 
00729         void copy_local_forest_to_triangulation ();
00730 
00731 
00737         void update_number_cache ();
00738 
00746         void attach_mesh_data();
00747 
00748 
00749         template <int, int> friend class ::internal::DoFHandler::Policy::ParallelDistributed;
00750     };
00751 
00752 
00760     template <int spacedim>
00761     class Triangulation<1,spacedim> : public ::Triangulation<1,spacedim>
00762     {
00763       public:
00769         Triangulation (MPI_Comm mpi_communicator);
00770 
00774         virtual ~Triangulation ();
00775 
00781         MPI_Comm get_communicator () const;
00782 
00792         unsigned int n_global_active_cells () const;
00793 
00801         const std::vector<unsigned int> &
00802         get_p4est_tree_to_coarse_cell_permutation() const;
00803 
00816         types::subdomain_id_t locally_owned_subdomain () const;
00817 
00825         std::vector<unsigned int> coarse_cell_to_p4est_tree_permutation;
00826         std::vector<unsigned int> p4est_tree_to_coarse_cell_permutation;
00827     };
00828   }
00829 }
00830 
00831 
00832 #else // DEAL_II_USE_P4EST
00833 
00834 namespace parallel
00835 {
00836   namespace distributed
00837   {
00853     template <int dim, int spacedim = dim>
00854     class Triangulation : public ::Triangulation<dim,spacedim>
00855     {
00856       private:
00860         Triangulation ();
00861 
00862       public:
00863 
00867         virtual ~Triangulation ();
00868 
00881         types::subdomain_id_t locally_owned_subdomain () const;
00882 
00888 #ifdef DEAL_II_COMPILER_SUPPORTS_MPI
00889         MPI_Comm get_communicator () const;
00890 #endif
00891     };
00892   }
00893 }
00894 
00895 
00896 #endif
00897 
00898 
00899 DEAL_II_NAMESPACE_CLOSE
00900 
00901 #endif
00902 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

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