I tried to create a new liquid medium by copying and modifying the TemplateMedium package. My liquid has a constant density and its viscosity is a function of temperature alone. However, when I try to include the model as a medium I get the error pasted below:
Internal error NFCeval.evalRelationEqual failed to evaluate ‘boundary.Medium.ThermoStates == Modelica.Media.Interfaces.Choices.IndependentVariables.dTX
The modified TemplateMedium package with my liquid info is: package viscOil "oil with constant density and temp dependent visc."
package viscOil "oil with constant density and temp dependent visc."
extends Modelica.Media.Interfaces.PartialMedium(
final mediumName="viscOil",
final substanceNames={mediumName},
final singleState=false,
final reducedX=true,
final fixedX=true,
Temperature(
min=-54,
max=473,
start=293));
// Provide medium constants here
constant SpecificHeatCapacity cp_const=2000
"Constant specific heat capacity at constant pressure";
redeclare model extends BaseProperties(final standardOrderComponents=true)
"Base properties of medium"
equation
d = 1003.5;
h = cp_const*T;
u = h - p/d;
MM = 0.024;
R_s = Modelica.Constants.R/MM;
state.p = p;
state.T = T;
end BaseProperties;
redeclare replaceable record ThermodynamicState
"A selection of variables that uniquely defines the thermodynamic state"
extends Modelica.Icons.Record;
AbsolutePressure p "Absolute pressure of medium";
Temperature T "Temperature of medium";
end ThermodynamicState;
redeclare function extends dynamicViscosity "Return dynamic viscosity"
algorithm
eta := 1003.5 * exp((3.25*(10^8)*(1.0/state.T)^3) + (-1869808.0*(1.0/state.T)^2) + (5696.648*(1.0/state.T)) - 6.49291);
end dynamicViscosity;
redeclare function extends thermalConductivity
"Return thermal conductivity"
algorithm
lambda := 0;
end thermalConductivity;
redeclare function extends specificEntropy "Return specific entropy"
algorithm
s := 0;
end specificEntropy;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure"
algorithm
cp := 0;
end specificHeatCapacityCp;
redeclare function extends
specificHeatCapacityCv
"Return specific heat capacity at constant volume"
algorithm
cv := 0;
end specificHeatCapacityCv;
redeclare function extends isentropicExponent "Return isentropic exponent"
extends Modelica.Icons.Function;
algorithm
gamma := 1;
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
algorithm
a := 0;
end velocityOfSound;
end viscOil;
I understand the error is related to defining the thermodynamic state. In my case it is only governed by one variable. How do I resolve it?
I tried to turn final reducedX to false and also turn final fixedX to false, but neither of them worked.
The error message you have in your question is due to the lack of the specific enthalpy and setState_pTX, the error mentioned in your question should be resolved with the model below.
However, some/most components in the MSL Fluid library seems to require compressability in the fluid that is used (as discussed here in another SO post). So you may run into some problems related to that unless you give it a small amount of compressibility.
package viscOil "oil with constant density and temp dependent visc."
extends Modelica.Media.Interfaces.PartialMedium(final mediumName = "viscOil", final substanceNames = {mediumName}, final singleState = false, final reducedX = true, final fixedX = true, Temperature(min = -54, max = 473, start = 293));
// Provide medium constants here
constant SpecificHeatCapacity cp_const = 2000 "Constant specific heat capacity at constant pressure";
redeclare model extends BaseProperties(final standardOrderComponents = true) "Base properties of medium"
equation
d = 1003.5;
h = cp_const*T;
u = h - p/d;
MM = 0.024;
R_s = Modelica.Constants.R/MM;
state.p = p;
state.T = T;
end BaseProperties;
redeclare replaceable record ThermodynamicState "A selection of variables that uniquely defines the thermodynamic state"
extends Modelica.Icons.Record;
AbsolutePressure p "Absolute pressure of medium";
Temperature T "Temperature of medium";
end ThermodynamicState;
redeclare function extends setState_pTX
algorithm
state := ThermodynamicState(p = p,T = T);
end setState_pTX;
redeclare function extends setState_phX
algorithm
state := ThermodynamicState(p=p,T = h / cp_const);
end setState_phX;
redeclare function extends specificEnthalpy "Return SpecificEnthalpy"
algorithm
h := cp_const*state.T;
end specificEnthalpy;
redeclare function extends dynamicViscosity "Return dynamic viscosity"
algorithm
eta := 1003.5*exp((3.25*(10^8)*(1.0/state.T)^3) + (-1869808.0*(1.0/state.T)^2) + (5696.648*(1.0/state.T)) - 6.49291);
end dynamicViscosity;
redeclare function extends thermalConductivity "Return thermal conductivity"
algorithm
lambda := 0;
end thermalConductivity;
redeclare function extends specificEntropy "Return specific entropy"
algorithm
s := 0;
end specificEntropy;
redeclare function extends specificHeatCapacityCp "Return specific heat capacity at constant pressure"
algorithm
cp := 0;
end specificHeatCapacityCp;
redeclare function extends specificHeatCapacityCv "Return specific heat capacity at constant volume"
algorithm
cv := 0;
end specificHeatCapacityCv;
redeclare function extends isentropicExponent "Return isentropic exponent"
extends Modelica.Icons.Function;
algorithm
gamma := 1;
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
algorithm
a := 0;
end velocityOfSound;
end viscOil;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With