installdumux.py 6.19 KB
Newer Older
1 2 3 4 5 6
#!/usr/bin/env python3

"""
One click install script for dumux
"""
import os
7
import sys
8
import argparse
9 10
import subprocess
from distutils.spawn import find_executable
11
from distutils.version import LooseVersion
12

13 14 15 16
parser = argparse.ArgumentParser(prog='installdumux',
                                 usage='./installdumux.py [OPTIONS]',
                                 description='This script downloads and compiles the latest release of Dumux.')
# Optional arguments
17 18 19 20
parser.add_argument('--dune-version',
                    default="2.7",
                    help='Dune version to be checked out.')
parser.add_argument('--dumux-version',
21
                    default="3.4",
22
                    help='Dumux version to be checked out.')
23 24
args = vars(parser.parse_args())

25 26 27
dune_branch = args["dune_version"] if args["dune_version"] == "master" else "releases/" + args["dune_version"]
dumux_branch = args["dumux_version"] if args["dumux_version"] == "master" else "releases/" + args["dumux_version"]

28

29 30 31 32 33 34 35 36 37
def show_message(message):
    print("*" * 120)
    print(message)
    print("*" * 120)


def check_cpp_version():
    requiredversion = "7"
    result = subprocess.check_output(["g++", "-dumpversion"]).decode().strip()
38
    if LooseVersion(result) < LooseVersion(requiredversion):
39 40 41 42
        print("-- An error occured while checking for prerequistes.")
        raise Exception("g++ greater than or equal to {} is required for dumux releases >=3.2!".format(requiredversion))


43
def run_command(command, workdir="."):
44
    with open("../installdumux.log", "a") as log:
45
        popen = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True, cwd=workdir)
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
        for line in popen.stdout:
            log.write(line)
            print(line, end='')
        for line in popen.stderr:
            log.write(line)
            print(line, end='')
        popen.stdout.close()
        popen.stderr.close()
        return_code = popen.wait()
        if return_code:
            print("\n")
            message = "\n    (Error) The command {} returned with non-zero exit code\n".format(command)
            message += "\n    If you can't fix the problem yourself consider reporting your issue\n"
            message += "    on the mailing list (dumux@listserv.uni-stuttgart.de) and attach the file 'installdumux.log'\n"
            show_message(message)
            sys.exit(1)


64 65 66 67
def git_clone(url, branch=None):
    clone = ["git", "clone"]
    if branch:
        clone += ["-b", branch]
68
    run_command(command=[*clone, url])
69 70


71 72 73 74 75
def git_setbranch(folder, branch):
    checkout = ["git", "checkout", branch]
    run_command(command=checkout, workdir=folder)


76 77 78
# clear the log file
open('installdumux.log', 'w').close()

79 80
#################################################################
#################################################################
81
# (1/3) Check some prerequistes
82 83
#################################################################
#################################################################
84
programs = ['git', 'gcc', 'g++', 'cmake', 'pkg-config']
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
show_message("(1/3) Checking all prerequistes: " + " ".join(programs) + "...")

# check some prerequistes
for program in programs:
    if find_executable(program) is None:
        print("-- An error occured while checking for prerequistes.")
        raise Exception("Program {} has not been found.".format(program))

if find_executable('paraview') is None:
    print("-- Warning: paraview seems to be missing. You may not be able to view simulation results!")

check_cpp_version()

show_message("(1/3) Step completed. All prerequistes found.")

#################################################################
#################################################################
102
# (2/3) Clone modules
103 104 105
#################################################################
#################################################################
# make a new folder containing everything
Timo Koch's avatar
Timo Koch committed
106 107
os.makedirs("./dumux", exist_ok=True)
os.chdir("dumux")
108 109 110 111 112 113

show_message("(2/3) Cloning repositories. This may take a while. Make sure to be connected to the internet...")

# the core modules
for module in ['common', 'geometry', 'grid', 'localfunctions', 'istl']:
    if not os.path.exists("dune-{}".format(module)):
114
        git_clone('https://gitlab.dune-project.org/core/dune-{}.git'.format(module), dune_branch)
115 116
    else:
        print("-- Skip cloning dune-{} because the folder already exists.".format(module))
117
        git_setbranch("dune-{}".format(module), dune_branch)
118 119 120

# dumux
if not os.path.exists("dumux"):
121
    git_clone('https://git.iws.uni-stuttgart.de/dumux-repositories/dumux.git', dumux_branch)
122 123
else:
    print("-- Skip cloning dumux because the folder already exists.")
124
    git_setbranch("dumux", dumux_branch)
125 126 127 128 129 130


show_message("(2/3) Step completed. All repositories have been cloned into a containing folder.")

#################################################################
#################################################################
131
# (3/3) Configure and build
132 133 134 135 136
#################################################################
#################################################################
show_message("(3/3) Configure and build dune modules and dumux using dunecontrol. This may take several minutes...")

# run dunecontrol
137
run_command(command=["./dune-common/bin/dunecontrol", "--opts=dumux/cmake.opts", "all"])
138 139 140 141 142

show_message("(3/3) Step completed. Succesfully configured and built dune and dumux.")

#################################################################
#################################################################
143
# Show message how to check that everything works
144 145
#################################################################
#################################################################
146 147 148 149 150 151
test_path = 'dumux/dumux/build-cmake/test/porousmediumflow/1p'
if dumux_branch == "master" or LooseVersion(args["dumux_version"]) > LooseVersion('3.3'):
    test_path += '/isothermal'
else:
    test_path += '/implicit/isothermal'

152
show_message("(Installation complete) To test if everything works, please run the following commands (can be copied to command line):\n\n"
153
             "  cd {}\n"
154 155
             "  make test_1p_tpfa\n"
             "  ./test_1p_tpfa\n"
156
             "  paraview *pvd\n".format(test_path))