Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2Mango.
4A program to simulate magnetic nanoparticles in a non magnetic fluid.
5Developed by James Cook 2015-2019 with supervison by Lorenzo Stella.
6"""
8# External Dependencies
9from sys import exit
11# Internal Dependencies
12from mango.debug import debug, profile
13from mango.constants import c
15from mango.arguments import parse, filenaming, verbosity
16from mango.managers import serverwrapper
17from mango.errors import _strings
18from mango.pp.main import readin
19from mango.magnetic_motion import integrate
21from mango.time import start, end
24def _main_run(argparse=True, opts={}):
25 """Error Catching."""
26 try:
27 if opts not in ["-h", '-ifh']:
28 assert type(opts) == dict
29 except AssertionError:
30 print("{}Arguments must be a dictionary".format(_strings._F))
32 try:
33 profile(main, argparse, opts, file="mprofiler.prof") if c.profile else main(argparse, opts)
34 except KeyboardInterrupt:
35 exit("{}Exiting".format(_strings._B[0]))
36 except EOFError:
37 exit(1)
40@debug(['main'])
41@serverwrapper("Error")
42def main(argparse, opts):
43 """
44 Main.
46 the input is parsed
47 variables are stored
48 calculations are started
49 Any plotting is completed as required
51 """
52 # Setup
53 var, flg = setup(argparse, opts)
55 # Calculation
56 if not flg.pp: 56 ↛ 59line 56 didn't jump to line 59, because the condition on line 56 was never false
57 timer, var.name = integrate(var, flg)
58 else:
59 timer = end(var.finishtime)
60 # TODO find why file not closed so postprocessing can possibly run after calculation if desired
61 readin(fname=var.name, run=flg.run, directory=var.directory, block=var.block, flg=flg)
63 print(timer.finished())
66def setup(argparse, opts):
68 var, flg = parse(argparse, opts)
69 var.finishtime = start(var.walltime)
70 filenaming(var, flg)
71 verbosity(var, flg)
72 return var, flg
75if __name__ == "__main__":
76 _main_run(argparse=True)