Skip to content

Instantly share code, notes, and snippets.

@pozitron57
Last active December 18, 2023 20:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pozitron57/971e0b7cb889b41fc72d42c1e91051bd to your computer and use it in GitHub Desktop.
Save pozitron57/971e0b7cb889b41fc72d42c1e91051bd to your computer and use it in GitHub Desktop.
Carnot cycle in problem #947 at https://phys.pro/problems/947
import numpy as np
import matplotlib.pyplot as plt
from matplotlib import rc, rcParams
lw=2.5
rcParams['font.size'] = 26
rc('axes', linewidth=1)
rc('xtick.major', size=7, width=lw/1.3)
rc('ytick.major', size=7, width=lw/1.3)
rc('xtick.minor', size=0, width=lw/2.5)
rc('ytick.minor', size=0, width=lw/2.5)
rcParams['text.usetex'] = True
rc('text.latex', preamble=r'\usepackage[T2A]{fontenc}')
rc('text.latex', preamble=r'\usepackage[utf8]{inputenc}')
rc('text.latex', preamble=r'\usepackage[russian]{babel}')
fig, ax = plt.subplots()
# Hide spines
ax.spines['bottom'].set_visible(False)
ax.spines['left'].set_visible(False)
ax.spines['right'].set_visible(False)
ax.spines['top'].set_visible(False)
# Set zero
ax.spines['bottom'].set_position('zero')
ax.spines['left'].set_position('zero')
# Arrows at axes
arrow_format=dict(arrowstyle="-|>,head_width=0.15",mutation_scale=25, fc='k', ec='k', lw=lw/1.4)
ax.annotate('', xy=(1.11, 0), xycoords=('axes fraction', 'data'),
xytext=(0, 0.05), textcoords=('axes fraction', 'data'),
arrowprops=arrow_format)
ax.annotate('', xy=(0, 1.11), xycoords=('data', 'axes fraction'),
xytext=(0.05, 0), textcoords=('data', 'axes fraction'),
arrowprops=arrow_format)
ax.set_ylabel('$p$', ha='right', y=1, rotation=0, labelpad=13)
ax.set_xlabel('$V$', x=1.06, labelpad=13)
# Set p, V
p1 = 10
V1 = 3
V2 = 6
V3 = 10
γ = 5/3
## Isothermal 1-2
V12 = np.linspace(V1,V2,100)
p12 = p1*V1/V12
## Adiabatic 2-3
V23 = np.linspace(V2,V3,100)
p2 = np.amin(p12)
p23 = p2*(V2/V23)**γ
## Isothermal 3-4
p3 = np.amin(p23)
V4 = V1**(γ/(γ-1)) * (p1 / (p3*V3))**(1/(γ-1))
V34 = np.linspace(V3,V4,100)
p34 = p3*V3/V34
## Adiabatic 4-1
V41 = np.linspace(V4,V1,100)
p4 = np.amax(p34)
p41 = p4*(V4/V41)**γ
## Plot
ax.plot(V12,p12,'k', lw=lw*.75)
ax.plot(V23,p23,'k', lw=lw*.75)
ax.plot(V34,p34,'k', lw=lw*.75)
ax.plot(V41,p41,'k', lw=lw*.75)
ax.scatter([V1, V2, V3, V4], [p1, p2, p3, p4], color='k', zorder=10, lw=1, clip_on=False)
dx=0.3
ax.text(V1+dx, p1, '$1$')
ax.text(V2+dx, p2, '$2$')
ax.text(V3+dx, p3, '$3$')
ax.text(V4-dx, p4, '$4$', ha='right', va='top')
ax.text(-1.5*dx, -2*dx, '$0$')
## Connect 2-4 with Bezier
p = (p2 + p4) / 2.2
V = (V2 + V4) / 2
t = np.linspace(0, 1, 100)
V24 = (1 - t)**2 * V2 + 2 * (1 - t) * t * V + t**2 * V4
p24 = (1 - t)**2 * p2 + 2 * (1 - t) * t * p + t**2 * p4
ax.plot(V24, p24, 'k', lw=lw*.75)
ax.set_xlim([0, 10.5])
ax.set_ylim([0, 10.5])
ax.set_xticks([])
ax.set_yticks([])
f = '947t' + '.svg'
plt.savefig(f, bbox_inches='tight')
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment