id_types.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2017 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_ID_TYPES_H
21 #define LIBMESH_ID_TYPES_H
22 
23 #include <limits>
24 #include <stdint.h>
25 
26 #include "libmesh/libmesh_config.h"
27 
28 namespace libMesh
29 {
30 
31 // A useful way to debug:
32 #if 0
33 class TestClass {
34  //int _c;
35  unsigned int _c;
36 public:
37  TestClass() : _c(0) {}
38  TestClass(unsigned int c) : _c(c) {}
39  TestClass & operator=(unsigned int c) { _c = c; return *this; }
40  bool operator<(const TestClass & l) const { return _c < l._c; }
41  operator int() const { return _c; }
42 };
44 #endif
45 
46 
47 // How many bytes do we need to specify subsets of the boundary? By
48 // default we'll allow for tens of thousands of different boundary
49 // ids.
50 #if LIBMESH_BOUNDARY_ID_BYTES == 1
51 typedef int8_t boundary_id_type;
52 #elif LIBMESH_BOUNDARY_ID_BYTES == 4
53 typedef int32_t boundary_id_type;
54 #elif LIBMESH_BOUNDARY_ID_BYTES == 8
55 typedef int64_t boundary_id_type;
56 #else // LIBMESH_BOUNDARY_ID_BYTES = 2 (default)
57 typedef int16_t boundary_id_type;
58 #endif
59 
60 
61 // How many bytes do we need to specify DoFObjects? By default we'll
62 // allow for a few billion (each) nodes & elements.
63 #if LIBMESH_DOF_ID_BYTES == 1
64 typedef uint8_t dof_id_type;
65 #elif LIBMESH_DOF_ID_BYTES == 2
66 typedef uint16_t dof_id_type;
67 #elif LIBMESH_DOF_ID_BYTES == 8
68 typedef uint64_t dof_id_type;
69 #else // LIBMESH_DOF_ID_BYTES = 4 (default)
70 typedef uint32_t dof_id_type;
71 #endif
72 
73 
74 
75 // How many bytes do we need to specify DoFObjects without ever
76 // renumbering? By default we'll allow for quintillions of
77 // one-time-use ids.
78 #if LIBMESH_UNIQUE_ID_BYTES == 1
79 typedef uint8_t unique_id_type;
80 #elif LIBMESH_UNIQUE_ID_BYTES == 2
81 typedef uint16_t unique_id_type;
82 #elif LIBMESH_UNIQUE_ID_BYTES == 4
83 typedef uint32_t unique_id_type;
84 #else // LIBMESH_UNIQUE_ID_BYTES == 8 (default)
85 typedef uint64_t unique_id_type;
86 
87 #endif
88 
89 
90 // We may want to specialize this later, but for now we'll assume
91 // numeric vector indices are the same as dof indices
92 typedef dof_id_type numeric_index_type;
93 
94 
95 // Define processor id storage type. We default to short to save
96 // space, but expanding to support more than 2^16-2 procs should work
97 // too.
98 #if LIBMESH_PROCESSOR_ID_BYTES == 1
99 typedef uint8_t processor_id_type;
100 #elif LIBMESH_PROCESSOR_ID_BYTES == 4
101 typedef uint32_t processor_id_type;
102 #elif LIBMESH_PROCESSOR_ID_BYTES == 8
103 typedef uint64_t processor_id_type;
104 #else // LIBMESH_PROCESSOR_ID_BYTES = 2 (default)
105 typedef uint16_t processor_id_type;
106 #endif
107 
108 
109 // How many bytes do we need to specify subsets of the interior? By
110 // default we'll allow for tens of thousands of different subdomain
111 // ids.
112 #if LIBMESH_SUBDOMAIN_ID_BYTES == 1
113 typedef uint8_t subdomain_id_type;
114 #elif LIBMESH_SUBDOMAIN_ID_BYTES == 4
115 
120 typedef int32_t subdomain_id_type;
121 #elif LIBMESH_SUBDOMAIN_ID_BYTES == 8
122 
126 typedef int64_t subdomain_id_type;
127 #else // LIBMESH_SUBDOMAIN_ID_BYTES = 2 (default)
128 typedef uint16_t subdomain_id_type;
129 #endif
130 
131 
132 // For serialization purposes we often like to pack the different
133 // kinds of ids together; how large a data type do we need to hold an
134 // arbitrary id?
135 #if (LIBMESH_BOUNDARY_ID_BYTES > 4) || (LIBMESH_DOF_ID_BYTES > 4) || \
136  (LIBMESH_UNIQUE_ID_BYTES > 4) || (LIBMESH_PROCESSOR_ID_BYTES > 4) || \
137  (LIBMESH_SUBDOMAIN_ID_BYTES > 4)
138 typedef uint64_t largest_id_type;
139 #elif (LIBMESH_BOUNDARY_ID_BYTES > 2) || (LIBMESH_DOF_ID_BYTES > 2) || \
140  (LIBMESH_UNIQUE_ID_BYTES > 2) || (LIBMESH_PROCESSOR_ID_BYTES > 2) || \
141  (LIBMESH_SUBDOMAIN_ID_BYTES > 2)
142 typedef uint32_t largest_id_type;
143 #elif (LIBMESH_BOUNDARY_ID_BYTES > 1) || (LIBMESH_DOF_ID_BYTES > 1) || \
144  (LIBMESH_UNIQUE_ID_BYTES > 1) || (LIBMESH_PROCESSOR_ID_BYTES > 1) || \
145  (LIBMESH_SUBDOMAIN_ID_BYTES > 1)
146 typedef uint16_t largest_id_type;
147 #else
148 typedef uint8_t largest_id_type;
149 #endif
150 
151 } // namespace libMesh
152 
153 #endif // LIBMESH_ID_TYPES_H
TestClass subdomain_id_type
Definition: id_types.h:43
uint64_t largest_id_type
Definition: id_types.h:138
uint8_t processor_id_type
Definition: id_types.h:99
TestClass(unsigned int c)
Definition: id_types.h:38
unsigned int _c
Definition: id_types.h:35
int8_t boundary_id_type
Definition: id_types.h:51
dof_id_type numeric_index_type
Definition: id_types.h:92
TestClass & operator=(unsigned int c)
Definition: id_types.h:39
bool operator<(const TestClass &l) const
Definition: id_types.h:40
uint8_t unique_id_type
Definition: id_types.h:79
uint8_t dof_id_type
Definition: id_types.h:64