From 3d38acd4ce3b30d76fc730bf7ec1393a7396f7ea Mon Sep 17 00:00:00 2001
From: Cody Permann <Cody.Permann@inl.gov>
Date: Wed, 8 Jun 2011 08:23:20 -0600
Subject: [PATCH] Configurable subdomain_id_type

---
 configure.in                      |   27 ++++++++++++++++++++++++++-
 examples/ex28/ex28.C              |    2 +-
 include/base/id_types.h           |   12 ++++++++++++
 include/base/libmesh_config.h.in  |   20 +++++---------------
 include/mesh/exodusII_io_helper.h |    2 +-
 src/mesh/exodusII_io_helper.C     |   18 +++++++++---------
 6 files changed, 54 insertions(+), 27 deletions(-)

diff --git a/configure.in b/configure.in
index c731823..0e61e3f 100644
--- a/configure.in
+++ b/configure.in
@@ -293,6 +293,32 @@ dnl argument to do it.
 AC_CHECK_SIZEOF([function_pointer], [], [typedef void (*function_pointer)();])
 dnl AC_CHECK_SIZEOF([void(*)(void)]) <-- Does not work! 
 
+dnl -------------------------------------------------------------
+dnl size of subdomain_id -- default 2
+dnl -------------------------------------------------------------
+AC_ARG_WITH([subdomain_id_bytes],
+	    AC_HELP_STRING([--subdomain-id-bytes=<1|2|4>],
+                           [bytes of storage per element used to store the subdomain_id]),
+	    [subdomain_bytes="$withval"],
+	    [subdomain_bytes=2])
+
+if test "$subdomain_bytes" == 1 ; then
+  AC_DEFINE(SUBDOMAIN_ID_BYTES, 1,
+           [size of subdomain_id])
+  AC_MSG_RESULT(configuring size of subdomain_id... 1)
+elif test "$subdomain_bytes" == 2 ; then
+  AC_DEFINE(SUBDOMAIN_ID_BYTES, 2,
+           [size of subdomain_id])
+  AC_MSG_RESULT(configuring size of subdomain_id... 2)
+elif test "$subdomain_bytes" == 4 ; then
+  AC_DEFINE(SUBDOMAIN_ID_BYTES, 4,
+           [size of subdomain_id])
+  AC_MSG_RESULT(configuring size of subdomain_id... 4)
+else
+  AC_MSG_RESULT(unrecognized subdomain_id size - configuring size...2)
+fi
+
+dnl -------------------------------------------------------------
 
 
 dnl --------------------------------------------------------------
@@ -533,7 +559,6 @@ fi
 dnl -------------------------------------------------------------
 
 
-
 dnl dnl -------------------------------------------------------------
 dnl dnl Expensive Data Structures -- enabled by default
 dnl dnl -------------------------------------------------------------
diff --git a/examples/ex28/ex28.C b/examples/ex28/ex28.C
index 644cc40..36529c2 100644
--- a/examples/ex28/ex28.C
+++ b/examples/ex28/ex28.C
@@ -229,7 +229,7 @@ int main (int argc, char** argv)
     equation_systems.add_system<LinearImplicitSystem> ("Poisson");
 
   
-  std::set<unsigned char> active_subdomains;
+  std::set<subdomain_id_type> active_subdomains;
 
   
   // Add the variable "u" to "Poisson".  "u"
diff --git a/include/base/id_types.h b/include/base/id_types.h
index 7374695..eec0714 100644
--- a/include/base/id_types.h
+++ b/include/base/id_types.h
@@ -23,6 +23,7 @@
 #define __id_types_h__
 
 #include <limits>
+#include "libmesh_config.h"
 
 namespace libMesh
 {
@@ -42,7 +43,18 @@ operator int() const { return _c; }
 typedef TestClass subdomain_id_type;
 #endif
 
+#if LIBMESH_SUBDOMAIN_ID_BYTES == 1
 typedef unsigned char subdomain_id_type;
+#elif LIBMESH_SUBDOMAIN_ID_BYTES == 4
+/**
+ * Note: subdomain_id_types are positive integers - however limitation in the exodusII
+ * API force us to use a signed integer here to represent subdomains.  This gives us 2^31
+ * possible unique blocks
+ */
+typedef int subdomain_id_type;
+#else // LIBMESH_SUBDOMAIN_ID_BYTES = 2 (default)
+typedef unsigned short subdomain_id_type;
+#endif
 
 } // namespace libMesh
 
diff --git a/include/base/libmesh_config.h.in b/include/base/libmesh_config.h.in
index 73071de..27fb78c 100644
--- a/include/base/libmesh_config.h.in
+++ b/include/base/libmesh_config.h.in
@@ -308,9 +308,6 @@
 /* Define to the one symbol short name of this package. */
 #undef PACKAGE_TARNAME
 
-/* Define to the home page for this package. */
-#undef PACKAGE_URL
-
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
 
@@ -341,6 +338,9 @@
 /* Define to 1 if you have the ANSI C header files. */
 #undef STDC_HEADERS
 
+/* size of subdomain_id */
+#undef SUBDOMAIN_ID_BYTES
+
 /* If the compiler supports a TLS storage class define it to that here */
 #undef TLS
 
@@ -350,16 +350,6 @@
 /* Flag indicating if the library should be built using real numbers */
 #undef USE_REAL_NUMBERS
 
-/* Define to the equivalent of the C99 'restrict' keyword, or to
-   nothing if this is not supported.  Do not define if restrict is
-   supported directly.  */
+/* Define to equivalent of C99 restrict keyword, or to nothing if this is not
+   supported. Do not define if restrict is supported directly. */
 #undef restrict
-/* Work around a bug in Sun C++: it does not support _Restrict or
-   __restrict__, even though the corresponding Sun C compiler ends up with
-   "#define restrict _Restrict" or "#define restrict __restrict__" in the
-   previous line.  Perhaps some future version of Sun C++ will work with
-   restrict; if so, hopefully it defines __RESTRICT like Sun C does.  */
-#if defined __SUNPRO_CC && !defined __RESTRICT
-# define _Restrict
-# define __restrict__
-#endif
diff --git a/include/mesh/exodusII_io_helper.h b/include/mesh/exodusII_io_helper.h
index 76af521..5756a9d 100644
--- a/include/mesh/exodusII_io_helper.h
+++ b/include/mesh/exodusII_io_helper.h
@@ -592,7 +592,7 @@ public:
   int   req_info;                      // Generic required info tag
   int   ret_int;                       // Generic int returned by ex_inquire
   int   num_elem_all_sidesets;         // Total number of elements in all side sets
-  std::vector<int> block_ids;          // Vector of the block identification numbers
+  std::vector<subdomain_id_type> block_ids; // Vector of the block identification numbers
   std::vector<int> connect;            // Vector of nodes in an element
   std::vector<int> ss_ids;             // Vector of the sideset IDs
   std::vector<int> nodeset_ids;        // Vector of the nodeset IDs
diff --git a/src/mesh/exodusII_io_helper.C b/src/mesh/exodusII_io_helper.C
index 6b9ac1a..10248e7 100644
--- a/src/mesh/exodusII_io_helper.C
+++ b/src/mesh/exodusII_io_helper.C
@@ -784,7 +784,7 @@ void ExodusII_IO_Helper::write_elements(const MeshBase & mesh)
   if ((_run_only_on_proc0) && (libMesh::processor_id() != 0))
     return;
 
-  std::map<unsigned int, std::vector<unsigned int>  > subdomain_map;
+  std::map<subdomain_id_type, std::vector<unsigned int>  > subdomain_map;
 
   MeshBase::const_element_iterator mesh_it = mesh.active_elements_begin();
   const MeshBase::const_element_iterator end = mesh.active_elements_end();
@@ -793,7 +793,7 @@ void ExodusII_IO_Helper::write_elements(const MeshBase & mesh)
   {
     Elem * elem = *mesh_it;
 
-    unsigned int cur_subdomain = elem->subdomain_id();
+    subdomain_id_type cur_subdomain = elem->subdomain_id();
 
     if(cur_subdomain == 0)
       cur_subdomain = std::numeric_limits<subdomain_id_type>::max();
@@ -803,7 +803,7 @@ void ExodusII_IO_Helper::write_elements(const MeshBase & mesh)
 
   std::vector<int> elem_num_map;
 
-  std::map<unsigned int, std::vector<unsigned int>  >::iterator it;
+  std::map<subdomain_id_type, std::vector<unsigned int>  >::iterator it;
 
   // element map vector
   block_ids.clear();
@@ -871,7 +871,7 @@ void ExodusII_IO_Helper::write_elements_discontinuous(const MeshBase & mesh)
   if ((_run_only_on_proc0) && (libMesh::processor_id() != 0))
     return;
 
-  std::map<unsigned int, std::vector<unsigned int>  > subdomain_map;
+  std::map<subdomain_id_type, std::vector<unsigned int>  > subdomain_map;
 
   MeshBase::const_element_iterator mesh_it = mesh.active_elements_begin();
   const MeshBase::const_element_iterator end = mesh.active_elements_end();
@@ -883,7 +883,7 @@ void ExodusII_IO_Helper::write_elements_discontinuous(const MeshBase & mesh)
       //Only write out the active elements
       if(elem->active())
       {
-        unsigned int cur_subdomain = elem->subdomain_id();
+        subdomain_id_type cur_subdomain = elem->subdomain_id();
 
         if(cur_subdomain == 0)
           cur_subdomain = std::numeric_limits<subdomain_id_type>::max();
@@ -894,7 +894,7 @@ void ExodusII_IO_Helper::write_elements_discontinuous(const MeshBase & mesh)
 
   std::vector<int> elem_num_map;
 
-  std::map<unsigned int, std::vector<unsigned int>  >::iterator it;
+  std::map<subdomain_id_type, std::vector<unsigned int>  >::iterator it;
 
   for(it = subdomain_map.begin() ; it != subdomain_map.end(); it++)
     {
@@ -1217,7 +1217,7 @@ void ExodusII_IO_Helper::write_element_values(const MeshBase & mesh, const std::
     return;
 
   // Loop over the element blocks and write the data one block at a time
-  std::map<unsigned int, std::vector<unsigned int>  > subdomain_map;
+  std::map<subdomain_id_type, std::vector<unsigned int>  > subdomain_map;
 
   const unsigned int num_vars = values.size() / num_elem;
 
@@ -1231,7 +1231,7 @@ void ExodusII_IO_Helper::write_element_values(const MeshBase & mesh, const std::
       //Only write out the active elements
       if(elem->active())
       {
-        unsigned int cur_subdomain = elem->subdomain_id();
+        subdomain_id_type cur_subdomain = elem->subdomain_id();
 
         if(cur_subdomain == 0)
           cur_subdomain = std::numeric_limits<subdomain_id_type>::max();
@@ -1243,7 +1243,7 @@ void ExodusII_IO_Helper::write_element_values(const MeshBase & mesh, const std::
   for (unsigned int l(0); l < num_vars; ++l)
   {
     // The size of the subdomain map is the number of blocks.
-    std::map<unsigned int, std::vector<unsigned int>  >::iterator it( subdomain_map.begin() );
+    std::map<subdomain_id_type, std::vector<unsigned int>  >::iterator it( subdomain_map.begin() );
 
     for(unsigned int j(0); it != subdomain_map.end(); ++it, ++j)
     {
-- 
1.7.4.1

