From 7a7a69dbad1ae13035d15a3b05ca15a87ef7aae4 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Mon, 19 Dec 2011 15:52:34 +0100
Subject: [PATCH] Cache functions

---
 dune/tectonic/globalruinanonlinearity.hh | 17 ++++++++++++++---
 1 file changed, 14 insertions(+), 3 deletions(-)

diff --git a/dune/tectonic/globalruinanonlinearity.hh b/dune/tectonic/globalruinanonlinearity.hh
index 4c15db46..4397aa34 100644
--- a/dune/tectonic/globalruinanonlinearity.hh
+++ b/dune/tectonic/globalruinanonlinearity.hh
@@ -30,7 +30,13 @@ class GlobalRuinaNonlinearity
         eta(eta),
         normalStress(normalStress),
         trivialNonlinearity(
-            new LocalNonlinearity<dim>(make_shared<TrivialFunction const>())) {}
+            new LocalNonlinearity<dim>(make_shared<TrivialFunction const>())),
+        restrictions(nodalIntegrals->size()) // TODO: can we get the size from
+                                             // another place?
+  {
+    for (auto &x : restrictions)
+      x = shared_ptr<LocalNonlinearity<dim> const>();
+  }
 
   /*
     Return a restriction of the outer function to the i'th node.
@@ -39,11 +45,14 @@ class GlobalRuinaNonlinearity
     if ((*nodalIntegrals)[i][0] == 0)
       return trivialNonlinearity;
 
-    // TODO: cache functions
+    if (restrictions[i] != NULL)
+      return restrictions[i];
+
     auto const func = make_shared<RuinaFunction const>(
         (*nodalIntegrals)[i][0], (*a)[i][0], (*mu)[i][0], (*eta)[i][0],
         (*normalStress)[i][0]);
-    return make_shared<LocalNonlinearity<dim> const>(func);
+    restrictions[i] = make_shared<LocalNonlinearity<dim> const>(func);
+    return restrictions[i];
   }
 
 private:
@@ -54,6 +63,8 @@ class GlobalRuinaNonlinearity
   shared_ptr<BlockVector<FieldVector<double, 1>> const> mu;
   shared_ptr<BlockVector<FieldVector<double, 1>> const> eta;
   shared_ptr<BlockVector<FieldVector<double, 1>> const> normalStress;
+
+  std::vector<shared_ptr<LocalNonlinearity<dim> const>> mutable restrictions;
 };
 }
 #endif
-- 
GitLab