Reference documentation for deal.II version 8.4.2
shared_tria.cc
1 // ---------------------------------------------------------------------
2 // @f$Id: tria.cc 32807 2014-04-22 15:01:57Z heister @f$
3 //
4 // Copyright (C) 2015 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/base/memory_consumption.h>
20 #include <deal.II/base/logstream.h>
21 #include <deal.II/lac/sparsity_tools.h>
22 #include <deal.II/lac/sparsity_pattern.h>
23 #include <deal.II/grid/tria.h>
24 #include <deal.II/grid/tria_accessor.h>
25 #include <deal.II/grid/tria_iterator.h>
26 #include <deal.II/grid/grid_tools.h>
27 #include <deal.II/grid/filtered_iterator.h>
28 #include <deal.II/distributed/shared_tria.h>
29 
30 
31 
32 
33 #include <algorithm>
34 #include <numeric>
35 #include <iostream>
36 #include <fstream>
37 
38 
39 DEAL_II_NAMESPACE_OPEN
40 
41 #ifdef DEAL_II_WITH_MPI
42 namespace parallel
43 {
44  namespace shared
45  {
46 
47  template <int dim, int spacedim>
48  Triangulation<dim,spacedim>::Triangulation (MPI_Comm mpi_communicator,
49  const typename ::Triangulation<dim,spacedim>::MeshSmoothing smooth_grid,
50  const bool allow_artificial_cells):
51  ::parallel::Triangulation<dim,spacedim>(mpi_communicator,smooth_grid,false),
52  allow_artificial_cells(allow_artificial_cells)
53  {
54  }
55 
56  template <int dim, int spacedim>
58  {
59  ::GridTools::partition_triangulation (this->n_subdomains, *this);
60 
62 
63  // loop over all cells and mark artificial:
64  typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator
65  cell = this->begin_active(),
66  endc = this->end();
67 
69  {
70  // get halo layer of (ghost) cells
71  // parallel::shared::Triangulation<dim>::
72  std_cxx11::function<bool (const typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator &)> predicate
74 
75  const std::vector<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
76  active_halo_layer_vector = GridTools::compute_active_cell_halo_layer (*this, predicate);
77  std::set<typename parallel::shared::Triangulation<dim,spacedim>::active_cell_iterator>
78  active_halo_layer(active_halo_layer_vector.begin(), active_halo_layer_vector.end());
79 
80  for (unsigned int index=0; cell != endc; cell++, index++)
81  {
82  // store original/true subdomain ids:
83  true_subdomain_ids_of_cells[index] = cell->subdomain_id();
84 
85  if (cell->is_locally_owned() == false &&
86  active_halo_layer.find(cell) == active_halo_layer.end())
87  cell->set_subdomain_id(numbers::artificial_subdomain_id);
88  }
89  }
90  else
91  {
92  // just store true subdomain ids
93  for (unsigned int index=0; cell != endc; cell++, index++)
94  true_subdomain_ids_of_cells[index] = cell->subdomain_id();
95 
96  }
97  }
98 
99  template <int dim, int spacedim>
100  bool
102  {
103  return allow_artificial_cells;
104  }
105 
106  template <int dim, int spacedim>
107  const std::vector<unsigned int> &
109  {
111  }
112 
113  template <int dim, int spacedim>
115  {
116 
117  }
118 
119  template <int dim, int spacedim>
120  void
122  {
124  partition();
125  this->update_number_cache ();
126  }
127 
128  template <int dim, int spacedim>
129  void
131  const std::vector< CellData< dim > > &cells,
132  const SubCellData &subcelldata)
133  {
134  try
135  {
137  create_triangulation (vertices, cells, subcelldata);
138  }
139  catch (const typename ::Triangulation<dim,spacedim>::DistortedCellList &)
140  {
141  // the underlying triangulation should not be checking for distorted
142  // cells
143  AssertThrow (false, ExcInternalError());
144  }
145  partition();
146  this->update_number_cache ();
147  }
148 
149  }
150 }
151 
152 #else
153 
154 namespace parallel
155 {
156  namespace shared
157  {
158  template <int dim, int spacedim>
160  :
162  {
163  Assert (false, ExcNotImplemented());
164  }
165 
166  template <int dim, int spacedim>
167  bool
169  {
170  Assert (false, ExcNotImplemented());
171  return true;
172  }
173 
174  template <int dim, int spacedim>
175  const std::vector<unsigned int> &
177  {
178  Assert (false, ExcNotImplemented());
180  }
181 
182  }
183 }
184 
185 
186 #endif
187 
188 
189 /*-------------- Explicit Instantiations -------------------------------*/
190 #include "shared_tria.inst"
191 
192 DEAL_II_NAMESPACE_CLOSE
unsigned int n_active_cells() const
Definition: tria.cc:10973
virtual void execute_coarsening_and_refinement()
Definition: shared_tria.cc:121
const std::vector< types::subdomain_id > & get_true_subdomain_ids_of_cells() const
Definition: shared_tria.cc:108
types::subdomain_id my_subdomain
Definition: tria_base.h:168
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:48
std::vector< Point< spacedim > > vertices
Definition: tria.h:3296
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: shared_tria.cc:130
active_cell_iterator begin_active(const unsigned int level=0) const
Definition: tria.cc:10397
#define AssertThrow(cond, exc)
Definition: exceptions.h:358
cell_iterator end() const
Definition: tria.cc:10465
virtual void execute_coarsening_and_refinement()
Definition: tria.cc:11602
#define Assert(cond, exc)
Definition: exceptions.h:294
virtual void update_number_cache()
Definition: tria_base.cc:143
virtual void create_triangulation(const std::vector< Point< spacedim > > &vertices, const std::vector< CellData< dim > > &cells, const SubCellData &subcelldata)
Definition: tria.cc:9130
const types::subdomain_id artificial_subdomain_id
Definition: types.h:255
std::vector< types::subdomain_id > true_subdomain_ids_of_cells
Definition: shared_tria.h:155
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:1490
types::subdomain_id n_subdomains
Definition: tria_base.h:173