-
Notifications
You must be signed in to change notification settings - Fork 4
/
Downward.h
116 lines (100 loc) · 3.19 KB
/
Downward.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
/**
* @file
* This file is part of PUML
*
* For conditions of distribution and use, please see the copyright
* notice in the file 'COPYING' at the root directory of this package
* and the copyright notice at https://github.com/TUM-I5/PUMGen
*
* @copyright 2017 Technische Universitaet Muenchen
* @author Sebastian Rettenberger <[email protected]>
*/
#ifndef PUML_DOWNWARD_H
#define PUML_DOWNWARD_H
#include <algorithm>
#include <cassert>
#include <cstring>
#include "utils/arrayutils.h"
#include "Element.h"
#include "Numbering.h"
#include "PUML.h"
#include "Topology.h"
#include "Utils.h"
namespace PUML
{
class Downward
{
public:
/**
* Returns all local face ids for a cell
*
* @param puml The PUML mesh
* @param cell The cell for which the faces should be returned
* @param lid The local ids of the faces
*/
template<TopoType Topo>
static void faces(const PUML<Topo> &puml, const typename PUML<Topo>::cell_t &cell, unsigned int* lid)
{
for (unsigned int i = 0; i < internal::Topology<Topo>::cellfaces(); i++) {
unsigned int v[internal::Topology<Topo>::facevertices()];
faceVertices(puml, cell, i, v);
int id = puml.faceByVertices(v);
assert(id >= 0);
lid[i] = id;
}
}
/**
* Returns all local vertex ids for a cell
*
* @param puml The PUML mesh
* @param cell The cell for which the vertices should be returned
* @param lid The local ids of the vertices
*/
template<TopoType Topo>
static void vertices(const PUML<Topo> &puml, const typename PUML<Topo>::cell_t &cell, unsigned int* lid)
{
memcpy(lid, cell.m_vertices, internal::Topology<Topo>::cellvertices() * sizeof(unsigned int));
}
/**
* Returns all global vertex ids for a cell
*
* @param puml The PUML mesh
* @param cell The cell for which the vertices should be returned
* @param gid The global ids of the vertices
*/
template<TopoType Topo>
static void gvertices(const PUML<Topo> &puml, const typename PUML<Topo>::cell_t &cell, unsigned long* gid)
{
unsigned int lid[internal::Topology<Topo>::cellvertices()];
vertices(puml, cell, lid);
internal::Utils::l2g<Topo, typename PUML<Topo>::vertex_t, internal::Topology<Topo>::cellvertices()>(puml, lid, gid);
}
/**
* @param faceId The local id of the face
* @return The side of the cell this face is on or -1 of the face is on no side
*/
template<TopoType Topo>
static int faceSide(const PUML<Topo> &puml, const typename PUML<Topo>::cell_t &cell, unsigned int faceId)
{
unsigned int faceIds[internal::Topology<Topo>::cellfaces()];
faces(puml, cell, faceIds);
unsigned int* end = faceIds+internal::Topology<Topo>::cellfaces();
unsigned int* pFaceId = std::find(faceIds, end, faceId);
if (pFaceId == end)
return -1;
return pFaceId - faceIds;
}
/**
* @param faceSide The side of the cell
*/
template<TopoType Topo>
static void faceVertices(const PUML<Topo> &puml, const typename PUML<Topo>::cell_t &cell, unsigned int faceSide, unsigned int* lid)
{
assert(faceSide < internal::Topology<Topo>::cellfaces());
for (unsigned int i = 0; i < internal::Topology<Topo>::facevertices(); i++) {
lid[i] = cell.m_vertices[internal::Numbering<Topo>::facevertices()[faceSide][i]];
}
}
};
}
#endif // PUML_DOWNWARD_H