I'm calculating molecular volume using a cubic EoS (peng robinson), so I need to solve the implicit function. I am trying to use pass rootfinder as a function so it can calculate volume/pressure given temperature and pressure/volume as input, but I keep getting the following error:
Wrong number or type of arguments for overloaded function 'Function_call'.
Possible prototypes are:
call(self,dict:DM,bool,bool)
call(self,[DM],bool,bool)
call(self,[SX],bool,bool)
call(self,dict:SX,bool,bool)
call(self,dict:MX,bool,bool)
call(self,[MX],bool,bool)
You have: '(Function,([SX],[int|SX]))'
The code follows below
R=8314;
g=9.81;mi=3.64e-3;
rho_l=760;Mg=16.7;
Ta=348;Va=64.34;
y=SX.sym('y',4)
z = SX.sym('x_PR',3)#0 is temperature, 1 is pressure, 2 is volume
Tc_PR=190.6;
Pc_PR=46.04*1.013e5;
w_PR=0.011;
R_PR=8.314;
a_PR=0.45724*(R_PR**2)*Tc_PR**2/Pc_PR;
b_PR=0.07780*R_PR*Tc_PR/Pc_PR;
k_PR=0.3764+1.54226*w_PR-0.26992*w_PR**2;
alpha_PR=(1+k_PR*(1-sqrt(z[0]/Tc_PR)))**2;
#p_PR=R_PR.*T./(V_PR-b_PR)-alpha_PR*a_PR./(V_PR.**2+2*b_PR.*V_PR-b_PR.**2);
PengRobinson=z[1]-R_PR*z[0]/(z[2]-b_PR)-alpha_PR*a_PR/(z[2]**2+2*b_PR*z[2]-b_PR**2);
PReosP1=Function("f1", [z[1],vertcat(z[0],z[2])],[PengRobinson])
PReosV1=Function("f2", [z[2],vertcat(z[0],z[1])],[PengRobinson])
PReosP=rootfinder("PReosP",'kinsol' ,PReosP1)
PReosV=rootfinder("PReosV", 'kinsol' ,PReosV1)
#those are some tests to see if it works
print(PReosP([100], [300,0.01]))
print(PReosP([200], [400,0.01]))
print(PReosP1([252064], [300,0.01]))
print(PReosP1([335102], [400,0.01]))
print(PReosV([0.01], [400,335102]))
#%%
#where the error happens
Pat=PReosP([R*Ta*y[0]/(Mg*Va)],[Ta,(Mg*Va)/(y[0]*1000)]);