Since calling functions in the externalmedia library is slightly complicated, I created a function to call directly, but the following warning appears.
Public component state.eta was neither input nor output
in function user.pT.h_pT.
Component context: state.eta
Component declared as DynamicViscosity eta in Modelica.Media.Interfaces.Types
File: C:/Users/Yao/Desktop/ExternalMedia/Media/BaseClasses/ExternalTwoPhaseMedium.mo, line 49
The following illustration is an example of a function.
model sss
parameter Real h1=3000;
parameter Real T=600;
Real p1;
equation
h1*1000=user.pT.h_pT(
p1,
T,
0);
end sss;
function h_pT
extends Modelica.Icons.Function;
input user.total.Medium.AbsolutePressure p "Pressure";
input user.total.Medium.Temperature T "Temperature";
input user.total.Medium.FixedPhase phase = 0
"2 for two-phase, 1 for one-phase, 0 if not known";
user.total.Medium.ThermodynamicState state;
output user.total.Medium.SpecificEnthalpy h;
algorithm
state:= user.total.Medium.setState_pT(
p,
T,
phase);
h:=state.h;
end h_pT;
function total
package Medium
extends ExternalMedia.Media.CoolPropMedium(
mediumName = "Water");
end Medium;
end total;
I don't know how to solve these problems and would very much like your answer.
As indicated by the error message the solution is to make state
protected:
function h_pT
extends Modelica.Icons.Function;
input user.total.Medium.AbsolutePressure p "Pressure";
input user.total.Medium.Temperature T "Temperature";
input user.total.Medium.FixedPhase phase = 0
"2 for two-phase, 1 for one-phase, 0 if not known";
protected
user.total.Medium.ThermodynamicState state;
public
output user.total.Medium.SpecificEnthalpy h;
algorithm
state:= user.total.Medium.setState_pT(
p,
T,
phase);
h:=state.h;
end h_pT;