Last active
November 28, 2023 08:15
-
-
Save pmocz/bd2257fcddb64aa52e555d67a5557a18 to your computer and use it in GitHub Desktop.
Revisions
-
pmocz revised this gist
Sep 14, 2020 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,6 +1,6 @@ def getAcc( pos, mass, G, softening ): """ Calculate the acceleration on each particle due to Newton's Law pos is an N x 3 matrix of positions mass is an N x 1 vector of masses G is Newton's Gravitational constant @@ -20,5 +20,5 @@ def getAcc( pos, mass, G, softening ): a[i,0] += G * (dx * inv_r3) * mass[j]; a[i,1] += G * (dy * inv_r3) * mass[j]; a[i,2] += G * (dz * inv_r3) * mass[j]; return a -
pmocz created this gist
Sep 14, 2020 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,24 @@ def getAcc( pos, mass, G, softening ): """ Calculate the acceleration on each particle due to Newton's Law pos is an N x 3 matrix of positions mass is an N x 1 vector of masses G is Newton's Gravitational constant softening is the softening length a is N x 3 matrix of accelerations """ N = pos.shape[0]; a = np.zeros((N,3)); for i in range(N): for j in range(N): dx = pos[j,0] - pos[i,0]; dy = pos[j,1] - pos[i,1]; dz = pos[j,2] - pos[i,2]; inv_r3 = (dx**2 + dy**2 + dz**2 + softening**2)**(-1.5); a[i,0] += G * (dx * inv_r3) * mass[j]; a[i,1] += G * (dy * inv_r3) * mass[j]; a[i,2] += G * (dz * inv_r3) * mass[j]; return a