Reputation: 97
I am trying to define a new media following the instructions in the TemplateMedium, but can not understand why I am getting the error
Called function 'MyPackage.TestOfMyMedium.Medium.specificEnthalpy' is partial.
when running the PartialTestModel and in the other models that I want to eventually use the medium in, however the error does not show when running PartialTestModel2 for some reason.
I think my issue is very closely related/same as what is presented here (OpenModelicaForum post from 2020). In it the question poster said that after comparing their model to the water example in the Annex60 library, adding some reference_XXX and default_XXX values, and smoothorder annotations their problem was resolved, but I was unable to recreate this solution.
Below is the package containing the medium I am trying to create (with the modifications made based on the link above) and the test I am getting the error in, any advice is appreciated.
Thank you.
package MyPackage
package MyMedia "Template for media models"
extends Modelica.Media.Interfaces.PartialMedium(
final mediumName="Diesel",
final substanceNames={mediumName},
final singleState=false,
final reducedX=true,
final fixedX=true,
Temperature(
min=273,
max=373,
start=323),
p_default = 1e5,
reference_p = 1e5,
reference_T = 278.15,
reference_X = {1});
// Provide medium constants here
constant SpecificHeatCapacity cp_const=1350
"Constant specific heat capacity at constant pressure -- using approx value at 300K";
redeclare model extends BaseProperties(final standardOrderComponents=true)
"Base properties of medium"
equation
d = density(state);
h = cp_const*(T-reference_T);
u = h - reference_p/d;
MM = 0.025;
R_s = 0;
state.p = p;
state.T = T;
end BaseProperties;
redeclare function extends density "Return the density"
algorithm
d := 971 + (((state.p + (-4)*state.T-reference_T + 1700)^(-0.38 + 1))/(-0.38 + 1)) + state.p*(3e-6*(state.T-reference_T)^1.41 + (-0.005)) + (-11)*((state.T-reference_T)^0.5);
annotation (
smoothOrder=1,
Inline=true);
end density;
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";
annotation (Documentation(info="<html>
</html>"));
end ThermodynamicState;
redeclare function extends dynamicViscosity "Return dynamic viscosity"
algorithm
eta := 0.014773467;
annotation (Documentation(info="<html>
</html>"));
end dynamicViscosity;
redeclare function extends thermalConductivity
"Return thermal conductivity"
algorithm
lambda := 0.1;
annotation (Documentation(info="<html>
</html>"));
end thermalConductivity;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure"
algorithm
cp := 1350;
annotation (Documentation(info="<html>
</html>"));
end specificHeatCapacityCp;
redeclare function extends isentropicExponent "Return isentropic exponent"
extends Modelica.Icons.Function;
algorithm
gamma := 1.16;
annotation (Documentation(info="<html>
</html>"));
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
algorithm
a := 1100;
annotation (Documentation(info="<html>
</html>"));
end velocityOfSound;
end MyMedia;
model TestOfMyMedium
extends Modelica.Media.Examples.Utilities.PartialTestModel(
redeclare package Medium = MyPackage.MyMedia);
end TestOfMyMedium;
end MyPackage;
Upvotes: 2
Views: 55
Reputation: 97
Adding the setState_pTX and setState_pHX and specific enthalpy functions made it so that the value of p, h, and T are updated explicitly, and more importantly the called functions are properly defined (not as partial functions).
It seems like even though the BaseProperties object exists, and the equations for the value of specific enthalpy exists within the BaseProperties, depending on the model that the medium is used in calls to these functions are still made, requiring these functions to be redeclared in the medium package.
I am guessing that Dymola is able to deduce that this needs to happen and is able to add the calls to these functions in the background, but not in OpenModelica.
package MyMedia "Template for media models"
extends Modelica.Media.Interfaces.PartialMedium(
final mediumName="Diesel",
final substanceNames={mediumName},
final singleState=false,
final reducedX=true,
final fixedX=true,
Temperature(
min=273,
max=373,
start=323),
p_default = 1e5,
reference_p = 1e5,
reference_T = 278.15,
reference_X = {1});
// Provide medium constants here
constant SpecificHeatCapacity cp_const=1350
"Constant specific heat capacity at constant pressure -- using approx value at 300K";
redeclare model extends BaseProperties(final standardOrderComponents=true)
"Base properties of medium"
equation
d = density(state);
h = SpecificEnthalpy(state);
u = h - reference_p/d;
MM = 0.025;
R_s = 0;
state.p = p;
state.T = T;
end BaseProperties;
redeclare function extends setState_pTX "Return thermodynamic state as function of p, T and composition X or Xi"
extends Modelica.Icons.Function;
algorithm
state := ThermodynamicState(p = p, T = T);
annotation(
Inline = true);
end setState_pTX;
redeclare function extends setState_phX "Return thermodynamic state as function of p, h and composition X or Xi"
algorithm
state := ThermodynamicState(p=p, T = h / cp_const + reference_T);
annotation(
Inline = true);
end setState_phX;
redeclare function extends specificEnthalpy "Return specific enthalpy"
extends Modelica.Icons.Function;
input ThermodynamicState state "Thermodynamic state record";
output SpecificEnthalpy h "Specific enthalpy";
algorithm
h := cp_const*(state.T-reference_T);
annotation(
Documentation(info = "<html></html>"));
end specificEnthalpy;
redeclare function extends density "Return the density"
algorithm
d := 971 + (((state.p + (-4)*state.T-reference_T + 1700)^(-0.38 + 1))/(-0.38 + 1)) + state.p*(3e-6*(state.T-reference_T)^1.41 + (-0.005)) + (-11)*((state.T-reference_T)^0.5);
annotation (
smoothOrder=1,
Inline=true);
end density;
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";
annotation (Documentation(info="<html>
</html>"));
end ThermodynamicState;
redeclare function extends dynamicViscosity "Return dynamic viscosity"
algorithm
eta := 0.014773467;
annotation (Documentation(info="<html>
</html>"));
end dynamicViscosity;
redeclare function extends thermalConductivity
"Return thermal conductivity"
algorithm
lambda := 0.1;
annotation (Documentation(info="<html>
</html>"));
end thermalConductivity;
redeclare function extends specificHeatCapacityCp
"Return specific heat capacity at constant pressure"
algorithm
cp := 1350;
annotation (Documentation(info="<html>
</html>"));
end specificHeatCapacityCp;
redeclare function extends isentropicExponent "Return isentropic exponent"
extends Modelica.Icons.Function;
algorithm
gamma := 1.16;
annotation (Documentation(info="<html>
</html>"));
end isentropicExponent;
redeclare function extends velocityOfSound "Return velocity of sound"
extends Modelica.Icons.Function;
algorithm
a := 1100;
annotation (Documentation(info="<html>
</html>"));
end velocityOfSound;
end MyMedia;
Upvotes: 0