我正在做一个柴油循环图,我想找出如何使我的滑块只影响一个图表,即.当你改变压缩比的值时,T-S图不应该改变.
以下是我的代码:
import numpy as np
import math
import plotly.io as pio
from plotly.subplots import make_subplots
pio.renderers.default='browser'
# Constants and assumptions
bore = .078
stroke = .062
vd = math.pi * (bore/2)**(2) * stroke
rk = 15 #typical compression ratio for small diesel engines
V2 = vd / (rk - 1)
V1 = rk * V2
T1 = 300 #kelvin assumed atmospheric
P1 = 101.325 #kpa assumed athmospheric
k = 1.4 #assumed ideal gas
rc = 2.5 #for high efficiency operation
S1 = 10 #change. for testing
cp = 1.0038
cv = 0.717
# equations based on value
P2 = P1 * (rk)**k
T2 = T1 * (rk)**(k-1)
P3 = P2
T3 = rc * T2
V3 = V2 * rc
V4 = V1
P4 = P3 * (V3 / V4)**k
T4 = T3 * (P4 / P3)**((k-1)/k)
m = (P1*V1)/(0.287*T1)
S3 = S1 + m * cp * np.log(T3/T2)
V = [V1]
P = [P1]
T = [T1]
S = [S1]
points12 = 100
points34 = 100
points23 = 100
points41 = 100
for i in range(1, points12 + 1):
Vi = V1 * (V2 / V1) ** (i / points12)
Pi = P1 * (V1 / Vi) ** k
V.append(Vi)
P.append(Pi)
for i in range(0, points23 + 1):
Ti = T2 * (T3 / T2) ** (i / points23)
Si = S1 + m * cp * np.log(Ti / T2)
T.append(Ti)
S.append(Si)
for i in range(0, points34 + 1):
Vi = V3 * (V4 / V3) ** (i / points34)
Pi = P3 * (V3 / Vi) ** k
V.append(Vi)
P.append(Pi)
for i in range(0, points41 + 1):
Ti = T4 * (T1 / T4) ** (i / points41)
Si = S3 + m * cv * np.log(Ti / T4)
T.append(Ti)
S.append(Si)
V.extend([V1, V1])
P.extend([P1, P1])
T.extend([T1, T1])
S.extend([S1, S1])
fig = make_subplots(cols=2)
slider_steps = []
for rk in range(10, 31):
V2 = vd / (rk - 1)
V1 = rk * V2
P2 = P1 * (rk)**k
T2 = T1 * (rk)**(k-1)
P3 = P2
T3 = rc * T2
V3 = V2 * rc
V4 = V1
P4 = P3 * (V3 / V4)**k
T4 = T3 * (P4 / P3)**((k-1)/k)
V = [V1]
P = [P1]
effi = (1-(1/(rk**(k-1)))*((((rc)**k)-1)/(k*(rc-1))))*100
clr= V2*1000000
# Recalculate the points using the new rk value
for i in range(1, points12 + 1):
Vi = V1 * (V2 / V1) ** (i / points12)
Pi = P1 * (V1 / Vi) ** k
V.append(Vi)
P.append(Pi)
# for i in range(1, points23 + 1):
# Ti = T2 * (T3 / T2) ** (i / points23)
# Si = S1 + m * cp * np.log(Ti / T2)
# T.append(Ti)
# S.append(Si)
for i in range(0, points34 + 1):
Vi = V3 * (V4 / V3) ** (i / points34)
Pi = P3 * (V3 / Vi) ** k
V.append(Vi)
P.append(Pi)
# for i in range(1, points41 + 1):
# Ti = T4 * (T1 / T4) ** (i / points41)
# Si = S3 + m * cv * np.log(Ti / T4)
# T.append(Ti)
# S.append(Si)
V.extend([V1, V1])
P.extend([P1, P1])
# T.extend([T1, T1])
# S.extend([S1, S1])
step = dict(
method="update",
label=f"rk = {rk} engine efficiency in percent: {effi} clearance/combustion chamber vol: {clr}cm^3 cut off ratio: {rc} mass={m}",
args=[{"y": [P], "x": [V]}],
)
slider_steps.append(step)
sliders = [
dict(
active=15,
currentvalue={"prefix": "Compression Ratio (rk): "},
pad={"t": 50},
steps=slider_steps,
)
]
fig.add_scatter(x=V, y=P, mode='lines+markers', name= 'Diesel Cycle PV', row=1, col=1)
fig.add_scatter(x=S, y=T, mode='lines+markers', name='Diesel Cycle TS', row=1, col=2)
fig.update_layout(
sliders=sliders,
title='Diesel Cycle P-V Diagram',
xaxis=dict(title='Volume (m^3)'),
yaxis=dict(title='Pressure (kPa)'),
)
fig.show()
问题:只要我移动滑块,t-S曲线图就变成了p-v曲线图的副本.
目前,我刚刚开始学习ploly和python,所以我对这段代码仍然不太确定,我需要对它进行更多的研究.最初的代码是由ChatGPT写的,我研究了几天,然后在网上寻找关于如何用LOOP绘制等熵曲线以及如何添加第二个曲线图的信息.
我对step = dict( args=[{"y", [P]], "x": [V]}])
有怀疑,我也需要帮助,了解如何指定要更新哪个曲线图的哪个x和y.