Skip to content

Commit 97556d3

Browse files
committed
Add tracers example in cookbook
1 parent 01b4a73 commit 97556d3

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

docs/index.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Welcome to StagPy's documentation!
2525
sources/cookbook/field
2626
sources/cookbook/nura
2727
sources/cookbook/vrmsra
28+
sources/cookbook/tracers
2829

2930
.. toctree::
3031
:maxdepth: 2

docs/sources/cookbook/tracers.rst

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
Plotting tracers information
2+
============================
3+
4+
StagPy gives you access to tracers information through StagyyData. Mind that
5+
tracers information is organized by blocks even if your run only has one
6+
block. The following script offers an example::
7+
8+
from stagpy.stagyydata import StagyyData
9+
import matplotlib.pyplot as plt
10+
import numpy as np
11+
12+
sdat = StagyyData('.')
13+
14+
time = []
15+
energy = []
16+
for snap in sdat.snaps:
17+
time.append(snap.time)
18+
energy.append(np.sum(snap.tracers['Mass'][0] *
19+
snap.tracers['Temperature'][0]))
20+
21+
fig, axes = plt.subplots(nrows=2)
22+
23+
axes[0].plot(time, energy)
24+
axes[0].set_xlabel("Time")
25+
axes[0].set_ylabel("Internal energy")
26+
27+
axes[1].hist(sdat.snaps[-1].tracers['TimeMelted'][0])
28+
axes[1].set_xlabel("Time melted")
29+
axes[1].set_ylabel("Number of tracers")
30+
31+
fig.tight_layout()
32+
plt.savefig('tracers.pdf')

0 commit comments

Comments
 (0)