uns_inert.py 2.89 KB
Newer Older
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
1
2
3
4
5
6
7
8
#!/usr/bin/env python
from __future__ import print_function

import numpy as np
import os,time
import sys
import argparse,textwrap

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
9
#sys.path=['/home/jcl/works/GIT/uns_projects/py/modules/','/home/jcl/works/GIT/uns_projects/py/modules/simulations']+sys.path
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
10

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
11
import unsiotools.simulations.cinert as cinert
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
12
#import simulations.csnapshot as csnap
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
13
#from unsiotools.simulations.csnapshot import *
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
14
15
16
17

#from IPython import embed

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
18
# commandLine, parse the command line
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
19
20
21
def commandLine():

    # help
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
22
    parser = argparse.ArgumentParser(description="Compute Moment of Inertia on UNS simulation",
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
23
24
25
26
                                     formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('snapshot', help="uns input snapshot",default=None)
    parser.add_argument('component', help="selected component",default=None)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
27
28
    parser.add_argument('--outfile', help="output file name",default=None)
    parser.add_argument('--ncut', help="#cuts ",default=20,type=int)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
29
30
    parser.add_argument('--fmin', help="fract min ",default=0.1,type=float)
    parser.add_argument('--fmax', help="fract max ",default=0.9,type=float)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
31
32
    parser.add_argument('--tree_threshold', help=">0 #particles, <0 percentage of particles ",default=-10.,type=float)
    parser.add_argument('--notree_density',help='don''t use tree density',dest="notree", action="store_true", default=False)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
33
34
    parser.add_argument('--cod', help="use COD file to re-center, or @sim (ex; @mdf648) to get file automatically from simulation ",default=None)
    parser.add_argument('--nocom', help='dont use com if no COD file requested',dest="nocom", action="store_true", default=False)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
35
    parser.add_argument('--nonemo', help='dont use Nemo algorithms (based on snapinert)',dest="nonemo", action="store_true", default=False)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
36
    parser.add_argument('--verbose',help='verbose mode',dest="verbose", action="store_true", default=False)
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
37

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
38
39
    # parse
    args = parser.parse_args()
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
40
    # start main function
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
41
42
43
44
45
    process(args)

# -----------------------------------------------------
# process, is the core function
def process(args):
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
46

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
47
    try:
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
48
49
50
51
52
53
54
55
56
        # instantiate CInert object
        inert=cinert.CInert(snapshot=args.snapshot,outfile=args.outfile,ncut=args.ncut,
                            component=args.component,center_file=args.cod,
                            fract_min=args.fmin,fract_max=args.fmax,com=not args.nocom,
                            verbose_debug=args.verbose,
                            tree_density=not args.notree,tree_threshold=args.tree_threshold,nonemo=args.nonemo)
        # start full process
        inert.fullProcess(args.snapshot,args.component)

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
57
58
59
60
    except Exception as x :
        print (x.message,file=sys.stderr)
    except KeyboardInterrupt:
        sys.exit()
LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
61

LAMBERT Jean-charles's avatar
LAMBERT Jean-charles committed
62
63
64
65
66

# -----------------------------------------------------
# main program
if __name__ == '__main__':
  commandLine()