Reference documentation for deal.II version 9.4.0
\(\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>
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
33namespace
34{
44 void
45 reorder_new_to_old_style(std::vector<CellData<1>> &)
46 {}
47
48
49 void
50 reorder_new_to_old_style(std::vector<CellData<2>> &cells)
51 {
52 for (auto &cell : cells)
53 std::swap(cell.vertices[2], cell.vertices[3]);
54 }
55
56
57 void
58 reorder_new_to_old_style(std::vector<CellData<3>> &cells)
59 {
60 unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
61 for (auto &cell : cells)
62 {
63 for (const unsigned int i : GeometryInfo<3>::vertex_indices())
64 tmp[i] = cell.vertices[i];
65 for (const unsigned int i : GeometryInfo<3>::vertex_indices())
66 cell.vertices[i] = tmp[GeometryInfo<3>::ucd_to_deal[i]];
67 }
68 }
69
70
74 void
75 reorder_old_to_new_style(std::vector<CellData<1>> &)
76 {}
77
78
79 void
80 reorder_old_to_new_style(std::vector<CellData<2>> &cells)
81 {
82 // just invert the permutation:
83 reorder_new_to_old_style(cells);
84 }
85
86
87 void
88 reorder_old_to_new_style(std::vector<CellData<3>> &cells)
89 {
90 // undo the ordering above
91 unsigned int tmp[GeometryInfo<3>::vertices_per_cell];
92 for (auto &cell : cells)
93 {
94 for (const unsigned int i : GeometryInfo<3>::vertex_indices())
95 tmp[i] = cell.vertices[i];
96 for (const unsigned int i : GeometryInfo<3>::vertex_indices())
97 cell.vertices[GeometryInfo<3>::ucd_to_deal[i]] = tmp[i];
98 }
99 }
100} // namespace
101
102
103
104template <int dim, int spacedim>
105void
107 const bool use_new_style_ordering)
108{
109 Assert(cells.size() != 0,
110 ExcMessage("List of elements to orient must have at least one cell"));
111
112 // there is nothing for us to do in 1d
113 if (dim == 1)
114 return;
115
116 // if necessary, convert to new-style format
117 if (use_new_style_ordering == false)
118 reorder_old_to_new_style(cells);
119
121
122 // and convert back if necessary
123 if (use_new_style_ordering == false)
124 reorder_new_to_old_style(cells);
125}
126
127
128
129template <>
130void
132 const std::vector<Point<1>> &,
133 std::vector<CellData<1>> &,
134 const bool)
135{
136 // nothing to be done in 1d
137}
138
139
140
141template <>
142void
144 const std::vector<Point<2>> &,
145 std::vector<CellData<1>> &,
146 const bool)
147{
148 // nothing to be done in 1d
149}
150
151
152
153template <>
154void
156 const std::vector<Point<3>> &,
157 std::vector<CellData<1>> &,
158 const bool)
159{
160 // nothing to be done in 1d
161}
162
163
164template <>
165void
167 const std::vector<Point<2>> &all_vertices,
168 std::vector<CellData<2>> & cells,
169 const bool use_new_style_ordering)
170{
171 if (!use_new_style_ordering)
172 reorder_old_to_new_style(cells);
173
175
176 if (!use_new_style_ordering)
177 reorder_new_to_old_style(cells);
178}
179
180
181
182template <>
183void
185 const std::vector<Point<3>> &,
186 std::vector<CellData<2>> &,
187 const bool)
188{
189 Assert(false, ExcNotImplemented());
190}
191
192
193
194template <>
195void
197 const std::vector<Point<3>> &all_vertices,
198 std::vector<CellData<3>> & cells,
199 const bool use_new_style_ordering)
200{
201 if (!use_new_style_ordering)
202 reorder_old_to_new_style(cells);
203
205
206 if (!use_new_style_ordering)
207 reorder_new_to_old_style(cells);
208}
209
210
211
212/* ------------------------ explicit instantiations ------------------- */
213template class GridReordering<1, 1>;
214template class GridReordering<1, 2>;
215template class GridReordering<1, 3>;
216template class GridReordering<2, 2>;
217template class GridReordering<2, 3>;
218template class GridReordering<3, 3>;
219
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:442
#define DEAL_II_NAMESPACE_CLOSE
Definition: config.h:443
static ::ExceptionBase & ExcNotImplemented()
#define Assert(cond, exc)
Definition: exceptions.h:1473
static ::ExceptionBase & ExcMessage(std::string arg1)
void consistently_order_cells(std::vector< CellData< dim > > &cells)
Definition: grid_tools.cc:1959
void invert_all_negative_measure_cells(const std::vector< Point< spacedim > > &all_vertices, std::vector< CellData< dim > > &cells)
Definition: grid_tools.cc:936
void swap(MemorySpaceData< Number, MemorySpace > &, MemorySpaceData< Number, MemorySpace > &)