#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
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
{
template <int, int> class Triangulation;
}
+
+ namespace shared
+ {
+ template <int, int> class Triangulation;
+ }
}
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
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
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
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
#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 -------------------------------*/
# 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
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;