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,188 @@
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.pset.cluster as clu
21
+ import pyparticles.forces.gravity as gr
22
+ import pyparticles.pset.particles_set as ps
23
+
24
+
25
+ class RandCluster(clu.Cluster):
26
+ def __init__(self):
27
+ pass
28
+
29
+ def insert3(
30
+ self,
31
+ X,
32
+ M=None,
33
+ V=None,
34
+ start_indx=0,
35
+ n=100,
36
+ centre=(0.0, 0.0, 0.0),
37
+ radius=1.0,
38
+ mass_rng=(0.5, 1),
39
+ vel_rng=(0.5, 1.0),
40
+ vel_mdl=None,
41
+ vel_dir=None,
42
+ randg=np.random.rand,
43
+ r_min=0.0,
44
+ ):
45
+ flag = True
46
+ si = int(start_indx)
47
+ ei = int(start_indx + n)
48
+ rng = range(si, ei)
49
+ indx = range(si, ei)
50
+
51
+ while flag:
52
+ nn = len(indx)
53
+ r = randg(nn) * radius
54
+ theta = np.random.rand(nn) * 2.0 * np.pi
55
+ phi = np.random.rand(nn) * np.pi
56
+
57
+ X[indx, 0] = centre[0] + r * np.cos(theta) * np.sin(phi)
58
+ X[indx, 1] = centre[1] + r * np.sin(theta) * np.sin(phi)
59
+ X[indx, 2] = centre[2] + r * np.cos(phi)
60
+
61
+ if r_min == 0.0:
62
+ flag = False
63
+ else:
64
+ d = dist.squareform(dist.pdist(X[rng, :]))
65
+ ax, bx = np.where(np.logical_and(d < r_min, d > 0.0))
66
+ indx = np.asarray(
67
+ start_indx + np.unique(np.concatenate((ax, bx))),
68
+ dtype=np.int64,
69
+ )
70
+ if len(indx) == 0:
71
+ flag = False
72
+
73
+ if M is not None:
74
+ M[si:ei, 0] = mass_rng[0] + randg(n) * (mass_rng[1] - mass_rng[0])
75
+
76
+ if V is not None and vel_mdl == "bomb":
77
+ self.bomb_vel(
78
+ X,
79
+ V,
80
+ n=n,
81
+ start_indx=start_indx,
82
+ centre=centre,
83
+ randg=randg,
84
+ vel_rng=vel_rng,
85
+ )
86
+ elif V is not None and vel_mdl == "const":
87
+ self.const_vel(
88
+ X,
89
+ V,
90
+ n=n,
91
+ start_indx=start_indx,
92
+ randg=randg,
93
+ vel_rng=vel_rng,
94
+ vel_dir=vel_dir,
95
+ )
96
+
97
+ def bomb_vel(
98
+ self,
99
+ X,
100
+ V,
101
+ start_indx=0,
102
+ n=100,
103
+ centre=(0.0, 0.0, 0.0),
104
+ vel_rng=(0.5, 1.0),
105
+ randg=np.random.rand,
106
+ ):
107
+ si = int(start_indx)
108
+ ei = int(start_indx + n)
109
+ mX = X[si:ei, :] - centre
110
+ norms = np.sqrt(np.sum(mX**2.0, axis=1))
111
+ norms[norms == 0.0] = 1.0
112
+ U = (mX.T / norms).T
113
+ V[si:ei, :] += (
114
+ U.T * (vel_rng[0] + randg(n) * (vel_rng[1] - vel_rng[0]))
115
+ ).T
116
+
117
+ def const_vel(
118
+ self,
119
+ X,
120
+ V,
121
+ start_indx=0,
122
+ n=100,
123
+ vel_rng=(0.5, 1.0),
124
+ vel_dir=(1, 0, 0),
125
+ randg=np.random.rand,
126
+ ):
127
+ si = int(start_indx)
128
+ ei = int(start_indx + n)
129
+ v_dir = np.zeros(V[si:ei, :].shape) + vel_dir
130
+ V[si:ei, :] += (
131
+ v_dir.T * (vel_rng[0] + randg(n) * (vel_rng[1] - vel_rng[0]))
132
+ ).T
133
+
134
+
135
+ class RandGalaxyCluster(clu.Cluster):
136
+ def __init__(self):
137
+ pass
138
+
139
+ def insert3(
140
+ self,
141
+ X,
142
+ M,
143
+ V,
144
+ G,
145
+ start_indx=0,
146
+ n=-1,
147
+ centre=(0.0, 0.0, 0.0),
148
+ radius=1.0,
149
+ mass_rng=(0.7, 1),
150
+ std=(3.0, 0.6, 0.2),
151
+ black_hole_mass=5000.0,
152
+ ):
153
+ if n <= 0:
154
+ n = X.shape[0] - start_indx
155
+
156
+ si = int(start_indx)
157
+ ei = int(start_indx + n)
158
+ rng = slice(si, ei)
159
+
160
+ X[rng, 0] = radius * np.random.normal(0.0, std[0], n)
161
+ X[rng, 1] = radius * np.random.normal(0.0, std[1], n)
162
+ X[rng, 2] = radius * np.random.normal(0.0, std[2], n)
163
+ X[si, :] = np.array([0.0, 0.0, 0.0])
164
+
165
+ if M is not None:
166
+ M[rng] = mass_rng[0] + np.random.rand(n, 1) * (mass_rng[1] - mass_rng[0])
167
+ M[si] = black_hole_mass
168
+
169
+ c = np.cross(X[rng], np.array([0, 0, 1]))
170
+ norms = np.sqrt(np.sum(c**2, axis=1))
171
+ nonzero = norms > 0.0
172
+ c[nonzero] = (c[nonzero].T / norms[nonzero]).T
173
+ c[~nonzero] = 0.0
174
+
175
+ pset = ps.ParticlesSet(n)
176
+ pset.X[:] = X[rng, :]
177
+ pset.M[:] = M[rng]
178
+
179
+ grav = gr.Gravity(n, Consts=G)
180
+ grav.set_masses(pset.M)
181
+ grav.update_force(pset)
182
+
183
+ f = np.sqrt(np.sum(grav.F**2, axis=1))
184
+ r = np.sqrt(np.sum(pset.X**2, axis=1))
185
+ v = np.sqrt(f * r / pset.M[:, 0])
186
+
187
+ V[rng, :] = (v * c.T).T / 1.3
188
+ X[rng, :] += np.asarray(centre)
@@ -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
+ import numpy as np
10
+ import pyparticles.pset.boundary as bd
11
+
12
+
13
+ class ReboundBoundary(bd.Boundary):
14
+ def __init__(self, bound=(-1, 1), dim=3):
15
+ self.set_boundary(bound, dim)
16
+ self.set_normals()
17
+
18
+ def set_normals(self):
19
+ self.__N = np.zeros((2 * self.dim, self.dim))
20
+
21
+ if self.dim >= 2:
22
+ self.__N[0, :2] = np.array([1, 0])
23
+ self.__N[1, :2] = np.array([-1, 0])
24
+ self.__N[2, :2] = np.array([0, 1])
25
+ self.__N[3, :2] = np.array([0, -1])
26
+
27
+ if self.dim == 3:
28
+ self.__N[4, :] = np.array([0, 0, 1])
29
+ self.__N[5, :] = np.array([0, 0, -1])
30
+
31
+ def needs_update(self, p_set):
32
+ for i in range(self.dim):
33
+ if np.any(p_set.X[:, i] < self.bound[i, 0]):
34
+ return True
35
+ if np.any(p_set.X[:, i] > self.bound[i, 1]):
36
+ return True
37
+ return False
38
+
39
+ def boundary(self, p_set):
40
+ v_mi = np.zeros(3)
41
+ v_mx = np.zeros(3)
42
+ changed = False
43
+
44
+ for i in range(self.dim):
45
+ j = 2 * i
46
+ v_mi[:] = 0.0
47
+ v_mx[:] = 0.0
48
+
49
+ b_mi = p_set.X[:, i] < self.bound[i, 0]
50
+ b_mx = p_set.X[:, i] > self.bound[i, 1]
51
+
52
+ if np.any(b_mi) or np.any(b_mx):
53
+ changed = True
54
+
55
+ v_mi[i] = self.bound[i, 0]
56
+ v_mx[i] = self.bound[i, 1]
57
+
58
+ p_set.X[b_mi, :] = p_set.X[b_mi, :] + 2.0 * self.__N[j, :] * (
59
+ v_mi - p_set.X[b_mi, :]
60
+ )
61
+ p_set.X[b_mx, :] = p_set.X[b_mx, :] + 2.0 * self.__N[j, :] * (
62
+ v_mx - p_set.X[b_mx, :]
63
+ )
64
+
65
+ p_set.V[b_mi, i] = -p_set.V[b_mi, i]
66
+ p_set.V[b_mx, i] = -p_set.V[b_mx, i]
67
+
68
+ return changed
@@ -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,72 @@
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 argparse
19
+
20
+ def parse_args():
21
+ desc = "PyParticles is a particle simulation tool box that support the most diffused numerical integration "
22
+ desc = desc + " and forces models "
23
+
24
+ parser = argparse.ArgumentParser( description=desc )
25
+
26
+ parser.add_argument("-m", "--config_model",
27
+ action="store_true",
28
+ dest="config_model",
29
+ help="Write out the model of a config file and exit")
30
+
31
+ parser.add_argument( "-d" , "--demo",
32
+ action="store",
33
+ choices=[ "springs" ,
34
+ "solar_system" ,
35
+ "gas_lj" ,
36
+ "bubble" ,
37
+ "cat_spri" ,
38
+ "el_static" ,
39
+ "elmag_field" ,
40
+ "fountain" ,
41
+ "galaxy"] ,
42
+ dest="demo",
43
+ default=None ,
44
+ help="Execute the specified buildin demo"
45
+ )
46
+
47
+ parser.add_argument( "-t" , "--test",
48
+ action="store",
49
+ choices=[ "fall" , "harmonic" , "dharmonic" ] ,
50
+ dest="test",
51
+ default=None ,
52
+ help="Execute the specified buildin test")
53
+
54
+ parser.add_argument(
55
+ dest="path_name",
56
+ nargs='?',
57
+ default=None
58
+ )
59
+
60
+ parser.add_argument( "-v" , "--version",
61
+ action="store_true",
62
+ dest="version",
63
+ help="print the current version and exit"
64
+ )
65
+
66
+ parser.add_argument( "-a" , "--about",
67
+ action="store_true",
68
+ dest="about",
69
+ help="print the about message and exit"
70
+ )
71
+
72
+ return parser.parse_args()