-
Notifications
You must be signed in to change notification settings - Fork 0
/
interface.py
160 lines (144 loc) · 7.99 KB
/
interface.py
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
from amuse.community import *
from amuse.community.interface.gd import GravitationalDynamics
from amuse.community.interface.gd import GravitationalDynamicsInterface
class EticsInterface(CodeInterface, GravitationalDynamicsInterface, LiteratureReferencesMixIn):
"""
.. [#] Meiron, Y., Li, B., Holley-Bockelmann, K., & Spurzem, R. 2014, ApJ, 792, 98:
.. [#] ... "Expansion techniques for collisionless stellar dynamical simulations"
"""
include_headers = ['worker_code.h']
def __init__(self, **keyword_arguments):
CodeInterface.__init__(self, name_of_the_worker='etics_worker', **keyword_arguments)
LiteratureReferencesMixIn.__init__(self)
@legacy_function
def new_particle():
function = LegacyFunctionSpecification()
function.can_handle_array = True
function.addParameter('index_of_the_particle', dtype='int32', direction=function.OUT)
function.addParameter('mass', dtype='float64', direction=function.IN,
description = 'The mass of the particle')
function.addParameter('x', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('y', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('z', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('vx', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.addParameter('vy', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.addParameter('vz', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.addParameter('radius', dtype='float64', direction=function.IN,
description = 'The radius of the particle', default = 0)
function.result_type = 'int32'
return function
@legacy_function
def set_state():
function = LegacyFunctionSpecification()
function.can_handle_array = True
function.addParameter('index_of_the_particle', dtype='int32', direction=function.IN)
function.addParameter('mass', dtype='float64', direction=function.IN,
description = 'The mass of the particle')
function.addParameter('radius', dtype='float64', direction=function.IN,
description = 'The radius of the particle')
function.addParameter('x', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('y', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('z', dtype='float64', direction=function.IN,
description = 'The initial position vector of the particle')
function.addParameter('vx', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.addParameter('vy', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.addParameter('vz', dtype='float64', direction=function.IN,
description = 'The initial velocity vector of the particle')
function.result_type = 'int32'
return function
@legacy_function
def get_state():
function = LegacyFunctionSpecification()
function.can_handle_array = True
function.addParameter('index_of_the_particle', dtype='int32', direction=function.IN)
function.addParameter('mass', dtype='float64', direction=function.OUT,
description = 'The mass of the particle')
function.addParameter('radius', dtype='float64', direction=function.OUT,
description = 'The radius of the particle')
function.addParameter('x', dtype='float64', direction=function.OUT,
description = 'The initial position vector of the particle')
function.addParameter('y', dtype='float64', direction=function.OUT,
description = 'The initial position vector of the particle')
function.addParameter('z', dtype='float64', direction=function.OUT,
description = 'The initial position vector of the particle')
function.addParameter('vx', dtype='float64', direction=function.OUT,
description = 'The initial velocity vector of the particle')
function.addParameter('vy', dtype='float64', direction=function.OUT,
description = 'The initial velocity vector of the particle')
function.addParameter('vz', dtype='float64', direction=function.OUT,
description = 'The initial velocity vector of the particle')
function.result_type = 'int32'
return function
@legacy_function
def evolve_model():
function = LegacyFunctionSpecification()
function.can_handle_array = True
function.addParameter('dt', dtype='float64', direction=function.IN)
function.result_type = 'int32'
return function
@legacy_function
def get_number_of_particles():
function = LegacyFunctionSpecification()
function.addParameter('number_of_particles', dtype='int32', direction=function.OUT, description = 'number of particles')
function.result_type = 'int32'
return function
@legacy_function
def set_time_step():
function = LegacyFunctionSpecification()
function.addParameter('time_step', dtype='float64', direction=function.IN, description = 'time step')
function.result_type = 'int32'
return function
@legacy_function
def update_force_potential_arrays():
function = LegacyFunctionSpecification()
function.can_handle_array = True
function.addParameter('dt', dtype='float64', direction=function.IN)
function.result_type = 'int32'
return function
class Etics(GravitationalDynamics):
def __init__(self, convert_nbody = None, **keyword_arguments):
legacy_interface = EticsInterface(**keyword_arguments)
GravitationalDynamics.__init__(self, legacy_interface, convert_nbody, **keyword_arguments)
def define_parameters(self, object):
object.add_method_parameter(
'get_begin_time',
'set_begin_time',
'begin_time',
'model time to start the simulation at',
default_value = 0.0 | nbody_system.time
)
object.add_method_parameter(
'get_time_step',
'set_time_step',
'time_step',
'constant timestep for iteration',
default_value = 0.001953125 | nbody_system.time
)
def define_methods(self, object):
GravitationalDynamics.define_methods(self, object)
# Define some shortcuts for better readability.
M = nbody_system.mass
L = nbody_system.length
V = nbody_system.speed
T = nbody_system.time
object.add_method('new_particle', (M,L,L,L,V,V,V,L), (object.INDEX, object.ERROR_CODE))
object.add_method('set_state', (object.INDEX, M,L,L,L,L,V,V,V), (object.ERROR_CODE))
object.add_method('get_state', (object.INDEX), (M,L,L,L,L,V,V,V, object.ERROR_CODE))
object.add_method('set_time_begin', (T), (object.ERROR_CODE))
object.add_method('get_time_begin', (), (T, object.ERROR_CODE))
object.add_method('get_number_of_particles', (), (units.none, object.ERROR_CODE))
object.add_method('get_time_step', (), (T, object.ERROR_CODE))
object.add_method('set_time_step', (T), (object.ERROR_CODE))
object.add_method('update_force_potential_arrays', (T), (object.ERROR_CODE))
def define_particle_sets(self, object):
GravitationalDynamics.define_particle_sets(self, object)