From ff2e10c3d881fa878d33a0e4e1309f5c257531ff Mon Sep 17 00:00:00 2001
From: Oliver Sander <oliver.sander@tu-dresden.de>
Date: Sat, 29 Sep 2018 20:32:25 +0200
Subject: [PATCH] Do not hard-wire the problems to be 3d

---
 dune/elasticity/materials/exphenckyenergy.hh |  2 +-
 dune/elasticity/materials/henckyenergy.hh    |  2 +-
 dune/elasticity/materials/neohookeenergy.hh  |  2 +-
 dune/elasticity/materials/neumannenergy.hh   | 12 +++++------
 dune/elasticity/materials/sumenergy.hh       | 10 ++++-----
 src/finite-strain-elasticity.cc              | 22 ++++++++++----------
 6 files changed, 25 insertions(+), 25 deletions(-)

diff --git a/dune/elasticity/materials/exphenckyenergy.hh b/dune/elasticity/materials/exphenckyenergy.hh
index d684227..1721e78 100644
--- a/dune/elasticity/materials/exphenckyenergy.hh
+++ b/dune/elasticity/materials/exphenckyenergy.hh
@@ -14,7 +14,7 @@ template<class GridView, class LocalFiniteElement, class field_type=double>
 class ExpHenckyEnergy
   : public LocalFEStiffness<GridView,
                             LocalFiniteElement,
-                            std::vector<Dune::FieldVector<field_type,3> > >
+                            std::vector<Dune::FieldVector<field_type,GridView::dimension> > >
 {
   // grid types
   typedef typename GridView::Grid::ctype DT;
diff --git a/dune/elasticity/materials/henckyenergy.hh b/dune/elasticity/materials/henckyenergy.hh
index c603a34..7a51315 100644
--- a/dune/elasticity/materials/henckyenergy.hh
+++ b/dune/elasticity/materials/henckyenergy.hh
@@ -12,7 +12,7 @@ namespace Dune {
 
 template<class GridView, class LocalFiniteElement, class field_type=double>
 class HenckyEnergy
-    : public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > >
+    : public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,GridView::dimension> > >
 {
     // grid types
     typedef typename GridView::Grid::ctype DT;
diff --git a/dune/elasticity/materials/neohookeenergy.hh b/dune/elasticity/materials/neohookeenergy.hh
index 09118d0..6989214 100644
--- a/dune/elasticity/materials/neohookeenergy.hh
+++ b/dune/elasticity/materials/neohookeenergy.hh
@@ -14,7 +14,7 @@ template<class GridView, class LocalFiniteElement, class field_type=double>
 class NeoHookeEnergy
   : public LocalFEStiffness<GridView,
                             LocalFiniteElement,
-                            std::vector<Dune::FieldVector<field_type,3> > >
+                            std::vector<Dune::FieldVector<field_type,GridView::dimension> > >
 {
   // grid types
   typedef typename GridView::Grid::ctype DT;
diff --git a/dune/elasticity/materials/neumannenergy.hh b/dune/elasticity/materials/neumannenergy.hh
index 539418d..3c16d38 100644
--- a/dune/elasticity/materials/neumannenergy.hh
+++ b/dune/elasticity/materials/neumannenergy.hh
@@ -15,7 +15,7 @@ namespace Dune {
 
 template<class GridView, class LocalFiniteElement, class field_type=double>
 class NeumannEnergy
-: public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > >
+: public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,GridView::dimension> > >
 {
  // grid types
   typedef typename GridView::ctype ctype;
@@ -29,7 +29,7 @@ public:
    * \param parameters The material parameters
    */
   NeumannEnergy(const BoundaryPatch<GridView>* neumannBoundary,
-                const Dune::VirtualFunction<Dune::FieldVector<ctype,dim>, Dune::FieldVector<double,3> >* neumannFunction)
+                const Dune::VirtualFunction<Dune::FieldVector<ctype,dim>, Dune::FieldVector<double,dim> >* neumannFunction)
   : neumannBoundary_(neumannBoundary),
     neumannFunction_(neumannFunction)
   {}
@@ -70,10 +70,10 @@ public:
             value[j] += shapeFunctionValues[i] * localConfiguration[i][j];
 
         // Value of the Neumann data at the current position
-        Dune::FieldVector<double,3> neumannValue;
+        Dune::FieldVector<double,dim> neumannValue;
 
-        if (dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,3> >*>(neumannFunction_))
-            dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,3> >*>(neumannFunction_)->evaluateLocal(element, quadPos, neumannValue);
+        if (dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_))
+            dynamic_cast<const VirtualGridViewFunction<GridView,Dune::FieldVector<double,dim> >*>(neumannFunction_)->evaluateLocal(element, quadPos, neumannValue);
         else
             neumannFunction_->evaluate(it.geometry().global(quad[pt].position()), neumannValue);
 
@@ -93,7 +93,7 @@ private:
   const BoundaryPatch<GridView>* neumannBoundary_;
 
   /** \brief The function implementing the Neumann data */
-  const Dune::VirtualFunction<Dune::FieldVector<double,dim>, Dune::FieldVector<double,3> >* neumannFunction_;
+  const Dune::VirtualFunction<Dune::FieldVector<double,dim>, Dune::FieldVector<double,dim> >* neumannFunction_;
 };
 
 }
diff --git a/dune/elasticity/materials/sumenergy.hh b/dune/elasticity/materials/sumenergy.hh
index c316a16..b2c9f50 100644
--- a/dune/elasticity/materials/sumenergy.hh
+++ b/dune/elasticity/materials/sumenergy.hh
@@ -15,7 +15,7 @@ namespace Dune {
 
 template<class GridView, class LocalFiniteElement, class field_type=double>
 class SumEnergy
-: public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > >
+: public LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,GridView::dimension> > >
 {
  // grid types
   typedef typename GridView::ctype ctype;
@@ -28,8 +28,8 @@ public:
   /** \brief Constructor with a set of material parameters
    * \param parameters The material parameters
    */
-  SumEnergy(std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > > > a,
-            std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > > > b)
+  SumEnergy(std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,dim> > > > a,
+            std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,dim> > > > b)
   : a_(a),
     b_(b)
   {}
@@ -45,9 +45,9 @@ public:
 
 private:
 
-  std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > > > a_;
+  std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,dim> > > > a_;
 
-  std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,3> > > > b_;
+  std::shared_ptr<LocalFEStiffness<GridView,LocalFiniteElement,std::vector<Dune::FieldVector<field_type,dim> > > > b_;
 };
 
 }
diff --git a/src/finite-strain-elasticity.cc b/src/finite-strain-elasticity.cc
index 81f6094..5976142 100644
--- a/src/finite-strain-elasticity.cc
+++ b/src/finite-strain-elasticity.cc
@@ -49,21 +49,21 @@ using namespace Dune;
 
 /** \brief A constant vector-valued function, for simple Neumann boundary values */
 struct NeumannFunction
-    : public Dune::VirtualFunction<FieldVector<double,dim>, FieldVector<double,3> >
+    : public Dune::VirtualFunction<FieldVector<double,dim>, FieldVector<double,dim> >
 {
-  NeumannFunction(const FieldVector<double,3> values,
+  NeumannFunction(const FieldVector<double,dim> values,
                   double homotopyParameter)
   : values_(values),
     homotopyParameter_(homotopyParameter)
   {}
 
-  void evaluate(const FieldVector<double, dim>& x, FieldVector<double,3>& out) const
+  void evaluate(const FieldVector<double, dim>& x, FieldVector<double,dim>& out) const
   {
     out = 0;
     out.axpy(-homotopyParameter_, values_);
   }
 
-  FieldVector<double,3> values_;
+  FieldVector<double,dim> values_;
   double homotopyParameter_;
 };
 
@@ -205,7 +205,7 @@ int main (int argc, char *argv[]) try
   SolutionType x(feBasis.size());
 
   lambda = std::string("lambda x: (") + parameterSet.get<std::string>("initialDeformation") + std::string(")");
-  PythonFunction<FieldVector<double,dim>, FieldVector<double,3> > pythonInitialDeformation(Python::evaluate(lambda));
+  PythonFunction<FieldVector<double,dim>, FieldVector<double,dim> > pythonInitialDeformation(Python::evaluate(lambda));
 
   ::Functions::interpolate(fufemFEBasis, x, pythonInitialDeformation);
 
@@ -225,7 +225,7 @@ int main (int argc, char *argv[]) try
 
   //  We need to subsample, because VTK cannot natively display real second-order functions
   SubsamplingVTKWriter<GridView> vtkWriter(gridView, Dune::refinementLevels(2));
-  vtkWriter.addVertexData(localDisplacementFunction, VTK::FieldInfo("displacement", VTK::FieldInfo::Type::scalar, 3));
+  vtkWriter.addVertexData(localDisplacementFunction, VTK::FieldInfo("displacement", VTK::FieldInfo::Type::scalar, dim));
   vtkWriter.write(resultPath + "finite-strain_homotopy_0");
 
   for (int i=0; i<numHomotopySteps; i++)
@@ -242,10 +242,10 @@ int main (int argc, char *argv[]) try
     const ParameterTree& materialParameters = parameterSet.sub("materialParameters");
     std::shared_ptr<NeumannFunction> neumannFunction;
     if (parameterSet.hasKey("neumannValues"))
-      neumannFunction = make_shared<NeumannFunction>(parameterSet.get<FieldVector<double,3> >("neumannValues"),
+      neumannFunction = make_shared<NeumannFunction>(parameterSet.get<FieldVector<double,dim> >("neumannValues"),
                                                      homotopyParameter);
 
-    std::cout << "Neumann values: " << parameterSet.get<FieldVector<double,3> >("neumannValues") << std::endl;
+    std::cout << "Neumann values: " << parameterSet.get<FieldVector<double,dim> >("neumannValues") << std::endl;
 
     if (mpiHelper.rank() == 0)
     {
@@ -257,7 +257,7 @@ int main (int argc, char *argv[]) try
     std::cout << "Selected energy is: " << parameterSet.get<std::string>("energy") << std::endl;
     std::shared_ptr<LocalFEStiffness<GridView,
                                      FEBasis::LocalView::Tree::FiniteElement,
-                                     std::vector<Dune::FieldVector<adouble, 3> > > > elasticEnergy;
+                                     std::vector<Dune::FieldVector<adouble, dim> > > > elasticEnergy;
 
     if (parameterSet.get<std::string>("energy") == "stvenantkirchhoff")
       elasticEnergy = std::make_shared<StVenantKirchhoffEnergy<GridView,
@@ -329,7 +329,7 @@ int main (int argc, char *argv[]) try
     Python::Reference dirichletValuesPythonObject = C(homotopyParameter);
 
     // Extract object member functions as Dune functions
-    PythonFunction<FieldVector<double,dim>, FieldVector<double,3> >   dirichletValues(dirichletValuesPythonObject.get("dirichletValues"));
+    PythonFunction<FieldVector<double,dim>, FieldVector<double,dim> >   dirichletValues(dirichletValuesPythonObject.get("dirichletValues"));
 
     ::Functions::interpolate(fufemFEBasis, x, dirichletValues, dirichletDofs);
 
@@ -355,7 +355,7 @@ int main (int argc, char *argv[]) try
 
     //  We need to subsample, because VTK cannot natively display real second-order functions
     SubsamplingVTKWriter<GridView> vtkWriter(gridView, Dune::refinementLevels(2));
-    vtkWriter.addVertexData(localDisplacementFunction, VTK::FieldInfo("displacement", VTK::FieldInfo::Type::scalar, 3));
+    vtkWriter.addVertexData(localDisplacementFunction, VTK::FieldInfo("displacement", VTK::FieldInfo::Type::scalar, dim));
     vtkWriter.write(resultPath + "finite-strain_homotopy_" + std::to_string(i+1));
   }
 
-- 
GitLab