diff --git a/Solver/function.cpp b/Solver/function.cpp
index 1ed574ab0e2e94246cf4e8639d121db8948507b6..9abe88f1df87b5caf3568fdc4419d5834958566f 100644
--- a/Solver/function.cpp
+++ b/Solver/function.cpp
@@ -234,12 +234,28 @@ dataCacheDouble *dataCacheMap::get(const function *f, dataCacheDouble *caller, b
   //special case
   if (f == function::getSolution()) {
     f = _functionSolution;
-    if (f == NULL)
-      Msg::Error ("solution function has not been set");
+    if (f == NULL) {
+      dataCacheMap *parent = _parent;
+      while (parent) {
+        f = _parent->_functionSolution;
+        if (f) break;
+        parent = _parent->_parent;
+      }
+      if (f == NULL) 
+        Msg::Error ("solution function has not been set");
+    }
   } else if (f == function::getSolutionGradient()) {
     f = _functionSolutionGradient;
-    if (f == NULL)
+    if (f == NULL) {
+      dataCacheMap *parent = _parent;
+      while (parent) {
+        f = _parent->_functionSolutionGradient;
+        if (f) break;
+        parent = _parent->_parent;
+      }
+      if (f == NULL) 
       Msg::Error ("solution function gradient has not been set");
+    }
   }
 
   // do I have a cache for this function ?