From 51339d246ea590aa853fc49baa9b26059255d739 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Wed, 7 Dec 2011 15:21:34 +0100
Subject: [PATCH] Use a shared pointer for Ruina's nodalIntegrals

---
 dune/tectonic/globalruinanonlinearity.hh |  8 ++++----
 src/one-body-sample.cc                   | 11 +++++++----
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/dune/tectonic/globalruinanonlinearity.hh b/dune/tectonic/globalruinanonlinearity.hh
index 13d9eed4..16161918 100644
--- a/dune/tectonic/globalruinanonlinearity.hh
+++ b/dune/tectonic/globalruinanonlinearity.hh
@@ -19,7 +19,7 @@ template <int dim>
 class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
 public:
   GlobalRuinaNonlinearity(
-      std::vector<FieldVector<double, 1>> const &nodalIntegrals,
+      shared_ptr<std::vector<FieldVector<double, 1>> const> nodalIntegrals,
       shared_ptr<std::vector<double> const> a,
       shared_ptr<std::vector<double> const> mu,
       shared_ptr<std::vector<double> const> eta,
@@ -36,11 +36,11 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
     Return a restriction of the outer function to the i'th node.
   */
   virtual shared_ptr<LocalNonlinearity<dim> const> restriction(int i) const {
-    if (nodalIntegrals[i][0] == 0)
+    if ((*nodalIntegrals)[i][0] == 0)
       return trivialNonlinearity;
 
     shared_ptr<NiceFunction const> const func(
-        new RuinaFunction(nodalIntegrals[i][0], (*a)[i], (*mu)[i], (*eta)[i],
+        new RuinaFunction((*nodalIntegrals)[i][0], (*a)[i], (*mu)[i], (*eta)[i],
                           (*normalStress)[i]));
     return shared_ptr<LocalNonlinearity<dim>>(new LocalNonlinearity<dim>(func));
   }
@@ -48,7 +48,7 @@ class GlobalRuinaNonlinearity : public GlobalNonlinearity<dim> {
 private:
   shared_ptr<LocalNonlinearity<dim> const> const trivialNonlinearity;
 
-  std::vector<FieldVector<double, 1>> nodalIntegrals;
+  shared_ptr<std::vector<FieldVector<double, 1>> const> nodalIntegrals;
   shared_ptr<std::vector<double> const> a;
   shared_ptr<std::vector<double> const> mu;
   shared_ptr<std::vector<double> const> eta;
diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc
index 794de63e..b837a84c 100644
--- a/src/one-body-sample.cc
+++ b/src/one-body-sample.cc
@@ -138,7 +138,8 @@ void assemble_frictional(
 void assemble_nonlinearity(
     int size, Dune::ParameterTree const &parset,
     Dune::shared_ptr<Dune::GlobalNonlinearity<dim> const> &myGlobalNonlinearity,
-    std::vector<Dune::FieldVector<double, 1>> &nodalIntegrals) {
+    Dune::shared_ptr<std::vector<Dune::FieldVector<double, 1>>>
+        nodalIntegrals) {
   // {{{ Assemble terms for the nonlinearity
   auto mu = Dune::shared_ptr<std::vector<double>>(new std::vector<double>());
   mu->resize(size);
@@ -170,7 +171,7 @@ void assemble_nonlinearity(
   } else if (friction_model == std::string("Laursen")) {
     auto const tmp =
         new Dune::GlobalLaursenNonlinearity<dim, Dune::LinearFunction>(
-            mu, normalStress, nodalIntegrals);
+            mu, normalStress, *nodalIntegrals);
     myGlobalNonlinearity =
         Dune::shared_ptr<Dune::GlobalNonlinearity<dim> const>(tmp);
   } else {
@@ -261,9 +262,11 @@ int main(int argc, char *argv[]) {
     VectorType b2;
     VectorType b3;
 
-    std::vector<Dune::FieldVector<double, 1>> nodalIntegrals;
+    auto nodalIntegrals =
+        Dune::shared_ptr<std::vector<Dune::FieldVector<double, 1>>>(
+            new std::vector<Dune::FieldVector<double, 1>>);
     assemble_frictional<GridType, GridView, SmallVector, P1Basis>(
-        leafView, p1Basis, frictionalNodes, nodalIntegrals);
+        leafView, p1Basis, frictionalNodes, *nodalIntegrals);
 
     Dune::shared_ptr<Dune::GlobalNonlinearity<dim> const> myGlobalNonlinearity;
     assemble_nonlinearity(grid.size(grid.maxLevel(), dim), parset,
-- 
GitLab