Created
July 19, 2023 09:54
-
-
Save shakayami/b858bb113423b471eeaa29a8bd22622c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from fractions import Fraction | |
def in_out_heat(a,b,c,d): | |
A=4*(c-a)*(d-b) | |
B=b*(c-a)*Fraction(3,2)+a*(d-b)*Fraction(5,2) | |
if B*(A+B)>=0: | |
dU=Fraction(3,2)*(c*d-b*a) | |
dW=(b-d)*(a+c)*Fraction(1,2) | |
dQ=dU-dW | |
if B>=0 and A+B>=0: | |
return (dQ,0) | |
else: | |
return (0,-dQ) | |
else: | |
t0=Fraction(-B,A) | |
x=(c-a)*t0+a | |
y=(d-b)*t0+b | |
dQin1,dQout1=in_out_heat(a,b,x,y) | |
dQin2,dQout2=in_out_heat(x,y,c,d) | |
return (dQin1+dQin2,dQout1+dQout2) | |
def thermal_efficiency(cycle): | |
N=len(cycle) | |
Work=0 | |
for i in range(N): | |
a=cycle[i][0] | |
b=cycle[i][1] | |
c=cycle[(i+1)%N][0] | |
d=cycle[(i+1)%N][1] | |
dW=(b-d)*(a+c)*Fraction(1,2) | |
Work+=dW | |
if Work>0: | |
return None | |
IN=0 | |
OUT=0 | |
for i in range(N): | |
a=cycle[i][0] | |
b=cycle[i][1] | |
c=cycle[(i+1)%N][0] | |
d=cycle[(i+1)%N][1] | |
dQin,dQout=in_out_heat(a,b,c,d) | |
IN+=dQin | |
OUT+=dQout | |
return 1-Fraction(OUT,IN) | |
cycle=[(1,1),(2,1),(2,2),(1,2)] | |
print(thermal_efficiency(cycle)) | |
#2/13 | |
cycle=[(1,1),(2,1),(1,2)] | |
print(thermal_efficiency(cycle)) | |
#16/97 | |
cycle=[(1,1),(2,2),(1,2)] | |
print(thermal_efficiency(cycle)) | |
#1/12 | |
cycle=[(1,1),(2,1),(2,2)] | |
print(thermal_efficiency(cycle)) | |
#1/13 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment