From ca04523c654b8d7842e8bca7cd15d917a974a78c Mon Sep 17 00:00:00 2001
From: Timo Koch <timo.koch@iws.uni-stuttgart.de>
Date: Mon, 9 Jul 2018 14:57:14 +0200
Subject: [PATCH] [course] Make this a dune module. Add install script.

---
 CMakeLists.txt           |  28 ++++++++++
 LICENSE.md               |  11 ++++
 cmake.opts               |  22 ++++++++
 config.h.cmake           |  45 +++++++++++++++
 dumux-course.pc.in       |  15 +++++
 dune.module              |  10 ++++
 exercises/CMakeLists.txt |   0
 scripts/README.md        |  30 ++++++++++
 scripts/install.opts     |  22 ++++++++
 scripts/install.sh       | 118 ++++++++++++++++++++++++++++++++++++++-
 scripts/test_dumux.sh    |   7 +++
 11 files changed, 306 insertions(+), 2 deletions(-)
 create mode 100644 CMakeLists.txt
 create mode 100644 LICENSE.md
 create mode 100644 cmake.opts
 create mode 100644 config.h.cmake
 create mode 100644 dumux-course.pc.in
 create mode 100644 dune.module
 create mode 100644 exercises/CMakeLists.txt
 create mode 100644 scripts/install.opts
 create mode 100755 scripts/test_dumux.sh

diff --git a/CMakeLists.txt b/CMakeLists.txt
new file mode 100644
index 00000000..39f45753
--- /dev/null
+++ b/CMakeLists.txt
@@ -0,0 +1,28 @@
+# We require version CMake version 3.1 to prevent issues
+# with dune_enable_all_packages and older CMake versions.
+cmake_minimum_required(VERSION 3.1)
+project(dumux-course CXX)
+
+if(NOT (dune-common_DIR OR dune-common_ROOT OR
+      "${CMAKE_PREFIX_PATH}" MATCHES ".*dune-common.*"))
+    string(REPLACE  ${CMAKE_PROJECT_NAME} dune-common dune-common_DIR
+      ${PROJECT_BINARY_DIR})
+endif()
+
+#find dune-common and set the module path
+find_package(dune-common REQUIRED)
+list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/modules"
+  ${dune-common_MODULE_PATH})
+
+#include the dune macros
+include(DuneMacros)
+
+# start a dune project with information from dune.module
+dune_project()
+
+dune_enable_all_packages()
+
+add_subdirectory(exercises)
+
+# finalize the dune project, e.g. generating config.h etc.
+finalize_dune_project(GENERATE_CONFIG_H_CMAKE)
diff --git a/LICENSE.md b/LICENSE.md
new file mode 100644
index 00000000..002a3b05
--- /dev/null
+++ b/LICENSE.md
@@ -0,0 +1,11 @@
+Licensing Information
+=====================
+
+Copyright holders
+-----------------
+
+| Year       | Name                       |
+|------------|----------------------------|
+| 2018       | LH2, IWS, University of Stuttgart |
+
+For educational use only. Please [contact us](http://www.hydrosys.uni-stuttgart.de/index.en.php) for license information.
diff --git a/cmake.opts b/cmake.opts
new file mode 100644
index 00000000..677a329c
--- /dev/null
+++ b/cmake.opts
@@ -0,0 +1,22 @@
+GXX_RELEASE_WARNING_OPTS=" \
+    -Wall \
+    -Wno-deprecated \
+    -Wno-deprecated-declarations \
+    -Wno-sign-compare"
+
+GXX_RELEASE_OPTS=" \
+    -fno-strict-aliasing \
+    -fstrict-overflow \
+    -fno-finite-math-only \
+    -O3 \
+    -march=native \
+    -funroll-loops \
+    -g0"
+
+CMAKE_FLAGS="
+-DCMAKE_C_COMPILER=/usr/bin/gcc
+-DCMAKE_CXX_COMPILER=/usr/bin/g++
+-DCMAKE_CXX_FLAGS_RELEASE='$GXX_RELEASE_OPTS $GXX_RELEASE_WARNING_OPTS'
+-DCMAKE_CXX_FLAGS_DEBUG='-O0 -ggdb -Wall'
+-DCMAKE_BUILD_TYPE=Release
+"
diff --git a/config.h.cmake b/config.h.cmake
new file mode 100644
index 00000000..6a0ccf87
--- /dev/null
+++ b/config.h.cmake
@@ -0,0 +1,45 @@
+/* begin dumux-course
+   put the definitions for config.h specific to
+   your project here. Everything above will be
+   overwritten
+*/
+
+/* begin private */
+/* Name of package */
+#define PACKAGE "@DUNE_MOD_NAME@"
+
+/* Define to the address where bug reports for this package should be sent. */
+#define PACKAGE_BUGREPORT "@DUNE_MAINTAINER@"
+
+/* Define to the full name of this package. */
+#define PACKAGE_NAME "@DUNE_MOD_NAME@"
+
+/* Define to the full name and version of this package. */
+#define PACKAGE_STRING "@DUNE_MOD_NAME@ @DUNE_MOD_VERSION@"
+
+/* Define to the one symbol short name of this package. */
+#define PACKAGE_TARNAME "@DUNE_MOD_NAME@"
+
+/* Define to the home page for this package. */
+#define PACKAGE_URL "@DUNE_MOD_URL@"
+
+/* Define to the version of this package. */
+#define PACKAGE_VERSION "@DUNE_MOD_VERSION@"
+
+/* end private */
+
+/* Define to the version of dumux-course */
+#define DUMUX_COURSE_VERSION "@DUMUX_COURSE_VERSION@"
+
+/* Define to the major version of dumux-course */
+#define DUMUX_COURSE_VERSION_MAJOR @DUMUX_COURSE_VERSION_MAJOR@
+
+/* Define to the minor version of dumux-course */
+#define DUMUX_COURSE_VERSION_MINOR @DUMUX_COURSE_VERSION_MINOR@
+
+/* Define to the revision of dumux-course */
+#define DUMUX_COURSE_VERSION_REVISION @DUMUX_COURSE_VERSION_REVISION@
+
+/* end dumux-course
+   Everything below here will be overwritten
+*/
diff --git a/dumux-course.pc.in b/dumux-course.pc.in
new file mode 100644
index 00000000..47f9a545
--- /dev/null
+++ b/dumux-course.pc.in
@@ -0,0 +1,15 @@
+prefix=@prefix@
+exec_prefix=@exec_prefix@
+libdir=@libdir@
+includedir=@includedir@
+CXX=@CXX@
+CC=@CC@
+DEPENDENCIES=@REQUIRES@
+
+Name: @PACKAGE_NAME@
+Version: @VERSION@
+Description: dumux-course module
+URL: http://dune-project.org/
+Requires: dumux
+Libs: -L${libdir}
+Cflags: -I${includedir}
diff --git a/dune.module b/dune.module
new file mode 100644
index 00000000..171716ea
--- /dev/null
+++ b/dune.module
@@ -0,0 +1,10 @@
+################################
+# Dune module information file #
+################################
+
+#Name of the module
+Module: dumux-course
+Version: 2018
+Maintainer: timo.koch@iws.uni-stuttgart.de
+#depending on
+Depends: dumux
diff --git a/exercises/CMakeLists.txt b/exercises/CMakeLists.txt
new file mode 100644
index 00000000..e69de29b
diff --git a/scripts/README.md b/scripts/README.md
index c41db16c..8bf9b208 100644
--- a/scripts/README.md
+++ b/scripts/README.md
@@ -3,4 +3,34 @@
 The install script is a shell script that will setup DuMu<sup>x</sup> on your computer
 in the version that is required to complete the current course's exercises.
 
+Installation guide dumux
+-------------------------
+
+You can set up dumux using the attached script install.sh.
+You need to have the following REQUIREMENTS installed:
+  * gcc >= 4.9
+  * cmake >= 3.1
+  * git
+  * pkg-config
+  * paraview (to visualize the results)
+
+On debian-based system you can use this:
+  apt-get install build-essential pkg-config cmake git paraview
+
+Then, you can the execute the script and it will download the dune repositories and dumux
+and configure all modules with CMake
+  ./install.sh
+This will clone the necessary repositories (in a subfolder 'dune'),
+build all libaries.
+
+The dune core modules are also available as debian packages
+(see http://www.dune-project.org/download.html#binary) where
+the version 2.4 is required.
+
+Run the script test_dumux.sh in the same folder you ran this script
+to test your installation of dumux.
+  ./test_dumux.sh
+It will compile and run a simple one-phase ground water flow example
+and visualizes the result using paraview.
+
 * Click [here](./install.sh) to view and download the install script
diff --git a/scripts/install.opts b/scripts/install.opts
new file mode 100644
index 00000000..677a329c
--- /dev/null
+++ b/scripts/install.opts
@@ -0,0 +1,22 @@
+GXX_RELEASE_WARNING_OPTS=" \
+    -Wall \
+    -Wno-deprecated \
+    -Wno-deprecated-declarations \
+    -Wno-sign-compare"
+
+GXX_RELEASE_OPTS=" \
+    -fno-strict-aliasing \
+    -fstrict-overflow \
+    -fno-finite-math-only \
+    -O3 \
+    -march=native \
+    -funroll-loops \
+    -g0"
+
+CMAKE_FLAGS="
+-DCMAKE_C_COMPILER=/usr/bin/gcc
+-DCMAKE_CXX_COMPILER=/usr/bin/g++
+-DCMAKE_CXX_FLAGS_RELEASE='$GXX_RELEASE_OPTS $GXX_RELEASE_WARNING_OPTS'
+-DCMAKE_CXX_FLAGS_DEBUG='-O0 -ggdb -Wall'
+-DCMAKE_BUILD_TYPE=Release
+"
diff --git a/scripts/install.sh b/scripts/install.sh
index a164ae11..bdad6681 100755
--- a/scripts/install.sh
+++ b/scripts/install.sh
@@ -1,3 +1,117 @@
-#!/bin/bash
+# One click install script dumux
+DUNE_VERSION=2.6
 
-echo "TODO Install script for the dumux course 2018"
+# check some prerequistes
+for PRGRM in git cmake gcc g++ wget paraview pkg-config; do
+    if ! [ -x "$(command -v $PRGRM)" ]; then
+        echo "Error: $PRGRM is not installed." >&2
+        exit 1
+    fi
+done
+
+currentver="$(gcc -dumpversion)"
+requiredver="4.9.0"
+if [ "$(printf '%s\n' "$requiredver" "$currentver" | sort -V | head -n1)" != "$requiredver" ]; then
+    echo "gcc greater than or equal to $requiredver is required!" >&2
+    exit 1
+fi
+
+# make a new folder containing everything
+mkdir $(pwd)/dumux
+cd dumux
+
+echo "*********************************************************************************************"
+echo "Sucessfully created a folder dumux."
+echo "*********************************************************************************************"
+
+echo "*********************************************************************************************"
+echo "(0/2) Downloading supplementary files. Make sure to be connected to the internet."
+echo "*********************************************************************************************"
+
+# download the install.opts and the test script
+wget https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/raw/master/scripts/test_dumux.sh
+chmod +x test_dumux.sh
+wget https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course/raw/master/cmake.opts
+
+# get the testing script
+
+echo "*********************************************************************************************"
+echo "(1/2) Cloning repositories. This may take a while. Make sure to be connected to the internet."
+echo "*********************************************************************************************"
+# the core modules
+for MOD in common geometry grid localfunctions istl; do
+    if [ ! -d "dune-$MOD" ]; then
+        git clone -b releases/$DUNE_VERSION https://gitlab.dune-project.org/core/dune-$MOD.git
+    else
+        echo "Skip cloning dune-$MOD because the folder already exists."
+        cd dune-$MOD
+        git checkout releases/$DUNE_VERSION
+        cd ..
+    fi
+done
+
+# extension modules
+for MOD in dune-foamgrid dune-alugrid; do
+    if [ ! -d "$MOD" ]; then
+        git clone -b releases/$DUNE_VERSION https://gitlab.dune-project.org/extensions/$MOD.git
+    else
+        echo "Skip cloning $MOD because the folder already exists."
+        cd $MOD
+        git checkout releases/$DUNE_VERSION
+        cd ..
+    fi
+done
+
+# dune-subgrid
+if [ ! -d "dune-subgrid" ]; then
+    git clone -b releases/$DUNE_VERSION https://git.imp.fu-berlin.de/agnumpde/dune-subgrid.git
+else
+    echo "Skip cloning dune-subgrid because the folder already exists."
+    cd dune-subgrid
+    git checkout releases/$DUNE_VERSION
+    cd ..
+fi
+
+# dumux
+if [ ! -d "dumux" ]; then
+    git clone -b master https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git
+else
+    echo "Skip cloning dumux because the folder already exists."
+    cd dumux
+    git checkout master
+    git reset --hard origin/master
+    cd ..
+fi
+
+# dumux-course
+if [ ! -d "dumux-course" ]; then
+    git clone https://git.iws.uni-stuttgart.de/dumux-repositories/dumux-course.git
+else
+    echo "Skip cloning dumux-course because the folder already exists."
+fi
+
+if [ $? -ne 0 ]; then
+    echo "*********************************************************************************************"
+    echo "Failed to clone the repositories."
+    echo "*********************************************************************************************"
+    exit $?
+fi
+
+echo "*********************************************************************************************"
+echo "(2/2) Configure dune modules and dumux. Build the dune libaries. This may take several minutes."
+echo "*********************************************************************************************"
+# run build
+./dune-common/bin/dunecontrol --opts=cmake.opts all
+#
+if [ $? -ne 0 ]; then
+    echo "*********************************************************************************************"
+    echo "Failed to build the dune libaries."
+    echo "*********************************************************************************************"
+    exit $?
+fi
+
+# echo result
+echo "*********************************************************************************************"
+echo "Succesfully configured and built dune and dumux."
+echo "Please change to the dumux folder and run the test_dumux.sh script to confirm everything works."
+echo "*********************************************************************************************"
diff --git a/scripts/test_dumux.sh b/scripts/test_dumux.sh
new file mode 100755
index 00000000..84c68bba
--- /dev/null
+++ b/scripts/test_dumux.sh
@@ -0,0 +1,7 @@
+# Compile and runs a simple
+# one-phase ground water flow example
+# and visualizes the result using paraview.
+cd dumux/build-cmake/test/porousmediumflow/1p/implicit
+make -B test_cc1p
+./test_cc1p test_cc1p.input
+paraview *pvd
-- 
GitLab