This video is part of the Tecplot for Barracuda Training Videos collection.
This training video shows how to calculate particle residence time using visualization data from Tecplot for Barracuda along with a Jupyter notebook. It is necessary to have Python installed in order to perform this analysis.
Concepts covered in this video:
- Enabling PyTecplot connections
- Opening Jupyter notebook through the Barracuda GUI
- Analyzing visualization data to create a plot
Download example Jupyter notebook script zip file.
The contents of the Jupyter notebook shown in the video are included below for easy copy-and-paste.
%matplotlib inline
import tecplot as tp
import matplotlib.pyplot as plt
import numpy as np
tp.session.connect()
with tp.session.suspend():
dataset = tp.active_frame().dataset
solutionTime = dataset.zone('Particles').solution_time
residenceTime = dataset.zone('Particles').values('Residence time').as_numpy_array()
print("Solution time:", "{0:.2f}".format(solutionTime), "s")
print("Number of particles:", len(residenceTime))
print("Minimum residence time:", np.amin(residenceTime))
print("Maximum residence time:", np.amax(residenceTime))
hist, bin_edges = np.histogram(residenceTime, bins=10)
normalized_hist = hist / np.sum(hist)
bin_centers = (bin_edges[:-1] + bin_edges[1:]) / 2
fig, ax = plt.subplots(tight_layout=True)
ax.plot(bin_centers, normalized_hist * 100, marker='o', linestyle='--')
ax.set_title('Residence time Distribution')
ax.set_xlabel('Time (s)')
ax.set_ylabel('% of Particles')
fig.savefig('particle_residence_time.png')
If you are using value blanking in Tecplot to exclude some particles from the view, and you wish to calculate the residence time distribution for only the particles that are still active after blanking, a slightly different method can be used for creating the “residenceTime” array. Instead of this:
residenceTime = dataset.zone('Particles').values('Residence time').as_numpy_array()
… you can use the extract_blanked_zones() method to retrieve data for only the desired particles:
# Extract blanked zone to get only particles that are desired
extractedZone = tp.data.extract.extract_blanked_zones(dataset.zone('Particles'))
residenceTime = extractedZone[0].values('Residence time').as_numpy_array()
