Reference documentation for deal.II version 8.5.1
shared_tria.cc
1 // ---------------------------------------------------------------------
2 // @f$Id: tria.cc 32807 2014-04-22 15:01:57Z heister @f$
3 //
4 // Copyright (C) 2015 - 2017 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 #include <deal.II/base/utilities.h>
18 #include <deal.II/base/mpi.h>
19 #include <deal.II/grid/tria.h>
20 #include <deal.II/grid/tria_accessor.h>
21 #include <deal.II/grid/tria_iterator.h>
22 #include <deal.II/grid/grid_tools.h>
23 #include <deal.II/grid/filtered_iterator.h>
24 #include <deal.II/distributed/shared_tria.h>
25 #include <deal.II/distributed/tria.h>
26 
27 
28 DEAL_II_NAMESPACE_OPEN
29 
30 #ifdef DEAL_II_WITH_MPI
31 namespace parallel
32 {
33  namespace shared
34  {
35 
36  template <int dim, int spacedim>
37  Triangulation<dim,spacedim>::Triangulation (MPI_Comm mpi_communicator,
38  const typename ::Triangulation<dim,spacedim>::MeshSmoothing smooth_grid,
39  const bool allow_artificial_cells):
40  ::parallel::Triangulation<dim,spacedim>(mpi_communicator,smooth_grid,false),
41  allow_artificial_cells(allow_artificial_cells)
42  {}
43 
44 
45 
46  template <int dim, int spacedim>
48  {
49  ::GridTools::partition_triangulation (this->n_subdomains, *this);
50 
51  true_subdomain_ids_of_cells.resize(this->n_active_cells());
52 
53  // loop over all cells and mark artificial:
54  typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
55  cell = this->begin_active(),
56  endc = this->end();
57 
58  if (allow_artificial_cells)
59  {
60  // get halo layer of (ghost) cells
61  // parallel::shared::Triangulation<dim>::
62  std_cxx11::function<bool (const typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator &)> predicate
63  = IteratorFilters::SubdomainEqualTo(this->my_subdomain);
64 
65  const std::vector<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
66  active_halo_layer_vector = GridTools::compute_active_cell_halo_layer (*this, predicate);
67  std::set<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
68  active_halo_layer(active_halo_layer_vector.begin(), active_halo_layer_vector.end());
69 
70  for (unsigned int index=0; cell != endc; cell++, index++)
71  {
72  // store original/true subdomain ids:
73  true_subdomain_ids_of_cells[index] = cell->subdomain_id();
74 
75  if (cell->is_locally_owned() == false &&
76  active_halo_layer.find(cell) == active_halo_layer.end())
77  cell->set_subdomain_id(numbers::artificial_subdomain_id);
78  }
79  }
80  else
81  {
82  // just store true subdomain ids
83  for (unsigned int index=0; cell != endc; cell++, index++)
84  true_subdomain_ids_of_cells[index] = cell->subdomain_id();
85 
86  }
87  }
88 
89 
90 
91  template <int dim, int spacedim>
92  bool
94  {
95  return allow_artificial_cells;
96  }
97 
98 
99 
100  template <int dim, int spacedim>
101  const std::vector<types::subdomain_id> &
103  {
104  return true_subdomain_ids_of_cells;
105  }
106 
107 
108 
109  template <int dim, int spacedim>
111  {}
112 
113 
114 
115  template <int dim, int spacedim>
116  void
118  {
120  partition();
121  this->update_number_cache ();
122  }
123 
124 
125 
126  template <int dim, int spacedim>
127  void
129  const std::vector< CellData< dim > > &cells,
130  const SubCellData &subcelldata)
131  {
132  try
133  {
135  create_triangulation (vertices, cells, subcelldata);
136  }
137  catch (const typename ::Triangulation<dim,spacedim>::DistortedCellList &)
138  {
139  // the underlying triangulation should not be checking for distorted
140  // cells
141  Assert (false, ExcInternalError());
142  }
143  partition();
144  this->update_number_cache ();
145  }
146 
147 
148 
149  template <int dim, int spacedim>
150  void
152  copy_triangulation (const ::Triangulation<dim, spacedim> &other_tria)
153  {
154  Assert ((dynamic_cast<const ::parallel::distributed::Triangulation<dim,spacedim> *>(&other_tria) == NULL),
155  ExcMessage("Cannot use this function on parallel::distributed::Triangulation."));
156 
158  partition();
159  this->update_number_cache ();
160  }
161 
162  }
163 }
164 
165 #else
166 
167 namespace parallel
168 {
169  namespace shared
170  {
171  template <int dim, int spacedim>
173  :
174  ::parallel::Triangulation<dim,spacedim>(MPI_COMM_SELF)
175  {
176  Assert (false, ExcNotImplemented());
177  }
178 
179 
180 
181  template <int dim, int spacedim>
182  bool
184  {
185  Assert (false, ExcNotImplemented());
186  return true;
187  }
188 
189 
190 
191  template <int dim, int spacedim>
192  const std::vector<unsigned int> &
194  {
195  Assert (false, ExcNotImplemented());
196  return true_subdomain_ids_of_cells;
197  }
198 
199  }
200 }
201 
202 
203 #endif
204 
205 
206 /*-------------- Explicit Instantiations -------------------------------*/
207 #include "shared_tria.inst"
208 
209 DEAL_II_NAMESPACE_CLOSE
virtual void execute_coarsening_and_refinement()
Definition: shared_tria.cc:117
Triangulation(MPI_Comm mpi_communicator, const typename ::Triangulation< dim, spacedim >::MeshSmoothing=(::Triangulation< dim, spacedim >::none), const bool allow_artificial_cells=false)
Definition: shared_tria.cc:37
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &old_tria)
Definition: tria_base.cc:63
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() const
Definition: shared_tria.cc:102
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: shared_tria.cc:128
cell_iterator end() const
Definition: tria.cc:10736
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:11899
static ::ExceptionBase & ExcMessage(std::string arg1)
virtual void copy_triangulation(const ::Triangulation< dim, spacedim > &other_tria)
Definition: shared_tria.cc:152
#define Assert(cond, exc)
Definition: exceptions.h:313
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: tria.cc:9401
const types::subdomain_id artificial_subdomain_id
Definition: types.h:261
static ::ExceptionBase & ExcNotImplemented()
std::vector< typename MeshType::active_cell_iterator > compute_active_cell_halo_layer(const MeshType &mesh, const std_cxx11::function< bool(const typename MeshType::active_cell_iterator &)> &predicate)
Definition: grid_tools.cc:1583
static ::ExceptionBase & ExcInternalError()