From ef375c38a317b93b5632e4ed3cf0a59f7cc68cdc Mon Sep 17 00:00:00 2001
From: Oliver Sander <oliver.sander@tu-dresden.de>
Date: Sun, 24 Jan 2016 05:18:04 +0100
Subject: [PATCH] Store the local energy in a pointer to the base class, rather
 than by value

This allows to select the energy at run-time, but this is not what we do.
It also allows to give extra parameters to the nonplanar Cosserat energy,
and that is what we need: in a subsequent patch the main program will compute
a surface normal field and pass it to the Nonplanar Cosserat energy.
---
 src/cosserat-continuum.cc | 29 ++++++++++++++++++++---------
 1 file changed, 20 insertions(+), 9 deletions(-)

diff --git a/src/cosserat-continuum.cc b/src/cosserat-continuum.cc
index 9f278552..58aafbd8 100644
--- a/src/cosserat-continuum.cc
+++ b/src/cosserat-continuum.cc
@@ -298,16 +298,27 @@ int main (int argc, char *argv[]) try
         }
 
     // Assembler using ADOL-C
-    using LocalEnergy = std::conditional<dim==dimworld,
-                                         CosseratEnergyLocalStiffness<FEBasis,3,adouble>,
-                                         NonplanarCosseratShellEnergy<FEBasis,3,adouble> >::type;
-
-    LocalEnergy cosseratEnergyADOLCLocalStiffness(materialParameters,
-                                                                              &neumannBoundary,
-                                                                              neumannFunction,
-                                                                              volumeLoad);
+    using LocalEnergyBase = LocalGeodesicFEStiffness<FEBasis,RigidBodyMotion<adouble,3> >;
+
+    std::shared_ptr<LocalEnergyBase> cosseratEnergyADOLCLocalStiffness;
+
+    if (dim==dimworld)
+    {
+      cosseratEnergyADOLCLocalStiffness = std::make_shared<CosseratEnergyLocalStiffness<FEBasis,3,adouble> >(materialParameters,
+                                                                                                             &neumannBoundary,
+                                                                                                             neumannFunction,
+                                                                                                             volumeLoad);
+    }
+    else
+    {
+      cosseratEnergyADOLCLocalStiffness = std::make_shared<NonplanarCosseratShellEnergy<FEBasis,3,adouble> >(materialParameters,
+                                                                                                             &neumannBoundary,
+                                                                                                             neumannFunction,
+                                                                                                             volumeLoad);
+    }
+
     LocalGeodesicFEADOLCStiffness<FEBasis,
-                                  TargetSpace> localGFEADOLCStiffness(&cosseratEnergyADOLCLocalStiffness);
+                                  TargetSpace> localGFEADOLCStiffness(cosseratEnergyADOLCLocalStiffness.get());
 
     GeodesicFEAssembler<FEBasis,TargetSpace> assembler(gridView, &localGFEADOLCStiffness);
 
-- 
GitLab