Reference documentation for deal.II version Git 7026f387cc 2019-10-15 14:19:01 -0400
\(\newcommand{\dealcoloneq}{\mathrel{\vcenter{:}}=}\)
cell_weights.cc
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2018 - 2019 by the deal.II authors
4 //
5 // This file is part of the deal.II library.
6 //
7 // The deal.II library is free software; you can use it, redistribute
8 // it, and/or modify it under the terms of the GNU Lesser General
9 // Public License as published by the Free Software Foundation; either
10 // version 2.1 of the License, or (at your option) any later version.
11 // The full text of the license can be found in the file LICENSE.md at
12 // the top level directory of deal.II.
13 //
14 // ---------------------------------------------------------------------
15 
16 
17 #include <deal.II/distributed/cell_weights.h>
18 
19 #include <deal.II/dofs/dof_accessor.h>
20 
21 
22 DEAL_II_NAMESPACE_OPEN
23 
24 namespace parallel
25 {
26  template <int dim, int spacedim>
28  const hp::DoFHandler<dim, spacedim> &dof_handler)
29  : dof_handler(&dof_handler, typeid(*this).name())
30  {
32  const_cast<::Triangulation<dim, spacedim> *>(
33  &(this->dof_handler->get_triangulation()))));
34 
35  if (triangulation != nullptr)
36  {
37  // Choose default weighting.
39 
40  // Add callback function to the cell_weight signal and store its
41  // connection.
42  tria_listener = triangulation->signals.cell_weight.connect(
43  [this](
44  const typename Triangulation<dim, spacedim>::cell_iterator &cell_,
45  const typename Triangulation<dim, spacedim>::CellStatus status) {
46  return this->weight_callback(cell_, status);
47  });
48  }
49  else
50  Assert(
51  triangulation != nullptr,
52  ExcMessage(
53  "parallel::CellWeights requires a parallel::TriangulationBase object."));
54  }
55 
56 
57  template <int dim, int spacedim>
59  {
60  tria_listener.disconnect();
61  }
62 
63 
64 
65  template <int dim, int spacedim>
66  void
68  const unsigned int factor)
69  {
71  [factor](const FiniteElement<dim, spacedim> &,
73  -> unsigned int { return factor; };
74  }
75 
76 
77  template <int dim, int spacedim>
78  void
80  const unsigned int factor)
81  {
83  [factor](const FiniteElement<dim, spacedim> &active_fe,
85  -> unsigned int { return factor * active_fe.dofs_per_cell; };
86  }
87 
88 
89  template <int dim, int spacedim>
90  void
92  const unsigned int factor)
93  {
95  [factor](const FiniteElement<dim, spacedim> &active_fe,
97  -> unsigned int {
98  return factor * active_fe.dofs_per_cell * active_fe.dofs_per_cell;
99  };
100  }
101 
102 
103  template <int dim, int spacedim>
104  void
106  const std::function<unsigned int(
109  custom_function)
110  {
111  weighting_function = custom_function;
112  }
113 
114 
115 
116  template <int dim, int spacedim>
117  unsigned int
119  const typename Triangulation<dim, spacedim>::cell_iterator &cell_,
120  const typename Triangulation<dim, spacedim>::CellStatus status)
121  {
122  // Check if we are still working with the correct combination of
123  // Triangulation and DoFHandler.
124  Assert(&(*triangulation) == &(dof_handler->get_triangulation()),
125  ExcMessage(
126  "Triangulation associated with the DoFHandler has changed!"));
127 
128  // Convert cell type from Triangulation to DoFHandler to be able
129  // to access the information about the degrees of freedom.
131  *cell_, dof_handler);
132 
133  // Determine which FiniteElement object will be present on this cell after
134  // refinement and will thus specify the number of degrees of freedom.
135  unsigned int fe_index = numbers::invalid_unsigned_int;
136  switch (status)
137  {
141  fe_index = cell->future_fe_index();
142  break;
143 
145  {
146  std::set<unsigned int> fe_indices_children;
147  for (unsigned int child_index = 0; child_index < cell->n_children();
148  ++child_index)
149  {
150  const auto child = cell->child(child_index);
151  Assert(child->active() && child->coarsen_flag_set(),
152  typename ::Triangulation<
153  dim>::ExcInconsistentCoarseningFlags());
154 
155  fe_indices_children.insert(child->future_fe_index());
156  }
157  Assert(!fe_indices_children.empty(), ExcInternalError());
158 
159  fe_index =
160  dof_handler->get_fe_collection().find_dominated_fe_extended(
161  fe_indices_children, /*codim=*/0);
162 
164  typename ::hp::FECollection<
165  dim>::ExcNoDominatedFiniteElementAmongstChildren());
166  }
167  break;
168 
169  default:
170  Assert(false, ExcInternalError());
171  break;
172  }
173 
174  // Return the cell weight determined by the function of choice.
175  return weighting_function(dof_handler->get_fe(fe_index), cell);
176  }
177 } // namespace parallel
178 
179 
180 // explicit instantiations
181 #include "cell_weights.inst"
182 
183 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
Definition: types.h:187
void register_ndofs_weighting(const unsigned int factor=1000)
Definition: cell_weights.cc:79
std::function< unsigned int(const FiniteElement< dim, spacedim > &, const typename hp::DoFHandler< dim, spacedim >::cell_iterator &)> weighting_function
Definition: cell_weights.h:167
static ::ExceptionBase & ExcMessage(std::string arg1)
CellWeights(const ::hp::DoFHandler< dim, spacedim > &dof_handler)
Definition: cell_weights.cc:27
typename ActiveSelector::cell_iterator cell_iterator
Definition: dof_handler.h:325
#define Assert(cond, exc)
Definition: exceptions.h:1407
boost::signals2::connection tria_listener
Definition: cell_weights.h:172
unsigned int weight_callback(const typename Triangulation< dim, spacedim >::cell_iterator &cell, const typename Triangulation< dim, spacedim >::CellStatus status)
const unsigned int dofs_per_cell
Definition: fe_base.h:282
void register_ndofs_squared_weighting(const unsigned int factor=1000)
Definition: cell_weights.cc:91
SmartPointer< const parallel::TriangulationBase< dim, spacedim >, CellWeights > triangulation
Definition: cell_weights.h:151
const Triangulation< dim, spacedim > & get_triangulation() const
SmartPointer< const ::hp::DoFHandler< dim, spacedim >, CellWeights > dof_handler
Definition: cell_weights.h:141
void register_constant_weighting(const unsigned int factor=1000)
Definition: cell_weights.cc:67
void register_custom_weighting(const std::function< unsigned int(const FiniteElement< dim, spacedim > &, const typename hp::DoFHandler< dim, spacedim >::cell_iterator &)> custom_function)
static ::ExceptionBase & ExcInternalError()