I wrote a code in ANSYS Twin Builder using Modelica. It throws me an error: "Calling function Medium.density(): can only call functions that have one algorithm section or external function specification " Would you help me why this error arises ? Thanks..
//Component(s)
Real f[2*T_per/(T_per/10)];
Real time_interval;
parameter Real opening_HP;
Real opening_NP;
parameter Real N;
parameter Real T_per;
parameter Real V_tod;
parameter Real V_unten;
Modelica.Fluid.Valves.ValveIncompressible NP (
dp_nominal = 65.21,
opening = opening_NP,
rho_nominal = 998.388,
Kv = 0.02178066,
V_flow(start = 0.0000488573),
dp = dp(start = 65.211094),
m_flow(start = 0.048778537));
Modelica.Fluid.Valves.ValveIncompressible HP (
Kv = 0.021549519,
opening=opening_HP,
dp_nominal = 66.6175,
rho_nominal = 1019.921,
V_flow(start = 0.0000478258),
dp(start = 66.6175),
m_flow(start = 0.048778537));
Modelica.Fluid.Machines.SweptVolume Swept1 (pistonCrossArea = 0.0001131, clearance = 0.000002, portsData = false);
Modelica.Fluid.Vessels.OpenTank tank (vessel_ps_static = 400000);
Modelica.Fluid.Vessels.OpenTank tank1 (vessel_ps_static = 50000000);
equation
T_per=pi/(180*3600*N/60);//Radian
time_interval=T_per/10;
for i in 1:2*T_per/(T_per/10) loop
f[i]=((V_unten_V_tod)/2)*sin((2*pi*i*time_interval/T_per)+(V_tod+(V_unten-V_tod)/2));
end for;
if der(f)>=0 then
opening_NP=1;
opening_HP=0;
else
opening_NP=0;
opening_HP=1;
end if;
//Connection(s)
connect(NP.port_a, Swept1.ports[1]);
connect(HP.port_b, Swept1.ports[2]);
connect(HP.opening, tank1.ports[1]);
connect(NP.opening, tank.ports[1]);
end Hochdruckreiniger2;
It seems you have not selected medium for Fluid-models, in Modelica you normally do that by modifying as follows:
(For NP, HP, tank and tank1.)
Without that the Medium is PartialMedium where Medium.density is a partial function with neither algorithm nor external call.
Note that other tools will detect this in various other ways, and technically calling a function with neither algorithm nor external call is legal since Modelica 3.3 (provided the output variables have declaration assignments - which they don't in this case).
Additionally
dp=dp(start=...)
should be justdp(start=...)
, andvessel_ps_static
shouldn't be changed like that.