function s=eos(T,rho,f) % Leachman Helmholtz EOS, evaluated natively in MATLAB (not ideal gas). % Coefficients pinned by SHA256 from CoolProp fluid JSON; no CoolProp binary. assert(T>=f.Tmin&&T<=f.Tmax&&rho>0,'EOS input outside declared domain.'); delta=rho/f.rhoc;tau=f.Tc/T; a0=log(delta);a0t=0; for k=1:numel(f.EOS.alpha0) q=f.EOS.alpha0{k}; switch q.type case 'IdealGasHelmholtzLead' a0=a0+q.a1+q.a2*tau;a0t=a0t+q.a2; case 'IdealGasHelmholtzLogTau' a0=a0+q.a*log(tau);a0t=a0t+q.a/tau; case 'IdealGasHelmholtzPlanckEinsteinFunctionT' theta=q.v(:)/f.Tc;nn=q.n(:);z=theta*tau; a0=a0+sum(nn.*log(-expm1(-z))); a0t=a0t+sum(nn.*theta./expm1(z)); otherwise,error('Unsupported ideal EOS term: %s',q.type); end end ar=0;ard=0;art=0; for k=1:numel(f.EOS.alphar) q=f.EOS.alphar{k};nn=q.n(:);dd=q.d(:);tt=q.t(:); switch q.type case 'ResidualHelmholtzPower' ll=q.l(:);damp=ones(size(ll));ix=ll>0;damp(ix)=exp(-delta.^ll(ix)); v=nn.*delta.^dd.*tau.^tt.*damp; ld=dd/delta;ld(ix)=ld(ix)-ll(ix).*delta.^(ll(ix)-1); ar=ar+sum(v);ard=ard+sum(v.*ld);art=art+sum(v.*tt/tau); case 'ResidualHelmholtzGaussian' eta=q.eta(:);ep=q.epsilon(:);bt=q.beta(:);ga=q.gamma(:); v=nn.*delta.^dd.*tau.^tt.*exp(-eta.*(delta-ep).^2-bt.*(tau-ga).^2); ar=ar+sum(v);ard=ard+sum(v.*(dd/delta-2*eta.*(delta-ep))); art=art+sum(v.*(tt/tau-2*bt.*(tau-ga))); otherwise,error('Unsupported residual EOS term: %s',q.type); end end p=rho*f.R*T*(1+delta*ard);u=f.R*T*tau*(a0t+art); h=f.R*T*(1+tau*(a0t+art)+delta*ard); g=f.R*T*(1+a0+ar+delta*ard); s=struct('T_K',T,'rho_kg_m3',rho,'p_Pa',p,'u_J_kg',u,'h_J_kg',h,'g_J_kg',g,'phase','single_phase'); end