Skip to content

Commit b7323a2

Browse files
Merge pull request #10 from EXP-code/develcompatibility
Minor updates for devel compatibility
2 parents c58f861 + fc7564e commit b7323a2

7 files changed

Lines changed: 143 additions & 2 deletions

File tree

Binary/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,25 @@
1+
# Binary star example
2+
13
A simple simulation of a binary star system, to exercise the code and give some experience with the file formats. The example takes two stars and evolves them under direct interaction. The initial conditions for the stars are specified in `binary.bods`, which follows standard `EXP` input format: the first line is the number of bodies (followed by two integers that specify the number of extra integer and double fields -- here set to be zero). Lines after the first line specify, for each body, the mass, xyz position, and xyz velocity.
24

5+
## How to run
6+
37
Run as follows. The YAML configuration file is set for the Docker container. If you are using a native build and installation, change the ldlibdir parameter to point at your library install directory. Then, execute the command: `mpirun -np 1 exp binary.yml`.
48

9+
## A fixed potential example
10+
511
There is also an example where the stars no longer feel mutual self-gravity, but instead are evolved in an external logarithmic potential. This may be run using `mpirun -np 1 exp logpot.yml`. This example demonstrates `noforce`.
612

13+
## Viewing results
14+
15+
Each example creates a trajectory file named `ORBTRACE.runX` where `X`
16+
is either `1` or `2`, for `binary.yml` or `logpot.yml`
17+
respectively. These may be plotted using the command:
18+
19+
``` bash
20+
python3 plotOrbit.py --input=ORBTRACE.runX
21+
```
22+
23+
## Additional exploration
24+
725
A first exercise to extend these examples would be to instead use the `usermw` module to simulate the orbit of the sun in the MW.

Binary/logpot.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Global:
1515
multistep : 12
1616
dynfracA : 0.01
1717
dynfracV : 0.01
18-
VERBOSE : 4
18+
VERBOSE : 1
1919
# ------------------------------------------------------------------------
2020
# This is a sequence of components. The parameters for the force are
2121
# now included as a parameter map, rather than a separate file.

Binary/plotOrbit.py

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import argparse
4+
5+
def plot_orbit(positions, title="Orbital Trajectory", save_path=None):
6+
"""
7+
Plots two orbital trajectories given a list of 3D positions.
8+
9+
Parameters:
10+
positions: The x, y, z positions for N times both trajectories as an ndarray of shape (N, 6).
11+
title (str): The title of the plot.
12+
save_path (str): If provided, the plot will be saved to this path.
13+
"""
14+
15+
# Extract x, y, z coordinates
16+
x1 = positions[:, 0]
17+
y1 = positions[:, 1]
18+
z1 = positions[:, 2]
19+
x2 = positions[:, 3]
20+
y2 = positions[:, 4]
21+
z2 = positions[:, 5]
22+
23+
# Create a 3D plot
24+
fig = plt.figure()
25+
ax = fig.add_subplot(111, projection='3d')
26+
27+
# Plot the trajectory
28+
ax.plot(x1, y1, z1, '-')
29+
ax.plot(x2, y2, z2, '-')
30+
31+
# Set labels and title
32+
ax.set_xlabel('X Position')
33+
ax.set_ylabel('Y Position')
34+
ax.set_zlabel('Z Position')
35+
ax.set_title(title)
36+
37+
# Show grid
38+
ax.grid(True)
39+
40+
# Save or show the plot
41+
if save_path:
42+
plt.savefig(save_path)
43+
else:
44+
plt.show()
45+
46+
47+
if __name__ == "__main__":
48+
parser = argparse.ArgumentParser(description="Plot orbital trajectory from 3D positions.")
49+
parser.add_argument('--input', type=str,
50+
default='ORBTRACE.run0',
51+
help="Path to the input file containing 3D positions (one per line as x,y,z).")
52+
53+
args = parser.parse_args()
54+
55+
data = np.loadtxt(args.input)
56+
57+
plot_orbit(data[:, [1,2,3,11,12,13]], title="Binary orbit")

DiskHalo/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ Components:
3939
bodyfile : disk.bod
4040
force :
4141
id : cylinder
42-
parameters : {acyl: 1.0, nmaxfid: 32, mmax: 2, hcyl: 0.05, nmax: 10, ncylodd: 2, ncylnx: 128, ncylny: 64, cachename: disk.cache}
42+
parameters : {acyl: 1.0, lmaxfid: 64, mmax: 2, hcyl: 0.05, sech2: false, nmax: 10, ncylodd: 2, ncylnx: 200, ncylny: 100, cachename: disk.cache}
4343
#
4444
# The parameters could be expressed like this, equivalently:
4545
#

DiskHalo/disk.cache

9.56 MB
Binary file not shown.

Nbody/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,3 +48,13 @@ testing.
4848

4949
The directory `data` contains some snapshots and coefficients for use
5050
with the pyEXP tutorials.
51+
52+
## Viewing results
53+
54+
This example creates a trajectory file with selected disk orbits named
55+
`ORBTRACE.run0`. These orbits may be plotted using the command:
56+
57+
``` bash
58+
python3 plotOrbit.py
59+
```
60+

Nbody/plotOrbit.py

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import matplotlib.pyplot as plt
2+
import numpy as np
3+
import argparse
4+
5+
def plot_orbit(positions, title="Orbital Trajectory", save_path=None):
6+
"""
7+
Plots two orbital trajectories given a list of 3D positions.
8+
9+
Parameters:
10+
positions: A list of 3d particle trajectories (x, y, z) positions for N times, as a list of M ndarrays of shape (N, 3).
11+
title (str): The title of the plot.
12+
save_path (str): If provided, the plot will be saved to this path.
13+
"""
14+
15+
# Create a 3D plot
16+
fig = plt.figure()
17+
ax = fig.add_subplot(111, projection='3d')
18+
19+
# Plot the trajectories
20+
for n in range(len(positions)):
21+
ax.plot(positions[n][:, 0], positions[n][:, 1], positions[n][:, 2], '-')
22+
23+
# Set labels and title
24+
ax.set_xlabel('X Position')
25+
ax.set_ylabel('Y Position')
26+
ax.set_zlabel('Z Position')
27+
ax.set_title(title)
28+
29+
# Show grid
30+
ax.grid(True)
31+
32+
# Save or show the plot
33+
if save_path:
34+
plt.savefig(save_path)
35+
else:
36+
plt.show()
37+
38+
39+
if __name__ == "__main__":
40+
parser = argparse.ArgumentParser(description="Plot orbital trajectory from 3D positions.")
41+
parser.add_argument('--input', type=str,
42+
default='ORBTRACE.run0',
43+
help="Path to the input file containing 3D positions (one per line as x,y,z).")
44+
45+
args = parser.parse_args()
46+
47+
data = np.loadtxt(args.input)
48+
49+
pos = []
50+
pos.append(data[:, 1:4]) # First object positions
51+
pos.append(data[:, 7:10]) # Second object positions
52+
pos.append(data[:, 13:16]) # Third object positions
53+
pos.append(data[:, 19:22]) # Fourth object positions
54+
pos.append(data[:, 25:28]) # Fifth object positions
55+
56+
plot_orbit(pos, title="Selected disk orbits")

0 commit comments

Comments
 (0)