| name | thermodynamics |
| description | Thermodynamic principles including laws of thermodynamics, entropy, free energy, phase transitions, heat engines, and statistical foundations for physics and engineering. |
| category | physics |
| tags | ["physics","thermodynamics","entropy","free-energy","heat-engines","phase-transitions","statistical-mechanics"] |
| difficulty | intermediate |
| author | neuralblitz |
Thermodynamics
What I do
I provide comprehensive expertise in thermodynamics, the branch of physics describing heat, work, and energy transformations. I enable you to apply the laws of thermodynamics, compute entropy and free energy, analyze heat engines and refrigerators, study phase transitions, work with thermodynamic potentials, and apply statistical interpretations. My knowledge spans from macroscopic laws to statistical foundations essential for engineering, chemistry, materials science, and physics.
When to use me
Use thermodynamics when you need to: analyze heat engine efficiency and cycles, calculate equilibrium properties of systems, study phase diagrams and phase transitions, compute chemical reaction spontaneity, design refrigeration and HVAC systems, analyze thermodynamic stability, calculate properties of gases and materials, or apply statistical mechanics to derive macroscopic laws.
Core Concepts
- Zeroth Law of Thermodynamics: Thermal equilibrium defines temperature and allows thermometers to measure it.
- First Law of Thermodynamics: Conservation of energy with heat (Q) and work (W) as energy transfer modes (ΔU = Q - W).
- Second Law of Thermodynamics: Entropy always increases in isolated systems with heat engines having maximum Carnot efficiency.
- Third Law of Thermodynamics: Entropy approaches a constant minimum (zero for perfect crystals) as T → 0.
- Entropy and Disorder: Statistical measure of microscopic configurations consistent with macroscopic state.
- Thermodynamic Potentials: Internal energy (U), enthalpy (H), Helmholtz free energy (F), and Gibbs free energy (G).
- Phase Transitions: Changes between states of matter with latent heat and discontinuities in derivatives of free energy.
- Carnot Cycle: Maximum possible efficiency for heat engines operating between two temperature reservoirs.
- Maxwell Relations: Derivatives of thermodynamic potentials connected through equality of mixed partials.
- Statistical Interpretation: Entropy as S = k_B ln(Ω) connecting microscopic and macroscopic descriptions.
Code Examples
Thermodynamic Laws and Cycles
import numpy as np
def first_law(Q, W):
"""Calculate internal energy change."""
return Q - W
def work_pressure_volume(P, V1, V2):
"""Isothermal work: W = ∫PdV = nRT ln(V2/V1)"""
return P * V2 - P * V1
def isothermal_work(n, R, T, V1, V2):
"""Work in isothermal expansion."""
return n * R * T * np.log(V2 / V1)
def adiabatic_work(n, R, T1, V1, V2, gamma):
"""Work in adiabatic expansion."""
return n * R * (T1 - T2) / (gamma - 1)
def adiabatic_temperature(T1, V1, V2, gamma):
"""TV^(γ-1) = constant."""
return T1 * (V1 / V2)**(gamma - 1)
R = 8.314
gamma = 1.4
print("First law examples:")
n = 1
T1 = 300
V1, V2 = 1, 2
T2 = adiabatic_temperature(T1, V1, V2, gamma)
W_adi = adiabatic_work(n, R, T1, V1, V2, gamma)
print(f" Adiabatic expansion V1→2V1 at T=K:")
()
()
():
- T_cold / T_hot
():
T_cold / (T_hot - T_cold)
T_hot, T_cold = ,
eta_carnot = carnot_efficiency(T_hot, T_cold)
cop_carnot = carnot_refrigerator_coefficient(T_cold, T_hot)
()
()
()
()
():
- / (r**(gamma - ))
():
- ( / r**(gamma - )) * (cutoff**gamma - ) / (gamma * (cutoff - ))
compression_ratio [, , ]:
eta = otto_cycle_efficiency(compression_ratio, gamma)
()
Entropy Calculations
import numpy as np
from scipy.integrate import quad
def entropy_change_isothermal(n, R, V2, V1):
"""ΔS = nR ln(V2/V1) for isothermal expansion."""
return n * R * np.log(V2 / V1)
def entropy_change_temperature(n, Cv, T2, T1):
"""ΔS = ∫dQ_rev/T = ∫Cv dT/T = Cv ln(T2/T1)"""
return n * Cv * np.log(T2 / T1)
def entropy_of_mixing(n1, n2, V1, V2):
"""Entropy of mixing two ideal gases."""
return n1 * R * np.log((V1 + V2) / V1) + n2 * R * np.log((V1 + V2) / V2)
n = 1
Cv = (3/2) * R
T1, T2 = 300, 600
V1, V2 = 1, 2
S_heat = entropy_change_temperature(n, Cv, T2, T1)
S_expand = entropy_change_isothermal(n, R, V2, V1)
print("Entropy calculations:")
print(f" Heating 1 mol from 300K to 600K: ΔS = {S_heat:.2f} J/K")
print(f" Isothermal expansion V→2V: ΔS = {S_expand:.2f} J/K")
print(f" Total ΔS: {S_heat + S_expand:.2f} J/K")
():
kB =
kB * np.log(omega)
omega = **
S_coins = boltzmann_entropy(omega)
()
()
()
()
():
* n * R * np.log((V1 + V2) / V1)
()
()
()
():
S_liquid =
S_ice =
S_vapor =
phase == :
S_liquid
phase == :
S_ice
:
S_vapor
()
()
()
Free Energy and Equilibrium
import numpy as np
def helmholtz_free_energy(T, V, n, U):
"""F = U - TS"""
return U - T * S
def gibbs_free_energy(T, P, n, H):
"""G = H - TS"""
return H - T * S
def gibbs_free_energy_reaction(T, dH, dS):
"""ΔG = ΔH - TΔS"""
return dH - T * dS
def reaction_spontaneity(dG):
"""Check if reaction is spontaneous."""
return dG < 0
def equilibrium_constant(dG, T, R=8.314):
"""K = exp(-ΔG°/RT)"""
return np.exp(-dG / (R * T))
dH_reaction = -92.4e3
dS_reaction = -198.7
T_298 = 298
dG_298 = gibbs_free_energy_reaction(T_298, dH_reaction, dS_reaction)
K_298 = equilibrium_constant(dG_298, T_298)
print("Gibbs free energy (Haber process):")
print(f" ΔH° = {dH_reaction/1000:.1f} kJ/mol")
print(f" ΔS° = {dS_reaction:.1f} J/(mol·K)")
print()
()
T [, , , , ]:
dG = gibbs_free_energy_reaction(T, dH_reaction, dS_reaction)
K = equilibrium_constant(dG, T)
()
():
np.log(K2/K1) == -dH/R * (/T2 - /T1)
():
():
mu0 + R * T * np.log(P / )
():
phi * P
()
mu0_N2 = -
P [, , ]:
mu = chemical_potential(, P * , mu0_N2)
()
Phase Transitions
import numpy as np
def clausius_clapeyron(dH, T, dV, R=8.314):
"""dP/dT = ΔH/(TΔV)"""
return dH / (T * dV)
def vapor_pressure_clausius(T, P1, T1, dH_vap):
"""ln(P2/P1) = -ΔH_vap/R (1/T2 - 1/T1)"""
return P1 * np.exp(-dH_vap/R * (1/T2 - 1/T1))
def critical_properties(Tc, Pc):
"""Estimate critical properties."""
Pc_atm = Pc / 1.013e5
a = 27 * R**2 * Tc**2 / (64 * Pc)
b = R * Tc / (8 * Pc)
return a, b
def reduced_properties(T, P, Tc, Pc):
"""Tr = T/Tc, Pr = P/Pc"""
return T / Tc, P / Pc
def law_of_rectilinear_diameters(T, T_c, rho_l_c, rho_v_c):
"""ρ_liq + ρ_vap = 2ρ_c + A(T_c - T)"""
A = 0.5
return rho_l_c + rho_v_c, 2 * rho_v_c + A * (T_c - T)
Tc_water = 647.1
Pc_water = 22.06e6
dH_vap_water = 40.7e3
()
()
P1 =
T1 =
dH_vap =
T [, , , , ]:
P_vap = vapor_pressure_clausius(T, P1, T1, dH_vap)
()
dH =
T =
dV =
dP_dT = clausius_clapeyron(dH, T, dV)
()
()
():
C - P +
()
()
()
()
Thermodynamic Cycles Analysis
import numpy as np
def rankine_cycle_efficiency(T_boiler, T_condenser, eta_pump=0.8):
"""
Rankine cycle (steam power plant) efficiency.
η = 1 - Q_out/Q_in
"""
T_hot = T_boiler + 273.15
T_cold = T_condenser + 273.15
eta_carnot = 1 - T_cold / T_hot
return eta_carnot * eta_pump
def rankine_work_output(T_boiler, T_condenser, m_dot, h1, h2, h3, h4):
"""
Calculate work output per unit mass flow.
W = (h1 - h2) + (h3 - h4)
"""
turbine_work = h1 - h2
pump_work = h3 - h4
return m_dot * (turbine_work - pump_work)
def heat_pump_cop(T_cold, T_hot, eta):
"""COP = T_cold/(T_hot - T_cold) for ideal."""
return T_cold / (T_hot - T_cold)
T_boiler = 500
T_condenser = 40
eta_rankine = rankine_cycle_efficiency(T_boiler, T_condenser)
print(f"Rankine cycle efficiency:")
print(f" T_boiler = {T_boiler}°C, T_condenser = {T_condenser}°C")
print(f" Ideal efficiency: {eta_rankine*100:.1f}%")
def ():
r = (T3 / T1)**(gamma / (gamma - ))
T4 = T3 / r**((gamma - ) / gamma)
T2 = T1 * r**((gamma - ) / gamma)
eta_ideal = - (T4 - T3) / (T2 - T1)
eta_ideal * eta_c * eta_t
T1, T3 = ,
r_pressure [, , , ]:
eta = brayton_cycle_efficiency(T3, T3, T1, T1)
()
():
carnot_efficiency(T_hot, T_cold)
():
eta_brayton + ( - eta_brayton) * eta_rankine_bottom
eta_cc = combined_cycle_efficiency(, )
()
()
Best Practices
- Always specify the system boundaries when applying thermodynamic laws to avoid confusion between system and surroundings.
- Use proper sign conventions consistently: work done BY system is positive, heat added TO system is positive.
- For irreversible processes, calculate entropy generation and distinguish between reversible and irreversible contributions.
- When analyzing cycles, calculate both thermal efficiency and second-law efficiency to identify irreversibilities.
- Apply the most appropriate thermodynamic potential for given constraints (constant S,V → U; constant S,P → H; constant T,V → F; constant T,P → G).
- For phase transitions, be aware of metastable states and nucleation barriers in first-order transitions.
- Use tabulated thermodynamic data for accuracy; empirical correlations introduce errors.
- In numerical calculations, ensure units are consistent (SI units recommended).
- For mixtures, use partial molar quantities and activity coefficients for non-ideal behavior.
- Remember that the third law establishes a reference point for absolute entropy but does not prevent negative heat capacities.