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.
Files changed (100) hide show
  1. pyparticles/__init__.py +26 -0
  2. pyparticles/__main__.py +7 -0
  3. pyparticles/animation/__init__.py +21 -0
  4. pyparticles/animation/animated_cli.py +53 -0
  5. pyparticles/animation/animated_ogl.py +691 -0
  6. pyparticles/animation/animated_ogl_compat.py +243 -0
  7. pyparticles/animation/animated_scatter.py +94 -0
  8. pyparticles/animation/animation.py +251 -0
  9. pyparticles/animation/test_animation.py +310 -0
  10. pyparticles/demo/__init__.py +33 -0
  11. pyparticles/demo/bubble.py +106 -0
  12. pyparticles/demo/electromagnetic_demo.py +128 -0
  13. pyparticles/demo/electrostatic_demo.py +126 -0
  14. pyparticles/demo/fountain.py +478 -0
  15. pyparticles/demo/gas_lennard_jones.py +87 -0
  16. pyparticles/demo/gravity_clusters.py +73 -0
  17. pyparticles/demo/solar_system.py +222 -0
  18. pyparticles/demo/springs.py +141 -0
  19. pyparticles/demo/springs_constr.py +135 -0
  20. pyparticles/demo/test.py +34 -0
  21. pyparticles/forces/__init__.py +21 -0
  22. pyparticles/forces/const_force.py +140 -0
  23. pyparticles/forces/damping.py +174 -0
  24. pyparticles/forces/drag.py +167 -0
  25. pyparticles/forces/electromagnetic.py +105 -0
  26. pyparticles/forces/electromagnetic_field.py +95 -0
  27. pyparticles/forces/electrostatic.py +72 -0
  28. pyparticles/forces/force.py +75 -0
  29. pyparticles/forces/force_constrained.py +32 -0
  30. pyparticles/forces/fused_const_drag.py +445 -0
  31. pyparticles/forces/gravity.py +345 -0
  32. pyparticles/forces/lennard_jones.py +74 -0
  33. pyparticles/forces/linear_spring.py +86 -0
  34. pyparticles/forces/linear_spring_constrained.py +72 -0
  35. pyparticles/forces/multiple_force.py +134 -0
  36. pyparticles/forces/pseudo_bubble.py +226 -0
  37. pyparticles/forces/van_der_waals_force.py +60 -0
  38. pyparticles/forces/vector_field_force.py +52 -0
  39. pyparticles/geometry/__init__.py +21 -0
  40. pyparticles/geometry/dist.py +24 -0
  41. pyparticles/geometry/intersection.py +62 -0
  42. pyparticles/geometry/transformations.py +387 -0
  43. pyparticles/main/__init__.py +21 -0
  44. pyparticles/main/main.py +466 -0
  45. pyparticles/measures/__init__.py +21 -0
  46. pyparticles/measures/elastic_potential_energy.py +67 -0
  47. pyparticles/measures/gravitational_potential_energy.py +69 -0
  48. pyparticles/measures/kinetic_energy.py +68 -0
  49. pyparticles/measures/mass.py +59 -0
  50. pyparticles/measures/measure.py +156 -0
  51. pyparticles/measures/momentum.py +144 -0
  52. pyparticles/measures/total_energy.py +68 -0
  53. pyparticles/ode/__init__.py +21 -0
  54. pyparticles/ode/euler_solver.py +214 -0
  55. pyparticles/ode/euler_solver_constrained.py +49 -0
  56. pyparticles/ode/leapfrog_solver.py +37 -0
  57. pyparticles/ode/leapfrog_solver_constrained.py +53 -0
  58. pyparticles/ode/midpoint_solver.py +43 -0
  59. pyparticles/ode/midpoint_solver_constrained.py +60 -0
  60. pyparticles/ode/ode_solver.py +134 -0
  61. pyparticles/ode/ode_solver_constrained.py +43 -0
  62. pyparticles/ode/runge_kutta_solver.py +79 -0
  63. pyparticles/ode/runge_kutta_solver_constrained.py +98 -0
  64. pyparticles/ode/sim_time.py +56 -0
  65. pyparticles/ode/stormer_verlet_solver.py +50 -0
  66. pyparticles/ode/stormer_verlet_solver_constrained.py +73 -0
  67. pyparticles/ogl/__init__.py +21 -0
  68. pyparticles/ogl/axis_ogl.py +210 -0
  69. pyparticles/ogl/draw_particles_ogl.py +313 -0
  70. pyparticles/ogl/draw_particles_ogl_compat.py +509 -0
  71. pyparticles/ogl/draw_vector_field.py +221 -0
  72. pyparticles/ogl/opencl_gl_vbo.py +485 -0
  73. pyparticles/ogl/trackball.py +131 -0
  74. pyparticles/ogl/translate_scene.py +87 -0
  75. pyparticles/pset/__init__.py +21 -0
  76. pyparticles/pset/boundary.py +69 -0
  77. pyparticles/pset/cluster.py +28 -0
  78. pyparticles/pset/constrained_force_interactions.py +63 -0
  79. pyparticles/pset/constrained_x.py +158 -0
  80. pyparticles/pset/constraint.py +42 -0
  81. pyparticles/pset/default_boundary.py +43 -0
  82. pyparticles/pset/file_cluster.py +131 -0
  83. pyparticles/pset/logger.py +152 -0
  84. pyparticles/pset/octree.py +451 -0
  85. pyparticles/pset/opencl_context.py +374 -0
  86. pyparticles/pset/particles_set.py +499 -0
  87. pyparticles/pset/periodic_boundary.py +36 -0
  88. pyparticles/pset/rand_cluster.py +188 -0
  89. pyparticles/pset/rebound_boundary.py +68 -0
  90. pyparticles/utils/__init__.py +21 -0
  91. pyparticles/utils/parse_args.py +72 -0
  92. pyparticles/utils/problem_config.py +608 -0
  93. pyparticles/utils/pypart_global.py +122 -0
  94. pyparticles/utils/time_formatter.py +50 -0
  95. pyparticles3-0.4.0.dist-info/METADATA +395 -0
  96. pyparticles3-0.4.0.dist-info/RECORD +100 -0
  97. pyparticles3-0.4.0.dist-info/WHEEL +5 -0
  98. pyparticles3-0.4.0.dist-info/entry_points.txt +3 -0
  99. pyparticles3-0.4.0.dist-info/licenses/LICENSE-gpl-3.0.txt +674 -0
  100. pyparticles3-0.4.0.dist-info/top_level.txt +1 -0
@@ -0,0 +1,387 @@
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
+ from collections import deque
19
+
20
+ import sys
21
+
22
+ class Transformations( object ):
23
+ """
24
+ Class used for administrate 3D transformations matrix using an OpenGl like method with a push_matrix & pop_matrix model. This method is very confortable if we want to create articulated geometric structures with a lot of subobjects and relative coordinates.
25
+
26
+ Example: ::
27
+
28
+ t = tr.Transformations() # init transfomation
29
+
30
+ t.set_points_tuple_size(2) # Pairwise points in the queue
31
+
32
+ t.rotY( np.radians(90) ) # Apply some transoformations matricies
33
+ t.rotX( np.radians(90) )
34
+ t.rotZ( np.radians(90) )
35
+ # Now the current matrix is: Ry(90) * Rx(90) * Rz(90)
36
+
37
+ t.append_point( list( [1,0,0] ) ) # Append some poits. It accept every Indexable type
38
+ t.append_point( np.array( [1,1,0] ) ) # The preview transoformations are applied on these points
39
+ t.append_point( np.array( [1,1,1] ) )
40
+ t.append_point( np.array( [0,1,1] ) )
41
+
42
+ t.push_matrix() # push the current matrix
43
+
44
+ t.translation( 10 , 2 , 2 ) # Apply a translation
45
+ # Now the current matrix is: Ry(90) * Rx(90) * Rz(90) * Tr( [ 10 , 2 , 2 ] )
46
+
47
+ t.append_point( [1,1,1] )
48
+ t.append_point( np.matrix( [0,1,1] ).T ) # Only vertical matrix
49
+
50
+ t.pop_matrix() # Back to the old matrix
51
+ # Now the current matrix is newly: Ry(90) * Rx(90) * Rz(90)
52
+
53
+ t.append_point( np.array( [1,0,0] ) )
54
+ t.append_point( [1,1,0] )
55
+ t.append_point( np.array( [1,1,1] ) )
56
+ t.append_point( [0,1,1] )
57
+
58
+ # Print the resulting points (in a paiwise tuple)
59
+ # Attention: the points are removed from the queue during the iteration.
60
+ for p in t :
61
+ # p is a tuple ( p1 , p2 ) see the function: t.set_points_tuple_size(2)
62
+ print( p[0] )
63
+ print( p[1] )
64
+
65
+
66
+ """
67
+ def __init__(self):
68
+ self.__cmatrix = np.matrix( np.eye( 4 ) )
69
+ self.__stack = list( [] )
70
+ self.__points = deque( [] )
71
+
72
+ self.__p = np.matrix( np.zeros( ( 4,1 ) ) )
73
+ self.__nr = 1
74
+
75
+ def __iter__(self):
76
+ return self
77
+
78
+ if sys.version_info[0] == 3:
79
+ def __next__(self):
80
+ """
81
+ iterate over the points in the queue, it pop and returns the transformed points.
82
+ The popped points in the queue are cancelled during the itarations.
83
+ """
84
+ if len( self.__points ) == 0 :
85
+ raise StopIteration
86
+ else :
87
+ p = self.pop_points()
88
+
89
+ return p
90
+ else:
91
+ def next(self):
92
+ """
93
+ iterate over the points in the queue, it pop and returns the transformed points.
94
+ The popped points in the queue are cancelled during the itarations.
95
+ """
96
+ if len( self.__points ) == 0 :
97
+ raise StopIteration
98
+ else :
99
+ p = self.pop_points()
100
+
101
+ return p
102
+
103
+ def identity(self):
104
+ """
105
+ Set the current matrix to the identity
106
+ """
107
+ self.__cmatrix = np.matrix( np.eye( 4 ) )
108
+
109
+ def push_matrix(self):
110
+ """
111
+ Push in the stack a copy of the current matrix
112
+ """
113
+ self.__stack.append( np.copy( self.__cmatrix ) )
114
+
115
+ def pop_matrix(self):
116
+ """
117
+ Pop and copy in the current matrix the last matrix in the stack
118
+ """
119
+ m = self.__stack.pop()
120
+ self.__cmatrix[:] = m[:]
121
+
122
+ def clear(self):
123
+ """
124
+ Clear the stack, the points in the queue and set to the identity the current matrix
125
+ """
126
+ del self.__stack
127
+ self.__stack = list( [] )
128
+
129
+ del self.__points
130
+ self.__points = deque( [] )
131
+
132
+ self.__cmatrix[:] = np.matrix( np.eye( 4 ) )
133
+
134
+
135
+ def set_points_tuple_size( self , nr ):
136
+ """
137
+ The points are organized by tuples of size nr. That's useful if you want to draw triangles squares or lines,
138
+ where the size of the tupre are respectively 3, 4 and 2.
139
+ """
140
+ if nr < 1 :
141
+ raise ValueError
142
+
143
+ self.__nr = int( nr )
144
+
145
+ def append_point( self , pt ):
146
+ """
147
+ Transforms and append a new point in the points queue
148
+
149
+ Argument:
150
+ pt : point coord: [ x , y , z ]
151
+ """
152
+ nwp = np.matrix( np.zeros( ( 4 , 1 ) ) )
153
+
154
+ nwp[0] = pt[0]
155
+ nwp[1] = pt[1]
156
+ nwp[2] = pt[2]
157
+ nwp[3] = 1.0
158
+
159
+ self.__points.append( self.transformv( nwp ) )
160
+
161
+ def pop_points( self ):
162
+ """
163
+ Returns the firsts #nr of points in the point queue, the returned points are organized in a tuple
164
+ """
165
+ if len( self.__points ) == 0 :
166
+ return None
167
+
168
+ l = list()
169
+
170
+ for i in range(self.__nr) :
171
+ p = self.__points.popleft()
172
+ l.append( p )
173
+
174
+ return tuple(l)
175
+
176
+ def get_matrix( self ):
177
+ """
178
+ Returns a copy of the current matrix
179
+ """
180
+ return np.copy( self.__cmatrix )
181
+
182
+ def set_matrix( self , m ):
183
+ """
184
+ set the current matrix to m
185
+ """
186
+ self.__cmatrix[:] = m[:]
187
+
188
+ matrix = property( get_matrix , set_matrix )
189
+
190
+
191
+ def transform( self , x , y , z ):
192
+ """
193
+ Transform the point ( x , y , z ) according to the current matrix and returns a 3 by 1 matrix containig the resulting point
194
+ """
195
+ self.__p[0] = x
196
+ self.__p[1] = y
197
+ self.__p[2] = z
198
+ self.__p[3] = 1.0
199
+
200
+ return (self.__cmatrix[:] * self.__p)[:3]
201
+
202
+ def transformv( self , pt ):
203
+ """
204
+ Transform the point pt: [ x , y , z ] according to the current matrix and returns a 3 by 1 matrix containig the resulting point
205
+ """
206
+ self.__p[0] = pt[0]
207
+ self.__p[1] = pt[1]
208
+ self.__p[2] = pt[2]
209
+ self.__p[3] = 1.0
210
+
211
+ return (self.__cmatrix[:] * self.__p)[:3]
212
+
213
+
214
+ def rotate( self , angle , x , y , z ):
215
+ """
216
+ Apply the rotation matrix around the axis [ x , y , z ] of the angle: *angle*
217
+ """
218
+ n = np.array( [ x , y , z ] )
219
+
220
+ n = n / np.linalg.norm( n )
221
+
222
+ ux = n[0]
223
+ uy = n[1]
224
+ uz = n[2]
225
+
226
+ sa = np.sin( angle )
227
+ ca = np.cos( angle )
228
+
229
+ m = np.matrix ( [
230
+ [ ux**2 + ca*(1. - ux**2) , ux*uy*(1.-ca)-uz*sa , uz*ux*(1.-ca) + uy*sa , 0.0 ] ,
231
+ [ ux*uy * (1. - ca) + uz*sa , uy**2 + ca*(1.-uy**2) , uy*uz*(1.-ca) - ux*sa , 0.0 ] ,
232
+ [ uz*ux*(1.-ca)-uy*sa , uy*uz*(1.-ca)+ux*sa , uz**2+ca*(1.-uz**2) , 0.0 ] ,
233
+ [ 0.0 , 0.0 , 0.0 , 1.0 ]
234
+ ] )
235
+
236
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
237
+
238
+
239
+ def rotX( self , angle ):
240
+ """
241
+ Apply the rotation around the x axis
242
+ """
243
+ m = np.matrix( np.eye( 4 ) )
244
+
245
+ m[1,1] = np.cos( angle )
246
+ m[2,2] = np.cos( angle )
247
+
248
+ m[2,1] = np.sin( angle )
249
+ m[1,2] = -np.sin( angle )
250
+
251
+
252
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
253
+
254
+
255
+ def rotY( self , angle ):
256
+ """
257
+ Apply the rotation around the y axis
258
+ """
259
+ m = np.matrix( np.eye( 4 ) )
260
+
261
+ m[0,0] = np.cos( angle )
262
+ m[2,2] = np.cos( angle )
263
+
264
+ m[0,2] = np.sin( angle )
265
+ m[2,0] = -np.sin( angle )
266
+
267
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
268
+
269
+
270
+ def rotZ( self , angle ):
271
+ """
272
+ Apply the rotation around the z axis
273
+ """
274
+
275
+ m = np.matrix( np.eye( 4 ) )
276
+
277
+ m[0,0] = np.cos( angle )
278
+ m[1,1] = np.cos( angle )
279
+
280
+ m[0,1] = -np.sin( angle )
281
+ m[1,0] = np.sin( angle )
282
+
283
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
284
+
285
+
286
+ def translation( self , x , y , z ):
287
+ """
288
+ apply the translation with the vector [x y z]
289
+ """
290
+
291
+ m = np.matrix( np.eye( 4 ) )
292
+
293
+ m[0,3] = x
294
+ m[1,3] = y
295
+ m[2,3] = z
296
+
297
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
298
+
299
+
300
+ def scale( self , x , y , z ):
301
+ """
302
+ Apply the scale with values x y z
303
+ """
304
+
305
+ m = np.matrix( np.eye( 4 ) )
306
+
307
+ m[0,0] = x
308
+ m[1,1] = y
309
+ m[2,2] = z
310
+
311
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
312
+
313
+ def shearX( self , a , b ):
314
+ """
315
+ Apply the shearing along X axis using the values a b
316
+ ::
317
+ SH_X(a,b) = [ 1 0 0 0
318
+ a 1 0 0
319
+ b 0 1 0
320
+ 0 0 0 1 ]
321
+
322
+ """
323
+ m = np.matrix( np.eye( 4 ) )
324
+
325
+ m[1,0] = a
326
+ m[2,0] = b
327
+
328
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
329
+
330
+
331
+ def shearY( self , a , b ):
332
+ """
333
+ Apply the shearing along Y axis using the values a b
334
+ ::
335
+
336
+ SH_Y(a,b) = [ 1 a 0 0
337
+ 0 1 0 0
338
+ 0 b 1 0
339
+ 0 0 0 1 ]
340
+
341
+ """
342
+ m = np.matrix( np.eye( 4 ) )
343
+
344
+ m[0,1] = a
345
+ m[2,1] = b
346
+
347
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
348
+
349
+ def shearZ( self , a , b ):
350
+ """
351
+ Apply the shearing along Z axis using the values a b
352
+ ::
353
+
354
+ SH_Z(a,b) = [ 1 0 a 0
355
+ 0 1 b 0
356
+ 0 0 1 0
357
+ 0 0 0 1 ]
358
+
359
+ """
360
+ m = np.matrix( np.eye( 4 ) )
361
+
362
+ m[0,2] = a
363
+ m[1,2] = b
364
+
365
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
366
+
367
+
368
+ def reflection( self , a , b , c ) :
369
+ """
370
+ Apply the reflection through the plane: ax + by + cz = 0
371
+ """
372
+ m = np.matrix ( [
373
+ [ 1.0 - 2.0*a**2 , -2.0*a*b , -2.0*a*c , 0.0 ] ,
374
+ [ -2.0*a*b , 1.0 - 2.0*b**2 , -2.0*b*c , 0.0 ] ,
375
+ [ -2.0*a*b , -2.0*b*c , 1.0 - 2.0*c**2 , 0.0 ] ,
376
+ [ 0.0 , 0.0 , 0.0 , 1.0 ]
377
+ ] )
378
+
379
+ self.__cmatrix[:] = self.__cmatrix[:] * m[:]
380
+
381
+
382
+
383
+
384
+
385
+
386
+
387
+
@@ -0,0 +1,21 @@
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
+
18
+ import os
19
+ import glob
20
+
21
+ __all__ = [ os.path.splitext( os.path.basename(f) )[0] for f in glob.glob(os.path.dirname(os.path.abspath(__file__))+"/*.py")]