1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2020 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 };
43 typedef TestClass subdomain_id_type;
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 //
64 // We'll need a sign bit in some internal buffers, so let's also
65 // define a signed type that we can convert to without loss.
66 #if LIBMESH_DOF_ID_BYTES == 1
67 typedef uint8_t dof_id_type;
68 typedef  int8_t dof_id_signed_type;
69 #elif LIBMESH_DOF_ID_BYTES == 2
70 typedef uint16_t dof_id_type;
71 typedef  int16_t dof_id_signed_type;
72 #elif LIBMESH_DOF_ID_BYTES == 8
73 typedef uint64_t dof_id_type;
74 typedef  int64_t dof_id_signed_type;
75 #else // LIBMESH_DOF_ID_BYTES = 4 (default)
76 typedef uint32_t dof_id_type;
77 typedef  int32_t dof_id_signed_type;
78 #endif
79 
80 
81 
82 // How many bytes do we need to specify DoFObjects without ever
83 // renumbering?  By default we'll allow for quintillions of
84 // one-time-use ids.
85 #if LIBMESH_UNIQUE_ID_BYTES == 1
86 typedef uint8_t unique_id_type;
87 #elif LIBMESH_UNIQUE_ID_BYTES == 2
88 typedef uint16_t unique_id_type;
89 #elif LIBMESH_UNIQUE_ID_BYTES == 4
90 typedef uint32_t unique_id_type;
91 #else // LIBMESH_UNIQUE_ID_BYTES == 8 (default)
92 typedef uint64_t unique_id_type;
93 
94 #endif
95 
96 
97 // We may want to specialize this later, but for now we'll assume
98 // numeric vector indices are the same as dof indices
99 typedef dof_id_type numeric_index_type;
100 
101 
102 // Define processor id storage type.
103 #if LIBMESH_PROCESSOR_ID_BYTES == 1
104 typedef uint8_t processor_id_type;
105 #elif LIBMESH_PROCESSOR_ID_BYTES == 2
106 typedef uint16_t processor_id_type;
107 #elif LIBMESH_PROCESSOR_ID_BYTES == 4
108 typedef uint32_t processor_id_type; // default
109 #elif LIBMESH_PROCESSOR_ID_BYTES == 8
110 typedef uint64_t processor_id_type;
111 #else
112 // We should not get here: it's not currently possible to set any
113 // other size.
114 DIE A HORRIBLE DEATH HERE...
115 #endif
116 
117 
118 // How many bytes do we need to specify subsets of the interior?  By
119 // default we'll allow for tens of thousands of different subdomain
120 // ids.
121 #if LIBMESH_SUBDOMAIN_ID_BYTES == 1
122 typedef uint8_t subdomain_id_type;
123 #elif LIBMESH_SUBDOMAIN_ID_BYTES == 4
124 /**
125  * \note \p subdomain_id_type should be a positive integer, but due to
126  * a limitation in the exodusII API, we are forced to use a signed
127  * integer here to represent subdomains.  This gives us 2^31 possible
128  * unique blocks.
129  */
130 typedef int32_t subdomain_id_type;
131 #elif LIBMESH_SUBDOMAIN_ID_BYTES == 8
132 /**
133  * Based on the 4-byte comment warning above, this probably doesn't
134  * work with exodusII *at all*...
135  */
136 typedef int64_t subdomain_id_type;
137 #else // LIBMESH_SUBDOMAIN_ID_BYTES = 2 (default)
138 typedef uint16_t subdomain_id_type;
139 #endif
140 
141 
142 // For serialization purposes we often like to pack the different
143 // kinds of ids together; how large a data type do we need to hold an
144 // arbitrary id?
145 #if (LIBMESH_BOUNDARY_ID_BYTES > 4) || (LIBMESH_DOF_ID_BYTES > 4) ||    \
146   (LIBMESH_UNIQUE_ID_BYTES > 4) || (LIBMESH_PROCESSOR_ID_BYTES > 4) ||  \
147   (LIBMESH_SUBDOMAIN_ID_BYTES > 4)
148 typedef uint64_t largest_id_type;
149 #elif (LIBMESH_BOUNDARY_ID_BYTES > 2) || (LIBMESH_DOF_ID_BYTES > 2) ||  \
150   (LIBMESH_UNIQUE_ID_BYTES > 2) || (LIBMESH_PROCESSOR_ID_BYTES > 2) ||  \
151   (LIBMESH_SUBDOMAIN_ID_BYTES > 2)
152 typedef uint32_t largest_id_type;
153 #elif (LIBMESH_BOUNDARY_ID_BYTES > 1) || (LIBMESH_DOF_ID_BYTES > 1) ||  \
154   (LIBMESH_UNIQUE_ID_BYTES > 1) || (LIBMESH_PROCESSOR_ID_BYTES > 1) ||  \
155   (LIBMESH_SUBDOMAIN_ID_BYTES > 1)
156 typedef uint16_t largest_id_type;
157 #else
158 typedef uint8_t largest_id_type;
159 #endif
160 
161 } // namespace libMesh
162 
163 #endif // LIBMESH_ID_TYPES_H
164