diff --git a/dune/uggrid/domain/std_domain.cc b/dune/uggrid/domain/std_domain.cc
index 9dd98b203f42e2bb33c3aec2109479adf6824c79..1ff481de092685a694c244973b7da6e22da5ea80 100644
--- a/dune/uggrid/domain/std_domain.cc
+++ b/dune/uggrid/domain/std_domain.cc
@@ -606,7 +606,7 @@ GetNumberOfPatches (PATCH * p)
     return (1);
   case POINT_PATCH_TYPE :
     return (POINT_PATCH_N (p));
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   case LINE_PATCH_TYPE :
     return (LINE_PATCH_N (p));
 #endif
@@ -625,7 +625,7 @@ GetPatchId (PATCH * p, INT i)
     return (PATCH_ID (p));
   case POINT_PATCH_TYPE :
     return (POINT_PATCH_PID (p, i));
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   case LINE_PATCH_TYPE :
     return (LINE_PATCH_PID (p, i));
 #endif
@@ -669,7 +669,7 @@ CreateBndPOnPoint (HEAP * Heap, PATCH * p)
                            PARAM_PATCH_RANGE (pp)[1][1]));
       switch (POINT_PATCH_CID (p, j))
       {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
       case 0 :
         ps->local[j][0] = PARAM_PATCH_RANGE (pp)[0][0];
         break;
@@ -677,7 +677,7 @@ CreateBndPOnPoint (HEAP * Heap, PATCH * p)
         ps->local[j][0] = PARAM_PATCH_RANGE (pp)[1][0];
         break;
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
       case 0 :
         ps->local[j][0] = PARAM_PATCH_RANGE (pp)[0][0];
         ps->local[j][1] = PARAM_PATCH_RANGE (pp)[0][1];
@@ -706,7 +706,7 @@ CreateBndPOnPoint (HEAP * Heap, PATCH * p)
     {
       switch (POINT_PATCH_CID (p, j))
       {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
       case 0 :
         ps->local[j][0] = 0.0;
         break;
@@ -714,7 +714,7 @@ CreateBndPOnPoint (HEAP * Heap, PATCH * p)
         ps->local[j][0] = 1.0;
         break;
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
       case 0 :
         ps->local[j][0] = 0.0;
         ps->local[j][1] = 0.0;
@@ -767,7 +767,7 @@ CreateCornerPoints (HEAP * Heap, STD_BVP * theBVP, BNDP ** bndp)
   return (0);
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 /** \brief Add a line between two vertices to the boundary data structure
 
    \param i, j  The line goes from vertex i to vertex j
@@ -890,7 +890,7 @@ BVP_Init (const char *name, HEAP * Heap, MESH * Mesh, INT MarkKey)
   PATCH **corners, **sides, *thePatch;
   unsigned short* segmentsPerPoint, *freeSegmentsPerPoint, *cornerCounters;
   INT i, j, n, m, maxSubDomains, ncorners, nlines, nsides;
-#       ifdef __THREEDIM__
+#       ifdef UG_DIM_3
   PATCH **lines;
   INT err;
   INT nn;
@@ -1115,7 +1115,7 @@ BVP_Init (const char *name, HEAP * Heap, MESH * Mesh, INT MarkKey)
 
   /* create line patches */
   nlines = 0;
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   /* The maximum number of boundary lines is equal to the number of
      boundary faces (nsides) times the max number of lines per face (=4)
      divided by two. */
@@ -1209,7 +1209,7 @@ BVP_Init (const char *name, HEAP * Heap, MESH * Mesh, INT MarkKey)
       POINT_PATCH_PID (thePatch, j) += m;
     theBVP->patches[n++] = thePatch;
   }
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   for (i = 0; i < nlines; i++)
   {
     thePatch = lines[i];
@@ -1439,7 +1439,7 @@ GetNumberOfCommonPatches (PATCH * p0, PATCH * p1, INT * Pid)
   return (cnt);
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static INT
 GetCommonPatchId (PATCH * p0, PATCH * p1, INT k)
 {
@@ -1798,7 +1798,7 @@ BVP_InsertBndP (HEAP * Heap, BVP * aBVP, INT argc, char **argv)
   pid = i + theBVP->sideoffset;
   p = theBVP->patches[pid];
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   /* check point on line or on point patch */
   if (abs(pos[0] - PARAM_PATCH_RANGE (p)[0][0]) < SMALL_DIFF)
   {
@@ -1857,7 +1857,7 @@ BVP_InsertBndP (HEAP * Heap, BVP * aBVP, INT argc, char **argv)
               currBVP->patches[PARAM_PATCH_POINTS (p, 2)], lc));
   }
 #endif
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   /* check point on point patch */
   if (abs(pos[0] - PARAM_PATCH_RANGE (p)[0][0]) < SMALL_DIFF)
     return (CreateBndPOnPoint
@@ -2005,13 +2005,13 @@ PatchGlobal (const PATCH * p, DOUBLE * lambda, DOUBLE * global)
     return ((*PARAM_PATCH_BS (p))(PARAM_PATCH_BSD (p), lambda, global));
   else if (PATCH_TYPE (p) == LINEAR_PATCH_TYPE)
   {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
     global[0] = (1 - lambda[0]) * LINEAR_PATCH_POS (p, 0)[0]
                 + lambda[0] * LINEAR_PATCH_POS (p, 1)[0];
     global[1] = (1 - lambda[0]) * LINEAR_PATCH_POS (p, 0)[1]
                 + lambda[0] * LINEAR_PATCH_POS (p, 1)[1];
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
     if (LINEAR_PATCH_N(p) ==3) {
       /* Linear interpolation for a triangle boundary segment */
@@ -2059,11 +2059,11 @@ FreeBNDS_Global (BND_PS * ps, DOUBLE * local, DOUBLE * global)
   }
 
   /* claculate global coordinates */
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   for (i = 0; i < DIM; i++)
     global[i] = (1.0 - local[0]) * pos[0][i] + local[0] * pos[1][i];
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   switch (ps->n)
   {
   case 3 :
@@ -2093,11 +2093,11 @@ local2lambda (BND_PS * ps, DOUBLE local[], DOUBLE lambda[])
 
   if ((PATCH_TYPE (p) == PARAMETRIC_PATCH_TYPE)
       || (PATCH_TYPE (p) == LINEAR_PATCH_TYPE))
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
     lambda[0] =
       (1.0 - local[0]) * ps->local[0][0] + local[0] * ps->local[1][0];
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     switch (ps->n)
     {
     case 3 :
@@ -2152,14 +2152,14 @@ BNDS_Global (BNDS * aBndS, DOUBLE * local, DOUBLE * global)
 static INT
 SideIsCooriented (BND_PS * ps)
 {
-#       ifdef __TWODIM__
+#       ifdef UG_DIM_2
   if (BND_LOCAL (ps, 1)[0] > BND_LOCAL (ps, 0)[0])
     return (YES);
   else
     return (NO);
 #       endif
 
-#       ifdef __THREEDIM__
+#       ifdef UG_DIM_3
   DOUBLE vp, x0[2], x1[2];
 
   ASSERT (BND_N (ps) >= 3);
@@ -2326,7 +2326,7 @@ BndPointGlobal (const BNDP * aBndP, DOUBLE * global)
     }
 
     return (0);
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   case LINE_PATCH_TYPE :
     s = currBVP->patches[LINE_PATCH_PID (p, 0)];
 
@@ -2409,7 +2409,7 @@ BNDP_BndPDesc (BNDP * theBndP, INT * move, INT * part)
     *move = PATCH_IS_FREE (p) ? DIM : 0;
     return (0);
 
-#               ifdef __THREEDIM__
+#               ifdef UG_DIM_3
   case LINE_PATCH_TYPE :
     if (STD_BVP_NDOMPART (currBVP) > 1)
       *part = DPI_LN2P (DOMAIN_PARTINFO (STD_BVP_DOMAIN (currBVP)),
@@ -2449,7 +2449,7 @@ BNDP_BndEDesc (BNDP * aBndP0, BNDP * aBndP1, INT * part)
   if (cnt == 0)
     return (1);
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   if (cnt > 1)
   {
     pid = GetCommonLinePatchId (p0, p1);
@@ -2484,7 +2484,7 @@ BNDP_CreateBndS (HEAP * Heap, BNDP ** aBndP, INT n)
   PATCH *p[4];
   DOUBLE *lambda[4];
   INT i, j, l, pid;
-#       ifdef __THREEDIM__
+#       ifdef UG_DIM_3
   INT k;
 #       endif
 
@@ -2501,7 +2501,7 @@ BNDP_CreateBndS (HEAP * Heap, BNDP ** aBndP, INT n)
   }
 
   pid = -1;
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   if (n != 2)
     return (NULL);
   /* find common patch of boundary points */
@@ -2520,7 +2520,7 @@ BNDP_CreateBndS (HEAP * Heap, BNDP ** aBndP, INT n)
       }
     }
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   switch (n)
   {
   case 3 :
@@ -2627,7 +2627,7 @@ BNDP_CreateBndP (HEAP * Heap, BNDP * aBndP0, BNDP * aBndP1, DOUBLE lcoord)
     return (NULL);
   bp->n = cnt;
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   if (cnt > 1)
   {
     PATCH *p;
@@ -2764,7 +2764,7 @@ BNDP_SaveInsertedBndP (BNDP * theBndP, char *data, INT max_data_size)
   case POINT_PATCH_TYPE :
     pid = POINT_PATCH_PID (p, 0) - currBVP->sideoffset;
     break;
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   case LINE_PATCH_TYPE :
     pid = LINE_PATCH_PID (p, 0) - currBVP->sideoffset;
     break;
@@ -2773,13 +2773,13 @@ BNDP_SaveInsertedBndP (BNDP * theBndP, char *data, INT max_data_size)
 
   PRINTDEBUG (dom, 1, (" Insert pid %d %d\n", bp->patch_id, pid));
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   if (sprintf (data, "bn %d %f", pid, (float) bp->local[0][0]) >
       max_data_size)
     return (1);
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   if (sprintf (data, "bn %d %f %f", (int) pid,
                (float) bp->local[0][0],
                (float) bp->local[0][1]) > max_data_size)
diff --git a/dune/uggrid/domain/std_domain.h b/dune/uggrid/domain/std_domain.h
index a397479862d0db4f790e25c827cb7eef3483fc42..f8bb273c9dd0cfbeb2e6acf2d8c13e112bfabf50 100644
--- a/dune/uggrid/domain/std_domain.h
+++ b/dune/uggrid/domain/std_domain.h
@@ -61,7 +61,7 @@ typedef struct {
   /** \brief Table segment to part */
   const INT *sg2part;
 
-# ifdef __THREEDIM__
+# ifdef UG_DIM_3
   /** \brief Table line to part */
   const INT **ln2part;
 # endif
diff --git a/dune/uggrid/domain/std_internal.h b/dune/uggrid/domain/std_internal.h
index aa1123db6810da418a5c921c636b733aecfb44d2..259aa9c9db8b9412ffdd0655b24e2dfa4e93e319 100644
--- a/dune/uggrid/domain/std_internal.h
+++ b/dune/uggrid/domain/std_internal.h
@@ -24,7 +24,7 @@ START_UGDIM_NAMESPACE
 typedef DOUBLE COORD_BND_VECTOR[DIM_OF_BND];
 
 enum PatchType {POINT_PATCH_TYPE,
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
                 LINE_PATCH_TYPE,
 #endif
                 LINEAR_PATCH_TYPE,
@@ -416,7 +416,7 @@ struct point_patch {
   struct point_on_patch pop[1];
 };
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 /** \brief ???
  *
  * \todo Please doc me!
@@ -534,7 +534,7 @@ union patch {
   struct point_patch po;
   struct linear_patch lp;
   struct parameter_patch pa;
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   struct line_patch li;
         #endif
 } ;
diff --git a/dune/uggrid/gm/GenerateRules.cc b/dune/uggrid/gm/GenerateRules.cc
index 29d6aa6200ff0109e94a6568e99c9db6f286e70d..5f11b91f122054f09c9941995d83bf8601c20241 100644
--- a/dune/uggrid/gm/GenerateRules.cc
+++ b/dune/uggrid/gm/GenerateRules.cc
@@ -31,7 +31,7 @@
 #include <dune/uggrid/low/general.h>
 
 /* only compile for 3D version */
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 /****************************************************************************/
 /*																			*/
diff --git a/dune/uggrid/gm/algebra.cc b/dune/uggrid/gm/algebra.cc
index f0c83751284310072ce0b5f51f6863ac184157ac..1e4c2b15cb6d39fd97d027675c3f392dbb2edac8 100644
--- a/dune/uggrid/gm/algebra.cc
+++ b/dune/uggrid/gm/algebra.cc
@@ -118,7 +118,7 @@ USING_UGDIM_NAMESPACE
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 static MULTIGRID *GBNV_mg;                      /* multigrid							*/
 static INT GBNV_MarkKey;                        /* key for Mark/Release					*/
 #endif
@@ -139,7 +139,7 @@ static DOUBLE InvMeshSize;
 #ifdef ModelP
 INT NS_DIM_PREFIX GetVectorSize (GRID *theGrid, INT VectorObjType, GEOM_OBJECT *object)
 {
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   return sizeof(double);
 #else
   return 0;
@@ -179,7 +179,7 @@ static INT CreateVectorInPart (GRID *theGrid, INT DomPart, VectorType VectorObjT
   *vHandle = NULL;
 
   theMG = MYMG(theGrid);
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   vtype = SIDEVEC;
 #else
   vtype = NOVTYPE;
@@ -382,7 +382,7 @@ INT NS_DIM_PREFIX ReinspectSonSideVector (GRID *g, ELEMENT *elem, INT side, VECT
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX DisposeDoubledSideVector (GRID *theGrid, ELEMENT *Elem0, INT Side0, ELEMENT *Elem1, INT Side1)
 {
   VECTOR *Vector0, *Vector1;
@@ -480,7 +480,7 @@ INT NS_DIM_PREFIX DisposeElementList (GRID *theGrid, NODE *theNode)
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX GetVectorsOfSides (const ELEMENT *theElement, INT *cnt, VECTOR **vList)
 {
   INT i;
@@ -524,7 +524,7 @@ INT NS_DIM_PREFIX GetVectorsOfOType (const ELEMENT *theElement, INT type, INT *c
 {
   switch (type)
   {
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   case SIDEVEC :
     return (GetVectorsOfSides(theElement,cnt,vList));
         #endif
@@ -583,7 +583,7 @@ INT NS_DIM_PREFIX GetVectorsOfDataTypesInObjects (const ELEMENT *theElement, INT
 
   *cnt = n = 0;
 
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   if (obj & BITWISE_TYPE(SIDEVEC))
   {
     INT i;
@@ -639,7 +639,7 @@ static void PrintVectorTriple (int i)
 
 INT NS_DIM_PREFIX PrepareGetBoundaryNeighbourVectors (GRID *theGrid, INT *MaxListLen)
 {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   ELEMENT *elem;
   VECTOR *v0,*v1;
   INT i;
@@ -690,16 +690,16 @@ INT NS_DIM_PREFIX PrepareGetBoundaryNeighbourVectors (GRID *theGrid, INT *MaxLis
 
   return (0);
 
-#endif /* __TWODIM__ */
+#endif /* UG_DIM_2 */
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   /* 3D requires somewhat more work! */
 
   /* but it should be possible to create an oriented list
      of neighbours for each boundary vector */
 
   REP_ERR_RETURN (1);
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 }
 
 /****************************************************************************/
@@ -835,7 +835,7 @@ INT NS_DIM_PREFIX GetAllVectorsOfElement (GRID *theGrid, ELEMENT *theElement, VE
   INT cnt;
 
   cnt = 0;
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
   {
     INT i;
@@ -867,7 +867,7 @@ INT NS_DIM_PREFIX GetAllVectorsOfElement (GRID *theGrid, ELEMENT *theElement, VE
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX GetElementInfoFromSideVector (const VECTOR *theVector, ELEMENT **Elements, INT *Sides)
 {
   INT i;
@@ -1042,7 +1042,7 @@ INT NS_DIM_PREFIX SetSurfaceClasses (MULTIGRID *theMG)
 INT NS_DIM_PREFIX CreateAlgebra (MULTIGRID *theMG)
 {
   GRID *g;
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   VECTOR *nbvec;
   ELEMENT *nbelem;
   INT j,n;
@@ -1064,7 +1064,7 @@ INT NS_DIM_PREFIX CreateAlgebra (MULTIGRID *theMG)
         if (EMASTER(elem)) SETEBUILDCON(elem,1);
 
         /* side vectors */
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
           for (INT side=0; side<SIDES_OF_ELEM(elem); side++)
             if (SVECTOR(elem,side)==NULL) {
               VECTOR *vec;
@@ -1076,7 +1076,7 @@ INT NS_DIM_PREFIX CreateAlgebra (MULTIGRID *theMG)
 #endif
       }
     }
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     /* dispose doubled side vectors */
       for (elem=PFIRSTELEMENT(g); elem!=NULL; elem=SUCCE(elem))
       {
@@ -1318,7 +1318,7 @@ static INT CheckVector (const INT s2p[], GEOM_OBJECT *theObject, const char *Obj
   if (theVector == NULL)
   {
     /* check if size is really 0 */
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     VectorType vtype = SIDEVEC;
 #else
     VectorType vtype = NOVTYPE;
@@ -1412,7 +1412,7 @@ static INT CheckVector (const INT s2p[], GEOM_OBJECT *theObject, const char *Obj
         }
         else
         {
-                                        #ifdef __THREEDIM__
+                                        #ifdef UG_DIM_3
           if (VectorObjType == SIDEVEC)
           {
             /* TODO: check side vector */
@@ -1491,7 +1491,7 @@ INT NS_DIM_PREFIX CheckAlgebra (GRID *theGrid)
   for (theElement=PFIRSTELEMENT(theGrid); theElement!=NULL;
        theElement=SUCCE(theElement))
   {
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     /* check side vectors */
     if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
     {
@@ -1547,7 +1547,7 @@ INT NS_DIM_PREFIX VectorInElement (ELEMENT *theElement, VECTOR *theVector)
 {
   VECTOR *vList[20];
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (VOTYPE(theVector) == SIDEVEC)
   {
     INT cnt;
@@ -1578,7 +1578,7 @@ INT NS_DIM_PREFIX VectorInElement (ELEMENT *theElement, VECTOR *theVector)
 
 INT NS_DIM_PREFIX VectorPosition (const VECTOR *theVector, DOUBLE *position)
 {
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   ELEMENT *theElement;
   INT theSide,j;
         #endif
@@ -1596,7 +1596,7 @@ INT NS_DIM_PREFIX VectorPosition (const VECTOR *theVector, DOUBLE *position)
 
   switch (VOTYPE(theVector))
   {
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   case SIDEVEC :
     theElement = (ELEMENT *)VOBJECT(theVector);
     theSide = VECTORSIDE(theVector);
@@ -1635,7 +1635,7 @@ INT NS_DIM_PREFIX VectorPosition (const VECTOR *theVector, DOUBLE *position)
 
 INT NS_DIM_PREFIX SeedVectorClasses (GRID *theGrid, ELEMENT *theElement)
 {
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT cnt;
 
   VECTOR *vList[20];
@@ -1815,7 +1815,7 @@ INT NS_DIM_PREFIX ClearNextVectorClasses (GRID *theGrid)
 INT NS_DIM_PREFIX SeedNextVectorClasses (GRID *theGrid, ELEMENT *theElement)
 {
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
   {
     VECTOR *vList[20];
diff --git a/dune/uggrid/gm/algebra.h b/dune/uggrid/gm/algebra.h
index 1602c45395039d2c1d263bda784fc13ba44a9387..c897459e138bb93b31d3a13146587d10b0fd5750 100644
--- a/dune/uggrid/gm/algebra.h
+++ b/dune/uggrid/gm/algebra.h
@@ -101,7 +101,7 @@ INT         DisposeVector            (GRID *theGrid, VECTOR *theVector);
 
 /** @name More create and dispose */
 /*@{*/
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT             DisposeDoubledSideVector                (GRID *theGrid, ELEMENT *Elem0, INT Side0, ELEMENT *Elem1, INT Side1);
 #endif
 INT             DisposeElementList(GRID *theGrid, NODE *theNode);
diff --git a/dune/uggrid/gm/elements.cc b/dune/uggrid/gm/elements.cc
index 74846dc8d32ce9de91f4728435dd0d0a8930844c..6bff4c90c46d3140c076d965990a06048133c122 100644
--- a/dune/uggrid/gm/elements.cc
+++ b/dune/uggrid/gm/elements.cc
@@ -78,7 +78,7 @@ INT NS_DIM_PREFIX reference2tag[MAX_CORNERS_OF_ELEM+1];
 /*																			*/
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 static GENERAL_ELEMENT def_triangle = {
   3,                                                                                    /* tag							*/
   4,                                                                                    /* max number of sons			*/
@@ -111,7 +111,7 @@ static GENERAL_ELEMENT def_quadrilateral = {
 } ;
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static GENERAL_ELEMENT def_tetrahedron = {
   4,                                                                                    /* tag							*/
   12,                                                                                   /* max number of sons			*/
@@ -281,7 +281,7 @@ static INT PreProcessElementDescription (GENERAL_ELEMENT *el)
 {
   INT tag;
   INT i,j,k,l,n,from,to;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT m,n1,n2;
         #endif
 
@@ -371,7 +371,7 @@ static INT PreProcessElementDescription (GENERAL_ELEMENT *el)
     for (j=0; j<MAX_EDGES_OF_ELEM; j++)
       el->edge_of_corner[i][j] = -1;
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   switch (tag)
   {
   case TRIANGLE :
@@ -460,7 +460,7 @@ static INT PreProcessElementDescription (GENERAL_ELEMENT *el)
   }
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   /* edge_of_two_sides(i,j) */
   for (i=0; i<MAX_SIDES_OF_ELEM; i++)
     for (j=0; j<MAX_SIDES_OF_ELEM; j++)
@@ -811,10 +811,10 @@ static INT ProcessElementDescription (MULTIGRID *theMG, GENERAL_ELEMENT *el)
   /* the sons */
   sons_offset[tag] = 0;
   /*
-     #ifdef __TWODIM__
+     #ifdef UG_DIM_2
                   sons_offset[tag] = p_count; p_count += el->max_sons_of_elem;
      #endif
-     #ifdef __THREEDIM__
+     #ifdef UG_DIM_3
                   sons_offset[tag] = p_count; p_count++;
      #endif
    */
@@ -835,7 +835,7 @@ static INT ProcessElementDescription (MULTIGRID *theMG, GENERAL_ELEMENT *el)
 
   /* side vector */
   svector_offset[tag] = 0;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (VEC_DEF_IN_OBJ_OF_MG(theMG,SIDEVEC))
   {
     svector_offset[tag] = p_count;
@@ -880,14 +880,14 @@ INT NS_DIM_PREFIX PreInitElementTypes (void)
 {
   INT err;
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   err = PreProcessElementDescription(&def_triangle);
   if (err!=GM_OK) return(err);
   err = PreProcessElementDescription(&def_quadrilateral);
   if (err!=GM_OK) return(err);
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   err = PreProcessElementDescription(&def_tetrahedron);
   if (err!=GM_OK) return(err);
   err = PreProcessElementDescription(&def_pyramid);
@@ -922,14 +922,14 @@ INT NS_DIM_PREFIX InitElementTypes (MULTIGRID *theMG)
   if (theMG==NULL)
     return(GM_ERROR);
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   err = ProcessElementDescription(theMG,&def_triangle);
   if (err!=GM_OK) return(err);
   err = ProcessElementDescription(theMG,&def_quadrilateral);
   if (err!=GM_OK) return(err);
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   err = ProcessElementDescription(theMG,&def_tetrahedron);
   if (err!=GM_OK) return(err);
   err = ProcessElementDescription(theMG,&def_pyramid);
diff --git a/dune/uggrid/gm/er.cc b/dune/uggrid/gm/er.cc
index 762730b56427513316d300b40abc43a36713215a..c01ac30ce39cb8eed20d7e635b0e046d4496f1fe 100644
--- a/dune/uggrid/gm/er.cc
+++ b/dune/uggrid/gm/er.cc
@@ -376,7 +376,7 @@ static void FillOrderedSons (const ERULE *er, DOUBLE oco[])
    doctext_disabled*/
 /****************************************************************************/
 
-#if (defined __THREEDIM__) || (defined __DEBUG_ER__)
+#if (defined UG_DIM_3) || (defined __DEBUG_ER__)
 static INT Hash_Init (int MarkKey)
 {
   int i;
@@ -505,7 +505,7 @@ static INT SonsAreEqual (INT nsons, const DOUBLE oco[], const HRULE *hr)
    doctext_disabled*/
 /****************************************************************************/
 
-#if (defined __THREEDIM__) || (defined __DEBUG_ER__)
+#if (defined UG_DIM_3) || (defined __DEBUG_ER__)
 static HRID GetRuleID
 (
         #ifdef Debug
@@ -732,7 +732,7 @@ static INT ExtractERule (ELEMENT *elem, ERULE *er)
    doctext_disabled*/
 /****************************************************************************/
 
-#if (defined __THREEDIM__) || (defined __DEBUG_ER__)
+#if (defined UG_DIM_3) || (defined __DEBUG_ER__)
 static int CountIFElements (DDD::DDDContext&, DDD_OBJ obj)
 {
   ELEMENT *elem = (ELEMENT*) obj;
@@ -1081,7 +1081,7 @@ static INT ExtractInterfaceRules (MULTIGRID *mg)
    doctext_disabled*/
 /****************************************************************************/
 
-#if (defined __THREEDIM__) || (defined __DEBUG_ER__)
+#if (defined UG_DIM_3) || (defined __DEBUG_ER__)
 static INT ExtractRules (MULTIGRID *mg)
 {
   ELEMENT *elem;
@@ -1273,7 +1273,7 @@ static void FindPathForNeighbours (MGIO_RR_RULE *rule, SHORT myID, SHORT Status[
    .n   none
    doctext_disabled*/
 /****************************************************************************/
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static void FillSonPaths (MGIO_RR_RULE *rule)
 {
   SHORT Status[MAX_SONS];
@@ -1348,7 +1348,7 @@ static INT GetFSidesOfCorners (int tag, int n, SHORT corners[MAX_CORNERS_OF_SIDE
       /* edge mid node */
       int ed = corners[co]-coe;
 
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
       corner_on_side[co][ed] = true;
                         #else
       int i;
@@ -1360,7 +1360,7 @@ static INT GetFSidesOfCorners (int tag, int n, SHORT corners[MAX_CORNERS_OF_SIDE
       }
                         #endif
     }
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   else if (corners[co]<(coe+eoe+soe))
   {
     /* side mid */
@@ -1613,7 +1613,7 @@ static void HRule2Mrule (const HRULE *hr, MGIO_RR_RULE *mr)
       }
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* 2D: not even in rm */
   /* son path */
   FillSonPaths(mr);
@@ -1930,7 +1930,7 @@ static void CheckMRules (MULTIGRID *mg, INT RefRuleOffset[], MGIO_RR_RULE *mrule
               }
             }
                                                 #ifndef ModelP
-                                                #ifdef __THREEDIM__
+                                                #ifdef UG_DIM_3
             /* check path
                     NOT CONSISTENT in rm since not used (says Stefan, 971219)
                if (s>0)
@@ -2063,7 +2063,7 @@ INT NS_DIM_PREFIX NEW_Write_RefRules (MULTIGRID *mg, INT RefRuleOffset[], INT Ma
   for (tag=0; tag<TAGS; tag++)
     global.maxrule[tag] = UGMAXRULE(tag);
 
-        #if (defined __THREEDIM__) || (defined __DEBUG_ER__)
+        #if (defined UG_DIM_3) || (defined __DEBUG_ER__)
   /* incomplete refrule set: extract non-existing rules that are realized in mg */
   if (ExtractRules(mg))
     REP_ERR_RETURN(1);
diff --git a/dune/uggrid/gm/evm.cc b/dune/uggrid/gm/evm.cc
index 47fc92bb9d5bad58664f8c56ef83f58c9e966ab4..e4c137340d00ec2bda96fb84bbb305d8bf759fe7 100644
--- a/dune/uggrid/gm/evm.cc
+++ b/dune/uggrid/gm/evm.cc
@@ -70,11 +70,11 @@ USING_UG_NAMESPACE
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 const DOUBLE NS_DIM_PREFIX unit_vec[DIM][DIM]={{1,0},{0,1}};
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 const DOUBLE NS_DIM_PREFIX unit_vec[DIM][DIM]={{1,0,0},{0,1,0},{0,0,1}};
 #endif
 
@@ -476,7 +476,7 @@ DOUBLE NS_DIM_PREFIX GeneralElementVolume (INT tag, DOUBLE *x_co[])
 {
   switch (tag)
   {
-#               ifdef __TWODIM__
+#               ifdef UG_DIM_2
   case TRIANGLE :
     return(c_tarea (x_co[0],x_co[1],x_co[2]));
 
@@ -484,7 +484,7 @@ DOUBLE NS_DIM_PREFIX GeneralElementVolume (INT tag, DOUBLE *x_co[])
     return(c_qarea (x_co[0],x_co[1],x_co[2],x_co[3]));
 #               endif
 
-#               ifdef __THREEDIM__
+#               ifdef UG_DIM_3
   case TETRAHEDRON :
     return(V_te(x_co[0],x_co[1],x_co[2],x_co[3]));
 
diff --git a/dune/uggrid/gm/evm.h b/dune/uggrid/gm/evm.h
index 6fd533ffe813a86d028a1c462a21441f9d30f6c1..1a4a2e6bd5a5c8d1a253362862d09128ef3956d8 100644
--- a/dune/uggrid/gm/evm.h
+++ b/dune/uggrid/gm/evm.h
@@ -195,7 +195,7 @@ START_UGDIM_NAMESPACE
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 
 #define V_BDIM_COPY(A,C)                        V1_COPY(A,C)
 
@@ -216,7 +216,7 @@ START_UGDIM_NAMESPACE
 
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 #define V_BDIM_COPY(A,C)                        V2_COPY(A,C)
 
diff --git a/dune/uggrid/gm/gm.h b/dune/uggrid/gm/gm.h
index a0154a71f3f2ec97c233633e0eac7f2bf59f2231..955d0cbc456fcc8f9559127b5faa295c5b7cc97e 100644
--- a/dune/uggrid/gm/gm.h
+++ b/dune/uggrid/gm/gm.h
@@ -77,7 +77,7 @@
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 #ifdef Sideon
 #error ****   two dimensional case cannot have side data        ****
 #endif
@@ -234,11 +234,11 @@ enum RefinementRule
 {NO_REFINEMENT = 0,
  COPY = 1,
  RED =  2,
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
  BLUE = 3,   // For quadrilaterals
 #endif
  COARSE = 4,
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
  // The BISECTION* rules are all triangle rules
  BISECTION_1 = 5,
  BISECTION_2_Q = 6,
@@ -246,7 +246,7 @@ enum RefinementRule
  BISECTION_2_T2 = 8,
  BISECTION_3 = 9
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
  TETRA_RED_HEX = 5,
 
@@ -632,7 +632,7 @@ struct link {
   struct node *nbnode;
 
   /** \brief ptr to neighboring elem                              */
-#if defined(__TWODIM__)
+#if defined(UG_DIM_2)
   union element *elem;
 #endif
 
@@ -1270,11 +1270,11 @@ struct hexahedron {
 /** \brief Objects that can hold an element */
 union element {
   struct generic_element ge;
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   struct triangle tr;
   struct quadrilateral qu;
         #endif
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   struct tetrahedron te;
   struct pyramid py;
   struct prism pr;
@@ -1750,13 +1750,13 @@ enum LV_ID_TYPES {
    add the weighted significant digits of the coordinates; the weights
    may not have a common divisor to ensure uniqueness of the result;
    take from this again the sigificant digits */
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 #define COORDINATE_TO_KEY(coord,dummy_int_ptr)  ((INT)(SIGNIFICANT_DIGITS((SIGNIFICANT_DIGITS((coord)[0],(dummy_int_ptr))*1.246509423749342 + \
                                                                            SIGNIFICANT_DIGITS((coord)[1],(dummy_int_ptr))*PI)\
                                                                           , (dummy_int_ptr))))
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define COORDINATE_TO_KEY(coord,dummy_int_ptr)  ((INT)(SIGNIFICANT_DIGITS((SIGNIFICANT_DIGITS((coord)[0],(dummy_int_ptr))*1.246509423749342 + \
                                                                            SIGNIFICANT_DIGITS((coord)[1],(dummy_int_ptr))*PI + \
                                                                            SIGNIFICANT_DIGITS((coord)[2],(dummy_int_ptr))*0.76453456834568356936598)\
@@ -2276,7 +2276,7 @@ enum GM_OBJECTS {
 #define MYEDGE(p)                                       ((EDGE *)((p)-LOFFSET(p)))
 #define REVERSE(p)                                      ((p)+(1-LOFFSET(p)*2))
 
-#if defined(__TWODIM__)
+#if defined(UG_DIM_2)
 #define LELEM(p)                                        ((p)->elem)
 #define SET_LELEM(p,e)                                  ((p)->elem = (e))
 #endif
@@ -2488,7 +2488,7 @@ START_UGDIM_NAMESPACE
 /** \todo NbElem is declared in ugm.h, but never defined.
     We need a clean solution. */
 /*
-   #if defined(__TWODIM__)
+   #if defined(UG_DIM_2)
    #define NBELEM(p,i)     NbElem((p),(i))
    #else
  */
@@ -2504,11 +2504,11 @@ START_UGDIM_NAMESPACE
 #define INNER_BOUNDARY(p,i) (InnerBoundary(p,i))
 /* TODO: replace by function call */
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 #define EDGE_ON_BND(p,i) (ELEM_BNDS(p,i) != NULL)
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define EDGE_ON_BND(p,i) (SIDE_ON_BND(p,SIDE_WITH_EDGE(p,i,0)) || \
                           SIDE_ON_BND(p,SIDE_WITH_EDGE(p,i,1)))
 #endif
@@ -2525,7 +2525,7 @@ START_UGDIM_NAMESPACE
 /** \todo Set_NbElem is declared in ugm.h, but never defined.
     We need a clean solution. */
 /*
-   #if defined(__TWODIM__)
+   #if defined(UG_DIM_2)
    #define SET_NBELEM(p,i,q)       Set_NbElem((p),(i),(q))
    #else
  */
@@ -2533,7 +2533,7 @@ START_UGDIM_NAMESPACE
 /*
    #endif
  */
-#if defined(__TWODIM__)
+#if defined(UG_DIM_2)
 #define VOID_NBELEM(p,i)        NBELEM(p,i)
 #else
 #define VOID_NBELEM(p,i)        ((p)->ge.refs[nb_offset[TAG(p)]+(i)])
@@ -2731,7 +2731,7 @@ START_UGDIM_NAMESPACE
 #endif
 #define NE(p)                           ((p)->nEdge)
 #define NS(p)                           ((p)->nSide)
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define VEC_DEF_IN_OBJ_OF_GRID(p,tp)     (true)   // 3d grids have side vectors
 #else
 #define VEC_DEF_IN_OBJ_OF_GRID(p,tp)     (false)  // 2d grids have no vectors at all
@@ -2788,7 +2788,7 @@ grid::dddContext()
 #define MG_NPROPERTY(p)                 ((p)->nProperty)
 #define GRID_ON_LEVEL(p,i)              ((p)->grids[i])
 #define MGNAME(p)                               ((p)->v.name)
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define VEC_DEF_IN_OBJ_OF_MG(p,tp)     (true)   // 3d grids have side vectors
 #else
 #define VEC_DEF_IN_OBJ_OF_MG(p,tp)     (false)  // 2d grids have no vectors at all
@@ -2804,7 +2804,7 @@ grid::dddContext()
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define FMT_S_VEC_TP(f,t)                               (sizeof(double))
 #else
 #define FMT_S_VEC_TP(f,t)                               (0)
@@ -2921,7 +2921,7 @@ INT         SetRefineInfo           (MULTIGRID *theMG);
 
 
 /* moving nodes */
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT                     GetSideIDFromScratch    (ELEMENT *theElement, NODE *theNode);
 #endif
 
@@ -2949,7 +2949,7 @@ LINK            *GetLink                                (const NODE *from, const
 EDGE            *GetSonEdge                             (const EDGE *theEdge);
 INT                     GetSonEdges                             (const EDGE *theEdge, EDGE *SonEdges[MAX_SON_EDGES]);
 EDGE            *GetFatherEdge                  (const EDGE *theEdge);
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 EDGE            *FatherEdge                             (NODE **SideNodes, INT ncorners, NODE **Nodes, EDGE *theEdge);
 #endif
 EDGE            *GetEdge                                (const NODE *from, const NODE *to);
diff --git a/dune/uggrid/gm/gmcheck.cc b/dune/uggrid/gm/gmcheck.cc
index d77e2de46bd3d26748743f8107237ac59c3d50b5..b6fe49ea6384126601dbd4aa8e6d2fc3fa1a5c93 100644
--- a/dune/uggrid/gm/gmcheck.cc
+++ b/dune/uggrid/gm/gmcheck.cc
@@ -255,7 +255,7 @@ static INT CheckVertex (ELEMENT *theElement, NODE* theNode, VERTEX *theVertex)
     }
     break;
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   case (SIDE_NODE) :
     if (theFather == NULL)
     {
@@ -514,7 +514,7 @@ static INT CheckEdge (ELEMENT *theElement, EDGE* theEdge, INT i)
 
   /** \todo Commented out because it uses GetElemLink, which does not exist */
 #if 0
-#       if defined(__TWODIM__)
+#       if defined(UG_DIM_2)
   {
     int elemlink,no_of_elem,No_Of_Elem;
     NODE *n0,*n1;
@@ -675,7 +675,7 @@ static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT
   ELEMENT *SonList[MAX_SONS];
   VERTEX  *theVertex,*Vertices[MAX_CORNERS_OF_ELEM];
 
-#if defined(ModelP) && defined(__TWODIM__)
+#if defined(ModelP) && defined(UG_DIM_2)
   auto& dddContext = theGrid->dddContext();
 #endif
 
@@ -879,7 +879,7 @@ static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT
         if (OBJT(theElement) == IEOBJ)
                                 #ifdef ModelP
           if (EMASTER(theElement))
-                                #if defined(__TWODIM__)
+                                #if defined(UG_DIM_2)
             if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
                                 #endif
                                 #endif
@@ -891,7 +891,7 @@ static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT
         {
                                   #ifdef ModelP
           if (EMASTER(theElement))
-                                  #if defined(__TWODIM__)
+                                  #if defined(UG_DIM_2)
             if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
                                   #endif
                                   #endif
@@ -911,7 +911,7 @@ static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT
         else if (ECLASS(theElement)!=YELLOW_CLASS)
                                         #ifdef ModelP
           if (EMASTER(theElement))
-                                    #if defined(__TWODIM__)
+                                    #if defined(UG_DIM_2)
             if (hghost_overlap!=0.0 || EdgeHasTMasterCopy(dddContext, theElement,i)==0)
                                         #endif
                                         #endif
@@ -1114,7 +1114,7 @@ static INT CheckElement (GRID *theGrid, ELEMENT *theElement, INT *SideError, INT
   return (0);
 }
 
-#if defined(__TWODIM__) || defined(ModelP)
+#if defined(UG_DIM_2) || defined(ModelP)
 
 INT CheckSubdomains (MULTIGRID *theMG)
 {
diff --git a/dune/uggrid/gm/refine.cc b/dune/uggrid/gm/refine.cc
index b1209829eb249add12b4e599cdd20c8553bfb7da..4a1968de926b5e3fdc28a507ebfadf248f5f94e9 100644
--- a/dune/uggrid/gm/refine.cc
+++ b/dune/uggrid/gm/refine.cc
@@ -499,7 +499,7 @@ static INT InitClosureFIFO (void)
 
 static INT UpdateFIFOLists (GRID *theGrid, ELEMENT *theElement, INT thePattern, INT NewPattern)
 {
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   INT j;
   EDGE    *theEdge;
   ELEMENT *NbElement;
@@ -507,7 +507,7 @@ static INT UpdateFIFOLists (GRID *theGrid, ELEMENT *theElement, INT thePattern,
 
   if (MARKCLASS(theElement)==RED_CLASS && thePattern!=NewPattern)
   {
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
     for (j=0; j<EDGES_OF_ELEM(theElement); j++)
     {
       if (EDGE_IN_PAT(thePattern,j)==0 &&
@@ -565,7 +565,7 @@ static INT UpdateFIFOLists (GRID *theGrid, ELEMENT *theElement, INT thePattern,
       }
     }
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     UserWriteF("UpdateFIFOLists(): ERROR fifo for 3D NOT implemented!\n");
     ASSERT(0);
                 #endif
@@ -779,7 +779,7 @@ static int Gather_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data,
 
   refinedata = 0;
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   GetEdgeInfo(theElement,&refinedata,PATTERN);
         #endif
 
@@ -827,7 +827,7 @@ static int Scatter_ElementClosureInfo (DDD::DDDContext&, DDD_OBJ obj, void *data
 
   refinedata = ((INT *)data)[0];
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   SetEdgeInfo(theElement,refinedata,PATTERN,|);
         #endif
 
@@ -903,7 +903,7 @@ static INT ExchangeElementRefine (GRID *theGrid)
   return(GM_OK);
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 /****************************************************************************/
 /*
@@ -1010,7 +1010,7 @@ static INT ExchangeClosureInfo (GRID *theGrid)
   /* exchange information of elements to compute closure */
   if (ExchangeElementClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* exchange information of edges to compute closure */
   if (ExchangeEdgeClosureInfo(theGrid) != GM_OK) RETURN(GM_ERROR);
         #endif
@@ -1058,7 +1058,7 @@ static INT ComputePatterns (GRID *theGrid)
                 #ifdef ModelP
     if (EGHOST(theElement))
     {
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
       SETSIDEPATTERN(theElement,0);
                         #endif
       continue;
@@ -1081,7 +1081,7 @@ static INT ComputePatterns (GRID *theGrid)
           SETPATTERN(theEdge,1);
         }
 
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
       /* SIDEPATTERN must be reset here for master elements, */
       /* because it overlaps with MARK (980217 s.l.)         */
       SETSIDEPATTERN(theElement,0);
@@ -1103,7 +1103,7 @@ static INT ComputePatterns (GRID *theGrid)
     }
     else
     {
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
       /* SIDEPATTERN must be reset here for master elements, */
       /* because it overlaps with MARK (980217 s.l.)         */
       SETSIDEPATTERN(theElement,0);
@@ -1115,7 +1115,7 @@ static INT ComputePatterns (GRID *theGrid)
   return(GM_OK);
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #ifdef DUNE_UGGRID_TET_RULESET
 
 /****************************************************************************/
@@ -1443,12 +1443,12 @@ static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt)
     /* compute element pattern */
     GetEdgeInfo(theElement,&theEdgePattern,PATTERN);
 
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
     thePattern = theEdgePattern;
     PRINTDEBUG(gm,2,(PFMT "SetElementRules(): e=" EID_FMTX " edgepattern=%d\n",
                      me,EID_PRTX(theElement),theEdgePattern));
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     theSidePattern = SIDEPATTERN(theElement);
     thePattern = theSidePattern<<EDGES_OF_ELEM(theElement) | theEdgePattern;
     PRINTDEBUG(gm,2,(PFMT "SetElementRules(): e=" EID_FMTX
@@ -1512,7 +1512,7 @@ static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt)
 
     REFINE_ELEMENT_LIST(1,theElement,"");
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     /* choose best tet_red rule according to (*theFullRefRule)() */
     if (TAG(theElement)==TETRAHEDRON && MARKCLASS(theElement)==RED_CLASS)
     {
@@ -1574,7 +1574,7 @@ static INT SetElementRules (GRID *theGrid, ELEMENT *firstElement, INT *cnt)
 
 static int Gather_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data)
 {
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   INT pat;
   ELEMENT *theElement = (ELEMENT *)obj;
 
@@ -1588,7 +1588,7 @@ static int Gather_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data)
   return(GM_OK);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT addpattern;
   EDGE    *theEdge = (EDGE *)obj;
 
@@ -1623,7 +1623,7 @@ static int Gather_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data)
 
 static int Scatter_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data)
 {
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   INT pat;
   ELEMENT *theElement = (ELEMENT *)obj;
 
@@ -1637,7 +1637,7 @@ static int Scatter_AddEdgePattern (DDD::DDDContext&, DDD_OBJ obj, void *data)
   return(GM_OK);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT addpattern;
   EDGE    *theEdge = (EDGE *)obj;
 
@@ -1676,12 +1676,12 @@ static INT ExchangeAddPatterns (GRID *theGrid)
   const auto& dddctrl = ddd_ctrl(context);
 
   /* exchange addpatterns of edges */
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   DDD_IFAOneway(context,
                 dddctrl.ElementVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT),
                 Gather_AddEdgePattern, Scatter_AddEdgePattern);
         #endif
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   DDD_IFAOneway(context,
                 dddctrl.EdgeVHIF,GRID_ATTR(theGrid),IF_FORWARD,sizeof(INT),
                 Gather_AddEdgePattern, Scatter_AddEdgePattern);
@@ -1768,7 +1768,7 @@ static INT BuildGreenClosure (GRID *theGrid)
   INT i;
   ELEMENT *theElement;
   EDGE    *theEdge;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT j;
         #endif
 
@@ -1847,7 +1847,7 @@ static INT BuildGreenClosure (GRID *theGrid)
       }
     }
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     /* if side node exists element needs to be green */
     for (i=0; i<SIDES_OF_ELEM(theElement); i++)
     {
@@ -2046,7 +2046,7 @@ static int Scatter_ElementInfo (DDD::DDDContext&, DDD_OBJ obj, void *Data)
   COMPARE_MACRO(theElement,theMaster,COARSEN,PrintDebug)
   COMPARE_MACRO(theElement,theMaster,USED,PrintDebug)
   /*	#ifndef DUNE_UGGRID_TET_RULESET */
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   COMPARE_MACRO(theElement,theMaster,SIDEPATTERN,PrintDebug)
         #endif
   /*	#endif */
@@ -2135,7 +2135,7 @@ static int GridClosure (GRID *theGrid)
   /* fifo loop */
   do
   {
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
                 #if defined(ModelP) && defined(DUNE_UGGRID_TET_RULESET)
     /* edge pattern is needed consistently in CorrectTetrahedronSidePattern() */
     if (!refine_seq)
@@ -2396,7 +2396,7 @@ INT NS_DIM_PREFIX GetSons (const ELEMENT *theElement, ELEMENT *SonList[MAX_SONS]
 
 static INT RestrictElementMark(ELEMENT *theElement)
 {
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
         #ifdef DUNE_UGGRID_TET_RULESET
   EDGE *theEdge;
   int j,Rule,Pattern;
@@ -2411,7 +2411,7 @@ static INT RestrictElementMark(ELEMENT *theElement)
     /* for different restrictions              */
     switch (TAG(theElement))
     {
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
     case TRIANGLE :
       SETMARK(theElement,T_RED);
       break;
@@ -2419,7 +2419,7 @@ static INT RestrictElementMark(ELEMENT *theElement)
       SETMARK(theElement,Q_RED);
       break;
                         #endif
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
     case TETRAHEDRON :
 #ifdef DUNE_UGGRID_TET_RULESET
       if (MARK(theElement)!=RED)
@@ -2449,7 +2449,7 @@ static INT RestrictElementMark(ELEMENT *theElement)
     /** \todo edit this for new element type or for different restrictions */
     switch (TAG(theElement))
     {
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
     case TRIANGLE :
       SETMARK(theElement,T_RED);
       break;
@@ -2458,7 +2458,7 @@ static INT RestrictElementMark(ELEMENT *theElement)
       SETMARK(theElement,Q_RED);
       break;
                         #endif
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
     case TETRAHEDRON :
 #ifdef DUNE_UGGRID_TET_RULESET
       /* theElement is not marked from outside, */
@@ -2780,7 +2780,7 @@ static void CheckElementContextConsistency(ELEMENT *theElement,
       }
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* check side nodes */
   for (i=CORNERS_OF_ELEM(theElement)+EDGES_OF_ELEM(theElement);
        i<CORNERS_OF_ELEM(theElement)+EDGES_OF_ELEM(theElement)+
@@ -2846,7 +2846,7 @@ static void CheckElementContextConsistency(ELEMENT *theElement,
 static int UpdateContext (GRID *theGrid, ELEMENT *theElement, NODE **theElementContext)
 {
   bool toCreate;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   ELEMENT *theNeighbor;                         /* neighbor and a son of current elem.	*/
   EDGE *fatherEdge;
   INT j;
@@ -2951,7 +2951,7 @@ static int UpdateContext (GRID *theGrid, ELEMENT *theElement, NODE **theElementC
   UserWriteF("\n");
   ENDDEBUG
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* nodes on refined sides */
   NODE** SideNodes = theElementContext+CORNERS_OF_ELEM(theElement)+
               EDGES_OF_ELEM(theElement);
@@ -3265,13 +3265,13 @@ INT NS_DIM_PREFIX GetSonSideNodes (const ELEMENT *theElement, INT side, INT *nod
   for (i=0; i<nedges; i++)
   {
     /** \todo delete
-       #ifdef __TWODIM__
+       #ifdef UG_DIM_2
        ASSERT(OBJT(NFATHER(SideNodes[i])) == NDOBJ);
        ASSERT(OBJT(NFATHER(SideNodes[i+1])) == NDOBJ);
         theEdge = GetEdge((NODE *)NFATHER(SideNodes[i]),
                                           (NODE *)NFATHER(SideNodes[i+1]));
        #endif
-       #ifdef __THREEDIM__
+       #ifdef UG_DIM_3
        ASSERT(OBJT(NFATHER(SideNodes[i])) == NDOBJ);
        ASSERT(OBJT(NFATHER(SideNodes[(i+1)%nedges])) == NDOBJ);
         theEdge = GetEdge((NODE *)NFATHER(SideNodes[i]),
@@ -3299,7 +3299,7 @@ INT NS_DIM_PREFIX GetSonSideNodes (const ELEMENT *theElement, INT side, INT *nod
     }
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* determine side node */
   {
     NODE *theNode;
@@ -3400,10 +3400,10 @@ INT NS_DIM_PREFIX Get_Sons_of_ElementSide (const ELEMENT *theElement, INT side,
     UserWriteF("   son[%d]=" EID_FMTX "\n",i,EID_PRTX(SonList[i]));
   ENDDEBUG
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   markclass = RED_CLASS;
         #endif
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* The following line used to read: markclass = (enum MarkClass) MARKCLASS(theElement);
      This works well within the UG grid refinement context.  However, now I want to use this
      method within the DUNE UGGridLeafIntersectionIterator.  The problem is that the user
@@ -3493,7 +3493,7 @@ INT NS_DIM_PREFIX Get_Sons_of_ElementSide (const ELEMENT *theElement, INT side,
       ENDDEBUG
 
       /* sonside on side */
-                                #ifdef __TWODIM__
+                                #ifdef UG_DIM_2
       assert(n<=2);
       if (n==2)
       {
@@ -3509,7 +3509,7 @@ INT NS_DIM_PREFIX Get_Sons_of_ElementSide (const ELEMENT *theElement, INT side,
         nsons++;
       }
                                 #endif
-                                #ifdef __THREEDIM__
+                                #ifdef UG_DIM_3
       if (n==3 || n==4)
       {
         INT edge0,edge1,sonside,side0,side1;
@@ -3674,10 +3674,10 @@ static INT Sort_Node_Ptr (INT n,NODE **nodes)
   switch (n)
   {
 
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
   case 2 :
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   case 3 :
   case 4 :
                 #endif
@@ -4076,7 +4076,7 @@ INT NS_DIM_PREFIX Connect_Sons_of_ElementSide (GRID *theGrid, ELEMENT *theElemen
                  NbSortTable[i]->elem);
       SET_NBELEM(NbSortTable[i]->elem,NbSortTable[i]->side,
                  ElemSortTable[i]->elem);
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
       if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
         if (DisposeDoubledSideVector(theGrid,ElemSortTable[i]->elem,
                                      ElemSortTable[i]->side,
@@ -5090,7 +5090,7 @@ static int RefineElementGreen (GRID *theGrid, ELEMENT *theElement, NODE **theCon
     }
   }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   /* If there are side vectors for the elements, then the CreateElement methods called above have
    * allocated one side vector for each new element face.  Therefore, for each face shared by
    * two elements there are now two side vectors, even though there should be only one (shared).
@@ -5279,10 +5279,10 @@ static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theEleme
                 }
             switch (pts)
             {
-                                                        #ifdef __TWODIM__
+                                                        #ifdef UG_DIM_2
             case (LINEPOINTS) :
                                                         #endif
-                                                        #ifdef __THREEDIM__
+                                                        #ifdef UG_DIM_3
             case (TRIPOINTS) :
             case (QUADPOINTS) :
                                                         #endif
@@ -5310,7 +5310,7 @@ static int RefineElementRed (GRID *theGrid, ELEMENT *theElement, NODE **theEleme
         ASSERT(SonList[side]!=NULL);
 
         /* dispose doubled side vectors if */
-                                #ifdef __THREEDIM__
+                                #ifdef UG_DIM_3
         if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
         {
           INT l;
diff --git a/dune/uggrid/gm/rm-write2file.cc b/dune/uggrid/gm/rm-write2file.cc
index 8b082be79a6df4e3a466f35b0220c4586f6dd80f..a25932a644116df8c262c3cafd3ff0823348820c 100644
--- a/dune/uggrid/gm/rm-write2file.cc
+++ b/dune/uggrid/gm/rm-write2file.cc
@@ -4,7 +4,7 @@
 
 #include "rm-write2file.h"
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static NS_DIM_PREFIX REFRULE Empty_Rule =
 {-1,-1,NS_DIM_PREFIX NO_CLASS,-1,
  {-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1},
diff --git a/dune/uggrid/gm/rm.cc b/dune/uggrid/gm/rm.cc
index 8bbbf8183cd68336214e644120347ba999e3287c..b4de100bb33bf547e404310d6113f2045a4c3730 100644
--- a/dune/uggrid/gm/rm.cc
+++ b/dune/uggrid/gm/rm.cc
@@ -77,7 +77,7 @@ USING_UG_NAMESPACES
 #define NOINDEX         -1
 
 /* rule count for element types */
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 #define MAX_TRI_RULES   18
 #define MAX_QUA_RULES   17
 #else
@@ -112,7 +112,7 @@ INT NS_DIM_PREFIX CenterNodeIndex[TAGS] = {0,0,0,0,0,0,0,0};
 REFRULE * NS_DIM_PREFIX RefRules[TAGS] = {NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL};
 SHORT const* NS_DIM_PREFIX Pattern2Rule[TAGS];
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 /* define the standard regular rules for tetrahedrons */
 FULLREFRULEPTR NS_DIM_PREFIX theFullRefRule;
 #endif
@@ -124,7 +124,7 @@ FULLREFRULEPTR NS_DIM_PREFIX theFullRefRule;
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 [[maybe_unused]] static REFRULE Empty_Rule =
 {-1,-1,NO_CLASS,-1,{-1,-1,-1,-1},-1,
  {{-1,-1},{-1,-1},{-1,-1},{-1,-1},{-1,-1}},
@@ -461,7 +461,7 @@ static REFRULE QuadrilateralRules[MAX_QUA_RULES] =
 
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 static INT theBFRRDirID;      /* env type for BestFullRefRule       */
 static INT theBFRRVarID;
@@ -1484,7 +1484,7 @@ static REFRULE HexahedronRules[MAX_HEX_RULES] =
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 INT NS_DIM_PREFIX GetRule_AnisotropicRed (ELEMENT *theElement, INT *Rule)
 {
@@ -2047,7 +2047,7 @@ static INT MaxArea (ELEMENT *theElement)
   return (refrule);
 }
 
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 
 
 /****************************************************************************/
@@ -2084,7 +2084,7 @@ INT NS_DIM_PREFIX MarkForRefinement (ELEMENT *theElement, enum RefinementRule ru
   /* choose dimension */
   switch (DIM)
   {
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
   /* 2D case */
   case (2) :
 
@@ -2194,10 +2194,10 @@ INT NS_DIM_PREFIX MarkForRefinement (ELEMENT *theElement, enum RefinementRule ru
       return(GM_ERROR);
     }
     break;
-                        #endif /* __TWODIM__ */
+                        #endif /* UG_DIM_2 */
 
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   /* 3D case */
   case (3) :
     switch (TAG(theElement))
@@ -2410,7 +2410,7 @@ INT NS_DIM_PREFIX MarkForRefinement (ELEMENT *theElement, enum RefinementRule ru
       return(GM_ERROR);
     }
     break;
-                        #endif /* __THREEDIM__ */
+                        #endif /* UG_DIM_3 */
 
   default :
     return(GM_ERROR);
@@ -2457,7 +2457,7 @@ INT NS_DIM_PREFIX EstimateHere (const ELEMENT *theElement)
 
 INT NS_DIM_PREFIX Patterns2Rules(ELEMENT *theElement, INT pattern)
 {
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   switch (TAG(theElement)) {
   case (TRIANGLE) :
     switch (pattern) {
@@ -2524,7 +2524,7 @@ INT NS_DIM_PREFIX Patterns2Rules(ELEMENT *theElement, INT pattern)
     assert(0); return(-1);
   }
         #endif
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   switch (TAG(theElement)) {
   case (TETRAHEDRON) :
 #ifdef DUNE_UGGRID_TET_RULESET
@@ -2720,7 +2720,7 @@ INT NS_DIM_PREFIX GetRefinementMark (ELEMENT *theElement, INT *rule, void *data)
 
   mark = MARK(theElement);
 
-        #if defined(__THREEDIM__)
+        #if defined(UG_DIM_3)
   /* tetrahedra have three red rules */
   if (TAG(theElement)==TETRAHEDRON &&
       (mark==TET_RED_2_4 || mark==TET_RED_0_5 || mark==TET_RED_1_3))
@@ -2735,7 +2735,7 @@ INT NS_DIM_PREFIX GetRefinementMark (ELEMENT *theElement, INT *rule, void *data)
   case RED :
     *rule=RED;
     break;
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   case Q_BLUE_0 :
     *rule = BLUE;
     break;
@@ -2788,7 +2788,7 @@ INT NS_DIM_PREFIX GetRefinementMarkType (ELEMENT *theElement)
   switch (rule)
   {
   case RED :
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   case BLUE :
 #endif
     return(1);
@@ -2951,7 +2951,7 @@ INT NS_DIM_PREFIX ShowRefRule (INT tag, INT nb)
 
 
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 /****************************************************************************/
 /** \brief
@@ -3104,9 +3104,9 @@ static INT InitRuleManager3D (void)
 }
 
 
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 
 
 /****************************************************************************/
@@ -3215,7 +3215,7 @@ static INT InitRuleManager2D (void)
 
   return (GM_OK);
 }
-#endif /* __TWODIM__ */
+#endif /* UG_DIM_2 */
 
 
 /****************************************************************************/
diff --git a/dune/uggrid/gm/rm.h b/dune/uggrid/gm/rm.h
index 92ae59ffa5e76217069f4f00dcd12174cedde1e9..16b83a2697c012960cb4932e2d07c17d00ec220a 100644
--- a/dune/uggrid/gm/rm.h
+++ b/dune/uggrid/gm/rm.h
@@ -341,7 +341,7 @@ INT                     InitRuleManager                 (void);
 INT                     Patterns2Rules                  (ELEMENT *theElement,INT pattern);
 ELEMENT         *ELEMENT_TO_MARK                (ELEMENT *theElement);
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT             GetRule_AnisotropicRed  (ELEMENT *theElement, INT *Rule);
 #endif
 
diff --git a/dune/uggrid/gm/shapes.cc b/dune/uggrid/gm/shapes.cc
index 0b1dafb1b34d64a419e6f5f68fa413e90f275fd7..a0aaf7d4c3595d69c2678b00f8614fca6d36797e 100644
--- a/dune/uggrid/gm/shapes.cc
+++ b/dune/uggrid/gm/shapes.cc
@@ -75,11 +75,11 @@ USING_UG_NAMESPACE
 /****************************************************************************/
 
 /* local midpoints */
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 static DOUBLE_VECTOR_2D LMP_Triangle            = {0.333333333333333333, 0.333333333333333333};
 static DOUBLE_VECTOR_2D LMP_Quadrilateral       = {0.5, 0.5};
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static DOUBLE_VECTOR_3D LMP_Tetrahedron         = {0.25, 0.25, 0.25};
 static DOUBLE_VECTOR_3D LMP_Pyramid             = {0.5, 0.5, 0.33333333333333333};
 static DOUBLE_VECTOR_3D LMP_Prism               = {0.333333333333333333,
@@ -108,7 +108,7 @@ static DOUBLE_VECTOR_3D LMP_Hexahedron          = {0.5, 0.5, 0.5};
 
 DOUBLE * NS_DIM_PREFIX LMP (INT n)
 {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   switch (n)
   {
   case 3 : return (LMP_Triangle);
@@ -116,7 +116,7 @@ DOUBLE * NS_DIM_PREFIX LMP (INT n)
   }
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   switch (n)
   {
   case 4 : return (LMP_Tetrahedron);
@@ -200,7 +200,7 @@ INT NS_DIM_PREFIX UG_GlobalToLocal (INT n, const DOUBLE **Corners,
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX TetraSideNormals (ELEMENT *theElement, DOUBLE **theCorners, DOUBLE_VECTOR theNormals[MAX_SIDES_OF_ELEM])
 {
   ELEMENT e;
@@ -244,7 +244,7 @@ INT NS_DIM_PREFIX TetraSideNormals (ELEMENT *theElement, DOUBLE **theCorners, DO
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX TetMaxSideAngle (ELEMENT *theElement, const DOUBLE **theCorners, DOUBLE *MaxAngle)
 {
   DOUBLE_VECTOR theNormal[MAX_SIDES_OF_ELEM];
@@ -282,7 +282,7 @@ INT NS_DIM_PREFIX TetMaxSideAngle (ELEMENT *theElement, const DOUBLE **theCorner
  */
 /****************************************************************************/
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 INT NS_DIM_PREFIX TetAngleAndLength (ELEMENT *theElement, const DOUBLE **theCorners, DOUBLE *Angle, DOUBLE *Length)
 {
   DOUBLE_VECTOR theNormals[MAX_SIDES_OF_ELEM],theEdge[MAX_EDGES_OF_ELEM];
diff --git a/dune/uggrid/gm/shapes.h b/dune/uggrid/gm/shapes.h
index 5b0384636fd29982f82ab6359d11c1061476aa13..8120b796d680ac41fe0470b8a922ad1aec18b2c8 100644
--- a/dune/uggrid/gm/shapes.h
+++ b/dune/uggrid/gm/shapes.h
@@ -51,7 +51,7 @@ START_UGDIM_NAMESPACE
 /*                                                                          */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 
 #define CORNER_COORDINATES_TRIANGLE(e,n,x)                                \
                                    {(n)=3;                                \
@@ -71,7 +71,7 @@ START_UGDIM_NAMESPACE
                  CORNER_COORDINATES_TRIANGLE((e),(n),(x))       \
   else           CORNER_COORDINATES_QUADRILATERAL((e),(n),(x))}
 
-#endif /* __TWODIM__ */
+#endif /* UG_DIM_2 */
 
 
 #define LOCAL_TO_GLOBAL_TRIANGLE(x,local,global)          \
@@ -131,7 +131,7 @@ START_UGDIM_NAMESPACE
   else TRANSFORMATION_OF_QUADRILATERAL((x),(local),(M)); }
 
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define CORNER_COORDINATES_TETRAHEDRON(e,n,x)                              \
                                   {(n) = 4;                                \
                                                                    (x)[0]=CVECT(MYVERTEX(CORNER((e),0)));  \
@@ -173,7 +173,7 @@ START_UGDIM_NAMESPACE
    else if (TAG((e))==PRISM)      CORNER_COORDINATES_PRISM((e),(n),(x))      \
    else CORNER_COORDINATES_HEXAHEDRON((e),(n),(x))}
 
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 
 
 #define LOCAL_TO_GLOBAL_TETRAHEDRON(x,local,global)                       \
@@ -436,13 +436,13 @@ START_UGDIM_NAMESPACE
   else TRANSFORMATION_OF_HEXAHEDRON((x),(local),(M));}
 
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 #define LOCAL_TO_GLOBAL(n,x,local,global)                       LOCAL_TO_GLOBAL_2D(n,x,local,global)
 #define AREA_OF_ELEMENT(n,x,area)                                       AREA_OF_ELEMENT_2D(n,x,area)
 #define TRANSFORMATION(n,x,local,M)                                     TRANSFORMATION_2D(n,x,local,M)
-#endif /* __TWODIM__ */
+#endif /* UG_DIM_2 */
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 #define TRANSFORMATION_BND(n,x,local,M)                         TRANSFORMATION_2D(n,x,local,M)
 #define LOCAL_TO_GLOBAL_BND(n,x,local,global)           LOCAL_TO_GLOBAL_2D(n,x,local,global)
 #define AREA_OF_ELEMENT_BND(n,x,area)                           AREA_OF_ELEMENT_2D(n,x,area)
@@ -451,7 +451,7 @@ START_UGDIM_NAMESPACE
 #define LOCAL_TO_GLOBAL(n,x,local,global)                       LOCAL_TO_GLOBAL_3D(n,x,local,global)
 #define AREA_OF_ELEMENT(n,x,area)                                       AREA_OF_ELEMENT_3D(n,x,area)
 #define TRANSFORMATION(n,x,local,M)                                     TRANSFORMATION_3D(n,x,local,M)
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 
 #define INVERSE_TRANSFORMATION(n,x,local,Jinv,Jdet)   \
 {   DOUBLE_VECTOR J[DIM];                             \
@@ -479,7 +479,7 @@ START_UGDIM_NAMESPACE
 DOUBLE  *LMP                  (INT n);
 INT      UG_GlobalToLocal     (INT n, const DOUBLE **Corners, const DOUBLE *EvalPoint, DOUBLE *LocalCoord);
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 DOUBLE  N                   (const INT i, const DOUBLE *LocalCoord);
 INT     TetraSideNormals    (ELEMENT *theElement, DOUBLE **theCorners, DOUBLE_VECTOR theNormals[MAX_SIDES_OF_ELEM]);
 INT     TetMaxSideAngle     (ELEMENT *theElement, const DOUBLE **theCorners, DOUBLE *MaxAngle);
diff --git a/dune/uggrid/gm/ugio.cc b/dune/uggrid/gm/ugio.cc
index 4b143beea614a10f44412e00ed0db9b8a062d56f..73f9b1fba70b632a7154633b6ad76a5ee7274f3e 100644
--- a/dune/uggrid/gm/ugio.cc
+++ b/dune/uggrid/gm/ugio.cc
@@ -1198,7 +1198,7 @@ static INT WriteElementParInfo (GRID *theGrid,
     pinfo->v_ident[k] = VXGID(theVertex);
   }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   for (k=0; k<EDGES_OF_ELEM(theElement); k++)
   {
     EDGE* theEdge = GetEdge(CORNER(theElement,CORNER_OF_EDGE(theElement,k,0)),
@@ -1701,7 +1701,7 @@ static INT Evaluate_pinfo (GRID *theGrid, ELEMENT *theElement, MGIO_PARINFO *pin
   auto& dddContext = theGrid->dddContext();
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   INT svec = VEC_DEF_IN_OBJ_OF_MG(MYMG(theGrid),SIDEVEC);
 #else
   INT svec = 0;
@@ -2332,7 +2332,7 @@ static INT InsertLocalTree (GRID *theGrid, ELEMENT *theElement, MGIO_REFINEMENT
   }
   offset = i;
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   for (; i<SIDES_OF_ELEM(theElement)+offset; i++)
   {
     if (theRule->pattern[i-CORNERS_OF_ELEM(theElement)]!=1)
@@ -2714,7 +2714,7 @@ MULTIGRID * NS_DIM_PREFIX LoadMultiGrid (const char *MultigridName,
   char buf[64],itype[10];
   int *vidlist;
   INT MarkKey;
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   ELEMENT *theNeighbor;
   INT k;
 #endif
@@ -3306,7 +3306,7 @@ nparfiles = UG_GlobalMinINT(*ppifContext, nparfiles);
   {
     theGrid = GRID_ON_LEVEL(theMG,i);
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     if (VEC_DEF_IN_OBJ_OF_MG(MYMG(theGrid),SIDEVEC))
       for (theElement = FIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement))
         for (j=0; j<SIDES_OF_ELEM(theElement); j++)
diff --git a/dune/uggrid/gm/ugm.cc b/dune/uggrid/gm/ugm.cc
index c3f65a16885417aeca48d0f17fa0fce7f5ab3597..a62291cbbc4ba18e76235d20f0a6b89228d29982 100644
--- a/dune/uggrid/gm/ugm.cc
+++ b/dune/uggrid/gm/ugm.cc
@@ -537,11 +537,11 @@ NODE *NS_DIM_PREFIX CreateMidNode (GRID *theGrid, ELEMENT *theElement, VERTEX *t
   if (theVertex==NULL)
   {
     if ((OBJT(v0) == BVOBJ) && (OBJT(v1) == BVOBJ))
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
       if (OBJT(theElement) == BEOBJ)
         if (SIDE_ON_BND(theElement,edge))
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
       if (EDSUBDOM(theEdge) == 0)
 #endif
     {
@@ -676,7 +676,7 @@ static INT SideOfNbElement(const ELEMENT *theElement, INT side)
   return(MAX_SIDES_OF_ELEM);
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 
 /****************************************************************************/
@@ -1407,7 +1407,7 @@ INT GetSideIDFromScratchOld (ELEMENT *theElement, NODE *theNode)
   return(SIDES_OF_ELEM(theFather));
 }
 
-#endif /* __THREEDIM__ */
+#endif /* UG_DIM_3 */
 
 
 /****************************************************************************/
@@ -1603,7 +1603,7 @@ INT NS_DIM_PREFIX GetNodeContext (const ELEMENT *theElement, NODE **theElementCo
   NODE *theNode, **MidNodes, **CenterNode;
   EDGE *theEdge;
   INT i,Corner0, Corner1;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   NODE **SideNodes;
         #endif
 
@@ -1635,7 +1635,7 @@ INT NS_DIM_PREFIX GetNodeContext (const ELEMENT *theElement, NODE **theElementCo
     MidNodes[i] = MIDNODE(theEdge);
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   SideNodes = theElementContext+CORNERS_OF_ELEM(theElement)+
               EDGES_OF_ELEM(theElement);
   for (i=0; i<SIDES_OF_ELEM(theElement); i++)
@@ -1818,7 +1818,7 @@ EDGE * NS_DIM_PREFIX GetFatherEdge (const EDGE *theEdge)
   /* one node is center node -> no father edge */
   if (CENTERTYPE(theNode0) || CENTERTYPE(theNode1)) return(NULL);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* one node is side node -> no father edge */
   if (SIDETYPE(theNode0) || SIDETYPE(theNode1)) return(NULL);
         #endif
@@ -1859,7 +1859,7 @@ EDGE * NS_DIM_PREFIX GetFatherEdge (const EDGE *theEdge)
   return NULL;
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 /****************************************************************************/
 /** \brief Return pointer to father edge if it exists
@@ -2056,7 +2056,7 @@ CreateEdge (GRID *theGrid, ELEMENT *theElement, INT edge, bool with_vector)
   EDGE *pe,*father_edge;
   NODE *from,*to,*n1,*n2;
   LINK *link0,*link1;
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   VERTEX *theVertex;
   NODE *nbn1,*nbn2,*nbn3,*nbn4;
   INT sc,found,side,k,j;
@@ -2133,7 +2133,7 @@ CreateEdge (GRID *theGrid, ELEMENT *theElement, INT edge, bool with_vector)
     }
     switch(NTYPE(n1)|(NTYPE(n2)<<4))
     {
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
     case (CORNER_NODE | (CORNER_NODE<<4)) :
       father_edge = GetEdge(NFATHER(n1),NFATHER(n2));
       if (father_edge!=NULL) SETEDSUBDOM(pe,EDSUBDOM(father_edge));
@@ -2152,7 +2152,7 @@ CreateEdge (GRID *theGrid, ELEMENT *theElement, INT edge, bool with_vector)
       if (NBNODE(LINK0(father_edge))==NFATHER(n1) || NBNODE(LINK1(father_edge))==NFATHER(n1)) SETEDSUBDOM(pe,EDSUBDOM(father_edge));
       break;
 #endif
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     case (CORNER_NODE | (CORNER_NODE<<4)) :
       father_edge = GetEdge(NFATHER(n1),NFATHER(n2));
       if (father_edge!=NULL) SETEDSUBDOM(pe,EDSUBDOM(father_edge));
@@ -2534,14 +2534,14 @@ INT NS_DIM_PREFIX CreateSonElementSide (GRID *theGrid, ELEMENT *theElement, INT
     ReinspectSonSideVector(theGrid,theSon,son_side,&vec);
     SET_SVECTOR(theSon,son_side,vec);
   }
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   theEdge = GetEdge(CORNER(theSon,CORNER_OF_EDGE(theSon,son_side,0)),
                     CORNER(theSon,CORNER_OF_EDGE(theSon,son_side,1)));
   ASSERT(theEdge != NULL);
   SETEDSUBDOM(theEdge,0);
         #endif
 
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   /** \todo is this necessary?
      for (i=0; i<EDGES_OF_SIDE(theSon,son_side); i++) {
           int k  = EDGE_OF_SIDE(theSon,son_side,i);
@@ -3201,7 +3201,7 @@ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement)
   BNDS    *bnds;
   ELEMENT *theFather;
   ELEMENT *succe = SUCCE(theElement);
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   VECTOR  *theVector;
   DOUBLE *local,fac;
   INT k,m,o,l;
@@ -3306,7 +3306,7 @@ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement)
         BNDS_Dispose(MGHEAP(MYMG(theGrid)),bnds);
     }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* reset VFATHER of sidenodes */
   for (j=0; j<SIDES_OF_ELEM(theElement); j++) {
     theNode = GetSideNode(theElement,j);
@@ -3350,7 +3350,7 @@ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement)
     {
       theVertex = MYVERTEX(MIDNODE(theEdge));
       if (VFATHER(theVertex) == theElement) {
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
         theFather = NBELEM(theElement,j);
         VFATHER(theVertex) = theFather;
         if (theFather != NULL)
@@ -3369,7 +3369,7 @@ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement)
           SETONEDGE(theVertex,j);
         }
                             #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
         VFATHER(theVertex) = NULL;
                             #endif
       }
@@ -3429,7 +3429,7 @@ INT NS_DIM_PREFIX DisposeElement (GRID *theGrid, ELEMENT *theElement)
   {
     ELEMENT *theNeighbor = NBELEM(theElement,i);
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
     {
       theVector = SVECTOR(theElement,i);
@@ -3617,7 +3617,7 @@ INT NS_DIM_PREFIX Collapse (MULTIGRID *theMG)
                         CORNER(theElement,
                                CORNER_OF_EDGE(theElement,i,1)));
       SETLEVEL(theEdge,0);
-                        #if (defined ModelP) && (defined __THREEDIM__)
+                        #if (defined ModelP) && (defined UG_DIM_3)
       DDD_AttrSet(PARHDR(theEdge),GRID_ATTR(theGrid));
                         #endif
     }
@@ -3957,7 +3957,7 @@ NODE * NS_DIM_PREFIX InsertBoundaryNode (GRID *theGrid, BNDP *bndp)
 
   SetStringValue(":bndp0",XC(theVertex));
   SetStringValue(":bndp1",YC(theVertex));
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   SetStringValue(":bndp2",ZC(theVertex));
         #endif
 
@@ -4013,7 +4013,7 @@ INT NS_DIM_PREFIX DeleteNode (GRID *theGrid, NODE *theNode)
   return(GM_OK);
 }
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 
 
 /****************************************************************************/
@@ -4057,7 +4057,7 @@ INT NS_DIM_PREFIX CheckOrientation (INT n, VERTEX **vertices)
 #define SWAP_IJ(a,i,j,t)                        {t = a[i]; a[i] = a[j]; a[j] = t;}
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 
 /****************************************************************************/
@@ -4310,7 +4310,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
   ELEMENT          *theElement,*Neighbor[MAX_SIDES_OF_ELEM];
   BNDS         *bnds[MAX_SIDES_OF_ELEM];
   BNDP         *bndp[MAX_CORNERS_OF_ELEM];
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   VERTEX           *theVertex;
   NODE             *theNode;
         #endif
@@ -4326,7 +4326,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
   }
 
   /* check parameters */
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   switch (n)
   {
   case 3 :
@@ -4341,7 +4341,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
   }
     #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   switch (n)
   {
   case 4 :
@@ -4370,7 +4370,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
     Vertex[i] = MYVERTEX(Node[i]);
   }
 
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   /* find orientation */
   if (!CheckOrientation(n,Vertex))
   {
@@ -4415,7 +4415,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
   }
         #endif
 
-    #ifdef __THREEDIM__
+    #ifdef UG_DIM_3
   if (!CheckOrientation (n,Vertex))
   {
     sideNode[0] = Node[0];
@@ -4518,7 +4518,7 @@ ELEMENT * NS_DIM_PREFIX InsertElement (GRID *theGrid, INT n, NODE **Node, ELEMEN
         return(NULL);
       }
       SET_NBELEM(Neighbor[i],NeighborSide[i],theElement);
-            #ifdef __THREEDIM__
+            #ifdef UG_DIM_3
       if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
         if (DisposeDoubledSideVector(theGrid,Neighbor[i],
                                      NeighborSide[i],theElement,i))
@@ -4735,7 +4735,7 @@ INT NS_DIM_PREFIX InsertMesh (MULTIGRID *theMG, MESH *theMesh)
    </ul> */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 bool NS_DIM_PREFIX PointInElement (const DOUBLE *x, const ELEMENT *theElement)  /* 2D version */
 {
   COORD_POINT point[MAX_CORNERS_OF_ELEM],thePoint;
@@ -4759,7 +4759,7 @@ bool NS_DIM_PREFIX PointInElement (const DOUBLE *x, const ELEMENT *theElement)
 }
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 bool NS_DIM_PREFIX PointInElement (const DOUBLE *global, const ELEMENT *theElement)
 {
   DOUBLE *x[MAX_CORNERS_OF_ELEM];
@@ -4811,7 +4811,7 @@ bool NS_DIM_PREFIX PointInElement (const DOUBLE *global, const ELEMENT *theEleme
    </ul> */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 INT NS_DIM_PREFIX PointOnSide(const DOUBLE *global, const ELEMENT *theElement, INT side)
 {
   INT n;
@@ -4878,7 +4878,7 @@ INT NS_DIM_PREFIX PointOnSide(const DOUBLE *global, const ELEMENT *theElement, I
    </ul> */
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 DOUBLE NS_DIM_PREFIX DistanceFromSide(const DOUBLE *global, const ELEMENT *theElement, INT side)
 {
   INT n;
@@ -5878,7 +5878,7 @@ void NS_DIM_PREFIX ListNode (const MULTIGRID *theMG, const NODE *theNode, INT da
   {
     for (theLink=START(theNode); theLink!=NULL; theLink=NEXT(theLink))
     {
-                        #if defined __THREEDIM__ && defined ModelP
+                        #if defined UG_DIM_3 && defined ModelP
       UserWriteF("   EDGE=%x/%08x ",MYEDGE(theLink),
                  DDD_InfoGlobalId(PARHDR(MYEDGE(theLink))));
                         #else
@@ -5992,7 +5992,7 @@ void NS_DIM_PREFIX ListElement (const MULTIGRID *theMG, const ELEMENT *theElemen
       {
         for(j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
         {
-                                                #if defined(ModelP) && defined(__THREEDIM__)
+                                                #if defined(ModelP) && defined(UG_DIM_3)
           UserWriteF("    NODE[ID=%ld]: ",
                      (long)(ID(CORNER(theElement,
                                       CORNER_OF_SIDE(theElement,i,j)))));
@@ -6034,10 +6034,10 @@ void NS_DIM_PREFIX ListVector (const MULTIGRID *theMG, const VECTOR *theVector,
   {
     if (VectorPosition(theVector,pos))
       return;
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
     UserWriteF("POS=(%10.2e,%10.2e)",pos[_X_],pos[_Y_]);
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     UserWriteF("POS=(%10.2e,%10.2e,%10.2e)",pos[_X_],pos[_Y_],pos[_Z_]);
                 #endif
   }
@@ -6046,7 +6046,7 @@ void NS_DIM_PREFIX ListVector (const MULTIGRID *theMG, const VECTOR *theVector,
   if (READ_FLAG(modifiers,LV_VO_INFO))
     switch (VOTYPE(theVector))
     {
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     case SIDEVEC :
     {
       ELEMENT *theElement = (ELEMENT*)VOBJECT(theVector);
@@ -7191,7 +7191,7 @@ char *PrintElementInfo (ELEMENT *theElement,INT full)
   strcat(out,"\n");
   for (i=0; i<CORNERS_OF_ELEM(theElement); i++)
   {
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
     sprintf(tmp,"    N%d=" ID_FMTX " x=%g  y=%g\n",
             i,
             ID_PRTX(CORNER(theElement,i)),
@@ -7199,7 +7199,7 @@ char *PrintElementInfo (ELEMENT *theElement,INT full)
             CVECT(MYVERTEX(CORNER(theElement,i)))[1]
             );
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     sprintf(tmp,"    N%d=" ID_FMTX " x=%g  y=%g z=%g\n",
             i,
             ID_PRTX(CORNER(theElement,i)),
@@ -7231,7 +7231,7 @@ char *PrintElementInfo (ELEMENT *theElement,INT full)
 
         for (j=0; j<CORNERS_OF_ELEM(SonList[i]); j++)
         {
-                                        #ifdef __TWODIM__
+                                        #ifdef UG_DIM_2
           sprintf(tmp,"        N%d= " ID_FMTX " x=%g  y=%g\n",
                   j,
                   ID_PRTX(CORNER(SonList[i],j)),
@@ -7239,7 +7239,7 @@ char *PrintElementInfo (ELEMENT *theElement,INT full)
                   CVECT(MYVERTEX(CORNER(SonList[i],j)))[1]
                   );
                                         #endif
-                                        #ifdef __THREEDIM__
+                                        #ifdef UG_DIM_3
           sprintf(tmp,"        N%d= " ID_FMTX " x=%g  y=%g z=%g\n",
                   j,
                   ID_PRTX(CORNER(SonList[i],j)),
@@ -7267,13 +7267,13 @@ char *PrintElementInfo (ELEMENT *theElement,INT full)
     {
       for(j=0; j<CORNERS_OF_SIDE(theElement,i); j++)
       {
-                                #ifdef __TWODIM__
+                                #ifdef UG_DIM_2
         sprintf(tmp,"    NODE[ID=%ld]: x=%g y=%g",
                 (long)(ID(CORNER(theElement,CORNER_OF_SIDE(theElement,i,j)))),
                 CVECT(MYVERTEX(CORNER(theElement,CORNER_OF_SIDE(theElement,i,j))))[0],
                 CVECT(MYVERTEX(CORNER(theElement,CORNER_OF_SIDE(theElement,i,j))))[1]);
                                 #endif
-                                #ifdef __THREEDIM__
+                                #ifdef UG_DIM_3
         sprintf(tmp,"    NODE[ID=%ld]: x=%g y=%g z=%g",
                 (long)(ID(CORNER(theElement,CORNER_OF_SIDE(theElement,i,j)))),
                 CVECT(MYVERTEX(CORNER(theElement,CORNER_OF_SIDE(theElement,i,j))))[0],
diff --git a/dune/uggrid/gm/ugm.h b/dune/uggrid/gm/ugm.h
index 0c89a793a9cb7083fe3fde77ffef5f4463515e48..adb352ea7de1fad22c9ef64b939acb395044f640 100644
--- a/dune/uggrid/gm/ugm.h
+++ b/dune/uggrid/gm/ugm.h
@@ -86,7 +86,7 @@ INT              ReleaseOBJT                    (GM_OBJECTS);
 /* create basic objects */
 /** \todo Commented out because no definitions exist for these declarations
 
-   #if defined(__TWODIM__)
+   #if defined(UG_DIM_2)
    int      GetElemLink (NODE *from, NODE *to, ELEMENT *theElement);
    ELEMENT *NbElem     (const ELEMENT *theElement, int i);
    void     Set_NbElem (ELEMENT *theElement, int i, ELEMENT *Neighbor);
@@ -121,7 +121,7 @@ NODE            *CreateMidNode                  (GRID *theGrid, ELEMENT *theElem
 NODE            *GetCenterNode                  (const ELEMENT *theElement);
 NODE        *CreateCenterNode       (GRID *theGrid, ELEMENT *theElement, VERTEX *theVertex);
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 NODE            *CreateSideNode                 (GRID *theGrid, ELEMENT *theElement, VERTEX *theVertex, INT side);
 NODE            *GetSideNode                    (const ELEMENT *theElement, INT side);
 #endif
diff --git a/dune/uggrid/low/dimension.h b/dune/uggrid/low/dimension.h
index 156da27dc4a5eef0d6ede02f38c13cb1f0acc342..eda4591d1715d0fe2ec5e9b560281f35e690b1ad 100644
--- a/dune/uggrid/low/dimension.h
+++ b/dune/uggrid/low/dimension.h
@@ -15,13 +15,11 @@
 #ifdef UG_DIM_3
 #error ****    define EITHER dimension UG_DIM_2 OR UG_DIM_3       ****
 #endif
-#define __TWODIM__
 #define DIM 2
 #define DIM_OF_BND 1
 #endif
 
 #ifdef UG_DIM_3
-#define __THREEDIM__
 #define DIM 3
 #define DIM_OF_BND 2
 #endif
diff --git a/dune/uggrid/parallel/dddif/debugger.cc b/dune/uggrid/parallel/dddif/debugger.cc
index 749f2f940137cd04b7f1bdb1ba545f25665a6a93..bfff20fa6b55665a09932a0c15c23a4923119b0e 100644
--- a/dune/uggrid/parallel/dddif/debugger.cc
+++ b/dune/uggrid/parallel/dddif/debugger.cc
@@ -112,18 +112,18 @@ void NS_DIM_PREFIX ddd_pstat(DDD::DDDContext& context, char *arg)
       DDD_TypeDisplay(context, dddctrl.TypeIVertex);
       DDD_TypeDisplay(context, dddctrl.TypeBVertex);
       DDD_TypeDisplay(context, dddctrl.TypeNode);
-                                #ifdef __THREEDIM__
+                                #ifdef UG_DIM_3
       DDD_TypeDisplay(context, dddctrl.TypeEdge);
                                 #endif
 
-                                #ifdef __TWODIM__
+                                #ifdef UG_DIM_2
       DDD_TypeDisplay(context, dddctrl.TypeTrElem);
       DDD_TypeDisplay(context, dddctrl.TypeTrBElem);
       DDD_TypeDisplay(context, dddctrl.TypeQuElem);
       DDD_TypeDisplay(context, dddctrl.TypeQuBElem);
                                 #endif
 
-                                #ifdef __THREEDIM__
+                                #ifdef UG_DIM_3
       DDD_TypeDisplay(context, dddctrl.TypeTeElem);
       DDD_TypeDisplay(context, dddctrl.TypeTeBElem);
       DDD_TypeDisplay(context, dddctrl.TypePyElem);
@@ -135,7 +135,7 @@ void NS_DIM_PREFIX ddd_pstat(DDD::DDDContext& context, char *arg)
                                 #endif
 
       /* display dependent types */
-                                #ifdef __TWODIM__
+                                #ifdef UG_DIM_2
       DDD_TypeDisplay(context, dddctrl.TypeEdge);
                                 #endif
     }
diff --git a/dune/uggrid/parallel/dddif/gridcons.cc b/dune/uggrid/parallel/dddif/gridcons.cc
index 301bae614db780698eb1a9ff5827f9616715998c..d5aafd253c4bd3340d409850ff43ab45e85805ff 100644
--- a/dune/uggrid/parallel/dddif/gridcons.cc
+++ b/dune/uggrid/parallel/dddif/gridcons.cc
@@ -148,7 +148,7 @@ static void ConstructConsistentGridLevel (GRID *theGrid)
   for (ELEMENT* theElement = PFIRSTELEMENT(theGrid); theElement!=NULL; theElement=SUCCE(theElement))
   {
     /* This is the SideVector part */
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
     if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
       for (INT i=0; i<SIDES_OF_ELEM(theElement); i++)
         SETVCOUNT(SVECTOR(theElement,i), (NBELEM(theElement,i) ? 2 : 1));
@@ -157,7 +157,7 @@ static void ConstructConsistentGridLevel (GRID *theGrid)
     /* Here comes the rest, all the way to the end of the element loop */
 
     /* TODO: delete now done in ElementObjMkCons()
-       #ifdef __THREEDIM__
+       #ifdef UG_DIM_3
                     if (EVGHOST(theElement))
                     {
                             ELEMENT *NbElement;
@@ -261,7 +261,7 @@ static void ConstructConsistentGridLevel (GRID *theGrid)
           break;
         }
 
-                                        #ifdef __THREEDIM__
+                                        #ifdef UG_DIM_3
         case (SIDE_NODE) :
         {
           /* always compute new coords for this case! */
diff --git a/dune/uggrid/parallel/dddif/handler.cc b/dune/uggrid/parallel/dddif/handler.cc
index 31fc62e3ff32981471e41058cced8e02c7464414..b2c4cd3a661536f79882b826a9396710e4263eab 100644
--- a/dune/uggrid/parallel/dddif/handler.cc
+++ b/dune/uggrid/parallel/dddif/handler.cc
@@ -523,7 +523,7 @@ static void NodeObjMkCons (DDD::DDDContext& context, DDD_OBJ obj, int newness)
 
   /* TODO: this needs to be done here not in NodeUpdate() for 2D,       */
   /* since father would be overwritten by ElemScatterEdge()                     */
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   if (NFATHER(theNode) != NULL)
   {
     switch (NTYPE(theNode))
@@ -581,7 +581,7 @@ static void NodeUpdate (DDD::DDDContext& context, DDD_OBJ obj)
 
   /* TODO: can this be done in NodeObjMkCons() also	*/
   /* to unify 2 and 3D case							*/
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (NFATHER(theNode) != NULL)
   {
     switch (NTYPE(theNode))
@@ -914,7 +914,7 @@ static void ElementXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC pro
     /* add edges of element */
     /* must be done before any XferCopyObj-call! herein    */
     /* or directly after XferCopyObj-call for this element */
-            #ifdef __TWODIM__
+            #ifdef UG_DIM_2
     DDD_XferAddData(context, EDGES_OF_ELEM(pe), dddctrl.TypeEdge);
             #endif
   }
@@ -1002,7 +1002,7 @@ static void ElementXferCopy (DDD::DDDContext& context, DDD_OBJ obj, DDD_PROC pro
 
 /****************************************************************************/
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
 static void ElemGatherEdge (DDD::DDDContext& context, ELEMENT *pe, int cnt, char *data)
 {
   INT i;
@@ -1169,7 +1169,7 @@ static void ElemScatterEdge (DDD::DDDContext& context, ELEMENT *pe, int cnt, cha
         }
   }
 }
-#endif /* end __TWODIM__ */
+#endif /* end UG_DIM_2 */
 
 
 /****************************************************************************/
@@ -1183,7 +1183,7 @@ static void ElemGatherI (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYP
     return;
   }
 
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   /* now: type_id is always TypeEdge */
   ElemGatherEdge(context, (ELEMENT *)obj, cnt, (char *)data);
         #endif
@@ -1199,7 +1199,7 @@ static void ElemScatterI (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TY
     return;
   }
 
-    #ifdef __TWODIM__
+    #ifdef UG_DIM_2
   /* type_id is always TypeEdge */
   ElemScatterEdge(context, (ELEMENT *)obj, cnt, (char *)data, newness);
         #endif
@@ -1226,7 +1226,7 @@ static void ElemGatherB (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TYP
   }
 
   /* now: type_id is TypeEdge or other */
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   if (type_id==ddd_ctrl(context).TypeEdge)
   {
     ElemGatherEdge(context, pe, cnt, (char *)data);
@@ -1259,7 +1259,7 @@ static void ElemScatterB (DDD::DDDContext& context, DDD_OBJ obj, int cnt, DDD_TY
   }
 
   /* now: type_id is TypeEdge or other */
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   if (type_id==ddd_ctrl(context).TypeEdge)
   {
     ElemScatterEdge(context, pe, cnt, (char *)data, newness);
@@ -1419,7 +1419,7 @@ static void ElementObjMkCons (DDD::DDDContext& context, DDD_OBJ obj, int newness
     }
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* update element count of edges for new created elements */
   if (newness == XFER_NEW)
     /* increment elem counter in edges */
@@ -1725,7 +1725,7 @@ static void ElemHandlerInit (DDD::DDDContext& context, DDD_TYPE etype, INT handl
   DDD_SetHandlerXFERCOPY        (context, etype, ElementXferCopy);
   DDD_SetHandlerSETPRIORITY     (context, etype, ElementPriorityUpdate);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   DDD_SetHandlerUPDATE          (context, etype, ElementUpdate);
         #endif
 
@@ -1808,7 +1808,7 @@ void NS_DIM_PREFIX ddd_HandlerInit (DDD::DDDContext& context, INT handlerSet)
 
 
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   IElemHandlerInit(context, dddctrl.TypeTrElem, handlerSet);
   BElemHandlerInit(context, dddctrl.TypeTrBElem, handlerSet);
 
@@ -1816,7 +1816,7 @@ void NS_DIM_PREFIX ddd_HandlerInit (DDD::DDDContext& context, INT handlerSet)
   BElemHandlerInit(context, dddctrl.TypeQuBElem, handlerSet);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   IElemHandlerInit(context, dddctrl.TypeTeElem, handlerSet);
   BElemHandlerInit(context, dddctrl.TypeTeBElem, handlerSet);
 
diff --git a/dune/uggrid/parallel/dddif/identify.cc b/dune/uggrid/parallel/dddif/identify.cc
index 2294bc464851f9a67b80c4cc0816fb7fb608795c..5b42956e27567c9d7ec8ef52b3e29664a1aa1b3a 100644
--- a/dune/uggrid/parallel/dddif/identify.cc
+++ b/dune/uggrid/parallel/dddif/identify.cc
@@ -401,7 +401,7 @@ static INT Identify_by_ObjectList (DDD::DDDContext& context, DDD_HDR *IdentObjec
   return 0;
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 
 static void IdentifySideVector (DDD::DDDContext& context, ELEMENT* theElement, ELEMENT *theNeighbor,
@@ -523,13 +523,13 @@ static void IdentifyNode (GRID *theGrid, ELEMENT *theNeighbor, NODE *theNode,
 
   case (MID_NODE) :
   {
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
     NODE **EdgeNodes;
     EdgeNodes = Nodes;
                         #endif
 
     EDGE *theEdge;
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
     NODE *EdgeNodes[MAX_SIDE_NODES];
 
     /* identification of cornernodes is done */
@@ -554,7 +554,7 @@ static void IdentifyNode (GRID *theGrid, ELEMENT *theNeighbor, NODE *theNode,
     if (Vec)
       IdentObjectHdr[nobject++] = PARHDR(NVECTOR(theNode));
 
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
     if (!NEW_NIDENT(theNode)) break;
                         #endif
 
@@ -580,7 +580,7 @@ static void IdentifyNode (GRID *theGrid, ELEMENT *theNeighbor, NODE *theNode,
     break;
   }
 
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
   case (SIDE_NODE) :
   {
     INT i;
@@ -658,12 +658,12 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
 
   nobject = nident = 0;
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   /* no identfication to nonrefined neighbors */
   if (MARK(theNeighbor) == NO_REFINEMENT) return(0);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* identification of sonedges is done in Identify_SonEdges() */
   {
     EDGE *FatherEdge;
@@ -686,7 +686,7 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
   /* edge locked -> already identified */
   if (EDIDENT(theEdge) == IDENT) return(0);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   IdentObjectHdr[nobject++] = PARHDR(theEdge);
         #endif
 
@@ -704,7 +704,7 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
     ASSERT(NFATHER(theNode0)!=NULL);
     IdentHdr[nident++] = PARHDR((NODE *)NFATHER(theNode0));
   }
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* since midnodes are identified later in Debug case */
   /* choose fatheredge here (s.l. 980227)              */
   else if (MIDTYPE(theNode0))
@@ -716,7 +716,7 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
   else
   {
     /* side node */
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     ASSERT(SIDETYPE(theNode0));
                 #endif
     IdentHdr[nident++] = PARHDR(theNode0);
@@ -727,7 +727,7 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
     ASSERT(NFATHER(theNode1)!=NULL);
     IdentHdr[nident++] = PARHDR((NODE *)NFATHER(theNode1));
   }
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* since midnodes are identified later in Debug case */
   /* choose fatheredge here (s.l. 980227)              */
   else if (MIDTYPE(theNode1))
@@ -739,7 +739,7 @@ static INT IdentifySideEdge (GRID *theGrid, EDGE *theEdge, ELEMENT *theElement,
   else
   {
     /* side node */
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
     ASSERT(SIDETYPE(theNode1));
                 #endif
     IdentHdr[nident++] = PARHDR(theNode1);
@@ -795,7 +795,7 @@ static INT IdentifyEdge (GRID *theGrid,
   NODE *Nodes[2];
   EDGE *theEdge;
   INT nobject,nident;
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT edge,corner0,corner1;
         #endif
   int *proclist;
@@ -805,12 +805,12 @@ static INT IdentifyEdge (GRID *theGrid,
 
   nobject = nident = 0;
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   Nodes[0] = CORNER(Son,CORNER_OF_EDGE(Son,SonSide,0));
   Nodes[1] = CORNER(Son,CORNER_OF_EDGE(Son,SonSide,1));
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   edge = EDGE_OF_SIDE(Son,SonSide,edgeofside);
   corner0 = CORNER_OF_EDGE(Son,edge,0);
   corner1 = CORNER_OF_EDGE(Son,edge,1);
@@ -828,12 +828,12 @@ static INT IdentifyEdge (GRID *theGrid,
   theEdge = GetEdge(Nodes[0],Nodes[1]);
   ASSERT(theEdge!=NULL);
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   /* no identfication to nonrefined neighbors */
   if (MARK(theNeighbor) == NO_REFINEMENT) return(0);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* identification of sonedges is done in Identify_SonEdges() */
   if (0)
     if (CORNERTYPE(Nodes[0]) && CORNERTYPE(Nodes[1]))
@@ -872,17 +872,17 @@ static INT IdentifyEdge (GRID *theGrid,
                       DDD_InfoGlobalId(PARHDRE(Son)),Son,ID(Son),
                       NTYPE(Nodes[0]), NTYPE(Nodes[1]), Vec))
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   IdentObjectHdr[nobject++] = PARHDR(theEdge);
         #endif
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   /* identify to proclist of neighbor */
   proclist = DDD_InfoProcList(context, PARHDRE(theNeighbor));
         #endif
 
   /* identify to proclist of father edge or neighbor*/
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (0)
   {
     EDGE *fatherEdge = NULL;
@@ -900,7 +900,7 @@ static INT IdentifyEdge (GRID *theGrid,
 
   if (CORNERTYPE(Nodes[0]))
     IdentHdr[nident++] = PARHDR((NODE *)NFATHER(Nodes[0]));
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* since midnodes are identified later in Debug case */
   /* choose fatheredge here (s.l. 980227)              */
   else if (MIDTYPE(Nodes[0]))
@@ -911,7 +911,7 @@ static INT IdentifyEdge (GRID *theGrid,
 
   if (CORNERTYPE(Nodes[1]))
     IdentHdr[nident++] = PARHDR((NODE *)NFATHER(Nodes[1]));
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* since midnodes are identified later in Debug case */
   /* choose fatheredge here (s.l. 980227)              */
   else if (MIDTYPE(Nodes[1]))
@@ -1024,7 +1024,7 @@ static INT IdentifyObjectsOfElementSide(GRID *theGrid, ELEMENT *theElement,
         }
       }
 
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
       if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))
       {
         auto& context = theGrid->dddContext();
@@ -1767,7 +1767,7 @@ static int Scatter_SonNodeInfo (DDD::DDDContext& context, DDD_OBJ obj, void *dat
 }
 
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 
 /****************************************************************************/
 /*
diff --git a/dune/uggrid/parallel/dddif/initddd.cc b/dune/uggrid/parallel/dddif/initddd.cc
index b58a794285b7ef0edb78149ecea8606852f343d5..a952a1cc2170be460157bb49cadf3fe295986b23 100644
--- a/dune/uggrid/parallel/dddif/initddd.cc
+++ b/dune/uggrid/parallel/dddif/initddd.cc
@@ -180,10 +180,10 @@ static void ddd_InitGenericElement(DDD::DDDContext& context, INT tag, DDD_TYPE d
                  EL_OBJPTR, r+n_offset[tag]*sizeof(void*),       ps*desc->corners_of_elem, dddctrl.TypeNode,
                  EL_OBJPTR, r+father_offset[tag]*sizeof(void*),  ps,                       dddType,
                  /* TODO: delete
-                    #ifdef __TWODIM__
+                    #ifdef UG_DIM_2
                                  EL_LDATA, r+sons_offset[tag]*sizeof(void*),    ps*desc->max_sons_of_elem,
                     #endif
-                    #ifdef __THREEDIM__
+                    #ifdef UG_DIM_3
                                  EL_LDATA, r+sons_offset[tag]*sizeof(void*),    ps*1,
                     #endif
                   */
@@ -199,7 +199,7 @@ static void ddd_InitGenericElement(DDD::DDDContext& context, INT tag, DDD_TYPE d
                    EL_OBJPTR, r+evector_offset[tag]*sizeof(void*), ps*1,     dddctrl.TypeVector,
                    EL_CONTINUE);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (ddd_ctrl(context).sideData)
     DDD_TypeDefine(context, dddType,
                    EL_OBJPTR, r+svector_offset[tag]*sizeof(void*), ps*desc->sides_of_elem, dddctrl.TypeVector,
@@ -317,14 +317,14 @@ static void ddd_DeclareTypes(DDD::DDDContext& context)
   MAP_TYPES(NDOBJ, dddctrl.TypeNode);
   dddctrl.dddObj[NDOBJ] = true;
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   dddctrl.TypeTrElem  = DDD_TypeDeclare(context, "TrElem");
   dddctrl.TypeTrBElem = DDD_TypeDeclare(context, "TrBElem");
   dddctrl.TypeQuElem  = DDD_TypeDeclare(context, "QuElem");
   dddctrl.TypeQuBElem = DDD_TypeDeclare(context, "QuBElem");
         #endif /* TWODIM */
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   dddctrl.TypeTeElem  = DDD_TypeDeclare(context, "TeElem");
   dddctrl.TypeTeBElem = DDD_TypeDeclare(context, "TeBElem");
   dddctrl.TypePyElem  = DDD_TypeDeclare(context, "PyElem");
@@ -438,11 +438,11 @@ static void ddd_DefineTypes(DDD::DDDContext& context)
                  /* TODO muss father LDATA oder OBJPTR sein?     */
                  /* LDATA, father ist nur lokal gueltig und      */
                  /* ist abhaengig von vertikaler Lastverteilung  */
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
                  /* TODO: ref-typ muss eigentlich {TypeTrElem,TypeTrBElem} sein! */
                  EL_OBJPTR, ELDEF(ivertex,father), dddctrl.TypeTrElem,
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
                  EL_LDATA,  ELDEF(ivertex,father),
                 #endif
 
@@ -476,11 +476,11 @@ static void ddd_DefineTypes(DDD::DDDContext& context)
                  /* TODO muss father LDATA oder OBJPTR sein?     */
                  /* LDATA, father ist nur lokal gueltig und      */
                  /* ist abhaengig von vertikaler Lastverteilung  */
-                #ifdef __TWODIM__
+                #ifdef UG_DIM_2
                  /* TODO: ref-typ muss eigentlich {TypeTrElem,TypeTrBElem} sein! */
                  EL_OBJPTR, ELDEF(bvertex,father), dddctrl.TypeTrElem,
                 #endif
-                #ifdef __THREEDIM__
+                #ifdef UG_DIM_3
                  EL_LDATA,  ELDEF(bvertex,father),
                 #endif
 
@@ -538,14 +538,14 @@ static void ddd_DefineTypes(DDD::DDDContext& context)
   DDD_PrioMergeDefault(context, dddctrl.TypeNode, PRIOMERGE_MAXIMUM);
 
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   ddd_InitGenericElement(context, TRIANGLE,      dddctrl.TypeTrElem,  Inside);
   ddd_InitGenericElement(context, TRIANGLE,      dddctrl.TypeTrBElem, Boundary);
   ddd_InitGenericElement(context, QUADRILATERAL, dddctrl.TypeQuElem,  Inside);
   ddd_InitGenericElement(context, QUADRILATERAL, dddctrl.TypeQuBElem, Boundary);
         #endif /* TWODIM */
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   ddd_InitGenericElement(context, TETRAHEDRON, dddctrl.TypeTeElem,  Inside);
   ddd_InitGenericElement(context, TETRAHEDRON, dddctrl.TypeTeBElem, Boundary);
   ddd_InitGenericElement(context, PYRAMID,     dddctrl.TypePyElem,  Inside);
@@ -566,10 +566,10 @@ static void ddd_DefineTypes(DDD::DDDContext& context)
   DDD_TypeDefine(context, dddctrl.TypeEdge,
                  /* link 0 data */
                  /*TODO: now unique
-                    #ifdef __TWODIM__
+                    #ifdef UG_DIM_2
                                  EL_GDATA,  ELDEF(EDGE,links[0].control),
                     #endif
-                    #ifdef __THREEDIM__
+                    #ifdef UG_DIM_3
                                  EL_LDATA,  ELDEF(EDGE,links[0].control),
                     #endif
                   */
@@ -638,13 +638,13 @@ static void ddd_IfInit(DDD::DDDContext& context)
 
 
   /* define element interfaces */
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   O[0] = dddctrl.TypeTrElem; O[1] = dddctrl.TypeTrBElem;
   O[2] = dddctrl.TypeQuElem; O[3] = dddctrl.TypeQuBElem;
   nO = 4;
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   O[0] = dddctrl.TypeTeElem; O[1] = dddctrl.TypeTeBElem;
   O[2] = dddctrl.TypePyElem; O[3] = dddctrl.TypePyBElem;
   O[4] = dddctrl.TypePrElem; O[5] = dddctrl.TypePrBElem;
@@ -850,14 +850,14 @@ static void InitDDDTypes(DDD::DDDContext& context)
   DDD_TypeDisplay(context, dddctrl.TypeNode);
   DDD_TypeDisplay(context, dddctrl.TypeEdge);
 
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   DDD_TypeDisplay(context, dddctrl.TypeTrElem);
   DDD_TypeDisplay(context, dddctrl.TypeTrBElem);
   DDD_TypeDisplay(context, dddctrl.TypeQuElem);
   DDD_TypeDisplay(context, dddctrl.TypeQuBElem);
         #endif
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   DDD_TypeDisplay(context, dddctrl.TypeTeElem);
   DDD_TypeDisplay(context, dddctrl.TypeTeBElem);
   DDD_TypeDisplay(context, dddctrl.TypePyElem);
@@ -869,7 +869,7 @@ static void InitDDDTypes(DDD::DDDContext& context)
         #endif
 
   /* display dependent types */
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   DDD_TypeDisplay(context, dddctrl.TypeEdge);
         #endif
   ENDDEBUG
diff --git a/dune/uggrid/parallel/dddif/overlap.cc b/dune/uggrid/parallel/dddif/overlap.cc
index 0c26c7fe8e5f0853f5f460c592a441f9fc7e3022..da78e897638404d5f5c2498babcc2da31d24697a 100644
--- a/dune/uggrid/parallel/dddif/overlap.cc
+++ b/dune/uggrid/parallel/dddif/overlap.cc
@@ -369,10 +369,10 @@ INT ConnectGridOverlap (GRID *theGrid)
       if (!THEFLAG(theElement) && !THEFLAG(theNeighbor)) continue;
 
       /* connect only TO master copies */
-                        #ifdef __TWODIM__
+                        #ifdef UG_DIM_2
       if (!IS_REFINED(theNeighbor) || !MASTERPRIO(prio)) continue;
                         #endif
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
       if (!IS_REFINED(theNeighbor)) continue;
                         #endif
 
@@ -722,7 +722,7 @@ static INT ConnectOverlapVerticalGrid (GRID *theGrid)
               assert (MIDNODE(theEdge)==NULL ||
                       MIDNODE(theEdge) == SonNode);
 
-                                                                #ifdef __TWODIM__
+                                                                #ifdef UG_DIM_2
               IFDEBUG(dddif,1)
               printf("ConnectOverlapVerticalGrid(): new "
                      " midnode relation between theEdge=%p"
@@ -731,7 +731,7 @@ static INT ConnectOverlapVerticalGrid (GRID *theGrid)
                      VID_PRTX(MYVERTEX(SonNode)));
               ENDDEBUG
                                                                 #endif
-                                                                #ifdef __THREEDIM__
+                                                                #ifdef UG_DIM_3
               printf("ConnectOverlapVerticalGrid(): new "
                      " midnode relation between theEdge=" ID_FMTX
                      " SonNode=" ID_FMTX "\n",
diff --git a/dune/uggrid/parallel/dddif/parallel.h b/dune/uggrid/parallel/dddif/parallel.h
index c1da21e2696d4c1939494f27e980470b80f27491..e5dc428746665c1ece7f51e38ef6e872231eda84 100644
--- a/dune/uggrid/parallel/dddif/parallel.h
+++ b/dune/uggrid/parallel/dddif/parallel.h
@@ -233,11 +233,11 @@ struct DDD_CTRL
 
   DDD_TYPE TypeUnknown;
 
-#ifdef __TWODIM__
+#ifdef UG_DIM_2
   DDD_TYPE TypeTrElem, TypeTrBElem, TypeQuElem, TypeQuBElem;
 #endif
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
   DDD_TYPE TypeTeElem, TypeTeBElem;
   DDD_TYPE TypePyElem, TypePyBElem;
   DDD_TYPE TypePrElem, TypePrBElem;
diff --git a/dune/uggrid/parallel/dddif/pgmcheck.cc b/dune/uggrid/parallel/dddif/pgmcheck.cc
index 6261bdb2203aed0c6b2336614f3e346128e3fd38..c71f8aabd4d041cf6212279f1263667fd421fca7 100644
--- a/dune/uggrid/parallel/dddif/pgmcheck.cc
+++ b/dune/uggrid/parallel/dddif/pgmcheck.cc
@@ -284,7 +284,7 @@ static INT CheckEdgePrio (DDD::DDDContext& context, ELEMENT *theElement, EDGE *t
 {
   INT nerrors = 0;
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT nmaster;
 
   /* check edge prio */
@@ -473,7 +473,7 @@ static int Gather_ElemObjectGids (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD
     ((DDD_GID *)data)[i] = GID(CORNER(theElement,i));
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* copy edge gids into buffer */
   for (INT i=CORNERS_OF_ELEM(theElement),j=0; i<EDGES_OF_ELEM(theElement); i++,j++)
   {
@@ -505,7 +505,7 @@ static int Scatter_ElemObjectGids (DDD::DDDContext&, DDD_OBJ obj, void *data, DD
     }
   }
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   /* compare edge gids with buffer gids */
   for (INT i=CORNERS_OF_ELEM(theElement),j=0; i<EDGES_OF_ELEM(theElement); i++,j++)
   {
@@ -526,7 +526,7 @@ static int Scatter_ElemObjectGids (DDD::DDDContext&, DDD_OBJ obj, void *data, DD
   return 0;
 }
 
-#ifdef __THREEDIM__
+#ifdef UG_DIM_3
 static int Gather_EdgeObjectGids (DDD::DDDContext&, DDD_OBJ obj, void *data, DDD_PROC proc, DDD_PRIO prio)
 {
   INT i;
@@ -637,10 +637,10 @@ static INT CheckDistributedObjects (GRID *theGrid)
   const auto& dddctrl = ddd_ctrl(context);
 
   INT nerrors;
-        #ifdef __TWODIM__
+        #ifdef UG_DIM_2
   INT size = MAX_CORNERS_OF_ELEM;       /* compare the 3/4 node ids */
         #endif
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   INT size = MAX_CORNERS_OF_ELEM+MAX_EDGES_OF_ELEM;             /* compare 8 nodes + 12 edges */
         #endif
 
@@ -651,7 +651,7 @@ static INT CheckDistributedObjects (GRID *theGrid)
                  dddctrl.ElementSymmVHIF,GRID_ATTR(theGrid),IF_BACKWARD,size*sizeof(DDD_GID),
                  Gather_ElemObjectGids, Scatter_ElemObjectGids);
 
-        #ifdef __THREEDIM__
+        #ifdef UG_DIM_3
   if (0)
     DDD_IFAOnewayX(context,
                    dddctrl.BorderEdgeSymmIF,GRID_ATTR(theGrid),IF_BACKWARD,3*sizeof(DDD_GID),
diff --git a/dune/uggrid/parallel/dddif/priority.cc b/dune/uggrid/parallel/dddif/priority.cc
index 443a7f04433a232973d606912b2f2d9c485676ad..7cc8f88aa604b5332d59289580dc82e8c6a9e57b 100644
--- a/dune/uggrid/parallel/dddif/priority.cc
+++ b/dune/uggrid/parallel/dddif/priority.cc
@@ -432,7 +432,7 @@ void NS_DIM_PREFIX SetGhostObjectPriorities (GRID *theGrid)
         EDGE_PRIORITY_SET(context, theGrid,theEdge,PrioMaster);
     }
 
-                        #ifdef __THREEDIM__
+                        #ifdef UG_DIM_3
     /* if one(all) of the side nodes is (are) a hghost (vghost) node   */
     /* then its a hghost (vghost) side vector                          */
     if (VEC_DEF_IN_OBJ_OF_GRID(theGrid,SIDEVEC))