PyParticles3 0.4.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- pyparticles/__init__.py +26 -0
- pyparticles/__main__.py +7 -0
- pyparticles/animation/__init__.py +21 -0
- pyparticles/animation/animated_cli.py +53 -0
- pyparticles/animation/animated_ogl.py +691 -0
- pyparticles/animation/animated_ogl_compat.py +243 -0
- pyparticles/animation/animated_scatter.py +94 -0
- pyparticles/animation/animation.py +251 -0
- pyparticles/animation/test_animation.py +310 -0
- pyparticles/demo/__init__.py +33 -0
- pyparticles/demo/bubble.py +106 -0
- pyparticles/demo/electromagnetic_demo.py +128 -0
- pyparticles/demo/electrostatic_demo.py +126 -0
- pyparticles/demo/fountain.py +478 -0
- pyparticles/demo/gas_lennard_jones.py +87 -0
- pyparticles/demo/gravity_clusters.py +73 -0
- pyparticles/demo/solar_system.py +222 -0
- pyparticles/demo/springs.py +141 -0
- pyparticles/demo/springs_constr.py +135 -0
- pyparticles/demo/test.py +34 -0
- pyparticles/forces/__init__.py +21 -0
- pyparticles/forces/const_force.py +140 -0
- pyparticles/forces/damping.py +174 -0
- pyparticles/forces/drag.py +167 -0
- pyparticles/forces/electromagnetic.py +105 -0
- pyparticles/forces/electromagnetic_field.py +95 -0
- pyparticles/forces/electrostatic.py +72 -0
- pyparticles/forces/force.py +75 -0
- pyparticles/forces/force_constrained.py +32 -0
- pyparticles/forces/fused_const_drag.py +445 -0
- pyparticles/forces/gravity.py +345 -0
- pyparticles/forces/lennard_jones.py +74 -0
- pyparticles/forces/linear_spring.py +86 -0
- pyparticles/forces/linear_spring_constrained.py +72 -0
- pyparticles/forces/multiple_force.py +134 -0
- pyparticles/forces/pseudo_bubble.py +226 -0
- pyparticles/forces/van_der_waals_force.py +60 -0
- pyparticles/forces/vector_field_force.py +52 -0
- pyparticles/geometry/__init__.py +21 -0
- pyparticles/geometry/dist.py +24 -0
- pyparticles/geometry/intersection.py +62 -0
- pyparticles/geometry/transformations.py +387 -0
- pyparticles/main/__init__.py +21 -0
- pyparticles/main/main.py +466 -0
- pyparticles/measures/__init__.py +21 -0
- pyparticles/measures/elastic_potential_energy.py +67 -0
- pyparticles/measures/gravitational_potential_energy.py +69 -0
- pyparticles/measures/kinetic_energy.py +68 -0
- pyparticles/measures/mass.py +59 -0
- pyparticles/measures/measure.py +156 -0
- pyparticles/measures/momentum.py +144 -0
- pyparticles/measures/total_energy.py +68 -0
- pyparticles/ode/__init__.py +21 -0
- pyparticles/ode/euler_solver.py +214 -0
- pyparticles/ode/euler_solver_constrained.py +49 -0
- pyparticles/ode/leapfrog_solver.py +37 -0
- pyparticles/ode/leapfrog_solver_constrained.py +53 -0
- pyparticles/ode/midpoint_solver.py +43 -0
- pyparticles/ode/midpoint_solver_constrained.py +60 -0
- pyparticles/ode/ode_solver.py +134 -0
- pyparticles/ode/ode_solver_constrained.py +43 -0
- pyparticles/ode/runge_kutta_solver.py +79 -0
- pyparticles/ode/runge_kutta_solver_constrained.py +98 -0
- pyparticles/ode/sim_time.py +56 -0
- pyparticles/ode/stormer_verlet_solver.py +50 -0
- pyparticles/ode/stormer_verlet_solver_constrained.py +73 -0
- pyparticles/ogl/__init__.py +21 -0
- pyparticles/ogl/axis_ogl.py +210 -0
- pyparticles/ogl/draw_particles_ogl.py +313 -0
- pyparticles/ogl/draw_particles_ogl_compat.py +509 -0
- pyparticles/ogl/draw_vector_field.py +221 -0
- pyparticles/ogl/opencl_gl_vbo.py +485 -0
- pyparticles/ogl/trackball.py +131 -0
- pyparticles/ogl/translate_scene.py +87 -0
- pyparticles/pset/__init__.py +21 -0
- pyparticles/pset/boundary.py +69 -0
- pyparticles/pset/cluster.py +28 -0
- pyparticles/pset/constrained_force_interactions.py +63 -0
- pyparticles/pset/constrained_x.py +158 -0
- pyparticles/pset/constraint.py +42 -0
- pyparticles/pset/default_boundary.py +43 -0
- pyparticles/pset/file_cluster.py +131 -0
- pyparticles/pset/logger.py +152 -0
- pyparticles/pset/octree.py +451 -0
- pyparticles/pset/opencl_context.py +374 -0
- pyparticles/pset/particles_set.py +499 -0
- pyparticles/pset/periodic_boundary.py +36 -0
- pyparticles/pset/rand_cluster.py +188 -0
- pyparticles/pset/rebound_boundary.py +68 -0
- pyparticles/utils/__init__.py +21 -0
- pyparticles/utils/parse_args.py +72 -0
- pyparticles/utils/problem_config.py +608 -0
- pyparticles/utils/pypart_global.py +122 -0
- pyparticles/utils/time_formatter.py +50 -0
- pyparticles3-0.4.0.dist-info/METADATA +395 -0
- pyparticles3-0.4.0.dist-info/RECORD +100 -0
- pyparticles3-0.4.0.dist-info/WHEEL +5 -0
- pyparticles3-0.4.0.dist-info/entry_points.txt +3 -0
- pyparticles3-0.4.0.dist-info/licenses/LICENSE-gpl-3.0.txt +674 -0
- pyparticles3-0.4.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
# PyParticles : Particles simulation in python
|
|
2
|
+
#Copyright (C) 2012 Simone Riva
|
|
3
|
+
#
|
|
4
|
+
#This program is free software: you can redistribute it and/or modify
|
|
5
|
+
#it under the terms of the GNU General Public License as published by
|
|
6
|
+
#the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
#(at your option) any later version.
|
|
8
|
+
#
|
|
9
|
+
#This program is distributed in the hope that it will be useful,
|
|
10
|
+
#but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
11
|
+
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the :
|
|
12
|
+
#GNU General Public License for more details.
|
|
13
|
+
#
|
|
14
|
+
#You should have received a copy of the GNU General Public License
|
|
15
|
+
#along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
16
|
+
|
|
17
|
+
import numpy as np
|
|
18
|
+
import csv
|
|
19
|
+
import re
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
class FileCluster(object):
|
|
23
|
+
"""
|
|
24
|
+
Read the data from a csv formatted file:
|
|
25
|
+
|
|
26
|
+
The first row of the csv contains the size and the dim of the particles set.
|
|
27
|
+
|
|
28
|
+
The other rows are the data of the perticles in the order:
|
|
29
|
+
"""
|
|
30
|
+
|
|
31
|
+
def __init__(self):
|
|
32
|
+
pass
|
|
33
|
+
|
|
34
|
+
def open( self , cfile , mode="r" ):
|
|
35
|
+
"""
|
|
36
|
+
Open the csv file named cfile.
|
|
37
|
+
|
|
38
|
+
:param cfile: The file name
|
|
39
|
+
:param mode: file mode (default reading)
|
|
40
|
+
"""
|
|
41
|
+
|
|
42
|
+
self.__cfile = cfile
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
def close(self):
|
|
46
|
+
"""
|
|
47
|
+
Close the file
|
|
48
|
+
"""
|
|
49
|
+
pass
|
|
50
|
+
#self.__f.close()
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def insert3( self , pset ):
|
|
54
|
+
"""
|
|
55
|
+
Insert the particles described in the file in the ParticlesSet pset
|
|
56
|
+
|
|
57
|
+
:param pset: A reference to the particles set
|
|
58
|
+
"""
|
|
59
|
+
ff = open( self.__cfile , 'rb')
|
|
60
|
+
csv_w = csv.reader( ff , delimiter=' ')
|
|
61
|
+
|
|
62
|
+
i = -1
|
|
63
|
+
|
|
64
|
+
dim = 0
|
|
65
|
+
size = 0
|
|
66
|
+
print( self.__cfile )
|
|
67
|
+
#print( csv_w )
|
|
68
|
+
|
|
69
|
+
label = False
|
|
70
|
+
|
|
71
|
+
for row in csv_w :
|
|
72
|
+
#print( row )
|
|
73
|
+
if i == -1 :
|
|
74
|
+
size = int(row[0])
|
|
75
|
+
dim = int(row[1])
|
|
76
|
+
try:
|
|
77
|
+
il = row.index( "label" )
|
|
78
|
+
label = True
|
|
79
|
+
except:
|
|
80
|
+
label = False
|
|
81
|
+
|
|
82
|
+
pset.realloc( size , dim , label=il)
|
|
83
|
+
|
|
84
|
+
else :
|
|
85
|
+
for j in range( dim ) :
|
|
86
|
+
pset.X[i,j] = float(row[j])
|
|
87
|
+
pset.V[i,j] = float(row[j+dim])
|
|
88
|
+
|
|
89
|
+
pset.M[i] = float( row[dim*2] )
|
|
90
|
+
|
|
91
|
+
if label :
|
|
92
|
+
pset.label[i] = row[dim*2+1]
|
|
93
|
+
|
|
94
|
+
i+=1
|
|
95
|
+
|
|
96
|
+
#print( pset.label )
|
|
97
|
+
ff.close()
|
|
98
|
+
#exit()
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def write_out( self , pset ):
|
|
103
|
+
"""
|
|
104
|
+
Write out in the csv file the particles described in pset.
|
|
105
|
+
|
|
106
|
+
:param pset: A reference to the particles set
|
|
107
|
+
"""
|
|
108
|
+
ff = open( self.__cfile , 'wb')
|
|
109
|
+
csv_w = csv.writer( ff , delimiter=' ')
|
|
110
|
+
|
|
111
|
+
head = [ str(pset.size) , str(pset.dim) ]
|
|
112
|
+
|
|
113
|
+
try:
|
|
114
|
+
foo = pset.Q
|
|
115
|
+
head.append("Charge")
|
|
116
|
+
except:
|
|
117
|
+
pass
|
|
118
|
+
|
|
119
|
+
if pset.label != None :
|
|
120
|
+
head.append( "Label" )
|
|
121
|
+
|
|
122
|
+
csv_w.writerow( head )
|
|
123
|
+
|
|
124
|
+
for i in range( pset.size ):
|
|
125
|
+
lst = pset.get_list( i , to=float )
|
|
126
|
+
csv_w.writerow( lst )
|
|
127
|
+
|
|
128
|
+
ff.close()
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
|
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# PyParticles : Particles simulation in python
|
|
2
|
+
# Copyright (C) 2012 Simone Riva
|
|
3
|
+
#
|
|
4
|
+
# This program is free software: you can redistribute it and/or modify
|
|
5
|
+
# it under the terms of the GNU General Public License as published by
|
|
6
|
+
# the Free Software Foundation, either version 3 of the License, or
|
|
7
|
+
# (at your option) any later version.
|
|
8
|
+
|
|
9
|
+
import numpy as np
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
class Logger(object):
|
|
13
|
+
"""Circular in-memory logger for particle positions and velocities."""
|
|
14
|
+
|
|
15
|
+
def __init__(self, pset, log_max_size, log_X=True, log_V=False, sim_time=None):
|
|
16
|
+
self.__pset = pset
|
|
17
|
+
self.__log_max_size = int(log_max_size)
|
|
18
|
+
self.__size = 0
|
|
19
|
+
self.__log_cnt = 0
|
|
20
|
+
self.__La = 0
|
|
21
|
+
self.__Lb = -1
|
|
22
|
+
self.__state = 0
|
|
23
|
+
|
|
24
|
+
if sim_time is not None:
|
|
25
|
+
self.__sim_time = sim_time
|
|
26
|
+
self.__log_time = np.zeros(self.__log_max_size)
|
|
27
|
+
else:
|
|
28
|
+
self.__sim_time = None
|
|
29
|
+
self.__log_time = None
|
|
30
|
+
|
|
31
|
+
self.__log_X = (
|
|
32
|
+
np.zeros((self.__log_max_size, pset.size, pset.dim)) if log_X else None
|
|
33
|
+
)
|
|
34
|
+
self.__log_V = (
|
|
35
|
+
np.zeros((self.__log_max_size, pset.size, pset.dim)) if log_V else None
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
def log(self):
|
|
39
|
+
self.__log_cnt += 1
|
|
40
|
+
|
|
41
|
+
if self.__state == 0:
|
|
42
|
+
self.__size += 1
|
|
43
|
+
self.__Lb += 1
|
|
44
|
+
|
|
45
|
+
if self.__state in (1, 2):
|
|
46
|
+
self.__La += 1
|
|
47
|
+
self.__Lb += 1
|
|
48
|
+
if self.__La >= self.__log_max_size:
|
|
49
|
+
self.__La = 0
|
|
50
|
+
if self.__Lb >= self.__log_max_size:
|
|
51
|
+
self.__Lb = 0
|
|
52
|
+
|
|
53
|
+
if self.__state != 0 and self.__La > self.__Lb:
|
|
54
|
+
self.__state = 1
|
|
55
|
+
if self.__state != 0 and self.__La < self.__Lb:
|
|
56
|
+
self.__state = 2
|
|
57
|
+
|
|
58
|
+
if self.__state == 0 and self.__Lb >= self.__log_max_size:
|
|
59
|
+
self.__size = self.__log_max_size
|
|
60
|
+
self.__Lb = 0
|
|
61
|
+
self.__La = 1
|
|
62
|
+
self.__state = 1
|
|
63
|
+
|
|
64
|
+
if self.__sim_time is not None:
|
|
65
|
+
self.__log_time[self.__Lb] = self.__sim_time.time
|
|
66
|
+
if self.__log_X is not None:
|
|
67
|
+
self.__log_X[self.__Lb, :, :] = self.__pset.X
|
|
68
|
+
if self.__log_V is not None:
|
|
69
|
+
self.__log_V[self.__Lb, :, :] = self.__pset.V
|
|
70
|
+
|
|
71
|
+
def close_log(self):
|
|
72
|
+
pass
|
|
73
|
+
|
|
74
|
+
def __get_log_indices(self):
|
|
75
|
+
if self.__size == 0:
|
|
76
|
+
return np.empty(0, dtype=np.int32)
|
|
77
|
+
|
|
78
|
+
if self.__state == 0:
|
|
79
|
+
return np.arange(self.__La, self.__Lb + 1, dtype=np.int32)
|
|
80
|
+
if self.__state == 1:
|
|
81
|
+
return np.concatenate(
|
|
82
|
+
(
|
|
83
|
+
np.arange(self.__La, self.log_max_size, dtype=np.int32),
|
|
84
|
+
np.arange(0, self.__Lb + 1, dtype=np.int32),
|
|
85
|
+
)
|
|
86
|
+
)
|
|
87
|
+
return np.concatenate(
|
|
88
|
+
(
|
|
89
|
+
np.arange(self.__La, self.__Lb, dtype=np.int32),
|
|
90
|
+
np.arange(self.__Lb, self.__log_max_size, dtype=np.int32),
|
|
91
|
+
)
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
def get_log_array(self, i, log_X=True, log_V=False, log_time=False):
|
|
95
|
+
ind = self.__get_log_indices()
|
|
96
|
+
result = []
|
|
97
|
+
if log_X:
|
|
98
|
+
result.append(self.__log_X[ind, i, :])
|
|
99
|
+
if log_V:
|
|
100
|
+
result.append(self.__log_V[ind, i, :])
|
|
101
|
+
if log_time:
|
|
102
|
+
result.append(self.__log_time[ind])
|
|
103
|
+
return tuple(result)
|
|
104
|
+
|
|
105
|
+
def read_log_array(self, i, ta, log_X=True, log_V=False, log_time=False):
|
|
106
|
+
ind = self.__get_log_indices()
|
|
107
|
+
li = len(ind)
|
|
108
|
+
|
|
109
|
+
if log_X:
|
|
110
|
+
ta[0][0:li, :] = self.__log_X[ind, i, :]
|
|
111
|
+
if log_V:
|
|
112
|
+
ta[1][0:li, :] = self.__log_V[ind, i, :]
|
|
113
|
+
if log_time:
|
|
114
|
+
ta[2][0:li] = self.__log_time[ind]
|
|
115
|
+
|
|
116
|
+
return (0, max(0, 2 * li - 2))
|
|
117
|
+
|
|
118
|
+
def get_log_indices_segments(self, full=False):
|
|
119
|
+
d = self.__log_max_size if full else self.__size
|
|
120
|
+
if d < 2:
|
|
121
|
+
return np.empty(0, dtype=np.uint32)
|
|
122
|
+
|
|
123
|
+
i = np.arange(d, dtype=np.uint32)
|
|
124
|
+
f = np.zeros(2 * d - 2, dtype=np.uint32)
|
|
125
|
+
f[2:(2 * d - 2):2] = i[1:(d - 1)]
|
|
126
|
+
f[1:(2 * d - 2):2] = i[1:]
|
|
127
|
+
return f
|
|
128
|
+
|
|
129
|
+
def resize(self, log_max_size):
|
|
130
|
+
raise NotImplementedError("Logger.resize is not implemented")
|
|
131
|
+
|
|
132
|
+
def jump(self):
|
|
133
|
+
pass
|
|
134
|
+
|
|
135
|
+
def get_log_max_size(self):
|
|
136
|
+
return self.__log_max_size
|
|
137
|
+
|
|
138
|
+
log_max_size = property(get_log_max_size, doc="get the max allowed size of the log")
|
|
139
|
+
|
|
140
|
+
def get_log_size(self):
|
|
141
|
+
return self.__size
|
|
142
|
+
|
|
143
|
+
log_size = property(get_log_size)
|
|
144
|
+
|
|
145
|
+
def get_log_X_enabled(self):
|
|
146
|
+
return self.__log_X is not None
|
|
147
|
+
|
|
148
|
+
def get_log_V_enabled(self):
|
|
149
|
+
return self.__log_V is not None
|
|
150
|
+
|
|
151
|
+
log_V_enabled = property(get_log_V_enabled)
|
|
152
|
+
log_X_enabled = property(get_log_X_enabled)
|