__main__.py 3.07 KB
Newer Older
Cristian Lalescu's avatar
Cristian Lalescu committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
#######################################################################
#                                                                     #
#  Copyright 2015 Max Planck Institute                                #
#                 for Dynamics and Self-Organization                  #
#                                                                     #
#  This file is part of bfps.                                         #
#                                                                     #
#  bfps is free software: you can redistribute it and/or modify       #
#  it under the terms of the GNU General Public License as published  #
#  by the Free Software Foundation, either version 3 of the License,  #
#  or (at your option) any later version.                             #
#                                                                     #
#  bfps is distributed in the hope that it will be useful,            #
#  but WITHOUT ANY WARRANTY; without even the implied warranty of     #
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      #
#  GNU General Public License for more details.                       #
#                                                                     #
#  You should have received a copy of the GNU General Public License  #
#  along with bfps.  If not, see <http://www.gnu.org/licenses/>       #
#                                                                     #
# Contact: Cristian.Lalescu@ds.mpg.de                                 #
#                                                                     #
#######################################################################



Cristian Lalescu's avatar
Cristian Lalescu committed
27
import sys
Cristian Lalescu's avatar
Cristian Lalescu committed
28
29
30
31
32
import argparse

import bfps
from .NavierStokes import NavierStokes
from .FluidResize import FluidResize
Cristian Lalescu's avatar
Cristian Lalescu committed
33
34

def main():
Cristian Lalescu's avatar
Cristian Lalescu committed
35
36
37
38
39
    parser = argparse.ArgumentParser(prog = 'bfps')
    parser.add_argument(
            '-v', '--version',
            action = 'version',
            version = '%(prog)s ' + bfps.__version__)
Cristian Lalescu's avatar
Cristian Lalescu committed
40
41
42
43
44
45
46
47
48
49
50
51
    NSoptions = ['NavierStokes',
                 'NavierStokes-single',
                 'NavierStokes-double',
                 'NS',
                 'NS-single',
                 'NS-double']
    FRoptions = ['FluidResize',
                 'FluidResize-single',
                 'FluidResize-double',
                 'FR',
                 'FR-single',
                 'FR-double']
Cristian Lalescu's avatar
Cristian Lalescu committed
52
53
    parser.add_argument(
            'base_class',
Cristian Lalescu's avatar
Cristian Lalescu committed
54
            choices = NSoptions + FRoptions,
Cristian Lalescu's avatar
Cristian Lalescu committed
55
            type = str)
56
    # first option is the choice of base class or -h or -v
57
    # all other options are passed on to the base_class instance
Cristian Lalescu's avatar
Cristian Lalescu committed
58
    opt = parser.parse_args(sys.argv[1:2])
59
    # error is thrown if first option is not a base class, so launch
60
    # cannot be executed by mistake.
Cristian Lalescu's avatar
Cristian Lalescu committed
61
    if 'double' in opt.base_class:
62
63
64
        precision = 'double'
    else:
        precision = 'single'
Cristian Lalescu's avatar
Cristian Lalescu committed
65
66
67
68
69
    if opt.base_class in NSoptions:
        base_class = NavierStokes
    elif opt.base_class in FRoptions:
        base_class = FluidResize
    c = base_class(fluid_precision = precision)
Cristian Lalescu's avatar
Cristian Lalescu committed
70
    c.launch(args = sys.argv[2:])
Cristian Lalescu's avatar
Cristian Lalescu committed
71
72
73
74
75
    return None

if __name__ == '__main__':
    main()