usnistgov / REFPROP-wrappers

Wrappers around NIST REFPROP for languages such as Python, MATLAB, etc.
193 stars 127 forks source link

Convergence issue #548

Closed KesriNandan closed 6 months ago

KesriNandan commented 1 year ago

Description

I am using MATLAb interface for REFPROP with mixtures. It is generating one error regularly.

[PHFLSH error 248] Single-phase iteration did not converge for P = 6.85002 MPa and H = 13499.6 J/mol. Error in Cond4_Vapor (line 64)

'''T_WF_2phase(i)=refpropm('T','P',P_1,'H',h_2phase_v(i),comp1,comp2,fraction);'''

But if I check the REFPROP , in there it gives the value . What could be the reason? If anyone has any idea it would mean a lot. Thanks in advance

Expected behavior: [What you expect to happen]

Actual behavior: [What actually happens]

Versions

REFPROP Version: 10.0 a Operating System and Version: Windows 11
Access Method:** [MATLAB]
image

ianhbell commented 1 year ago

refpropm is no longer supported. Please switch to the python interface, which will give you the ability to call SATSPLNdll which should help.

KesriNandan commented 1 year ago

refpropm is no longer supported. Please switch to the python interface, which will give you the ability to call SATSPLNdll which should help.

Thankyou for your swift response. As you have suggested I have started working with python interface. I will let you know if that works.

KesriNandan commented 1 year ago

Hi Ian, @ianhbell diary.txt

I have some doubts related to python wrapper implementation. I am calculating enthalpy values of a mixture (CO2R32) by keeping the inputs pressure and entropy. While running the code it changes the value slightly. and when running the function on command window, first it gives the wrong value but if you change something in the function then it gives the right value. iFlag =1 , iUnits =21, Mixture = (CO2R32), s_2s = 1.3365e+03 r=RP.REFPROPdll( Mixture, 'PS', 'H', iUnits, iMass, iFlag,20000000,s_2s, fraction).Output(1) I am attaching a diary of MATLAB where you will understand how it proceeds.

I think it is giving the value of enthalpy in Molar base even if the iMass =1 . What should i do?

Will be really grateful to you if this is solved. Thanks in advance

KesriNandan commented 1 year ago
clear;  
close all

%To initialize REFPROP, you tell it what the root path of your REFPROP installation is:
RP = py.ctREFPROP.ctREFPROP.REFPROPFunctionLibrary('C:\Program Files (x86)\REFPROP') ; 
%to confirm that everything is working correctly, let's print out the version of REFPROP that you have loaded:
RP.RPVersion()

iUnits = RP.MASS_BASE_SI;  
iMass = int8(1); % 0: molar fractions; 1: mass fractions
iFlag = int8(1); % 0: don't call SATSPLN; 1: call SATSPLN

% environment parameters: 
T_0 = 24+273.15; 
P_0 = 100000;  
% Heat source parameters:
HS_Pr=100000; 
HS_T_in=210+273.15;
HS_fluid='air'; 
% Heat SINK parameters:
SS_Pr=100000; 
SS_T_in=24+273.15;  
SS_fluid='water';  
% cycle parameters:
eta_Turb = 0.65; 
eta_pump = 0.85; 
MFR_WF =  1; 
T_Cond_exit = 30 + 273.15;  
Mixture= 'CO2*R32';
T_PP=5;     
delT_HS_Turb_in = 10;  
T_Turb_in= 473.15;       
fraction={0.9 0.1};

    % Critical Temperature: (K)
    r1 = RP.REFPROPdll( Mixture,'CRIT','P,T',iUnits,iMass,iFlag,0,0,fraction);  % to get the critical pr and Temp of the mixture
    PC= double(r1.Output(1));
    TC = double(r1.Output(2));

    r2= RP.REFPROPdll( Mixture, 'TQ', 'P,H,S', iUnits, iMass, iFlag, T_Cond_exit, 0, fraction);
    P_1= double(r2.Output(1));  % to get the condenser pr using condenser exit temp & quality 
    h_1= double(r2.Output(2)) % to get the h_1 (enthalpy) at pump inlet 
    s_1= double(r2.Output(3));

    j=1;
    for P=25:-1:5  % the lowest limit is kept as 5 as P_1 is 4.43 MPa at T_Cond_exit  = 30 oC    

        P3 = P*(10^6); % to convert into Pa        

        s_2s=s_1 % isentropic condition

            r11=RP.REFPROPdll( Mixture, 'PS', 'H', iUnits, iMass, iFlag,P3,s_1, fraction);
            h_2s= double(r11.Output(1))
            h_2a=h_1 + ((h_2s-h_1)/0.85); 

            r22=RP.REFPROPdll( Mixture, 'PH', 'S', iUnits, iMass, iFlag,P3,h_2a, fraction);
            s_2a=double(r22.Output(1)); 

             r33= RP.REFPROPdll( Mixture, 'TP', 'H,S', iUnits, iMass, iFlag,T_Turb_in, P3, fraction);
            h_3=double(r33.Output(1)); % enthalpy @Turb.inlet using guessed T3, P3.
            s_3=double(r33.Output(2)); % entropy @Turb.inlet using guessed T3, P3.

            s_4s= s_3; % isentropic condition
            r44=RP.REFPROPdll( Mixture, 'PS', 'H', iUnits, iMass, iFlag,P_1,s_4s, fraction);
            h_4s= double(r44.Output(1)); 

            h_4a=h_3-0.6*(h_3-h_4s); 

            r55=RP.REFPROPdll( Mixture, 'PH', 'S,T', iUnits, iMass, iFlag,P_1,h_4a, fraction);
            x_4= double(r55.q);
            s_4a=double(r55.Output(1));
            T_4a=double(r55.Output(2));

            r66=RP.REFPROPdll( Mixture, 'PQ', 'S,H', iUnits, iMass, iFlag,P_1,1, fraction);
            s_5=double(r66.Output(1));
            h_5= double(r66.Output(2));

            x4_temp1(P,1)=x_4;             

            if x_4>0.9                

               [UA_Ev_avg]= RP_Py_Evap1(RP,h_3,h_2a,P3,Mixture,iUnits,iMass,iFlag,fraction,HS_T_in,s_3,s_2a,T_PP,HS_Pr);

            j=j+1

            end 

        end
    %end   
q=q+1

@ianhbell This is is the code I am working on. The value of h_2s change after the loop when Py_Evap function runs. when I comments the Py_Evap1 function then it gives the correct value however when it runs it gives the incorrect values.

ianhbell commented 1 year ago

Please reduce your example to the minimal set of code demonstrating the problem. There is too much to sort through.

KesriNandan commented 1 year ago

Please reduce your example to the minimal set of code demonstrating the problem. There is too much to sort through.

I have reduced the code and the function file for this program. I also sent you the mail from bhawandeepsharma@gtiit.edu.cn which includes the function file .

ianhbell commented 1 year ago

What is needed is an even simpler example that doesn't call to your own RP_Py_Evap1. One thing I note from your example is that you jump from mixture to air and back (makes sense because you have a HX), but that could cause problems. I recommend to use CoolProp for the air as a pseudo-pure fluid, and do all the refrigerant properties with REFPROP, so that you never need to re-initialize the mixture. Also makes sure you are using the saturation splines.

KesriNandan commented 1 year ago

I am trying to reduce it as suggested but combining the function makes it even bigger so I am working on it. Can i use Refpropm function instead of Coolprop? Also, I am using iFlag=1 and in the documentation it says it means satspline is On. is it correct? or is there nay other way to use the saturation spline.

ianhbell commented 1 year ago

No, refpropm is deprecated and no longer supported.

Yes, that is how to turn on saturation splines.