From 3441176f7b0939c22d2835c6484ba789180ea051 Mon Sep 17 00:00:00 2001
From: Elias Pipping <elias.pipping@fu-berlin.de>
Date: Thu, 23 Feb 2012 18:06:13 +0100
Subject: [PATCH] Make assemble_nonlinearity a factory method

---
 src/one-body-sample.cc | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/src/one-body-sample.cc b/src/one-body-sample.cc
index c86e18c3..e0c4fe76 100644
--- a/src/one-body-sample.cc
+++ b/src/one-body-sample.cc
@@ -140,10 +140,9 @@ void assemble_frictional(
 }
 
 template <class VectorType, class MatrixType>
-void assemble_nonlinearity(
+Dune::shared_ptr<Dune::GlobalNonlinearity<VectorType, MatrixType> const>
+assemble_nonlinearity(
     int size, Dune::ParameterTree const &parset,
-    Dune::shared_ptr<Dune::GlobalNonlinearity<VectorType, MatrixType> const> &
-        myGlobalNonlinearity,
     Dune::shared_ptr<Dune::BlockVector<Dune::FieldVector<double, 1>>>
         nodalIntegrals) {
   typedef Dune::BlockVector<Dune::FieldVector<double, 1>> SingletonVectorType;
@@ -164,11 +163,11 @@ void assemble_nonlinearity(
     auto eta = Dune::make_shared<SingletonVectorType>(size);
     *eta = parset.get<double>("boundary.friction.eta");
 
-    myGlobalNonlinearity = Dune::make_shared<
+    return Dune::make_shared<
         Dune::GlobalRuinaNonlinearity<VectorType, MatrixType> const>(
         nodalIntegrals, a, mu, eta, normalStress);
   } else if (friction_model == std::string("Laursen")) {
-    myGlobalNonlinearity = Dune::make_shared<Dune::GlobalLaursenNonlinearity<
+    return Dune::make_shared<Dune::GlobalLaursenNonlinearity<
         Dune::LinearFunction, VectorType, MatrixType> const>(mu, normalStress,
                                                              nodalIntegrals);
   } else {
@@ -272,11 +271,8 @@ int main(int argc, char *argv[]) {
     assemble_frictional<GridType, GridView, SmallVector, P1Basis>(
         leafView, p1Basis, frictionalNodes, *nodalIntegrals);
 
-    Dune::shared_ptr<Dune::GlobalNonlinearity<VectorType, OperatorType> const>
-    myGlobalNonlinearity;
-    assemble_nonlinearity<VectorType, OperatorType>(
-        grid->size(grid->maxLevel(), dim), parset, myGlobalNonlinearity,
-        nodalIntegrals);
+    auto myGlobalNonlinearity = assemble_nonlinearity<VectorType, OperatorType>(
+        grid->size(grid->maxLevel(), dim), parset, nodalIntegrals);
 
     // {{{ Set up TNNMG solver
     // linear iteration step components
-- 
GitLab