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,466 @@
1
+
2
+ # PyParticles : Particles simulation in python
3
+ # Copyright (C) 2012 Simone Riva mail: simone.rva {at} gmail {dot} com
4
+ #
5
+ # This program is free software: you can redistribute it and/or modify
6
+ # it under the terms of the GNU General Public License as published by
7
+ # the Free Software Foundation, either version 3 of the License, or
8
+ # (at your option) any later version.
9
+ #
10
+ # This program is distributed in the hope that it will be useful,
11
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ # GNU General Public License for more details.
14
+ #
15
+ # You should have received a copy of the GNU General Public License
16
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
17
+
18
+ import matplotlib.animation as animation
19
+
20
+ from pyparticles.utils.pypart_global import *
21
+
22
+ from mpl_toolkits.mplot3d import Axes3D
23
+ import matplotlib.pyplot as plt
24
+ import matplotlib
25
+ import numpy as np
26
+
27
+ import pyparticles.pset.particles_set as ps
28
+ import pyparticles.pset.logger as log
29
+
30
+ import pyparticles.animation.animated_scatter as anim
31
+
32
+ import pyparticles.animation as pan
33
+
34
+ import pyparticles.animation.test_animation as test
35
+
36
+ import pyparticles.pset.rand_cluster as clu
37
+ import pyparticles.forces.gravity as gr
38
+
39
+ import pyparticles.ode.euler_solver as els
40
+ import pyparticles.ode.leapfrog_solver as lps
41
+ import pyparticles.ode.runge_kutta_solver as rks
42
+ import pyparticles.ode.stormer_verlet_solver as svs
43
+
44
+ import matplotlib.animation as animation
45
+
46
+
47
+ import pyparticles.pset.periodic_boundary as pb
48
+ import pyparticles.pset.rebound_boundary as rb
49
+ import pyparticles.forces.const_force as cf
50
+ import pyparticles.forces.vector_field_force as vf
51
+ import pyparticles.forces.linear_spring as ls
52
+ import pyparticles.pset.file_cluster as fc
53
+
54
+ import pyparticles.demo.solar_system as sol
55
+ import pyparticles.demo.springs as spr
56
+ import pyparticles.demo.gas_lennard_jones as lj
57
+ import pyparticles.demo.bubble as bu
58
+ import pyparticles.demo.springs_constr as spc
59
+ import pyparticles.demo.test as tst
60
+ import pyparticles.demo.electrostatic_demo as eld
61
+ import pyparticles.demo.electromagnetic_demo as emd
62
+ import pyparticles.demo.fountain as fou
63
+ import pyparticles.demo.gravity_clusters as grav
64
+
65
+ import pyparticles.utils.parse_args as arg
66
+
67
+ import pyparticles.utils.problem_config as pc
68
+ import pyparticles.pset.octree as ot
69
+
70
+ from pyparticles.geometry.dist import distance
71
+
72
+ import pyparticles.pset.constrained_x as ct
73
+ import pyparticles.pset.constrained_force_interactions as cfi
74
+
75
+ import pyparticles.geometry.transformations as tr
76
+
77
+ import time
78
+
79
+ import sys
80
+
81
+ import pyparticles.animation.animated_ogl as aogl
82
+
83
+
84
+ def main():
85
+
86
+ #my_test()
87
+
88
+ np.seterr(all='ignore')
89
+
90
+ options = arg.parse_args()
91
+
92
+ cfg = pc.ParticlesConfig()
93
+
94
+ if options.version :
95
+ print( py_particle_version() )
96
+ return
97
+
98
+ if options.about :
99
+ about()
100
+ return
101
+
102
+ if options.test :
103
+ print("")
104
+ print("Start a test simulation:")
105
+ print(" It compares the simulated solution with the analytical solution in a specific problem")
106
+ tst.test( options.test )
107
+ return
108
+
109
+ if options.config_model :
110
+ file_name = "example_pyparticles_config.cfg"
111
+ cfg.write_example_config_file("example_pyparticles_config.cfg")
112
+ print( "A file named: %s has been written in the current directory" % file_name )
113
+ print( "" )
114
+ return
115
+
116
+ if options.demo == "fountain" :
117
+ print("")
118
+ print("Start the simulation example:")
119
+ print(" 250K Particles fountain")
120
+ fou.fountain()
121
+ return
122
+
123
+ if options.demo == "springs" :
124
+ print("")
125
+ print("Start the simulation example:")
126
+ print(" 3 body springs")
127
+ spr.springs()
128
+ return
129
+
130
+ if options.demo == "cat_spri" :
131
+ print("")
132
+ print("Start the simulation example:")
133
+ print(" catenary springs (constraints demo)")
134
+ spc.spring_constr()
135
+ return
136
+
137
+ if options.demo == "gas_lj" :
138
+ print("")
139
+ print("Start the simulation example:")
140
+ print(" Pseudo gas with Lennard Jones potential")
141
+ lj.gas_lj()
142
+ return
143
+
144
+ if options.demo == "bubble" :
145
+ print("")
146
+ print("Start the simulation example:")
147
+ print(" Pseudo bubble demo")
148
+ bu.bubble()
149
+ return
150
+
151
+ if options.demo == "el_static" :
152
+ print("")
153
+ print("Start the simulation example:")
154
+ print(" electrostatic")
155
+ eld.electro()
156
+ return
157
+
158
+ if options.demo == "elmag_field" :
159
+ print("")
160
+ print("Start the simulation example:")
161
+ print(" electromagnetic fields")
162
+ emd.electromag_field()
163
+ return
164
+
165
+ if options.demo == "galaxy" :
166
+ print("")
167
+ print("Start the simulation example:")
168
+ print(" Gravitational clusters")
169
+ grav.gravity_cluster()
170
+ return
171
+
172
+ if options.path_name == None or options.demo == "solar_system":
173
+
174
+ print("")
175
+ print("Start the simulation example:")
176
+ print(" Solar system")
177
+ print(" -- Try to watch the Moon ... around the Earth ")
178
+ print("")
179
+ print(" Use your mouse for rotating, zooming and tranlating the scene.")
180
+ print("")
181
+ print("For more details type:")
182
+ print(" pyparticles --help")
183
+ print("")
184
+
185
+ sol.solar_system()
186
+ return
187
+
188
+
189
+
190
+ if options.path_name != None :
191
+
192
+ cfg.read_config( options.path_name )
193
+ ( an , pset , force , ode_solver ) = cfg.build_problem()
194
+
195
+ an.build_animation()
196
+
197
+ print("")
198
+ print("Start the simulation described in: %s ... " % options.path_name )
199
+
200
+ an.start()
201
+ return
202
+
203
+ print("Ops ... ")
204
+ return
205
+
206
+
207
+
208
+
209
+
210
+
211
+
212
+ ####################################################################
213
+ ####################################################################
214
+ ####################################################################
215
+ ####################################################################
216
+ ####################################################################
217
+ ####################################################################
218
+ #### Old test code .....and tests ....
219
+ ####################################################################
220
+
221
+
222
+ class MyField( vf.VectorFieldForce ):
223
+ def __init__(self,size,dim):
224
+ super(MyField,self).__init__(size)
225
+ self.v = np.zeros((dim,size))
226
+
227
+ def vect_fun( self , X ):
228
+ self.v[:] = ( X**2 ).T
229
+ return ( self.v * -X.T/np.sqrt( np.sum(self.v,0) ) ).T
230
+
231
+
232
+
233
+ def my_test() :
234
+
235
+
236
+ pset = ps.ParticlesSet( 10 )
237
+
238
+ lo = log.Logger( pset , 10 )
239
+
240
+ for i in range( 105 ) :
241
+ pset.X[:] = float(i)
242
+ lo.log()
243
+
244
+ print( lo.get_particles_log( 3 ) )
245
+
246
+ exit()
247
+
248
+ t = tr.Transformations()
249
+
250
+ t.set_points_tuple_size(1)
251
+
252
+ t.rotate( np.radians(90) , 1 , 0 , 0 )
253
+ #t.rotX( np.radians(90) )
254
+
255
+ t.append_point( list( [1,0,0] ) )
256
+ t.append_point( np.array( [1,1,0] ) )
257
+ t.append_point( np.array( [1,1,1] ) )
258
+ t.append_point( np.array( [0,1,1] ) )
259
+
260
+ t.push_matrix()
261
+ t.identity()
262
+ t.translation( 10 , 2 , 2 )
263
+ #t.rotate( np.radians(20) , 1 , 1 , 1 )
264
+
265
+ t.append_point( [1,1,1] )
266
+ t.append_point( np.matrix( [0,1,1] ).T )
267
+
268
+ t.pop_matrix()
269
+
270
+ t.append_point( np.array( [1,0,0] ) )
271
+ t.append_point( [1,1,0] )
272
+ t.append_point( np.array( [1,1,1] ) )
273
+ t.append_point( [0,1,1] )
274
+
275
+ #print( t.transform(pt[0] , pt[1] , pt[2] ) )
276
+
277
+ print("")
278
+
279
+ for (p) in t :
280
+ print( p )
281
+
282
+ exit()
283
+
284
+ n = 10
285
+ dt = 0.005
286
+ #dt = 0.0023453
287
+
288
+ steps = 1000000
289
+
290
+ G = 0.001
291
+ #G = 6.67384e-11
292
+
293
+ FLOOR = -10
294
+ CEILING = 10
295
+
296
+
297
+
298
+ #ff = fc.FileCluster()
299
+ #ff.open( options.path_name )
300
+
301
+ pset = ps.ParticlesSet( n , label=True )
302
+
303
+ pset.label[8] = "tttt"
304
+ pset.label[9] = "tzzzttt"
305
+
306
+ pset.add_property_by_name("ciao",dim=1 , model="list")
307
+
308
+ pset.get_by_name("ciao")[3] = 100
309
+ pset.get_by_name("X")[3,:] = 101
310
+
311
+ sz = 15
312
+ pset.resize( sz )
313
+
314
+ tree = ot.OcTree()
315
+
316
+ pset.get_by_name("X")[:] = np.random.rand(sz,3)
317
+ pset.get_by_name("M")[:] = 1.0
318
+
319
+ pset.update_centre_of_mass()
320
+
321
+ print(" C O M pset")
322
+ print( pset.centre_of_mass() )
323
+ print("")
324
+
325
+ csrt = ct.ConstrainedX( pset )
326
+
327
+ cfit = cfi.ConstrainedForceInteractions( pset )
328
+
329
+ cfit.add_connections( [[12,3],[4,4],[6,8],[1,1]] )
330
+ cfit.remove_connections( [[12,3]] )
331
+
332
+ print( cfit.dense )
333
+ print( cfit.sparse )
334
+ print( cfit.items )
335
+
336
+ cc = np.array( [[1,2,3],[3,3,3]] )
337
+ cc = np.array( [[1,2,3],[3,3,5]] )
338
+
339
+ csrt.add_x_constraint( [2,5] , cc )
340
+ csrt.add_x_constraint( [7,10] , cc )
341
+
342
+ print( csrt.get_cx_indicies() )
343
+ print( csrt.cX )
344
+
345
+ csrt.remove_x_constraint( [2,10] )
346
+
347
+ print( csrt.get_cx_indicies() )
348
+ print( csrt.cX )
349
+
350
+ exit()
351
+
352
+ tree.set_global_boundary()
353
+
354
+ a = time.time()
355
+ tree.build_tree( pset )
356
+ b = time.time()
357
+
358
+ print( "Tot time: % f" %(b-a) )
359
+
360
+ C = np.array([0.5,0.4,0.3])
361
+ R = 0.05
362
+
363
+ a = time.time()
364
+ for ix in range( pset.size ):
365
+ nl = tree.search_neighbour( pset.X[ix,:] , R )
366
+ b = time.time()
367
+
368
+ print( "Tot time octree : % f" %(b-a) )
369
+
370
+ nl = np.sort( nl )
371
+
372
+ print("")
373
+ print("nl:")
374
+ print( nl )
375
+
376
+ print("")
377
+ print("dd:")
378
+
379
+ a = time.time()
380
+ for ix in range( pset.size ):
381
+ dd = np.sqrt( np.sum( (pset.X[ix,:] - pset.X)**2 , 1 ) )
382
+ din, = np.where( dd <= R )
383
+ b = time.time()
384
+
385
+ print( "Tot time numpy : % f" %(b-a) )
386
+
387
+ print( din )
388
+
389
+ print(" C O M")
390
+ print( tree.centre_of_mass )
391
+ print("")
392
+
393
+ print ( np.all( nl == din ) )
394
+
395
+ #tree.print_tree()
396
+
397
+
398
+ #print( pset.get_by_name( "ciao" ) )
399
+ #print( pset.get_by_name( "X" ) )
400
+ #print("")
401
+ #print( pset.X )
402
+ #print( pset.label )
403
+
404
+
405
+ exit()
406
+ return
407
+
408
+ #ff.insert3( pset )
409
+ #ff.close()
410
+
411
+ #pset.unit = 149597870700.0
412
+ #pset.mass_unit = 5.9736e24
413
+
414
+
415
+ cs = clu.RandCluster()
416
+
417
+ cs.insert3( pset.X , M=pset.M , V=pset.V ,
418
+ n = n/2 , centre=(-1.5,1,0.5) , mass_rng=(0.5,5.0) ,
419
+ vel_rng=(0,0) , vel_mdl="bomb" )
420
+
421
+ cs.insert3( pset.X , M=pset.M , V=pset.V ,
422
+ start_indx=int(n/2) , n = int(n/2) , centre=(1.5,-0.5,0.5) ,
423
+ vel_rng=(0.2,0.4) , vel_mdl="const" , vel_dir=[-1.0,0.0,0.0] )
424
+ #
425
+
426
+ grav = gr.Gravity( pset.size , Consts=G )
427
+ #grav = cf.ConstForce(n , u_force=[0,0,-1.0] )
428
+ #grav = MyField( pset.size , dim=3 )
429
+ #grav = ls.LinearSpring( pset.size , Consts=10e8 )
430
+
431
+ grav.set_masses( pset.M )
432
+
433
+
434
+ bound = None
435
+ #bound = pb.PeriodicBoundary( (-50.0 , 50.0) )
436
+ #bound = rb.ReboundBoundary( (-10.0 , 10.0) )
437
+
438
+ pset.set_boundary( bound )
439
+ grav.update_force( pset )
440
+
441
+ solver = els.EulerSolver( grav , pset , dt )
442
+ #solver = lps.LeapfrogSolver( grav , pset , dt )
443
+ #solver = svs.StormerVerletSolver( grav , pset , dt )
444
+ #solver = rks.RungeKuttaSolver( grav , pset , dt )
445
+
446
+ a = aogl.AnimatedGl()
447
+ # a = anim.AnimatedScatter()
448
+
449
+
450
+ a.xlim = ( FLOOR , CEILING )
451
+ a.ylim = ( FLOOR , CEILING )
452
+ a.zlim = ( FLOOR , CEILING )
453
+
454
+ a.ode_solver = solver
455
+ a.pset = pset
456
+ a.steps = steps
457
+
458
+ a.build_animation()
459
+
460
+ a.start()
461
+
462
+ return
463
+
464
+
465
+ if __name__ == '__main__':
466
+ main()
@@ -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")]
@@ -0,0 +1,67 @@
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 scipy.spatial.distance as dist
19
+
20
+ import pyparticles.measures.measure as me
21
+
22
+ class ElasticPotentialEnergy( me.Measure ):
23
+ """
24
+ Class derived from Measure usedfor computing the total elastic potential energy of the particle system
25
+ """
26
+ def __init__( self , pset=None , force=None ):
27
+
28
+ self.__pot = 0.0
29
+
30
+ super( ElasticPotentialEnergy , self ).__init__( pset , force )
31
+
32
+
33
+ def value(self):
34
+ """
35
+ return the current value of the potential energy
36
+ """
37
+ return self.__pot
38
+
39
+
40
+ def update_measure( self ):
41
+ """
42
+ Compute and return the elestic potential energy on the current state of the pset
43
+ """
44
+
45
+ D = dist.pdist( self.pset.X , 'euclidean' )
46
+ self.__pot = np.sum( 1.0/2.0 * D**2.0 * self.force.const )
47
+
48
+ return self.__pot
49
+
50
+
51
+ def shape( self ):
52
+ """
53
+ return a tuple containing the shape of the measures dataset
54
+ """
55
+ return 1,
56
+
57
+ def dim( self ):
58
+ """
59
+ return the dimension of the measure: 1 for the potential energy
60
+ """
61
+ return 1
62
+
63
+ def name(self):
64
+ """
65
+ Return the string: "potential energy"
66
+ """
67
+ return "potential energy"
@@ -0,0 +1,69 @@
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 scipy.spatial.distance as dist
19
+
20
+ import pyparticles.measures.measure as me
21
+
22
+ class GravitationalPotentialEnergy( me.Measure ):
23
+ """
24
+ Class derived from Measure usedfor computing the total gravitational potential energy of the particle system
25
+ """
26
+ def __init__( self , pset=None , force=None ):
27
+
28
+ self.__pot = 0.0
29
+
30
+ super( GravitationalPotentialEnergy , self ).__init__( pset , force )
31
+
32
+
33
+ def value(self):
34
+ """
35
+ return the current value of the potential energy
36
+ """
37
+ return self.__pot
38
+
39
+
40
+ def update_measure( self ):
41
+ """
42
+ Compute and return the elestic potential energy on the current state of the pset
43
+ """
44
+
45
+ D = dist.pdist( self.pset.X , 'euclidean' )
46
+ Mm = dist.pdist( self.pset.M , lambda v , u : v*u )
47
+
48
+ self.__pot = np.sum( - Mm/D * self.force.const )
49
+
50
+ return self.__pot
51
+
52
+
53
+ def shape( self ):
54
+ """
55
+ return a tuple containing the shape of the measures dataset
56
+ """
57
+ return 1,
58
+
59
+ def dim( self ):
60
+ """
61
+ return the dimension of the measure: 1 for the potential energy
62
+ """
63
+ return 1
64
+
65
+ def name(self):
66
+ """
67
+ Return the string: "potential energy"
68
+ """
69
+ return "potential energy"
@@ -0,0 +1,68 @@
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 scipy.spatial.distance as dist
19
+
20
+ import pyparticles.measures.measure as me
21
+
22
+ class KineticEnergy( me.Measure ):
23
+ """
24
+ Mesure for computing the total potential energy of the particle system
25
+ """
26
+ def __init__( self , pset=None , force=None ):
27
+
28
+ self.__ke = 0.0
29
+
30
+ super( KineticEnergy , self ).__init__( pset , force )
31
+
32
+
33
+ def value(self):
34
+ """
35
+ return the current value of the potential energy
36
+ """
37
+ return self.__ke
38
+
39
+
40
+ def update_measure( self ):
41
+ """
42
+ Compute and return the elestic potential energy on the current state of the pset
43
+ """
44
+
45
+ self.__Va = np.sum( self.pset.V**2.0 , 1 )
46
+
47
+ self.__ke = np.sum( 1.0/2.0 * self.__Va * self.pset.M.T )
48
+
49
+ return self.__ke
50
+
51
+
52
+ def shape( self ):
53
+ """
54
+ return a tuple containing the shape of the measures dataset
55
+ """
56
+ return 1,
57
+
58
+ def dim( self ):
59
+ """
60
+ return the dimension of the measure: 1 for the potential energy
61
+ """
62
+ return 1
63
+
64
+ def name(self):
65
+ """
66
+ Return the string: "potential energy"
67
+ """
68
+ return "kinetic energy"