diff --git a/src/Makefile.am b/src/Makefile.am
index 3101380e6abacbf89e012dae347cd7276df265dd..fa6b659891685097c8750bc72e373325c549c948 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -17,11 +17,11 @@ common_sources = \
 sand_wedge_2D_SOURCES = $(common_sources) sand-wedge.cc
 sand_wedge_2D_CPPFLAGS = \
 	$(AM_CPPFLAGS) $(BOOST_CPPFLAGS) \
-	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DDIM=2
+	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DMY_DIM=2
 sand_wedge_3D_SOURCES = $(common_sources) sand-wedge.cc
 sand_wedge_3D_CPPFLAGS = \
 	$(AM_CPPFLAGS) $(BOOST_CPPFLAGS) \
-	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DDIM=3
+	-Ddatadir=\"$(abs_srcdir)/sand-wedge-data/\" -DMY_DIM=3
 
 # Some are for clang, others are for gcc
 AM_CXXFLAGS = \
diff --git a/src/assemblers_tmpl.cc b/src/assemblers_tmpl.cc
index 36628ed9d1a317fe9c90dd089f081c4912d1e69e..c2384ddcdd7f8791fb30d7649c50ffc7007fa7f2 100644
--- a/src/assemblers_tmpl.cc
+++ b/src/assemblers_tmpl.cc
@@ -1,7 +1,7 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitgrid.hh"
 
-template class MyAssembler<GridView, DIM>;
+template class MyAssembler<GridView, MY_DIM>;
diff --git a/src/boundary_writer_tmpl.cc b/src/boundary_writer_tmpl.cc
index 8d7f43c4eb8170c3be1d46ac27483f5354f28929..378584de089e6f52cb492bcf131dcae58837a2f2 100644
--- a/src/boundary_writer_tmpl.cc
+++ b/src/boundary_writer_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitvectors.hh"
diff --git a/src/coupledtimestepper_tmpl.cc b/src/coupledtimestepper_tmpl.cc
index d72f58449333d68c48b23b80265a0985f05351e4..a7831212a8fe4e3b8fffe342eea73a77faa52153 100644
--- a/src/coupledtimestepper_tmpl.cc
+++ b/src/coupledtimestepper_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include <dune/common/function.hh>
@@ -18,9 +18,9 @@
 
 using Function = Dune::VirtualFunction<double, double>;
 using Factory = SolverFactory<
-    DIM, MyBlockProblem<ConvexProblem<GlobalFriction<Matrix, Vector>, Matrix>>,
+    MY_DIM, MyBlockProblem<ConvexProblem<GlobalFriction<Matrix, Vector>, Matrix>>,
     Grid>;
 using MyStateUpdater = StateUpdater<ScalarVector, Vector>;
-using MyVelocityUpdater = TimeSteppingScheme<Vector, Matrix, Function, DIM>;
+using MyVelocityUpdater = TimeSteppingScheme<Vector, Matrix, Function, MY_DIM>;
 
 template class CoupledTimeStepper<Factory, MyStateUpdater, MyVelocityUpdater>;
diff --git a/src/explicitgrid.hh b/src/explicitgrid.hh
index bf50999496ddaf87e0e03ac1d35339be169948f0..c1e8500e0b869f5717641a140b423c3430a3956d 100644
--- a/src/explicitgrid.hh
+++ b/src/explicitgrid.hh
@@ -6,6 +6,6 @@
 #include <dune/grid/alugrid.hh>
 #pragma clang diagnostic pop
 
-using Grid = Dune::ALUGrid<DIM, DIM, Dune::simplex, Dune::nonconforming>;
+using Grid = Dune::ALUGrid<MY_DIM, MY_DIM, Dune::simplex, Dune::nonconforming>;
 using GridView = Grid::LeafGridView;
 #endif
diff --git a/src/explicitvectors.hh b/src/explicitvectors.hh
index 832888e123cb12a5de2453321a2a43c921336ed1..923a8c359782057f732c135a8a9e7d479652a397 100644
--- a/src/explicitvectors.hh
+++ b/src/explicitvectors.hh
@@ -6,8 +6,8 @@
 #include <dune/istl/bcrsmatrix.hh>
 #include <dune/istl/bvector.hh>
 
-using LocalVector = Dune::FieldVector<double, DIM>;
-using LocalMatrix = Dune::FieldMatrix<double, DIM, DIM>;
+using LocalVector = Dune::FieldVector<double, MY_DIM>;
+using LocalMatrix = Dune::FieldMatrix<double, MY_DIM, MY_DIM>;
 using Vector = Dune::BlockVector<LocalVector>;
 using Matrix = Dune::BCRSMatrix<LocalMatrix>;
 using ScalarVector = Dune::BlockVector<Dune::FieldVector<double, 1>>;
diff --git a/src/fixedpointiterator_tmpl.cc b/src/fixedpointiterator_tmpl.cc
index 22631e8e74c2440d87a13e3a2c38ae43cb79609c..41d4f910c29e5ff2136a91ed1f717c74ed577092 100644
--- a/src/fixedpointiterator_tmpl.cc
+++ b/src/fixedpointiterator_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include <dune/common/function.hh>
@@ -18,9 +18,9 @@
 
 using Function = Dune::VirtualFunction<double, double>;
 using Factory = SolverFactory<
-    DIM, MyBlockProblem<ConvexProblem<GlobalFriction<Matrix, Vector>, Matrix>>,
+    MY_DIM, MyBlockProblem<ConvexProblem<GlobalFriction<Matrix, Vector>, Matrix>>,
     Grid>;
 using MyStateUpdater = StateUpdater<ScalarVector, Vector>;
-using MyVelocityUpdater = TimeSteppingScheme<Vector, Matrix, Function, DIM>;
+using MyVelocityUpdater = TimeSteppingScheme<Vector, Matrix, Function, MY_DIM>;
 
 template class FixedPointIterator<Factory, MyStateUpdater, MyVelocityUpdater>;
diff --git a/src/friction_writer_tmpl.cc b/src/friction_writer_tmpl.cc
index 6b50b0f6efe8724233ca3bc992063332317a60f4..5ac5e7d55873569ad0a84eb55fdd3c2277d44183 100644
--- a/src/friction_writer_tmpl.cc
+++ b/src/friction_writer_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitvectors.hh"
diff --git a/src/sand-wedge-data/mygeometry.hh b/src/sand-wedge-data/mygeometry.hh
index 25ef5027cd08ce392d8b0ccf2c94d781e0317921..10693e074c296a9368629d2d2c15cc112d160f97 100644
--- a/src/sand-wedge-data/mygeometry.hh
+++ b/src/sand-wedge-data/mygeometry.hh
@@ -10,7 +10,7 @@ namespace {
   using LocalVector2D = Dune::FieldVector<double, 2>;
   using LocalMatrix2D = Dune::FieldMatrix<double, 2, 2>;
 
-  using LocalVector = Dune::FieldVector<double, DIM>;
+  using LocalVector = Dune::FieldVector<double, MY_DIM>;
 
   // kludge because fieldvectors have no initialiser_list constructor, see
   // https://dune-project.org/flyspray/index.php?do=details&task_id=1166
diff --git a/src/sand-wedge-data/mygrid.cc b/src/sand-wedge-data/mygrid.cc
index 8755a29c5cbfa370049563a87a9d2bc1a95386d8..5929d4229672a35ac2f53daf737d744e5cda6e03 100644
--- a/src/sand-wedge-data/mygrid.cc
+++ b/src/sand-wedge-data/mygrid.cc
@@ -5,13 +5,13 @@
 #include "mygrid.hh"
 #include "midpoint.hh"
 
-#if DIM == 3
+#if MY_DIM == 3
 SimplexManager::SimplexManager(unsigned int shift) : shift_(shift) {}
 #endif
 
 void SimplexManager::addFromVertices(unsigned int U, unsigned int V,
                                      unsigned int W) {
-#if DIM == 3
+#if MY_DIM == 3
   unsigned int const U2 = U + shift_;
   unsigned int const V2 = V + shift_;
   unsigned int const W2 = W + shift_;
@@ -51,10 +51,10 @@ template <class Grid> GridConstructor<Grid>::GridConstructor() {
 
   unsigned int const vc = 11;
 
-#if DIM == 3
-  Dune::FieldMatrix<double, 2 * vc, DIM> vertices;
+#if MY_DIM == 3
+  Dune::FieldMatrix<double, 2 * vc, MY_DIM> vertices;
 #else
-  Dune::FieldMatrix<double, vc, DIM> vertices;
+  Dune::FieldMatrix<double, vc, MY_DIM> vertices;
 #endif
   for (size_t i = 0; i < 2; ++i) {
     size_t k = 0;
@@ -70,7 +70,7 @@ template <class Grid> GridConstructor<Grid>::GridConstructor() {
     vertices[k++][i] = ACC[i];
     vertices[k++][i] = C[i];
     assert(k == vc);
-#if DIM == 3
+#if MY_DIM == 3
     vertices[k++][i] = A[i];
     vertices[k++][i] = AAB[i];
     vertices[k++][i] = AB[i];
@@ -86,7 +86,7 @@ template <class Grid> GridConstructor<Grid>::GridConstructor() {
 #endif
   }
 
-#if DIM == 3
+#if MY_DIM == 3
   for (size_t k = 0; k < vc; ++k) {
     vertices[k][2] = -MyGeometry::depth / 2.0;
     vertices[k + vc][2] = MyGeometry::depth / 2.0;
@@ -97,13 +97,13 @@ template <class Grid> GridConstructor<Grid>::GridConstructor() {
     gridFactory.insertVertex(vertices[i]);
 
   Dune::GeometryType cell;
-#if DIM == 3
+#if MY_DIM == 3
   cell.makeTetrahedron();
 #else
   cell.makeTriangle();
 #endif
 
-#if DIM == 3
+#if MY_DIM == 3
   SimplexManager sm(vc);
 #else
   SimplexManager sm;
@@ -122,8 +122,8 @@ template <class Grid> GridConstructor<Grid>::GridConstructor() {
 
   // sanity-check choices of simplices
   for (size_t i = 0; i < simplices.size(); ++i) {
-    Dune::FieldMatrix<double, DIM, DIM> check;
-    for (size_t j = 0; j < DIM; ++j)
+    Dune::FieldMatrix<double, MY_DIM, MY_DIM> check;
+    for (size_t j = 0; j < MY_DIM; ++j)
       check[j] = vertices[simplices[i][j + 1]] - vertices[simplices[i][j]];
     assert(check.determinant() > 0);
     gridFactory.insertElement(cell, simplices[i]);
@@ -173,7 +173,7 @@ bool MyFaces<GridView>::xyBetween(Vector const &v1, Vector const &v2,
 template <class GridView>
 MyFaces<GridView>::MyFaces(GridView const &gridView)
     :
-#if DIM == 3
+#if MY_DIM == 3
       lower(gridView),
       right(gridView),
       upper(gridView),
@@ -191,7 +191,7 @@ MyFaces<GridView>::MyFaces(GridView const &gridView)
   lower.insertFacesByProperty([&](typename GridView::Intersection const &in) {
     return isClose(0, in.geometry().center()[1]);
   });
-#if DIM == 3
+#if MY_DIM == 3
   front.insertFacesByProperty([&](typename GridView::Intersection const &in) {
     return isClose(MyGeometry::depth / 2.0, in.geometry().center()[2]);
   });
diff --git a/src/sand-wedge-data/mygrid.hh b/src/sand-wedge-data/mygrid.hh
index 9759252b91173b5178f01d0649ec6bae82f1bbb5..cb4593e678a35001ec7696de568b7586910c8dd4 100644
--- a/src/sand-wedge-data/mygrid.hh
+++ b/src/sand-wedge-data/mygrid.hh
@@ -19,7 +19,7 @@ template <class GridView> struct MyFaces {
   BoundaryPatch<GridView> right;
   BoundaryPatch<GridView> upper;
 
-#if DIM == 3
+#if MY_DIM == 3
   BoundaryPatch<GridView> front;
   BoundaryPatch<GridView> back;
 #endif
@@ -45,7 +45,7 @@ class SimplexManager {
 public:
   using SimplexList = std::vector<std::vector<unsigned int>>;
 
-#if DIM == 3
+#if MY_DIM == 3
   SimplexManager(unsigned int shift);
 #endif
 
@@ -56,7 +56,7 @@ class SimplexManager {
 private:
   SimplexList simplices_;
 
-#if DIM == 3
+#if MY_DIM == 3
   unsigned int const shift_;
 #endif
 };
diff --git a/src/sand-wedge-data/mygrid_tmpl.cc b/src/sand-wedge-data/mygrid_tmpl.cc
index ea5190a1ee9924420716affa09314bba259cfa70..0ffd11dcdf7a1d52c29f5ab1d322b92bad2d5549 100644
--- a/src/sand-wedge-data/mygrid_tmpl.cc
+++ b/src/sand-wedge-data/mygrid_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitgrid.hh"
diff --git a/src/sand-wedge-data/patchfunction.hh b/src/sand-wedge-data/patchfunction.hh
index 78e90ccdd84e017445ca3bfde55500c4529bd239..197ae5cfbdfc948690d99d98ebfa9d57f44949df 100644
--- a/src/sand-wedge-data/patchfunction.hh
+++ b/src/sand-wedge-data/patchfunction.hh
@@ -6,7 +6,7 @@
 #include <dune/common/parametertree.hh>
 
 class PatchFunction
-    : public Dune::VirtualFunction<Dune::FieldVector<double, DIM>,
+    : public Dune::VirtualFunction<Dune::FieldVector<double, MY_DIM>,
                                    Dune::FieldVector<double, 1>> {
 private:
   bool static isBetween(double x, double lower, double upper) {
@@ -17,13 +17,13 @@ class PatchFunction
     return std::abs(a - b) < 1e-14;
   };
 
-  bool insideRegion2(Dune::FieldVector<double, DIM> const &z) const {
+  bool insideRegion2(Dune::FieldVector<double, MY_DIM> const &z) const {
     assert(isClose(0, z[1]));
     return isBetween(z[0], _X[0], _Y[0]);
   }
 
-  Dune::FieldVector<double, DIM> const &_X;
-  Dune::FieldVector<double, DIM> const &_Y;
+  Dune::FieldVector<double, MY_DIM> const &_X;
+  Dune::FieldVector<double, MY_DIM> const &_Y;
 
   double const _v1;
   double const _v2;
@@ -32,7 +32,7 @@ class PatchFunction
   PatchFunction(double v1, double v2)
       : _X(MyGeometry::X), _Y(MyGeometry::Y), _v1(v1), _v2(v2) {}
 
-  void evaluate(Dune::FieldVector<double, DIM> const &x,
+  void evaluate(Dune::FieldVector<double, MY_DIM> const &x,
                 Dune::FieldVector<double, 1> &y) const {
     y = insideRegion2(x) ? _v2 : _v1;
   }
diff --git a/src/sand-wedge-data/twopiece.hh b/src/sand-wedge-data/twopiece.hh
index d969c845b1a61f691db28591820a139d26d51b95..02872d666f95fb3a595674702c1b7bb85f033e7e 100644
--- a/src/sand-wedge-data/twopiece.hh
+++ b/src/sand-wedge-data/twopiece.hh
@@ -8,20 +8,20 @@
 #include "mygeometry.hh"
 
 class TwoPieceFunction
-    : public Dune::VirtualFunction<Dune::FieldVector<double, DIM>,
+    : public Dune::VirtualFunction<Dune::FieldVector<double, MY_DIM>,
                                    Dune::FieldVector<double, 1>> {
 private:
-  bool liesBelow(Dune::FieldVector<double, DIM> const &x,
-                 Dune::FieldVector<double, DIM> const &y,
-                 Dune::FieldVector<double, DIM> const &z) const {
+  bool liesBelow(Dune::FieldVector<double, MY_DIM> const &x,
+                 Dune::FieldVector<double, MY_DIM> const &y,
+                 Dune::FieldVector<double, MY_DIM> const &z) const {
     return (z[0] - x[0]) * (y[1] - x[1]) / (y[0] - x[0]) >= z[1] - x[1];
   };
-  bool insideRegion2(Dune::FieldVector<double, DIM> const &z) const {
+  bool insideRegion2(Dune::FieldVector<double, MY_DIM> const &z) const {
     return liesBelow(_K, _M, z);
   };
 
-  Dune::FieldVector<double, DIM> const &_K;
-  Dune::FieldVector<double, DIM> const &_M;
+  Dune::FieldVector<double, MY_DIM> const &_K;
+  Dune::FieldVector<double, MY_DIM> const &_M;
 
   double const _v1;
   double const _v2;
@@ -30,7 +30,7 @@ class TwoPieceFunction
   TwoPieceFunction(double v1, double v2)
       : _K(MyGeometry::K), _M(MyGeometry::M), _v1(v1), _v2(v2) {}
 
-  void evaluate(Dune::FieldVector<double, DIM> const &x,
+  void evaluate(Dune::FieldVector<double, MY_DIM> const &x,
                 Dune::FieldVector<double, 1> &y) const {
     y = insideRegion2(x) ? _v2 : _v1;
   }
diff --git a/src/sand-wedge.cc b/src/sand-wedge.cc
index 7b9ecf0f2b537fa8496a0fdc57d158c236db022f..74d93ab0472af6d4e2384c1fab6be03ac5a513d4 100644
--- a/src/sand-wedge.cc
+++ b/src/sand-wedge.cc
@@ -16,8 +16,8 @@
 #error datadir unset
 #endif
 
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #if !HAVE_ALUGRID
@@ -84,7 +84,7 @@
 #include "timestepping.hh"
 #include "vtk.hh"
 
-size_t const dims = DIM;
+size_t const dims = MY_DIM;
 
 void initPython() {
   Python::start();
@@ -139,7 +139,7 @@ int main(int argc, char *argv[]) {
       if (myFaces.lower.containsVertex(i))
         dirichletNodes[i][1] = true;
 
-#if DIM == 3
+#if MY_DIM == 3
       if (myFaces.front.containsVertex(i) || myFaces.back.containsVertex(i))
         dirichletNodes[i][2] = true;
 #endif
diff --git a/src/solverfactory_tmpl.cc b/src/solverfactory_tmpl.cc
index db6ecb8945d4c05a1d5ba5425f6fb7a463710716..f9edf6e2707022664c45bec582845eac08636c91 100644
--- a/src/solverfactory_tmpl.cc
+++ b/src/solverfactory_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitgrid.hh"
@@ -13,10 +13,10 @@
 #include <dune/tectonic/myblockproblem.hh>
 
 template class SolverFactory<
-    DIM,
+    MY_DIM,
     MyBlockProblem<ConvexProblem<GlobalFriction<Matrix, Vector>, Matrix>>,
     Grid>;
 template class SolverFactory<
-    DIM, BlockNonlinearTNNMGProblem<
+    MY_DIM, BlockNonlinearTNNMGProblem<
              ConvexProblem<ZeroNonlinearity<LocalVector, LocalMatrix>, Matrix>>,
     Grid>;
diff --git a/src/timestepping_tmpl.cc b/src/timestepping_tmpl.cc
index 7c63e759ee4b1c51e0b05ea6ea671954543e6b04..a61958b8e19ad336ec5624f5ccdbd6194236cadc 100644
--- a/src/timestepping_tmpl.cc
+++ b/src/timestepping_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include <dune/common/function.hh>
@@ -8,5 +8,5 @@
 
 using Function = Dune::VirtualFunction<double, double>;
 
-template class Newmark<Vector, Matrix, Function, DIM>;
-template class BackwardEuler<Vector, Matrix, Function, DIM>;
+template class Newmark<Vector, Matrix, Function, MY_DIM>;
+template class BackwardEuler<Vector, Matrix, Function, MY_DIM>;
diff --git a/src/vtk_tmpl.cc b/src/vtk_tmpl.cc
index 2b1930040ce0ea55c49d31e3e85ac3f76a86ff74..f6790e5cbe221a728c0e03d7aa080a6303080832 100644
--- a/src/vtk_tmpl.cc
+++ b/src/vtk_tmpl.cc
@@ -1,5 +1,5 @@
-#ifndef DIM
-#error DIM unset
+#ifndef MY_DIM
+#error MY_DIM unset
 #endif
 
 #include "explicitgrid.hh"