Reference documentation for deal.II version 9.1.1
\(\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(
44  std::ref(*this),
45  std::placeholders::_1,
46  std::placeholders::_2));
47  }
48  else
49  Assert(
50  triangulation != nullptr,
51  ExcMessage(
52  "parallel::CellWeights requires a parallel::Triangulation object."));
53  }
54 
55 
56  template <int dim, int spacedim>
58  {
59  tria_listener.disconnect();
60  }
61 
62 
63 
64  template <int dim, int spacedim>
65  void
67  const unsigned int factor)
68  {
69  weighting_function =
70  [factor](const FiniteElement<dim, spacedim> &,
72  -> unsigned int { return factor; };
73  }
74 
75 
76  template <int dim, int spacedim>
77  void
79  const unsigned int factor)
80  {
81  weighting_function =
82  [factor](const FiniteElement<dim, spacedim> &active_fe,
84  -> unsigned int { return factor * active_fe.dofs_per_cell; };
85  }
86 
87 
88  template <int dim, int spacedim>
89  void
91  const unsigned int factor)
92  {
93  weighting_function =
94  [factor](const FiniteElement<dim, spacedim> &active_fe,
96  -> unsigned int {
97  return factor * active_fe.dofs_per_cell * active_fe.dofs_per_cell;
98  };
99  }
100 
101 
102  template <int dim, int spacedim>
103  void
105  const std::function<unsigned int(
108  custom_function)
109  {
110  weighting_function = custom_function;
111  }
112 
113 
114 
115  template <int dim, int spacedim>
116  unsigned int
118  const typename Triangulation<dim, spacedim>::cell_iterator &cell_,
119  const typename Triangulation<dim, spacedim>::CellStatus status)
120  {
121  // Check if we are still working with the correct combination of
122  // Triangulation and DoFHandler.
123  Assert(&(*triangulation) == &(dof_handler->get_triangulation()),
124  ExcMessage(
125  "Triangulation associated with the DoFHandler has changed!"));
126 
127  // Convert cell type from Triangulation to DoFHandler to be able
128  // to access the information about the degrees of freedom.
130  *cell_, dof_handler);
131 
132  // Determine which FiniteElement object will be present on this cell after
133  // refinement and will thus specify the number of degrees of freedom.
134  unsigned int fe_index = numbers::invalid_unsigned_int;
135  switch (status)
136  {
140  fe_index = cell->future_fe_index();
141  break;
142 
144  {
145  std::set<unsigned int> fe_indices_children;
146  for (unsigned int child_index = 0;
147  child_index < GeometryInfo<dim>::max_children_per_cell;
148  ++child_index)
149  fe_indices_children.insert(
150  cell->child(child_index)->future_fe_index());
151 
152  Assert(dof_handler->get_fe_collection().find_dominating_fe_extended(
153  fe_indices_children, /*codim=*/0) !=
155  ExcMessage(
156  "No FiniteElement has been found in your FECollection "
157  "that dominates all children of a cell you are trying "
158  "to coarsen!"));
159  }
160  break;
161 
162  default:
163  Assert(false, ExcInternalError());
164  break;
165  }
166 
167  // Return the cell weight determined by the function of choice.
168  return weighting_function(dof_handler->get_fe(fe_index), cell);
169  }
170 } // namespace parallel
171 
172 
173 // explicit instantiations
174 #include "cell_weights.inst"
175 
176 DEAL_II_NAMESPACE_CLOSE
static const unsigned int invalid_unsigned_int
Definition: types.h:173
void register_ndofs_weighting(const unsigned int factor=1000)
Definition: cell_weights.cc:78
SmartPointer< const parallel::Triangulation< dim, spacedim >, CellWeights > triangulation
Definition: cell_weights.h:151
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:316
#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:90
const Triangulation< dim, spacedim > & get_triangulation() const
void register_constant_weighting(const unsigned int factor=1000)
Definition: cell_weights.cc:66
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()