Reference documentation for deal.II version 9.3.2
\(\newcommand{\dealvcentcolon}{\mathrel{\mathop{:}}}\) \(\newcommand{\dealcoloneq}{\dealvcentcolon\mathrel{\mkern-1.2mu}=}\) \(\newcommand{\jump}[1]{\left[\!\left[ #1 \right]\!\right]}\) \(\newcommand{\average}[1]{\left\{\!\left\{ #1 \right\}\!\right\}}\)
grid_reordering.cc
Go to the documentation of this file.
1 // ---------------------------------------------------------------------
2 //
3 // Copyright (C) 2000 - 2021 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/base/timer.h>
18 #include <deal.II/base/utilities.h>
19 
22 
23 #include <algorithm>
24 #include <fstream>
25 #include <functional>
26 #include <iostream>
27 #include <set>
28 
30 
31 
32 // anonymous namespace for internal helper functions
33 namespace
34 {
44  void reorder_new_to_old_style(std::vector<CellData<1>> &)
45  {}
46 
47 
48  void reorder_new_to_old_style(std::vector<CellData<2>> &cells)
49  {
50  for (auto &cell : cells)
51  std::swap(cell.vertices[2], cell.vertices[3]);
52  }
53 
54 
55  void reorder_new_to_old_style(std::vector<CellData<3>> &cells)
56  {
57  unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
58  for (auto &cell : cells)
59  {
60  for (const unsigned int i : GeometryInfo<3>::vertex_indices())
61  tmp[i] = cell.vertices[i];
62  for (const unsigned int i : GeometryInfo<3>::vertex_indices())
63  cell.vertices[i] = tmp[GeometryInfo<3>::ucd_to_deal[i]];
64  }
65  }
66 
67 
71  void reorder_old_to_new_style(std::vector<CellData<1>> &)
72  {}
73 
74 
75  void reorder_old_to_new_style(std::vector<CellData<2>> &cells)
76  {
77  // just invert the permutation:
78  reorder_new_to_old_style(cells);
79  }
80 
81 
82  void reorder_old_to_new_style(std::vector<CellData<3>> &cells)
83  {
84  // undo the ordering above
85  unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
86  for (auto &cell : cells)
87  {
88  for (const unsigned int i : GeometryInfo<3>::vertex_indices())
89  tmp[i] = cell.vertices[i];
90  for (const unsigned int i : GeometryInfo<3>::vertex_indices())
91  cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
92  }
93  }
94 } // namespace
95 
96 
97 
98 template <int dim, int spacedim>
99 void
101  const bool use_new_style_ordering)
102 {
103  Assert(cells.size() != 0,
104  ExcMessage("List of elements to orient must have at least one cell"));
105 
106  // there is nothing for us to do in 1d
107  if (dim == 1)
108  return;
109 
110  // if necessary, convert to new-style format
111  if (use_new_style_ordering == false)
112  reorder_old_to_new_style(cells);
113 
115 
116  // and convert back if necessary
117  if (use_new_style_ordering == false)
118  reorder_new_to_old_style(cells);
119 }
120 
121 
122 
123 template <>
124 void
126  const std::vector<Point<1>> &,
127  std::vector<CellData<1>> &,
128  const bool)
129 {
130  // nothing to be done in 1d
131 }
132 
133 
134 
135 template <>
136 void
138  const std::vector<Point<2>> &,
139  std::vector<CellData<1>> &,
140  const bool)
141 {
142  // nothing to be done in 1d
143 }
144 
145 
146 
147 template <>
148 void
150  const std::vector<Point<3>> &,
151  std::vector<CellData<1>> &,
152  const bool)
153 {
154  // nothing to be done in 1d
155 }
156 
157 
158 template <>
159 void
161  const std::vector<Point<2>> &all_vertices,
162  std::vector<CellData<2>> & cells,
163  const bool use_new_style_ordering)
164 {
165  if (!use_new_style_ordering)
166  reorder_old_to_new_style(cells);
167 
169 
170  if (!use_new_style_ordering)
171  reorder_new_to_old_style(cells);
172 }
173 
174 
175 
176 template <>
177 void
179  const std::vector<Point<3>> &,
180  std::vector<CellData<2>> &,
181  const bool)
182 {
183  Assert(false, ExcNotImplemented());
184 }
185 
186 
187 
188 template <>
189 void
191  const std::vector<Point<3>> &all_vertices,
192  std::vector<CellData<3>> & cells,
193  const bool use_new_style_ordering)
194 {
195  if (!use_new_style_ordering)
196  reorder_old_to_new_style(cells);
197 
199 
200  if (!use_new_style_ordering)
201  reorder_new_to_old_style(cells);
202 }
203 
204 
205 
206 /* ------------------------ explicit instantiations ------------------- */
207 template class GridReordering<1, 1>;
208 template class GridReordering<1, 2>;
209 template class GridReordering<1, 3>;
210 template class GridReordering<2, 2>;
211 template class GridReordering<2, 3>;
212 template class GridReordering<3, 3>;
213 
static void reorder_cells(std::vector< CellData< dim >> &original_cells, const bool use_new_style_ordering=false)
static void invert_all_cells_of_negative_grid(const std::vector< Point< spacedim >> &all_vertices, std::vector< CellData< dim >> &original_cells, const bool use_new_style_ordering=false)
#define DEAL_II_NAMESPACE_OPEN
Definition: config.h:396
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:397
#define Assert(cond, exc)
Definition: exceptions.h:1465
static ::ExceptionBase & ExcNotImplemented()
static ::ExceptionBase & ExcMessage(std::string arg1)
void invert_all_negative_measure_cells(const std::vector< Point< spacedim >> &all_vertices, std::vector< CellData< dim >> &cells)
Definition: grid_tools.cc:863
void consistently_order_cells(std::vector< CellData< dim >> &cells)
Definition: grid_tools.cc:1921
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)