From 453d4964be9731654c5cf1701b9dfeb620514e0f Mon Sep 17 00:00:00 2001
From: Jonathan Youett <youett@math.fu-berlin.de>
Date: Mon, 29 Oct 2018 10:21:38 +0100
Subject: [PATCH] Only use Amira if it is installed

Otherwise fixed grids are created and the Dirichlet condition is set to zero
---
 src/2bcontact.cc | 38 ++++++++++++++++++++++++++++++++++++--
 1 file changed, 36 insertions(+), 2 deletions(-)

diff --git a/src/2bcontact.cc b/src/2bcontact.cc
index d472720d..92115b7a 100644
--- a/src/2bcontact.cc
+++ b/src/2bcontact.cc
@@ -35,6 +35,7 @@
 #include <dune/fufem/functions/vtkbasisgridfunction.hh>
 #include <dune/fufem/functions/coarsegridfunctionwrapper.hh>
 #include <dune/fufem/utilities/dirichletbcassembler.hh>
+#include <dune/fufem/utilities/gridconstruction.hh>
 
 #include <dune/functions/functionspacebases/lagrangebasis.hh>
 #ifdef HAVE_IPOPT
@@ -128,7 +129,7 @@ int main (int argc, char *argv[]) try
     typedef BoundaryPatch<GridType::LeafGridView> LeafBoundaryPatch;
 
     std::array<std::unique_ptr<GridType>, 2> grids;
-
+#if HAVE_AMIRAMESH
     if (paramBoundaries) {
         parFile0 = parameterSet.get<std::string>("parFile0");
         parFile1 = parameterSet.get<std::string>("parFile1");
@@ -138,13 +139,42 @@ int main (int argc, char *argv[]) try
         grids[0] = AmiraMeshReader<GridType>::read(path + object0Name);
         grids[1] = AmiraMeshReader<GridType>::read(path + object1Name);
     }
+#else
+    // if no Amira is found create a box and a die
+    ParameterTree configBox;
+    configBox["lowerCorner"] = "0 0 0";
+    configBox["upperCorner"] = "4 9 3";
+    configBox["elements"] = "4 8 2";
+    configBox["tetrahedral"] = "1";
+    grids[0] = GridConstruction<GridType, dim>::createCuboid(configBox);
+
+    ParameterTree configDie;
+    configDie["center"] = "-0.7 4.5 6.2";
+    configDie["thickness"] = "0.2";
+    configDie["length"]= "5.2";
+    configDie["innerRadius"]= "3";
+    configDie["fromAngle"] = "3.1415";
+    configDie["toAngle"] = "6.283";
+    configDie["nElementRing"] = "25";
+    configDie["nElementLength"] = "10";
+    configDie["closeTube"] = "0";
+    configDie["axis"] = "0";
+    configDie["tetrahedra"] = "1";
+    configDie["parameterizedBoundary"] = "0";
+    grids[1] = GridConstruction<GridType, dim>::createTubeSegment(configDie);
+#endif
 
     std::array<VectorType, 2> coarseDirichletValues;
     coarseDirichletValues[0].resize(grids[0]->size(0, dim));
     coarseDirichletValues[1].resize(grids[1]->size(0, dim));
+#if HAVE_AMIRAMESH
     AmiraMeshReader<GridType>::readFunction(coarseDirichletValues[0], path + dirichletValuesFile0);
     AmiraMeshReader<GridType>::readFunction(coarseDirichletValues[1], path + dirichletValuesFile1);
-
+#else
+#warning You have to set Dirichlet values manually or get Amira!
+    coarseDirichletValues[0] = 0;
+    coarseDirichletValues[1] = 0;
+#endif
     // Scale Dirichlet values
     coarseDirichletValues[0] *= scaling;
     coarseDirichletValues[1] *= scaling;
@@ -498,6 +528,7 @@ int main (int argc, char *argv[]) try
     // Output result
     std::string writer = parameterSet.get("writer","Vtk");
     if (writer=="Amira") {
+#if HAVE_AMIRAMESH
         LeafAmiraMeshWriter<GridType> amiramesh;
         amiramesh.addLeafGrid(*grids[0],true);
         amiramesh.addVertexData(x[0], grids[0]->leafGridView());
@@ -507,6 +538,9 @@ int main (int argc, char *argv[]) try
         amiramesh2.addLeafGrid(*grids[1],true);
         amiramesh2.addVertexData(x[1], grids[1]->leafGridView());
         amiramesh2.write(resultPath+"1resultGrid",1);
+#else
+#error Cannot write results in Amira format without Amiramesh
+#endif
     } else {
 
         VTKWriter<GridType::LeafGridView> vtkWriter0(grids[0]->leafGridView());
-- 
GitLab