BubbleProfiler  0.3.0
by Peter Athron, Csaba Balazs, Michael Bardsley, Andrew Fowlie, Dylan Harries & Graham White
pyshooting.py
Go to the documentation of this file.
1 """
2 Solve one-dimensional bounce problem with shooting method
3 ==========================================================
4 
5 export LD_PRELOAD=/usr/lib/libginac.so.2.1.0:/usr/lib/x86_64-linux-gnu/libboost_log.so.1.61.0:/usr/lib/x86_64-linux-gnu/libnlopt.so.0.8.1:/usr/lib/x86_64-linux-gnu/libalglib.so.3.8.0
6 
7 """
8 
9 import ctypes
10 import os
11 
12 
13 PATH = os.path.dirname(os.path.abspath(__file__))
14 LIB_NAME = '{}/../lib/libbubbler.so'.format(PATH)
15 
16 lib = ctypes.CDLL(LIB_NAME)
17 c_action = lib.action
18 c_action.argtypes = [ctypes.c_double, ctypes.c_double, ctypes.c_int, ctypes.Structure]
19 c_action.restype = ctypes.c_double
20 
21 
22 class Settings(ctypes.Structure):
23  """
24  Struct for Shooting::default.
25  """
26  _fields_ = [('shoot_bisect_bits', ctypes.c_int),
27  ('action_arrived_rel', ctypes.c_double),
28  ('shoot_ode_abs', ctypes.c_double),
29  ('shoot_ode_rel', ctypes.c_double),
30  ('action_ode_abs', ctypes.c_double),
31  ('action_ode_rel', ctypes.c_double),
32  ('drho_frac', ctypes.c_double),
33  ('evolve_change_rel', ctypes.c_double),
34  ('evolve_rho_min', ctypes.c_double),
35  ('bisect_lambda_max', ctypes.c_double),
36  ('iter_max', ctypes.c_int),
37  ('periods_max', ctypes.c_double),
38  ('f_y_max', ctypes.c_double),
39  ('f_y_min', ctypes.c_double)]
40 
41 # Make struct of default arguments
42 
43 default = Settings()
44 default.shoot_bisect_bits = 5
45 default.action_arrived_rel = 1.e-3
46 default.shoot_ode_abs = 1.e-4
47 default.shoot_ode_rel = 1.e-4
48 default.action_ode_abs = 1.e-6
49 default.action_ode_rel = 1.e-6
50 default.drho_frac = 1.e-3
51 default.evolve_change_rel = 1.e-2
52 default.evolve_rho_min = 1.e-3
53 default.bisect_lambda_max = 5
54 default.iter_max = 100000
55 default.periods_max = 1.e2
56 default.f_y_max = 1.e6
57 default.f_y_min = 1.e-3
58 
59 
60 def make_struct(settings):
61  """
62  Populate struct for Shooting::default from a dictionary.
63  """
64  struct = default
65 
66  for k, v in settings.iteritems():
67  struct.__setattr__(k, v)
68 
69  return struct
70 
71 def action(E, alpha, dim=3, **kwargs):
72  """
73  Wrapper for C function that calculates action.
74  """
75  return c_action(E, alpha, dim, make_struct(kwargs))
76 
77 
78 if __name__ == "__main__":
79 
80  E = 1.
81  alpha = 0.65
82  print "alpha = {}".format(alpha)
83  print "E = {}".format(E)
84  print "action = {}".format(action(E, alpha))
def make_struct(settings)
Definition: pyshooting.py:60
def action(E, alpha, dim=3, kwargs)
Definition: pyshooting.py:71