From 08ca70601a1ba20677e5bd749db6393b4f3fbbf9 Mon Sep 17 00:00:00 2001
From: Jonathan Lambrechts <jonathan.lambrechts@uclouvain.be>
Date: Wed, 8 Dec 2010 14:58:53 +0000
Subject: [PATCH] dg : remove more bugs

---
 Solver/function.cpp | 22 +++++++++++++++++++---
 1 file changed, 19 insertions(+), 3 deletions(-)

diff --git a/Solver/function.cpp b/Solver/function.cpp
index 1ed574ab0e..9abe88f1df 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 ?
-- 
GitLab