diff --git a/src/harmonicmaps.cc b/src/harmonicmaps.cc
index 45decd8efcfaac0eaacede631b398f23854c42e0..23e6d958e1381c23d7e91babfec74014145ebb68 100644
--- a/src/harmonicmaps.cc
+++ b/src/harmonicmaps.cc
@@ -21,6 +21,7 @@
 #include <dune/fufem/boundarypatch.hh>
 #include <dune/fufem/functions/vtkbasisgridfunction.hh>
 #include <dune/fufem/functiontools/basisinterpolator.hh>
+#include <dune/fufem/discretizationerror.hh>
 #include <dune/fufem/dunepython.hh>
 
 #include <dune/solvers/solvers/iterativesolver.hh>
@@ -230,6 +231,35 @@ int main (int argc, char *argv[]) try
 
     vtkWriter.write(resultPath + "_" + energy + "_result");
 
+    /////////////////////////////////////////////////////////////////
+    //   Measure the discretization error, if requested
+    /////////////////////////////////////////////////////////////////
+
+    if (parameterSet.get<std::string>("discretizationErrorMode")=="analytical")
+    {
+      // Read reference solution into a PythonFunction
+      std::string lambda = std::string("lambda x: (") + parameterSet.get<std::string>("referenceSolution") + std::string(")");
+      PythonFunction<FieldVector<double,dim>, TargetSpace::CoordinateType > pythonReferenceSolution(Python::evaluate(lambda));
+
+      std::vector<TargetSpace::CoordinateType> xEmbedded(x.size());
+      for (size_t i=0; i<x.size(); i++)
+        xEmbedded[i] = x[i].globalCoordinates();
+
+      BasisGridFunction<FEBasis,std::vector<TargetSpace::CoordinateType> > numericalSolution(feBasis, xEmbedded);
+
+      // QuadratureRule for the integral of the L^2 error
+      QuadratureRuleKey quadKey(dim,3);
+
+      // Compute the embedded L^2 error
+      double l2Error = DiscretizationError<GridType::LeafGridView>::computeL2Error(&numericalSolution,
+                                                                                   &pythonReferenceSolution,
+                                                                                   quadKey);
+
+      std::cout << "L^2 error: " << l2Error << std::endl;
+
+
+    }
+
  } catch (Exception e) {
 
     std::cout << e << std::endl;