]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
introduced shared parallel triangulation
authordenis.davydov <denis.davydov@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 20 Mar 2014 16:57:24 +0000 (16:57 +0000)
committerdenis.davydov <denis.davydov@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 20 Mar 2014 16:57:24 +0000 (16:57 +0000)
git-svn-id: https://svn.dealii.org/branches/branch_sharedtria@32674 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/distributed/tria.h
deal.II/include/deal.II/dofs/dof_accessor.templates.h
deal.II/include/deal.II/grid/tria_accessor.templates.h
deal.II/source/distributed/tria.cc
deal.II/source/distributed/tria.inst.in
deal.II/source/dofs/dof_tools.cc

index b00a01b224483e5e2cbe0825ded255754a79cc50..2e3bd67ed6362a283f013765c97175fd9bc5bd91 100644 (file)
@@ -931,6 +931,47 @@ namespace parallel
 
 #endif
 
+namespace parallel
+{
+  namespace shared
+  {
+    template <int dim, int spacedim = dim>
+    class Triangulation : public dealii::Triangulation<dim,spacedim>
+    {
+    public:
+      /**
+       * Constructor.
+       */
+      Triangulation (MPI_Comm mpi_communicator);
+
+      /**
+       * Destructor.
+       */
+      virtual ~Triangulation ();
+
+      types::subdomain_id locally_owned_subdomain () const;
+
+      /**
+       * Return the MPI communicator used by this triangulation.
+       */
+      MPI_Comm get_communicator () const;
+      
+      virtual void execute_coarsening_and_refinement ();
+      
+      virtual void     create_triangulation (const std::vector< Point< spacedim > > &vertices, 
+                                                                         const std::vector< CellData< dim > > &cells, 
+                                                                         const SubCellData &subcelldata);
+      
+      
+    private:
+      MPI_Comm mpi_communicator;
+      types::subdomain_id my_subdomain;
+      types::subdomain_id num_subdomains;
+      
+      void mark_artificial();
+    };
+  }
+}
 
 DEAL_II_NAMESPACE_CLOSE
 
index 42446a05c0d516235405b33551b0d3a9cb3a0308..cd33e62451d1956cb98d128f85220b5e17baf0f3 100644 (file)
@@ -3261,8 +3261,10 @@ void
 DoFCellAccessor<DH,level_dof_access>::get_dof_indices (std::vector<types::global_dof_index> &dof_indices) const
 {
   Assert (this->active(), ExcMessage ("get_dof_indices() only works on active cells."));
-  Assert (this->is_artificial() == false,
-          ExcMessage ("Can't ask for DoF indices on artificial cells."));
+  
+  Assert ( (dynamic_cast<const dealii::parallel::distributed::Triangulation<DH::dimension,DH::space_dimension>*>(this->tria)==0)
+         ||(this->is_artificial() == false),
+          ExcMessage ("Can't ask for DoF indices on artificial cells of distributed triangulation."));
   AssertDimension (dof_indices.size(), this->get_fe().dofs_per_cell);
 
   const types::global_dof_index *cache
index 19bb7ad61a3148733855692ed674fc1dcc00c4ec..5f51543613f34b566927e5be3a8d11ab43cbd0ba 100644 (file)
@@ -39,6 +39,11 @@ namespace parallel
   {
     template <int, int> class Triangulation;
   }
+  
+  namespace shared
+  {
+    template <int, int> class Triangulation;
+  }
 }
 
 
@@ -2877,6 +2882,13 @@ bool
 CellAccessor<dim,spacedim>::is_locally_owned () const
 {
   Assert (this->active(), ExcMessage("is_locally_owned() only works on active cells!"));
+  
+  const parallel::shared::Triangulation<dim,spacedim> *pst
+    = dynamic_cast<const parallel::shared::Triangulation<dim,spacedim> *>(this->tria);
+
+  if (pst != 0)
+    return (this->subdomain_id() == pst->locally_owned_subdomain());
+    
 #ifndef DEAL_II_WITH_P4EST
   return true;
 #else
@@ -2899,6 +2911,12 @@ inline
 bool
 CellAccessor<dim,spacedim>::is_locally_owned_on_level () const
 {
+  const parallel::shared::Triangulation<dim,spacedim> *pst
+    = dynamic_cast<const parallel::shared::Triangulation<dim,spacedim> *>(this->tria);
+
+  if (pst != 0)
+    return (this->level_subdomain_id() == pst->locally_owned_subdomain());
+    
 #ifndef DEAL_II_WITH_P4EST
   return true;
 #else
@@ -2919,6 +2937,16 @@ bool
 CellAccessor<dim,spacedim>::is_ghost () const
 {
   Assert (this->active(), ExcMessage("is_ghost() only works on active cells!"));
+  
+  if (is_artificial() || this->has_children())
+    return false;
+
+  const parallel::shared::Triangulation<dim,spacedim> *pst
+    = dynamic_cast<const parallel::shared::Triangulation<dim,spacedim> *>(this->tria);
+
+  if (pst != 0)
+    return (this->subdomain_id() != pst->locally_owned_subdomain());
+  
 #ifndef DEAL_II_WITH_P4EST
   return false;
 #else
@@ -2943,6 +2971,13 @@ bool
 CellAccessor<dim,spacedim>::is_artificial () const
 {
   Assert (this->active(), ExcMessage("is_artificial() only works on active cells!"));
+  
+  const parallel::shared::Triangulation<dim,spacedim> *pst
+    = dynamic_cast<const parallel::shared::Triangulation<dim,spacedim> *>(this->tria);
+
+  if (pst != 0)
+    return this->subdomain_id() == numbers::artificial_subdomain_id;//could probably keep this line only?
+    
 #ifndef DEAL_II_WITH_P4EST
   return false;
 #else
index 4085903ce0b2afd76dd87113209becc1cc5f4e7c..ef29d175dab7ad03ad735fc09391269aef18dff2 100644 (file)
@@ -4115,6 +4115,109 @@ namespace parallel
 #endif // DEAL_II_WITH_P4EST
 
 
+namespace parallel
+{
+  namespace shared
+  {
+    template <int dim, int spacedim>
+    Triangulation<dim,spacedim>::Triangulation (MPI_Comm mpi_communicator):
+        dealii::Triangulation<dim,spacedim>(),
+       mpi_communicator (Utilities::MPI::
+                          duplicate_communicator(mpi_communicator)),
+        my_subdomain (Utilities::MPI::this_mpi_process (this->mpi_communicator)),
+        num_subdomains(Utilities::MPI::n_mpi_processes(mpi_communicator))
+    {
+
+    }
+
+
+    template <int dim, int spacedim>
+    Triangulation<dim,spacedim>::~Triangulation ()
+    {
+
+    }
+
+
+
+    template <int dim, int spacedim>
+    types::subdomain_id
+    Triangulation<dim,spacedim>::locally_owned_subdomain () const
+    {
+      return my_subdomain;
+    }
+    
+    template <int dim, int spacedim>
+    void 
+    Triangulation<dim,spacedim>::execute_coarsening_and_refinement () {
+         dealii::Triangulation<dim,spacedim>::execute_coarsening_and_refinement ();
+         dealii::GridTools::partition_triangulation (num_subdomains, *this);
+         mark_artificial();
+    }
+    
+    template <int dim, int spacedim>
+    void       
+    Triangulation<dim,spacedim>::create_triangulation (const std::vector< Point< spacedim > > &vertices, 
+                                                                                                  const std::vector< CellData< dim > > &cells, 
+                                                                                                  const SubCellData &subcelldata) {                                                                                               
+      try
+        {
+          dealii::Triangulation<dim,spacedim>::
+          create_triangulation (vertices, cells, subcelldata);
+        }
+      catch (const typename dealii::Triangulation<dim,spacedim>::DistortedCellList &)
+        {
+          // the underlying triangulation should not be checking for distorted
+          // cells
+          AssertThrow (false, ExcInternalError());
+        }
+      dealii::GridTools::partition_triangulation (num_subdomains, *this);
+      mark_artificial();
+    }
+
+
+    template <int dim, int spacedim>
+    MPI_Comm
+    Triangulation<dim,spacedim>::get_communicator () const
+    {
+      return mpi_communicator;
+    }
+    
+    template <int dim, int spacedim>
+    void
+    Triangulation<dim,spacedim>::mark_artificial() 
+    {
+    
+       std::vector<bool > marked_vertices(this->n_vertices(),false);
+        for (typename dealii::Triangulation<dim,spacedim>::active_cell_iterator
+                   cell = this->begin_active();
+                   cell != this->end(); ++cell)
+            if (cell->subdomain_id() == this->locally_owned_subdomain())
+                for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+                    marked_vertices[cell->vertex_index(v)] = true;
+                    
+                    
+                    
+        for (typename dealii::Triangulation<dim,spacedim>::active_cell_iterator
+                   cell = this->begin_active();
+                   cell != this->end(); ++cell)
+            if (cell->subdomain_id() != this->locally_owned_subdomain()) {
+               bool is_ghost = false;
+               for (unsigned int v=0; v<GeometryInfo<dim>::vertices_per_cell; ++v)
+                       if (marked_vertices[cell->vertex_index(v)] == true)
+                       {
+                               is_ghost = true;
+                               break;
+                               }
+                       if (is_ghost)
+                               continue;
+                               
+                       cell->set_subdomain_id(numbers::artificial_subdomain_id);       
+               }                   
+    }
+    
+
+  }
+}
 
 
 /*-------------- Explicit Instantiations -------------------------------*/
index b5199699f313c3042d6c45c4d93bd97daea2d829..3b80440cb58dac00c8d891501a255c53e98e7478 100644 (file)
@@ -61,6 +61,17 @@ for (deal_II_dimension : DIMENSIONS)
 #       if deal_II_dimension < 3
         template class Triangulation<deal_II_dimension, deal_II_dimension+1>;
 #       endif
+#       if deal_II_dimension < 2
+        template class Triangulation<deal_II_dimension, deal_II_dimension+2>;
+#       endif
+      \}
+      
+      namespace shared
+      \{
+        template class Triangulation<deal_II_dimension>;
+#       if deal_II_dimension < 3
+        template class Triangulation<deal_II_dimension, deal_II_dimension+1>;
+#       endif
 #       if deal_II_dimension < 2
         template class Triangulation<deal_II_dimension, deal_II_dimension+2>;
 #       endif
index 3ea549933447ed05ab9bf7388230f450e8851844..14020557203c3a6d6a66f185073c3fc188df9ee9 100644 (file)
@@ -1096,9 +1096,10 @@ namespace DoFTools
     endc = dof_handler.end();
     for (; cell!=endc; ++cell)
       {
-        Assert (cell->is_artificial() == false,
-                ExcMessage ("You can't call this function for meshes that "
-                            "have artificial cells."));
+        //can comment it since the case of distributed triangulations is handled above.
+        //Assert (cell->is_artificial() == false,
+        //        ExcMessage ("You can't call this function for meshes that "
+        //                    "have artificial cells."));
 
         const types::subdomain_id subdomain_id = cell->subdomain_id();
         const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.